summaryrefslogtreecommitdiff
path: root/src/game-server/autoattack.cpp
blob: dae6b0ffcabead8b6e2f3e34cb97d94b37e3b381 (plain) (blame)
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
#include "autoattack.hpp"

void AutoAttacks::add(AutoAttack n)
{
    mAutoAttacks.push_back(n);
    // Slow, but safe.
    mAutoAttacks.sort();
}

void AutoAttacks::clear()
{
    mAutoAttacks.clear();
}

void AutoAttacks::stop()
{
    for (std::list<AutoAttack>::iterator it = mAutoAttacks.begin(); it != mAutoAttacks.end(); ++it)
        it->halt();
    mActive = false;
}

void AutoAttacks::start()
{
    for (std::list<AutoAttack>::iterator it = mAutoAttacks.begin(); it != mAutoAttacks.end(); ++it)
        it->softReset();
    mActive = true;
}

void AutoAttacks::tick(std::list<AutoAttack> *ret)
{
    for (std::list<AutoAttack>::iterator it = mAutoAttacks.begin(); it != mAutoAttacks.end(); ++it)
        if (it->tick()) {
            if (mActive)
                it->reset();
            else
                it->halt();
        } else if (ret && it->isReady())
            ret->push_back(*it);
}