Replace most collections with Arbutils collections for more safety.
All checks were successful
continuous-integration/drone/push Build is passing
All checks were successful
continuous-integration/drone/push Build is passing
This commit is contained in:
@@ -2,11 +2,15 @@
|
||||
#define CREATURELIB_EXECUTINGATTACK_HPP
|
||||
|
||||
#include <Arbutils/Assert.hpp>
|
||||
#include <Arbutils/Collections/Dictionary.hpp>
|
||||
#include <Arbutils/Collections/List.hpp>
|
||||
#include <cstdint>
|
||||
#include <unordered_map>
|
||||
#include <vector>
|
||||
#include "Creature.hpp"
|
||||
|
||||
using namespace Arbutils::Collections;
|
||||
|
||||
namespace CreatureLib::Battling {
|
||||
class ExecutingAttack : public ScriptSource {
|
||||
public:
|
||||
@@ -35,7 +39,7 @@ namespace CreatureLib::Battling {
|
||||
|
||||
class TargetData {
|
||||
bool _isHit = true;
|
||||
std::vector<HitData> _hits;
|
||||
List<HitData> _hits;
|
||||
|
||||
public:
|
||||
explicit TargetData(uint8_t numberOfHits) : _hits(numberOfHits) {
|
||||
@@ -47,26 +51,25 @@ namespace CreatureLib::Battling {
|
||||
|
||||
HitData* GetHit(uint8_t index) { return &_hits[index]; }
|
||||
|
||||
uint8_t GetNumberOfHits() const { return _hits.size(); }
|
||||
uint8_t GetNumberOfHits() const { return _hits.Count(); }
|
||||
|
||||
bool IsHit() const { return _isHit; }
|
||||
};
|
||||
|
||||
private:
|
||||
std::unordered_map<Creature*, TargetData> _targets;
|
||||
Dictionary<Creature*, TargetData> _targets;
|
||||
Creature* _user;
|
||||
LearnedAttack* _attack;
|
||||
Script* _script;
|
||||
|
||||
public:
|
||||
ExecutingAttack(const std::vector<Creature*>& targets, uint8_t numberHits, Creature* user,
|
||||
LearnedAttack* attack, Script* script)
|
||||
: _user(user), _attack(attack), _script(script) {
|
||||
ExecutingAttack(const List<Creature*>& targets, uint8_t numberHits, Creature* user, LearnedAttack* attack,
|
||||
Script* script)
|
||||
: _targets(targets.Count()), _user(user), _attack(attack), _script(script) {
|
||||
AssertNotNull(user)
|
||||
AssertNotNull(attack)
|
||||
_targets.reserve(targets.size());
|
||||
for (auto target : targets) {
|
||||
_targets.insert({target, TargetData(numberHits)});
|
||||
_targets.Insert(target, TargetData(numberHits));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -74,17 +77,17 @@ namespace CreatureLib::Battling {
|
||||
|
||||
TargetData* GetAttackDataForTarget(Creature* creature) { return &_targets[creature]; }
|
||||
|
||||
bool IsCreatureTarget(Creature* creature) { return _targets.find(creature) != _targets.end(); }
|
||||
bool IsCreatureTarget(Creature* creature) { return _targets.Has(creature); }
|
||||
|
||||
std::unordered_map<Creature*, TargetData>& GetTargets() { return _targets; }
|
||||
Dictionary<Creature*, TargetData>& GetTargets() { return _targets; }
|
||||
|
||||
Creature* GetUser() { return _user; }
|
||||
|
||||
LearnedAttack* GetAttack() { return _attack; }
|
||||
|
||||
protected:
|
||||
void GetActiveScripts(std::vector<ScriptWrapper>& scripts) override {
|
||||
scripts.emplace_back(&_script);
|
||||
void GetActiveScripts(Arbutils::Collections::List<ScriptWrapper>& scripts) override {
|
||||
scripts.Append(&_script);
|
||||
_user->GetActiveScripts(scripts);
|
||||
}
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user