<?php
/**
 * Character object file
 * @author Lauri Lüüs <mad@webpoint.ee>
 * @version $Id: Character.php 12 2005-05-27 13:47:30Z madest $
 * @package AccountManager
 * @filesource
 */

/**
 * Character object
 * @author Lauri Lüüs <mad@webpoint.ee>
 * @version $Id: Character.php 12 2005-05-27 13:47:30Z madest $
 * @package AccountManager
 */
class Character extends AccountManager
{
	var $account_name;
	var $charId;
	var $char_name;
	var $level;
	var $maxHp;
	var $curHp;
	var $maxMp;
	var $curMp;
	var $acc;
	var $crit;
	var $evasion;
	var $mAtk;
	var $mDef;
	var $mSpd;
	var $pAtk;
	var $pDef;
	var $pSpd;
	var $runSpd;
	var $walkSpd;
	var $str;
	var $con;
	var $dex;
	var $_int;
	var $men;
	var $wit;
	var $face;
	var $hairStyle;
	var $hairColor;
	var $sex;
	var $heading;
	var $x;
	var $y;
	var $z;
	var $movement_multiplier;
	var $attack_speed_multiplier;
	var $colRad;
	var $colHeight;
	var $exp;
	var $sp;
	var $karma;
	var $pvpkills;
	var $pkkills;
	var $clanid;
	var $maxload;
	var $race;
	var $classid;
	var $deletetime;
	var $cancraft;
	var $title;
	var $allyId;
	var $accesslevel;
	var $char_slot;
	var $online;

	/**
	 * Class Name
	 */
	var $class;
	
	/**
	 * Character constructor
	 */
	function Character($charId)
	{
		$this->AccountManager();
		$this->charId = $charId;
		$this->get();
	}
	
	/**
	 * Get character data
	 */ 	
	function get()
	{
		
		$q = mysql_query("SELECT * FROM characters WHERE charId = '{$this->charId}'");
		$r = mysql_fetch_array($q);
		
		if(mysql_num_rows($q)!=0)
		{
			foreach ($r as $key => $val )
			{
				$this->$key = $val;				
			}
			$q = mysql_query("SELECT * FROM char_templates WHERE ClassId = '{$r['classid']}'");
			$r = mysql_fetch_array($q);
			$this->class = $r['ClassName'];
			return true;
			
		} else { // No such character
			return false;
		}
	}
	
	/**
	 * Set characters access
	 */
	function set_access($new_access)
	{
		if($_POST['access'] <= 999 && $_POST['access'] >= -999)
		{
			mysql_query("UPDATE characters SET accesslevel = '{$new_access}' WHERE charId = '{$this->charId}'");
			return  true;
		} else {
			return  false;
		}
	}
	
	/**
	 * Delete character and his stuff (inventory, warehouse .. etc)
	 */
	function delete()
	{
		/**
		 * com.l2jserver.gameserver.network.L2GameClient.deleteCharByObjId(int objid)
		 *  -- www.l2jserver.com L2GameClient.java rev.4426  2010/12/11
		 * modify: JOJO
		 */
		$objid = $this->charId;
		//mysql_query('START TRANSACTION');
		@mysql_query("DELETE FROM character_friends WHERE charId=$objid OR friendId=$objid");
		@mysql_query("DELETE FROM character_hennas WHERE charId=$objid");
		@mysql_query("DELETE FROM character_macroses WHERE charId=$objid");
		@mysql_query("DELETE FROM character_quests WHERE charId=$objid");
		@mysql_query("DELETE FROM character_quest_global_data WHERE charId=$objid");
		@mysql_query("DELETE FROM character_recipebook WHERE charId=$objid");
		@mysql_query("DELETE FROM character_shortcuts WHERE charId=$objid");
		@mysql_query("DELETE FROM character_skills WHERE charId=$objid");
		@mysql_query("DELETE FROM character_skills_save WHERE charId=$objid");
		@mysql_query("DELETE FROM character_subclasses WHERE charId=$objid");
		@mysql_query("DELETE FROM heroes WHERE charId=$objid");
		@mysql_query("DELETE FROM olympiad_nobles WHERE charId=$objid");
		@mysql_query("DELETE FROM seven_signs WHERE charId=$objid");
		@mysql_query("DELETE FROM pets WHERE item_obj_id IN (SELECT object_id FROM items WHERE items.owner_id=$objid)");
		@mysql_query("DELETE FROM item_attributes WHERE itemId IN (SELECT object_id FROM items WHERE items.owner_id=$objid)");
		@mysql_query("DELETE FROM items WHERE owner_id=$objid");
		@mysql_query("DELETE FROM merchant_lease WHERE player_id=$objid");
		@mysql_query("DELETE FROM character_raid_points WHERE charId=$objid");
		@mysql_query("DELETE FROM character_reco_bonus WHERE charId=$objid");
		@mysql_query("DELETE FROM character_instance_time WHERE charId=$objid");
		@mysql_query("DELETE FROM characters WHERE charId=$objid");
		//mysql_query('COMMIT');
	}
}
?>