include 'functions.php'; $message = array(); /*message to be returned*/ $gameId = $_POST['gameId']; /*the game being played */ $itemId = $_POST['item']; /*the item to bwe used */ $targetId = $_POST['target']; /*get the target the item is to be used on*/ $ip = $_SERVER['REMOTE_ADDR']; /*ip address of user */ $userId = GetIdFromConnections($ip); /*get user id associated with this ip*/ /*Step 1 verify user is in game*/ if (IsPlayerInGame($gameId, $userId) == true) { /*Step 2 verify item is accoitated with user and has not been used*/ if (UserHasActiveItem($userId, $itemId, $gameId) == true) { /*Step 3 get distance between the user and the target, verify it is less than the range of the item*/ if (IsTargetInRange($userId, $itemId, $targetId, $gameId) == true) { /*Step 4 set the item acitve to false to indicate it has been used*/ SetItemActiveToFalse($itemId); /*Step5 check if target has protection item and use*/ if (UseProtection($targetId, $gameId) == false) { /*Step 6 reduce the targets gold*/ $stealGold = GetItemsTheftAmount($itemId); /*get items gold theft value*/ $targetsGold = GetPlayersGold($gameId, $targetId);
function AddPlayerToGame($gameId, $userId, $iconId) { /*check if player currently in game*/ if (IsPlayerInGame($gameId, $userId) === false) { $sql = sprintf("INSERT INTO game_players (GameId, PlayerId , Gold ,Lat ,Lng ,Alive,PlayerIcon) \n\t\t\t\t\t\t\t\t\t\t\tVALUES ( %d, %d , 0 ,0 , 0, 1 ,%d)", $gameId, $userId, $iconId); RunSql($sql); } }