aboutsummaryrefslogtreecommitdiffstats
path: root/src/main/cpp/MeleeWeapon.cpp
blob: 8c7ffce3b1bfe6be90eba0e692f7a254111601b2 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
#include "Weapon.hpp"
#include "MeleeWeapon.hpp"
#include "Actor.hpp"

#include <string>

MeleeWeapon::MeleeWeapon(Type t, const std::string &name, bool throwable)
: Weapon(Item::Type::MELEEWEAPON, name), type(t), _throwable(throwable)
{
}

bool MeleeWeapon::use(Actor &user, Actor &actor)
{
    //TODO implements attack probability
    //TODO balance advantages 
    MeleeWeapon* weapon = dynamic_cast <MeleeWeapon*> (user.weapon());
    int bonus;

    if (MeleeWeapon* enemyWeapon = dynamic_cast <MeleeWeapon*> (actor.weapon())) {
        switch (weapon->type) {
        case MeleeWeapon::Type::AXE:
            switch (enemyWeapon->type) {
            case MeleeWeapon::Type::AXE:
                bonus = 0;
                break;
            case MeleeWeapon::Type::LANCE:
                bonus = 10;
                break;
            case MeleeWeapon::Type::SWORD:
                bonus = -10;
                break;
            }
            break;
        case MeleeWeapon::Type::LANCE:
            switch (enemyWeapon->type) {
            case MeleeWeapon::Type::AXE:
                bonus = -10;
                break;
            case MeleeWeapon::Type::LANCE:
                bonus = 0;
                break;
            case MeleeWeapon::Type::SWORD:
                bonus = 10;
                break;
            }
            break;
        case MeleeWeapon::Type::SWORD:
            switch (enemyWeapon->type) {
            case MeleeWeapon::Type::AXE:
                bonus = 10;
                break;
            case MeleeWeapon::Type::LANCE:
                bonus = -10;
                break;
            case MeleeWeapon::Type::SWORD:
                bonus = 0;
                break;
            }
            break;
        }
    } else {
        bonus = 0;
    }

    if (actor.levelAxe() <= _requiredLevel) {
        actor.damage(_damage + user.attack() - actor.defence() + bonus);
        return true;
    } else {
        return false;
    }
}