Skip to content

Commit

Permalink
Теперь на героя можно наложить сколько угодно эффектов на один бой.
Browse files Browse the repository at this point in the history
  • Loading branch information
devapromix committed Jan 27, 2023
1 parent dfe3da8 commit 60cfdf5
Show file tree
Hide file tree
Showing 5 changed files with 43 additions and 66 deletions.
30 changes: 9 additions & 21 deletions server/includes/class.battle.php
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ public function start_battle() {
$r .= 'Вы стали намного опытнее для текущего уровня и поэтому получаете меньше опыта и золота! Нужно посетить Квартал Гильдий и повысить уровень!#';
}

$this->clear_effects();
$user['class']['effect']->clear();
$user['battlelog'] = $r;

}
Expand All @@ -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']);
Expand All @@ -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']) {
Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -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);
}

}

?>
49 changes: 22 additions & 27 deletions server/includes/class.item.php
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -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;
Expand All @@ -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);
Expand Down Expand Up @@ -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":"Вам сначала нужно вернуться к жизни!"}');

Expand Down Expand Up @@ -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)
Expand All @@ -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":"Вам сначала нужно вернуться к жизни!"}');

Expand Down Expand Up @@ -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);
Expand All @@ -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;
Expand Down Expand Up @@ -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;
Expand All @@ -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)];
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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);
Expand Down
20 changes: 6 additions & 14 deletions server/includes/class.magic.php
Original file line number Diff line number Diff line change
Expand Up @@ -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).' маны!"}');
}
Expand All @@ -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);
}
Expand All @@ -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);
}
Expand All @@ -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);
}
Expand Down
8 changes: 5 additions & 3 deletions server/includes/class.stringbox.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

Expand All @@ -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;
}
Expand All @@ -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) {
Expand All @@ -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 {
Expand Down
2 changes: 1 addition & 1 deletion server/locations/battle.php
Original file line number Diff line number Diff line change
Expand Up @@ -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']."'");

}

Expand Down

0 comments on commit 60cfdf5

Please sign in to comment.