Initial setup for script hooks (likely to be revamped)
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:
15
src/Battling/ScriptHandling/Hooks.hpp
Normal file
15
src/Battling/ScriptHandling/Hooks.hpp
Normal file
@@ -0,0 +1,15 @@
|
||||
#ifndef CREATURELIB_HOOKS_HPP
|
||||
#define CREATURELIB_HOOKS_HPP
|
||||
|
||||
#include <cstdint>
|
||||
|
||||
namespace CreatureLib::Battling{
|
||||
enum class Hook : uint8_t{
|
||||
IncomingAttackFails,
|
||||
IsInvulnerable,
|
||||
AttackMiss,
|
||||
ChangeMove,
|
||||
};
|
||||
}
|
||||
|
||||
#endif //CREATURELIB_HOOKS_HPP
|
||||
27
src/Battling/ScriptHandling/Script.hpp
Normal file
27
src/Battling/ScriptHandling/Script.hpp
Normal file
@@ -0,0 +1,27 @@
|
||||
#ifndef CREATURELIB_SCRIPT_HPP
|
||||
#define CREATURELIB_SCRIPT_HPP
|
||||
|
||||
#include <any>
|
||||
#include <string>
|
||||
#include <utility>
|
||||
#include <vector>
|
||||
#include "Hooks.hpp"
|
||||
|
||||
namespace CreatureLib::Battling{
|
||||
class Script{
|
||||
const std::string _name;
|
||||
|
||||
public:
|
||||
explicit Script(std::string name) :_name(std::move(name)){}
|
||||
virtual ~Script() = default;
|
||||
|
||||
virtual void Execute(Hook hook, const std::vector<std::any>& args){};
|
||||
virtual void Stack(){};
|
||||
|
||||
const std::string& GetName(){
|
||||
return _name;
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
#endif //CREATURELIB_SCRIPT_HPP
|
||||
34
src/Battling/ScriptHandling/ScriptSet.hpp
Normal file
34
src/Battling/ScriptHandling/ScriptSet.hpp
Normal file
@@ -0,0 +1,34 @@
|
||||
#ifndef CREATURELIB_SCRIPTSET_HPP
|
||||
#define CREATURELIB_SCRIPTSET_HPP
|
||||
|
||||
#include <any>
|
||||
#include <unordered_map>
|
||||
#include "Script.hpp"
|
||||
|
||||
namespace CreatureLib::Battling{
|
||||
class ScriptSet{
|
||||
std::unordered_map<std::string, Script*> _scripts;
|
||||
public:
|
||||
void Execute(Hook hook, const std::vector<std::any>& args){
|
||||
for (auto s: _scripts){
|
||||
s.second->Execute(hook, args);
|
||||
}
|
||||
}
|
||||
|
||||
void Add(Script* script){
|
||||
auto f = _scripts.find(script->GetName());
|
||||
if (f != _scripts.end()){
|
||||
f->second->Stack();
|
||||
}
|
||||
else{
|
||||
_scripts.insert({script->GetName(), script});
|
||||
}
|
||||
}
|
||||
|
||||
void Remove(const std::string& key){
|
||||
_scripts.erase(key);
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
#endif //CREATURELIB_SCRIPTSET_HPP
|
||||
Reference in New Issue
Block a user