Exemple #1
0
 /**
  * @method POST
  * @api attack
  */
 public function attack()
 {
     $bat = $this->getBattleList();
     if ($bat == false) {
         return $this->response(array('status' => 0, 'message' => 'There is no active battle!'));
     }
     $characters = new Character();
     $challenger = $characters->getCharacterByID($_POST['character_id']);
     $monsters = new Monsters();
     $monster = $monsters->getMonsterByID($bat['battle_opponent_id']);
     $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'];
     ### START armour info arrays ###
     // array info: 0=helm, 1=armour, 2=gloves, 3=buckler, 4=amulet, 5=ring, 6=hp_regen, 7=mp_regen
     $armour_info = explode(',', $bat['battle_challenger_equipment_info']);
     $helm_equip = $armour_info[0] != '' ? $armour_info[0] : intval(0);
     $armour_equip = $armour_info[1] != '' ? $armour_info[1] : intval(0);
     $gloves_equip = $armour_info[2] != '' ? $armour_info[2] : intval(0);
     $buckler_equip = $armour_info[3] != '' ? $armour_info[3] : intval(0);
     $amulet_equip = $armour_info[4] != '' ? $armour_info[4] : intval(0);
     $ring_equip = $armour_info[5] != '' ? $armour_info[5] : intval(0);
     // Define the base weapon quality and power
     $weap = isset($_POST['item_weapon']) ? intval($_POST['item_weapon']) : false;
     $power = 1;
     $quality = 0;
     $battle_message = array();
     $item = false;
     if ($weap) {
         /*$sql = " SELECT * FROM " . ADR_SHOPS_ITEMS_TABLE . "
                         WHERE item_in_shop = 0 
                         AND item_in_warehouse = 0
                         AND item_duration > 0
                         $item_sql
                         AND item_owner_id = $user_id 
                         AND item_id = $weap ";
                     if( !($result = $db->sql_query($sql)) )
                     {
                         message_die(GENERAL_ERROR, 'Could not query battle list', '', __LINE__, __FILE__, $sql);
                     }
                     $item = $db->sql_fetchrow($result);
         
                     if ( $challenger['character_mp'] < $item['item_mp_use'] || $challenger['character_mp'] < 0 || $item['item_mp_use'] == '' ) 
                     {   
                         adr_previous ( Adr_battle_check , 'adr_battle' , '' );
                     }
         
                     if ( $item['item_mp_use'] > 0 )
                     {
                         $sql = "UPDATE " . ADR_CHARACTERS_TABLE . "
                             SET character_mp = character_mp - " . $item['item_mp_use'] . "
                             WHERE character_id = $user_id ";
                         if( !($result = $db->sql_query($sql)) )
                         {
                             message_die(GENERAL_ERROR, 'Could not update battle', '', __LINE__, __FILE__, $sql);
                         }
                     }
         
                     // Check for magic weap bonuses. Also get better crit threat range later on...
                     $quality = ($item['item_type_use'] == '6') ? ($item['item_quality'] *2) : $item['item_quality'];
                     $power = ($item['item_power'] + $item['item_add_power']);
                     adr_use_item($weap , $user_id);*/
     }
     // Let's check if the attack succeeds
     $dice = rand(1, 20);
     $diff = $bat['battle_challenger_att'] + $quality + $dice + $challenger['character_level'] > $bat['battle_opponent_def'] + $challenger['character_level'] ? TRUE : FALSE;
     $power = $power + adr_modifier_calc($challenger['character_might']);
     $damage = 1;
     $elements = new Elements();
     $elemental = $elements->getElementByID($opponent_element);
     // Grab item element infos if not bare hands strike
     //$element_name = ($item['item_name'] != '') ? adr_get_element_infos($item['item_element']) : '';
     ##=== START: Critical hit code
     $threat_range = 20;
     //NEED ITEMS $threat_range = ($item['item_type_use'] == '6') ? '19' : '20'; // magic weaps get slightly better threat range
     $crit_result = adr_battle_make_crit_roll($bat['battle_challenger_att'], $challenger['character_level'], $bat['battle_opponent_def'], $item['item_type_use'], $power, $quality, $threat_range);
     ##=== END: Critical hit code
     // Bare fist strike
     if (!$item || $item['item_name'] == '') {
         $monster_def_dice = rand(1, 20);
         $monster_modifier = 0;
         //rand(1,20); // this is temp. until proper monster characteristics are added to ADR
         // Grab modifers
         $bare_power = adr_modifier_calc($challenger['character_might']);
         if ($dice + $bare_power >= $monster_def_dice + $monster_modifier && $dice != '1' || $dice == '20') {
             $damage = rand(1, 3);
             $damage = $damage > $bat['battle_opponent_hp'] ? $bat['battle_opponent_hp'] : $damage;
             array_push($battle_message, sprintf(ADR::Lang('Adr_battle_attack_bare'), $challenger['character_name'], $damage, $monster['monster_name']));
         } else {
             $damage = 0;
             array_push($battle_message, sprintf(ADR::Lang('Adr_battle_attack_bare_fail'), $challenger['character_name'], $monster['monster_name']));
         }
     } else {
         if ($diff === TRUE && $dice != '1' || $dice >= $threat_range) {
             // Prefix msg if crit hit
             if ($crit_result === TRUE) {
                 array_push($battle_message, ADR::Lang('Adr_battle_critical_hit'));
             }
             $damage = 1;
             // Work out attack type
             if ($item['item_element'] && $item['item_element'] === $elemental['element_oppose_strong'] && $item['item_duration'] > '1' && !empty($item['item_name'])) {
                 $damage = ceil($power * ($item['item_element_weak_dmg'] / 100));
             } elseif ($item['item_element'] && !empty($item['item_name']) && $item['item_element'] === $opponent_element && $item['item_duration'] > '1') {
                 $damage = ceil($power * ($item['item_element_same_dmg'] / 100));
             } elseif ($item['item_element'] && !empty($item['item_name']) && $item['item_element'] === $elemental['element_oppose_weak'] && $item['item_duration'] > '1') {
                 $damage = ceil($power * ($item['item_element_str_dmg'] / 100));
             } else {
                 $damage = ceil($power);
             }
             // Fix dmg value
             $damage = $damage < '1' ? rand(1, 3) : $damage;
             $damage = $damage > $bat['battle_opponent_hp'] ? $bat['battle_opponent_hp'] : $damage;
             // Fix attack msg type
             if ($item['item_element'] > '0' && $element_name['element_name'] != '') {
                 array_push($battle_message, sprintf(ADR::Lang('Adr_battle_attack_success'), $challenger['character_name'], $monster['monster_name'], $item['item_name'], adr_get_lang($element_name['element_name']), $damage));
             } else {
                 array_push($battle_message, sprintf(ADR::Lang('Adr_battle_attack_success_norm'), $challenger['character_name'], $monster['monster_name'], $item['item_name'], $damage));
             }
         } else {
             $damage = 0;
             array_push($battle_message, sprintf(ADR::Lang('Adr_battle_attack_failure'), $challenger['character_name'], $monster['monster_name'], $item['item_name']));
         }
     }
     if ($item && $item['item_duration'] < '2' && $item['item_name'] != '') {
         array_push($battle_message, sprintf(ADR::Lang('Adr_battle_attack_dura'), $challenger['character_name'], adr_get_lang($item['item_name'])));
     }
     $bat['battle_challenger_dmg'] = $damage;
     $opponent_hp = $bat['battle_opponent_hp'] - $damage;
     if ($opponent_hp <= 0) {
         $return = $this->win($bat, $monster, $challenger);
         $return['message'] = array_merge($battle_message, $return['message']);
         return $this->response($return);
     } else {
         $this->updateBattleList(array('battle_opponent_hp' => $opponent_hp, 'battle_turn' => 2, 'battle_round' => $bat['battle_round'] + 1, 'battle_challenger_dmg' => $damage));
         return $this->response(array('status' => 1, 'message' => $battle_message, 'damage' => $damage, 'opponent_hp' => $opponent_hp));
     }
 }
 $diff = $current_att + $quality + $dice + $current_infos['character_level'] > $opponent_def + $opponent_infos['character_level'] ? TRUE : FALSE;
 $power = $power + adr_modifier_calc($current_infos['character_might']);
 $damage = 1;
 // Elemental infos
 $elemental = adr_get_element_infos($opponent_element);
 $element_name = $item['item_name'] != '' ? adr_get_element_infos($item['item_element']) : '';
 // Here we apply text colour if set
 if ($element_name['element_colour'] != '') {
     $item['item_name'] = '<font color="' . $element_name['element_colour'] . '">' . adr_get_lang($item['item_name']) . '</font>';
 } else {
     $item['item_name'] = adr_get_lang($item['item_name']);
 }
 ##=== START: Critical hit code
 $threat_range = $item['item_type_use'] == '6' ? '19' : '20';
 // magic weaps get slightly better threat range
 $crit_result = adr_battle_make_crit_roll($current_att, $current_infos['character_level'], $opponent_def, $item['item_type_use'], $power, $quality, $threat_range);
 ##=== END: Critical hit code
 // Bare hands strike!
 if ($item['item_name'] == '') {
     // Opponent roll
     $opponent_def_dice = rand(1, 20);
     // Grab modifers
     $str_modifier = 1 + adr_modifier_calc($current_str);
     $dex_modifier = 1 + adr_modifier_calc($opponent_dex);
     if ($dice + $str_modifier >= $opponent_def_dice + $dex_modifier && $dice > '1' || $dice == '20') {
         // Attack success, calculate the damage. Critical dice roll is still success
         $damage = rand(1, 3);
         $damage = $damage > $opponent_hp ? $opponent_hp : $damage;
         $battle_message .= sprintf($lang['Adr_pvp_attack_bare_success'], $current_name, $opponent_name, $damage) . '<br />';
     } else {
         $damage = 0;
function adr_spell_offensive()
{
    global $monster, $power, $bat, $adr_user, $opponent_element, $item, $db, $lang, $user_id, $power, $quality;
    global $challenger, $battle_message, $user_action, $monster_action, $attack_img, $attackwith_overlay;
    // Sort out magic check & opponents saving throw
    $dice = rand(1, 20);
    $monster['monster_wisdom'] = 10 + rand(1, $monster['monster_level']) * 2;
    //temp calc
    $magic_check = ceil($dice + $item['item_power'] + adr_modifier_calc($challenger['character_intelligence']));
    $fort_save = 11 + adr_modifier_calc($monster['monster_wisdom']);
    $diff = $magic_check >= $fort_save && $dice != '1' || $dice == '20';
    $power = $power + adr_modifier_calc($challenger['character_intelligence']);
    // Grab details for Elemental infos
    $elemental = adr_get_element_infos($opponent_element);
    $element_name = adr_get_element_infos($item['item_element']);
    // Here we apply text colour if set
    if ($element_name['element_colour'] != '') {
        $item['item_name'] = '<span style="color: ' . $element_name['element_colour'] . '">' . $item['item_name'] . '</span>';
    } else {
        $item['item_name'] = $item['item_name'];
    }
    ##=== START: Critical hit code
    $threat_range = $item['item_type_use'] == '6' ? '19' : '20';
    // magic weaps get slightly better threat range
    list($crit_result, $power) = adr_battle_make_crit_roll($bat['battle_challenger_att'], $challenger['character_level'], $bat['battle_opponent_def'], $item['item_type_use'], $power, $quality, $threat_range);
    ##=== END: Critical hit code
    rabbit_pet_regen();
    $attbonus = adr_weapon_skill_check($user_id);
    if ($diff === TRUE && $dice != '1' || $dice == '20') {
        $damage = adr_calc_item_damage($item, $power, $attbonus);
        // Fix dmg value
        $damage = $damage > $bat['battle_opponent_hp'] ? $bat['battle_opponent_hp'] : $damage;
        // Fix attack msg type
        if ($item['item_element'] > '0' && $element_name['element_name'] != '') {
            $battle_message .= sprintf($lang['Adr_battle_spell_success'], $challenger['character_name'], $item['item_name'], adr_get_lang($element_name['element_name']), $damage, $monster['monster_name']) . '<br>';
        } else {
            $battle_message .= sprintf($lang['Adr_battle_spell_success_norm'], $challenger['character_name'], $item['item_name'], $damage, $monster['monster_name']) . '<br>';
        }
    } else {
        $damage = 0;
        $battle_message .= sprintf($lang['Adr_battle_spell_failure'], $challenger['character_name'], $item_name, $monster['monster_name']) . '<br />';
    }
    if ($item['item_duration'] < 2) {
        $battle_message .= '</span><span class="gensmall">';
        // set new span class
        $battle_message .= '&nbsp;&nbsp;>&nbsp;' . sprintf($lang['Adr_battle_spell_dura'], $challenger['character_name'], $item['item_name']) . '<br>';
        $battle_message .= '</span><span class="genmed">';
        // reset span class to default
    }
    //$item['item_duration'] < 2
    // Update the database
    $sql = "UPDATE " . ADR_BATTLE_LIST_TABLE . "\n\t\tSET battle_opponent_hp = battle_opponent_hp - {$damage} ,\n\t\t\tbattle_challenger_dmg = {$damage} , \n\t\t\tbattle_turn = 2 ,\n\t\t\tbattle_round = (battle_round + 1)\n\t\tWHERE battle_challenger_id = {$user_id}\n\t\tAND battle_result = 0\n\t\tAND battle_type = 1 ";
    if (!($result = $db->sql_query($sql))) {
        message_die(GENERAL_ERROR, 'Could not update battle', '', __LINE__, __FILE__, $sql);
    }
    //!($result = $db->sql_query($sql))
    // Let's sort out the spell (attack) animations...
    // Make table for battle sequence...
    // 0 = Standing image , 1 = Attack image
    $user_action = 1;
    $monster_action = 1;
    $attack_img = $item['item_name'];
    $attackwith_overlay = file_exists("adr/images/battle/spells/" . $attack_img . ".gif") ? '<img src="adr/images/battle/spells/' . $attack_img . '.gif" width="256" height="96" border="0">' : '';
}
Exemple #4
0
 $power = $power + adr_modifier_calc($challenger['character_might']);
 $damage = 1;
 // Grab details for Elemental addon
 $elemental = adr_get_element_infos($opponent_element);
 // Grab item element infos if not bare hands strike
 $element_name = $item['item_name'] != '' ? adr_get_element_infos($item['item_element']) : '';
 // Here we apply text colour if set
 if ($element_name['element_colour'] != '') {
     $item['item_name'] = '<font color="' . $element_name['element_colour'] . '">' . $item['item_name'] . '</font>';
 } else {
     $item['item_name'] = $item['item_name'];
 }
 ##=== START: Critical hit code
 $threat_range = $item['item_type_use'] == '6' ? '19' : '20';
 // magic weaps get slightly better threat range
 $crit_result = adr_battle_make_crit_roll($bat['battle_challenger_att'], $challenger['character_level'], $bat['battle_opponent_def'], $item['item_type_use'], $power, $quality, $threat_range);
 ##=== END: Critical hit code
 // Bare fist strike
 if ($item['item_name'] == '') {
     $monster_def_dice = rand(1, 20);
     $monster_modifier = rand(1, 20);
     // this is temp. until proper monster characteristics are added to ADR
     // Grab modifers
     $bare_power = adr_modifier_calc($challenger['character_might']);
     if ($dice + $bare_power >= $monster_def_dice + $monster_modifier && $dice != '1' || $dice == '20') {
         $damage = rand(1, 3);
         $damage = $damage > $bat['battle_opponent_hp'] ? $bat['battle_opponent_hp'] : $damage;
         $battle_message .= sprintf($lang['Adr_battle_attack_bare'], $challenger['character_name'], $damage, $monster['monster_name']) . '<br>';
     } else {
         $damage = 0;
         $battle_message .= sprintf($lang['Adr_battle_attack_bare_fail'], $challenger['character_name'], $monster['monster_name']) . '<br>';