function getGold($who) { if (DEBUG) { throw new Exception('Use of deprecated function "getGold" from commands.php, should be replaced with get_gold($char_id)'); } return get_gold(get_char_id($who)); }
function add_gold($char_id, $amount) { $amount = (int) $amount; if ($amount != 0) { // Only update anything if it's a non-null non-zero value. query('UPDATE players SET gold = gold + CASE WHEN gold + :amount1 < 0 THEN gold*(-1) ELSE :amount2 END where player_id = :char_id', array(':char_id' => $char_id, ':amount1' => array($amount, PDO::PARAM_INT), ':amount2' => array($amount, PDO::PARAM_INT))); } return get_gold($char_id); }
$timestamp = date("F j, Y, g:i a"); if (isset($_POST['building']) || isset($_POST['killer_button'])) { if (isset($_POST['killer_button'])) { session_destroy(); header("Location: ninja_gold.php"); die; } if (isset($_POST['building'])) { $building = $_POST['building']; if ($building == 'farm') { $this_gold_value = get_gold(10, 20); } if ($building == 'cave') { $this_gold_value = get_gold(5, 10); } if ($building == 'house') { $this_gold_value = get_gold(2, 5); } if ($building == 'casino') { $this_gold_value = get_gold(-50, 50); } } $_SESSION['total_gold'] += $this_gold_value; if ($this_gold_value < 0) { $this_gold_value *= -1; $_SESSION['activity_log'][] = "<p class='red'>You entered a {$building} and lost {$this_gold_value} golds ...OUCH! ({$timestamp})</p>"; } else { $_SESSION['activity_log'][] = "<p>You entered a {$building} and earned {$this_gold_value} golds! ({$timestamp})</p>"; } } header('Location: ninja_gold.php');
/** * Generates the view spec hash for displaying a template * * @param p_parts Array Name/Value pairings to pass to the view * @return Array */ private function render($p_parts) { $p_parts['gold'] = get_gold($this->sessionData['char_id']); $p_parts['item_costs'] = $this->itemCosts; $p_parts['is_logged_in'] = $this->sessionData['is_logged_in']; return ['template' => 'shop.tpl', 'title' => 'Shop', 'parts' => $p_parts, 'options' => ['quickstat' => 'viewinv']]; }
$gold_count = 0; $activity = array(); $class = "green"; switch ($building) { case 'farm': $gold_count = get_gold(10, 20); break; case 'cave': $gold_count = get_gold(5, 10); break; case 'house': $gold_count = get_gold(2, 5); break; case 'casino': $percent = rand(0, 100); if ($percent <= 70) { $gold_count = get_gold(-50, -1); $class = 'red'; $message = 'Ouch'; } else { $gold_count = get_gold(1, 50); $class = 'green'; $message = 'Nice'; } break; } $_SESSION['gold_count'] += $gold_count; $_SESSION['activity'][] = "<span class='" . $class . "'> You entered a " . $building . " and earned " . $gold_count . " gold." . ($building == 'casino' ? "..." . $message . "..." : "") . " (" . date('M d, Y h:ia') . ")<span><br>"; header("Location: index.php"); exit; }
/** * Command for a user to reduce their bounty by paying their own gold * * @param bribe int The amount to spend on reducing bounty * @return Array */ public function bribe() { $bribe = intval(in('bribe')); $error = 0; $quickstat = false; if ($bribe <= get_gold($this->sessionData['char_id']) && $bribe > 0) { subtract_gold($this->sessionData['char_id'], $bribe); subtractBounty($this->sessionData['char_id'], $bribe / 2); $location = 1; $quickstat = 'player'; } else { if ($bribe < 0) { // Was a bug, now the doshin beats you up! Yay! if (get_gold($this->sessionData['char_id']) > 1000) { // *** If they have more than 1000 gold, their bounty will be mostly removed by this event. $bountyReduction = getBounty($this->sessionData['char_id']) * 0.7; subtractBounty($this->sessionData['char_id'], $bountyReduction); } subtractGold($this->sessionData['username'], floor(getGold($this->sessionData['username']) * 0.8)); //Takes away 80% of the players gold. $location = 2; $quickstat = 'player'; } else { $location = 0; $error = 5; } } return $this->render(['error' => $error, 'quickstat' => $quickstat, 'location' => $location, 'command' => 'bribe']); }
$resultMessage .= " __TARGET__ no longer has any turns."; } } } 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 (!$victim_alive) { // Someone died. if ($target->player_id == $player->player_id) { // Attacker killed themself. $loot = 0; $suicided = true; } else { // Attacker killed someone else. $killed_target = true; $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); $added_bounty = floor($level_check / 5); if ($added_bounty > 0) { addBounty($char_id, $added_bounty * 25); } else { // Can only receive bounty if you're not getting it on your own head. if ($bounty = rewardBounty($char_id, $target->vo->player_id)) { $bounty_msg = "You have valiantly slain the wanted criminal, {$target}! For your efforts, you have been awarded {$bounty} gold!"; sendMessage('Village Doshin', $username, $bounty_msg); } } $target_message = "{$attacker_id} has killed you with {$command} and taken {$loot} gold."; send_event($attacker_char_id, $target->id(), $target_message);
$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')); }
$loser = $attacker; } $attacker_died = true; $defenderKillpoints = 1; if ($duel) { // *** if they were dueling when they died *** $duel_log_msg = "{$attacker} has dueled {$target} and lost at {$today}."; sendMessage("SysMsg", "SysMsg", $duel_log_msg); sendLogOfDuel($attacker, $target, 0, $killpoints); // *** Makes a loss in the duel log. *** } addKills($target_id, $defenderKillpoints); // *** Adds a kill for the defender. *** $attacking_player->death(); if (!$simultaneousKill) { $loot = round($gold_mod * get_gold($attacker_id)); //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); } if ($rounds > 4) {