예제 #1
0
파일: Temple.php 프로젝트: ZerGabriel/ADR2
 /**
  * @method POST
  * @api resurrect
  */
 public function resurrect()
 {
     $characters = new Character();
     $adr_char = $characters->getCharacterByID($_POST['character_id']);
     $cost = $this->getCosts($_POST['character_id']);
     $cost = $cost['resurrect_price'];
     $user = new User();
     $points = $user->getPoints();
     if ($points['user_points'] < $cost) {
         return $this->response(array('status' => 0, 'message' => ADR::Lang("Adr_lack_points")));
     }
     if ($adr_char['character_hp'] > 0) {
         return $this->response(array('status' => 0, 'message' => ADR::Lang("Adr_temple_heal_instead")));
     }
     $user->subtractPoints($cost);
     $this->replenish($adr_char);
     return $this->response(array('status' => 1, 'current_points' => $points['user_points'] - $cost, 'message' => ADR::Lang("Adr_temple_resurrected")));
 }
예제 #2
0
파일: Battle.php 프로젝트: ZerGabriel/ADR2
 /**
  * @method POST
  * @api opponent_turn
  */
 public function opponent_turn()
 {
     $bat = $this->getBattleList();
     if ($bat == false) {
         return $this->response(array('status' => 0, 'message' => 'There is no active battle!'));
     }
     $adr_general = ADR::getGeneralConfig();
     $characters = new Character();
     $challenger = $characters->getCharacterByID($_POST['character_id']);
     $monsters = new Monsters();
     $monster = $monsters->getMonsterByID($bat['battle_opponent_id']);
     $monster_name = adr_get_lang($monster['monster_name']);
     $character_name = $challenger['character_name'];
     $monster['monster_crit_hit_mod'] = 2;
     $monster['monster_crit_hit'] = 20;
     $monster['monster_int'] = 10 + rand(1, $monster['monster_level']) * 2;
     //temp calc
     $monster['monster_str'] = 10 + rand(1, $monster['monster_level']) * 2;
     //temp calc
     $user_ma = $bat['battle_challenger_magic_attack'];
     $user_md = $bat['battle_challenger_magic_resistance'];
     $monster_ma = $bat['battle_opponent_magic_attack'];
     $monster_md = $bat['battle_opponent_magic_resistance'];
     $challenger_element = $challenger['character_element'];
     $opponent_element = $monster['monster_base_element'];
     $battle_round = $bat['battle_round'];
     $battle_message = array();
     $def = false;
     if ($def != TRUE) {
         $power = ceil($monster['monster_level'] * rand(1, 3));
     } else {
         $power = floor($monster['monster_level'] * rand(1, 3) / 2);
     }
     // Has the monster the ability to steal from user?
     $thief_chance = 0;
     //NEED ITEMS $thief_chance = rand(1,20);
     if ($adr_general['thief_enable'] == '1' && $thief_chance == '20') {
         /*$sql = "SELECT item_id, item_name FROM  " . ADR_SHOPS_ITEMS_TABLE . "
                         WHERE item_monster_thief = '0'
                         AND item_in_warehouse = '0'
                         AND item_in_shop = '0'
                         AND item_duration > '0'
                         AND item_owner_id = '$user_id'
                         AND item_id NOT IN ($helm_equip, $armour_equip, $gloves_equip, $buckler_equip, $amulet_equip, $ring_equip)
                         ORDER BY rand() LIMIT 1";
                     if(!($result = $db->sql_query($sql))){
                         message_die(GENERAL_ERROR, 'Could not query items for monster item steal', '', __LINE__, __FILE__, $sql);}
                     $item_to_steal = $db->sql_fetchrow($result);
         
                     // Rand to check type of thief attack
                     $success_chance = rand(1,20);
                     $rand = rand(1,20);
         
                     ##=== START: steal item checks
                     $challenger_item_spot_check = (20 + adr_modifier_calc($challenger['character_skill_thief']));
                     $monster_item_attempt = (((($rand + adr_modifier_calc($monster['monster_thief_skill'])) > $challenger_item_spot_check) && ($rand != '1')) || ($rand == '20')) ? TRUE : FALSE;
                     ##=== END: steal item checks
         
                     ##=== START: steal points checks
                     $challenger_points_spot_check = (10 + adr_modifier_calc($challenger['character_skill_thief']));
                     $monster_points_attempt = (((($rand + $monster['monster_thief_skill']) > $challenger_points_spot_check) && ($rand != '1')) || ($rand == '20')) ? TRUE : FALSE;
                     ##=== END: steal points checks
         
                     if(($success_chance == '20') && ($monster_item_attempt == TRUE) && ($item_to_steal['item_name'] != '')){
                         $damage = 0;
         
                         // Mark the item as stolen
                         $sql = "UPDATE " . ADR_SHOPS_ITEMS_TABLE . "
                             SET item_monster_thief = 1
                             WHERE item_owner_id = '$user_id'
                             AND item_id = '" . $item_to_steal['item_id'] . "'";
                         if(!($result = $db->sql_query($sql))){
                             message_die(GENERAL_ERROR, 'Could not update stolen item by monster', '', __LINE__, __FILE__, $sql);}
         
                             array_push($battle_message, sprintf(ADR::Lang('Adr_battle_opponent_thief_success'), $monster_name, adr_get_lang($item_to_steal['item_name']), $character_name));
                     }
                     elseif(($success_chance >= '15') && ($success_chance != '20') && ($user_points > '0') && ($monster_points_attempt == TRUE)){
                         $damage = 0;
                         $points_stolen = floor(($user_points / 100) *$adr_general['thief_points']);
                         subtract_reward($user_id, $points_stolen);
                         array_push($battle_message, sprintf(ADR::Lang('Adr_battle_opponent_thief_points'), $monster_name, $points_stolen, get_reward_name(), $character_name));
                     }
                     else{
                         $damage = 0;
                         array_push($battle_message, sprintf(ADR::Lang('Adr_battle_opponent_thief_failure'), $monster_name, adr_get_lang($item_to_steal['item_name']), $character_name));
                     }*/
     } else {
         $attack_type = rand(1, 20);
         ##=== START: Critical hit code
         $threat_range = $monster['monster_crit_hit'];
         //          list($crit_result, $power) = explode('-', adr_battle_make_crit_roll($bat['battle_opponent_att'], $monster['monster_level'], $bat['battle_challenger_def'], 0, $power, 0, $threat_range, 0));
         ##=== END: Critical hit code
         if ($bat['battle_opponent_mp'] > '0' && $bat['battle_opponent_mp'] >= $bat['battle_opponent_mp_power'] && $attack_type > '16') {
             $damage = 1;
             $power = ceil($power + adr_modifier_calc($bat['battle_opponent_mp_power']));
             $elements = new Elements();
             $monster_elemental = $elements->getElementByID($opponent_element);
             // Sort out magic check & opponents saving throw
             $dice = rand(1, 20);
             $magic_check = ceil($dice + $bat['battle_opponent_mp_power'] + adr_modifier_calc($monster['monster_int']));
             $fort_save = 11 + adr_modifier_calc($challenger['character_wisdom']);
             $success = $magic_check >= $fort_save && $dice != '1' || $dice >= $threat_range ? TRUE : FALSE;
             if ($success === TRUE) {
                 // Prefix msg if crit hit
                 if ($dice >= $threat_range) {
                     array_push($battle_message, ADR::Lang('Adr_battle_critical_hit'));
                 }
                 // Work out attack type
                 if ($challenger_element === $monster_elemental['element_oppose_weak']) {
                     $damage = ceil($power * ($monster_elemental['element_oppose_strong_dmg'] / 100));
                 } elseif ($challenger_element === $opponent_element) {
                     $damage = ceil($power * ($monster_elemental['element_oppose_same_dmg'] / 100));
                 } elseif ($challenger_element === $monster_elemental['element_oppose_strong']) {
                     $damage = ceil($power * ($monster_elemental['element_oppose_weak_dmg'] / 100));
                 } else {
                     $damage = ceil($power);
                 }
                 // Fix dmg value
                 $damage = $damage < '1' ? rand(1, 3) : $damage;
                 $damage = $dice >= $threat_range ? $damage * $monster['monster_crit_hit_mod'] : $damage;
                 $damage = $damage > $challenger['character_hp'] ? $challenger['character_hp'] : $damage;
                 // Fix attack msg type
                 if ($monster['monster_base_custom_spell'] != '') {
                     array_push($battle_message, sprintf(ADR::Lang('Adr_battle_opponent_spell_success'), $monster_name, $monster['monster_base_custom_spell'], $character_name, $damage));
                 } else {
                     array_push($battle_message, sprintf(ADR::Lang('Adr_battle_opponent_spell_success2'), $monster_name, $character_name, $damage));
                 }
             } else {
                 $damage = 0;
                 array_push($battle_message, sprintf(ADR::Lang('Adr_battle_opponent_spell_failure'), $monster_name, $character_name));
             }
             // Remove monster MP
             $opponent_mp_remaining = $bat['battle_opponent_mp'] - $bat['battle_opponent_mp_power'];
             $this->updateBattleList(array('battle_opponent_mp' => $opponent_mp_remaining));
         } else {
             // Let's check if the attack succeeds
             $dice = rand(1, 20);
             $success = $bat['battle_opponent_att'] + $dice >= $bat['battle_challenger_def'] + adr_modifier_calc($challenger['character_dexterity']) && $dice != '1' || $dice >= $threat_range ? TRUE : FALSE;
             $power = ceil($power / 2 + adr_modifier_calc($monster['monster_str']));
             $damage = 1;
             if ($success == TRUE) {
                 // Attack success , calculate the damage . Critical dice roll is still success
                 $damage = $power < '1' ? rand(1, 3) : $power;
                 $damage = $dice >= $threat_range ? ceil($damage * $monster['monster_crit_hit_mod']) : ceil($damage);
                 $damage = $damage > $challenger['character_hp'] ? $challenger['character_hp'] : $damage;
                 if ($dice >= $threat_range) {
                     array_push($battle_message, ADR::Lang('Adr_battle_critical_hit'));
                 }
                 array_push($battle_message, sprintf(ADR::Lang('Adr_battle_opponent_attack_success'), $monster_name, $character_name, $damage));
             } else {
                 $damage = 0;
                 array_push($battle_message, sprintf(ADR::Lang('Adr_battle_opponent_attack_failure'), $monster_name, $character_name));
             }
         }
         $bat['battle_opponent_dmg'] = $damage;
         // Prevent instant kills at start of battle
         $challenger_hp = $challenger['character_hp'] - $damage;
         if ($bat['battle_round'] == 0 && $challenger_hp < 1) {
             $challenger_hp = 1;
         }
         $db = DB::instance();
         $db->update('adr_characters', array('character_hp' => $challenger_hp), array('character_id' => $bat['battle_challenger_id']));
         if ($challenger_hp <= 0) {
             $return = $this->lose($bat, $monster, $challenger);
             $return['message'] = array_merge($battle_message, $return['message']);
             return $this->response($return);
         } else {
             return $this->response(array('status' => 1, 'message' => $battle_message, 'damage' => $damage, 'challenger_hp' => $challenger_hp));
         }
     }
 }