Skip to content

Commit e083c31

Browse files
committed
controller fix
1 parent da54738 commit e083c31

File tree

11 files changed

+122
-43
lines changed

11 files changed

+122
-43
lines changed

cpp-backend-new/src/combatants/Combatant.cpp

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -17,19 +17,14 @@ Combatant::Combatant(int troops, Stats stats)
1717
*
1818
* @param status_effect value passed status effect
1919
*/
20-
void Combatant::addStatusEffect(TimedEffect status_effect)
20+
void Combatant::addStatusEffect(TimedEffect timed_effect, EffectType type)
2121
{
22-
status_effects.push_back(status_effect);
22+
status_manager.addStatusEffect(timed_effect, type);
2323
}
2424

25-
/**
26-
* @brief adds a buff effect to the combatant
27-
*
28-
* @param buff_effect value passed buff effect
29-
*/
30-
void Combatant::addBuffEffect(TimedEffect buff_effect)
25+
bool Combatant::checkEffectActive(EffectType effect_type)
3126
{
32-
buff_effects.push_back(buff_effect);
27+
return status_manager.checkEffectActive(effect_type);
3328
}
3429

3530
void Combatant::addSkill(Skill& skill, CombatantEvent combat_event)

cpp-backend-new/src/combatants/Combatant.hpp

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,10 @@
22
#define COMBATANT_HPP
33

44
#include "../effects/TimedEffect.hpp"
5+
#include "../effects/EffectType.hpp"
56
#include "../orchestration/CombatPublisher.hpp"
67
#include "../orchestration/CombatantEvents.hpp"
8+
#include "StatusController.hpp"
79
#include "../skills/Skill.hpp"
810
#include "Stats.hpp"
911
#include <vector>
@@ -13,9 +15,9 @@ class Combatant
1315
public:
1416
Combatant(int troops, Stats stats);
1517

18+
bool checkEffectActive(EffectType effect_type);
1619
void addSkill(Skill& skill, CombatantEvent combat_event);
17-
void addStatusEffect(TimedEffect status_effect);
18-
void addBuffEffect(TimedEffect buff_effect);
20+
void addStatusEffect(TimedEffect timed_effect, EffectType type);
1921

2022
void setTroops(int troops);
2123
int getTroops();
@@ -28,10 +30,11 @@ class Combatant
2830
int troops;
2931
Stats stats;
3032
CombatPublisher combat_publisher;
31-
33+
StatusController status_manager;
34+
3235
std::vector<TimedEffect> status_effects;
3336
std::vector<TimedEffect> buff_effects;
3437
std::vector<const Skill*> skills;
35-
};
38+
};
3639

3740
#endif
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
#include "StatusController.hpp"
2+
#include "effects/EffectType.hpp"
3+
4+
StatusController::StatusController()
5+
{
6+
for (int i = 0; i < static_cast<int>(EffectType::COUNT); ++i)
7+
{
8+
debuff_collection[static_cast<EffectType>(i)] = std::vector<TimedEffect>();
9+
}
10+
}
11+
12+
void StatusController::addStatusEffect(const TimedEffect effect, EffectType type)
13+
{
14+
// get the timed effects for a specific debuff type
15+
std::vector<TimedEffect>& timed_effects = debuff_collection[type];
16+
// needs to check its not already on there also, do later
17+
timed_effects.push_back(effect);
18+
}
19+
20+
void StatusController::removeRandomBuffEffect(int num_removals)
21+
{
22+
// filler 4 now
23+
}
24+
void StatusController::removeAllDebuffEffects()
25+
{
26+
// filler 4 now
27+
}
28+
29+
bool StatusController::checkEffectActive(EffectType type) const
30+
{
31+
const std::vector<TimedEffect>& timed_effects = debuff_collection.at(type);
32+
return (timed_effects.size() > 0);
33+
}
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
#ifndef STATUS_MANAGER_HPP
2+
#define STATUS_MANAGER_HPP
3+
4+
#include "effects/TimedEffect.hpp"
5+
#include "effects/EffectType.hpp"
6+
7+
#include <vector>
8+
#include <map>
9+
10+
class StatusController
11+
{
12+
public:
13+
StatusController();
14+
void addStatusEffect(const TimedEffect effect, EffectType type);
15+
void removeRandomBuffEffect(int num_removals);
16+
void removeAllDebuffEffects();
17+
bool checkEffectActive(EffectType type) const;
18+
private:
19+
// Collection of active debuffs grouped by type
20+
std::map<EffectType, std::vector<TimedEffect>> debuff_collection;
21+
// List of general status effects
22+
std::vector<TimedEffect> status_effects;
23+
};
24+
25+
#endif

cpp-backend-new/src/combatants/StatusManager.hpp

Lines changed: 0 additions & 23 deletions
This file was deleted.
Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,16 @@
1-
#ifndef EFFECT_TYPES_HPP
2-
#define EFFECT_TYPES_HPP
1+
#ifndef EFFECT_TYPE_HPP
2+
#define EFFECT_TYPE_HPP
33

44
enum class EffectType
55
{
6+
START,
67
BURN,
78
BLEED,
89
POISON,
910
ABSORPTION,
1011
HEALING,
1112
RETRIBUTION,
12-
DIRECT_DAMAGE
13+
COUNT
1314
};
1415

1516
#endif
Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
#ifndef TIMER
2-
#define TIMER
1+
#ifndef TIMER_HPP
2+
#define TIMER_HPP
33

44
class Timer
55
{
@@ -10,4 +10,4 @@ class Timer
1010
short duration;
1111
};
1212

13-
#endif
13+
#endif // TIMER_HPP

cpp-backend-new/src/main.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1-
int main() {
1+
int main()
2+
{
23
return 0;
34
}
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
#ifndef CONDITION_TYPE_HPP
2+
#define CONDITION_TYPE_HPP
3+
4+
enum class ConditionType
5+
{
6+
HAS_EFFECT_SELF,
7+
HAS_EFFECT_TARGET,
8+
TROOP_COUNT_GREATER_THAN_TARGET
9+
};
10+
11+
#endif
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
#include "SkillCondition.hpp"
2+
3+
bool SkillCondition::isMet(Combatant self, Combatant target)
4+
{
5+
switch(condition_type)
6+
{
7+
case ConditionType::HAS_EFFECT_SELF:
8+
break;
9+
case ConditionType::HAS_EFFECT_TARGET:
10+
break;
11+
case ConditionType::TROOP_COUNT_GREATER_THAN_TARGET:
12+
break;
13+
}
14+
return true;
15+
}

0 commit comments

Comments
 (0)