$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*/
/*validate ip is associated with a user*/ $message['AllPlayersInfo'] = null; $message['AllPlayerMarkers'] = null; $message['AllItems'] = null; /*Verify the game exists*/ if (IsGameInDb($gameId) == true) { $activeItems = GetActiveItems($gameId); /*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);