forked from Dzejrou/tdt
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathOnHitHelper.cpp
More file actions
48 lines (42 loc) · 1.22 KB
/
OnHitHelper.cpp
File metadata and controls
48 lines (42 loc) · 1.22 KB
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
#include "OnHitHelper.hpp"
#include "Components.hpp"
#include "EntitySystem.hpp"
#include "lppscript/LppScript.hpp"
void OnHitHelper::set_blueprint(EntitySystem& ents, std::size_t id, const std::string& val)
{
auto comp = ents.get_component<OnHitComponent>(id);
if(comp)
comp->blueprint = val;
}
const std::string& OnHitHelper::get_blueprint(EntitySystem& ents, std::size_t id)
{
static const std::string NO_BLUEPRINT{"ERROR"};
auto comp = ents.get_component<OnHitComponent>(id);
if(comp)
return comp->blueprint;
else
return NO_BLUEPRINT;
}
void OnHitHelper::call(EntitySystem& ents, std::size_t id, std::size_t hitter)
{
auto comp = ents.get_component<OnHitComponent>(id);
if(comp && comp->curr_time >= comp->cooldown)
{
comp->curr_time = 0.f;
lpp::Script::get_singleton().call<void, std::size_t, std::size_t>(comp->blueprint + ".on_hit", id, hitter);
}
}
void OnHitHelper::set_cooldown(EntitySystem& ents, std::size_t id, Ogre::Real val)
{
auto comp = ents.get_component<OnHitComponent>(id);
if(comp)
comp->cooldown = val;
}
Ogre::Real OnHitHelper::get_cooldown(EntitySystem& ents, std::size_t id)
{
auto comp = ents.get_component<OnHitComponent>(id);
if(comp)
return comp->cooldown;
else
return Ogre::Real{};
}