-
Notifications
You must be signed in to change notification settings - Fork 10
/
lib.php
executable file
·333 lines (306 loc) · 10 KB
/
lib.php
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
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
<?php
//start new stuff
/*
=======================================================
GET COMPATIBLE ACCESSORIES
$item['mountaccessory'] must be set.
$item['formount'] can be a comma-separated list of Mounts for which this can be an accessory, or it can be "all".
EXAMPLE:
$item['mountaccessory']=true;
$item['formount']="1,7,27"; //can be used with mountids 1, 7, and 27
=======================================================
*/
function iitems_mountaccessories_get_compatible_accessories($mountid){
$ret = array();
if (!$mountid) return $ret;
global $session;
require_once "modules/iitems/lib/lib.php";
$allitems = iitems_get_all_item_details();
$mountaccessories = array();
//select all iitems that are Mount Accessories
foreach ($allitems AS $item => $details){
if ($details['mountaccessory']) $mountaccessories[$item]=$details;
}
//check to see if there are no available mount accessories before we go further
if (!count($mountaccessories)) return $ret;
//select all Mount Accessories that are appropriate for this Mount
foreach ($mountaccessories AS $item => $details){
if ($details['formount']=="all"){
$ret[$item]=$details;
} else {
$compatibilitylist = explode(",",$details['formount']);
foreach($compatibilitylist AS $cmount){
if ($cmount==$mountid) $ret[$item]=$details;
}
}
}
return $ret;
}
//end new stuff
/*
Required functions and features:
acc Editor with hooks for other modules (simple pref unserializer/editor).
Stables navigation page which lists all available accs for player's Mount.
Function to apply effects from the addons that the user has purchased (include hooks for other modules).
New Day function which incorporates the above function.
/*
/*
=======================================================
GET MASTER LIST OF MOUNT ACCESSORIES
Returns arrays for every accessory default.
=======================================================
*/
function get_default_accs_list() {
$accs = unserialize(get_module_setting("accessories", "mountaccessories"));
if (!is_array($accs)) {
$accs = array();
set_module_setting("accessories", serialize($accs), "mountaccessories");
}
$accs = unserialize(get_module_setting("accessories", "mountaccessories"));
return $accs;
}
/*
=======================================================
GET ACCESSORIES FOR ANY GIVEN MOUNT
Returns arrays for every accessory intended for a specific Mount.
=======================================================
*/
function get_mount_accs_list($mountid) {
$accs = unserialize(get_module_setting("accessories", "mountaccessories"));
$mountaccs = array();
foreach($accs AS $acc => $details){
if ($details['mountid']==$mountid){
$mountaccs[$acc] = $details;
}
}
if (!is_array($mountaccs)){
return false;
}
return $mountaccs;
}
/*
=======================================================
GET PLAYER ACCESSORY LIST
Returns arrays for every accessory for the given player.
Rather than assigning a list of ID's to the player, the entire accessory is duplicated.
This uses a little more disk space but makes it possible to affect a player's individual accessory - allowing, for example, damage to accessories.
=======================================================
*/
function get_player_acc_list($userid=false) {
global $session;
$accs = unserialize(get_module_pref("accessories", "mountaccessories", $userid));
if (!is_array($accs)) {
$accs = array();
set_module_pref("accessories", serialize($accs), "mountaccessories", $userid);
}
$accs=unserialize(get_module_pref("accessories", "mountaccessories", $userid));
return $accs;
}
/*
=======================================================
GET ACCESSORY DETAILS
Returns full info array for a given accessory in a player's pref.
Returns False if the player does not have the accessory.
=======================================================
*/
function get_player_acc($acc, $userid=false) {
global $session;
if ($userid === false) $userid = $session['user']['acctid'];
$playeraccs = get_player_acc_list($userid);
if (!isset($playeraccs[$acc])){
return false;
}
return($playeraccs[$acc]);
}
/*
*******************************************************
GIVE ACCESSORY
Gives the given accessory to the given player.
Returns False if the accessory is not installed, not intended for the player's mount, or if the player already has the accessory.
*******************************************************
*/
function give_accessory($acc, $userid=false) {
global $session;
if ($userid === false) $userid = $session['user']['acctid'];
$playeraccs = get_player_acc_list($userid);
if (!isset($playeraccs[$acc])){
$defaultaccs = get_default_accs_list();
if (isset($defaultaccs[$acc])){
$playeraccs[$acc] = $defaultaccs[$acc];
set_module_pref("accessories", serialize($playeraccs), "mountaccessories", $userid);
return($playeraccs[$acc]);
} else {
return false;
}
}
}
/*
*******************************************************
TAKE MONEY
Takes the player's gold and/or gems.
Returns false if the accessory is not installed, or if the user doesn't have enough resources.
*******************************************************
*/
function mountaccessories_takemoney($acc, $userid=false) {
global $session;
if ($userid === false) $userid = $session['user']['acctid'];
$defaultaccs = get_default_accs_list();
if (isset($defaultaccs[$acc])){
$goldcost = $defaultaccs[$acc]['goldcost'];
$gemcost = $defaultaccs[$acc]['gemcost'];
if ($session['user']['gold'] >= $goldcost && $session['user']['gems'] >= $gemcost){
$session['user']['gold'] -= $goldcost;
$session['user']['gems'] -= $gemcost;
return true;
} else {
return false;
}
} else {
return false;
}
}
/*
*******************************************************
APPLY ACCESSORY
Applies effects of the selected Mount accessory. Standard functionality applies buffs - turns are only applied at newday.
Includes a hook for other accessory effects to be applied.
*******************************************************
*/
function apply_accessory($acckey, $userid=false) {
global $session;
if ($userid === false) $userid = $session['user']['acctid'];
$acc = get_player_acc($acckey, $userid);
if (isset($acc['buffname'])){
$name = $acc['buffname'];
}
if (isset($acc['buffrounds'])){
$rounds = $acc['buffrounds'];
} else {
$rounds = 0;
}
if (isset($acc['buffwearoffmsg'])){
$wearoff = $acc['buffwearoffmsg'];
}
if (isset($acc['buffeffectmsg'])){
$effectmsg = $acc['buffeffectmsg'];
}
if (isset($acc['buffnodmgmsg'])){
$effectnodmgmsg = $acc['buffnodmgmsg'];
}
if (isset($acc['buffeffectfailmsg'])){
$effectfailmsg = $acc['buffeffectfailmsg'];
}
if (isset($acc['buffatkmod'])){
$atkmod = $acc['buffatkmod'];
} else {
$atkmod = 1;
}
if (isset($acc['buffdefmod'])){
$defmod = $acc['buffdefmod'];
} else {
$defmod = 1;
}
if (isset($acc['buffinvulnerable'])){
$invulnerable = $acc['buffinvulnerable'];
}
if (isset($acc['buffregen'])){
$regen = $acc['buffregen'];
}
if (isset($acc['buffminioncount'])){
$minioncount = $acc['buffminioncount'];
}
if (isset($acc['buffminbadguydamage'])){
$minbadguydamage = $acc['buffminbadguydamage'];
}
if (isset($acc['buffmaxbadguydamage'])){
$maxbadguydamage = $acc['buffmaxbadguydamage'];
}
if (isset($acc['buffmingoodguydamage'])){
$mingoodguydamage = $acc['buffmingoodguydamage'];
}
if (isset($acc['buffmaxgoodguydamage'])){
$maxgoodguydamage = $acc['buffmaxgoodguydamage'];
}
if (isset($acc['bufflifetap'])){
$lifetap = $acc['bufflifetap'];
}
if (isset($acc['buffdamageshield'])){
$damageshield = $acc['buffdamageshield'];
}
if (isset($acc['buffbadguydmgmod'])){
$badguydmgmod = $acc['buffbadguydmgmod'];
} else {
$badguydmgmod = 1;
}
if (isset($acc['buffbadguyatkmod'])){
$badguyatkmod = $acc['buffbadguyatkmod'];
} else {
$badguyatkmod = 1;
}
if (isset($acc['buffbadguydefmod'])){
$badguydefmod = $acc['buffbadguydefmod'];
} else {
$badguydefmod = 1;
}
apply_buff($acckey, array(
"name"=>$name,
"rounds"=>$rounds,
"wearoff"=>$wearoff,
"effectmsg"=>$effectmsg,
"effectnodmgmsg"=>$effectnodmgmsg,
"effectfailmsg"=>$effectfailmsg,
"atkmod"=>$atkmod,
"defmod"=>$defmod,
"invulnerable"=>$invulnerable,
"regen"=>$regen,
"minioncount"=>$minioncount,
"minbadguydamage"=>$minbadguydamage,
"maxbadguydamage"=>$maxbadguydamage,
"mingoodguydamage"=>$mingoodguydamage,
"maxgoodguydamage"=>$maxgoodguydamage,
"lifetap"=>$lifetap,
"damageshield"=>$damageshield,
"badguydmgmod"=>$badguydmgmod,
"badguyatkmod"=>$badguyatkmod,
"badguydefmod"=>$badguydefmod,
)
);
modulehook("mountaccessories_apply_accessory", $acc);
return true;
}
/*
*******************************************************
APPLY ALL ACCESSORIES
Applies effects of all Mount accessories. Used at newday.
*******************************************************
*/
function apply_all_accessories($userid=false) {
global $session;
if ($userid === false) $userid = $session['user']['acctid'];
$accs = get_player_acc_list($userid);
foreach($accs AS $acc => $details){
apply_accessory($acc, $userid);
$session['user']['turns'] += $details['turns'];
if (isset($details['newdaymsg'])){
output_notl("%s",$details['newdaymsg']);
}
}
}
/*
*******************************************************
STRIP ACCESSORIES
Removes Accessories, strips associated Buffs. Includes a hook to remove effects of modules intended to work with Mount Accessories.
Use when player is selling a Mount.
*******************************************************
*/
function strip_accessories() {
global $session;
$accs = get_player_acc_list($userid);
foreach($accs AS $acc => $details){
strip_buff($acc);
modulehook("mountaccessories_strip_accessories", $acc);
}
$blank = array();
set_module_pref("accessories", serialize($blank), "mountaccessories");
}
?>