-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathPriorityActionList.cpp
144 lines (131 loc) · 5.12 KB
/
PriorityActionList.cpp
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
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
#include "PriorityActionList.h"
#include "PlayerCharacter.h"
std::vector<PriorityAction *>& PriorityActionList::getPriorityActions()
{
return priorityActions;
}
PriorityActionList::PriorityActionList()
{
}
PriorityAction *PriorityActionList::getNextAction(PlayerCharacter *PC, float timestamp)
{
if (PC->getIsCasting()) {
return nullptr;
}
bool showFailureReason = false;
FailureReason failureReason;
for (int i=0; i<this->priorityActions.size(); ++i) {
bool shouldCheckAbility = true;
if (this->priorityActions[i]->getPredicate() != nullptr) {
shouldCheckAbility = this->priorityActions[i]->getPredicate()(PC, timestamp);
if (!shouldCheckAbility) {
failureReason = FailureReason::Predicate;
if (this->priorityActions[i]->getSkipToNextActionIfUseConditionFails() == false) {
//skip lower priority skills if this flag is set to false
break;
}
}
}
if (this->priorityActions[i]->getDisabled()) {
shouldCheckAbility = false;
failureReason = FailureReason::Disabled;
}
if (shouldCheckAbility) {
if (this->priorityActions[i]->getAbility() != nullptr) {
bool meetsGcdCondition =
this->priorityActions[i]->getIgnoreGcd() ||
!this->priorityActions[i]->getAbility()->getIsGcdAbility() ||
!PC->getIsGcdActive(timestamp);
if (meetsGcdCondition) {
bool cdCondition = !this->priorityActions[i]->getAbility()->isOnCooldown(PC, timestamp);
bool resourceCondition =
this->priorityActions[i]->getIgnoreResourceCost() ||
this->priorityActions[i]->getAbility()->hasEnoughResource(PC, timestamp);
bool meetsCdAndResourceCondition =
cdCondition && resourceCondition;
if (meetsCdAndResourceCondition) {
if (this->priorityActions[i]->getAbility()->getCanUseFunction() == nullptr ||
this->priorityActions[i]->getAbility()->getCanUseFunction()(PC, this->priorityActions[i]->getAbility()->getRank(), timestamp)) {
failureReason = FailureReason::Success;
return this->priorityActions[i];
} else {
failureReason = FailureReason::CanUseCondition;
}
}
else {
if (!cdCondition)
failureReason = FailureReason::Cooldown;
else if (!resourceCondition)
failureReason = FailureReason::OutOfResource;
}
}
else {
failureReason = FailureReason::GCD;
}
}
}
if (failureReason != FailureReason::Success) {
//std::cout<<this->priorityActions[i]->getAbility()->getName()<<" failed due to "<<(int)failureReason<<'\n';
}
if (failureReason == FailureReason::OutOfResource) {
//Do not try lower priority skills if we were out of resource
break;
}
}
return nullptr;
}
PriorityAction *PriorityActionList::getActionFromAbilityName(std::string name)
{
for (int i=0; i<this->priorityActions.size(); ++i) {
if (this->priorityActions[i]->getAbility() != nullptr && this->priorityActions[i]->getAbility()->getName() == name) {
return this->priorityActions[i];
}
}
return nullptr;
}
PriorityAction *PriorityActionList::getActionFromInternalName(std::string name)
{
for (int i=0; i<this->priorityActions.size(); ++i) {
if (this->priorityActions[i]->getInternalName() == name) {
return this->priorityActions[i];
}
}
return nullptr;
}
PriorityAction *PriorityActionList::addNewAction(PriorityAction *action)
{
if (action != nullptr) {
this->priorityActions.push_back(action);
}
return action;
}
bool PriorityActionList::removeExistingAction(PriorityAction *action)
{
if (action == nullptr)
return false;
for (auto&& it=this->priorityActions.begin(); it!=this->priorityActions.end(); ++it) {
if (*it == action) {
this->priorityActions.erase(it);
return true;
}
}
return false;
}
PriorityAction *PriorityActionList::getMainHandAutoAttackAction()
{
PriorityAction *mhAttack = this->getActionFromAbilityName("Main-hand attack");
return mhAttack;
}
PriorityAction *PriorityActionList::getOffHandAutoAttackAction()
{
PriorityAction *ohAttack = this->getActionFromAbilityName("Off-hand attack");
return ohAttack;
}
void PriorityActionList::resetAllAbilities()
{
for (int i=0; i<this->priorityActions.size(); ++i) {
if (this->priorityActions[i]->getAbility() != nullptr) {
this->priorityActions[i]->getAbility()->reset();
}
}
}