/** * User command for betting on the coin toss game in the casino * * @param bet int The amount of money to bet on the coin toss game * @return Array * * @note * If the player bets within ~1% of the maximum bet, they will receive a reward item */ public function bet() { $player = new Player(self_char_id()); $bet = intval(in('bet')); $negative = $bet < 0; set_setting('bet', max(0, $bet)); $pageParts = ['reminder-max-bet']; if ($negative) { $pageParts = ['result-cheat']; $player->vo->health = subtractHealth($player->id(), 99); } else { if ($bet > $player->vo->gold) { $pageParts = ['result-no-gold']; } else { if ($bet > 0 && $bet <= self::MAX_BET) { if (rand(0, 1) === 1) { $pageParts = ['result-win']; $player->vo->gold = add_gold($player->id(), $bet); if ($bet >= round(self::MAX_BET * 0.99)) { // within about 1% of the max bet & you win, you get a reward item. add_item($player->id(), self::REWARD, 1); } } else { $player->vo->gold = subtract_gold($player->id(), $bet); $pageParts = ['result-lose']; } } } } // End of not cheating check. return $this->render(['pageParts' => $pageParts, 'player' => $player, 'bet' => get_setting('bet')]); }
$res[$header] = $data[$field]; } return $res; } if (!$attack_error) { // Nothing to prevent the attack from happening. // Initial attack conditions are alright. $result = ''; if ($command == 'Sight') { $covert = true; $sight_data = pull_sight_data($target); $display_sight_table = true; } elseif ($command == 'Steal') { $covert = true; $gold_decrease = min($target->gold(), rand(5, 50)); add_gold($char_id, $gold_decrease); // *** This one actually adds the value. subtract_gold($target->id(), $gold_decrease); // *** Subtracts whatever positive value is put in. $msg = "{$attacker_id} stole {$gold_decrease} gold from you."; send_event($attacker_char_id, $target->id(), $msg); $generic_skill_result_message = "You have stolen {$gold_decrease} gold from __TARGET__!"; } else { if ($command == 'Unstealth') { $state = 'unstealthed'; if ($target->hasStatus(STEALTH)) { $target->subtractStatus(STEALTH); $generic_state_change = "You are now {$state}."; } else { $turn_cost = 0; $generic_state_change = "__TARGET__ is already {$state}.";
$group_gold = 0; } $npc_template = 'npc.thief-group.tpl'; $combat_data = array('attack' => $group_attack, 'gold' => $group_gold, 'victory' => $victory); } else { // Normal attack on a single thief. $thief_attack = rand(0, 35); // *** Thief Damage *** if ($player->vo->health = $victory = subtractHealth($char_id, $thief_attack)) { $thief_gold = rand(0, 40); // *** Thief Gold *** if ($thief_attack > 30) { subtract_gold($char_id, $thief_gold); } else { if ($thief_attack < 30) { add_gold($char_id, $thief_gold); add_item($char_id, 'shuriken', $quantity = 1); } } } else { $thief_gold = 0; } $npc_template = 'npc.thief.tpl'; $combat_data = array('attack' => $thief_attack, 'gold' => $thief_gold, 'victory' => $victory); } } } } } } }
function subtract_gold($char_id, $amount) { return add_gold($char_id, $amount * -1); }
} } if (empty($resultMessage) && !empty($result)) { $resultMessage = $result; } if (!$victim_alive) { // Target was killed by the item. if (!$self_use) { // *** SUCCESSFUL KILL, not self-use of an item *** $attacker_id = $player->hasStatus(STEALTH) ? "A Stealthed Ninja" : $username; if (!$gold_mod) { $gold_mod = 0.15; } $loot = round($gold_mod * get_gold($target_id)); subtract_gold($target_id, $loot); add_gold($char_id, $loot); addKills($char_id, 1); $kill = true; $bountyMessage = runBountyExchange($username, $target); //Rewards or increases bounty. } else { $loot = 0; $suicide = true; } // Send mails if the target was killed. send_kill_mails($username, $target, $attacker_id, $article, $item->getName(), $today = null, $loot); } else { // They weren't killed. $attacker_id = $username; } if (!$self_use && $item_used) {
$work_multiplier = 30; $worked = $new_gold = $not_enough_energy = $use_second_description = null; $is_logged_in = is_logged_in(); $worked = intval(in('worked')); $recommended_to_work = 10; // Store or retrieve the last value of turns worked. if ($worked && is_numeric($worked)) { set_setting('turns_worked', $worked); $recommended_to_work = $worked; } else { $last_worked = get_setting('turns_worked'); $recommended_to_work = $last_worked ? $last_worked : 10; } // Work only if the work was requested, not just if the setting was set. if ($worked > 0) { $turns = get_turns($char_id); if ($worked > $turns) { $not_enough_energy = true; } else { $new_gold = $worked * $work_multiplier; // *** calc amount worked *** add_gold($char_id, $new_gold); $turns = subtractTurns($char_id, $worked); $use_second_description = true; } } $gold = get_gold($char_id); // Get the current/final gold. $gold_display = number_format($gold); display_page('work.tpl', 'Working in the Village', get_certain_vars(get_defined_vars(), array()), array('quickstat' => 'player')); }
// Adds a kill for the defender $attacking_player->death(); if (!$simultaneousKill) { $loot = floor($gold_mod * $attacking_player->gold()); //Loot for defender if he lives. } $target_msg = "You have killed {$attacker} in combat and taken {$loot} gold."; $attacker_msg = "DEATH: You've been killed by {$target} and lost {$loot} gold!"; sendMessage($attacker, $target, $target_msg); sendMessage($target, $attacker, $attacker_msg); } } // *** END MAIN ATTACK AND DUELING SECTION *** } if ($loot) { add_gold(get_char_id($victor), $loot); subtract_gold(get_char_id($loser), $loot); } /** * HACK(ajv) Because the player obj is modified throughout the above code * we can't really keep track of what happened to safely use the * ActiveRecord pattern. Therefore, we pull another copy of the player * from the data layer, modify it, and save it down here, then transfer * the updated data to the existing object to keep everything in sync */ if ($rounds > 4) { // Evenly matched battle! Reward some ki to the attacker, even if they die $rewarded_ki = 1; $hack_player = Player::find($attacking_player->id()); $hack_player->set_ki($hack_player->ki() + $rewarded_ki); $hack_player->save();
function rewardBounty($bounty_to, $bounty_on) { $bounty = getBounty($bounty_on); setBounty($bounty_on, 0); //Sets bounty to zero. add_gold($bounty_to, $bounty); return $bounty; }