forked from miki151/keeperrl
-
Notifications
You must be signed in to change notification settings - Fork 0
/
event.cpp
86 lines (70 loc) · 2.97 KB
/
event.cpp
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
#include "stdafx.h"
#include "event.h"
#include "creature.h"
vector<EventListener*> EventListener::listeners;
void EventListener::initialize() {
listeners.clear();
}
void EventListener::addListener(EventListener* l) {
listeners.push_back(l);
}
void EventListener::removeListener(EventListener* l) {
removeElement(listeners, l);
}
void EventListener::addPickupEvent(const Creature* c, const vector<Item*>& items) {
for (EventListener* l : listeners)
if (l->getListenerLevel() == c->getLevel() || l->getListenerLevel() == nullptr)
l->onPickupEvent(c, items);
}
void EventListener::addDropEvent(const Creature* c, const vector<Item*>& items) {
for (EventListener* l : listeners)
if (l->getListenerLevel() == c->getLevel() || l->getListenerLevel() == nullptr)
l->onDropEvent(c, items);
}
void EventListener::addItemsAppeared(const Level* level, Vec2 position, const vector<Item*>& items) {
for (EventListener* l : listeners)
if (l->getListenerLevel() == level)
l->onItemsAppeared(position, items);
}
void EventListener::addKillEvent(const Creature* victim, const Creature* killer) {
for (EventListener* l : listeners)
if (l->getListenerLevel() == victim->getLevel() || l->getListenerLevel() == nullptr)
l->onKillEvent(victim, killer);
}
void EventListener::addAttackEvent(const Creature* victim, const Creature* attacker) {
for (EventListener* l : listeners)
if (l->getListenerLevel() == victim->getLevel() || l->getListenerLevel() == nullptr)
l->onAttackEvent(victim, attacker);
}
void EventListener::addThrowEvent(const Level* level, const Creature* thrower,
const Item* item, const vector<Vec2>& trajectory) {
for (EventListener* l : listeners)
if (l->getListenerLevel() == level || l->getListenerLevel() == nullptr)
l->onThrowEvent(thrower, item, trajectory);
}
void EventListener::addExplosionEvent(const Level* level, Vec2 pos) {
for (EventListener* l : listeners)
if (l->getListenerLevel() == level || l->getListenerLevel() == nullptr)
l->onExplosionEvent(level, pos);
}
void EventListener::addTriggerEvent(const Level* level, Vec2 pos) {
for (EventListener* l : listeners)
if (l->getListenerLevel() == level || l->getListenerLevel() == nullptr)
l->onTriggerEvent(level, pos);
}
void EventListener::addSquareReplacedEvent(const Level* level, Vec2 pos) {
for (EventListener* l : listeners)
if (l->getListenerLevel() == level || l->getListenerLevel() == nullptr)
l->onSquareReplacedEvent(level, pos);
}
void EventListener::addChangeLevelEvent(const Creature* c, const Level* level, Vec2 pos,
const Level* to, Vec2 toPos) {
for (EventListener* l : listeners)
if (l->getListenerLevel() == level || l->getListenerLevel() == nullptr)
l->onChangeLevelEvent(c, level, pos, to, toPos);
}
void EventListener::addCombatEvent(const Creature* c) {
for (EventListener* l : listeners)
if (l->getListenerLevel() == c->getLevel() || l->getListenerLevel() == nullptr)
l->onCombatEvent(c);
}