-
Notifications
You must be signed in to change notification settings - Fork 0
/
ZoneQueue.h
85 lines (72 loc) · 2.28 KB
/
ZoneQueue.h
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
72
73
74
75
76
77
78
79
80
81
82
83
84
85
#pragma once
#include "PlayerData.h"
#include <list>
class ZoneQueue;
class ZoneQueueBucket;
class ZoneQueueRequirement;
// ZoneQueue is described with a name and a list of requirements
// it may have a number of players added to it
// each player added must fulfill a requirement (until the max number of that requirements is met)
//
// ZoneQueueBucket is how the requirements are added to a zone
// the bucket holds a requirement, and any players that match that requirement for the zone
typedef std::shared_ptr<ZoneQueue> ZoneQueuePtr;
typedef std::list <ZoneQueueRequirement> RequirementsList;
class ZoneQueue
{
public:
ZoneQueue(const std::string & _name, const std::list <ZoneQueueRequirement> & requirements);
bool AddPlayer(const PlayerDataPtr& player);
bool RemovePlayer(const PlayerDataPtr& player);
std::list<PlayerDataPtr> GetPlayers() const;
bool Complete() {
if (IsReady()) {
_complete = true;
}
return _complete;
}
bool IsFull() const;
bool IsComplete() const {return _complete; }
bool IsReady() const;
void report() const;
unsigned getCount() const { return _count; }
std::string getName() const { return _name; }
private:
std::string _name;
std::list <ZoneQueueBucket> _buckets;
unsigned _count;
bool _complete;
};
class ZoneQueueRequirement
{
public:
ZoneQueueRequirement(PlayerClassEnum classRestriction, unsigned minLevel, unsigned maxLevel, unsigned minPlayers, unsigned maxPlayers) :
_class(classRestriction),
_minLevel(minLevel),
_maxLevel(maxLevel),
_minPlayers(minPlayers),
_maxPlayers(maxPlayers) {}
bool IsMet(const PlayerDataPtr& player) const;
const PlayerClassEnum _class;
const unsigned _minLevel;
const unsigned _maxLevel;
const unsigned _minPlayers;
const unsigned _maxPlayers;
};
class ZoneQueueBucket {
public:
ZoneQueueBucket(ZoneQueueRequirement r) : _requirement(r) {};
std::list<PlayerDataPtr> _players;
ZoneQueueRequirement _requirement;
bool IsFull() const;
bool IsReady() const;
bool Has(const PlayerDataPtr& player);
bool Remove(const PlayerDataPtr& player);
private:
std::list<PlayerDataPtr>::iterator Find(const PlayerDataPtr& player) {
const PlayerIdType id = player->getId();
auto iter = std::find_if(std::begin(_players), std::end(_players),
[&](const auto p) { return p->getId() == id; });
return iter;
}
};