コード例 #1
0
ファイル: Item.php プロジェクト: NinjaWars/ninjawars
 /**
  * Set all the default settings for items, overridden by specified settings
  */
 public function __construct($dirty_content = null)
 {
     // Potentially, an identity string is what's being passed in.
     if (is_string($dirty_content) && trim($dirty_content) !== '') {
         $data = item_info_from_identity($dirty_content);
         $this->buildFromArray($data);
     }
 }
コード例 #2
0
 /**
  * Get an item by it's item identity
  */
 private function getItemByIdentity($p_itemIdentity)
 {
     return buildItem(item_info_from_identity($p_itemIdentity));
 }
コード例 #3
0
ファイル: npc.php プロジェクト: reillo/ninjawars
 // ******* FIGHT *********** & Hope for victory.
 $victory = false;
 $survive_fight = $player->vo->health = subtractHealth($char_id, $npco->damage());
 $armored = $npco->has_trait('armored') ? 1 : 0;
 $kill_npc = $npco->health() < $player->damage();
 if ($survive_fight) {
     // The ninja survived, they'll get gold.
     $received_gold = rand(floor($reward_gold / 5), $reward_gold);
     add_gold($char_id, $received_gold);
     $received_display_items = array();
     if ($kill_npc) {
         $victory = true;
         // Victory occurred, reward the poor sap.
         if ($npco->inventory()) {
             foreach ($npco->inventory() as $l_item => $avail) {
                 $item_info = item_info_from_identity($l_item);
                 $received_display_items[] = $item_info['item_display_name'];
                 add_item($char_id, $item_info['item_internal_name'], 1);
             }
         }
         // Add bounty where applicable.
         if ((bool) $bounty_mod) {
             $attacker_level = $player->vo->level;
             // *** Bounty or no bounty ***
             if ($attacker_level > 5) {
                 if ($attacker_level <= 50) {
                     // No bounty after this level?
                     $added_bounty = floor($attacker_level / 3 * $bounty_mod);
                     addBounty($char_id, $added_bounty);
                 }
             }
コード例 #4
0
ファイル: NpcController.php プロジェクト: NinjaWars/ninjawars
 /**
  * Handle Standard Abstract Npcs
  *
  * @param String $victim
  * @param Player $player
  * @param Array $npcs
  * @return array [$npc_template, $combat_data]
  */
 private function attackAbstractNpc($victim, Player $player, $npcs)
 {
     $npc_stats = $npcs[$victim];
     // Pull an npcs individual stats with generic fallbacks.
     $npco = new Npc($npc_stats);
     // Construct the npc object.
     $display_name = first_value(isset($npc_stats['name']) ? $npc_stats['name'] : null, ucfirst($victim));
     $status_effect = isset($npc_stats['status']) ? $npc_stats['status'] : null;
     // TODO: Calculate and display damage verbs
     $reward_item = isset($npc_stats['item']) && $npc_stats['item'] ? $npc_stats['item'] : null;
     $is_quick = (bool) ($npco->speed() > $player->speed());
     // Beyond basic speed and they see you coming, so show that message.
     $bounty_mod = isset($npc_stats['bounty']) ? $npc_stats['bounty'] : null;
     $is_weaker = $npco->strength() * 3 < $player->strength();
     // Npc much weaker?
     $is_stronger = $npco->strength() > $player->strength() * 3;
     // Npc More than twice as strong?
     $image = isset($npc_stats['img']) ? $npc_stats['img'] : null;
     // Assume defeat...
     $victory = false;
     $received_gold = null;
     $received_display_items = null;
     $added_bounty = null;
     $is_rewarded = null;
     // Gets items or gold.
     $display_statuses = $display_statuses_classes = null;
     $image_path = null;
     // If the image exists, set the path to it for use on the page.
     if ($image && file_exists(SERVER_ROOT . 'www/images/characters/' . $image)) {
         $image_path = IMAGE_ROOT . 'characters/' . $image;
     }
     // ******* FIGHT Logic ***********
     $npc_damage = $npco->damage();
     $survive_fight = $player->harm($npc_damage);
     $kill_npc = $npco->health() < $player->damage();
     if ($survive_fight > 0) {
         // The ninja survived, they get any gold the npc has.
         $received_gold = $this->calcReceivedGold($npco, (bool) $reward_item);
         $player->set_gold($player->gold() + $received_gold);
         $received_display_items = array();
         if ($kill_npc) {
             $victory = true;
             // Victory occurred, reward the poor sap.
             if ($npco->inventory()) {
                 foreach (array_keys($npco->inventory()) as $l_item) {
                     $item_info = item_info_from_identity($l_item);
                     $received_display_items[] = $item_info['item_display_name'];
                     add_item($player->id(), $item_info['item_internal_name'], 1);
                 }
             }
             // Add bounty where applicable.
             if ((bool) $bounty_mod && $player->level > self::MIN_LEVEL_FOR_BOUNTY && $player->level <= self::MAX_LEVEL_FOR_BOUNTY) {
                 $added_bounty = floor($player->level / 3 * $bounty_mod);
                 $player->set_bounty($player->bounty() + $added_bounty);
             }
         }
         $is_rewarded = (bool) $received_gold || (bool) count($received_display_items);
         if (isset($npc_stats['status']) && null !== $npc_stats['status']) {
             $player->addStatus($npc_stats['status']);
             // Get the statuses and status classes for display.
             $display_statuses = implode(', ', get_status_list());
             $display_statuses_classes = implode(' ', get_status_list());
             // TODO: Take healthy out of the list since it's redundant.
         }
     }
     $player->save();
     return ['npc.abstract.tpl', ['victim' => $victim, 'display_name' => $display_name, 'attack_damage' => $npc_damage, 'status_effect' => $status_effect, 'display_statuses' => $display_statuses, 'display_statuses_classes' => $display_statuses_classes, 'received_gold' => $received_gold, 'received_display_items' => $received_display_items, 'is_rewarded' => $is_rewarded, 'victory' => $victory, 'survive_fight' => $survive_fight, 'kill_npc' => $kill_npc, 'image_path' => $image_path, 'npc_stats' => $npc_stats, 'is_quick' => $is_quick, 'added_bounty' => $added_bounty, 'is_villager' => $npco->has_trait('villager'), 'race' => $npco->race(), 'is_weaker' => $is_weaker, 'is_stronger' => $is_stronger]];
 }