/**
  * Get the slugs and parameters values.
  */
 private function parse_slugs($give = false, $self_use = false)
 {
     $url_part = $_SERVER['REQUEST_URI'];
     $path = parse_url($url_part, PHP_URL_PATH);
     $slugs = explode('/', trim($path, '/'));
     $selfTarget = whichever(in('selfTarget'), $self_use);
     $link_back = whichever(in('link_back'), $selfTarget ? 'inventory' : null);
     $item_in = $slugs[2];
     $in_target = isset($slugs[3]) ? $slugs[3] : null;
     return ['link_back' => $link_back, 'item_in' => $item_in, 'in_target' => $in_target, 'selfTarget' => $selfTarget, 'give' => $give];
 }
示例#2
0
 /**
  * Command for current user to purchase a quantity of a specific item
  *
  * @param quantity int The quantity of the item to purchase
  * @param item string The identity of the item to purchase
  * @return Array
  */
 public function buy()
 {
     $in_quantity = in('quantity');
     $in_item = in('item');
     $gold = get_gold($this->sessionData['char_id']);
     $current_item_cost = 0;
     $no_funny_business = false;
     // Pull the item info from the database
     $item_costs = $this->itemForSaleCosts();
     $item = getItemByID(item_id_from_display_name($in_item));
     $quantity = whichever(positive_int($in_quantity), 1);
     $item_text = null;
     if ($item instanceof Item) {
         $item_text = $quantity > 1 ? $item->getPluralName() : $item->getName();
         $purchaseOrder = new PurchaseOrder();
         // Determine the quantity from input or as a fallback, default of 1.
         $purchaseOrder->quantity = $quantity;
         $purchaseOrder->item = $item;
         $potential_cost = isset($item_costs[$purchaseOrder->item->identity()]['item_cost']) ? $item_costs[$purchaseOrder->item->identity()]['item_cost'] : null;
         $current_item_cost = first_value($potential_cost, 0);
         $current_item_cost = $current_item_cost * $purchaseOrder->quantity;
         if (!$this->sessionData['char_id'] || !$purchaseOrder->item || $purchaseOrder->quantity < 1) {
             $no_funny_business = true;
         } else {
             if ($gold >= $current_item_cost) {
                 // Has enough gold.
                 try {
                     add_item($this->sessionData['char_id'], $purchaseOrder->item->identity(), $purchaseOrder->quantity);
                     subtract_gold($this->sessionData['char_id'], $current_item_cost);
                 } catch (\Exception $e) {
                     $invalid_item = $e->getMessage();
                     error_log('Invalid Item attempted :' . $invalid_item);
                     $no_funny_business = true;
                 }
             }
         }
     } else {
         $no_funny_business = true;
     }
     $parts = array('current_item_cost' => $current_item_cost, 'quantity' => $quantity, 'item_text' => $item_text, 'no_funny_business' => $no_funny_business, 'view_part' => 'buy');
     return $this->render($parts);
 }
示例#3
0
/**
 * Returns the state of the player from the database,
 * uses a user_id if one is present, otherwise
 * defaults to the currently logged in player, but can act on any player
 * if another username is passed in.
 * @param $user user_id or username
**/
function char_info($p_id)
{
    if (!$p_id) {
        if (defined('DEBUG') && DEBUG) {
            nw_error('DEPRECATED: call to char_info with a null argument.  For clarity reasons, this is now deprecated, use the player object instead. Backtrace: ' . print_r(debug_backtrace(), true));
        }
        return self_info();
    }
    $id = whichever($p_id, SESSION::get('player_id'));
    // *** Default to current player. ***
    if (!is_numeric($id)) {
        // If there's no id, don't try to get any data.
        return null;
    }
    $player = new Player($id);
    // Constructor uses DAO to get player object.
    $player_data = array();
    if ($player instanceof Player && $player->id()) {
        // Turn the player data vo into a simple array.
        $player_data = (array) $player->vo;
        $player_data['clan_id'] = $player->getClan() ? $player->getClan()->getID() : null;
        $player_data = add_data_to_player_row($player_data);
    }
    return $player_data;
}
示例#4
0
 public function testWhicheverNegative()
 {
     $this->assertNull(whichever('', null, false));
 }
示例#5
0
文件: npc.php 项目: reillo/ninjawars
         $oni_killed = false;
     }
     $npc_template = 'npc.oni.tpl';
     $combat_data = array('victory' => $oni_killed);
 } elseif (array_key_exists($victim, $npcs)) {
     /**** Abstracted NPCs *****/
     $npc_stats = $npcs[$victim];
     // Pull an npcs individual stats with generic fallbacks.
     /* ============= STANDARD NPCS ======================= */
     $npco = new Npc($npc_stats);
     // Construct the npc object.
     $display_name = first_value(@$npc_stats['name'], ucfirst($victim));
     $max_damage = $npco->max_damage();
     $percent_damage = null;
     // Percent damage does to the player's health.
     $status_effect = whichever(@$npc_stats['status'], null);
     $reward_item = first_value(@$npc_stats['item'], null);
     $base_gold = $npco->gold();
     $npc_gold = (int) @$npc_stats['gold'];
     $is_quick = $npco->speed() > $player->speed() ? true : false;
     // Beyond basic speed and they see you coming, so show that message.
     // If npc gold explicitly set to 0, then none will be given.
     $reward_gold = $npc_gold === 0 ? 0 : ($reward_item ? round($base_gold * 0.9) : $base_gold);
     // Hack a little off reward gold if items received.
     $bounty_mod = @$npc_stats['bounty'];
     $is_villager = $npco->has_trait('villager');
     // Give the villager message with the bounty.
     $is_weaker = $npco->strength() * 3 < $player->strength();
     // Npc much weaker?
     $is_stronger = $npco->strength() > $player->strength() * 2;
     // Npc More than twice as strong?
示例#6
0
文件: dojo.php 项目: reillo/ninjawars
 $userKills = $player->vo->kills;
 $user_turns = $player->turns();
 $userClass = $player->class_identity();
 $user_class_display = $player->class_display_name();
 $user_class_theme = class_theme($userClass);
 // Pull info for the class requested to change to.
 $destination_class_identity = isset($requested_identity) && isset($classes[$requested_identity]) ? $requested_identity : null;
 $destination_class_info = $destination_class_display = $destination_class_theme = null;
 if ($destination_class_identity) {
     $destination_class_info = $classes[$destination_class_identity];
     $destination_class_display = $destination_class_info['class_name'];
     $destination_class_theme = $destination_class_info['theme'];
 }
 // Pull the number of kills required to get to the next level.
 $required_kills = required_kills_to_level($player->level());
 $current_class_untrusted = whichever($current_class_untrusted, $userClass);
 // Initialize the class record to prevent double change on refresh.
 // Requirement functions.
 // Returns an error if there's an obstacle to changing classes.
 function class_change_reqs($char_obj, $turn_req)
 {
     $error = null;
     if ($char_obj->turns() < $turn_req) {
         // Check the turns, return the error if it's too below.
         $error = "You don't have enough turns to change your class.";
     }
     return $error;
 }
 // Returns an error if the requirements for getting a dim mak aren't met.
 function dim_mak_reqs($char_obj, $turn_req, $str_req)
 {
示例#7
0
$alive = true;
if ($error = init($private, $alive)) {
    display_error($error);
    die;
} else {
    $link_back = in('link_back');
    $selfTarget = in('selfTarget');
    $item_in = in('item');
    // Item identifier, either it's id or internal name
    $give = in('give');
    $target_id = in('target_id');
    $in_target = in('target');
    ///TODO clean up this travesty
    $target_id = $target_id ? (int) $target_id : self_char_id();
    $target = first_value($target_id, $in_target);
    $target_id = whichever($target_id, get_char_id($target));
    $give = in_array($give, array('on', 'Give'));
    $user_id = self_char_id();
    $player = new Player($user_id);
    $victim_alive = true;
    $using_item = true;
    $item_used = true;
    $stealthLost = false;
    $error = false;
    $suicide = false;
    $kill = false;
    $repeat = false;
    $ending_turns = null;
    $turns_change = null;
    $turns_to_take = null;
    $gold_mod = NULL;
示例#8
0
 /**
  * Try to view a single quest
  */
 public function view($qid = null)
 {
     // Hack to get the quest/view/{id}
     $url_part = $_SERVER['REQUEST_URI'];
     if (preg_match('#\\/(\\w+)(\\/)?$#', $url_part, $matches)) {
         $in_quest_id = isset($matches[1]) ? $matches[1] : null;
     } else {
         $in_quest_id = null;
     }
     $quest_id = whichever($in_quest_id, $qid);
     $quests = null;
     $quest = null;
     // When accepting a quest, simply display that quest.
     if ($quest_id) {
         $quests = format_quests(get_quests($quest_id));
         $title = 'A Quest';
         $quest = reset($quests);
         $tpl = 'quests.single_quest.tpl';
     }
     $parts = ['quest' => $quest, 'quests' => $quests];
     return ['template' => $tpl, 'title' => $title, 'parts' => $parts, 'options' => null];
 }
示例#9
0
/*
 * Deals with the non-skill based attacks and stealthed attacks.
 *
 * @package combat
 * @subpackage attack
 */
$private = true;
$alive = true;
$page_title = "Battle Status";
$quickstat = "player";
if ($error = init($private, $alive)) {
    display_error($error);
    die;
}
// *** ********* GET VARS FROM POST - OR GET ************* ***
$target = whichever(in('target'), in('attackee'));
$duel = in('duel') ? true : NULL;
$blaze = in('blaze') ? true : NULL;
$deflect = in('deflect') ? true : NULL;
$evade = in('evasion') ? true : NULL;
// Template vars.
$stealthed_attack = $stealth_damage = $stealth_lost = $pre_battle_stats = $rounds = $combat_final_results = $killed_target = $attacker_died = $bounty_result = $rewarded_ki = $wrath_regain = false;
// *** Attack System Initialization ***
$killpoints = 0;
// *** Starting state for killpoints. ***
$attack_turns = 1;
// *** Default cost, will go to zero if an error prevents combat. ***
$required_turns = 0;
$what = "";
// *** This will be the attack type string, e.g. "duel". ***
$loot = 0;