diff --git a/server/includes/class.battle.php b/server/includes/class.battle.php index d556aa0..ba7a871 100644 --- a/server/includes/class.battle.php +++ b/server/includes/class.battle.php @@ -120,7 +120,7 @@ public function start_battle() { $r .= 'Вы стали намного опытнее для текущего уровня и поэтому получаете меньше опыта и золота! Нужно посетить Квартал Гильдий и повысить уровень!#'; } - $this->clear_effects(); + $user['class']['effect']->clear(); $user['battlelog'] = $r; } @@ -131,10 +131,10 @@ private function player_battle_round() { $r = ''; if (($user['char_life_cur'] > 0) && ($user['enemy_life_cur'] > 0)) { - if ($this->has_effect(Magic::PLAYER_EFFECT_REGEN)) + if ($user['class']['effect']->has(Magic::PLAYER_EFFECT_REGEN)) $r .= $this->effect_regen(); if (rand(1, $user['enemy_armor']) <= rand(1, $user['char_armor'])) { - if ($this->has_effect(Magic::PLAYER_EFFECT_BLESS)) + if ($user['class']['effect']->has(Magic::PLAYER_EFFECT_BLESS)) $d = $user['char_damage_max']; else $d = rand($user['char_damage_min'], $user['char_damage_max']); @@ -143,7 +143,7 @@ private function player_battle_round() { if ($d <= 0) { $r .= 'Вы не можете пробить защиту '.$user['enemy_name'].'.#'; } else { - if ($this->has_effect(Magic::PLAYER_EFFECT_LEECH)) + if ($user['class']['effect']->has(Magic::PLAYER_EFFECT_LEECH)) if ((rand(1, 2) == 1) && ($user['char_life_cur'] < $user['char_life_max']) && ($user['enemy_life_cur'] > 0)) $r .= $this->effect_leech(); if (rand(1, 100) <= $user['skill_bewil']) { @@ -268,26 +268,26 @@ private function str_line() { return '--------------------------------------------------------#'; } - private function get_real_damage($atk_damage, $def_armor, $atk_level, $def_level) { + private function get_real_damage(int $atk_damage, int $def_armor, int $atk_level, int $def_level) { return $atk_damage - round($atk_damage * $def_armor / 100); } - private function get_glancing_blow_damage($damage){ + private function get_glancing_blow_damage(int $damage){ $r = round($damage / rand(2, 3)); if ($r < 1) $r = 1; return $r; } - private function get_crushing_blow_damage($damage) { + private function get_crushing_blow_damage(int $damage) { return $damage * rand(3, 5); } - private function get_bewildering_strike_damage($damage) { + private function get_bewildering_strike_damage(int $damage) { return rand(round($damage * 0.75), round($damage * 1.2)); } - private function get_value($value) { + private function get_value(int $value) { global $user; if ($user['enemy_level'] < $user['char_level'] - 1) { @@ -352,18 +352,6 @@ private function effect_leech() { return $r; } - private function clear_effects() { - global $user; - $user['char_effect'] = 0; - $user['char_effects'] = "[]"; - } - - private function has_effect(int $effect_ident) { - global $user; - $strbox = new StringBox($user['char_effects']); - return $strbox->has($effect_ident); - } - } ?> \ No newline at end of file diff --git a/server/includes/class.item.php b/server/includes/class.item.php index 70b7f68..8652cb5 100644 --- a/server/includes/class.item.php +++ b/server/includes/class.item.php @@ -39,7 +39,7 @@ public function __construct() { } - public function get_price($type, $price, $count) { + public function get_price(int $type, int $price, int $count) { global $user; $r = 0; switch($type) { @@ -87,18 +87,12 @@ public function pickup_all() { return $r; } - public function get_slot_ident($item_slot) { + public function get_slot_ident(int $item_slot) { global $user; return $user['item_slot_'.strval($item_slot)]; } - public function has_item(int $item_ident) { - global $user; - $strbox = new StringBox($user['char_inventory']); - return $strbox->has($item_ident); - } - - public function gold_trade($type) { + public function gold_trade(int $type) { global $user, $tb_item, $connection; $query = "SELECT * FROM ".$tb_item." WHERE item_type=".$type; @@ -125,7 +119,7 @@ public function gold_trade($type) { return $gold; } - public function buy_empty_elixir($count = 1) { + public function buy_empty_elixir(int $count = 1) { global $user; if ($user['char_gold'] < 100) die('{"info":"Нужно не менее 100 золотых монет!"}'); $this->add(self::ELIXIR_EMPTY, $count); @@ -162,7 +156,7 @@ public function make_elixir($elix_id, $t, $ing1_name, $ing1_id, $ing1_amount, $i } else die('{"info":"Нужен Пустой Флакон!"}'); } - public function item_info($item_ident) { + public function item_info(int $item_ident) { global $user, $tb_item, $connection; if ($user['char_life_cur'] <= 0) die('{"error":"Вам сначала нужно вернуться к жизни!"}'); @@ -252,7 +246,7 @@ public function item_info($item_ident) { die('{"item":"'.$item['item_name'].'\nУровень предмета: '.$this->get_region_item_level($item['item_level']).'\n'.$ef.'"}'); } - private function item_values($item_ident) { + private function item_values(int $item_ident) { global $user, $tb_item, $connection; $query = "SELECT * FROM ".$tb_item." WHERE item_ident=".$item_ident; $result = mysqli_query($connection, $query) @@ -271,18 +265,14 @@ private function item_values($item_ident) { } } - public function add_item_to_shop($item_slot, $item_ident) { + public function add_item_to_shop(int $item_slot, int $item_ident) { global $user; $user['item_slot_'.strval($item_slot)] = $item_ident; $user['item_slot_'.strval($item_slot).'_values'] = $this->item_values($item_ident); User::update('item_slot_'.strval($item_slot).'='.$user['item_slot_'.strval($item_slot)]); } - private function add_effect(int $effect_ident) { - - } - - public function use_item($item_ident) { + public function use_item(int $item_ident) { global $user, $tb_item, $connection; if ($user['char_life_cur'] <= 0) die('{"error":"Вам сначала нужно вернуться к жизни!"}'); @@ -327,9 +317,8 @@ public function use_item($item_ident) { break; case self::CAT_ELIXIR_TROLL: $this->modify($item_ident, -1); - $user['char_effect'] = Magic::PLAYER_EFFECT_REGEN; - User::update("char_effect=".$user['char_effect']); - $result = ',"char_effect":"'.$user['char_effect'].'"'; + $user['class']['effect']->add(Magic::PLAYER_EFFECT_REGEN); + $result = ',"char_effects":'.json_encode($user['char_effects'], JSON_UNESCAPED_UNICODE); break; case self::CAT_SCROLL_TP: $result = $user['class']['magic']->use_scroll_tp($item_ident); @@ -354,7 +343,7 @@ public function use_item($item_ident) { return $result; } - public function inv_item_list($type) { + public function inv_item_list(int $type) { global $user, $tb_item, $connection; $query = "SELECT * FROM ".$tb_item." WHERE item_type=".$type; @@ -402,14 +391,14 @@ public function inv_item_list($type) { return $r; } - private function get_region_item_level($item_level) { + private function get_region_item_level(int $item_level) { $result = 1; if ($item_level > 1) $result = ($item_level - 1) * 12; return $result; } - public function save_loot_slot($item_ident, $item_name, $item_type, $item_slot = 1) { + public function save_loot_slot(int $item_ident, $item_name, int $item_type, int $item_slot = 1) { global $user; $user['loot_slot_'.strval($item_slot)] = $item_ident; @@ -420,7 +409,7 @@ public function save_loot_slot($item_ident, $item_name, $item_type, $item_slot = User::update("loot_slot_".strval($item_slot)."=".$user['loot_slot_'.strval($item_slot)].",loot_slot_".strval($item_slot)."_type=".$user['loot_slot_'.strval($item_slot).'_type'].",loot_slot_".strval($item_slot)."_name='".$user['loot_slot_'.strval($item_slot).'_name']."'"); } - private function gen_random_loot($loot_type_array, $loot_level) { + private function gen_random_loot($loot_type_array, int $loot_level) { global $user, $tb_item, $connection; $loot_type = $loot_type_array[array_rand($loot_type_array)]; @@ -538,7 +527,7 @@ public function gen_loot() { } } - public function equip_item($item_ident, $item_amount = 1) { + public function equip_item(int $item_ident, int $item_amount = 1) { global $user, $tb_item, $connection; $query = "SELECT * FROM ".$tb_item." WHERE item_ident=".$item_ident; $result = mysqli_query($connection, $query) @@ -626,13 +615,19 @@ public function pickup_equip_item() { return $r; } + public function has_item(int $item_ident) { + global $user; + $strbox = new StringBox($user['char_inventory']); + return $strbox->has($item_ident); + } + private function amount(int $item_ident) { global $user; $strbox = new StringBox($user['char_inventory']); return $strbox->amount($item_ident); } - public function modify(int $item_ident, int $value) { + public function modify(int $item_ident, int $item_count) { global $user; $strbox = new StringBox($user['char_inventory']); $strbox->modify($item_ident, $item_count); diff --git a/server/includes/class.magic.php b/server/includes/class.magic.php index d7d5610..d4f7221 100644 --- a/server/includes/class.magic.php +++ b/server/includes/class.magic.php @@ -15,14 +15,6 @@ public function __construct() { } - private function add_effect(int $effect_ident) { - global $user; - $strbox = new StringBox($user['char_effects']); - $strbox->add($effect_ident); - $user['char_effects'] = $strbox->get_string(); - User::update("char_effects=".$user['char_effects']); - } - private function need_mana($mana) { die('{"info":"Вы пытаетесь произнести заклинание, но чувствуете, что магических сил недостаточно. Нужно '.strval($mana).' маны!"}'); } @@ -46,8 +38,8 @@ public function use_scroll_leech($item_ident) { if ($user['char_mana_cur'] >= $mana) { $user['class']['item']->modify($item_ident, -1); $user['char_mana_cur'] -= $mana; - $this->add_effect($effect_ident); - $result = ',"char_effects":"'.$user['char_effects'].'","char_mana_cur":"'.$user['char_mana_cur'].'","char_mana_max":"'.$user['char_mana_max'].'"'; + $user['class']['effect']->add($effect_ident); + $result = ',"char_effects":'.json_encode($user['char_effects'], JSON_UNESCAPED_UNICODE).',"char_mana_cur":"'.$user['char_mana_cur'].'","char_mana_max":"'.$user['char_mana_max'].'"'; return $result; } else $this->need_mana($mana); } @@ -59,8 +51,8 @@ public function use_scroll_bless($item_ident) { if ($user['char_mana_cur'] >= $mana) { $user['class']['item']->modify($item_ident, -1); $user['char_mana_cur'] -= $mana; - $this->add_effect($effect_ident); - $result = ',"char_effects":"'.$user['char_effects'].'","char_mana_cur":"'.$user['char_mana_cur'].'","char_mana_max":"'.$user['char_mana_max'].'"'; + $user['class']['effect']->add($effect_ident); + $result = ',"char_effects":'.json_encode($user['char_effects'], JSON_UNESCAPED_UNICODE).',"char_mana_cur":"'.$user['char_mana_cur'].'","char_mana_max":"'.$user['char_mana_max'].'"'; return $result; } else $this->need_mana($mana); } @@ -72,8 +64,8 @@ public function use_scroll_heal($item_ident) { if ($user['char_mana_cur'] >= $mana) { $user['class']['item']->modify($item_ident, -1); $user['char_mana_cur'] -= $mana; - $this->add_effect($effect_ident); - $result = ',"char_effects":"'.$user['char_effects'].'","char_mana_cur":"'.$user['char_mana_cur'].'","char_mana_max":"'.$user['char_mana_max'].'"'; + $user['class']['effect']->add($effect_ident); + $result = ',"char_effects":'.json_encode($user['char_effects'], JSON_UNESCAPED_UNICODE).',"char_mana_cur":"'.$user['char_mana_cur'].'","char_mana_max":"'.$user['char_mana_max'].'"'; return $result; } else $this->need_mana($mana); } diff --git a/server/includes/class.stringbox.php b/server/includes/class.stringbox.php index 8984489..4139d46 100644 --- a/server/includes/class.stringbox.php +++ b/server/includes/class.stringbox.php @@ -3,10 +3,12 @@ class StringBox { protected $values = array(); + protected $str = ""; protected $num = 0; public function __construct($str) { $this->values = json_decode($str, true); + $this->str = $str; $this->num = count($this->values); } @@ -24,7 +26,7 @@ public function amount(int $item_ident) { $result = 0; for($i = 0; $i < $this->num; $i++) { $item = $this->values[$i]; - if (intval($item['id']) == $item_ident) { + if (strval($item['id']) == strval($item_ident)) { $result = intval($item['count']); break; } @@ -35,7 +37,7 @@ public function amount(int $item_ident) { public function modify(int $item_ident, int $item_count = 1) { for($i = 0; $i < $this->num; $i++) { $item = $this->values[$i]; - if (intval($item['id']) == $item_ident) { + if (strval($item['id']) == strval($item_ident)) { $count = intval($item['count']); $count += $item_count; if ($count <= 0) { @@ -51,7 +53,7 @@ public function modify(int $item_ident, int $item_count = 1) { } public function has(int $item_ident) { - $pos = strripos($this->values, '"id":"'.strval($region_ident).'"'); + $pos = strripos($this->str, '"id":"'.strval($item_ident).'"'); if ($pos === false) { return false; } else { diff --git a/server/locations/battle.php b/server/locations/battle.php index 83720bd..7f1882e 100644 --- a/server/locations/battle.php +++ b/server/locations/battle.php @@ -46,7 +46,7 @@ $user['frame'] = 'get_random_place'; Location::addlink('Осмотреть локацию', 'index.php?action=random_place', 1); } - User::update("enemy_name='',enemy_image='',char_life_cur=".$user['char_life_cur'].",char_mana_cur=".$user['char_mana_cur'].",char_exp=".$user['char_exp'].",char_gold=".$user['char_gold'].",enemy_life_cur=".$user['enemy_life_cur'].",stat_kills=".$user['stat_kills'].",stat_boss_kills=".$user['stat_boss_kills'].",stat_deads=".$user['stat_deads'].",char_effect=".$user['char_effect']); + User::update("enemy_name='',enemy_image='',char_life_cur=".$user['char_life_cur'].",char_mana_cur=".$user['char_mana_cur'].",char_exp=".$user['char_exp'].",char_gold=".$user['char_gold'].",enemy_life_cur=".$user['enemy_life_cur'].",stat_kills=".$user['stat_kills'].",stat_boss_kills=".$user['stat_boss_kills'].",stat_deads=".$user['stat_deads'].",char_effects='".$user['char_effects']."'"); }