📄 class_character.php
字号:
<?php
include_once "items.php";
class character {
//main variables
var $id;
var $name;
var $user;
var $cclass; //instead of Class only!
var $race;
var $image;
var $age;
var $sex;
var $location;
var $location_data;
//attribute vars
var $strength;
var $dexterity;
var $wisdom;
var $constitution;
//changeable vars
var $hit_points;
var $stamina_points;
var $level;
var $xp;
var $gold;
var $stats_points;
//equipment vars
var $weapon;
var $armor;
var $gloves;
var $helm;
var $shield;
var $boots;
//vars to be calculated
var $max_hp;
var $next_level;
var $available_points;
var $max_stamina;
var $stamina_degrade;
var $max_rep;
//other vars
var $time_since_regen;
var $stamina_time_since_regen;
var $rep_time_since_regen;
var $regen_time;
var $rep_time;
var $no_regen_hp;
//Fighting_Vars
var $weapon_min;
var $weapon_max;
var $weapon_name;
var $armor_ac;
var $boots_ac;
var $gloves_ac;
var $shield_ac;
var $helm_ac;
//trade & inventory
var $max_inventory;
// Skills
var $fight;
var $defence;
var $weaponless;
var $lockpick;
var $traps;
// Reputation
var $rep_points;
var $rep_helpfull;
var $rep_generious;
var $rep_combat;
//end_of_vars
function finding() {
//TODO: finding could be a character skill
$finding= $this->wisdom;
$fchance= (int)(33.33+6.66*sqrt($finding));//DONT add random effects to modify fchance, this has to be deterministic
return $fchance;
}
function ac() {
return $this->armor_ac+$this->boots_ac+$this->gloves_ac+$this->helm_ac+$this->shield_ac;
}
function attack_skill_min() {
$skill = $this->weapon==0 ? $this->weaponless : $this->fight;
$skill+= $this->attack_bonus();
return fairInt(pow($skill*$this->dexterity,0.66));
}
function attack_skill_max() {
$exp= 0.80;
if ($this->weapon==0) {
return fairInt(pow(($this->strength+$this->dexterity)*$this->weaponless,$exp));
} else {
return fairInt(pow(($this->strength+$this->dexterity)*$this->fight,$exp));
}
}
function defense_max() {
return $this->defense_min()+fairInt(sqrt($this->dexterity*($this->defence+1)));
}
function defense_min() {
return $this->ac()+$this->weaponless+$this->defense_bonus();
}
function defense_skill_max() {
return $this->defense_min()+fairInt(sqrt($this->dexterity*($this->defence+1)));
}
function defense_skill_min() {
return fairInt(sqrt($this->ac())+$this->weaponless+$this->defense_bonus());
}
function attack_min() {
if ($this->weapon==0) {
return $this->weaponless*$this->strength;
} else {
return $this->weapon_min*$this->strength;
}
}
function attack_max() {
if ($this->weapon==0) {
$skill= $this->weaponless;
} else {
$skill= $this->weapon_max+$this->fight;
}
return fairInt( ($this->strength+$this->dexterity)*$skill );//TODO: change phaos_opponents and use sqrt(dex) here
}
function fight_reduction() {
$factor= $this->stamina_points/$this->max_stamina;
if($factor> 0.66) {
return 1;
} elseif($factor<0.33) {
return 0.33;
} else {
return 0.33+($factor-0.33)*2;
}
}
function attack_roll($comb_act,$test=false) {
if(DEBUG) {
if($comb_act == "magic_attack") {
$_SESSION['disp_msg'][] = "**DEBUG: wisdom: ".$this->wisdom;
} else {
$_SESSION['disp_msg'][] = "**DEBUG: strength: $this->strength";
$_SESSION['disp_msg'][] = "**DEBUG: dexterity: $this->dexterity";
$_SESSION['disp_msg'][] = "**DEBUG: fight: $this->fight";
$_SESSION['disp_msg'][] = "**DEBUG: weapon name: $this->weapon_name";
$_SESSION['disp_msg'][] = "**DEBUG: weapon: $this->weapon_max";
$_SESSION['disp_msg'][] = "**DEBUG: weaponless: $this->weaponless";
$_SESSION['disp_msg'][] = "**DEBUG: attack_skill_min: ".$this->attack_skill_min();
$_SESSION['disp_msg'][] = "**DEBUG: attack_skill_max: ".$this->attack_skill_max();
$_SESSION['disp_msg'][] = "**DEBUG: attack_min: ".$this->attack_min();
$_SESSION['disp_msg'][] = "**DEBUG: attack_max: ".$this->attack_max();
}
}
$rollthedice = diceroll();
if(DEBUG>=2) {$_SESSION['disp_msg'][] = "**DEBUG: dice roll = $rollthedice";}
if ($comb_act == "magic_attack") {
$char_attack = round(($this->wisdom+$rollthedice)/2);
} else {
$fight_reduction= $this->fight_reduction();
if(DEBUG>=1) {
$_SESSION['disp_msg'][] = "**DEBUG: fight reduction = $fight_reduction";}
$char_attack = round(($this->dexterity+rand(
(int)($this->attack_skill_min()*$fight_reduction),
(int)($this->attack_skill_max()*$fight_reduction)
)
+$rollthedice)/8);
}
if(!$test){
if($this->stamina_points>0){
--$this->stamina_points;
}
}
return $char_attack;
}
function defence_roll($comb_act,$test=false){
$rollthedice = diceroll();
if(DEBUG>=2) {$_SESSION['disp_msg'][] = "**DEBUG: dice roll = $rollthedice";}
if ($comb_act == "magic_attack") {
$char_defence= (int)(($this->wisdom+$rollthedice)/2+rand(0,99)*0.01);
} else {
if(DEBUG>=2) {$_SESSION['disp_msg'][] = "**DEBUG: defense_min = ".($this->defense_min());}
$char_def = rand($this->defense_skill_min(),$this->defense_skill_max());
$char_defence= (int)(($this->dexterity+$char_def+$rollthedice)/10 +rand(0,99)*0.01 );
}
if(!$test){
if($this->stamina_points>0){
--$this->stamina_points;
}
}
return $char_defence;
}
//Update Character Stamina Points in the DataBase
function update_stamina(){
if($this->stamina_points>$this->max_stamina){
$this->stamina_points= $this->max_stamina;
}
$sql = "UPDATE phaos_characters SET stamina = ".$this->stamina_points." WHERE id=$this->id";
$res = mysql_query($sql);
if(!$res){ showError(__FILE__,__LINE__,__FUNCTION__); exit; };
}
function attack_bonus() {
if($this->location_data){
if( 'Elf' == $this->race && stristr($this->location_data['name'],'Woodland') !== false ){
return 1+fairInt($this->level*0.05);
}
}
}
function defense_bonus() {
if($this->location_data){
if( 'Elf' == $this->race && stristr($this->location_data['name'],'Woodland') !== false ){
return 1+fairInt($this->level*0.1);
}
}
}
/**
* constructor
* @param character id
*/
function character($id){
$result = mysql_query ("SELECT * FROM phaos_characters WHERE id = '$id'");
if ($row = mysql_fetch_array($result)) {
//define main vars
$this->id=$row["id"];
$this->name=$row["name"];
$this->user=$row["username"];
$this->cclass=$row["class"];
$this->race=$row["race"];
$this->sex=$row["sex"];
$this->image=$row["image_path"];
$this->age=$row["age"];
$this->location=$row["location"];
//define attribute vars
$this->strength = $row["strength"];
$this->dexterity = $row["dexterity"];
$this->wisdom = $row["wisdom"];
$this->constitution = $row["constitution"];
//define changeable vars
$this->hit_points = $row["hit_points"];
$this->stamina_points=$row["stamina"];
if($row['level'] == 0 OR $row['level'] == "") {
$this->level = 1;
} else {
$this->level = (int)$row['level'];
}
$this->xp = (int)$row["xp"];
$this->gold = $row["gold"];
$this->stat_points = $row["stat_points"];
//define equipment vars
$this->weapon = $row["weapon"];
$this->armor = $row["armor"];
$this->boots = $row["boots"];
$this->shield = $row["shield"];
$this->gloves = $row["gloves"];
$this->helm = $row["helm"];
//FIX
//at some point during development some characters had negative strength
//this should not happen usually
if($this->constitution<1){
$this->constitution=1;
}
if($this->strength<1){
$this->strength=1;
}
//calculated stuff
$this->available_points = $this->strength+$this->dexterity+$this->wisdom+$this->constitution;
$this->max_hp = $this->constitution*6;
$this->max_stamina = ($this->constitution+$this->strength)*10;
$this->max_rep = 7;
//other stuff
$this->regen_time = $row["regen_time"];
$this->stamina_time = $row["stamina_time"];
$this->rep_time = $row["rep_time"];
$this->no_regen_hp = $row["hit_points"];
//regeneration
$actTime=time();
$this->time_since_regen = $actTime-$this->regen_time;
$this->stamina_time_since_regen = $actTime-$this->stamina_time;
$this->rep_time_since_regen = $actTime-$this->rep_time;
//skills
$this->fight = $row["fight"];
$this->defence = $row["defence"];
$this->weaponless = $row["weaponless"];
$this->lockpick = $row["lockpick"];
$this->traps = $row["traps"];
//reputation
$this->rep_points = $row["rep_points"];
$this->rep_helpfull = $row["rep_helpfull"];
$this->rep_generious = $row["rep_generious"];
$this->rep_combat = $row["rep_combat"];
//weapon & fight Calculation
//fill weapon:
$result = mysql_query ("SELECT * FROM phaos_weapons WHERE id = '".$this->weapon."'");
if ($row = mysql_fetch_array($result)) {
$this->weapon_min = $row["min_damage"];
$this->weapon_max = $row["max_damage"];
$this->weapon_name = $row["name"];
} else {
$this->weapon = 0;
$this->weapon_min = 0;
$this->weapon_max = 1;
$this->weapon_name = 'Bare Hands';
}
//fill armor
$result = mysql_query ("SELECT * FROM phaos_armor WHERE id = '".$this->armor."'");
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -