forked from elonafoobar/elonafoobar
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbuff.cpp
275 lines (250 loc) · 6.62 KB
/
buff.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
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
#include "buff.hpp"
#include "ability.hpp"
#include "cat.hpp"
#include "character.hpp"
#include "elona.hpp"
#include "fov.hpp"
#include "i18n.hpp"
#include "random.hpp"
#include "variables.hpp"
#include <iostream>
using namespace elona;
namespace elona
{
buff_db the_buff_db;
buff_db::buff_db()
{
storage.emplace(
0,
buff_data{0,
LUA_REFNIL,
buff_data::type_t::buff,
LUA_REFNIL,
LUA_REFNIL}); // dummy
}
void buff_db::define(lua_State* L)
{
const char* id = luaL_checkstring(L, -2);
if (!id)
throw std::runtime_error(u8"Error: fail to load buff data");
ELONA_CAT_DB_FIELD_INTEGER(type_, 0);
ELONA_CAT_DB_FIELD_REF(duration);
ELONA_CAT_DB_FIELD_REF(on_refresh);
cat::ref self = luaL_ref(L, LUA_REGISTRYINDEX);
// Dummy; after calling this function, the caller pop one value from the Lua
// stack.
lua_pushnil(L);
storage.emplace(
std::stoi(id), // TODO
buff_data{
std::stoi(id),
self,
buff_data::type_t(type_),
duration,
on_refresh,
});
}
int buff_find(int prm_799, int prm_800)
{
int f_at_m131 = 0;
f_at_m131 = -1;
for (int cnt = 0; cnt < 16; ++cnt)
{
if (cdata[prm_799].buffs[cnt].id == 0)
{
break;
}
if (cdata[prm_799].buffs[cnt].id == prm_800)
{
f_at_m131 = cnt;
break;
}
}
return f_at_m131;
}
int buff_add(int prm_801, int prm_802, int prm_803, int prm_804)
{
int p_at_m132 = 0;
int fixeddur_at_m132 = 0;
int f_at_m132 = 0;
if (prm_804 <= 0)
{
return 0;
}
p_at_m132 = -1;
for (int cnt = 0; cnt < 16; ++cnt)
{
if (cdata[prm_801].buffs[cnt].id == prm_802)
{
if (cdata[prm_801].buffs[cnt].turns < prm_804)
{
p_at_m132 = cnt;
break;
}
else
{
p_at_m132 = -2;
break;
}
}
if (cdata[prm_801].buffs[cnt].id == 0)
{
p_at_m132 = cnt;
break;
}
}
if (p_at_m132 == -1)
{
p_at_m132 = rnd(16);
}
if (p_at_m132 == -2)
{
if (is_in_fov(prm_801))
{
txt(lang(
u8"しかし、効果はなかった。"s,
u8"But it produces no effect."s));
return 0;
}
}
fixeddur_at_m132 = prm_804;
if (the_buff_db[prm_802]->type == buff_data::type_t::hex)
{
f_at_m132 = 0;
if (sdata(60, prm_801) / 2 > rnd(prm_803 * 2 + 100))
{
f_at_m132 = 1;
}
if (prm_803 * 3 < sdata(60, prm_801))
{
f_at_m132 = 1;
}
if (prm_803 / 3 > sdata(60, prm_801))
{
f_at_m132 = 0;
}
if (cdata[prm_801].quality > 3)
{
if (rnd(4))
{
f_at_m132 = 1;
}
else
{
fixeddur_at_m132 = prm_804 / 5 + 1;
}
}
if (cdata[prm_801].quality >= 4)
{
if (prm_802 == 16)
{
f_at_m132 = 1;
}
}
if (buff_find(prm_801, 10) != -1)
{
if (cdata[prm_801].buffs[buff_find(prm_801, 10)].power + 50
> prm_803 * 5 / 2
|| rnd(cdata[prm_801].buffs[buff_find(prm_801, 10)].power + 50)
> rnd(prm_803 + 1))
{
txt(lang(
u8"ホーリーヴェイルが呪いを防いだ。"s,
u8"The holy veil repels the hex."s));
return 0;
}
}
if (f_at_m132 == 1)
{
if (is_in_fov(prm_801))
{
txt(lang(
name(prm_801) + u8"は抵抗した。"s,
name(prm_801) + u8" resist"s + _s(prm_801)
+ u8" the hex."s));
}
return 0;
}
if (cc == 0)
{
hostileaction(0, prm_801);
}
}
if (the_buff_db[prm_802]->type != buff_data::type_t::food
&& is_in_fov(prm_801))
{
txt(lang(
name(prm_801)
+ i18n::_(u8"buff", std::to_string(prm_802), u8"message_0"),
name(prm_801) + u8" "s
+ i18n::_(u8"buff", std::to_string(prm_802), u8"message_0")
+ _s(prm_801)
+ i18n::_(u8"buff", std::to_string(prm_802), u8"message_1")));
}
cdata[prm_801].buffs[p_at_m132].id = prm_802;
cdata[prm_801].buffs[p_at_m132].power = prm_803;
cdata[prm_801].buffs[p_at_m132].turns = fixeddur_at_m132;
chara_refresh(prm_801);
return 0;
}
void buff_delete(int prm_805, int prm_806)
{
if (prm_805 == 0)
{
txtef(8);
txt(lang(
""s
+ i18n::_(
u8"buff",
std::to_string(cdata[prm_805].buffs[prm_806].id),
u8"name")
+ u8"の効果が切れた。"s,
u8"The effect of "s
+ i18n::_(
u8"buff",
std::to_string(cdata[prm_805].buffs[prm_806].id),
u8"name")
+ u8" ends."s));
}
if (cdata[prm_805].buffs[prm_806].id == 15)
{
if (prm_805 == 0)
{
incognitoend();
}
}
if (cdata[prm_805].buffs[prm_806].id == 16)
{
cdata[prm_805].is_sentenced_daeth() = false;
}
if (cdata[prm_805].buffs[prm_806].id == 18)
{
cdata[prm_805].is_contracting_with_reaper() = false;
}
cdata[prm_805].buffs[prm_806].id = 0;
for (int cnt = prm_806, cnt_end = cnt + (16 - prm_806 - 1); cnt < cnt_end;
++cnt)
{
if (cdata[prm_805].buffs[cnt].id == 0)
{
if (cdata[prm_805].buffs[cnt + 1].id != 0)
{
cdata[prm_805].buffs[cnt].id = cdata[prm_805].buffs[cnt + 1].id;
cdata[prm_805].buffs[cnt].power =
cdata[prm_805].buffs[cnt + 1].power;
cdata[prm_805].buffs[cnt].turns =
cdata[prm_805].buffs[cnt + 1].turns;
cdata[prm_805].buffs[cnt + 1].id = 0;
cdata[prm_805].buffs[cnt + 1].power = 0;
cdata[prm_805].buffs[cnt + 1].turns = 0;
}
else
{
break;
}
}
}
chara_refresh(prm_805);
return;
}
} // namespace elona