⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 combat.php

📁 三國好好 子
💻 PHP
📖 第 1 页 / 共 3 页
字号:
<?
include "header.php";

/* part Copyright 2005 peter.schaefer@gmail.com */

session_start();

// INITIAL SETUP

include_once "class_character.php";

/*
 * return the root of the damage
 * FIXME: charcters attacks, magic, and the opponents table have to be fixed to use the same system
 * the damage inflicted by character is completely out of proportion compared to damage min/max of npcs
 */
function root_damage($damage) {
    $exp= 0.49;//0.50
    return (int)(pow($damage,$exp)+rand(0,99)*0.01);
}

/*
 * return a random damage between min and max
 * Adding this kind of randomness should make combat more exciting, while keeping damage in the lower range most of the time.
 * FIXME: This function should somehow make root_damage superfluous, but that requires making npcs more player like
 */
function roll_damage($mindamage, $maxdamage) {

    $delta= $maxdamage-$mindamage;
    if($delta<1){
        $delta= 1;
    }

    $damage= floor( $mindamage+ exp( rand(0,floor(137.0*log($delta)))/137.0 ) + rand(0,99)*0.01 );
    DEBUG AND $_SESSION['disp_msg'][] = "DEBUG: damage between $mindamage-$maxdamage = $damage";
    return $damage;
}

$character = new character($PHP_PHAOS_CHARID);

$_SESSION['disp_msg'] = array();
if (isset($_GET['charfrom']))	{ $_SESSION['charfrom'] = $_GET['charfrom'];}

//FIXME: way to easy to hack
$_SESSION['fightbonus']= isset($_GET['bonus'])? $_GET['bonus']: 1;
if($_SESSION['fightbonus']>4){
    $_SESSION['fightbonus']= 4;
}

function setcombatlocation($combatlocation){
    $_SESSION['combatlocation']= $combatlocation;
    $result = mysql_query("select name from phaos_locations where id=$_SESSION[combatlocation] LIMIT 1");
    @list($_SESSION['locationname']) = mysql_fetch_row($result);
}

DEBUG AND $_SESSION['disp_msg'][] = "DEBUG: character hp= $character->hit_points";

// OPPONENT INFORMATION
if( @$_SESSION['charfrom'] != "arena" ) {
    DEBUG AND $_SESSION['disp_msg'][] = "DEBUG: normal combat";
    setcombatlocation($character->location);
    $list= whos_here($_SESSION['combatlocation'],'phaos_npc');
}else{
        //CAVEAT: usernames have limited length, so don't use too long names for npc character types

        $list= array();
        if(@$_SESSION['combatlocation']){
            $list= whos_here($_SESSION['combatlocation'],'phaos_arena_fighting');
            DEBUG AND $_SESSION['disp_msg'][] = "DEBUG: Trying to locate previous opponents, found ".count($list);
        } else {
        //place new monsters in arena
        // this code has to be moved/adapted into the arena.php, I guess, since otherwise the arena cannot properly set the level of the monster
            DEBUG AND $_SESSION['disp_msg'][] = "DEBUG: arena initial setup";

            //Set opponents level
            $opponent_level= intval(@$_GET['opponent_level']);
            if($opponent_level>0){
                $_SESSION['opp_level'] = $opponent_level;
            }else{
                $_SESSION['opp_level'] = (int)rand((int)($character->level/5),($character->level));
            }
            $other_opp_level= $_SESSION['opp_level'];

            // Set number of opponents
            $_SESSION['num_of_opps'] = rand(1, ceil(sqrt($opponent_level)) );

            $opponent_id= intval(@$_GET['opponent_id']);
            DEBUG AND $_SESSION['disp_msg'][] = "DEBUG: choosing opponent $opponent_id, lvl $_SESSION[opp_level] , $_SESSION[num_of_opps] foes";

            //find or create an arena location
            //FIXME
            //find out whether there is a city or special here, and use the name
            $result = mysql_query("select name from phaos_locations where id=$character->location LIMIT 1");
            @list($locationname) = mysql_fetch_row($result);

            $arenaat= isset($locationname)? $locationname : "Unknown ".rand(0,99);
            $arenaname= "Arena ".rand(1,3)." at $arenaat";

            //check whether this arena exists already
            $result = mysql_query("select id from phaos_locations where name='$arenaname' order by id DESC");
            @list($arenalocation) = mysql_fetch_row($result);
            if(!@$arenalocation){
                DEBUG and $_SESSION['disp_msg'][] = "DEBUG: adding new arena ";
                $arenalocation= nextLocationIdFromRange('arena_fighting_location',__FILE__,__LINE__);
                //insert if not exists
                $query= "insert into phaos_locations
                 (id, name, image_path, special, buildings, pass, explore)
                 values
                 ($arenalocation, '$arenaname','images/arena.gif',1,0,1,0)
                  ";
                $req = mysql_query($query);
                if (!$req) { showError(__FILE__,__LINE__,__FUNCTION__); exit;}

                $result = mysql_query("select id from phaos_locations where name='$arenaname' order by id DESC");
                @list($arenalocation) = mysql_fetch_row($result);

                //make arena point to itself so that monsters don't wander off
                $query= "update phaos_locations
                 set
                `above_left`= $arenalocation,
                `above`= $arenalocation,
                `above_right`= $arenalocation,
                `leftside`= $arenalocation,
                `rightside`= $arenalocation,
                `below_left`= $arenalocation,
                `below`= $arenalocation,
                `below_right`= $arenalocation
                where id= $arenalocation";
                $req = mysql_query($query);
                if (!$req) { showError(__FILE__,__LINE__,__FUNCTION__); exit;}
            }

            (@$arenalocation)or die('Must have a special location for arena');

            $_SESSION['arenalocation']= $arenalocation;
            setcombatlocation($_SESSION['arenalocation']);

            $opplocation= $character->location;

            //empty arena of old combatants
            //FIXME: check whether arena is in use
            $query= "update phaos_characters
             set location= '$opplocation',
                  username= 'phaos_npc_arena'
            where location= '$arenalocation'";
            $req = mysql_query($query);
            if (!$req) { showError(__FILE__,__LINE__,__FUNCTION__); exit;}

            $oppsneeded= $_SESSION['num_of_opps'];

            if(@$opponent_id){
                //try to find requested opponent
                $query = "SELECT id FROM phaos_characters WHERE $opplocation AND id=$opponent_id AND username LIKE 'phaos_%_arena'";
                $result = mysql_query($query);
                //place requested opponent
                if( mysql_num_rows($result)>0 ){
                    $oppcharacter= new character($opponent_id);
                    $oppcharacter->user= 'phaos_arena_fighting';
                    $oppcharacter->place($arenalocation);
                    $opponent_id= $oppcharacter->id;//paranoia
                    $list[]= $opponent_id;
                    $_SESSION['opponent_id'] = $opponent_id;
                    --$oppsneeded;
                    if(--$other_opp_level<1){
                        $other_opp_level= 1;
                    }
                }
            }

            //place new monsters on map
            $query = "SELECT * FROM phaos_opponents WHERE location='$opplocation' ORDER BY RAND() LIMIT $oppsneeded";
            $blueprints= fetch_all($query);
            foreach($blueprints as $blueprint){
                $npc= new np_character_from_blueprint($blueprint,$other_opp_level,'phaos_arena_fighting');
                $npc->place($arenalocation);
                $list[]= $npc->id;
                DEBUG AND $_SESSION['disp_msg'][] = @"DEBUG: placing $npc->name $npc->level $npc->username";
            }
            //$list= whos_here($_SESSION['combatlocation'],'phaos_arena_fighting');
        }// set up arena
}

$_SESSION['num_of_opps'] = count($list);
DEBUG AND $_SESSION['disp_msg'][] = "DEBUG: There are ".count($list)." opponents here.";

//TODO: for spells
//$opponentList= makeList($list);

$oppcharacter= null;
if (!count($list)) {
    $comb_act = 'endfight';
    DEBUG and print_msgs($_SESSION['disp_msg'],'','<br>');
    $link= endfight();
    jsChangeLocation($link);
    $skip_actions = true;
}else{
    $skip_actions = false;

    if(!@$_SESSION['opponent_id']){
        $_SESSION['opponent_id']= $list[0];
    }

    //load opponents
    $opponents= array();
    foreach($list as $id) {
        $opponents[$id]= new character($id);
    }

    if(@$_SESSION['opponent_id']){
        DEBUG AND $_SESSION['disp_msg'][] = "DEBUG: Using old opponent";
        $oppcharacter = &$opponents[$_SESSION['opponent_id']];
    }
    if(!@$oppcharacter || $oppcharacter->hit_points<=0 ) {
        $_SESSION['opponent_id'] = $list[0];
        $oppcharacter = &$opponents[$_SESSION['opponent_id']];
        DEBUG AND $_SESSION['disp_msg'][] = "DEBUG: Using new opponent";
    }
}

if(DEBUG){
    $_SESSION['disp_msg'][] = "DEBUG: location: ".@$character->location;
    $_SESSION['disp_msg'][] = "DEBUG: charfrom: ".@$_SESSION['charfrom'];
    $_SESSION['disp_msg'][] = "DEBUG: combat location: ".@$_SESSION['combatlocation'];
    $_SESSION['disp_msg'][] = "DEBUG: opponent id: ".@$oppcharacter->id;
    $_SESSION['disp_msg'][] = "DEBUG: opponent session id: ".@$_SESSION['opponent_id'];
    $_SESSION['disp_msg'][] = "DEBUG: LIST: ".print_r(@$list,true);
}

//$_SESSION['opponent_id']: the an opponent to attack
//$_SESSION['endcombat']: whether combat skips the monster attack, maybe if monster is dead

$_SESSION['endcombat'] = false;

if($skip_actions) {
    DEBUG AND $_SESSION['disp_msg'][] = "DEBUG: Skipping actions";
} else {  // Do this if we have an opponent ID  (only time we shouldn't have one is when we FIRST enter combat)

   $combat_continue = 1;   //Combat continues from where it left off

   if(isset($healed)) {
      if($_SESSION['no_heal'] == 1) {
         $_SESSION['disp_msg'][] = $lang_comb["not_heal_this"];
      } else {
        $_SESSION['disp_msg'][] = $lang_comb["drink"].$_SESSION['heal_points']."";
        refsidebar();
      }
      unset($healed);
   }

   // COMBAT ACTIONS
   if(!isset($comb_act)){
    $comb_act= 'travel';
   }

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -