forked from Illarion-eV/Illarion-Server
/
LuaMonsterScript.cpp
150 lines (123 loc) · 5.7 KB
/
LuaMonsterScript.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
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
/*
* illarionserver - server for the game Illarion
* Copyright 2011 Illarion e.V.
*
* This file is part of illarionserver.
*
* illarionserver is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* illarionserver is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with illarionserver. If not, see <http://www.gnu.org/licenses/>.
*/
#include "LuaMonsterScript.hpp"
#include "Monster.hpp"
#include "World.hpp"
#include "Character.hpp"
#include "Player.hpp"
#include "fuse_ptr.hpp"
LuaMonsterScript::LuaMonsterScript() throw(ScriptException)
: LuaScript() {
}
LuaMonsterScript::LuaMonsterScript(std::string filename) throw(ScriptException)
: LuaScript(filename) {
}
LuaMonsterScript::~LuaMonsterScript() throw() {}
void LuaMonsterScript::onDeath(Character *Monster) {
fuse_ptr<Character> fuse_Monster(Monster);
callEntrypoint("onDeath", fuse_Monster);
}
void LuaMonsterScript::lookAtMonster(Character *source, Character *target, unsigned char mode) {
fuse_ptr<Character> fuse_source(source);
fuse_ptr<Character> fuse_target(target);
callEntrypoint("lookAtMonster", fuse_source, fuse_target, mode);
}
void LuaMonsterScript::receiveText(Character *Monster, Character::talk_type tt, std::string message, Character *cc) {
fuse_ptr<Character> fuse_Monster(Monster);
fuse_ptr<Character> fuse_cc(cc);
callEntrypoint("receiveText", fuse_Monster, (int)tt, message, fuse_cc);
}
void LuaMonsterScript::onAttacked(Character *Monster, Character *attacker) {
fuse_ptr<Character> fuse_Monster(Monster);
fuse_ptr<Character> fuse_attacker(attacker);
callEntrypoint("onAttacked", fuse_Monster, fuse_attacker);
}
void LuaMonsterScript::onCasted(Character *Monster, Character *caster) {
fuse_ptr<Character> fuse_Monster(Monster);
fuse_ptr<Character> fuse_caster(caster);
callEntrypoint("onCasted", fuse_Monster, fuse_caster);
}
void LuaMonsterScript::useMonster(Character *Monster, Character *user, unsigned short int counter, unsigned short int param, unsigned char ltastate) {
fuse_ptr<Character> fuse_Monster(Monster);
fuse_ptr<Character> fuse_user(user);
callEntrypoint("useMonster", fuse_Monster, fuse_user, counter, param, ltastate);
}
void LuaMonsterScript::useMonsterWithCharacter(Character *Monster, Character *user, Character *targetChar, unsigned short int counter, unsigned short param, unsigned char ltastate) {
fuse_ptr<Character> fuse_Monster(Monster);
fuse_ptr<Character> fuse_user(user);
fuse_ptr<Character> fuse_targetChar(targetChar);
callEntrypoint("useMonsterWithCharacter", fuse_Monster, fuse_user, fuse_targetChar, counter, param, ltastate);
}
void LuaMonsterScript::useMonsterWithField(Character *Monster, Character *user, position pos, unsigned short int counter, unsigned short param, unsigned char ltastate) {
fuse_ptr<Character> fuse_Monster(Monster);
fuse_ptr<Character> fuse_user(user);
callEntrypoint("useMonsterWithField", fuse_Monster, fuse_user, pos, counter, param, ltastate);
}
void LuaMonsterScript::useMonsterWithItem(Character *Monster, Character *user, ScriptItem item, unsigned short int counter, unsigned short param, unsigned char ltastate) {
fuse_ptr<Character> fuse_Monster(Monster);
fuse_ptr<Character> fuse_user(user);
callEntrypoint("useMonsterWithItem", fuse_Monster, fuse_user, item, counter, param, ltastate);
}
bool LuaMonsterScript::actionDisturbed(Character *performer, Character *disturber) {
fuse_ptr<Character> fuse_performer(performer);
fuse_ptr<Character> fuse_disturber(disturber);
return callEntrypoint<bool>("actionDisturbed", fuse_performer, fuse_disturber);
}
void LuaMonsterScript::onAttack(Character *Monster, Character *target) {
fuse_ptr<Character> fuse_Monster(Monster);
fuse_ptr<Character> fuse_target(target);
callEntrypoint("onAttack", fuse_Monster, fuse_target);
}
bool LuaMonsterScript::enemyOnSight(Character *Monster, Character *enemy) {
fuse_ptr<Character> fuse_Monster(Monster);
fuse_ptr<Character> fuse_enemy(enemy);
return callEntrypoint<bool>("enemyOnSight", fuse_Monster, fuse_enemy);
}
bool LuaMonsterScript::enemyNear(Character *Monster, Character *enemy) {
fuse_ptr<Character> fuse_Monster(Monster);
fuse_ptr<Character> fuse_enemy(enemy);
return callEntrypoint<bool>("enemyNear", fuse_Monster, fuse_enemy);
}
void LuaMonsterScript::abortRoute(Character *Monster) {
fuse_ptr<Character> fuse_Monster(Monster);
callEntrypoint("abortRoute", fuse_Monster);
}
void LuaMonsterScript::onSpawn(Character *Monster) {
fuse_ptr<Character> fuse_Monster(Monster);
callEntrypoint("onSpawn", fuse_Monster);
}
bool LuaMonsterScript::setTarget(Character *Monster, std::vector<Player *> & CandidateList, Player * &Target) {
Target = 0;
if (!existsEntrypoint("setTarget")) {
return false;
}
luabind::object luaCandidateList = luabind::newtable(_luaState);
int index = 1;
for (auto it = CandidateList.begin(); it != CandidateList.end(); ++it) {
fuse_ptr<Character> fuse_it(*it);
luaCandidateList[index++] = fuse_it;
}
fuse_ptr<Character> fuse_Monster(Monster);
index = callEntrypoint<int>("setTarget", fuse_Monster, luaCandidateList) - 1;
if (index >= 0 && index < (int)CandidateList.size()) {
Target = CandidateList[index];
}
return true;
}