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

Размер файла: 21.83Kb
<?php

	function RandEquipMission($equip) {
			 if ($equip <= 1) if (rand(0,100) < 30) return 1; else return 0; 
		else if ($equip <= 2) {
			if (rand(0,100) < 30) return 2; else return rand(0,1);
		} else if ($equip <= 3) {
			$rand = rand(0,100);
				 if ($rand < 3) return 3;
			else if ($rand < 30) return 2;
			else if ($rand < 50) return 1;
			else return 0;
		} else if ($equip <= 4) {
			$rand = rand(0,100);
				 if ($rand < 1) return 4;
			else if ($rand < 4) return 3;
			else if ($rand < 30) return 2;
			else if ($rand < 50) return 1;
			else return 0;
		}  else if ($equip <= 5) {
			$rand = rand(0,200);
				 if ($rand == 0) return 5;
			else if ($rand <  3) return 4;
			else if ($rand < 20) return 3;
			else if ($rand < 90) return 3;
			else if ($rand < 160) return 2;
			else return 0;
		}
		
	}

	function KeyJournalMassiv($time) {
		$tt = explode(' ', microtime());
		$tt[1] = $tt[1] - $time;
		$tt1 = explode('.', $tt[0]);
		return $tt[1].$tt1[1];
	}
	
	function SetAbilitiesOgon($ogon, $race) {
			if ($ogon == 0) $return = array('add_uron' => 10, 'active' => 10, 'refresh' => 25);
	   else if ($ogon == 1) $return = array('add_uron' => 15, 'active' => 12, 'refresh' => 23);
	   else if ($ogon == 2) $return = array('add_uron' => 25, 'active' => 14, 'refresh' => 21);
	   else if ($ogon == 3) $return = array('add_uron' => 40, 'active' => 16, 'refresh' => 19);
	   else if ($ogon == 4) $return = array('add_uron' => 60, 'active' => 18, 'refresh' => 17);
	   else if ($ogon == 5) $return = array('add_uron' => 85, 'active' => 20, 'refresh' => 15);
	   if ($race == 1) $return['add_uron'] = $return['add_uron'] + 10;
	   return $return;
	}
	
	function SetAbilitiesVoda($voda, $race) {
			if ($voda == 0) $return = array('add_uron' => 60, 'active' => 10, 'refresh' => 25);
	   else if ($voda == 1) $return = array('add_uron' => 60, 'active' => 12, 'refresh' => 23);
	   else if ($voda == 2) $return = array('add_uron' => 60, 'active' => 14, 'refresh' => 21);
	   else if ($voda == 3) $return = array('add_uron' => 60, 'active' => 16, 'refresh' => 19);
	   else if ($voda == 4) $return = array('add_uron' => 60, 'active' => 18, 'refresh' => 17);
	   else if ($voda == 5) $return = array('add_uron' => 60, 'active' => 20, 'refresh' => 15);
	   if ($race == 2) $return['add_uron'] = $return['add_uron'] + 10;
	   return $return;
	}

	function SetAbilitiesVosdyh($vosdyh, $race) {
			if ($vosdyh == 0) $return = array('chanse' =>  3, 'add_hp' =>  5, 'refresh' => 25);
	   else if ($vosdyh == 1) $return = array('chanse' =>  4, 'add_hp' =>  7, 'refresh' => 23);
	   else if ($vosdyh == 2) $return = array('chanse' =>  5, 'add_hp' =>  9, 'refresh' => 21);
	   else if ($vosdyh == 3) $return = array('chanse' =>  7, 'add_hp' => 11, 'refresh' => 19);
	   else if ($vosdyh == 4) $return = array('chanse' => 11, 'add_hp' => 13, 'refresh' => 17);
	   else if ($vosdyh == 5) $return = array('chanse' => 15, 'add_hp' => 20, 'refresh' => 15);
	   if ($race == 3) $return['add_hp'] = $return['add_hp'] + 10;
	   return $return;
	}
	
	function SetAbilitiesZemlya($zemlya, $race) {
			if ($zemlya == 0) $return = array('minus_uron' =>  3, 'active' => 10, 'refresh' => 25);
	   else if ($zemlya == 1) $return = array('minus_uron' =>  8, 'active' => 12, 'refresh' => 23);
	   else if ($zemlya == 2) $return = array('minus_uron' => 14, 'active' => 14, 'refresh' => 21);
	   else if ($zemlya == 3) $return = array('minus_uron' => 25, 'active' => 16, 'refresh' => 19);
	   else if ($zemlya == 4) $return = array('minus_uron' => 40, 'active' => 18, 'refresh' => 17);
	   else if ($zemlya == 5) $return = array('minus_uron' => 60, 'active' => 20, 'refresh' => 15);
	   if ($race == 4) $return['minus_uron'] = $return['minus_uron'] + 10;
	   return $return;
	}
	
	function ResetAbilitiesUser($user) {
		deletecache('element_user_id'.$user.'_abilities_vozdyh');
		deletecache('element_user_id'.$user.'_abilities_zemlya');
		deletecache('element_user_id'.$user.'_abilities_ogon');
		deletecache('element_user_id'.$user.'_abilities_voda');
	}
	
	// Умение Ловушка ветра
	function AbilitiesVozdyh($quality, $race, $activate, $user_id) {
		$cache = readcache('element_user_id'.$user_id.'_abilities_vozdyh');
		$abilit = SetAbilitiesVosdyh($quality, $race);
		$time = time();
		
		if ($activate AND $cache <= $time) {
			$cache = $time + $abilit['refresh'];
			writecache('element_user_id'.$user_id.'_abilities_vozdyh', $cache);
			if (rand(0, 100) <= $abilit['chanse']) {
				return array('active' => true, 'add_hp' => $abilit['add_hp'], 'seconds' => ($cache - $time));
			} else return array('active' => true, 'add_hp' => 0, 'seconds' => ($cache - $time));
		
		} else {
			if ($cache >= $time) { $seconds = $cache - $time; $act = true; } else { $seconds = 0; $act = false; }
			return array('active' => $act, 'add_hp' => 0, 'seconds' => $seconds);
		}
	}
	
	// Умение Земляной щит
	function AbilitiesZemlya($quality, $race, $activate, $user_id) {
		$cache = readcache('element_user_id'.$user_id.'_abilities_zemlya');
		$abilit = SetAbilitiesZemlya($quality, $race);
		$update = false;
		$time = time();
		$add_time = $abilit['active'] + $abilit['refresh'];
		
			// Если есть кэш с умением, продолжаем, иначе создаем
			if ($cache) {
				
				// Если нужно активировать умение, добавляем время
				if ($activate) {
					
					// Если умение не активно, активируем
					if ($cache <= $time) { 
						$cache = $time + $add_time;
						$update = true;
					}
				}	
				
			} else {
				$cache = $time;
				if ($activate) $cache = $time + $add_time;
				$update = true;
			}
			
			if ($update) writecache('element_user_id'.$user_id.'_abilities_zemlya', $cache);
			
			if ($cache > $time) {
				$other_time = $cache - $time;		// Отнимаем время восстановления
					
					if ($other_time >= ($add_time - $abilit['active'])) {
						return array('add_procent' => $abilit['minus_uron'], 'activate' => true, 'seconds' => ($other_time - ($add_time - $abilit['active'])));
					} else return array('add_procent' => 0, 'activate' => true, 'seconds' => $other_time);
					
			} else return array('add_procent' => 0, 'activate' => false);
	}
	
	// Умение Огненная Сила
	function AbilitiesOgon($quality, $race, $activate, $user_id) {
		$cache = readcache('element_user_id'.$user_id.'_abilities_ogon');
		$abilit = SetAbilitiesOgon($quality, $race);
		$update = false;
		$time = time();
		$add_time = $abilit['active'] + $abilit['refresh'];
		
			// Если есть кэш с умением, продолжаем, иначе создаем
			if ($cache) {
				
				// Если нужно активировать умение, добавляем время
				if ($activate) {
					
					// Если умение не активно, активируем
					if ($cache <= $time) { 
						$cache = $time + $add_time;
						$update = true;
					}
				}	
				
			} else {
				$cache = $time;
				if ($activate) $cache = $time + $add_time;
				$update = true;
			}
			
			if ($update) writecache('element_user_id'.$user_id.'_abilities_ogon', $cache);
			
			if ($cache > $time) {
				$other_time = $cache - $time;		// Отнимаем время восстановления
					
					if ($other_time >= ($add_time - $abilit['active'])) {
						return array('add_procent' => $abilit['add_uron'], 'activate' => true, 'seconds' => ($other_time - ($add_time - $abilit['active'])));
					} else return array('add_procent' => 0, 'activate' => true, 'seconds' => $other_time);
					
			} else return array('add_procent' => 0, 'activate' => false);
	}

	// Умение Водяной Крит
	function AbilitiesVoda($quality, $race, $activate, $user_id) {
		$cache = readcache('element_user_id'.$user_id.'_abilities_voda');
		$abilit = SetAbilitiesVoda($quality, $race);
		$update = false;
		$time = time();
		$add_time = $abilit['active'] + $abilit['refresh'];
		
			// Если есть кэш с умением, продолжаем, иначе создаем
			if ($cache) {
				
				// Если нужно активировать умение, добавляем время
				if ($activate) {
					
					// Если умение не активно, активируем
					if ($cache <= $time) { 
						$cache = $time + $add_time;
						$update = true;
					}
				}	
				
			} else {
				$cache = $time;
				if ($activate) $cache = $time + $add_time;
				$update = true;
			}
			
			if ($update) writecache('element_user_id'.$user_id.'_abilities_voda', $cache);
			
			if ($cache > $time) {
				$other_time = $cache - $time;		// Отнимаем время восстановления
					
					if ($other_time >= ($add_time - $abilit['active'])) {
						return array('add_procent' => $abilit['add_uron'], 'activate' => true, 'seconds' => ($other_time - ($add_time - $abilit['active'])));
					} else return array('add_procent' => 0, 'activate' => true, 'seconds' => $other_time);
					
			} else return array('add_procent' => 0, 'activate' => false);
	}
	
	function EchoAbiliteBattle($ogon, $voda, $vozdyh, $zemlya, $target, $width_class, $width_image, $training, $url) {
		echo '<div class="nfl p5 mb5 cntr small mlra">';
			
			// Тергейт. Цель
			if ($target) {
			echo '<span class="inbl '.$width_class.' mt5 va_t">
				  <a class="atask" href="'.$url.'?go=attaka&target&action='.rand(1000000, 9999999).'">
				  <span class="inbl prel">
				  <img width="'.$width_image.'" height="'.$width_image.'" src="/images/equipment/epic/weapon.jpg" alt=""/>
				  </span><br/>
				  <span class="small lngreen mt3">Цель</span>
				  </a>
				  </span>';
			}
			
			// Бить врага
			echo '<span class="inbl '.$width_class.' mt5 va_t">
				  <a class="atask" href="'.$url.'?go=attaka&action='.rand(1000000, 9999999).'">
				  <span class="inbl prel">
				  '.(($training == 1) ? '<img width="17" height="25" class="g-arrow" src="/images/green-arrow.png"/>' : '').'
				  <img width="'.$width_image.'" height="'.$width_image.'" src="/images/equipment/epic/weapon.jpg" alt=""/>
				  </span><br/>
				  <span class="small lngreen mt3">Бить</span>
				  </a>
				  </span>';
				
			// Огненная сила
			$add_uron = ($ogon['add_procent'] > 0) ? true : false;
			echo '<span class="inbl '.$width_class.' mt5 va_t">
				  <a class="atask" href="'.$url.'?go=attaka&id=1&action='.rand(1000000, 9999999).'">
				  <span class="inbl prel">
				  '.((!$ogon['activate'] AND !$add_uron AND $training == 2) ? '<img width="17" height="25" class="g-arrow" src="/images/green-arrow.png"/>' : '').'
				  <img width="'.$width_image.'" height="'.$width_image.'" src="/images/fire.png" alt=""/>
				  </span><br/>
				  '.(($ogon['activate']) ? (($add_uron) ? '<span class="small lngreen mt3">'.$ogon['seconds'].' с.</span>' : '<span class="small ccc mt3">'.$ogon['seconds'].' с.</span>') : '<span class="small lngreen mt3">Гот.</span>').'
				  </a>
				  </span>';
			
			// Водяной крит
			$add_uron = ($voda['add_procent'] > 0) ? true : false;
			echo '<span class="inbl '.$width_class.' mt5 va_t">
				  <a class="atask" href="'.$url.'?go=attaka&id=2&action='.rand(1000000, 9999999).'">
				  <span class="inbl prel">
				  '.((!$voda['activate'] AND !$add_uron AND $training == 3) ? '<img width="17" height="25" class="g-arrow" src="/images/green-arrow.png"/>' : '').'
				  <img width="'.$width_image.'" height="'.$width_image.'" src="/images/water.png" alt=""/>
				  </span><br/>
				  '.(($voda['activate']) ? (($add_uron) ? '<span class="small lngreen mt3">'.$voda['seconds'].' с.</span>' : '<span class="small ccc mt3">'.$voda['seconds'].' с.</span>') : '<span class="small lngreen mt3">Гот.</span>').'
				  </a>
				  </span>';
		
			// Ловушка Ветра
			echo '<span class="inbl '.$width_class.' mt5 va_t">
				  <a class="atask" href="'.$url.'?go=attaka&id=3&action='.rand(1000000, 9999999).'">
				  <span class="inbl prel">
				  '.((!$vozdyh['active'] AND $training == 4) ? '<img width="17" height="25" class="g-arrow" src="/images/green-arrow.png"/>' : '').'
				  <img width="'.$width_image.'" height="'.$width_image.'" src="/images/air.png" alt=""/>
				  </span><br/>
				  '.(($vozdyh['active']) ? '<span class="small ccc mt3">'.$vozdyh['seconds'].' с.</span>' : '<span class="small lngreen mt3">Гот.</span>').'
				  </a>
				  </span>';
		
			// Земляной щит
			$add_uron = ($zemlya['add_procent'] > 0) ? true : false;
			echo '<span class="inbl '.$width_class.' mt5 va_t">
				  <a class="atask" href="'.$url.'?go=attaka&id=4&action='.rand(1000000, 9999999).'">
				  <span class="inbl prel">
				  '.((!$zemlya['activate'] AND !$add_uron AND $training == 5) ? '<img width="17" height="25" class="g-arrow" src="/images/green-arrow.png"/>' : '').'
				  <img width="'.$width_image.'" height="'.$width_image.'" src="/images/ground.png" alt=""/>
				  </span><br/>
				  '.(($zemlya['activate']) ? (($add_uron) ? '<span class="small lngreen mt3">'.$zemlya['seconds'].' с.</span>' : '<span class="small ccc mt3">'.$zemlya['seconds'].' с.</span>') : '<span class="small lngreen mt3">Гот.</span>').'
				  </a>
				  </span>';
		
		echo '</div>';
	}
	 //EchoAbiliteBattle(AbilitiesOgon(1, $user['lost_race'], true, $user['lost_id']), AbilitiesVoda(1, $user['lost_race'], true, $user['lost_id']), AbilitiesVozdyh(1, $user['lost_race'], true, $user['lost_id']), AbilitiesZemlya(5, 4, true, $user['lost_id']), true, 'w15', 35, 3, '/mission');
	
	// Функция выводит мои и врага параметры в бою
	function EchoTableUsersBattle($my_info, $bot_info) {
		echo '<table><td class="mr5">'.(($my_info['user_race'] > 0) ? '<img width="50" height="50" src="/images/user_ava_'.$my_info['user_race'].'.png">' : '<img width="50" height="50" src="/images/icons/empty.png">').'</td>';
		echo '<td class="small w90 white ml5" valign="top">';
		echo '<span class="bl ml5 mb5 prg-bar"><span class="bl fl prg-blue" style="width:'.ceil(($my_info['user_hp'] / $my_info['user_other_hp']) * 100).'%">&nbsp;</span>';
		echo '<span class="bl fl prg-red" style="width:'.(($my_info['user_uron'] > 0) ? (int)(($my_info['user_uron'] / $my_info['user_other_hp']) * 100) : 0).'%">&nbsp;</span></span>';
		echo '<div class="fr bold">'.(($my_info['user_add_hp'] > 0) ? ' <span class="lngreen">+'.$my_info['user_add_hp'].'</span> ' : '').''.(($my_info['user_uron'] > 0) ? ' <span class="red">-'.$my_info['user_uron'].'</span>' : '').'</div>';
		echo '<span class="ml5 yellow1 bold">'.ikonka_user($my_info['user_race'], 'online').' '.$my_info['user_name'].', <img src="/images/icons/heatpoints.png"> '.$my_info['user_hp'].'</span>';
		echo '</td></table>';
		
		echo '<table><td class="mr5">'.(($bot_info['user_race'] > 0) ? '<img width="50" height="50" src="/images/user_ava_'.$bot_info['user_race'].'.png">' : '<img width="50" height="50" src="/images/icons/empty.png">').'</td>';
		echo '<td class="small w90 ml5" valign="top">';
		echo '<span class="bl ml5 mb5 prg-bar"><span class="bl fl prg-blue" style="width:'.ceil(($bot_info['user_hp'] / $bot_info['user_other_hp']) * 100).'%">&nbsp;</span>';
		echo '<span class="bl fl prg-red" style="width:'.(($bot_info['user_uron'] > 0) ? (int)(($bot_info['user_uron'] / $bot_info['user_other_hp']) * 100) : 0).'%">&nbsp;</span></span>';
		echo '<div class="fr bold">'.(($bot_info['user_add_hp'] > 0) ? ' <span class="lngreen">+'.$bot_info['user_uron'].'</span> ' : '').''.(($bot_info['user_uron'] > 0) ? ' <span class="red">-'.$bot_info['user_uron'].'</span>' : '').'</div>';
		echo '<span class="ml5 yellow1 bold">'.(($bot_info['user_race'] > 0) ? ikonka_user($bot_info['user_race'], 'online') : '<img src="/images/icons/arena.gif">').' '.$bot_info['user_name'].', <img src="/images/icons/heatpoints.png"> '.$bot_info['user_hp'].'</span>';
		echo '</td></table>';
	}
	
	
	
	// Генерируем максимальное здоровье в бою
	function GenerationMaxHeatpoints($heatpoints) {
		if ($heatpoints > 0) $heatpoints = $heatpoints * 2; else $heatpoints = 50;
		return $heatpoints;
	}
	
	function GenerationProtection($protection) {
		// Если защита больше 5000 (70%) то за каждые 500 защиты сверх 5000 добавляем 1% 
		if ($protection > 5000) {
			$add_pr = (int)(($protection - 5000) / 500);
			if ($add_pr > 0) $add_pr = $add_pr * 1; else $add_pr = 0;
			$procent = round((5000 / 7143) * 100, 2);
			$procent = $procent + $add_pr;
		} else $procent = round(($protection / 7143) * 100, 2);
		return $procent;
	}
	
	// Генерируем удар, в зависимости от силы, умений, защиты
	function GenerationUron($str, $time, $um_ogon, $um_voda, $um_zeml, $protection) {
		
		// Вычисляем время последнего удара, насколько его нужно умножить. Если не указано, бьем максимально
		if (!$time) { $x_time = rand(4,5).'.'.rand(10,99).''; } else {
			$time = explode(' ', $time);								// Время посл. удара, с учетом миллисекунд
			$time_1 = $time[1] + $time[0];								// Время посл. удара, с учетом миллисекунд
			$time_2 = explode(' ', microtime());						// Разбиваем текущее время на сек. и мс.
			$x_time = round(($time_2[1] + $time_2[0]) - $time_1, 2);	// Считаем, насколько умножить удар, в зависимости от посл.
			if ($x_time > 5) $x_time = '5.'.rand(10,50);
		}
		
		// Считаем силу удара
		$uron = (int)(($str / 15) * $x_time);
		if ($um_ogon > 0)	 $uron = (int)(($uron / 100) * (100 + $um_ogon));
		if ($um_voda > 0) 	 $uron = (int)(($uron / 100) * (100 + $um_voda));
		if ($um_zeml > 0)	 $uron = (int)(($uron / 100) * (100 - $um_zeml));
		if ($protection > 0) $uron = (int)(($uron / 100) * (100 - $protection));
		if ($uron <= 0) $uron = 1;
		
		return $uron;
	}

	
	function Protection($protection, $max_protection) {
		$procent = round(($protection / $max_protection) * 100, 2);
		return ($procent > 50) ? 50 : $procent;
	}

	function GenerateUron($strlen,$last_time,$protection) {
		$last_time = explode(' ', $last_time);					// Время последнего удара, с учетом миллисекунд
		$last_time_1 = $last_time[1] + $last_time[0];			// Текущие секунды + миллисекунды посл. удара
		$last_time_2 = explode(" ", microtime());				// Разбиваем текущее время на сек. и мс.
		$last_time_3 = round(($last_time_2[1] + $last_time_2[0]) - $last_time_1,2);	// Считаем время от посл. удара к текущему
		if ($last_time_3 > 5) $last_time_3 = '5.'.rand(10,50);

		$uron = (($strlen / 15) * $last_time_3);
		$minus = ($uron / 100) * $protection;
		$uron = $uron - $minus;
		return ($uron <= 0) ? 1 : ceil($uron);
	}
	
	function abilities_race_ogon($uron, $time, $procent, $time_activ, $time_refresh, $add_1) {
		$active = false; $vosst = false;
		if ($time >= time()) {
			$other_time_activate = $time - $time_refresh; 		// Вычисляем, когда закончиться активность 
				if (time() < $other_time_activate) {			// Прибавляем процент удара, если активно
					if ($add_1 == 1) $add = ceil($uron * ('1.'.$procent)); else $add = $uron;	
					$active = $other_time_activate - time();	// Скоролько секунд ещё будет активно 
				} else { 
					$add = $uron;
					$vosst = $time - time();
				}
			return array($add, $active, $vosst);
		} return array($uron, $active, $vosst);
	}
	
	function abilities_race_voda($uron, $time, $time_activ, $time_refresh, $add_1) {
		$active = false; $vosst = false;
		if ($time >= time()) {
			$other_time_activate = $time - $time_refresh; 		// Вычисляем, когда закончиться активность 
				if (time() < $other_time_activate) {			// Прибавляем процент удара, если активно
					if ($add_1 == 1) $add = ceil($uron * '1.60'); else $add = $uron;	
					$active = $other_time_activate - time();	// Скоролько секунд ещё будет активно 
				} else { 
					$add = $uron;
					$vosst = $time - time();
				}
			return array($add, $active, $vosst);
		} return array($uron, $active, $vosst);
	}
	
	function abilities_race_vozduh($procent, $bot_hp, $bot_hp_other, $user_hp, $user_hp_other) {
		$rand = rand(1,100);
		if ($procent >= $rand) {
			$proc_hp = (int)(($bot_hp_other / 100) * $procent);
			$proc_hp = ($proc_hp <= 0) ? 1 : $proc_hp;
			
			$bot_hp = $bot_hp - $proc_hp;
			$bot_hp = ($bot_hp <= 0) ? 0 : $bot_hp;
			
			$user_hp = $user_hp + $proc_hp;
			
			if ($user_hp > $user_hp_other) {
				$proc_hp = $user_hp - $user_hp_other;
				$user_hp = $user_hp_other;
			}
			
			return array(1, $bot_hp, $user_hp, $proc_hp);
		} else array(0, $bot_hp, $user_hp, 0);
	}
	
	
	function abilities_race_zemlya($uron, $time, $procent, $time_activ, $time_refresh, $add_1) {
		$active = false; $vosst = false;
		if ($time >= time()) {
			$other_time_activate = $time - $time_refresh; 		// Вычисляем, когда закончиться активность 
	
				if (time() < $other_time_activate) {			// Прибавляем процент удара, если активно
					if ($add_1 == 1) $add = ceil($uron * ('0.'.(100 - $procent))); else $add = $uron;	
					$active = $other_time_activate - time();	// Скоролько секунд ещё будет активно 
				} else { 
					$add = $uron;
					$vosst = $time - time();
				}
			return array($add, $active, $vosst);
		} return array($uron, $active, $vosst);
	}
	
?>