Created
April 2, 2019 17:05
-
-
Save hhatto/89bc96f6524309586e2c151b39391557 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
diff --git a/DreamGame.py b/DreamGame.py | |
index bbe3119..9723b73 100644 | |
--- a/DreamGame.py | |
+++ b/DreamGame.py | |
@@ -34,18 +34,24 @@ class DreamGame(SimGame): | |
vision_aggro_rule, | |
damage_provokes_rule] | |
- def __init__(self, bf=None, rules=None, is_sim = False, is_server=True, seed = None): | |
+ def __init__( | |
+ self, | |
+ bf=None, | |
+ rules=None, | |
+ is_sim=False, | |
+ is_server=True, | |
+ seed=None): | |
self.is_sim = is_sim | |
self.is_server = is_server | |
self.random = random.Random(seed) if seed else random.Random(100) | |
self.units = set() | |
self.obstacles = set() | |
- self.bf : Battlefield = bf or Battlefield(8, 8) | |
+ self.bf: Battlefield = bf or Battlefield(8, 8) | |
self.bf.game = self | |
self.vision = Vision(self) | |
- self.the_hero : Unit= None | |
+ self.the_hero: Unit = None | |
self.enemy_ai = BruteAI(self) | |
self.random_ai = RandomAI(self) | |
@@ -58,7 +64,6 @@ class DreamGame(SimGame): | |
self.loop_state = True | |
self.player_turn_lock = False | |
- | |
for rule in (rules or DreamGame.default_rules): | |
rule(self) | |
@@ -70,7 +75,6 @@ class DreamGame(SimGame): | |
game = DreamGame(bf, is_server=is_server) | |
bf.game = game | |
- | |
game.the_hero = hero | |
hero.cell = dungeon.hero_entrance | |
hero.faction = Faction.PLAYER | |
@@ -85,10 +89,13 @@ class DreamGame(SimGame): | |
return game | |
- def add_unit(self, unit: Unit, cell = None, faction = None, facing = None): | |
- if cell is not None: unit.cell = cell | |
- if faction is not None: unit.faction = faction | |
- if facing is not None: unit.facing = facing | |
+ def add_unit(self, unit: Unit, cell=None, faction=None, facing=None): | |
+ if cell is not None: | |
+ unit.cell = cell | |
+ if faction is not None: | |
+ unit.faction = faction | |
+ if facing is not None: | |
+ unit.facing = facing | |
assert unit.cell | |
assert unit.facing | |
@@ -104,7 +111,6 @@ class DreamGame(SimGame): | |
self.units.add(unit) | |
unit.update() | |
- | |
def unit_died(self, unit: Unit): | |
unit.alive = False | |
self.turns_manager.remove_unit(unit) | |
@@ -115,14 +121,13 @@ class DreamGame(SimGame): | |
obstacle.alive = False | |
self.obstacles.remove(obstacle) | |
- | |
- def add_obstacle(self, obstacle: Obstacle, cell = None): | |
+ def add_obstacle(self, obstacle: Obstacle, cell=None): | |
obstacle.game = self | |
self.obstacles.add(obstacle) | |
if cell: | |
obstacle.cell = cell | |
- def loop(self, turns = None): | |
+ def loop(self, turns=None): | |
n_turns = 0 | |
player_in_game = not bool(self.game_over()) | |
@@ -137,12 +142,11 @@ class DreamGame(SimGame): | |
print(game_over) | |
return self.turns_manager.time | |
- | |
active_unit = self.turns_manager.get_next() | |
if active_unit.faction == Faction.PLAYER: | |
self.player_turn_lock = True | |
- while self.player_turn_lock and self.loop_state : | |
+ while self.player_turn_lock and self.loop_state: | |
time.sleep(0.02) | |
continue | |
@@ -157,8 +161,6 @@ class DreamGame(SimGame): | |
else: | |
active_unit.readiness -= 0.5 | |
- | |
- | |
def game_over(self): | |
if len(self.player_units) == 0: | |
@@ -170,7 +172,6 @@ class DreamGame(SimGame): | |
else: | |
return None | |
- | |
def __repr__(self): | |
return f"{'Simulated ' if self.is_sim else ''}{self.bf.h} by" \ | |
f" {self.bf.w} dungeon with {len(self.units)} units in it." | |
@@ -179,20 +180,21 @@ class DreamGame(SimGame): | |
if self.turns_manager.get_next() is self.the_hero: | |
cell_from = self.the_hero.cell | |
facing = self.the_hero.facing | |
- cell_to = Cell.from_complex( cell_from.complex + c_vec * facing ) | |
+ cell_to = Cell.from_complex(cell_from.complex + c_vec * facing) | |
self.ui_order(cell_to.x, cell_to.y) | |
def ui_order(self, x, y): | |
print(f"ordered: move to {x},{y}") | |
if self.turns_manager.get_next() is self.the_hero: | |
- cell = Cell.from_complex(x + y* 1j) | |
+ cell = Cell.from_complex(x + y * 1j) | |
if cell in self.bf.cells_to_objs: | |
- self.order_attack(self.the_hero, random.choice(self.bf.cells_to_objs[cell])) | |
+ self.order_attack( | |
+ self.the_hero, random.choice( | |
+ self.bf.cells_to_objs[cell])) | |
else: | |
self.order_move(self.the_hero, cell) | |
- | |
def order_turn_cw(self): | |
if self.turns_manager.get_next() is self.the_hero: | |
self._order_turn(ccw=False) | |
@@ -201,7 +203,6 @@ class DreamGame(SimGame): | |
if self.turns_manager.get_next() is self.the_hero: | |
self._order_turn(ccw=True) | |
- | |
def _order_turn(self, ccw): | |
active = self.the_hero.turn_ccw_active if ccw else self.the_hero.turn_cw_active | |
self.order_action(self.the_hero, active, None) | |
@@ -235,26 +236,29 @@ class DreamGame(SimGame): | |
if unit is self.the_hero: | |
raise PydolonsError("The hero is immobilized.") | |
- | |
affordable_actives = [a for a in actives if a.affordable()] | |
if not affordable_actives: | |
self._complain_missing(unit, actives, "move") | |
- valid_actives = [a for a in affordable_actives if a.check_target(target_cell)] | |
+ valid_actives = [ | |
+ a for a in affordable_actives if a.check_target(target_cell)] | |
if valid_actives: | |
- chosen_active = min(valid_actives, key=DreamGame.cost_heuristic(unit)) | |
+ chosen_active = min( | |
+ valid_actives, | |
+ key=DreamGame.cost_heuristic(unit)) | |
self.order_action(unit, chosen_active, target_cell) | |
return | |
else: | |
# We can't directly execute this order. | |
if not AI_assist: | |
- raise PydolonsError("None of the user movement actives can reach " | |
- "the target cell.") | |
+ raise PydolonsError( | |
+ "None of the user movement actives can reach " | |
+ "the target cell.") | |
- angle, ccw = Cell.angle_between(unit.facing, | |
- target_cell.complex - cell_from.complex) | |
+ angle, ccw = Cell.angle_between( | |
+ unit.facing, target_cell.complex - cell_from.complex) | |
if angle > 45: | |
active = unit.turn_ccw_active if ccw else unit.turn_cw_active | |
self.order_action(unit, active, None) | |
@@ -265,11 +269,12 @@ class DreamGame(SimGame): | |
if distance >= 2: | |
vec = target_cell.complex - cell_from.complex | |
vec_magnitude_1 = vec / abs(vec) | |
- closer_target = Cell.from_complex(cell_from.complex + vec_magnitude_1) | |
+ closer_target = Cell.from_complex( | |
+ cell_from.complex + vec_magnitude_1) | |
self.order_move(unit, closer_target) | |
else: | |
- raise PydolonsError("None of the user movement actives can reach the target.") | |
- | |
+ raise PydolonsError( | |
+ "None of the user movement actives can reach the target.") | |
def order_attack(self, unit: Unit, _target: Unit, AI_assist=True): | |
actives = unit.attack_actives | |
@@ -289,19 +294,24 @@ class DreamGame(SimGame): | |
if not affordable_actives: | |
self._complain_missing(unit, actives, "attack") | |
- valid_actives = [a for a in affordable_actives if a.check_target(unit_target)] | |
+ valid_actives = [ | |
+ a for a in affordable_actives if a.check_target(unit_target)] | |
if valid_actives: | |
- chosen_active = min(valid_actives, key=DreamGame.cost_heuristic(unit)) | |
+ chosen_active = min( | |
+ valid_actives, | |
+ key=DreamGame.cost_heuristic(unit)) | |
self.order_action(unit, chosen_active, unit_target) | |
return | |
else: | |
if not AI_assist: | |
- raise PydolonsError("None of the user attack actives can reach the target.") | |
+ raise PydolonsError( | |
+ "None of the user attack actives can reach the target.") | |
else: | |
target_cell = unit_target.cell | |
- angle, ccw = Cell.angle_between(unit.facing, target_cell.complex -unit.cell.complex) | |
+ angle, ccw = Cell.angle_between( | |
+ unit.facing, target_cell.complex - unit.cell.complex) | |
if angle > 45: | |
active = unit.turn_ccw_active if ccw else unit.turn_cw_active | |
self.order_action(unit, active, None) | |
@@ -311,8 +321,8 @@ class DreamGame(SimGame): | |
if distance >= 2: | |
self.order_move(unit, target_cell) | |
else: | |
- raise PydolonsError("None of the user attack actives can reach the target.") | |
- | |
+ raise PydolonsError( | |
+ "None of the user attack actives can reach the target.") | |
def order_action(self, unit, active, target): | |
if target is None: | |
@@ -344,4 +354,3 @@ class DreamGame(SimGame): | |
def get_units_distances_from(self, p): | |
return self.bf.get_units_dists_to(p, self.units) | |
- | |
diff --git a/GameImitation.py b/GameImitation.py | |
index d6b6421..64ab0d0 100644 | |
--- a/GameImitation.py | |
+++ b/GameImitation.py | |
@@ -10,6 +10,7 @@ if TYPE_CHECKING: | |
from typing import Dict | |
from game_objects.battlefield_objects import Unit, Obstacle | |
+ | |
class TurnsManager: | |
def __init__(self): | |
self.unit = None | |
@@ -20,17 +21,18 @@ class TurnsManager: | |
self.unit_locations = units | |
self.managed_units = list(units.keys()) | |
- | |
def get_next(self): | |
return self.unit | |
def managed_units(self): | |
return list(self.unit_locations.values()) | |
+ | |
class GameLog: | |
def __init__(self): | |
self.msg = 'game imitation' | |
+ | |
class DreamGame: | |
def __init__(self, dungeon, hero, is_server=True): | |
@@ -47,7 +49,8 @@ class DreamGame: | |
self.the_hero = hero | |
- self.faction = {unit:Faction.ENEMY for unit in unit_locations if not unit.is_obstacle} | |
+ self.faction = { | |
+ unit: Faction.ENEMY for unit in unit_locations if not unit.is_obstacle} | |
self.faction[hero] = Faction.PLAYER | |
units_who_make_turns = [unit for unit in unit_locations.keys() | |
@@ -92,9 +95,6 @@ class DreamGame: | |
def order_turn_cw(self): | |
self.gamelog.msg = 'order_turn_cw' | |
- | |
- | |
- | |
def loop(self, turns=None): | |
while self.loop_state: | |
time.sleep(0.2) | |
diff --git a/GameLog.py b/GameLog.py | |
index ca66dbd..12a77a9 100644 | |
--- a/GameLog.py | |
+++ b/GameLog.py | |
@@ -7,6 +7,7 @@ class LogTargets(Enum): | |
PRINT = auto() | |
SILENT = auto() | |
+ | |
class GameLog: | |
the_log = None | |
diff --git a/GameLoopThread.py b/GameLoopThread.py | |
index d61685b..7794bca 100644 | |
--- a/GameLoopThread.py | |
+++ b/GameLoopThread.py | |
@@ -21,6 +21,7 @@ class ProxyEmit(object): | |
""" | |
play_movement_anim = None | |
+ | |
def __init__(self, arg): | |
super(ProxyEmit, self).__init__() | |
@@ -38,6 +39,7 @@ class GameLoopThread(QtCore.QThread): | |
play_nextunit_anim = QtCore.Signal() | |
play_levelstatus = QtCore.Signal(str) | |
obstacle_destroyed = QtCore.Signal(dict) | |
+ | |
def __init__(self, parent=None): | |
super(GameLoopThread, self).__init__(parent) | |
self.game = None | |
@@ -63,13 +65,20 @@ class GameLoopThread(QtCore.QThread): | |
self.setConnection() | |
def setConnection(self): | |
- self.play_movement_anim.connect(self.the_ui.gameRoot.level.units.unitMoveSlot) | |
- self.maybe_play_damage_anim.connect(self.the_ui.gameRoot.level.units.targetDamageSlot) | |
- self.maybe_play_hit_anim.connect(self.the_ui.gameRoot.level.units.targetDamageHitSlot) | |
- self.play_attack_anim.connect(self.the_ui.gameRoot.level.units.attackSlot) | |
- self.play_perish_anim.connect(self.the_ui.gameRoot.level.units.unitDiedSlot) | |
- self.play_trun_anim.connect(self.the_ui.gameRoot.level.units.unitTurnSlot) | |
- self.play_nextunit_anim.connect(self.the_ui.gameRoot.gamePages.gameMenu.updateUnitStack) | |
+ self.play_movement_anim.connect( | |
+ self.the_ui.gameRoot.level.units.unitMoveSlot) | |
+ self.maybe_play_damage_anim.connect( | |
+ self.the_ui.gameRoot.level.units.targetDamageSlot) | |
+ self.maybe_play_hit_anim.connect( | |
+ self.the_ui.gameRoot.level.units.targetDamageHitSlot) | |
+ self.play_attack_anim.connect( | |
+ self.the_ui.gameRoot.level.units.attackSlot) | |
+ self.play_perish_anim.connect( | |
+ self.the_ui.gameRoot.level.units.unitDiedSlot) | |
+ self.play_trun_anim.connect( | |
+ self.the_ui.gameRoot.level.units.unitTurnSlot) | |
+ self.play_nextunit_anim.connect( | |
+ self.the_ui.gameRoot.gamePages.gameMenu.updateUnitStack) | |
self.play_levelstatus.connect(self.the_ui.gameRoot.level.setStatus) | |
self.obstacle_destroyed.connect(self.debug) | |
@@ -78,4 +87,3 @@ class GameLoopThread(QtCore.QThread): | |
def debug(self, msg): | |
print('DEBUG MSG', msg) | |
- | |
diff --git a/LEngine.py b/LEngine.py | |
index 4381038..bfb3036 100644 | |
--- a/LEngine.py | |
+++ b/LEngine.py | |
@@ -21,9 +21,10 @@ class LEngine: | |
""" | |
LogicEngine | |
""" | |
+ | |
def __init__(self): | |
- self.character:Character = None | |
- self.the_hero = None | |
+ self.character: Character = None | |
+ self.the_hero = None | |
self.dungeon = None | |
def getHero(self): | |
@@ -58,10 +59,15 @@ class LEngine: | |
move_anim_trigger(game), | |
obstacle_destroy_trigger(game) | |
- def getShop(self, single_palyer = True): | |
+ def getShop(self, single_palyer=True): | |
shop = None | |
if single_palyer and self.character is not None: | |
- return Shop(generate_assortment(all_blueprints, all_materials, QualityLevels.all), | |
- 1, 500, customer=self.character) | |
+ return Shop( | |
+ generate_assortment( | |
+ all_blueprints, | |
+ all_materials, | |
+ QualityLevels.all), | |
+ 1, | |
+ 500, | |
+ customer=self.character) | |
return shop | |
- | |
diff --git a/battlefield/Battlefield.py b/battlefield/Battlefield.py | |
index 079cd12..21ecbc7 100644 | |
--- a/battlefield/Battlefield.py | |
+++ b/battlefield/Battlefield.py | |
@@ -1,23 +1,25 @@ | |
from __future__ import annotations | |
+from my_utils.utils import ReadOnlyDict | |
+from collections import defaultdict | |
+from battlefield.Cell import Cell | |
from typing import Dict, Collection, List, TYPE_CHECKING | |
if TYPE_CHECKING: | |
from game_objects.battlefield_objects import BattlefieldObject, Wall | |
from typing import Set, FrozenSet, Collection | |
import DreamGame | |
-from battlefield.Cell import Cell | |
-from collections import defaultdict | |
-from my_utils.utils import ReadOnlyDict | |
+ | |
class Battlefield: | |
space_per_cell = 10 | |
- def __init__(self, w, h, game: DreamGame = None, walls: Collection[Wall] = frozenset()): | |
+ def __init__(self, w, h, game: DreamGame = None, | |
+ walls: Collection[Wall] = frozenset()): | |
self.w = w | |
self.h = h | |
self.game = game | |
self._walls = frozenset(walls) | |
- self.walls = ReadOnlyDict({w.cell:w for w in self._walls}) | |
+ self.walls = ReadOnlyDict({w.cell: w for w in self._walls}) | |
all_cells = [] | |
for i in range(self.w): | |
@@ -39,33 +41,37 @@ class Battlefield: | |
one = one.cell | |
if hasattr(another, "alive"): | |
another = another.cell | |
- return Cell._distance(Cell.maybe_complex(one), Cell.maybe_complex(another)) | |
+ return Cell._distance( | |
+ Cell.maybe_complex(one), | |
+ Cell.maybe_complex(another)) | |
@staticmethod | |
def get_units_dists_to(p, units_subset): | |
- unit_dist_tuples = [ (u, Battlefield.distance(p, u)) for u in units_subset] | |
- return sorted(unit_dist_tuples, key=lambda x:x[1]) | |
+ unit_dist_tuples = [(u, Battlefield.distance(p, u)) | |
+ for u in units_subset] | |
+ return sorted(unit_dist_tuples, key=lambda x: x[1]) | |
def get_units_within_radius(self, center, radius): | |
- return [u for u in self.all_objs if Battlefield.distance(center, u) <= radius] | |
+ return [ | |
+ u for u in self.all_objs if Battlefield.distance( | |
+ center, u) <= radius] | |
def get_objects_at(self, _cell) -> List[BattlefieldObject]: | |
cell = Cell.maybe_complex(_cell) | |
if cell in self.cells_to_objs: | |
return self.cells_to_objs[cell] | |
- | |
def neighbours_exclude_center(self, cell, distance=1) -> List[Cell]: | |
neighbours = set(self.get_cells_within_dist(cell, distance)) | |
neighbours.remove(cell) | |
return list(neighbours) | |
def get_cells_within_dist(self, cell, distance) -> List[Cell]: | |
- return Cell.get_neighbours(cell,distance, self.w, self.h) | |
+ return Cell.get_neighbours(cell, distance, self.w, self.h) | |
def get_nearest_cell(self, candidates, target): | |
pairs = [(c, self.distance(c, target)) for c in candidates] | |
- return min(pairs, key=lambda x:x[1]) | |
+ return min(pairs, key=lambda x: x[1]) | |
def space_free(self, cell: Cell): | |
space_taken = sum([o.size for o in self.get_objects_at(cell)]) | |
@@ -85,7 +91,6 @@ class Battlefield: | |
return 9000, None | |
return Cell.angle_between(unit.facing, vector_to_target) | |
- | |
@property | |
def cells_to_objs(self) -> Dict[Cell, List[BattlefieldObject]]: | |
result = defaultdict(list) | |
@@ -93,22 +98,26 @@ class Battlefield: | |
result[unit.cell].append(unit) | |
return result | |
- | |
- def units_in_area(self, area : Collection[Cell]) -> List[BattlefieldObject]: | |
+ def units_in_area(self, area: Collection[Cell]) -> List[BattlefieldObject]: | |
return [u for u in self.all_objs if u.cell in area] | |
- def cone(self, cell_from, direction:complex, angle_max, dist_min, dist_max): | |
+ def cone( | |
+ self, | |
+ cell_from, | |
+ direction: complex, | |
+ angle_max, | |
+ dist_min, | |
+ dist_max): | |
result = [] | |
for cell in self.all_cells: | |
if dist_min <= self.distance(cell, cell_from) <= dist_max: | |
vector_to_target = cell.complex - cell_from.complex | |
- if Cell.angle_between(direction, vector_to_target)[0] <= angle_max: | |
+ if Cell.angle_between(direction, vector_to_target)[ | |
+ 0] <= angle_max: | |
result.append(cell) | |
return result | |
- | |
@staticmethod | |
def _distance(p1, p2): | |
return Cell._distance(p1, p2) | |
- | |
diff --git a/battlefield/Cell.py b/battlefield/Cell.py | |
index c59da91..2d1d51d 100644 | |
--- a/battlefield/Cell.py | |
+++ b/battlefield/Cell.py | |
@@ -4,17 +4,20 @@ import functools | |
from math import hypot | |
from typing import Union, List, Tuple | |
+ | |
def positive_angle(angle): | |
- assert -pi*2 <= angle < 2*pi | |
+ assert -pi * 2 <= angle < 2 * pi | |
if angle < 0: | |
- return angle + 2* pi | |
+ return angle + 2 * pi | |
else: | |
return angle | |
+ | |
def cw_phase(c): | |
p = phase(c) | |
return positive_angle(p) | |
+ | |
class Cell: | |
def __init__(self, x, y): | |
self.x = x | |
@@ -26,12 +29,13 @@ class Cell: | |
@staticmethod | |
def from_complex(c: complex) -> Cell: | |
- return Cell( int(c.real + 0.5), int(c.imag+ 0.5) ) | |
+ return Cell(int(c.real + 0.5), int(c.imag + 0.5)) | |
@staticmethod | |
def maybe_complex(cell_or_complex: Union[Cell, complex]) -> Cell: | |
c_or_c = cell_or_complex | |
- return Cell(int(c_or_c.real), int(c_or_c.imag)) if isinstance(c_or_c, complex) else c_or_c | |
+ return Cell(int(c_or_c.real), int(c_or_c.imag) | |
+ ) if isinstance(c_or_c, complex) else c_or_c | |
@staticmethod | |
def angle_between(c1: complex, c2: complex) -> Tuple[float, bool]: | |
@@ -47,26 +51,31 @@ class Cell: | |
angle_cw = positive_angle(p2 - p1) | |
angle_ccw = positive_angle(p1 - p2) | |
- return min(angle_cw, angle_ccw) / pi * 180, angle_ccw < angle_cw | |
+ return min(angle_cw, angle_ccw) / pi * 180, angle_ccw < angle_cw | |
@staticmethod | |
@functools.lru_cache() | |
- def get_neighbours(cell_or_complex, distance, w=1000, h=1000) -> List[Cell]: | |
+ def get_neighbours( | |
+ cell_or_complex, | |
+ distance, | |
+ w=1000, | |
+ h=1000) -> List[Cell]: | |
c = Cell.maybe_complex(cell_or_complex) | |
neighbours = [] | |
- x_min, x_max = int(max(0, c.x - distance)), int(min(w-1, c.x+distance)) | |
- y_min, y_max = int(max(0, c.y - distance)), int(min(h-1, c.y+distance)) | |
- | |
- for x in range(x_min, x_max+1): | |
- for y in range(y_min, y_max+1): | |
- test_cell = Cell(x,y) | |
+ x_min, x_max = int(max(0, c.x - distance) | |
+ ), int(min(w - 1, c.x + distance)) | |
+ y_min, y_max = int(max(0, c.y - distance) | |
+ ), int(min(h - 1, c.y + distance)) | |
+ | |
+ for x in range(x_min, x_max + 1): | |
+ for y in range(y_min, y_max + 1): | |
+ test_cell = Cell(x, y) | |
if Cell._distance(c, test_cell) <= distance: | |
neighbours.append(test_cell) | |
return neighbours | |
- | |
@staticmethod | |
def _distance(p1, p2): | |
return Cell._hypot(p1.x - p2.x, p1.y - p2.y) | |
@@ -77,14 +86,18 @@ class Cell: | |
return hypot(x, y) | |
def __eq__(self, other): | |
- if self is other: return True | |
- if other is None: return False | |
- if isinstance(other, complex): return self.x == other.real and self.y == other.imag | |
- if self.__class__ != other.__class__: return False | |
+ if self is other: | |
+ return True | |
+ if other is None: | |
+ return False | |
+ if isinstance(other, complex): | |
+ return self.x == other.real and self.y == other.imag | |
+ if self.__class__ != other.__class__: | |
+ return False | |
return self.x == other.x and self.y == other.y | |
def __hash__(self): | |
- return hash(self.x*10000 + self.y) | |
+ return hash(self.x * 10000 + self.y) | |
def __repr__(self): | |
return f"({self.x},{self.y})" | |
diff --git a/battlefield/Facing.py b/battlefield/Facing.py | |
index f300265..406bf18 100644 | |
--- a/battlefield/Facing.py | |
+++ b/battlefield/Facing.py | |
@@ -6,12 +6,7 @@ class Facing: | |
SOUTH = (0 + 1j) | |
EAST = (1 + 0j) | |
- | |
- | |
- to_str = {NORTH : "NORTH", | |
- WEST : "WEST", | |
- SOUTH : "SOUTH", | |
- EAST : "EAST"} | |
- | |
- | |
- | |
+ to_str = {NORTH: "NORTH", | |
+ WEST: "WEST", | |
+ SOUTH: "SOUTH", | |
+ EAST: "EAST"} | |
diff --git a/battlefield/Vision.py b/battlefield/Vision.py | |
index 30a1778..afdd1c1 100644 | |
--- a/battlefield/Vision.py | |
+++ b/battlefield/Vision.py | |
@@ -27,10 +27,11 @@ class Vision: | |
unit.facing, | |
cell_from, | |
self.game.bf)) | |
- blocking_cells = {cell for cell in bf.cells_to_objs if bf.space_free(cell) < | |
- bf.space_per_cell / 2} | |
+ blocking_cells = {cell for cell in bf.cells_to_objs if bf.space_free( | |
+ cell) < bf.space_per_cell / 2} | |
blocking_cells -= {cell_from} | |
- visible_walls = frozenset({cell for cell in bf.walls if cell in visible_cells}) | |
+ visible_walls = frozenset( | |
+ {cell for cell in bf.walls if cell in visible_cells}) | |
diag_wall_blockers = Vision._merge_walls(visible_walls) | |
blocking_cells |= diag_wall_blockers | |
for obstacle in blocking_cells: | |
@@ -49,11 +50,14 @@ class Vision: | |
:return: set of new imaginary obstacles | |
""" | |
new_obstacles = set() | |
- diag_dist = Cell._distance(Cell(0,0), Cell(1,1)) | |
+ diag_dist = Cell._distance(Cell(0, 0), Cell(1, 1)) | |
for o1 in obstacles: | |
for o2 in obstacles: | |
if Cell._distance(o1, o2) == diag_dist: | |
- new_obstacles.add(Cell( (o1.x+o2.x)/2 , (o1.y+o2.y)/2 )) | |
+ new_obstacles.add( | |
+ Cell( | |
+ (o1.x + o2.x) / 2, | |
+ (o1.y + o2.y) / 2)) | |
return new_obstacles | |
@@ -99,12 +103,11 @@ class Vision: | |
@staticmethod | |
def _dist_eliptic_x(p1, p2): | |
- return Cell._hypot( 1.45*(p1.x - p2.x) , (p1.y - p2.y) ) | |
+ return Cell._hypot(1.45 * (p1.x - p2.x), (p1.y - p2.y)) | |
@staticmethod | |
def _dist_eliptic_y(p1, p2): | |
- return Cell._hypot((p1.x - p2.x), 1.45*(p1.y - p2.y)) | |
- | |
+ return Cell._hypot((p1.x - p2.x), 1.45 * (p1.y - p2.y)) | |
@staticmethod | |
@functools.lru_cache(maxsize=int(2**16)) | |
@@ -115,7 +118,8 @@ class Vision: | |
:return: True if the :obstacle blocks the view | |
""" | |
- # caching trick: halve the search space (assumes symmetry, which is tested) | |
+ # caching trick: halve the search space (assumes symmetry, which is | |
+ # tested) | |
if looking_from.x > looking_to.x: | |
return Vision.blocks(looking_to, looking_from, obstacle) | |
@@ -125,22 +129,23 @@ class Vision: | |
if looking_from == obstacle: | |
return False | |
- #obstacle behind the target can't block it. | |
- if Cell._distance(looking_from, looking_to) < Cell._distance(looking_from, obstacle): | |
+ # obstacle behind the target can't block it. | |
+ if Cell._distance( | |
+ looking_from, | |
+ looking_to) < Cell._distance( | |
+ looking_from, | |
+ obstacle): | |
return False | |
- | |
norm = np.linalg.norm | |
p1 = np.asarray([looking_from.x, looking_from.y]) | |
p2 = np.asarray([looking_to.x, looking_to.y]) | |
p3 = np.asarray([obstacle.x, obstacle.y]) | |
- #obstacle which is in diferent semiplane can't possibly block it | |
- if np.dot( p2 - p1, p3 - p1) <= 0: | |
+ # obstacle which is in diferent semiplane can't possibly block it | |
+ if np.dot(p2 - p1, p3 - p1) <= 0: | |
return False | |
- | |
- dist_to_perpendicular = norm(np.cross(p2 - p1, p1 - p3)) / norm(p2 - p1) | |
+ dist_to_perpendicular = norm( | |
+ np.cross(p2 - p1, p1 - p3)) / norm(p2 - p1) | |
return dist_to_perpendicular < 0.65 | |
- | |
- | |
diff --git a/character/Character.py b/character/Character.py | |
index 8f5a1d9..4c4de68 100644 | |
--- a/character/Character.py | |
+++ b/character/Character.py | |
@@ -8,8 +8,9 @@ from character.perks.everymans_perks.everymans_perk_tree import everymans_perks | |
from typing import List, Set | |
+ | |
class Character: | |
- def __init__(self, base_type : BaseType): | |
+ def __init__(self, base_type: BaseType): | |
self.base_type = base_type | |
self.masteries = Masteries() | |
self._unit = Unit(base_type, masteries=self.masteries) | |
@@ -43,36 +44,36 @@ class Character: | |
if self.temp_attributes: | |
return self.attributes_count - sum(self.temp_attributes.values()) | |
else: | |
- return self.attributes_count - sum(self.base_type.attributes.values()) | |
+ return self.attributes_count - \ | |
+ sum(self.base_type.attributes.values()) | |
@property | |
def free_xp(self) -> int: | |
if self.temp_masteries: | |
- masteries_xp = self.temp_masteries.total_exp_spent | |
+ masteries_xp = self.temp_masteries.total_exp_spent | |
else: | |
masteries_xp = self.masteries.total_exp_spent | |
- return self.xp - masteries_xp - sum( pt.spent_xp for pt in self.perk_trees) | |
- | |
+ return self.xp - masteries_xp - \ | |
+ sum(pt.spent_xp for pt in self.perk_trees) | |
def increase_attrib(self, attrib_enum: CharAttributes) -> None: | |
if self.free_attribute_points <= 0: | |
return | |
assert attrib_enum in CharAttributes | |
- if self.temp_attributes is None : | |
+ if self.temp_attributes is None: | |
self.temp_attributes = copy.copy(self.base_type.attributes) | |
self.temp_attributes[attrib_enum] += 1 | |
def reduce_attrib(self, attrib_enum: CharAttributes) -> None: | |
assert attrib_enum in CharAttributes | |
- if self.temp_attributes is None : | |
+ if self.temp_attributes is None: | |
return | |
self.temp_attributes[attrib_enum] -= 1 | |
- | |
def increase_mastery(self, mastery: MasteriesEnum) -> None: | |
- if not mastery in self.masteries_can_go_up: | |
+ if mastery not in self.masteries_can_go_up: | |
return | |
if self.temp_masteries is None: | |
@@ -80,7 +81,6 @@ class Character: | |
self.temp_masteries.level_up(mastery) | |
- | |
def commit(self): | |
if self.temp_attributes: | |
self.base_type.attributes = self.temp_attributes | |
@@ -90,7 +90,6 @@ class Character: | |
self.masteries = self.temp_masteries | |
self.temp_masteries = None | |
- | |
def reset(self): | |
self.temp_attributes = None | |
self.temp_masteries = None | |
@@ -104,10 +103,10 @@ class Character: | |
cpy.attributes = self.temp_attributes | |
return cpy | |
- | |
@property | |
def unit(self) -> Unit: | |
- self._unit.update(self.base_type_prelim, masteries=self.temp_masteries or self.masteries) | |
+ self._unit.update(self.base_type_prelim, | |
+ masteries=self.temp_masteries or self.masteries) | |
for pt in self.perk_trees: | |
for a in pt.all_abils: | |
self._unit.add_ability(a) | |
diff --git a/character/masteries/Masteries.py b/character/masteries/Masteries.py | |
index 02f250a..56e1563 100644 | |
--- a/character/masteries/Masteries.py | |
+++ b/character/masteries/Masteries.py | |
@@ -2,10 +2,11 @@ from character.masteries import MasteriesEnum, MasteriesGroups | |
# from character.MasteriesEnumSimple import MasteriesEnum | |
from functools import lru_cache | |
+ | |
class Masteries: | |
def __init__(self, exp=0): | |
exp_per_mastery = int(exp / len(MasteriesEnum)) | |
- self.exp_spent = {m:exp_per_mastery for m in MasteriesEnum} | |
+ self.exp_spent = {m: exp_per_mastery for m in MasteriesEnum} | |
@property | |
def total_exp_spent(self): | |
@@ -18,30 +19,35 @@ class Masteries: | |
return 4 | |
else: | |
if current_level <= 100: | |
- return int(2 + (current_level ** (5/3)/10) + Masteries.increment_cost(current_level-1)) | |
+ return int(2 + (current_level ** (5 / 3) / 10) + | |
+ Masteries.increment_cost(current_level - 1)) | |
else: | |
- return int(2**(current_level/13) + Masteries.increment_cost(current_level-1)) | |
+ return int(2**(current_level / 13) + | |
+ Masteries.increment_cost(current_level - 1)) | |
@staticmethod | |
@lru_cache(maxsize=512) | |
def cumulative_cost(current_level): | |
- return sum([Masteries.increment_cost(i) for i in range(current_level+1)]) | |
+ return sum([Masteries.increment_cost(i) | |
+ for i in range(current_level + 1)]) | |
@staticmethod | |
def achieved_level(exp): | |
level = 0 | |
- while exp >= Masteries.cumulative_cost(level+1): | |
+ while exp >= Masteries.cumulative_cost(level + 1): | |
level += 1 | |
return level | |
@property | |
def values(self): | |
- return { m: Masteries.achieved_level(exp) for m, exp in self.exp_spent.items()} | |
+ return {m: Masteries.achieved_level(exp) | |
+ for m, exp in self.exp_spent.items()} | |
def calculate_cost(self, mastery_up): | |
- direct_cost = self.cumulative_cost(self.values[mastery_up] + 1) - self.exp_spent[mastery_up] | |
+ direct_cost = self.cumulative_cost( | |
+ self.values[mastery_up] + 1) - self.exp_spent[mastery_up] | |
indirect_costs = {} | |
for mastery in MasteriesEnum: | |
coupling = MasteriesGroups.coupling(mastery, mastery_up) | |
@@ -52,36 +58,27 @@ class Masteries: | |
return total_cost, direct_cost, indirect_costs | |
def level_up(self, mastery_up): | |
- total_cost, direct_cost, indirect_costs = self.calculate_cost(mastery_up) | |
+ total_cost, direct_cost, indirect_costs = self.calculate_cost( | |
+ mastery_up) | |
self.exp_spent[mastery_up] += direct_cost | |
for m in indirect_costs: | |
self.exp_spent[m] += indirect_costs[m] | |
@staticmethod | |
- def max_out(exp, chosen: MasteriesEnum, percentage = 0.9): | |
+ def max_out(exp, chosen: MasteriesEnum, percentage=0.9): | |
assert 0 <= percentage <= 1 | |
- distributed_xp = exp * (1-percentage) | |
- _masteries = Masteries(exp = distributed_xp) | |
+ distributed_xp = exp * (1 - percentage) | |
+ _masteries = Masteries(exp=distributed_xp) | |
_masteries.exp_spent[chosen] += exp - distributed_xp | |
return _masteries | |
- | |
def __getitem__(self, item): | |
exp = self.exp_spent[item] | |
lvl = self.achieved_level(exp) | |
return lvl | |
- | |
- | |
- | |
- | |
- | |
- | |
- | |
- | |
- | |
if __name__ == "__main__": | |
masteries = Masteries() | |
total = 0 | |
@@ -95,7 +92,6 @@ if __name__ == "__main__": | |
# for m in MasteriesEnum: | |
# print(m, masteries.requirements(m,100)) | |
- | |
masteries = Masteries() | |
# masteries.exp_spent[MasteriesEnum.AXE] = 5000 | |
# masteries.exp_spent[MasteriesEnum.SWORD] = 15000 | |
@@ -104,19 +100,18 @@ if __name__ == "__main__": | |
print(masteries.exp_spent) | |
print(masteries.values) | |
- while masteries.values[MasteriesEnum.CLUB]<10: | |
+ while masteries.values[MasteriesEnum.CLUB] < 10: | |
masteries.level_up(MasteriesEnum.CLUB) | |
print(masteries.level_up(MasteriesEnum.CLUB)) | |
print(masteries.exp_spent) | |
print(masteries.values) | |
- while masteries.values[MasteriesEnum.AXE]<30: | |
+ while masteries.values[MasteriesEnum.AXE] < 30: | |
masteries.level_up(MasteriesEnum.AXE) | |
print(masteries.level_up(MasteriesEnum.AXE)) | |
print(masteries.exp_spent) | |
print(masteries.values) | |
- while masteries.values[MasteriesEnum.SWORD]<50: | |
+ while masteries.values[MasteriesEnum.SWORD] < 50: | |
masteries.level_up(MasteriesEnum.SWORD) | |
print(masteries.level_up(MasteriesEnum.SWORD)) | |
print(masteries.exp_spent) | |
print(masteries.values) | |
- | |
diff --git a/character/masteries/MasteriesEnumSimple.py b/character/masteries/MasteriesEnumSimple.py | |
index f0555e6..2d291c3 100644 | |
--- a/character/masteries/MasteriesEnumSimple.py | |
+++ b/character/masteries/MasteriesEnumSimple.py | |
@@ -1,6 +1,7 @@ | |
from my_utils.named_enums import NameEnum, auto | |
from functools import lru_cache | |
+ | |
class MasteriesEnum(NameEnum): | |
AXE = auto() | |
SWORD = auto() | |
@@ -13,14 +14,14 @@ class MasteriesEnum(NameEnum): | |
UNARMED = auto() | |
FIRE = auto() | |
- FROST = auto() | |
- LIGHTNING = auto() | |
+ FROST = auto() | |
+ LIGHTNING = auto() | |
EARTH = auto() | |
- ACID = auto() | |
+ ACID = auto() | |
AIR = auto() | |
- LIGHT = auto() | |
+ LIGHT = auto() | |
ASTRAL = auto() | |
NATURE = auto() | |
@@ -43,7 +44,7 @@ class MasteriesGroups: | |
spicky = [m.SPEAR, m.LIGHTNING, m.LIGHT] | |
loud = [m.SONIC, m.HAMMER, m.EARTH, m.UNARMED] | |
explosive = [m.FIRE, m.EARTH, m.SONIC, m.AXE, m.SHOOT] | |
- cold = [ m.SWORD, m.DAGGER, m.FROST] | |
+ cold = [m.SWORD, m.DAGGER, m.FROST] | |
arcane = [m.MIND, m.ASTRAL] | |
chemical = [m.ACID, m.EARTH, m.SHOOT] | |
all_battle = [m.CLUB, m.SWORD, m.AXE, m.DAGGER, m.SPEAR, m.UNARMED, | |
@@ -52,7 +53,6 @@ class MasteriesGroups: | |
all_magic = [m.FROST, m.FIRE, m.LIGHT, m.LIGHTNING, m.EARTH, | |
m.ACID, m.SONIC, m.ASTRAL, m.MIND, m.HOLY, m.DARK, m.NATURE] | |
- | |
all = [chop_chop_chop, stabby, bashy, | |
sniping, spicky, loud, cold, | |
arcane, chemical, explosive, all_battle, all_magic] | |
@@ -70,7 +70,6 @@ class MasteriesGroups: | |
return n | |
- | |
@classmethod | |
@lru_cache() | |
def total_occurances(cls): | |
@@ -80,7 +79,6 @@ class MasteriesGroups: | |
return result | |
- | |
@classmethod | |
@lru_cache(maxsize=2048) | |
def coupling(cls, m1, m2): | |
@@ -89,7 +87,8 @@ class MasteriesGroups: | |
if m1 in group and m2 in group: | |
coupling += 1 | |
- return coupling * cls.coupling_coef / ( 1 + cls.occurances(m1) + cls.occurances(m2)) | |
+ return coupling * cls.coupling_coef / \ | |
+ (1 + cls.occurances(m1) + cls.occurances(m2)) | |
if __name__ == "__main__": | |
@@ -99,4 +98,4 @@ if __name__ == "__main__": | |
for m1 in MasteriesEnum: | |
for m2 in MasteriesEnum: | |
- print(m1, m2, MasteriesGroups.coupling(m1, m2)) | |
\ No newline at end of file | |
+ print(m1, m2, MasteriesGroups.coupling(m1, m2)) | |
diff --git a/character/perks/Perk.py b/character/perks/Perk.py | |
index 6ccc497..be5dc98 100644 | |
--- a/character/perks/Perk.py | |
+++ b/character/perks/Perk.py | |
@@ -3,12 +3,18 @@ from typing import Dict, TYPE_CHECKING | |
if TYPE_CHECKING: | |
from mechanics.buffs import Ability | |
+ | |
class Perk: | |
max_level = 3 | |
abilities = {} | |
- def __init__(self, name, level_to_abils: Dict[int, Ability], cost_factor=1, icon = "strange_perk.png"): | |
+ def __init__(self, | |
+ name, | |
+ level_to_abils: Dict[int, | |
+ Ability], | |
+ cost_factor=1, | |
+ icon="strange_perk.png"): | |
self.name = name | |
self.current_level = 0 | |
self.level_to_abils = level_to_abils | |
@@ -21,9 +27,9 @@ class Perk: | |
@property | |
def tooltip_info(self): | |
- return {'name': f"{repr(self)}" } | |
+ return {'name': f"{repr(self)}"} | |
def __repr__(self): | |
if self.current_level == 0: | |
return f"not learned {self.name[self.current_level+1]}" | |
- return f"{self.name[self.current_level]}" | |
\ No newline at end of file | |
+ return f"{self.name[self.current_level]}" | |
diff --git a/character/perks/PerkGroup.py b/character/perks/PerkGroup.py | |
index 6c2bd7a..dcaec02 100644 | |
--- a/character/perks/PerkGroup.py | |
+++ b/character/perks/PerkGroup.py | |
@@ -4,7 +4,8 @@ from character.perks import Perk | |
class PerkGroup: | |
- def __init__(self, perk_list: List[Perk], requirements: Dict[PerkGroup:int] = None): | |
+ def __init__(self, perk_list: List[Perk], | |
+ requirements: Dict[PerkGroup:int] = None): | |
self.perk_list = perk_list | |
self.requirements = requirements | |
@@ -18,4 +19,4 @@ class PerkGroup: | |
return sum([p.current_level for p in self.perk_list]) | |
def __repr__(self): | |
- return f"group of {self.perk_list}" | |
\ No newline at end of file | |
+ return f"group of {self.perk_list}" | |
diff --git a/character/perks/PerkTree.py b/character/perks/PerkTree.py | |
index 6db9302..be93948 100644 | |
--- a/character/perks/PerkTree.py | |
+++ b/character/perks/PerkTree.py | |
@@ -7,11 +7,12 @@ from my_utils.utils import flatten | |
import math | |
+ | |
class PerkTree: | |
- cost_factors = {1:1, 2:3, 3:7} | |
+ cost_factors = {1: 1, 2: 3, 3: 7} | |
- def __init__(self, name, perk_groups: List[PerkGroup], base_cost = 100): | |
+ def __init__(self, name, perk_groups: List[PerkGroup], base_cost=100): | |
self.name = name | |
self.perk_groups = perk_groups | |
self.base_cost = base_cost | |
@@ -21,8 +22,10 @@ class PerkTree: | |
return [pg for pg in self.perk_groups if pg.requirements_matched()] | |
def accessible_perks(self) -> List[Perk]: | |
- perks_in_accessible_groups = flatten([pg.perk_list for pg in self.get_accessible_groups()]) | |
- not_maxed = [ p for p in perks_in_accessible_groups if p.current_level < 3] | |
+ perks_in_accessible_groups = flatten( | |
+ [pg.perk_list for pg in self.get_accessible_groups()]) | |
+ not_maxed = [ | |
+ p for p in perks_in_accessible_groups if p.current_level < 3] | |
return not_maxed | |
@property | |
@@ -36,25 +39,23 @@ class PerkTree: | |
@property | |
def cost_growth(self) -> float: | |
tl = self.total_level | |
- return 2 ** (tl*11/13) | |
+ return 2 ** (tl * 11 / 13) | |
def cost_to_levelup(self, perk: Perk) -> int: | |
assert perk in self.all_perks | |
- precise_cost = perk.cost_factor * self.base_cost * self.cost_growth * \ | |
- ( self.cost_factors[perk.current_level+1] ** (1 + self.total_level/60) ) | |
+ precise_cost = perk.cost_factor * self.base_cost * self.cost_growth * \ | |
+ (self.cost_factors[perk.current_level + 1] ** (1 + self.total_level / 60)) | |
- log10 = int( math.log10(precise_cost) ) | |
- base = 10 ** (log10-1) | |
- return int( precise_cost // base * base ) | |
+ log10 = int(math.log10(precise_cost)) | |
+ base = 10 ** (log10 - 1) | |
+ return int(precise_cost // base * base) | |
@property | |
def all_abils(self): | |
return flatten([p.abils for p in self.all_perks]) | |
- | |
- | |
if __name__ == "__main__": | |
for i in range(25): | |
tl = i | |
- print(i, tl/2 + 2 ** (tl*4/3)) | |
\ No newline at end of file | |
+ print(i, tl / 2 + 2 ** (tl * 4 / 3)) | |
diff --git a/character/perks/everymans_perks/everymans_perk_tree.py b/character/perks/everymans_perks/everymans_perk_tree.py | |
index 2ff3986..6e126a3 100644 | |
--- a/character/perks/everymans_perks/everymans_perk_tree.py | |
+++ b/character/perks/everymans_perks/everymans_perk_tree.py | |
@@ -5,22 +5,22 @@ from character.perks.everymans_perks.group_param import pg_params | |
import copy | |
+ | |
def everymans_perks(): | |
- return copy.deepcopy(PerkTree("Generic perks", [pg_attributes, pg_params])) | |
+ return copy.deepcopy(PerkTree("Generic perks", [pg_attributes, pg_params])) | |
if __name__ == "__main__": | |
from pprint import pprint | |
ep = everymans_perks() | |
- | |
- pprint( ep.accessible_perks() ) | |
- pprint( ep.cost_to_levelup( ep.accessible_perks()[0] ) ) | |
- pprint( ep.cost_to_levelup( ep.accessible_perks()[1] ) ) | |
- pprint( ep.cost_to_levelup( ep.accessible_perks()[2] ) ) | |
- print('-*-'*50) | |
+ pprint(ep.accessible_perks()) | |
+ pprint(ep.cost_to_levelup(ep.accessible_perks()[0])) | |
+ pprint(ep.cost_to_levelup(ep.accessible_perks()[1])) | |
+ pprint(ep.cost_to_levelup(ep.accessible_perks()[2])) | |
+ print('-*-' * 50) | |
str_perk = ep.accessible_perks()[0] | |
agi_perk = ep.accessible_perks()[1] | |
@@ -28,20 +28,19 @@ if __name__ == "__main__": | |
p1 = ep.accessible_perks()[3] | |
p2 = ep.accessible_perks()[4] | |
- | |
str_perk.current_level += 1 | |
pprint(ep.cost_to_levelup(ep.accessible_perks()[0])) | |
pprint(ep.cost_to_levelup(ep.accessible_perks()[1])) | |
pprint(ep.cost_to_levelup(ep.accessible_perks()[2])) | |
- print('-*-'*50) | |
+ print('-*-' * 50) | |
agi_perk.current_level += 1 | |
pprint(ep.cost_to_levelup(ep.accessible_perks()[0])) | |
pprint(ep.cost_to_levelup(ep.accessible_perks()[1])) | |
pprint(ep.cost_to_levelup(ep.accessible_perks()[2])) | |
- print('-*-'*50) | |
+ print('-*-' * 50) | |
str_perk.current_level += 1 | |
@@ -49,45 +48,44 @@ if __name__ == "__main__": | |
pprint(ep.cost_to_levelup(ep.accessible_perks()[1])) | |
pprint(ep.cost_to_levelup(ep.accessible_perks()[2])) | |
- print('-*-'*50) | |
+ print('-*-' * 50) | |
p1.current_level += 1 | |
pprint(ep.cost_to_levelup(ep.accessible_perks()[0])) | |
pprint(ep.cost_to_levelup(ep.accessible_perks()[1])) | |
pprint(ep.cost_to_levelup(ep.accessible_perks()[2])) | |
- print('-*-'*50) | |
+ print('-*-' * 50) | |
p1.current_level += 1 | |
pprint(ep.cost_to_levelup(ep.accessible_perks()[0])) | |
pprint(ep.cost_to_levelup(ep.accessible_perks()[1])) | |
pprint(ep.cost_to_levelup(ep.accessible_perks()[2])) | |
- print('-*-'*50) | |
+ print('-*-' * 50) | |
p1.current_level += 1 | |
pprint(ep.cost_to_levelup(ep.accessible_perks()[0])) | |
pprint(ep.cost_to_levelup(ep.accessible_perks()[1])) | |
pprint(ep.cost_to_levelup(ep.accessible_perks()[2])) | |
- print('-*-'*50) | |
+ print('-*-' * 50) | |
p2.current_level += 1 | |
pprint(ep.cost_to_levelup(ep.accessible_perks()[0])) | |
pprint(ep.cost_to_levelup(ep.accessible_perks()[1])) | |
pprint(ep.cost_to_levelup(ep.accessible_perks()[2])) | |
- print('-*-'*50) | |
+ print('-*-' * 50) | |
p2.current_level += 1 | |
pprint(ep.cost_to_levelup(ep.accessible_perks()[0])) | |
pprint(ep.cost_to_levelup(ep.accessible_perks()[1])) | |
pprint(ep.cost_to_levelup(ep.accessible_perks()[2])) | |
- print('-*-'*50) | |
+ print('-*-' * 50) | |
p2.current_level += 1 | |
pprint(ep.cost_to_levelup(ep.accessible_perks()[0])) | |
pprint(ep.cost_to_levelup(ep.accessible_perks()[1])) | |
pprint(ep.cost_to_levelup(ep.accessible_perks()[2])) | |
- | |
diff --git a/character/perks/everymans_perks/group_attrib.py b/character/perks/everymans_perks/group_attrib.py | |
index 6efbd89..c2d76d7 100644 | |
--- a/character/perks/everymans_perks/group_attrib.py | |
+++ b/character/perks/everymans_perks/group_attrib.py | |
@@ -1,10 +1,11 @@ | |
from mechanics.buffs import Ability | |
-#TODO packaging makes no sense? | |
+# TODO packaging makes no sense? | |
from game_objects.battlefield_objects import CharAttributes, enum_to_abbrev | |
from game_objects.attributes import Bonus, Attribute | |
from character.perks import Perk | |
from character.perks import PerkGroup | |
+ | |
def attr_bonus_abilities(attr): | |
b1 = Bonus({attr: Attribute(1, 10, 1)}) | |
b2 = Bonus({attr: Attribute(2, 20, 2)}) | |
@@ -14,19 +15,22 @@ def attr_bonus_abilities(attr): | |
a2 = Ability(b2) | |
a3 = Ability(b3) | |
- return {1:a1, 2:a2, 3:a3} | |
+ return {1: a1, 2: a2, 3: a3} | |
+ | |
def attr_perk_names(attr): | |
fmt = "Gifted: {}" | |
return { | |
- 1:fmt.format(str(attr) +" I"), | |
- 2: fmt.format(str(attr) + " II"), | |
- 3: fmt.format(str(attr) + " III")} | |
+ 1: fmt.format(str(attr) + " I"), | |
+ 2: fmt.format(str(attr) + " II"), | |
+ 3: fmt.format(str(attr) + " III")} | |
+ | |
def build_perk(attr): | |
return Perk(attr_perk_names(attr), attr_bonus_abilities(attr), | |
- # icon=os.path.join("icons", "params", "64", enum_to_abbrev[attr]) +".png" ) | |
- icon=enum_to_abbrev[attr] +".png") | |
+ # icon=os.path.join("icons", "params", "64", | |
+ # enum_to_abbrev[attr]) +".png" ) | |
+ icon=enum_to_abbrev[attr] + ".png") | |
str_perk = build_perk(CharAttributes.STREINGTH) | |
@@ -38,4 +42,5 @@ int_perk = build_perk(CharAttributes.INTELLIGENCE) | |
cha_perk = build_perk(CharAttributes.CHARISMA) | |
-pg_attributes = PerkGroup([str_perk, agi_perk, end_perk, prc_perk, int_perk, cha_perk]) | |
\ No newline at end of file | |
+pg_attributes = PerkGroup( | |
+ [str_perk, agi_perk, end_perk, prc_perk, int_perk, cha_perk]) | |
diff --git a/character/perks/everymans_perks/group_param.py b/character/perks/everymans_perks/group_param.py | |
index 772ee84..09e1964 100644 | |
--- a/character/perks/everymans_perks/group_param.py | |
+++ b/character/perks/everymans_perks/group_param.py | |
@@ -1,5 +1,5 @@ | |
from mechanics.buffs import Ability | |
-#TODO packaging makes no sense? | |
+# TODO packaging makes no sense? | |
from game_objects.battlefield_objects.CharAttributes import CharAttributes as ca, Constants as c | |
from game_objects.attributes import Bonus, Attribute | |
from character.perks import Perk | |
@@ -8,17 +8,17 @@ from character.perks import PerkGroup | |
from character.perks.everymans_perks.group_attrib import pg_attributes | |
- | |
def param_bonus_abilities(attr, base, bonus, multi): | |
b1 = Bonus({attr: Attribute(base, multi, bonus)}) | |
- b2 = Bonus({attr: Attribute(base*2, multi*2.25, bonus*2)}) | |
- b3 = Bonus({attr: Attribute(base*3, multi*4, bonus*4)}) | |
+ b2 = Bonus({attr: Attribute(base * 2, multi * 2.25, bonus * 2)}) | |
+ b3 = Bonus({attr: Attribute(base * 3, multi * 4, bonus * 4)}) | |
a1 = Ability(b1) | |
a2 = Ability(b2) | |
a3 = Ability(b3) | |
- return {1:a1, 2:a2, 3:a3} | |
+ return {1: a1, 2: a2, 3: a3} | |
+ | |
def attr_perk_names(attr): | |
fmt1 = "Unusual {}" | |
@@ -26,21 +26,46 @@ def attr_perk_names(attr): | |
fmt3 = "Incredible {}" | |
return { | |
- 1:fmt1.format(str(attr) +" I"), | |
- 2: fmt2.format(str(attr) + " II"), | |
- 3: fmt3.format(str(attr) + " III")} | |
- | |
-health_perk = Perk(attr_perk_names(ca.HEALTH), param_bonus_abilities(ca.HEALTH, 1 * c.HP_PER_END, 20, 2 * c.HP_PER_END), cost_factor=2.5) | |
- | |
-mana_perk = Perk(attr_perk_names(ca.MANA), param_bonus_abilities(ca.MANA, 2*c.MANA_PER_INT, 30, 2*c.MANA_PER_INT), cost_factor=2.5) | |
- | |
-stamina_perk = Perk(attr_perk_names(ca.STAMINA), param_bonus_abilities(ca.STAMINA, 2 * c.STAMINA_PER_STR, 30, | |
- 2 * c.STAMINA_PER_STR), cost_factor=2.5) | |
- | |
-ini_perk = Perk(attr_perk_names(ca.INITIATIVE), param_bonus_abilities(ca.INITIATIVE, 0.3, 7, 0.3), cost_factor=2.5) | |
- | |
- | |
- | |
- | |
-pg_params = PerkGroup([health_perk, mana_perk, stamina_perk, ini_perk], requirements={pg_attributes:2}) | |
- | |
+ 1: fmt1.format(str(attr) + " I"), | |
+ 2: fmt2.format(str(attr) + " II"), | |
+ 3: fmt3.format(str(attr) + " III")} | |
+ | |
+ | |
+health_perk = Perk( | |
+ attr_perk_names( | |
+ ca.HEALTH), | |
+ param_bonus_abilities( | |
+ ca.HEALTH, | |
+ 1 * c.HP_PER_END, | |
+ 20, | |
+ 2 * c.HP_PER_END), | |
+ cost_factor=2.5) | |
+ | |
+mana_perk = Perk( | |
+ attr_perk_names( | |
+ ca.MANA), | |
+ param_bonus_abilities( | |
+ ca.MANA, | |
+ 2 * c.MANA_PER_INT, | |
+ 30, | |
+ 2 * c.MANA_PER_INT), | |
+ cost_factor=2.5) | |
+ | |
+stamina_perk = Perk( | |
+ attr_perk_names( | |
+ ca.STAMINA), | |
+ param_bonus_abilities( | |
+ ca.STAMINA, | |
+ 2 * c.STAMINA_PER_STR, | |
+ 30, | |
+ 2 * c.STAMINA_PER_STR), | |
+ cost_factor=2.5) | |
+ | |
+ini_perk = Perk( | |
+ attr_perk_names( | |
+ ca.INITIATIVE), param_bonus_abilities( | |
+ ca.INITIATIVE, 0.3, 7, 0.3), cost_factor=2.5) | |
+ | |
+ | |
+pg_params = PerkGroup([health_perk, mana_perk, stamina_perk, | |
+ ini_perk], requirements={pg_attributes: 2}) | |
diff --git a/cntent/abilities/aoe_damage/ability.py b/cntent/abilities/aoe_damage/ability.py | |
index bd726a0..4138113 100644 | |
--- a/cntent/abilities/aoe_damage/ability.py | |
+++ b/cntent/abilities/aoe_damage/ability.py | |
@@ -1,11 +1,13 @@ | |
from mechanics.buffs import Ability | |
from cntent.abilities.aoe_damage.trigger import aoe_damage as aoe_trigger | |
-def trig_factory( ability: Ability): | |
+ | |
+def trig_factory(ability: Ability): | |
owner = ability.bound_to | |
- return aoe_trigger(owner, | |
- ability.radius if hasattr(ability, 'radius') else None, | |
- ability.percentage if hasattr(ability, 'percentage') else None) | |
+ return aoe_trigger( | |
+ owner, ability.radius if hasattr( | |
+ ability, 'radius') else None, ability.percentage if hasattr( | |
+ ability, 'percentage') else None) | |
def aoe_damage(radius=1.5, percentage=1.): | |
@@ -14,4 +16,4 @@ def aoe_damage(radius=1.5, percentage=1.): | |
a.radius = radius | |
a.percentage = percentage | |
return a | |
- return _ | |
\ No newline at end of file | |
+ return _ | |
diff --git a/cntent/abilities/aoe_damage/trigger.py b/cntent/abilities/aoe_damage/trigger.py | |
index 930f017..1832fa9 100644 | |
--- a/cntent/abilities/aoe_damage/trigger.py | |
+++ b/cntent/abilities/aoe_damage/trigger.py | |
@@ -3,14 +3,19 @@ from mechanics.events import DamageEvent | |
from mechanics.damage import ImpactFactor | |
-def aoe_damage_callback(t,e:DamageEvent): | |
+def aoe_damage_callback(t, e: DamageEvent): | |
bf = e.game.bf | |
target_cell = e.target.cell | |
- recipients = bf.get_units_within_radius(center=target_cell, radius=t.radius) | |
+ recipients = bf.get_units_within_radius( | |
+ center=target_cell, radius=t.radius) | |
for unit in recipients: | |
- new_e = DamageEvent(e.damage*t.percentage, unit, | |
- source=e.source, impact_factor=ImpactFactor.GRAZE, fire=False) | |
+ new_e = DamageEvent( | |
+ e.damage * t.percentage, | |
+ unit, | |
+ source=e.source, | |
+ impact_factor=ImpactFactor.GRAZE, | |
+ fire=False) | |
new_e.secondary = True | |
new_e.fire() | |
@@ -19,10 +24,10 @@ def aoe_damage(unit, radius, percentage): | |
assert radius >= 0 | |
trig = Trigger(DamageEvent, | |
platform=unit.game.events_platform, | |
- conditions=[lambda t,e : e.impact_factor is ImpactFactor.CRIT and | |
- e.source.uid == unit.uid and | |
- not hasattr(e, "secondary")], | |
- callbacks=[aoe_damage_callback]) | |
+ conditions=[lambda t, e: e.impact_factor is ImpactFactor.CRIT and | |
+ e.source.uid == unit.uid and | |
+ not hasattr(e, "secondary")], | |
+ callbacks=[aoe_damage_callback]) | |
trig.radius = radius | |
trig.percentage = percentage | |
- return trig | |
\ No newline at end of file | |
+ return trig | |
diff --git a/cntent/abilities/bash/ability.py b/cntent/abilities/bash/ability.py | |
index c2edd28..9ebc67a 100644 | |
--- a/cntent/abilities/bash/ability.py | |
+++ b/cntent/abilities/bash/ability.py | |
@@ -1,9 +1,12 @@ | |
from mechanics.buffs import Ability | |
from cntent.abilities.bash.trigger import bash as bash_trigger | |
-def trig_factory( ability: Ability): | |
+ | |
+def trig_factory(ability: Ability): | |
owner = ability.bound_to | |
- return bash_trigger(owner, ability.bash_chance if hasattr(ability, 'bash_chance') else 1) | |
+ return bash_trigger( | |
+ owner, ability.bash_chance if hasattr( | |
+ ability, 'bash_chance') else 1) | |
def bash(chance=1): | |
@@ -11,4 +14,4 @@ def bash(chance=1): | |
a = Ability(trigger_factories=[trig_factory]) | |
a.bash_chance = chance | |
return a | |
- return _ | |
\ No newline at end of file | |
+ return _ | |
diff --git a/cntent/abilities/bash/trigger.py b/cntent/abilities/bash/trigger.py | |
index 5e32e7e..0fcdb1a 100644 | |
--- a/cntent/abilities/bash/trigger.py | |
+++ b/cntent/abilities/bash/trigger.py | |
@@ -3,8 +3,7 @@ from mechanics.events import DamageEvent | |
from mechanics.damage import DamageTypeGroups | |
- | |
-def bash_callback(t,e:DamageEvent): | |
+def bash_callback(t, e: DamageEvent): | |
chance = t.chance | |
if e.game.random.random() < chance: | |
e.target.readiness -= 0.25 * e.source.str / e.target.str | |
@@ -12,10 +11,14 @@ def bash_callback(t,e:DamageEvent): | |
def bash(unit, chance): | |
assert 0 < chance <= 1 | |
- trig = Trigger(DamageEvent, | |
- platform=unit.game.events_platform, | |
- conditions=[lambda t,e : e.source.uid == unit.uid, | |
- lambda t,e: e.damage.type in DamageTypeGroups.physical], | |
- callbacks=[bash_callback]) | |
+ trig = Trigger( | |
+ DamageEvent, | |
+ platform=unit.game.events_platform, | |
+ conditions=[ | |
+ lambda t, | |
+ e: e.source.uid == unit.uid, | |
+ lambda t, | |
+ e: e.damage.type in DamageTypeGroups.physical], | |
+ callbacks=[bash_callback]) | |
trig.chance = chance | |
- return trig | |
\ No newline at end of file | |
+ return trig | |
diff --git a/cntent/abilities/battle_rage/ability.py b/cntent/abilities/battle_rage/ability.py | |
index 80bce0d..660062f 100644 | |
--- a/cntent/abilities/battle_rage/ability.py | |
+++ b/cntent/abilities/battle_rage/ability.py | |
@@ -1,9 +1,12 @@ | |
from mechanics.buffs import Ability | |
from cntent.abilities.battle_rage.trigger import battle_rage as br_trigger | |
-def trig_factory( ability: Ability): | |
+ | |
+def trig_factory(ability: Ability): | |
owner = ability.bound_to | |
- return br_trigger(owner, ability.rage_chance if hasattr(ability, 'rage_chance') else 1) | |
+ return br_trigger( | |
+ owner, ability.rage_chance if hasattr( | |
+ ability, 'rage_chance') else 1) | |
def battle_rage(chance=1): | |
@@ -11,4 +14,4 @@ def battle_rage(chance=1): | |
a = Ability(trigger_factories=[trig_factory]) | |
a.rage_chance = chance | |
return a | |
- return _ | |
\ No newline at end of file | |
+ return _ | |
diff --git a/cntent/abilities/battle_rage/trigger.py b/cntent/abilities/battle_rage/trigger.py | |
index d75157f..b0da3f2 100644 | |
--- a/cntent/abilities/battle_rage/trigger.py | |
+++ b/cntent/abilities/battle_rage/trigger.py | |
@@ -6,15 +6,15 @@ from game_objects.battlefield_objects import CharAttributes as ca | |
from mechanics.buffs import Buff | |
-def battle_rage_callback(t,e:DamageEvent): | |
+def battle_rage_callback(t, e: DamageEvent): | |
chance = t.chance | |
if e.game.random.random() < chance: | |
BuffAppliedEvent( | |
Buff(8, bonus=Bonus( | |
- {ca.STREINGTH: Attribute(1, 5, 0), | |
- ca.ENDURANCE: Attribute(1, 5, 0), | |
- ca.AGILITY: Attribute(1, 5, 0), | |
- ca.PERCEPTION: Attribute(-1, -5, 0)})), | |
+ {ca.STREINGTH: Attribute(1, 5, 0), | |
+ ca.ENDURANCE: Attribute(1, 5, 0), | |
+ ca.AGILITY: Attribute(1, 5, 0), | |
+ ca.PERCEPTION: Attribute(-1, -5, 0)})), | |
e.target) | |
@@ -22,7 +22,7 @@ def battle_rage(unit, chance): | |
assert 0 < chance <= 1 | |
trig = Trigger(DamageEvent, | |
platform=unit.game.events_platform, | |
- conditions=[lambda t,e : e.target.uid == unit.uid], | |
- callbacks=[battle_rage_callback]) | |
+ conditions=[lambda t, e: e.target.uid == unit.uid], | |
+ callbacks=[battle_rage_callback]) | |
trig.chance = chance | |
- return trig | |
\ No newline at end of file | |
+ return trig | |
diff --git a/cntent/abilities/generic/ability.py b/cntent/abilities/generic/ability.py | |
index ad6cca9..fcbd159 100644 | |
--- a/cntent/abilities/generic/ability.py | |
+++ b/cntent/abilities/generic/ability.py | |
@@ -3,12 +3,10 @@ from game_objects.attributes import Bonus, Attribute | |
from game_objects.battlefield_objects import CharAttributes as ca | |
+def fat(): return Ability(bonus=Bonus({ca.HEALTH: Attribute(0, 60, 0), | |
+ ca.INITIATIVE: Attribute(0, -30, 0)})) | |
-fat = lambda : Ability(bonus=Bonus({ca.HEALTH: Attribute(0, 60, 0), | |
- ca.INITIATIVE: Attribute(0, -30, 0)})) | |
def evasive(base, mult, bonus): | |
- return lambda : Ability(bonus=Bonus({ca.EVASION: Attribute(base, mult, bonus)})) | |
- | |
- | |
- | |
+ return lambda: Ability(bonus=Bonus( | |
+ {ca.EVASION: Attribute(base, mult, bonus)})) | |
diff --git a/cntent/abilities/mana_drain/ability.py b/cntent/abilities/mana_drain/ability.py | |
index e147a8f..bab255e 100644 | |
--- a/cntent/abilities/mana_drain/ability.py | |
+++ b/cntent/abilities/mana_drain/ability.py | |
@@ -6,9 +6,13 @@ PCT_DRAIN = "percentage_drain" | |
PCT_HEAL = "percentage_heal" | |
-def trig_factory( ability: Ability): | |
+def trig_factory(ability: Ability): | |
owner = ability.bound_to | |
- return build_mana_drain_trigger(owner, getattr(ability, AMOUNT), getattr(ability, PCT_DRAIN), getattr(ability, PCT_HEAL)) | |
+ return build_mana_drain_trigger( | |
+ owner, getattr( | |
+ ability, AMOUNT), getattr( | |
+ ability, PCT_DRAIN), getattr( | |
+ ability, PCT_HEAL)) | |
def mana_drain(amount, percentage_drain, percentage_heal): | |
@@ -21,5 +25,3 @@ def mana_drain(amount, percentage_drain, percentage_heal): | |
return a | |
return _ | |
- | |
- | |
diff --git a/cntent/abilities/mana_drain/trigger.py b/cntent/abilities/mana_drain/trigger.py | |
index 06fd981..60877cf 100644 | |
--- a/cntent/abilities/mana_drain/trigger.py | |
+++ b/cntent/abilities/mana_drain/trigger.py | |
@@ -4,11 +4,11 @@ from mechanics.events import DamageEvent, HealingEvent | |
def mana_drain_callback(amount, percentage_mana_drained, percentage_healed): | |
- def _drain_cb(t,e:DamageEvent): | |
+ def _drain_cb(t, e: DamageEvent): | |
mana_initially = e.target.mana | |
- e.target.mana -= ( e.target.mana * percentage_mana_drained + amount) | |
+ e.target.mana -= (e.target.mana * percentage_mana_drained + amount) | |
drained = mana_initially - e.target.mana | |
healed = drained * percentage_healed | |
@@ -17,16 +17,14 @@ def mana_drain_callback(amount, percentage_mana_drained, percentage_healed): | |
return _drain_cb | |
-def build_mana_drain_trigger(unit, amount, percentage_drain, percentage_heal): | |
+def build_mana_drain_trigger(unit, amount, percentage_drain, percentage_heal): | |
cb = mana_drain_callback(amount, percentage_drain, percentage_heal) | |
trig = Trigger(DamageEvent, | |
- platform=unit.game.events_platform, | |
- conditions={lambda t,e : e.source.uid == unit.uid, | |
- lambda t,e: e.amount > 0}, | |
- callbacks=[cb]) | |
+ platform=unit.game.events_platform, | |
+ conditions={lambda t, e: e.source.uid == unit.uid, | |
+ lambda t, e: e.amount > 0}, | |
+ callbacks=[cb]) | |
return trig | |
- | |
- | |
diff --git a/cntent/abilities/undead/ability.py b/cntent/abilities/undead/ability.py | |
index ded5fc9..96f395b 100644 | |
--- a/cntent/abilities/undead/ability.py | |
+++ b/cntent/abilities/undead/ability.py | |
@@ -5,17 +5,16 @@ from game_objects.battlefield_objects import CharAttributes as ca | |
UNDEAD_N_HITS = "undead_n_hits" | |
-def trig_factory( ability: Ability): | |
+ | |
+def trig_factory(ability: Ability): | |
owner = ability.bound_to | |
return undead_trigger(owner, getattr(ability, UNDEAD_N_HITS)) | |
def undying(n): | |
def _(): | |
- a = Ability(bonus=Bonus({ca.STAMINA: Attribute(10, 200, 0), ca.INITIATIVE: Attribute(0, -25, 0)}), | |
- trigger_factories=[trig_factory]) | |
+ a = Ability(bonus=Bonus({ca.STAMINA: Attribute(10, 200, 0), ca.INITIATIVE: Attribute( | |
+ 0, -25, 0)}), trigger_factories=[trig_factory]) | |
setattr(a, UNDEAD_N_HITS, n) | |
return a | |
return _ | |
- | |
- | |
diff --git a/cntent/abilities/undead/trigger.py b/cntent/abilities/undead/trigger.py | |
index d40f7d8..1ada63a 100644 | |
--- a/cntent/abilities/undead/trigger.py | |
+++ b/cntent/abilities/undead/trigger.py | |
@@ -2,27 +2,33 @@ from mechanics.events import PermanentInterrupt, CounteredInterrupt | |
from mechanics.events import UnitDiedEvent | |
from mechanics.events import DamageEvent | |
+ | |
def immortality(unit): | |
trig = PermanentInterrupt(UnitDiedEvent, | |
platform=unit.game.events_platform, | |
- conditions={lambda t,e : e.unit.uid == unit.uid}) | |
+ conditions={lambda t, e: e.unit.uid == unit.uid}) | |
return trig | |
-def give_1_hp_cb(t,e): | |
+ | |
+def give_1_hp_cb(t, e): | |
e.unit.health += 1 | |
+ | |
def undead_n_hits(unit, n_hits): | |
trig = CounteredInterrupt(UnitDiedEvent, | |
platform=unit.game.events_platform, | |
- conditions={lambda t,e : e.unit.uid == unit.uid}, | |
+ conditions={lambda t, e: e.unit.uid == unit.uid}, | |
callbacks=[give_1_hp_cb], | |
n_counters=n_hits) | |
return trig | |
def refraction(unit, n_hits): | |
- trig = CounteredInterrupt(DamageEvent, | |
- platform=unit.game.events_platform, | |
- conditions={lambda t,e : e.target.uid == unit.uid}, | |
- n_counters=n_hits) | |
- return trig | |
\ No newline at end of file | |
+ trig = CounteredInterrupt( | |
+ DamageEvent, | |
+ platform=unit.game.events_platform, | |
+ conditions={ | |
+ lambda t, | |
+ e: e.target.uid == unit.uid}, | |
+ n_counters=n_hits) | |
+ return trig | |
diff --git a/cntent/actives/callbacks/callbacks_consumables.py b/cntent/actives/callbacks/callbacks_consumables.py | |
index 569e1d2..fa038e9 100644 | |
--- a/cntent/actives/callbacks/callbacks_consumables.py | |
+++ b/cntent/actives/callbacks/callbacks_consumables.py | |
@@ -6,20 +6,18 @@ if TYPE_CHECKING: | |
def healing_potion_cb(amount): | |
- def _(active :Active, target :None): | |
+ def _(active: Active, target: None): | |
HealingEvent(amount, active.owner) | |
return _ | |
+ | |
def mana_potion_cb(amount): | |
- def _(active :Active, target :None): | |
+ def _(active: Active, target: None): | |
active.owner.mana += amount | |
return _ | |
+ | |
def stamina_potion_cb(amount): | |
- def _(active :Active, target :None): | |
+ def _(active: Active, target: None): | |
active.owner.stamina += amount | |
return _ | |
- | |
- | |
- | |
- | |
diff --git a/cntent/actives/conditions/conditions.py b/cntent/actives/conditions/conditions.py | |
index 3802d58..3fff990 100644 | |
--- a/cntent/actives/conditions/conditions.py | |
+++ b/cntent/actives/conditions/conditions.py | |
@@ -12,16 +12,21 @@ def proximity_condition(max_distance): | |
return c | |
+ | |
def range_condition(min_dist, max_dist): | |
def _(active, target): | |
- return min_dist <= active.game.bf.distance(active.owner, target) <= max_dist | |
+ return min_dist <= active.game.bf.distance( | |
+ active.owner, target) <= max_dist | |
- c = ActiveCondition("Range", _, | |
- f"Distance to target must be in range [{min_dist},{max_dist}].") | |
+ c = ActiveCondition( | |
+ "Range", | |
+ _, | |
+ f"Distance to target must be in range [{min_dist},{max_dist}].") | |
return c | |
+ | |
def __get_angle(active, target): | |
target_cell = target if isinstance(target, Cell) else target.cell | |
return Battlefield.angle_to(active.owner, target_cell) | |
@@ -32,24 +37,33 @@ def within_angle(max_angle_inkl): | |
_angle = __get_angle(active, targeting)[0] | |
return _angle <= max_angle_inkl | |
- c = ActiveCondition("Within angle", _, | |
- f"You must face at most {max_angle_inkl} away from the direction to the target") | |
+ c = ActiveCondition( | |
+ "Within angle", | |
+ _, | |
+ f"You must face at most {max_angle_inkl} away from the direction to the target") | |
return c | |
+ | |
def between_angles(ang_min, ang_max): | |
def _(active, targeting): | |
_angle = __get_angle(active, targeting)[0] | |
return ang_min <= _angle <= ang_max | |
- c = ActiveCondition("Angle range", _, | |
- f"Angle to target must be in range [{ang_min},{ang_max}].") | |
+ c = ActiveCondition( | |
+ "Angle range", | |
+ _, | |
+ f"Angle to target must be in range [{ang_min},{ang_max}].") | |
return c | |
+ | |
def _can_move_to_target_cell(active, cell): | |
e = MovementEvent(active.owner, cell, fire=False) | |
return e.check_conditions() | |
-can_move_to_target_cell = ActiveCondition("Movement possible", _can_move_to_target_cell, | |
- "Can't move to the cell {target}") | |
\ No newline at end of file | |
+ | |
+can_move_to_target_cell = ActiveCondition( | |
+ "Movement possible", | |
+ _can_move_to_target_cell, | |
+ "Can't move to the cell {target}") | |
diff --git a/cntent/actives/std/buffs/std_buffs.py b/cntent/actives/std/buffs/std_buffs.py | |
index af90f66..9ed4c96 100644 | |
--- a/cntent/actives/std/buffs/std_buffs.py | |
+++ b/cntent/actives/std/buffs/std_buffs.py | |
@@ -4,13 +4,13 @@ from game_objects.battlefield_objects import CharAttributes as ca | |
from mechanics.buffs import Buff | |
- | |
def rest_buff(): | |
return Buff(2, bonus=Bonus( | |
{ca.EVASION: Attribute(0, -35, 0), | |
ca.PRECISION: Attribute(0, -50, 0)})) | |
+ | |
def onguard_buff(): | |
return Buff(2.5, bonus=Bonus( | |
- {ca.EVASION: Attribute(0, 50, 0), | |
- ca.PRECISION: Attribute(0, 10, 0)})) | |
\ No newline at end of file | |
+ {ca.EVASION: Attribute(0, 50, 0), | |
+ ca.PRECISION: Attribute(0, 10, 0)})) | |
diff --git a/cntent/actives/std/callbacks/callbacks.py b/cntent/actives/std/callbacks/callbacks.py | |
index 5011b5f..e7ad01a 100644 | |
--- a/cntent/actives/std/callbacks/callbacks.py | |
+++ b/cntent/actives/std/callbacks/callbacks.py | |
@@ -8,26 +8,29 @@ if TYPE_CHECKING: | |
from game_objects.battlefield_objects import Unit | |
- | |
-def attack_callback(active :Active, target :Unit): | |
+def attack_callback(active: Active, target: Unit): | |
Attack.melee_attack(source=active.owner, target=target) | |
-def attack_on_cell_callback(active :Active, target :Cell): | |
+ | |
+def attack_on_cell_callback(active: Active, target: Cell): | |
units_on_target_cell = active.game.bf.get_objects_at(target) | |
if units_on_target_cell: | |
chosen_target = active.game.random.choice(units_on_target_cell) | |
Attack.melee_attack(source=active.owner, target=chosen_target) | |
-def ranged_attack_cb(active :Active, target :Unit): | |
+ | |
+def ranged_attack_cb(active: Active, target: Unit): | |
RangedAttack.ranged_attack(source=active.owner, target=target) | |
def move_on_target_cell(active: Active, target: Cell): | |
MovementEvent(active.owner, target) | |
+ | |
def turn_ccw_callback(active: Active, _): | |
TurnEvent(active.owner, ccw=True) | |
+ | |
def turn_cw_callback(active: Active, _): | |
TurnEvent(active.owner, ccw=False) | |
diff --git a/cntent/actives/std/callbacks/callbacks_misc.py b/cntent/actives/std/callbacks/callbacks_misc.py | |
index 2b405b0..d8f5161 100644 | |
--- a/cntent/actives/std/callbacks/callbacks_misc.py | |
+++ b/cntent/actives/std/callbacks/callbacks_misc.py | |
@@ -1,20 +1,17 @@ | |
from __future__ import annotations | |
+from cntent.actives.std.buffs.std_buffs import rest_buff, onguard_buff | |
from mechanics.events import BuffAppliedEvent | |
from typing import TYPE_CHECKING | |
if TYPE_CHECKING: | |
from mechanics.actives import Active | |
-from cntent.actives.std.buffs.std_buffs import rest_buff, onguard_buff | |
- | |
- | |
-def onguard_callback(active :Active, target :None): | |
+def onguard_callback(active: Active, target: None): | |
BuffAppliedEvent(onguard_buff(), active.owner) | |
-def rest_callback(active :Active, target :None): | |
+ | |
+def rest_callback(active: Active, target: None): | |
active.owner.mana += active.owner.max_mana / 20 | |
active.owner.stamina += active.owner.max_stamina / 10 | |
BuffAppliedEvent(rest_buff(), active.owner) | |
- | |
- | |
diff --git a/cntent/actives/std/std_melee_attack.py b/cntent/actives/std/std_melee_attack.py | |
index 3074242..35a6662 100644 | |
--- a/cntent/actives/std/std_melee_attack.py | |
+++ b/cntent/actives/std/std_melee_attack.py | |
@@ -8,7 +8,8 @@ from cntent.actives.std.callbacks.callbacks import attack_callback, attack_on_ce | |
from cntent.actives.conditions.conditions import proximity_condition, within_angle | |
-std_attack_cost = lambda self: Cost(stamina=1)*self.owner.get_melee_weapon().atb_factor | |
+def std_attack_cost(self): return Cost(stamina=1) * \ | |
+ self.owner.get_melee_weapon().atb_factor | |
attack_unit_active = Active(BattlefieldObject, | |
@@ -28,8 +29,3 @@ attack_cell_active = Active(Cell, | |
name="Attack Cell") | |
std_attacks = [attack_unit_active] | |
- | |
- | |
- | |
- | |
- | |
diff --git a/cntent/actives/std/std_misc.py b/cntent/actives/std/std_misc.py | |
index 6c946f6..c4240bd 100644 | |
--- a/cntent/actives/std/std_misc.py | |
+++ b/cntent/actives/std/std_misc.py | |
@@ -4,25 +4,26 @@ from mechanics.actives import Cost | |
from cntent.actives.std.callbacks.callbacks_misc import onguard_callback, rest_callback | |
- | |
- | |
wait_active = Active(None, | |
- [], | |
- Cost(readiness=0.15), | |
- game=None, | |
- callbacks=[], | |
- tags=[ActiveTags.WAIT], | |
- name="Wait") | |
+ [], | |
+ Cost(readiness=0.15), | |
+ game=None, | |
+ callbacks=[], | |
+ tags=[ActiveTags.WAIT], | |
+ name="Wait") | |
onguard_active = Active(None, | |
- [], | |
- Cost(readiness=0.4), | |
- game=None, | |
- callbacks=[onguard_callback], | |
- tags=[ActiveTags.DEFEND], | |
- name="Prepare to defend") | |
+ [], | |
+ Cost(readiness=0.4), | |
+ game=None, | |
+ callbacks=[onguard_callback], | |
+ tags=[ActiveTags.DEFEND], | |
+ name="Prepare to defend") | |
+ | |
+ | |
+def fixed_rest_cost(self): return Cost( | |
+ readiness=1) * (self.owner.initiative / 10) | |
-fixed_rest_cost = lambda self: Cost(readiness=1) * ( self.owner.initiative / 10) | |
rest_active = Active(None, | |
[], | |
@@ -31,9 +32,3 @@ rest_active = Active(None, | |
callbacks=[rest_callback], | |
tags=[ActiveTags.RESTORATION], | |
name="Rest") | |
- | |
- | |
- | |
- | |
- | |
- | |
diff --git a/cntent/actives/std/std_movements.py b/cntent/actives/std/std_movements.py | |
index 7da9c57..038698a 100644 | |
--- a/cntent/actives/std/std_movements.py | |
+++ b/cntent/actives/std/std_movements.py | |
@@ -18,7 +18,7 @@ move_forward = Active(Cell, | |
simulate=sim_move_on_target_cell) | |
move_diag = Active(Cell, | |
- [proximity_condition(1.5), between_angles(1,89), can_move_to_target_cell], | |
+ [proximity_condition(1.5), between_angles(1, 89), can_move_to_target_cell], | |
Cost(stamina=2, readiness=0.6), | |
game=None, | |
callbacks=[move_on_target_cell], | |
@@ -27,7 +27,7 @@ move_diag = Active(Cell, | |
simulate=sim_move_on_target_cell) | |
move_side = Active(Cell, | |
- [proximity_condition(1), between_angles(89,91), can_move_to_target_cell], | |
+ [proximity_condition(1), between_angles(89, 91), can_move_to_target_cell], | |
Cost(stamina=1, readiness=0.5), | |
game=None, | |
callbacks=[move_on_target_cell], | |
@@ -35,14 +35,12 @@ move_side = Active(Cell, | |
name="move to the side", | |
simulate=sim_move_on_target_cell) | |
-move_back = Active(Cell, | |
- [proximity_condition(1), between_angles(180,180), can_move_to_target_cell], | |
- Cost(stamina=1, readiness=0.6), | |
- game=None, | |
- callbacks=[move_on_target_cell], | |
- tags=[ActiveTags.MOVEMENT], | |
- name="move back", | |
- simulate=sim_move_on_target_cell) | |
+move_back = Active( | |
+ Cell, [ | |
+ proximity_condition(1), between_angles( | |
+ 180, 180), can_move_to_target_cell], Cost( | |
+ stamina=1, readiness=0.6), game=None, callbacks=[move_on_target_cell], tags=[ | |
+ ActiveTags.MOVEMENT], name="move back", simulate=sim_move_on_target_cell) | |
turn_cw = Active(None, | |
None, | |
@@ -51,16 +49,16 @@ turn_cw = Active(None, | |
callbacks=[turn_cw_callback], | |
tags=[ActiveTags.TURNING], | |
name="turn CW", | |
- simulate=sim_turn(ccw=False)) | |
+ simulate=sim_turn(ccw=False)) | |
turn_ccw = Active(None, | |
- None, | |
- Cost(readiness=0.2), | |
- game=None, | |
- callbacks=[turn_ccw_callback], | |
- tags=[ActiveTags.TURNING], | |
- name="turn CCW", | |
- simulate=sim_turn(ccw=True)) | |
+ None, | |
+ Cost(readiness=0.2), | |
+ game=None, | |
+ callbacks=[turn_ccw_callback], | |
+ tags=[ActiveTags.TURNING], | |
+ name="turn CCW", | |
+ simulate=sim_turn(ccw=True)) | |
std_movements = [move_back, move_diag, move_forward, move_side] | |
diff --git a/cntent/actives/std/std_ranged_attack.py b/cntent/actives/std/std_ranged_attack.py | |
index 0d0c07b..b0d5630 100644 | |
--- a/cntent/actives/std/std_ranged_attack.py | |
+++ b/cntent/actives/std/std_ranged_attack.py | |
@@ -7,7 +7,8 @@ from cntent.actives.std.callbacks.callbacks import ranged_attack_cb | |
from cntent.actives.conditions.conditions import range_condition, within_angle | |
-std_ranged_cost = lambda self: Cost(stamina=1) * self.owner.get_ranged_weapon().atb_factor | |
+def std_ranged_cost(self): return Cost(stamina=1) * \ | |
+ self.owner.get_ranged_weapon().atb_factor | |
bow_shot_active = Active(BattlefieldObject, | |
@@ -25,8 +26,3 @@ crossbow_shot_active = Active(BattlefieldObject, | |
callbacks=[ranged_attack_cb], | |
tags=[ActiveTags.RANGED, ActiveTags.ATTACK], | |
name="Crossbow shot") | |
- | |
- | |
- | |
- | |
- | |
diff --git a/cntent/actives/temp_simulation.py b/cntent/actives/temp_simulation.py | |
index 6a3d3cf..612234b 100644 | |
--- a/cntent/actives/temp_simulation.py | |
+++ b/cntent/actives/temp_simulation.py | |
@@ -5,6 +5,7 @@ from game_objects.battlefield_objects import BattlefieldObject | |
from contextlib import contextmanager | |
import mechanics.AI.SimUtils as SimUtils | |
+ | |
@contextmanager | |
def sim_move_on_target_cell(active: Active, target: Cell): | |
unit = active.owner | |
@@ -47,5 +48,3 @@ def sim_turn(ccw): | |
unit.facing = facing_before | |
return _ | |
- | |
- | |
diff --git a/cntent/base_types/demo_hero.py b/cntent/base_types/demo_hero.py | |
index 728117b..2cc424a 100644 | |
--- a/cntent/base_types/demo_hero.py | |
+++ b/cntent/base_types/demo_hero.py | |
@@ -1,5 +1,9 @@ | |
+from game_objects.battlefield_objects import BattlefieldObject | |
+from mechanics.actives import Cost | |
+from mechanics.actives import Active, ActiveTags | |
from game_objects.battlefield_objects.BaseType import BaseType | |
+ | |
class hero_sound_map: | |
move = "SftStep3.wav" | |
hit = "c_skeleton_hit2.mp3" | |
@@ -7,13 +11,9 @@ class hero_sound_map: | |
perish = "c_skeleton_death.mp3" | |
-from mechanics.actives import Active, ActiveTags | |
-from mechanics.actives import Cost | |
-from game_objects.battlefield_objects import BattlefieldObject | |
+def imba_dmg_callback(a, unit): return unit.lose_health(99999, a.owner) | |
-imba_dmg_callback = lambda a, unit: unit.lose_health(99999, a.owner) | |
- | |
imba_active = Active(BattlefieldObject, | |
[], | |
Cost(readiness=0.1), | |
@@ -21,5 +21,10 @@ imba_active = Active(BattlefieldObject, | |
tags=[ActiveTags.ATTACK], | |
name="imba", cooldown=5) | |
-demohero_basetype = BaseType({'str':25, 'agi': 20,'end': 25, 'prc': 25}, "Demo Hero", icon="hero.png", sound_map=hero_sound_map) | |
- | |
+demohero_basetype = BaseType({'str': 25, | |
+ 'agi': 20, | |
+ 'end': 25, | |
+ 'prc': 25}, | |
+ "Demo Hero", | |
+ icon="hero.png", | |
+ sound_map=hero_sound_map) | |
diff --git a/cntent/base_types/doors.py b/cntent/base_types/doors.py | |
index a0bc6c5..96822b5 100644 | |
--- a/cntent/base_types/doors.py | |
+++ b/cntent/base_types/doors.py | |
@@ -1,3 +1,5 @@ | |
from game_objects.battlefield_objects import Obstacle | |
-wooden_door = lambda : Obstacle("Wooden door", 250, armor=10, resists={}, icon="door.png") | |
\ No newline at end of file | |
+ | |
+def wooden_door(): return Obstacle("Wooden door", 250, | |
+ armor=10, resists={}, icon="door.png") | |
diff --git a/cntent/base_types/mud_golem.py b/cntent/base_types/mud_golem.py | |
index 78bfdd3..ecd0b71 100644 | |
--- a/cntent/base_types/mud_golem.py | |
+++ b/cntent/base_types/mud_golem.py | |
@@ -1,7 +1,8 @@ | |
from game_objects.battlefield_objects.BaseType import BaseType | |
from mechanics.damage import DamageTypeGroups | |
-resists = {x:0.6 for x in DamageTypeGroups.physical} | |
-resists.update({x:-0.5 for x in DamageTypeGroups.elemental}) | |
+resists = {x: 0.6 for x in DamageTypeGroups.physical} | |
+resists.update({x: -0.5 for x in DamageTypeGroups.elemental}) | |
-mud_golem_basetype = BaseType({'str':17, 'agi':4, 'int':0}, "Mud Golem", resists=resists, icon="golem.png") | |
\ No newline at end of file | |
+mud_golem_basetype = BaseType( | |
+ {'str': 17, 'agi': 4, 'int': 0}, "Mud Golem", resists=resists, icon="golem.png") | |
diff --git a/cntent/base_types/walls.py b/cntent/base_types/walls.py | |
index d62f1d0..9f40ccc 100644 | |
--- a/cntent/base_types/walls.py | |
+++ b/cntent/base_types/walls.py | |
@@ -2,7 +2,13 @@ from game_objects.battlefield_objects import Obstacle | |
from mechanics.damage import DamageTypeGroups | |
-resists = {x:-0.6 for x in DamageTypeGroups.physical} | |
-resists.update({x:0.75 for x in DamageTypeGroups.elemental}) | |
+resists = {x: -0.6 for x in DamageTypeGroups.physical} | |
+resists.update({x: 0.75 for x in DamageTypeGroups.elemental}) | |
-mud_wall = lambda : Obstacle("Wall of mud", 5000, armor=50, resists=resists, icon="wall.png") | |
\ No newline at end of file | |
+ | |
+def mud_wall(): return Obstacle( | |
+ "Wall of mud", | |
+ 5000, | |
+ armor=50, | |
+ resists=resists, | |
+ icon="wall.png") | |
diff --git a/cntent/dungeons/dark_wood.py b/cntent/dungeons/dark_wood.py | |
index a9703e3..da36d85 100644 | |
--- a/cntent/dungeons/dark_wood.py | |
+++ b/cntent/dungeons/dark_wood.py | |
@@ -4,13 +4,13 @@ from game_objects.dungeon.Dungeon import Dungeon | |
def build_units(g): | |
- werewolf_band = [werewolf.create(g, 3+3j), | |
- werewolf.create(g, 6+6j), | |
- werewolf.create(g, 3+6j)] | |
+ werewolf_band = [werewolf.create(g, 3 + 3j), | |
+ werewolf.create(g, 6 + 6j), | |
+ werewolf.create(g, 3 + 6j)] | |
return werewolf_band | |
dark_wood = Dungeon("Dark Wood", 8, 8, | |
construct_objs=build_units, | |
hero_entrance=Cell(3, 4), | |
- icon="dark_wood.jpg") | |
\ No newline at end of file | |
+ icon="dark_wood.jpg") | |
diff --git a/cntent/dungeons/demo_dungeon.py b/cntent/dungeons/demo_dungeon.py | |
index 2562028..1996aba 100644 | |
--- a/cntent/dungeons/demo_dungeon.py | |
+++ b/cntent/dungeons/demo_dungeon.py | |
@@ -8,10 +8,18 @@ from mechanics.factions import Faction | |
def create_monsters(g): | |
monsters = [pirate_scum.create(g, Cell(4, 4)), | |
- pirate_scum.create(g, Cell(4, 5)), | |
- pirate_scum.create(g, Cell(5, 4)), | |
- Unit(mud_golem_basetype, cell=Cell(3, 3))] | |
+ pirate_scum.create(g, Cell(4, 5)), | |
+ pirate_scum.create(g, Cell(5, 4)), | |
+ Unit(mud_golem_basetype, cell=Cell(3, 3))] | |
return monsters | |
-demo_dungeon = Dungeon("Pirate Bar", 16, 16, construct_objs=create_monsters, hero_entrance=Cell(3, 4), icon="pirates_1.jpg") | |
+demo_dungeon = Dungeon( | |
+ "Pirate Bar", | |
+ 16, | |
+ 16, | |
+ construct_objs=create_monsters, | |
+ hero_entrance=Cell( | |
+ 3, | |
+ 4), | |
+ icon="pirates_1.jpg") | |
diff --git a/cntent/dungeons/demo_dungeon_walls.py b/cntent/dungeons/demo_dungeon_walls.py | |
index 1735a31..c771629 100644 | |
--- a/cntent/dungeons/demo_dungeon_walls.py | |
+++ b/cntent/dungeons/demo_dungeon_walls.py | |
@@ -5,6 +5,7 @@ from game_objects.battlefield_objects import Unit | |
from game_objects.dungeon.Dungeon import Dungeon | |
from game_objects.battlefield_objects import Wall | |
+ | |
def create_units(g): | |
pirate_band = [Unit(pirate_basetype) for i in range(3)] | |
locations = [Cell(4, 4), Cell(4, 5), Cell(5, 4)] | |
@@ -13,19 +14,18 @@ def create_units(g): | |
unit_locations[Unit(mud_golem_basetype)] = Cell(11, 0) | |
- for u,c in unit_locations.items(): | |
+ for u, c in unit_locations.items(): | |
u.cell = c | |
return list(unit_locations.keys()) | |
+ | |
def create_walls(): | |
return [Wall(cell=Cell(8, y)) for y in range(9)] | |
- | |
walls_dungeon = Dungeon("Great Wall", 12, 12, | |
construct_objs=create_units, | |
construct_walls=create_walls, | |
hero_entrance=Cell(3, 4), | |
icon="pirates_2.jpg") | |
- | |
diff --git a/cntent/dungeons/pirate_lair.py b/cntent/dungeons/pirate_lair.py | |
index 139aa22..9874456 100644 | |
--- a/cntent/dungeons/pirate_lair.py | |
+++ b/cntent/dungeons/pirate_lair.py | |
@@ -1,8 +1,10 @@ | |
+from game_objects.battlefield_objects import Wall | |
from battlefield.Battlefield import Cell | |
from game_objects.dungeon.Dungeon import Dungeon | |
from cntent.monsters.pirates import pirate_scum, pirate_boatswain, pirate_captain | |
+ | |
def create_units(g): | |
unit_locations = {} | |
@@ -10,41 +12,39 @@ def create_units(g): | |
locations = [Cell(4, 4), Cell(4, 5), Cell(5, 4)] | |
unit_locations.update({pirate_band[i]: locations[i] for i in range(3)}) | |
- unit_locations[pirate_boatswain.create(g)] = Cell(6,6) | |
- | |
+ unit_locations[pirate_boatswain.create(g)] = Cell(6, 6) | |
pirate_band = [pirate_scum.create(g) for i in range(3)] | |
locations = [Cell(4, 12), Cell(4, 13), Cell(5, 12)] | |
unit_locations.update({pirate_band[i]: locations[i] for i in range(3)}) | |
- unit_locations[pirate_boatswain.create(g)] = Cell(6,12) | |
+ unit_locations[pirate_boatswain.create(g)] = Cell(6, 12) | |
+ unit_locations[pirate_boatswain.create(g)] = Cell(12, 12) | |
+ unit_locations[pirate_boatswain.create(g)] = Cell(13, 12) | |
- unit_locations[pirate_boatswain.create(g)] = Cell(12,12) | |
- unit_locations[pirate_boatswain.create(g)] = Cell(13,12) | |
- | |
- unit_locations[pirate_captain.create(g)] = Cell(14,4) | |
+ unit_locations[pirate_captain.create(g)] = Cell(14, 4) | |
for u, c in unit_locations.items(): | |
u.cell = c | |
return list(unit_locations.keys()) | |
-from game_objects.battlefield_objects import Wall | |
+ | |
def create_walls(): | |
walls = [] | |
# split into 2 areas | |
- walls += [Wall(cell=Cell(8, y)) for y in set(range(0,15)) - {12}] | |
+ walls += [Wall(cell=Cell(8, y)) for y in set(range(0, 15)) - {12}] | |
# unit_locations[wooden_door()] = Cell(wall_x, 12) | |
# 2 rooms in area 1 | |
- walls += [Wall(cell=Cell(x, 8)) for x in set(range(0,8)) - {4}] | |
+ walls += [Wall(cell=Cell(x, 8)) for x in set(range(0, 8)) - {4}] | |
# unit_locations[wooden_door()] = Cell(4, wall_y) | |
# captains room in area 2 | |
- walls += [Wall(cell=Cell(11, y)) for y in set(range(0,6)) - {4}] | |
- walls += [Wall(cell=Cell(x, 6)) for x in range(11,16)] | |
+ walls += [Wall(cell=Cell(11, y)) for y in set(range(0, 6)) - {4}] | |
+ walls += [Wall(cell=Cell(x, 6)) for x in range(11, 16)] | |
# unit_locations[wooden_door()] = Cell(wall_x, 4) | |
return walls | |
@@ -55,7 +55,3 @@ pirate_lair = Dungeon("Pirate headquaters", 16, 16, | |
construct_walls=create_walls, | |
hero_entrance=Cell(2, 0), | |
icon="pirates_3.jpg") | |
- | |
- | |
- | |
- | |
diff --git a/cntent/dungeons/small_graveyard.py b/cntent/dungeons/small_graveyard.py | |
index d36b000..a74b92d 100644 | |
--- a/cntent/dungeons/small_graveyard.py | |
+++ b/cntent/dungeons/small_graveyard.py | |
@@ -4,13 +4,19 @@ from game_objects.dungeon.Dungeon import Dungeon | |
def build_unit_locations(g): | |
- monsters = [skeleton.create(g, 1+1j), | |
- skeleton.create(g, 1+7j), | |
- zombie.create(g, 4+4j)] | |
- | |
+ monsters = [skeleton.create(g, 1 + 1j), | |
+ skeleton.create(g, 1 + 7j), | |
+ zombie.create(g, 4 + 4j)] | |
return monsters | |
- | |
-small_graveyard = Dungeon("Haunted Graveyard", 8, 8, construct_objs=build_unit_locations, hero_entrance=Cell(3, 4), icon="undead.jpg") | |
+small_graveyard = Dungeon( | |
+ "Haunted Graveyard", | |
+ 8, | |
+ 8, | |
+ construct_objs=build_unit_locations, | |
+ hero_entrance=Cell( | |
+ 3, | |
+ 4), | |
+ icon="undead.jpg") | |
diff --git a/cntent/dungeons/small_orc_cave.py b/cntent/dungeons/small_orc_cave.py | |
index f17cb93..ea6cd84 100644 | |
--- a/cntent/dungeons/small_orc_cave.py | |
+++ b/cntent/dungeons/small_orc_cave.py | |
@@ -3,12 +3,19 @@ from cntent.monsters.greenskins import goblin, orc, ogre | |
from game_objects.dungeon.Dungeon import Dungeon | |
- | |
def build_unit_locations(g): | |
- orcs_band = [goblin.create(g, 3+3j), | |
- orc.create(g, 6+6j), | |
- ogre.create(g, 3+6j)] | |
+ orcs_band = [goblin.create(g, 3 + 3j), | |
+ orc.create(g, 6 + 6j), | |
+ ogre.create(g, 3 + 6j)] | |
return orcs_band | |
-small_orc_cave = Dungeon("Greenskin's Cave", 8, 8, construct_objs=build_unit_locations, hero_entrance=Cell(3, 4), icon="greenskins.png") | |
+small_orc_cave = Dungeon( | |
+ "Greenskin's Cave", | |
+ 8, | |
+ 8, | |
+ construct_objs=build_unit_locations, | |
+ hero_entrance=Cell( | |
+ 3, | |
+ 4), | |
+ icon="greenskins.png") | |
diff --git a/cntent/dungeons/tel_razi_factory.py b/cntent/dungeons/tel_razi_factory.py | |
index 5044dc8..03af161 100644 | |
--- a/cntent/dungeons/tel_razi_factory.py | |
+++ b/cntent/dungeons/tel_razi_factory.py | |
@@ -3,15 +3,14 @@ from cntent.monsters.tel_razi.monsters import golem, sentinel | |
from game_objects.dungeon.Dungeon import Dungeon | |
- | |
def build_unit_locations(g): | |
- monsters = [sentinel.create(g, 5+5j), | |
- sentinel.create(g, 5 + 6j), | |
- golem.create(g, 6 + 5j), | |
- golem.create(g, 6 + 6j), | |
- golem.create(g, 4 + 5j), | |
- golem.create(g, 4 + 6j)] | |
+ monsters = [sentinel.create(g, 5 + 5j), | |
+ sentinel.create(g, 5 + 6j), | |
+ golem.create(g, 6 + 5j), | |
+ golem.create(g, 6 + 6j), | |
+ golem.create(g, 4 + 5j), | |
+ golem.create(g, 4 + 6j)] | |
return monsters | |
diff --git a/cntent/dungeons/tel_razi_temple.py b/cntent/dungeons/tel_razi_temple.py | |
index 858361a..d6495bf 100644 | |
--- a/cntent/dungeons/tel_razi_temple.py | |
+++ b/cntent/dungeons/tel_razi_temple.py | |
@@ -4,10 +4,10 @@ from game_objects.dungeon.Dungeon import Dungeon | |
def build_unit_locations(g): | |
- tel_band = [golem.create(g, 3+3j), | |
- golem.create(g, 6+6j), | |
- tel_razi_scrub.create(g, 3+6j), | |
- tel_razi_zealot.create(g, 4+4j)] | |
+ tel_band = [golem.create(g, 3 + 3j), | |
+ golem.create(g, 6 + 6j), | |
+ tel_razi_scrub.create(g, 3 + 6j), | |
+ tel_razi_zealot.create(g, 4 + 4j)] | |
return tel_band | |
diff --git a/cntent/items/QualityLevels.py b/cntent/items/QualityLevels.py | |
index 5c2b5c5..ac4e530 100644 | |
--- a/cntent/items/QualityLevels.py | |
+++ b/cntent/items/QualityLevels.py | |
@@ -1,5 +1,6 @@ | |
from game_objects.items import QualityLevel | |
+ | |
class QualityLevels: | |
CRUDE = QualityLevel("Crude", 0.6) | |
PRIMITIVE = QualityLevel("Primitive", 0.8) | |
@@ -8,4 +9,4 @@ class QualityLevels: | |
MASTERPIECE = QualityLevel("Masterpiece", 1.3) | |
LEGENDARY = QualityLevel("Legendary", 1.45) | |
- all = [CRUDE, PRIMITIVE, USUAL, SUPERIOR, MASTERPIECE, LEGENDARY] | |
\ No newline at end of file | |
+ all = [CRUDE, PRIMITIVE, USUAL, SUPERIOR, MASTERPIECE, LEGENDARY] | |
diff --git a/cntent/items/blueprints/armor/body_armor.py b/cntent/items/blueprints/armor/body_armor.py | |
index 8bfcb17..4c4bd54 100644 | |
--- a/cntent/items/blueprints/armor/body_armor.py | |
+++ b/cntent/items/blueprints/armor/body_armor.py | |
@@ -1,12 +1,22 @@ | |
from game_objects.items import ArmorTypes, ArmorBlueprint | |
-leather_outfit = ArmorBlueprint("leather outfit", target_item_type=ArmorTypes.LEATHER_JACKET, rarity=0.75) | |
-pirate_jacket = ArmorBlueprint("pirate jacket", target_item_type=ArmorTypes.LEATHER_JACKET, rarity=0.85) | |
+leather_outfit = ArmorBlueprint( | |
+ "leather outfit", | |
+ target_item_type=ArmorTypes.LEATHER_JACKET, | |
+ rarity=0.75) | |
+pirate_jacket = ArmorBlueprint( | |
+ "pirate jacket", | |
+ target_item_type=ArmorTypes.LEATHER_JACKET, | |
+ rarity=0.85) | |
-scalemail = ArmorBlueprint("scalemail", target_item_type=ArmorTypes.SCAILMAIL, rarity=1.05) | |
- | |
-cuirass = ArmorBlueprint("cuirass", target_item_type=ArmorTypes.CUIRASS, rarity=1.3) | |
- | |
+scalemail = ArmorBlueprint( | |
+ "scalemail", | |
+ target_item_type=ArmorTypes.SCAILMAIL, | |
+ rarity=1.05) | |
+cuirass = ArmorBlueprint( | |
+ "cuirass", | |
+ target_item_type=ArmorTypes.CUIRASS, | |
+ rarity=1.3) | |
diff --git a/cntent/items/blueprints/weapons/weapons.py b/cntent/items/blueprints/weapons/weapons.py | |
index ef4732a..007693f 100644 | |
--- a/cntent/items/blueprints/weapons/weapons.py | |
+++ b/cntent/items/blueprints/weapons/weapons.py | |
@@ -1,34 +1,91 @@ | |
+from cntent.actives.std.std_ranged_attack import bow_shot_active, crossbow_shot_active | |
from game_objects.items import WeaponBlueprint, WeaponTypes, MaterialTypes | |
-short_sword = WeaponBlueprint("short sword", weapon_type=WeaponTypes.SWORD, material_type=MaterialTypes.METAL, rarity=1) | |
-dagger = WeaponBlueprint("dagger", weapon_type=WeaponTypes.DAGGER, material_type=MaterialTypes.METAL, rarity=1) | |
-axe = WeaponBlueprint("axe", weapon_type=WeaponTypes.AXE, material_type=MaterialTypes.METAL, rarity=1) | |
-hammer = WeaponBlueprint("hammer", weapon_type=WeaponTypes.HAMMER, material_type=MaterialTypes.METAL, rarity=1) | |
-spear = WeaponBlueprint("spear", weapon_type=WeaponTypes.SPEAR, material_type=MaterialTypes.METAL, rarity=1) | |
- | |
-scimitar = WeaponBlueprint("scimitar", weapon_type=WeaponTypes.SWORD, material_type=MaterialTypes.METAL, | |
- rarity=1, damage=1.1, durability=0.8) | |
- | |
-occult_blade = WeaponBlueprint("occult blade", weapon_type=WeaponTypes.SWORD, material_type=MaterialTypes.METAL, | |
- rarity=1.3, damage=1.1, durability=0.6) | |
- | |
-rapier = WeaponBlueprint("rapier", weapon_type=WeaponTypes.SWORD, material_type=MaterialTypes.METAL, | |
- rarity=1.6, durability=0.8) | |
- | |
-heavenly_mercy = WeaponBlueprint("heavenly mercy", weapon_type=WeaponTypes.SWORD, material_type=MaterialTypes.METAL, | |
- rarity=2.3, durability=1.2) | |
+short_sword = WeaponBlueprint( | |
+ "short sword", | |
+ weapon_type=WeaponTypes.SWORD, | |
+ material_type=MaterialTypes.METAL, | |
+ rarity=1) | |
+dagger = WeaponBlueprint( | |
+ "dagger", | |
+ weapon_type=WeaponTypes.DAGGER, | |
+ material_type=MaterialTypes.METAL, | |
+ rarity=1) | |
+axe = WeaponBlueprint( | |
+ "axe", | |
+ weapon_type=WeaponTypes.AXE, | |
+ material_type=MaterialTypes.METAL, | |
+ rarity=1) | |
+hammer = WeaponBlueprint( | |
+ "hammer", | |
+ weapon_type=WeaponTypes.HAMMER, | |
+ material_type=MaterialTypes.METAL, | |
+ rarity=1) | |
+spear = WeaponBlueprint( | |
+ "spear", | |
+ weapon_type=WeaponTypes.SPEAR, | |
+ material_type=MaterialTypes.METAL, | |
+ rarity=1) | |
+ | |
+scimitar = WeaponBlueprint( | |
+ "scimitar", | |
+ weapon_type=WeaponTypes.SWORD, | |
+ material_type=MaterialTypes.METAL, | |
+ rarity=1, | |
+ damage=1.1, | |
+ durability=0.8) | |
+ | |
+occult_blade = WeaponBlueprint( | |
+ "occult blade", | |
+ weapon_type=WeaponTypes.SWORD, | |
+ material_type=MaterialTypes.METAL, | |
+ rarity=1.3, | |
+ damage=1.1, | |
+ durability=0.6) | |
+ | |
+rapier = WeaponBlueprint( | |
+ "rapier", | |
+ weapon_type=WeaponTypes.SWORD, | |
+ material_type=MaterialTypes.METAL, | |
+ rarity=1.6, | |
+ durability=0.8) | |
+ | |
+heavenly_mercy = WeaponBlueprint( | |
+ "heavenly mercy", | |
+ weapon_type=WeaponTypes.SWORD, | |
+ material_type=MaterialTypes.METAL, | |
+ rarity=2.3, | |
+ durability=1.2) | |
+ | |
+ | |
+primordial_axe = WeaponBlueprint( | |
+ "primordial axe", | |
+ weapon_type=WeaponTypes.AXE, | |
+ material_type=MaterialTypes.STONE, | |
+ rarity=0.9, | |
+ damage=1.2, | |
+ durability=0.5) | |
+ | |
+wooden_spear = WeaponBlueprint( | |
+ "spear", | |
+ weapon_type=WeaponTypes.SPEAR, | |
+ material_type=MaterialTypes.WOOD, | |
+ rarity=1.1) | |
+kris = WeaponBlueprint( | |
+ "kris", | |
+ weapon_type=WeaponTypes.DAGGER, | |
+ material_type=MaterialTypes.METAL, | |
+ rarity=1.2) | |
+ritual_dagger = WeaponBlueprint( | |
+ "ritual dagger", | |
+ weapon_type=WeaponTypes.DAGGER, | |
+ material_type=MaterialTypes.STONE, | |
+ rarity=1.3, | |
+ damage=1.2, | |
+ durability=0.5) | |
-primordial_axe = WeaponBlueprint("primordial axe", weapon_type=WeaponTypes.AXE, material_type=MaterialTypes.STONE, rarity=0.9, damage=1.2, durability=0.5) | |
- | |
-wooden_spear = WeaponBlueprint("spear", weapon_type=WeaponTypes.SPEAR, material_type=MaterialTypes.WOOD, rarity=1.1) | |
-kris = WeaponBlueprint("kris", weapon_type=WeaponTypes.DAGGER, material_type=MaterialTypes.METAL, rarity=1.2) | |
-ritual_dagger = WeaponBlueprint("ritual dagger", weapon_type=WeaponTypes.DAGGER, material_type=MaterialTypes.STONE, rarity=1.3, damage=1.2, durability=0.5) | |
- | |
- | |
-from cntent.actives.std.std_ranged_attack import bow_shot_active, crossbow_shot_active | |
- | |
bow = WeaponBlueprint("bow", | |
weapon_type=WeaponTypes.BOW, | |
material_type=MaterialTypes.WOOD, | |
@@ -47,5 +104,17 @@ std_blueprints = [short_sword, dagger, axe, hammer, spear, bow, crossbow] | |
fancy_blueprints = [occult_blade, wooden_spear, kris, ritual_dagger] | |
if __name__ == "__main__": | |
- for bp in [short_sword, dagger, axe, hammer, spear, scimitar, primordial_axe, bow, crossbow, rapier, occult_blade, heavenly_mercy]: | |
+ for bp in [ | |
+ short_sword, | |
+ dagger, | |
+ axe, | |
+ hammer, | |
+ spear, | |
+ scimitar, | |
+ primordial_axe, | |
+ bow, | |
+ crossbow, | |
+ rapier, | |
+ occult_blade, | |
+ heavenly_mercy]: | |
print(bp, bp.price) | |
diff --git a/cntent/items/materials/materials.py b/cntent/items/materials/materials.py | |
index a704d54..feaed12 100644 | |
--- a/cntent/items/materials/materials.py | |
+++ b/cntent/items/materials/materials.py | |
@@ -17,10 +17,14 @@ class Stones: | |
granite = Material(mt.STONE, "granite", 0.85) | |
flintstone = Material(mt.STONE, "flintstone", 1.15) | |
blackrock = Material(mt.STONE, "blackrock", 1.45) | |
- obsidian = Material(mt.STONE, "obsidian", 1.7, magic_complexity=1.2, energy=125) | |
+ obsidian = Material( | |
+ mt.STONE, | |
+ "obsidian", | |
+ 1.7, | |
+ magic_complexity=1.2, | |
+ energy=125) | |
corundum = Material(mt.STONE, "corundum", 3.3) | |
- | |
all = [stone, granite, flintstone, blackrock, obsidian, corundum] | |
@@ -30,13 +34,31 @@ class Leathers: | |
lizard_skin = Material(mt.SKIN, "lizard_skin", 1) | |
green_troll_skin = Material(mt.SKIN, "green troll skin", 1.6, energy=100) | |
black_troll_skin = Material(mt.SKIN, "black troll skin", 2, energy=125) | |
- green_dragon_skin = Material(mt.SKIN, "green dragon skin", 2.5, magic_complexity=1.4) | |
- red_dragon_skin = Material(mt.SKIN, "red dragon skin", 2.7, magic_complexity=1.5) | |
- black_dragon_skin = Material(mt.SKIN, "black dragon skin", 3, magic_complexity=1.6) | |
- | |
- | |
- all = [skin, thick_skin, lizard_skin, green_troll_skin, black_troll_skin, green_dragon_skin, black_dragon_skin, red_dragon_skin] | |
- | |
+ green_dragon_skin = Material( | |
+ mt.SKIN, | |
+ "green dragon skin", | |
+ 2.5, | |
+ magic_complexity=1.4) | |
+ red_dragon_skin = Material( | |
+ mt.SKIN, | |
+ "red dragon skin", | |
+ 2.7, | |
+ magic_complexity=1.5) | |
+ black_dragon_skin = Material( | |
+ mt.SKIN, | |
+ "black dragon skin", | |
+ 3, | |
+ magic_complexity=1.6) | |
+ | |
+ all = [ | |
+ skin, | |
+ thick_skin, | |
+ lizard_skin, | |
+ green_troll_skin, | |
+ black_troll_skin, | |
+ green_dragon_skin, | |
+ black_dragon_skin, | |
+ red_dragon_skin] | |
class Woods: | |
diff --git a/cntent/items/std/potions.py b/cntent/items/std/potions.py | |
index be73534..07ed11c 100644 | |
--- a/cntent/items/std/potions.py | |
+++ b/cntent/items/std/potions.py | |
@@ -2,12 +2,20 @@ from cntent.actives.callbacks.callbacks_consumables import healing_potion_cb, ma | |
from game_objects.items import ChargedItem | |
from mechanics.actives import ActiveTags | |
-minor_healing_potion = ChargedItem("minor healing potion", use_callbacks=[healing_potion_cb(175)], tags=[ActiveTags.RESTORATION]) | |
-minor_mana_potion = ChargedItem("minor mana potion", use_callbacks=[mana_potion_cb(40)], tags=[ActiveTags.RESTORATION]) | |
-minor_stamina_potion = ChargedItem("minor stamina potion", use_callbacks=[stamina_potion_cb(12)], tags=[ActiveTags.RESTORATION]) | |
- | |
-rejuvination_potion = ChargedItem("rejuvination potion", max_charges=2, | |
- use_callbacks=[healing_potion_cb(135), mana_potion_cb(30), stamina_potion_cb(5)], | |
- tags=[ActiveTags.RESTORATION]) | |
- | |
+minor_healing_potion = ChargedItem( | |
+ "minor healing potion", use_callbacks=[ | |
+ healing_potion_cb(175)], tags=[ | |
+ ActiveTags.RESTORATION]) | |
+minor_mana_potion = ChargedItem( | |
+ "minor mana potion", use_callbacks=[ | |
+ mana_potion_cb(40)], tags=[ | |
+ ActiveTags.RESTORATION]) | |
+minor_stamina_potion = ChargedItem( | |
+ "minor stamina potion", use_callbacks=[ | |
+ stamina_potion_cb(12)], tags=[ | |
+ ActiveTags.RESTORATION]) | |
+rejuvination_potion = ChargedItem( | |
+ "rejuvination potion", max_charges=2, use_callbacks=[ | |
+ healing_potion_cb(135), mana_potion_cb(30), stamina_potion_cb(5)], tags=[ | |
+ ActiveTags.RESTORATION]) | |
diff --git a/cntent/items/std/std_items.py b/cntent/items/std/std_items.py | |
index f884387..4e4c4cd 100644 | |
--- a/cntent/items/std/std_items.py | |
+++ b/cntent/items/std/std_items.py | |
@@ -3,47 +3,76 @@ from cntent.items.blueprints.weapons import weapons as bp_weapons | |
from cntent.items.blueprints.armor import body_armor as bp_armor | |
from cntent.items.QualityLevels import QualityLevels | |
-axe_ancient = bp_weapons.primordial_axe.to_item(Stones.flintstone, QualityLevels.SUPERIOR) | |
-stone_axe_cheap = bp_weapons.primordial_axe.to_item(Stones.stone, QualityLevels.CRUDE) | |
+axe_ancient = bp_weapons.primordial_axe.to_item( | |
+ Stones.flintstone, QualityLevels.SUPERIOR) | |
+stone_axe_cheap = bp_weapons.primordial_axe.to_item( | |
+ Stones.stone, QualityLevels.CRUDE) | |
-sword_cheap = bp_weapons.short_sword.to_item(Metals.bronze, QualityLevels.PRIMITIVE) | |
+sword_cheap = bp_weapons.short_sword.to_item( | |
+ Metals.bronze, QualityLevels.PRIMITIVE) | |
axe_cheap = bp_weapons.axe.to_item(Metals.bronze, QualityLevels.PRIMITIVE) | |
-dagger_cheap = bp_weapons.dagger.to_item(Metals.bronze, QualityLevels.PRIMITIVE) | |
+dagger_cheap = bp_weapons.dagger.to_item( | |
+ Metals.bronze, QualityLevels.PRIMITIVE) | |
spear_cheap = bp_weapons.spear.to_item(Metals.bronze, QualityLevels.PRIMITIVE) | |
-hammer_cheap = bp_weapons.hammer.to_item(Metals.bronze, QualityLevels.PRIMITIVE) | |
- | |
-sword_superior = bp_weapons.short_sword.to_item(Metals.iron, QualityLevels.SUPERIOR) | |
-sword_inferior = bp_weapons.short_sword.to_item(Metals.iron, QualityLevels.CRUDE) | |
-sword_bronze_superior = bp_weapons.short_sword.to_item(Metals.bronze, QualityLevels.SUPERIOR) | |
-sword_mithril = bp_weapons.short_sword.to_item(Metals.mithril, QualityLevels.USUAL) | |
- | |
+hammer_cheap = bp_weapons.hammer.to_item( | |
+ Metals.bronze, QualityLevels.PRIMITIVE) | |
+sword_superior = bp_weapons.short_sword.to_item( | |
+ Metals.iron, QualityLevels.SUPERIOR) | |
+sword_inferior = bp_weapons.short_sword.to_item( | |
+ Metals.iron, QualityLevels.CRUDE) | |
+sword_bronze_superior = bp_weapons.short_sword.to_item( | |
+ Metals.bronze, QualityLevels.SUPERIOR) | |
+sword_mithril = bp_weapons.short_sword.to_item( | |
+ Metals.mithril, QualityLevels.USUAL) | |
axe_superior = bp_weapons.axe.to_item(Metals.iron, QualityLevels.SUPERIOR) | |
spear_superior = bp_weapons.spear.to_item(Metals.iron, QualityLevels.SUPERIOR) | |
-dagger_superior = bp_weapons.dagger.to_item(Metals.iron, QualityLevels.SUPERIOR) | |
-hammer_superior = bp_weapons.hammer.to_item(Metals.iron, QualityLevels.SUPERIOR) | |
+dagger_superior = bp_weapons.dagger.to_item( | |
+ Metals.iron, QualityLevels.SUPERIOR) | |
+hammer_superior = bp_weapons.hammer.to_item( | |
+ Metals.iron, QualityLevels.SUPERIOR) | |
-elven_skimitar = bp_weapons.scimitar.to_item(Metals.mithril, QualityLevels.MASTERPIECE) | |
+elven_skimitar = bp_weapons.scimitar.to_item( | |
+ Metals.mithril, QualityLevels.MASTERPIECE) | |
smiths_hammer = bp_weapons.hammer.to_item(Metals.steel, QualityLevels.SUPERIOR) | |
-jacket_cheap = bp_armor.pirate_jacket.to_item(Leathers.skin, QualityLevels.PRIMITIVE) | |
-jacket_usual = bp_armor.leather_outfit.to_item(Leathers.thick_skin, QualityLevels.SUPERIOR) | |
+jacket_cheap = bp_armor.pirate_jacket.to_item( | |
+ Leathers.skin, QualityLevels.PRIMITIVE) | |
+jacket_usual = bp_armor.leather_outfit.to_item( | |
+ Leathers.thick_skin, QualityLevels.SUPERIOR) | |
-jacket_trollhide = bp_armor.leather_outfit.to_item(Leathers.green_troll_skin, QualityLevels.USUAL) | |
-scalemail_inferior = bp_armor.scalemail.to_item(Metals.iron, QualityLevels.PRIMITIVE) | |
+jacket_trollhide = bp_armor.leather_outfit.to_item( | |
+ Leathers.green_troll_skin, QualityLevels.USUAL) | |
+scalemail_inferior = bp_armor.scalemail.to_item( | |
+ Metals.iron, QualityLevels.PRIMITIVE) | |
cuirass_usual = bp_armor.cuirass.to_item(Metals.steel, QualityLevels.USUAL) | |
if __name__ == "__main__": | |
- for item in [axe_ancient, dagger_cheap, sword_cheap, hammer_cheap, sword_superior,dagger_superior, elven_skimitar, smiths_hammer, jacket_trollhide]: | |
+ for item in [ | |
+ axe_ancient, | |
+ dagger_cheap, | |
+ sword_cheap, | |
+ hammer_cheap, | |
+ sword_superior, | |
+ dagger_superior, | |
+ elven_skimitar, | |
+ smiths_hammer, | |
+ jacket_trollhide]: | |
print(item, item.price, item.material.price, item.blueprint.price) | |
- print( "*Ü*" * 20) | |
+ print("*Ü*" * 20) | |
- for item in [axe_ancient, stone_axe_cheap, sword_inferior, sword_superior, sword_bronze_superior, sword_mithril]: | |
+ for item in [ | |
+ axe_ancient, | |
+ stone_axe_cheap, | |
+ sword_inferior, | |
+ sword_superior, | |
+ sword_bronze_superior, | |
+ sword_mithril]: | |
print(item, item.price, item.material.price, item.blueprint.price) | |
diff --git a/cntent/items/std/std_ranged.py b/cntent/items/std/std_ranged.py | |
index 3d8d78e..2809ab4 100644 | |
--- a/cntent/items/std/std_ranged.py | |
+++ b/cntent/items/std/std_ranged.py | |
@@ -6,8 +6,7 @@ from cntent.items.QualityLevels import QualityLevels | |
black_bow = bp_weapons.bow.to_item(Woods.black_wood, QualityLevels.USUAL) | |
cheap_bow = bp_weapons.bow.to_item(Woods.oak, QualityLevels.CRUDE) | |
-cadamba_crossbow = bp_weapons.crossbow.to_item(Woods.cadamba_tree, QualityLevels.USUAL) | |
-quality_crossbow = bp_weapons.crossbow.to_item(Woods.wood, QualityLevels.MASTERPIECE) | |
- | |
- | |
- | |
+cadamba_crossbow = bp_weapons.crossbow.to_item( | |
+ Woods.cadamba_tree, QualityLevels.USUAL) | |
+quality_crossbow = bp_weapons.crossbow.to_item( | |
+ Woods.wood, QualityLevels.MASTERPIECE) | |
diff --git a/cntent/monsters/greenskins.py b/cntent/monsters/greenskins.py | |
index ffa445c..5ce9795 100644 | |
--- a/cntent/monsters/greenskins.py | |
+++ b/cntent/monsters/greenskins.py | |
@@ -15,12 +15,14 @@ class goblin_sound_map: | |
attack = "c_ogre_atk2.wav" | |
perish = "c_ogre_death.WAV" | |
+ | |
class orc_sound_map: | |
move = "SftStep3.wav" | |
hit = "c_koraboros_hit1.mp3" | |
attack = "c_koraboros_atk1.mp3" | |
perish = "c_koraboros_death.mp3" | |
+ | |
class ogre_sound_map: | |
move = "SftStep3.wav" | |
hit = "c_ogre_hit1.wav" | |
@@ -28,36 +30,78 @@ class ogre_sound_map: | |
perish = "c_ogre_death.wav" | |
-goblin_bt = BaseType({'str':8, 'end':7, 'prc':15, 'agi':15, 'int':12, 'cha':7}, | |
- "Goblin", resists={dt.FIRE:0.15}, abilities=[battle_rage(1)], | |
- icon=["gobl.jpg","goblin.jpg" ,"goblin Ambusher.png", | |
- "Goblin Crew-Leader.png","Goblin Poacher.png", | |
- "Goblin Scout.png","Goblin Watchman.png","Goblin Skirmisher.png"], sound_map=goblin_sound_map) | |
+goblin_bt = BaseType({'str': 8, | |
+ 'end': 7, | |
+ 'prc': 15, | |
+ 'agi': 15, | |
+ 'int': 12, | |
+ 'cha': 7}, | |
+ "Goblin", | |
+ resists={dt.FIRE: 0.15}, | |
+ abilities=[battle_rage(1)], | |
+ icon=["gobl.jpg", | |
+ "goblin.jpg", | |
+ "goblin Ambusher.png", | |
+ "Goblin Crew-Leader.png", | |
+ "Goblin Poacher.png", | |
+ "Goblin Scout.png", | |
+ "Goblin Watchman.png", | |
+ "Goblin Skirmisher.png"], | |
+ sound_map=goblin_sound_map) | |
goblin = Monster(goblin_bt, | |
- [ | |
- [si.dagger_cheap, si.dagger_superior, si.sword_cheap, si.spear_cheap], | |
- [si.jacket_usual, si.jacket_cheap] | |
- ]) | |
+ [[si.dagger_cheap, | |
+ si.dagger_superior, | |
+ si.sword_cheap, | |
+ si.spear_cheap], | |
+ [si.jacket_usual, | |
+ si.jacket_cheap]]) | |
-orc_bt = BaseType({'str':14, 'end':14, 'prc':12, 'agi':12, 'int':6, 'cha':6}, | |
- "Orc", resists={dt.FIRE:0.20}, abilities=[bash(0.33), fat, battle_rage(1)], | |
- icon=["orc.jpg", "Ork2.jpg", "Ork.jpg", "Ork Rager.jpg"], sound_map=orc_sound_map) | |
+orc_bt = BaseType({'str': 14, | |
+ 'end': 14, | |
+ 'prc': 12, | |
+ 'agi': 12, | |
+ 'int': 6, | |
+ 'cha': 6}, | |
+ "Orc", | |
+ resists={dt.FIRE: 0.20}, | |
+ abilities=[bash(0.33), | |
+ fat, | |
+ battle_rage(1)], | |
+ icon=["orc.jpg", | |
+ "Ork2.jpg", | |
+ "Ork.jpg", | |
+ "Ork Rager.jpg"], | |
+ sound_map=orc_sound_map) | |
-orc = Monster(orc_bt, | |
- [ | |
- [si.axe_superior, si.hammer_superior, si.sword_superior], | |
- [si.jacket_trollhide, si.scalemail_inferior, si.jacket_usual, si.cuirass_usual] | |
- ]) | |
+orc = Monster(orc_bt, [[si.axe_superior, si.hammer_superior, si.sword_superior], [ | |
+ si.jacket_trollhide, si.scalemail_inferior, si.jacket_usual, si.cuirass_usual]]) | |
-ogre_bt = BaseType({'str':22, 'end':25, 'prc':14, 'agi':9, 'int':10, 'cha':4},"Ogre", sound_map=ogre_sound_map, | |
- resists={dt.FIRE:0.30}, | |
- abilities=[bash(0.5), fat, battle_rage(1), aoe_damage(radius=2,percentage=0.5)], | |
- icon=["troll.png","ogre.png","ogrs.jpg"]) | |
+ogre_bt = BaseType({'str': 22, | |
+ 'end': 25, | |
+ 'prc': 14, | |
+ 'agi': 9, | |
+ 'int': 10, | |
+ 'cha': 4}, | |
+ "Ogre", | |
+ sound_map=ogre_sound_map, | |
+ resists={dt.FIRE: 0.30}, | |
+ abilities=[bash(0.5), | |
+ fat, | |
+ battle_rage(1), | |
+ aoe_damage(radius=2, | |
+ percentage=0.5)], | |
+ icon=["troll.png", | |
+ "ogre.png", | |
+ "ogrs.jpg"]) | |
ogre = Monster(ogre_bt, | |
- [ | |
- [si.smiths_hammer, si.hammer_superior, si.axe_superior, si.axe_ancient], | |
- [si.jacket_trollhide, si.scalemail_inferior, si.jacket_usual, si.cuirass_usual] | |
- ]) | |
\ No newline at end of file | |
+ [[si.smiths_hammer, | |
+ si.hammer_superior, | |
+ si.axe_superior, | |
+ si.axe_ancient], | |
+ [si.jacket_trollhide, | |
+ si.scalemail_inferior, | |
+ si.jacket_usual, | |
+ si.cuirass_usual]]) | |
diff --git a/cntent/monsters/pirates.py b/cntent/monsters/pirates.py | |
index 0fb8995..b582fde 100644 | |
--- a/cntent/monsters/pirates.py | |
+++ b/cntent/monsters/pirates.py | |
@@ -2,6 +2,7 @@ from cntent.items.std import std_items | |
from game_objects.battlefield_objects import BaseType | |
from game_objects.monsters.Monster import Monster | |
+ | |
class pirate_sound_map: | |
move = "SftStep3.wav" | |
hit = "fat_1_male_hit_4.wav" | |
@@ -9,25 +10,46 @@ class pirate_sound_map: | |
perish = "male_1_death_3.wav" | |
-pirate_basetype = BaseType({'int':11, 'cha':7}, "Pirate Scum", icon=["pirate.jpg","pirate.png", "pirate skirmisher.jpg"], sound_map=pirate_sound_map) | |
+pirate_basetype = BaseType({'int': 11, 'cha': 7}, "Pirate Scum", icon=[ | |
+ "pirate.jpg", "pirate.png", "pirate skirmisher.jpg"], sound_map=pirate_sound_map) | |
pirate_scum = Monster(pirate_basetype, | |
- [ | |
- [std_items.sword_cheap, std_items.dagger_cheap, std_items.axe_cheap], | |
- [std_items.jacket_cheap, std_items.scalemail_inferior] | |
- ]) | |
+ [[std_items.sword_cheap, | |
+ std_items.dagger_cheap, | |
+ std_items.axe_cheap], | |
+ [std_items.jacket_cheap, | |
+ std_items.scalemail_inferior]]) | |
-pirate_2_basetype = BaseType({'str':13, 'end':12, 'int':11, 'cha':7}, "Pirate Boatswain", icon=["pirate female.png", "pirate brute.jpg", "pirat.jpg"], sound_map=pirate_sound_map) | |
+pirate_2_basetype = BaseType({'str': 13, | |
+ 'end': 12, | |
+ 'int': 11, | |
+ 'cha': 7}, | |
+ "Pirate Boatswain", | |
+ icon=["pirate female.png", | |
+ "pirate brute.jpg", | |
+ "pirat.jpg"], | |
+ sound_map=pirate_sound_map) | |
pirate_boatswain = Monster(pirate_2_basetype, | |
- [ | |
- [std_items.hammer_superior, std_items.axe_cheap, std_items.sword_superior], | |
- [std_items.jacket_trollhide, std_items.scalemail_inferior] | |
- ]) | |
+ [[std_items.hammer_superior, | |
+ std_items.axe_cheap, | |
+ std_items.sword_superior], | |
+ [std_items.jacket_trollhide, | |
+ std_items.scalemail_inferior]]) | |
-pirate_3_basetype = BaseType({'str':13, 'end':12, 'agi':15, 'prc':16, 'int':11, 'cha':7}, "Pirate Captain", icon=["pirate captain.jpg", "pirate thief.jpg"], sound_map=pirate_sound_map) | |
+pirate_3_basetype = BaseType({'str': 13, | |
+ 'end': 12, | |
+ 'agi': 15, | |
+ 'prc': 16, | |
+ 'int': 11, | |
+ 'cha': 7}, | |
+ "Pirate Captain", | |
+ icon=["pirate captain.jpg", | |
+ "pirate thief.jpg"], | |
+ sound_map=pirate_sound_map) | |
pirate_captain = Monster(pirate_3_basetype, | |
- [ | |
- [std_items.smiths_hammer, std_items.elven_skimitar, std_items.sword_superior], | |
- [std_items.cuirass_usual, std_items.scalemail_inferior] | |
- ]) | |
\ No newline at end of file | |
+ [[std_items.smiths_hammer, | |
+ std_items.elven_skimitar, | |
+ std_items.sword_superior], | |
+ [std_items.cuirass_usual, | |
+ std_items.scalemail_inferior]]) | |
diff --git a/cntent/monsters/tel_razi/Golem.py b/cntent/monsters/tel_razi/Golem.py | |
index 33660a6..495c209 100644 | |
--- a/cntent/monsters/tel_razi/Golem.py | |
+++ b/cntent/monsters/tel_razi/Golem.py | |
@@ -1,6 +1,8 @@ | |
from __future__ import annotations | |
+from game_objects.battlefield_objects import Unit | |
import GameLog | |
+ | |
class GolemDisabled: | |
""" | |
If a golem has 0 or less charges, he is always disabled. | |
@@ -31,16 +33,13 @@ class GolemCharge: | |
golem._golem_charge = max(0, min(value, golem.golem_max_charge)) | |
delta = value - old_value | |
if delta > 0: | |
- print( f"{golem} gains {delta :g} charge; it has {golem.golem_charge:g} charge now.") | |
+ print( | |
+ f"{golem} gains {delta :g} charge; it has {golem.golem_charge:g} charge now.") | |
else: | |
- print( f"{golem} loses {abs(delta) :g} charge; it has {golem.golem_charge:g} charge now.") | |
- | |
- | |
+ print( | |
+ f"{golem} loses {abs(delta) :g} charge; it has {golem.golem_charge:g} charge now.") | |
- | |
- | |
-from game_objects.battlefield_objects import Unit | |
class Golem(Unit): | |
disabled = GolemDisabled() | |
golem_charge = GolemCharge() | |
@@ -61,4 +60,4 @@ class Golem(Unit): | |
unit.__class__ = Golem | |
unit.usual_disabled = old_value | |
unit._golem_charge = max_charges | |
- unit.golem_max_charge = max_charges | |
\ No newline at end of file | |
+ unit.golem_max_charge = max_charges | |
diff --git a/cntent/monsters/tel_razi/abilities/golem_n_charges.py b/cntent/monsters/tel_razi/abilities/golem_n_charges.py | |
index a86f6e7..8f5f8c3 100644 | |
--- a/cntent/monsters/tel_razi/abilities/golem_n_charges.py | |
+++ b/cntent/monsters/tel_razi/abilities/golem_n_charges.py | |
@@ -5,7 +5,7 @@ from game_objects.battlefield_objects import CharAttributes as ca | |
from mechanics.damage import Armor | |
-def trig_factory( ability: Ability): | |
+def trig_factory(ability: Ability): | |
owner = ability.bound_to | |
return charge_drop_trigger(owner, ability.max_golem_charges) | |
@@ -18,5 +18,3 @@ def golem_n_charges(n): | |
a.max_golem_charges = n | |
return a | |
return _ | |
- | |
- | |
diff --git a/cntent/monsters/tel_razi/abilities/teleport_on_hit.py b/cntent/monsters/tel_razi/abilities/teleport_on_hit.py | |
index e2a52ef..d7bb492 100644 | |
--- a/cntent/monsters/tel_razi/abilities/teleport_on_hit.py | |
+++ b/cntent/monsters/tel_razi/abilities/teleport_on_hit.py | |
@@ -1,7 +1,8 @@ | |
from cntent.monsters.tel_razi.triggers.teleport_on_hit import random_teleport_trigger | |
from mechanics.buffs import Ability | |
-def trig_factory( ability: Ability): | |
+ | |
+def trig_factory(ability: Ability): | |
owner = ability.bound_to | |
return random_teleport_trigger(owner, | |
ability.random_teleport_radius, | |
@@ -17,5 +18,3 @@ def teleport_on_hit(radius, chance, cost): | |
a.random_teleport_cost = cost | |
return a | |
return _ | |
- | |
- | |
diff --git a/cntent/monsters/tel_razi/abilities/zone_control.py b/cntent/monsters/tel_razi/abilities/zone_control.py | |
index bd16743..5cf4e72 100644 | |
--- a/cntent/monsters/tel_razi/abilities/zone_control.py | |
+++ b/cntent/monsters/tel_razi/abilities/zone_control.py | |
@@ -2,9 +2,12 @@ from cntent.monsters.tel_razi.triggers.zone_control import zone_control_trigger, | |
from mechanics.buffs import Ability | |
-def trig_factory( ability: Ability): | |
+def trig_factory(ability: Ability): | |
owner = ability.bound_to | |
- return zone_control_trigger(owner, ability.zone_control_radius, ability.zone_control_chance) | |
+ return zone_control_trigger( | |
+ owner, | |
+ ability.zone_control_radius, | |
+ ability.zone_control_chance) | |
def zone_control(radius, chance): | |
@@ -16,10 +19,10 @@ def zone_control(radius, chance): | |
return _ | |
- | |
-def trig_factory_damage( ability: Ability): | |
+def trig_factory_damage(ability: Ability): | |
owner = ability.bound_to | |
- return zone_control_damage_cond_trigger(owner, ability.zone_control_radius, ability.zone_control_chance) | |
+ return zone_control_damage_cond_trigger( | |
+ owner, ability.zone_control_radius, ability.zone_control_chance) | |
def zone_control_damage(radius, chance): | |
@@ -29,5 +32,3 @@ def zone_control_damage(radius, chance): | |
a.zone_control_chance = chance | |
return a | |
return _ | |
- | |
- | |
diff --git a/cntent/monsters/tel_razi/actives.py b/cntent/monsters/tel_razi/actives.py | |
index 95ab1f8..f76b284 100644 | |
--- a/cntent/monsters/tel_razi/actives.py | |
+++ b/cntent/monsters/tel_razi/actives.py | |
@@ -1,3 +1,5 @@ | |
+from mechanics.conditions import ActiveCondition | |
+from cntent.monsters.tel_razi.callbacks import stun_bolt | |
from mechanics.actives import Active, ActiveTags | |
from mechanics.actives import Cost | |
from game_objects.battlefield_objects import BattlefieldObject | |
@@ -7,8 +9,6 @@ from cntent.monsters.tel_razi.callbacks import give_charges_callback | |
from cntent.actives.conditions.conditions import proximity_condition, within_angle | |
- | |
- | |
tel_razi_electrify = Active(BattlefieldObject, | |
[proximity_condition(2), within_angle(89)], | |
Cost(stamina=1, mana=10), | |
@@ -18,29 +18,18 @@ tel_razi_electrify = Active(BattlefieldObject, | |
name="Electify", | |
cooldown=5) | |
-from cntent.monsters.tel_razi.callbacks import stun_bolt | |
- | |
-from mechanics.conditions import ActiveCondition | |
- | |
- | |
- | |
-no_direct_activation_cond = ActiveCondition("No direct activation", | |
- lambda a, t: a.owner.readiness < 1, | |
- "This ability can't be activated on the owners turn.") | |
- | |
- | |
-sentinel_shot = Active(BattlefieldObject, | |
- [proximity_condition(3), within_angle(130), no_direct_activation_cond], | |
- Cost(stamina=1, mana=20), | |
- game=None, | |
- callbacks=[stun_bolt(40, 0.2)], | |
- tags=[ActiveTags.ATTACK, ActiveTags.RANGED], | |
- name="Electify", | |
- cooldown=4) | |
- | |
- | |
- | |
- | |
+no_direct_activation_cond = ActiveCondition( | |
+ "No direct activation", | |
+ lambda a, | |
+ t: a.owner.readiness < 1, | |
+ "This ability can't be activated on the owners turn.") | |
+sentinel_shot = Active( | |
+ BattlefieldObject, [ | |
+ proximity_condition(3), within_angle(130), no_direct_activation_cond], Cost( | |
+ stamina=1, mana=20), game=None, callbacks=[ | |
+ stun_bolt( | |
+ 40, 0.2)], tags=[ | |
+ ActiveTags.ATTACK, ActiveTags.RANGED], name="Electify", cooldown=4) | |
diff --git a/cntent/monsters/tel_razi/callbacks.py b/cntent/monsters/tel_razi/callbacks.py | |
index 6efd980..ab53645 100644 | |
--- a/cntent/monsters/tel_razi/callbacks.py | |
+++ b/cntent/monsters/tel_razi/callbacks.py | |
@@ -1,30 +1,29 @@ | |
from __future__ import annotations | |
+from mechanics.damage import DamageTypes, Damage | |
+from mechanics.events import DamageEvent | |
+from cntent.monsters.tel_razi import Golem | |
+from game_objects.battlefield_objects import Unit | |
from typing import TYPE_CHECKING | |
if TYPE_CHECKING: | |
from mechanics.actives import Active | |
-from game_objects.battlefield_objects import Unit | |
-from cntent.monsters.tel_razi import Golem | |
- | |
-from mechanics.events import DamageEvent | |
-from mechanics.damage import DamageTypes, Damage | |
- | |
def give_charges_callback(n): | |
- def _(active :Active, target :Unit): | |
+ def _(active: Active, target: Unit): | |
if isinstance(target, Golem): | |
target.golem_charge += n | |
- target.golem_charge = min(target.golem_charge, target.golem_max_charge) | |
+ target.golem_charge = min( | |
+ target.golem_charge, target.golem_max_charge) | |
elif isinstance(target, Unit): | |
- dmg = Damage(10*n + target.mana * n / 20, DamageTypes.LIGHTNING) | |
+ dmg = Damage(10 * n + target.mana * n / 20, DamageTypes.LIGHTNING) | |
DamageEvent(dmg, target, source=active.owner) | |
return _ | |
def stun_bolt(n_dmg, stun_amount): | |
- def _(active :Active, target :Unit): | |
+ def _(active: Active, target: Unit): | |
dmg = Damage(n_dmg, DamageTypes.LIGHTNING) | |
e = DamageEvent(dmg, target, source=active.owner) | |
@@ -32,4 +31,3 @@ def stun_bolt(n_dmg, stun_amount): | |
target.readiness -= stun_amount | |
return _ | |
- | |
diff --git a/cntent/monsters/tel_razi/monsters.py b/cntent/monsters/tel_razi/monsters.py | |
index 2f15cd7..5b6f421 100644 | |
--- a/cntent/monsters/tel_razi/monsters.py | |
+++ b/cntent/monsters/tel_razi/monsters.py | |
@@ -1,3 +1,8 @@ | |
+from mechanics.actives import Cost | |
+from cntent.monsters.tel_razi.abilities.teleport_on_hit import teleport_on_hit | |
+from cntent.monsters.tel_razi.actives import tel_razi_electrify | |
+from cntent.monsters.tel_razi.actives import sentinel_shot | |
+from cntent.monsters.tel_razi.abilities.zone_control import zone_control_damage | |
from cntent.abilities.generic.ability import fat | |
from cntent.monsters.tel_razi.abilities.golem_n_charges import golem_n_charges | |
from cntent.items.std import std_items, std_ranged | |
@@ -13,34 +18,43 @@ class golems_sound_map: | |
perish = "c_ghast_death.mp3" | |
- | |
-golem_bt = BaseType({'str':24, 'end':15, 'prc':0, 'agi':2, 'int':2, 'cha':8}, | |
- "Crude Golem", abilities=[golem_n_charges(15), fat], icon=["golem.png"], sound_map=golems_sound_map) | |
+golem_bt = BaseType({'str': 24, | |
+ 'end': 15, | |
+ 'prc': 0, | |
+ 'agi': 2, | |
+ 'int': 2, | |
+ 'cha': 8}, | |
+ "Crude Golem", | |
+ abilities=[golem_n_charges(15), | |
+ fat], | |
+ icon=["golem.png"], | |
+ sound_map=golems_sound_map) | |
golem = Monster(golem_bt, | |
- [ | |
- | |
- ]) | |
+ [ | |
- | |
-from cntent.monsters.tel_razi.abilities.zone_control import zone_control_damage | |
-from cntent.monsters.tel_razi.actives import sentinel_shot | |
+ ]) | |
-sentinel_bt = BaseType({'str':9, 'end':13, 'prc':18, 'agi':12, 'int':12, 'cha':8}, | |
- "Sentinel", abilities=[golem_n_charges(12), zone_control_damage(3, 0.5)], | |
- actives=[sentinel_shot], | |
- icon=["sentinel.jpg"], sound_map=golems_sound_map) | |
+sentinel_bt = BaseType({'str': 9, | |
+ 'end': 13, | |
+ 'prc': 18, | |
+ 'agi': 12, | |
+ 'int': 12, | |
+ 'cha': 8}, | |
+ "Sentinel", | |
+ abilities=[golem_n_charges(12), | |
+ zone_control_damage(3, | |
+ 0.5)], | |
+ actives=[sentinel_shot], | |
+ icon=["sentinel.jpg"], | |
+ sound_map=golems_sound_map) | |
sentinel = Monster(sentinel_bt, | |
- [ | |
- | |
- ]) | |
+ [ | |
+ ]) | |
-from cntent.monsters.tel_razi.actives import tel_razi_electrify | |
-from cntent.monsters.tel_razi.abilities.teleport_on_hit import teleport_on_hit | |
-from mechanics.actives import Cost | |
class tel_razi_sound_map: | |
move = "SftStep3.wav" | |
@@ -48,27 +62,45 @@ class tel_razi_sound_map: | |
attack = "c_ghast_atk1.mp3" | |
perish = "c_ghast_death.mp3" | |
-tel_razi_scrub_bt = BaseType({'str':5, 'end':8, 'prc':16, 'agi':12, 'int':21, 'cha':12}, | |
- actives=[tel_razi_electrify], | |
- abilities=[teleport_on_hit(3, 0.8, Cost(stamina=1, mana=5, readiness=0.1))], | |
- type_name="Tel'Razi Scrub", icon=["wormface.jpg"], sound_map=tel_razi_sound_map) | |
-tel_razi_scrub = Monster(tel_razi_scrub_bt, | |
- [ | |
- [std_items.jacket_cheap], | |
- [std_ranged.black_bow, std_ranged.cheap_bow, std_ranged.quality_crossbow] | |
- ]) | |
- | |
-tel_razi_zealot_bt = BaseType({'str':15, 'end':16, 'prc':16, 'agi':21, 'int':12, 'cha':12}, | |
- actives=[tel_razi_electrify], | |
- abilities=[teleport_on_hit(2, 0.5, Cost(stamina=1, mana=5, readiness=0.1))], | |
- type_name="Tel'Razi Zealot", icon=["wormface2.jpg"], sound_map=tel_razi_sound_map) | |
+tel_razi_scrub_bt = BaseType({'str': 5, | |
+ 'end': 8, | |
+ 'prc': 16, | |
+ 'agi': 12, | |
+ 'int': 21, | |
+ 'cha': 12}, | |
+ actives=[tel_razi_electrify], | |
+ abilities=[teleport_on_hit(3, | |
+ 0.8, | |
+ Cost(stamina=1, | |
+ mana=5, | |
+ readiness=0.1))], | |
+ type_name="Tel'Razi Scrub", | |
+ icon=["wormface.jpg"], | |
+ sound_map=tel_razi_sound_map) | |
+ | |
+tel_razi_scrub = Monster(tel_razi_scrub_bt, [[std_items.jacket_cheap], [ | |
+ std_ranged.black_bow, std_ranged.cheap_bow, std_ranged.quality_crossbow]]) | |
+ | |
+tel_razi_zealot_bt = BaseType({'str': 15, | |
+ 'end': 16, | |
+ 'prc': 16, | |
+ 'agi': 21, | |
+ 'int': 12, | |
+ 'cha': 12}, | |
+ actives=[tel_razi_electrify], | |
+ abilities=[teleport_on_hit(2, | |
+ 0.5, | |
+ Cost(stamina=1, | |
+ mana=5, | |
+ readiness=0.1))], | |
+ type_name="Tel'Razi Zealot", | |
+ icon=["wormface2.jpg"], | |
+ sound_map=tel_razi_sound_map) | |
tel_razi_zealot = Monster(tel_razi_zealot_bt, | |
- [ | |
- [std_items.jacket_cheap, std_items.jacket_trollhide], | |
- [std_items.sword_superior, std_items.axe_superior, std_items.spear_superior] | |
- ]) | |
- | |
- | |
- | |
+ [[std_items.jacket_cheap, | |
+ std_items.jacket_trollhide], | |
+ [std_items.sword_superior, | |
+ std_items.axe_superior, | |
+ std_items.spear_superior]]) | |
diff --git a/cntent/monsters/tel_razi/triggers/charge_drop.py b/cntent/monsters/tel_razi/triggers/charge_drop.py | |
index 32d6e48..aad1061 100644 | |
--- a/cntent/monsters/tel_razi/triggers/charge_drop.py | |
+++ b/cntent/monsters/tel_razi/triggers/charge_drop.py | |
@@ -3,7 +3,8 @@ from mechanics.events import Trigger | |
from mechanics.events import ActiveEvent | |
from cntent.monsters.tel_razi import Golem | |
-def charge_drop_callback(t:Trigger,e:ActiveEvent): | |
+ | |
+def charge_drop_callback(t: Trigger, e: ActiveEvent): | |
unit: Golem = e.active.owner | |
charges_cost = e.active.cost.readiness + e.active.cost.stamina | |
unit.golem_charge -= charges_cost | |
@@ -11,13 +12,10 @@ def charge_drop_callback(t:Trigger,e:ActiveEvent): | |
def charge_drop_trigger(unit, max_charges): | |
trig = Trigger(ActiveEvent, | |
- platform=unit.game.events_platform, | |
- conditions={lambda t, e : e.active.owner.uid == unit.uid}, | |
- callbacks=[charge_drop_callback]) | |
- | |
+ platform=unit.game.events_platform, | |
+ conditions={lambda t, e: e.active.owner.uid == unit.uid}, | |
+ callbacks=[charge_drop_callback]) | |
Golem.golemize(unit, max_charges) | |
- | |
return trig | |
- | |
diff --git a/cntent/monsters/tel_razi/triggers/teleport_on_hit.py b/cntent/monsters/tel_razi/triggers/teleport_on_hit.py | |
index d06c760..621be62 100644 | |
--- a/cntent/monsters/tel_razi/triggers/teleport_on_hit.py | |
+++ b/cntent/monsters/tel_razi/triggers/teleport_on_hit.py | |
@@ -6,8 +6,9 @@ from typing import TYPE_CHECKING | |
if TYPE_CHECKING: | |
from game_objects.battlefield_objects import Unit | |
-def random_teleport_callback(t:Trigger,e:AttackEvent): | |
- unit:Unit = e.target | |
+ | |
+def random_teleport_callback(t: Trigger, e: AttackEvent): | |
+ unit: Unit = e.target | |
if not unit.alive: | |
return | |
@@ -19,7 +20,8 @@ def random_teleport_callback(t:Trigger,e:AttackEvent): | |
if e.game.random.random() < chance: | |
initial_location = unit.cell | |
- possible_cells = e.game.bf.neighbours_exclude_center(initial_location, radius) | |
+ possible_cells = e.game.bf.neighbours_exclude_center( | |
+ initial_location, radius) | |
target_cell = e.game.random.choice(possible_cells) | |
MovementEvent(unit, target_cell) | |
unit.pay(cost) | |
@@ -27,13 +29,12 @@ def random_teleport_callback(t:Trigger,e:AttackEvent): | |
def random_teleport_trigger(unit, radius, chance, cost): | |
trig = Trigger(AttackEvent, | |
- platform=unit.game.events_platform, | |
- conditions={lambda t, e : e.target.uid == unit.uid}, | |
- callbacks=[random_teleport_callback]) | |
+ platform=unit.game.events_platform, | |
+ conditions={lambda t, e: e.target.uid == unit.uid}, | |
+ callbacks=[random_teleport_callback]) | |
trig.random_teleport_radius = radius | |
trig.random_teleport_chance = chance | |
trig.random_teleport_cost = cost | |
return trig | |
- | |
diff --git a/cntent/monsters/tel_razi/triggers/zone_control.py b/cntent/monsters/tel_razi/triggers/zone_control.py | |
index e5c1fa0..7f17315 100644 | |
--- a/cntent/monsters/tel_razi/triggers/zone_control.py | |
+++ b/cntent/monsters/tel_razi/triggers/zone_control.py | |
@@ -1,27 +1,31 @@ | |
from __future__ import annotations | |
+from mechanics.chances.CritHitGrazeMiss import ImpactFactor | |
+from mechanics.events import MovementEvent, AttackEvent, DamageEvent | |
+from mechanics.events import Trigger | |
from typing import TYPE_CHECKING | |
if TYPE_CHECKING: | |
from game_objects.battlefield_objects import Unit | |
-from mechanics.events import Trigger | |
-from mechanics.events import MovementEvent, AttackEvent, DamageEvent | |
-from mechanics.chances.CritHitGrazeMiss import ImpactFactor | |
- | |
def punish_move_attack_conditioned_cb(t: Trigger, e: MovementEvent): | |
chance = t.zone_control_chance | |
if e.game.random.random() < chance: | |
unit = t.zone_control_unit | |
- actives_validity = {active: active.check_target(e.unit) and active.affordable() for active in unit.attack_actives} | |
+ actives_validity = {active: active.check_target( | |
+ e.unit) and active.affordable() for active in unit.attack_actives} | |
valid_actives = [k for k, v in actives_validity.items() if v is True] | |
punishing_action = e.game.random.choice(valid_actives) | |
spy = [] | |
- e.game.events_platform.history.append( spy ) | |
+ e.game.events_platform.history.append(spy) | |
punishing_action.activate(e.unit) | |
- attk_events = [event for event, happened in spy if isinstance(event, AttackEvent) and event.source is unit] | |
+ attk_events = [ | |
+ event for event, | |
+ happened in spy if isinstance( | |
+ event, | |
+ AttackEvent) and event.source is unit] | |
for attk_event in attk_events: | |
if attk_event.impact is not ImpactFactor.MISS: | |
e.interrupted = True | |
@@ -36,15 +40,20 @@ def punish_move_damage_conditioned_cb(t: Trigger, e: MovementEvent): | |
if e.game.random.random() < chance: | |
unit = t.zone_control_unit | |
- actives_validity = {active: active.check_target(e.unit) and active.affordable() for active in unit.attack_actives} | |
+ actives_validity = {active: active.check_target( | |
+ e.unit) and active.affordable() for active in unit.attack_actives} | |
valid_actives = [k for k, v in actives_validity.items() if v is True] | |
punishing_action = e.game.random.choice(valid_actives) | |
spy = [] | |
- e.game.events_platform.history.append( spy ) | |
+ e.game.events_platform.history.append(spy) | |
punishing_action.activate(e.unit) | |
- dmg_events = [event for event, happened in spy if isinstance(event, DamageEvent) and event.source is unit] | |
+ dmg_events = [ | |
+ event for event, | |
+ happened in spy if isinstance( | |
+ event, | |
+ DamageEvent) and event.source is unit] | |
for dmg_event in dmg_events: | |
if dmg_event.amount > 0: | |
e.interrupted = True | |
@@ -59,35 +68,38 @@ def cond_enemy_moves(t, e: MovementEvent): | |
def cond_from_within_radius(t, e: MovementEvent): | |
initial_location = e.cell_from | |
- return e.game.bf.distance(t.zone_control_unit, initial_location) <= t.zone_control_radius | |
+ return e.game.bf.distance( | |
+ t.zone_control_unit, | |
+ initial_location) <= t.zone_control_radius | |
def cond_not_disabled(t, e): | |
return not t.zone_control_unit.disabled | |
+ | |
def cond_readiness_threshold(t, e): | |
return t.zone_control_unit.readiness > 0 | |
def cond_can_attack(t, e: MovementEvent): | |
- opportunities = [active.check_target(e.unit) and active.affordable() for active in t.zone_control_unit.attack_actives] | |
+ opportunities = [active.check_target(e.unit) and active.affordable( | |
+ ) for active in t.zone_control_unit.attack_actives] | |
return any(opportunities) | |
def zone_control_trigger(unit: Unit, radius, chance): | |
- | |
trig = Trigger(MovementEvent, | |
- platform = unit.game.events_platform, | |
- is_interrupt = True, | |
+ platform=unit.game.events_platform, | |
+ is_interrupt=True, | |
- conditions = {cond_enemy_moves, | |
- cond_from_within_radius, | |
- cond_not_disabled, | |
- cond_readiness_threshold, | |
- cond_can_attack}, | |
+ conditions={cond_enemy_moves, | |
+ cond_from_within_radius, | |
+ cond_not_disabled, | |
+ cond_readiness_threshold, | |
+ cond_can_attack}, | |
- callbacks = [punish_move_attack_conditioned_cb]) | |
+ callbacks=[punish_move_attack_conditioned_cb]) | |
trig.zone_control_unit = unit | |
trig.zone_control_radius = radius | |
@@ -98,18 +110,17 @@ def zone_control_trigger(unit: Unit, radius, chance): | |
def zone_control_damage_cond_trigger(unit: Unit, radius, chance): | |
- | |
trig = Trigger(MovementEvent, | |
- platform = unit.game.events_platform, | |
- is_interrupt = True, | |
+ platform=unit.game.events_platform, | |
+ is_interrupt=True, | |
- conditions = {cond_enemy_moves, | |
- cond_from_within_radius, | |
- cond_not_disabled, | |
- cond_readiness_threshold, | |
- cond_can_attack}, | |
+ conditions={cond_enemy_moves, | |
+ cond_from_within_radius, | |
+ cond_not_disabled, | |
+ cond_readiness_threshold, | |
+ cond_can_attack}, | |
- callbacks = [punish_move_damage_conditioned_cb]) | |
+ callbacks=[punish_move_damage_conditioned_cb]) | |
trig.zone_control_unit = unit | |
trig.zone_control_radius = radius | |
diff --git a/cntent/monsters/undead.py b/cntent/monsters/undead.py | |
index 892323a..54275ce 100644 | |
--- a/cntent/monsters/undead.py | |
+++ b/cntent/monsters/undead.py | |
@@ -1,3 +1,4 @@ | |
+from mechanics.damage import DamageTypes | |
from cntent.items.std import std_items, std_ranged | |
from cntent.abilities.generic.ability import fat, evasive | |
from cntent.abilities.undead.ability import undying | |
@@ -15,15 +16,27 @@ class zombie_sound_map: | |
perish = "c_ghast_death.mp3" | |
- | |
-zombie_bt = BaseType({'str':11, 'end':9, 'prc':5, 'agi':5, 'int':3, 'cha':3}, | |
- "Zombie", abilities=[undying(3), fat], icon=["zombie.png","zombie3.png","zombie2.jpg" ], sound_map=zombie_sound_map) | |
+zombie_bt = BaseType({'str': 11, | |
+ 'end': 9, | |
+ 'prc': 5, | |
+ 'agi': 5, | |
+ 'int': 3, | |
+ 'cha': 3}, | |
+ "Zombie", | |
+ abilities=[undying(3), | |
+ fat], | |
+ icon=["zombie.png", | |
+ "zombie3.png", | |
+ "zombie2.jpg"], | |
+ sound_map=zombie_sound_map) | |
zombie = Monster(zombie_bt, | |
- [ | |
- [std_items.sword_cheap, std_items.hammer_cheap, std_items.axe_cheap], | |
- [std_items.jacket_trollhide, std_items.scalemail_inferior] | |
- ]) | |
+ [[std_items.sword_cheap, | |
+ std_items.hammer_cheap, | |
+ std_items.axe_cheap], | |
+ [std_items.jacket_trollhide, | |
+ std_items.scalemail_inferior]]) | |
+ | |
class skeleton_sound_map: | |
move = "SftStep3.wav" | |
@@ -32,27 +45,60 @@ class skeleton_sound_map: | |
perish = "c_skeleton_death.mp3" | |
-skeleton_bt = BaseType({'str':8, 'end':6, 'prc':5, 'agi':25, 'int':3, 'cha':3}, | |
- "Skeleton", abilities=[undying(1)], icon=["skeleton.png","kosti2.jpg","kosti.jpg","kost.jpg"], sound_map=skeleton_sound_map) | |
+skeleton_bt = BaseType({'str': 8, | |
+ 'end': 6, | |
+ 'prc': 5, | |
+ 'agi': 25, | |
+ 'int': 3, | |
+ 'cha': 3}, | |
+ "Skeleton", | |
+ abilities=[undying(1)], | |
+ icon=["skeleton.png", | |
+ "kosti2.jpg", | |
+ "kosti.jpg", | |
+ "kost.jpg"], | |
+ sound_map=skeleton_sound_map) | |
skeleton = Monster(skeleton_bt, | |
- [ | |
- [std_items.sword_cheap]*2+[ std_items.sword_superior, std_items.hammer_cheap, std_items.axe_cheap], | |
- [std_items.cuirass_usual, std_items.scalemail_inferior] | |
- ]) | |
- | |
+ [[std_items.sword_cheap] * 2 + [std_items.sword_superior, | |
+ std_items.hammer_cheap, | |
+ std_items.axe_cheap], | |
+ [std_items.cuirass_usual, | |
+ std_items.scalemail_inferior]]) | |
skeleton_archer = Monster(skeleton_bt, | |
- [ | |
- [std_ranged.cheap_bow]*3+[ std_ranged.black_bow, std_ranged.quality_crossbow], | |
- [std_items.jacket_cheap, std_items.scalemail_inferior] | |
- ]) | |
- | |
- | |
-from mechanics.damage import DamageTypes | |
-ghost_bt = BaseType({'str':13, 'end':10, 'prc':13, 'agi':14, 'int':8, 'cha':7}, | |
- "Ghost", abilities=[undying(2), mana_drain(20, 0.03, 2), evasive(0,50,50)], unarmed_damage_type=DamageTypes.FROST, | |
- icon=["skeleton.png","kosti2.jpg","kosti.jpg","kost.jpg"], sound_map=skeleton_sound_map) | |
- | |
-ghost = Monster(ghost_bt) | |
\ No newline at end of file | |
+ [[std_ranged.cheap_bow] * 3 + [std_ranged.black_bow, | |
+ std_ranged.quality_crossbow], | |
+ [std_items.jacket_cheap, | |
+ std_items.scalemail_inferior]]) | |
+ | |
+ | |
+ghost_bt = BaseType( | |
+ { | |
+ 'str': 13, | |
+ 'end': 10, | |
+ 'prc': 13, | |
+ 'agi': 14, | |
+ 'int': 8, | |
+ 'cha': 7}, | |
+ "Ghost", | |
+ abilities=[ | |
+ undying(2), | |
+ mana_drain( | |
+ 20, | |
+ 0.03, | |
+ 2), | |
+ evasive( | |
+ 0, | |
+ 50, | |
+ 50)], | |
+ unarmed_damage_type=DamageTypes.FROST, | |
+ icon=[ | |
+ "skeleton.png", | |
+ "kosti2.jpg", | |
+ "kosti.jpg", | |
+ "kost.jpg"], | |
+ sound_map=skeleton_sound_map) | |
+ | |
+ghost = Monster(ghost_bt) | |
diff --git a/cntent/monsters/werewolves.py b/cntent/monsters/werewolves.py | |
index 749bd43..6e4a0d1 100644 | |
--- a/cntent/monsters/werewolves.py | |
+++ b/cntent/monsters/werewolves.py | |
@@ -21,14 +21,16 @@ werewolf_bt = BaseType( | |
"Werewolf", | |
sound_map=WerewolfSoundMap, | |
resists={dt.SLASH: 0.30}, | |
- abilities=[bash(0.5), battle_rage(1), aoe_damage(radius=2,percentage=0.5)], | |
+ abilities=[bash(0.5), battle_rage(1), aoe_damage(radius=2, percentage=0.5)], | |
icon=["werewolf.jpg"] | |
) | |
-werewolf = Monster( | |
- werewolf_bt, | |
- [ | |
- [si.smiths_hammer, si.hammer_superior, si.axe_superior, si.axe_ancient], | |
- [si.jacket_trollhide, si.scalemail_inferior, si.jacket_usual, si.cuirass_usual] | |
- ] | |
-) | |
\ No newline at end of file | |
+werewolf = Monster(werewolf_bt, | |
+ [[si.smiths_hammer, | |
+ si.hammer_superior, | |
+ si.axe_superior, | |
+ si.axe_ancient], | |
+ [si.jacket_trollhide, | |
+ si.scalemail_inferior, | |
+ si.jacket_usual, | |
+ si.cuirass_usual]]) | |
diff --git a/cntent/spells/callbacks.py b/cntent/spells/callbacks.py | |
index 7a1776e..241f01e 100644 | |
--- a/cntent/spells/callbacks.py | |
+++ b/cntent/spells/callbacks.py | |
@@ -12,9 +12,10 @@ def lightning_bolt_callback(active, unit): | |
DamageEvent(dmg, target=target, source=source) | |
+ | |
def healing_callback(active, unit): | |
source = active.owner | |
target = unit | |
spell = active.spell | |
- HealingEvent(spell.amount, target, source=source) | |
\ No newline at end of file | |
+ HealingEvent(spell.amount, target, source=source) | |
diff --git a/cntent/spells/concepts.py b/cntent/spells/concepts.py | |
index 607546b..05bc819 100644 | |
--- a/cntent/spells/concepts.py | |
+++ b/cntent/spells/concepts.py | |
@@ -1,4 +1,4 @@ | |
-from game_objects.spells import SpellConcept | |
+from game_objects.spells import SpellConcept | |
from game_objects.battlefield_objects import Unit | |
from character.masteries.MasteriesEnumSimple import MasteriesEnum | |
from mechanics.actives import Cost | |
@@ -20,4 +20,4 @@ heal_concept = SpellConcept(name="healing", | |
cost=Cost(4, 40, 0, readiness=1), | |
amount=60, duration=None, precision_factor=1, | |
distance=2, radius=None, | |
- resolve_callback=healing_callback) | |
\ No newline at end of file | |
+ resolve_callback=healing_callback) | |
diff --git a/cntent/spells/fire/burning_hands/callbacks.py b/cntent/spells/fire/burning_hands/callbacks.py | |
index 89bdafe..44a28e0 100644 | |
--- a/cntent/spells/fire/burning_hands/callbacks.py | |
+++ b/cntent/spells/fire/burning_hands/callbacks.py | |
@@ -6,6 +6,7 @@ from typing import TYPE_CHECKING | |
if TYPE_CHECKING: | |
from mechanics.actives import Active | |
+ | |
def burning_hands_callback(active: Active, _): | |
source = active.owner | |
@@ -16,11 +17,15 @@ def burning_hands_callback(active: Active, _): | |
starting_location = source.cell | |
facing = source.facing | |
- units_hit = bf.units_in_area(bf.cone(starting_location, facing, angle_max=spell.radius*20, dist_min=1, dist_max=spell.range)) | |
+ units_hit = bf.units_in_area( | |
+ bf.cone( | |
+ starting_location, | |
+ facing, | |
+ angle_max=spell.radius * 20, | |
+ dist_min=1, | |
+ dist_max=spell.range)) | |
dmg = Damage(n_damage, DamageTypes.FIRE) | |
for unit in units_hit: | |
DamageEvent(dmg, target=unit, source=source) | |
- | |
- | |
diff --git a/cntent/spells/fire/concepts.py b/cntent/spells/fire/concepts.py | |
index 4f3d024..b5f74a8 100644 | |
--- a/cntent/spells/fire/concepts.py | |
+++ b/cntent/spells/fire/concepts.py | |
@@ -1,4 +1,4 @@ | |
-from game_objects.spells import SpellConcept | |
+from game_objects.spells import SpellConcept | |
from character.masteries.MasteriesEnumSimple import MasteriesEnum | |
from mechanics.actives import Cost | |
from cntent.spells.fire.burning_hands.callbacks import burning_hands_callback | |
@@ -6,23 +6,31 @@ from cntent.spells.fire.immolation.callbacks import immolation_callback | |
from game_objects.battlefield_objects import BattlefieldObject | |
-burning_hands_concept = SpellConcept(name="burning hands", | |
- school=MasteriesEnum.FIRE, | |
- targeting_cls=None, | |
- complexity=15, | |
- cost=Cost(3, 25, 0, readiness=1), | |
- cooldown=4, | |
- amount=25, duration=None, precision_factor=1, | |
- distance=3, radius=2, | |
- resolve_callback=burning_hands_callback) | |
+burning_hands_concept = SpellConcept( | |
+ name="burning hands", | |
+ school=MasteriesEnum.FIRE, | |
+ targeting_cls=None, | |
+ complexity=15, | |
+ cost=Cost( | |
+ 3, | |
+ 25, | |
+ 0, | |
+ readiness=1), | |
+ cooldown=4, | |
+ amount=25, | |
+ duration=None, | |
+ precision_factor=1, | |
+ distance=3, | |
+ radius=2, | |
+ resolve_callback=burning_hands_callback) | |
immolation_concept = SpellConcept(name="immolation", | |
- school=MasteriesEnum.FIRE, | |
- targeting_cls=BattlefieldObject, | |
- complexity=8, | |
- cost=Cost(3, 25, 0, readiness=1), | |
- cooldown=4, | |
- amount=25, duration=4, precision_factor=1, | |
- distance=3, radius=None, | |
- resolve_callback=immolation_callback) | |
+ school=MasteriesEnum.FIRE, | |
+ targeting_cls=BattlefieldObject, | |
+ complexity=8, | |
+ cost=Cost(3, 25, 0, readiness=1), | |
+ cooldown=4, | |
+ amount=25, duration=4, precision_factor=1, | |
+ distance=3, radius=None, | |
+ resolve_callback=immolation_callback) | |
diff --git a/cntent/spells/fire/immolation/buffs.py b/cntent/spells/fire/immolation/buffs.py | |
index 2753d4d..1a118e7 100644 | |
--- a/cntent/spells/fire/immolation/buffs.py | |
+++ b/cntent/spells/fire/immolation/buffs.py | |
@@ -5,25 +5,34 @@ from mechanics.buffs import Buff | |
def burn_callback(t, e: BuffExpiredEvent): | |
- DamageEvent(damage=t.buff.damage_per_second ,target=t.buff.bound_to, source=t.buff.source) | |
+ DamageEvent( | |
+ damage=t.buff.damage_per_second, | |
+ target=t.buff.bound_to, | |
+ source=t.buff.source) | |
e.buff.duration = 1 | |
def burn_trigger(buff): | |
t = CounteredInterrupt(BuffExpiredEvent, | |
- platform=buff.bound_to.game.events_platform, | |
- conditions={lambda t, e: e.buff is buff}, | |
- callbacks=[burn_callback], | |
- n_counters=buff.n_ticks) | |
+ platform=buff.bound_to.game.events_platform, | |
+ conditions={lambda t, e: e.buff is buff}, | |
+ callbacks=[burn_callback], | |
+ n_counters=buff.n_ticks) | |
t.buff = buff | |
return t | |
+ | |
def trigger_factory(buff: Buff): | |
t = burn_trigger(buff) | |
return t | |
+ | |
def build_burning_buff(dps, source, duration) -> Buff: | |
- b = Buff(1, triggers_factories=[trigger_factory], source=source, name= "Burning") | |
+ b = Buff( | |
+ 1, | |
+ triggers_factories=[trigger_factory], | |
+ source=source, | |
+ name="Burning") | |
b.damage_per_second = dps | |
b.n_ticks = duration // 1 | |
- return b | |
\ No newline at end of file | |
+ return b | |
diff --git a/cntent/spells/fire/immolation/callbacks.py b/cntent/spells/fire/immolation/callbacks.py | |
index 258f9af..5fd4592 100644 | |
--- a/cntent/spells/fire/immolation/callbacks.py | |
+++ b/cntent/spells/fire/immolation/callbacks.py | |
@@ -1,4 +1,6 @@ | |
from __future__ import annotations | |
+from cntent.spells.fire.immolation.buffs import build_burning_buff | |
+from mechanics.events import BuffAppliedEvent | |
from mechanics.damage import Damage, DamageTypes | |
from typing import TYPE_CHECKING | |
@@ -7,16 +9,12 @@ if TYPE_CHECKING: | |
from game_objects.battlefield_objects import BattlefieldObject | |
-from mechanics.events import BuffAppliedEvent | |
-from cntent.spells.fire.immolation.buffs import build_burning_buff | |
- | |
-def immolation_callback(active: Active, target:BattlefieldObject): | |
+def immolation_callback(active: Active, target: BattlefieldObject): | |
source = active.owner | |
spell = active.spell | |
- | |
buff = build_burning_buff(dps=Damage(spell.amount, DamageTypes.FIRE), | |
source=source, | |
duration=spell.duration) | |
- BuffAppliedEvent(buff, target) | |
\ No newline at end of file | |
+ BuffAppliedEvent(buff, target) | |
diff --git a/cntent/spells/runes.py b/cntent/spells/runes.py | |
index 46ba854..35266f5 100644 | |
--- a/cntent/spells/runes.py | |
+++ b/cntent/spells/runes.py | |
@@ -2,25 +2,28 @@ from game_objects.spells import Rune, SpellAttributes | |
from game_objects.attributes import Bonus, Attribute | |
-__double_damage_bonus = Bonus({SpellAttributes.AMOUNT: Attribute(0,100,0)}) | |
-__double_duration_bonus = Bonus({SpellAttributes.DURATION: Attribute(0,100,0)}) | |
+__double_damage_bonus = Bonus({SpellAttributes.AMOUNT: Attribute(0, 100, 0)}) | |
+__double_duration_bonus = Bonus( | |
+ {SpellAttributes.DURATION: Attribute(0, 100, 0)}) | |
-__complexity_cost_bonus = lambda x: Bonus({SpellAttributes.COMPLEXITY: Attribute(0,0,x)}) | |
+def __complexity_cost_bonus(x): return Bonus( | |
+ {SpellAttributes.COMPLEXITY: Attribute(0, 0, x)}) | |
-__low_mana_cost_bonus = lambda x: Bonus({SpellAttributes.MANA_COST: Attribute(0,0,-x)}) | |
-__low_cooldown_bonus = lambda x: Bonus({SpellAttributes.COOLDOWN: Attribute(0,0,-x)}) | |
+def __low_mana_cost_bonus(x): return Bonus( | |
+ {SpellAttributes.MANA_COST: Attribute(0, 0, -x)}) | |
+def __low_cooldown_bonus(x): return Bonus( | |
+ {SpellAttributes.COOLDOWN: Attribute(0, 0, -x)}) | |
+ | |
double_damage_rune = Rune([__double_damage_bonus, __complexity_cost_bonus(15)]) | |
-double_duration_rune = Rune([__double_duration_bonus, __complexity_cost_bonus(11)]) | |
+double_duration_rune = Rune( | |
+ [__double_duration_bonus, __complexity_cost_bonus(11)]) | |
-cheap_casting_rune = Rune([__low_mana_cost_bonus(5), __complexity_cost_bonus(5)]) | |
+cheap_casting_rune = Rune( | |
+ [__low_mana_cost_bonus(5), __complexity_cost_bonus(5)]) | |
fast_casting_rune = Rune([__low_cooldown_bonus(1), __complexity_cost_bonus(5)]) | |
- | |
- | |
- | |
- | |
diff --git a/cntent/triggers/damage_to_attacker.py b/cntent/triggers/damage_to_attacker.py | |
index 011bd46..e48da03 100644 | |
--- a/cntent/triggers/damage_to_attacker.py | |
+++ b/cntent/triggers/damage_to_attacker.py | |
@@ -8,12 +8,11 @@ def damage_to_attackers(source, protected_unit, damage, interrupt=False): | |
def callback_deal_damage(_, attack_event): | |
DamageEvent(damage, target=attack_event.source, source=source) | |
- | |
trig = Trigger(AttackEvent, | |
- conditions={lambda t,e: e.target == protected_unit}, | |
+ conditions={lambda t, e: e.target == protected_unit}, | |
platform=protected_unit.game.events_platform, | |
source=source, | |
callbacks=[callback_deal_damage], | |
is_interrupt=interrupt) | |
- return trig | |
\ No newline at end of file | |
+ return trig | |
diff --git a/cntent/triggers/upgrade_hits.py b/cntent/triggers/upgrade_hits.py | |
index 31066e4..adc4cfe 100644 | |
--- a/cntent/triggers/upgrade_hits.py | |
+++ b/cntent/triggers/upgrade_hits.py | |
@@ -4,14 +4,16 @@ from mechanics.chances import ImpactFactor | |
def upgrade_hits(unit, n_hits): | |
- def upgrade_hit_to_crit_callback(_, damage_event ): | |
+ def upgrade_hit_to_crit_callback(_, damage_event): | |
damage_event.impact_factor = ImpactFactor.CRIT | |
- trig = CounteredInterrupt(DamageEvent, | |
- platform=unit.game.events_platform, | |
- conditions={lambda t,e : e.source is unit and e.impact_factor is ImpactFactor.HIT}, | |
- n_counters=n_hits, | |
- interrupt_event=False, | |
- callbacks=[upgrade_hit_to_crit_callback]) | |
+ trig = CounteredInterrupt( | |
+ DamageEvent, | |
+ platform=unit.game.events_platform, | |
+ conditions={ | |
+ lambda t, | |
+ e: e.source is unit and e.impact_factor is ImpactFactor.HIT}, | |
+ n_counters=n_hits, | |
+ interrupt_event=False, | |
+ callbacks=[upgrade_hit_to_crit_callback]) | |
return trig | |
- | |
diff --git a/exceptions/CantAffordActiveException.py b/exceptions/CantAffordActiveException.py | |
index 3e27226..672a09d 100644 | |
--- a/exceptions/CantAffordActiveException.py | |
+++ b/exceptions/CantAffordActiveException.py | |
@@ -1,5 +1,6 @@ | |
from exceptions import PydolonsError | |
+ | |
class CantAffordActiveError(PydolonsError): | |
def __init__(self, active, missing): | |
@@ -8,4 +9,4 @@ class CantAffordActiveError(PydolonsError): | |
self.missing = missing | |
def __repr__(self): | |
- return f"Need more {self.missing} to activate {self.active}" | |
\ No newline at end of file | |
+ return f"Need more {self.missing} to activate {self.active}" | |
diff --git a/exceptions/InvalidTargetException.py b/exceptions/InvalidTargetException.py | |
index b9146bc..0b71655 100644 | |
--- a/exceptions/InvalidTargetException.py | |
+++ b/exceptions/InvalidTargetException.py | |
@@ -1,5 +1,6 @@ | |
from exceptions import PydolonsError | |
+ | |
class InvalidTargetError(PydolonsError): | |
def __init__(self, target, order): | |
@@ -7,4 +8,4 @@ class InvalidTargetError(PydolonsError): | |
self.order = order | |
def __repr__(self): | |
- return f"Target.py {self.target} is invalid for the order {self.order}" | |
\ No newline at end of file | |
+ return f"Target.py {self.target} is invalid for the order {self.order}" | |
diff --git a/exceptions/PydolonsError.py b/exceptions/PydolonsError.py | |
index de75172..f5af87f 100644 | |
--- a/exceptions/PydolonsError.py | |
+++ b/exceptions/PydolonsError.py | |
@@ -1,8 +1,7 @@ | |
class PydolonsError(Exception): | |
- | |
def __init__(self, message): | |
self.message = message | |
def __repr__(self): | |
- return self.message | |
\ No newline at end of file | |
+ return self.message | |
diff --git a/game_objects/attributes/Attribute.py b/game_objects/attributes/Attribute.py | |
index 2208d05..e206aaa 100644 | |
--- a/game_objects/attributes/Attribute.py | |
+++ b/game_objects/attributes/Attribute.py | |
@@ -16,22 +16,20 @@ class Attribute: | |
new_bonus = self.bonus + other | |
return Attribute(new_base, new_multiplier, new_bonus) | |
- | |
+ | |
def __mul__(self, other): | |
new_base = self.base * other | |
new_multiplier = self.multiplier * other | |
new_bonus = self.bonus * other | |
return Attribute(new_base, new_multiplier, new_bonus) | |
- | |
- | |
def value(self): | |
""" | |
value = base * multiplier + bonus | |
multiplier can not be less than 10% | |
""" | |
multiplier = max(10, self.multiplier) | |
- return max(1, int(self.base * multiplier / 100 + self.bonus) ) | |
+ return max(1, int(self.base * multiplier / 100 + self.bonus)) | |
@staticmethod | |
def attribute_or_none(base): | |
@@ -39,5 +37,3 @@ class Attribute: | |
return None | |
else: | |
return Attribute(base, 100, 0) | |
- | |
- | |
diff --git a/game_objects/attributes/AttributeWithBonuses.py b/game_objects/attributes/AttributeWithBonuses.py | |
index 1720266..f216b95 100644 | |
--- a/game_objects/attributes/AttributeWithBonuses.py | |
+++ b/game_objects/attributes/AttributeWithBonuses.py | |
@@ -1,5 +1,6 @@ | |
from functools import lru_cache | |
+ | |
class AttributeWithBonuses: | |
def __init__(self, name_base, bonus_enum): | |
@@ -19,10 +20,3 @@ class AttributeWithBonuses: | |
if matching_bonus: | |
attr += matching_bonus | |
return attr.value() | |
- | |
- | |
- | |
- | |
- | |
- | |
- | |
diff --git a/game_objects/attributes/DynamicParameter.py b/game_objects/attributes/DynamicParameter.py | |
index 1482fce..a1beaaa 100644 | |
--- a/game_objects/attributes/DynamicParameter.py | |
+++ b/game_objects/attributes/DynamicParameter.py | |
@@ -2,7 +2,6 @@ from my_utils.utils import clamp | |
from typing import Union, List, Callable | |
- | |
class DynamicParameter: | |
""" | |
Dynamic parameter defines a property that has maximum value, which might change. | |
@@ -26,8 +25,10 @@ class DynamicParameter: | |
except AttributeError: | |
pass | |
- | |
- def __init__(self, max_name: str, on_zero_callbacks: List[Callable] = None): | |
+ def __init__( | |
+ self, | |
+ max_name: str, | |
+ on_zero_callbacks: List[Callable] = None): | |
cls = self.__class__ | |
prefix = cls.__name__ | |
self.max_name = max_name | |
@@ -67,4 +68,4 @@ class DynamicParameter: | |
return | |
percentage_full = getattr(unit, self.storage_name) / old_max_value | |
setattr(unit, self.storage_name, new_max_value * percentage_full) | |
- setattr(unit, self.old_max_storage, new_max_value) | |
\ No newline at end of file | |
+ setattr(unit, self.old_max_storage, new_max_value) | |
diff --git a/game_objects/attributes/__init__.py b/game_objects/attributes/__init__.py | |
index edd6825..5a7536c 100644 | |
--- a/game_objects/attributes/__init__.py | |
+++ b/game_objects/attributes/__init__.py | |
@@ -2,4 +2,3 @@ from game_objects.attributes.Attribute import Attribute | |
from game_objects.attributes.AttributeWithBonuses import AttributeWithBonuses | |
from game_objects.attributes.Bonus import Bonus | |
from game_objects.attributes.DynamicParameter import DynamicParameter | |
- | |
diff --git a/game_objects/battlefield_objects/BaseType.py b/game_objects/battlefield_objects/BaseType.py | |
index fc093f6..d03331b 100644 | |
--- a/game_objects/battlefield_objects/BaseType.py | |
+++ b/game_objects/battlefield_objects/BaseType.py | |
@@ -5,22 +5,23 @@ from mechanics.damage import DamageTypes | |
from character.masteries.Masteries import Masteries | |
from ui.sounds import sound_maps | |
+ | |
class BaseType: | |
default_unarmed_chances = ImpactChances(crit=0.05, hit=0.5, graze=0.6) | |
def __init__(self, attributes, type_name, *, | |
unarmed_damage_type=DamageTypes.CRUSH, | |
- unarmed_chances = default_unarmed_chances, | |
+ unarmed_chances=default_unarmed_chances, | |
resists=None, | |
armor_dict=None, | |
armor_base=0, | |
- inventory_capacity = 20, | |
- quick_items = 3, | |
+ inventory_capacity=20, | |
+ quick_items=3, | |
actives=None, | |
- abilities = None, | |
+ abilities=None, | |
icon="default.png", | |
- xp = None, | |
- sound_map = None): | |
+ xp=None, | |
+ sound_map=None): | |
self.attributes = {} | |
for attr in list(attributes.keys()): | |
@@ -48,4 +49,5 @@ class BaseType: | |
self.icon = icon | |
self.sound_map = sound_map or sound_maps.std_sound_map | |
- self.xp = xp or Masteries.cumulative_cost( sum(self.attributes.values()) - 40 ) | |
\ No newline at end of file | |
+ self.xp = xp or Masteries.cumulative_cost( | |
+ sum(self.attributes.values()) - 40) | |
diff --git a/game_objects/battlefield_objects/BattlefieldObject.py b/game_objects/battlefield_objects/BattlefieldObject.py | |
index 8770d14..67fb5f8 100644 | |
--- a/game_objects/battlefield_objects/BattlefieldObject.py | |
+++ b/game_objects/battlefield_objects/BattlefieldObject.py | |
@@ -3,12 +3,13 @@ from battlefield import Cell | |
from exceptions import PydolonsError | |
from typing import Union | |
+ | |
class BattlefieldObject(ABC): | |
size = 3 | |
last_uid = 0 | |
- def __init__(self, cell = None): | |
+ def __init__(self, cell=None): | |
BattlefieldObject.last_uid += 1 | |
self.uid = BattlefieldObject.last_uid | |
self._cell = None | |
@@ -35,8 +36,7 @@ class BattlefieldObject(ABC): | |
else: | |
raise PydolonsError( | |
f"Obj.cell attribute can only be assigned with complex or Cell types." | |
- f"Actual passed type: {type(value)}" | |
- ) | |
+ f"Actual passed type: {type(value)}") | |
- def lose_health(self, amount, source = None): | |
- raise NotImplementedError | |
\ No newline at end of file | |
+ def lose_health(self, amount, source=None): | |
+ raise NotImplementedError | |
diff --git a/game_objects/battlefield_objects/CharAttributes.py b/game_objects/battlefield_objects/CharAttributes.py | |
index 23abdb3..8efc195 100644 | |
--- a/game_objects/battlefield_objects/CharAttributes.py | |
+++ b/game_objects/battlefield_objects/CharAttributes.py | |
@@ -21,38 +21,58 @@ class CharAttributes(NameEnum): | |
PRECISION = auto() | |
EVASION = auto() | |
+ | |
c = CharAttributes | |
-abbrev_to_enum = {'str':c.STREINGTH, 'end':c.ENDURANCE, 'agi':c.AGILITY, | |
- 'prc':c.PERCEPTION, 'int':c.INTELLIGENCE, 'cha':c.CHARISMA, | |
- 'health':c.HEALTH, 'stamina': c.STAMINA, 'mana':c.MANA, | |
- 'initiative':c.INITIATIVE, 'armor':c.ARMOR, 'resistances':c.RESISTANCES, | |
- 'melee_precision': c.PRECISION, 'melee_evasion': c.EVASION} | |
+abbrev_to_enum = { | |
+ 'str': c.STREINGTH, | |
+ 'end': c.ENDURANCE, | |
+ 'agi': c.AGILITY, | |
+ 'prc': c.PERCEPTION, | |
+ 'int': c.INTELLIGENCE, | |
+ 'cha': c.CHARISMA, | |
+ 'health': c.HEALTH, | |
+ 'stamina': c.STAMINA, | |
+ 'mana': c.MANA, | |
+ 'initiative': c.INITIATIVE, | |
+ 'armor': c.ARMOR, | |
+ 'resistances': c.RESISTANCES, | |
+ 'melee_precision': c.PRECISION, | |
+ 'melee_evasion': c.EVASION} | |
-base_attributes = [c.STREINGTH, c.ENDURANCE, c.AGILITY, c.PERCEPTION, c.INITIATIVE, c.CHARISMA] | |
+base_attributes = [ | |
+ c.STREINGTH, | |
+ c.ENDURANCE, | |
+ c.AGILITY, | |
+ c.PERCEPTION, | |
+ c.INITIATIVE, | |
+ c.CHARISMA] | |
enum_to_abbrev = {v: k for k, v in abbrev_to_enum.items()} | |
+ | |
def get_attrib_by_enum(unit, enum): | |
name = enum_to_abbrev[enum] | |
return getattr(unit, name) | |
+ | |
class Constants: | |
HP_PER_END = 25 | |
STAMINA_PER_STR = 5 | |
MANA_PER_INT = 10 | |
UNARMED_DAMAGE_PER_STR = 3 | |
+ | |
std_bonus = Attribute(1, 0.05, 2) | |
value_norms = { | |
- c.STREINGTH : std_bonus*1, | |
- c.ENDURANCE: std_bonus*1, | |
- c.AGILITY: std_bonus*1, | |
- c.PERCEPTION: std_bonus*1, | |
- c.INTELLIGENCE: std_bonus*1, | |
- c.CHARISMA: std_bonus*1, | |
- c.HEALTH : std_bonus*2*Constants.HP_PER_END, | |
- c.MANA: std_bonus*2*Constants.MANA_PER_INT, | |
- c.STAMINA: std_bonus*2*Constants.STAMINA_PER_STR, | |
- c.INITIATIVE : std_bonus*0.2 | |
-} | |
\ No newline at end of file | |
+ c.STREINGTH: std_bonus * 1, | |
+ c.ENDURANCE: std_bonus * 1, | |
+ c.AGILITY: std_bonus * 1, | |
+ c.PERCEPTION: std_bonus * 1, | |
+ c.INTELLIGENCE: std_bonus * 1, | |
+ c.CHARISMA: std_bonus * 1, | |
+ c.HEALTH: std_bonus * 2 * Constants.HP_PER_END, | |
+ c.MANA: std_bonus * 2 * Constants.MANA_PER_INT, | |
+ c.STAMINA: std_bonus * 2 * Constants.STAMINA_PER_STR, | |
+ c.INITIATIVE: std_bonus * 0.2 | |
+} | |
diff --git a/game_objects/battlefield_objects/Corpse.py b/game_objects/battlefield_objects/Corpse.py | |
index 90e3cd0..788b4aa 100644 | |
--- a/game_objects/battlefield_objects/Corpse.py | |
+++ b/game_objects/battlefield_objects/Corpse.py | |
@@ -4,6 +4,7 @@ from typing import TYPE_CHECKING | |
if TYPE_CHECKING: | |
from game_objects.battlefield_objects import Unit | |
+ | |
class Corpse(Obstacle): | |
size = 1 | |
@@ -16,4 +17,4 @@ class Corpse(Obstacle): | |
max_health=unit.max_health * 10, | |
armor=unit.armor, | |
resists=unit.resists, | |
- icon='corpse.jpg') | |
\ No newline at end of file | |
+ icon='corpse.jpg') | |
diff --git a/game_objects/battlefield_objects/Obstacle.py b/game_objects/battlefield_objects/Obstacle.py | |
index 741e4f6..d966d69 100644 | |
--- a/game_objects/battlefield_objects/Obstacle.py | |
+++ b/game_objects/battlefield_objects/Obstacle.py | |
@@ -7,24 +7,35 @@ from ui.sounds import sound_maps | |
class Obstacle(BattlefieldObject): | |
- sound_map = sound_maps.std_sound_map #TODO specific obstacle sound maps | |
- health = DynamicParameter("max_health", [lambda u : events.ObstacleDestroyedEvent(u)]) | |
+ sound_map = sound_maps.std_sound_map # TODO specific obstacle sound maps | |
+ health = DynamicParameter("max_health", | |
+ [lambda u: events.ObstacleDestroyedEvent(u)]) | |
melee_evasion = 0 | |
is_obstacle = True | |
- def __init__(self, name, max_health, *, cell=None, game=None, armor=0, resists=None, icon="wall.png"): | |
+ def __init__( | |
+ self, | |
+ name, | |
+ max_health, | |
+ *, | |
+ cell=None, | |
+ game=None, | |
+ armor=0, | |
+ resists=None, | |
+ icon="wall.png"): | |
super().__init__(cell) | |
self.game = game | |
self.name = name | |
self.max_health = max_health | |
- self.armor = armor if isinstance(armor,Armor) else Armor(base_value=armor) | |
+ self.armor = armor if isinstance( | |
+ armor, Armor) else Armor( | |
+ base_value=armor) | |
self.resists = resists or Resistances() | |
self.icon = icon | |
self.alive = True | |
self.last_damaged_by = None | |
- | |
def lose_health(self, dmg_amount, source=None): | |
assert dmg_amount >= 0 | |
@@ -32,13 +43,12 @@ class Obstacle(BattlefieldObject): | |
self.last_damaged_by = source | |
self.health -= dmg_amount | |
- | |
@property | |
def tooltip_info(self): | |
- return {'name':f"{self.name}_{self.uid}", | |
- 'hp':str(int(self.health)), | |
+ return {'name': f"{self.name}_{self.uid}", | |
+ 'hp': str(int(self.health)), | |
'armor': repr(self.armor), | |
- 'defence':str(self.melee_evasion)} | |
+ 'defence': str(self.melee_evasion)} | |
def __repr__(self): | |
return f"{self.name} with {self.health :.0f} HP" | |
diff --git a/game_objects/battlefield_objects/Unit.py b/game_objects/battlefield_objects/Unit.py | |
index 3c645dc..d14d430 100644 | |
--- a/game_objects/battlefield_objects/Unit.py | |
+++ b/game_objects/battlefield_objects/Unit.py | |
@@ -1,6 +1,20 @@ | |
from __future__ import annotations | |
+import random | |
+from battlefield import Facing | |
+from character.masteries.Masteries import Masteries, MasteriesEnum | |
+from cntent.actives.std.std_melee_attack import std_attacks | |
+from cntent.actives.std.std_movements import std_movements, turn_ccw, turn_cw | |
+from mechanics.factions import Faction | |
+from mechanics.actives import ActiveTags, Active | |
+from mechanics import events | |
+from mechanics.damage import Resistances, Armor | |
+from mechanics.damage import Damage | |
+from game_objects.items import Inventory, Equipment, Weapon, QuickItems, EquipmentSlotUids | |
+from game_objects.attributes import Attribute, AttributeWithBonuses, DynamicParameter | |
+from game_objects.battlefield_objects.CharAttributes import Constants | |
+from game_objects.battlefield_objects import BaseType, BattlefieldObject, CharAttributes as ca | |
import copy | |
from functools import lru_cache | |
from typing import Set, TYPE_CHECKING, List | |
@@ -10,25 +24,9 @@ if TYPE_CHECKING: | |
from mechanics.actives import Cost | |
from battlefield import Cell | |
-from game_objects.battlefield_objects import BaseType, BattlefieldObject, CharAttributes as ca | |
-from game_objects.battlefield_objects.CharAttributes import Constants | |
-from game_objects.attributes import Attribute, AttributeWithBonuses, DynamicParameter | |
-from game_objects.items import Inventory, Equipment, Weapon, QuickItems, EquipmentSlotUids | |
-from mechanics.damage import Damage | |
-from mechanics.damage import Resistances, Armor | |
-from mechanics import events | |
-from mechanics.actives import ActiveTags, Active | |
-from mechanics.factions import Faction | |
-from cntent.actives.std.std_movements import std_movements, turn_ccw, turn_cw | |
-from cntent.actives.std.std_melee_attack import std_attacks | |
-from character.masteries.Masteries import Masteries, MasteriesEnum | |
-from battlefield import Facing | |
- | |
-import random | |
class Unit(BattlefieldObject): | |
- | |
str = AttributeWithBonuses("str_base", ca.STREINGTH) | |
end = AttributeWithBonuses("end_base", ca.ENDURANCE) | |
prc = AttributeWithBonuses("prc_base", ca.PERCEPTION) | |
@@ -44,22 +42,23 @@ class Unit(BattlefieldObject): | |
armor = AttributeWithBonuses("armor_base", ca.ARMOR) | |
resists = AttributeWithBonuses("resists_base", ca.RESISTANCES) | |
- melee_precision = AttributeWithBonuses("melee_precision_base", ca.PRECISION) | |
+ melee_precision = AttributeWithBonuses( | |
+ "melee_precision_base", ca.PRECISION) | |
melee_evasion = AttributeWithBonuses("melee_evasion_base", ca.EVASION) | |
- | |
- health = DynamicParameter("max_health", [lambda u : events.UnitDiedEvent(u)]) | |
+ health = DynamicParameter( | |
+ "max_health", [ | |
+ lambda u: events.UnitDiedEvent(u)]) | |
mana = DynamicParameter("max_mana") | |
stamina = DynamicParameter("max_stamina") | |
is_obstacle = False | |
- | |
def __init__(self, | |
base_type: BaseType, *, | |
- cell = None, | |
- facing = Facing.NORTH, | |
- faction = Faction.ENEMY, | |
+ cell=None, | |
+ facing=Facing.NORTH, | |
+ faction=Faction.ENEMY, | |
game=None, | |
masteries: Masteries = None): | |
super().__init__(cell) | |
@@ -76,7 +75,7 @@ class Unit(BattlefieldObject): | |
self.inventory = Inventory(base_type.inventory_capacity, self) | |
self.quick_items = QuickItems(base_type.quick_items, self) | |
- self.equipment :Equipment = Equipment(self) | |
+ self.equipment: Equipment = Equipment(self) | |
self.xp = base_type.xp | |
masteries = masteries or Masteries(base_type.xp) | |
@@ -88,21 +87,24 @@ class Unit(BattlefieldObject): | |
self.update(base_type, masteries) | |
- | |
- def update(self, base_type = None, masteries = None): | |
+ def update(self, base_type=None, masteries=None): | |
base_type = base_type or self.base_type | |
- self.str_base = Attribute.attribute_or_none(base_type.attributes[ca.STREINGTH]) | |
- self.end_base = Attribute.attribute_or_none(base_type.attributes[ca.ENDURANCE]) | |
- self.prc_base = Attribute.attribute_or_none(base_type.attributes[ca.PERCEPTION]) | |
- self.agi_base = Attribute.attribute_or_none(base_type.attributes[ca.AGILITY]) | |
- self.int_base = Attribute.attribute_or_none(base_type.attributes[ca.INTELLIGENCE]) | |
- self.cha_base = Attribute.attribute_or_none(base_type.attributes[ca.CHARISMA]) | |
+ self.str_base = Attribute.attribute_or_none( | |
+ base_type.attributes[ca.STREINGTH]) | |
+ self.end_base = Attribute.attribute_or_none( | |
+ base_type.attributes[ca.ENDURANCE]) | |
+ self.prc_base = Attribute.attribute_or_none( | |
+ base_type.attributes[ca.PERCEPTION]) | |
+ self.agi_base = Attribute.attribute_or_none( | |
+ base_type.attributes[ca.AGILITY]) | |
+ self.int_base = Attribute.attribute_or_none( | |
+ base_type.attributes[ca.INTELLIGENCE]) | |
+ self.cha_base = Attribute.attribute_or_none( | |
+ base_type.attributes[ca.CHARISMA]) | |
self.masteries = masteries or self.masteries | |
- | |
self.type_name = base_type.type_name | |
- | |
self.unarmed_damage_type = base_type.unarmed_damage_type | |
self.unarmed_chances = base_type.unarmed_chances | |
self.resists_base = Resistances(base_type.resists) | |
@@ -133,8 +135,6 @@ class Unit(BattlefieldObject): | |
if slot.content: | |
slot.content.on_equip(slot) | |
- | |
- | |
self.turn_ccw_active = self.give_active(turn_ccw) | |
self.turn_ccw = lambda: self.activate(self.turn_ccw_active) | |
@@ -174,14 +174,15 @@ class Unit(BattlefieldObject): | |
self.recalc() | |
def recalc(self): | |
- bonus_lists = [ability.bonus for ability in self.abilities if ability.bonus] | |
+ bonus_lists = [ | |
+ ability.bonus for ability in self.abilities if ability.bonus] | |
bonus_lists += [buff.bonus for buff in self.buffs if buff.bonus] | |
bonus_lists += self.equipment.bonuses | |
self.bonuses = frozenset(bonus_lists) | |
@property | |
def sight_range(self): | |
- return 1 + (self.prc/4) ** (2/3) | |
+ return 1 + (self.prc / 4) ** (2 / 3) | |
@property | |
def armor_base(self): | |
@@ -211,7 +212,7 @@ class Unit(BattlefieldObject): | |
@lru_cache() | |
def __initiative_formula(agi, intel, stamina): | |
return Attribute(1 + 9 * ((0.4 + agi / 25 + intel / 25) ** (3 / 5)) * ((stamina / ( | |
- 10*Constants.STAMINA_PER_STR)) ** (1 / 4)), 100, 0) | |
+ 10 * Constants.STAMINA_PER_STR)) ** (1 / 4)), 100, 0) | |
@property | |
def initiative(self): | |
@@ -230,11 +231,9 @@ class Unit(BattlefieldObject): | |
mastery = self.masteries[self.melee_mastery] | |
return Attribute(self.str + self.prc + mastery, 100, 0) | |
- | |
@property | |
def melee_evasion_base(self): | |
- return Attribute(self.prc*2 + self.agi*3, 100, 0) | |
- | |
+ return Attribute(self.prc * 2 + self.agi * 3, 100, 0) | |
def reset(self): | |
"""Give unit maximum values for all dynamic attributes""" | |
@@ -242,19 +241,18 @@ class Unit(BattlefieldObject): | |
@property | |
def tooltip_info(self): | |
- return {'name':f"{self.type_name}_{self.uid}", | |
- 'hp':str(int(self.health)), | |
- 'mana':str(self.mana), | |
- 'stamina':str(int(self.stamina)), | |
+ return {'name': f"{self.type_name}_{self.uid}", | |
+ 'hp': str(int(self.health)), | |
+ 'mana': str(self.mana), | |
+ 'stamina': str(int(self.stamina)), | |
'initiative': str(int(self.initiative)), | |
'damage': str(int(self.get_melee_weapon().damage.amount)), | |
'armor': repr(self.armor), | |
- 'attack':str(self.melee_precision), | |
- 'defence':str(self.melee_evasion)} | |
- | |
+ 'attack': str(self.melee_precision), | |
+ 'defence': str(self.melee_evasion)} | |
def give_active(self, active) -> Active: | |
cpy = copy.deepcopy(active) | |
@@ -269,25 +267,32 @@ class Unit(BattlefieldObject): | |
active = [a for a in self.actives if a.uid == searched_uid][0] | |
self.actives.remove(active) | |
- | |
- def activate(self, active: Active, user_targeting = None): | |
+ def activate(self, active: Active, user_targeting=None): | |
active.owner = self | |
return active.activate(user_targeting) | |
@property | |
def movement_actives(self): | |
- return [active for active in self.actives if ActiveTags.MOVEMENT in active.tags] | |
+ return [ | |
+ active for active in self.actives if ActiveTags.MOVEMENT in active.tags] | |
@property | |
def attack_actives(self): | |
- return [active for active in self.actives if ActiveTags.ATTACK in active.tags] | |
- | |
+ return [ | |
+ active for active in self.actives if ActiveTags.ATTACK in active.tags] | |
def get_unarmed_weapon(self): | |
- dmg = Damage(amount=self.str * Constants.UNARMED_DAMAGE_PER_STR, type=self.unarmed_damage_type) | |
- return Weapon(name="Fists", damage=dmg, chances=self.unarmed_chances, is_ranged=False, | |
- mastery=MasteriesEnum.UNARMED, game=self.game) | |
- | |
+ dmg = Damage( | |
+ amount=self.str * | |
+ Constants.UNARMED_DAMAGE_PER_STR, | |
+ type=self.unarmed_damage_type) | |
+ return Weapon( | |
+ name="Fists", | |
+ damage=dmg, | |
+ chances=self.unarmed_chances, | |
+ is_ranged=False, | |
+ mastery=MasteriesEnum.UNARMED, | |
+ game=self.game) | |
def get_melee_weapon(self): | |
weapon = self.equipment[EquipmentSlotUids.HANDS] | |
@@ -302,13 +307,11 @@ class Unit(BattlefieldObject): | |
return weapon | |
def can_pay(self, cost: Cost): | |
- return not any( [ | |
+ return not any([ | |
cost.mana > self.mana, | |
cost.stamina > self.stamina, | |
cost.health > self.health]) | |
- | |
- | |
def pay(self, cost): | |
self.mana -= cost.mana | |
self.stamina -= cost.stamina | |
@@ -326,7 +329,5 @@ class Unit(BattlefieldObject): | |
def attacks(self): | |
return [a for a in self.actives if ActiveTags.ATTACK in a.tags] | |
- | |
- | |
def __repr__(self): | |
return f"{self.type_name} {self.uid} with {self.health :.0f} HP" | |
diff --git a/game_objects/battlefield_objects/Wall.py b/game_objects/battlefield_objects/Wall.py | |
index 125837a..598660c 100644 | |
--- a/game_objects/battlefield_objects/Wall.py | |
+++ b/game_objects/battlefield_objects/Wall.py | |
@@ -2,6 +2,7 @@ from battlefield import Cell | |
from exceptions import PydolonsError | |
from typing import Union | |
+ | |
class Wall: | |
def __init__(self, cell: Union[Cell, complex], icon: str = 'wall.png'): | |
self.cell = cell | |
@@ -20,5 +21,4 @@ class Wall: | |
else: | |
raise PydolonsError( | |
f"Obj.cell attribute can only be assigned with complex or Cell types." | |
- f"Actual passed type: {type(value)}" | |
- ) | |
+ f"Actual passed type: {type(value)}") | |
diff --git a/game_objects/dungeon/Dungeon.py b/game_objects/dungeon/Dungeon.py | |
index cc3ca86..b68003d 100644 | |
--- a/game_objects/dungeon/Dungeon.py | |
+++ b/game_objects/dungeon/Dungeon.py | |
@@ -6,10 +6,12 @@ if TYPE_CHECKING: | |
from battlefield import Cell | |
from DreamGame import DreamGame | |
+ | |
class Dungeon: | |
@property | |
def tooltip_info(self): | |
return self.name | |
+ | |
def __init__(self, name: str, h: int, w: int, *, | |
construct_objs: Callable[[DreamGame], Collection[BattlefieldObject]], | |
hero_entrance: Union[Cell, complex], | |
@@ -24,4 +26,3 @@ class Dungeon: | |
self.hero_entrance = hero_entrance | |
self.icon = icon | |
- | |
diff --git a/game_objects/items/ChargedItem.py b/game_objects/items/ChargedItem.py | |
index b0dd8df..8a581bf 100644 | |
--- a/game_objects/items/ChargedItem.py | |
+++ b/game_objects/items/ChargedItem.py | |
@@ -3,13 +3,28 @@ from game_objects.attributes import DynamicParameter | |
from mechanics.events import ItemUsedUpEvent | |
from mechanics.actives import Active, ActiveTags, Cost | |
-#Design: ensure item has game variable as soon as it enters any interactable containers. | |
-class ChargedItem(Item): | |
+# Design: ensure item has game variable as soon as it enters any | |
+# interactable containers. | |
+ | |
- charges = DynamicParameter("max_charges", on_zero_callbacks=[ItemUsedUpEvent]) | |
+class ChargedItem(Item): | |
- def __init__(self, name, max_charges=1, *, targeting_cls=None, conditions=None, atb_cost=0.5, | |
- use_callbacks, tags=None, game=None, icon=None): | |
+ charges = DynamicParameter( | |
+ "max_charges", | |
+ on_zero_callbacks=[ItemUsedUpEvent]) | |
+ | |
+ def __init__( | |
+ self, | |
+ name, | |
+ max_charges=1, | |
+ *, | |
+ targeting_cls=None, | |
+ conditions=None, | |
+ atb_cost=0.5, | |
+ use_callbacks, | |
+ tags=None, | |
+ game=None, | |
+ icon=None): | |
super().__init__(name, ItemTypes.CHARGED, game=game, icon=icon) | |
assert isinstance(name, str) | |
assert isinstance(max_charges, int) | |
@@ -18,8 +33,12 @@ class ChargedItem(Item): | |
def decrease_charges_cb(active, target): | |
self.charges -= 1 | |
- self.active = Active(targeting_cls, conditions, Cost(readiness=atb_cost), name=f"Use {self}", | |
- callbacks=use_callbacks +[decrease_charges_cb], tags=[ActiveTags.CHARGED_ITEM] + (tags or [])) | |
+ self.active = Active(targeting_cls, | |
+ conditions, | |
+ Cost(readiness=atb_cost), | |
+ name=f"Use {self}", | |
+ callbacks=use_callbacks + [decrease_charges_cb], | |
+ tags=[ActiveTags.CHARGED_ITEM] + (tags or [])) | |
def on_equip(self, slot): | |
if slot.item_type == self.item_type: | |
@@ -28,11 +47,3 @@ class ChargedItem(Item): | |
def on_unequip(self, slot): | |
if slot.item_type == self.item_type: | |
self.owner.remove_active(self.active) | |
- | |
- | |
- | |
- | |
- | |
- | |
- | |
- | |
diff --git a/game_objects/items/Item.py b/game_objects/items/Item.py | |
index e07c672..289b87c 100644 | |
--- a/game_objects/items/Item.py | |
+++ b/game_objects/items/Item.py | |
@@ -6,8 +6,15 @@ if TYPE_CHECKING: | |
from game_objects.battlefield_objects import Unit | |
from game_objects.items import Slot, ItemTypes | |
+ | |
class Item: | |
- def __init__(self, name: str, item_type: ItemTypes, *, game: DreamGame=None, icon=None): | |
+ def __init__( | |
+ self, | |
+ name: str, | |
+ item_type: ItemTypes, | |
+ *, | |
+ game: DreamGame = None, | |
+ icon=None): | |
assert isinstance(name, str) | |
assert isinstance(item_type, ItemTypes) | |
self.item_type = item_type | |
@@ -23,4 +30,4 @@ class Item: | |
"type": f"{self.item_type}"} | |
def __repr__(self): | |
- return f"Item: {self.name}" | |
\ No newline at end of file | |
+ return f"Item: {self.name}" | |
diff --git a/game_objects/items/ItemTypes.py b/game_objects/items/ItemTypes.py | |
index b32c92d..52e91e7 100644 | |
--- a/game_objects/items/ItemTypes.py | |
+++ b/game_objects/items/ItemTypes.py | |
@@ -1,5 +1,6 @@ | |
from my_utils.named_enums import NameEnum, auto | |
+ | |
class ItemTypes(NameEnum): | |
BODY_ARMOR = auto() | |
WEAPON = auto() | |
@@ -15,5 +16,3 @@ class ItemTypes(NameEnum): | |
SPELL = auto() | |
CHARGED = auto() | |
- | |
- | |
diff --git a/game_objects/items/WearableItem.py b/game_objects/items/WearableItem.py | |
index d514892..a32da01 100644 | |
--- a/game_objects/items/WearableItem.py | |
+++ b/game_objects/items/WearableItem.py | |
@@ -9,15 +9,28 @@ from typing import TYPE_CHECKING | |
if TYPE_CHECKING: | |
from game_objects.items import Blueprint, Material, QualityLevel | |
-#Design: ensure item has game variable as soon as it enters any interactable containers. | |
+# Design: ensure item has game variable as soon as it enters any | |
+# interactable containers. | |
+ | |
+ | |
class WearableItem(Item): | |
- durability = DynamicParameter("max_durability", on_zero_callbacks=[ItemDestroyedEvent]) | |
+ durability = DynamicParameter( | |
+ "max_durability", | |
+ on_zero_callbacks=[ItemDestroyedEvent]) | |
energy = DynamicParameter("max_energy") | |
- def __init__(self, name, item_type, *, blueprint:Blueprint=None, quality:QualityLevel=None, material:Material=None, | |
- max_durability=None, actives = None, | |
- game=None): | |
+ def __init__( | |
+ self, | |
+ name, | |
+ item_type, | |
+ *, | |
+ blueprint: Blueprint = None, | |
+ quality: QualityLevel = None, | |
+ material: Material = None, | |
+ max_durability=None, | |
+ actives=None, | |
+ game=None): | |
super().__init__(name, item_type, game=game) | |
assert isinstance(name, str) | |
self.blueprint = blueprint | |
@@ -26,16 +39,20 @@ class WearableItem(Item): | |
self.max_durability = max_durability | |
self.rarity = self.calc_rarity() | |
- self.max_complexity = self.material.magic_complexity * self.rarity if self.material else 0 | |
- self.max_energy = self.material.magic_complexity * self.rarity ** 2 if self.material else 50 | |
+ self.max_complexity = self.material.magic_complexity * \ | |
+ self.rarity if self.material else 0 | |
+ self.max_energy = self.material.magic_complexity * \ | |
+ self.rarity ** 2 if self.material else 50 | |
self.active_enchantment = None | |
self.bonuses = [] | |
self.actives = actives or [] | |
@property | |
def price(self): | |
- components_price = self.blueprint.price + ( self.material.price * self.blueprint.material_count) | |
- return tractable_value( components_price * (0.8 + self.quality.rarity ** 4 / 5 ) ) | |
+ components_price = self.blueprint.price + \ | |
+ (self.material.price * self.blueprint.material_count) | |
+ return tractable_value( | |
+ components_price * (0.8 + self.quality.rarity ** 4 / 5)) | |
@property | |
def durability_factor(self): | |
@@ -50,7 +67,6 @@ class WearableItem(Item): | |
total_rarity = mr * qr * br | |
return total_rarity | |
- | |
def on_equip(self, slot): | |
if slot.item_type == self.item_type: | |
for active in self.actives: | |
@@ -60,6 +76,3 @@ class WearableItem(Item): | |
if slot.item_type == self.item_type: | |
for active in self.actives: | |
self.owner.remove_active(active) | |
- | |
- | |
- | |
diff --git a/game_objects/items/blueprints/Blueprint.py b/game_objects/items/blueprints/Blueprint.py | |
index f987396..70140fe 100644 | |
--- a/game_objects/items/blueprints/Blueprint.py | |
+++ b/game_objects/items/blueprints/Blueprint.py | |
@@ -2,35 +2,42 @@ from game_objects.items import Item, ItemTypes | |
from game_objects.items.materials.MaterialTypes import durability_per_material | |
from my_utils.utils import tractable_value | |
+ | |
class Blueprint(Item): | |
durability_per_rarity = 35 | |
BASE_PRICE = 5 | |
- def __init__(self, name, target_item_type, rarity, durability, material_count, material_type): | |
+ def __init__( | |
+ self, | |
+ name, | |
+ target_item_type, | |
+ rarity, | |
+ durability, | |
+ material_count, | |
+ material_type): | |
assert durability is None or 0.05 <= durability <= 20 | |
super().__init__(name, ItemTypes.BLUEPRINT) | |
self.target_item_type = target_item_type | |
self.name = name | |
self.rarity = rarity | |
- self.durability = (durability or 1) * rarity * Blueprint.durability_per_rarity | |
+ self.durability = (durability or 1) * rarity * \ | |
+ Blueprint.durability_per_rarity | |
self.material_count = material_count | |
self.material_type = material_type | |
- self.value = self.rarity ** 2.2 * (1+ (durability or 1) ) ** 2/3 | |
+ self.value = self.rarity ** 2.2 * (1 + (durability or 1)) ** 2 / 3 | |
self.bonuses = [] | |
- | |
- | |
@property | |
def price(self): | |
- return tractable_value(Blueprint.BASE_PRICE * (self.value ** 4.1 + 2 * self.value ** 3.3 + 1) ) | |
- | |
+ return tractable_value(Blueprint.BASE_PRICE * | |
+ (self.value ** 4.1 + 2 * self.value ** 3.3 + 1)) | |
def item_durability(self, rarity): | |
- return self.durability * rarity * durability_per_material[self.material_type] | |
+ return self.durability * rarity * \ | |
+ durability_per_material[self.material_type] | |
# @property | |
# def price(self): | |
# return | |
- | |
diff --git a/game_objects/items/blueprints/types/ArmorBlueprint.py b/game_objects/items/blueprints/types/ArmorBlueprint.py | |
index 6079546..d8c1f12 100644 | |
--- a/game_objects/items/blueprints/types/ArmorBlueprint.py | |
+++ b/game_objects/items/blueprints/types/ArmorBlueprint.py | |
@@ -7,17 +7,32 @@ from mechanics.damage import Armor | |
class ArmorBlueprint(Blueprint): | |
armor_per_rarity = 25 | |
- | |
- def __init__(self, name, target_item_type, rarity, armor=None, durability=None, material_count = 8): | |
+ def __init__( | |
+ self, | |
+ name, | |
+ target_item_type, | |
+ rarity, | |
+ armor=None, | |
+ durability=None, | |
+ material_count=8): | |
assert target_item_type in ArmorTypes | |
assert armor is None or isinstance(armor, Armor) | |
- super().__init__(name, target_item_type, rarity, durability, material_type=material_type_from_armor_type[target_item_type], material_count=material_count) | |
+ super().__init__( | |
+ name, | |
+ target_item_type, | |
+ rarity, | |
+ durability, | |
+ material_type=material_type_from_armor_type[target_item_type], | |
+ material_count=material_count) | |
self.armor = armor or Armor(rarity * ArmorBlueprint.armor_per_rarity) | |
def to_item(self, material, quality, *, game=None): | |
assert material.material_type is self.material_type | |
- total_rarity = material.rarity * quality.rarity *self.rarity | |
- armor = Armor(armor_dict={t: v*total_rarity for t, v in self.armor.items()} ) | |
+ total_rarity = material.rarity * quality.rarity * self.rarity | |
+ armor = Armor( | |
+ armor_dict={ | |
+ t: v * total_rarity for t, | |
+ v in self.armor.items()}) | |
durability = self.item_durability(total_rarity) | |
full_name = f"{quality.name} {self.name} of {material}" | |
return BodyArmor(full_name, armor, durability, blueprint=self, | |
@@ -25,5 +40,3 @@ class ArmorBlueprint(Blueprint): | |
def __repr__(self): | |
return f"{self.name} blueprint" | |
- | |
- | |
diff --git a/game_objects/items/blueprints/types/ArmorTypes.py b/game_objects/items/blueprints/types/ArmorTypes.py | |
index 7ba023d..69f0187 100644 | |
--- a/game_objects/items/blueprints/types/ArmorTypes.py | |
+++ b/game_objects/items/blueprints/types/ArmorTypes.py | |
@@ -1,6 +1,7 @@ | |
from my_utils.named_enums import auto, NameEnum | |
from game_objects.items import MaterialTypes | |
+ | |
class ArmorTypes(NameEnum): | |
T_SHIRT = auto() | |
LEATHER_JACKET = auto() | |
@@ -8,12 +9,12 @@ class ArmorTypes(NameEnum): | |
CUIRASS = auto() | |
FUR_SUIT = auto() | |
+ | |
a = ArmorTypes | |
m = MaterialTypes | |
material_type_from_armor_type = {a.T_SHIRT: m.CLOTH, | |
a.LEATHER_JACKET: m.SKIN, | |
- a.SCAILMAIL : m.METAL, | |
- a.CUIRASS : m.METAL, | |
- a.FUR_SUIT : m.FUR} | |
- | |
+ a.SCAILMAIL: m.METAL, | |
+ a.CUIRASS: m.METAL, | |
+ a.FUR_SUIT: m.FUR} | |
diff --git a/game_objects/items/blueprints/types/WeaponBlueprint.py b/game_objects/items/blueprints/types/WeaponBlueprint.py | |
index eb8354c..6e04908 100644 | |
--- a/game_objects/items/blueprints/types/WeaponBlueprint.py | |
+++ b/game_objects/items/blueprints/types/WeaponBlueprint.py | |
@@ -6,12 +6,28 @@ from mechanics.damage import Damage | |
class WeaponBlueprint(Blueprint): | |
damage_per_rarity = 50 | |
- def __init__(self, name, *, weapon_type: WeaponType, material_type, rarity, | |
- damage=None, durability=None, material_count = 3, actives=None, is_ranged=False): | |
+ def __init__( | |
+ self, | |
+ name, | |
+ *, | |
+ weapon_type: WeaponType, | |
+ material_type, | |
+ rarity, | |
+ damage=None, | |
+ durability=None, | |
+ material_count=3, | |
+ actives=None, | |
+ is_ranged=False): | |
assert material_type in MaterialTypes | |
assert damage is None or 0.05 <= damage <= 20 | |
- super().__init__(name, weapon_type, rarity, durability, material_type=material_type, material_count=material_count) | |
- self.damage = (damage or 1) | |
+ super().__init__( | |
+ name, | |
+ weapon_type, | |
+ rarity, | |
+ durability, | |
+ material_type=material_type, | |
+ material_count=material_count) | |
+ self.damage = (damage or 1) | |
self.weapon_type = weapon_type | |
self.actives = actives | |
self.is_ranged = is_ranged | |
@@ -20,15 +36,14 @@ class WeaponBlueprint(Blueprint): | |
if self.is_ranged: | |
self.value *= 1.4 | |
- | |
def to_item(self, material, quality, *, game=None): | |
assert material.material_type is self.material_type | |
total_rarity = material.rarity * quality.rarity | |
- damage = Damage( self.damage * | |
- WeaponBlueprint.damage_per_rarity * total_rarity * \ | |
- self.weapon_type.damage_factor, | |
- self.weapon_type.damage_type) | |
+ damage = Damage(self.damage * | |
+ WeaponBlueprint.damage_per_rarity * total_rarity * | |
+ self.weapon_type.damage_factor, | |
+ self.weapon_type.damage_type) | |
durability = self.durability * total_rarity | |
full_name = f"{quality.name} {self.name} of {material}" | |
@@ -42,5 +57,3 @@ class WeaponBlueprint(Blueprint): | |
def __repr__(self): | |
return f"{self.name} blueprint" | |
- | |
- | |
diff --git a/game_objects/items/blueprints/types/WeaponTypes.py b/game_objects/items/blueprints/types/WeaponTypes.py | |
index 73dcf81..e1076e4 100644 | |
--- a/game_objects/items/blueprints/types/WeaponTypes.py | |
+++ b/game_objects/items/blueprints/types/WeaponTypes.py | |
@@ -5,43 +5,101 @@ from mechanics.chances.CritHitGrazeMiss import ImpactChances | |
baseline_chances = ImpactChances(0.05, 0.35, 0.5) | |
+ | |
def chances_price(chances: ImpactChances): | |
crit_awesomeness = 0.2 + chances.crit / baseline_chances.crit | |
hit_awesomeness = 0.2 + chances.hit / baseline_chances.hit | |
graze_awesomeness = 0.2 + chances.crit / baseline_chances.graze | |
- return (crit_awesomeness * 2 + hit_awesomeness ** 5 + graze_awesomeness ** 5) / 5 | |
- | |
+ return (crit_awesomeness * 2 + hit_awesomeness ** | |
+ 5 + graze_awesomeness ** 5) / 5 | |
class WeaponType: | |
- def __init__(self, damage_type, mastery, chances, damage_factor=1., atb_factor=1., cost_factor=1): | |
+ def __init__( | |
+ self, | |
+ damage_type, | |
+ mastery, | |
+ chances, | |
+ damage_factor=1., | |
+ atb_factor=1., | |
+ cost_factor=1): | |
self.damage_type = damage_type | |
self.mastery = mastery | |
self.chances = chances | |
self.damage_factor = damage_factor | |
self.atb_factor = atb_factor | |
- self.cost_factor = cost_factor * chances_price(chances) * ( 1 + damage_factor ** 2 / (atb_factor** (2/3) )) / 2 | |
+ self.cost_factor = cost_factor * \ | |
+ chances_price(chances) * (1 + damage_factor ** 2 / (atb_factor ** (2 / 3))) / 2 | |
d = DamageTypes | |
m = MasteriesEnum | |
+ | |
class WeaponTypes: | |
- AXE = WeaponType(d.SLASH, m.AXE, ImpactChances(0.05, 0.3, 0.7), damage_factor=1.3, atb_factor=1.6) | |
+ AXE = WeaponType( | |
+ d.SLASH, | |
+ m.AXE, | |
+ ImpactChances( | |
+ 0.05, | |
+ 0.3, | |
+ 0.7), | |
+ damage_factor=1.3, | |
+ atb_factor=1.6) | |
SWORD = WeaponType(d.SLASH, m.SWORD, ImpactChances(0.05, 0.4, 0.5)) | |
- DAGGER = WeaponType(d.PIERCE, m.DAGGER, ImpactChances(0.10, 0.3, 0.2), damage_factor=0.7, atb_factor=0.45) | |
+ DAGGER = WeaponType( | |
+ d.PIERCE, | |
+ m.DAGGER, | |
+ ImpactChances( | |
+ 0.10, | |
+ 0.3, | |
+ 0.2), | |
+ damage_factor=0.7, | |
+ atb_factor=0.45) | |
SPEAR = WeaponType(d.PIERCE, m.SPEAR, ImpactChances(0.05, 0.4, 0.5)) | |
- HAMMER = WeaponType(d.CRUSH, m.HAMMER, ImpactChances(0.1, 0.35, 0.25), damage_factor=1.5, atb_factor=2.1) | |
+ HAMMER = WeaponType( | |
+ d.CRUSH, | |
+ m.HAMMER, | |
+ ImpactChances( | |
+ 0.1, | |
+ 0.35, | |
+ 0.25), | |
+ damage_factor=1.5, | |
+ atb_factor=2.1) | |
CLUB = WeaponType(d.CRUSH, m.CLUB, ImpactChances(0.07, 0.37, 0.47)) | |
- BOW = WeaponType(d.PIERCE, m.BOW, ImpactChances(0.02, 0.25, 0.25), cost_factor=3) | |
- CROSSBOW = WeaponType(d.PIERCE, m.SHOOT, ImpactChances(0.02, 0.25, 0.25), damage_factor=1.5, atb_factor=2.1, cost_factor=3) | |
+ BOW = WeaponType( | |
+ d.PIERCE, | |
+ m.BOW, | |
+ ImpactChances( | |
+ 0.02, | |
+ 0.25, | |
+ 0.25), | |
+ cost_factor=3) | |
+ CROSSBOW = WeaponType( | |
+ d.PIERCE, | |
+ m.SHOOT, | |
+ ImpactChances( | |
+ 0.02, | |
+ 0.25, | |
+ 0.25), | |
+ damage_factor=1.5, | |
+ atb_factor=2.1, | |
+ cost_factor=3) | |
if __name__ == "__main__": | |
wts = WeaponTypes | |
- for wt in [wts.AXE, wts.SWORD, wts.DAGGER, wts.SPEAR, wts.HAMMER, wts.CLUB, wts.BOW, wts.CROSSBOW]: | |
- print(wt.cost_factor) | |
\ No newline at end of file | |
+ for wt in [ | |
+ wts.AXE, | |
+ wts.SWORD, | |
+ wts.DAGGER, | |
+ wts.SPEAR, | |
+ wts.HAMMER, | |
+ wts.CLUB, | |
+ wts.BOW, | |
+ wts.CROSSBOW]: | |
+ print(wt.cost_factor) | |
diff --git a/game_objects/items/materials/MaterialTypes.py b/game_objects/items/materials/MaterialTypes.py | |
index fcdda54..8c07006 100644 | |
--- a/game_objects/items/materials/MaterialTypes.py | |
+++ b/game_objects/items/materials/MaterialTypes.py | |
@@ -1,6 +1,7 @@ | |
from my_utils.named_enums import NameEnum, auto | |
from mechanics.damage import DamageTypes, DamageTypeGroups | |
+ | |
class MaterialTypes(NameEnum): | |
STONE = auto() | |
WOOD = auto() | |
@@ -16,34 +17,28 @@ mt = MaterialTypes | |
dt = DamageTypes | |
dtg = DamageTypeGroups | |
-armor_per_material = {m : {d:1 for d in dt} for m in mt} | |
+armor_per_material = {m: {d: 1 for d in dt} for m in mt} | |
for m in armor_per_material: | |
armor_per_material[m][dt.SONIC] = 0.2 | |
-armor_per_material[mt.METAL].update({ d : 1.15 for d in dtg.physical}) | |
-armor_per_material[mt.METAL].update({d : 0.4 for d in dtg.elemental}) | |
+armor_per_material[mt.METAL].update({d: 1.15 for d in dtg.physical}) | |
+armor_per_material[mt.METAL].update({d: 0.4 for d in dtg.elemental}) | |
armor_per_material[mt.METAL][dt.LIGHTNING] = 0.15 | |
armor_per_material[mt.METAL][dt.SONIC] = 0.15 | |
-armor_per_material[mt.SKIN].update({d : 1.2 for d in dtg.elemental}) | |
+armor_per_material[mt.SKIN].update({d: 1.2 for d in dtg.elemental}) | |
armor_per_material[mt.SKIN][dt.PIERCE] = 0.7 | |
armor_per_material[mt.SKIN][dt.SONIC] = 0.33 | |
-armor_per_material[mt.FUR].update({d : 2 for d in dtg.elemental}) | |
+armor_per_material[mt.FUR].update({d: 2 for d in dtg.elemental}) | |
armor_per_material[mt.FUR][dt.ACID] = 1 | |
armor_per_material[mt.FUR][dt.SONIC] = 0.33 | |
-armor_per_material[mt.CRYSTAL].update({d : 2 for d in dtg.physical}) | |
+armor_per_material[mt.CRYSTAL].update({d: 2 for d in dtg.physical}) | |
armor_per_material[mt.CRYSTAL][dt.CRUSH] = 0.5 | |
armor_per_material[mt.CLOTH].update({d: 0.3 for d in dtg.physical}) | |
-durability_per_material = {m : 1 for m in mt} | |
+durability_per_material = {m: 1 for m in mt} | |
durability_per_material[mt.STONE] = 0.6 | |
durability_per_material[mt.METAL] = 2.5 | |
durability_per_material[mt.CRYSTAL] = 0.15 | |
durability_per_material[mt.WOOD] = 2 | |
durability_per_material[mt.BONE] = 0.7 | |
- | |
- | |
- | |
- | |
- | |
- | |
diff --git a/game_objects/items/materials/Materials.py b/game_objects/items/materials/Materials.py | |
index 67839dd..a4e90ba 100644 | |
--- a/game_objects/items/materials/Materials.py | |
+++ b/game_objects/items/materials/Materials.py | |
@@ -5,6 +5,7 @@ from typing import TYPE_CHECKING | |
if TYPE_CHECKING: | |
from game_objects.items.materials.MaterialTypes import MaterialTypes | |
+ | |
class MaterialPieces(items.Item): | |
def __init__(self, material, pieces): | |
super().__init__(material.name, items.ItemTypes.MATERIAL) | |
@@ -14,18 +15,26 @@ class MaterialPieces(items.Item): | |
class Material: | |
BASE_PRICE = 30 | |
- def __init__(self, material_type:MaterialTypes, name, rarity, magic_complexity=1, energy=50): | |
+ def __init__( | |
+ self, | |
+ material_type: MaterialTypes, | |
+ name, | |
+ rarity, | |
+ magic_complexity=1, | |
+ energy=50): | |
self.material_type = material_type | |
self.name = name | |
self.rarity = rarity | |
self.magic_complexity = magic_complexity | |
self.energy = energy | |
- self.value = self.rarity** 2.7 * ( 1 + (self.magic_complexity - 1) ** 2 + (self.energy-50)/150 ) | |
+ self.value = self.rarity ** 2.7 * \ | |
+ (1 + (self.magic_complexity - 1) ** 2 + (self.energy - 50) / 150) | |
@property | |
def price(self): | |
- return tractable_value( Material.BASE_PRICE * ( 1e-3*self.value**5 + 1e-2*self.value**3 + self.value ) ) | |
+ return tractable_value( | |
+ Material.BASE_PRICE * (1e-3 * self.value**5 + 1e-2 * self.value**3 + self.value)) | |
def to_pieces(self, count_pieces): | |
return MaterialPieces(self, count_pieces) | |
diff --git a/game_objects/items/on_unit/ItemTransactions.py b/game_objects/items/on_unit/ItemTransactions.py | |
index 9b6f961..48b8c74 100644 | |
--- a/game_objects/items/on_unit/ItemTransactions.py | |
+++ b/game_objects/items/on_unit/ItemTransactions.py | |
@@ -1,5 +1,6 @@ | |
from game_objects.items import Item, Slot | |
+ | |
class ItemTransactions: | |
def __init__(self, unit): | |
@@ -18,11 +19,9 @@ class ItemTransactions: | |
return False | |
return True | |
- | |
def take_from(self, slot): | |
self.manipulation_slot.swap_item(slot) | |
- | |
def stop_manipulation(self): | |
if self.manipulation_slot: | |
if self.pickup(self.manipulation_slot): | |
@@ -35,7 +34,3 @@ class ItemTransactions: | |
def __exit__(self, exc_type, exc_val, exc_tb): | |
self.stop_manipulation() | |
- | |
- | |
- | |
- | |
diff --git a/game_objects/items/on_unit/Slot.py b/game_objects/items/on_unit/Slot.py | |
index b0c1d21..e49a833 100644 | |
--- a/game_objects/items/on_unit/Slot.py | |
+++ b/game_objects/items/on_unit/Slot.py | |
@@ -8,7 +8,11 @@ if TYPE_CHECKING: | |
class Slot: | |
- def __init__(self, name:str, item_type : ItemTypes = None, owner: Unit = None): | |
+ def __init__( | |
+ self, | |
+ name: str, | |
+ item_type: ItemTypes = None, | |
+ owner: Unit = None): | |
self.name = name | |
self.item_type = item_type | |
self.owner = owner | |
@@ -52,9 +56,10 @@ class Slot: | |
else: | |
return self.item_type is item.item_type | |
- | |
def swap_item(self, other_slot: Slot): | |
- if self.check_type_match(other_slot.content) and other_slot.check_type_match(self.content): | |
+ if self.check_type_match( | |
+ other_slot.content) and other_slot.check_type_match( | |
+ self.content): | |
self._content, other_slot._content = other_slot.pop_item(), self.pop_item() | |
return True | |
else: | |
@@ -83,5 +88,3 @@ class Slot: | |
def __repr__(self): | |
return f"{self.owner}'s {self.name} slot with {self.content}" | |
- | |
- | |
diff --git a/game_objects/items/on_unit/StandardEquipment.py b/game_objects/items/on_unit/StandardEquipment.py | |
index c79f01f..0e572a0 100644 | |
--- a/game_objects/items/on_unit/StandardEquipment.py | |
+++ b/game_objects/items/on_unit/StandardEquipment.py | |
@@ -3,6 +3,7 @@ from game_objects.items.on_unit.EquipmentSlotUids import EquipmentSlotUids | |
ss = EquipmentSlotUids | |
+ | |
class StandardEquipment: | |
std_slots = [ | |
@@ -19,6 +20,6 @@ class StandardEquipment: | |
result = {} | |
for uid, slot_type in StandardEquipment.std_slots: | |
- result[uid] = Slot( uid.name, slot_type, owner ) | |
+ result[uid] = Slot(uid.name, slot_type, owner) | |
- return result | |
\ No newline at end of file | |
+ return result | |
diff --git a/game_objects/items/on_unit/slot_groups/Equipment.py b/game_objects/items/on_unit/slot_groups/Equipment.py | |
index b464075..c328a94 100644 | |
--- a/game_objects/items/on_unit/slot_groups/Equipment.py | |
+++ b/game_objects/items/on_unit/slot_groups/Equipment.py | |
@@ -10,9 +10,10 @@ if TYPE_CHECKING: | |
class Equipment(SlotGroup): | |
def __init__(self, owner): | |
- self.map : Dict[EquipmentSlotUids, Slot] = StandardEquipment.get_standard_slots(owner) | |
- all_slots = [v for k,v in self.map.items()] | |
- self.slots_per_type = {st:[] for st in ItemTypes} | |
+ self.map: Dict[EquipmentSlotUids, | |
+ Slot] = StandardEquipment.get_standard_slots(owner) | |
+ all_slots = [v for k, v in self.map.items()] | |
+ self.slots_per_type = {st: [] for st in ItemTypes} | |
for slot in all_slots: | |
slot_type = slot.item_type | |
self.slots_per_type[slot_type].append(slot) | |
@@ -21,7 +22,8 @@ class Equipment(SlotGroup): | |
@property | |
def bonuses(self): | |
- return itertools.chain.from_iterable([item.bonuses for item in self.all_items]) | |
+ return itertools.chain.from_iterable( | |
+ [item.bonuses for item in self.all_items]) | |
def equip_item(self, item) -> Tuple[bool, str]: | |
""" | |
@@ -41,20 +43,21 @@ class Equipment(SlotGroup): | |
if not all_slots_of_type: | |
return False, "owner does not have a slot for this type of item" | |
- empty_slots_of_type = [slot for slot in all_slots_of_type if not slot.content] | |
+ empty_slots_of_type = [ | |
+ slot for slot in all_slots_of_type if not slot.content] | |
if empty_slots_of_type: | |
chosen_slot = empty_slots_of_type[0] | |
chosen_slot.content = item | |
self.owner.recalc() | |
- return True ,"item was put into an empty slot" | |
+ return True, "item was put into an empty slot" | |
else: | |
if self.owner.inventory.add_from(all_slots_of_type[0]): | |
all_slots_of_type[0].content = item | |
self.owner.recalc() | |
return True, "replaced an item" | |
else: | |
- return False , "slot is occupied, inventory is full: can't equip" | |
+ return False, "slot is occupied, inventory is full: can't equip" | |
def equip(self, slot_from: Slot): | |
item = slot_from.pop_item() | |
@@ -64,7 +67,6 @@ class Equipment(SlotGroup): | |
return success, message | |
- | |
def unequip_slot(self, slot): | |
if isinstance(slot, EquipmentSlotUids): | |
slot = self.map[slot] | |
@@ -81,13 +83,5 @@ class Equipment(SlotGroup): | |
if slot.content is item: | |
self.unequip_slot(slot) | |
- | |
def __getitem__(self, item): | |
return self.map[item].content | |
- | |
- | |
- | |
- | |
- | |
- | |
- | |
diff --git a/game_objects/items/on_unit/slot_groups/Inventory.py b/game_objects/items/on_unit/slot_groups/Inventory.py | |
index c0d2ce0..245fb9b 100644 | |
--- a/game_objects/items/on_unit/slot_groups/Inventory.py | |
+++ b/game_objects/items/on_unit/slot_groups/Inventory.py | |
@@ -1,6 +1,7 @@ | |
from game_objects.items import Slot | |
from game_objects.items.on_unit.slot_groups.SlotGroup import SlotGroup | |
+ | |
class Inventory(SlotGroup): | |
@staticmethod | |
@@ -8,10 +9,6 @@ class Inventory(SlotGroup): | |
return "inventory_{0:00d}".format(i) | |
def __init__(self, max_capacity, owner): | |
- all_slots = [Slot(Inventory.slot_name_at(i), owner=owner) for i in range(max_capacity)] | |
+ all_slots = [Slot(Inventory.slot_name_at(i), owner=owner) | |
+ for i in range(max_capacity)] | |
super().__init__(all_slots, owner) | |
- | |
- | |
- | |
- | |
- | |
diff --git a/game_objects/items/on_unit/slot_groups/QuickItems.py b/game_objects/items/on_unit/slot_groups/QuickItems.py | |
index 32401f7..f2a8bc5 100644 | |
--- a/game_objects/items/on_unit/slot_groups/QuickItems.py | |
+++ b/game_objects/items/on_unit/slot_groups/QuickItems.py | |
@@ -1,6 +1,7 @@ | |
from game_objects.items import Slot, ItemTypes | |
from game_objects.items.on_unit.slot_groups.SlotGroup import SlotGroup | |
+ | |
class QuickItems(SlotGroup): | |
@staticmethod | |
@@ -8,11 +9,9 @@ class QuickItems(SlotGroup): | |
return "Quick item {0:0d}".format(i) | |
def __init__(self, max_capacity, owner): | |
- all_slots = [Slot(self.slot_name_at(i), item_type=ItemTypes.CHARGED, owner=owner) for i in range(max_capacity)] | |
+ all_slots = [ | |
+ Slot( | |
+ self.slot_name_at(i), | |
+ item_type=ItemTypes.CHARGED, | |
+ owner=owner) for i in range(max_capacity)] | |
super().__init__(all_slots, owner) | |
- | |
- | |
- | |
- | |
- | |
- | |
diff --git a/game_objects/items/on_unit/slot_groups/SlotGroup.py b/game_objects/items/on_unit/slot_groups/SlotGroup.py | |
index d2a0d99..bf8f698 100644 | |
--- a/game_objects/items/on_unit/slot_groups/SlotGroup.py | |
+++ b/game_objects/items/on_unit/slot_groups/SlotGroup.py | |
@@ -5,9 +5,10 @@ if TYPE_CHECKING: | |
from game_objects.items import Slot | |
from game_objects.battlefield_objects import Unit | |
+ | |
class SlotGroup: | |
- def __init__(self, all_slots : List[Slot], owner: Unit): | |
+ def __init__(self, all_slots: List[Slot], owner: Unit): | |
self.all_slots = all_slots | |
self.owner = owner | |
@@ -51,6 +52,3 @@ class SlotGroup: | |
def __len__(self): | |
return len(self.all_slots) | |
- | |
- | |
- | |
diff --git a/game_objects/items/types/BodyArmor.py b/game_objects/items/types/BodyArmor.py | |
index 5c242f3..dc8aeeb 100644 | |
--- a/game_objects/items/types/BodyArmor.py | |
+++ b/game_objects/items/types/BodyArmor.py | |
@@ -2,12 +2,28 @@ from game_objects.items import WearableItem, ItemTypes | |
from mechanics.damage import Armor | |
import copy | |
+ | |
class BodyArmor(WearableItem): | |
- def __init__(self, name, armor, max_durability, *, blueprint=None, material=None, quality=None, game): | |
+ def __init__( | |
+ self, | |
+ name, | |
+ armor, | |
+ max_durability, | |
+ *, | |
+ blueprint=None, | |
+ material=None, | |
+ quality=None, | |
+ game): | |
assert isinstance(armor, Armor) | |
- super().__init__(name, item_type=ItemTypes.BODY_ARMOR, blueprint=blueprint, material=material, quality=quality, | |
- max_durability=max_durability, game=game) | |
+ super().__init__( | |
+ name, | |
+ item_type=ItemTypes.BODY_ARMOR, | |
+ blueprint=blueprint, | |
+ material=material, | |
+ quality=quality, | |
+ max_durability=max_durability, | |
+ game=game) | |
self._armor = armor | |
@property | |
@@ -27,4 +43,3 @@ class BodyArmor(WearableItem): | |
def __repr__(self): | |
return f"{self.name} providing {self.armor} armor" | |
- | |
diff --git a/game_objects/items/types/Weapon.py b/game_objects/items/types/Weapon.py | |
index 939394d..4a6a314 100644 | |
--- a/game_objects/items/types/Weapon.py | |
+++ b/game_objects/items/types/Weapon.py | |
@@ -4,14 +4,32 @@ from mechanics.chances.CritHitGrazeMiss import ImpactChances | |
import copy | |
+ | |
class Weapon(WearableItem): | |
- def __init__(self, name, damage, chances=None, atb_factor=1., *,max_durability=None, | |
- mastery=None, blueprint=None, material=None,quality=None, actives=None, | |
- is_ranged, | |
- game): | |
- super().__init__(name, ItemTypes.WEAPON, blueprint=blueprint, quality=quality, | |
- material=material, max_durability=max_durability, actives=actives, | |
- game=game) | |
+ def __init__( | |
+ self, | |
+ name, | |
+ damage, | |
+ chances=None, | |
+ atb_factor=1., | |
+ *, | |
+ max_durability=None, | |
+ mastery=None, | |
+ blueprint=None, | |
+ material=None, | |
+ quality=None, | |
+ actives=None, | |
+ is_ranged, | |
+ game): | |
+ super().__init__( | |
+ name, | |
+ ItemTypes.WEAPON, | |
+ blueprint=blueprint, | |
+ quality=quality, | |
+ material=material, | |
+ max_durability=max_durability, | |
+ actives=actives, | |
+ game=game) | |
assert isinstance(damage, Damage) | |
if chances: | |
assert isinstance(chances, ImpactChances) | |
@@ -27,7 +45,10 @@ class Weapon(WearableItem): | |
if self.max_durability is None: | |
return copy.copy(self._damage) | |
- return Damage(self._damage.amount * self.durability_factor, self._damage.type) | |
+ return Damage( | |
+ self._damage.amount * | |
+ self.durability_factor, | |
+ self._damage.type) | |
@property | |
def tooltip_info(self): | |
diff --git a/game_objects/monsters/Monster.py b/game_objects/monsters/Monster.py | |
index 07ff773..eaa0b2c 100644 | |
--- a/game_objects/monsters/Monster.py | |
+++ b/game_objects/monsters/Monster.py | |
@@ -3,9 +3,14 @@ from game_objects.battlefield_objects import BaseType, Unit | |
from game_objects.monsters.MonsterEquipment import MonsterEquipment | |
import copy | |
+ | |
class Monster: | |
- def __init__(self, base_type: BaseType, items = None, masteries : Masteries = None ): | |
+ def __init__( | |
+ self, | |
+ base_type: BaseType, | |
+ items=None, | |
+ masteries: Masteries = None): | |
if items: | |
if not isinstance(items, MonsterEquipment): | |
@@ -15,7 +20,6 @@ class Monster: | |
self.items = items | |
self.masteries = masteries | |
- | |
def create(self, game, cell=None) -> Unit: | |
unit = Unit(self.base_type, game=game, cell=cell) | |
if self.items: | |
@@ -26,8 +30,7 @@ class Monster: | |
if self.masteries: | |
unit.masteries = copy.copy(self.masteries) | |
else: | |
- unit.masteries = Masteries.max_out(self.base_type.xp, unit.melee_mastery) | |
- | |
+ unit.masteries = Masteries.max_out( | |
+ self.base_type.xp, unit.melee_mastery) | |
return unit | |
- | |
diff --git a/game_objects/monsters/MonsterEquipment.py b/game_objects/monsters/MonsterEquipment.py | |
index 890724e..0992efa 100644 | |
--- a/game_objects/monsters/MonsterEquipment.py | |
+++ b/game_objects/monsters/MonsterEquipment.py | |
@@ -1,5 +1,6 @@ | |
import copy | |
+ | |
class MonsterEquipment: | |
def __init__(self, groups_sequence): | |
@@ -20,7 +21,7 @@ class MonsterEquipment: | |
self.random = None | |
def new_sequence(self, random): | |
- return [copy.deepcopy( random.choice(group) ) for group in self.sequence] | |
+ return [copy.deepcopy(random.choice(group)) for group in self.sequence] | |
def __iter__(self): | |
return iter(self.new_sequence(self.random)) | |
@@ -43,4 +44,3 @@ class MonsterEquipment: | |
# | |
# for item in me: | |
# print(item) | |
- | |
diff --git a/game_objects/spells/Rune.py b/game_objects/spells/Rune.py | |
index ac20248..8197dfd 100644 | |
--- a/game_objects/spells/Rune.py | |
+++ b/game_objects/spells/Rune.py | |
@@ -1,6 +1,7 @@ | |
from game_objects.items import Item, ItemTypes | |
+ | |
class Rune(Item): | |
def __init__(self, bonuses, name="Mysterious Rune"): | |
super().__init__(name, ItemTypes.SPELL) | |
- self.bonuses = bonuses | |
\ No newline at end of file | |
+ self.bonuses = bonuses | |
diff --git a/game_objects/spells/Spell.py b/game_objects/spells/Spell.py | |
index 94b6837..73ae276 100644 | |
--- a/game_objects/spells/Spell.py | |
+++ b/game_objects/spells/Spell.py | |
@@ -34,4 +34,3 @@ class Spell(Item): | |
def complexity_check(self, unit): | |
return unit.masteries[self.school] + unit.int >= self.complexity | |
- | |
diff --git a/game_objects/spells/SpellAttributes.py b/game_objects/spells/SpellAttributes.py | |
index 85b531a..db1e0dd 100644 | |
--- a/game_objects/spells/SpellAttributes.py | |
+++ b/game_objects/spells/SpellAttributes.py | |
@@ -1,5 +1,6 @@ | |
from my_utils.named_enums import NameEnum, auto | |
+ | |
class SpellAttributes: | |
COMPLEXITY = auto() | |
MANA_COST = auto() | |
diff --git a/game_objects/spells/SpellConcept.py b/game_objects/spells/SpellConcept.py | |
index a6e7589..705cd68 100644 | |
--- a/game_objects/spells/SpellConcept.py | |
+++ b/game_objects/spells/SpellConcept.py | |
@@ -6,16 +6,24 @@ from game_objects.items import Item, ItemTypes | |
class SpellConcept(Item): | |
- complexity = AttributeWithBonuses("complexity_base", SpellAttributes.COMPLEXITY) | |
- | |
- mana_cost = AttributeWithBonuses("mana_cost_base", SpellAttributes.MANA_COST) | |
- stamina_cost = AttributeWithBonuses("stamina_cost_base", SpellAttributes.STAMINA_COST) | |
- health_cost = AttributeWithBonuses("health_cost_base", SpellAttributes.HEALTH_COST) | |
- readiness_cost = AttributeWithBonuses("readiness_cost_base", SpellAttributes.READINESS_COST) | |
+ complexity = AttributeWithBonuses( | |
+ "complexity_base", SpellAttributes.COMPLEXITY) | |
+ | |
+ mana_cost = AttributeWithBonuses( | |
+ "mana_cost_base", SpellAttributes.MANA_COST) | |
+ stamina_cost = AttributeWithBonuses( | |
+ "stamina_cost_base", SpellAttributes.STAMINA_COST) | |
+ health_cost = AttributeWithBonuses( | |
+ "health_cost_base", SpellAttributes.HEALTH_COST) | |
+ readiness_cost = AttributeWithBonuses( | |
+ "readiness_cost_base", | |
+ SpellAttributes.READINESS_COST) | |
amount = AttributeWithBonuses("amount_base", SpellAttributes.AMOUNT) | |
duration = AttributeWithBonuses("duration_base", SpellAttributes.DURATION) | |
- precision_factor = AttributeWithBonuses("precision_factor_base", SpellAttributes.PRECISION_FACTOR) | |
+ precision_factor = AttributeWithBonuses( | |
+ "precision_factor_base", | |
+ SpellAttributes.PRECISION_FACTOR) | |
distance = AttributeWithBonuses("distance_base", SpellAttributes.DISTANCE) | |
radius = AttributeWithBonuses("radius_base", SpellAttributes.RADIUS) | |
@@ -40,7 +48,8 @@ class SpellConcept(Item): | |
self.amount_base = Attribute.attribute_or_none(amount) | |
self.duration_base = Attribute.attribute_or_none(duration) | |
- self.precision_factor_base = Attribute.attribute_or_none(precision_factor) | |
+ self.precision_factor_base = Attribute.attribute_or_none( | |
+ precision_factor) | |
self.distance_base = Attribute.attribute_or_none(distance) | |
self.radius_base = Attribute.attribute_or_none(radius) | |
@@ -49,24 +58,31 @@ class SpellConcept(Item): | |
@property | |
def bonuses(self): | |
- #TODO test that same runes stack - set is a risk w/o copying the bonuses. | |
+ # TODO test that same runes stack - set is a risk w/o copying the | |
+ # bonuses. | |
if self.runes: | |
return frozenset(flatten([rune.bonuses for rune in self.runes])) | |
else: | |
return frozenset() | |
- | |
- | |
- | |
def to_spell(self, runes): | |
self.runes = runes | |
- cost = Cost(self.mana_cost, self.stamina_cost, self.health_cost, self.readiness_cost) | |
- spell = Spell(runes=runes, concept=self, complexity=self.complexity, cooldown=self.cooldown, | |
- cost=cost, amount=self.amount, duration=self.duration, | |
- precision_factor=self.precision_factor, range=self.distance, | |
- radius=self.radius, resolve_callback=self.resolve_callback) | |
+ cost = Cost( | |
+ self.mana_cost, | |
+ self.stamina_cost, | |
+ self.health_cost, | |
+ self.readiness_cost) | |
+ spell = Spell( | |
+ runes=runes, | |
+ concept=self, | |
+ complexity=self.complexity, | |
+ cooldown=self.cooldown, | |
+ cost=cost, | |
+ amount=self.amount, | |
+ duration=self.duration, | |
+ precision_factor=self.precision_factor, | |
+ range=self.distance, | |
+ radius=self.radius, | |
+ resolve_callback=self.resolve_callback) | |
self.runes = None | |
return spell | |
- | |
- | |
- | |
diff --git a/launch.py b/launch.py | |
index 933fdaf..c078b1f 100644 | |
--- a/launch.py | |
+++ b/launch.py | |
@@ -1,3 +1,4 @@ | |
+from cProfile import Profile | |
from ui.TheUI import TheUI | |
import sys | |
@@ -8,8 +9,11 @@ from LEngine import LEngine | |
def one_game(): | |
# Qt application initialization | |
app = QtWidgets.QApplication(sys.argv) | |
- app.setOverrideCursor(QtGui.QCursor(QtGui.QPixmap('resources/assets/ui/cursor.png'), | |
- hotX =1, hotY= 1)) | |
+ app.setOverrideCursor( | |
+ QtGui.QCursor( | |
+ QtGui.QPixmap('resources/assets/ui/cursor.png'), | |
+ hotX=1, | |
+ hotY=1)) | |
lengine = LEngine() | |
window = TheUI(lengine) | |
app.aboutToQuit.connect(window.close_app) | |
@@ -18,7 +22,7 @@ def one_game(): | |
# one_game() | |
-from cProfile import Profile | |
+ | |
profiler = Profile() | |
profiler.runcall(one_game) | |
profiler.print_stats('cumulative') | |
diff --git a/mechanics/AI/AstarAI.py b/mechanics/AI/AstarAI.py | |
index 910a790..9639491 100644 | |
--- a/mechanics/AI/AstarAI.py | |
+++ b/mechanics/AI/AstarAI.py | |
@@ -7,6 +7,7 @@ if TYPE_CHECKING: | |
from game_objects.battlefield_objects import Unit | |
from DreamGame import DreamGame | |
+ | |
class StarSearch(AStar): | |
really_big_number = 1e50 | |
@@ -24,7 +25,8 @@ class StarSearch(AStar): | |
return neighbours | |
def distance_between(self, n1, n2): | |
- #TODO maybe we need to ensure actual measurement on the nodes, not the fast, emulated one. | |
+ # TODO maybe we need to ensure actual measurement on the nodes, not the | |
+ # fast, emulated one. | |
return n1.utility(self.faction) - n2.utility(self.faction) | |
def heuristic_cost_estimate(self, current, goal): | |
@@ -39,7 +41,6 @@ class AstarAI: | |
self.game = game | |
self.random_ai = RandomAI(game) | |
- | |
def decide_step(self, active_unit, depth_limit=50): | |
astar = StarSearch(self.game, active_unit, depth_limit) | |
@@ -48,4 +49,3 @@ class AstarAI: | |
node = list(path)[1] | |
choice = node.choice | |
return choice | |
- | |
diff --git a/mechanics/AI/BroadAI.py b/mechanics/AI/BroadAI.py | |
index 6dd4062..26986d5 100644 | |
--- a/mechanics/AI/BroadAI.py | |
+++ b/mechanics/AI/BroadAI.py | |
@@ -1,12 +1,13 @@ | |
from mechanics.AI import RandomAI | |
import random | |
+ | |
class BroadAI: | |
def __init__(self, game): | |
self.game = game | |
self.random_ai = RandomAI(game) | |
- def decide_step(self, active_unit, epsilon = 0.0): | |
+ def decide_step(self, active_unit, epsilon=0.0): | |
if random.random() < epsilon: | |
return self.random_ai.decide_step(active_unit) | |
@@ -18,7 +19,10 @@ class BroadAI: | |
circle2 += node.get_all_neighbouring_states(active_unit) | |
faction = active_unit.faction | |
- utilities = {node:(node.utility(faction) + node.node_from.utility(faction)) for node in circle2} | |
+ utilities = { | |
+ node: ( | |
+ node.utility(faction) + | |
+ node.node_from.utility(faction)) for node in circle2} | |
# this bug a lot of taps | |
best_node2 = max(circle2, key=lambda x: utilities[x]) | |
best_node1 = best_node2.node_from | |
diff --git a/mechanics/AI/BruteAI.py b/mechanics/AI/BruteAI.py | |
index 7e44b79..e145c5d 100644 | |
--- a/mechanics/AI/BruteAI.py | |
+++ b/mechanics/AI/BruteAI.py | |
@@ -1,12 +1,13 @@ | |
from mechanics.AI import RandomAI | |
import random | |
+ | |
class BruteAI: | |
def __init__(self, game): | |
self.game = game | |
self.random_ai = RandomAI(game) | |
- def decide_step(self, active_unit, epsilon = 0.0) : | |
+ def decide_step(self, active_unit, epsilon=0.0): | |
if random.random() < epsilon: | |
return self.random_ai.decide_step(active_unit) | |
@@ -14,16 +15,8 @@ class BruteAI: | |
neighbour_nodes = self.game.get_all_neighbouring_states(active_unit) | |
faction = active_unit.faction | |
- # nodes_utils = [(node, node.utility(faction)) for node in neighbour_nodes] #easy debug | |
- best_node = max(neighbour_nodes, key= lambda x: x.utility(faction)) | |
+ # nodes_utils = [(node, node.utility(faction)) for node in | |
+ # neighbour_nodes] #easy debug | |
+ best_node = max(neighbour_nodes, key=lambda x: x.utility(faction)) | |
return best_node.choice | |
- | |
- | |
- | |
- | |
- | |
- | |
- | |
- | |
- | |
diff --git a/mechanics/AI/RandomAI.py b/mechanics/AI/RandomAI.py | |
index da8eaf1..276238e 100644 | |
--- a/mechanics/AI/RandomAI.py | |
+++ b/mechanics/AI/RandomAI.py | |
@@ -2,12 +2,11 @@ import random | |
class RandomAI: | |
- def __init__(self, game, chance_pass = 0.): | |
+ def __init__(self, game, chance_pass=0.): | |
self.game = game | |
self.battlefield = self.game.bf | |
self.chance_pass = chance_pass | |
- | |
def decide_step(self, active_unit): | |
if self.chance_pass > random.random(): | |
@@ -25,15 +24,13 @@ class RandomAI: | |
targets[a] = tgts | |
actives_with_valid_targets = set(targets.keys()) | |
- actives_without_targeting = {a for a in actives if a.targeting_cls is None} | |
+ actives_without_targeting = { | |
+ a for a in actives if a.targeting_cls is None} | |
- active = random.choice( list(actives_with_valid_targets | actives_without_targeting) ) | |
+ active = random.choice( | |
+ list(actives_with_valid_targets | actives_without_targeting)) | |
if active in actives_without_targeting: | |
return active, None | |
else: | |
target = random.choice(targets[active]) | |
return active, target | |
- | |
- | |
- | |
- | |
diff --git a/mechanics/AI/SearchNode.py b/mechanics/AI/SearchNode.py | |
index d4d203d..b63704e 100644 | |
--- a/mechanics/AI/SearchNode.py | |
+++ b/mechanics/AI/SearchNode.py | |
@@ -21,4 +21,3 @@ class SearchNode: | |
def __repr__(self): | |
return f"{len(self.game.units) if self.game else 'Lazy'} via {self.choice[0]} targeted on {self.choice[1]}" | |
- | |
diff --git a/mechanics/AI/SimGame.py b/mechanics/AI/SimGame.py | |
index 04478d6..a0ad8f8 100644 | |
--- a/mechanics/AI/SimGame.py | |
+++ b/mechanics/AI/SimGame.py | |
@@ -12,12 +12,12 @@ if TYPE_CHECKING: | |
from mechanics.actives import Active | |
from mechanics.factions import Faction | |
+ | |
class SimGame: | |
gamelog = None | |
units: Set[Unit] = None | |
bf: Battlefield = None | |
- | |
def simulation(self): | |
sim = copy.deepcopy(self) | |
sim.is_sim = True | |
@@ -25,7 +25,6 @@ class SimGame: | |
return sim | |
- | |
def get_all_neighbouring_states(self, _unit: Unit): | |
unit = self.find_unit(_unit) | |
@@ -35,7 +34,8 @@ class SimGame: | |
nodes = [self.get_neighbour(c) for c in choices] | |
return nodes | |
- def get_neighbour(self, c:Tuple[Active, Union[Cell, BattlefieldObject, None]]): | |
+ def get_neighbour( | |
+ self, c: Tuple[Active, Union[Cell, BattlefieldObject, None]]): | |
active, target = c | |
if active.simulate_callback: | |
@@ -43,44 +43,61 @@ class SimGame: | |
else: | |
sim = self.step_into_sim(active, target) | |
- return SearchNode(SearchNode(None,None,self), c, sim) | |
+ return SearchNode(SearchNode(None, None, self), c, sim) | |
- def step_into_sim(self, active: Active, target: Union[Cell, BattlefieldObject, None]): | |
+ def step_into_sim(self, | |
+ active: Active, | |
+ target: Union[Cell, | |
+ BattlefieldObject, | |
+ None]): | |
sim = self.simulation() | |
sim_active = sim.find_active(active) | |
- sim_target = sim.find_unit(target) if isinstance(target, BattlefieldObject) else target | |
+ sim_target = sim.find_unit(target) if isinstance( | |
+ target, BattlefieldObject) else target | |
sim_active.activate(sim_target) | |
return sim | |
- | |
- def fake_measure(self, choice: Tuple[Active, Union[Cell, BattlefieldObject, None]], | |
- fraction: Faction, use_position=True): | |
+ def fake_measure(self, | |
+ choice: Tuple[Active, | |
+ Union[Cell, | |
+ BattlefieldObject, | |
+ None]], | |
+ fraction: Faction, | |
+ use_position=True): | |
active, target = choice | |
with active.simulate(target): | |
return self.utility(fraction, use_position=use_position) | |
- def delta(self, choice: Tuple[Active, Union[Cell, BattlefieldObject, None]], fraction = None): | |
+ def delta(self, | |
+ choice: Tuple[Active, | |
+ Union[Cell, | |
+ BattlefieldObject, | |
+ None]], | |
+ fraction=None): | |
_fraction = fraction or choice[0].owner.faction | |
- _delta = self.get_neighbour(choice).utility(_fraction) - self.utility(_fraction) | |
+ _delta = self.get_neighbour(choice).utility( | |
+ _fraction) - self.utility(_fraction) | |
return _delta | |
- | |
# The marvel of convoluted math, | |
- # we evaluate how good the game is for a given fraction with a single number! | |
+ # we evaluate how good the game is for a given fraction with a single | |
+ # number! | |
+ | |
def utility(self, faction, use_position=True): | |
total = 0 | |
own_units = [unit for unit in self.units if unit.faction is faction] | |
- opponent_units = [unit for unit in self.units if unit.faction is not faction] | |
+ opponent_units = [ | |
+ unit for unit in self.units if unit.faction is not faction] | |
total += sum([self.unit_utility(unit) for unit in own_units]) | |
total -= sum([self.unit_utility(unit) for unit in opponent_units]) | |
if use_position: | |
- position_util = self.position_utility(own_units, opponent_units) / \ | |
- (1 + 1e13 * len(self.units)) | |
+ position_util = self.position_utility( | |
+ own_units, opponent_units) / (1 + 1e13 * len(self.units)) | |
total += position_util | |
return total | |
@@ -90,25 +107,26 @@ class SimGame: | |
total = 0 | |
for own_unit in own: | |
for other in opponent: | |
- importance = (self.unit_utility(own_unit) * self.unit_utility(other)) ** (1/2) | |
+ importance = (self.unit_utility(own_unit) * | |
+ self.unit_utility(other)) ** (1 / 2) | |
dist = self.bf.distance(own_unit, other) | |
# the closer the better | |
- distance_util = 1e5 * (6 - dist **(1/2)) * importance | |
+ distance_util = 1e5 * (6 - dist ** (1 / 2)) * importance | |
assert distance_util >= 0 | |
total += distance_util | |
# we want to face towards opponents | |
if dist > 0: | |
- own_facing_util = 1e9 * (1/dist) * \ | |
- (6 - self.bf.angle_to(own_unit, other)[0] / 45) * importance | |
+ own_facing_util = 1e9 * (1 / dist) * \ | |
+ (6 - self.bf.angle_to(own_unit, other)[0] / 45) * importance | |
assert own_facing_util >= 0 | |
total += own_facing_util | |
- #its best for opponents to face away from us | |
- opponent_facing_away_util = (1/dist) * self.bf.angle_to(other, own_unit)[0] \ | |
- / 45 * importance | |
+ # its best for opponents to face away from us | |
+ opponent_facing_away_util = ( | |
+ 1 / dist) * self.bf.angle_to(other, own_unit)[0] / 45 * importance | |
assert opponent_facing_away_util >= 0 | |
total += opponent_facing_away_util | |
@@ -126,7 +144,8 @@ class SimGame: | |
hp_factor = 1 + unit.health | |
other_factors = 1 | |
# + (unit.mana + unit.stamina + unit.readiness*3) * len(unit.actives) / 1000 | |
- magnitude = sum([unit.str, unit.end, unit.agi, unit.prc, unit.int, unit.cha]) | |
+ magnitude = sum([unit.str, unit.end, unit.agi, | |
+ unit.prc, unit.int, unit.cha]) | |
utility = magnitude * hp_factor * 1 * other_factors | |
@@ -135,8 +154,6 @@ class SimGame: | |
return utility | |
- | |
- | |
# extracting all possible transitions | |
def get_all_choices(self, unit: Unit): | |
@@ -149,11 +166,10 @@ class SimGame: | |
if tgts: | |
choices += [(a, tgt) for tgt in tgts] | |
elif tgts is None: | |
- choices.append( (a, None) ) | |
+ choices.append((a, None)) | |
return choices | |
- | |
def get_possible_targets(self, active): | |
targeting_cls = active.targeting_cls | |
@@ -192,21 +208,23 @@ class SimGame: | |
if active_uid == other.uid: | |
return other | |
- | |
@staticmethod | |
- def cost_heuristic(unit: Unit, factors = None): | |
+ def cost_heuristic(unit: Unit, factors=None): | |
_factors = factors or {} | |
def _(active): | |
cost = active.cost | |
- hp_relative_cost = cost.health / unit.health * _factors.get("hp", 1) | |
- mana_relative_cost = cost.mana / unit.mana * _factors.get("mana", 0.5) | |
- stamina_relative_cost = cost.stamina / unit.stamina * _factors.get("stamina", 0.5) | |
+ hp_relative_cost = cost.health / \ | |
+ unit.health * _factors.get("hp", 1) | |
+ mana_relative_cost = cost.mana / \ | |
+ unit.mana * _factors.get("mana", 0.5) | |
+ stamina_relative_cost = cost.stamina / \ | |
+ unit.stamina * _factors.get("stamina", 0.5) | |
readiness_cost = cost.readiness * _factors.get("rdy", 0.1) | |
- return sum( (hp_relative_cost, | |
- mana_relative_cost, | |
- stamina_relative_cost, | |
- readiness_cost) ) | |
+ return sum((hp_relative_cost, | |
+ mana_relative_cost, | |
+ stamina_relative_cost, | |
+ readiness_cost)) | |
- return _ | |
\ No newline at end of file | |
+ return _ | |
diff --git a/mechanics/AI/SimUtils.py b/mechanics/AI/SimUtils.py | |
index 53aed53..a753601 100644 | |
--- a/mechanics/AI/SimUtils.py | |
+++ b/mechanics/AI/SimUtils.py | |
@@ -1,5 +1,6 @@ | |
from contextlib import contextmanager | |
+ | |
@contextmanager | |
def virtual(unit): | |
health_before = unit.health | |
@@ -14,6 +15,7 @@ def virtual(unit): | |
unit.stamina = stamina_before | |
unit.readiness = readiness_before | |
+ | |
@contextmanager | |
def simulate_death(game, unit): | |
position = game.get_location(unit) | |
@@ -22,4 +24,3 @@ def simulate_death(game, unit): | |
game.unit_died(unit) | |
yield | |
game.add_unit(unit, position, facing, fraction) | |
- | |
diff --git a/mechanics/AI/__init__.py b/mechanics/AI/__init__.py | |
index 5523cf2..a1d3bdd 100644 | |
--- a/mechanics/AI/__init__.py | |
+++ b/mechanics/AI/__init__.py | |
@@ -4,5 +4,3 @@ from mechanics.AI.RandomAI import RandomAI | |
from mechanics.AI.BruteAI import BruteAI | |
from mechanics.AI.BroadAI import BroadAI | |
from mechanics.AI.AstarAI import AstarAI | |
- | |
- | |
diff --git a/mechanics/AI/pathfinding/astar_pathfinder.py b/mechanics/AI/pathfinding/astar_pathfinder.py | |
index 788760a..a30b11a 100644 | |
--- a/mechanics/AI/pathfinding/astar_pathfinder.py | |
+++ b/mechanics/AI/pathfinding/astar_pathfinder.py | |
@@ -1,4 +1,5 @@ | |
from __future__ import annotations | |
+from astar import AStar | |
from collections import namedtuple | |
from battlefield import Battlefield | |
from mechanics.actives import ActiveTags | |
@@ -10,7 +11,6 @@ if TYPE_CHECKING: | |
Node = namedtuple("PathNode", "pos facing") | |
-from astar import AStar | |
class StarSearch(AStar): | |
@@ -84,9 +84,3 @@ class StarSearch(AStar): | |
transitions.append((0j, 1j, unit.turn_ccw_active.cost)) | |
return transitions | |
- | |
- | |
- | |
- | |
- | |
- | |
diff --git a/mechanics/actives/__init__.py b/mechanics/actives/__init__.py | |
index 4131de8..a82f745 100644 | |
--- a/mechanics/actives/__init__.py | |
+++ b/mechanics/actives/__init__.py | |
@@ -1,4 +1,3 @@ | |
from mechanics.actives.active.ActionTags import ActiveTags | |
from mechanics.actives.active.Active import Active | |
from mechanics.actives.cost.Cost import Cost | |
- | |
diff --git a/mechanics/actives/active/ActionTags.py b/mechanics/actives/active/ActionTags.py | |
index 745a089..ba24580 100644 | |
--- a/mechanics/actives/active/ActionTags.py | |
+++ b/mechanics/actives/active/ActionTags.py | |
@@ -1,5 +1,6 @@ | |
from enum import Enum, auto | |
+ | |
class ActiveTags(Enum): | |
MOVEMENT = auto() | |
TURNING = auto() | |
@@ -13,4 +14,3 @@ class ActiveTags(Enum): | |
DEFEND = auto() | |
CHARGED_ITEM = auto() | |
- | |
diff --git a/mechanics/actives/active/Active.py b/mechanics/actives/active/Active.py | |
index 5094aec..8e3af03 100644 | |
--- a/mechanics/actives/active/Active.py | |
+++ b/mechanics/actives/active/Active.py | |
@@ -1,4 +1,6 @@ | |
from __future__ import annotations | |
+from mechanics.conditions.ActiveCondition import ActiveCondition | |
+from mechanics.conditions.ActiveCheck import ActiveCheck | |
from mechanics.events import ActiveEvent | |
from mechanics.actives import ActiveTags | |
from battlefield import Cell | |
@@ -12,16 +14,23 @@ if TYPE_CHECKING: | |
from mechanics.actives import Cost | |
from DreamGame import DreamGame | |
-from mechanics.conditions.ActiveCheck import ActiveCheck | |
-from mechanics.conditions.ActiveCondition import ActiveCondition | |
- | |
class Active: | |
last_uid = 0 | |
- def __init__(self, targeting_cls: ClassVar = None, conditions: List[Callable] = None, cost: Union[Cost, Callable] = None,*, | |
- game: DreamGame=None, callbacks: List[Callable], tags: List[ActiveTags]=None, | |
- name: str = "nameless active", cooldown = 0, simulate = None, icon: str = "fire.jpg"): | |
+ def __init__(self, | |
+ targeting_cls: ClassVar = None, | |
+ conditions: List[Callable] = None, | |
+ cost: Union[Cost, | |
+ Callable] = None, | |
+ *, | |
+ game: DreamGame = None, | |
+ callbacks: List[Callable], | |
+ tags: List[ActiveTags] = None, | |
+ name: str = "nameless active", | |
+ cooldown=0, | |
+ simulate=None, | |
+ icon: str = "fire.jpg"): | |
self.name = name | |
self.game = game | |
self.targeting_cls = targeting_cls | |
@@ -40,7 +49,6 @@ class Active: | |
Active.last_uid += 1 | |
self.uid = Active.last_uid | |
- | |
def check_target(self, target): | |
failing_conditions = self.checker.not_satisfied_conds(self, target) | |
# for c in failing_conditions: | |
@@ -69,7 +77,6 @@ class Active: | |
return False | |
return self.owner.can_pay(self.cost) | |
- | |
def why_not_affordable(self) -> str: | |
if self.spell: | |
if not self.spell.complexity_check(self.owner): | |
@@ -90,7 +97,8 @@ class Active: | |
@staticmethod | |
def from_spell(spell, game=None): | |
- new_active = Active(spell.targeting_cls, [spell.targeting_cond] if spell.targeting_cond else None, | |
+ new_active = Active(spell.targeting_cls, | |
+ [spell.targeting_cond] if spell.targeting_cond else None, | |
spell.cost, | |
cooldown=spell.cooldown, | |
game=game, | |
@@ -107,7 +115,7 @@ class Active: | |
@property | |
def tooltip_info(self): | |
- return {"name":f"{self.name}"} | |
+ return {"name": f"{self.name}"} | |
# the hack is here because sometimes we want to calculate cost dynamically. setting property doesn't work - | |
# deepcopy throws TypeError on properties. But it does not on lambdas. Therefore _cost is either a Cost | |
@@ -122,4 +130,5 @@ class Active: | |
return self._cost | |
def __repr__(self): | |
- return f"{self.name} active with {self.cost} cost ({self.tags[0] if len(self.tags) == 1 else self.tags}).".capitalize() | |
+ return f"{self.name} active with {self.cost} cost ({self.tags[0] if len(self.tags) == 1 else self.tags}).".capitalize( | |
+ ) | |
diff --git a/mechanics/actives/cost/Cost.py b/mechanics/actives/cost/Cost.py | |
index fa6b5a1..45b9336 100644 | |
--- a/mechanics/actives/cost/Cost.py | |
+++ b/mechanics/actives/cost/Cost.py | |
@@ -6,13 +6,12 @@ if TYPE_CHECKING: | |
class Cost: | |
- def __init__(self, stamina=0., mana=0., health=0., readiness = 1.): | |
+ def __init__(self, stamina=0., mana=0., health=0., readiness=1.): | |
self.stamina = stamina | |
self.mana = mana | |
self.health = health | |
self.readiness = readiness | |
- | |
def complain(self, unit: Unit): | |
HP = "Health" | |
MANA = "MANA" | |
@@ -26,10 +25,11 @@ class Cost: | |
elif unit.stamina < self.stamina: | |
return fmt.format(STAMINA) | |
else: | |
- raise PydolonsError(f"Cost {self} is no problem for {unit}. Why are we seeing this message? :D") | |
+ raise PydolonsError( | |
+ f"Cost {self} is no problem for {unit}. Why are we seeing this message? :D") | |
def __mul__(self, other): | |
- other = float(other) # assert other is a number | |
+ other = float(other) # assert other is a number | |
return Cost(self.stamina * other, | |
self.mana * other, | |
@@ -57,7 +57,14 @@ class Cost: | |
self.readiness == other.readiness)) | |
def __hash__(self): | |
- return hash(self.stamina * 1e12 + self.mana * 1e8 + self.health * 1e4 +self.readiness) | |
+ return hash( | |
+ self.stamina * | |
+ 1e12 + | |
+ self.mana * | |
+ 1e8 + | |
+ self.health * | |
+ 1e4 + | |
+ self.readiness) | |
def __repr__(self): | |
return f"{self.readiness} rdy, {self.stamina} sta, {self.mana} mp, {self.health} hp" | |
diff --git a/mechanics/buffs/Ability.py b/mechanics/buffs/Ability.py | |
index 769101b..0697d7e 100644 | |
--- a/mechanics/buffs/Ability.py | |
+++ b/mechanics/buffs/Ability.py | |
@@ -9,9 +9,14 @@ if TYPE_CHECKING: | |
class Ability: | |
- def __init__(self, bonus: Bonus = None, trigger_factories: List[Callable] = None, name = "Nameless ability"): | |
+ def __init__( | |
+ self, | |
+ bonus: Bonus = None, | |
+ trigger_factories: List[Callable] = None, | |
+ name="Nameless ability"): | |
self.bonus = bonus | |
- self.trigger_factories = trigger_factories # callable( Ability ) -> Trigger | |
+ # callable( Ability ) -> Trigger | |
+ self.trigger_factories = trigger_factories | |
self.to_deactivate: List[Trigger] = [] | |
self.bound_to: Unit = None | |
self.name = name | |
@@ -34,9 +39,5 @@ class Ability: | |
for tf in self.trigger_factories: | |
descr += "\n" + repr(tf) | |
- | |
- | |
def __repr__(self): | |
return f"{self.name} belonging to {self.bound_to}" | |
- | |
- | |
diff --git a/mechanics/buffs/Buff.py b/mechanics/buffs/Buff.py | |
index 10ab30c..6af907e 100644 | |
--- a/mechanics/buffs/Buff.py | |
+++ b/mechanics/buffs/Buff.py | |
@@ -3,12 +3,16 @@ from game_objects.attributes import DynamicParameter | |
from mechanics.events import BuffExpiredEvent | |
- | |
class Buff(Ability): | |
duration = DynamicParameter("max_duration", [BuffExpiredEvent]) | |
- | |
- def __init__(self, duration: float, bonus = None, triggers_factories = None, source = None, name="nameless"): | |
+ def __init__( | |
+ self, | |
+ duration: float, | |
+ bonus=None, | |
+ triggers_factories=None, | |
+ source=None, | |
+ name="nameless"): | |
super().__init__(bonus, triggers_factories, name) | |
self.max_duration = duration | |
self.source = source | |
@@ -18,5 +22,3 @@ class Buff(Ability): | |
def __repr__(self): | |
return f"Buff {self.name}: {self.duration}/{self.max_duration} s left; on {self.bound_to}" | |
- | |
- | |
diff --git a/mechanics/chances/ChanceCalculator.py b/mechanics/chances/ChanceCalculator.py | |
index 15f5032..9b3b25e 100644 | |
--- a/mechanics/chances/ChanceCalculator.py | |
+++ b/mechanics/chances/ChanceCalculator.py | |
@@ -1,5 +1,6 @@ | |
from functools import lru_cache | |
+ | |
class ChanceCalculator: | |
advantage_to_double = 25 | |
@@ -14,32 +15,43 @@ class ChanceCalculator: | |
return base_prob | |
if evasion > precision: | |
- adv = 1 + (evasion - precision) / ChanceCalculator.advantage_to_double | |
+ adv = 1 + (evasion - precision) / \ | |
+ ChanceCalculator.advantage_to_double | |
else: | |
- adv = 1 / (1 + (precision - evasion) / ChanceCalculator.advantage_to_double) | |
- | |
+ adv = 1 / (1 + (precision - evasion) / | |
+ ChanceCalculator.advantage_to_double) | |
if base_prob >= 0.5: | |
- new_chance = base_prob ** adv # Note: as base_prob is below one, powers below one increase the | |
+ # Note: as base_prob is below one, powers below one increase the | |
+ new_chance = base_prob ** adv | |
else: | |
chance_to_avoid = 1 - base_prob | |
- adv = 1/adv | |
+ adv = 1 / adv | |
new_chance_to_avoid = chance_to_avoid ** adv | |
new_chance = 1 - new_chance_to_avoid | |
- | |
assert 0 <= new_chance <= 1 | |
return new_chance | |
- | |
if __name__ == "__main__": | |
for base_chance in [0.01, 0.1, 0.25, 0.5, 0.75, 0.9, 0.99]: | |
- for attack, defense in [(0,25), (25,0), (75,0), (0, 75) , (225,0), (0, 225)]: | |
+ for attack, defense in [ | |
+ (0, 25), (25, 0), (75, 0), (0, 75), (225, 0), (0, 225)]: | |
if defense > attack: | |
- adv = 1 + (defense - attack) / ChanceCalculator.advantage_to_double | |
+ adv = 1 + (defense - attack) / \ | |
+ ChanceCalculator.advantage_to_double | |
else: | |
- adv = 1 / (1 + (attack - defense) / ChanceCalculator.advantage_to_double) | |
- print(base_chance, attack, defense, adv, ChanceCalculator.chance(base_chance, attack, defense)) | |
\ No newline at end of file | |
+ adv = 1 / (1 + (attack - defense) / | |
+ ChanceCalculator.advantage_to_double) | |
+ print( | |
+ base_chance, | |
+ attack, | |
+ defense, | |
+ adv, | |
+ ChanceCalculator.chance( | |
+ base_chance, | |
+ attack, | |
+ defense)) | |
diff --git a/mechanics/chances/CritHitGrazeMiss.py b/mechanics/chances/CritHitGrazeMiss.py | |
index 78d4ef7..fd62a0b 100644 | |
--- a/mechanics/chances/CritHitGrazeMiss.py | |
+++ b/mechanics/chances/CritHitGrazeMiss.py | |
@@ -3,6 +3,7 @@ from my_utils.named_enums import NameEnum, auto | |
from mechanics.chances.ChanceCalculator import ChanceCalculator | |
from dataclasses import dataclass | |
+ | |
class ImpactFactor(NameEnum): | |
CRIT = auto() | |
HIT = auto() | |
@@ -12,17 +13,17 @@ class ImpactFactor(NameEnum): | |
@dataclass(frozen=True) | |
class ImpactChances: | |
- crit:float | |
- hit:float | |
- graze:float | |
+ crit: float | |
+ hit: float | |
+ graze: float | |
@property | |
def sequential_hit_chance(self): | |
- return (1-self.crit)*self.hit | |
+ return (1 - self.crit) * self.hit | |
@property | |
def sequential_graze_chance(self): | |
- return (1-self.crit)*(1-self.hit)*self.graze | |
+ return (1 - self.crit) * (1 - self.hit) * self.graze | |
def actual(self, precision, evasion): | |
return self._calc_chances(self, precision, evasion) | |
@@ -39,9 +40,13 @@ class ImpactChances: | |
return ImpactFactor.MISS | |
@staticmethod | |
- def _calc_chances(initial_chances: ImpactChances, precision, evasion) -> ImpactChances: | |
- chance_crit, chance_hit, chance_graze = [ChanceCalculator.chance(c, precision, evasion) for c in | |
- initial_chances] | |
+ def _calc_chances( | |
+ initial_chances: ImpactChances, | |
+ precision, | |
+ evasion) -> ImpactChances: | |
+ chance_crit, chance_hit, chance_graze = [ | |
+ ChanceCalculator.chance( | |
+ c, precision, evasion) for c in initial_chances] | |
return ImpactChances(chance_crit, chance_hit, chance_graze) | |
def __iter__(self): | |
@@ -51,13 +56,8 @@ class ImpactChances: | |
return f"crit/hit/graze chances: {100*self.crit:.2f} / {100*self.sequential_hit_chance:.2f} / {100*self.sequential_graze_chance:.2f}%" | |
- | |
- | |
- | |
- | |
- | |
if __name__ == "__main__": | |
- ic = ImpactChances(0.05, 0.5,0.5) | |
+ ic = ImpactChances(0.05, 0.5, 0.5) | |
print(ic) | |
ic = ImpactChances(0.05, 0.75, 0.5) | |
@@ -66,4 +66,4 @@ if __name__ == "__main__": | |
ic = ImpactChances(0.01, 0.5, 0.6) | |
print(ic) | |
ic2 = ic.calc_chances(ic, 0, 50) | |
- print(ic2) | |
\ No newline at end of file | |
+ print(ic2) | |
diff --git a/mechanics/chances/Rolls.py b/mechanics/chances/Rolls.py | |
index c54ef21..c2404de 100644 | |
--- a/mechanics/chances/Rolls.py | |
+++ b/mechanics/chances/Rolls.py | |
@@ -1,7 +1,6 @@ | |
from mechanics.chances import ChanceCalculator | |
+ | |
def roll(base_a, bet_a, bet_b, random): | |
chance_a = ChanceCalculator.chance(base_a, bet_a, bet_b) | |
return random.random() < chance_a | |
- | |
- | |
diff --git a/mechanics/combat/Attack.py b/mechanics/combat/Attack.py | |
index de1c876..6bcadd0 100644 | |
--- a/mechanics/combat/Attack.py | |
+++ b/mechanics/combat/Attack.py | |
@@ -13,14 +13,10 @@ class Attack: | |
weapon = source.get_melee_weapon() | |
return AttackEvent(source, target, weapon) | |
- | |
@staticmethod | |
- def expected_dmg(source: Unit, target:BattlefieldObject): | |
+ def expected_dmg(source: Unit, target: BattlefieldObject): | |
weapon = source.get_melee_weapon() | |
fake_event = AttackEvent(source, target, weapon, fire=False) | |
chances = fake_event.calculate_chances() | |
expected_dmg = Damage.expected(chances, weapon.damage, target) | |
return expected_dmg | |
- | |
- | |
- | |
diff --git a/mechanics/combat/RangedAttack.py b/mechanics/combat/RangedAttack.py | |
index 0ab29b8..ef50d45 100644 | |
--- a/mechanics/combat/RangedAttack.py | |
+++ b/mechanics/combat/RangedAttack.py | |
@@ -5,8 +5,6 @@ if TYPE_CHECKING: | |
from game_objects.battlefield_objects import BattlefieldObject, Unit | |
- | |
- | |
class RangedAttack: | |
@staticmethod | |
@@ -15,7 +13,6 @@ class RangedAttack: | |
assert weapon is not None | |
return RangedAttackEvent(source, target, weapon) | |
- | |
# @staticmethod | |
# def expected_dmg(source: Unit, target:BattlefieldObject): | |
# weapon = source.get_melee_weapon() | |
@@ -23,6 +20,3 @@ class RangedAttack: | |
# chances = fake_event.calculate_chances() | |
# expected_dmg = Damage.expected(chances, weapon.damage, target) | |
# return expected_dmg | |
- | |
- | |
- | |
diff --git a/mechanics/conditions/ActiveCheck.py b/mechanics/conditions/ActiveCheck.py | |
index f2bc388..ca8a75c 100644 | |
--- a/mechanics/conditions/ActiveCheck.py | |
+++ b/mechanics/conditions/ActiveCheck.py | |
@@ -16,7 +16,9 @@ class ActiveCheck: | |
self._conditions = [] | |
def not_satisfied_conds(self, active, target) -> List[ActiveCondition]: | |
- result = [c for c in self._conditions if not c.evaluate(active, target)] | |
+ result = [ | |
+ c for c in self._conditions if not c.evaluate( | |
+ active, target)] | |
return result | |
def append(self, cond: ActiveCondition): | |
diff --git a/mechanics/conditions/ActiveCondition.py b/mechanics/conditions/ActiveCondition.py | |
index 146a903..b754476 100644 | |
--- a/mechanics/conditions/ActiveCondition.py | |
+++ b/mechanics/conditions/ActiveCondition.py | |
@@ -1,5 +1,6 @@ | |
from typing import Callable | |
+ | |
class ActiveCondition: | |
def __init__(self, name: str, expr: Callable, message_fmt: str): | |
self.expr = expr | |
@@ -9,9 +10,9 @@ class ActiveCondition: | |
def evaluate(self, active, target): | |
return self.expr(active, target) | |
- | |
def message(self, active, target): | |
- return self.message_fmt.format_map({"active":active, "target":target, "cond_name":self.name}) | |
+ return self.message_fmt.format_map( | |
+ {"active": active, "target": target, "cond_name": self.name}) | |
def __repr__(self): | |
- return f"{self.name} active condition" | |
\ No newline at end of file | |
+ return f"{self.name} active condition" | |
diff --git a/mechanics/damage/Armor.py b/mechanics/damage/Armor.py | |
index b1b2701..39acdd4 100644 | |
--- a/mechanics/damage/Armor.py | |
+++ b/mechanics/damage/Armor.py | |
@@ -1,30 +1,28 @@ | |
from mechanics.damage.DamageTypes import DamageTypes, DamageTypeGroups | |
+ | |
class Armor: | |
MIN_ARMOR = 0 | |
- def __init__(self, base_value = 0, armor_dict=None): | |
+ def __init__(self, base_value=0, armor_dict=None): | |
self.armor_values = {} | |
for dtype in DamageTypes: | |
self[dtype] = base_value | |
if armor_dict: | |
self.armor_values.update(armor_dict) | |
- | |
def value(self): | |
self.finalize() | |
return self | |
- | |
def finalize(self): | |
- for k,v in self.armor_values.items(): | |
+ for k, v in self.armor_values.items(): | |
if v < Armor.MIN_ARMOR: | |
self[k] = Armor.MIN_ARMOR | |
- | |
def __setitem__(self, key, value): | |
assert isinstance(key, DamageTypes) | |
- self.armor_values.__setitem__(key, int(value) ) | |
+ self.armor_values.__setitem__(key, int(value)) | |
def __getitem__(self, item): | |
return self.armor_values[item] | |
@@ -36,7 +34,7 @@ class Armor: | |
return Armor(armor_dict=result) | |
def __mul__(self, other): | |
- assert other < 1e20 # is a number | |
+ assert other < 1e20 # is a number | |
result = {} | |
for damage_type in self.armor_values.keys(): | |
@@ -57,12 +55,11 @@ class Armor: | |
def physical(self): | |
types = DamageTypeGroups.physical | |
- return sum([self[dt] for dt in types])/len(types) | |
+ return sum([self[dt] for dt in types]) / len(types) | |
def elemental(self): | |
types = DamageTypeGroups.elemental | |
- return sum([self[dt] for dt in types])/len(types) | |
+ return sum([self[dt] for dt in types]) / len(types) | |
def __repr__(self): | |
return f"{self.display_value() :.0f}" | |
- | |
diff --git a/mechanics/damage/Damage.py b/mechanics/damage/Damage.py | |
index 7d8688d..b09d01f 100644 | |
--- a/mechanics/damage/Damage.py | |
+++ b/mechanics/damage/Damage.py | |
@@ -1,5 +1,6 @@ | |
from mechanics.chances.CritHitGrazeMiss import ImpactFactor, ImpactChances | |
+ | |
class Damage: | |
protection_coef = { | |
ImpactFactor.CRIT: 0.7, | |
@@ -19,7 +20,7 @@ class Damage: | |
self.type = type | |
def __mul__(self, other): | |
- return Damage(self.amount*other, self.type) | |
+ return Damage(self.amount * other, self.type) | |
def __imul__(self, other): | |
return Damage(self.amount * other, self.type) | |
@@ -29,48 +30,54 @@ class Damage: | |
result = 0 | |
- result += Damage.calculate_damage(damage, target, ImpactFactor.CRIT)[0] * chances.crit | |
- result += Damage.calculate_damage(damage, target, ImpactFactor.HIT)[0] * chances.sequential_hit_chance | |
- result += Damage.calculate_damage(damage, target, ImpactFactor.GRAZE)[0] * chances.sequential_graze_chance | |
+ result += Damage.calculate_damage(damage, | |
+ target, | |
+ ImpactFactor.CRIT)[0] * chances.crit | |
+ result += Damage.calculate_damage(damage, target, ImpactFactor.HIT)[ | |
+ 0] * chances.sequential_hit_chance | |
+ result += Damage.calculate_damage(damage, target, ImpactFactor.GRAZE)[ | |
+ 0] * chances.sequential_graze_chance | |
return result | |
- | |
@staticmethod | |
def calculate_damage(damage, target, impact_factor=ImpactFactor.HIT): | |
dmg_type = damage.type | |
resist = target.resists[dmg_type] | |
armor = target.armor[dmg_type] * \ | |
- Damage.protection_coef[impact_factor] | |
+ Damage.protection_coef[impact_factor] | |
damage_final = int(max((damage.amount - armor) * (1 - resist), 0) * | |
Damage.effect_coef[impact_factor]) | |
# print(damage_final) | |
- return damage_final, \ | |
- Damage.calculate_armor_dur_damage(damage_final, armor, target.max_health), \ | |
- Damage.calculate_weapon_dur_damage(damage.amount, damage_final, impact_factor) | |
- | |
- | |
+ return damage_final, Damage.calculate_armor_dur_damage( | |
+ damage_final, armor, target.max_health), Damage.calculate_weapon_dur_damage( | |
+ damage.amount, damage_final, impact_factor) | |
@staticmethod | |
def calculate_armor_dur_damage(final_damage, armor_amount, target_hp): | |
if final_damage == 0: | |
return 0 | |
- return int(5 * final_damage / (armor_amount + target_hp/final_damage)) | |
+ return int(5 * final_damage / | |
+ (armor_amount + target_hp / final_damage)) | |
@staticmethod | |
- def calculate_weapon_dur_damage(damage_initial, damage_final, impact_factor): | |
+ def calculate_weapon_dur_damage( | |
+ damage_initial, | |
+ damage_final, | |
+ impact_factor): | |
assert damage_initial > 0 | |
assert damage_final >= 0 | |
- reduction = damage_initial * Damage.effect_coef[impact_factor] - damage_final | |
- threshold = 0.33 * damage_initial # if reduction is greater than the threshold, the weapon is damaged. | |
+ reduction = damage_initial * \ | |
+ Damage.effect_coef[impact_factor] - damage_final | |
+ # if reduction is greater than the threshold, the weapon is damaged. | |
+ threshold = 0.33 * damage_initial | |
reduction_over_threshold = reduction - threshold | |
if reduction_over_threshold > 0: | |
return int(5 * (reduction_over_threshold / damage_initial)) | |
else: | |
return 0 | |
- | |
def __repr__(self): | |
return f"{self.amount:.1f} of {self.type} damage" | |
diff --git a/mechanics/damage/DamageTypes.py b/mechanics/damage/DamageTypes.py | |
index 8bcc69c..f4d7171 100644 | |
--- a/mechanics/damage/DamageTypes.py | |
+++ b/mechanics/damage/DamageTypes.py | |
@@ -1,5 +1,6 @@ | |
from my_utils.named_enums import NameEnum, auto | |
+ | |
class DamageTypes(NameEnum): | |
SLASH = auto() | |
CRUSH = auto() | |
@@ -10,13 +11,20 @@ class DamageTypes(NameEnum): | |
LIGHTNING = auto() | |
ACID = auto() | |
- # design: succeptable entities have strong vulnerability. damage of below types comes in small amounts. | |
+ # design: succeptable entities have strong vulnerability. damage of below | |
+ # types comes in small amounts. | |
SONIC = auto() | |
+ | |
class DamageTypeGroups: | |
physical = {DamageTypes.SLASH, DamageTypes.CRUSH, DamageTypes.PIERCE} | |
- elemental = {DamageTypes.FIRE, DamageTypes.FROST, DamageTypes.LIGHTNING, DamageTypes.ACID} | |
+ elemental = { | |
+ DamageTypes.FIRE, | |
+ DamageTypes.FROST, | |
+ DamageTypes.LIGHTNING, | |
+ DamageTypes.ACID} | |
exotic = {DamageTypes.SONIC} | |
+ | |
if __name__ == "__main__": | |
- print(list(DamageTypes)) | |
\ No newline at end of file | |
+ print(list(DamageTypes)) | |
diff --git a/mechanics/damage/Resistances.py b/mechanics/damage/Resistances.py | |
index 90075fe..88196c7 100644 | |
--- a/mechanics/damage/Resistances.py | |
+++ b/mechanics/damage/Resistances.py | |
@@ -1,6 +1,7 @@ | |
from mechanics.damage.DamageTypes import DamageTypes | |
from my_utils.utils import clamp | |
+ | |
class Resistances: | |
MAX_RESISTANCE = 0.95 | |
MAX_VULNERABILITY = -20 | |
@@ -21,18 +22,14 @@ class Resistances: | |
def finalize(self): | |
for dtype in DamageTypes: | |
self.resist_values[dtype] = clamp(self.resist_values[dtype], | |
- Resistances.MAX_VULNERABILITY, | |
- Resistances.MAX_RESISTANCE) | |
+ Resistances.MAX_VULNERABILITY, | |
+ Resistances.MAX_RESISTANCE) | |
def __getitem__(self, item): | |
return self.resist_values[item] | |
- | |
def __add__(self, other): | |
result = {} | |
for damage_type in self.resist_values.keys(): | |
result[damage_type] = self[damage_type] + other[damage_type] | |
return Resistances(resists_dict=result) | |
- | |
- | |
- | |
diff --git a/mechanics/events/ActiveEvent.py b/mechanics/events/ActiveEvent.py | |
index 8f95937..6245fad 100644 | |
--- a/mechanics/events/ActiveEvent.py | |
+++ b/mechanics/events/ActiveEvent.py | |
@@ -5,6 +5,7 @@ from typing import TYPE_CHECKING | |
if TYPE_CHECKING: | |
from mechanics.actives import Active | |
+ | |
class ActiveEvent(Event): | |
channel = EventsChannels.ActiveChannel | |
diff --git a/mechanics/events/NextUnitEvent.py b/mechanics/events/NextUnitEvent.py | |
index 30a68bf..0203f77 100644 | |
--- a/mechanics/events/NextUnitEvent.py | |
+++ b/mechanics/events/NextUnitEvent.py | |
@@ -5,6 +5,7 @@ from typing import TYPE_CHECKING | |
if TYPE_CHECKING: | |
from game_objects.battlefield_objects import Unit | |
+ | |
class NextUnitEvent(Event): | |
channel = EventsChannels.NextUnitChannel | |
diff --git a/mechanics/events/TimePassedEvent.py b/mechanics/events/TimePassedEvent.py | |
index 38099fd..55eb0a2 100644 | |
--- a/mechanics/events/TimePassedEvent.py | |
+++ b/mechanics/events/TimePassedEvent.py | |
@@ -5,6 +5,7 @@ from typing import TYPE_CHECKING | |
if TYPE_CHECKING: | |
from DreamGame import DreamGame | |
+ | |
class TimePassedEvent(Event): | |
channel = EventsChannels.TimePassedChannel | |
diff --git a/mechanics/events/TurnEvent.py b/mechanics/events/TurnEvent.py | |
index daabb6a..4d95e4e 100644 | |
--- a/mechanics/events/TurnEvent.py | |
+++ b/mechanics/events/TurnEvent.py | |
@@ -5,6 +5,7 @@ from typing import TYPE_CHECKING | |
if TYPE_CHECKING: | |
from game_objects.battlefield_objects import Unit | |
+ | |
class TurnEvent(Event): | |
channel = EventsChannels.TurnChannel | |
@@ -20,7 +21,6 @@ class TurnEvent(Event): | |
turn = -1j if self.ccw else 1j | |
self.unit.facing *= turn | |
- | |
def __repr__(self): | |
direction = "counter-clockwise" if self.ccw else "clockwise" | |
return f"{self.unit} turns {direction}." | |
diff --git a/mechanics/events/combat/AttackEvent.py b/mechanics/events/combat/AttackEvent.py | |
index 19110a1..d08b5b0 100644 | |
--- a/mechanics/events/combat/AttackEvent.py | |
+++ b/mechanics/events/combat/AttackEvent.py | |
@@ -11,41 +11,55 @@ if TYPE_CHECKING: | |
class AttackEvent(Event): | |
channel = EventsChannels.AttackChannel | |
- def __init__(self, source: Unit, target: BattlefieldObject, weapon : Weapon=None, fire: bool=True): | |
+ | |
+ def __init__( | |
+ self, | |
+ source: Unit, | |
+ target: BattlefieldObject, | |
+ weapon: Weapon = None, | |
+ fire: bool = True): | |
game = source.game | |
self.source = source | |
self.target = target | |
self.weapon = weapon or source.get_melee_weapon() | |
- self.is_backstab = not target.is_obstacle and not game.vision.x_sees_y(target, source) | |
+ self.is_backstab = not target.is_obstacle and not game.vision.x_sees_y( | |
+ target, source) | |
self.is_blind = not game.vision.x_sees_y(source, target) | |
precision, evasion = self.effective_precision_evasion() | |
- self.impact = self.weapon.chances.actual(precision, evasion).roll_impact(random=game.random) | |
+ self.impact = self.weapon.chances.actual( | |
+ precision, evasion).roll_impact( | |
+ random=game.random) | |
- super().__init__(game,fire, logging=True) | |
+ super().__init__(game, fire, logging=True) | |
def check_conditions(self) -> bool: | |
- return all( (self.source, self.source.alive, self.target, | |
- self.target.alive, self.weapon, | |
- self.weapon.durability is None or self.weapon.durability > 0) ) | |
+ return all( | |
+ (self.source, | |
+ self.source.alive, | |
+ self.target, | |
+ self.target.alive, | |
+ self.weapon, | |
+ self.weapon.durability is None or self.weapon.durability > 0)) | |
def resolve(self) -> None: | |
if self.impact is not ImpactFactor.MISS: | |
- dmg_event = DamageEvent( self.weapon.damage, self.target, source=self.source, impact_factor = self.impact) | |
+ dmg_event = DamageEvent( | |
+ self.weapon.damage, | |
+ self.target, | |
+ source=self.source, | |
+ impact_factor=self.impact) | |
if not dmg_event.interrupted and self.weapon and self.weapon.durability: | |
self.weapon.durability -= dmg_event.weapon_dur_dmg | |
else: | |
self.game.gamelog(f"{self.source} misses {self.target}") | |
- | |
- | |
def calculate_chances(self) -> ImpactChances: | |
p, e = self.effective_precision_evasion() | |
return self.source.unarmed_chances.actual(p, e) | |
- | |
def effective_precision_evasion(self)-> Tuple[float, float]: | |
effective_precision = self.source.melee_precision | |
if self.is_blind: | |
@@ -57,7 +71,6 @@ class AttackEvent(Event): | |
return effective_precision, effective_evasion | |
- | |
def __repr__(self): | |
msg = "" | |
msg += "Backstab! " if self.is_backstab else "" | |
diff --git a/mechanics/events/combat/DamageEvent.py b/mechanics/events/combat/DamageEvent.py | |
index 2279c61..2e76475 100644 | |
--- a/mechanics/events/combat/DamageEvent.py | |
+++ b/mechanics/events/combat/DamageEvent.py | |
@@ -10,11 +10,17 @@ if TYPE_CHECKING: | |
from game_objects.battlefield_objects import BattlefieldObject, Unit | |
- | |
class DamageEvent(Event): | |
channel = EventsChannels.DamageChannel | |
- def __init__(self, damage: Damage, target: BattlefieldObject, *, source: Unit=None, impact_factor=ImpactFactor.HIT, fire=True): | |
+ def __init__( | |
+ self, | |
+ damage: Damage, | |
+ target: BattlefieldObject, | |
+ *, | |
+ source: Unit = None, | |
+ impact_factor=ImpactFactor.HIT, | |
+ fire=True): | |
self.source = source | |
self.target = target | |
self.damage = damage | |
@@ -22,21 +28,20 @@ class DamageEvent(Event): | |
self.weapon_dur_dmg = 0 | |
- | |
super().__init__(target.game, fire, logging=True) | |
- | |
@property | |
def amount(self): | |
- return Damage.calculate_damage(self.damage, self.target, self.impact_factor)[0] | |
- | |
+ return Damage.calculate_damage( | |
+ self.damage, self.target, self.impact_factor)[0] | |
def check_conditions(self): | |
return self.target.alive | |
def resolve(self): | |
- _, armor_dur_dmg, weapon_dur_dmg = Damage.calculate_damage(self.damage, self.target, self.impact_factor) | |
+ _, armor_dur_dmg, weapon_dur_dmg = Damage.calculate_damage( | |
+ self.damage, self.target, self.impact_factor) | |
if not self.target.is_obstacle: | |
body_armor = self.target.equipment[EquipmentSlotUids.BODY] | |
@@ -46,8 +51,6 @@ class DamageEvent(Event): | |
self.weapon_dur_dmg = weapon_dur_dmg | |
self.target.lose_health(self.amount, self.source) | |
- | |
- | |
def __repr__(self): | |
if self.amount == 0: | |
@@ -56,11 +59,11 @@ class DamageEvent(Event): | |
if self.source: | |
return "{}! {} recieves {} {} damage from {}.".format( | |
- self.impact_factor, | |
- self.target, | |
- self.amount, | |
- self.damage.type, | |
- self.source) | |
+ self.impact_factor, | |
+ self.target, | |
+ self.amount, | |
+ self.damage.type, | |
+ self.source) | |
else: | |
return "{}! {} recieves {} {} damage.".format(self.impact_factor, | |
self.target, | |
diff --git a/mechanics/events/combat/HealingEvent.py b/mechanics/events/combat/HealingEvent.py | |
index 80d82b7..5155b87 100644 | |
--- a/mechanics/events/combat/HealingEvent.py | |
+++ b/mechanics/events/combat/HealingEvent.py | |
@@ -5,10 +5,16 @@ from typing import TYPE_CHECKING | |
if TYPE_CHECKING: | |
from game_objects.battlefield_objects import Unit, BattlefieldObject | |
+ | |
class HealingEvent(Event): | |
channel = EventsChannels.HealingChannel | |
- def __init__(self, healing_amount: float, target: BattlefieldObject, *, source: Unit=None): | |
+ def __init__( | |
+ self, | |
+ healing_amount: float, | |
+ target: BattlefieldObject, | |
+ *, | |
+ source: Unit = None): | |
self.source = source | |
self.target = target | |
self.healing_amount = healing_amount | |
diff --git a/mechanics/events/combat/MovementEvent.py b/mechanics/events/combat/MovementEvent.py | |
index 4c3ca06..373ed69 100644 | |
--- a/mechanics/events/combat/MovementEvent.py | |
+++ b/mechanics/events/combat/MovementEvent.py | |
@@ -6,6 +6,7 @@ from typing import TYPE_CHECKING, Union | |
if TYPE_CHECKING: | |
from game_objects.battlefield_objects import Unit | |
+ | |
class MovementEvent(Event): | |
channel = EventsChannels.MovementChannel | |
@@ -19,15 +20,11 @@ class MovementEvent(Event): | |
def check_conditions(self): | |
return all((self.unit.alive, | |
- not self.cell_to in self.game.bf.walls, | |
- self.cell_to in self.game.bf.all_cells)) | |
+ self.cell_to not in self.game.bf.walls, | |
+ self.cell_to in self.game.bf.all_cells)) | |
def resolve(self): | |
self.unit.cell = self.cell_to | |
def __repr__(self): | |
return f"{self.unit} moves from {self.cell_from} to {self.cell_to}" | |
- | |
- | |
- | |
- | |
diff --git a/mechanics/events/combat/PushEvent.py b/mechanics/events/combat/PushEvent.py | |
index 8e823b6..60dbc94 100644 | |
--- a/mechanics/events/combat/PushEvent.py | |
+++ b/mechanics/events/combat/PushEvent.py | |
@@ -8,6 +8,7 @@ from typing import TYPE_CHECKING | |
if TYPE_CHECKING: | |
from game_objects.battlefield_objects import Unit | |
+ | |
class PushEvent(Event): | |
channel = EventsChannels.PushChannel | |
@@ -18,7 +19,6 @@ class PushEvent(Event): | |
self.push_against = push_against | |
self.cell_to = push_against.cell | |
- | |
super().__init__(game) | |
def check_conditions(self): | |
@@ -27,13 +27,22 @@ class PushEvent(Event): | |
def resolve(self): | |
dmg_factor = 0.05 | |
- damage = Damage( (self.unit.max_health + self.push_against.max_health)* dmg_factor, type=DamageTypes.CRUSH) | |
+ damage = Damage( | |
+ (self.unit.max_health + | |
+ self.push_against.max_health) * | |
+ dmg_factor, | |
+ type=DamageTypes.CRUSH) | |
events.DamageEvent(damage, self.push_against, source=self.unit) | |
events.DamageEvent(damage, self.unit, source=self.push_against) | |
if self.unit.alive and self.push_against.alive: | |
- pushed_to = self.game.random.choice(self.bf.get_cells_within_dist(self.cell_to, 1)) | |
- success = roll(0.6, self.unit.str * 2, self.push_against.str * 2, self.game.random) | |
+ pushed_to = self.game.random.choice( | |
+ self.bf.get_cells_within_dist(self.cell_to, 1)) | |
+ success = roll( | |
+ 0.6, | |
+ self.unit.str * 2, | |
+ self.push_against.str * 2, | |
+ self.game.random) | |
if success: | |
victor, loser = self.unit, self.push_against | |
@@ -47,11 +56,5 @@ class PushEvent(Event): | |
loser.readiness -= pushed_atb_cost | |
victor.readiness -= pusher_atb_cost | |
- | |
- | |
def __repr__(self): | |
return f"{self.unit} pushes against {self.push_against} to {self.cell_to}" | |
- | |
- | |
- | |
- | |
diff --git a/mechanics/events/combat/RangedAttackEvent.py b/mechanics/events/combat/RangedAttackEvent.py | |
index f2722f7..89d61c3 100644 | |
--- a/mechanics/events/combat/RangedAttackEvent.py | |
+++ b/mechanics/events/combat/RangedAttackEvent.py | |
@@ -11,41 +11,52 @@ if TYPE_CHECKING: | |
class RangedAttackEvent(Event): | |
channel = EventsChannels.RangedAttackChannel | |
- def __init__(self, source: Unit, target: BattlefieldObject, weapon : Weapon, fire: bool=True): | |
+ | |
+ def __init__( | |
+ self, | |
+ source: Unit, | |
+ target: BattlefieldObject, | |
+ weapon: Weapon, | |
+ fire: bool = True): | |
game = source.game | |
self.source = source | |
self.target = target | |
self.weapon = weapon | |
- self.is_backstab = not target.is_obstacle and not game.vision.x_sees_y(target, source) | |
+ self.is_backstab = not target.is_obstacle and not game.vision.x_sees_y( | |
+ target, source) | |
self.is_blind = not game.vision.x_sees_y(source, target) | |
- super().__init__(game,fire, logging=True) | |
+ super().__init__(game, fire, logging=True) | |
def check_conditions(self) -> bool: | |
- return all( (self.source, self.source.alive, self.target, self.target.alive, | |
- self.weapon, self.weapon.durability is None or self.weapon.durability > 0) ) | |
+ return all( | |
+ (self.source, | |
+ self.source.alive, | |
+ self.target, | |
+ self.target.alive, | |
+ self.weapon, | |
+ self.weapon.durability is None or self.weapon.durability > 0)) | |
def resolve(self) -> None: | |
precision, evasion = self.effective_precision_evasion() | |
- impact = self.weapon.chances.actual(precision, evasion).roll_impact(random=self.game.random) | |
+ impact = self.weapon.chances.actual( | |
+ precision, evasion).roll_impact( | |
+ random=self.game.random) | |
if impact is not ImpactFactor.MISS: | |
- dmg_event = DamageEvent( self.weapon.damage, self.target, | |
- source=self.source, | |
- impact_factor = impact) | |
+ dmg_event = DamageEvent(self.weapon.damage, self.target, | |
+ source=self.source, | |
+ impact_factor=impact) | |
if self.weapon and self.weapon.durability: | |
self.weapon.durability -= dmg_event.weapon_dur_dmg | |
else: | |
self.game.gamelog("MISS") | |
- | |
- | |
def calculate_chances(self) -> ImpactChances: | |
p, e = self.effective_precision_evasion() | |
return self.source.unarmed_chances.actual(p, e) | |
- | |
def effective_precision_evasion(self)-> Tuple[float, float]: | |
effective_precision = self.source.melee_precision | |
if self.is_blind: | |
@@ -57,7 +68,6 @@ class RangedAttackEvent(Event): | |
return effective_precision, effective_evasion | |
- | |
def __repr__(self): | |
msg = "" | |
msg += "Backstab! " if self.is_backstab else "" | |
diff --git a/mechanics/events/combat/UnitDiedEvent.py b/mechanics/events/combat/UnitDiedEvent.py | |
index 0c1cc94..e2fbc28 100644 | |
--- a/mechanics/events/combat/UnitDiedEvent.py | |
+++ b/mechanics/events/combat/UnitDiedEvent.py | |
@@ -1,12 +1,11 @@ | |
from __future__ import annotations | |
+from game_objects import battlefield_objects | |
from mechanics.events.src.Event import Event | |
from mechanics.events import EventsChannels | |
from typing import TYPE_CHECKING | |
if TYPE_CHECKING: | |
from game_objects.battlefield_objects import Unit | |
-from game_objects import battlefield_objects | |
- | |
class UnitDiedEvent(Event): | |
channel = EventsChannels.UnitDiedChannel | |
diff --git a/mechanics/events/items/ItemDestroyedEvent.py b/mechanics/events/items/ItemDestroyedEvent.py | |
index 27a79f2..046e79c 100644 | |
--- a/mechanics/events/items/ItemDestroyedEvent.py | |
+++ b/mechanics/events/items/ItemDestroyedEvent.py | |
@@ -5,6 +5,7 @@ from typing import TYPE_CHECKING | |
if TYPE_CHECKING: | |
from game_objects.items import WearableItem | |
+ | |
class ItemDestroyedEvent(Event): | |
channel = EventsChannels.ItemDestroyedChannel | |
@@ -18,18 +19,17 @@ class ItemDestroyedEvent(Event): | |
def resolve(self): | |
if self.item.owner and self.item.blueprint and self.item.material: | |
i1 = self.item.blueprint | |
- i2 = self.item.material.to_pieces(self.item.blueprint.material_count) | |
+ i2 = self.item.material.to_pieces( | |
+ self.item.blueprint.material_count) | |
self.item.owner.inventory.add(i1) | |
self.item.owner.inventory.add(i2) | |
- | |
if self.item.slot: | |
self.item.slot.pop_item() | |
- | |
def __repr__(self): | |
if self.item.owner: | |
return f"{self.item.owner}'s {self.item} was destroyed" | |
else: | |
- return f"{self.item} was destroyed" | |
\ No newline at end of file | |
+ return f"{self.item} was destroyed" | |
diff --git a/mechanics/events/items/ItemDroppedEvent.py b/mechanics/events/items/ItemDroppedEvent.py | |
index a48770e..5b1948a 100644 | |
--- a/mechanics/events/items/ItemDroppedEvent.py | |
+++ b/mechanics/events/items/ItemDroppedEvent.py | |
@@ -5,10 +5,11 @@ from typing import TYPE_CHECKING | |
if TYPE_CHECKING: | |
from game_objects.items import Item | |
+ | |
class ItemDroppedEvent(Event): | |
channel = EventsChannels.DropChannel | |
- def __init__(self, item: Item, cell = None): | |
+ def __init__(self, item: Item, cell=None): | |
self.item = item | |
g = item.game | |
if cell: | |
@@ -17,7 +18,7 @@ class ItemDroppedEvent(Event): | |
if item.owner: | |
location = g.bf.unit_locations[item.owner] | |
else: | |
- location = g.random.sample( g.bf.all_cells, 1 )[0] | |
+ location = g.random.sample(g.bf.all_cells, 1)[0] | |
self.location = location | |
super().__init__(g, logging=True) | |
@@ -32,4 +33,4 @@ class ItemDroppedEvent(Event): | |
# TODO enable pickup of dropped items | |
def __repr__(self): | |
- return f"{self.item} was dropped at {self.location}." | |
\ No newline at end of file | |
+ return f"{self.item} was dropped at {self.location}." | |
diff --git a/mechanics/events/items/ItemUsedUpEvent.py b/mechanics/events/items/ItemUsedUpEvent.py | |
index c074b97..d0c0a65 100644 | |
--- a/mechanics/events/items/ItemUsedUpEvent.py | |
+++ b/mechanics/events/items/ItemUsedUpEvent.py | |
@@ -5,6 +5,7 @@ from typing import TYPE_CHECKING | |
if TYPE_CHECKING: | |
from game_objects.items import ChargedItem | |
+ | |
class ItemUsedUpEvent(Event): | |
channel = EventsChannels.UsedUpChannel | |
@@ -22,4 +23,4 @@ class ItemUsedUpEvent(Event): | |
if self.item.owner: | |
return f"{self.item.owner}'s {self.item} was used up." | |
else: | |
- return f"{self.item} was used up." | |
\ No newline at end of file | |
+ return f"{self.item} was used up." | |
diff --git a/mechanics/events/magic/BuffAppliedEvent.py b/mechanics/events/magic/BuffAppliedEvent.py | |
index ecc4e35..dbd8ef1 100644 | |
--- a/mechanics/events/magic/BuffAppliedEvent.py | |
+++ b/mechanics/events/magic/BuffAppliedEvent.py | |
@@ -6,6 +6,7 @@ if TYPE_CHECKING: | |
from mechanics.buffs import Buff | |
from game_objects.battlefield_objects import Unit | |
+ | |
class BuffAppliedEvent(Event): | |
channel = EventsChannels.BuffAppliedChannel | |
diff --git a/mechanics/events/magic/BuffDetachedEvent.py b/mechanics/events/magic/BuffDetachedEvent.py | |
index aa49cb6..67ef3b2 100644 | |
--- a/mechanics/events/magic/BuffDetachedEvent.py | |
+++ b/mechanics/events/magic/BuffDetachedEvent.py | |
@@ -5,6 +5,7 @@ from typing import TYPE_CHECKING | |
if TYPE_CHECKING: | |
from mechanics.buffs import Buff | |
+ | |
class BuffDetachedEvent(Event): | |
channel = EventsChannels.BuffDetachedChannel | |
diff --git a/mechanics/events/magic/BuffDispelledEvent.py b/mechanics/events/magic/BuffDispelledEvent.py | |
index 3f24393..43ed203 100644 | |
--- a/mechanics/events/magic/BuffDispelledEvent.py | |
+++ b/mechanics/events/magic/BuffDispelledEvent.py | |
@@ -9,6 +9,7 @@ if TYPE_CHECKING: | |
class BuffDispelledEvent(Event): | |
channel = EventsChannels.BuffDispelledChannel | |
+ | |
def __init__(self, buff: Buff, source: Unit): | |
self.buff = buff | |
self.source = source | |
@@ -21,4 +22,4 @@ class BuffDispelledEvent(Event): | |
BuffDetachedEvent(self.buff) | |
def __repr__(self): | |
- return f"{self.buff} was dispelled by {self.source}." | |
\ No newline at end of file | |
+ return f"{self.buff} was dispelled by {self.source}." | |
diff --git a/mechanics/events/magic/BuffExpiredEvent.py b/mechanics/events/magic/BuffExpiredEvent.py | |
index 5d32b65..60f6958 100644 | |
--- a/mechanics/events/magic/BuffExpiredEvent.py | |
+++ b/mechanics/events/magic/BuffExpiredEvent.py | |
@@ -5,6 +5,7 @@ from typing import TYPE_CHECKING | |
if TYPE_CHECKING: | |
from mechanics.buffs import Buff | |
+ | |
class BuffExpiredEvent(Event): | |
channel = EventsChannels.BuffExpiredChannel | |
@@ -19,4 +20,4 @@ class BuffExpiredEvent(Event): | |
BuffDetachedEvent(self.buff) | |
def __repr__(self): | |
- return f"{self.buff} has expired." | |
\ No newline at end of file | |
+ return f"{self.buff} has expired." | |
diff --git a/mechanics/events/src/Event.py b/mechanics/events/src/Event.py | |
index a90d5d6..170a28a 100644 | |
--- a/mechanics/events/src/Event.py | |
+++ b/mechanics/events/src/Event.py | |
@@ -4,8 +4,13 @@ from typing import TYPE_CHECKING | |
if TYPE_CHECKING: | |
from DreamGame import DreamGame | |
+ | |
class Event: | |
- def __init__(self, game: DreamGame, fire: bool=True, logging:bool = False): | |
+ def __init__( | |
+ self, | |
+ game: DreamGame, | |
+ fire: bool = True, | |
+ logging: bool = False): | |
self.interrupted = False | |
self.game = game | |
self.logging = logging | |
@@ -13,7 +18,7 @@ class Event: | |
self.fire() | |
def fire(self) -> None: | |
- if not self.game is None: | |
+ if self.game is not None: | |
self.game.events_platform.process_event(self) | |
@abstractmethod | |
diff --git a/mechanics/events/src/EventChannels.py b/mechanics/events/src/EventChannels.py | |
index 95827b5..648f0b1 100644 | |
--- a/mechanics/events/src/EventChannels.py | |
+++ b/mechanics/events/src/EventChannels.py | |
@@ -1,5 +1,6 @@ | |
from my_utils.named_enums import auto, NameEnum | |
+ | |
class EventsChannels(NameEnum): | |
DamageChannel = auto() | |
HealingChannel = auto() | |
@@ -19,7 +20,6 @@ class EventsChannels(NameEnum): | |
UsedUpChannel = auto() | |
DropChannel = auto() | |
- | |
BuffAppliedChannel = auto() | |
BuffDetachedChannel = auto() | |
BuffDispelledChannel = auto() | |
@@ -37,4 +37,3 @@ class EventsChannels(NameEnum): | |
ServerOrderRecievedChannel = auto() | |
ClientOrderIssuedChannel = auto() | |
ClientOrderRecievedChannel = auto() | |
- | |
diff --git a/mechanics/events/src/EventsPlatform.py b/mechanics/events/src/EventsPlatform.py | |
index 2856f0b..d9ae3c9 100644 | |
--- a/mechanics/events/src/EventsPlatform.py | |
+++ b/mechanics/events/src/EventsPlatform.py | |
@@ -1,11 +1,12 @@ | |
from mechanics.events import EventsChannels | |
+ | |
class EventsPlatform: | |
def __init__(self, gamelog): | |
self.gamelog = gamelog | |
- self.interrupts = { ch: set() for ch in EventsChannels } | |
- self.triggers = { ch: set() for ch in EventsChannels } | |
+ self.interrupts = {ch: set() for ch in EventsChannels} | |
+ self.triggers = {ch: set() for ch in EventsChannels} | |
self.history = [] | |
def process_event(self, event): | |
@@ -21,7 +22,7 @@ class EventsPlatform: | |
if self.history: | |
for spy in self.history: | |
- spy.append( (event, True) ) | |
+ spy.append((event, True)) | |
if event.logging: | |
self.gamelog(event) | |
@@ -32,13 +33,10 @@ class EventsPlatform: | |
else: | |
if self.history: | |
for spy in self.history: | |
- spy.append( (event, False) ) | |
+ spy.append((event, False)) | |
self.gamelog(f"{event}: INTERRUPTED") | |
- | |
def collect_history(self): | |
spy = [] | |
self.history.append(spy) | |
return spy | |
- | |
- | |
diff --git a/mechanics/events/src/Interrupt.py b/mechanics/events/src/Interrupt.py | |
index 5127596..ddfb805 100644 | |
--- a/mechanics/events/src/Interrupt.py | |
+++ b/mechanics/events/src/Interrupt.py | |
@@ -1,24 +1,42 @@ | |
from mechanics.events import Trigger | |
+ | |
def interrupt_modifier(_, event): | |
event.interrupted = True | |
class PermanentInterrupt(Trigger): | |
- def __init__(self, target_event_cls, conditions, interrupt_event = True, callbacks=None, *, platform): | |
+ def __init__( | |
+ self, | |
+ target_event_cls, | |
+ conditions, | |
+ interrupt_event=True, | |
+ callbacks=None, | |
+ *, | |
+ platform): | |
callbacks = callbacks or [] | |
if interrupt_event: | |
callbacks.append(interrupt_modifier) | |
- | |
- super().__init__(target_event_cls, conditions=conditions, is_interrupt=True, | |
- callbacks=callbacks, platform=platform) | |
+ super().__init__( | |
+ target_event_cls, | |
+ conditions=conditions, | |
+ is_interrupt=True, | |
+ callbacks=callbacks, | |
+ platform=platform) | |
class CounteredInterrupt(PermanentInterrupt): | |
- def __init__(self, target_event_cls, conditions, interrupt_event = True, callbacks:list=None, | |
- n_counters=1, *, platform): | |
+ def __init__( | |
+ self, | |
+ target_event_cls, | |
+ conditions, | |
+ interrupt_event=True, | |
+ callbacks: list = None, | |
+ n_counters=1, | |
+ *, | |
+ platform): | |
self.n_counters = n_counters | |
@@ -26,8 +44,6 @@ class CounteredInterrupt(PermanentInterrupt): | |
if callbacks: | |
_callbacks += callbacks | |
- | |
- | |
super().__init__(target_event_cls, conditions, interrupt_event, | |
callbacks=_callbacks, platform=platform) | |
@@ -35,4 +51,4 @@ class CounteredInterrupt(PermanentInterrupt): | |
def count_down(self, _): | |
self.n_counters -= 1 | |
if self.n_counters <= 0: | |
- self.deactivate() | |
\ No newline at end of file | |
+ self.deactivate() | |
diff --git a/mechanics/events/src/Trigger.py b/mechanics/events/src/Trigger.py | |
index 0d20721..ceb4966 100644 | |
--- a/mechanics/events/src/Trigger.py | |
+++ b/mechanics/events/src/Trigger.py | |
@@ -5,11 +5,17 @@ if TYPE_CHECKING: | |
from mechanics.events import EventsPlatform | |
from game_objects.battlefield_objects import Unit | |
+ | |
class Trigger: | |
- def __init__(self, target_event_cls: ClassVar,*, platform: EventsPlatform, conditions: Collection[Callable] = None, | |
- source: Unit = None, | |
- is_interrupt: bool = False, | |
- callbacks: List[Callable] = None): | |
+ def __init__( | |
+ self, | |
+ target_event_cls: ClassVar, | |
+ *, | |
+ platform: EventsPlatform, | |
+ conditions: Collection[Callable] = None, | |
+ source: Unit = None, | |
+ is_interrupt: bool = False, | |
+ callbacks: List[Callable] = None): | |
assert inspect.isclass(target_event_cls) | |
self.channel = target_event_cls.channel | |
@@ -47,5 +53,3 @@ class Trigger: | |
self.platform.triggers[self.channel].remove(self) | |
except KeyError: | |
pass | |
- | |
- | |
diff --git a/mechanics/factions/Faction.py b/mechanics/factions/Faction.py | |
index db5a6b1..f002c3a 100644 | |
--- a/mechanics/factions/Faction.py | |
+++ b/mechanics/factions/Faction.py | |
@@ -1,6 +1,7 @@ | |
from enum import Enum, auto | |
+ | |
class Faction(Enum): | |
PLAYER = auto() | |
ENEMY = auto() | |
- NEUTRALS = auto() | |
\ No newline at end of file | |
+ NEUTRALS = auto() | |
diff --git a/mechanics/loot/ability_generator.py b/mechanics/loot/ability_generator.py | |
index b405364..0c5423a 100644 | |
--- a/mechanics/loot/ability_generator.py | |
+++ b/mechanics/loot/ability_generator.py | |
@@ -2,4 +2,4 @@ from game_objects.items import WearableItem | |
from game_objects.items import Material, MaterialTypes | |
from game_objects.items import Blueprint | |
-#TODO implement me | |
\ No newline at end of file | |
+# TODO implement me | |
diff --git a/mechanics/rpg/aggro.py b/mechanics/rpg/aggro.py | |
index 48d94dd..df36226 100644 | |
--- a/mechanics/rpg/aggro.py | |
+++ b/mechanics/rpg/aggro.py | |
@@ -4,7 +4,6 @@ from mechanics.events import MovementEvent, DamageEvent | |
from mechanics.factions import Faction | |
- | |
# no bleeding? | |
def gain_aggro_cb(t, e: MovementEvent): | |
@@ -22,7 +21,7 @@ def gain_aggro_cb(t, e: MovementEvent): | |
def lose_agro_cb(t, e: MovementEvent): | |
active_enemies = [u for u in e.game.units | |
- if u.faction is Faction.ENEMY and u.fights_hero] | |
+ if u.faction is Faction.ENEMY and u.fights_hero] | |
player_units = [u for u in e.game.units if u.faction is Faction.PLAYER] | |
@@ -34,8 +33,6 @@ def lose_agro_cb(t, e: MovementEvent): | |
enemy.fights_hero = False | |
- | |
- | |
def vision_aggro_rule(game): | |
return Trigger(MovementEvent, | |
platform=game.events_platform, | |
@@ -55,4 +52,4 @@ def damage_provokes_rule(game): | |
return Trigger(DamageEvent, | |
platform=game.events_platform, | |
conditions={}, | |
- callbacks=[damage_provokes_cb]) | |
\ No newline at end of file | |
+ callbacks=[damage_provokes_cb]) | |
diff --git a/mechanics/rpg/experience.py b/mechanics/rpg/experience.py | |
index 2f49c1a..cd3350a 100644 | |
--- a/mechanics/rpg/experience.py | |
+++ b/mechanics/rpg/experience.py | |
@@ -4,13 +4,14 @@ from mechanics.factions import Faction | |
from my_utils.utils import tractable_value | |
+ | |
def compute_exp_gain(hero, monster): | |
- factor = (monster.xp / hero.xp) ** (4/5) | |
- std_amount = monster.xp ** (7/10) // 25 | |
+ factor = (monster.xp / hero.xp) ** (4 / 5) | |
+ std_amount = monster.xp ** (7 / 10) // 25 | |
return tractable_value(std_amount * factor + 0.5, digits=3) | |
-def condition(t,e): | |
+def condition(t, e): | |
if not e.killer: | |
return False | |
@@ -18,6 +19,7 @@ def condition(t,e): | |
e.unit.faction is Faction.ENEMY and \ | |
e.killer.faction is Faction.PLAYER | |
+ | |
def grant_xp_callback(t, e): | |
e.killer.xp += compute_exp_gain(e.killer, e.unit) | |
@@ -29,11 +31,11 @@ def exp_rule(game): | |
callbacks=[grant_xp_callback]) | |
- | |
if __name__ == "__main__": | |
from collections import namedtuple | |
dummy_unit = namedtuple("unit", "xp") | |
for hero_xp in [500, 2500, 12500, 50000, 1e6]: | |
for monster_xp in [500, 2500, 12500, 50000, 1e6]: | |
- print(f"{hero_xp} | {monster_xp} | {compute_exp_gain(dummy_unit(hero_xp), dummy_unit(monster_xp))}") | |
\ No newline at end of file | |
+ print( | |
+ f"{hero_xp} | {monster_xp} | {compute_exp_gain(dummy_unit(hero_xp), dummy_unit(monster_xp))}") | |
diff --git a/mechanics/rpg/push.py b/mechanics/rpg/push.py | |
index 6a8a77d..3b2a273 100644 | |
--- a/mechanics/rpg/push.py | |
+++ b/mechanics/rpg/push.py | |
@@ -1,22 +1,25 @@ | |
from mechanics.events.src.Trigger import Trigger | |
from mechanics.events import MovementEvent, PushEvent | |
+ | |
def push_callback(t, e: MovementEvent): | |
bf = e.game.bf | |
pusher = e.unit | |
ctr = 0 | |
- while bf.space_free( e.cell_to ) < 0 and len(bf.cells_to_objs[e.cell_to]) > 1 and \ | |
- pusher.alive and ctr < 10: | |
+ while bf.space_free(e.cell_to) < 0 and len( | |
+ bf.cells_to_objs[e.cell_to]) > 1 and pusher.alive and ctr < 10: | |
ctr += 1 | |
- push_against = e.game.random.choice(list(set(bf.cells_to_objs[e.cell_to]) - {pusher})) | |
+ push_against = e.game.random.choice( | |
+ list(set(bf.cells_to_objs[e.cell_to]) - {pusher})) | |
PushEvent(pusher, push_against) | |
def push_condition(t, e): | |
- return e.game.bf.space_free( e.cell_to ) < 0 | |
+ return e.game.bf.space_free(e.cell_to) < 0 | |
+ | |
def push_rule(game): | |
return Trigger(MovementEvent, | |
platform=game.events_platform, | |
conditions={push_condition}, | |
- callbacks=[push_callback]) | |
\ No newline at end of file | |
+ callbacks=[push_callback]) | |
diff --git a/mechanics/rpg/regen.py b/mechanics/rpg/regen.py | |
index 4d65fa1..95e475f 100644 | |
--- a/mechanics/rpg/regen.py | |
+++ b/mechanics/rpg/regen.py | |
@@ -8,12 +8,16 @@ FULL_MANA_REGEN_PERIOD = 120 | |
FULL_STAMINA_REGEN_PERIOD = 120 | |
# no bleeding? | |
+ | |
+ | |
def regen_all_callback(t, e): | |
for unit in list(e.game.units): | |
if not unit.is_obstacle and unit.alive: | |
- is_undead = any([hasattr(a, UNDEAD_N_HITS) for a in unit.abilities]) | |
+ is_undead = any([hasattr(a, UNDEAD_N_HITS) | |
+ for a in unit.abilities]) | |
if not is_undead: | |
- unit.health += unit.max_health * (2 * (unit.health / unit.max_health) - 1) * e.dt / FULL_REGEN_PERIOD | |
+ unit.health += unit.max_health * \ | |
+ (2 * (unit.health / unit.max_health) - 1) * e.dt / FULL_REGEN_PERIOD | |
unit.mana += unit.max_mana * e.dt / FULL_MANA_REGEN_PERIOD | |
unit.stamina += unit.max_stamina * e.dt / FULL_STAMINA_REGEN_PERIOD | |
@@ -23,4 +27,4 @@ def regen_rule(game): | |
return Trigger(TimePassedEvent, | |
platform=game.events_platform, | |
conditions={}, | |
- callbacks=[regen_all_callback]) | |
\ No newline at end of file | |
+ callbacks=[regen_all_callback]) | |
diff --git a/mechanics/turns/AtbTurnsManager.py b/mechanics/turns/AtbTurnsManager.py | |
index 8f59171..453fd10 100644 | |
--- a/mechanics/turns/AtbTurnsManager.py | |
+++ b/mechanics/turns/AtbTurnsManager.py | |
@@ -11,6 +11,8 @@ if TYPE_CHECKING: | |
from DreamGame import DreamGame | |
epsilon = 1e-6 | |
+ | |
+ | |
class AtbTurnsManager(TurnsManager): | |
def __init__(self, game: DreamGame): | |
self.game = game | |
@@ -77,7 +79,6 @@ class AtbTurnsManager(TurnsManager): | |
def sort(self): | |
self.managed.sort(key=self.time_until_turn) | |
- | |
def add_unit(self, unit): | |
if unit not in self.managed: | |
self.managed.append(unit) | |
diff --git a/mechanics/turns/SequentialTM.py b/mechanics/turns/SequentialTM.py | |
index 9610294..f39795e 100644 | |
--- a/mechanics/turns/SequentialTM.py | |
+++ b/mechanics/turns/SequentialTM.py | |
@@ -1,6 +1,7 @@ | |
from mechanics.turns import TurnsManager | |
from collections import deque | |
+ | |
class SequentialTM(TurnsManager): | |
def __init__(self, units=None): | |
self.units = deque(units or []) | |
diff --git a/mechanics/turns/TurnsManager.py b/mechanics/turns/TurnsManager.py | |
index b0a9970..206c72e 100644 | |
--- a/mechanics/turns/TurnsManager.py | |
+++ b/mechanics/turns/TurnsManager.py | |
@@ -1,5 +1,6 @@ | |
from abc import ABC, abstractmethod | |
+ | |
class TurnsManager(ABC): | |
@abstractmethod | |
diff --git a/multiplayer/Client.py b/multiplayer/Client.py | |
index d5c1b4b..90dde40 100644 | |
--- a/multiplayer/Client.py | |
+++ b/multiplayer/Client.py | |
@@ -43,38 +43,40 @@ def order_recieved_trigger(game): | |
conditions={}, | |
callbacks=[order_recieved_cb]) | |
+ | |
def order_issued_cb(t, e): | |
t.client.send(e) | |
+ | |
def order_issued_trigger(game, client): | |
t = Trigger(ClientOrderIssuedEvent, | |
platform=game.events_platform, | |
conditions={}, | |
- callbacks=[order_issued_cb]) | |
+ callbacks=[order_issued_cb]) | |
t.client = client | |
return t | |
- | |
class PydolonsClient: | |
def __init__(self): | |
character = Character(demohero_basetype) | |
- self.game = DreamGame.start_dungeon(demo_dungeon, character.unit, is_server=False) | |
+ self.game = DreamGame.start_dungeon( | |
+ demo_dungeon, character.unit, is_server=False) | |
self.game.character = character | |
self.client = ClientSocket(self.game) | |
- order_issued_trigger(self.game, self.client) # local actions cause sending orders to the server | |
- order_recieved_trigger(self.game) # orders from the server cause local actions | |
+ # local actions cause sending orders to the server | |
+ order_issued_trigger(self.game, self.client) | |
+ # orders from the server cause local actions | |
+ order_recieved_trigger(self.game) | |
def start_sync(self): | |
self.client.connect() | |
th = Thread(target=self.client.myreceive) | |
th.start() | |
- | |
- | |
def start_gui(self): | |
app = QtWidgets.QApplication(sys.argv) | |
@@ -99,7 +101,6 @@ class PydolonsClient: | |
# application waiting for shutdown thread | |
loop.wait() | |
- | |
# call exit from window | |
app.aboutToQuit.connect(close_app) | |
loop.game = self.game | |
@@ -108,6 +109,7 @@ class PydolonsClient: | |
loop.setSiganls(ProxyEmit) | |
sys.exit(app.exec_()) | |
+ | |
if __name__ == "__main__": | |
c = PydolonsClient() | |
c.start_sync() | |
diff --git a/multiplayer/Server.py b/multiplayer/Server.py | |
index 9031222..c58738e 100644 | |
--- a/multiplayer/Server.py | |
+++ b/multiplayer/Server.py | |
@@ -45,7 +45,7 @@ def order_issued_trigger(game, server): | |
t = Trigger(ServerOrderIssuedEvent, | |
platform=game.events_platform, | |
conditions={}, | |
- callbacks=[order_issued_cb]) | |
+ callbacks=[order_issued_cb]) | |
t.server = server | |
return t | |
@@ -53,11 +53,11 @@ def order_issued_trigger(game, server): | |
class PydolonsServer: | |
def __init__(self): | |
- character = Character(demohero_basetype) | |
+ character = Character(demohero_basetype) | |
self.game = DreamGame.start_dungeon(demo_dungeon, character.unit) | |
self.game.character = character | |
- self.server_socket = ServerSocket(self.game, set(self.game.fractions.values()) - {Faction.ENEMY, | |
- Faction.NEUTRALS}) | |
+ self.server_socket = ServerSocket(self.game, set( | |
+ self.game.fractions.values()) - {Faction.ENEMY, Faction.NEUTRALS}) | |
order_issued_trigger(self.game, self.server_socket) | |
order_recieved_trigger(self.game) | |
@@ -86,7 +86,8 @@ class PydolonsServer: | |
def __exit__(self, exc_type, exc_val, exc_tb): | |
self.server_socket.serversocket.close() | |
+ | |
if __name__ == "__main__": | |
s = PydolonsServer() | |
s.listen() | |
- s.start_when_ready() | |
\ No newline at end of file | |
+ s.start_when_ready() | |
diff --git a/multiplayer/events/ClientOrderIssuedEvent.py b/multiplayer/events/ClientOrderIssuedEvent.py | |
index cd41866..de2b233 100644 | |
--- a/multiplayer/events/ClientOrderIssuedEvent.py | |
+++ b/multiplayer/events/ClientOrderIssuedEvent.py | |
@@ -1,6 +1,7 @@ | |
from mechanics.events.src.Event import Event | |
from mechanics.events import EventsChannels | |
+ | |
class ClientOrderIssuedEvent(Event): | |
channel = EventsChannels.ClientOrderIssuedChannel | |
diff --git a/multiplayer/events/ClientOrderRecievedEvent.py b/multiplayer/events/ClientOrderRecievedEvent.py | |
index 84e0cf6..d49f471 100644 | |
--- a/multiplayer/events/ClientOrderRecievedEvent.py | |
+++ b/multiplayer/events/ClientOrderRecievedEvent.py | |
@@ -1,6 +1,7 @@ | |
from mechanics.events.src.Event import Event | |
from mechanics.events import EventsChannels | |
+ | |
class ClientOrderRecievedEvent(Event): | |
channel = EventsChannels.ClientOrderRecievedChannel | |
diff --git a/multiplayer/events/ServerOrderIssuedEvent.py b/multiplayer/events/ServerOrderIssuedEvent.py | |
index fe46bc7..27e2977 100644 | |
--- a/multiplayer/events/ServerOrderIssuedEvent.py | |
+++ b/multiplayer/events/ServerOrderIssuedEvent.py | |
@@ -1,10 +1,12 @@ | |
from mechanics.events.src.Event import Event | |
from mechanics.events import EventsChannels | |
+ | |
class ServerOrderIssuedEvent(Event): | |
channel = EventsChannels.ServerOrderIssuedChannel | |
next_uid = 0 | |
+ | |
def __init__(self, game, unit_uid, active_uid, target): | |
ServerOrderIssuedEvent.next_uid += 1 | |
self.uid = ServerOrderIssuedEvent.next_uid | |
diff --git a/multiplayer/events/ServerOrderReceivedEvent.py b/multiplayer/events/ServerOrderReceivedEvent.py | |
index aaafb46..805bc73 100644 | |
--- a/multiplayer/events/ServerOrderReceivedEvent.py | |
+++ b/multiplayer/events/ServerOrderReceivedEvent.py | |
@@ -1,10 +1,11 @@ | |
from mechanics.events.src.Event import Event | |
from mechanics.events import EventsChannels | |
+ | |
class ServerOrderRecievedEvent(Event): | |
channel = EventsChannels.ServerOrderRecievedChannel | |
- def __init__(self, game, fraction,unit_uid, active_uid, target): | |
+ def __init__(self, game, fraction, unit_uid, active_uid, target): | |
self.unit_uid = unit_uid | |
self.active_uid = active_uid | |
self.target = target | |
@@ -19,4 +20,3 @@ class ServerOrderRecievedEvent(Event): | |
def __repr__(self): | |
return f"SOR player {self.fraction} gave order: unit:{self.unit_uid} active:{self.active_uid} target:{self.target}" | |
- | |
diff --git a/multiplayer/network/ClientSocket.py b/multiplayer/network/ClientSocket.py | |
index 2fbfb38..0e402ef 100644 | |
--- a/multiplayer/network/ClientSocket.py | |
+++ b/multiplayer/network/ClientSocket.py | |
@@ -16,10 +16,8 @@ class ClientSocket: | |
self.next_order = 1 | |
self.orders_stored = {} | |
- | |
- | |
def connect(self): | |
- self.socket.connect((host,port)) | |
+ self.socket.connect((host, port)) | |
name = self.socket.recv(2048).decode("utf-8", "strict") | |
self.name = name | |
print(f"Connected as {self.name}") | |
@@ -28,25 +26,22 @@ class ClientSocket: | |
while True: | |
data = self.socket.recv(4096) | |
print("bytes actually recieved: ", sys.getsizeof(data)) | |
- e : ServerOrderIssuedEvent = pickle.loads(data) | |
+ e: ServerOrderIssuedEvent = pickle.loads(data) | |
assert isinstance(e, ServerOrderIssuedEvent) | |
if self.next_order != e.uid: | |
self.orders_stored[e.uid] = e | |
else: | |
- ClientOrderRecievedEvent(self.game, e.unit_uid, e.active_uid, e.target) | |
+ ClientOrderRecievedEvent( | |
+ self.game, e.unit_uid, e.active_uid, e.target) | |
self.next_order += 1 | |
while self.next_order in self.orders_stored: | |
e = self.orders_stored[self.next_order] | |
- ClientOrderRecievedEvent(e.unit_uid, e.active_uid, e.target) | |
+ ClientOrderRecievedEvent( | |
+ e.unit_uid, e.active_uid, e.target) | |
self.next_order += 1 | |
- | |
- def send(self, e : ClientOrderRecievedEvent): | |
+ def send(self, e: ClientOrderRecievedEvent): | |
e.game = None | |
data_string = pickle.dumps(e) | |
self.socket.send(data_string) | |
- | |
- | |
- | |
- | |
diff --git a/multiplayer/network/ServerSocket.py b/multiplayer/network/ServerSocket.py | |
index c4608a2..0a4ad33 100644 | |
--- a/multiplayer/network/ServerSocket.py | |
+++ b/multiplayer/network/ServerSocket.py | |
@@ -20,7 +20,6 @@ class ServerSocket: | |
self.free_fractions = list(fractions_for_players) | |
self.socket_fractions = {} | |
- | |
def listen(self): | |
print("listening.") | |
while True: | |
@@ -48,15 +47,15 @@ class ServerSocket: | |
self.active_clients.remove(sock) | |
self.free_fractions.append(self.socket_fractions[sock]) | |
- | |
def client_thread(self, clientsocket): | |
while True: | |
data = clientsocket.recv(4096) | |
print("bytes actually recieved: ", sys.getsizeof(data)) | |
e = pickle.loads(data) | |
assert isinstance(e, ClientOrderIssuedEvent) | |
- ServerOrderRecievedEvent(self.game, self.socket_fractions[clientsocket], | |
- e.unit_uid, e.active_uid, e.target) | |
- | |
- | |
- | |
+ ServerOrderRecievedEvent( | |
+ self.game, | |
+ self.socket_fractions[clientsocket], | |
+ e.unit_uid, | |
+ e.active_uid, | |
+ e.target) | |
diff --git a/multiplayer/network/config.py b/multiplayer/network/config.py | |
index 9b90026..af10c69 100644 | |
--- a/multiplayer/network/config.py | |
+++ b/multiplayer/network/config.py | |
@@ -1,3 +1,2 @@ | |
host = 'localhost' | |
port = 43210 | |
- | |
diff --git a/my_utils/named_enums.py b/my_utils/named_enums.py | |
index 86ae1d8..4c10bc1 100644 | |
--- a/my_utils/named_enums.py | |
+++ b/my_utils/named_enums.py | |
@@ -1,8 +1,9 @@ | |
from enum import Enum, auto | |
+ | |
class NameEnum(Enum): | |
def _generate_next_value_(name, start, count, last_values): | |
- return name | |
+ return name | |
def __repr__(self): | |
return self.name.lower() | |
@@ -12,7 +13,7 @@ class NameEnum(Enum): | |
@property | |
def tooltip_info(self): | |
- return {'name':self.name} | |
+ return {'name': self.name} | |
if __name__ == "__main__": | |
@@ -22,5 +23,4 @@ if __name__ == "__main__": | |
East = auto() | |
West = auto() | |
- | |
- print(list(Ordinal)) | |
\ No newline at end of file | |
+ print(list(Ordinal)) | |
diff --git a/my_utils/utils.py b/my_utils/utils.py | |
index 86e1d65..7e98a72 100644 | |
--- a/my_utils/utils.py | |
+++ b/my_utils/utils.py | |
@@ -1,21 +1,22 @@ | |
import collections | |
from typing import Union, Any, Iterable, Iterator, List | |
-import math | |
+import math | |
epsilon = 1e-4 | |
-def tractable_value(true_value, digits = 2): | |
+ | |
+def tractable_value(true_value, digits=2): | |
log10 = int(math.log10(true_value)) | |
base = 10 ** (log10 + 1 - digits) | |
return int(true_value // base * base) | |
-def kmb_number_display( value ): | |
- dividors = {1e9 : 'b', 1e6 : 'm', 1e3: 'k'} | |
+def kmb_number_display(value): | |
+ dividors = {1e9: 'b', 1e6: 'm', 1e3: 'k'} | |
for k, v in dividors.items(): | |
if value >= k: | |
- return f"{value / k:.1f}" + v | |
+ return f"{value / k:.1f}" + v | |
return str(value) | |
@@ -27,17 +28,19 @@ def clamp(n, minn, maxn): | |
else: | |
return n | |
+ | |
def flatten(l: Iterable[Union[Any, Iterable[Any]]]) -> List[Any]: | |
def gen(): | |
for el in l: | |
- if isinstance(el, collections.Iterable) and not isinstance(el, (str, bytes)): | |
+ if isinstance( | |
+ el, collections.Iterable) and not isinstance( | |
+ el, (str, bytes)): | |
yield from flatten(el) | |
else: | |
yield el | |
return list(gen()) | |
-import collections | |
class ReadOnlyDict(collections.Mapping): | |
@@ -55,4 +58,3 @@ class ReadOnlyDict(collections.Mapping): | |
def __str__(self): | |
return str(self._data) | |
- | |
diff --git a/single_player/Shop.py b/single_player/Shop.py | |
index 318c64d..57b53b3 100644 | |
--- a/single_player/Shop.py | |
+++ b/single_player/Shop.py | |
@@ -1,4 +1,10 @@ | |
from __future__ import annotations | |
+from my_utils.utils import tractable_value, kmb_number_display as kmb | |
+from game_objects.items import Inventory | |
+from cntent.items.QualityLevels import QualityLevels | |
+from cntent.items.blueprints.armor.body_armor import leather_outfit, pirate_jacket, cuirass, scalemail | |
+from cntent.items.blueprints.weapons.weapons import fancy_blueprints, std_blueprints | |
+from cntent.items.materials.materials import Stones, Metals, Leathers, Woods | |
import random | |
from game_objects.items.materials.MaterialTypes import MaterialTypes | |
from typing import TYPE_CHECKING, List, Dict | |
@@ -7,7 +13,10 @@ if TYPE_CHECKING: | |
from game_objects.items import Slot | |
-def generate_assortment(blueprints: List[Blueprint], materials: Dict[MaterialTypes:List[Material]], quality_levels: List[QualityLevel], n=100): | |
+def generate_assortment(blueprints: List[Blueprint], | |
+ materials: Dict[MaterialTypes:List[Material]], | |
+ quality_levels: List[QualityLevel], | |
+ n=100): | |
for bp in blueprints: | |
assert bp.material_type in materials | |
@@ -22,18 +31,17 @@ def generate_assortment(blueprints: List[Blueprint], materials: Dict[MaterialTyp | |
assortment.append(bp.to_item(material, quality)) | |
- return sorted(assortment, key=lambda x:x.price) | |
- | |
+ return sorted(assortment, key=lambda x: x.price) | |
-from cntent.items.materials.materials import Stones, Metals, Leathers, Woods | |
-from cntent.items.blueprints.weapons.weapons import fancy_blueprints, std_blueprints | |
-from cntent.items.blueprints.armor.body_armor import leather_outfit, pirate_jacket, cuirass, scalemail | |
-from cntent.items.QualityLevels import QualityLevels | |
all_armor = [leather_outfit, pirate_jacket, cuirass, scalemail] | |
all_blueprints = all_armor + std_blueprints + fancy_blueprints | |
mt = MaterialTypes | |
-all_materials = {mt.STONE: Stones.all, mt.METAL: Metals.all, mt.WOOD: Woods.all, mt.SKIN: Leathers.all} | |
+all_materials = { | |
+ mt.STONE: Stones.all, | |
+ mt.METAL: Metals.all, | |
+ mt.WOOD: Woods.all, | |
+ mt.SKIN: Leathers.all} | |
# itemz = generate_assortment(all_blueprints, all_materials, QualityLevels.all) | |
@@ -42,22 +50,24 @@ all_materials = {mt.STONE: Stones.all, mt.METAL: Metals.all, mt.WOOD: Woods.all, | |
# print(item, item.price) | |
- | |
# def total_value(items, mod): | |
# return sum([mod(i.value) for i in items]) | |
-from game_objects.items import Inventory | |
-from my_utils.utils import tractable_value, kmb_number_display as kmb | |
-def price_buy(orig_price, trust, baseline): | |
+def price_buy(orig_price, trust, baseline): | |
expensive_factor = orig_price / baseline | |
if expensive_factor < 1: | |
- factor = expensive_factor ** (4/3) | |
+ factor = expensive_factor ** (4 / 3) | |
else: | |
- factor = expensive_factor ** (3/4) | |
+ factor = expensive_factor ** (3 / 4) | |
- return tractable_value ( trust * orig_price * factor / expensive_factor , digits=3) | |
+ return tractable_value( | |
+ trust * | |
+ orig_price * | |
+ factor / | |
+ expensive_factor, | |
+ digits=3) | |
# return tractable_value ( trust * orig_price , digits=3) | |
@@ -70,13 +80,24 @@ def price_sell(orig_price, trust, baseline): | |
factor = expensive_factor ** (4 / 3) | |
# print(expensive_factor, factor) | |
- return tractable_value( 1 / trust * orig_price * factor / expensive_factor , digits=3) | |
+ return tractable_value( | |
+ 1 / | |
+ trust * | |
+ orig_price * | |
+ factor / | |
+ expensive_factor, | |
+ digits=3) | |
# return tractable_value( 1 / trust * orig_price , digits=3) | |
class Shop: | |
- def __init__(self, assortment, trust = 1, baseline = 500, customer: Character = None): | |
+ def __init__( | |
+ self, | |
+ assortment, | |
+ trust=1, | |
+ baseline=500, | |
+ customer: Character = None): | |
self.inventory = Inventory(len(assortment) * 2 + 50, None) | |
for item in assortment: | |
@@ -94,8 +115,13 @@ class Shop: | |
def display_inventory(self): | |
for item in self.inventory.all_items: | |
- print(item, kmb(item.price), kmb(self.price_low(item.price)), kmb(self.price_high(item.price))) | |
- | |
+ print( | |
+ item, kmb( | |
+ item.price), kmb( | |
+ self.price_low( | |
+ item.price)), kmb( | |
+ self.price_high( | |
+ item.price))) | |
def buy(self, inventory_slot: Slot): | |
assert inventory_slot in self.inventory | |
@@ -131,9 +157,14 @@ if __name__ == "__main__": | |
char = Character(demohero_basetype) | |
char.gold = 1e6 | |
- shop = Shop(generate_assortment(all_blueprints, all_materials, QualityLevels.all), 1, 500, customer=char) | |
+ shop = Shop( | |
+ generate_assortment( | |
+ all_blueprints, | |
+ all_materials, | |
+ QualityLevels.all), | |
+ 1, | |
+ 500, | |
+ customer=char) | |
shop.display_inventory() | |
print("testing") | |
- | |
- | |
diff --git a/tests/AI/conftest.py b/tests/AI/conftest.py | |
index 94b5f3a..2b2b44e 100644 | |
--- a/tests/AI/conftest.py | |
+++ b/tests/AI/conftest.py | |
@@ -9,7 +9,6 @@ from mechanics.actives import Cost | |
from game_objects.battlefield_objects import BattlefieldObject | |
- | |
@pytest.fixture() | |
def empty_simgame(): | |
bf = Battlefield(6, 6) | |
@@ -17,18 +16,16 @@ def empty_simgame(): | |
@pytest.fixture() | |
-def minigame(pirate, hero): | |
+def minigame(pirate, hero): | |
bf = Battlefield(6, 6) | |
_game = DreamGame(bf) | |
- _game.add_unit(hero, (2+2j), Faction.PLAYER) | |
+ _game.add_unit(hero, (2 + 2j), Faction.PLAYER) | |
_game.add_unit(pirate, (4 + 4j), Faction.ENEMY) | |
- | |
return _game | |
- | |
@pytest.fixture() | |
def sim_game(hero, pirate_band): | |
bf = Battlefield(8, 8) | |
@@ -46,50 +43,54 @@ def sim_game(hero, pirate_band): | |
return _game | |
+ | |
@pytest.fixture() | |
def walls_game(walls_dungeon, hero): | |
_game = DreamGame.start_dungeon(walls_dungeon, hero) | |
return _game | |
+ | |
@pytest.fixture() | |
def imba_ability(): | |
- imba_dmg_callback = lambda a, unit: unit.lose_health(99999, a.owner) | |
+ def imba_dmg_callback(a, unit): return unit.lose_health(99999, a.owner) | |
_imba_ability = Active(BattlefieldObject, | |
- [], | |
- Cost(readiness=0.1), | |
- callbacks=[imba_dmg_callback], | |
- tags=[ActiveTags.ATTACK], | |
+ [], | |
+ Cost(readiness=0.1), | |
+ callbacks=[imba_dmg_callback], | |
+ tags=[ActiveTags.ATTACK], | |
name="imba") | |
return _imba_ability | |
+ | |
@pytest.fixture() | |
def tiny_imba_ability(): | |
- imba_dmg_callback = lambda a, unit: unit.lose_health(9, a.owner) | |
+ def imba_dmg_callback(a, unit): return unit.lose_health(9, a.owner) | |
_imba_ability = Active(BattlefieldObject, | |
- [], | |
- Cost(readiness=0.1), | |
- callbacks=[imba_dmg_callback], | |
- tags=[ActiveTags.ATTACK], | |
+ [], | |
+ Cost(readiness=0.1), | |
+ callbacks=[imba_dmg_callback], | |
+ tags=[ActiveTags.ATTACK], | |
name="imba") | |
return _imba_ability | |
+ | |
@pytest.fixture() | |
def enabler(imba_ability): | |
- enabler_callback = lambda a, unit: unit.give_active(imba_ability) | |
+ def enabler_callback(a, unit): return unit.give_active(imba_ability) | |
_enabler = Active(BattlefieldObject, | |
- [], | |
- Cost(readiness=0.1), | |
- callbacks=[enabler_callback], | |
- tags=[ActiveTags.ATTACK], | |
- name="gives imba") | |
+ [], | |
+ Cost(readiness=0.1), | |
+ callbacks=[enabler_callback], | |
+ tags=[ActiveTags.ATTACK], | |
+ name="gives imba") | |
return _enabler | |
@@ -97,17 +98,16 @@ def enabler(imba_ability): | |
@pytest.fixture() | |
def increase_utility(minigame): | |
- minigame.utility = lambda : 0 | |
+ minigame.utility = lambda: 0 | |
def increase_utility(_, __): | |
- minigame.utility = lambda : 1e3 | |
- | |
+ minigame.utility = lambda: 1e3 | |
_imba_ability = Active(BattlefieldObject, | |
- [], | |
- Cost(readiness=0.1), | |
+ [], | |
+ Cost(readiness=0.1), | |
game=minigame, | |
- callbacks=[increase_utility], | |
+ callbacks=[increase_utility], | |
tags=[ActiveTags.ATTACK], | |
name="imba") | |
@@ -130,6 +130,3 @@ def take_punishment(minigame): | |
name="imba") | |
return _imba_ability | |
- | |
- | |
- | |
diff --git a/tests/AI/test_astar_AI.py b/tests/AI/test_astar_AI.py | |
index d501d36..b6d6dd8 100644 | |
--- a/tests/AI/test_astar_AI.py | |
+++ b/tests/AI/test_astar_AI.py | |
@@ -14,9 +14,8 @@ def test_returns_actions(minigame): | |
def test_locations_are_intact(minigame): | |
- | |
locations_initial = (minigame.bf.cells_to_objs, | |
- [{u:u.facing} for u in minigame.units]) | |
+ [{u: u.facing} for u in minigame.units]) | |
for i in range(3): | |
ai = AstarAI(minigame) | |
@@ -24,7 +23,7 @@ def test_locations_are_intact(minigame): | |
ai.decide_step(unit) | |
assert locations_initial == (minigame.bf.cells_to_objs, | |
- [{u:u.facing} for u in minigame.units]) | |
+ [{u: u.facing} for u in minigame.units]) | |
def test_chooses_imba_targets_enemy(minigame, imba_ability): | |
@@ -38,14 +37,14 @@ def test_chooses_imba_targets_enemy(minigame, imba_ability): | |
assert int(action.uid / 1e7) == imba_ability.uid | |
assert target.faction is not unit.faction | |
+ | |
@pytest.mark.skip(reason="not supported") | |
def test_uses_enabler_abilities(minigame, enabler): | |
- | |
ai = AstarAI(minigame) | |
unit = list(minigame.units)[0] | |
unit.give_active(enabler) | |
action, target = ai.decide_step(unit) | |
- assert int(action.uid / 1e7) == enabler.uid | |
\ No newline at end of file | |
+ assert int(action.uid / 1e7) == enabler.uid | |
diff --git a/tests/AI/test_broad_AI.py b/tests/AI/test_broad_AI.py | |
index fd97472..547ea10 100644 | |
--- a/tests/AI/test_broad_AI.py | |
+++ b/tests/AI/test_broad_AI.py | |
@@ -1,6 +1,6 @@ | |
from mechanics.AI import BroadAI | |
from mechanics.actives import Active | |
-from DreamGame import DreamGame | |
+from DreamGame import DreamGame | |
from mechanics.AI.SimGame import SimGame | |
from mechanics.factions import Faction | |
from game_objects.battlefield_objects import Unit | |
@@ -20,7 +20,7 @@ def test_locations_are_intact(minigame): | |
ai = BroadAI(minigame) | |
locations_initial = (minigame.bf.cells_to_objs, | |
- [{u:u.facing} for u in minigame.units]) | |
+ [{u: u.facing} for u in minigame.units]) | |
for u in minigame.units: | |
ai.decide_step(u) | |
@@ -31,36 +31,34 @@ def test_locations_are_intact(minigame): | |
def test_chooses_imba_targets_enemy(minigame, imba_ability, hero, pirate): | |
- | |
ai = BroadAI(minigame) | |
ingame_imba = hero.give_active(imba_ability) | |
action, target = ai.decide_step(hero) | |
- | |
- assert minigame.delta( (ingame_imba, pirate) ) > 0 | |
- assert minigame.delta( (ingame_imba, hero) ) < 0 | |
- | |
+ assert minigame.delta((ingame_imba, pirate)) > 0 | |
+ assert minigame.delta((ingame_imba, hero)) < 0 | |
assert action is ingame_imba | |
assert target.faction is not hero.faction | |
-def test_chooses_imba_targets_enemy_inverse(minigame, imba_ability, hero, pirate): | |
+ | |
+def test_chooses_imba_targets_enemy_inverse( | |
+ minigame, imba_ability, hero, pirate): | |
ai = BroadAI(minigame) | |
ingame_imba = pirate.give_active(imba_ability) | |
action, target = ai.decide_step(pirate) | |
- | |
assert minigame.delta((ingame_imba, hero)) > 0 | |
assert minigame.delta((ingame_imba, pirate)) < 0 | |
assert action is ingame_imba | |
assert target.faction is not pirate.faction | |
-def test_uses_enabler_abilities(minigame, enabler): | |
+def test_uses_enabler_abilities(minigame, enabler): | |
ai = BroadAI(minigame) | |
unit = list(minigame.units)[0] | |
@@ -71,8 +69,13 @@ def test_uses_enabler_abilities(minigame, enabler): | |
assert action is ingame_imba | |
+ | |
@pytest.mark.skip(reason="actions are rolled out and can seem harmless.") | |
-def test_no_friendly_fire(simple_battlefield, hero, mud_golem, pirate_basetype): | |
+def test_no_friendly_fire( | |
+ simple_battlefield, | |
+ hero, | |
+ mud_golem, | |
+ pirate_basetype): | |
_game = DreamGame(simple_battlefield) | |
_game.add_unit(mud_golem, 3 + 3j, Faction.ENEMY, 1j) | |
_game.add_unit(hero, 3 + 4j, Faction.PLAYER, 1 + 0j) | |
@@ -81,7 +84,6 @@ def test_no_friendly_fire(simple_battlefield, hero, mud_golem, pirate_basetype) | |
pirate2 = Unit(pirate_basetype) | |
pirate3 = Unit(pirate_basetype) | |
- | |
_game.add_unit(pirate1, 4 + 4j, Faction.ENEMY, -1 + 0j) | |
_game.add_unit(pirate2, 4 + 5j, Faction.ENEMY, -1 + 0j) | |
_game.add_unit(pirate3, 5 + 3j, Faction.ENEMY, 1 + 0j) | |
@@ -93,4 +95,4 @@ def test_no_friendly_fire(simple_battlefield, hero, mud_golem, pirate_basetype) | |
if isinstance(target, Unit): | |
if target.faction is active_unit.faction: | |
assert False | |
- active_unit.activate(active, target) | |
\ No newline at end of file | |
+ active_unit.activate(active, target) | |
diff --git a/tests/AI/test_brute_AI.py b/tests/AI/test_brute_AI.py | |
index 771e381..6a3634f 100644 | |
--- a/tests/AI/test_brute_AI.py | |
+++ b/tests/AI/test_brute_AI.py | |
@@ -1,3 +1,7 @@ | |
+import copy | |
+from battlefield.Facing import Facing | |
+from mechanics.actives import Active, ActiveTags | |
+from DreamGame import Faction | |
from mechanics.AI import BruteAI | |
from game_objects.battlefield_objects import Unit | |
import pytest | |
@@ -25,6 +29,7 @@ def test_basetype_gives_valid_actives(sim_game, pirate_basetype): | |
action, target = ai.decide_step(pirate) | |
assert isinstance(action, Active) | |
+ | |
def test_is_deterministic(minigame, hero): | |
actions = set() | |
@@ -37,10 +42,11 @@ def test_is_deterministic(minigame, hero): | |
assert 1 == len(actions) | |
+ | |
def test_locations_are_intact(minigame, hero, pirate): | |
locations_initial = (minigame.bf.cells_to_objs, | |
- [{u:u.facing} for u in minigame.units]) | |
+ [{u: u.facing} for u in minigame.units]) | |
for u in minigame.units: | |
ai = BruteAI(minigame) | |
@@ -49,8 +55,8 @@ def test_locations_are_intact(minigame, hero, pirate): | |
assert locations_initial == (minigame.bf.cells_to_objs, | |
[{u: u.facing} for u in minigame.units]) | |
-def test_chooses_imba_targets_enemy(minigame, imba_ability): | |
+def test_chooses_imba_targets_enemy(minigame, imba_ability): | |
ai = BruteAI(minigame) | |
unit = list(minigame.units)[0] | |
@@ -62,6 +68,8 @@ def test_chooses_imba_targets_enemy(minigame, imba_ability): | |
assert target.faction is not unit.faction | |
# @pytest.mark.skip(reason="non-deterministic ai does not guarantee this.") | |
+ | |
+ | |
def test_no_suicide(sim_game): | |
for i in range(10): | |
@@ -81,12 +89,13 @@ def test_no_friendly_fire(sim_game, hero, pirate): | |
choices = sim_game.get_all_choices(unit) | |
actives = [c[0] for c in choices] | |
attack_actives = [a for a in actives if ActiveTags.ATTACK in a.tags] | |
- if len(attack_actives)>0: | |
+ if len(attack_actives) > 0: | |
assert action not in attack_actives | |
+ | |
def test_with_obstacle(sim_game, hero, pirate, obstacle): | |
- sim_game.add_obstacle(obstacle, 5+5j) | |
+ sim_game.add_obstacle(obstacle, 5 + 5j) | |
for unit in sim_game.units: | |
ai = BruteAI(sim_game) | |
choices = sim_game.get_all_choices(unit) | |
@@ -94,6 +103,7 @@ def test_with_obstacle(sim_game, hero, pirate, obstacle): | |
real_actives = [sim_game.find_active(a) for a in actives] | |
# no exceptions thrown | |
+ | |
def test_hits_take_prio(empty_simgame, hero, pirate, no_chances): | |
ai = BruteAI(empty_simgame) | |
@@ -111,13 +121,14 @@ def test_hits_take_prio(empty_simgame, hero, pirate, no_chances): | |
choices = empty_simgame.get_all_choices(unit) | |
actives = [c[0] for c in choices] | |
attack_actives = [a for a in actives if ActiveTags.ATTACK in a.tags] | |
- if len(attack_actives)>0: | |
+ if len(attack_actives) > 0: | |
# delta = game.delta( (action, target) ) | |
# attack_active = attack_actives[0] | |
# atarget = game.get_possible_targets(attack_active)[0] | |
# attack_delta = game.delta( (attack_active, atarget) ) | |
assert action in attack_actives | |
+ | |
def test_own_turn_first(minigame, hero, pirate): | |
hero.facing = 1j | |
@@ -134,31 +145,33 @@ def test_moves_closer(minigame, hero, pirate): | |
hero.facing = 1j | |
pirate.facing = -1j | |
- distance_before = bf.distance(hero,pirate) | |
+ distance_before = bf.distance(hero, pirate) | |
ai = BruteAI(minigame) | |
active, target = ai.decide_step(pirate, epsilon=0) | |
pirate.activate(active, target) | |
- distance_after = bf.distance(hero,pirate) | |
+ distance_after = bf.distance(hero, pirate) | |
assert distance_after < distance_before | |
+ | |
def test_moves_closer_too(minigame, hero, pirate): | |
bf = minigame.bf | |
hero.facing = 1j | |
pirate.facing = -1j | |
- distance_before = bf.distance(hero,pirate) | |
+ distance_before = bf.distance(hero, pirate) | |
ai = BruteAI(minigame) | |
active, target = ai.decide_step(hero, epsilon=0) | |
hero.activate(active, target) | |
- distance_after = bf.distance(hero,pirate) | |
+ distance_after = bf.distance(hero, pirate) | |
assert distance_after < distance_before | |
+ | |
def chooses_rewarding_action(take_drugs, minigame, hero): | |
hero.give_active(take_drugs) | |
@@ -178,19 +191,13 @@ def avoids_punishing_action(take_punishment, minigame, hero): | |
assert int(action.uid / 1e7) != take_punishment.uid | |
-from DreamGame import Faction | |
-from mechanics.actives import Active, ActiveTags | |
-from battlefield.Facing import Facing | |
-import copy | |
- | |
- | |
def test_attacks(empty_game, hero, pirate, no_chances): | |
g = empty_game | |
pirates = [copy.deepcopy(pirate) for _ in range(3)] | |
pirate2, pirate3, pirate4 = pirates | |
- g.add_unit(hero, (3+3j), Faction.PLAYER) | |
+ g.add_unit(hero, (3 + 3j), Faction.PLAYER) | |
g.add_unit(pirate, (3 + 4j), Faction.ENEMY, facing=Facing.NORTH) | |
g.add_unit(pirate2, (4 + 3j), Faction.ENEMY, facing=Facing.WEST) | |
@@ -216,12 +223,3 @@ def test_attacks(empty_game, hero, pirate, no_chances): | |
a, t = ai.decide_step(pirate4) | |
assert ActiveTags.ATTACK in a.tags | |
assert t is hero | |
- | |
- | |
- | |
- | |
- | |
- | |
- | |
- | |
- | |
diff --git a/tests/AI/test_fake_sim.py b/tests/AI/test_fake_sim.py | |
index 1fa0315..238694f 100644 | |
--- a/tests/AI/test_fake_sim.py | |
+++ b/tests/AI/test_fake_sim.py | |
@@ -20,5 +20,3 @@ def test_results_match(minigame, hero): | |
assert len(mismatches) == 0 | |
assert count_simulated > 0 | |
- | |
- | |
diff --git a/tests/AI/test_few_turns.py b/tests/AI/test_few_turns.py | |
index 86c736d..fa94147 100644 | |
--- a/tests/AI/test_few_turns.py | |
+++ b/tests/AI/test_few_turns.py | |
@@ -9,7 +9,6 @@ def test_few_turns(minigame, hero, pirate): | |
for _ in range(10): | |
minigame.add_unit(copy.deepcopy(pirate), 2 + 2j, Faction.ENEMY) | |
- MovementEvent(hero, 2+2j) | |
+ MovementEvent(hero, 2 + 2j) | |
- | |
- minigame.loop(turns=20) | |
\ No newline at end of file | |
+ minigame.loop(turns=20) | |
diff --git a/tests/AI/test_pathfinder.py b/tests/AI/test_pathfinder.py | |
index 274f5bf..fef6c76 100644 | |
--- a/tests/AI/test_pathfinder.py | |
+++ b/tests/AI/test_pathfinder.py | |
@@ -1,11 +1,11 @@ | |
from mechanics.AI.pathfinding.astar_pathfinder import StarSearch | |
import pytest | |
+ | |
@pytest.mark.timeout(50) | |
def test_finds_path(walls_game, hero): | |
search = StarSearch(walls_game, hero) | |
- goal = 11+0j | |
+ goal = 11 + 0j | |
path = search.path_to(goal) | |
assert path is not None | |
- assert 1.5*len(path) >= walls_game.bf.distance(hero, goal) | |
- | |
+ assert 1.5 * len(path) >= walls_game.bf.distance(hero, goal) | |
diff --git a/tests/AI/test_random_AI.py b/tests/AI/test_random_AI.py | |
index af0710c..c67010e 100644 | |
--- a/tests/AI/test_random_AI.py | |
+++ b/tests/AI/test_random_AI.py | |
@@ -1,6 +1,7 @@ | |
from mechanics.AI import RandomAI | |
from mechanics.actives import Active | |
+ | |
def test_returns_actions(minigame): | |
randomAI = RandomAI(minigame) | |
@@ -9,6 +10,7 @@ def test_returns_actions(minigame): | |
action, target = randomAI.decide_step(unit) | |
assert isinstance(action, Active) | |
+ | |
def test_returns_targets_for_targeted_actions(minigame): | |
randomAI = RandomAI(minigame) | |
@@ -46,5 +48,6 @@ def test_returns_different_targets(minigame): | |
action, target = randomAI.decide_step(unit) | |
targets.setdefault(action, set()).add(target) | |
- count_diff_targets = [1 for multiple in targets.values() if len(multiple) > 1] | |
- assert len(count_diff_targets) > 0 | |
\ No newline at end of file | |
+ count_diff_targets = [ | |
+ 1 for multiple in targets.values() if len(multiple) > 1] | |
+ assert len(count_diff_targets) > 0 | |
diff --git a/tests/AI/test_ranged_weapon.py b/tests/AI/test_ranged_weapon.py | |
index 74e545d..bd8aba7 100644 | |
--- a/tests/AI/test_ranged_weapon.py | |
+++ b/tests/AI/test_ranged_weapon.py | |
@@ -1,11 +1,12 @@ | |
from cntent.monsters.tel_razi.monsters import tel_razi_scrub | |
from mechanics.AI import BruteAI | |
+ | |
def test_shoots(empty_simgame, hero): | |
shooter = tel_razi_scrub.create(empty_simgame) | |
- empty_simgame.add_unit(shooter, 2+2j, faction="Clan A", facing=1j) | |
- empty_simgame.add_unit(hero, 2+4j, faction="Clan B") | |
+ empty_simgame.add_unit(shooter, 2 + 2j, faction="Clan A", facing=1j) | |
+ empty_simgame.add_unit(hero, 2 + 4j, faction="Clan B") | |
ai = BruteAI(empty_simgame) | |
active, target = ai.decide_step(shooter) | |
@@ -14,40 +15,43 @@ def test_shoots(empty_simgame, hero): | |
assert target is hero | |
+ | |
def test_can_shoot(empty_simgame, hero): | |
assert empty_simgame.bf.game is empty_simgame | |
shooter = tel_razi_scrub.create(empty_simgame) | |
- empty_simgame.add_unit(shooter, 2+2j, facing=1j) | |
- empty_simgame.add_unit(hero, 2+4j) | |
+ empty_simgame.add_unit(shooter, 2 + 2j, facing=1j) | |
+ empty_simgame.add_unit(hero, 2 + 4j) | |
from mechanics.actives import ActiveTags | |
- ranged_actives = [a for a in shooter.actives if ActiveTags.RANGED in a.tags] | |
+ ranged_actives = [ | |
+ a for a in shooter.actives if ActiveTags.RANGED in a.tags] | |
ranged_active = ranged_actives[0] | |
assert hero in empty_simgame.get_possible_targets(ranged_active) | |
+ | |
def test_cant_shoot_facing(empty_simgame, hero): | |
shooter = tel_razi_scrub.create(empty_simgame) | |
- empty_simgame.add_unit(shooter, 2+2j, facing=-1j) | |
- empty_simgame.add_unit(hero, 2+4j) | |
+ empty_simgame.add_unit(shooter, 2 + 2j, facing=-1j) | |
+ empty_simgame.add_unit(hero, 2 + 4j) | |
from mechanics.actives import ActiveTags | |
- ranged_actives = [a for a in shooter.actives if ActiveTags.RANGED in a.tags] | |
+ ranged_actives = [ | |
+ a for a in shooter.actives if ActiveTags.RANGED in a.tags] | |
ranged_active = ranged_actives[0] | |
assert hero not in empty_simgame.get_possible_targets(ranged_active) | |
+ | |
def test_has_shoot_active(empty_simgame): | |
shooter = tel_razi_scrub.create(empty_simgame) | |
- empty_simgame.add_unit(shooter, 2+2j) | |
+ empty_simgame.add_unit(shooter, 2 + 2j) | |
from mechanics.actives import ActiveTags | |
- ranged_actives = [ a for a in shooter.actives if ActiveTags.RANGED in a.tags] | |
+ ranged_actives = [ | |
+ a for a in shooter.actives if ActiveTags.RANGED in a.tags] | |
assert ranged_actives | |
- | |
- | |
- | |
diff --git a/tests/AI/test_simulation.py b/tests/AI/test_simulation.py | |
index 1f5e632..31873a7 100644 | |
--- a/tests/AI/test_simulation.py | |
+++ b/tests/AI/test_simulation.py | |
@@ -8,12 +8,12 @@ def test_simulation_units_dont_rly_die(minigame): | |
sim = minigame.simulation() | |
assert sim is not minigame | |
- sim_unit_count_before = len( sim.units ) | |
+ sim_unit_count_before = len(sim.units) | |
units = list(sim.units) | |
units[0].health -= 99999 | |
- sim_unit_count_after = len( sim.units ) | |
+ sim_unit_count_after = len(sim.units) | |
assert not units[0].alive | |
assert sim_unit_count_after < sim_unit_count_before | |
@@ -35,12 +35,11 @@ def test_simulation_units_dont_rly_move(minigame): | |
assert sim_location_before != sim_unit.cell | |
- | |
- | |
real_location_after = real_unit.cell | |
assert real_location_before == real_location_after | |
+ | |
def test_events_work(minigame): | |
real_unit = list(minigame.units)[0] | |
real_location_before = real_unit.cell | |
@@ -78,12 +77,12 @@ def test_triggers_present_in_sim(minigame, hero): | |
hero.health -= 99999 | |
assert hero.alive | |
- | |
sim = minigame.simulation() | |
sim_hero = sim.find_unit(hero) | |
sim_hero.health -= 99999 | |
assert sim_hero.alive | |
+ | |
def test_sim_persists(minigame): | |
sim = minigame.simulation() | |
assert sim is not minigame | |
@@ -106,10 +105,3 @@ def test_hp_transfered(minigame, hero): | |
assert hero.health == sim_hero.health | |
assert hero.mana == sim_hero.mana | |
assert hero.stamina == sim_hero.stamina | |
- | |
- | |
- | |
- | |
- | |
- | |
- | |
diff --git a/tests/AI/test_utility.py b/tests/AI/test_utility.py | |
index dc6dacb..dcf2704 100644 | |
--- a/tests/AI/test_utility.py | |
+++ b/tests/AI/test_utility.py | |
@@ -4,16 +4,19 @@ import pytest | |
utility = SimGame.unit_utility | |
+ | |
def test_unit_util_positive(hero, pirate): | |
assert utility(hero) > 0 | |
assert utility(pirate) > 0 | |
+ | |
def test_more_hp_is_better(minigame, hero): | |
utility_initial = minigame.utility(hero.faction) | |
hero.max_health += 100 | |
assert utility_initial < minigame.utility(hero.faction) | |
+ | |
def test_invertion(minigame, hero): | |
pirate = [unit for unit in minigame.units if unit is not hero][0] | |
@@ -21,12 +24,14 @@ def test_invertion(minigame, hero): | |
hero.max_health += 100 | |
assert utility_initial > minigame.utility(pirate.faction) | |
+ | |
def test_less_hp_is_worse(minigame, hero): | |
utility_initial = minigame.utility(hero.faction) | |
hero.max_health -= 100 | |
assert utility_initial > minigame.utility(hero.faction) | |
+ | |
def test_double_inversion(minigame, hero): | |
pirate = [unit for unit in minigame.units if unit is not hero][0] | |
@@ -34,18 +39,21 @@ def test_double_inversion(minigame, hero): | |
hero.max_health -= 100 | |
assert utility_initial < minigame.utility(pirate.faction) | |
+ | |
@pytest.mark.skip(reason="not supported") | |
def test_more_mana_is_better(minigame, hero): | |
utility_initial = minigame.utility(hero.faction) | |
hero.max_mana += 100 | |
assert utility_initial < minigame.utility(hero.faction) | |
+ | |
@pytest.mark.skip(reason="not supported") | |
def test_more_stamina_is_better(minigame, hero): | |
utility_initial = minigame.utility(hero.faction) | |
hero.max_stamina += 100 | |
assert utility_initial < minigame.utility(hero.faction) | |
+ | |
@pytest.mark.skip(reason="not supported") | |
def test_more_readiness_is_better(minigame, hero): | |
utility_initial = minigame.utility(hero.faction) | |
@@ -53,8 +61,6 @@ def test_more_readiness_is_better(minigame, hero): | |
assert utility_initial < minigame.utility(hero.faction) | |
- | |
- | |
def test_hurt_negative_delta(minigame, hero, no_chances, imba_ability): | |
old_abilities = set(hero.actives) | |
@@ -62,20 +68,25 @@ def test_hurt_negative_delta(minigame, hero, no_chances, imba_ability): | |
hero.give_active(imba_ability) | |
hero.readiness += 10 | |
- ability = list(set(hero.actives)-old_abilities)[0] | |
+ ability = list(set(hero.actives) - old_abilities)[0] | |
choice = ability, hero | |
delta = minigame.delta(choice) | |
assert delta < 0 | |
-def test_small_hurt_negative_delta(minigame, hero, no_chances, tiny_imba_ability): | |
+ | |
+def test_small_hurt_negative_delta( | |
+ minigame, | |
+ hero, | |
+ no_chances, | |
+ tiny_imba_ability): | |
old_abilities = set(hero.actives) | |
hero.give_active(tiny_imba_ability) | |
hero.readiness += 10 | |
- ability = list(set(hero.actives)-old_abilities)[0] | |
+ ability = list(set(hero.actives) - old_abilities)[0] | |
choice = ability, hero | |
delta = minigame.delta(choice) | |
@@ -92,11 +103,16 @@ def test_pirates_cry_too(minigame, pirate, no_chances, imba_ability): | |
ability = list(set(pirate.actives) - old_abilities)[0] | |
choice = ability, pirate | |
- delta = minigame.delta( choice ) | |
+ delta = minigame.delta(choice) | |
assert delta < 0 | |
-def test_pirates_cry_too_a_little(minigame, pirate, no_chances, tiny_imba_ability): | |
+ | |
+def test_pirates_cry_too_a_little( | |
+ minigame, | |
+ pirate, | |
+ no_chances, | |
+ tiny_imba_ability): | |
old_abilities = set(pirate.actives) | |
@@ -109,6 +125,7 @@ def test_pirates_cry_too_a_little(minigame, pirate, no_chances, tiny_imba_abilit | |
assert delta < 0 | |
+ | |
@pytest.mark.skip(reason="not supported") | |
def test_positions_can_go_out_of_utility(minigame): | |
n_checked = 0 | |
@@ -124,9 +141,4 @@ def test_positions_can_go_out_of_utility(minigame): | |
delta = minigame.delta(c) | |
assert delta == 0 | |
- | |
assert n_checked > 0 | |
- | |
- | |
- | |
- | |
diff --git a/tests/_conceptual/deep_copy.py b/tests/_conceptual/deep_copy.py | |
index e66917c..1bfb9a9 100644 | |
--- a/tests/_conceptual/deep_copy.py | |
+++ b/tests/_conceptual/deep_copy.py | |
@@ -1,5 +1,9 @@ | |
+import copy | |
+ | |
+ | |
class Unit: | |
counter = 0 | |
+ | |
def __init__(self, friend, enemy): | |
Unit.counter += 1 | |
self.friend = friend | |
@@ -16,7 +20,8 @@ a = Unit(None, None) | |
b = Unit(a, None) | |
c = Unit(b, a) | |
-rl = RelationshipDB([a,b,c]) | |
+rl = RelationshipDB([a, b, c]) | |
+ | |
def my_printout(relationsDB): | |
x = relationsDB.units[0] | |
@@ -30,8 +35,7 @@ def my_printout(relationsDB): | |
my_printout(rl) | |
-import copy | |
rl_2 = copy.deepcopy(rl) | |
-my_printout(rl_2) | |
\ No newline at end of file | |
+my_printout(rl_2) | |
diff --git a/tests/_conceptual/lru_cache.py b/tests/_conceptual/lru_cache.py | |
index 1dde96e..662ce82 100644 | |
--- a/tests/_conceptual/lru_cache.py | |
+++ b/tests/_conceptual/lru_cache.py | |
@@ -2,8 +2,11 @@ | |
This script tests the savings from using lru cache. | |
""" | |
+from collections import namedtuple | |
+import random | |
import functools | |
+ | |
class MyVision: | |
counter = 0 | |
@@ -11,10 +14,9 @@ class MyVision: | |
def my_dummy_calc(self, x, y, z): | |
if x.x > y.x: | |
return self.my_dummy_calc(y, x, z) | |
- self.counter+=1 | |
+ self.counter += 1 | |
return x | |
-from collections import namedtuple | |
quack = namedtuple("quack", "x y") | |
@@ -23,9 +25,8 @@ m = MyVision() | |
quacks = list() | |
for i in range(8): | |
for j in range(8): | |
- quacks.append( quack(i,j) ) | |
+ quacks.append(quack(i, j)) | |
-import random | |
results = [] | |
@@ -42,9 +43,6 @@ while len(results) < 500_000: | |
q2 = random.choice(quacks) | |
q3 = random.choice(quacks) | |
- results.append(m.my_dummy_calc(q1,q2,q3)) | |
+ results.append(m.my_dummy_calc(q1, q2, q3)) | |
print(m.counter) | |
- | |
- | |
- | |
diff --git a/tests/_conceptual/mem_used.py b/tests/_conceptual/mem_used.py | |
index 9615d96..f3f6f1b 100644 | |
--- a/tests/_conceptual/mem_used.py | |
+++ b/tests/_conceptual/mem_used.py | |
@@ -4,6 +4,7 @@ from cntent.dungeons.demo_dungeon_walls import walls_dungeon | |
from game_objects.battlefield_objects import Unit | |
import sys | |
+ | |
def get_size(obj, seen=None): | |
"""Recursively finds size of objects""" | |
size = sys.getsizeof(obj) | |
@@ -24,6 +25,7 @@ def get_size(obj, seen=None): | |
size += sum([get_size(i, seen) for i in obj]) | |
return size | |
+ | |
game = DreamGame.start_dungeon(walls_dungeon, Unit(demohero_basetype)) | |
sims = [] | |
@@ -33,6 +35,6 @@ for i in range(1000): | |
print(len(sims)) | |
-print( get_size(sims) ) | |
+print(get_size(sims)) | |
-print( get_size(game) ) | |
+print(get_size(game)) | |
diff --git a/tests/actives/test_cooldown.py b/tests/actives/test_cooldown.py | |
index a7ca96d..a50f7b2 100644 | |
--- a/tests/actives/test_cooldown.py | |
+++ b/tests/actives/test_cooldown.py | |
@@ -3,7 +3,7 @@ from mechanics.events import TimePassedEvent | |
def test_wait(empty_game, hero): | |
- empty_game.add_unit(hero, 1+1j) | |
+ empty_game.add_unit(hero, 1 + 1j) | |
wait_active.cooldown = 1 | |
units_active = hero.give_active(wait_active) | |
@@ -15,7 +15,3 @@ def test_wait(empty_game, hero): | |
TimePassedEvent(empty_game, 0.501) | |
assert hero.activate(units_active) # no longer on cooldown | |
- | |
- | |
- | |
- | |
diff --git a/tests/actives/test_std_misc.py b/tests/actives/test_std_misc.py | |
index d279c69..e00cbcc 100644 | |
--- a/tests/actives/test_std_misc.py | |
+++ b/tests/actives/test_std_misc.py | |
@@ -2,7 +2,7 @@ from cntent.actives.std.std_misc import onguard_active, rest_active, wait_active | |
def test_wait(empty_game, hero): | |
- empty_game.add_unit(hero, 1+1j) | |
+ empty_game.add_unit(hero, 1 + 1j) | |
units_active = hero.give_active(wait_active) | |
@@ -13,7 +13,7 @@ def test_wait(empty_game, hero): | |
def test_rest(empty_game, hero): | |
- empty_game.add_unit(hero, 1+1j) | |
+ empty_game.add_unit(hero, 1 + 1j) | |
units_active = hero.give_active(rest_active) | |
@@ -32,11 +32,11 @@ def test_rest(empty_game, hero): | |
assert rdy_before > hero.readiness | |
- #resting restores mana and stamina | |
+ # resting restores mana and stamina | |
assert mana_before < hero.mana | |
assert stamina_before < hero.stamina | |
- #resting weakens temporarily | |
+ # resting weakens temporarily | |
assert attk_before > hero.melee_precision | |
assert def_before > hero.melee_evasion | |
@@ -46,8 +46,9 @@ def test_rest(empty_game, hero): | |
assert attk_before == hero.melee_precision | |
assert def_before == hero.melee_evasion | |
+ | |
def test_rest_debuff_temporary(empty_game, hero): | |
- empty_game.add_unit(hero, 1+1j) | |
+ empty_game.add_unit(hero, 1 + 1j) | |
units_active = hero.give_active(rest_active) | |
@@ -56,15 +57,15 @@ def test_rest_debuff_temporary(empty_game, hero): | |
hero.activate(units_active) | |
- | |
empty_game.turns_manager.pass_time(50) | |
# after some time attk and def back to normal | |
assert attk_before == hero.melee_precision | |
assert def_before == hero.melee_evasion | |
+ | |
def test_onguard(empty_game, hero): | |
- empty_game.add_unit(hero, 1+1j) | |
+ empty_game.add_unit(hero, 1 + 1j) | |
units_active = hero.give_active(onguard_active) | |
@@ -81,7 +82,3 @@ def test_onguard(empty_game, hero): | |
# after some time attk and def back to normal | |
assert attk_before == hero.melee_precision | |
assert def_before == hero.melee_evasion | |
- | |
- | |
- | |
- | |
diff --git a/tests/attributes/abilities/test_abilities.py b/tests/attributes/abilities/test_abilities.py | |
index d9e8d28..8fec998 100644 | |
--- a/tests/attributes/abilities/test_abilities.py | |
+++ b/tests/attributes/abilities/test_abilities.py | |
@@ -5,10 +5,12 @@ from game_objects.battlefield_objects import CharAttributes, get_attrib_by_enum | |
from mechanics.buffs import Ability | |
-@pytest.fixture(params = set(CharAttributes) - {CharAttributes.ARMOR, CharAttributes.RESISTANCES}) | |
+@pytest.fixture(params=set(CharAttributes) - | |
+ {CharAttributes.ARMOR, CharAttributes.RESISTANCES}) | |
def attrib(request): | |
yield request.param | |
+ | |
@pytest.fixture() | |
def inner_power(attrib): | |
bonus = Attribute(2, 100, 0) | |
@@ -17,6 +19,7 @@ def inner_power(attrib): | |
yield inner_power | |
+ | |
@pytest.fixture() | |
def bonus_str(): | |
bonus = Attribute(0, 0, 50) | |
@@ -26,7 +29,6 @@ def bonus_str(): | |
yield abil_hp | |
- | |
def test_str_helps(hero, inner_power, attrib): | |
attrib_before = get_attrib_by_enum(hero, attrib) | |
@@ -38,6 +40,7 @@ def test_str_helps(hero, inner_power, attrib): | |
assert attrib_after > attrib_before | |
+ | |
def test_rescale(hero, bonus_str): | |
hp_before = hero.health | |
@@ -46,6 +49,7 @@ def test_rescale(hero, bonus_str): | |
assert hp_after > hp_before | |
+ | |
def test_multiplier(hero, pirate): | |
bonus = Attribute(0, 50, 0) | |
@@ -62,6 +66,7 @@ def test_multiplier(hero, pirate): | |
assert delta_hero > delta_pirate | |
+ | |
def test_bonus(hero, pirate): | |
bonus = Attribute(0, 0, 50) | |
@@ -80,5 +85,3 @@ def test_bonus(hero, pirate): | |
delta_pirate = pirate.health - hp_before | |
assert delta_hero == delta_pirate | |
- | |
- | |
diff --git a/tests/attributes/test_attribute.py b/tests/attributes/test_attribute.py | |
index 0415505..4b30133 100644 | |
--- a/tests/attributes/test_attribute.py | |
+++ b/tests/attributes/test_attribute.py | |
@@ -1,5 +1,6 @@ | |
from game_objects.attributes import Attribute | |
+ | |
def test_summation(): | |
attrib1 = Attribute(100, 100, 100) | |
attrib2 = Attribute(10, 20, 30) | |
@@ -10,9 +11,10 @@ def test_summation(): | |
assert attrib3.multiplier == attrib1.multiplier + attrib2.multiplier | |
assert attrib3.bonus == attrib1.bonus + attrib2.bonus | |
+ | |
def test_value(): | |
attrib1 = Attribute(100, 100, 100) | |
attrib2 = Attribute(100, 150, 200) | |
assert attrib1.value() == 200 | |
- assert attrib2.value() == 350 | |
\ No newline at end of file | |
+ assert attrib2.value() == 350 | |
diff --git a/tests/attributes/test_bonus_armor.py b/tests/attributes/test_bonus_armor.py | |
index a678147..8996b4c 100644 | |
--- a/tests/attributes/test_bonus_armor.py | |
+++ b/tests/attributes/test_bonus_armor.py | |
@@ -15,6 +15,7 @@ def total_armor(): | |
yield _total_armor | |
+ | |
@pytest.fixture() | |
def broken_armor(): | |
armor = Armor(-10) | |
@@ -23,9 +24,10 @@ def broken_armor(): | |
yield _total_armor | |
+ | |
@pytest.fixture() | |
def special_armor(): | |
- armor = Armor(armor_dict={DamageTypes.ACID:100}) | |
+ armor = Armor(armor_dict={DamageTypes.ACID: 100}) | |
bonus = Bonus({CharAttributes.ARMOR: armor}) | |
_special_armor = Ability(bonus) | |
@@ -35,14 +37,14 @@ def special_armor(): | |
def test_right_type_works(game_hvsp, hero, special_armor): | |
hp_before_dmg = hero.health | |
dmg = Damage(50, DamageTypes.ACID) | |
- DamageEvent( dmg, hero) | |
+ DamageEvent(dmg, hero) | |
dealt_no_armor = hp_before_dmg - hero.health | |
hp_before_dmg = hero.health | |
hero.add_ability(special_armor) | |
- DamageEvent( dmg, hero) | |
+ DamageEvent(dmg, hero) | |
dealt_armor = hp_before_dmg - hero.health | |
assert dealt_no_armor > dealt_armor | |
@@ -51,18 +53,19 @@ def test_right_type_works(game_hvsp, hero, special_armor): | |
def test_wrong_type_useless(game_hvsp, hero, special_armor): | |
hp_before_dmg = hero.health | |
dmg = Damage(50, DamageTypes.FIRE) | |
- DamageEvent( dmg, hero) | |
+ DamageEvent(dmg, hero) | |
dealt_no_armor = hp_before_dmg - hero.health | |
hp_before_dmg = hero.health | |
hero.add_ability(special_armor) | |
- DamageEvent( dmg, hero) | |
+ DamageEvent(dmg, hero) | |
dealt_armor = hp_before_dmg - hero.health | |
assert dealt_no_armor == dealt_armor | |
+ | |
def test_armor_reduces_damage(game_hvsp, hero, total_armor): | |
hp_before_dmg = hero.health | |
@@ -113,4 +116,4 @@ def test_negative_armor(game_hvsp, hero, broken_armor): | |
DamageEvent(dmg, hero) | |
dealt_reduced_armor = hp_before_dmg - hero.health | |
- assert dealt_reduced_armor > dealt_armor | |
\ No newline at end of file | |
+ assert dealt_reduced_armor > dealt_armor | |
diff --git a/tests/attributes/test_bonus_resists.py b/tests/attributes/test_bonus_resists.py | |
index 8159fb6..0816f45 100644 | |
--- a/tests/attributes/test_bonus_resists.py | |
+++ b/tests/attributes/test_bonus_resists.py | |
@@ -10,24 +10,26 @@ from mechanics.buffs import Ability | |
@pytest.fixture() | |
def total_resist(): | |
def _(): | |
- resists = Resistances({dt:0.5 for dt in DamageTypes}) | |
+ resists = Resistances({dt: 0.5 for dt in DamageTypes}) | |
bonus = Bonus({CharAttributes.RESISTANCES: resists}) | |
_total_resist = Ability(bonus) | |
return _total_resist | |
return _ | |
+ | |
@pytest.fixture() | |
def special_resist(): | |
- resist = Resistances({DamageTypes.ACID:100}) | |
+ resist = Resistances({DamageTypes.ACID: 100}) | |
bonus = Bonus({CharAttributes.RESISTANCES: resist}) | |
_special_resist = Ability(bonus) | |
return _special_resist | |
+ | |
@pytest.fixture() | |
def vulnerability(): | |
- resists = Resistances({dt:-0.5 for dt in DamageTypes}) | |
+ resists = Resistances({dt: -0.5 for dt in DamageTypes}) | |
bonus = Bonus({CharAttributes.RESISTANCES: resists}) | |
_vulnerability = Ability(bonus) | |
@@ -65,6 +67,7 @@ def test_wrong_type_useless(game_hvsp, hero, special_resist): | |
assert dealt_no_armor == dealt_armor | |
+ | |
def test_armor_reduces_damage(game_hvsp, hero, total_resist): | |
hp_before_dmg = hero.health | |
@@ -114,4 +117,4 @@ def test_negative_armor(game_hvsp, hero, vulnerability): | |
DamageEvent(dmg, hero) | |
dealt_reduced_armor = hp_before_dmg - hero.health | |
- assert dealt_reduced_armor > dealt_armor | |
\ No newline at end of file | |
+ assert dealt_reduced_armor > dealt_armor | |
diff --git a/tests/battlefield/aoe/test_neighbours.py b/tests/battlefield/aoe/test_neighbours.py | |
index 51bfbfc..6b52a1a 100644 | |
--- a/tests/battlefield/aoe/test_neighbours.py | |
+++ b/tests/battlefield/aoe/test_neighbours.py | |
@@ -1,23 +1,28 @@ | |
from battlefield.Cell import Cell | |
import pytest | |
+ | |
def test_neighbours(): | |
- c = Cell(5,5) | |
+ c = Cell(5, 5) | |
assert len(Cell.get_neighbours(c, distance=0)) == 1 | |
assert len(Cell.get_neighbours(c, distance=1)) == 5 | |
assert len(Cell.get_neighbours(c, distance=1.5)) == 9 | |
assert len(Cell.get_neighbours(c, distance=2)) == 13 | |
-@pytest.mark.parametrize("w, h", [(1,1), (1,5), (5,2), (33,1), (16,17), (4,4)]) | |
-def test_borders(w,h): | |
- c = Cell(2,2) | |
- all_valid_cells = Cell.get_neighbours(c, distance=500, w=w,h=h) | |
- assert len(all_valid_cells) == w*h | |
- min_x, max_x = min([c.x for c in all_valid_cells]), max([c.x for c in all_valid_cells]) | |
- min_y, max_y = min([c.y for c in all_valid_cells]), max([c.y for c in all_valid_cells]) | |
+@pytest.mark.parametrize( | |
+ "w, h", [(1, 1), (1, 5), (5, 2), (33, 1), (16, 17), (4, 4)]) | |
+def test_borders(w, h): | |
+ c = Cell(2, 2) | |
+ | |
+ all_valid_cells = Cell.get_neighbours(c, distance=500, w=w, h=h) | |
+ assert len(all_valid_cells) == w * h | |
+ min_x, max_x = min([c.x for c in all_valid_cells]), max( | |
+ [c.x for c in all_valid_cells]) | |
+ min_y, max_y = min([c.y for c in all_valid_cells]), max( | |
+ [c.y for c in all_valid_cells]) | |
assert min_x == min_y == 0 | |
- assert max_x == w-1 | |
- assert max_y == h-1 | |
\ No newline at end of file | |
+ assert max_x == w - 1 | |
+ assert max_y == h - 1 | |
diff --git a/tests/battlefield/obstacles/test_can_be_destroyed.py b/tests/battlefield/obstacles/test_can_be_destroyed.py | |
index 5506aad..d4bebe8 100644 | |
--- a/tests/battlefield/obstacles/test_can_be_destroyed.py | |
+++ b/tests/battlefield/obstacles/test_can_be_destroyed.py | |
@@ -5,6 +5,7 @@ from mechanics.events import DamageEvent | |
from mechanics.combat.Attack import Attack | |
import pytest | |
+ | |
@pytest.fixture() | |
def obstacle(game_hvsp): | |
obstacle = Obstacle("dummy", 500, game=game_hvsp) | |
@@ -12,7 +13,6 @@ def obstacle(game_hvsp): | |
return obstacle | |
- | |
def test_can_take_damage(obstacle): | |
health_before = obstacle.health | |
dmg = Damage(50, DamageTypes.SONIC) | |
@@ -31,7 +31,6 @@ def test_can_be_destroyed(obstacle, empty_game): | |
assert obstacle not in empty_game.obstacles | |
- | |
def test_can_be_attacked(obstacle, hero, no_chances): | |
health_before = obstacle.health | |
diff --git a/tests/battlefield/obstacles/test_impassable.py b/tests/battlefield/obstacles/test_impassable.py | |
index 99e7a2e..5e4d504 100644 | |
--- a/tests/battlefield/obstacles/test_impassable.py | |
+++ b/tests/battlefield/obstacles/test_impassable.py | |
@@ -1,3 +1,5 @@ | |
+from exceptions import PydolonsError | |
+import pytest | |
from mechanics.events import MovementEvent | |
from battlefield import Cell | |
from game_objects.battlefield_objects import Wall | |
@@ -5,20 +7,20 @@ from game_objects.battlefield_objects import Wall | |
def test_impassable_event(obstacle, hero, empty_game): | |
- empty_game.add_unit(hero, 1+1j) | |
- empty_game.bf.set_new_walls( [Wall(1+2j)] ) | |
+ empty_game.add_unit(hero, 1 + 1j) | |
+ empty_game.bf.set_new_walls([Wall(1 + 2j)]) | |
- MovementEvent(hero, 1+2j) | |
+ MovementEvent(hero, 1 + 2j) | |
- assert hero.cell == 1+1j | |
+ assert hero.cell == 1 + 1j | |
-def test_impassible_action(obstacle, hero, empty_game): | |
+def test_impassible_action(obstacle, hero, empty_game): | |
- empty_game.add_unit(hero, 1+1j, facing=1j) | |
- empty_game.bf.set_new_walls( [Wall(1+2j)] ) | |
+ empty_game.add_unit(hero, 1 + 1j, facing=1j) | |
+ empty_game.bf.set_new_walls([Wall(1 + 2j)]) | |
- tgt_cell = Cell(1,2) | |
+ tgt_cell = Cell(1, 2) | |
valid_action = None | |
for a in hero.movement_actives: | |
if a.check_target(tgt_cell): | |
@@ -27,18 +29,14 @@ def test_impassible_action(obstacle, hero, empty_game): | |
assert valid_action is None | |
-import pytest | |
-from exceptions import PydolonsError | |
- | |
def test_impassible_order(obstacle, hero, empty_game): | |
+ empty_game.add_unit(hero, 1 + 1j, facing=1j) | |
+ empty_game.bf.set_new_walls([Wall(1 + 2j)]) | |
- empty_game.add_unit(hero, 1+1j, facing=1j) | |
- empty_game.bf.set_new_walls( [Wall(1+2j)] ) | |
- | |
- tgt_cell = Cell(1,2) | |
+ tgt_cell = Cell(1, 2) | |
with pytest.raises(PydolonsError): | |
empty_game.order_move(hero, tgt_cell) | |
- assert hero.cell == 1+1j | |
\ No newline at end of file | |
+ assert hero.cell == 1 + 1j | |
diff --git a/tests/battlefield/pushing/test_push.py b/tests/battlefield/pushing/test_push.py | |
index 20d63c7..048daa5 100644 | |
--- a/tests/battlefield/pushing/test_push.py | |
+++ b/tests/battlefield/pushing/test_push.py | |
@@ -1,31 +1,32 @@ | |
+import pytest | |
+from exceptions import PydolonsError | |
+import copy | |
from mechanics.events import MovementEvent, PushEvent | |
+ | |
def test_no_push(empty_game, hero, pirate, monkeypatch): | |
- empty_game.add_unit(hero, 1+1j) | |
- empty_game.add_unit(pirate, 2+2j) | |
+ empty_game.add_unit(hero, 1 + 1j) | |
+ empty_game.add_unit(pirate, 2 + 2j) | |
called = [] | |
+ | |
def fake_resolved(*args): | |
called.append("zip") | |
monkeypatch.setattr(PushEvent, "resolve", fake_resolved) | |
- MovementEvent(hero, 2+2j) | |
+ MovementEvent(hero, 2 + 2j) | |
assert not called | |
- assert hero.cell == 2+2j | |
+ assert hero.cell == 2 + 2j | |
-import pytest | |
-import copy | |
-from exceptions import PydolonsError | |
def test_push(empty_game, hero, pirate, monkeypatch): | |
- empty_game.add_unit(hero, 1+1j) | |
- | |
- empty_game.add_unit(copy.copy(pirate), 2+2j) | |
- empty_game.add_unit(copy.copy(pirate), 2+2j) | |
- empty_game.add_unit(copy.copy(pirate), 2+2j) | |
+ empty_game.add_unit(hero, 1 + 1j) | |
+ empty_game.add_unit(copy.copy(pirate), 2 + 2j) | |
+ empty_game.add_unit(copy.copy(pirate), 2 + 2j) | |
+ empty_game.add_unit(copy.copy(pirate), 2 + 2j) | |
def fake_resolved(*args): | |
raise PydolonsError("bla") | |
@@ -33,20 +34,14 @@ def test_push(empty_game, hero, pirate, monkeypatch): | |
monkeypatch.setattr(PushEvent, "resolve", fake_resolved) | |
with pytest.raises(PydolonsError): | |
- MovementEvent(hero, 2+2j) | |
+ MovementEvent(hero, 2 + 2j) | |
def test_mass_push(empty_game, hero, pirate): | |
- empty_game.add_unit(hero, 1+1j) | |
+ empty_game.add_unit(hero, 1 + 1j) | |
for _ in range(10): | |
- empty_game.add_unit(copy.copy(pirate), 2+2j) | |
+ empty_game.add_unit(copy.copy(pirate), 2 + 2j) | |
- MovementEvent(hero, 2+2j) | |
+ MovementEvent(hero, 2 + 2j) | |
assert len(empty_game.bf.get_objects_at(2 + 2j)) == 3 | |
- | |
- | |
- | |
- | |
- | |
- | |
diff --git a/tests/battlefield/test_battlefield.py b/tests/battlefield/test_battlefield.py | |
index 3d0d654..78dc507 100644 | |
--- a/tests/battlefield/test_battlefield.py | |
+++ b/tests/battlefield/test_battlefield.py | |
@@ -1,7 +1,10 @@ | |
+import pytest | |
+from battlefield import Battlefield | |
from battlefield.Battlefield import Cell | |
from battlefield.Facing import Facing | |
from game_objects.battlefield_objects import Wall | |
+ | |
def test_movement_preserves_facing(game_hvsp, hero): | |
for facing in [Facing.EAST, Facing.NORTH, Facing.WEST, Facing.SOUTH]: | |
@@ -14,20 +17,23 @@ def test_units_dont_block_movement(game_hvsp, hero): | |
location_before = Cell(3, 4) | |
hero.cell = location_before | |
- assert game_hvsp.bf.cells_to_objs[Cell(4, 4)] # expecting a pirate from conftest | |
+ # expecting a pirate from conftest | |
+ assert game_hvsp.bf.cells_to_objs[Cell(4, 4)] | |
game_hvsp.order_move(hero, Cell(4, 4)) | |
assert location_before != hero.cell | |
+ | |
def test_walls_block_movement(empty_game, hero): | |
location_before = Cell(3, 4) | |
hero.cell = location_before | |
empty_game.add_unit(hero) | |
- empty_game.bf.set_new_walls( [Wall(4+4j)] ) | |
+ empty_game.bf.set_new_walls([Wall(4 + 4j)]) | |
empty_game.order_move(hero, Cell(4, 4)) | |
assert location_before == hero.cell | |
+ | |
def test_distance_unit_to_point(game_hvsp): | |
battlefield8 = game_hvsp.bf | |
@@ -36,22 +42,21 @@ def test_distance_unit_to_point(game_hvsp): | |
pirate = battlefield8.get_objects_at(Cell(4, 4))[0] | |
d1 = battlefield8.distance(pirate, Cell(1, 4)) | |
- d2 = battlefield8.distance(pirate, Cell(4, 1)) | |
+ d2 = battlefield8.distance(pirate, Cell(4, 1)) | |
assert d1 == d2 | |
assert battlefield8.distance(pirate, Cell(4, 4)) == 0 | |
-import pytest | |
-from battlefield import Battlefield | |
@pytest.fixture() | |
def battlefield8(): | |
- yield Battlefield(8,8) | |
+ yield Battlefield(8, 8) | |
+ | |
def test_neighbouring_cells(battlefield8): | |
battlefield8 = Battlefield(8, 8) | |
- #corners have 2 adjecent cells | |
+ # corners have 2 adjecent cells | |
assert len(battlefield8.neighbours_exclude_center(Cell(0, 0))) == 2 | |
assert len(battlefield8.neighbours_exclude_center(Cell(0, 7))) == 2 | |
assert len(battlefield8.neighbours_exclude_center(Cell(7, 0))) == 2 | |
@@ -77,19 +82,41 @@ def test_neighbouring_cells(battlefield8): | |
def test_cells_within_dist(battlefield8): | |
assert len(battlefield8.get_cells_within_dist(Cell(4, 4), distance=1)) == 5 | |
- assert len(battlefield8.get_cells_within_dist(Cell(4, 4), distance=1.5)) == 9 | |
- assert len(battlefield8.get_cells_within_dist(Cell(4, 4), distance=2)) == 13 | |
- assert len(battlefield8.get_cells_within_dist(Cell(4, 4), distance=2.5)) == 21 | |
- assert len(battlefield8.get_cells_within_dist(Cell(4, 4), distance=2.99)) == 25 | |
- assert len(battlefield8.get_cells_within_dist(Cell(4, 4), distance=3)) == 29 | |
- | |
- | |
- | |
+ assert len( | |
+ battlefield8.get_cells_within_dist( | |
+ Cell( | |
+ 4, | |
+ 4), | |
+ distance=1.5)) == 9 | |
+ assert len( | |
+ battlefield8.get_cells_within_dist( | |
+ Cell( | |
+ 4, | |
+ 4), | |
+ distance=2)) == 13 | |
+ assert len( | |
+ battlefield8.get_cells_within_dist( | |
+ Cell( | |
+ 4, | |
+ 4), | |
+ distance=2.5)) == 21 | |
+ assert len( | |
+ battlefield8.get_cells_within_dist( | |
+ Cell( | |
+ 4, | |
+ 4), | |
+ distance=2.99)) == 25 | |
+ assert len( | |
+ battlefield8.get_cells_within_dist( | |
+ Cell( | |
+ 4, | |
+ 4), | |
+ distance=3)) == 29 | |
def test_distance_calc(battlefield8): | |
- p1 = Cell(1,1) | |
- p2 = Cell(1,2) | |
+ p1 = Cell(1, 1) | |
+ p2 = Cell(1, 2) | |
assert battlefield8.distance(p1, p2) == 1 | |
@@ -104,10 +131,7 @@ def test_distance_calc(battlefield8): | |
assert 1 < battlefield8.distance(p1, p2) < 2 | |
- | |
def test_cells_eq(): | |
cell1 = Cell(1, 1) | |
cell2 = Cell(1, 1) | |
assert cell1 == cell2 | |
- | |
- | |
diff --git a/tests/battlefield/test_cell.py b/tests/battlefield/test_cell.py | |
index 22108ca..6d527d7 100644 | |
--- a/tests/battlefield/test_cell.py | |
+++ b/tests/battlefield/test_cell.py | |
@@ -1,9 +1,11 @@ | |
from battlefield import Cell | |
+ | |
class Foo: | |
def __init__(self): | |
pass | |
+ | |
def test_cell(): | |
a = Cell(1, 2) | |
b = Cell(2, 3) | |
@@ -12,8 +14,8 @@ def test_cell(): | |
f.x = 1 | |
f.y = 2 | |
- assert (a == None) == False | |
+ assert (a is None) == False | |
assert (a == f) == False | |
assert (a == b) == False | |
- assert (a == c) == True | |
- assert (a == a) == True | |
+ assert (a == c) | |
+ assert (a == a) | |
diff --git a/tests/battlefield/test_cell_angles.py b/tests/battlefield/test_cell_angles.py | |
index f703e58..ac37cc6 100644 | |
--- a/tests/battlefield/test_cell_angles.py | |
+++ b/tests/battlefield/test_cell_angles.py | |
@@ -1,21 +1,24 @@ | |
from battlefield import Cell | |
import pytest | |
-@pytest.mark.parametrize('vec', [1+0j, 1j, 1e9j, 1e-12 + 1e-12j]) | |
+ | |
+@pytest.mark.parametrize('vec', [1 + 0j, 1j, 1e9j, 1e-12 + 1e-12j]) | |
def test_zero_to_self(vec): | |
assert Cell.angle_between(vec, vec)[0] == 0 | |
+ | |
@pytest.mark.parametrize('vectors_ccw', | |
- [ (-1j, 1+0j, False), | |
- (-1j, 1-0j, False), | |
- (-1j, 1 - 2j, False), | |
- (-1j, -1+0j, True), | |
- (-1j, -1-0j, True)]) | |
+ [(-1j, 1 + 0j, False), | |
+ (-1j, 1 - 0j, False), | |
+ (-1j, 1 - 2j, False), | |
+ (-1j, -1 + 0j, True), | |
+ (-1j, -1 - 0j, True)]) | |
def test_ccw_cw(vectors_ccw): | |
v1, v2, ccw_bool = vectors_ccw | |
assert Cell.angle_between(v1, v2)[1] is ccw_bool | |
+ | |
def test_angles(): | |
q1 = 1 - 1j | |
q2 = -1 - 1j | |
@@ -46,4 +49,4 @@ def test_angles(): | |
assert Cell.angle_between(q2, q4)[0] == 180 | |
assert Cell.angle_between(q3, q2) < (90, False) | |
- assert Cell.angle_between(q1, q4) < (90, False) | |
\ No newline at end of file | |
+ assert Cell.angle_between(q1, q4) < (90, False) | |
diff --git a/tests/battlefield/test_cell_float.py b/tests/battlefield/test_cell_float.py | |
index 90a616c..a0174b1 100644 | |
--- a/tests/battlefield/test_cell_float.py | |
+++ b/tests/battlefield/test_cell_float.py | |
@@ -1,9 +1,11 @@ | |
from battlefield import Cell | |
+ | |
class Foo: | |
def __init__(self): | |
pass | |
+ | |
def test_cell(): | |
a = Cell(1.5, 2.0) | |
b = Cell(2.5, 3.0) | |
@@ -12,8 +14,8 @@ def test_cell(): | |
f.x = 1.5 | |
f.y = 2.0 | |
- assert (a == None) == False | |
+ assert (a is None) == False | |
assert (a == f) == False | |
assert (a == b) == False | |
- assert (a == c) == True | |
- assert (a == a) == True | |
+ assert (a == c) | |
+ assert (a == a) | |
diff --git a/tests/battlefield/visibility/test_blind_backstab.py b/tests/battlefield/visibility/test_blind_backstab.py | |
index e5216d1..dd7e3c7 100644 | |
--- a/tests/battlefield/visibility/test_blind_backstab.py | |
+++ b/tests/battlefield/visibility/test_blind_backstab.py | |
@@ -2,11 +2,11 @@ from mechanics.events import AttackEvent | |
from battlefield.Cell import Cell | |
from battlefield.Facing import Facing | |
-def test_backstab(empty_game, hero, pirate): | |
- empty_game.add_unit(hero, Cell(1,1)) | |
- empty_game.add_unit(pirate, Cell(1,2)) | |
+def test_backstab(empty_game, hero, pirate): | |
+ empty_game.add_unit(hero, Cell(1, 1)) | |
+ empty_game.add_unit(pirate, Cell(1, 2)) | |
hero.facing = Facing.SOUTH | |
pirate.facing = Facing.SOUTH | |
@@ -25,4 +25,3 @@ def test_backstab(empty_game, hero, pirate): | |
ae = AttackEvent(pirate, hero) | |
assert ae.is_backstab | |
assert not ae.is_blind | |
- | |
diff --git a/tests/battlefield/visibility/test_blocks.py b/tests/battlefield/visibility/test_blocks.py | |
index 840f6a0..938fda8 100644 | |
--- a/tests/battlefield/visibility/test_blocks.py | |
+++ b/tests/battlefield/visibility/test_blocks.py | |
@@ -6,14 +6,14 @@ from battlefield.Facing import Facing | |
def test_dead_units_dont_block(empty_game, hero, pirate): | |
hero.prc_base += 100 | |
- empty_game.add_unit(hero, Cell(1,1), facing=Facing.SOUTH) | |
+ empty_game.add_unit(hero, Cell(1, 1), facing=Facing.SOUTH) | |
vision = empty_game.vision | |
free_vision = vision.std_seen_cells(hero) | |
pirate.size = 9 | |
- empty_game.add_unit(pirate, Cell(1,2)) | |
+ empty_game.add_unit(pirate, Cell(1, 2)) | |
blocked_vision = vision.std_seen_cells(hero) | |
assert blocked_vision != free_vision | |
@@ -28,10 +28,10 @@ def test_blocks(game_hvsp): | |
vision = game_hvsp.vision | |
- blocks = vision.blocks(looking_from=Cell(1,1), | |
- looking_to=Cell(1,4), | |
- obstacle=Cell(1,2)) | |
- assert blocks == True | |
+ blocks = vision.blocks(looking_from=Cell(1, 1), | |
+ looking_to=Cell(1, 4), | |
+ obstacle=Cell(1, 2)) | |
+ assert blocks | |
blocks = vision.blocks(looking_from=Cell(1, 1), | |
looking_to=Cell(1, 2), | |
@@ -41,12 +41,12 @@ def test_blocks(game_hvsp): | |
blocks = vision.blocks(looking_from=Cell(1, 1), | |
looking_to=Cell(2, 7), | |
obstacle=Cell(1, 2)) | |
- assert blocks == True | |
+ assert blocks | |
blocks = vision.blocks(looking_from=Cell(1, 1), | |
looking_to=Cell(2, 7), | |
obstacle=Cell(1, 3)) | |
- assert blocks == True | |
+ assert blocks | |
def test_symmetry(game_hvsp): | |
@@ -56,14 +56,16 @@ def test_symmetry(game_hvsp): | |
cells = [] | |
for x in range(4): | |
for y in range(4): | |
- cells.append(Cell(x,y)) | |
+ cells.append(Cell(x, y)) | |
for cell_from in cells: | |
for cell_to in cells: | |
if cell_to == cell_from: | |
continue | |
for obstacle in cells: | |
- result = vision.blocks(cell_from, cell_to, obstacle) == vision.blocks(cell_to, cell_from, obstacle) | |
+ result = vision.blocks( | |
+ cell_from, cell_to, obstacle) == vision.blocks( | |
+ cell_to, cell_from, obstacle) | |
if not result: | |
print(cell_from, cell_to, obstacle) | |
assert result | |
@@ -74,26 +76,19 @@ def test_visibility(game_hvsp, hero, pirate): | |
vision = game_hvsp.vision | |
hero.prc_base += 100 | |
- hero.cell = Cell(1,1) | |
+ hero.cell = Cell(1, 1) | |
hero.facing = Facing.SOUTH | |
- | |
cells_seen = vision.std_seen_cells(hero) | |
assert Cell(1, 4) in cells_seen | |
assert Cell(1, 5) in cells_seen | |
assert Cell(5, 1) in cells_seen | |
- | |
- game_hvsp.add_unit(pirate, cell=1+2j) | |
+ game_hvsp.add_unit(pirate, cell=1 + 2j) | |
pirate.size = 9 | |
cells_seen = vision.std_seen_cells(hero) | |
- assert Cell(1,5) not in cells_seen | |
- assert Cell(5,1) in cells_seen | |
+ assert Cell(1, 5) not in cells_seen | |
+ assert Cell(5, 1) in cells_seen | |
assert Cell(1, 4) not in cells_seen | |
- | |
- | |
- | |
- | |
- | |
diff --git a/tests/battlefield/visibility/test_visibility.py b/tests/battlefield/visibility/test_visibility.py | |
index 52643c0..068e2cb 100644 | |
--- a/tests/battlefield/visibility/test_visibility.py | |
+++ b/tests/battlefield/visibility/test_visibility.py | |
@@ -5,6 +5,8 @@ import pytest | |
f = Facing | |
+ | |
+ | |
@pytest.fixture(params=[f.NORTH, f.EAST, f.SOUTH, f.WEST]) | |
def var_facing(request) -> complex: | |
return request.param | |
@@ -12,7 +14,7 @@ def var_facing(request) -> complex: | |
@pytest.mark.parametrize('prc', [6, 10, 12, 17, 23, 29, 53, 113]) | |
def test_symmetric(huge_game, hero, prc, var_facing): | |
- hero_c_coords = 30+30j | |
+ hero_c_coords = 30 + 30j | |
huge_game.add_unit(hero, hero_c_coords, facing=var_facing) | |
hero.prc_base.base = prc | |
@@ -36,38 +38,37 @@ def test_symmetric(huge_game, hero, prc, var_facing): | |
def test_visibility(game_hvsp, hero): | |
- game_hvsp.add_unit(hero, cell=Cell(1,1), facing=Facing.SOUTH) | |
+ game_hvsp.add_unit(hero, cell=Cell(1, 1), facing=Facing.SOUTH) | |
cells_seen = game_hvsp.vision.std_seen_cells(hero) | |
- assert Cell(0,0) not in cells_seen | |
- assert Cell(7,7) not in cells_seen | |
- assert Cell(7,0) not in cells_seen | |
- assert Cell(0,7) not in cells_seen | |
+ assert Cell(0, 0) not in cells_seen | |
+ assert Cell(7, 7) not in cells_seen | |
+ assert Cell(7, 0) not in cells_seen | |
+ assert Cell(0, 7) not in cells_seen | |
- assert Cell(1,1) in cells_seen | |
- cell = Cell(1,int(1+hero.sight_range)) | |
+ assert Cell(1, 1) in cells_seen | |
+ cell = Cell(1, int(1 + hero.sight_range)) | |
print(cells_seen) | |
assert cell in cells_seen | |
- cell = Cell(1+int(hero.sight_range),1) | |
+ cell = Cell(1 + int(hero.sight_range), 1) | |
assert cell not in cells_seen | |
def test_borders(game_hvsp, hero): | |
- | |
hero.facing = Facing.SOUTH | |
- hero.cell = Cell(1,1) | |
+ hero.cell = Cell(1, 1) | |
vision = game_hvsp.vision | |
cells_seen_before = vision.std_seen_cells(hero) | |
- | |
- hero.cell = Cell(7,7) | |
+ hero.cell = Cell(7, 7) | |
cells_seen_after = vision.std_seen_cells(hero) | |
assert len(cells_seen_after) < len(cells_seen_before) | |
- assert Cell(8,8) not in cells_seen_after | |
+ assert Cell(8, 8) not in cells_seen_after | |
+ | |
def test_direction_same_number(hero_only_game, hero): | |
@@ -77,15 +78,8 @@ def test_direction_same_number(hero_only_game, hero): | |
hero.cell = Cell(4, 4) | |
cells_seen_before = vision.std_seen_cells(hero) | |
- | |
hero.facing = Facing.NORTH | |
cells_seen_after = vision.std_seen_cells(hero) | |
assert len(cells_seen_after) == len(cells_seen_before) | |
assert cells_seen_before != cells_seen_after | |
- | |
- | |
- | |
- | |
- | |
- | |
diff --git a/tests/battlefield/visibility/test_walls_diag_block.py b/tests/battlefield/visibility/test_walls_diag_block.py | |
index cf7fa74..8845d92 100644 | |
--- a/tests/battlefield/visibility/test_walls_diag_block.py | |
+++ b/tests/battlefield/visibility/test_walls_diag_block.py | |
@@ -1,3 +1,4 @@ | |
+from game_objects.battlefield_objects import Wall | |
from battlefield.Vision import Vision | |
from battlefield.Facing import Facing | |
from battlefield.Cell import Cell | |
@@ -8,7 +9,6 @@ def test_units_no_diag_block(hero, empty_game, pirate_band): | |
empty_game.add_unit(hero, Cell(1, 1)) | |
hero.facing = Facing.SOUTH | |
- | |
p1 = pirate_band[0] | |
p2 = pirate_band[1] | |
empty_game.add_unit(p1, Cell(1, 2)) | |
@@ -18,7 +18,6 @@ def test_units_no_diag_block(hero, empty_game, pirate_band): | |
assert Cell(2, 2) in cells_seen | |
-from game_objects.battlefield_objects import Wall | |
def test_walls_diag_block(hero, empty_game, steel_wall): | |
@@ -32,4 +31,4 @@ def test_walls_diag_block(hero, empty_game, steel_wall): | |
empty_game.bf.set_new_walls([Wall(Cell(1, 2)), Wall(Cell(2, 1))]) | |
cells_seen = empty_game.vision.std_seen_cells(hero) | |
- assert Cell(2, 2) not in cells_seen | |
\ No newline at end of file | |
+ assert Cell(2, 2) not in cells_seen | |
diff --git a/tests/character/conftest.py b/tests/character/conftest.py | |
index 0157bed..7bf964a 100644 | |
--- a/tests/character/conftest.py | |
+++ b/tests/character/conftest.py | |
@@ -2,7 +2,8 @@ import pytest | |
from character.Character import Character | |
from cntent.base_types import pirate_basetype | |
+ | |
@pytest.fixture() | |
def char(): | |
c = Character(pirate_basetype) | |
- return c | |
\ No newline at end of file | |
+ return c | |
diff --git a/tests/character/perks/test_everymans.py b/tests/character/perks/test_everymans.py | |
index 03cda33..5fefd6f 100644 | |
--- a/tests/character/perks/test_everymans.py | |
+++ b/tests/character/perks/test_everymans.py | |
@@ -1,5 +1,7 @@ | |
+import copy | |
from character.perks.everymans_perks.everymans_perk_tree import everymans_perks | |
+ | |
def test_cost_grows(): | |
ep = everymans_perks() | |
@@ -29,7 +31,6 @@ def test_gives_abilities(): | |
assert len(ep.all_abils) == 1 | |
- | |
str_perk.current_level += 1 | |
assert len(ep.all_abils) == 1 | |
@@ -38,7 +39,6 @@ def test_gives_abilities(): | |
assert len(ep.all_abils) == 2 | |
-import copy | |
def test_gives_bonuses(hero): | |
ep = everymans_perks() | |
@@ -62,26 +62,24 @@ def test_gives_bonuses(hero): | |
assert hero2.str > hero.str | |
+ | |
def test_works_on_character(char): | |
ep = char.perk_trees[0] | |
str_perk = ep.accessible_perks()[0] | |
str_before = char.unit.str | |
- str_perk.current_level +=3 | |
+ str_perk.current_level += 3 | |
assert char.unit.str > str_before | |
+ | |
def test_stable_on_character(char): | |
ep = char.perk_trees[0] | |
str_perk = ep.accessible_perks()[0] | |
- str_perk.current_level +=3 | |
+ str_perk.current_level += 3 | |
str_before = char.unit.str | |
assert char.unit.str == str_before | |
- | |
- | |
- | |
- | |
diff --git a/tests/character/test_items_preserved.py b/tests/character/test_items_preserved.py | |
index de2223b..fc394b7 100644 | |
--- a/tests/character/test_items_preserved.py | |
+++ b/tests/character/test_items_preserved.py | |
@@ -2,7 +2,6 @@ from cntent.items.std.std_items import sword_cheap | |
from cntent.items.std.potions import minor_healing_potion | |
- | |
def test_inventory(char): | |
unit = char.unit | |
@@ -11,10 +10,11 @@ def test_inventory(char): | |
new_unit = char.unit | |
assert minor_healing_potion in new_unit.inventory.all_items | |
+ | |
def test_equipment(char): | |
unit = char.unit | |
unit.equipment.equip_item(sword_cheap) | |
new_unit = char.unit | |
- assert sword_cheap in new_unit.equipment.all_items | |
\ No newline at end of file | |
+ assert sword_cheap in new_unit.equipment.all_items | |
diff --git a/tests/combat/test_actions.py b/tests/combat/test_actions.py | |
index aafc779..b223489 100644 | |
--- a/tests/combat/test_actions.py | |
+++ b/tests/combat/test_actions.py | |
@@ -3,6 +3,7 @@ from battlefield.Facing import Facing | |
from exceptions.PydolonsError import PydolonsError | |
import pytest | |
+ | |
def test_move(game_hvsp, hero): | |
initial_location = hero.cell | |
@@ -12,6 +13,7 @@ def test_move(game_hvsp, hero): | |
assert initial_location != hero.cell | |
assert target_location == hero.cell | |
+ | |
def test_facing_no_problem(game_hvsp, hero): | |
initial_location = hero.cell | |
@@ -35,7 +37,7 @@ def test_can_make_multiple_steps(game_hvsp, hero): | |
hero.facing = Facing.NORTH | |
target_location = Cell(0, 6) | |
- hero.readiness=1.09 | |
+ hero.readiness = 1.09 | |
try: | |
for _ in range(20): | |
game_hvsp.order_move(hero, target_location) | |
@@ -46,6 +48,7 @@ def test_can_make_multiple_steps(game_hvsp, hero): | |
assert initial_location != hero.cell | |
assert target_location == hero.cell | |
+ | |
def test_can_use_diag_step(game_hvsp, hero): | |
initial_location = hero.cell | |
hero.facing = Facing.SOUTH | |
@@ -57,6 +60,7 @@ def test_can_use_diag_step(game_hvsp, hero): | |
assert initial_location != hero.cell | |
assert target_location == hero.cell | |
+ | |
def test_go_and_hit(game_hvsp, hero): | |
""" | |
Hero goes to the pirate and kicks pirate. | |
@@ -73,18 +77,13 @@ def test_go_and_hit(game_hvsp, hero): | |
game_hvsp.order_move(hero, step) | |
hero.readiness = 1 | |
- | |
- | |
while the_enemy_pirate.health > 0: | |
game_hvsp.order_attack(hero, pirate_location) | |
hero.readiness = 1 | |
- | |
game_hvsp.order_move(hero, pirate_location) | |
except Exception as e: | |
print(e) | |
assert False | |
assert pirate_location == hero.cell | |
- | |
- | |
diff --git a/tests/combat/test_active.py b/tests/combat/test_active.py | |
index 74e3a74..1808373 100644 | |
--- a/tests/combat/test_active.py | |
+++ b/tests/combat/test_active.py | |
@@ -4,10 +4,10 @@ from cntent.actives.std.std_melee_attack import attack_cell_active, attack_unit_ | |
from game_objects.battlefield_objects import Unit | |
-#TODO program and test that actives are unique. Use factory. | |
+# TODO program and test that actives are unique. Use factory. | |
def test_attack_cell(pirate_basetype, no_chances): | |
- bf = Battlefield(3,3) | |
+ bf = Battlefield(3, 3) | |
game = DreamGame(bf) | |
unit1 = Unit(pirate_basetype) | |
@@ -26,20 +26,19 @@ def test_attack_cell(pirate_basetype, no_chances): | |
assert unit2.health < hp_before | |
+ | |
def test_attack_unit(pirate_basetype, no_chances): | |
- bf = Battlefield(3,3) | |
+ bf = Battlefield(3, 3) | |
game = DreamGame(bf) | |
# monkeypatch.setattr(game, 'unit_died', lambda x: None) | |
unit1 = Unit(pirate_basetype) | |
unit2 = Unit(pirate_basetype) | |
- | |
loc1 = Cell(1, 1) | |
loc2 = Cell(1, 2) | |
game.add_unit(unit1, loc1, -1j) | |
game.add_unit(unit2, loc2, -1j) | |
- | |
hp_before = unit2.health | |
attack_unit_active.checker._conditions = [] | |
@@ -47,6 +46,3 @@ def test_attack_unit(pirate_basetype, no_chances): | |
unit1.activate(active_cpy, unit2) | |
assert unit2.health < hp_before | |
- | |
- | |
- | |
diff --git a/tests/combat/test_armor.py b/tests/combat/test_armor.py | |
index c17bcb0..7dd24cf 100644 | |
--- a/tests/combat/test_armor.py | |
+++ b/tests/combat/test_armor.py | |
@@ -8,11 +8,12 @@ def test_armor_only_vs_valid_damage_types(): | |
with pytest.raises(AssertionError): | |
armor["BULLSHIT_DAMAGE_TYPE"] = 55 | |
+ | |
def test_armor_reduces_damage(hero_only_game, hero): | |
hp_before_dmg = hero.health | |
dmg = Damage(5, DamageTypes.FIRE) | |
- DamageEvent( dmg, hero) | |
+ DamageEvent(dmg, hero) | |
dealt_no_armor = hp_before_dmg - hero.health | |
hp_before_dmg = hero.health | |
@@ -20,7 +21,7 @@ def test_armor_reduces_damage(hero_only_game, hero): | |
armor = Armor(3) | |
hero.natural_armor = armor | |
- DamageEvent( dmg, hero) | |
+ DamageEvent(dmg, hero) | |
dealt_armor = hp_before_dmg - hero.health | |
assert dealt_no_armor > dealt_armor | |
@@ -30,6 +31,7 @@ def test_armor_reduces_damage(hero_only_game, hero): | |
def dmg(request): | |
yield Damage(5, request.param) | |
+ | |
def test_types_matter(hero_only_game, hero, dmg): | |
hp_before_dmg = hero.health | |
@@ -37,11 +39,9 @@ def test_types_matter(hero_only_game, hero, dmg): | |
armor = Armor(3, {DamageTypes.FIRE: 4000}) | |
hero.natural_armor = armor | |
- DamageEvent( dmg, hero) | |
+ DamageEvent(dmg, hero) | |
if dmg.type == DamageTypes.FIRE: | |
assert hp_before_dmg == hero.health | |
else: | |
assert hp_before_dmg > hero.health | |
- | |
- | |
diff --git a/tests/combat/test_attack_defense.py b/tests/combat/test_attack_defense.py | |
index 314f329..430e817 100644 | |
--- a/tests/combat/test_attack_defense.py | |
+++ b/tests/combat/test_attack_defense.py | |
@@ -2,6 +2,7 @@ from mechanics.chances.ChanceCalculator import ChanceCalculator | |
import pytest | |
+ | |
@pytest.mark.parametrize("attack, defense", [ | |
(0, 0), | |
(0, 10), | |
@@ -19,26 +20,30 @@ def test_zero_one_do_not_change(attack, defense): | |
modified_chance = ChanceCalculator.chance(base_chance, attack, defense) | |
assert modified_chance == base_chance | |
+ | |
def test_attack_increases(): | |
base_chance = 0.5 | |
assert ChanceCalculator.chance(base_chance, 10, 0) > base_chance | |
+ | |
def test_defence_reduces(): | |
base_chance = 0.5 | |
assert ChanceCalculator.chance(base_chance, 0, 10) < base_chance | |
+ | |
def test_extreme_attack_close_to_one(): | |
base_chance = 0.5 | |
extremely_a_lot = 1e10 | |
epsilon = 1e-4 | |
- new_chance = ChanceCalculator.chance(base_chance, precision=extremely_a_lot, evasion=0) | |
+ new_chance = ChanceCalculator.chance( | |
+ base_chance, precision=extremely_a_lot, evasion=0) | |
assert abs(new_chance - 1) < epsilon | |
+ | |
def test_extreme_defense_close_to_zero(): | |
base_chance = 0.5 | |
extremely_a_lot = 1e10 | |
epsilon = 1e-4 | |
- new_chance = ChanceCalculator.chance(base_chance, precision=0, evasion=extremely_a_lot) | |
+ new_chance = ChanceCalculator.chance( | |
+ base_chance, precision=0, evasion=extremely_a_lot) | |
assert new_chance < epsilon | |
- | |
- | |
diff --git a/tests/combat/test_weapon_atb_factor.py b/tests/combat/test_weapon_atb_factor.py | |
index 5208fc1..2ac7a91 100644 | |
--- a/tests/combat/test_weapon_atb_factor.py | |
+++ b/tests/combat/test_weapon_atb_factor.py | |
@@ -1,7 +1,6 @@ | |
from cntent.items.std import std_items | |
- | |
def test_takes_different_time(game_hvsp, hero, mud_golem): | |
hero_pos = hero.cell | |
@@ -19,7 +18,6 @@ def test_takes_different_time(game_hvsp, hero, mud_golem): | |
hero.equipment.equip_item(std_items.sword_cheap) | |
assert hero.get_melee_weapon() is std_items.sword_cheap | |
- | |
rdy_before = hero.readiness | |
hero.attacks[0].activate(mud_golem) | |
delta_rdy_sword = rdy_before - hero.readiness | |
@@ -27,14 +25,9 @@ def test_takes_different_time(game_hvsp, hero, mud_golem): | |
hero.equipment.equip_item(std_items.hammer_cheap) | |
assert hero.get_melee_weapon() is std_items.hammer_cheap | |
- | |
rdy_before = hero.readiness | |
hero.attacks[0].activate(mud_golem) | |
delta_rdy_hammer = rdy_before - hero.readiness | |
assert delta_rdy_dagger < delta_rdy_sword | |
assert delta_rdy_sword < delta_rdy_hammer | |
- | |
- | |
- | |
- | |
diff --git a/tests/conftest.py b/tests/conftest.py | |
index e7026c2..3bc7140 100644 | |
--- a/tests/conftest.py | |
+++ b/tests/conftest.py | |
@@ -1,18 +1,20 @@ | |
+from game_objects.battlefield_objects import Wall | |
+from game_objects.battlefield_objects import Obstacle | |
+from cntent.base_types.mud_golem import mud_golem_basetype | |
+from mechanics.factions import Faction | |
+from mechanics.chances import ChanceCalculator | |
+from mechanics.damage import DamageTypeGroups | |
+from game_objects.dungeon.Dungeon import Dungeon | |
+from game_objects.battlefield_objects import Unit, BaseType, Obstacle | |
+from battlefield.Battlefield import Cell, Battlefield | |
+from DreamGame import DreamGame | |
import pytest | |
-import sys, os | |
+import sys | |
+import os | |
my_path = os.path.dirname(os.path.abspath(__file__)) | |
-sys.path.insert(0, my_path +'/../') | |
+sys.path.insert(0, my_path + '/../') | |
-from DreamGame import DreamGame | |
-from battlefield.Battlefield import Cell, Battlefield | |
-from game_objects.battlefield_objects import Unit, BaseType, Obstacle | |
-from game_objects.dungeon.Dungeon import Dungeon | |
-from mechanics.damage import DamageTypeGroups | |
-from mechanics.chances import ChanceCalculator | |
-from mechanics.factions import Faction | |
-from cntent.base_types.mud_golem import mud_golem_basetype | |
-from game_objects.battlefield_objects import Obstacle | |
@pytest.fixture() | |
def obstacle(): | |
@@ -22,28 +24,36 @@ def obstacle(): | |
@pytest.fixture() | |
def no_chances(monkeypatch): | |
- monkeypatch.setattr(ChanceCalculator, "chance", lambda x,y,z: 1) | |
+ monkeypatch.setattr(ChanceCalculator, "chance", lambda x, y, z: 1) | |
@pytest.fixture() | |
def pirate_basetype(): | |
_pirate_basetype = BaseType({}, "Pirate") | |
- yield _pirate_basetype | |
+ yield _pirate_basetype | |
@pytest.fixture() | |
def demohero_basetype(): | |
- _demohero_basetype = BaseType({'str':25, 'agi': 35,'prc': 15}, "Demo Hero") | |
- yield _demohero_basetype | |
+ _demohero_basetype = BaseType( | |
+ {'str': 25, 'agi': 35, 'prc': 15}, "Demo Hero") | |
+ yield _demohero_basetype | |
+ | |
@pytest.fixture() | |
def hero(demohero_basetype, empty_game): | |
- return Unit(demohero_basetype, game=empty_game, cell=1+1j, faction=Faction.PLAYER) | |
+ return Unit( | |
+ demohero_basetype, | |
+ game=empty_game, | |
+ cell=1 + 1j, | |
+ faction=Faction.PLAYER) | |
+ | |
@pytest.fixture() | |
def pirate(pirate_basetype, empty_game): | |
return Unit(pirate_basetype, game=empty_game, cell=0j) | |
+ | |
@pytest.fixture() | |
def mud_golem(): | |
yield(Unit(mud_golem_basetype, cell=0j)) | |
@@ -54,8 +64,16 @@ def steel_wall(): | |
resists = {x: -0.6 for x in DamageTypeGroups.physical} | |
resists.update({x: 0.75 for x in DamageTypeGroups.elemental}) | |
- _steel_wall = lambda g, c: Obstacle("Wall of steel!", 5000, game=g, cell=c, resists=resists, | |
- armor=500, icon="wall.png") | |
+ def _steel_wall( | |
+ g, | |
+ c): return Obstacle( | |
+ "Wall of steel!", | |
+ 5000, | |
+ game=g, | |
+ cell=c, | |
+ resists=resists, | |
+ armor=500, | |
+ icon="wall.png") | |
return _steel_wall | |
@@ -65,9 +83,8 @@ def demo_dungeon(pirate_band): | |
units_locations = {pirate_band[i]: locations[i] for i in range(3)} | |
demo_dungeon = Dungeon(units_locations, 8, 8, hero_entrance=Cell(1, 1)) | |
- yield demo_dungeon | |
+ yield demo_dungeon | |
-from game_objects.battlefield_objects import Wall | |
@pytest.fixture() | |
def walls_dungeon(pirate_basetype, steel_wall): | |
@@ -83,7 +100,8 @@ def walls_dungeon(pirate_basetype, steel_wall): | |
construct_walls=create_walls, | |
hero_entrance=Cell(0, 0)) | |
- yield _walls_dungeon | |
+ yield _walls_dungeon | |
+ | |
@pytest.fixture() | |
def walls_game(walls_dungeon, hero): | |
@@ -96,12 +114,14 @@ def pirate_band(pirate_basetype): | |
_pirate_band = [Unit(pirate_basetype) for i in range(3)] | |
return _pirate_band | |
+ | |
@pytest.fixture() | |
def empty_game(): | |
bf = Battlefield(6, 6) | |
_game = DreamGame(bf) | |
return _game | |
+ | |
@pytest.fixture() | |
def huge_game(): | |
bf = Battlefield(60, 60) | |
@@ -117,6 +137,7 @@ def hero_only_game(hero): | |
return _game | |
+ | |
@pytest.fixture() | |
def game_hvsp(hero, pirate_band): | |
bf = Battlefield(8, 8) | |
@@ -133,12 +154,4 @@ def game_hvsp(hero, pirate_band): | |
for unit in pirate_band + [hero]: | |
_game.add_unit(unit) | |
- | |
- | |
return _game | |
- | |
- | |
- | |
- | |
- | |
- | |
diff --git a/tests/content/abilities/test_aoe.py b/tests/content/abilities/test_aoe.py | |
index 8dd69f1..2ac435c 100644 | |
--- a/tests/content/abilities/test_aoe.py | |
+++ b/tests/content/abilities/test_aoe.py | |
@@ -4,27 +4,20 @@ from mechanics.damage import DamageTypes, Damage, ImpactFactor | |
from mechanics.events import DamageEvent | |
- | |
def test_aoe(empty_game, hero, pirate_band): | |
- empty_game.add_unit(hero, 1+1j) | |
- ability = aoe_damage(1,1)() | |
- hero.add_ability( ability ) | |
+ empty_game.add_unit(hero, 1 + 1j) | |
+ ability = aoe_damage(1, 1)() | |
+ hero.add_ability(ability) | |
p1, p2, p3 = pirate_band | |
- empty_game.add_unit(p1, 2+2j) | |
- empty_game.add_unit(p2, 2+3j) | |
- empty_game.add_unit(p3, 3+4j) | |
+ empty_game.add_unit(p1, 2 + 2j) | |
+ empty_game.add_unit(p2, 2 + 3j) | |
+ empty_game.add_unit(p3, 3 + 4j) | |
- DamageEvent(Damage(100, DamageTypes.LIGHTNING), p2, source=hero, impact_factor=ImpactFactor.CRIT) | |
+ DamageEvent(Damage(100, DamageTypes.LIGHTNING), p2, | |
+ source=hero, impact_factor=ImpactFactor.CRIT) | |
assert p1.health < p1.max_health | |
assert p3.health == p3.max_health | |
- | |
- | |
- | |
- | |
- | |
- | |
- | |
diff --git a/tests/content/abilities/test_bash.py b/tests/content/abilities/test_bash.py | |
index b94f638..fb76439 100644 | |
--- a/tests/content/abilities/test_bash.py | |
+++ b/tests/content/abilities/test_bash.py | |
@@ -6,16 +6,19 @@ from mechanics.damage import DamageTypes, Damage | |
from mechanics.events import DamageEvent | |
- | |
def test_bash(empty_game, hero, pirate): | |
- empty_game.add_unit(hero, 1+1j) | |
- hero.add_ability( bash(1)() ) | |
- | |
- empty_game.add_unit(pirate, 2+1j) | |
+ empty_game.add_unit(hero, 1 + 1j) | |
+ hero.add_ability(bash(1)()) | |
+ empty_game.add_unit(pirate, 2 + 1j) | |
rdy_before = pirate.readiness | |
- DamageEvent(damage=Damage(100, DamageTypes.CRUSH), target=pirate, source=hero) | |
+ DamageEvent( | |
+ damage=Damage( | |
+ 100, | |
+ DamageTypes.CRUSH), | |
+ target=pirate, | |
+ source=hero) | |
delta_rdy = pirate.readiness - rdy_before | |
assert delta_rdy < 0 | |
@@ -28,7 +31,12 @@ def test_pirate_no_bash(empty_game, hero, pirate): | |
empty_game.add_unit(pirate, 2 + 1j) | |
rdy_before = hero.readiness | |
- DamageEvent(damage=Damage(100, DamageTypes.CRUSH), target=hero, source=pirate) | |
+ DamageEvent( | |
+ damage=Damage( | |
+ 100, | |
+ DamageTypes.CRUSH), | |
+ target=hero, | |
+ source=pirate) | |
delta_rdy = hero.readiness - rdy_before | |
assert delta_rdy == 0 | |
@@ -42,12 +50,12 @@ def test_no_bash_magic(empty_game, hero, pirate): | |
empty_game.add_unit(pirate, 2 + 1j) | |
rdy_before = pirate.readiness | |
- DamageEvent(damage=Damage(100, DamageTypes.FROST), target=pirate, source=hero) | |
+ DamageEvent( | |
+ damage=Damage( | |
+ 100, | |
+ DamageTypes.FROST), | |
+ target=pirate, | |
+ source=hero) | |
delta_rdy = pirate.readiness - rdy_before | |
assert delta_rdy == 0 | |
- | |
- | |
- | |
- | |
- | |
diff --git a/tests/content/abilities/test_generic_abilities.py b/tests/content/abilities/test_generic_abilities.py | |
index 75dff53..fd95948 100644 | |
--- a/tests/content/abilities/test_generic_abilities.py | |
+++ b/tests/content/abilities/test_generic_abilities.py | |
@@ -4,15 +4,13 @@ from game_objects.battlefield_objects import BaseType | |
from game_objects.monsters.Monster import Monster | |
- | |
-zombie_norm = BaseType({},"Zombie") | |
-zombie_fat = BaseType({},"Zombie", abilities=[fat]) | |
+zombie_norm = BaseType({}, "Zombie") | |
+zombie_fat = BaseType({}, "Zombie", abilities=[fat]) | |
zombie_norm = Monster(zombie_norm) | |
zombie_fat = Monster(zombie_fat) | |
- | |
def test_fat(empty_game): | |
z_norm = zombie_norm.create(empty_game) | |
diff --git a/tests/content/abilities/test_manadrain.py b/tests/content/abilities/test_manadrain.py | |
index 3ac31aa..a6e1a1f 100644 | |
--- a/tests/content/abilities/test_manadrain.py | |
+++ b/tests/content/abilities/test_manadrain.py | |
@@ -4,13 +4,12 @@ from mechanics.damage import DamageTypes, Damage, ImpactFactor | |
from mechanics.events import DamageEvent | |
- | |
def test_drain_heal(empty_game, hero, pirate): | |
- empty_game.add_unit(hero, 1+1j) | |
- hero.add_ability( mana_drain(20, 0.05, 0.5)() ) | |
+ empty_game.add_unit(hero, 1 + 1j) | |
+ hero.add_ability(mana_drain(20, 0.05, 0.5)()) | |
- empty_game.add_unit(pirate, 2+2j) | |
+ empty_game.add_unit(pirate, 2 + 2j) | |
hero.health -= 100 | |
@@ -18,18 +17,8 @@ def test_drain_heal(empty_game, hero, pirate): | |
hero_health_before = hero.health | |
- DamageEvent(Damage(100, DamageTypes.LIGHTNING), pirate, source=hero, impact_factor=ImpactFactor.HIT) | |
- | |
+ DamageEvent(Damage(100, DamageTypes.LIGHTNING), pirate, | |
+ source=hero, impact_factor=ImpactFactor.HIT) | |
assert pirate.mana < pirate_mana_before | |
assert hero.health > hero_health_before | |
- | |
- | |
- | |
- | |
- | |
- | |
- | |
- | |
- | |
- | |
diff --git a/tests/content/abilities/test_rage.py b/tests/content/abilities/test_rage.py | |
index a1e6bb7..c7485a0 100644 | |
--- a/tests/content/abilities/test_rage.py | |
+++ b/tests/content/abilities/test_rage.py | |
@@ -6,29 +6,40 @@ from mechanics.damage import DamageTypes, Damage | |
from mechanics.events import DamageEvent | |
- | |
def test_rage(game_hvsp, hero): | |
pirate = game_hvsp.enemy_units[0] | |
- hero.add_ability( battle_rage(1)() ) | |
+ hero.add_ability(battle_rage(1)()) | |
str_before = hero.str | |
hpmax_before = hero.max_health | |
ini_before = hero.initiative | |
- DamageEvent(damage=Damage(100, DamageTypes.CRUSH), target=hero, source=pirate) | |
+ DamageEvent( | |
+ damage=Damage( | |
+ 100, | |
+ DamageTypes.CRUSH), | |
+ target=hero, | |
+ source=pirate) | |
assert str_before < hero.str | |
assert hpmax_before < hero.max_health | |
- # assert ini_before < hero.initiative # initiative is rounded as an integer and is not guaranteed to grow | |
+ # assert ini_before < hero.initiative # initiative is rounded as an | |
+ # integer and is not guaranteed to grow | |
+ | |
def test_rage_expires(game_hvsp, hero): | |
pirate = game_hvsp.enemy_units[0] | |
- hero.add_ability( battle_rage(1)() ) | |
+ hero.add_ability(battle_rage(1)()) | |
str_before = hero.str | |
hpmax_before = hero.max_health | |
ini_before = hero.initiative | |
- DamageEvent(damage=Damage(100, DamageTypes.CRUSH), target=hero, source=pirate) | |
+ DamageEvent( | |
+ damage=Damage( | |
+ 100, | |
+ DamageTypes.CRUSH), | |
+ target=hero, | |
+ source=pirate) | |
game_hvsp.turns_manager.pass_time(10) | |
@@ -40,30 +51,26 @@ def test_rage_expires(game_hvsp, hero): | |
def test_stacks(game_hvsp, hero): | |
pirate = game_hvsp.enemy_units[0] | |
- hero.add_ability( battle_rage(1)() ) | |
+ hero.add_ability(battle_rage(1)()) | |
- | |
- DamageEvent(damage=Damage(100, DamageTypes.CRUSH), target=hero, source=pirate) | |
+ DamageEvent( | |
+ damage=Damage( | |
+ 100, | |
+ DamageTypes.CRUSH), | |
+ target=hero, | |
+ source=pirate) | |
str_before = hero.str | |
hpmax_before = hero.max_health | |
ini_before = hero.initiative | |
- DamageEvent(damage=Damage(100, DamageTypes.CRUSH), target=hero, source=pirate) | |
+ DamageEvent( | |
+ damage=Damage( | |
+ 100, | |
+ DamageTypes.CRUSH), | |
+ target=hero, | |
+ source=pirate) | |
assert str_before < hero.str | |
assert hpmax_before < hero.max_health | |
assert ini_before < hero.initiative | |
- | |
- | |
- | |
- | |
- | |
- | |
- | |
- | |
- | |
- | |
- | |
- | |
- | |
diff --git a/tests/content/spells/test_fire.py b/tests/content/spells/test_fire.py | |
index b1a3265..effc8af 100644 | |
--- a/tests/content/spells/test_fire.py | |
+++ b/tests/content/spells/test_fire.py | |
@@ -2,28 +2,23 @@ from cntent.spells.fire.concepts import burning_hands_concept | |
from cntent.spells.runes import double_damage_rune | |
from mechanics.actives import Active | |
+ | |
def test_burning_hands(empty_game, hero, pirate_band): | |
spell = burning_hands_concept.to_spell([double_damage_rune]) | |
hero.int_base += 100 | |
- empty_game.add_unit(hero, 1+1j, facing=1+0j) | |
- new_active = hero.give_active( Active.from_spell( spell ) ) | |
+ empty_game.add_unit(hero, 1 + 1j, facing=1 + 0j) | |
+ new_active = hero.give_active(Active.from_spell(spell)) | |
p1, p2, p3 = pirate_band | |
- empty_game.add_unit(p1, 2+1j) | |
- empty_game.add_unit(p2, 3+1j) | |
- empty_game.add_unit(p3, 4+1j) | |
+ empty_game.add_unit(p1, 2 + 1j) | |
+ empty_game.add_unit(p2, 3 + 1j) | |
+ empty_game.add_unit(p3, 4 + 1j) | |
hero.activate(new_active) | |
assert p1.health < p1.max_health | |
assert p2.health < p2.max_health | |
assert p3.health < p3.max_health | |
- | |
- | |
- | |
- | |
- | |
- | |
diff --git a/tests/content/tel_razi/test_golem.py b/tests/content/tel_razi/test_golem.py | |
index 944a7b9..903637d 100644 | |
--- a/tests/content/tel_razi/test_golem.py | |
+++ b/tests/content/tel_razi/test_golem.py | |
@@ -6,12 +6,15 @@ import pytest | |
@pytest.fixture() | |
def just_a_golem(empty_game): | |
gol = golem.create(empty_game) | |
- empty_game.add_unit(gol, 1+1j) | |
+ empty_game.add_unit(gol, 1 + 1j) | |
return gol | |
+ | |
def test_one_trigger(just_a_golem, empty_game): | |
- assert len(empty_game.events_platform.triggers[EventsChannels.ActiveChannel]) == 1 | |
- assert len(empty_game.events_platform.interrupts[EventsChannels.ActiveChannel]) == 0 | |
+ assert len( | |
+ empty_game.events_platform.triggers[EventsChannels.ActiveChannel]) == 1 | |
+ assert len( | |
+ empty_game.events_platform.interrupts[EventsChannels.ActiveChannel]) == 0 | |
def test_discharges(just_a_golem, monkeypatch): | |
@@ -23,22 +26,24 @@ def test_discharges(just_a_golem, monkeypatch): | |
assert just_a_golem.disabled is True | |
+ | |
def test_discharges_stamina(just_a_golem, monkeypatch): | |
assert just_a_golem.disabled is False | |
just_a_golem.max_stamina += 9999 | |
- | |
monkeypatch.setattr(just_a_golem.turn_ccw_active.cost, "stamina", 100) | |
just_a_golem.activate(just_a_golem.turn_ccw_active) | |
assert just_a_golem.disabled is True | |
+ | |
def test_can_be_disabled(just_a_golem): | |
just_a_golem.disabled = True | |
assert just_a_golem.disabled | |
+ | |
def test_can_be_recharged(just_a_golem): | |
just_a_golem.golem_charge = 0 | |
@@ -56,6 +61,7 @@ def test_enough_charge(just_a_golem): | |
assert just_a_golem.disabled is False | |
+ | |
def test_enough_charge_move(just_a_golem, empty_game): | |
assert just_a_golem.disabled is False | |
@@ -68,10 +74,3 @@ def test_enough_charge_move(just_a_golem, empty_game): | |
assert just_a_golem.disabled is False | |
assert just_a_golem.cell.complex == cell_in_front | |
- | |
- | |
- | |
- | |
- | |
- | |
- | |
diff --git a/tests/content/tel_razi/test_random_teleport.py b/tests/content/tel_razi/test_random_teleport.py | |
index df8e630..fd01c25 100644 | |
--- a/tests/content/tel_razi/test_random_teleport.py | |
+++ b/tests/content/tel_razi/test_random_teleport.py | |
@@ -7,8 +7,8 @@ def test_random_teleport(pirate_band, empty_game, no_chances): | |
p1 = pirate_band[0] | |
p2 = pirate_band[1] | |
- empty_game.add_unit(p1, 2+2j,"FACTION_1", facing=1j) | |
- empty_game.add_unit(p2, 2+3j,"FACTION_2", facing=1j) | |
+ empty_game.add_unit(p1, 2 + 2j, "FACTION_1", facing=1j) | |
+ empty_game.add_unit(p2, 2 + 3j, "FACTION_2", facing=1j) | |
random_teleport_trigger(p2, 4, 1, Cost(readiness=0.1)) | |
@@ -19,15 +19,15 @@ def test_random_teleport(pirate_band, empty_game, no_chances): | |
p2.readiness = 0.5 | |
empty_game.order_attack(p1, p2) | |
- assert p2.cell.complex != 2+3j | |
+ assert p2.cell.complex != 2 + 3j | |
actives_found = 0 | |
attacks_found = 0 | |
moves_found = 0 | |
for event, happened in spy: | |
if isinstance(event, AttackEvent): | |
- attacks_found +=1 | |
+ attacks_found += 1 | |
elif isinstance(event, ActiveEvent): | |
- actives_found +=1 | |
+ actives_found += 1 | |
elif isinstance(event, MovementEvent): | |
moves_found += 1 | |
@@ -101,6 +101,7 @@ def test_random_teleport_chance_blocks(pirate_band, empty_game, no_chances): | |
assert attacks_found == 1 | |
assert moves_found == 0 | |
+ | |
def test_dying_unit_dies(pirate_band, empty_game, no_chances): | |
p1 = pirate_band[0] | |
p2 = pirate_band[1] | |
@@ -114,7 +115,4 @@ def test_dying_unit_dies(pirate_band, empty_game, no_chances): | |
p1.readiness = 2 | |
p2.readiness = 0.5 | |
empty_game.order_attack(p1, p2) | |
- pass # no exceptions thrown | |
- | |
- | |
- | |
+ pass # no exceptions thrown | |
diff --git a/tests/content/tel_razi/test_sentinel.py b/tests/content/tel_razi/test_sentinel.py | |
index 2d00ff8..80bf70a 100644 | |
--- a/tests/content/tel_razi/test_sentinel.py | |
+++ b/tests/content/tel_razi/test_sentinel.py | |
@@ -1,27 +1,23 @@ | |
from cntent.monsters.tel_razi.monsters import sentinel | |
from mechanics.events import EventsChannels | |
-def test_trigger_removed_on_death(empty_game): | |
- triggers_before = set( empty_game.events_platform.triggers[EventsChannels.MovementChannel]) | \ | |
- set( empty_game.events_platform.interrupts[EventsChannels.MovementChannel]) | |
+def test_trigger_removed_on_death(empty_game): | |
+ triggers_before = set(empty_game.events_platform.triggers[EventsChannels.MovementChannel]) | \ | |
+ set(empty_game.events_platform.interrupts[EventsChannels.MovementChannel]) | |
s = sentinel.create(empty_game) | |
- empty_game.add_unit(s, 1+1j) | |
+ empty_game.add_unit(s, 1 + 1j) | |
- triggers_after = set( empty_game.events_platform.triggers[EventsChannels.MovementChannel]) | \ | |
- set( empty_game.events_platform.interrupts[EventsChannels.MovementChannel]) | |
+ triggers_after = set(empty_game.events_platform.triggers[EventsChannels.MovementChannel]) | \ | |
+ set(empty_game.events_platform.interrupts[EventsChannels.MovementChannel]) | |
assert len(triggers_before) < len(triggers_after) | |
s.health = 0 | |
triggers_rip = set(empty_game.events_platform.triggers[EventsChannels.MovementChannel]) | \ | |
- set(empty_game.events_platform.interrupts[EventsChannels.MovementChannel]) | |
+ set(empty_game.events_platform.interrupts[EventsChannels.MovementChannel]) | |
assert len(triggers_before) == len(triggers_rip) | |
- | |
- | |
- | |
- | |
diff --git a/tests/content/tel_razi/test_zone_control.py b/tests/content/tel_razi/test_zone_control.py | |
index 6caad2f..4645465 100644 | |
--- a/tests/content/tel_razi/test_zone_control.py | |
+++ b/tests/content/tel_razi/test_zone_control.py | |
@@ -6,8 +6,8 @@ def test_zone_control(pirate_band, empty_game, no_chances): | |
p1 = pirate_band[0] | |
p2 = pirate_band[1] | |
- empty_game.add_unit(p1, 2+2j,"FACTION_1", facing=1j) | |
- empty_game.add_unit(p2, 2+3j,"FACTION_2", facing=1j) | |
+ empty_game.add_unit(p1, 2 + 2j, "FACTION_1", facing=1j) | |
+ empty_game.add_unit(p2, 2 + 3j, "FACTION_2", facing=1j) | |
zone_control_trigger(p1, 1, 1) | |
@@ -16,16 +16,16 @@ def test_zone_control(pirate_band, empty_game, no_chances): | |
p1.readiness = 0.9 | |
p2.readiness = 1.5 | |
- empty_game.order_move(p2, 2+4j) | |
+ empty_game.order_move(p2, 2 + 4j) | |
- assert p2.cell.complex == 2+3j | |
+ assert p2.cell.complex == 2 + 3j | |
actives_found = 0 | |
attacks_found = 0 | |
for event, happened in spy: | |
if isinstance(event, AttackEvent): | |
- attacks_found +=1 | |
+ attacks_found += 1 | |
elif isinstance(event, ActiveEvent): | |
- actives_found +=1 | |
+ actives_found += 1 | |
elif isinstance(event, MovementEvent): | |
assert not happened | |
assert actives_found == 2 | |
@@ -36,8 +36,8 @@ def test_zone_control_no_friendly_fire(pirate_band, empty_game, no_chances): | |
p1 = pirate_band[0] | |
p2 = pirate_band[1] | |
- empty_game.add_unit(p1, 2+2j,"FACTION_1", facing=1j) | |
- empty_game.add_unit(p2, 2+3j,"FACTION_1", facing=1j) | |
+ empty_game.add_unit(p1, 2 + 2j, "FACTION_1", facing=1j) | |
+ empty_game.add_unit(p2, 2 + 3j, "FACTION_1", facing=1j) | |
zone_control_trigger(p1, 1, 1) | |
@@ -46,29 +46,30 @@ def test_zone_control_no_friendly_fire(pirate_band, empty_game, no_chances): | |
p1.readiness = 0.9 | |
p2.readiness = 1.5 | |
- empty_game.order_move(p2, 2+4j) | |
+ empty_game.order_move(p2, 2 + 4j) | |
- assert p2.cell.complex == 2+4j | |
+ assert p2.cell.complex == 2 + 4j | |
actives_found = 0 | |
attacks_found = 0 | |
for event, happened in spy: | |
if isinstance(event, AttackEvent): | |
- attacks_found +=1 | |
+ attacks_found += 1 | |
elif isinstance(event, ActiveEvent): | |
- actives_found +=1 | |
+ actives_found += 1 | |
elif isinstance(event, MovementEvent): | |
assert happened | |
assert actives_found == 1 | |
assert attacks_found == 0 | |
+ | |
def test_zone_control_need_active(pirate_band, empty_game, no_chances): | |
p1 = pirate_band[0] | |
p1.actives = [] | |
p2 = pirate_band[1] | |
- empty_game.add_unit(p1, 2+2j,"FACTION_1", facing=1j) | |
- empty_game.add_unit(p2, 2+3j,"FACTION_1", facing=1j) | |
+ empty_game.add_unit(p1, 2 + 2j, "FACTION_1", facing=1j) | |
+ empty_game.add_unit(p2, 2 + 3j, "FACTION_1", facing=1j) | |
zone_control_trigger(p1, 1, 1) | |
@@ -77,17 +78,17 @@ def test_zone_control_need_active(pirate_band, empty_game, no_chances): | |
p1.readiness = 0.9 | |
p2.readiness = 1.5 | |
- empty_game.order_move(p2, 2+4j) | |
+ empty_game.order_move(p2, 2 + 4j) | |
- assert p2.cell.complex == 2+4j | |
+ assert p2.cell.complex == 2 + 4j | |
actives_found = 0 | |
attacks_found = 0 | |
for event, happened in spy: | |
if isinstance(event, AttackEvent): | |
- attacks_found +=1 | |
+ attacks_found += 1 | |
elif isinstance(event, ActiveEvent): | |
- actives_found +=1 | |
+ actives_found += 1 | |
elif isinstance(event, MovementEvent): | |
assert happened | |
assert actives_found == 1 | |
@@ -98,8 +99,8 @@ def test_zone_control_need_readiness(pirate_band, empty_game, no_chances): | |
p1 = pirate_band[0] | |
p2 = pirate_band[1] | |
- empty_game.add_unit(p1, 2+2j,"FACTION_1", facing=1j) | |
- empty_game.add_unit(p2, 2+3j,"FACTION_2", facing=1j) | |
+ empty_game.add_unit(p1, 2 + 2j, "FACTION_1", facing=1j) | |
+ empty_game.add_unit(p2, 2 + 3j, "FACTION_2", facing=1j) | |
zone_control_trigger(p1, 1, 1) | |
@@ -108,20 +109,20 @@ def test_zone_control_need_readiness(pirate_band, empty_game, no_chances): | |
p1.readiness = 0 | |
p2.readiness = 1.5 | |
- empty_game.order_move(p2, 2+4j) | |
+ empty_game.order_move(p2, 2 + 4j) | |
- assert p2.cell.complex == 2+4j | |
+ assert p2.cell.complex == 2 + 4j | |
actives_found = 0 | |
attacks_found = 0 | |
for event, happened in spy: | |
if isinstance(event, AttackEvent): | |
- attacks_found +=1 | |
+ attacks_found += 1 | |
elif isinstance(event, ActiveEvent): | |
- actives_found +=1 | |
+ actives_found += 1 | |
elif isinstance(event, MovementEvent): | |
assert happened | |
assert actives_found == 1 | |
- assert attacks_found == 0 | |
\ No newline at end of file | |
+ assert attacks_found == 0 | |
diff --git a/tests/content/test_undead.py b/tests/content/test_undead.py | |
index 8de71af..1e1f167 100644 | |
--- a/tests/content/test_undead.py | |
+++ b/tests/content/test_undead.py | |
@@ -16,7 +16,6 @@ def test_undying(game_hvsp): | |
s.health -= 99999 | |
assert s.alive | |
- | |
for _ in range(10): | |
z.health -= 99999 | |
s.health -= 99999 | |
@@ -29,13 +28,12 @@ def test_ghost(empty_game): | |
g = ghost.create(empty_game) | |
z = zombie.create(empty_game) | |
- empty_game.add_unit(g, 1+1j) | |
- | |
- empty_game.add_unit(z, 1+1j) | |
+ empty_game.add_unit(g, 1 + 1j) | |
+ empty_game.add_unit(z, 1 + 1j) | |
DamageEvent(damage=Damage(1, DamageTypes.ACID), target=z, source=g) | |
- assert z.mana == z.max_mana # no damage | |
+ assert z.mana == z.max_mana # no damage | |
DamageEvent(damage=Damage(300, DamageTypes.ACID), target=z, source=g) | |
assert z.mana < z.max_mana | |
diff --git a/tests/gameutilstest.py b/tests/gameutilstest.py | |
index 19ee82d..b6e98a1 100644 | |
--- a/tests/gameutilstest.py | |
+++ b/tests/gameutilstest.py | |
@@ -8,7 +8,7 @@ from gameutils import GameMath | |
class TestMethod(unittest.TestCase): | |
def test_get_direction(self): | |
- self.assertEqual((1, 1),GameMath.get_direction(1, 1)) | |
- self.assertEqual((0, -1),GameMath.get_direction(0, -5)) | |
- self.assertEqual((-1, 0),GameMath.get_direction(-5, -2)) | |
- self.assertEqual((1, 0),GameMath.get_direction(5, 2)) | |
+ self.assertEqual((1, 1), GameMath.get_direction(1, 1)) | |
+ self.assertEqual((0, -1), GameMath.get_direction(0, -5)) | |
+ self.assertEqual((-1, 0), GameMath.get_direction(-5, -2)) | |
+ self.assertEqual((1, 0), GameMath.get_direction(5, 2)) | |
diff --git a/tests/items/charged/test_gives_active.py b/tests/items/charged/test_gives_active.py | |
index 28f21b7..33bbc4e 100644 | |
--- a/tests/items/charged/test_gives_active.py | |
+++ b/tests/items/charged/test_gives_active.py | |
@@ -1,5 +1,6 @@ | |
from cntent.items.std.potions import minor_healing_potion, rejuvination_potion | |
+ | |
def test_gives_active(hero): | |
actives_before = len(hero.actives) | |
@@ -14,7 +15,7 @@ def test_usage_removes_charges(hero): | |
hero.quick_items.add(rejuvination_potion) | |
charges_before = rejuvination_potion.charges | |
- new_active = list( set(hero.actives) - actives_no_potion )[0] | |
+ new_active = list(set(hero.actives) - actives_no_potion)[0] | |
hero.activate(new_active) | |
assert charges_before == rejuvination_potion.charges + 1 | |
@@ -30,16 +31,13 @@ def test_healing_potion_heals(hero): | |
new_active = list(set(hero.actives) - actives_no_potion)[0] | |
- hero.health /=2 | |
+ hero.health /= 2 | |
health_before = hero.health | |
hero.activate(new_active) | |
assert hero.health > health_before | |
- | |
- | |
- | |
def test_active_lost_with_item(hero): | |
hero.quick_items.add(minor_healing_potion) | |
@@ -65,4 +63,4 @@ def test_no_active_lost_inventary(hero): | |
actives_before = len(hero.actives) | |
minor_healing_potion.charges -= 99999 | |
- assert len(hero.actives) == actives_before | |
\ No newline at end of file | |
+ assert len(hero.actives) == actives_before | |
diff --git a/tests/items/conftest.py b/tests/items/conftest.py | |
index d5f0a8f..db36bb9 100644 | |
--- a/tests/items/conftest.py | |
+++ b/tests/items/conftest.py | |
@@ -1,8 +1,9 @@ | |
+from cntent.items.std.std_ranged import black_bow, cadamba_crossbow | |
import pytest | |
from game_objects.items import WeaponBlueprint, WeaponTypes, Material, MaterialTypes, ArmorTypes, ArmorBlueprint | |
from game_objects.items import QualityLevel | |
-from game_objects.items import BodyArmor, Weapon | |
+from game_objects.items import BodyArmor, Weapon | |
from mechanics.damage import Damage, DamageTypes, Armor | |
@@ -10,46 +11,69 @@ from mechanics.damage import Damage, DamageTypes, Armor | |
def bronze(): | |
return Material(MaterialTypes.METAL, "bronze", 0.5) | |
+ | |
@pytest.fixture() | |
def silver(): | |
return Material(MaterialTypes.METAL, "bronze", 1.1) | |
+ | |
@pytest.fixture() | |
def troll_skin(): | |
return Material(MaterialTypes.SKIN, "Black Troll Hide", 1.4) | |
+ | |
@pytest.fixture() | |
def usual(): | |
return QualityLevel("usual", 1) | |
+ | |
@pytest.fixture() | |
def legendary(): | |
return QualityLevel("legendary", 2) | |
+ | |
@pytest.fixture() | |
def my_sword_blueprint(): | |
- return WeaponBlueprint("sword", weapon_type=WeaponTypes.SWORD, material_type=MaterialTypes.METAL, rarity=1) | |
+ return WeaponBlueprint( | |
+ "sword", | |
+ weapon_type=WeaponTypes.SWORD, | |
+ material_type=MaterialTypes.METAL, | |
+ rarity=1) | |
+ | |
@pytest.fixture() | |
def my_cuirass_blueprint(): | |
- return ArmorBlueprint("cuirass", target_item_type=ArmorTypes.CUIRASS, rarity=1) | |
+ return ArmorBlueprint( | |
+ "cuirass", | |
+ target_item_type=ArmorTypes.CUIRASS, | |
+ rarity=1) | |
+ | |
@pytest.fixture() | |
def real_weapon(my_sword_blueprint, bronze, usual, empty_game): | |
- return Weapon("test axe1", Damage(50, DamageTypes.SLASH), max_durability=50, | |
- blueprint=my_sword_blueprint, material=bronze, quality=usual, | |
- game=empty_game, is_ranged=False) | |
+ return Weapon( | |
+ "test axe1", | |
+ Damage( | |
+ 50, | |
+ DamageTypes.SLASH), | |
+ max_durability=50, | |
+ blueprint=my_sword_blueprint, | |
+ material=bronze, | |
+ quality=usual, | |
+ game=empty_game, | |
+ is_ranged=False) | |
+ | |
def _weapon(empty_game): | |
return Weapon("test axe1", Damage(50, DamageTypes.SLASH), | |
max_durability=50, game=empty_game, is_ranged=False) | |
+ | |
@pytest.fixture() | |
def weapon(empty_game): | |
return _weapon(empty_game) | |
- | |
def _armor(empty_game): | |
return BodyArmor("da armor", Armor(30), max_durability=50, game=empty_game) | |
@@ -58,17 +82,18 @@ def _armor(empty_game): | |
def armor(empty_game): | |
return _armor(empty_game) | |
+ | |
@pytest.fixture(params=[_weapon, _armor]) | |
def diff_item(request, empty_game): | |
item = request.param(empty_game) | |
yield item | |
-from cntent.items.std.std_ranged import black_bow, cadamba_crossbow | |
@pytest.fixture() | |
def bow(): | |
return black_bow | |
+ | |
@pytest.fixture() | |
def crossbow(): | |
- return cadamba_crossbow | |
\ No newline at end of file | |
+ return cadamba_crossbow | |
diff --git a/tests/items/enchanted/test_passive_bonuses.py b/tests/items/enchanted/test_passive_bonuses.py | |
index 3e5a975..4315927 100644 | |
--- a/tests/items/enchanted/test_passive_bonuses.py | |
+++ b/tests/items/enchanted/test_passive_bonuses.py | |
@@ -2,7 +2,8 @@ from game_objects.battlefield_objects import Unit, CharAttributes | |
from game_objects.attributes import Bonus | |
from game_objects.items import WearableItem, ItemTypes | |
-def test_equip_gives_bonuses(hero:Unit, empty_game): | |
+ | |
+def test_equip_gives_bonuses(hero: Unit, empty_game): | |
ring = WearableItem("bronze ring", ItemTypes.RING) | |
bns = Bonus({CharAttributes.HEALTH: 50}) | |
ring.bonuses.append(bns) | |
@@ -21,11 +22,10 @@ def test_unequip_removes_bonuses(hero, empty_game): | |
bns = Bonus({CharAttributes.HEALTH: 50}) | |
ring.bonuses.append(bns) | |
- | |
hero.equipment.equip_item(ring) | |
health_with_ring = hero.health | |
hero.equipment.unequip_item(ring) | |
- assert health_with_ring > hero.health | |
\ No newline at end of file | |
+ assert health_with_ring > hero.health | |
diff --git a/tests/items/ranged/test_active_causes_attack.py b/tests/items/ranged/test_active_causes_attack.py | |
index 3903528..b73aeb2 100644 | |
--- a/tests/items/ranged/test_active_causes_attack.py | |
+++ b/tests/items/ranged/test_active_causes_attack.py | |
@@ -5,10 +5,10 @@ def test_usage_ranged_attack(hero, bow, empty_game, pirate, no_chances): | |
actives_no_potion = set(hero.actives) | |
hero.equipment.equip_item(bow) | |
- ranged_attack_active = list( set(hero.actives) - actives_no_potion )[0] | |
+ ranged_attack_active = list(set(hero.actives) - actives_no_potion)[0] | |
- empty_game.add_unit(hero, (1+1j), facing=1j) | |
- empty_game.add_unit(pirate, (2+3j), facing=1j) | |
+ empty_game.add_unit(hero, (1 + 1j), facing=1j) | |
+ empty_game.add_unit(pirate, (2 + 3j), facing=1j) | |
from mechanics.events import RangedAttackEvent | |
@@ -21,7 +21,6 @@ def test_usage_ranged_attack(hero, bow, empty_game, pirate, no_chances): | |
if isinstance(e, RangedAttackEvent): | |
ranged_attack_event = e | |
- | |
assert ranged_attack_event is not None | |
assert ranged_attack_event.target is pirate | |
assert ranged_attack_event.source is hero | |
@@ -41,16 +40,17 @@ def test_too_close(hero, bow, empty_game, pirate, monkeypatch): | |
actives_no_potion = set(hero.actives) | |
hero.equipment.equip_item(bow) | |
- new_active = list( set(hero.actives) - actives_no_potion )[0] | |
+ new_active = list(set(hero.actives) - actives_no_potion)[0] | |
- empty_game.add_unit(hero, (1+1j), facing=1j) | |
- empty_game.add_unit(pirate, (1+2j), facing=1j) | |
+ empty_game.add_unit(hero, (1 + 1j), facing=1j) | |
+ empty_game.add_unit(pirate, (1 + 2j), facing=1j) | |
from mechanics.combat import RangedAttack | |
spy = [] | |
+ | |
def spy_lambda(source, target): | |
- spy.append( (source, target) ) | |
+ spy.append((source, target)) | |
monkeypatch.setattr(RangedAttack, 'ranged_attack', spy_lambda) | |
@@ -58,6 +58,7 @@ def test_too_close(hero, bow, empty_game, pirate, monkeypatch): | |
assert len(spy) == 0 | |
+ | |
def test_too_far(hero, bow, empty_game, pirate, monkeypatch): | |
actives_no_potion = set(hero.actives) | |
hero.equipment.equip_item(bow) | |
@@ -86,22 +87,20 @@ def test_angle(hero, bow, empty_game, pirate, monkeypatch): | |
actives_no_potion = set(hero.actives) | |
hero.equipment.equip_item(bow) | |
- new_active = list( set(hero.actives) - actives_no_potion )[0] | |
+ new_active = list(set(hero.actives) - actives_no_potion)[0] | |
- empty_game.add_unit(hero, (1+1j), facing=-1j) | |
- empty_game.add_unit(pirate, (2+3j), facing=1j) | |
+ empty_game.add_unit(hero, (1 + 1j), facing=-1j) | |
+ empty_game.add_unit(pirate, (2 + 3j), facing=1j) | |
from mechanics.combat import RangedAttack | |
spy = [] | |
+ | |
def spy_lambda(source, target): | |
- spy.append( (source, target) ) | |
+ spy.append((source, target)) | |
monkeypatch.setattr(RangedAttack, 'ranged_attack', spy_lambda) | |
hero.activate(new_active, pirate) | |
assert len(spy) == 0 | |
- | |
- | |
- | |
diff --git a/tests/items/ranged/test_equip_active.py b/tests/items/ranged/test_equip_active.py | |
index ae5a561..1f9195b 100644 | |
--- a/tests/items/ranged/test_equip_active.py | |
+++ b/tests/items/ranged/test_equip_active.py | |
@@ -6,6 +6,7 @@ def test_gives_active(hero, bow): | |
assert len(hero.actives) > actives_before | |
+ | |
def test_gives_active_crossbow(hero, crossbow): | |
actives_before = len(hero.actives) | |
@@ -13,6 +14,7 @@ def test_gives_active_crossbow(hero, crossbow): | |
assert len(hero.actives) > actives_before | |
+ | |
def test_unequip(hero, crossbow): | |
hero.equipment.equip_item(crossbow) | |
@@ -22,9 +24,3 @@ def test_unequip(hero, crossbow): | |
hero.equipment.unequip_slot(EquipmentSlotUids.HANDS) | |
assert len(hero.actives) < actives_before | |
- | |
- | |
- | |
- | |
- | |
- | |
diff --git a/tests/items/test_equipment.py b/tests/items/test_equipment.py | |
index fe6fa35..e2a80e8 100644 | |
--- a/tests/items/test_equipment.py | |
+++ b/tests/items/test_equipment.py | |
@@ -1,6 +1,7 @@ | |
from game_objects.items import Equipment, Slot, EquipmentSlotUids | |
import pytest | |
+ | |
def test_can_equip_directly(weapon, hero): | |
eq = Equipment(hero) | |
eq.equip_item(weapon) | |
@@ -16,6 +17,3 @@ def test_equip(weapon, hero): | |
assert eq[EquipmentSlotUids.HANDS] is weapon | |
assert inventory_slot.content is None | |
- | |
- | |
- | |
diff --git a/tests/items/test_inventory.py b/tests/items/test_inventory.py | |
index f8a4225..3aefa06 100644 | |
--- a/tests/items/test_inventory.py | |
+++ b/tests/items/test_inventory.py | |
@@ -1,6 +1,7 @@ | |
from game_objects.items import Item, Inventory | |
import pytest | |
+ | |
@pytest.fixture() | |
def full_inventory(weapon): | |
inv = Inventory(3, None) | |
@@ -12,14 +13,13 @@ def full_inventory(weapon): | |
yield inv | |
- | |
def test_limited_size(weapon): | |
inv = Inventory(3, None) | |
for i in range(3): | |
item = weapon | |
added = inv.add(item) | |
- assert added == True | |
+ assert added | |
assert len(inv.all_items) == 3 | |
@@ -29,6 +29,7 @@ def test_limited_size(weapon): | |
assert len(inv) == 3 | |
+ | |
def test_can_drop(full_inventory, weapon): | |
full_inventory.drop(0) | |
full_inventory.drop(1) | |
@@ -37,9 +38,4 @@ def test_can_drop(full_inventory, weapon): | |
for i in range(3): | |
item = weapon | |
added = full_inventory.add(item) | |
- assert added == True | |
- | |
- | |
- | |
- | |
- | |
+ assert added | |
diff --git a/tests/items/test_items.py b/tests/items/test_items.py | |
index 95cd501..c08cb76 100644 | |
--- a/tests/items/test_items.py | |
+++ b/tests/items/test_items.py | |
@@ -1,12 +1,14 @@ | |
from game_objects.items import ItemTransactions, Slot | |
import pytest | |
+ | |
def test_equip(hero, diff_item): | |
with ItemTransactions(hero) as trans: | |
slot = hero.inventory.get_empty_slot() | |
slot.content = diff_item | |
hero.equipment.equip(slot) | |
+ | |
def test_transaction_safe(hero, diff_item): | |
slot = hero.inventory.get_empty_slot() | |
slot.content = diff_item | |
@@ -16,8 +18,3 @@ def test_transaction_safe(hero, diff_item): | |
assert len(hero.inventory.all_items) == 0 | |
assert len(hero.inventory.all_items) == 1 | |
- | |
- | |
- | |
- | |
- | |
diff --git a/tests/items/test_shop.py b/tests/items/test_shop.py | |
index 11ea408..27e6e51 100644 | |
--- a/tests/items/test_shop.py | |
+++ b/tests/items/test_shop.py | |
@@ -14,14 +14,23 @@ def assortment(): | |
all_blueprints = all_armor + std_blueprints + fancy_blueprints | |
from game_objects.items.materials.MaterialTypes import MaterialTypes | |
mt = MaterialTypes | |
- all_materials = {mt.STONE: Stones.all, mt.METAL: Metals.all, mt.WOOD: Woods.all, mt.SKIN: Leathers.all} | |
+ all_materials = { | |
+ mt.STONE: Stones.all, | |
+ mt.METAL: Metals.all, | |
+ mt.WOOD: Woods.all, | |
+ mt.SKIN: Leathers.all} | |
+ | |
+ return generate_assortment( | |
+ all_blueprints, | |
+ all_materials, | |
+ QualityLevels.all) | |
- return generate_assortment(all_blueprints, all_materials, QualityLevels.all) | |
@fixture() | |
def shop(assortment): | |
return Shop(assortment, 1, 500) | |
+ | |
@fixture() | |
def customer(): | |
from character.Character import Character | |
@@ -35,8 +44,10 @@ def customer(): | |
def test_transactions(shop, customer): | |
shop.customer = customer | |
- items_in_shop = lambda : len(shop.inventory.all_items) | |
- items_hero_has = lambda : len(customer.unit.inventory.all_items) | |
+ | |
+ def items_in_shop(): return len(shop.inventory.all_items) | |
+ | |
+ def items_hero_has(): return len(customer.unit.inventory.all_items) | |
assert items_in_shop() > 10 | |
assert items_hero_has() == 0 | |
@@ -45,7 +56,7 @@ def test_transactions(shop, customer): | |
starting_assortment = items_in_shop() | |
starting_belongings = items_hero_has() | |
- shop.buy( shop.inventory[3] ) | |
+ shop.buy(shop.inventory[3]) | |
assert customer.gold < starting_money | |
assert starting_assortment > items_in_shop() | |
@@ -58,6 +69,3 @@ def test_transactions(shop, customer): | |
assert starting_money > customer.gold > money_after_buying | |
assert starting_assortment == items_in_shop() | |
assert starting_belongings == items_hero_has() | |
- | |
- | |
- | |
diff --git a/tests/items/test_slots.py b/tests/items/test_slots.py | |
index 1af7bee..c80c928 100644 | |
--- a/tests/items/test_slots.py | |
+++ b/tests/items/test_slots.py | |
@@ -1,7 +1,8 @@ | |
-from game_objects.items import ItemTypes, Slot | |
+from game_objects.items import ItemTypes, Slot | |
import pytest | |
import copy | |
+ | |
def test_slot(weapon): | |
slot = Slot("test slot", ItemTypes.WEAPON) | |
weapon2 = copy.copy(weapon) | |
@@ -13,6 +14,7 @@ def test_slot(weapon): | |
slot.content = weapon2 | |
assert slot.content == weapon2 | |
+ | |
def test_swap(weapon): | |
slot1 = Slot("test slot") | |
item1 = weapon | |
@@ -26,4 +28,3 @@ def test_swap(weapon): | |
assert slot1.content == item2 | |
assert slot2.content == item1 | |
- | |
diff --git a/tests/items/wearable/test_body_armor.py b/tests/items/wearable/test_body_armor.py | |
index ae541ab..8e9834b 100644 | |
--- a/tests/items/wearable/test_body_armor.py | |
+++ b/tests/items/wearable/test_body_armor.py | |
@@ -9,5 +9,6 @@ def test_body_armor_gives_armor(hero, armor): | |
def test_tooltip_with_armor(armor): | |
- is_in_tooltip = lambda tooltip, search: any([search in val for val in tooltip.values()]) | |
- assert is_in_tooltip(armor.tooltip_info, str(armor.armor)) | |
\ No newline at end of file | |
+ def is_in_tooltip(tooltip, search): return any( | |
+ [search in val for val in tooltip.values()]) | |
+ assert is_in_tooltip(armor.tooltip_info, str(armor.armor)) | |
diff --git a/tests/items/wearable/test_create_armor.py b/tests/items/wearable/test_create_armor.py | |
index 0de837b..cee621d 100644 | |
--- a/tests/items/wearable/test_create_armor.py | |
+++ b/tests/items/wearable/test_create_armor.py | |
@@ -5,6 +5,7 @@ from mechanics.damage import DamageTypes | |
def test_create_blueprint(my_cuirass_blueprint): | |
assert my_cuirass_blueprint.armor is not None | |
+ | |
def test_create_item(bronze, usual, my_cuirass_blueprint): | |
my_cuirass = my_cuirass_blueprint.to_item(bronze, usual) | |
assert my_cuirass.armor[DamageTypes.FIRE] < my_cuirass_blueprint.armor[DamageTypes.FIRE] | |
diff --git a/tests/items/wearable/test_create_weapon.py b/tests/items/wearable/test_create_weapon.py | |
index 547f78b..5386ace 100644 | |
--- a/tests/items/wearable/test_create_weapon.py | |
+++ b/tests/items/wearable/test_create_weapon.py | |
@@ -2,14 +2,16 @@ | |
def test_create_blueprint(my_sword_blueprint): | |
assert my_sword_blueprint.name is not None | |
+ | |
def test_create_item(bronze, silver, usual, my_sword_blueprint): | |
my_sword1 = my_sword_blueprint.to_item(bronze, usual, game=None) | |
my_sword2 = my_sword_blueprint.to_item(silver, usual, game=None) | |
assert my_sword1.damage.amount < my_sword2.damage.amount | |
+ | |
def test_quality_matters(bronze, usual, legendary, my_sword_blueprint): | |
sword1 = my_sword_blueprint.to_item(bronze, usual, game=None) | |
sword2 = my_sword_blueprint.to_item(bronze, legendary, game=None) | |
- assert sword1.damage.amount < sword2.damage.amount | |
\ No newline at end of file | |
+ assert sword1.damage.amount < sword2.damage.amount | |
diff --git a/tests/items/wearable/test_destroy_item.py b/tests/items/wearable/test_destroy_item.py | |
index 092b681..d0c03df 100644 | |
--- a/tests/items/wearable/test_destroy_item.py | |
+++ b/tests/items/wearable/test_destroy_item.py | |
@@ -2,7 +2,6 @@ from mechanics.events import ItemDestroyedEvent | |
from game_objects.items import EquipmentSlotUids | |
- | |
def test_breaks_into_blueprint(hero, real_weapon): | |
hero.equipment.equip_item(real_weapon) | |
@@ -15,17 +14,16 @@ def test_breaks_into_blueprint(hero, real_weapon): | |
assert hero.equipment[EquipmentSlotUids.HANDS] is None | |
assert len_inventory_after == len_inventory_before + 2 | |
+ | |
def test_destroyed_on_0_durability(hero, real_weapon): | |
hero.equipment.equip_item(real_weapon) | |
- | |
len_inventory_before = len(hero.inventory.all_items) | |
real_weapon.durability = 0 | |
len_inventory_after = len(hero.inventory.all_items) | |
- | |
assert hero.equipment[EquipmentSlotUids.HANDS] is None | |
- assert len_inventory_after == len_inventory_before + 2 | |
\ No newline at end of file | |
+ assert len_inventory_after == len_inventory_before + 2 | |
diff --git a/tests/items/wearable/test_durability.py b/tests/items/wearable/test_durability.py | |
index caa786f..dbd821f 100644 | |
--- a/tests/items/wearable/test_durability.py | |
+++ b/tests/items/wearable/test_durability.py | |
@@ -1,16 +1,28 @@ | |
from mechanics.events import AttackEvent | |
-def test_loses_durability(game_hvsp, hero, weapon, pirate, armor, no_chances, monkeypatch): | |
+def test_loses_durability( | |
+ game_hvsp, | |
+ hero, | |
+ weapon, | |
+ pirate, | |
+ armor, | |
+ no_chances, | |
+ monkeypatch): | |
game_hvsp.add_unit(pirate) | |
- hero.equipment.equip_item( weapon ) | |
- pirate.equipment.equip_item( armor ) | |
+ hero.equipment.equip_item(weapon) | |
+ pirate.equipment.equip_item(armor) | |
weapon_dur_before = weapon.durability | |
armor_dur_before = armor.durability | |
- monkeypatch.setattr(game_hvsp.vision, 'x_sees_y', lambda x, y:True, raising=False) | |
+ monkeypatch.setattr( | |
+ game_hvsp.vision, | |
+ 'x_sees_y', | |
+ lambda x, | |
+ y: True, | |
+ raising=False) | |
AttackEvent(hero, pirate) | |
@@ -45,6 +57,7 @@ def test_maximum_holds(weapon): | |
weapon.durability += maximum * 2 | |
assert weapon.durability == maximum | |
+ | |
def test_zero_holds(armor): | |
maximum = armor.max_durability | |
armor.durability -= maximum * 2 | |
diff --git a/tests/items/wearable/test_weapon.py b/tests/items/wearable/test_weapon.py | |
index d613dd8..2553fc5 100644 | |
--- a/tests/items/wearable/test_weapon.py | |
+++ b/tests/items/wearable/test_weapon.py | |
@@ -2,10 +2,9 @@ | |
def test_weapon_gives_damage(hero, weapon): | |
- | |
damage_before = hero.get_melee_weapon().damage | |
- hero.equipment.equip_item( weapon ) | |
+ hero.equipment.equip_item(weapon) | |
damage_after = hero.get_melee_weapon().damage | |
@@ -13,22 +12,22 @@ def test_weapon_gives_damage(hero, weapon): | |
def test_tooltip_with_name(weapon): | |
- is_in_tooltip = lambda tooltip, search: any([search in val for val in tooltip.values()]) | |
+ def is_in_tooltip(tooltip, search): return any( | |
+ [search in val for val in tooltip.values()]) | |
assert is_in_tooltip(weapon.tooltip_info, str(weapon.name)) | |
def test_tooltip_with_damage(weapon): | |
- is_in_tooltip = lambda tooltip, search : any([search in val for val in tooltip.values()]) | |
+ def is_in_tooltip(tooltip, search): return any( | |
+ [search in val for val in tooltip.values()]) | |
assert is_in_tooltip(weapon.tooltip_info, str(int(weapon.damage.amount))) | |
def test_tooltip_with_durab(weapon): | |
- is_in_tooltip = lambda tooltip, search: any([search in val for val in tooltip.values()]) | |
+ def is_in_tooltip(tooltip, search): return any( | |
+ [search in val for val in tooltip.values()]) | |
assert is_in_tooltip(weapon.tooltip_info, str(weapon.durability)) | |
- | |
- | |
- | |
diff --git a/tests/spells/conftest.py b/tests/spells/conftest.py | |
index 16fb61e..a13c870 100644 | |
--- a/tests/spells/conftest.py | |
+++ b/tests/spells/conftest.py | |
@@ -1,7 +1,7 @@ | |
from mechanics.damage import Damage, DamageTypes | |
from mechanics.events import DamageEvent | |
from cntent.spells import runes | |
-from game_objects.spells import SpellConcept | |
+from game_objects.spells import SpellConcept | |
from character.masteries import MasteriesEnum | |
from mechanics.actives import Cost, Active | |
from game_objects.spells import Rune, SpellAttributes | |
@@ -12,12 +12,16 @@ import pytest | |
@pytest.fixture() | |
def double_damage_rune(): | |
- __double_damage_bonus = Bonus({SpellAttributes.AMOUNT: Attribute(0, 100, 0)}) | |
- __complexity_cost_bonus = Bonus({SpellAttributes.COMPLEXITY: Attribute(0, 0, 20)}) | |
+ __double_damage_bonus = Bonus( | |
+ {SpellAttributes.AMOUNT: Attribute(0, 100, 0)}) | |
+ __complexity_cost_bonus = Bonus( | |
+ {SpellAttributes.COMPLEXITY: Attribute(0, 0, 20)}) | |
- _double_damage_rune = Rune([__double_damage_bonus, __complexity_cost_bonus]) | |
+ _double_damage_rune = Rune( | |
+ [__double_damage_bonus, __complexity_cost_bonus]) | |
return _double_damage_rune | |
+ | |
@pytest.fixture() | |
def lightning_bolt_callback(): | |
def _lightning_bolt_callback(active, unit): | |
@@ -44,12 +48,14 @@ def lightning_concept(lightning_bolt_callback): | |
resolve_callback=lightning_bolt_callback) | |
return concept | |
+ | |
@pytest.fixture() | |
def lightning_spell_dd(lightning_concept): | |
spell = lightning_concept.to_spell([runes.double_damage_rune]) | |
return spell | |
+ | |
@pytest.fixture() | |
def lightning_active(lightning_spell_dd): | |
active = Active.from_spell(lightning_spell_dd) | |
- return active | |
\ No newline at end of file | |
+ return active | |
diff --git a/tests/spells/test_spell_active.py b/tests/spells/test_spell_active.py | |
index 8d13d29..2d87d51 100644 | |
--- a/tests/spells/test_spell_active.py | |
+++ b/tests/spells/test_spell_active.py | |
@@ -1,7 +1,11 @@ | |
from mechanics.events import ActiveEvent | |
-def test_lightning_depends_on_mastery(game_hvsp, pirate_band, hero, lightning_active): | |
+def test_lightning_depends_on_mastery( | |
+ game_hvsp, | |
+ pirate_band, | |
+ hero, | |
+ lightning_active): | |
hero.int_base += -50 | |
pirate = pirate_band[0] | |
@@ -30,7 +34,6 @@ def test_lightning_depends_on_mastery(game_hvsp, pirate_band, hero, lightning_ac | |
hero.masteries.exp_spent[lightning_active.spell.school] += 1e15 | |
hero.activate(lightning_active, pirate) | |
- | |
assert mana_before > hero.mana | |
assert stamina_before > hero.stamina | |
assert readiness_before > hero.readiness | |
@@ -38,7 +41,11 @@ def test_lightning_depends_on_mastery(game_hvsp, pirate_band, hero, lightning_ac | |
assert pirate.health < hp_before | |
-def test_lightning_depends_on_int(hero, game_hvsp, pirate_band, lightning_active): | |
+def test_lightning_depends_on_int( | |
+ hero, | |
+ game_hvsp, | |
+ pirate_band, | |
+ lightning_active): | |
hero.int_base += -50 | |
pirate = pirate_band[0] | |
@@ -70,4 +77,4 @@ def test_lightning_depends_on_int(hero, game_hvsp, pirate_band, lightning_active | |
assert stamina_before > hero.stamina | |
assert readiness_before > hero.readiness | |
- assert pirate.health < hp_before | |
\ No newline at end of file | |
+ assert pirate.health < hp_before | |
diff --git a/tests/triggers/test_interrupts.py b/tests/triggers/test_interrupts.py | |
index cb52eed..e230804 100644 | |
--- a/tests/triggers/test_interrupts.py | |
+++ b/tests/triggers/test_interrupts.py | |
@@ -3,13 +3,14 @@ from mechanics.damage import Damage, DamageTypes | |
from mechanics.events import DamageEvent | |
import pytest | |
+ | |
def test_immortality(game_hvsp, hero): | |
trig = immortality(hero) | |
dmg = Damage(200, DamageTypes.ACID) | |
while hero.health > 0: | |
- DamageEvent(dmg,hero) | |
+ DamageEvent(dmg, hero) | |
assert hero.alive | |
@@ -17,7 +18,8 @@ def test_immortality(game_hvsp, hero): | |
DamageEvent(dmg, hero) | |
assert not hero.alive | |
-@pytest.mark.parametrize("n",[1,3,8]) | |
+ | |
+@pytest.mark.parametrize("n", [1, 3, 8]) | |
def test_undead_n_hits(game_hvsp, hero, n): | |
undead_n_hits(hero, n) | |
@@ -30,16 +32,17 @@ def test_undead_n_hits(game_hvsp, hero, n): | |
DamageEvent(dmg, hero) | |
assert hero.alive | |
- n_left = n-1 | |
+ n_left = n - 1 | |
for _ in range(n_left): | |
DamageEvent(dmg, hero) | |
assert hero.alive | |
- DamageEvent(dmg,hero) | |
+ DamageEvent(dmg, hero) | |
assert not hero.alive | |
-@pytest.mark.parametrize("n",[1,3,8]) | |
+ | |
+@pytest.mark.parametrize("n", [1, 3, 8]) | |
def test_refraction(game_hvsp, hero, n): | |
refraction(hero, n) | |
@@ -47,12 +50,9 @@ def test_refraction(game_hvsp, hero, n): | |
dmg = Damage(200, DamageTypes.FROST) | |
for _ in range(n): | |
- DamageEvent( dmg, hero) | |
+ DamageEvent(dmg, hero) | |
assert hero.health == hero.max_health | |
- DamageEvent( dmg, hero) | |
+ DamageEvent(dmg, hero) | |
assert hero.health < hero.max_health | |
- | |
- | |
- | |
diff --git a/tests/triggers/test_triggers.py b/tests/triggers/test_triggers.py | |
index 36c65da..285558f 100644 | |
--- a/tests/triggers/test_triggers.py | |
+++ b/tests/triggers/test_triggers.py | |
@@ -2,6 +2,7 @@ from cntent.triggers.damage_to_attacker import damage_to_attackers | |
from mechanics.combat import Attack | |
from mechanics.damage import Damage, DamageTypes | |
+ | |
def test_damage_to_attackers(game_hvsp, hero, pirate_band): | |
trig = damage_to_attackers(hero, hero, Damage(15, DamageTypes.FIRE)) | |
for pirate in pirate_band: | |
@@ -17,8 +18,10 @@ def test_damage_to_attackers(game_hvsp, hero, pirate_band): | |
assert [pirate.health for pirate in pirate_band] == health_before | |
-def test_interrupting_damage_to_attackers(game_hvsp, hero, pirate_band, no_chances): | |
- trig = damage_to_attackers(hero, hero, Damage(1500, DamageTypes.LIGHTNING), interrupt=True) | |
+def test_interrupting_damage_to_attackers( | |
+ game_hvsp, hero, pirate_band, no_chances): | |
+ trig = damage_to_attackers(hero, hero, Damage( | |
+ 1500, DamageTypes.LIGHTNING), interrupt=True) | |
for pirate in pirate_band: | |
Attack.melee_attack(pirate, hero) | |
assert not pirate.alive | |
diff --git a/tests/triggers/test_upgrade_hits.py b/tests/triggers/test_upgrade_hits.py | |
index d9cf98b..ef39d2a 100644 | |
--- a/tests/triggers/test_upgrade_hits.py | |
+++ b/tests/triggers/test_upgrade_hits.py | |
@@ -5,7 +5,7 @@ from mechanics.events import DamageEvent | |
import pytest | |
-@pytest.mark.parametrize("n",[1,3,8]) | |
+@pytest.mark.parametrize("n", [1, 3, 8]) | |
def test_undead_n_hits(game_hvsp, hero, n): | |
trig = upgrade_hits(hero, n) | |
@@ -23,4 +23,3 @@ def test_undead_n_hits(game_hvsp, hero, n): | |
DamageEvent(dmg, hero, source=hero, impact_factor=ImpactFactor.HIT) | |
hp_after = hero.health | |
assert hp_before - hp_after <= damage_amount | |
- | |
diff --git a/tests/triggers/test_xp.py b/tests/triggers/test_xp.py | |
index d40f3e1..ea64572 100644 | |
--- a/tests/triggers/test_xp.py | |
+++ b/tests/triggers/test_xp.py | |
@@ -3,7 +3,6 @@ from mechanics.events.combat.DamageEvent import DamageEvent | |
from mechanics.damage import DamageTypes, Damage | |
- | |
def test_gain_xp_by_kill(game_hvsp, hero, pirate_band): | |
exp_rule(game_hvsp) | |
@@ -49,4 +48,4 @@ def test_no_xp_foreign_kill(game_hvsp, hero, pirate_band): | |
xp_after = hero.xp | |
- assert xp_after == xp_before | |
\ No newline at end of file | |
+ assert xp_after == xp_before | |
diff --git a/tests/turns/test_atb.py b/tests/turns/test_atb.py | |
index 13a965f..1aa1cce 100644 | |
--- a/tests/turns/test_atb.py | |
+++ b/tests/turns/test_atb.py | |
@@ -1,21 +1,22 @@ | |
from mechanics.turns.AtbTurnsManager import AtbTurnsManager | |
+ | |
def test_different_units(empty_game, hero, pirate): | |
- empty_game.add_unit(hero, 1+1j) | |
- empty_game.add_unit(pirate, 2+1j) | |
+ empty_game.add_unit(hero, 1 + 1j) | |
+ empty_game.add_unit(pirate, 2 + 1j) | |
atm = empty_game.turns_manager | |
units_returned = set() | |
- | |
for i in range(10): | |
unit = atm.get_next() | |
unit.readiness = 0 | |
- units_returned.add( unit) | |
+ units_returned.add(unit) | |
assert hero in units_returned | |
assert pirate in units_returned | |
+ | |
def test_readiness_defines_turn(empty_game, hero, pirate): | |
empty_game.add_unit(hero, 1 + 1j) | |
empty_game.add_unit(pirate, 2 + 1j) | |
@@ -31,6 +32,7 @@ def test_readiness_defines_turn(empty_game, hero, pirate): | |
assert atm.get_next() is hero | |
+ | |
def test_cycles_well(empty_game, hero, pirate): | |
empty_game.add_unit(hero, 1 + 1j) | |
empty_game.add_unit(pirate, 2 + 1j) | |
@@ -46,6 +48,7 @@ def test_cycles_well(empty_game, hero, pirate): | |
assert units_returned.count(hero) > 1 | |
assert units_returned.count(pirate) > 1 | |
+ | |
def test_disabled(empty_game, hero, pirate): | |
empty_game.add_unit(hero, 1 + 1j) | |
empty_game.add_unit(pirate, 2 + 1j) | |
diff --git a/tests/turns/test_buffs_expire.py b/tests/turns/test_buffs_expire.py | |
index 66d8695..2fc366a 100644 | |
--- a/tests/turns/test_buffs_expire.py | |
+++ b/tests/turns/test_buffs_expire.py | |
@@ -41,12 +41,10 @@ def test_buffs_do_not_stop_units(game_hvsp, hero): | |
assert isinstance(atm, AtbTurnsManager) | |
for dur in range(0, 50): | |
- buff = Buff(dur/10) | |
+ buff = Buff(dur / 10) | |
BuffAppliedEvent(buff, hero) | |
for i in range(10): | |
unit = atm.get_next() | |
assert isinstance(unit, Unit) | |
unit.readiness = 0 | |
- | |
- | |
diff --git a/tests/turns/test_regen.py b/tests/turns/test_regen.py | |
index 0a7d4c4..457865c 100644 | |
--- a/tests/turns/test_regen.py | |
+++ b/tests/turns/test_regen.py | |
@@ -1,10 +1,12 @@ | |
+from cntent.monsters.undead import zombie | |
+ | |
+ | |
def test_regen(game_hvsp, hero): | |
assert hero in game_hvsp.turns_manager.managed | |
assert hero in game_hvsp.units | |
- | |
hero.health -= 100 | |
hero.mana -= 100 | |
hero.stamina -= 100 | |
@@ -13,7 +15,6 @@ def test_regen(game_hvsp, hero): | |
mana_before = hero.mana | |
stamina_before = hero.stamina | |
- | |
game_hvsp.turns_manager.pass_time(3) | |
assert hero.health > health_before | |
@@ -25,22 +26,18 @@ def test_bleeding(game_hvsp, hero): | |
assert hero in game_hvsp.turns_manager.managed | |
assert hero in game_hvsp.units | |
- | |
hero.health -= 0.75 * hero.health | |
health_before = hero.health | |
- | |
game_hvsp.turns_manager.pass_time(3) | |
assert hero.health < health_before | |
-from cntent.monsters.undead import zombie | |
- | |
def test_undead_no_regen(empty_game): | |
zomb = zombie.create(empty_game) | |
- empty_game.add_unit(zomb, 1+1j, None) | |
+ empty_game.add_unit(zomb, 1 + 1j, None) | |
zomb.health -= 100 | |
health_before = zomb.health | |
@@ -54,4 +51,4 @@ def test_undead_no_regen(empty_game): | |
empty_game.turns_manager.pass_time(3) | |
- assert zomb.health == health_before | |
\ No newline at end of file | |
+ assert zomb.health == health_before | |
diff --git a/tests/ui/GamePages/xml/test_xml_engine.py b/tests/ui/GamePages/xml/test_xml_engine.py | |
index dbc6265..451d6d1 100644 | |
--- a/tests/ui/GamePages/xml/test_xml_engine.py | |
+++ b/tests/ui/GamePages/xml/test_xml_engine.py | |
@@ -11,15 +11,18 @@ def read_tree(start_node): | |
node = queue.pop() # извлечь первый элемент в очереди | |
name = node.attrib.get('name') | |
if name is not None: | |
- res += name + '\n' | |
+ res += name + '\n' | |
for child in node: # все преемники текущего узла, ... | |
if not visited[child]: # ... которые ещё не были посещены ... | |
- queue.append(child) # ... добавить в конец очереди... | |
- visited[child] = True # ... и пометить как посещённые | |
+ # ... добавить в конец очереди... | |
+ queue.append(child) | |
+ # ... и пометить как посещённые | |
+ visited[child] = True | |
return res | |
+ | |
OUTPUT = \ | |
-"""a_4 | |
+ """a_4 | |
a_4_b_2 | |
a_4_b_2_c_1 | |
a_4_b_1 | |
@@ -48,6 +51,7 @@ a_1_b_2_c_1 | |
a_1_b_1 | |
""" | |
+ | |
def test_read_tree(): | |
from xml.etree import ElementTree as ET | |
data_as_string = """<?xml version="1.0" encoding="UTF-8" ?> | |
diff --git a/tests/ui/GameWorld/test_TileItem.py b/tests/ui/GameWorld/test_TileItem.py | |
index 996aefc..5c5868d 100644 | |
--- a/tests/ui/GameWorld/test_TileItem.py | |
+++ b/tests/ui/GameWorld/test_TileItem.py | |
@@ -1,13 +1,15 @@ | |
from ui.GameWorld.TileItem import TileItem | |
from battlefield.Cell import Cell | |
-def init_map(tile_map:TileItem, cells): | |
+ | |
+def init_map(tile_map: TileItem, cells): | |
for cell in cells: | |
tile_map.add_cell(0, cell) | |
+ | |
def test_calculate_bound(): | |
- points_1 = [Cell(1,1),Cell(1,0), Cell(0,1), Cell(0,2)] | |
- points_2 = [Cell(1,1),Cell(0,0), Cell(0,1), Cell(1,2)] | |
+ points_1 = [Cell(1, 1), Cell(1, 0), Cell(0, 1), Cell(0, 2)] | |
+ points_2 = [Cell(1, 1), Cell(0, 0), Cell(0, 1), Cell(1, 2)] | |
cell_1 = Cell(0, 0) | |
cell_2 = Cell(1, 2) | |
diff --git a/tests/ui/test_BasicUnit.py b/tests/ui/test_BasicUnit.py | |
index 83dab43..4320a6c 100644 | |
--- a/tests/ui/test_BasicUnit.py | |
+++ b/tests/ui/test_BasicUnit.py | |
@@ -21,7 +21,10 @@ class TestBasicUnit(UsesQApp): | |
self.unit_list = [self.unit_a, self.unit_b, self.unit_c] | |
self.unit_set = {self.unit_a, self.unit_b, self.unit_c} | |
- self.unit_dict = {self.unit_a:self.unit_a.worldPos, self.unit_b:self.unit_b.worldPos, self.unit_c:self.unit_c.worldPos} | |
+ self.unit_dict = { | |
+ self.unit_a: self.unit_a.worldPos, | |
+ self.unit_b: self.unit_b.worldPos, | |
+ self.unit_c: self.unit_c.worldPos} | |
pass | |
def test_first(self): | |
@@ -57,4 +60,3 @@ class TestBasicUnit(UsesQApp): | |
if __name__ == '__main__': | |
unittest.main() | |
- | |
diff --git a/tests/ui/test_UnitsHeap.py b/tests/ui/test_UnitsHeap.py | |
index f2d631d..d823db3 100644 | |
--- a/tests/ui/test_UnitsHeap.py | |
+++ b/tests/ui/test_UnitsHeap.py | |
@@ -20,7 +20,11 @@ class TestBasicUnit(UsesQApp): | |
def setUp(self): | |
super(TestBasicUnit, self).setUp() | |
- pic_path = path.join(pydolons_rootdir, 'resources', 'icons','default_128.png') | |
+ pic_path = path.join( | |
+ pydolons_rootdir, | |
+ 'resources', | |
+ 'icons', | |
+ 'default_128.png') | |
pixmap = QtGui.QPixmap(pic_path) | |
self.unit_a = self.getUnit(2, 1, 32, pixmap) | |
self.unit_b = self.getUnit(2, 1, 13, pixmap) | |
@@ -79,4 +83,3 @@ class TestBasicUnit(UsesQApp): | |
if __name__ == '__main__': | |
unittest.main() | |
- | |
diff --git a/tests/ui/test_attack_obstacle.py b/tests/ui/test_attack_obstacle.py | |
index 73d62a4..a9869d8 100644 | |
--- a/tests/ui/test_attack_obstacle.py | |
+++ b/tests/ui/test_attack_obstacle.py | |
@@ -1,16 +1,17 @@ | |
from mechanics.events import DamageEvent | |
+ | |
def test_move_into_obstacle_attack(empty_game, hero, obstacle, no_chances): | |
- empty_game.add_unit(hero, 1+1j, facing=1) | |
- empty_game.add_obstacle(obstacle, 2+1j) | |
+ empty_game.add_unit(hero, 1 + 1j, facing=1) | |
+ empty_game.add_obstacle(obstacle, 2 + 1j) | |
empty_game.the_hero = hero | |
hero.readiness = 1 | |
spy = empty_game.events_platform.collect_history() | |
- empty_game.ui_order(2,1) | |
+ empty_game.ui_order(2, 1) | |
damage_event_present = False | |
for event, happened in spy: | |
diff --git a/tests/ui/test_std_movements.py b/tests/ui/test_std_movements.py | |
index e599b0f..6cbf054 100644 | |
--- a/tests/ui/test_std_movements.py | |
+++ b/tests/ui/test_std_movements.py | |
@@ -4,14 +4,17 @@ from battlefield.Facing import Facing | |
from battlefield.Battlefield import Cell | |
import pytest | |
+ | |
@pytest.fixture() | |
def collect_events(hero_only_game): | |
events = [] | |
hero_only_game.events_platform.process_event = lambda x: events.append(x) | |
yield events | |
+ | |
facings = [Facing.NORTH, Facing.EAST, Facing.SOUTH, Facing.WEST] | |
+ | |
def check_contains_right_action_and_cell(collect_events, action, cell): | |
activated = False | |
assert collect_events | |
@@ -23,6 +26,7 @@ def check_contains_right_action_and_cell(collect_events, action, cell): | |
assert activated | |
+ | |
@pytest.mark.parametrize("facing", facings) | |
def test_can_move_forward(hero_only_game, hero, collect_events, facing): | |
pos = hero.cell | |
@@ -31,8 +35,8 @@ def test_can_move_forward(hero_only_game, hero, collect_events, facing): | |
target_cell = Cell.from_complex(pos.complex + facing) | |
hero_only_game.ui_order(target_cell.x, target_cell.y) | |
- check_contains_right_action_and_cell(collect_events, move_forward, target_cell) | |
- | |
+ check_contains_right_action_and_cell( | |
+ collect_events, move_forward, target_cell) | |
@pytest.mark.parametrize("facing", facings) | |
@@ -44,8 +48,8 @@ def test_can_move_back(hero_only_game, hero, collect_events, facing): | |
hero_only_game.ui_order(target_cell.x, target_cell.y) | |
- check_contains_right_action_and_cell(collect_events, move_back, target_cell) | |
- | |
+ check_contains_right_action_and_cell( | |
+ collect_events, move_back, target_cell) | |
@pytest.mark.parametrize("facing", facings) | |
@@ -57,8 +61,8 @@ def test_can_move_left(hero_only_game, hero, collect_events, facing): | |
hero_only_game.ui_order(target_cell.x, target_cell.y) | |
- check_contains_right_action_and_cell(collect_events, move_side, target_cell) | |
- | |
+ check_contains_right_action_and_cell( | |
+ collect_events, move_side, target_cell) | |
@pytest.mark.parametrize("facing", facings) | |
@@ -70,7 +74,8 @@ def test_can_move_right(hero_only_game, hero, collect_events, facing): | |
hero_only_game.ui_order(target_cell.x, target_cell.y) | |
- check_contains_right_action_and_cell(collect_events, move_side, target_cell) | |
+ check_contains_right_action_and_cell( | |
+ collect_events, move_side, target_cell) | |
@pytest.mark.parametrize("facing", facings) | |
@@ -79,9 +84,10 @@ def test_can_move_diag_left(hero_only_game, hero, collect_events, facing): | |
pos = hero.cell | |
hero.facing = facing | |
- target_cell = Cell.from_complex(pos.complex + facing * (1+1j) ) | |
+ target_cell = Cell.from_complex(pos.complex + facing * (1 + 1j)) | |
hero_only_game.ui_order(target_cell.x, target_cell.y) | |
- check_contains_right_action_and_cell(collect_events, move_diag, target_cell) | |
+ check_contains_right_action_and_cell( | |
+ collect_events, move_diag, target_cell) | |
@pytest.mark.parametrize("facing", facings) | |
@@ -91,8 +97,5 @@ def test_can_move_diag_right(hero_only_game, hero, collect_events, facing): | |
target_cell = Cell.from_complex(pos.complex + facing * (1 - 1j)) | |
hero_only_game.ui_order(target_cell.x, target_cell.y) | |
- check_contains_right_action_and_cell(collect_events, move_diag, target_cell) | |
- | |
- | |
- | |
- | |
+ check_contains_right_action_and_cell( | |
+ collect_events, move_diag, target_cell) | |
diff --git a/ui/GameAnimation/AnimatedItem.py b/ui/GameAnimation/AnimatedItem.py | |
index 3b4f4ef..9962267 100644 | |
--- a/ui/GameAnimation/AnimatedItem.py | |
+++ b/ui/GameAnimation/AnimatedItem.py | |
@@ -6,7 +6,7 @@ from random import randint | |
class AnimatedItem(QtCore.QObject, GameObject): | |
animationFinished = QtCore.Signal() | |
- def __init__(self, *arg, gameconfig, parent = None): | |
+ def __init__(self, *arg, gameconfig, parent=None): | |
QtCore.QObject.__init__(self, parent) | |
GameObject.__init__(self, *arg) | |
self.cfg = gameconfig | |
@@ -45,8 +45,8 @@ class AnimatedItem(QtCore.QObject, GameObject): | |
else: | |
self.current_index = 0 | |
self.setPixmap(self.picmaps[self.current_index]) | |
- if framerate > 0 : | |
- self.m_timer.setInterval(1000/framerate) | |
+ if framerate > 0: | |
+ self.m_timer.setInterval(1000 / framerate) | |
self.m_timer.start() | |
def on_timerTick(self): | |
@@ -62,7 +62,3 @@ class AnimatedItem(QtCore.QObject, GameObject): | |
self.animationFinished.emit() | |
else: | |
self.setPixmap(self.picmaps[self.current_index]) | |
- | |
- | |
- | |
- | |
diff --git a/ui/GameAnimation/Animations.py b/ui/GameAnimation/Animations.py | |
index 93504f2..0db3c37 100644 | |
--- a/ui/GameAnimation/Animations.py | |
+++ b/ui/GameAnimation/Animations.py | |
@@ -28,13 +28,9 @@ class Animations: | |
self.setRotation(angel) | |
""" | |
- | |
@staticmethod | |
def getDirectionAnim(target): | |
animation = QtCore.QPropertyAnimation(target, b'angle') | |
animation.setDuration(500) | |
animation.valueChanged.connect(target.setQAngle) | |
return animation | |
- | |
- | |
- | |
diff --git a/ui/GameAnimation/GameVariantAnimation.py b/ui/GameAnimation/GameVariantAnimation.py | |
index a9a080d..dd5d288 100644 | |
--- a/ui/GameAnimation/GameVariantAnimation.py | |
+++ b/ui/GameAnimation/GameVariantAnimation.py | |
@@ -2,10 +2,9 @@ from PySide2.QtCore import QVariantAnimation | |
class GameVariantAnimation(QVariantAnimation): | |
- DURATION_BASIC = 500 | |
- DURATION_UNIT_MOVE = 300 | |
- | |
- def __init__(self, parent): | |
- super(GameVariantAnimation, self).__init__(parent) | |
- self.setDuration(self.DURATION_BASIC) | |
+ DURATION_BASIC = 500 | |
+ DURATION_UNIT_MOVE = 300 | |
+ def __init__(self, parent): | |
+ super(GameVariantAnimation, self).__init__(parent) | |
+ self.setDuration(self.DURATION_BASIC) | |
diff --git a/ui/GameAnimation/SmoothAnimation.py b/ui/GameAnimation/SmoothAnimation.py | |
index c7fcd03..2684072 100644 | |
--- a/ui/GameAnimation/SmoothAnimation.py | |
+++ b/ui/GameAnimation/SmoothAnimation.py | |
@@ -11,7 +11,12 @@ class SmoothAnimation: | |
Для использования класса необходимо указать слот изменения контроллируемого аттрибута, | |
например QObject.setRotation для угра поворота. Дальше достаточно просто вызывать play_anim(start, end) | |
""" | |
- def __init__(self, target, slot, basic_duration = GameVariantAnimation.DURATION_BASIC): | |
+ | |
+ def __init__( | |
+ self, | |
+ target, | |
+ slot, | |
+ basic_duration=GameVariantAnimation.DURATION_BASIC): | |
self.basic_duration = basic_duration | |
self.anim = GameVariantAnimation(target) | |
@@ -24,7 +29,8 @@ class SmoothAnimation: | |
if state == QtCore.QAbstractAnimation.Stopped: | |
if self.queue: | |
start, end = self.queue.popleft() | |
- self.anim.setDuration(self.basic_duration / (2 + len(self.queue))) | |
+ self.anim.setDuration( | |
+ self.basic_duration / (2 + len(self.queue))) | |
self.anim.setStartValue(start) | |
self.anim.setEndValue(end) | |
self.anim.start() | |
diff --git a/ui/GameAnimation/__init__.py b/ui/GameAnimation/__init__.py | |
index 80b9f97..c59b9ae 100644 | |
--- a/ui/GameAnimation/__init__.py | |
+++ b/ui/GameAnimation/__init__.py | |
@@ -2,4 +2,3 @@ from ui.GameAnimation.Animations import Animations | |
from ui.GameAnimation.SmoothAnimation import SmoothAnimation | |
from ui.GameAnimation.objects.Direction import Direction | |
from ui.GameAnimation.GameVariantAnimation import GameVariantAnimation | |
- | |
diff --git a/ui/GameAnimation/objects/Direction.py b/ui/GameAnimation/objects/Direction.py | |
index bc81ad2..255adfa 100644 | |
--- a/ui/GameAnimation/objects/Direction.py | |
+++ b/ui/GameAnimation/objects/Direction.py | |
@@ -1,8 +1,9 @@ | |
from PySide2 import QtCore, QtWidgets | |
+ | |
class Direction(QtCore.QObject, QtWidgets.QGraphicsPixmapItem): | |
"""docstring for .""" | |
- def __init__(self, parent = None): | |
+ | |
+ def __init__(self, parent=None): | |
QtCore.QObject.__init__(self, parent) | |
QtWidgets.QGraphicsPixmapItem.__init__(self, parent) | |
- | |
diff --git a/ui/GameController.py b/ui/GameController.py | |
index 3a8841e..ce3ccfc 100644 | |
--- a/ui/GameController.py | |
+++ b/ui/GameController.py | |
@@ -20,7 +20,7 @@ class GameController(QtCore.QObject): | |
""" | |
self.gameRoot = None | |
self.tr = QtGui.QTransform() | |
- self.tr_support:TransformSupport = None | |
+ self.tr_support: TransformSupport = None | |
self.cursor = QtWidgets.QGraphicsEllipseItem(-10, -10, 20, 20) | |
@@ -29,7 +29,6 @@ class GameController(QtCore.QObject): | |
self.lost_m_pos = QtCore.QPoint() | |
self.r_mouse = False | |
- | |
def setGameRoot(self, gameRoot): | |
self.tr_support = TransformSupport(gameRoot) | |
gameRoot.view.resized.connect(self.tr_support.resized) | |
@@ -67,10 +66,13 @@ class GameController(QtCore.QObject): | |
self.r_mouse = True | |
try: | |
if not self.gameRoot.gamePages.isGamePage: | |
- if self.tr_support.floor_rect.contains(self.lost_m_pos.x(), self.lost_m_pos.y()): | |
- self.gameRoot.game.ui_order(self.last_point.x, self.last_point.y) | |
+ if self.tr_support.floor_rect.contains( | |
+ self.lost_m_pos.x(), self.lost_m_pos.y()): | |
+ self.gameRoot.game.ui_order( | |
+ self.last_point.x, self.last_point.y) | |
self.selected_point.x, self.selected_point.y = self.last_point.x, self.last_point.y | |
- self.middleLayer.showSelectedItem(self.selected_point.x, self.selected_point.y) | |
+ self.middleLayer.showSelectedItem( | |
+ self.selected_point.x, self.selected_point.y) | |
except PydolonsError as exc: | |
UiErrorMessageEvent(self.gameRoot.game, repr(exc)) | |
@@ -122,8 +124,16 @@ class GameController(QtCore.QObject): | |
self.gameRoot.gameMenu.setDefaultPos() | |
def itemSelect(self, pos): | |
- x = int((pos.x() - self.tr_support.tr.m31() - self.world.pos().x()) / self.gameRoot.cfg.unit_size[0]) | |
- y = int((pos.y() - self.tr_support.tr.m32() - self.world.pos().y()) / self.gameRoot.cfg.unit_size[1]) | |
+ x = int( | |
+ (pos.x() - | |
+ self.tr_support.tr.m31() - | |
+ self.world.pos().x()) / | |
+ self.gameRoot.cfg.unit_size[0]) | |
+ y = int( | |
+ (pos.y() - | |
+ self.tr_support.tr.m32() - | |
+ self.world.pos().y()) / | |
+ self.gameRoot.cfg.unit_size[1]) | |
self.last_point.x, self.last_point.y = x, y | |
self.middleLayer.selectItem(x, y) | |
@@ -150,4 +160,3 @@ class GameController(QtCore.QObject): | |
self.tr_support.setMovableMaps() | |
if self.middleLayer.targeted: | |
self.middleLayer.removeTargets() | |
- | |
diff --git a/ui/GamePages/AbstractPage.py b/ui/GamePages/AbstractPage.py | |
index 621eded..65da966 100644 | |
--- a/ui/GamePages/AbstractPage.py | |
+++ b/ui/GamePages/AbstractPage.py | |
@@ -14,9 +14,9 @@ if TYPE_CHECKING: | |
class AbstractPage(QtCore.QObject, QtWidgets.QGraphicsItemGroup): | |
"""docstring for AbstractPage.""" | |
focusable = QtCore.Signal(bool) | |
- ITEM_TYPES = {'other':BaseItem, 'text':TextItem, 'group':GroupItem} | |
+ ITEM_TYPES = {'other': BaseItem, 'text': TextItem, 'group': GroupItem} | |
- def __init__(self, gamePages, parent = None): | |
+ def __init__(self, gamePages, parent=None): | |
QtCore.QObject.__init__(self, parent) | |
QtWidgets.QGraphicsItemGroup.__init__(self) | |
# super(AbstractPage, self).__init__() | |
@@ -24,11 +24,11 @@ class AbstractPage(QtCore.QObject, QtWidgets.QGraphicsItemGroup): | |
self.items = {} | |
self.widget_pos = QtCore.QPoint() | |
self.setFlag(QtWidgets.QGraphicsItem.ItemIgnoresTransformations, True) | |
- self.gamePages:GamePages = gamePages | |
+ self.gamePages: GamePages = gamePages | |
self.state = False | |
self.isService = False | |
- def read_tree(self, start_node = None): | |
+ def read_tree(self, start_node=None): | |
if start_node is None: | |
start_node = self.xml_page | |
visited = {} # изначально список посещённых узлов пуст | |
@@ -41,11 +41,12 @@ class AbstractPage(QtCore.QObject, QtWidgets.QGraphicsItemGroup): | |
node = queue.pop() # извлечь первый элемент в очереди | |
self.create_item(node) | |
# if node == goal_node: | |
- # return True # проверить, не является ли текущий узел целевым | |
+ # return True # проверить, не является ли | |
+ # текущий узел целевым | |
for child in node: # все преемники текущего узла, ... | |
if not visited[child]: # ... которые ещё не были посещены ... | |
if self.check_attr(node.attrib): | |
- child.attrib['parent_node']=node.attrib['name'] | |
+ child.attrib['parent_node'] = node.attrib['name'] | |
queue.append(child) # ... добавить в конец очереди... | |
visited[child] = True # ... и пометить как посещённые | |
@@ -70,9 +71,9 @@ class AbstractPage(QtCore.QObject, QtWidgets.QGraphicsItemGroup): | |
def readXML(self, name): | |
tree = self.gamePages.gameRoot.cfg.getXML_Page(name) | |
- self.xml_page:ET.Element = tree.getroot() | |
+ self.xml_page: ET.Element = tree.getroot() | |
- def find_element(self, start_node, name = None, func = None): | |
+ def find_element(self, start_node, name=None, func=None): | |
def plug(node): | |
pass | |
if func is None: | |
@@ -99,19 +100,21 @@ class AbstractPage(QtCore.QObject, QtWidgets.QGraphicsItemGroup): | |
for k, v in data.items(): | |
result = result + k + ' : ' + v + '\n' | |
return result | |
- | |
+ | |
@abstractmethod | |
def setUp(self): | |
""" | |
Устанавливаем настройки страницы | |
""" | |
pass | |
+ | |
@abstractmethod | |
def showPage(self): | |
""" | |
Показать страницу | |
""" | |
pass | |
+ | |
@abstractmethod | |
def updatePage(self): | |
""" | |
@@ -159,15 +162,14 @@ class AbstractPage(QtCore.QObject, QtWidgets.QGraphicsItemGroup): | |
if w_screen > w_pic: | |
prec = w_pic / w_screen | |
else: | |
- prec = w_screen /w_pic | |
+ prec = w_screen / w_pic | |
background.setScale(prec) | |
- x = (self.gamePages.gameRoot.cfg.dev_size[0] - self.background.boundingRect().width() * prec) / 2 | |
- y = (self.gamePages.gameRoot.cfg.dev_size[1] - self.background.boundingRect().height() * prec) / 2 | |
+ x = (self.gamePages.gameRoot.cfg.dev_size[0] - | |
+ self.background.boundingRect().width() * prec) / 2 | |
+ y = (self.gamePages.gameRoot.cfg.dev_size[1] - | |
+ self.background.boundingRect().height() * prec) / 2 | |
background.setPos(x, y) | |
def updatePos(self): | |
""" update position for scale view""" | |
self.setPos(self.gamePages.gameRoot.view.mapToScene(0, 0)) | |
- | |
- | |
- | |
diff --git a/ui/GamePages/BackGorundPage.py b/ui/GamePages/BackGorundPage.py | |
index d717fc9..2bc7b0a 100644 | |
--- a/ui/GamePages/BackGorundPage.py | |
+++ b/ui/GamePages/BackGorundPage.py | |
@@ -5,6 +5,7 @@ from ui.GamePages import AbstractPage | |
class BackGorundPage(AbstractPage): | |
"""docstring for StartPage.""" | |
+ | |
def __init__(self, gamePages): | |
super().__init__(gamePages) | |
self.state = True | |
@@ -13,11 +14,12 @@ class BackGorundPage(AbstractPage): | |
self.gamePages.gameRoot.view.wheel_change.connect(self.updatePos) | |
def setUpWidgets(self): | |
- self.background = QtWidgets.QGraphicsPixmapItem(self.gamePages.gameRoot.cfg.getPicFile('dungeon.jpg')) | |
+ self.background = QtWidgets.QGraphicsPixmapItem( | |
+ self.gamePages.gameRoot.cfg.getPicFile('dungeon.jpg')) | |
self.resizeBackground(self.background) | |
self.addToGroup(self.background) | |
def resized(self): | |
super().resized() | |
self.resizeBackground(self.background) | |
- pass | |
\ No newline at end of file | |
+ pass | |
diff --git a/ui/GamePages/GameMenuPage.py b/ui/GamePages/GameMenuPage.py | |
index d570c35..649db24 100644 | |
--- a/ui/GamePages/GameMenuPage.py | |
+++ b/ui/GamePages/GameMenuPage.py | |
@@ -9,6 +9,7 @@ from ui.GamePages import AbstractPage | |
class GameMenuPage(AbstractPage): | |
"""docstring for ScreenMenu.""" | |
+ | |
def __init__(self, gamePages): | |
super(GameMenuPage, self).__init__(gamePages) | |
self.gui_console = None | |
@@ -19,9 +20,11 @@ class GameMenuPage(AbstractPage): | |
def setUpGui(self): | |
self.actives = Actives(self, columns=6) | |
- self.actives.setTargets.connect(self.gamePages.gameRoot.level.middleLayer.getTargets) | |
+ self.actives.setTargets.connect( | |
+ self.gamePages.gameRoot.level.middleLayer.getTargets) | |
- self.gamePages.gameRoot.controller.mouseMove.connect(self.actives.mouseMoveEvent) | |
+ self.gamePages.gameRoot.controller.mouseMove.connect( | |
+ self.actives.mouseMoveEvent) | |
self.unitStack = QtWidgets.QGraphicsRectItem(self) | |
self.unitStack.setBrush(QtCore.Qt.blue) | |
@@ -30,18 +33,21 @@ class GameMenuPage(AbstractPage): | |
w_u = int(64 * self.gamePages.gameRoot.cfg.scale_x) | |
self.active_select = GameObject() | |
- self.active_select.setPixmap(self.gamePages.gameRoot.cfg.getPicFile('active select 96.png').scaled(w_u, w_u)) | |
+ self.active_select.setPixmap(self.gamePages.gameRoot.cfg.getPicFile( | |
+ 'active select 96.png').scaled(w_u, w_u)) | |
self.active_select.setParentItem(self.unitStack) | |
self.active_select.setPos(self.unitStack.x(), self.unitStack.y()) | |
- if not self.gamePages.gameRoot.level is None: | |
+ if self.gamePages.gameRoot.level is not None: | |
self.createUnitStack() | |
self.updateUnitStack() | |
- sup_panel = SupportPanel(page=self, gameconfig=self.gamePages.gameRoot.cfg) | |
+ sup_panel = SupportPanel( | |
+ page=self, gameconfig=self.gamePages.gameRoot.cfg) | |
sup_panel.setUpWidgets() | |
self.sup_panel = self.gamePages.gameRoot.scene.addWidget(sup_panel) | |
- self.sup_panel.setFlags(QtWidgets.QGraphicsItem.ItemIgnoresTransformations) | |
+ self.sup_panel.setFlags( | |
+ QtWidgets.QGraphicsItem.ItemIgnoresTransformations) | |
self.updadteSupPanlePos() | |
def createUnitStack(self): | |
@@ -64,14 +70,20 @@ class GameMenuPage(AbstractPage): | |
self.gui_console = GuiConsole(self.gamePages.gameRoot.game.gamelog) | |
self.gui_console.id = self.gui_console.startTimer(50) | |
self.gui_console.setTabChangesFocus(False) | |
- self.gui_console.resize(320 * self.gamePages.gameRoot.cfg.scale_x, 240 * self.gamePages.gameRoot.cfg.scale_y) | |
- self.gamePages.gameRoot.controller.mouseMove.connect(self.gui_console.setMousePos) | |
+ self.gui_console.resize( | |
+ 320 * self.gamePages.gameRoot.cfg.scale_x, | |
+ 240 * self.gamePages.gameRoot.cfg.scale_y) | |
+ self.gamePages.gameRoot.controller.mouseMove.connect( | |
+ self.gui_console.setMousePos) | |
self.gui_console.btn.clicked.connect(self.updateGuiConsolePos) | |
self.p_gui_console = self.scene().addWidget(self.gui_console) | |
- self.p_gui_console.setFlags(QtWidgets.QGraphicsItem.ItemIgnoresTransformations) | |
+ self.p_gui_console.setFlags( | |
+ QtWidgets.QGraphicsItem.ItemIgnoresTransformations) | |
def updateGuiConsolePos(self): | |
- self.p_gui_console.setPos(self.gamePages.gameRoot.view.mapToScene(self.gui_console.widget_pos)) | |
+ self.p_gui_console.setPos( | |
+ self.gamePages.gameRoot.view.mapToScene( | |
+ self.gui_console.widget_pos)) | |
def rmToUnitStack(self, uid): | |
self.unitStack.items[uid].setParentItem(None) | |
@@ -85,13 +97,18 @@ class GameMenuPage(AbstractPage): | |
self.unitStack.rect().setWidth(w * w_u) | |
i = 0 | |
for bf_unit in units_stack: | |
- self.unitStack.items[bf_unit.uid].setPos(self.unitStack.x() + i * w_u, self.unitStack.y()) | |
+ self.unitStack.items[bf_unit.uid].setPos( | |
+ self.unitStack.x() + i * w_u, self.unitStack.y()) | |
i += 1 | |
def setDefaultPos(self): | |
# TODO setDefaultPos is deprecated method, delete in future. | |
- pos = self.scene().views()[0].mapToScene(self.gamePages.gameRoot.cfg.correct_size[0], self.gamePages.gameRoot.cfg.correct_size[1]) | |
- self.gui_console.move(self.gui_console.x() + pos.x(), self.gui_console.y() + pos.y()) | |
+ pos = self.scene().views()[0].mapToScene( | |
+ self.gamePages.gameRoot.cfg.correct_size[0], | |
+ self.gamePages.gameRoot.cfg.correct_size[1]) | |
+ self.gui_console.move( | |
+ self.gui_console.x() + pos.x(), | |
+ self.gui_console.y() + pos.y()) | |
self.setX(pos.x()) | |
self.setY(pos.y()) | |
@@ -122,11 +139,12 @@ class GameMenuPage(AbstractPage): | |
self.updadteSupPanlePos() | |
def upateActivesPos(self): | |
- self.actives.mainWidget.setPos(self.gamePages.gameRoot.view.mapToScene(self.actives.x, self.actives.y)) | |
+ self.actives.mainWidget.setPos( | |
+ self.gamePages.gameRoot.view.mapToScene( | |
+ self.actives.x, self.actives.y)) | |
def updadteSupPanlePos(self): | |
- self.sup_panel.setPos(self.gamePages.gameRoot.view.mapToScene(self.sup_panel.widget().widget_x, \ | |
- self.sup_panel.widget().widget_y)) | |
- | |
- | |
- | |
+ self.sup_panel.setPos( | |
+ self.gamePages.gameRoot.view.mapToScene( | |
+ self.sup_panel.widget().widget_x, | |
+ self.sup_panel.widget().widget_y)) | |
diff --git a/ui/GamePages/GamePages.py b/ui/GamePages/GamePages.py | |
index 607829c..aba93a6 100644 | |
--- a/ui/GamePages/GamePages.py | |
+++ b/ui/GamePages/GamePages.py | |
@@ -25,16 +25,17 @@ if TYPE_CHECKING: | |
class GamePages(object): | |
"""docstring for GamePages.""" | |
+ | |
def __init__(self): | |
super(GamePages, self).__init__() | |
- self.gameRoot:GameRootNode = None | |
+ self.gameRoot: GameRootNode = None | |
# this is current page | |
self.focusState = False | |
- self.page:AbstractPage = None | |
+ self.page: AbstractPage = None | |
self.focus = False | |
# init pages | |
self.pages = {} | |
- self.gameMenu:GameMenuPage = None | |
+ self.gameMenu: GameMenuPage = None | |
self.visiblePage = True | |
def setGameRoot(self, gameRoot): | |
@@ -51,7 +52,7 @@ class GamePages(object): | |
def destroyPages(self): | |
pages = list(self.pages.values())[:] | |
keys = list(self.pages.keys())[:] | |
- i =0 | |
+ i = 0 | |
for page in pages: | |
if not page.isService: | |
page.destroy() | |
@@ -71,14 +72,16 @@ class GamePages(object): | |
def setUpStartPage(self, ui): | |
self.startPage = self.buildPage('startPage', StartPage) | |
self.page = self.startPage | |
- self.toolTip = SuWidgetFactory.getToolTip(self.gameRoot, w = 128, h = 0, opacity=1.) | |
+ self.toolTip = SuWidgetFactory.getToolTip( | |
+ self.gameRoot, w=128, h=0, opacity=1.) | |
self.toolTip.gameRoot = self.gameRoot | |
self.gameRoot.view.wheel_change.connect(self.toolTip.wheel_change) | |
self.notify = SuWidgetFactory.getNotifyText(self.gameRoot) | |
def setUpLevelsPage(self): | |
self.levelSelect = self.buildPage('levelSelect', LevelSelect) | |
- self.gameRoot.controller.mousePress.connect(self.levelSelect.mousePressEvent) | |
+ self.gameRoot.controller.mousePress.connect( | |
+ self.levelSelect.mousePressEvent) | |
def setUpGameMenu(self): | |
gameMenu = self.buildPage('gameMenu', GameMenuPage) | |
@@ -150,5 +153,3 @@ class GamePages(object): | |
@property | |
def isFocus(self): | |
return self.focusState or self.gameMenu.isFocus() | |
- | |
- | |
diff --git a/ui/GamePages/InventoryPage.py b/ui/GamePages/InventoryPage.py | |
index 0712bc6..d29d373 100644 | |
--- a/ui/GamePages/InventoryPage.py | |
+++ b/ui/GamePages/InventoryPage.py | |
@@ -43,7 +43,8 @@ class InventoryPage(AbstractPage): | |
def setUpWidgets(self): | |
self.gamePages.gameRoot.scene.addItem(self) | |
- self.background = QtWidgets.QGraphicsPixmapItem(self.gamePages.gameRoot.cfg.getPicFile('arena.jpg')) | |
+ self.background = QtWidgets.QGraphicsPixmapItem( | |
+ self.gamePages.gameRoot.cfg.getPicFile('arena.jpg')) | |
self.resizeBackground(self.background) | |
self.item = QtWidgets.QGraphicsPixmapItem() | |
@@ -139,7 +140,11 @@ class InventoryPage(AbstractPage): | |
def updatePage(self): | |
self.mainWidget.upateSlots() | |
- self.update(0, 0, self.gamePages.gameRoot.cfg.dev_size[0],self.gamePages.gameRoot.cfg.dev_size[1]) | |
+ self.update( | |
+ 0, | |
+ 0, | |
+ self.gamePages.gameRoot.cfg.dev_size[0], | |
+ self.gamePages.gameRoot.cfg.dev_size[1]) | |
def swap_item(self, source, target): | |
with ItemTransactions(self.the_hero) as trans: | |
@@ -165,4 +170,3 @@ class InventoryPage(AbstractPage): | |
self.item.setX(pos.x() + 10) | |
self.item.setY(pos.y() + 10) | |
pass | |
- | |
diff --git a/ui/GamePages/LevelSelect.py b/ui/GamePages/LevelSelect.py | |
index 49b1440..3d48fd7 100644 | |
--- a/ui/GamePages/LevelSelect.py | |
+++ b/ui/GamePages/LevelSelect.py | |
@@ -17,6 +17,7 @@ from DreamGame import DreamGame | |
class LevelSelect(AbstractPage): | |
"""docstring for LevelSelect.""" | |
+ | |
def __init__(self, gamePages): | |
super().__init__(gamePages) | |
self.w = 600 * self.gamePages.gameRoot.cfg.scale_x | |
@@ -25,19 +26,28 @@ class LevelSelect(AbstractPage): | |
self.x = 24 | |
self.dungeon_widgets = [] | |
self.fake_btns = [] | |
- self.setUpWidgets([small_orc_cave, pirate_lair, small_graveyard, demo_dungeon, walls_dungeon, tel_razi_temple, tel_razi_factory, dark_wood]) | |
+ self.setUpWidgets([small_orc_cave, | |
+ pirate_lair, | |
+ small_graveyard, | |
+ demo_dungeon, | |
+ walls_dungeon, | |
+ tel_razi_temple, | |
+ tel_razi_factory, | |
+ dark_wood]) | |
self.defaultGame = True | |
self.isService = True | |
self.gamePages.gameRoot.view.wheel_change.connect(self.updatePos) | |
def setUpWidgets(self, dung_list): | |
- self.background = QtWidgets.QGraphicsPixmapItem(self.gamePages.gameRoot.cfg.getPicFile('arena.jpg')) | |
+ self.background = QtWidgets.QGraphicsPixmapItem( | |
+ self.gamePages.gameRoot.cfg.getPicFile('arena.jpg')) | |
self.resizeBackground(self.background) | |
self.addToGroup(self.background) | |
mainWidget: QtWidgets.QWidget = QtWidgets.QWidget() | |
mainWidget.resize(self.w, self.h) | |
- mainWidget.setStyleSheet('background-color: rgba(0, 0, 0, 0);color:white') | |
+ mainWidget.setStyleSheet( | |
+ 'background-color: rgba(0, 0, 0, 0);color:white') | |
self.buttonStyle = 'QPushButton{background-color:grey;color:black;}QPushButton:pressed{background-color:white;color:black;}' | |
@@ -73,7 +83,8 @@ class LevelSelect(AbstractPage): | |
mainWidget.setLayout(mainLayout) | |
self.mainWidget = self.gamePages.gameRoot.scene.addWidget(mainWidget) | |
- self.mainWidget.setFlags(QtWidgets.QGraphicsItem.ItemIgnoresTransformations) | |
+ self.mainWidget.setFlags( | |
+ QtWidgets.QGraphicsItem.ItemIgnoresTransformations) | |
self.gamePages.gameRoot.scene.removeItem(self.mainWidget) | |
self.resized() | |
@@ -85,12 +96,12 @@ class LevelSelect(AbstractPage): | |
self.gamePages.gameRoot.lengine.dungeon = dungeon | |
self.gamePages.gameRoot.ui.startCharacterPage() | |
- frame:QtWidgets.QFrame = QtWidgets.QFrame(parent=parent) | |
- frame.setProperty('dungeon', dungeon) | |
+ frame: QtWidgets.QFrame = QtWidgets.QFrame(parent=parent) | |
+ frame.setProperty('dungeon', dungeon) | |
frame.setObjectName("DungeonFrame") | |
frame.setStyleSheet("#DungeonFrame {border: 2px solid black}") | |
- form_layout = QtWidgets.QFormLayout(parent = parent) | |
+ form_layout = QtWidgets.QFormLayout(parent=parent) | |
icon = QtWidgets.QLabel(parent=parent) | |
icon.setPixmap(self.gamePages.gameRoot.cfg.getPicFile(dungeon.icon)) | |
@@ -99,10 +110,12 @@ class LevelSelect(AbstractPage): | |
form_layout.addRow(QtWidgets.QLabel(dungeon.name, parent)) | |
objs = dungeon.construct_objs(DreamGame()) | |
- n_units_label = QtWidgets.QLabel(f'{len([u for u in objs if not u.is_obstacle])}', parent) | |
+ n_units_label = QtWidgets.QLabel( | |
+ f'{len([u for u in objs if not u.is_obstacle])}', parent) | |
form_layout.addRow('Units in the dungeon:', n_units_label) | |
- max_xp_label = QtWidgets.QLabel(f'{max([u.xp for u in objs if not u.is_obstacle])}', parent) | |
+ max_xp_label = QtWidgets.QLabel( | |
+ f'{max([u.xp for u in objs if not u.is_obstacle])}', parent) | |
form_layout.addRow('Strongest enemy XP: ', max_xp_label) | |
start = QtWidgets.QPushButton('start', parent) | |
@@ -143,8 +156,10 @@ class LevelSelect(AbstractPage): | |
def resized(self): | |
super().resized() | |
self.w = self.mainWidget.boundingRect().width() | |
- self.widget_pos.setX((self.gamePages.gameRoot.cfg.dev_size[0] - self.w) / 2) | |
- self.widget_pos.setY((self.gamePages.gameRoot.cfg.dev_size[1] - self.h) / 2) | |
+ self.widget_pos.setX( | |
+ (self.gamePages.gameRoot.cfg.dev_size[0] - self.w) / 2) | |
+ self.widget_pos.setY( | |
+ (self.gamePages.gameRoot.cfg.dev_size[1] - self.h) / 2) | |
self.mainWidget.setPos(self.widget_pos) | |
self.resizeBackground(self.background) | |
pass | |
@@ -156,7 +171,15 @@ class LevelSelect(AbstractPage): | |
def mousePressEvent(self, e): | |
for widget in self.dungeon_widgets: | |
- qr = QtCore.QRect(self.mainWidget.x() + self.frame.x() + widget.x(), self.mainWidget.y() + self.frame.y() + widget.y(), widget.size().width(), widget.size().height()) | |
+ qr = QtCore.QRect( | |
+ self.mainWidget.x() + | |
+ self.frame.x() + | |
+ widget.x(), | |
+ self.mainWidget.y() + | |
+ self.frame.y() + | |
+ widget.y(), | |
+ widget.size().width(), | |
+ widget.size().height()) | |
if qr.contains(e.pos().x(), e.pos().y()): | |
widget.setStyleSheet("#DungeonFrame {border: 2px solid blue}") | |
self.selectDungeon(widget.property('dungeon')) | |
@@ -172,11 +195,6 @@ class LevelSelect(AbstractPage): | |
def updatePos(self): | |
super().updatePos() | |
- self.mainWidget.setPos(self.gamePages.gameRoot.view.mapToScene(self.widget_pos)) | |
- | |
- | |
- | |
- | |
- | |
- | |
- | |
+ self.mainWidget.setPos( | |
+ self.gamePages.gameRoot.view.mapToScene( | |
+ self.widget_pos)) | |
diff --git a/ui/GamePages/ReadmePage.py b/ui/GamePages/ReadmePage.py | |
index 945b48f..183df87 100644 | |
--- a/ui/GamePages/ReadmePage.py | |
+++ b/ui/GamePages/ReadmePage.py | |
@@ -6,6 +6,7 @@ from os import path | |
class ReadmePage(AbstractPage): | |
"""docstring for StartPage.""" | |
+ | |
def __init__(self, gamePages): | |
super().__init__(gamePages) | |
self.w = 480 | |
@@ -16,11 +17,13 @@ class ReadmePage(AbstractPage): | |
self.gamePages.gameRoot.view.wheel_change.connect(self.updatePos) | |
def setUpWidgets(self): | |
- self.background = QtWidgets.QGraphicsPixmapItem(self.gamePages.gameRoot.cfg.getPicFile('arena.jpg')) | |
+ self.background = QtWidgets.QGraphicsPixmapItem( | |
+ self.gamePages.gameRoot.cfg.getPicFile('arena.jpg')) | |
self.resizeBackground(self.background) | |
self.addToGroup(self.background) | |
self.scroll = QtWidgets.QGraphicsRectItem() | |
- brush = QtGui.QBrush(self.gamePages.gameRoot.cfg.getPicFile('scroll_background.png')) | |
+ brush = QtGui.QBrush( | |
+ self.gamePages.gameRoot.cfg.getPicFile('scroll_background.png')) | |
self.scroll.setBrush(brush) | |
self.addToGroup(self.scroll) | |
self.text = QtWidgets.QGraphicsTextItem() | |
@@ -30,12 +33,14 @@ class ReadmePage(AbstractPage): | |
def getHtml(self): | |
- with open(path.join('resources','html', 'readme.html'), 'r') as f: | |
+ with open(path.join('resources', 'html', 'readme.html'), 'r') as f: | |
return f.read() | |
def setUpSize(self): | |
- self.w = int((self.gamePages.gameRoot.cfg.dev_size[0] / 128) * 0.6) * 128 | |
- self.h = int((self.gamePages.gameRoot.cfg.dev_size[1] / 128) * 0.8) * 128 | |
+ self.w = int( | |
+ (self.gamePages.gameRoot.cfg.dev_size[0] / 128) * 0.6) * 128 | |
+ self.h = int( | |
+ (self.gamePages.gameRoot.cfg.dev_size[1] / 128) * 0.8) * 128 | |
def showPage(self): | |
if self.state: | |
@@ -69,8 +74,10 @@ class ReadmePage(AbstractPage): | |
def resized(self): | |
super().resized() | |
self.setUpSize() | |
- self.widget_pos.setX((self.gamePages.gameRoot.cfg.dev_size[0] - self.w) / 2) | |
- self.widget_pos.setY((self.gamePages.gameRoot.cfg.dev_size[1] - self.h) / 2) | |
+ self.widget_pos.setX( | |
+ (self.gamePages.gameRoot.cfg.dev_size[0] - self.w) / 2) | |
+ self.widget_pos.setY( | |
+ (self.gamePages.gameRoot.cfg.dev_size[1] - self.h) / 2) | |
pos = self.gamePages.gameRoot.view.mapToScene(self.widget_pos) | |
self.scroll.setRect(pos.x(), pos.y(), self.w, self.h) | |
self.text.setPos(pos) | |
diff --git a/ui/GamePages/SettingsPage.py b/ui/GamePages/SettingsPage.py | |
index 8ef2115..26c1d47 100644 | |
--- a/ui/GamePages/SettingsPage.py | |
+++ b/ui/GamePages/SettingsPage.py | |
@@ -5,6 +5,7 @@ from ui.GamePages import AbstractPage | |
class SettingsPage(AbstractPage): | |
"""docstring for StartPage.""" | |
+ | |
def __init__(self, gamePages): | |
super().__init__(gamePages) | |
self.w = 420 * self.gamePages.gameRoot.cfg.scale_x | |
@@ -15,8 +16,10 @@ class SettingsPage(AbstractPage): | |
self.gamePages.gameRoot.view.wheel_change.connect(self.updatePos) | |
def setUpWidgets(self): | |
- self.res_id=self.gamePages.gameRoot.cfg.resolutions.index(self.gamePages.gameRoot.cfg.deviceConfig.dev_size) | |
- self.background = QtWidgets.QGraphicsPixmapItem(self.gamePages.gameRoot.cfg.getPicFile('arena.jpg')) | |
+ self.res_id = self.gamePages.gameRoot.cfg.resolutions.index( | |
+ self.gamePages.gameRoot.cfg.deviceConfig.dev_size) | |
+ self.background = QtWidgets.QGraphicsPixmapItem( | |
+ self.gamePages.gameRoot.cfg.getPicFile('arena.jpg')) | |
self.resizeBackground(self.background) | |
self.addToGroup(self.background) | |
@@ -26,17 +29,24 @@ class SettingsPage(AbstractPage): | |
formlayout = QtWidgets.QFormLayout(mainWidget) | |
- formlayout.addRow('Device\nresolution', QtWidgets.QLabel(self.res_to_str(self.gamePages.gameRoot.cfg.deviceConfig.device_resolution))) | |
+ formlayout.addRow( | |
+ 'Device\nresolution', QtWidgets.QLabel( | |
+ self.res_to_str( | |
+ self.gamePages.gameRoot.cfg.deviceConfig.device_resolution))) | |
self.resolution = self.getResolutions() | |
formlayout.addRow('Resolutions', self.resolution) | |
self.select_resolution = QtWidgets.QLabel('', parent=mainWidget) | |
- self.select_resolution.setText(self.res_to_str(self.resolution.itemData(self.resolution.currentIndex()))) | |
+ self.select_resolution.setText( | |
+ self.res_to_str( | |
+ self.resolution.itemData( | |
+ self.resolution.currentIndex()))) | |
formlayout.addRow('Select\nresolution', self.select_resolution) | |
- self.fullscreen = self.getCheckBox(mainWidget, 'Full screen', formlayout, self.ceckFullScreenBox) | |
+ self.fullscreen = self.getCheckBox( | |
+ mainWidget, 'Full screen', formlayout, self.ceckFullScreenBox) | |
save = QtWidgets.QPushButton('SAVE') | |
save.clicked.connect(self.saveSlot) | |
formlayout.addRow('save\nchanges', save) | |
@@ -44,7 +54,8 @@ class SettingsPage(AbstractPage): | |
mainWidget.setLayout(formlayout) | |
self.readFromConfig() | |
self.mainWidget = self.gamePages.gameRoot.scene.addWidget(mainWidget) | |
- self.mainWidget.setFlags(QtWidgets.QGraphicsItem.ItemIgnoresTransformations) | |
+ self.mainWidget.setFlags( | |
+ QtWidgets.QGraphicsItem.ItemIgnoresTransformations) | |
self.gamePages.gameRoot.scene.removeItem(self.mainWidget) | |
self.resized() | |
@@ -78,18 +89,22 @@ class SettingsPage(AbstractPage): | |
def getResolutions(self): | |
resolution = QtWidgets.QComboBox() | |
- resolution.setSizeAdjustPolicy(QtWidgets.QComboBox.AdjustToMinimumContentsLengthWithIcon) | |
+ resolution.setSizeAdjustPolicy( | |
+ QtWidgets.QComboBox.AdjustToMinimumContentsLengthWithIcon) | |
resolution.activated.connect(self.changeResolution) | |
for res in self.gamePages.gameRoot.cfg.resolutions: | |
- resolution.addItem(str(res[0])+'x'+str(res[1]), res) | |
+ resolution.addItem(str(res[0]) + 'x' + str(res[1]), res) | |
resolution.setCurrentIndex(self.res_id) | |
return resolution | |
def changeResolution(self, index): | |
- self.gamePages.gameRoot.cfg.userConfig.setSize(self.resolution.itemData(index)) | |
- self.select_resolution.setText(self.res_to_str(self.resolution.itemData(index))) | |
+ self.gamePages.gameRoot.cfg.userConfig.setSize( | |
+ self.resolution.itemData(index)) | |
+ self.select_resolution.setText( | |
+ self.res_to_str( | |
+ self.resolution.itemData(index))) | |
- def getCheckBox(self, mainWidget, name = None, formLayout = None, slot = None): | |
+ def getCheckBox(self, mainWidget, name=None, formLayout=None, slot=None): | |
checkBox = QtWidgets.QCheckBox(parent=mainWidget) | |
if formLayout is not None: | |
if name is None: | |
@@ -104,10 +119,13 @@ class SettingsPage(AbstractPage): | |
if self.fullscreen.isChecked(): | |
self.resolution.setEnabled(False) | |
self.gamePages.gameRoot.cfg.userConfig.read_config['window']['fullscreen'] = True | |
- index = self.gamePages.gameRoot.cfg.resolutions.index(self.gamePages.gameRoot.cfg.deviceConfig.device_resolution) | |
+ index = self.gamePages.gameRoot.cfg.resolutions.index( | |
+ self.gamePages.gameRoot.cfg.deviceConfig.device_resolution) | |
self.resolution.setCurrentIndex(index) | |
- self.select_resolution.setText(self.res_to_str(self.gamePages.gameRoot.cfg.deviceConfig.device_resolution)) | |
- self.gamePages.gameRoot.cfg.userConfig.setSize(self.gamePages.gameRoot.cfg.deviceConfig.device_resolution) | |
+ self.select_resolution.setText(self.res_to_str( | |
+ self.gamePages.gameRoot.cfg.deviceConfig.device_resolution)) | |
+ self.gamePages.gameRoot.cfg.userConfig.setSize( | |
+ self.gamePages.gameRoot.cfg.deviceConfig.device_resolution) | |
else: | |
self.gamePages.gameRoot.cfg.userConfig.read_config['window']['fullscreen'] = False | |
self.resolution.setEnabled(True) | |
@@ -119,22 +137,28 @@ class SettingsPage(AbstractPage): | |
def updatePos(self): | |
super().updatePos() | |
- self.mainWidget.setPos(self.gamePages.gameRoot.view.mapToScene(self.widget_pos)) | |
+ self.mainWidget.setPos( | |
+ self.gamePages.gameRoot.view.mapToScene( | |
+ self.widget_pos)) | |
def resized(self): | |
super().resized() | |
- self.widget_pos.setX((self.gamePages.gameRoot.cfg.dev_size[0] - self.w) / 2) | |
- self.widget_pos.setY((self.gamePages.gameRoot.cfg.dev_size[1] - self.h) / 2) | |
+ self.widget_pos.setX( | |
+ (self.gamePages.gameRoot.cfg.dev_size[0] - self.w) / 2) | |
+ self.widget_pos.setY( | |
+ (self.gamePages.gameRoot.cfg.dev_size[1] - self.h) / 2) | |
self.mainWidget.setPos(self.widget_pos) | |
self.resizeBackground(self.background) | |
pass | |
@property | |
def dev_resolution(self): | |
- return str(self.gamePages.gameRoot.cfg.dev_size[0])+'x'+str(self.gamePages.gameRoot.cfg.dev_size[1]) | |
+ return str( | |
+ self.gamePages.gameRoot.cfg.dev_size[0]) + 'x' + str( | |
+ self.gamePages.gameRoot.cfg.dev_size[1]) | |
def res_to_str(self, size): | |
- return str(size[0])+'x'+str(size[1]) | |
+ return str(size[0]) + 'x' + str(size[1]) | |
def saveSlot(self): | |
try: | |
@@ -151,6 +175,4 @@ class SettingsPage(AbstractPage): | |
h = self.gamePages.gameRoot.cfg.userConfig.read_config['window']['resolution']['height'] | |
index = self.gamePages.gameRoot.cfg.resolutions.index((w, h)) | |
self.resolution.setCurrentIndex(index) | |
- self.select_resolution.setText(str(w)+'x'+str(h)) | |
- | |
- | |
+ self.select_resolution.setText(str(w) + 'x' + str(h)) | |
diff --git a/ui/GamePages/StartPage.py b/ui/GamePages/StartPage.py | |
index 533a4c3..b77a320 100644 | |
--- a/ui/GamePages/StartPage.py | |
+++ b/ui/GamePages/StartPage.py | |
@@ -7,6 +7,7 @@ from ui.GameAnimation.AnimatedItem import AnimatedItem | |
class StartPage(AbstractPage): | |
"""docstring for StartPage.""" | |
+ | |
def __init__(self, gamePages): | |
super().__init__(gamePages) | |
self.state = True | |
@@ -21,7 +22,8 @@ class StartPage(AbstractPage): | |
def setUpWidgets(self): | |
self.buttons = [] | |
- self.background = QtWidgets.QGraphicsPixmapItem(self.gamePages.gameRoot.cfg.getPicFile('arena.jpg')) | |
+ self.background = QtWidgets.QGraphicsPixmapItem( | |
+ self.gamePages.gameRoot.cfg.getPicFile('arena.jpg')) | |
self.resizeBackground(self.background) | |
self.addToGroup(self.background) | |
@@ -76,7 +78,8 @@ class StartPage(AbstractPage): | |
mainWidget.setLayout(laoyout) | |
self.mainWidget = self.gamePages.gameRoot.scene.addWidget(mainWidget) | |
- self.mainWidget.setFlags(QtWidgets.QGraphicsItem.ItemIgnoresTransformations) | |
+ self.mainWidget.setFlags( | |
+ QtWidgets.QGraphicsItem.ItemIgnoresTransformations) | |
self.resized() | |
self.setUpAnim() | |
@@ -110,12 +113,16 @@ class StartPage(AbstractPage): | |
return x1, x2, y | |
def setAnimPos(self, button_id): | |
- self.fire_one.setPos(self.buttons_pos[button_id][0], self.buttons_pos[button_id][2]) | |
- self.fire_two.setPos(self.buttons_pos[button_id][1], self.buttons_pos[button_id][2]) | |
+ self.fire_one.setPos( | |
+ self.buttons_pos[button_id][0], | |
+ self.buttons_pos[button_id][2]) | |
+ self.fire_two.setPos( | |
+ self.buttons_pos[button_id][1], | |
+ self.buttons_pos[button_id][2]) | |
def showPage(self): | |
if self.state: | |
- if not self.gamePages.gameRoot.loop is None: | |
+ if self.gamePages.gameRoot.loop is not None: | |
self.state = False | |
self.focusable.emit(False) | |
self.gamePages.page = None | |
@@ -143,9 +150,13 @@ class StartPage(AbstractPage): | |
def resized(self): | |
super().resized() | |
- self.widget_pos.setX((self.gamePages.gameRoot.cfg.dev_size[0] - self.w) / 2) | |
- self.widget_pos.setY((self.gamePages.gameRoot.cfg.dev_size[1] - self.h) / 2) | |
- self.mainWidget.setPos(self.gamePages.gameRoot.view.mapToScene(self.widget_pos)) | |
+ self.widget_pos.setX( | |
+ (self.gamePages.gameRoot.cfg.dev_size[0] - self.w) / 2) | |
+ self.widget_pos.setY( | |
+ (self.gamePages.gameRoot.cfg.dev_size[1] - self.h) / 2) | |
+ self.mainWidget.setPos( | |
+ self.gamePages.gameRoot.view.mapToScene( | |
+ self.widget_pos)) | |
self.resizeBackground(self.background) | |
pass | |
@@ -206,7 +217,9 @@ class StartPage(AbstractPage): | |
def updatePos(self): | |
super().updatePos() | |
- self.mainWidget.setPos(self.gamePages.gameRoot.view.mapToScene(self.widget_pos)) | |
+ self.mainWidget.setPos( | |
+ self.gamePages.gameRoot.view.mapToScene( | |
+ self.widget_pos)) | |
def get_wig(self, button): | |
self.button_id = self.buttons.index(button) | |
diff --git a/ui/GamePages/_CharacterPage.py b/ui/GamePages/_CharacterPage.py | |
index 3e8f82e..c8add17 100644 | |
--- a/ui/GamePages/_CharacterPage.py | |
+++ b/ui/GamePages/_CharacterPage.py | |
@@ -11,6 +11,7 @@ from game_objects.battlefield_objects import base_attributes | |
class CharacterPage(AbstractPage): | |
"""docstring for CharacterPage.""" | |
+ | |
def __init__(self, gamePages): | |
super(CharacterPage, self).__init__(gamePages) | |
self.character = self.gamePages.gameRoot.lengine.character | |
@@ -23,31 +24,46 @@ class CharacterPage(AbstractPage): | |
self.gamePages.gameRoot.view.wheel_change.connect(self.updatePos) | |
def setUpWidgets(self): | |
- self.background = QtWidgets.QGraphicsPixmapItem(self.gamePages.gameRoot.cfg.getPicFile('arena.jpg')) | |
+ self.background = QtWidgets.QGraphicsPixmapItem( | |
+ self.gamePages.gameRoot.cfg.getPicFile('arena.jpg')) | |
self.resizeBackground(self.background) | |
self.addToGroup(self.background) | |
self.buttonStyle = 'QPushButton{background-color:grey;color:black;}QPushButton:pressed{background-color:white;color:black;}' | |
mainWidget: QtWidgets.QWidget = QtWidgets.QWidget() | |
- mainWidget.setSizePolicy(QtWidgets.QSizePolicy.Minimum, QtWidgets.QSizePolicy.Minimum) | |
- mainWidget.setStyleSheet('background-color: rgba(0, 0, 0, 0);color:white') | |
+ mainWidget.setSizePolicy( | |
+ QtWidgets.QSizePolicy.Minimum, | |
+ QtWidgets.QSizePolicy.Minimum) | |
+ mainWidget.setStyleSheet( | |
+ 'background-color: rgba(0, 0, 0, 0);color:white') | |
mainLayout: QtWidgets.QGridLayout = QtWidgets.QGridLayout() | |
mainLayout.setSizeConstraint(QtWidgets.QLayout.SetMinimumSize) | |
- self.charWidget = CharacterWidget(self, parent = mainWidget) | |
- self.masteriWidget = MasteriesWidget(self, parent = mainWidget) | |
- self.perkWidget = QPerkTree(self.gamePages.gameRoot.cfg, self.character.perk_trees[0], self.character, mainWidget) | |
+ self.charWidget = CharacterWidget(self, parent=mainWidget) | |
+ self.masteriWidget = MasteriesWidget(self, parent=mainWidget) | |
+ self.perkWidget = QPerkTree( | |
+ self.gamePages.gameRoot.cfg, | |
+ self.character.perk_trees[0], | |
+ self.character, | |
+ mainWidget) | |
mainLayout.addWidget(self.charWidget, 0, 0, 1, 1) | |
mainLayout.addWidget(self.perkWidget, 0, 3, 3, 1) | |
mainLayout.addWidget(self.masteriWidget, 1, 0, 1, 3) | |
- mainLayout.addLayout(self.getPageBtnLayout(mainWidget), 2, 3, 1, 1, alignment = QtCore.Qt.AlignRight) | |
+ mainLayout.addLayout( | |
+ self.getPageBtnLayout(mainWidget), | |
+ 2, | |
+ 3, | |
+ 1, | |
+ 1, | |
+ alignment=QtCore.Qt.AlignRight) | |
mainWidget.setLayout(mainLayout) | |
self.mainWidget = self.gamePages.gameRoot.scene.addWidget(mainWidget) | |
- self.mainWidget.setFlags(QtWidgets.QGraphicsItem.ItemIgnoresTransformations) | |
+ self.mainWidget.setFlags( | |
+ QtWidgets.QGraphicsItem.ItemIgnoresTransformations) | |
self.gamePages.gameRoot.scene.removeItem(self.mainWidget) | |
msgBox = GameMsgBox(page=self) | |
@@ -55,7 +71,8 @@ class CharacterPage(AbstractPage): | |
msgBox.setText('This character page') | |
msgBox.setInformativeText('Change character elements and up hero') | |
self.msgBox = self.gamePages.gameRoot.scene.addWidget(msgBox) | |
- self.msgBox.setFlag(QtWidgets.QGraphicsItem.ItemIgnoresTransformations, True) | |
+ self.msgBox.setFlag( | |
+ QtWidgets.QGraphicsItem.ItemIgnoresTransformations, True) | |
self.gamePages.gameRoot.scene.removeItem(self.msgBox) | |
self.updatePage() | |
self.resized() | |
@@ -89,7 +106,7 @@ class CharacterPage(AbstractPage): | |
bar = QtWidgets.QProgressBar(parent) | |
bar.setFixedWidth(100) | |
bar.setTextVisible(False) | |
- layout.addWidget(bar, row, 1, 1, 1, QtCore.Qt.AlignLeft) | |
+ layout.addWidget(bar, row, 1, 1, 1, QtCore.Qt.AlignLeft) | |
barLabel = QtWidgets.QLabel('', parent) | |
barLabel.setFixedWidth(50) | |
layout.addWidget(barLabel, row, 2, 1, 1, QtCore.Qt.AlignLeft) | |
@@ -136,9 +153,13 @@ class CharacterPage(AbstractPage): | |
super().resized() | |
self.w = self.mainWidget.widget().width() | |
self.h = self.mainWidget.widget().height() | |
- self.widget_pos.setX((self.gamePages.gameRoot.cfg.dev_size[0] - self.w) / 2) | |
- self.widget_pos.setY((self.gamePages.gameRoot.cfg.dev_size[1] - self.h) / 2) | |
- self.mainWidget.setPos(self.gamePages.gameRoot.view.mapToScene(self.widget_pos)) | |
+ self.widget_pos.setX( | |
+ (self.gamePages.gameRoot.cfg.dev_size[0] - self.w) / 2) | |
+ self.widget_pos.setY( | |
+ (self.gamePages.gameRoot.cfg.dev_size[1] - self.h) / 2) | |
+ self.mainWidget.setPos( | |
+ self.gamePages.gameRoot.view.mapToScene( | |
+ self.widget_pos)) | |
self.resizeBackground(self.background) | |
pass | |
@@ -182,9 +203,12 @@ class CharacterPage(AbstractPage): | |
def updatePos(self): | |
super().updatePos() | |
- self.mainWidget.setPos(self.gamePages.gameRoot.view.mapToScene(self.widget_pos)) | |
- self.msgBox.setPos(self.gamePages.gameRoot.view.mapToScene(self.msgBox.widget().widget_pos)) | |
- | |
+ self.mainWidget.setPos( | |
+ self.gamePages.gameRoot.view.mapToScene( | |
+ self.widget_pos)) | |
+ self.msgBox.setPos( | |
+ self.gamePages.gameRoot.view.mapToScene( | |
+ self.msgBox.widget().widget_pos)) | |
def toolTipShow(self, widget): | |
x = widget.x() + self.mainWidget.pos().x() | |
diff --git a/ui/GamePages/__DefaultPage.py b/ui/GamePages/__DefaultPage.py | |
index caddcef..671dd56 100644 | |
--- a/ui/GamePages/__DefaultPage.py | |
+++ b/ui/GamePages/__DefaultPage.py | |
@@ -11,6 +11,7 @@ function for GamePages | |
""" | |
+ | |
class DefaultPage(AbstractPage): | |
"""docstring for DefaultPage. | |
self.mainWidget.widget() -- native Qt Widget | |
@@ -27,8 +28,11 @@ class DefaultPage(AbstractPage): | |
def setUpWidgets(self): | |
# SetUp background | |
- self.background = QtWidgets.QGraphicsRectItem(0, 0, self.gamePages.gameRoot.cfg.dev_size[0], | |
- self.gamePages.gameRoot.cfg.dev_size[1]) | |
+ self.background = QtWidgets.QGraphicsRectItem( | |
+ 0, | |
+ 0, | |
+ self.gamePages.gameRoot.cfg.dev_size[0], | |
+ self.gamePages.gameRoot.cfg.dev_size[1]) | |
self.background.setBrush(QtGui.QBrush(QtCore.Qt.black)) | |
self.addToGroup(self.background) | |
@@ -38,11 +42,12 @@ class DefaultPage(AbstractPage): | |
mainWidget: QtWidgets.QWidget = QtWidgets.QWidget() | |
mainWidget.resize(self.w, self.h) | |
# SetUp opacity for main Widget | |
- mainWidget.setStyleSheet('background-color: rgba(0, 0, 0, 0);color:white') | |
+ mainWidget.setStyleSheet( | |
+ 'background-color: rgba(0, 0, 0, 0);color:white') | |
# Add main Laout | |
- mainLayout:QtWidgets.QVBoxLayout = QtWidgets.QVBoxLayout() | |
+ mainLayout: QtWidgets.QVBoxLayout = QtWidgets.QVBoxLayout() | |
- layout:QtWidgets.QHBoxLayout = QtWidgets.QHBoxLayout() | |
+ layout: QtWidgets.QHBoxLayout = QtWidgets.QHBoxLayout() | |
self.ok = QtWidgets.QPushButton("ok", mainWidget) | |
self.ok.setStyleSheet(self.buttonStyle) | |
@@ -103,9 +108,6 @@ class DefaultPage(AbstractPage): | |
self.gamePages.gameRoot.scene.addItem(self) | |
self.gamePages.gameRoot.scene.addItem(self.mainWidget) | |
- | |
- | |
def destroy(self): | |
self.gamePages.gameRoot.scene.removeItem(self.mainWidget) | |
del self.mainWidget | |
- | |
diff --git a/ui/GamePages/character_page/CharacterPage.py b/ui/GamePages/character_page/CharacterPage.py | |
index 7cb35a2..f962486 100644 | |
--- a/ui/GamePages/character_page/CharacterPage.py | |
+++ b/ui/GamePages/character_page/CharacterPage.py | |
@@ -35,15 +35,24 @@ class CharacterPage(AbstractPage): | |
self.hide() | |
self.scene().removeItem(self) | |
- def sceneEvent(self, event:QtCore.QEvent): | |
+ def sceneEvent(self, event: QtCore.QEvent): | |
if event.type() is QtCore.QEvent.GraphicsSceneMousePress: | |
- self.pressItem(self.scene().itemAt(event.scenePos(), self.scene().views()[0].transform())) | |
+ self.pressItem( | |
+ self.scene().itemAt( | |
+ event.scenePos(), | |
+ self.scene().views()[0].transform())) | |
return True | |
elif event.type() is QtCore.QEvent.GraphicsSceneMouseRelease: | |
- self.releaseItem(self.scene().itemAt(event.scenePos(), self.scene().views()[0].transform())) | |
+ self.releaseItem( | |
+ self.scene().itemAt( | |
+ event.scenePos(), | |
+ self.scene().views()[0].transform())) | |
return True | |
elif event.type() is QtCore.QEvent.GraphicsSceneHoverMove: | |
- self.hoverMove(self.scene().itemAt(event.scenePos(), self.scene().views()[0].transform())) | |
+ self.hoverMove( | |
+ self.scene().itemAt( | |
+ event.scenePos(), | |
+ self.scene().views()[0].transform())) | |
return True | |
# elif event.type() is QtCore.QEvent.GraphicsSceneHoverLeave: | |
# self.hoverLeave(self.scene().itemAt(event.scenePos(), self.scene().views()[0].transform())) | |
@@ -57,7 +66,7 @@ class CharacterPage(AbstractPage): | |
# print(item.name, 'press') | |
pass | |
- def releaseItem(self, item:BaseItem): | |
+ def releaseItem(self, item: BaseItem): | |
if item is not None: | |
# print(item.name, 'release') | |
if item.input == 'button': | |
@@ -133,7 +142,11 @@ class CharacterPage(AbstractPage): | |
if mastery is not None: | |
self.gm.mastery_up(mastery) | |
self.mastery_all_update() | |
- self.update(0, 0, self.gamePages.gameRoot.cfg.dev_size[0], self.gamePages.gameRoot.cfg.dev_size[1]) | |
+ self.update( | |
+ 0, | |
+ 0, | |
+ self.gamePages.gameRoot.cfg.dev_size[0], | |
+ self.gamePages.gameRoot.cfg.dev_size[1]) | |
def mastery_hover(self, name): | |
mastery = self.gm.masteries.get(name) | |
@@ -147,7 +160,8 @@ class CharacterPage(AbstractPage): | |
def mastery_all_update(self): | |
for name, mastery in self.gm.masteries.items(): | |
- self.items.get(f'mastery_{name}_point').setText(self.gm.mastery_value(mastery)) | |
+ self.items.get(f'mastery_{name}_point').setText( | |
+ self.gm.mastery_value(mastery)) | |
perc, __ = self.gm.mastery_prec(mastery) | |
bar = self.items.get(f'mastery_{name}_bar') | |
if bar is not None: | |
@@ -176,7 +190,7 @@ class CharacterPage(AbstractPage): | |
spent_value.setText(self.gha.free_xp) | |
self.hero_attr_update() | |
- def heroAttr_change(self, item:BaseItem): | |
+ def heroAttr_change(self, item: BaseItem): | |
if item._names[2] == 'up': | |
self.heroAttr_up(item._names[1]) | |
elif item._names[2] == 'down': | |
@@ -194,9 +208,12 @@ class CharacterPage(AbstractPage): | |
self.gha.attr_down(heroAttr) | |
def hero_attr_update(self): | |
- self.items.get('attr_health_value').setText(self.gha.max_health + ' / ' + self.gha.health) | |
- self.items.get('attr_mana_value').setText(self.gha.max_mana + ' / ' + self.gha.mana) | |
- self.items.get('attr_stamina_value').setText(self.gha.max_stamina + ' / ' + self.gha.stamina) | |
+ self.items.get('attr_health_value').setText( | |
+ self.gha.max_health + ' / ' + self.gha.health) | |
+ self.items.get('attr_mana_value').setText( | |
+ self.gha.max_mana + ' / ' + self.gha.mana) | |
+ self.items.get('attr_stamina_value').setText( | |
+ self.gha.max_stamina + ' / ' + self.gha.stamina) | |
##################### | |
### B U T T O N S ### | |
@@ -234,7 +251,3 @@ class CharacterPage(AbstractPage): | |
for item in self.items.values(): | |
if isinstance(item, TextItem): | |
item.setColor(item._color) | |
- | |
- | |
- | |
- | |
diff --git a/ui/GamePages/character_page/GameHeroAttr.py b/ui/GamePages/character_page/GameHeroAttr.py | |
index b48917a..206a77e 100644 | |
--- a/ui/GamePages/character_page/GameHeroAttr.py | |
+++ b/ui/GamePages/character_page/GameHeroAttr.py | |
@@ -11,7 +11,9 @@ class GameHeroAttr: | |
def setUpHeroAttr(self): | |
self.attrs = {v: k for k, v in enum_to_abbrev.items()} | |
- self.attrs_info = {'cha_'+name:attr.tooltip_info for name, attr in self.attrs.items()} | |
+ self.attrs_info = { | |
+ 'cha_' + name: attr.tooltip_info for name, | |
+ attr in self.attrs.items()} | |
self._free_xp = self.free_xp | |
def freePointsChanged(self, value, attr): | |
@@ -42,6 +44,7 @@ class GameHeroAttr: | |
else: | |
attributes = self.character.temp_attributes | |
return str(attributes[attr]) | |
+ | |
@property | |
def health(self): | |
return str(self.gameRoot.lengine.the_hero.health) | |
@@ -79,6 +82,7 @@ class GameHeroAttr: | |
self.character.commit() | |
except Exception as er: | |
print("D'ont commit character", er) | |
+ | |
@property | |
def hero_icon(self): | |
- return self.gameRoot.lengine.the_hero.icon | |
\ No newline at end of file | |
+ return self.gameRoot.lengine.the_hero.icon | |
diff --git a/ui/GamePages/character_page/GameMasteries.py b/ui/GamePages/character_page/GameMasteries.py | |
index 524b978..163ad57 100644 | |
--- a/ui/GamePages/character_page/GameMasteries.py | |
+++ b/ui/GamePages/character_page/GameMasteries.py | |
@@ -9,8 +9,12 @@ class GameMasteries: | |
pass | |
def setUpMasteries(self): | |
- self.masteries = dict(zip([m.name.lower() for m in MasteriesGroups.all_magic+MasteriesGroups.all_battle], MasteriesGroups.all_magic+MasteriesGroups.all_battle)) | |
- self.masteries_info = {'mastery_'+name:mastery.tooltip_info for name, mastery in self.masteries.items()} | |
+ self.masteries = dict(zip([m.name.lower() for m in MasteriesGroups.all_magic + | |
+ MasteriesGroups.all_battle], MasteriesGroups.all_magic + | |
+ MasteriesGroups.all_battle)) | |
+ self.masteries_info = { | |
+ 'mastery_' + name: mastery.tooltip_info for name, | |
+ mastery in self.masteries.items()} | |
def mastery_up(self, mastery): | |
self.character.increase_mastery(mastery) | |
diff --git a/ui/GamePages/character_page/GamePerkTree.py b/ui/GamePages/character_page/GamePerkTree.py | |
index d061e47..0d1a26a 100644 | |
--- a/ui/GamePages/character_page/GamePerkTree.py | |
+++ b/ui/GamePages/character_page/GamePerkTree.py | |
@@ -6,7 +6,6 @@ from character.perks.everymans_perks.group_param import attr_perk_names as param | |
from game_objects.battlefield_objects import CharAttributes, enum_to_abbrev | |
- | |
class GamePerkTree: | |
def __init__(self, perk_tree: PerkTree, character): | |
assert perk_tree in character.perk_trees | |
@@ -29,11 +28,12 @@ class GamePerkTree: | |
CharAttributes.INTELLIGENCE, | |
CharAttributes.CHARISMA] | |
cha_params = [CharAttributes.HEALTH, | |
- CharAttributes.MANA, | |
- CharAttributes.STAMINA, | |
- CharAttributes.INITIATIVE] | |
+ CharAttributes.MANA, | |
+ CharAttributes.STAMINA, | |
+ CharAttributes.INITIATIVE] | |
cha_atrs_names = [attr_names(attr) for attr in cha_attributes] | |
- cha_atrs_names = cha_atrs_names + [param_names(attr) for attr in cha_params] | |
+ cha_atrs_names = cha_atrs_names + \ | |
+ [param_names(attr) for attr in cha_params] | |
cha_atrs_abrv = [enum_to_abbrev[attr] for attr in cha_attributes] | |
cha_atrs_abrv = cha_atrs_abrv[0:6] + ['hel', 'man', 'sta', 'ini'] | |
l = len(cha_atrs_names) | |
@@ -41,7 +41,9 @@ class GamePerkTree: | |
for perk in self.get_perks(): | |
if perk.name == cha_atrs_names[i]: | |
self.perks[cha_atrs_abrv[i]] = perk | |
- self.perks_info = {'perk_'+abrv: perk.tooltip_info for abrv, perk in self.perks.items()} | |
+ self.perks_info = { | |
+ 'perk_' + abrv: perk.tooltip_info for abrv, | |
+ perk in self.perks.items()} | |
def xp_to_levelup(self, perk): | |
return self.perk_tree.cost_to_levelup(perk) | |
@@ -51,6 +53,7 @@ class GamePerkTree: | |
return self.string_cost(self.xp_to_levelup(perk)) | |
else: | |
return "^maxed^" | |
+ | |
@property | |
def spent_xp(self): | |
return self.string_cost(self.perk_tree.spent_xp) | |
@@ -79,5 +82,3 @@ class GamePerkTree: | |
else: | |
result = str(cost) | |
return result | |
- | |
- | |
diff --git a/ui/GamePages/inventory_page/GameEquipment.py b/ui/GamePages/inventory_page/GameEquipment.py | |
index 9a8c5d6..3b847f3 100644 | |
--- a/ui/GamePages/inventory_page/GameEquipment.py | |
+++ b/ui/GamePages/inventory_page/GameEquipment.py | |
@@ -16,8 +16,10 @@ class GameEquipment(SlotsGroup): | |
name_slot = 'ring1' | |
elif name_slot == 'ring_2': | |
name_slot = 'ring2' | |
- item:Element = self.page.find_element(element, name=f'equip_slot_{name_slot}') | |
- self.default_icons[f'equip_slot_{name_slot}'] = item.get('icon', 'default.png') | |
+ item: Element = self.page.find_element( | |
+ element, name=f'equip_slot_{name_slot}') | |
+ self.default_icons[f'equip_slot_{name_slot}'] = item.get( | |
+ 'icon', 'default.png') | |
self.slots[f'equip_slot_{name_slot}'] = slot | |
if slot.content is not None: | |
item.set('icon', slot.content.icon) | |
diff --git a/ui/GamePages/inventory_page/GameInventrory.py b/ui/GamePages/inventory_page/GameInventrory.py | |
index ca86f04..58b94d2 100644 | |
--- a/ui/GamePages/inventory_page/GameInventrory.py | |
+++ b/ui/GamePages/inventory_page/GameInventrory.py | |
@@ -13,7 +13,7 @@ class GameInventrory(SlotsGroup): | |
self.slots['inventory_slot_' + str(self._l)] = slot | |
elemnt.append(self.create_slot(slot)) | |
- def create_slot(self, slot:Slot, width=128, space=10): | |
+ def create_slot(self, slot: Slot, width=128, space=10): | |
self._width += width | |
self._space += space | |
attr = {} | |
@@ -31,11 +31,3 @@ class GameInventrory(SlotsGroup): | |
tag = 'item' | |
self._l += 1 | |
return Element(tag, attr) | |
- | |
- | |
- | |
- | |
- | |
- | |
- | |
- | |
diff --git a/ui/GamePages/inventory_page/InventoryPage.py b/ui/GamePages/inventory_page/InventoryPage.py | |
index f4e7091..824baaf 100644 | |
--- a/ui/GamePages/inventory_page/InventoryPage.py | |
+++ b/ui/GamePages/inventory_page/InventoryPage.py | |
@@ -9,7 +9,6 @@ from ui.GamePages.inventory_page.SlotsGroup import SlotsGroup | |
from ui.GamePages.inventory_page.SlotMoveMaster import SlotMoveMaster | |
- | |
from PySide2 import QtCore | |
@@ -56,12 +55,19 @@ class InventoryPage(AbstractPage): | |
self.item.hide() | |
self.updatePage() | |
- def sceneEvent(self, event:QtCore.QEvent): | |
- self.update(0, 0, self.gamePages.gameRoot.cfg.dev_size[0], self.gamePages.gameRoot.cfg.dev_size[1]) | |
+ def sceneEvent(self, event: QtCore.QEvent): | |
+ self.update( | |
+ 0, | |
+ 0, | |
+ self.gamePages.gameRoot.cfg.dev_size[0], | |
+ self.gamePages.gameRoot.cfg.dev_size[1]) | |
# if self.scrollSetEvent(event): | |
# return True | |
if event.type() is QtCore.QEvent.GraphicsSceneHoverMove: | |
- self.hoverMove(self.scene().itemAt(event.scenePos(), self.scene().views()[0].transform())) | |
+ self.hoverMove( | |
+ self.scene().itemAt( | |
+ event.scenePos(), | |
+ self.scene().views()[0].transform())) | |
return True | |
elif event.type() is QtCore.QEvent.GraphicsSceneContextMenu: | |
self.contextMenuEvent(event) | |
@@ -80,7 +86,9 @@ class InventoryPage(AbstractPage): | |
return super(InventoryPage, self).sceneEvent(event) | |
def contextMenuEvent(self, event): | |
- item = self.scene().itemAt(event.scenePos(), self.scene().views()[0].transform()) | |
+ item = self.scene().itemAt( | |
+ event.scenePos(), | |
+ self.scene().views()[0].transform()) | |
print('contex', item.name) | |
if item._names[0] == 'shop': | |
self.move_master.buy(item) | |
@@ -90,7 +98,9 @@ class InventoryPage(AbstractPage): | |
self.move_master.unequip(item) | |
def mousePressEvent(self, event): | |
- item = self.scene().itemAt(event.scenePos(), self.scene().views()[0].transform()) | |
+ item = self.scene().itemAt( | |
+ event.scenePos(), | |
+ self.scene().views()[0].transform()) | |
if item._names[0] == 'inventory': | |
self.moveInventoryItem(item) | |
@@ -101,7 +111,9 @@ class InventoryPage(AbstractPage): | |
self.s_engine.mouseReleaseEvent() | |
def mousePressLeft(self, event): | |
- item = self.scene().itemAt(event.scenePos(), self.scene().views()[0].transform()) | |
+ item = self.scene().itemAt( | |
+ event.scenePos(), | |
+ self.scene().views()[0].transform()) | |
if item._names[0] == 'inventory': | |
self.move_master.moved_slot = self.inventories.getMovedSlot(item) | |
elif item._names[0] == 'equip': | |
@@ -132,9 +144,9 @@ class InventoryPage(AbstractPage): | |
def show_info(self, item): | |
if item._names[0] == 'equip': | |
self.show_equipment_info(item) | |
- elif item._names[0] +'_'+ item._names[1] == 'inventory_slot': | |
+ elif item._names[0] + '_' + item._names[1] == 'inventory_slot': | |
self.show_inventory_info(item) | |
- elif item._names[0] +'_'+ item._names[1] == 'shop_slot': | |
+ elif item._names[0] + '_' + item._names[1] == 'shop_slot': | |
self.show_shop_info(item) | |
def keyPressEvent(self, e): | |
@@ -200,12 +212,14 @@ class InventoryPage(AbstractPage): | |
############ S C R O L L ############## | |
def setUpScroll(self): | |
- self.s_engine = ScrollBlock(self, width=self.items['scroll_block'].width) | |
+ self.s_engine = ScrollBlock( | |
+ self, width=self.items['scroll_block'].width) | |
self.s_engine.setScrollBut(self.items['scroll_but']) | |
for i in range(self.inventories.len): | |
- self.s_engine.addScrollItem(self.items['inventory_slot_'+str(i)]) | |
+ self.s_engine.addScrollItem(self.items['inventory_slot_' + str(i)]) | |
- self.s_engine_2 = ScrollBlock(self, width=self.items['shop_scroll_block'].width) | |
+ self.s_engine_2 = ScrollBlock( | |
+ self, width=self.items['shop_scroll_block'].width) | |
self.s_engine_2.setScrollBut(self.items['shop_scroll_but']) | |
for i in range(self.shop.len): | |
self.s_engine_2.addScrollItem(self.items['shop_slot_' + str(i)]) | |
@@ -250,7 +264,8 @@ class InventoryPage(AbstractPage): | |
def show_equipment_info(self, item): | |
slot = self.equipments.slots.get(item.name) | |
if slot is not None: | |
- self.items.get('info_value').setText(self.setDict(slot.tooltip_info)) | |
+ self.items.get('info_value').setText( | |
+ self.setDict(slot.tooltip_info)) | |
############## S H O P ############## | |
@@ -265,5 +280,5 @@ class InventoryPage(AbstractPage): | |
def show_shop_info(self, item): | |
slot = self.shop.slots.get(item.name) | |
if slot is not None: | |
- self.items.get('info_value').setText(self.setDict(self.shop.show_info(slot))) | |
- | |
+ self.items.get('info_value').setText( | |
+ self.setDict(self.shop.show_info(slot))) | |
diff --git a/ui/GamePages/inventory_page/ScrollBlock.py b/ui/GamePages/inventory_page/ScrollBlock.py | |
index ed1d670..dea6074 100644 | |
--- a/ui/GamePages/inventory_page/ScrollBlock.py | |
+++ b/ui/GamePages/inventory_page/ScrollBlock.py | |
@@ -3,7 +3,7 @@ from PySide2.QtWidgets import QGraphicsSceneEvent | |
class ScrollBlock: | |
- def __init__(self, page, width = 0): | |
+ def __init__(self, page, width=0): | |
self.page = page | |
self.but = None | |
self.but_step = 0 | |
@@ -27,7 +27,8 @@ class ScrollBlock: | |
def getItemsWidth(self): | |
l = len(self.scoll_items) | |
if l > 1: | |
- return self.scoll_items[l-1]._left - self.scoll_items[0]._left + 2 * self.scoll_items[l-1]._width | |
+ return self.scoll_items[l - 1]._left - \ | |
+ self.scoll_items[0]._left + 2 * self.scoll_items[l - 1]._width | |
elif l == 1: | |
return self.scoll_items[0]._width | |
elif l == 0: | |
@@ -65,11 +66,13 @@ class ScrollBlock: | |
for item in self.scoll_items: | |
item.scroll_x = item.scroll_x + self.items_step * self.getValue() | |
- def isScrollBut(self, event:QGraphicsSceneEvent): | |
- item = self.page.scene().itemAt(event.scenePos(), self.page.scene().views()[0].transform()) | |
+ def isScrollBut(self, event: QGraphicsSceneEvent): | |
+ item = self.page.scene().itemAt( | |
+ event.scenePos(), | |
+ self.page.scene().views()[0].transform()) | |
return item.name == self.but.name | |
- def mousePressEvent(self, event:QGraphicsSceneEvent): | |
+ def mousePressEvent(self, event: QGraphicsSceneEvent): | |
if self.isScrollBut(event): | |
self.start_pos.setX(event.screenPos().x()) | |
self.start_pos.setY(event.screenPos().y()) | |
@@ -82,11 +85,11 @@ class ScrollBlock: | |
self.but_x = x | |
self.items_upate_pos() | |
- def mouseMoveEvent(self, event:QGraphicsSceneEvent): | |
+ def mouseMoveEvent(self, event: QGraphicsSceneEvent): | |
if self.isDown: | |
self.delta_x = self.start_pos.x() - event.screenPos().x() | |
self.delta_y = self.start_pos.y() - event.screenPos().y() | |
self.but_move() | |
def getValue(self): | |
- return int(self.delta_x/self.but_step) | |
+ return int(self.delta_x / self.but_step) | |
diff --git a/ui/GamePages/inventory_page/SlotMoveMaster.py b/ui/GamePages/inventory_page/SlotMoveMaster.py | |
index 8ee9309..f17034f 100644 | |
--- a/ui/GamePages/inventory_page/SlotMoveMaster.py | |
+++ b/ui/GamePages/inventory_page/SlotMoveMaster.py | |
@@ -4,7 +4,7 @@ from game_objects.items import ItemTransactions | |
class SlotMoveMaster: | |
def __init__(self, gameRoot, page): | |
- self.gameRoot =gameRoot | |
+ self.gameRoot = gameRoot | |
self.page = page | |
self.moved_slot = None | |
self.emty_icon = 'cha_page_elemnt_bg.png' | |
@@ -21,7 +21,8 @@ class SlotMoveMaster: | |
if self.moved_slot is not None and target_slot is not None: | |
if self.moved_slot.content.item_type == target_slot.item_type: | |
with ItemTransactions(self.gameRoot.lengine.the_hero) as trans: | |
- state, msg = self.gameRoot.lengine.the_hero.equipment.equip(self.moved_slot) | |
+ state, msg = self.gameRoot.lengine.the_hero.equipment.equip( | |
+ self.moved_slot) | |
self.page.inventories.update_attr() | |
self.page.equipments.update_attr() | |
@@ -29,14 +30,15 @@ class SlotMoveMaster: | |
target_slot = self.page.inventories.slots.get(target_item.name) | |
if self.moved_slot is not None and target_slot is not None: | |
# if target_slot.content is not None: | |
- self.swap_slot(target_slot) | |
+ self.swap_slot(target_slot) | |
def equip(self, item): | |
slot = self.page.inventories.slots.get(item.name) | |
if slot is not None: | |
if slot.content is not None: | |
with ItemTransactions(self.gameRoot.lengine.the_hero) as trans: | |
- state, msg = self.gameRoot.lengine.the_hero.equipment.equip(slot) | |
+ state, msg = self.gameRoot.lengine.the_hero.equipment.equip( | |
+ slot) | |
self.page.inventories.update_attr() | |
self.page.equipments.update_attr() | |
@@ -47,7 +49,8 @@ class SlotMoveMaster: | |
with ItemTransactions(self.gameRoot.lengine.the_hero) as trans: | |
self.gameRoot.lengine.the_hero.equipment.unequip_slot(slot) | |
if slot.content is None: | |
- item.setPixmapIcon(self.page.equipments.default_icons[item.name]) | |
+ item.setPixmapIcon( | |
+ self.page.equipments.default_icons[item.name]) | |
def drop_slot(self): | |
if self.moved_slot is not None: | |
@@ -81,4 +84,5 @@ class SlotMoveMaster: | |
item.setPixmapIcon(self.emty_icon) | |
def update_gold_count(self): | |
- self.page.items['hero_gold_value'].setText(str(self.gameRoot.game.shop.customer.gold)) | |
+ self.page.items['hero_gold_value'].setText( | |
+ str(self.gameRoot.game.shop.customer.gold)) | |
diff --git a/ui/GamePages/inventory_page/SlotsGroup.py b/ui/GamePages/inventory_page/SlotsGroup.py | |
index 3dfa3b3..4d5113a 100644 | |
--- a/ui/GamePages/inventory_page/SlotsGroup.py | |
+++ b/ui/GamePages/inventory_page/SlotsGroup.py | |
@@ -22,10 +22,10 @@ class SlotsGroup: | |
def len(self): | |
return self._l | |
- def setUpSlots(self, element:Element): | |
+ def setUpSlots(self, element: Element): | |
pass | |
- def create_slot(self, slot:Slot, width=128, height=128, space=10): | |
+ def create_slot(self, slot: Slot, width=128, height=128, space=10): | |
pass | |
def update_attr(self): | |
@@ -51,6 +51,3 @@ class SlotsGroup: | |
for k, v in data.items(): | |
result = result + k + ' : ' + v + '\n' | |
return result | |
- | |
- | |
- | |
diff --git a/ui/GamePages/suwidgets/Actives.py b/ui/GamePages/suwidgets/Actives.py | |
index 8bbbbb1..d6d3c6d 100644 | |
--- a/ui/GamePages/suwidgets/Actives.py | |
+++ b/ui/GamePages/suwidgets/Actives.py | |
@@ -7,7 +7,15 @@ class Actives(QtCore.QObject): | |
setTargets = QtCore.Signal(list) | |
action_on = QtCore.Signal(dict) | |
- def __init__(self, page, parent = None, widget_size = (64, 64), margin = 10, columns = 3): | |
+ def __init__( | |
+ self, | |
+ page, | |
+ parent=None, | |
+ widget_size=( | |
+ 64, | |
+ 64), | |
+ margin=10, | |
+ columns=3): | |
super(Actives, self).__init__(parent) | |
self.x, self.y = 0, 0 | |
self.rect = QtCore.QRectF(self.x, self.y, 1, 1) | |
@@ -26,7 +34,9 @@ class Actives(QtCore.QObject): | |
self.row = 0 | |
self.column = 0 | |
- self.sizePolicy = QtWidgets.QSizePolicy(QtWidgets.QSizePolicy.Minimum, QtWidgets.QSizePolicy.Minimum) | |
+ self.sizePolicy = QtWidgets.QSizePolicy( | |
+ QtWidgets.QSizePolicy.Minimum, | |
+ QtWidgets.QSizePolicy.Minimum) | |
self.setFrameSize(self.widget_size, 1, 1) | |
self.setActivesSize() | |
self.setNames() | |
@@ -39,11 +49,11 @@ class Actives(QtCore.QObject): | |
self.rect.setWidth(self.w) | |
self.rect.setHeight(self.h) | |
- def setFrameSize(self, size:set, col:int, row:int): | |
+ def setFrameSize(self, size: set, col: int, row: int): | |
w = size[0] * col + self.margin * (col + 2) | |
h = size[1] * row + self.margin * (row + 2) | |
self.frame_size = (w, h) | |
- if not self.frame is None: | |
+ if self.frame is not None: | |
self.frame.setMinimumSize(self.frame_size[0], self.frame_size[1]) | |
def addWidget(self, name): | |
@@ -64,15 +74,20 @@ class Actives(QtCore.QObject): | |
else: | |
self.column += 1 | |
self.n += 1 | |
- self.setFrameSize(self.widget_size, self.columns, self.rows) | |
+ self.setFrameSize(self.widget_size, self.columns, self.rows) | |
self.setActivesSize() | |
- widget.ajGeometry = QtCore.QRect(self.x + widget.x(), self.y + widget.y(), self.widget_size[0], self.widget_size[1]) | |
+ widget.ajGeometry = QtCore.QRect( | |
+ self.x + widget.x(), | |
+ self.y + widget.y(), | |
+ self.widget_size[0], | |
+ self.widget_size[1]) | |
self.widgets[name] = widget | |
def showToolTip(self, widget): | |
x = widget.x() + self.frame.x() + self.x | |
y = widget.y() + self.frame.y() + self.y | |
- self.page.gamePages.toolTip.setPos(self.page.scene().views()[0].mapToScene(x, y)) | |
+ self.page.gamePages.toolTip.setPos( | |
+ self.page.scene().views()[0].mapToScene(x, y)) | |
self.page.gamePages.toolTip.setText(widget.property('active_name')) | |
self.page.gamePages.toolTip.show() | |
pass | |
@@ -86,12 +101,12 @@ class Actives(QtCore.QObject): | |
widget.setProperty('status', active.affordable()) | |
widget.setProperty('active', active) | |
widget.setStyleSheet('QPushButton[status = "true"]{' | |
- 'background-color:black;}' | |
- 'QPushButton[status = "false"]{' | |
- 'background-color:gray;}' | |
- 'QPushButton:pressed {' | |
- 'background-color: white;' | |
- 'color:black}') | |
+ 'background-color:black;}' | |
+ 'QPushButton[status = "false"]{' | |
+ 'background-color:gray;}' | |
+ 'QPushButton:pressed {' | |
+ 'background-color: white;' | |
+ 'color:black}') | |
def setNames(self): | |
self.names = ['run', | |
@@ -140,13 +155,15 @@ class Actives(QtCore.QObject): | |
self.mainWidget.setLayout(mainLayout) | |
self.up.pressed.connect(self.upSlot) | |
self.down.pressed.connect(self.downSlot) | |
- self.mainWidget:QtWidgets.QGraphicsProxyWidget = self.page.gamePages.gameRoot.scene.addWidget(self.mainWidget) | |
- self.mainWidget.setFlags(QtWidgets.QGraphicsItem.ItemIgnoresTransformations) | |
+ self.mainWidget: QtWidgets.QGraphicsProxyWidget = self.page.gamePages.gameRoot.scene.addWidget( | |
+ self.mainWidget) | |
+ self.mainWidget.setFlags( | |
+ QtWidgets.QGraphicsItem.ItemIgnoresTransformations) | |
self.resized() | |
- def resized(self, size = None): | |
+ def resized(self, size=None): | |
size = self.page.gamePages.gameRoot.cfg.dev_size | |
- self.x = size[0] / 2 - self.w /2 | |
+ self.x = size[0] / 2 - self.w / 2 | |
self.y = size[1] - self.h | |
self.mainWidget.setPos(self.x, self.y) | |
self.mainWidget.widget().setFixedSize(self.w + 30, self.h) | |
@@ -160,7 +177,8 @@ class Actives(QtCore.QObject): | |
if active.name == 'turn CW': | |
self.page.gamePages.gameRoot.game.order_turn_cw() | |
return | |
- targets = self.page.gamePages.gameRoot.game.get_possible_targets(active) | |
+ targets = self.page.gamePages.gameRoot.game.get_possible_targets( | |
+ active) | |
if targets is not None: | |
if targets: | |
self.setTargets.emit(targets) | |
@@ -203,5 +221,3 @@ class Actives(QtCore.QObject): | |
else: | |
name = 'active_move.png' | |
return QIcon(self.page.gamePages.gameRoot.cfg.getPicFile(name)) | |
- | |
- | |
diff --git a/ui/GamePages/suwidgets/BaseItem.py b/ui/GamePages/suwidgets/BaseItem.py | |
index 7c4378c..055bb44 100644 | |
--- a/ui/GamePages/suwidgets/BaseItem.py | |
+++ b/ui/GamePages/suwidgets/BaseItem.py | |
@@ -11,7 +11,8 @@ class BaseItem(QGraphicsObject): | |
self.attrib = None | |
self.setAcceptHoverEvents(True) | |
self.setAcceptDrops(True) | |
- self.setAcceptedMouseButtons(QtCore.Qt.LeftButton | QtCore.Qt.RightButton) | |
+ self.setAcceptedMouseButtons( | |
+ QtCore.Qt.LeftButton | QtCore.Qt.RightButton) | |
self.isHover = False | |
self.isDown = False | |
self.isChecked = False | |
@@ -56,7 +57,8 @@ class BaseItem(QGraphicsObject): | |
self.paint = self.paint_bg | |
if attrib.get('icon') is not None: | |
self.paint = self.paint_pic | |
- if attrib.get('icon') is not None and attrib.get('background-color') is not None: | |
+ if attrib.get('icon') is not None and attrib.get( | |
+ 'background-color') is not None: | |
self.paint = self.paint_pic_bg | |
if attrib.get('input') is None: | |
self.input = '' | |
@@ -66,23 +68,49 @@ class BaseItem(QGraphicsObject): | |
def boundingRect(self): | |
return QtCore.QRect(self._left, self._top, self._width, self._height) | |
- def paint(self, painter:QPainter, option:QStyleOptionGraphicsItem, widget:QWidget=...): | |
+ def paint( | |
+ self, | |
+ painter: QPainter, | |
+ option: QStyleOptionGraphicsItem, | |
+ widget: QWidget = ...): | |
painter.drawRect(self._left, self._top, self._width, self._height) | |
- def paint_bg(self, painter:QPainter, option:QStyleOptionGraphicsItem, widget:QWidget=...): | |
+ def paint_bg( | |
+ self, | |
+ painter: QPainter, | |
+ option: QStyleOptionGraphicsItem, | |
+ widget: QWidget = ...): | |
painter.setBrush(self._bg_brush) | |
painter.drawRect(self._left, self._top, self._width, self._height) | |
pass | |
- def paint_pic(self, painter:QPainter, option:QStyleOptionGraphicsItem, widget:QWidget=...): | |
+ def paint_pic( | |
+ self, | |
+ painter: QPainter, | |
+ option: QStyleOptionGraphicsItem, | |
+ widget: QWidget = ...): | |
painter.setRenderHint(QPainter.SmoothPixmapTransform, True) | |
- painter.drawPixmap(self._left, self._top, self._width, self._height, self.pixmap) | |
+ painter.drawPixmap( | |
+ self._left, | |
+ self._top, | |
+ self._width, | |
+ self._height, | |
+ self.pixmap) | |
pass | |
- def paint_pic_bg(self, painter:QPainter, option:QStyleOptionGraphicsItem, widget:QWidget=...): | |
+ def paint_pic_bg( | |
+ self, | |
+ painter: QPainter, | |
+ option: QStyleOptionGraphicsItem, | |
+ widget: QWidget = ...): | |
painter.setBrush(self._bg_brush) | |
painter.drawRect(self._left, self._top, self._width, self._height) | |
- painter.drawPixmap(self._left, self._top, self._width, self._height, self.pixmap) | |
+ painter.drawPixmap( | |
+ self._left, | |
+ self._top, | |
+ self._width, | |
+ self._height, | |
+ self.pixmap) | |
pass | |
@property | |
@@ -90,17 +118,13 @@ class BaseItem(QGraphicsObject): | |
return int(self.attrib.get('width')) * self.scale_x | |
def update(self): | |
- super(BaseItem, self).update(self._left, self._top, self.width, self._height) | |
- | |
- def setPixmapIcon(self, icon:str): | |
+ super( | |
+ BaseItem, | |
+ self).update( | |
+ self._left, | |
+ self._top, | |
+ self.width, | |
+ self._height) | |
+ | |
+ def setPixmapIcon(self, icon: str): | |
self.pixmap = self.gameRoot.cfg.getPicFile(icon) | |
- | |
- | |
- | |
- | |
- | |
- | |
- | |
- | |
- | |
- | |
diff --git a/ui/GamePages/suwidgets/GameButton.py b/ui/GamePages/suwidgets/GameButton.py | |
index 4b4482a..915afae 100644 | |
--- a/ui/GamePages/suwidgets/GameButton.py | |
+++ b/ui/GamePages/suwidgets/GameButton.py | |
@@ -5,12 +5,12 @@ class GameButton(QtWidgets.QPushButton): | |
hovered = QtCore.Signal(QtCore.QObject) | |
hover_out = QtCore.Signal(QtCore.QObject) | |
- def __init__(self, *args, parent = None): | |
+ def __init__(self, *args, parent=None): | |
super(GameButton, self).__init__(*args, parent) | |
self.setAttribute(QtCore.Qt.WA_Hover) | |
self.installEventFilter(self) | |
- def eventFilter(self, watched:QtCore.QObject, event:QtCore.QEvent): | |
+ def eventFilter(self, watched: QtCore.QObject, event: QtCore.QEvent): | |
if event.type() == QtCore.QEvent.HoverEnter: | |
watched.hovered.emit(watched) | |
pass | |
diff --git a/ui/GamePages/suwidgets/GameLabel.py b/ui/GamePages/suwidgets/GameLabel.py | |
index 3f5c861..42b9235 100644 | |
--- a/ui/GamePages/suwidgets/GameLabel.py | |
+++ b/ui/GamePages/suwidgets/GameLabel.py | |
@@ -5,12 +5,12 @@ class GameLabel(QtWidgets.QLabel): | |
hovered = QtCore.Signal(QtCore.QObject) | |
hover_out = QtCore.Signal(QtCore.QObject) | |
- def __init__(self, *args, parent = None): | |
+ def __init__(self, *args, parent=None): | |
super(GameLabel, self).__init__(*args, parent) | |
self.setAttribute(QtCore.Qt.WA_Hover) | |
self.installEventFilter(self) | |
- def eventFilter(self, watched:QtCore.QObject, event:QtCore.QEvent): | |
+ def eventFilter(self, watched: QtCore.QObject, event: QtCore.QEvent): | |
if event.type() == QtCore.QEvent.HoverEnter: | |
watched.hovered.emit(watched) | |
pass | |
diff --git a/ui/GamePages/suwidgets/GameMsgBox.py b/ui/GamePages/suwidgets/GameMsgBox.py | |
index 19c83f4..a69000b 100644 | |
--- a/ui/GamePages/suwidgets/GameMsgBox.py | |
+++ b/ui/GamePages/suwidgets/GameMsgBox.py | |
@@ -7,13 +7,16 @@ class GameMsgBox(QtWidgets.QDialog): | |
CANCEL = 1 | |
SAVE = 2 | |
- def __init__(self, page, parent = None): | |
+ def __init__(self, page, parent=None): | |
super(GameMsgBox, self).__init__(parent) | |
self.widget_pos = QtCore.QPoint() | |
self.page = page | |
self.setWidgetGeometry(page.gamePages.gameRoot.cfg) | |
- self.setStyleSheet("background-image: url('resources/UI/Assets/scroll_background.png');") | |
- self.setSizePolicy(QtWidgets.QSizePolicy.Fixed, QtWidgets.QSizePolicy.Fixed) | |
+ self.setStyleSheet( | |
+ "background-image: url('resources/UI/Assets/scroll_background.png');") | |
+ self.setSizePolicy( | |
+ QtWidgets.QSizePolicy.Fixed, | |
+ QtWidgets.QSizePolicy.Fixed) | |
self.finished.connect(self.hide) | |
self.setUpWigets() | |
@@ -30,29 +33,38 @@ class GameMsgBox(QtWidgets.QDialog): | |
h = 640 | |
elif cfg.dev_size[1] >= 1050: | |
h = 960 | |
- self.widget_pos.setX((cfg.dev_size[0] - w)/2) | |
- self.widget_pos.setY((cfg.dev_size[1] - h)/2) | |
+ self.widget_pos.setX((cfg.dev_size[0] - w) / 2) | |
+ self.widget_pos.setY((cfg.dev_size[1] - h) / 2) | |
self.move(self.widget_pos) | |
self.setFixedSize(w, h) | |
def setUpWigets(self): | |
self.grid = QtWidgets.QGridLayout(self) | |
self.tetx_label = QtWidgets.QLabel('text') | |
- self.grid.addWidget(self.tetx_label, 1, 0, alignment = QtCore.Qt.AlignCenter) | |
+ self.grid.addWidget( | |
+ self.tetx_label, | |
+ 1, | |
+ 0, | |
+ alignment=QtCore.Qt.AlignCenter) | |
self.info_text_label = QtWidgets.QLabel('info text') | |
- self.grid.addWidget(self.info_text_label, 2, 0, 3, 1, alignment = QtCore.Qt.AlignCenter) | |
+ self.grid.addWidget(self.info_text_label, 2, 0, 3, | |
+ 1, alignment=QtCore.Qt.AlignCenter) | |
self.btn_layout = QtWidgets.QHBoxLayout() | |
but = self.getButton('Ok') | |
but.clicked.connect(self.accept) | |
self.btn_layout.addWidget(but) | |
- self.grid.addLayout(self.btn_layout, 7, 0, alignment = QtCore.Qt.AlignRight) | |
+ self.grid.addLayout( | |
+ self.btn_layout, | |
+ 7, | |
+ 0, | |
+ alignment=QtCore.Qt.AlignRight) | |
- def setInformativeText(self, text, format = QtCore.Qt.AutoText): | |
+ def setInformativeText(self, text, format=QtCore.Qt.AutoText): | |
self.info_text_label.setTextFormat(format) | |
self.info_text_label.setText(text) | |
pass | |
- def setText(self, text, format = QtCore.Qt.AutoText): | |
+ def setText(self, text, format=QtCore.Qt.AutoText): | |
self.tetx_label.setTextFormat(format) | |
self.tetx_label.setText(text) | |
pass | |
@@ -74,7 +86,11 @@ class GameMsgBox(QtWidgets.QDialog): | |
self.btn_layout.addWidget(but) | |
elif index == 2: | |
self.btn_layout.addWidget(self.getButton('Save')) | |
- self.grid.addLayout(self.btn_layout, 7, 0, alignment=QtCore.Qt.AlignRight) | |
+ self.grid.addLayout( | |
+ self.btn_layout, | |
+ 7, | |
+ 0, | |
+ alignment=QtCore.Qt.AlignRight) | |
pass | |
def getButton(self, name): | |
@@ -92,4 +108,4 @@ class GameMsgBox(QtWidgets.QDialog): | |
self.setResult(1) | |
def resized(self): | |
- pass | |
\ No newline at end of file | |
+ pass | |
diff --git a/ui/GamePages/suwidgets/GroupItem.py b/ui/GamePages/suwidgets/GroupItem.py | |
index cb32354..f527c82 100644 | |
--- a/ui/GamePages/suwidgets/GroupItem.py | |
+++ b/ui/GamePages/suwidgets/GroupItem.py | |
@@ -41,5 +41,6 @@ class GroupItem: | |
self.paint = self.paint_bg | |
if attrib.get('icon') is not None: | |
self.paint = self.paint_pic | |
- if attrib.get('icon') is not None and attrib.get('background-color') is not None: | |
+ if attrib.get('icon') is not None and attrib.get( | |
+ 'background-color') is not None: | |
self.paint = self.paint_pic_bg | |
diff --git a/ui/GamePages/suwidgets/GuiConsole.py b/ui/GamePages/suwidgets/GuiConsole.py | |
index 0ec8670..163f72c 100644 | |
--- a/ui/GamePages/suwidgets/GuiConsole.py | |
+++ b/ui/GamePages/suwidgets/GuiConsole.py | |
@@ -28,7 +28,11 @@ class GuiConsole(QtWidgets.QPlainTextEdit): | |
x = self.widget_pos.x() + self.btn.width() - self.width() | |
self.state = True | |
self.widget_pos.setX(x) | |
- self.rect.setRect(self.widget_pos.x(), self.widget_pos.y(), self.width(), self.height()) | |
+ self.rect.setRect( | |
+ self.widget_pos.x(), | |
+ self.widget_pos.y(), | |
+ self.width(), | |
+ self.height()) | |
def timerEvent(self, e): | |
if self.last_msg != self.log.msg: | |
@@ -41,11 +45,14 @@ class GuiConsole(QtWidgets.QPlainTextEdit): | |
else: | |
self.widget_pos.setX(dev_size[0] - self.btn.width()) | |
self.widget_pos.setY(dev_size[1] - self.height()) | |
- self.rect.setRect(self.widget_pos.x(), self.widget_pos.y(), self.width(), self.height()) | |
+ self.rect.setRect( | |
+ self.widget_pos.x(), | |
+ self.widget_pos.y(), | |
+ self.width(), | |
+ self.height()) | |
def setMousePos(self, e): | |
self.mousePos = e.pos() | |
def isFocus(self): | |
return self.rect.contains(self.mousePos) | |
- | |
diff --git a/ui/GamePages/suwidgets/Layouts/GameGridLayout.py b/ui/GamePages/suwidgets/Layouts/GameGridLayout.py | |
index 95a547d..52624c3 100644 | |
--- a/ui/GamePages/suwidgets/Layouts/GameGridLayout.py | |
+++ b/ui/GamePages/suwidgets/Layouts/GameGridLayout.py | |
@@ -20,27 +20,31 @@ class GameGridLayout(GameLayout): | |
# h = item.sizeHint().height() | |
w = s.width() | |
h = s.height() | |
- item.setPos(self._x + i * self._spacing + i * w, self._y + j * self._spacing + j * h) | |
+ item.setPos( | |
+ self._x + i * self._spacing + i * w, | |
+ self._y + j * self._spacing + j * h) | |
def sizeHint(self): | |
s = QtCore.QSize(0, 0) | |
n = len(self.items) | |
j, i = self.maxInex() | |
- j, i = j+1, i+1 | |
+ j, i = j + 1, i + 1 | |
if n > 0: | |
s = QtCore.QSize(32, 32) | |
for item in self.items: | |
s = s.expandedTo(item.sizeHint()) | |
- return QtCore.QSize(i*s.width() + i * self._spacing, j*s.height() + j * self._spacing) | |
+ return QtCore.QSize( | |
+ i * s.width() + i * self._spacing, | |
+ j * s.height() + j * self._spacing) | |
def maxInex(self): | |
- _i,_j = 0, 0 | |
- for i,j in self.items_pos.values(): | |
+ _i, _j = 0, 0 | |
+ for i, j in self.items_pos.values(): | |
if i > _i: | |
_i = i | |
if j > _j: | |
_j = j | |
- return _i,_j | |
+ return _i, _j | |
def maxSizeWidget(self): | |
s = QtCore.QSize(0, 0) | |
diff --git a/ui/GamePages/suwidgets/Layouts/GameLayout.py b/ui/GamePages/suwidgets/Layouts/GameLayout.py | |
index 851fe46..c5e1a1a 100644 | |
--- a/ui/GamePages/suwidgets/Layouts/GameLayout.py | |
+++ b/ui/GamePages/suwidgets/Layouts/GameLayout.py | |
@@ -28,4 +28,3 @@ class GameLayout: | |
def maxSizeWidget(self): | |
pass | |
- | |
diff --git a/ui/GamePages/suwidgets/NotifyText.py b/ui/GamePages/suwidgets/NotifyText.py | |
index cb16b2f..f7430f0 100644 | |
--- a/ui/GamePages/suwidgets/NotifyText.py | |
+++ b/ui/GamePages/suwidgets/NotifyText.py | |
@@ -2,7 +2,7 @@ from PySide2 import QtCore, QtWidgets | |
class NotifyText(QtWidgets.QGraphicsTextItem): | |
- def __init__(self, parent = None): | |
+ def __init__(self, parent=None): | |
QtWidgets.QGraphicsTextItem.__init__(self, parent) | |
self.gameRoot = None | |
self.setFlag(QtWidgets.QGraphicsItem.ItemIgnoresTransformations, True) | |
@@ -27,5 +27,8 @@ class NotifyText(QtWidgets.QGraphicsTextItem): | |
self.anim.start() | |
def resized(self): | |
- self.setPos(self.gameRoot.view.mapToScene(self.widget_pos[0], self.widget_pos[1])) | |
+ self.setPos( | |
+ self.gameRoot.view.mapToScene( | |
+ self.widget_pos[0], | |
+ self.widget_pos[1])) | |
pass | |
diff --git a/ui/GamePages/suwidgets/SuWidgetFactory.py b/ui/GamePages/suwidgets/SuWidgetFactory.py | |
index bd55d21..b9b6279 100644 | |
--- a/ui/GamePages/suwidgets/SuWidgetFactory.py | |
+++ b/ui/GamePages/suwidgets/SuWidgetFactory.py | |
@@ -5,13 +5,21 @@ from ui.GamePages.suwidgets.NotifyText import NotifyText | |
from abc import abstractmethod | |
+ | |
class SuWidgetFactory: | |
"""docstring for SuWidgetFactory.""" | |
+ | |
def __init__(self): | |
pass | |
@abstractmethod | |
- def getToolTip(gameRoot, w = 128, h = 128, minimumLeters = 16, pointSize = 16, opacity = 0.8): | |
+ def getToolTip( | |
+ gameRoot, | |
+ w=128, | |
+ h=128, | |
+ minimumLeters=16, | |
+ pointSize=16, | |
+ opacity=0.8): | |
tooltip = ToolTip(gameRoot) | |
tooltip.minimumLeters = minimumLeters | |
tooltip.setBrush(QtGui.QBrush(QtCore.Qt.black)) | |
diff --git a/ui/GamePages/suwidgets/SupportPanel.py b/ui/GamePages/suwidgets/SupportPanel.py | |
index a14125d..2c7ceb9 100644 | |
--- a/ui/GamePages/suwidgets/SupportPanel.py | |
+++ b/ui/GamePages/suwidgets/SupportPanel.py | |
@@ -25,13 +25,16 @@ class SupportPanel(QtWidgets.QWidget): | |
self.down_chest = None | |
pic_path = self.cfg.pic_file_paths.get('chest_0.png') | |
if pic_path: | |
- self.down_chest = "background-image: url('" + pic_path + "');"+bg_style | |
+ self.down_chest = "background-image: url('" + \ | |
+ pic_path + "');" + bg_style | |
pic_path = self.cfg.pic_file_paths.get('chest_1.png') | |
if pic_path: | |
- self.up_chest = "background-image: url('" + pic_path + "');"+bg_style | |
+ self.up_chest = "background-image: url('" + \ | |
+ pic_path + "');" + bg_style | |
pic_path = self.cfg.pic_file_paths.get('navigation.png') | |
- self.navigation = "background-image: url('" + pic_path + "');"+bg_style | |
+ self.navigation = "background-image: url('" + \ | |
+ pic_path + "');" + bg_style | |
def setUpWidgets(self): | |
layout = QtWidgets.QVBoxLayout(self) | |
diff --git a/ui/GamePages/suwidgets/TextItem.py b/ui/GamePages/suwidgets/TextItem.py | |
index 63fc796..6163165 100644 | |
--- a/ui/GamePages/suwidgets/TextItem.py | |
+++ b/ui/GamePages/suwidgets/TextItem.py | |
@@ -82,7 +82,8 @@ class TextItem(QGraphicsSimpleTextItem): | |
self.paint = self.paint_bg | |
if attrib.get('icon') is not None: | |
self.paint = self.paint_pic | |
- if attrib.get('icon') is not None and attrib.get('background-color') is not None: | |
+ if attrib.get('icon') is not None and attrib.get( | |
+ 'background-color') is not None: | |
self.paint = self.paint_pic_bg | |
if attrib.get('input') is None: | |
self.input = '' | |
@@ -94,9 +95,10 @@ class TextItem(QGraphicsSimpleTextItem): | |
self.setText(attrib['text']) | |
self._font = self.cfg.getFont() | |
if attrib.get('font_size') is None: | |
- self._font.setPointSize(int(16* self.scale_y)) | |
+ self._font.setPointSize(int(16 * self.scale_y)) | |
else: | |
- self._font.setPointSize(int(attrib.get('font_size')) * self.scale_y) | |
+ self._font.setPointSize( | |
+ int(attrib.get('font_size')) * self.scale_y) | |
self.setFont(self._font) | |
# if self.document().size().width() > self._width: | |
# while self.document().size().width() > self._width: | |
diff --git a/ui/GamePages/suwidgets/ToolTip.py b/ui/GamePages/suwidgets/ToolTip.py | |
index a80a556..af92f67 100644 | |
--- a/ui/GamePages/suwidgets/ToolTip.py | |
+++ b/ui/GamePages/suwidgets/ToolTip.py | |
@@ -10,7 +10,8 @@ class ToolTip(QtCore.QObject, QtWidgets.QGraphicsRectItem): | |
self.minimuWidth Зависит от шрифта и self.minimumLeters -- минимальное количество символов | |
""" | |
- def __init__(self, gameRoot, parent = None): | |
+ | |
+ def __init__(self, gameRoot, parent=None): | |
QtCore.QObject.__init__(self, parent) | |
QtWidgets.QGraphicsRectItem.__init__(self, parent) | |
self.setFlag(QtWidgets.QGraphicsItem.ItemIgnoresTransformations, True) | |
diff --git a/ui/GamePages/suwidgets/items/GropsTypes.py b/ui/GamePages/suwidgets/items/GropsTypes.py | |
index 032c65f..5363222 100644 | |
--- a/ui/GamePages/suwidgets/items/GropsTypes.py | |
+++ b/ui/GamePages/suwidgets/items/GropsTypes.py | |
@@ -1,5 +1,6 @@ | |
from my_utils.named_enums import NameEnum, auto | |
+ | |
class GropusTypes(NameEnum): | |
INVENTORY = auto() | |
EQUIPMENT = auto() | |
diff --git a/ui/GamePages/suwidgets/items/InventoryGroupsWidget.py b/ui/GamePages/suwidgets/items/InventoryGroupsWidget.py | |
index 9ceefe4..6c2f34b 100644 | |
--- a/ui/GamePages/suwidgets/items/InventoryGroupsWidget.py | |
+++ b/ui/GamePages/suwidgets/items/InventoryGroupsWidget.py | |
@@ -36,11 +36,11 @@ class InventoryGroupsWidget: | |
def getInventoryGroup(self): | |
group = QtWidgets.QTabWidget(self) | |
self.equimpment = EquipmentWidget(page=self.page, parent=group) | |
- group.addTab(self.equimpment,'Equipment') | |
+ group.addTab(self.equimpment, 'Equipment') | |
self.quick_items = QuickItems(page=self.page, parent=group) | |
- group.addTab(self.quick_items,'Quick items') | |
+ group.addTab(self.quick_items, 'Quick items') | |
self.scroll = QtWidgets.QScrollArea(parent=self) | |
- self.shop = ShopWidget(page=self.page, parent=group ) | |
+ self.shop = ShopWidget(page=self.page, parent=group) | |
self.scroll.setWidget(self.shop) | |
group.addTab(self.scroll, 'Shop') | |
return group | |
diff --git a/ui/GamePages/suwidgets/items/SlotWidget.py b/ui/GamePages/suwidgets/items/SlotWidget.py | |
index 8dc38a2..c1b2e48 100644 | |
--- a/ui/GamePages/suwidgets/items/SlotWidget.py | |
+++ b/ui/GamePages/suwidgets/items/SlotWidget.py | |
@@ -8,7 +8,7 @@ class SlotWidget(QtWidgets.QGraphicsObject, QtWidgets.QGraphicsLayoutItem): | |
hover_out = QtCore.Signal(QtCore.QObject) | |
slot_changed = QtCore.Signal(QtWidgets.QLabel, QtWidgets.QLabel) | |
- def __init__(self, name, page, slot_type, parent = None): | |
+ def __init__(self, name, page, slot_type, parent=None): | |
QtWidgets.QGraphicsObject.__init__(self, parent) | |
QtWidgets.QGraphicsLayoutItem.__init__(self, parent) | |
self.page = page | |
@@ -17,7 +17,8 @@ class SlotWidget(QtWidgets.QGraphicsObject, QtWidgets.QGraphicsLayoutItem): | |
self.slot_type = slot_type | |
self.setAcceptHoverEvents(True) | |
self.setAcceptDrops(True) | |
- self.setAcceptedMouseButtons(QtCore.Qt.LeftButton|QtCore.Qt.RightButton) | |
+ self.setAcceptedMouseButtons( | |
+ QtCore.Qt.LeftButton | QtCore.Qt.RightButton) | |
self.setFlag(QtWidgets.QGraphicsItem.ItemIgnoresTransformations, True) | |
self._pos = QtCore.QPoint(-10, -10) | |
self.brush = self.cfg.brushs['b5adb7'] | |
@@ -31,35 +32,53 @@ class SlotWidget(QtWidgets.QGraphicsObject, QtWidgets.QGraphicsLayoutItem): | |
# self.installEventFilter(self) | |
self.state = False | |
- def setPixmap(self, pixmap:QtGui.QPixmap): | |
+ def setPixmap(self, pixmap: QtGui.QPixmap): | |
if pixmap is not None: | |
- self._geometry = QtCore.QRectF(self.pos().x(), self.pos().y(), pixmap.height(), pixmap.height()) | |
+ self._geometry = QtCore.QRectF( | |
+ self.pos().x(), | |
+ self.pos().y(), | |
+ pixmap.height(), | |
+ pixmap.height()) | |
self._pixmap = pixmap | |
def pixmap(self): | |
return self._pixmap | |
def boundingRect(self): | |
- return QtCore.QRect(0, 0, self._geometry.width(), self._geometry.height()) | |
- | |
- def paint(self, painter:QtGui.QPainter, option:QtWidgets.QStyleOptionGraphicsItem, widget:QtWidgets.QWidget=...): | |
- painter.setPen( self.pen) | |
+ return QtCore.QRect( | |
+ 0, | |
+ 0, | |
+ self._geometry.width(), | |
+ self._geometry.height()) | |
+ | |
+ def paint( | |
+ self, | |
+ painter: QtGui.QPainter, | |
+ option: QtWidgets.QStyleOptionGraphicsItem, | |
+ widget: QtWidgets.QWidget = ...): | |
+ painter.setPen(self.pen) | |
painter.setBrush(self.brush) | |
painter.setBackground(self.brush) | |
painter.drawRect(0, 0, self._geometry.width(), self._geometry.height()) | |
if self._pixmap is not None: | |
painter.drawPixmap(0, 0, self._pixmap) | |
- def sizeHint(self, which:QtCore.Qt.SizeHint = None, constraint:QtCore.QSizeF=None): | |
- return QtCore.QSize(self.boundingRect().width(), self.boundingRect().height()) | |
+ def sizeHint(self, which: QtCore.Qt.SizeHint = None, | |
+ constraint: QtCore.QSizeF = None): | |
+ return QtCore.QSize( | |
+ self.boundingRect().width(), | |
+ self.boundingRect().height()) | |
def geometry(self): | |
return QtCore.QRectF(0, 0, 64, 64) | |
- def sceneEventFilter(self, watched:QtWidgets.QGraphicsItem, event:QtCore.QEvent): | |
+ def sceneEventFilter( | |
+ self, | |
+ watched: QtWidgets.QGraphicsItem, | |
+ event: QtCore.QEvent): | |
return True | |
- def mouseReleaseEvent(self, event:QtWidgets.QGraphicsSceneMouseEvent): | |
+ def mouseReleaseEvent(self, event: QtWidgets.QGraphicsSceneMouseEvent): | |
if self.isDown: | |
if self.isChecked: | |
self.isChecked = False | |
@@ -82,7 +101,8 @@ class SlotWidget(QtWidgets.QGraphicsObject, QtWidgets.QGraphicsLayoutItem): | |
def mouseMoveEvent(self, event: QtWidgets.QGraphicsSceneMouseEvent): | |
if event.buttons() == QtCore.Qt.LeftButton: | |
- if QtWidgets.QApplication.startDragDistance() <= (event.pos() - self.dragStart).manhattanLength(): | |
+ if QtWidgets.QApplication.startDragDistance() <= ( | |
+ event.pos() - self.dragStart).manhattanLength(): | |
self.startDrag() | |
pass | |
@@ -94,18 +114,18 @@ class SlotWidget(QtWidgets.QGraphicsObject, QtWidgets.QGraphicsLayoutItem): | |
self.setY(pos.y() - self._pos.y()) | |
pass | |
- def hoverEnterEvent(self, event:QtWidgets.QGraphicsSceneHoverEvent): | |
+ def hoverEnterEvent(self, event: QtWidgets.QGraphicsSceneHoverEvent): | |
self.brush = self.cfg.brushs['d7a784'] | |
self.hovered.emit(self) | |
self.update(0, 0, self._geometry.width(), self._geometry.height()) | |
- def hoverLeaveEvent(self, event:QtWidgets.QGraphicsSceneHoverEvent): | |
+ def hoverLeaveEvent(self, event: QtWidgets.QGraphicsSceneHoverEvent): | |
if not self.isChecked: | |
self.brush = self.cfg.brushs['b5adb7'] | |
self.hover_out.emit(self) | |
self.update(0, 0, self._geometry.width(), self._geometry.height()) | |
- def dragEnterEvent(self, ev:QtGui.QDragEnterEvent): | |
+ def dragEnterEvent(self, ev: QtGui.QDragEnterEvent): | |
formats = ev.mimeData().formats() | |
self.brush = self.cfg.brushs['d7a784'] | |
self.update(0, 0, self._geometry.width(), self._geometry.height()) | |
@@ -114,14 +134,14 @@ class SlotWidget(QtWidgets.QGraphicsObject, QtWidgets.QGraphicsLayoutItem): | |
ev.setAccepted(True) | |
ev.acceptProposedAction() | |
- def dropEvent(self, ev:QtGui.QDropEvent): | |
+ def dropEvent(self, ev: QtGui.QDropEvent): | |
# Step 1 | |
if ev.dropAction() != QtCore.Qt.IgnoreAction: | |
self.page.startManipulation(self) | |
ev.acceptProposedAction() | |
pass | |
- def dragLeaveEvent(self, event:QtWidgets.QGraphicsSceneDragDropEvent): | |
+ def dragLeaveEvent(self, event: QtWidgets.QGraphicsSceneDragDropEvent): | |
self.brush = self.cfg.brushs['b5adb7'] | |
self.update(0, 0, self._geometry.width(), self._geometry.height()) | |
pass | |
@@ -132,7 +152,7 @@ class SlotWidget(QtWidgets.QGraphicsObject, QtWidgets.QGraphicsLayoutItem): | |
mimeData.setText(self.name) | |
drag.setPixmap(self.pixmap()) | |
drag.setMimeData(mimeData) | |
- result = drag.exec_(QtCore.Qt.CopyAction|QtCore.Qt.MoveAction) | |
+ result = drag.exec_(QtCore.Qt.CopyAction | QtCore.Qt.MoveAction) | |
self.page.startManipulation(self) | |
if result == QtCore.Qt.IgnoreAction: | |
self.page.drop(self.property('slot')) | |
@@ -170,6 +190,3 @@ class SlotWidget(QtWidgets.QGraphicsObject, QtWidgets.QGraphicsLayoutItem): | |
def clearSlot(self): | |
self.setPixmap(self.empty_pix) | |
- | |
- | |
- | |
diff --git a/ui/GamePages/suwidgets/items/on_unit/EquipmentWidget.py b/ui/GamePages/suwidgets/items/on_unit/EquipmentWidget.py | |
index 2dae55e..1cee173 100644 | |
--- a/ui/GamePages/suwidgets/items/on_unit/EquipmentWidget.py | |
+++ b/ui/GamePages/suwidgets/items/on_unit/EquipmentWidget.py | |
@@ -21,7 +21,7 @@ class EquipmentWidget(SlotGroupWidget): | |
self.setPicSlot(game_slot, slot) | |
layout.addItem(slot, 0, 2) | |
elif game_slot.name == EquipmentSlotUids.BODY.name: | |
- slot = self.getSlotWidget(game_slot, game_slot.name, h = 128) | |
+ slot = self.getSlotWidget(game_slot, game_slot.name, h=128) | |
self.setPicSlot(game_slot, slot) | |
layout.addItem(slot, 1, 2) | |
elif game_slot.name == EquipmentSlotUids.RING_1.name: | |
@@ -33,16 +33,18 @@ class EquipmentWidget(SlotGroupWidget): | |
self.setPicSlot(game_slot, slot) | |
layout.addItem(slot, 1, 4) | |
elif game_slot.name == EquipmentSlotUids.HANDS.name: | |
- slot_l = self.getSlotWidget(game_slot, game_slot.name + '_l', h = 128) | |
+ slot_l = self.getSlotWidget( | |
+ game_slot, game_slot.name + '_l', h=128) | |
self.setPicSlot(game_slot, slot_l) | |
layout.addItem(slot_l, 1, 1) | |
- slot_r = self.getSlotWidget(game_slot, game_slot.name + '_r', h = 128) | |
+ slot_r = self.getSlotWidget( | |
+ game_slot, game_slot.name + '_r', h=128) | |
self.setPicSlot(game_slot, slot_r) | |
layout.addItem(slot_r, 1, 3) | |
slot_l.setProperty('hand', slot_r) | |
slot_r.setProperty('hand', slot_l) | |
elif game_slot.name == EquipmentSlotUids.FEET.name: | |
- slot = self.getSlotWidget(game_slot, game_slot.name, h = 128) | |
+ slot = self.getSlotWidget(game_slot, game_slot.name, h=128) | |
self.setPicSlot(game_slot, slot) | |
layout.addItem(slot, 3, 2) | |
diff --git a/ui/GamePages/suwidgets/items/on_unit/InventoryWidget.py b/ui/GamePages/suwidgets/items/on_unit/InventoryWidget.py | |
index 274d653..c9decce 100644 | |
--- a/ui/GamePages/suwidgets/items/on_unit/InventoryWidget.py | |
+++ b/ui/GamePages/suwidgets/items/on_unit/InventoryWidget.py | |
@@ -16,7 +16,7 @@ class InventoryWidget(SlotGroupWidget): | |
layout = GameGridLayout() | |
j = 0 | |
for i, game_slot in enumerate(self.the_hero.inventory): | |
- label = self.getSlotWidget(game_slot, name = 'slot_' + str(i + 1)) | |
+ label = self.getSlotWidget(game_slot, name='slot_' + str(i + 1)) | |
self.setPicSlot(game_slot, label) | |
layout.addItem(label, row, j) | |
j += 1 | |
@@ -24,4 +24,3 @@ class InventoryWidget(SlotGroupWidget): | |
j = 0 | |
row += 1 | |
self.setLayout(layout) | |
- | |
diff --git a/ui/GamePages/suwidgets/items/on_unit/QuickItems.py b/ui/GamePages/suwidgets/items/on_unit/QuickItems.py | |
index 93d10ea..cef29cf 100644 | |
--- a/ui/GamePages/suwidgets/items/on_unit/QuickItems.py | |
+++ b/ui/GamePages/suwidgets/items/on_unit/QuickItems.py | |
@@ -16,7 +16,7 @@ class QuickItems(SlotGroupWidget): | |
layout = GameGridLayout() | |
j = 0 | |
for i, game_slot in enumerate(self.the_hero.quick_items): | |
- label = self.getSlotWidget(game_slot, name = 'slot_' + str(i + 1)) | |
+ label = self.getSlotWidget(game_slot, name='slot_' + str(i + 1)) | |
self.setPicSlot(game_slot, label) | |
layout.addItem(label, row, j) | |
j += 1 | |
diff --git a/ui/GamePages/suwidgets/items/on_unit/SlotGroupWidget.py b/ui/GamePages/suwidgets/items/on_unit/SlotGroupWidget.py | |
index 51d0cb5..05d632d 100644 | |
--- a/ui/GamePages/suwidgets/items/on_unit/SlotGroupWidget.py | |
+++ b/ui/GamePages/suwidgets/items/on_unit/SlotGroupWidget.py | |
@@ -21,7 +21,7 @@ class SlotGroupWidget: | |
def setUpWidgets(self): | |
pass | |
- def getSlotWidget(self, game_slot, name, w = 64, h = 64): | |
+ def getSlotWidget(self, game_slot, name, w=64, h=64): | |
slot = SlotWidget(name, page=self.page, slot_type=self.slot_type) | |
slot.hovered.connect(self.toolTipShow) | |
slot.hover_out.connect(self.page.toolTipHide) | |
@@ -49,7 +49,8 @@ class SlotGroupWidget: | |
if slot.property('slot').content is None: | |
self.page.gamePages.toolTip.setText('Slot empty') | |
else: | |
- self.page.gamePages.toolTip.setDict(slot.property('slot').tooltip_info) | |
+ self.page.gamePages.toolTip.setDict( | |
+ slot.property('slot').tooltip_info) | |
self.page.gamePages.toolTip.show() | |
pass | |
@@ -99,4 +100,3 @@ class SlotGroupWidget: | |
def pos(self): | |
return self._x, self._y | |
- | |
diff --git a/ui/GamePages/widgets/WidgetFactory.py b/ui/GamePages/widgets/WidgetFactory.py | |
index cbb7db9..8012d13 100644 | |
--- a/ui/GamePages/widgets/WidgetFactory.py | |
+++ b/ui/GamePages/widgets/WidgetFactory.py | |
@@ -1,5 +1,6 @@ | |
class WidgetFactory(object): | |
"""docstring for WidgetFactory.""" | |
+ | |
def __init__(self, gameconfig): | |
super(WidgetFactory, self).__init__() | |
self.page = None | |
diff --git a/ui/GameRootNode.py b/ui/GameRootNode.py | |
index 1c1f296..deb2080 100644 | |
--- a/ui/GameRootNode.py | |
+++ b/ui/GameRootNode.py | |
@@ -18,19 +18,20 @@ if TYPE_CHECKING: | |
class GameRootNode(object): | |
"""docstring for GameRootNode.""" | |
+ | |
def __init__(self): | |
super(GameRootNode, self).__init__() | |
- self.scene:QGraphicsScene = None | |
- self.view:QGraphicsView = None | |
- self.controller:GameController = None | |
- self.cfg:GameConfiguration = None | |
- self.level:BaseLevel = None | |
- self.levelFactory:LevelFactory = None | |
- self.gamePages:GamePages = None | |
- self.game:DreamGame = None | |
- self.lengine:LEngine = None | |
+ self.scene: QGraphicsScene = None | |
+ self.view: QGraphicsView = None | |
+ self.controller: GameController = None | |
+ self.cfg: GameConfiguration = None | |
+ self.level: BaseLevel = None | |
+ self.levelFactory: LevelFactory = None | |
+ self.gamePages: GamePages = None | |
+ self.game: DreamGame = None | |
+ self.lengine: LEngine = None | |
self.loop = None | |
- self.ui:TheUI = None | |
+ self.ui: TheUI = None | |
def setView(self, view): | |
self.view = view | |
diff --git a/ui/GameView.py b/ui/GameView.py | |
index 8f6ffb4..778a61e 100644 | |
--- a/ui/GameView.py | |
+++ b/ui/GameView.py | |
@@ -8,7 +8,7 @@ class GameView(QtWidgets.QGraphicsView): | |
keyPress = QtCore.Signal(QtCore.QEvent) | |
mouseMove = QtCore.Signal(QtCore.QEvent) | |
- def __init__(self, parent = None): | |
+ def __init__(self, parent=None): | |
QtWidgets.QGraphicsView.__init__(self, parent) | |
# Задаем минимальный размер виджета | |
# Отключаем полосы прокрутки | |
diff --git a/ui/GameWorld/GameWorld.py b/ui/GameWorld/GameWorld.py | |
index 1ce22cf..3739f89 100644 | |
--- a/ui/GameWorld/GameWorld.py | |
+++ b/ui/GameWorld/GameWorld.py | |
@@ -9,10 +9,11 @@ if TYPE_CHECKING: | |
from ui.gameconfig.GameConfiguration import GameConfiguration | |
from battlefield.Battlefield import Battlefield | |
+ | |
class GameWorld(QtWidgets.QGraphicsItemGroup): | |
def __init__(self, cfg): | |
super(GameWorld, self).__init__() | |
- self.cfg:GameConfiguration = cfg | |
+ self.cfg: GameConfiguration = cfg | |
self.size = QtCore.QRectF(0., 0., 1., 1.) | |
self.worldSize = (1, 1) | |
self.worldHalfSize = (1, 1) | |
@@ -34,7 +35,10 @@ class GameWorld(QtWidgets.QGraphicsItemGroup): | |
def setFloor(self, pixMap): | |
# cfg.getPicFile('floor.png', 102001001) | |
- self.floor = TileItem(gameRoot=self.cfg.gameRoot, w=pixMap.width(), h=pixMap.width()) | |
+ self.floor = TileItem( | |
+ gameRoot=self.cfg.gameRoot, | |
+ w=pixMap.width(), | |
+ h=pixMap.width()) | |
self.floor.add_pixmap(0, pixMap) | |
for i in range(self.worldSize[0]): | |
for j in range(self.worldSize[1]): | |
@@ -49,11 +53,10 @@ class GameWorld(QtWidgets.QGraphicsItemGroup): | |
self.floor.add_pixmap(wall.icon, pixmap) | |
self.floor.add_cell(wall.icon, cell) | |
- def setUpFloors(self, bf:Battlefield): | |
+ def setUpFloors(self, bf: Battlefield): | |
self.setFloor(self.cfg.getPicFile('floor.png', 102001001)) | |
if bf.walls is not {}: | |
self.setWall(bf.walls) | |
# print('walls', bf.walls) | |
# for cell, wall in bf.walls.items(): | |
# print(wall.icon) | |
- | |
diff --git a/ui/GameWorld/TileItem.py b/ui/GameWorld/TileItem.py | |
index 31c2a07..4f510ac 100644 | |
--- a/ui/GameWorld/TileItem.py | |
+++ b/ui/GameWorld/TileItem.py | |
@@ -10,9 +10,9 @@ if TYPE_CHECKING: | |
class TileItem(QGraphicsObject): | |
- def __init__(self, gameRoot, parent=None, w =1, h=1): | |
+ def __init__(self, gameRoot, parent=None, w=1, h=1): | |
super(TileItem, self).__init__(parent) | |
- self.gameRoot:GameRootNode = gameRoot | |
+ self.gameRoot: GameRootNode = gameRoot | |
self.pixmaps = {} | |
self._brushs = {} | |
self.cells = {} | |
@@ -23,12 +23,12 @@ class TileItem(QGraphicsObject): | |
self._cell_2 = None | |
pass | |
- def add_pixmap(self, id:int, pixmap): | |
+ def add_pixmap(self, id: int, pixmap): | |
self.pixmaps[id] = pixmap | |
self._brushs[id] = QBrush(pixmap) | |
pass | |
- def add_cell(self, id:int, cell:Cell): | |
+ def add_cell(self, id: int, cell: Cell): | |
self.cells[cell] = id | |
self._positions[(cell.x * self._width, cell.y * self._height)] = id | |
self.__calculate_bound(cell) | |
@@ -60,20 +60,29 @@ class TileItem(QGraphicsObject): | |
if cell.y > self._cell_2.y: | |
self._cell_2.y = cell.y | |
- def paint(self, painter:QPainter, option:QStyleOptionGraphicsItem, widget:QWidget=...): | |
+ def paint( | |
+ self, | |
+ painter: QPainter, | |
+ option: QStyleOptionGraphicsItem, | |
+ widget: QWidget = ...): | |
for pos, id in self._positions.items(): | |
- painter.drawPixmap(pos[0], pos[1], self._width, self._height, self.pixmaps[id]) | |
+ painter.drawPixmap( | |
+ pos[0], | |
+ pos[1], | |
+ self._width, | |
+ self._height, | |
+ self.pixmaps[id]) | |
def boundingRect(self): | |
return QtCore.QRectF(self.pos().x(), | |
- self.pos().y(), | |
- 0, 0) | |
+ self.pos().y(), | |
+ 0, 0) | |
def _boundingRect(self): | |
return QtCore.QRectF(self.pos().x(), | |
- self.pos().y(), | |
- self.pos().x() + self._cell_2.x * self._width, | |
- self.pos().y() + self._cell_2.y * self._height) | |
+ self.pos().y(), | |
+ self.pos().x() + self._cell_2.x * self._width, | |
+ self.pos().y() + self._cell_2.y * self._height) | |
def rect(self): | |
return self.boundingRect() | |
diff --git a/ui/TheUI.py b/ui/TheUI.py | |
index 8cde0d7..6d6de9b 100644 | |
--- a/ui/TheUI.py | |
+++ b/ui/TheUI.py | |
@@ -24,7 +24,7 @@ class TheUI(QtWidgets.QWidget): | |
view = None | |
singleton = None | |
- def __init__(self, lengine:LEngine, game = None): | |
+ def __init__(self, lengine: LEngine, game=None): | |
super().__init__() | |
self.setAcceptDrops(True) | |
print('cfg ===> newGame init TheUI', datetime.now()) | |
@@ -53,7 +53,8 @@ class TheUI(QtWidgets.QWidget): | |
self.layout.setMargin(2) | |
size = self.gameconfig.dev_cfg_size | |
if size is not None: | |
- self.scene = QtWidgets.QGraphicsScene(0, 0, self.gameconfig.dev_cfg_size[0], self.gameconfig.dev_cfg_size[1]) | |
+ self.scene = QtWidgets.QGraphicsScene( | |
+ 0, 0, self.gameconfig.dev_cfg_size[0], self.gameconfig.dev_cfg_size[1]) | |
else: | |
self.scene = QtWidgets.QGraphicsScene(0, 0, 500, 500) | |
self.gameRoot.setScene(self.scene) | |
@@ -90,7 +91,7 @@ class TheUI(QtWidgets.QWidget): | |
self.gameconfig.ava_size[0], | |
self.gameconfig.ava_size[1]) | |
- def initLevel(self, level_name = None): | |
+ def initLevel(self, level_name=None): | |
print('Iinit level') | |
self.level = self.levelFactory.getLevel() | |
self.levelFactory.addLevelToScene(self.scene) | |
@@ -102,7 +103,7 @@ class TheUI(QtWidgets.QWidget): | |
self.gameRoot.level = None | |
def close_app(self): | |
- if not self.gameRoot.loop is None: | |
+ if self.gameRoot.loop is not None: | |
self.stopGame() | |
def setDefaultGame(self): | |
@@ -138,9 +139,8 @@ class TheUI(QtWidgets.QWidget): | |
self.gamePages.page = self.gamePages.gameMenu | |
self.view.controller = self.controller | |
- | |
def stopGame(self): | |
- if not self.gameRoot.loop is None: | |
+ if self.gameRoot.loop is not None: | |
# game.loop stop condition | |
self.gameRoot.game.loop_state = False | |
self.destroyLevel() | |
@@ -167,7 +167,6 @@ class TheUI(QtWidgets.QWidget): | |
sys.exit(app.exec_()) | |
- | |
if __name__ == '__main__': | |
from DreamGame import DreamGame | |
from cntent.base_types.demo_hero import demohero_basetype | |
diff --git a/ui/TransformSupport.py b/ui/TransformSupport.py | |
index a7d9479..ca63adf 100644 | |
--- a/ui/TransformSupport.py | |
+++ b/ui/TransformSupport.py | |
@@ -26,7 +26,7 @@ class TransformSupport: | |
# Offset for map | |
self.off = 32 | |
self.l_mouse = False | |
- self.isMovable = False | |
+ self.isMovable = False | |
def setItemPos(self, item, x, y): | |
# item.setPos(x - (item.rect().x() + self.tr.m31()), | |
@@ -40,9 +40,9 @@ class TransformSupport: | |
# item.rect().x() + self.tr.m31() + item.pos().x() + item.rect().width(),\ | |
# item.rect().y() + self.tr.m32() + item.pos().y() + item.rect().height() | |
return item.boundingRect().x() + self.tr.m31() + item.pos().x(),\ | |
- item.boundingRect().y() + self.tr.m32() + item.pos().y(), \ | |
- item.boundingRect().x() + self.tr.m31() + item.pos().x() + item.boundingRect().width(),\ | |
- item.boundingRect().y() + self.tr.m32() + item.pos().y() + item.boundingRect().height() | |
+ item.boundingRect().y() + self.tr.m32() + item.pos().y(), \ | |
+ item.boundingRect().x() + self.tr.m31() + item.pos().x() + item.boundingRect().width(),\ | |
+ item.boundingRect().y() + self.tr.m32() + item.pos().y() + item.boundingRect().height() | |
def updadte_tr(self): | |
"""Update transform for new dev_size | |
@@ -54,12 +54,13 @@ class TransformSupport: | |
self.level = level | |
self.tr.translate(-self.tr.m31(), -self.tr.m32()) | |
self.tr.translate(self.cfg.dev_size[0] / 2, self.cfg.dev_size[1] / 2) | |
- self.tr.translate(-level.world.floor.rect().width()/2, -level.world.floor.rect().height()/2) | |
+ self.tr.translate(-level.world.floor.rect().width() / | |
+ 2, -level.world.floor.rect().height() / 2) | |
level.world.setTransform(self.tr) | |
self.floor_rect.setRect(level.world.pos().x() + self.tr.m31(), | |
level.world.pos().y() + self.tr.m32(), | |
- level.world.floor.rect().width() -2, | |
- level.world.floor.rect().height() -2) | |
+ level.world.floor.rect().width() - 2, | |
+ level.world.floor.rect().height() - 2) | |
level.units.setTransform(self.tr) | |
level.gameVision.setTransform(self.tr) | |
level.middleLayer.setTransform(self.tr) | |
@@ -67,10 +68,12 @@ class TransformSupport: | |
def setMovableMaps(self): | |
if self.isMovable: | |
- self.gameRoot.level.world.setFlag(QtWidgets.QGraphicsItem.ItemIsMovable, False) | |
+ self.gameRoot.level.world.setFlag( | |
+ QtWidgets.QGraphicsItem.ItemIsMovable, False) | |
self.isMovable = False | |
else: | |
- self.gameRoot.level.world.setFlag(QtWidgets.QGraphicsItem.ItemIsMovable, True) | |
+ self.gameRoot.level.world.setFlag( | |
+ QtWidgets.QGraphicsItem.ItemIsMovable, True) | |
self.isMovable = True | |
def updateItemsPos(self): | |
@@ -110,7 +113,9 @@ class TransformSupport: | |
self.setItemPos(world, wx1, wy2 - world.boundingRect().height()) | |
if mx2 > wx2 and my2 > wy2: | |
- self.setItemPos(world, wx2 - world.boundingRect().width(), wy2 - world.boundingRect().height()) | |
+ self.setItemPos(world, wx2 - | |
+ world.boundingRect().width(), wy2 - | |
+ world.boundingRect().height()) | |
if mx2 > wx2 and my1 < wy1: | |
self.setItemPos(world, wx2 - world.boundingRect().width(), wy1) | |
@@ -172,19 +177,24 @@ class TransformSupport: | |
# self.updateScreenField() | |
def rectHitGroupItem(self, item): | |
- x = item.pos().x() + item.parentItem().pos().x() + item.parentItem().transform().m31() | |
- y = item.pos().y() + item.parentItem().pos().y() + item.parentItem().transform().m32() | |
+ x = item.pos().x() + item.parentItem().pos().x() + \ | |
+ item.parentItem().transform().m31() | |
+ y = item.pos().y() + item.parentItem().pos().y() + \ | |
+ item.parentItem().transform().m32() | |
pos = self.gameRoot.view.mapFromScene(x, y) | |
- size = self.gameRoot.view.transform().map(item.boundingRect().width(), item.boundingRect().height()) | |
+ size = self.gameRoot.view.transform().map( | |
+ item.boundingRect().width(), item.boundingRect().height()) | |
return QtCore.QRectF(pos.x(), pos.y(), size[0], size[1]) | |
def rectHitItem(self, item): | |
pos = self.gameRoot.view.mapFromScene(item.pos()) | |
- size = self.gameRoot.view.transform().map(item.boundingRect().width(), item.boundingRect().height()) | |
+ size = self.gameRoot.view.transform().map( | |
+ item.boundingRect().width(), item.boundingRect().height()) | |
return QtCore.QRectF(pos.x(), pos.y(), size[0], size[1]) | |
def groupToScene(self, item): | |
- x = item.pos().x() + item.parentItem().pos().x() + item.parentItem().transform().m31() | |
- y = item.pos().y() + item.parentItem().pos().y() + item.parentItem().transform().m32() | |
+ x = item.pos().x() + item.parentItem().pos().x() + \ | |
+ item.parentItem().transform().m31() | |
+ y = item.pos().y() + item.parentItem().pos().y() + \ | |
+ item.parentItem().transform().m32() | |
return x, y | |
- | |
diff --git a/ui/debug/DebugLayer.py b/ui/debug/DebugLayer.py | |
index 9ed7826..8fe5f40 100644 | |
--- a/ui/debug/DebugLayer.py | |
+++ b/ui/debug/DebugLayer.py | |
@@ -16,11 +16,11 @@ class DebugLayer(QtWidgets.QGraphicsItemGroup): | |
def getItem(self, brush=None, pen=None, opacity=None): | |
item = QtWidgets.QGraphicsRectItem() | |
- if not pen is None: | |
+ if pen is not None: | |
item.setPen(pen) | |
- if not brush is None: | |
+ if brush is not None: | |
item.setBrush(brush) | |
- if not opacity is None: | |
+ if opacity is not None: | |
item.setOpacity(opacity) | |
self.addToGroup(item) | |
return item | |
@@ -30,4 +30,3 @@ class DebugLayer(QtWidgets.QGraphicsItemGroup): | |
# self.select_rect = self.getItem(self.b_green, self.pen, 0.5) | |
# self.select_rect.setRect(0, 0, 128, 128) | |
pass | |
- | |
diff --git a/ui/events/LevelStatusEvent.py b/ui/events/LevelStatusEvent.py | |
index 57c8ebb..0afc425 100644 | |
--- a/ui/events/LevelStatusEvent.py | |
+++ b/ui/events/LevelStatusEvent.py | |
@@ -1,6 +1,7 @@ | |
from mechanics.events.src.Event import Event | |
from mechanics.events import EventsChannels | |
+ | |
class LevelStatusEvent(Event): | |
channel = EventsChannels.LevelStatus | |
diff --git a/ui/events/UiErrorMessageEvent.py b/ui/events/UiErrorMessageEvent.py | |
index 749e87d..357e43e 100644 | |
--- a/ui/events/UiErrorMessageEvent.py | |
+++ b/ui/events/UiErrorMessageEvent.py | |
@@ -1,6 +1,7 @@ | |
from mechanics.events.src.Event import Event | |
from mechanics.events import EventsChannels | |
+ | |
class UiErrorMessageEvent(Event): | |
channel = EventsChannels.UiErrorMessage | |
diff --git a/ui/experimental/DungeonChoice.py b/ui/experimental/DungeonChoice.py | |
index 5cdeda5..e6cddb3 100644 | |
--- a/ui/experimental/DungeonChoice.py | |
+++ b/ui/experimental/DungeonChoice.py | |
@@ -15,7 +15,6 @@ from cntent.dungeons.tel_razi_temple import tel_razi_temple | |
from ui.experimental.DungeonWidget import DungeonWidget | |
- | |
class DungeonChoice(QGroupBox): | |
def __init__(self, dung_list, parent=None, gc=None): | |
QGroupBox.__init__(self, parent) | |
@@ -25,7 +24,7 @@ class DungeonChoice(QGroupBox): | |
layout = QtWidgets.QGridLayout() | |
for i, d in enumerate(dung_list): | |
dung_widg = DungeonWidget(d, gc=gc) | |
- layout.addWidget(dung_widg, i // 2, i%2) | |
+ layout.addWidget(dung_widg, i // 2, i % 2) | |
self.dungeon_widgets.append(dung_widg) | |
dung_widg.selected.connect(self.select_dungeon) | |
@@ -41,7 +40,6 @@ class DungeonChoice(QGroupBox): | |
layout.addWidget(start_button) | |
self.setLayout(layout) | |
- | |
@property | |
def selected_dungeon(self): | |
for dw in self.dungeon_widgets: | |
@@ -66,14 +64,18 @@ class DungeonChoice(QGroupBox): | |
self.start_button.setEnabled(True) | |
- | |
- | |
if __name__ == "__main__": | |
from ui.gameconfig.GameConfiguration import GameConfiguration | |
qt_app = QApplication(sys.argv) | |
gc = GameConfiguration() | |
- app = DungeonChoice([small_orc_cave, pirate_lair, small_graveyard, demo_dungeon, walls_dungeon, tel_razi_temple], gc=gc) | |
+ app = DungeonChoice([small_orc_cave, | |
+ pirate_lair, | |
+ small_graveyard, | |
+ demo_dungeon, | |
+ walls_dungeon, | |
+ tel_razi_temple], | |
+ gc=gc) | |
app.show() | |
- qt_app.exec_() | |
\ No newline at end of file | |
+ qt_app.exec_() | |
diff --git a/ui/experimental/DungeonWidget.py b/ui/experimental/DungeonWidget.py | |
index 00c967f..e3a86cc 100644 | |
--- a/ui/experimental/DungeonWidget.py | |
+++ b/ui/experimental/DungeonWidget.py | |
@@ -10,11 +10,9 @@ class DungeonWidget(QFrame): | |
selected = Signal(object) | |
deselected = Signal() | |
- def __init__(self, dungeon, parent = None, gc=None): | |
+ def __init__(self, dungeon, parent=None, gc=None): | |
QFrame.__init__(self, parent) | |
- | |
- | |
self.setObjectName("DungeonFrame") | |
self.setStyleSheet("#DungeonFrame {border: 2px solid black}") | |
self.dungeon = dungeon | |
@@ -27,12 +25,13 @@ class DungeonWidget(QFrame): | |
self.form_layout.addRow(QLabel(dungeon.name)) | |
- | |
locs = dungeon.unit_locations(DreamGame()) | |
- self.n_units_label = QLabel(f'{len([u for u in locs.keys() if not u.is_obstacle])}', self) | |
+ self.n_units_label = QLabel( | |
+ f'{len([u for u in locs.keys() if not u.is_obstacle])}', self) | |
self.form_layout.addRow('Units in the dungeon:', self.n_units_label) | |
- self.max_xp_label = QLabel(f'{max([u.xp for u in locs.keys() if not u.is_obstacle])}', self) | |
+ self.max_xp_label = QLabel( | |
+ f'{max([u.xp for u in locs.keys() if not u.is_obstacle])}', self) | |
self.form_layout.addRow('Strongest enemy XP: ', self.max_xp_label) | |
self.rbutton = QRadioButton(self) | |
@@ -41,10 +40,9 @@ class DungeonWidget(QFrame): | |
self.setLayout(self.form_layout) | |
- | |
@Slot() | |
def toggled(self, selected): | |
if selected: | |
self.selected.emit(self) | |
else: | |
- self.deselected.emit() | |
\ No newline at end of file | |
+ self.deselected.emit() | |
diff --git a/ui/experimental/perk_tree/QPerk.py b/ui/experimental/perk_tree/QPerk.py | |
index db2fc9c..db72dd3 100644 | |
--- a/ui/experimental/perk_tree/QPerk.py | |
+++ b/ui/experimental/perk_tree/QPerk.py | |
@@ -20,7 +20,7 @@ class QPerk(QWidget): | |
layout = QVBoxLayout() | |
- pixmap = QPixmap( os.path.join(config.res_dir,perk.icon) ) | |
+ pixmap = QPixmap(os.path.join(config.res_dir, perk.icon)) | |
icon = QLabel() | |
icon.setPixmap(pixmap) | |
icon.setFixedSize(pixmap.size()) | |
@@ -33,14 +33,14 @@ class QPerk(QWidget): | |
# up_button.setIcon(up_icon) | |
# up_button.setIconSize(QSize(32,50)) | |
up_button.clicked.connect(self.on_click) | |
- up_button.setText( "Not initialized" ) | |
+ up_button.setText("Not initialized") | |
layout.addWidget(up_button) | |
self.up_button = up_button | |
layout.setSizeConstraint(QVBoxLayout.SetFixedSize) | |
self.setLayout(layout) | |
- self.border_color = {0:"white", 1:"yellow", 2:"orange", 3:"red"} | |
+ self.border_color = {0: "white", 1: "yellow", 2: "orange", 3: "red"} | |
self.match_level() | |
@property | |
@@ -61,14 +61,14 @@ class QPerk(QWidget): | |
if cost >= 1e6: | |
value = int(cost // 1000_000) | |
- rest = int((cost - value*1000_000) // 100_000) | |
+ rest = int((cost - value * 1000_000) // 100_000) | |
if rest != 0: | |
result = f"{value}.{rest}m" | |
else: | |
result = f"{value}m" | |
elif cost > 1000: | |
value = int(cost // 1000) | |
- rest = int((cost - value*1000) // 100) | |
+ rest = int((cost - value * 1000) // 100) | |
if rest != 0: | |
result = f"{value}.{rest}k" | |
else: | |
@@ -92,7 +92,6 @@ class QPerk(QWidget): | |
self.group.levelup() | |
- | |
if __name__ == "__main__": | |
from character.perks.everymans_perks.group_attrib import str_perk | |
from PySide2.QtWidgets import QApplication | |
@@ -102,5 +101,4 @@ if __name__ == "__main__": | |
app = QPerk(str_perk) | |
app.show() | |
- | |
- qt_app.exec_() | |
\ No newline at end of file | |
+ qt_app.exec_() | |
diff --git a/ui/experimental/perk_tree/QPerkGroup.py b/ui/experimental/perk_tree/QPerkGroup.py | |
index d62164e..fea6fef 100644 | |
--- a/ui/experimental/perk_tree/QPerkGroup.py | |
+++ b/ui/experimental/perk_tree/QPerkGroup.py | |
@@ -1,5 +1,6 @@ | |
from __future__ import annotations | |
+import math | |
from PySide2.QtWidgets import QWidget, QHBoxLayout, QVBoxLayout, QLayout | |
from ui.experimental.perk_tree.QPerk import QPerk | |
@@ -8,10 +9,9 @@ if TYPE_CHECKING: | |
from character.perks import PerkGroup | |
from ui.experimental.perk_tree.QPerkTree import QPerkTree | |
-import math | |
class QPerkGroup(QWidget): | |
- def __init__(self, perk_group: PerkGroup, parent:QPerkTree): | |
+ def __init__(self, perk_group: PerkGroup, parent: QPerkTree): | |
self.perk_group = perk_group | |
self.tree = parent | |
super().__init__(parent) | |
@@ -20,21 +20,21 @@ class QPerkGroup(QWidget): | |
layout.setSizeConstraint(QLayout.SetFixedSize) | |
- n_perks = len( perk_group.perk_list ) | |
- n_per_row = math.ceil( n_perks ** (1/2) ) | |
+ n_perks = len(perk_group.perk_list) | |
+ n_per_row = math.ceil(n_perks ** (1 / 2)) | |
n_rows = math.ceil(n_perks / n_per_row) | |
self.identities = {} | |
for i in range(n_rows): | |
- start = i*n_per_row | |
+ start = i * n_per_row | |
finish = start + n_per_row | |
- row, new_identities = self.build_row( perk_group.perk_list[start:finish] ) | |
+ row, new_identities = self.build_row( | |
+ perk_group.perk_list[start:finish]) | |
self.identities.update(new_identities) | |
layout.addWidget(row) | |
self.setLayout(layout) | |
- | |
def xp_changed(self, new_xp): | |
can_spend = new_xp | |
if not self.perk_group.requirements_matched(): | |
@@ -46,7 +46,6 @@ class QPerkGroup(QWidget): | |
def levelup(self): | |
self.tree.levelup() | |
- | |
def build_row(self, perks): | |
row = QWidget() | |
layout = QHBoxLayout() | |
@@ -66,9 +65,6 @@ class QPerkGroup(QWidget): | |
return f"UI for {self.perk_group}" | |
- | |
- | |
- | |
if __name__ == "__main__": | |
from PySide2.QtWidgets import QApplication | |
from character.perks.everymans_perks.group_attrib import pg_attributes | |
@@ -78,4 +74,4 @@ if __name__ == "__main__": | |
app = QPerkGroup(pg_attributes) | |
app.show() | |
- qt_app.exec_() | |
\ No newline at end of file | |
+ qt_app.exec_() | |
diff --git a/ui/experimental/perk_tree/QPerkTree.py b/ui/experimental/perk_tree/QPerkTree.py | |
index fe99ab6..ae406e7 100644 | |
--- a/ui/experimental/perk_tree/QPerkTree.py | |
+++ b/ui/experimental/perk_tree/QPerkTree.py | |
@@ -15,7 +15,6 @@ if TYPE_CHECKING: | |
class QPerkTree(QWidget): | |
- | |
def __init__(self, perk_tree: PerkTree, character: Character, parent=None): | |
assert perk_tree in character.perk_trees | |
@@ -29,15 +28,14 @@ class QPerkTree(QWidget): | |
self.name = QLabel(perk_tree.name) | |
layout.addWidget(self.name) | |
- self.total_spent = QLabel( str(perk_tree.spent_xp) ) | |
+ self.total_spent = QLabel(str(perk_tree.spent_xp)) | |
layout.addWidget(self.total_spent) | |
- | |
self.visuals = {} | |
for perk_group in perk_tree.perk_groups: | |
- qpg = QPerkGroup( perk_group, self ) | |
+ qpg = QPerkGroup(perk_group, self) | |
self.visuals[perk_group] = qpg | |
- layout.addWidget( qpg ) | |
+ layout.addWidget(qpg) | |
layout.addStretch(2) | |
self.setLayout(layout) | |
@@ -57,7 +55,6 @@ if __name__ == "__main__": | |
from character.Character import Character | |
from cntent.base_types.demo_hero import demohero_basetype | |
- | |
c = Character(demohero_basetype) | |
c.unit.xp = 1e6 | |
@@ -68,4 +65,4 @@ if __name__ == "__main__": | |
app = QPerkTree(tree, c) | |
app.show() | |
- qt_app.exec_() | |
\ No newline at end of file | |
+ qt_app.exec_() | |
diff --git a/ui/gameconfig/DeviceConfig.py b/ui/gameconfig/DeviceConfig.py | |
index 5c7d609..f499ac1 100644 | |
--- a/ui/gameconfig/DeviceConfig.py | |
+++ b/ui/gameconfig/DeviceConfig.py | |
@@ -34,7 +34,8 @@ class DeviceConfig: | |
:atribute dev_size - размер устройства деленый на 2 | |
""" | |
self.desktop = QDesktopWidget() | |
- self.dev_size = self.desktop.screenGeometry().width(), self.desktop.screenGeometry().height() | |
+ self.dev_size = self.desktop.screenGeometry( | |
+ ).width(), self.desktop.screenGeometry().height() | |
self.device_resolution = self.dev_size[0], self.dev_size[1] | |
if self.device_resolution not in self.RESOLUTIONS: | |
self.device_resolution = self.RESOLUTIONS[0] | |
@@ -54,8 +55,8 @@ class DeviceConfig: | |
for step in range(16, 257, 4): | |
temp = [] | |
for w, h in self.RESOLUTIONS: | |
- temp.append(int(w/step)) | |
- temp.append(int(h/step)) | |
+ temp.append(int(w / step)) | |
+ temp.append(int(h / step)) | |
res.append(temp) | |
with open('file_input', "w", newline='') as csv_file: | |
diff --git a/ui/gameconfig/GameConfiguration.py b/ui/gameconfig/GameConfiguration.py | |
index 3bfa8fb..034a326 100644 | |
--- a/ui/gameconfig/GameConfiguration.py | |
+++ b/ui/gameconfig/GameConfiguration.py | |
@@ -11,13 +11,14 @@ class GameConfiguration: | |
"""docstring for GameConfiguration. | |
Установка основных конфигураций игры | |
""" | |
- def __init__(self, lazy = True): | |
+ | |
+ def __init__(self, lazy=True): | |
print('cfg ===> start init', datetime.now()) | |
self.deviceConfig = None | |
self.userConfig = None | |
self.resourceConfig = None | |
- self.styleConfig:StyleConfig = None | |
+ self.styleConfig: StyleConfig = None | |
# Setup configuration for curent device | |
self.deviceConfig = DeviceConfig(self) | |
@@ -33,7 +34,7 @@ class GameConfiguration: | |
self.gameRoot = None | |
def setGameRoot(self, gameRoot): | |
- self.gameRoot = gameRoot | |
+ self.gameRoot = gameRoot | |
self.gameRoot.cfg = self | |
def setWorld(self, world): | |
@@ -46,7 +47,7 @@ class GameConfiguration: | |
def setUpResourceConfig(self, lazy): | |
"""from Resource Config""" | |
self.resourceConfig = ResourceConfig(lazy) | |
- self.resourceConfig.rez_step =self.rez_step | |
+ self.resourceConfig.rez_step = self.rez_step | |
self.main_font_name = self.resourceConfig.main_font_name | |
self.pix_maps = self.resourceConfig.pix_maps | |
self.unit_size = self.resourceConfig.unit_size | |
@@ -57,7 +58,7 @@ class GameConfiguration: | |
"""from Resource Config""" | |
return self.resourceConfig.getSize(id) | |
- def getPicFile(self, filename, id = None, size = None): | |
+ def getPicFile(self, filename, id=None, size=None): | |
"""from Resource Config""" | |
return self.resourceConfig.getPicFile(filename, id, size) | |
@@ -74,13 +75,13 @@ class GameConfiguration: | |
self.userConfig.read_config = copy(DEFAULT_CONFIG) | |
finally: | |
self.dev_size = self.userConfig.read_config['window']['resolution']['width'], \ | |
- self.userConfig.read_config['window']['resolution']['height'] | |
+ self.userConfig.read_config['window']['resolution']['height'] | |
@property | |
def dev_cfg_size(self): | |
"""from User Config""" | |
return self.userConfig.read_config['window']['resolution']['width'], \ | |
- self.userConfig.read_config['window']['resolution']['height'] | |
+ self.userConfig.read_config['window']['resolution']['height'] | |
def setUpStyleConfig(self): | |
self.styleConfig = StyleConfig(self) | |
@@ -102,19 +103,5 @@ class GameConfiguration: | |
self.scale_x = self.dev_size[0] / WIDTH | |
self.scale_y = self.dev_size[1] / HEIGHT | |
- def getFont(self, name = None): | |
+ def getFont(self, name=None): | |
return self.styleConfig.getFont(name) | |
- | |
- | |
- | |
- | |
- | |
- | |
- | |
- | |
- | |
- | |
- | |
- | |
- | |
- | |
diff --git a/ui/gameconfig/GameSizeConfig.py b/ui/gameconfig/GameSizeConfig.py | |
index 7b7831e..7dcbe3f 100644 | |
--- a/ui/gameconfig/GameSizeConfig.py | |
+++ b/ui/gameconfig/GameSizeConfig.py | |
@@ -21,5 +21,5 @@ def setUpSize(): | |
gameItemsSizes[103001001] = ((128, 128), (128, 128), (128, 128)) | |
return gameItemsSizes | |
-gameItemsSizes = setUpSize() | |
+gameItemsSizes = setUpSize() | |
diff --git a/ui/gameconfig/ResourceConfig.py b/ui/gameconfig/ResourceConfig.py | |
index 5cf859b..8ad5958 100644 | |
--- a/ui/gameconfig/ResourceConfig.py | |
+++ b/ui/gameconfig/ResourceConfig.py | |
@@ -12,8 +12,10 @@ from xml.etree import ElementTree as ET | |
class ResourceConfig: | |
- def __init__(self, cfg, lazy = True): | |
- self.ignore_path = ('resources/assets/sprites/axe',) # Игнорируемые папки | |
+ def __init__(self, cfg, lazy=True): | |
+ self.ignore_path = ( | |
+ 'resources/assets/sprites/axe', | |
+ ) # Игнорируемые папки | |
self.rez_step = 0 | |
self.pic_formats = ('png', 'jpg') | |
self.pic_file_paths = {} | |
@@ -47,9 +49,12 @@ class ResourceConfig: | |
:atribute unit_x_size - размер юнита c умноженный на x, где x = [a = 1/2, b = 1/3, c = 1/4] | |
""" | |
self.unit_size = 128, 128 | |
- self.unit_a_size = int(self.unit_size[0] * (1/2)), int(self.unit_size[0] * (1/2)) | |
- self.unit_b_size = int(self.unit_size[0] * (1/3)), int(self.unit_size[0] * (1/3)) | |
- self.unit_c_size = int(self.unit_size[0] * (1/4)), int(self.unit_size[0] * (1/4)) | |
+ self.unit_a_size = int( | |
+ self.unit_size[0] * (1 / 2)), int(self.unit_size[0] * (1 / 2)) | |
+ self.unit_b_size = int( | |
+ self.unit_size[0] * (1 / 3)), int(self.unit_size[0] * (1 / 3)) | |
+ self.unit_c_size = int( | |
+ self.unit_size[0] * (1 / 4)), int(self.unit_size[0] * (1 / 4)) | |
def loadFilesPath(self): | |
""" | |
@@ -58,7 +63,7 @@ class ResourceConfig: | |
Словарь вида {filename: filepath} | |
""" | |
# генератор путей, файлов и папок | |
- self.walks = os.walk(top = os.path.join(pydolons_rootdir, 'resources') ) | |
+ self.walks = os.walk(top=os.path.join(pydolons_rootdir, 'resources')) | |
# Словарь путей к изображениям, ключ название файла | |
# self.pic_file_paths = {} | |
# получаем данные генератора | |
@@ -68,11 +73,14 @@ class ResourceConfig: | |
# Получаем спискок фйалов | |
for name in item[2]: | |
if name[-3:].lower() in self.pic_formats: | |
- self.pic_file_paths[name.lower()] = os.path.join(item[0], name) | |
+ self.pic_file_paths[name.lower()] = os.path.join( | |
+ item[0], name) | |
elif name[-3:].lower() in self.sound_formats: | |
- self.sound_file_paths[name.lower()] = os.path.join(item[0], name) | |
+ self.sound_file_paths[name.lower()] = os.path.join( | |
+ item[0], name) | |
elif name[-3:].lower() in self.fonts_formats: | |
- self.fonts_file_paths[name.lower()] = os.path.join(item[0], name) | |
+ self.fonts_file_paths[name.lower()] = os.path.join( | |
+ item[0], name) | |
elif name[-3:] == 'xml': | |
self.xml_file_paths[name] = os.path.join(item[0], name) | |
@@ -94,7 +102,7 @@ class ResourceConfig: | |
except Exception as e: | |
print(e) | |
- def getPicFile(self, filename, id = None, size = None): | |
+ def getPicFile(self, filename, id=None, size=None): | |
""" | |
если файл не найден генерируется ошибка | |
argument: filename -- название файла в файловой системе | |
@@ -106,7 +114,7 @@ class ResourceConfig: | |
if pixmap is None: | |
# print(filename + ' image was not found. using default.') | |
pixmap = self.pix_maps.get("default_128.png") | |
- if not id is None: | |
+ if id is not None: | |
size = self.getSize(id) | |
pixmap = pixmap.scaled(size[0], size[1]) | |
return pixmap | |
@@ -165,4 +173,3 @@ class ResourceConfig: | |
return page | |
else: | |
return self.xml_maps.get('404_page.xml') | |
- | |
diff --git a/ui/gameconfig/StyleConfig.py b/ui/gameconfig/StyleConfig.py | |
index a28c93b..d3eef82 100644 | |
--- a/ui/gameconfig/StyleConfig.py | |
+++ b/ui/gameconfig/StyleConfig.py | |
@@ -4,13 +4,14 @@ from typing import TYPE_CHECKING | |
if TYPE_CHECKING: | |
from ui.gameconfig.GameConfiguration import GameConfiguration | |
+ | |
class StyleConfig: | |
def __init__(self, cfg: GameConfiguration): | |
self.colors = {} | |
self.brushs = {} | |
self.setUpColors() | |
self.cfg = cfg | |
- self.system_font :QFont = QGuiApplication.font() | |
+ self.system_font: QFont = QGuiApplication.font() | |
self.system_hint = self.system_font.hintingPreference() | |
self.system_pixelSize = self.system_font.pixelSize() | |
self.default_pixel_size = 15 | |
@@ -34,7 +35,7 @@ class StyleConfig: | |
print('weight', info.weight()) | |
print('styleHint', info.styleHint()) | |
- self.main_font:QFont = self.cfg.resourceConfig.fonts_maps['imfeenrm28p.ttf'] | |
+ self.main_font: QFont = self.cfg.resourceConfig.fonts_maps['imfeenrm28p.ttf'] | |
self.base_point_size = int(self.default_point_size * self.cfg.scale_y) | |
self.base_pixel_size = int(self.default_pixel_size * self.cfg.scale_y) | |
self.base_weight = int(self.default_weight * self.cfg.scale_y) | |
@@ -52,7 +53,7 @@ class StyleConfig: | |
print('font system_hint', self.system_hint) | |
print('font system_pixelSize', self.system_pixelSize) | |
- def getFont(self, name = None): | |
+ def getFont(self, name=None): | |
# print(self.cfg.resourceConfig.main_font_name) | |
font = None | |
if name is None: | |
diff --git a/ui/gameconfig/UserConfig.py b/ui/gameconfig/UserConfig.py | |
index 409d5dc..09aa60e 100644 | |
--- a/ui/gameconfig/UserConfig.py | |
+++ b/ui/gameconfig/UserConfig.py | |
@@ -4,18 +4,18 @@ from json import dumps, loads | |
from copy import copy | |
DEFAULT_CONFIG = { | |
- 'window':{ | |
- 'resolution':{'width':1366, | |
- 'height':768}, | |
- 'fullscreen':True, | |
+ 'window': { | |
+ 'resolution': {'width': 1366, | |
+ 'height': 768}, | |
+ 'fullscreen': True, | |
} | |
} | |
DEFAULT_SIZE_CONFIG = { | |
- 'window':{ | |
- 'resolution':{'width':1024, | |
- 'height':768}, | |
- 'fullscreen':False | |
+ 'window': { | |
+ 'resolution': {'width': 1024, | |
+ 'height': 768}, | |
+ 'fullscreen': False | |
} | |
} | |
@@ -81,4 +81,3 @@ class UserConfig(object): | |
# print(cfg.read_config) | |
# cfg.saveSetting(DEFAULT_SIZE_CONFIG) | |
# print(cfg.read_config) | |
- | |
diff --git a/ui/gui_util/gamemath.py b/ui/gui_util/gamemath.py | |
index ffd5438..a1bd408 100644 | |
--- a/ui/gui_util/gamemath.py | |
+++ b/ui/gui_util/gamemath.py | |
@@ -1,7 +1,9 @@ | |
import math | |
+ | |
class GameMath(object): | |
"""docstring for GameMath.""" | |
+ | |
def __init__(self): | |
super(GameMath, self).__init__() | |
@@ -10,7 +12,8 @@ class GameMath(object): | |
"""Метод возвращет направление по текущим координатам относительно | |
центра | |
""" | |
- dVectors = ((0,1),(1,1),(1,0),(1,-1),(0,-1),(-1,-1),(-1,0),(-1,1)) | |
+ dVectors = ((0, 1), (1, 1), (1, 0), (1, -1), | |
+ (0, -1), (-1, -1), (-1, 0), (-1, 1)) | |
deg = int(math.degrees(math.atan2(x, y))) | |
if x == 0 and y == 0: | |
@@ -32,13 +35,13 @@ class GameMath(object): | |
elif deg < -156 or deg > 156: | |
return 0, -1 | |
# print('N') | |
- elif deg < -111 and deg > -157: | |
+ elif deg < -111 and deg > -157: | |
return -1, -1 | |
# print('NO') | |
- elif deg < -67 and deg > -112: | |
+ elif deg < -67 and deg > -112: | |
return -1, 0 | |
# print('O') | |
- elif deg < -22 and deg > -68: | |
+ elif deg < -22 and deg > -68: | |
return -1, 1 | |
# print('SO') | |
# print(int(math.degrees(at))) | |
diff --git a/ui/levels/BaseLevel.py b/ui/levels/BaseLevel.py | |
index dbc014f..a784368 100644 | |
--- a/ui/levels/BaseLevel.py | |
+++ b/ui/levels/BaseLevel.py | |
@@ -11,10 +11,10 @@ if TYPE_CHECKING: | |
class BaseLevel(object): | |
def __init__(self): | |
super(BaseLevel, self).__init__() | |
- self.gameRoot:GameRootNode = None | |
- self.middleLayer:UnitMiddleLayer = None | |
- self.world:GameWorld = None | |
- self.units:Units = None | |
+ self.gameRoot: GameRootNode = None | |
+ self.middleLayer: UnitMiddleLayer = None | |
+ self.world: GameWorld = None | |
+ self.units: Units = None | |
def setGameRoot(self, gameRoot): | |
self.gameRoot = gameRoot | |
@@ -22,7 +22,7 @@ class BaseLevel(object): | |
def setMiddleLayer(self, middleLayer): | |
self.middleLayer = middleLayer | |
- self.middleLayer.level = self | |
+ self.middleLayer.level = self | |
def setGameWorld(self, world): | |
self.world = world | |
diff --git a/ui/levels/DemoGameTread.py b/ui/levels/DemoGameTread.py | |
index 28b3cfd..87ece96 100644 | |
--- a/ui/levels/DemoGameTread.py | |
+++ b/ui/levels/DemoGameTread.py | |
@@ -1,5 +1,6 @@ | |
from PySide2 import QtCore | |
+ | |
class DemoGameTread(QtCore.QThread): | |
finished = QtCore.Signal(str) | |
diff --git a/ui/levels/LevelFactory.py b/ui/levels/LevelFactory.py | |
index e421d4c..74e85f7 100644 | |
--- a/ui/levels/LevelFactory.py | |
+++ b/ui/levels/LevelFactory.py | |
@@ -9,7 +9,7 @@ from ui.levels.BaseLevel import BaseLevel | |
from ui.debug.DebugLayer import DebugLayer | |
from game_objects import battlefield_objects as bf_objs | |
-from game_objects.battlefield_objects import Obstacle | |
+from game_objects.battlefield_objects import Obstacle | |
from typing import TYPE_CHECKING | |
if TYPE_CHECKING: | |
@@ -18,11 +18,12 @@ if TYPE_CHECKING: | |
from ui.units import Units | |
from battlefield.Cell import Cell | |
+ | |
class LevelFactory: | |
def __init__(self, logicEngine): | |
- self.LEngine:LEngine = logicEngine | |
- self.gameRoot:GameRootNode = None | |
- self.level:BaseLevel = None | |
+ self.LEngine: LEngine = logicEngine | |
+ self.gameRoot: GameRootNode = None | |
+ self.level: BaseLevel = None | |
pass | |
def setGameRoot(self, gameRoot): | |
@@ -43,14 +44,17 @@ class LevelFactory: | |
def setUpLevel(self): | |
self.level.setGameWorld(GameWorld(self.gameRoot.cfg)) | |
- self.level.world.setWorldSize(self.gameRoot.game.bf.w, self.gameRoot.game.bf.h) | |
+ self.level.world.setWorldSize( | |
+ self.gameRoot.game.bf.w, | |
+ self.gameRoot.game.bf.h) | |
self.level.world.setUpFloors(self.gameRoot.game.bf) | |
self.level.setMiddleLayer(UnitMiddleLayer(self.gameRoot.cfg)) | |
self.level.gameVision = GameVision(self.level) | |
self.setUpUnits(self.gameRoot.game.bf) | |
self.level.gameRoot.cfg.setWorld(self.level.world) | |
- self.level.gameRoot.controller.setUp(self.level.world, self.level.units, self.level.middleLayer) | |
+ self.level.gameRoot.controller.setUp( | |
+ self.level.world, self.level.units, self.level.middleLayer) | |
self.level.gameRoot.controller.tr_support.initLevel(self.level) | |
self.level.debugLayer = DebugLayer(self.level) | |
@@ -59,7 +63,11 @@ class LevelFactory: | |
for unit_pos, units in battlefield.cells_to_objs.items(): | |
unit = units[0] | |
if isinstance(unit, bf_objs.Unit): | |
- gameUnit = BasicUnit(self.gameRoot.cfg.unit_size[0], self.gameRoot.cfg.unit_size[1], gameconfig=self.gameRoot.cfg, unit_bf = unit) | |
+ gameUnit = BasicUnit( | |
+ self.gameRoot.cfg.unit_size[0], | |
+ self.gameRoot.cfg.unit_size[1], | |
+ gameconfig=self.gameRoot.cfg, | |
+ unit_bf=unit) | |
if unit.icon == 'hero.png': | |
self.active_unit = True | |
gameUnit.setPixmap(self.gameRoot.cfg.getPicFile(unit.icon)) | |
@@ -75,7 +83,7 @@ class LevelFactory: | |
elif isinstance(unit, Obstacle): | |
obstacle = ObstacleUnit(self.gameRoot.cfg.unit_size[0], | |
self.gameRoot.cfg.unit_size[1], | |
- name = unit.name) | |
+ name=unit.name) | |
obstacle.setPixmap(self.gameRoot.cfg.getPicFile(unit.icon)) | |
obstacle.setWorldPos(unit_pos.x, unit_pos.y) | |
obstacle.uid = unit.uid | |
@@ -83,7 +91,8 @@ class LevelFactory: | |
if obstacle.name == 'Wooden door': | |
self.level.units.units_at[unit.uid] = obstacle | |
self.level.world.obstacles[unit.uid] = obstacle | |
- self.level.units.active_unit = self.level.units.units_at[self.gameRoot.game.turns_manager.get_next().uid] | |
+ self.level.units.active_unit = self.level.units.units_at[self.gameRoot.game.turns_manager.get_next( | |
+ ).uid] | |
self.level.units.updateVision() | |
def addLevelToScene(self, scene): | |
@@ -110,7 +119,3 @@ class LevelFactory: | |
self.level.middleLayer.level = None | |
self.level.middleLayer = None | |
del self.level | |
- | |
- | |
- | |
- | |
diff --git a/ui/levels/Level_demo_dungeon.py b/ui/levels/Level_demo_dungeon.py | |
index 55cf798..a560ddc 100644 | |
--- a/ui/levels/Level_demo_dungeon.py | |
+++ b/ui/levels/Level_demo_dungeon.py | |
@@ -7,13 +7,12 @@ from game_objects import battlefield_objects as bf_objs | |
from ui.levels.BaseLevel import BaseLevel | |
- | |
class Level_demo_dungeon(BaseLevel): | |
def __init__(self, gameconfig): | |
super(Level_demo_dungeon, self).__init__() | |
self.gameconfig = gameconfig | |
- self.z_values = [ i for i in range(demo_dungeon.w)] | |
+ self.z_values = [i for i in range(demo_dungeon.w)] | |
def setUpLevel(self, game, controller): | |
self.setGameWorld(GameWorld(self.gameconfig)) | |
@@ -29,13 +28,16 @@ class Level_demo_dungeon(BaseLevel): | |
controller.setUp(self.world, self.units, self.middleLayer) | |
def printResult(self, time): | |
- print('time = ',time) | |
+ print('time = ', time) | |
def setUpUnits(self, battlefield): | |
self.setUnits(Units()) | |
for unit, unit_pos in battlefield.unit_locations.items(): | |
- gameUnit = BasicUnit(self.gameconfig.unit_size[0], self.gameconfig.unit_size[1], gameconfig = self.gameconfig) | |
+ gameUnit = BasicUnit( | |
+ self.gameconfig.unit_size[0], | |
+ self.gameconfig.unit_size[1], | |
+ gameconfig=self.gameconfig) | |
if unit.icon == 'hero.png': | |
self.active_unit = True | |
gameUnit.setPixmap(self.gameconfig.getPicFile(unit.icon)) | |
@@ -47,5 +49,6 @@ class Level_demo_dungeon(BaseLevel): | |
# добавили gameunit | |
self.units.cells_to_objs[unit.uid] = gameUnit | |
- self.units.active_unit = self.units.cells_to_objs[self.game.turns_manager.get_next().uid] | |
+ self.units.active_unit = self.units.cells_to_objs[self.game.turns_manager.get_next( | |
+ ).uid] | |
self.middleLayer.createSuppot(self.units.cells_to_objs) | |
diff --git a/ui/sounds/damage_sounds.py b/ui/sounds/damage_sounds.py | |
index fbfb8e5..1086b28 100644 | |
--- a/ui/sounds/damage_sounds.py | |
+++ b/ui/sounds/damage_sounds.py | |
@@ -7,6 +7,7 @@ prefix = os.path.abspath(prefix) | |
print(prefix) | |
+ | |
class sound_paths: | |
slash = os.path.join(prefix, 'slash.wav') | |
bash = os.path.join(prefix, 'bash.wav') | |
@@ -26,7 +27,6 @@ damage_sounds = {} | |
t = DamageTypes | |
- | |
damage_sounds[t.SLASH] = sound_paths.slash | |
damage_sounds[t.CRUSH] = sound_paths.bash | |
# damage_sounds[t.PIERCE] = sound_paths.pierce | |
@@ -37,5 +37,3 @@ damage_sounds[t.CRUSH] = sound_paths.bash | |
# damage_sounds[t.ACID] = sound_paths.acid | |
# damage_sounds[t.SONIC] = sound_paths.sonic | |
- | |
- | |
diff --git a/ui/triggers/animation_triggers.py b/ui/triggers/animation_triggers.py | |
index 7eea939..7a8385b 100644 | |
--- a/ui/triggers/animation_triggers.py | |
+++ b/ui/triggers/animation_triggers.py | |
@@ -8,7 +8,7 @@ from GameLoopThread import ProxyEmit | |
def play_movement_anim(t, e): | |
# comment bug threading | |
- ProxyEmit.play_movement_anim.emit({'unit':e.unit,"cell_to":e.cell_to}) | |
+ ProxyEmit.play_movement_anim.emit({'unit': e.unit, "cell_to": e.cell_to}) | |
# TheUI.singleton.gameRoot.level.unitMoveSlot({'unit':e.unit,"cell_to":e.cell_to}) | |
@@ -20,11 +20,16 @@ def move_anim_trigger(game): | |
########### DAMAGE ################# | |
+ | |
def maybe_play_damage_anim(t, e): | |
- ProxyEmit.maybe_play_damage_anim.emit({'amount':e.amount,'target':e.target, 'damage_type':e.damage.type}) | |
+ ProxyEmit.maybe_play_damage_anim.emit( | |
+ {'amount': e.amount, 'target': e.target, 'damage_type': e.damage.type}) | |
+ | |
def maybe_play_hit_anim(t, e): | |
- ProxyEmit.maybe_play_hit_anim.emit({'sound':e.target.sound_map.hit.lower()}) | |
+ ProxyEmit.maybe_play_hit_anim.emit( | |
+ {'sound': e.target.sound_map.hit.lower()}) | |
+ | |
def damage_anim_trigger(game): | |
return Trigger(DamageEvent, | |
@@ -33,11 +38,14 @@ def damage_anim_trigger(game): | |
callbacks=[maybe_play_damage_anim, maybe_play_hit_anim]) | |
########### ATTACK ################# | |
+ | |
def play_attack_anim(t, e): | |
# print('e dir :\n',dir(e)) | |
- ProxyEmit.maybe_play_hit_anim.emit({'sound':e.source.sound_map.attack.lower()}) | |
+ ProxyEmit.maybe_play_hit_anim.emit( | |
+ {'sound': e.source.sound_map.attack.lower()}) | |
pass | |
+ | |
def attack_anin_trigger(game): | |
return Trigger(AttackEvent, | |
platform=game.events_platform, | |
@@ -48,9 +56,11 @@ def attack_anin_trigger(game): | |
def play_perish_anim(t, e): | |
- ProxyEmit.play_perish_anim.emit({'unit':e.unit, 'sound':e.unit.sound_map.perish.lower()}) | |
+ ProxyEmit.play_perish_anim.emit( | |
+ {'unit': e.unit, 'sound': e.unit.sound_map.perish.lower()}) | |
pass | |
+ | |
def perish_anim_trigger(game): | |
return Trigger(UnitDiedEvent, | |
platform=game.events_platform, | |
@@ -62,7 +72,8 @@ def perish_anim_trigger(game): | |
def play_trun_anim(t, e): | |
- ProxyEmit.play_trun_anim.emit({'uid':e.unit.uid,'turn':e.unit.facing}) | |
+ ProxyEmit.play_trun_anim.emit({'uid': e.unit.uid, 'turn': e.unit.facing}) | |
+ | |
def turn_anim_trigger(game): | |
return Trigger(TurnEvent, | |
@@ -76,6 +87,7 @@ def turn_anim_trigger(game): | |
def play_nextunit_anim(t, e): | |
ProxyEmit.play_nextunit_anim.emit() | |
+ | |
def nexunit_anim_trigger(game): | |
return Trigger(NextUnitEvent, | |
platform=game.events_platform, | |
@@ -88,6 +100,7 @@ def nexunit_anim_trigger(game): | |
def play_levelstatus(t, e): | |
ProxyEmit.play_levelstatus.emit(e.status) | |
+ | |
def levelstatus_trigger(game): | |
return Trigger(LevelStatusEvent, | |
platform=game.events_platform, | |
@@ -100,6 +113,7 @@ def levelstatus_trigger(game): | |
def display_ui_error(t, e): | |
ProxyEmit.play_levelstatus.emit(e.message) | |
+ | |
def ui_error_message_trigger(game): | |
return Trigger(UiErrorMessageEvent, | |
platform=game.events_platform, | |
@@ -110,7 +124,7 @@ def ui_error_message_trigger(game): | |
def obstacle_destroyed(t, e): | |
- ProxyEmit.obstacle_estroyed.emit({'unit':e.unit}) | |
+ ProxyEmit.obstacle_estroyed.emit({'unit': e.unit}) | |
def obstacle_destroy_trigger(game): | |
@@ -118,4 +132,3 @@ def obstacle_destroy_trigger(game): | |
platform=game.events_platform, | |
conditions={no_sim_condition}, | |
callbacks=[obstacle_destroyed]) | |
- | |
diff --git a/ui/triggers/no_sim_condition.py b/ui/triggers/no_sim_condition.py | |
index b302374..c71b808 100644 | |
--- a/ui/triggers/no_sim_condition.py | |
+++ b/ui/triggers/no_sim_condition.py | |
@@ -1,4 +1,4 @@ | |
-def no_sim_condition(t,e): | |
- return not e.game.is_sim | |
\ No newline at end of file | |
+def no_sim_condition(t, e): | |
+ return not e.game.is_sim | |
diff --git a/ui/triggers/sound_triggers.py b/ui/triggers/sound_triggers.py | |
index acffea1..97fdbf0 100644 | |
--- a/ui/triggers/sound_triggers.py | |
+++ b/ui/triggers/sound_triggers.py | |
@@ -9,17 +9,18 @@ def maybe_play_damage_sound(t, e): | |
# alternative - use impact factor to determine the volume | |
# volume = (e.damage.amount / e.target.health) ** (1/2) | |
# if volume > 0.4: | |
- sound = damage_sounds[e.damage.type] | |
- # sound.set_volume(volume) | |
- sound.play() | |
+ sound = damage_sounds[e.damage.type] | |
+ # sound.set_volume(volume) | |
+ sound.play() | |
+ | |
def maybe_play_hit_sound(t, e): | |
# volume = (e.amount / e.target.health) ** (1/3) | |
# if volume > 0.25: | |
- sound = e.target.sound_map.hit | |
- # sound.set_volume(volume) | |
- sound.play() | |
- # sound.play(delay = 0.2) | |
+ sound = e.target.sound_map.hit | |
+ # sound.set_volume(volume) | |
+ sound.play() | |
+ # sound.play(delay = 0.2) | |
def damage_sounds_trig(): | |
@@ -31,10 +32,12 @@ def damage_sounds_trig(): | |
########### ATTACK ################# | |
+ | |
def play_attack_sound(t, e): | |
sound = e.source.sound_map.melee_attack | |
sound.play() | |
+ | |
def attack_sounds_trig(): | |
return Trigger(AttackEvent, | |
conditions={no_sim_condition}, | |
@@ -44,10 +47,12 @@ def attack_sounds_trig(): | |
########### PERISH ################# | |
+ | |
def play_perish_sound(t, e): | |
sound = e.unit.sound_map.perish | |
sound.play() | |
+ | |
def perish_sounds_trig(): | |
return Trigger(UnitDiedEvent, | |
conditions={no_sim_condition}, | |
@@ -57,11 +62,13 @@ def perish_sounds_trig(): | |
########### MOVE ################# | |
+ | |
def play_move_sound(t, e): | |
sound = e.unit.sound_map.move | |
print(e.unit) | |
sound.play() | |
+ | |
def move_sounds_trig(): | |
return Trigger(MovementEvent, | |
conditions={no_sim_condition}, | |
diff --git a/ui/units/BasicUnit.py b/ui/units/BasicUnit.py | |
index 5cfeaeb..8eb25d8 100644 | |
--- a/ui/units/BasicUnit.py | |
+++ b/ui/units/BasicUnit.py | |
@@ -17,7 +17,7 @@ class BasicUnit(QObject, GameObject): | |
hovered = QtCore.Signal(QtCore.QObject) | |
hover_out = QtCore.Signal() | |
- def __init__(self, *arg, gameconfig, parent = None, unit_bf = None): | |
+ def __init__(self, *arg, gameconfig, parent=None, unit_bf=None): | |
QObject.__init__(self, parent) | |
GameObject.__init__(self, *arg) | |
self.uid = 0 | |
@@ -42,15 +42,17 @@ class BasicUnit(QObject, GameObject): | |
if self.gameconfig is not None: | |
self.direction = Direction() | |
self.direction.setParentItem(self) | |
- self.direction.setPixmap(self.gameconfig.getPicFile('DIRECTION POINTER.png')) | |
- self.direction.setTransformOriginPoint(self.direction.boundingRect().width()/2, - self.h/2 + self.direction.boundingRect().height()) | |
+ self.direction.setPixmap( | |
+ self.gameconfig.getPicFile('DIRECTION POINTER.png')) | |
+ self.direction.setTransformOriginPoint(self.direction.boundingRect( | |
+ ).width() / 2, - self.h / 2 + self.direction.boundingRect().height()) | |
dirY = self.h - self.direction.boundingRect().height() | |
dirX = (self.w / 2) - (self.direction.boundingRect().width() / 2) | |
self.direction.setPos(dirX, dirY) | |
- self.dirAni = SmoothAnimation(self.direction, self.direction.setRotation) | |
+ self.dirAni = SmoothAnimation( | |
+ self.direction, self.direction.setRotation) | |
- | |
- dir_dict = {(Facing.SOUTH, Facing.EAST) : (360., 270.), | |
+ dir_dict = {(Facing.SOUTH, Facing.EAST): (360., 270.), | |
(Facing.SOUTH, Facing.WEST): (0., 90.), | |
(Facing.EAST, Facing.SOUTH): (270., 360.), | |
(Facing.WEST, Facing.SOUTH): (90., 0.), | |
@@ -71,7 +73,8 @@ class BasicUnit(QObject, GameObject): | |
def mouseMove(self, event): | |
if self.isVisible() and not self.parentItem() is None: | |
- if self.gameRoot.tr_support.rectHitGroupItem(self).contains(event.pos()): | |
+ if self.gameRoot.tr_support.rectHitGroupItem( | |
+ self).contains(event.pos()): | |
self.isHover = True | |
self.hovered.emit(self) | |
else: | |
@@ -99,7 +102,7 @@ class BasicUnit(QObject, GameObject): | |
self.hpText.setText(amount) | |
def getHPprec(self, unit): | |
- return (unit.health * 100)/unit.max_health | |
+ return (unit.health * 100) / unit.max_health | |
def setScale(self, scale): | |
super(BasicUnit, self).setScale(scale) | |
@@ -132,13 +135,17 @@ class BasicUnit(QObject, GameObject): | |
self.anim_move.setDuration(GameVariantAnimation.DURATION_UNIT_MOVE) | |
def __eq__(self, other): | |
- if self is other: return True | |
- if other is None: return False | |
- if self.__class__ != other.__class__: return False | |
+ if self is other: | |
+ return True | |
+ if other is None: | |
+ return False | |
+ if self.__class__ != other.__class__: | |
+ return False | |
return self.__hash__() == other.__hash__() | |
def __hash__(self): | |
- return hash(self.worldPos.x * 2 + self.worldPos.y * 3 + self.uid*4)*3 | |
+ return hash(self.worldPos.x * 2 + | |
+ self.worldPos.y * 3 + self.uid * 4) * 3 | |
def __repr__(self): | |
return f"{self.worldPos} -> BasicUnit {self.uid}" | |
diff --git a/ui/units/GameTooltip.py b/ui/units/GameTooltip.py | |
index 8c89103..0a0a2cd 100644 | |
--- a/ui/units/GameTooltip.py | |
+++ b/ui/units/GameTooltip.py | |
@@ -1,7 +1,8 @@ | |
from PySide2 import QtWidgets | |
+ | |
class GameTooltip(QtWidgets.QGraphicsRectItem): | |
def __init__(self, arg): | |
super(GameTooltip, self).__init__() | |
- self.setRect(0, 0, 32, 32) | |
\ No newline at end of file | |
+ self.setRect(0, 0, 32, 32) | |
diff --git a/ui/units/GameVision.py b/ui/units/GameVision.py | |
index 4eb2277..333abb9 100644 | |
--- a/ui/units/GameVision.py | |
+++ b/ui/units/GameVision.py | |
@@ -3,6 +3,7 @@ from PySide2 import QtWidgets, QtCore, QtGui | |
class GameVision(QtWidgets.QGraphicsItemGroup): | |
"""docs GameVision""" | |
+ | |
def __init__(self, level): | |
super(GameVision, self).__init__() | |
self.level = level | |
@@ -18,10 +19,15 @@ class GameVision(QtWidgets.QGraphicsItemGroup): | |
self.createPoly() | |
def getMainPoly(self): | |
- poly= QtGui.QPolygonF() | |
+ poly = QtGui.QPolygonF() | |
poly.append(QtCore.QPoint(0, 0)) | |
poly.append(QtCore.QPoint(self.bf_w * self.cell_w, 0)) | |
- poly.append(QtCore.QPoint(self.bf_w * self.cell_w, self.bf_h * self.cell_h )) | |
+ poly.append( | |
+ QtCore.QPoint( | |
+ self.bf_w * | |
+ self.cell_w, | |
+ self.bf_h * | |
+ self.cell_h)) | |
poly.append(QtCore.QPoint(0, self.bf_h * self.cell_h)) | |
return poly | |
@@ -58,12 +64,18 @@ class GameVision(QtWidgets.QGraphicsItemGroup): | |
def updatePoly(self): | |
painPath = self.getPainterPath(self.cur_cells) | |
- self.shadowGray.setPolygon(self.polyGray.subtracted(painPath.toFillPolygon())) | |
+ self.shadowGray.setPolygon( | |
+ self.polyGray.subtracted( | |
+ painPath.toFillPolygon())) | |
self.polyDark = self.polyDark.subtracted(painPath.toFillPolygon()) | |
self.shadowDark.setPolygon(self.polyDark) | |
def getPainterPath(self, cells): | |
painPath = QtGui.QPainterPath() | |
for cell in cells: | |
- painPath.addRect(cell.x * self.cell_w, cell.y * self.cell_h , self.cell_w, self.cell_h ) | |
+ painPath.addRect( | |
+ cell.x * self.cell_w, | |
+ cell.y * self.cell_h, | |
+ self.cell_w, | |
+ self.cell_h) | |
return painPath | |
diff --git a/ui/units/HealthBar.py b/ui/units/HealthBar.py | |
index 9995fb5..87dcd2b 100644 | |
--- a/ui/units/HealthBar.py | |
+++ b/ui/units/HealthBar.py | |
@@ -6,6 +6,7 @@ from PySide2.QtGui import QColor | |
class HealthBar(QGraphicsRectItem): | |
"""docstring for HealtBar.""" | |
orange = QColor(255, 102, 0) | |
+ | |
def __init__(self, parent=None): | |
super(HealthBar, self).__init__(parent) | |
self.setBrush(Qt.red) | |
diff --git a/ui/units/HealthText.py b/ui/units/HealthText.py | |
index 1e54e0f..9bc2f59 100644 | |
--- a/ui/units/HealthText.py | |
+++ b/ui/units/HealthText.py | |
@@ -27,7 +27,7 @@ class HealthText(QGraphicsTextItem): | |
self.setVisible(True) | |
def setUnitPos(self, pos): | |
- self.setPos(pos.x() + 32, pos.y()-64) | |
+ self.setPos(pos.x() + 32, pos.y() - 64) | |
def setOffset(self, x, y): | |
# self.setPos(x + 32, y - 32) | |
@@ -45,4 +45,3 @@ class HealthText(QGraphicsTextItem): | |
def setUpFont(self): | |
self.setFont(QFont("Times", 36, 10, False)) | |
- | |
diff --git a/ui/units/ObstacleUnit.py b/ui/units/ObstacleUnit.py | |
index 9be11fd..cebbdb9 100644 | |
--- a/ui/units/ObstacleUnit.py | |
+++ b/ui/units/ObstacleUnit.py | |
@@ -3,6 +3,7 @@ from ui.gamecore import GameObject | |
class ObstacleUnit(GameObject): | |
"""docstring for ObstacleUnit.""" | |
+ | |
def __init__(self, *args, name): | |
super(ObstacleUnit, self).__init__(*args) | |
self.uid = 0 | |
@@ -13,13 +14,16 @@ class ObstacleUnit(GameObject): | |
self.is_obstacle = True | |
def __eq__(self, other): | |
- if self is other: return True | |
- if other is None: return False | |
- if self.__class__ != other.__class__: return False | |
+ if self is other: | |
+ return True | |
+ if other is None: | |
+ return False | |
+ if self.__class__ != other.__class__: | |
+ return False | |
return self.worldPos == other.worldPos.x | |
def __hash__(self): | |
return hash(self.worldPos) * 5 | |
def __repr__(self): | |
- return f"{self.worldPos} -> ObstacleUnit {self.uid} " | |
\ No newline at end of file | |
+ return f"{self.worldPos} -> ObstacleUnit {self.uid} " | |
diff --git a/ui/units/SelectItem.py b/ui/units/SelectItem.py | |
index 3f95151..38b6985 100644 | |
--- a/ui/units/SelectItem.py | |
+++ b/ui/units/SelectItem.py | |
@@ -1,8 +1,9 @@ | |
from PySide2 import QtCore, QtWidgets | |
+ | |
class SelectItem(QtWidgets.QGraphicsRectItem): | |
def __init__(self, *arg): | |
super(SelectItem, self).__init__(*arg) | |
self.setBrush(QtCore.Qt.cyan) | |
- self.setOpacity(0.3) | |
\ No newline at end of file | |
+ self.setOpacity(0.3) | |
diff --git a/ui/units/Target.py b/ui/units/Target.py | |
index 1d94a3b..bcea28e 100644 | |
--- a/ui/units/Target.py | |
+++ b/ui/units/Target.py | |
@@ -1,4 +1,4 @@ | |
-from PySide2 import QtCore, QtGui,QtWidgets | |
+from PySide2 import QtCore, QtGui, QtWidgets | |
from battlefield import Cell | |
@@ -17,7 +17,7 @@ class Target(QtWidgets.QGraphicsRectItem): | |
def setWorldY(self, y): | |
self.worldPos.y = y | |
- self.setY(y * self.h ) | |
+ self.setY(y * self.h) | |
def setWorldPos(self, x, y): | |
self.setWorldX(x) | |
diff --git a/ui/units/UnitMiddleLayer.py b/ui/units/UnitMiddleLayer.py | |
index ee04e49..d9205af 100644 | |
--- a/ui/units/UnitMiddleLayer.py | |
+++ b/ui/units/UnitMiddleLayer.py | |
@@ -14,11 +14,12 @@ class UnitMiddleLayer(QtWidgets.QGraphicsItemGroup): | |
self.targeted = False | |
def setLevel(self, level): | |
- self.level = level | |
+ self.level = level | |
self.level.middleLayer = self | |
def setUp(self): | |
- self.level.gameRoot.pages.gameMenu.actives.setTargets.connect(self.getTargets) | |
+ self.level.gameRoot.pages.gameMenu.actives.setTargets.connect( | |
+ self.getTargets) | |
def setUpSelectItem(self): | |
self.select_item = QtWidgets.QGraphicsRectItem() | |
diff --git a/ui/units/Units.py b/ui/units/Units.py | |
index 92d988b..1b99d53 100644 | |
--- a/ui/units/Units.py | |
+++ b/ui/units/Units.py | |
@@ -12,12 +12,12 @@ if TYPE_CHECKING: | |
class Units(QtWidgets.QGraphicsItemGroup): | |
def __init__(self, *arg): | |
super(Units, self).__init__(*arg) | |
- self.active_unit:BasicUnit = None | |
+ self.active_unit: BasicUnit = None | |
self.units_at = {} | |
self.units_pos = {} | |
self.groups_at = {} | |
self.units_heaps = {} | |
- self.level:BaseLevel = None | |
+ self.level: BaseLevel = None | |
self.acceptHoverEvents() | |
def setLevel(self, level): | |
@@ -51,7 +51,7 @@ class Units(QtWidgets.QGraphicsItemGroup): | |
self.updateVision() | |
self.units_at[uid].setDirection(turn) | |
- def collisionHeorOfUnits(self, x = None, y = None): | |
+ def collisionHeorOfUnits(self, x=None, y=None): | |
if x is None: | |
if not (self.active_unit.worldPos.x, y) in self.getUitsLocations(): | |
self.active_unit.setWorldY(y) | |
@@ -65,7 +65,8 @@ class Units(QtWidgets.QGraphicsItemGroup): | |
self.active_unit = self.units_at[unit.uid] | |
def unitMoveSlot(self, msg): | |
- self.level.gameRoot.cfg.sound_maps[msg.get('unit').sound_map.move.lower()].play() | |
+ self.level.gameRoot.cfg.sound_maps[msg.get( | |
+ 'unit').sound_map.move.lower()].play() | |
self.moveUnit(msg.get('unit'), msg.get('cell_to')) | |
self.update_heaps() | |
@@ -75,7 +76,8 @@ class Units(QtWidgets.QGraphicsItemGroup): | |
def targetDamageSlot(self, msg): | |
# Требуется рефакторинг метод срабатывает после смерти юнита | |
if msg.get('target').uid in self.units_at.keys(): | |
- self.units_at[msg.get('target').uid].updateSupport(msg.get('target'), msg.get('amount')) | |
+ self.units_at[msg.get('target').uid].updateSupport( | |
+ msg.get('target'), msg.get('amount')) | |
self.level.gameRoot.cfg.sound_maps[msg.get('damage_type')].play() | |
pass | |
@@ -87,7 +89,8 @@ class Units(QtWidgets.QGraphicsItemGroup): | |
self.level.gameRoot.cfg.sound_maps[msg.get('sound')].play() | |
def unitDiedSlot(self, msg): | |
- self.level.gameRoot.gamePages.gameMenu.rmToUnitStack(msg.get('unit').uid) | |
+ self.level.gameRoot.gamePages.gameMenu.rmToUnitStack( | |
+ msg.get('unit').uid) | |
self.level.gameRoot.cfg.sound_maps[msg.get('sound')].play() | |
self.unitDied(msg.get('unit')) | |
@@ -96,7 +99,7 @@ class Units(QtWidgets.QGraphicsItemGroup): | |
# if group is None: | |
# self.groups_at[unit.worldPos] = | |
# print('add', unit) | |
- pass | |
+ pass | |
def getUnitsFromCell(self, cell_to): | |
for unit in self.units_at.values(): | |
@@ -105,9 +108,11 @@ class Units(QtWidgets.QGraphicsItemGroup): | |
def updateVision(self): | |
hero = self.level.gameRoot.game.the_hero | |
- self.level.gameVision.setSeenCells(self.level.gameRoot.game.vision.std_seen_cells(hero)) | |
+ self.level.gameVision.setSeenCells( | |
+ self.level.gameRoot.game.vision.std_seen_cells(hero)) | |
for cell, units in self.level.gameRoot.game.bf.cells_to_objs.items(): | |
- if cell not in self.level.gameRoot.game.vision.std_seen_cells(hero): | |
+ if cell not in self.level.gameRoot.game.vision.std_seen_cells( | |
+ hero): | |
for u in units: | |
unit = self.units_at.get(u.uid) | |
if unit is not None: | |
@@ -123,12 +128,17 @@ class Units(QtWidgets.QGraphicsItemGroup): | |
if len(units) > 1: | |
if cell in self.units_heaps.keys(): | |
self.units_heaps[cell].info() | |
- self.units_heaps[cell].update_units(list(self.units_from_(units))) | |
+ self.units_heaps[cell].update_units( | |
+ list(self.units_from_(units))) | |
else: | |
- self.units_heaps[cell] = UnitsHeap(gameRoot=self.level.gameRoot) | |
- self.level.gameRoot.controller.mouseMove.connect(self.units_heaps[cell].mouseMoveEvent) | |
- self.level.gameRoot.controller.mousePress.connect(self.units_heaps[cell].mousePressEvent) | |
- self.units_heaps[cell].update_units(list(self.units_from_(units))) | |
+ self.units_heaps[cell] = UnitsHeap( | |
+ gameRoot=self.level.gameRoot) | |
+ self.level.gameRoot.controller.mouseMove.connect( | |
+ self.units_heaps[cell].mouseMoveEvent) | |
+ self.level.gameRoot.controller.mousePress.connect( | |
+ self.units_heaps[cell].mousePressEvent) | |
+ self.units_heaps[cell].update_units( | |
+ list(self.units_from_(units))) | |
else: | |
if self.units_heaps.get(cell) is not None: | |
self.destroyUnitsHeap(cell) | |
@@ -152,7 +162,8 @@ class Units(QtWidgets.QGraphicsItemGroup): | |
units = self.level.gameRoot.game.bf.cells_to_objs.get(item.worldPos) | |
if units is not None: | |
if len(units) == 1: | |
- self.level.gameRoot.gamePages.toolTip.setDict(units[0].tooltip_info) | |
+ self.level.gameRoot.gamePages.toolTip.setDict( | |
+ units[0].tooltip_info) | |
# else: | |
# for u in units: | |
# if u.uid == self.units_heaps[item.worldPos].units[-1].uid: | |
@@ -171,8 +182,10 @@ class Units(QtWidgets.QGraphicsItemGroup): | |
self.level.gameRoot.view.mouseMove.disconnect(unit.mouseMove) | |
def destroyUnitsHeap(self, cell): | |
- self.level.gameRoot.controller.mouseMove.disconnect(self.units_heaps[cell].mouseMoveEvent) | |
- self.level.gameRoot.controller.mousePress.disconnect(self.units_heaps[cell].mousePressEvent) | |
+ self.level.gameRoot.controller.mouseMove.disconnect( | |
+ self.units_heaps[cell].mouseMoveEvent) | |
+ self.level.gameRoot.controller.mousePress.disconnect( | |
+ self.units_heaps[cell].mousePressEvent) | |
del self.units_heaps[cell] | |
def destroy(self): | |
@@ -185,7 +198,3 @@ class Units(QtWidgets.QGraphicsItemGroup): | |
self.units_heaps.clear() | |
self.level = None | |
self = None | |
- | |
- | |
- | |
- | |
diff --git a/ui/units/UnitsHeap.py b/ui/units/UnitsHeap.py | |
index 6e07d87..92133fd 100644 | |
--- a/ui/units/UnitsHeap.py | |
+++ b/ui/units/UnitsHeap.py | |
@@ -36,7 +36,7 @@ class UnitsHeap(QObject, GameObject): | |
self.setPos(new_units[0].pos().x(), new_units[0].pos().y()) | |
if self.units != new_units: | |
for u in self.units: | |
- if not u in new_units: | |
+ if u not in new_units: | |
self.reset_gui(u) | |
self.units = new_units[:] | |
self.units.reverse() | |
@@ -66,9 +66,12 @@ class UnitsHeap(QObject, GameObject): | |
def mouseMoveEvent(self, e): | |
pos = self.gameRoot.view.mapToScene(e.pos().x(), e.pos().y()) | |
- x = pos.x() - self.gameRoot.controller.tr_support.tr.m31() - self.gameRoot.level.world.pos().x() | |
- y = pos.y() - self.gameRoot.controller.tr_support.tr.m32() - self.gameRoot.level.world.pos().y() | |
- if self.pos().x() < x and self.pos().x() + 128 > x and self.pos().y() < y and self.pos().y() + 128 > y: | |
+ x = pos.x() - self.gameRoot.controller.tr_support.tr.m31() - \ | |
+ self.gameRoot.level.world.pos().x() | |
+ y = pos.y() - self.gameRoot.controller.tr_support.tr.m32() - \ | |
+ self.gameRoot.level.world.pos().y() | |
+ if self.pos().x() < x and self.pos().x() + \ | |
+ 128 > x and self.pos().y() < y and self.pos().y() + 128 > y: | |
unit = self.getTopLayer(x, y) | |
if unit is not None: | |
if unit != self.select_unit: | |
@@ -87,9 +90,12 @@ class UnitsHeap(QObject, GameObject): | |
def mousePressEvent(self, e): | |
if e.button() == QtCore.Qt.MouseButton.RightButton: | |
pos = self.gameRoot.view.mapToScene(e.pos().x(), e.pos().y()) | |
- x = pos.x() - self.gameRoot.controller.tr_support.tr.m31() - self.gameRoot.level.world.pos().x() | |
- y = pos.y() - self.gameRoot.controller.tr_support.tr.m32() - self.gameRoot.level.world.pos().y() | |
- if self.pos().x() < x and self.pos().x() + 128 > x and self.pos().y() < y and self.pos().y() + 128 > y: | |
+ x = pos.x() - self.gameRoot.controller.tr_support.tr.m31() - \ | |
+ self.gameRoot.level.world.pos().x() | |
+ y = pos.y() - self.gameRoot.controller.tr_support.tr.m32() - \ | |
+ self.gameRoot.level.world.pos().y() | |
+ if self.pos().x() < x and self.pos().x() + \ | |
+ 128 > x and self.pos().y() < y and self.pos().y() + 128 > y: | |
if self.select_unit is not None: | |
self.units.remove(self.select_unit) | |
self.units.append(self.select_unit) | |
@@ -127,6 +133,3 @@ class UnitsHeap(QObject, GameObject): | |
# if a.x() < b.x() or a.y() < b.y(): | |
# print('a of b') | |
return True | |
- | |
- | |
- |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment