/*get the items in game*/ while ($r = $activeItems->fetch_assoc()) { $message['AllItems'][] = $r; } $Players = getPlayers($gameId); /*get all players in the game*/ while ($r = $Players->fetch_assoc()) { $message['AllPlayerMarkers'][] = $r; $items = GetPlayersItems($gameId, $r["PlayerId"]); /*get the Players picked up items*/ $itemArray = array(); $itemArray["items"] = null; while ($row = $items->fetch_assoc()) { $itemArray["items"][] = $row; } $itemArray["gold"] = GetPlayersGold($gameId, $r["PlayerId"]); $message['AllPlayersInfo'][] = $itemArray; } } echo json_encode($message); /*return the message as ajson encoded object*/ function IsGameInDb($gameId) { $sql = sprintf("SELECT COUNT(*) FROM games WHERE id = '%d'", $gameId); $result = RunSql($sql); $COUNT_NUMBER = $result->fetch_array(); $count = $COUNT_NUMBER[0]; /*if count == 0 then no game found*/ if ($count == 0) { return false; } else {
$offset = 0; if ($newValue < 0) { $offset = $newValue; $newValue = 0; } SetPlayersGold($gameId, $targetId, $newValue); /*sets the players new gold in db*/ /*Step 7 increase the users gold*/ $stealGold = GetItemsTheftAmount($itemId); /*get items gold theft value*/ $playersGold = GetPlayersGold($gameId, $userId); /*get the targets gold value*/ $newValue = $playersGold + $stealGold + $offset; /*subtract the gold from the targets gold*/ SetPlayersGold($gameId, $userId, $newValue); /*sets the players new gold in db*/ } } } } } /*Step 8 return to user new gold and list of active items*/ $playerItems = GetPlayersItems($gameId, $userId); /*get the Players picked up items*/ while ($r = $playerItems->fetch_assoc()) { $message['MyItemsList'][] = $r; } $message['CurrentGold'] = GetPlayersGold($gameId, $userId); /*get the current players gold*/ echo json_encode($message); /*return the message as ajson encoded object*/
function AsignItemToPlayer($gameId, $userId, $itemId) { /*confirm that item has not alread been asigned*/ $sql = sprintf("Select PickedUp from game_items Where id =%d", $itemId); $result = RunSql($sql); $row = $result->fetch_assoc(); $pickedUp = $row['PickedUp']; if ($pickedUp == 0) { /*Assign*/ $sql = sprintf("UPDATE game_items SET User = %d, PickedUp =1 Where id =%d", $userId, $itemId); RunSql($sql); $itemGold = GetitemsGold($itemId); /*get items gold value*/ $playersGold = GetPlayersGold($gameId, $userId); /*get the players gold value*/ $newValue = $itemGold + $playersGold; /*add the items gold to the players gold*/ SetPlayersGold($gameId, $userId, $newValue); /*sets the players new gold in db*/ } }