📄 class_character.php
字号:
if ($row = mysql_fetch_array($result)) {
$this->armor_ac = $row["armor_class"];
} else {
$this->armor_ac = 0;
}
$result = mysql_query ("SELECT * FROM phaos_boots WHERE id = '".$this->boots."'");
if ($row = mysql_fetch_array($result)) {
$this->boots_ac = $row["armor_class"];
} else {
$this->boots_ac = 0;
}
$result = mysql_query ("SELECT * FROM phaos_gloves WHERE id = '".$this->gloves."'");
if ($row = mysql_fetch_array($result)) {
$this->gloves_ac = $row["armor_class"];
} else {
$this->gloves_ac = 0;
}
$result = mysql_query ("SELECT * FROM phaos_shields WHERE id = '".$this->shield."'");
if ($row = mysql_fetch_array($result)) {
$this->shield_ac = $row["armor_class"];
} else {
$this->shield_ac = 0;
}
$result = mysql_query ("SELECT * FROM phaos_helmets WHERE id = '".$this->helm."'");
if ($row = mysql_fetch_array($result)) {
$this->helm_ac = $row["armor_class"];
} else {
$this->helm_ac = 0;
}
$this->max_inventory=$this->strength*5;
} else {
global $lang_na;
$this->name = $lang_na;
$this->strength = $lang_na;
$this->dexterity = $lang_na;
$this->wisdom = $lang_na;
$this->constitution = $lang_na;
$this->hit_points = $lang_na;
$this->max_hp = $lang_na;
$this->weapon = $lang_na;
$this->armor = $lang_na;
$this->boots = $lang_na;
$this->shield = $lang_na;
$this->gloves = $lang_na;
$this->helm = $lang_na;
$this->level = $lang_na;
$this->next_lev_xp = $lang_na;
$this->xp = $lang_na;
$this->gold = $lang_na;
$this->available_points = $lang_na;
}
if( !$this->image ) {
if($this->user=='phaos_npc') {
$this->image = "images/monster/forest_troll.gif";
}else{
$this->image = "images/icons/characters/character_1.gif";
}
}
//get location to be able to have location modifiers
$this->location_data= fetch_first("select * from phaos_locations where id='$this->location'");
//FIXME: since characters now have location data, many places in the code don't need to fetch it.
}
function auto_heal()
/**
* heals the character, if he is bellow maxhealth (and an given time has been exceeded)
*/
{
$result = @mysql_query('SELECT * FROM phaos_races WHERE name = \''.$this->race.'\'');
$data = @mysql_fetch_assoc($result);
if($this->time_since_regen >= $data['healing_time'] && $data['healing_rate'] > 0)
{
$char_regen_hp = $this->hit_points+(int)($this->time_since_regen/$data['healing_rate']);
if ($this->hit_points < $this->max_hp){
if($char_regen_hp > $this->max_hp){
$char_regen_hp = $this->max_hp;
}
$query = ("UPDATE phaos_characters SET hit_points = '$char_regen_hp', regen_time = '".time()."'WHERE id = '".$this->id."'");
$req = @mysql_query($query);
$this->hit_points=$char_regen_hp;
}else{
$query = ("UPDATE phaos_characters SET regen_time = '".time()."'WHERE id = '".$this->id."'");
$req = @mysql_query($query);
}
}
}
function auto_stamina ()
/**
* regens the character stamina, if he is below max_stamina (and an given time has been exceeded)
*/
{
$result = mysql_query('SELECT * FROM phaos_races WHERE name = \''.$this->race.'\'');
$data = mysql_fetch_assoc($result);
if($this->stamina_time_since_regen >= $data['stamina_regen_time'] && $data['stamina_regen_rate'] > 0)
{
//recover less during a fight, but leave the player a little opportunity to cheat in combat by waiting
$rate= @$_SESSION['opponent_id']?0.025:0.25;
$delta = fairInt(($this->stamina_time_since_regen/$data['stamina_regen_rate'])*(sqrt($this->constitution)*$rate+rand(0,99)*0.01));
if ($delta>0 && $this->stamina_points<$this->max_stamina)
{
$char_regen = $this->stamina_points+ $delta;
//defined('DEBUG') and DEBUG and print "updating $this->name from $this->stamina_points to $char_regen, max $this->max_stamina<br>";
if($char_regen > $this->max_stamina)
{
$char_regen = $this->max_stamina;
}
$query = ("UPDATE phaos_characters SET stamina = '$char_regen', stamina_time = '".time()."'WHERE id = '".$this->id."'");
$req = mysql_query($query);
$this->stamina_points=$char_regen;
}
else
{
$query = ("UPDATE phaos_characters SET stamina_time = '".time()."'WHERE id = '".$this->id."'");
$req = mysql_query($query);
}
}
}
/**
* regens the character reputation points to distribute, if a given time has been exceeded.
*/
function auto_reputation(){
//There are 86400 seconds in 24 hours
if($this->rep_time_since_regen >= 86400) {
//Add 1 rep point every 24 hours
$rep_regen = $this->rep_points+(INT)($this->rep_time_since_regen/86400);
if ($this->rep_points < $this->max_rep){
if($rep_regen > $this->max_rep) {$rep_regen = $this->max_rep;}
$query = ("UPDATE phaos_characters SET rep_points = '$rep_regen', rep_time = '".time()."' WHERE id = '".$this->id."'");
$req = mysql_query($query);
$this->rep_points=$rep_regen;
if (!$req) {showError(__FILE__,__LINE__,__FUNCTION__); exit;}
} else {
//print("Rep points at max");
$this->rep_points = $this->max_rep;
$query = ("UPDATE phaos_characters SET rep_points='$this->rep_points', rep_time = '".time()."' WHERE id = '".$this->id."'");
$req = mysql_query($query);
if (!$req) {showError(__FILE__,__LINE__,__FUNCTION__); exit;}
}
}
}
/**
* drinks the fist found potion in the inventory
*/
function drink_potion(){
// FIXME: this just gets the first potion from inventory!! Not a specific potion!
$result = mysql_query ("SELECT * FROM phaos_char_inventory WHERE username = '".$this->user."' AND type = 'potion'");
if ($row = mysql_fetch_array($result)) {
$potion_id = $row["item_id"];
$inv_id = $row["id"];
$result = mysql_query ("SELECT * FROM phaos_potion WHERE id = '$potion_id'");
if ($row = mysql_fetch_array($result)) { // if it's a valid potion
list($effect,$details) = split(' ',$row["effect"]); // determine potion effect
if ($effect == "heal") {
$heal_amount=$details;
$new_hp_amount = $this->hit_points + $heal_amount;
if($new_hp_amount > $this->max_hp) {$new_hp_amount = $this->max_hp;}
$query = ("UPDATE phaos_characters SET hit_points = $new_hp_amount WHERE id = '".$this->id."'");
$req=mysql_query($query);
if (!$req) {showError(__FILE__,__LINE__,__FUNCTION__); exit;}
$query = "DELETE FROM phaos_char_inventory WHERE id = '$inv_id'";
$result = mysql_query($query) or die ("Error in query: $query. " . mysql_error());
$this->hit_points=$new_hp_amount;
}
}
}
}
/**
* drinks a given Potion of the inventory
* @param $Inv_ID identifies the inventory-slot
*/
function drink_potion2($Inv_ID) {
$charID = $this->id;
$presult = mysql_query ("SELECT * FROM phaos_char_inventory WHERE id='$Inv_ID'");
if ($pot = mysql_fetch_array($presult)) {
$potion_id = $pot["item_id"];
$inv_id = $pot["id"];
$result = mysql_query ("SELECT * FROM phaos_potion WHERE id = '$potion_id'");
if ($row = mysql_fetch_array($result)) {
list($effect,$details) = split(' ',$row["effect"]); // determine potion effect
if ($effect == "heal" or $effect == "stamina") {
$current =& $this->hit_points; // pointer to hit_points value
$max=$this->max_hp;
$min=0;
$dbfield="hit_points";
$sayfield="hit points";
}
if ($effect == "stamina") {
$current =& $this->stamina_points; // pointer to stamina value
$max=$this->max_stamina;
$min=0;
$dbfield="stamina";
$sayfield="stamina";
}
if(@$dbfield) {
$add=$details;
if($current+$add > $max) {$add = $max-$current;}
if($current+$add < $min) {$add = $min-$current;}
$current += $add; // updates EITHER $this->hit_points or $this->stamina depending on pointer
$sql="UPDATE phaos_characters SET $dbfield = $current WHERE id = $charID";
mysql_query($sql) OR die("<B>Error ".mysql_errno()." :</B> full Query: $sql Mysql-error:".mysql_error()."");
$sql = "DELETE FROM phaos_char_inventory WHERE id = $inv_id";
mysql_query($sql) OR die ("Error in query: $query. ".mysql_error());
return "你得到 $add $sayfield";
} else {
return "这瓶药水效果未知";
}
}
}
}
/**
* (string)$attribute -> Attribute collumn of the char that has to be increesed
* @return Returns 0 on failure and 1 on all done successfully. (mainly SQL-errors!!)
*/
function level_up($attribute){
$query = ("UPDATE phaos_characters SET stat_points = stat_points-1, $attribute = $attribute+1 WHERE id = '".$this->id."'");
$req = mysql_query($query);
if (!$req) {return(0);}
else {return(1);}
}
/**
* @return returns character Level
*/
function level(){
return $this->level;
}
/**
* @return returns character available_points
*/
function available_points(){
return $this->available_points;
}
/**
* kill a character
* @return Returns 0 on failure and 1 on all done successfully. (mainly SQL-errors!!)
*/
function kill_character(){
$query = "DELETE FROM phaos_characters WHERE username = '".$this->user."'";
$result = mysql_query($query) or die ("Error in query: $query. " .
mysql_error());
$query = "DELETE FROM phaos_char_inventory WHERE username = '".$this->user."'";
$result = mysql_query($query) or die ("Error in query: $query. " .
mysql_error());
return 1;
}
/**
* @param (ID) ID character number to identify the desired character
* @return Returns 0 on failure and 1 on all done successfully. (mainly SQL-errors!!)
*/
function kill_characterid(){
$query = "DELETE FROM phaos_characters WHERE id = '".$this->id."'";
$result = mysql_query($query) or die ("Error in query: $query. " . mysql_error());
// FIXME: DBS - this should be changed so items are dropped at location
$query = "DELETE FROM phaos_char_inventory WHERE username = '".$this->user."'";
$result = mysql_query($query) or die ("Error in query: $query. " . mysql_error());
return 1;
}
/**
* check whether an item is equipped
* @param (string)$item_type - choose the item type as string
* @param (string)$item_id - the ID of the includet object
* @return boolean
*/
function equipped($item_type,$item_id){
if ($item_type=="armor"){return $this->armor==$item_id;}
if ($item_type=="weapon"){return $this->weapon==$item_id;}
if ($item_type=="gloves"){return $this->gloves==$item_id;}
if ($item_type=="helm"){return $this->helm==$item_id;}
if ($item_type=="shield"){return $this->shield==$item_id;}
if ($item_type=="boots"){return $this->boots==$item_id;}
return false;
}
/**
* equip an item
* @param (string)$item_type - choose the item type as string
* @param (string)$item_id - the ID of the includet object
* @return Returns 0 on failure and 1 on all done successfully. (mainly SQL-errors!!)
*/
function equipt($item_type,$item_id){
$query = ("UPDATE phaos_characters SET $item_type = '$item_id' WHERE id = '".$this->id."'");
$req = mysql_query($query);
if (!$req) { showError(__FILE__,__LINE__,__FUNCTION__); return 0; exit;}
if ($item_type=="armor"){$this->armor=$item_id;}
if ($item_type=="weapon"){$this->weapon=$item_id;}
if ($item_type=="gloves"){$this->gloves=$item_id;}
if ($item_type=="helm"){$this->helm=$item_id;}
if ($item_type=="shield"){$this->shield=$item_id;}
if ($item_type=="boots"){$this->boots=$item_id;}
return 1;
}
/**
* @param (string)$item_type - choose the item type as string
* @return Returns 0 on failure and 1 on all done successfully. (mainly SQL-errors!!)
*/
function unequipt($item_type){
switch($item_type){
case "armor":
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -