Файл: include/skill.php
Строк: 69
<?php
include_once("table_name.php");
include_once("constants.php");
include_once("player.php");
/**
    class for work player skill
*/
class CSkill extends CBase
{
    /**
        Constructor
    */
    function CSkill($database,$vnum = 0)
    {
        $this->db=$database;
        $this->table_name=$GLOBALS['table_player_skill'];
        $this->vnum=$vnum;
    }
    function getSkillProgress($type)
    {
        $sql = "select progress from $this->table_name where vnum='$this->vnum' and type='$type'";
        $result = $this->execSQL($sql);
        if($result->numRows()==0) return false;
        $row = $result->fetchRow();
        return $row[0];
    }
    function getSkills()
    {
        $sql = "select type from $this->table_name where vnum='$this->vnum'";
        $result = $this->execSQL($sql);
        $skills = array();
        while($row = $result->fetchRow())
        {
            $skills[] = array("type" => $row[0]);
        }
        return $skills;
    }
    /**
        Get skill level
        param type type skill
    */
    function getSkillLevel($type)
    {
        $sql = "select level from $this->table_name where vnum='$this->vnum' and
type='$type'";
        $result = $this->execSQL($sql);
        if($result->numRows()==0) return false;
        $row = $result->fetchRow();
        return $row[0];
    }
    
    /**
        set player skill
        param type type skill
    */
    function setSkill($type,$progress=1,$level=1)
    {
        global $skill_exp_table;
        
        $prog=$this->getSkillProgress($type);
        if($prog==false){
            //need insert
            $sql = "insert into $this->table_name(vnum,type,progress,level)".
            "values ('$this->vnum','$type','$progress','$level')";
            
            $result = $this->execSQL($sql);
        }else{
            //need update
            $sql = "update $this->table_name set progress=progress+$progress where vnum='$this->vnum' and
type='$type'";
            
            $result = $this->execSQL($sql);
            
            //check level update
            $prog+=$progress;
            $level=$this->getSkillLevel($type);
            $exp=$skill_exp_table[$level+1];
            if($exp<$prog){
                //need update level
                $sql = "update $this->table_name set level=level+1 where vnum='$this->vnum' and
type='$type'";
                
                $result = $this->execSQL($sql);
                
                if($type==SKILL_HP){
                    //need update hp hero
                    $hp=$this->getHPSkill();
                    $player = new CPlayer($this->db,$this->vnum);
                    $max_hp=$player->getMaxHP();
                    $player->setMaxHP($max_hp+$hp);
                }
            }
        }
        
    }
    /**
        get HP on skill
    */
    function getHPSkill()
    {
        $hp=mt_rand(8,12);
        return $hp;
    }
}
?>