Файл: include/player_battle.php
Строк: 208
<?php
include_once("table_name.php");
include_once("base.php");
include_once("skill.php");
include_once("player.php");
include_once("player_thing.php");
include_once("thing.php");
include_once("common_func.php");
/**
class battle player
*/
class CPlayerBattle extends CBase
{
/** pointer on player skill class */
var $player_skill;
/** pointer on player class */
var $player;
/** pointer on player things*/
var $player_things;
/**
Constructor
*/
function CPlayerBattle($database,$vnum = 0)
{
global $table_player,$table_player_skill;
$this->db = $database;
$this->table_name=$table_player;
$this->vnum=$vnum;
$this->player_skill = new CSkill($database,$vnum);
$this->player = new CPlayer($database,$vnum);
$this->player_things = new CPlayerThings($database,$vnum);
}
/**
Get armor player, need calculate all cloth wear on player
*/
function getAC()
{
$ac=0;
$wear_head_id = $this->player_things->getWearThing(WEAR_HEAD);
$wear_body_id = $this->player_things->getWearThing(WEAR_BODY);
$wear_belt_id = $this->player_things->getWearThing(WEAR_BELT);
$wear_legs_id = $this->player_things->getWearThing(WEAR_LEGS);
$wear_foot_id = $this->player_things->getWearThing(WEAR_FOOT);
$thing = new CThing($this->db);
if($wear_head_id!=-1){
$wear_head_id=$this->player_things->getThingID($wear_head_id);
$thing->setVnum($wear_head_id);
$ac+=$thing->getV0();
}
if($wear_body_id!=-1){
$wear_body_id=$this->player_things->getThingID($wear_body_id);
$thing->setVnum($wear_body_id);
$ac+=$thing->getV0();
}
if($wear_belt_id!=-1){
$wear_belt_id=$this->player_things->getThingID($wear_belt_id);
$thing->setVnum($wear_belt_id);
$ac+=$thing->getV0();
}
if($wear_legs_id!=-1){
$wear_legs_id=$this->player_things->getThingID($wear_legs_id);
$thing->setVnum($wear_legs_id);
$ac+=$thing->getV0();
}
if($wear_foot_id!=-1){
$wear_foot_id=$this->player_things->getThingID($wear_foot_id);
$thing->setVnum($wear_foot_id);
$ac+=$thing->getV0();
}
return $ac;
}
/**
Get damage player in battle
param max_dm if max=0, then max damage
*/
function getWeaponDamage()
{
$weapon = array();
$thing = new CThing($this->db);
//get weapon in hand
$things_wear=$this->player_things->getWearThingsInHand();
//check two hand weapon
if(isset($things_wear[WEAR_TWO_HAND])){
$skill_id = $this->player_things->getThingSkill($things_wear[WEAR_TWO_HAND]);
$weapon_id=$this->player_things->getThingID($things_wear[WEAR_TWO_HAND]);
$thing->setVnum($weapon_id);
$level=$thing->getLevel();
$skill_level = $this->player_skill->getSkillLevel($skill_id);
//chance hit
$chance=getProbability($level,$skill_level);
$chance=floor(50+$skill_level/2);
if($chance==0){
$dm=0;//player not have using this weapon
}else{
$dm=$thing->getV2();
}
$weapon[WEAR_TWO_HAND]=array($weapon_id,$skill_id,$chance,$dm);
return $weapon;
}
//check left hand
if(isset($things_wear[WEAR_LEFT_HAND])){
$skill_id = $this->player_things->getThingSkill($things_wear[WEAR_LEFT_HAND]);
$weapon_id = $this->player_things->getThingID($things_wear[WEAR_LEFT_HAND]);
$thing->setVnum($weapon_id);
$level=$thing->getLevel();
$skill_level = $this->player_skill->getSkillLevel($skill_id);
//chance hit
$chance=getProbability($level,$skill_level);
if($chance==0){
$dm=0;//player not have using this weapon
}else{
$dm=$thing->getV2();
}
$chance=floor(50+$skill_level/2);
$weapon[WEAR_LEFT_HAND] = array($weapon_id,$skill_id,$chance,$dm);
}else{
$skill_level = $this->player_skill->getSkillLevel(SKILL_HAND_TO_HAND);
$chance=floor(50+$skill_level/2);
$dm="1d$skill_level";
$weapon[WEAR_LEFT_HAND] = array(0,SKILL_HAND_TO_HAND,$chance,$dm);
}
//check right hand
if(isset($things_wear[WEAR_RIGHT_HAND])){
$skill_id = $this->player_things->getThingSkill($things_wear[WEAR_RIGHT_HAND]);
$weapon_id = $this->player_things->getThingID($things_wear[WEAR_RIGHT_HAND]);
$thing->setVnum($weapon_id);
$level=$thing->getLevel();
$skill_level = $this->player_skill->getSkillLevel($skill_id);
//chance hit
$chance=getProbability($level,$skill_level);
$chance=floor(50+$skill_level/2);
if($chance==0){
$dm=0;//player not have using this weapon
}else{
$dm=$thing->getV2();
}
$weapon[WEAR_RIGHT_HAND] = array($weapon_id,$skill_id,$chance,$dm);
}else{
$skill_level = $this->player_skill->getSkillLevel(SKILL_HAND_TO_HAND);
$chance=floor(50+$skill_level/2);
$dm="1d$skill_level";
$weapon[WEAR_RIGHT_HAND] = array(0,SKILL_HAND_TO_HAND,$chance,$dm);
}
return $weapon;
}
/**
Get maximum damage player in battle
*/
function getMaxDM()
{
$dm=0;
$weapon=$this->getWeaponDamage();
if(isset($weapon[WEAR_TWO_HAND])){
//player have two hand weapon
$dm=phpmud_get_d_value($weapon[WEAR_TWO_HAND][3],1);
}else{
$dm=phpmud_get_d_value($weapon[WEAR_LEFT_HAND][3],1)+phpmud_get_d_value($weapon[WEAR_RIGHT_HAND][3],1);
}
return $dm;
}
//update player expirience in battle
function updateExp($skill_id,$expr)
{
$exp_skill=ceil(0.8*$expr);
$exp_hp=$expr-$exp_skill;
$this->player_skill->setSkill($skill_id,$exp_skill);
$this->player_skill->setSkill(SKILL_HP,$exp_hp);
}
function startBattle($vnum_mobs)
{
$this->player->setState(STATE_COMBAT);
$this->player->setObject($vnum_mobs);
$this->player->setRound(0);
}
}
?>