Просмотр файла element_function/element_function_item.php

Размер файла: 16.7Kb
<?php
	$quality_name = array('Обычное','Эпическое','Легендарное','Дары Богов','Трофейное', 'Уникальное');
	
	$max_count_item = 20;
	
	$array_1 = array('helmet' => array('lost_params_heatpoints', 'здоровья'),
					 'cape' => 	 array('lost_params_heatpoints', 'здоровья'),
					 'armor' =>  array('lost_params_heatpoints', 'здоровья'),
					 'zone' =>   array('lost_params_strlen', 'силы'),
					 'feet' =>   array('lost_params_protection', 'защиты'),
					 'hands' => array('lost_params_strlen', 'силы'),
					 'shield' => array('lost_params_protection', 'защиты'),
					 'weapon' => array('lost_params_strlen', 'силы'),
					 'shoes' => array('lost_params_protection', 'защиты'));
	
	function item_params_type($mesto) {
		global $array_1;
		return $array_1[$mesto];
	}
	// item_params_type();
	function item_razbor($quality) {
		$count = array(10,20,30,40,50);
		return $count[$quality];
	}
	
	function SelectItemUser($user, $bag, $mesto) {
		if ($mesto) return mysql_fetch_array(mysql_query("SELECT * FROM `element_item` WHERE `lost_id` = '$user' AND `lost_bag` = '$bag' AND `lost_mesto` = '$mesto' LIMIT 1"));
	else return mysql_fetch_array(mysql_query("SELECT * FROM `element_item` WHERE `lost_id` = '$user' AND `lost_bag` = '$bag' LIMIT 1"));
	}
	
	// Функция переобразирует тип вешей на русский
	function name_item_mesto($mesto) {
		$name_mesto = array('helmet' => 'Голова', 'weapon' => 'Правая рука', 'shield' => 'Левая рука', 
							'zone' => 'Пояс', 'armor' => 'Тело', 'cape' => 'Накидка',
							'feet' => 'Ноги', 'hands' => 'Руки', 'shoes' => 'Обувь');
		return $name_mesto[$mesto];
	}
	
	function item_enchants_quality($quality, $params_name) {
		if ($quality >= 0) {
			$array_enchants = array(0 => 50, 1 => 75, 2 => 150, 3 => 250, 4 => 350, 5 => 500);
			$image = quality_item_name($quality);
			return array('params' => $array_enchants[$quality], 'quality' => $quality, 'image' => $image['image'], 'name' => $params_name);
		} return false;
	}
	
	///////////////////////////////////////////////////////
	//////////////////сила//////здоровье//////защита///////
	// Голова 	////   10	///	  17	///// 	13	 //////		здоровье
	// Оружие	////   17	///   10 	///// 	13   //////		сила
	// Щит  	////   10 	///   13	/////   17	 //////     защита
	// Пояс	    ////    9 	///    9 	///// 	 9 	 //////		сила
	// Брониров ////   10 	///   13    ///// 	13 	 //////		здоровье
	// Накидка 	////    9	///   11	///// 	 9	 //////		здоровье
	// Штаны	////   11	///    9 	/////    9	 //////		защита
	// Перчатки	////   13	///    9	/////    9   //////		сила
	// Обувь	////   13	///   10	/////   10 	 //////		защита
	// Сумма	////  102	///  101	/////  102	 //////		
	///////////////////////////////////////////////////////
	
	function item_generation_quality($quality) {
		if ($quality == 0) return rand(  0, 25);
		if ($quality == 1) return rand( 26, 50);
		if ($quality == 2) return rand( 51,100);
		if ($quality == 3) return rand(101,150);
		if ($quality == 4) return rand(151,250);
		if ($quality == 5) return rand(251,400);
	}
	
	function item_generation_params($strlen, $heatpoints, $protection, $comparison) {
		$array_params = array(explode(':', $strlen), explode(':', $heatpoints), explode(':', $protection));
		$array_genera = array(params($array_params[0][0], $array_params[0][1]),params($array_params[1][0], $array_params[1][1]),params($array_params[2][0], $array_params[2][1]));
		
		if ($comparison > 0) {
			$pr = $comparison * 5;
			$array_genera[0][0] = (int)(($array_genera[0][0] / 100) * (100 + $pr));
			$array_genera[1][0] = (int)(($array_genera[1][0] / 100) * (100 + $pr));
			$array_genera[2][0] = (int)(($array_genera[2][0] / 100) * (100 + $pr));
		}
		$summa = $array_genera[0][0] + $array_genera[1][0] + $array_genera[2][0];
		
		return array('strlen' => $array_genera[0][0], 'strlen_pr' => $array_genera[0][1],
					 'heatpoints' => $array_genera[1][0], 'heatpoints_pr' => $array_genera[1][1],
					 'protection' => $array_genera[2][0], 'protection_pr' => $array_genera[2][1],
					 'summa' => $summa);
	}
	
	

	
	// Функция создания вещей: 0 - айди юзера, 1 - массив с вещами, 2 - качество, 3 - пр. сила, 4 - пр. хп, 5 - пр. бр
	// 6 - чара силы, 7 - чара хп, 8 - чара защиты, 9 - новая/личная
	function create_item($user_id, $bag, $quality, $pr_str, $pr_hp, $pr_prot, $enchants, $new, $set, $type, $comparison) {
	if (count($bag) < 20) {
		if (!$quality) $quality = 0;									// Если не указан шанс, генерируем его
		if (!$pr_str)  $pr_str = item_generation_quality($quality);		// Если не указан процент, генерируем его
		if (!$pr_hp)   $pr_hp = item_generation_quality($quality);		// Если не указан процент, генерируем его
		if (!$pr_prot) $pr_prot = item_generation_quality($quality);	// Если не указан процент, генерируем его

		if (!$enchants) $enchants = -1;
		
		if (!$new) $new = 0;
		
		if (!$type) {
			global $array_type;
			$type = $array_type[array_rand($array_type)];
		}
		
		if (!$comparison) $comparison = 0;
		
		$item = mysql_fetch_array(mysql_query("SELECT * FROM `element_equipment` WHERE `lost_quality` = '$quality' AND `lost_mesto` = '$type' LIMIT 1"));
		
		if ($item) {
			mysql_query("INSERT INTO `element_item` SET `lost_name` = '$item[lost_name]',
														`lost_quality` = '$quality',
														`lost_user` = '$user_id',
														`lost_strlen` = '$item[lost_strlen]:$pr_str',
														`lost_heatpoints` = '$item[lost_heatpoints]:$pr_hp',
														`lost_protection` = '$item[lost_protection]:$pr_prot',
														`lost_mesto` = '$item[lost_mesto]',
														`lost_set` = '$item[lost_set]',
														`lost_avatar` = '$item[lost_avatar]',
														`lost_bag` = '0',
														`lost_new` = '$new',
														`lost_enchants` = '$enchants',
														`lost_comparison` = '$comparison'");
														echo mysql_error();
			$insert = mysql_insert_id();
			$bag[$insert] = $insert;	// Записываем в массив вещей в рюкзаку
			writecache('element_shoot_item_user_id'.$user_id, $bag);
			return $insert;
		}
	} else return false;
	}
	//create_item($user, 5, 1000, false, false);
	
	
	function delete_item($user, $item, $shoot, $header) {
		if ($item['lost_user'] == $user['lost_id'] AND $item['lost_bag'] == 0) {
			$genaration_params = item_generation_params($item['lost_strlen'], $item['lost_heatpoints'], $item['lost_protection'], $item['lost_comparison']);
			if ($item['lost_quality'] >= 4) 
				mysql_query("UPDATE `element_item` SET `lost_bag` = '2' WHERE `lost_id` = '$item[lost_id]' LIMIT 1");
			else mysql_query("DELETE FROM `element_item` WHERE `lost_id` = '$item[lost_id]' LIMIT 1");
			$summa_del = ((int)(($genaration_params['summa'] / 100) * 50));
			update_money_exp($user, 0, $summa_del, 0, 0);
			unset($shoot[$item['lost_id']]);
			writecache('element_shoot_item_user_id'.$user['lost_id'], $shoot);
			if ($header) header('Location: /bag');
		}
	}
	// element_item_id_
	
	// Функция снятия вещи
	function shoot_item($user, $item, $shoot, $wear, $header) {
		// Если вещь моя, и она одета, работаем
		if ($user['lost_id'] == $item['lost_user'] AND $item['lost_bag'] == 1) {
			unset($wear[$item['lost_mesto']]);				// Удаляем с массива надетых вещей	
			$shoot[$item['lost_id']] = $item['lost_id'];	// Записываем в массив вещей в рюкзаку
			
			$params = item_generation_params($item['lost_strlen'], $item['lost_heatpoints'], $item['lost_protection'], $item['lost_comparison']);
		
			if ($item['lost_enchants'] >= 0) {
				$it_pr_tp = item_params_type($item['lost_mesto']);
				$qwerty = item_enchants_quality($item['lost_enchants'], '');
				$user[$it_pr_tp[0]] = $user[$it_pr_tp[0]] - $qwerty['params'];
			}
		
			// Обновляем данные
			mysql_query("UPDATE `element_item` SET `lost_bag` = '0' WHERE `lost_id` = '$item[lost_id]' AND `lost_user` = '$user[lost_id]' LIMIT 1");

			$user = SetParams($user, -$params['strlen'], -$params['heatpoints'], -$params['protection'], true);
			
			// Записываем данные в кэш
			writecache('element_wear_item_user_id'.$user['lost_id'], $wear);
			writecache('element_shoot_item_user_id'.$user['lost_id'], $shoot);
			
			if (!empty($header)) {
				header('Location: '.$header);
			} else return array('wear' => $wear, 'shoot' => $shoot, 'user' => $user);
		}
	return false;
	}

	
	
	function wear_item($user, $item, $shoot, $wear, $header, $new) {
		if ($user['lost_id'] == $item['lost_user'] AND $item['lost_bag'] == 0) {
			
			// Если на мне уже одета такая вещь, снимаем
			if (!empty($wear[$item['lost_mesto']])) {
				$cache_item = cache_item($wear[$item['lost_mesto']]);
				$shoot_item = shoot_item($user, $cache_item, $shoot, $wear, '');
				$shoot = $shoot_item['shoot'];
				$wear = $shoot_item['wear'];
				$user = $shoot_item['user'];
			}
			
			$wear[$item['lost_mesto']] = $item['lost_id'];
			unset($shoot[$item['lost_id']]);
			$item['lost_bag'] = 1;
			if ($new) $item['lost_new'] = 1;
		
			$params = item_generation_params($item['lost_strlen'], $item['lost_heatpoints'], $item['lost_protection'],  $item['lost_comparison']);
		
			if ($item['lost_enchants'] >= 0) {
				$it_pr_tp = item_params_type($item['lost_mesto']);
				$qwerty = item_enchants_quality($item['lost_enchants'], '');
				$user[$it_pr_tp[0]] = $user[$it_pr_tp[0]] + $qwerty['params'];
			}
		
			// Обновляем данные
			mysql_query("UPDATE `element_item` SET `lost_bag` = '1', `lost_new` = '$item[lost_new]' WHERE `lost_id` = '$item[lost_id]' AND `lost_user` = '$user[lost_id]' LIMIT 1");
			SetParams($user, $params['strlen'], $params['heatpoints'], $params['protection'], false);
			
			// Записываем данные в кэш
			writecache('element_wear_item_user_id'.$user['lost_id'], $wear);
			writecache('element_shoot_item_user_id'.$user['lost_id'], $shoot);
			if (!empty($header)) header('Location: '.$header);
		}
	}
	
	function AuctionItemCancel($user_id, $bag, $item, $header) {
		if ($item['lost_user'] == $user_id AND $item['lost_bag'] == 3) {
			$item['lost_bag'] = 0;
			mysql_query("UPDATE `element_item` SET `lost_bag` = '0' WHERE `lost_id` = '$item[lost_id]' LIMIT 1");
			mysql_query("DELETE FROM `element_auction` WHERE `lost_id` = '$item[lost_id]' LIMIT 1");
			
			$bag[$item['lost_id']] = $item['lost_id'];
			
			writecache('element_shoot_item_user_id'.$user_id, $bag);
			header('Location: '.$header);
		}
	}
	
	function AuctionItemShop($user, $bag, $item, $header, $shop, $okay, $otmena) {
		// Если владелец вещи не я, и она на аукционе, идем дальше
		if ($item['lost_user'] != $user['lost_id'] AND $item['lost_bag'] == 3) {
			// Если данная вещь есть на аукционе, идем дальше
			$auc_item = mysql_fetch_array(mysql_query("SELECT * FROM `element_auction` WHERE `lost_id` = '$item[lost_id]' LIMIT 1"));
			if ($auc_item) {
			
				if ($shop) {
					if ($user['lost_money_gold'] < $auc_item['lost_gold']) $error = 'Вам нехватает <img src="/images/icons/gold.png">'.($auc_item['lost_gold'] - $user['lost_money_gold']).' золота<br/><a class="button w50 mt3" href="/payment">Купить золото</a>';
					if (count($bag) >= 20) $error = 'В рюкзаке нехватает места';
						
					if (!isset($error)) {
						$item['lost_user'] = $user['lost_id'];
						$item['lost_bag'] = 0;
						mysql_query("UPDATE `element_item` SET `lost_bag` = '0', `lost_user` = '$user[lost_id]' WHERE `lost_id` = '$item[lost_id]' LIMIT 1");
						mysql_query("DELETE FROM `element_auction` WHERE `lost_id` = '$item[lost_id]' LIMIT 1");
					
						$bag[$item['lost_id']] = $item['lost_id'];
						
							
							$profile_other = explode(' ', $user['lost_other']);		// Разбиваем на массив
							$profile_other[2] = $profile_other[2] + 1;				// Добавляем +1 письмо
							$user['lost_other'] = implode(' ', $profile_other);		// Возвращаем массив в строку
							
							$statistika_user = 'Время: '.rdate("Y год, d M H:i", time()).'<br/>
							Аукцион: покупка "<a href="/item?id='.$item['lost_id'].'">'.$item['lost_name'].'</a>" у [user]'.$auc_item['lost_user'].'[/user]  за <img src="/images/icons/gold.png">'.$auc_item['lost_gold'].' золота';
							update_money_exp($user, 0, 0, 0, -$auc_item['lost_gold']);	// Отнимаем мои деньги
							
							$lost_sub_text = 'Покупка "'.$item['lost_name'].'" за <img src="/images/icons/gold.png">'.$auc_item['lost_gold'].' золота';
							$lost_text = '<span class="admin">Покупка "'.$item['lost_name'].'" за <img src="/images/icons/gold.png">'.$auc_item['lost_gold'].' золота.<br/></span>';
							mysql_query("INSERT INTO `element_mail` SET `lost_out` = '0',
																		`lost_in` = '$user[lost_id]',
																		`lost_sub_text` = '$lost_sub_text',
																		`lost_text` = '$lost_text',
																		`lost_user_out` = '0',
																		`lost_user_in` = '$user[lost_id]',
																		`lost_time` = '".time()."',
																		`lost_system` = 'Аукцион',
																		`lost_new` = '1'");		
														
							$count_in = Cache_Count_Message($user['lost_id']);
							if (!empty($count_in['all'])) $count_in['all']++;
							if (!empty($count_in['in'])) $count_in['in']++;
							if (!empty($count_in['new'])) $count_in['new']++;
							writecache('element_count_message'.$user['lost_id'], $count_in);
					
							$prodav = cache_user($auc_item['lost_user']);
							
							$profile_other = explode(' ', $prodav['lost_other']);		// Разбиваем на массив
							$profile_other[2] = $profile_other[2] + 1;					// Добавляем +1 письмо
							$prodav['lost_other'] = implode(' ', $profile_other);		// Возвращаем массив в строку
							
							$statistika_user = 'Время: '.rdate("Y год, d M H:i", time()).'<br/>
							Аукцион: продажа "<a href="/item?id='.$item['lost_id'].'">'.$item['lost_name'].'</a>" персонажу [user]'.$user['lost_id'].'[/user]  за <img src="/images/icons/gold.png">'.$auc_item['lost_gold'].' золота';
							update_money_exp($prodav, 0, 0, 0, $auc_item['lost_gold']);	// Добавляем продавцу деньги
					
							$lost_sub_text = 'Продажа "'.$item['lost_name'].'" за <img src="/images/icons/gold.png">'.$auc_item['lost_gold'].' золота';
							$lost_text = '<span class="admin">Продажа "'.$item['lost_name'].'" за <img src="/images/icons/gold.png">'.$auc_item['lost_gold'].' золота.<br/></span>';
							mysql_query("INSERT INTO `element_mail` SET `lost_out` = '0',
																		`lost_in` = '$prodav[lost_id]',
																		`lost_sub_text` = '$lost_sub_text',
																		`lost_text` = '$lost_text',
																		`lost_user_out` = '0',
																		`lost_user_in` = '$prodav[lost_id]',
																		`lost_time` = '".time()."',
																		`lost_system` = 'Аукцион',
																		`lost_new` = '1'");		
														
							$count_in = Cache_Count_Message($prodav['lost_id']);
							if (!empty($count_in['all'])) $count_in['all']++;
							if (!empty($count_in['in'])) $count_in['in']++;
							if (!empty($count_in['new'])) $count_in['new']++;
							writecache('element_count_message'.$prodav['lost_id'], $count_in);
					
					
						writecache('element_shoot_item_user_id'.$user['lost_id'], $bag);
						header('Location: '.$header);
					
					} else echo '<div class="nfl p5 mt5 mb5 cntr small mlra red">'.$error.'</div>';
					
				} else {
					echo '<div class="nfl p5 mb5 cntr small yellow1 mt5 mlra">';
					echo 'Вы уверены что хотите купить "'.$item['lost_name'].'" за <img src="/images/icons/gold.png">'.$auc_item['lost_gold'].' золота?';
					echo '<div class="mt5">
						   <a class="button w40" href="'.$okay.'">Да</a>
						   <a class="button w40" href="'.$otmena.'">Нет</a>
					      </div>';
					echo '</div>';
				}
			
			}
		}
	}
	
?>