⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 class_character.php

📁 三國好好 子
💻 PHP
📖 第 1 页 / 共 4 页
字号:
                $this->armor='';
                break;
            case "weapon":
                $this->weapon='';
                break;
            case "gloves":
                $this->gloves='';
                break;
            case "helm":
                $this->helm='';
                break;
            case "shield":
                $this->shield='';
                break;
            case "boots":
                $this->boots='';
                break;
            default:
                return 0;
        }

		$query = ("UPDATE phaos_characters SET $item_type = '' WHERE id = '".$this->id."'");
		$req = mysql_query($query);
		if (!$req)  {showError(__FILE__,__LINE__,__FUNCTION__); return 0; exit;}
		return 1;
	}

	/**
    * Check whether the player still owns the items he has equipped
	* @param (string)$item_type - choose the item type as string
	* @param (string)$item_id   - choose the item id  as string
	* @return 1 on failure and 0 on all done successfully. (mainly SQL-errors!!)
	* system function to check the equipped items (do not use in public)
	*/
	function checkequipped($item_type,$item_id){
		if ($item_id=='' OR $item_id=='0' OR $item_id=='N/A'){ return(0); }

		$res=mysql_query("SELECT * FROM phaos_char_inventory WHERE username = '".$this->user."' AND item_id = '$item_id' AND type = '$item_type'");
		if ($row = mysql_fetch_array($res)) {
			return 0;
		} else {
            $this->unequipt($item_type);
			return 1;
		}
	}

	/**
	* @return the number of failures during check if "0" then all done correctly
	* Purpose: Usercalled function to check the equipped items
	*/
	function checkequipment(){
		$c1=$this->checkequipped("armor",$this->armor);
		$c1+=$this->checkequipped("weapon",$this->weapon);

		$c1+=$this->checkequipped("boots",$this->boots);
		$c1+=$this->checkequipped("shield",$this->shield);
		$c1+=$this->checkequipped("helm",$this->helm);
		$c1+=$this->checkequipped("gloves",$this->gloves);
		return $c1;
	}

	function get_eq_item_name($item_type){
		global $lang_na;
		if ($item_type=="armor"){$result = mysql_query ("SELECT * FROM phaos_armor WHERE id = '".$this->armor."'");}
		if ($item_type=="weapon"){$result = mysql_query ("SELECT * FROM phaos_weapons WHERE id = '".$this->weapon."'");}
		if ($item_type=="gloves"){$result = mysql_query ("SELECT * FROM phaos_gloves WHERE id = '".$this->gloves."'");}
		if ($item_type=="helm"){$result = mysql_query ("SELECT * FROM phaos_helmets WHERE id = '".$this->helm."'");}
		if ($item_type=="shield"){$result = mysql_query ("SELECT * FROM phaos_shields WHERE id = '".$this->shield."'");}
		if ($item_type=="boots"){$result = mysql_query ("SELECT * FROM phaos_boots WHERE id = '".$this->boots."'");}
		if ($row = mysql_fetch_array($result)) {
			return ($row["name"]);
		} else {return $lang_na;}

	}
	function get_eq_item_pic($item_type){
		global $lang_na;
		if ($item_type=="armor"){$result = mysql_query ("SELECT * FROM phaos_armor WHERE id = '".$this->armor."'");}
		if ($item_type=="weapons"){$result = mysql_query ("SELECT * FROM phaos_weapons WHERE id = '".$this->weapon."'");}
		if ($item_type=="gloves"){$result = mysql_query ("SELECT * FROM phaos_gloves WHERE id = '".$this->gloves."'");}
		if ($item_type=="helms"){$result = mysql_query ("SELECT * FROM phaos_helmets WHERE id = '".$this->helm."'");}
		if ($item_type=="shields"){$result = mysql_query ("SELECT * FROM phaos_shields WHERE id = '".$this->shield."'");}
		if ($item_type=="boots"){$result = mysql_query ("SELECT * FROM phaos_boots WHERE id = '".$this->boots."'");}
		if ($row = mysql_fetch_array($result)) {
			return ($row["image_path"]);
		} else {return 'images/icons/'.$item_type.'/na.gif';}

	}
	function reduce_stamina($ammount){
		$def=$this->stamina_points;
		$this->stamina_points=$def-$ammount;
				$query = ("UPDATE phaos_characters SET stamina = '".$this->stamina_points."'
							   WHERE id = '".$this->id."'");
				$req = mysql_query($query);
	}

	//shop functions of Character
	function pay($amount){
		// FIXME: this function should also take a payee character ID and add gold to them
		if($amount <= $this->gold) {
			//echo "paying:".$amount;
			$this->gold = $this->gold-$amount;
			$req = mysql_query("UPDATE phaos_characters SET gold = ".$this->gold." WHERE id = ".$this->id);
			if (!$req) {showError(__FILE__,__LINE__,__FUNCTION__); exit;}
			return 1;
		}	else {
			return 0;
		}
	}

	function invent_count(){
		$result 	 = mysql_query("SELECT * FROM phaos_char_inventory WHERE username = '".$this->user."'");
		$inv_count = mysql_num_rows($result);
		return $inv_count;
	}

	function add_item($item_id,$item_type){
		$query = "INSERT INTO phaos_char_inventory
				(username,item_id,type)
				VALUES
				('".$this->user."','$item_id','$item_type')";
		$req = mysql_query($query);
		if (!$req) {showError(__FILE__,__LINE__,__FUNCTION__); exit;}
		return 1;
	}

	function remove_item($item_id,$item_type){
		$query = "select id FROM phaos_char_inventory
				WHERE username='$this->user'
                   AND item_id='$item_id'
                   AND type='$item_type'";
        $id= fetch_value($query,__FILE__,__LINE__,__FUNCTION__);
        if($id){
    		$req = mysql_query("delete from phaos_char_inventory where id=$id");
    		if (!$req) {showError(__FILE__,__LINE__,__FUNCTION__); exit;}
    		return 1;
        }else{
            return 0;
        }
	}

    //
    // pickup one or more items from the ground - includes gold.
    // the actual change of the ground happens elsewhere
    //
    function pickup_item($item){
        $pickedup= 0;
        if($item['type']=="gold") {
            $req = mysql_query("update phaos_characters set gold=gold+$item[number] where id='$this->id'");
            if (!$req) {showError(__FILE__,__LINE__,__FUNCTION__); exit;}
            $pickedup+= 1;
        }else{
            for($i=0;$i<$item['number'];++$i){
                $pickedup+= $this->add_item($item['id'],$item['type']);                
            }
        }
        return $pickedup;
    }

    //
    // drop one or more items to the ground - includes gold.
    // the actual change of the ground happens elsewhere
    //
    function drop_item($item){
        $location= $this->location;
        $dropped= 0;
        if($item['type']=="gold") {
            $req = mysql_query("update phaos_characters set gold=gold-$item[number] where id='$this->id'");
            if (!$req) {showError(__FILE__,__LINE__,__FUNCTION__); exit;}
            $dropped+= $item['number'];
        }else{
            for($i=0;$i<$item['number'];++$i){
                $dropped+= $this->remove_item($item['id'],$item['type']);
            }
        }
        return $dropped;
    }

	// skill Raising and lowering
	function skillup($skillname){
        if($skillname == 'wisdom') {
    		$total=$this->fight+$this->defence+$this->weaponless+$this->lockpick+$this->traps+$this->wisdom;
            $wisdomoffset= 4+$this->level*2;
        }else{
    		$total=$this->fight+$this->defence+$this->weaponless+$this->lockpick+$this->traps;
            $wisdomoffset= 0; 
       }

        $chance= 10;
        if($this->race=='Gnome' && $skillname=='wisdom'){
            $total-= 1;
            $chance= 15;
        }

		if ($total<(10+$this->level+$wisdomoffset)){
			$rnd=rand(1,100); //normaly set to 100!
			if ($rnd<$chance){
				$query="update phaos_characters set $skillname=$skillname+1 where id='".$this->id."';";
				$exec=mysql_query($query);
				return(1);
			}
		}
		else{
			return(0);
		}
	}
		function skilldown(){
			$rnd=rand(1,100); //normaly set to 100!
			if ($rnd<5+($this->level/10)){
			$rnd2=rand(1,5);
			switch ($rnd2){
				case 1 : $skillname="fight";
									if ($this->fight<=1){ $exec=0;}
									else {$exec=1;}
									break;
				case 2 : $skillname="defence";
									if ($this->defence<=1){ $exec=0;}
									else {$exec=1;}
									break;
				case 3 : $skillname="weaponless";
									if ($this->weaponless<=1){ $exec=0;}
									else {$exec=1;}
									break;
				case 4 : $skillname="lockpick";
									if ($this->lockpick<=1){ $exec=0;}
									else {$exec=1;}
									break;
				case 5 : $skillname="trap";
									if ($this->trap<=1){ $exec=0;}
									else {$exec=1;}
									break;
				}
				if ($exec==1){
					$query="update phaos_characters set $skillname=$skillname-1 where id='".$this->id."';";
					$exec=mysql_query($query);
					echo mysql_error(); //debug row
					return(1);
				}
		}
		else{
			return(0);
		}
	}
	function inv_skillmatch(){
        $error= 0;
		 $wstr=$this->weapon_min+$this->weapon_max;
		 if ($wstr>($this->fight*3)+10){
	 			$this->unequipt("weapon");
				$error++;
		 }
		 if ($this->armor_ac>($this->defence*3)+10){
	 			$this->unequipt("armor");
				$error++;
		 }
		 if ($this->helm_ac>($this->defence)){
	 			$this->unequipt("helm");
				$error++;
		 }
		 if ($this->boots_ac>($this->defence)){
	 			$this->unequipt("boots");
				$error++;
		 }
		 if ($this->gloves_ac>($this->defence)){
	 			$this->unequipt("gloves");
				$error++;
		 }
		 if ($this->shield_ac>($this->defence)){
	 			$this->unequipt("shield");
				$error++;
		 }
		 return($error);
	}

    //place a character on the map
    // @optional $locationid the new location of the character
    // no argument = just save character information using the current location.
    function place($locationid=-1) {
        if($this->id>0) {
            $idkey= 'id,';
            $idvalue= "$this->id,";
            $auto_increment_id= false;
        }else{
            $idkey= "";
            $idvalue= "";
            //we use mysqls AUTO_INCREMENT feature
            $auto_increment_id= true;
        }
        if($locationid>=0){
            $this->location= $locationid;
        }
        $query = "REPLACE INTO phaos_characters
        (  $idkey location,image_path,username,name,age,strength,dexterity,wisdom,constitution,hit_points,race,class,sex,gold,fight,defence,weaponless,lockpick,traps
         , weapon,xp,level,armor,stat_points,boots,gloves,helm,shield,regen_time,stamina,stamina_time,rep_time,rep_points,rep_helpfull,rep_generious,rep_combat
        )
        VALUES
        (
           $idvalue '$this->location','$this->image','$this->user','$this->name','$this->age','$this->strength','$this->dexterity','$this->wisdom','$this->constitution','$this->hit_points','$this->race','$this->cclass','$this->sex',$this->gold
         , $this->fight,$this->defence,$this->weaponless,$this->lockpick,$this->traps
         , $this->weapon,$this->xp,$this->level,$this->armor,$this->stat_points,$this->boots,$this->gloves,$this->helm,$this->shield,$this->regen_time,$this->stamina_points,$this->stamina_time,$this->rep_time,$this->rep_points,$this->rep_helpfull,$this->rep_generious,$this->rep_combat
        )";

        $req = mysql_query($query);
        if (!$req) {showError(__FILE__,__LINE__,__FUNCTION__); exit;}

        if( $auto_increment_id ){
            $query= "select id from phaos_characters where location='$this->location' order by id desc LIMIT 1";
            $req = mysql_query($query);
            if (!$req) {showError(__FILE__,__LINE__,__FUNCTION__); exit;}
            $row= mysql_fetch_assoc($req);
            if($row) {
                $this->id= $row['id'];
            }
        }
        defined('DEBUG') and DEBUG and $GLOBALS['debugmsgs'][]= " placed $this->name(id:$this->id, user:$this->user)";
    }

    function all_skillsup($action,$lang_fun) {
    	if ($action == "magic_attack") {
			$ret=$this->skillup("wisdom");
			if ($ret==1){ $_SESSION['disp_msg'][] = $lang_fun["gai_wis"]; }
		} else {
			if ($this->weapon==0){
			$ret=$this->skillup("weaponless");

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -