Ejemplo n.º 1
0
function movenpc()
{
    // select an NPC/creature to move - let's pick the one that hasn't moved in the longest time
    $result = mysql_query("SELECT id FROM phaos_characters WHERE username='******' ORDER BY stamina_time LIMIT 1");
    if ($row = mysql_fetch_array($result)) {
        $npc = new character($row["id"]);
        defined('DEBUG') and DEBUG and $GLOBALS['debugmsgs'][] = " trying to relocate {$npc->name}({$npc->id}) at {$npc->location} with stamina_time={$npc->stamina_time}";
        // let NPC heal HP and stamina
        if ($npc->hit_points < $npc->max_hp) {
            $npc->hit_points += (int) ($npc->max_hp / 5);
            // heal 20%
            if ($npc->hit_points > $npc->max_hp) {
                $npc->hit_points = $npc->max_hp;
            }
        }
        if ($npc->stamina_points < $npc->max_stamina) {
            $npc->stamina_points += 3;
            // 3 at a time -- perhaps this should be calc another way
            if ($npc->stamina_points > $npc->max_stamina) {
                $npc->stamina_points = $npc->max_stamina;
            }
        }
        // reset stamina and regen time
        $npc->stamina_time = time() + 1000;
        // FIXME: using 1000 as temp amount
        $npc->regen_time = time() + 1000;
        // FIXME: using 1000 as temp amount
        if ($npc->location != 0) {
            $npc->relocate((int) rand(1, 8));
        }
        if ($npc->location == 0) {
            $condition_pass = $npc->sql_may_pass();
            // how did he get here??  -- let's put him at a random location
            defined('DEBUG') and DEBUG and $GLOBALS['debugmsgs'][] = " trying to relocate {$npc->name}({$npc->id}) at {$npc->location} with stamina_time={$npc->stamina_time}";
            $result = mysql_query("SELECT `id` FROM phaos_locations WHERE {$condition_pass} ORDER BY RAND() LIMIT 1") or die(mysql_error());
            list($newloc) = mysql_fetch_array($result);
            $npc->place($newloc);
        }
        // now we can update the DB
        $query = "UPDATE phaos_characters SET\n\t\t\thit_points\t=" . $npc->hit_points . ",\n\t\t\tstamina\t\t=" . $npc->stamina_points . ",\n\t\t\tstamina_time\t=" . $npc->stamina_time . ",\n\t\t\tregen_time\t=" . $npc->regen_time . "\n\t\t\tWHERE id\t='" . $npc->id . "'";
        $result = mysql_query($query);
        if (!$result) {
            echo "{$query}:<B>Error " . mysql_errno() . " :</B> " . mysql_error() . "";
            exit;
        }
    } else {
        // didn't set $row from sql query
        die("why could we not select a creature to move?");
    }
}
Ejemplo n.º 2
0
 $query = "update players\n             set location= '{$opplocation}',\n                  user= '******'\n            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 players WHERE {$opplocation} AND id={$opponent_id} AND user LIKE 'phaos_%_arena'";
     $result = mysql_query($query);
     //place requested opponent
     if (mysql_num_rows($result) > 0) {
         $oppcharacter = new character($opponent_id);
         $oppcharacter->user = '******';
         $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');