/
game_battler.h
660 lines (555 loc) · 13.9 KB
/
game_battler.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
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
/*
* 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_GAME_BATTLER_H
#define EP_GAME_BATTLER_H
// Headers
#include <string>
#include <vector>
#include "rpg_state.h"
#include "system.h"
class Game_Actor;
class Game_Party_Base;
namespace Game_BattleAlgorithm {
class AlgorithmBase;
}
typedef std::shared_ptr<Game_BattleAlgorithm::AlgorithmBase> BattleAlgorithmRef;
/**
* Game_Battler class.
*/
class Game_Battler {
public:
/**
* Constructor.
*/
Game_Battler();
/**
* Gets if battler has a state.
*
* @param state_id database state ID.
* @return whether the battler has the state.
*/
bool HasState(int state_id) const;
/**
* Gets battler states.
*
* @return vector containing the IDs of all states the battler has.
*/
std::vector<int16_t> GetInflictedStates() const;
/**
* Apply effects of Conditions to Battler
*
* @return Damage taken to Battler from conditions
*/
int ApplyConditions();
/**
* Gets battler states.
* This returns the raw state list with not inflected states set to 0 and
* inflected states set to at least 1 (this maps to the turn count).
*
* @return vector containing state list
*/
virtual const std::vector<int16_t>& GetStates() const = 0;
virtual std::vector<int16_t>& GetStates() = 0;
/**
* Checks all states and returns the first restriction that different to
* normal or normal if that is the only restriction.
*
* @return First non-normal restriction or normal if not restricted
*/
int GetSignificantRestriction() const;
/**
* Gets the Battler ID.
*
* @return Battler ID
*/
virtual int GetId() const = 0;
/**
* Tests if the battler has a "No Action" condition like sleep.
*
* @return can act
*/
bool CanAct() const;
/**
* Gets current battler state with highest priority.
*
* @return the highest priority state affecting the battler.
* Returns NULL if no states.
*/
const RPG::State* GetSignificantState() const;
/**
* Gets the state probability by rate (A-E).
*
* @param state_id State to test
* @param rate State rate to get
* @return state rate (probability)
*/
int GetStateRate(int state_id, int rate) const;
/**
* Gets the attribute damage multiplier/protection (A-E).
*
* @param attribute_id Attribute to test
* @param rate Attribute rate to get
* @return Attribute rate
*/
int GetAttributeRate(int attribute_id, int rate) const;
/**
* Applies a modifier (buff/debuff) to an attribute rate.
* GetAttributeModifier will use this shift in the rate lookup.
* A shift of +1 changed a C to D and a -1 a C to B.
* The maximum shift value is +-1.
* Calling this function again applies the new shift to the previous shifts.
* The shift is cleared after the battle ended.
*
* @param attribute_id Attribute to modify
* @param shift Shift to apply.
*/
void ShiftAttributeRate(int attribute_id, int shift);
/*
* @return true if we can shift the attribute rate by shift
*/
bool CanShiftAttributeRate(int attribute_id, int shift) const;
/**
* Gets the current modifier (buff/debuff) to an attribute rate.
* The shift is cleared after the battle ended.
*
* @param attribute_id Attribute modified
* @return shift Shift applied.
*/
int GetAttributeRateShift(int attribute_id);
/**
* Gets probability that a state can be inflicted on this actor.
*
* @param state_id State to test
* @return Probability of state infliction
*/
virtual int GetStateProbability(int state_id) const = 0;
/**
* Gets attribute protection when the actor is damaged.
*
* @param attribute_id Attribute to test
* @return Attribute resistence
*/
virtual int GetAttributeModifier(int attribute_id) const = 0;
/**
* Gets the final effect multiplier when a skill/attack is targeting this battler.
*
* @param attributes set for the incoming action
* @return effect multiplier
*/
float GetAttributeMultiplier(const std::vector<bool>& attributes_set) const;
/**
* Gets the characters name
*
* @return Character name
*/
virtual const std::string& GetName() const = 0;
/**
* Gets the filename of the character sprite
*
* @return Filename of character sprite
*/
virtual const std::string& GetSpriteName() const = 0;
/**
* Gets battler HP.
*
* @return current HP.
*/
virtual int GetHp() const = 0;
/**
* Sets the current battler HP.
*/
virtual void SetHp(int hp) = 0;
/**
* Increases/Decreases hp.
* Also handles death condition.
*
* @param hp relative hp change
*/
virtual void ChangeHp(int hp);
/**
* Gets the battler max HP.
*
* @return current max HP.
*/
virtual int GetMaxHp() const;
/**
* Gets if the battler has full hp.
*
* @return if battler is healty.
*/
virtual bool HasFullHp() const;
/**
* Gets battler SP.
*
* @return current SP.
*/
virtual int GetSp() const = 0;
/**
* Sets the current battler SP.
*/
virtual void SetSp(int _sp) = 0;
/**
* Increases/Decreases sp.
*
* @param sp relative sp change
*/
virtual void ChangeSp(int sp);
/**
* Gets the battler max SP.
*
* @return current max SP.
*/
virtual int GetMaxSp() const;
/**
* Gets if the battler has full sp.
*
* @return if battler is full of magic.
*/
virtual bool HasFullSp() const;
/**
* Gets the current battler attack.
*
* @return current attack.
*/
virtual int GetAtk() const;
/**
* Gets the current battler defense.
*
* @return current defense.
*/
virtual int GetDef() const;
/**
* Gets the current battler spirit.
*
* @return current spirit.
*/
virtual int GetSpi() const;
/**
* Gets the current battler agility.
*
* @return current agility.
*/
virtual int GetAgi() const;
/**
* Gets the maximum HP for the current level.
*
* @return max HP.
*/
virtual int GetBaseMaxHp() const = 0;
/**
* Gets the maximum SP for the current level.
*
* @return max SP.
*/
virtual int GetBaseMaxSp() const= 0;
/**
* Gets the attack for the current level.
*
* @return attack.
*/
virtual int GetBaseAtk() const = 0;
/**
* Gets the defense for the current level.
*
* @return defense.
*/
virtual int GetBaseDef() const = 0;
/**
* Gets the spirit for the current level.
*
* @return spirit.
*/
virtual int GetBaseSpi() const = 0;
/**
* Gets the agility for the current level.
*
* @return agility.
*/
virtual int GetBaseAgi() const = 0;
virtual bool IsHidden() const;
virtual bool IsImmortal() const;
virtual bool Exists() const;
bool IsDead() const;
/**
* Kills the battler
*/
void Kill();
/**
* Checks if the actor can use the skill.
*
* @param skill_id ID of skill to check.
* @return true if skill can be used.
*/
virtual bool IsSkillUsable(int skill_id) const;
/**
* Applies the effects of an item.
* Tests if using that item makes any sense (e.g. for HP healing
* items if there are any HP to heal)
*
* @param item_id ID if item to use
* @return true if item affected anything
*/
virtual bool UseItem(int item_id, const Game_Battler* source);
/**
* Applies the effects of a skill.
* Tests if using that skill makes any sense (e.g. for HP healing
* skills if there are any HP to heal)
* Does not reduce the MP, use Game_Party->UseSkill for this.
*
* @param skill_id ID of skill to use
* @param source battler who threw the skill
* @return true if skill affected anything
*/
virtual bool UseSkill(int skill_id, const Game_Battler* source);
/**
* Calculates the Skill costs including all modifiers.
*
* @param skill_id ID of skill to calculate.
* @return needed skill cost.
*/
virtual int CalculateSkillCost(int skill_id) const;
/**
* Sets the battler attack modifier.
*
* @param modifier attack modifier
*/
void SetAtkModifier(int modifier);
/**
* Sets the battler defense modifier.
*
* @param modifier defense modifier.
*/
void SetDefModifier(int modifier);
/**
* Sets the battler spirity modifier.
*
* @param modifier spirity modifier.
*/
void SetSpiModifier(int modifier);
/**
* Sets the battler agility modifier.
*
* @param modifier agility modifier.
*/
void SetAgiModifier(int modifier);
void ChangeAtkModifier(int modifier);
void ChangeDefModifier(int modifier);
void ChangeSpiModifier(int modifier);
void ChangeAgiModifier(int modifier);
/**
* Adds a State.
*
* @param state_id ID of state to add.
*/
virtual void AddState(int state_id);
/**
* Removes a State.
*
* @param state_id ID of state to remove.
*/
virtual void RemoveState(int state_id);
/**
* Removes all states which end after battle.
*/
virtual void RemoveBattleStates();
/**
* Removes all states.
*/
virtual void RemoveAllStates();
/**
* Tests if the battler has a state that provides reflect.
* Attack skills targeted at this battler will be reflected to the source.
*
* @return Reflect is enabled.
*/
bool HasReflectState() const;
/**
* Gets X position against the battle background.
*
* @return X position in battle scene
*/
virtual int GetBattleX() const = 0;
/**
* Gets Y position against the battle background.
*
* @return Y position in battle scene
*/
virtual int GetBattleY() const = 0;
/**
* Gets X position on the screen.
*
* This is equal to GetBattleX, plus a displacement for
* any screen shaking.
*/
int GetDisplayX() const;
/**
* Gets Y position on the screen.
*/
int GetDisplayY() const;
virtual int GetHue() const;
virtual int GetBattleAnimationId() const = 0;
virtual int GetHitChance() const = 0;
virtual float GetCriticalHitChance() const = 0;
/**
* @return If battler is charged (next attack double damages)
*/
bool IsCharged() const;
/**
* Sets charge state (next attack double damages)
*
* @param charge new charge state
*/
void SetCharged(bool charge);
/**
* @return If battler is defending (next turn, defense is doubled)
*/
bool IsDefending() const;
/**
* @return If battler has strong defense (defense is tripled when defending)
*/
virtual bool HasStrongDefense() const;
/**
* Tests if the battler has a weapon that grants preemption.
*
* @return true if a weapon is having preempt attribute
*/
virtual bool HasPreemptiveAttack() const;
/**
* Sets defence state (next turn, defense is doubled)
*
* @param defend new defence state
*/
void SetDefending(bool defend);
enum BattlerType {
Type_Ally,
Type_Enemy
};
virtual BattlerType GetType() const = 0;
/**
* Convenience function to access the party based on the type of this
* battler. This function does not ensure that the battler is in the
* party.
* @return Party this member probably belongs to.
*/
Game_Party_Base& GetParty() const;
/**
* Gets the maximal gauge value.
*/
int GetMaxGauge() const;
/**
* Gets the current state of the battle gauge in percent.
* Used by RPG2k3 battle system.
*
* @return gauge in percent
*/
int GetGauge() const;
/**
* Sets the gauge to a new percentage in range 0-100
* Used by RPG2k3 battle system.
*
* @param new_gauge new gauge value in percent
*/
void SetGauge(int new_gauge);
/**
* Increments the gauge by current agi.
* The size of the step is altered by the multiplier (usually based on
* the highest agi of all battlers)
* Used by RPG2k3 battle system.
*
* @param multiplier gauge increment factor
*/
void UpdateGauge(int multiplier);
/**
* Tests if the battler is ready for an action.
* Used by RPG2k3 battle system.
*
* @return If gauge is full
*/
bool IsGaugeFull() const;
/**
* @return Offset of flying enemies
*/
virtual int GetFlyingOffset() const;
/**
* Updates the Battler
*/
virtual void UpdateBattle();
/**
* Gets the current BattleAlgorithm (action to execute in battle)
*
* @return Current algorithm or NULL if none
*/
const BattleAlgorithmRef GetBattleAlgorithm() const;
/**
* Assigns a new battle algorithm (action to execute in battle) to the
* battler.
*
* @param battle_algorithm New algorithm to assign
*/
void SetBattleAlgorithm(const BattleAlgorithmRef battle_algorithm);
/**
* @return Current turn in battle
*/
int GetBattleTurn() const;
/**
* Increases the turn counter of the actor and heals states that reached
* the required numbers of turns.
*
* @return Healed states
*/
std::vector<int16_t> NextBattleTurn();
/**
* Heals states based on the passed physical rate.
*
* @param physical_rate Physical rate of the attack
*
* @return Healed states
*/
std::vector<int16_t> BattlePhysicalStateHeal(int physical_rate);
void SetBattleOrderAgi(int val);
int GetBattleOrderAgi();
void SetLastBattleAction(int battle_action);
int GetLastBattleAction() const;
void SetBattleCombo(int command_id, int times);
void GetBattleCombo(int& command_id, int& times) const;
/**
* Initializes battle related data to there default values.
*/
virtual void ResetBattle();
/**
* @return Effective physical hit rate modifier from inflicted states.
*/
int GetHitChanceModifierFromStates() const;
protected:
/** Gauge for RPG2k3 Battle */
int gauge;
/** Battle action for next turn */
BattleAlgorithmRef battle_algorithm;
bool charged;
bool defending;
int atk_modifier;
int def_modifier;
int spi_modifier;
int agi_modifier;
int battle_turn;
int last_battle_action;
int battle_combo_command_id;
int battle_combo_times;
std::vector<int> attribute_shift;
int battle_order = 0;
};
#endif