-
Notifications
You must be signed in to change notification settings - Fork 2
/
setup_equip.php
404 lines (375 loc) · 14 KB
/
setup_equip.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
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
<?php
define ('INCLUDE_DIR','include/');
require_once INCLUDE_DIR.'errorlog.php';
#Prep the game objects.
require_once INCLUDE_DIR.'party.php';
require_once INCLUDE_DIR.'team.php';
session_start();
#Do LOGIN stuff :)
require_once 'common_auth.php';
$userid=authenticate_membership_access('dse','/auth/login.php','index.php');
redirect_on_hold($userid,'dse','on_hold.php','../index.php');
//If there is a fight in progress, jump to it.
/*
if(isset($_SESSION['prefight']))
{
header('Location: rpg.php');
exit;
}
*/
//New way!
require_once INCLUDE_DIR.'fight_store.php';
$fight_store=new FIGHT_STORE();
$result=$fight_store->get_fight($userid);
if($result!=false)
{
header('Location: rpg.php');
exit;
}
#If all the data we need isn't here, then load in the filler data.
if(!isset($_SESSION['party']))
{
header('Location: pick_team.php');
exit;
}
#Check for a cancel
if(isset($_POST['GO_BACK']))
{
header('Location: setup_fight.php');
exit;
}
#Generate a temporary hero party.
$party=$_SESSION['party'];
$team=$_SESSION['team'];
#Break down the hero's items and equipment.
$group=$_GET['group'];
$position=$_GET['position'];
$status='';
#Break down the hero's items and equipment.
$character=&$party->get_character("$group;$position");
//list($name,$job,$level,$personality,$group,$inventory,$equipment)=$_SESSION['heroes'][$hero_index];
$job_name=$jobs[$character->jobid]->name;
$personality_name=$character->personality->name;
//Check for equipping.
for($index=0;$index<count($character->inventory);$index++)
{
if(isset($_POST["equip$index"]))
{
switch($_POST["equip$index"])
{
case 'Unequip':
$character->unequip_item($index);
$status.="{$character->name} removed the {$items[$character->inventory[$index]['item']]->name}.";
break;
case 'Equip':
case 'Equip Left':
case 'Equip Right':
do {
$result=$character->equip_item($index,($_POST["equip$index"]=='Equip Left'?0:1));
if(is_numeric($result))
{
$status.="{$character->name} removed the {$items[$character->inventory[$result]['item']]->name}.";
$character->unequip_item($result);
}
} while (is_numeric($result));
if (is_array($result))
$status.="{$character->name} equipped the {$items[$character->inventory[$index]['item']]->name}.";
else
$status.="{$character->name} could not equip the {$items[$character->inventory[$index]['item']]->name}.";
break;
}
$party->store_party();
}
}
//Now process an action, if needed.
if(isset($_POST['DO_ACTION']))
{
$GLOBALS['output']='';
$action=$_POST['action'];
$ability=$_POST['ability'];
if(isset($_POST['qty']))
$qty=$_POST['qty'];
if(isset($_POST['group']))
$tgroup=$_POST['group'];
if(isset($_POST['character']))
$tposition=$_POST['character'];
switch($_POST['action'])
{
case 2: //Use item
$myability=$GLOBALS['items'][$character->inventory[$ability]['item']];
$status=perform_setup_action($party,$action,$ability,'used',$myability->name,$myability->use_targets,$group,$position,$tgroup,$tposition);
break;
case 5: //Cast spell
$myability=$GLOBALS['abilities'][$character->abilities[$ability]];
$status=perform_setup_action($party,$action,$ability,'cast',$myability->name,$myability->targets,$group,$position,$tgroup,$tposition);
break;
case 4: //Use skill
$myability=$GLOBALS['abilities'][$character->abilities[$ability]];
$status=perform_setup_action($party,$action,$ability,'performed',$myability->name,$myability->targets,$group,$position,$tgroup,$tposition);
break;
case 9: //Give item
$item=$character->inventory[$ability]['item'];
$myitem=$GLOBALS['items'][$item];
$qty=$character->remove_item($ability,$qty);
$mychar=&$party->get_character("$tgroup;$tposition");
$given=$qty-$mychar->add_item($item,$qty);
if($qty!=$given)
$character->add_item($item,$qty-$given);
$party->store_party();
if($group!=$tgroup ||$position!=$tposition)
$status="{$character->name} gave $given {$myitem->name}(s) to {$mychar->name}. ";
else
$status="{$character->name} reorganized $given {$myitem->name}(s). ";
break;
case 1001: //Sell item
$item=$character->inventory[$ability]['item'];
$sold=$character->remove_item($ability,$qty);
$worth=round($sold*$GLOBALS['items'][$item]->price*.75);
$team->gold+=$worth;
$team->store_team();
$status="{$character->name} sold $sold {$GLOBALS['items'][$item]->name}(s) for $worth gold.";
break;
}
}
function perform_setup_action(&$party,$action,$actionindex,$verb,$name,$range,$group,$position,$tgroup,$tposition)
{
$character=$party->get_character("$group;$position");
$status="{$character->name} $verb $name";
if($range<-1)
$status.=" on the entire party";
elseif($range==-1)
$status.=" on {$party->group[$tgroup]->name}";
elseif($range==0)
{
if($group!=$tgroup || $position!=$tposition)
$status.=" on {$party->groups[$tgroup]->characters[$tposition]->name}";
}
else
{
for($index=-$range;$index<=$range;$index++)
if($index+$tposition>=0 && $index+$tposition<$party->groups[$tgroup]->count())
$names[].=$party->groups[$tgroup]->characters[$tposition+$index]->name;
aray_push('and '.array_pop($names));
$status.=" on ".implode((count($names)>2?', ':' '),$names);
}
$status.=". ";
#Do action
$action_list=$party->do_field_action($action,$actionindex,$group,$position,$tgroup,$tposition);
//var_dump($action_list);
$results=convert_action_list_to_playlist($action_list,-1,$party);
//var_dump($results);
#Process results
if($action==4||$action==5)
array_shift($results);
$tgroup=0;
foreach($results as $result)
{
if($result[0]==0)
switch($result[1])
{
case "present_group":
$tgroup=$result[3];
break;
case "alter_stat":
if($result[6]>0)
$status.= $party->groups[$tgroup]->characters[$result[4]]->name."'s $result[5] increased by $result[6]. ";
elseif($result[6]<0)
$status.= $party->groups[$tgroup]->characters[$result[4]]->name."'s $result[5] decreased by ".(-$result[6]).". ";
else
$status.= $party->groups[$tgroup]->characters[$result[4]]->name."'s $result[5] did not change. ";
break;
}
}
return $status;
}
//Build item list
$item_list=array();
$full_item_list=array();
$qty_list=array();
foreach($character->inventory as $index=>$item)
{
$myitem=&$GLOBALS['items'][$item['item']];
if($myitem->effect!=0)
$item_list[]=array($index,$myitem->name,$myitem->useable_in_field());
$full_item_list[]=array($index,$myitem->name,true);
$qty_list[]=$item['qty'];
}
//Build spell list
$spell_list=array();
$skill_list=array();
foreach($character->abilities as $index=>$ability)
{
$myability=&$GLOBALS['abilities'][$ability];
if($myability->type==1) //is skill
$skill_list[]=array($index,"{$myability->name} ($myability->mp_used)",$myability->useable_in_field() & ($character->current['MP']>=$myability->mp_used));
else //is spell
$spell_list[]=array($index,"{$myability->name} ($myability->mp_used)",$myability->useable_in_field() & ($character->current['MP']>=$myability->mp_used));
}
//Build action list
$action_list=array();
if (count($item_list)>0)
$action_list[2]='Use Item';
if (count($spell_list)>0)
$action_list[5]='Cast Spell';
if (count($skill_list)>0)
$action_list[4]='Use Skill';
if (count($character->inventory)>0)
{
$action_list[9]='Give Item';
$action_list[1001]='Sell Item';
}
//Build fake list
$fake_list=array();
//For sake of argument, refresh the team data
$team->refresh_team();
?>
<html>
<head>
<script type="text/javascript" src="javascript/constants.js"></script>
<script type="text/javascript">
var item_list=<?php echo php_data_to_js($item_list); ?>;
var full_item_list=<?php echo php_data_to_js($full_item_list); ?>;
var spell_list=<?php echo php_data_to_js($spell_list); ?>;
var skill_list=<?php echo php_data_to_js($skill_list); ?>;
var qty_list=<?php echo php_data_to_js($qty_list); ?>;
var abilities=<?php echo $GLOBALS["abilities_js"]; ?>;
var items=<?php echo $GLOBALS["items_js"]; ?>;
var party=<?php echo php_data_to_js($party); ?>;
var character=party.groups[<?php echo $group; ?>].characters[<?php echo $position; ?>];
var action=null;
var ability=null;
var range=null;
var effect=null;
var group=null;
function select_character(object)
{
if(action!=COMMAND_GIVE_ITEM && must_be_alive(effect) && party.groups[group].characters[parseInt(object.value)].current.HP==0)
return false;
document.form_data.DO_ACTION.style.visibility='visible';
}
</script>
</head>
<body>
<h1 style="color:orange"><?php echo $status; ?></h1>
<form method="post" name="form_data">
<table>
<tr><th valign="top">
<table width="100%">
<caption><b><?php echo $character->name; ?> - Level <?php echo $character->level; ?> <?php echo $job_name; ?></b></caption>
<tr>
<th>XP Earned</th>
<td><?php echo $character->exp; ?>/<?php echo $character->need; ?></td>
<th>PXP Rating</th>
<td><?php echo $character->pxp; ?></td>
</tr>
</table>
<table width="100%">
<?php
echo "<tr>\n";
foreach($GLOBALS['character_stats'] as $key)
echo "<th>$key</th>\n";
echo "</tr>\n<tr>\n";
foreach($GLOBALS['character_stats'] as $key)
{
$value = $character->base[$key];
echo "<td align=\"center\">";
if(in_array($key,array('HP','MP')))
echo $character->current[$key].'/'.$character->get_base($key);
else
echo $value;
echo "</td>\n";
}
echo "</tr>\n<tr>\n";
foreach($GLOBALS['character_stats'] as $key)
{
$value = $character->base[$key];
echo "<td align=\"center\">";
if(count(array_keys_strict($character->equipment,null))!=count($character->equipment))
{
$character->command=1;
$base=$character->get_current($key);
$stat1=$base-$value;
if($stat1>=0) $stat1='+'.$stat1;
if(!in_array($key,array('HP','MP')))
echo "$base ($stat1)";
else
{
$stat1=$character->get_base($key)-$value;
if($stat1>=0) $stat1='+'.$stat1;
echo "($stat1)";
}
if(in_array($key,array('Accuracy','Strength','Speed'))
&& $character->equipment['lhand']!==$character->equipment['rhand'])
{
$character->command=0;
$base=$character->get_current($key);
$stat2=$base-$value;
if($stat2>=0) $stat2='+'.$stat2;
echo "<br>$base ($stat2)";
}
}
echo "</td>\n";
}
echo "</tr>\n";
?>
</table>
<table>
<tr>
<th>Item</th>
<th>Qty</th>
<th>Where Equipped</th>
<th>Action</th>
</tr>
<?php
foreach(array_keys($character->inventory) as $index)
{
$iteminfo=$character->inventory[$index];
$itemid=$iteminfo['item'];
$qty=$iteminfo['qty'];
?>
<tr>
<td><?php echo ($qty>0?$GLOBALS['items'][$itemid]->name:''); ?></td>
<td align="center"><?php echo ($qty>1?$qty:''); ?></td>
<td align="center"><?php
#This here will list where an item is equipped.
$keys=array_keys_strict($character->equipment,$index);
echo implode(', ',$keys);
?></td>
<td align="center"><?php
#This here will list button(s) or link(s) if the item is equippable.
if(count($keys)>0)
echo "<input type=\"submit\"name=\"equip$index\" value=\"Unequip\">";
elseif (count($items[$itemid]->equip_type)>0)
{
if(count(array_intersect($items[$itemid]->equip_type,array('hand','arm')))>0)
echo "<input type=\"submit\" name=\"equip$index\" value=\"Equip Left\"><input type=\"submit\" name=\"equip$index\" value=\"Equip Right\">";
elseif(count(array_intersect($items[$itemid]->equip_type,array('ammo')))>0)
{
if(!is_null($character->equipment['lhand'])
&& $items[$itemid]->ammo_type==$items[$character->inventory[$character->equipment['lhand']]['item']]->ammo_type
&& $character->equipment['lhand']!=$character->equipment['rhand'])
echo "<input type=\"submit\" name=\"equip$index\" value=\"Equip Left\">";
if(!is_null($character->equipment['rhand'])
&& $items[$itemid]->ammo_type==$items[$character->inventory[$character->equipment['rhand']]['item']]->ammo_type)
echo "<input type=\"submit\" name=\"equip$index\" value=\"Equip Right\">";
}
else
echo "<input type=\"submit\" name=\"equip$index\" value=\"Equip\">";
}
?></td>
</tr>
<?php
}
?>
</table>
</th>
</tr>
<tr>
<td>
<input type="submit" name="GO_BACK" value="Return To Last Menu">
</td>
</tr>
</table>
</form>
</body>
</html>