aboutsummaryrefslogtreecommitdiffstats
path: root/src/main/cpp/RangedWeapon.cpp
blob: 6f246669e9cb2813fffa23e2891c108fb57c9b32 (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
#include "RangedWeapon.hpp"
#include "Actor.hpp"
#include "Bullet.hpp"

RangedWeapon::RangedWeapon(const std::string &name)
: Weapon(Item::Type::RANGEDWEAPON, name)
{
}

bool RangedWeapon::use(Actor &user, Actor &actor)
{
    //TODO implement attack probability
    if (_charged) {
        actor.damage(user.attack() + _damage - actor.defence());
        _charged = false;
    }

    return true;
}

bool RangedWeapon::reload(Actor &actor)
{
    //TODO add bullet type
    std::list<Item*> inventory = actor.inventory();
    for (Item *item : inventory) {
        if (item->type == Item::Type::BULLET) {
            //TODO get the bullet
            // Bullet *bullet = dynamic_cast <Bullet*> (item);
            break;
        }
    }

    // TODO remove
    return true;

    /*
    if (bullet->decreaseAmount(1)) {
        _charged = true;
        return true;
    } else {
        return false;
    }
    */

}