/*subtract the gold from the targets gold*/ $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);
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*/ } }