Rename : damage_stats -> combat_stats
This commit is contained in:
+18
-18
@@ -8,7 +8,7 @@ from .environment import TEST_ENV_ENABLED
|
|||||||
|
|
||||||
from . import backend_proxy
|
from . import backend_proxy
|
||||||
from .backend_proxy import InitializationResult, INITIALIZATION_RESULT
|
from .backend_proxy import InitializationResult, INITIALIZATION_RESULT
|
||||||
from .stats import damage_stats, fame_stats, time_stats, combat_state
|
from .stats import combat_stats, fame_stats, time_stats, combat_state
|
||||||
from .consts import events as ev_consts
|
from .consts import events as ev_consts
|
||||||
from .event_receiver import VisibilityEventReceiver
|
from .event_receiver import VisibilityEventReceiver
|
||||||
from .stats.visibility import Visibility
|
from .stats.visibility import Visibility
|
||||||
@@ -23,7 +23,7 @@ class VisibilityType:
|
|||||||
|
|
||||||
@dataclass(frozen=True)
|
@dataclass(frozen=True)
|
||||||
class StatType:
|
class StatType:
|
||||||
Damage = 'Damage'
|
Combat = 'Combat'
|
||||||
Fame = 'Fame'
|
Fame = 'Fame'
|
||||||
Time = 'Time'
|
Time = 'Time'
|
||||||
|
|
||||||
@@ -31,17 +31,17 @@ class StatType:
|
|||||||
class GameStats():
|
class GameStats():
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
self.zone = {
|
self.zone = {
|
||||||
StatType.Damage: damage_stats.DamageStats(),
|
StatType.Combat: combat_stats.CombatStats(),
|
||||||
StatType.Fame: fame_stats.FameStats(),
|
StatType.Fame: fame_stats.FameStats(),
|
||||||
StatType.Time: time_stats.TimeStats(),
|
StatType.Time: time_stats.TimeStats(),
|
||||||
}
|
}
|
||||||
self.last_fight = {
|
self.last_fight = {
|
||||||
StatType.Damage: damage_stats.DamageStats(),
|
StatType.Combat: combat_stats.CombatStats(),
|
||||||
StatType.Fame: fame_stats.FameStats(),
|
StatType.Fame: fame_stats.FameStats(),
|
||||||
StatType.Time: time_stats.TimeStats(),
|
StatType.Time: time_stats.TimeStats(),
|
||||||
}
|
}
|
||||||
self.history = {
|
self.history = {
|
||||||
StatType.Damage: damage_stats.DamageStats(),
|
StatType.Combat: combat_stats.CombatStats(),
|
||||||
StatType.Fame: fame_stats.FameStats(),
|
StatType.Fame: fame_stats.FameStats(),
|
||||||
StatType.Time: time_stats.TimeStats(),
|
StatType.Time: time_stats.TimeStats(),
|
||||||
}
|
}
|
||||||
@@ -54,21 +54,21 @@ class GameStats():
|
|||||||
self._construct_new_stats([VisibilityType.LastFight])
|
self._construct_new_stats([VisibilityType.LastFight])
|
||||||
|
|
||||||
elif event[ev_consts.EvKeyName] == ev_consts.EvNameZoneChange:
|
elif event[ev_consts.EvKeyName] == ev_consts.EvNameZoneChange:
|
||||||
self.history[StatType.Damage].update(self.zone[StatType.Damage])
|
self.history[StatType.Combat].update(self.zone[StatType.Combat])
|
||||||
self.history[StatType.Fame].update(self.zone[StatType.Fame])
|
self.history[StatType.Fame].update(self.zone[StatType.Fame])
|
||||||
self.history[StatType.Time].update(self.zone[StatType.Time])
|
self.history[StatType.Time].update(self.zone[StatType.Time])
|
||||||
|
|
||||||
self._construct_new_stats([VisibilityType.Zone])
|
self._construct_new_stats([VisibilityType.Zone])
|
||||||
|
|
||||||
self.zone[StatType.Damage].receive(event)
|
self.zone[StatType.Combat].receive(event)
|
||||||
self.last_fight[StatType.Damage].receive(event)
|
self.last_fight[StatType.Combat].receive(event)
|
||||||
self.zone[StatType.Fame].receive(event)
|
self.zone[StatType.Fame].receive(event)
|
||||||
self.last_fight[StatType.Fame].receive(event)
|
self.last_fight[StatType.Fame].receive(event)
|
||||||
self.visibility.receive(event)
|
self.visibility.receive(event)
|
||||||
|
|
||||||
def reset(self, stat_type):
|
def reset(self, stat_type):
|
||||||
if stat_type == VisibilityType.Zone:
|
if stat_type == VisibilityType.Zone:
|
||||||
for t in (StatType.Damage, StatType.Time, StatType.Fame):
|
for t in (StatType.Combat, StatType.Time, StatType.Fame):
|
||||||
self.history[t].update(self.zone[t])
|
self.history[t].update(self.zone[t])
|
||||||
self._construct_new_stats(
|
self._construct_new_stats(
|
||||||
(VisibilityType.Zone, VisibilityType.LastFight))
|
(VisibilityType.Zone, VisibilityType.LastFight))
|
||||||
@@ -78,13 +78,13 @@ class GameStats():
|
|||||||
self._construct_new_stats(
|
self._construct_new_stats(
|
||||||
(VisibilityType.Zone, VisibilityType.Overall, VisibilityType.LastFight))
|
(VisibilityType.Zone, VisibilityType.Overall, VisibilityType.LastFight))
|
||||||
|
|
||||||
def damage_stats(self, stat_type):
|
def combat_stats(self, stat_type):
|
||||||
if stat_type == VisibilityType.Zone:
|
if stat_type == VisibilityType.Zone:
|
||||||
return self.zone[StatType.Damage].player_list(self.visibility)
|
return self.zone[StatType.Combat].player_list(self.visibility)
|
||||||
elif stat_type == VisibilityType.LastFight:
|
elif stat_type == VisibilityType.LastFight:
|
||||||
return self.last_fight[StatType.Damage].player_list(self.visibility)
|
return self.last_fight[StatType.Combat].player_list(self.visibility)
|
||||||
elif stat_type == VisibilityType.Overall:
|
elif stat_type == VisibilityType.Overall:
|
||||||
return self.history[StatType.Damage].combined(self.zone[StatType.Damage]).player_list(self.visibility)
|
return self.history[StatType.Combat].combined(self.zone[StatType.Combat]).player_list(self.visibility)
|
||||||
|
|
||||||
def fame_stats(self, stat_type):
|
def fame_stats(self, stat_type):
|
||||||
if stat_type == VisibilityType.Zone:
|
if stat_type == VisibilityType.Zone:
|
||||||
@@ -103,19 +103,19 @@ class GameStats():
|
|||||||
return self.history[StatType.Time].combined(self.zone[StatType.Time]).stats()
|
return self.history[StatType.Time].combined(self.zone[StatType.Time]).stats()
|
||||||
|
|
||||||
def _construct_new_stats(self, scope: Iterable[str]):
|
def _construct_new_stats(self, scope: Iterable[str]):
|
||||||
types = (StatType.Damage, StatType.Time, StatType.Fame)
|
types = (StatType.Combat, StatType.Time, StatType.Fame)
|
||||||
for s in scope:
|
for s in scope:
|
||||||
for t in types:
|
for t in types:
|
||||||
if t == StatType.Time:
|
if t == StatType.Time:
|
||||||
getattr(self, s)[t] = time_stats.TimeStats()
|
getattr(self, s)[t] = time_stats.TimeStats()
|
||||||
elif t == StatType.Damage:
|
elif t == StatType.Combat:
|
||||||
getattr(self, s)[t] = damage_stats.DamageStats.from_other(
|
getattr(self, s)[t] = combat_stats.CombatStats.from_other(
|
||||||
getattr(self, s)[t])
|
getattr(self, s)[t])
|
||||||
elif t == StatType.Fame:
|
elif t == StatType.Fame:
|
||||||
getattr(self, s)[t] = fame_stats.FameStats()
|
getattr(self, s)[t] = fame_stats.FameStats()
|
||||||
|
|
||||||
def _are_everyone_in_session_out_of_combat(self):
|
def _are_everyone_in_session_out_of_combat(self):
|
||||||
return all(player.combat_state == combat_state.CombatState.OutOfCombat for player in self.zone[StatType.Damage].player_list(self.visibility))
|
return all(player.combat_state == combat_state.CombatState.OutOfCombat for player in self.zone[StatType.Combat].player_list(self.visibility))
|
||||||
|
|
||||||
def _merged_stats(self, stats: dict):
|
def _merged_stats(self, stats: dict):
|
||||||
result = {}
|
result = {}
|
||||||
@@ -167,7 +167,7 @@ def get_stats(stat_type: VisibilityType):
|
|||||||
if not new_events and cached_players:
|
if not new_events and cached_players:
|
||||||
return (cached_players, fame, time)
|
return (cached_players, fame, time)
|
||||||
|
|
||||||
players = game_stats.damage_stats(stat_type)
|
players = game_stats.combat_stats(stat_type)
|
||||||
|
|
||||||
return (players, fame, time)
|
return (players, fame, time)
|
||||||
|
|
||||||
|
|||||||
@@ -84,7 +84,7 @@ class Player(Stats):
|
|||||||
return time_utils.as_milliseconds(self.damage_done / self.time_in_combat)
|
return time_utils.as_milliseconds(self.damage_done / self.time_in_combat)
|
||||||
|
|
||||||
|
|
||||||
class DamageStats(CombatEventReceiver, Stats):
|
class CombatStats(CombatEventReceiver, Stats):
|
||||||
def __init__(self, players=None):
|
def __init__(self, players=None):
|
||||||
if not players:
|
if not players:
|
||||||
players = {}
|
players = {}
|
||||||
@@ -92,11 +92,11 @@ class DamageStats(CombatEventReceiver, Stats):
|
|||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def new(self):
|
def new(self):
|
||||||
return DamageStats()
|
return CombatStats()
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def from_other(other):
|
def from_other(other):
|
||||||
return DamageStats({k: Player.from_other(v) for (k, v) in other.players.items()})
|
return CombatStats({k: Player.from_other(v) for (k, v) in other.players.items()})
|
||||||
|
|
||||||
def update(self, other):
|
def update(self, other):
|
||||||
for (id, player) in other.players.items():
|
for (id, player) in other.players.items():
|
||||||
@@ -107,7 +107,7 @@ class DamageStats(CombatEventReceiver, Stats):
|
|||||||
self.players[id].update(player)
|
self.players[id].update(player)
|
||||||
|
|
||||||
def combined(self, other):
|
def combined(self, other):
|
||||||
stats = DamageStats()
|
stats = CombatStats()
|
||||||
stats.update(self)
|
stats.update(self)
|
||||||
stats.update(other)
|
stats.update(other)
|
||||||
|
|
||||||
Reference in New Issue
Block a user