forked from EasyRPG/Player
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathautobattle.h
210 lines (181 loc) · 7.2 KB
/
autobattle.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
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
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
/*
* This file is part of EasyRPG Player.
*
* EasyRPG Player is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* EasyRPG Player is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with EasyRPG Player. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef EP_AUTOBATTLE_H
#define EP_AUTOBATTLE_H
#include <lcf/rpg/fwd.h>
#include <lcf/rpg/system.h>
#include <lcf/rpg/saveactor.h>
#include <game_battler.h>
#include <memory>
class Game_Actor;
class Game_Enemy;
namespace AutoBattle {
class AlgorithmBase;
/**
* Auto battle algorithm factory function which creates auto battle algorithm from the given name
*
* @param name of the algo.
* @return An auto battle algorithm to be used in battles.
*/
std::unique_ptr<AlgorithmBase> CreateAlgorithm(StringView name);
/**
* Base class for auto battle algorithm implementations.
*/
class AlgorithmBase {
public:
virtual ~AlgorithmBase() {}
/** @return the id of this algorithm */
virtual int GetId() const = 0;
/** @return the name of this algorithm */
virtual StringView GetName() const = 0;
/**
* Calculates the auto battle algorithm and sets the algorithm on source.
* This computation ignores states on the actor, it is the resposibility of the caller
* to handle death, confuse, provoke, etc..
*
* @param source The source actor to set the action for.
* @post source will have a BattleAlgorithm set.
*/
void SetAutoBattleAction(Game_Actor& source);
private:
virtual void vSetAutoBattleAction(Game_Actor& source) = 0;
};
/**
* The default autobattle algorithm which is strictly compatible with RPG_RT, bugs included.
*/
class RpgRtCompat: public AlgorithmBase {
public:
static constexpr auto id = 0;
static constexpr auto name = "RPG_RT";
int GetId() const override { return id; }
StringView GetName() const override { return name; }
private:
void vSetAutoBattleAction(Game_Actor& source) override;
};
/**
* An autobattle algorithm which only does physical attacks.
*/
class AttackOnly: public AlgorithmBase {
public:
static constexpr auto id = 2;
static constexpr auto name = "ATTACK";
int GetId() const override { return id; }
StringView GetName() const override { return name; }
private:
void vSetAutoBattleAction(Game_Actor& source) override;
};
/**
* A custom autobattle algorithm which is similar to RPG_RT but fixes bugs and has improved logic.
*/
class RpgRtImproved: public AlgorithmBase {
public:
static constexpr auto id = 1;
static constexpr auto name = "RPG_RT+";
int GetId() const override { return id; }
StringView GetName() const override { return name; }
private:
void vSetAutoBattleAction(Game_Actor& source) override;
};
/**
* Calculate the auto battle effectiveness rank of source using healing skill on target.
*
* @param source the user of the skill
* @param target the target of the skill
* @param skill the skill
* @param cond the battle condition
* @param apply_variance If true, apply variance to the damage
* @param emulate_bugs Emulate all RPG_RT bugs for accuracy
*
* @pre skill Must be a normal or subskill or the result is undefined.
* @pre skill must target self, ally, or ally party or the result is undefined.
*/
double CalcSkillHealAutoBattleTargetRank(const Game_Actor& source, const Game_Battler& target, const lcf::rpg::Skill& skill, lcf::rpg::System::BattleCondition cond, bool apply_variance, bool emulate_bugs);
/**
* Calculate the auto battle effectiveness rank of source using damage skill on target.
*
* @param source the user of the skill
* @param target the target of the skill
* @param skill the skill
* @param cond the battle condition
* @param apply_variance If true, apply variance to the damage
* @param emulate_bugs Emulate all RPG_RT bugs for accuracy
*
* @pre skill Must be a normal or subskill or the result is undefined.
* @pre skill must target enemy, or enemy party or the result is undefined.
*/
double CalcSkillDmgAutoBattleTargetRank(const Game_Actor& source, const Game_Battler& target, const lcf::rpg::Skill& skill, lcf::rpg::System::BattleCondition cond, bool apply_variance, bool emulate_bugs);
/**
* Calculate the auto battle total effectiveness rank of using a skill.
*
* @param source the user of the skill
* @param skill the skill
* @param cond the battle condition
* @param apply_variance If true, apply variance to the damage
* @param emulate_bugs Emulate all RPG_RT bugs for accuracy
*/
double CalcSkillAutoBattleRank(const Game_Actor& source, const lcf::rpg::Skill& skill, lcf::rpg::System::BattleCondition cond, bool apply_variance, bool emulate_bugs);
/**
* Calculate the auto battle effectiveness rank of source attacking target.
*
* @param source the user of the skill
* @param target the target of the skill
* @param cond the battle condition
* @param apply_variance If true, apply variance to the damage
* @param emulate_bugs Emulate all RPG_RT bugs for accuracy
*/
double CalcNormalAttackAutoBattleTargetRank(const Game_Actor& source, const Game_Battler& target, Game_Battler::Weapon weapon, lcf::rpg::System::BattleCondition cond, bool apply_variance, bool emulate_bugs);
/**
* Calculate the auto battle total effectiveness rank of using a normal attack.
*
* @param source the user of the skill
* @param weapon Which weapon to use in the calculation
* @param cond the battle condition
* @param apply_variance If true, apply variance to the damage
* @param emulate_bugs Emulate all RPG_RT bugs for accuracy
*/
double CalcNormalAttackAutoBattleRank(const Game_Actor& source, Game_Battler::Weapon weapon, lcf::rpg::System::BattleCondition cond, bool apply_variance, bool emulate_bugs);
/**
* Runs the RPG_RT auto battle algorithm and sets a Game_BattlerAlgorithm on the source.
*
* @param actor Which actor to select auto battle action for
* @param weapon Which weapon to use in the calculation
* @param cond the battle condition
* @param do_skills Whether to include skills or not
* @param attack_variance Whether to include variance in normal attack ranking
* @param skill_variance Whether to include variance in skill ranking
* @param emulate_bugs Emulate all RPG_RT bugs for accuracy
* @post actor may have a battle algorithm set, unless an error occured.
*/
void SelectAutoBattleAction(Game_Actor& source,
Game_Battler::Weapon weapon,
lcf::rpg::System::BattleCondition cond,
bool do_skills,
bool attack_variance,
bool skill_variance,
bool emulate_bugs);
/**
* Calls SelectAutoBattleAction() with RPG_RT strictly compatible flags.
*
* @param actor Which actor to select auto battle action for
* @param cond the battle condition
* @post actor may have a battle algorithm set, unless an error occured.
*/
inline void SelectAutoBattleActionRpgRtCompat(Game_Actor& source, lcf::rpg::System::BattleCondition cond) {
SelectAutoBattleAction(source, Game_Battler::WeaponAll, cond, true, false, true, true);
}
} // namespace AutoBattle
#endif