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?"); } }
/** * @param: none * return: none * purpose: generate new NPC/monster and add to database */ function npcgen() { $res = mysql_query("SELECT * FROM phaos_opponents WHERE location='0' ORDER BY RAND() LIMIT 1") or die(mysql_error()); if ($blueprint = mysql_fetch_array($res)) { //create 50% level 1 characters, and not more than 37,5% characters with level>3 $level = 1 + (int) (rand(0, 1) * (pow(1 + rand(0, 10) * rand(0, 10) * 0.01, 4) + rand(0, 99) * 0.01)); $npc = new np_character_from_blueprint($blueprint, $level); $condition_passable = $npc->real_sql_may_pass(); //TODO: add generator regions/locations feature to phaos $tries = 10; while ($tries-- > 0) { $res = null; //FIXME: this actually should depend on the area covered by dungeons //20050717 //Wilderness 14277 //Woodlands 1891 //Dungeon 675 if (!@$res && rand(0, 99) < 4) { $location = 'Rune Gate%'; $sql = "SELECT id FROM phaos_locations WHERE (name LIKE 'Rune Gate%' OR name LIKE 'Dungeon') AND {$condition_passable} ORDER BY RAND() LIMIT 1"; //defined('DEBUG') and DEBUG and $GLOBALS['debugmsgs'][]= __FUNCTION__.": sql: $sql"; $res = mysql_query($sql) or die(mysql_error()); } if (!@$res) { $location = 'Wilderness'; $sql = "SELECT id FROM phaos_locations WHERE (name LIKE 'Wilderness' OR name LIKE 'Woodlands' OR name LIKE 'Rune Gate%' OR name LIKE 'Dungeon') AND {$condition_passable} ORDER BY RAND() LIMIT 1"; //defined('DEBUG') and DEBUG and $GLOBALS['debugmsgs'][]= __FUNCTION__.": sql: $sql"; $res = mysql_query($sql) or die(mysql_error()); } list($locationid) = mysql_fetch_array($res); //check whether location is crowded $res = mysql_query("SELECT count(*) FROM phaos_characters WHERE location='{$locationid}' AND username='******'") or die(mysql_error()); list($count) = mysql_fetch_array($res); if ($count > $level + 1) { defined('DEBUG') and DEBUG and $GLOBALS['debugmsgs'][] = " location {$locationid} is <b>crowded</b>, not placing here ({$count} npcs)"; //trying to fix $res = mysql_query("SELECT id FROM phaos_characters WHERE location='{$locationid}' AND username='******'") or die(mysql_error()); while (list($id) = mysql_fetch_array($res)) { $crowd = new character($id); $crowd->relocate((int) rand(1, 8)); } } else { break; //stop while loop } } } else { die("cant find valid mob in DB: " . mysql_error()); } $npc->place($locationid); DEBUG and $_SESSION['disp_msg'][] = "**DEBUG: {$npc->name}({$npc->level}) generated at location {$location} {$locationid}"; return 1; }
} unset($healed); } // COMBAT ACTIONS if (!isset($comb_act)) { $comb_act = 'travel'; } if ($comb_act == 'flee') { // Flee Code $char_flee_roll = $character->dexterity + $character->level + diceroll(); $opp_flee_roll = $oppcharacter->dexterity + $oppcharacter->level + diceroll(); DEBUG and $_SESSION['disp_msg'][] = "DEBUG: Flee roll {$char_flee_roll} > {$opp_flee_roll}?"; if ($char_flee_roll > $opp_flee_roll or rand(1, 100) < 10) { //move character to random adjacent location for ($i = 0; $i < 24; ++$i) { if ($character->relocate(rand(1, 8))) { break; } } //Character Flees $link = endfight(); jsChangeLocation($link); } else { jsChangeLocation("combat.php?comb_act=npc_attack&fleefail=1"); } } // BEGIN ATTACK CODE if ($comb_act == 'both_attack' or $comb_act == 'char_attack' or $comb_act == 'magic_attack') { //Check Stamina points if ($character->stamina_points <= 0) { $_SESSION['disp_msg'][] = $lang_comb["stam_noo"];