Source

Selador / held.php

Full commit
  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
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
<?php

/* held.php - Front-end for the "Held" page
 *
 * Copyright (C) 2006, 2007, 2008 Kevin Read, Simone Schaefer
 *
 * This file is part of Selador, a browser-based fantasy strategy game
 *
 * This program is distributed under the terms of the GNU Affero General Public License.
 *
 *
 *   Selador is free software: you can redistribute it and/or modify
 *   it under the terms of the GNU Affero General Public License as published by
 *   the Free Software Foundation, either version 3 of the License, or
 *   any later version.
 *
 *   Selador 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 Affero General Public License for more details.
 *
 *   You should have received a copy of the GNU Affero General Public License
 *   along with Selador.  If not, see <http://www.gnu.org/licenses/>.
 **/

require_once("php/base/user.inc.php");
require_once("php/base.php");
require_once("php/event.php");
require_once("headers.php");

// We should also pass this on to the tutorial, if it is still going strong
if (is_object ($tutorial))
{
	if ($tutorial->active)
		$tutorial->is_in_hero ();
}

function setLine($colspan)
{
	/*echo '<tr>
			<td colspan="'.$colspan.'"><img src="styles/sun/line_thin.gif" width="98%" height="1px"></td>
		</tr>';*/
}

if ($_GET['f'] == 3)
{
	require_once("Herotalents.inc.php");
	$query = "select fight0,fight1,fight2,fight3,fight4,fight5,build0,build1,build2,build3,build4,build5,knowledge0,knowledge1,knowledge2,knowledge3,knowledge4,points_m from hero where uid=".$me->uid;
	if (!$res = mysql_query($query))
		log_err("Could not read hero talents: ".$query.", ".mysql_error());
	else
		$row = mysql_fetch_array($res);
	$obj = new Herotalents ($row, $me->hero); // we build our heroobject here so that we can use it in the javascript src

	if (isset($_GET['t']))
		if ($obj->points_left > 0)
			if ($obj->checkDependencies(0,false))
			{
				if ($_GET['really'] != true)
					$obj->safetyCheck();
				else
				{
					if ($obj->updateTalents())
					{
						// Now check if we need to reload villages or the hero
						if ($obj->hero_needs_refreshing)
							$me->hero->refresh ();

						if ($obj->villages_need_refreshing)
						{
							log_debug ("Calculating research because of hero talent upgrade");
							$me->CalcResearch (true);
						}

						if ($obj->research_needs_refreshing)
							$me->CalcResearch (false);

						unset($obj);
						//We do the following because we want the tree to show the changes immediately
						$row[(int)$_GET['t']] = $row[(int)$_GET['t']]+1;
						$obj = new Herotalents($row, $me->hero);
					}
				}
			}
			if ($obj->errmsg)
				echo "<div id=\"ap_check\"><span class=\"error\"><b>".$obj->errmsg."</b></span></div>";
?>
<script type="text/javascript">
function doAction(which)
{
	writeInfo(which);
}

function leaveAction()
{
	deleteInfo();
}

function showIcon(x,y,bild)
{
	document.innerhtml = "<img src=\"gfx/held/test.jpg\">";
}

function hideIcon()
{

}

function writeInfo(which)
{
	contents = new Array(
<?php
foreach ($obj->talentheader as $idx=>$value)
{
	if (isset($visited))
		echo ", ";
	echo '
	"<h2>'.$value.'</h2>'.$obj->talentcontent[$idx];
	echo '<br><br><b>'._('Current Level').': </b> '.(int)$obj->talentrow[$idx];
	if ($obj->points_left == 0)
		echo '<span class=\"error\">'._('You don\'t have enough experience to level at the moment.').'</span>"';
	else
	{
		if ($obj->checkDependencies($idx,true))
			echo '<span class=\"info\">'.sprintf(_('You still have %s skill points left. Click on the picture to level a talent.'), $me->hero->points_left_m).'</span>"';
		else
			echo '<span class=\"info\">'.sprintf(_('You still have %s skill points left.</span><span class=\"error\"> But to level this talent, you need to level other talents first'), $me->hero->points_left_m).'</span>"';
	}
	$visited=true;
}
?>
	);
	
	document.getElementById("infoarea").innerHTML="<h3>Talentinfo: </h3>"+contents[which];
}

function deleteInfo()
{
	document.getElementById("infoarea").innerHTML="";
}
</script>
<?php

}

// Acquire lock for village here!

// Handle past events

// $me->event_handler (true, $me->activevillageid, $gui);

// Then calculate ressources through checking income - this takes into account
// past events, because event_handler might have updated $secspassed
// $me->activevillage->do_income ();

$me->activevillage->update_stamp ();

// We include basic design parts here
require_once ("styles/php/base_design-".$_SESSION['theme'].".php");

$actions = array (0=>_("Supporting in")." ", 4=>_("Attack against")." ", 6=>_("Support for")." ", 7=>_("Raid attack against")." ", 10=>_("Returning from")." ", 12=>_("Move to")." ");

?>
<div id="contentbox">

<?php
$query = "select picture from profile where userid='".$me->uid."'";

if ($result = mysql_query($query))
{
	if ($row = mysql_fetch_array($result))
	{
		$picture = $row['picture'];
	}
}

?>

<?php

if (isset ($_REQUEST['f']))
{
  $f = $_REQUEST['f'];
}
else
	$f = 1;

switch ($f)
{
/**hero overview*/
 case 1:
 	$healing = false;
	$xp_to_level = xp_needed_level($me->hero->level);
	$time_to_heal = ($me->hero->hp - $me->hero->health) / ($me->hero->regen * WORLD_SPEED) * 3600;
	unset ($query);

	if (round ($me->hero->health) <= 0)
	{
		$hero_ret_time = (int)(-$me->hero->health / ($me->hero->regen * WORLD_SPEED )* 3600);
		if ($hero_ret_time > 0)
		{
			$activity = sprintf(_("Your hero is missing. The townsfolk are looking for him and hope to know more in %s"), "<span id=\"timer".(int)($gui->displayedtimers+1)."\">".external_calcdur ($hero_ret_time.'</span>'));
			$gui->displayedtimers++;
		}
		else
			$activity = _("Your hero has been seen and will appear here any minute.");
	}
 	else
 	{
		if (!$me->hero->troopid)
		{
			$hl = $me->hero->location;
			if (isset ($me->villages[$hl]))
			{
				$locationname = $me->villages[$hl]->name;
				$location = $me->villages[$hl]->y * $world->sizex + $me->villages[$hl]->y;
				$what = _("town");
			}
			else
			{
				foreach ($me->villages as $vid=>$this_vill)
				{
					if (isset ($this_vill->outposts[$hl]))
					{
						$locationname=$this_vill->outposts[$hl]->name;
						$location = $this_vill->outposts[$hl]->y * $world->sizex + $this_vill->outposts[$hl]->y;
						$what = _("outpost");
					}
				}
			}

			if (!isset ($locationname))
				$query = "select y*".$world->sizex."+x as z, name, outpost_of from village where villageid=".$hl;
		}
		else
			$query = "select A.*, B.name, B.outpost_of, B.y*".$world->sizex."+B.x as z from armies A, village B where A.location=B.villageid and A.troopid=".$me->hero->troopid;

		if (isset ($query))
		{
			if (($res = mysql_query ($query)))
			{
				if (!($row = mysql_fetch_array ($res)))
				{
					log_err ("No rows returned when looking for hero whereabouts. Query: ".$query.", ".mysql_error ());
					$errmsg = _("A database error occured.");
				}
				else
				{
					$locationname = $row['name'];
					$location = $row['z'];
					if ($row['outpost_of'])
						$what = _("outpost");
					else
						$what = _("town");


					$action = $row['flag'];
					$activity = $actions[$action].$what." <a href=\"land.php?z=".$location."\">".$locationname."</a>";
				}
			}
			else
			{
				log_err ("Error when looking for hero whereabouts. Query: ".$query.", ".mysql_error ());
				$errmsg = _("A database error occured.");
			}
		}

		if (!isset ($activity))
		{
			if ($time_to_heal)
			{
				$healing = true;
				$activity = sprintf(_("Resting in %s %s"), $what, $locationname);
			}
			else
				$activity = sprintf(_("Sleeping in %s %s"), $what, $locationname);
		}
	}

 ?>
 <table class="border">
	 <tr>
		<td rowspan="11" width="120px"><img src="<?php echo $picture?>" width="120" height="174" border="0" alt=""></td>
	 </tr>
	 <tr>
		<th class="bold" colspan="2"><?php echo $me->user; ?></th>
	</tr>
	 <tr>
		<td><?php echo _("Where and what")?>:</td><td><?php echo $activity; ?></td>
	</tr>
	 <tr class="iterate">
		<td><?php echo _("Nation") ?>:</td><td><?php echo $races_byid[$me->race]; ?></td>
	</tr>
	 <tr>
		<td><?php echo _("Class")?>:</td><td><?php echo $classes_byid[$me->class]; ?></td>
	</tr>
	 <tr class="iterate">
		<td><?php echo _("Hit points")?></td>
		<td>
		<?php
		if ($me->hero->health < 0)
			echo _("The hero's status is unknown.");
		else
			echo sprintf(_("currently %d hit points from %d in total"), round ($me->hero->health), $me->hero->hp)."</td></tr>";
			//echo round ($me->hero->health)." "._("from")." ".$me->hero->hp." (".(int)($me->hero->health / $me->hero->hp * 100)."%)</td></tr>";
		echo "<tr><td>"._("Heeling").":</td><td>";
		if ($me->hero->health < 0)
			echo _("The hero's status is unknown.");
		else
		{
			if ($time_to_heal)
			{
				if (!$healing)
					echo _("The hero will heal as soon as he gets rest in a town");
				else
					echo sprintf(_("Healed in %s, healing %s hit points per hour"),external_calcdur ((int)$time_to_heal), ($me->hero->regen * WORLD_SPEED));
			}
			else
				echo "Completely healed";
		}
		?>
		</td>
	 </tr>
	 <tr class="iterate">
		<td><?php echo _("Level")?>:</td><td><?php echo $me->hero->level; ?></td>
	</tr>
	 <tr>
		<td><?php echo _("Experience")?>:</td><td><?php echo $me->hero->xp; ?></td>
	</tr>
	 <tr class="iterate">
		<td><?php echo _("Next level")?>: </td><td><?php echo xp_needed_level ($me->hero->level); ?></td>
	</tr>
</table>




 <?php
 break;
 /**hero attributes*/
 case 2:
	echo '
		<form name="hero" action="held.php?f=2" method="POST ">
		<input type="hidden" name="f" value="2">
	';
	if (isset($_REQUEST['points']))
	{
		if (in_array ($_REQUEST['points'], array ("p1", "p2", "p3")))
		{
			$query = "select points_p from hero where uid=".$me->uid;
			if (!$res = mysql_query($query))
				log_err("held.php: Could not read hero points when updating: ".$query.", ".mysql_error());
			else
			{
				if ($row = mysql_fetch_array($res))
				{
					if ($row['points_p'] > 0)
					{
						$query = "update hero set ".mysql_real_escape_string($_REQUEST['points'])."=".mysql_real_escape_string($_REQUEST['points'])."+1 where uid=".$me->uid;
						if (!mysql_query($query))
						{
							echo '<span class="error">'._('A database error occured.').'</span><br>';
							log_err("held.php: Could not update points. ".$query.", ".mysql_error());
						}
						else
						{
							$query = "update hero set points_p=points_p-1 where uid=".$me->uid;
							if (!mysql_query($query))
							{
								echo '<span class="error">'._('A database error occured.').'</span><br>';
								log_err("held.php: Could not decrement points. ".$query.", ".mysql_error());
							}

							unset ($query);
							switch ($_REQUEST['points'])
							{
								case "p1":
									$query = "update hero set hp=hp+25,regen=regen+2 where uid=".$me->uid;
									break;
								case "p2":
									$query = "update hero set damage=damage+10,speed=speed+10 where uid=".$me->uid;
									break;
								case "p3":
									$query = "update hero set ini=ini+1,att=att+5 where uid=".$me->uid;
									break;
							}

							if (isset ($query))
							{
								if (!mysql_query($query))
								{
									echo '<span class="error">'._('A database error occured.').'</span><br>';
									log_err("held.php: Could not update hero stats after leveling ".$query.", ".mysql_error());
								}
							}
							$me->hero->refresh ();
						}
					}
				}
			}
		}
	}
	echo '<table class="border">
		<tr>
			<td rowspan="9" width="120px"> <img src="'.$picture.'" width="120" height="174" border="0" alt=""></td>
			<th  class="bold">'._('Attributes').'</th>
		</tr>
		<tr>';
	$query = "select p1,p2,p3 , points_p from hero where uid=".$me->uid;
	if (!$res = mysql_query($query))
		log_err("held.php: Could not read hero points: ".$query.", ".mysql_error());
	else
	{
		if ($row = mysql_fetch_array($res))
		{

			$attributes = array (
				"p1" => array (_("Stamina"), _("Increases hit points and regeneration")),
				"p2" => array(_("Strength"), _("Increases damage and speed")),
				"p3" => array(_("Dexterity") , _("Increases initiative and attack"))
			);
			if ($row['points_p'] > 0)
			{
				echo '
					<tr>
						<td>'.sprintf(_('You still have %d attribute points left. Click on %s to increase this attribute.'), $row['points_p'], '<img src="styles/'.$_SESSION['theme'].'/add.png" height="12px">').'.</td>
					</tr>';
			}
			else
			{
				echo '
					<tr>
						<td><span class="info">'._('You don\'t have any attribute points left.').'</span></td>
					</tr>';
			}
			foreach ($attributes as $column => $content)
			{
				echo '
				<tr>
					<th>'.$content[0].'</th>
				</tr>
				<tr>
					<td><span class="info">'.$content[1].'</span>
					<b>'.sprintf(_('Currently %d points leveled'), $row[$column]).'</b>';
					if ($row['points_p'] > 0)
						echo '
							<a href="held.php?f=2&points='.$column.'"><img src="styles/'.$_SESSION['theme'].'/add.png" title="'._('level attribute').'">';
				echo '</td>
				</tr>';
			}
		}
	}
	echo '</table></form>';

	echo '<table class="border"><tr><th class="bold" colspan="2">'._('Current values').'</th></tr>';
	echo '<tr><td>'._('hit points').'</th><td>'.$me->hero->hp.'</td></tr>';
	echo '<tr class="iterate"><td>'._('speed').'</th><td>'.$me->hero->speed.'</td></tr>';
	echo '<tr><td>'._('attack').'</th><td>'.$me->hero->attack.'</td></tr>';
	echo '<tr class="iterate"><td>'._('initiative').'</th><td>'.$me->hero->ini.'</td></tr>';
	echo '<tr><td>'._('damage').'</th><td>'.$me->hero->damage.'</td></tr>';
	echo '</table>';
   ?>

<br>

<?php
 break;
 case 3:

	$obj->setBackground();
	$obj->setTree();
	$obj->setMap();
	$obj->setInfoArea();


 ?>




<?php
	break;
	}

echo '</div>';
require_once("footer.php");
?>