Updated silver and item collection
This commit is contained in:
+58
-6
@@ -9,7 +9,7 @@ from .environment import TEST_ENV_ENABLED
|
||||
|
||||
from . import backend_proxy
|
||||
from .backend_proxy import InitializationResult, INITIALIZATION_RESULT
|
||||
from .stats import combat_stats, fame_stats, time_stats, combat_state
|
||||
from .stats import combat_stats, economy_stats, fame_stats, time_stats, combat_state
|
||||
from .consts import events as ev_consts
|
||||
from .event_receiver import VisibilityEventReceiver
|
||||
from .stats.visibility import Visibility
|
||||
@@ -30,6 +30,7 @@ class StatType:
|
||||
Combat: str = 'Combat'
|
||||
Fame: str = 'Fame'
|
||||
Time: str = 'Time'
|
||||
Economy: str = 'Economy'
|
||||
|
||||
|
||||
@dataclass(frozen=True)
|
||||
@@ -46,16 +47,19 @@ class GameStats():
|
||||
StatType.Combat: combat_stats.CombatStats(self.visibility),
|
||||
StatType.Fame: fame_stats.FameStats(),
|
||||
StatType.Time: time_stats.TimeStats(),
|
||||
StatType.Economy: economy_stats.EconomyStats(),
|
||||
}
|
||||
self.last_fight = {
|
||||
StatType.Combat: combat_stats.CombatStats(self.visibility),
|
||||
StatType.Fame: fame_stats.FameStats(),
|
||||
StatType.Time: time_stats.TimeStats(),
|
||||
StatType.Economy: economy_stats.EconomyStats(),
|
||||
}
|
||||
self.history = {
|
||||
StatType.Combat: combat_stats.CombatStats(self.visibility),
|
||||
StatType.Fame: fame_stats.FameStats(),
|
||||
StatType.Time: time_stats.TimeStats(),
|
||||
StatType.Economy: economy_stats.EconomyStats(),
|
||||
}
|
||||
|
||||
def register_event(self, event):
|
||||
@@ -68,6 +72,7 @@ class GameStats():
|
||||
self.zone[StatType.Combat])
|
||||
self.history[StatType.Fame].update(self.zone[StatType.Fame])
|
||||
self.history[StatType.Time].update(self.zone[StatType.Time])
|
||||
self.history[StatType.Economy].update(self.zone[StatType.Economy])
|
||||
|
||||
self._construct_new_stats([VisibilityType.Zone])
|
||||
|
||||
@@ -75,11 +80,13 @@ class GameStats():
|
||||
self.last_fight[StatType.Combat].receive(event)
|
||||
self.zone[StatType.Fame].receive(event)
|
||||
self.last_fight[StatType.Fame].receive(event)
|
||||
self.zone[StatType.Economy].receive(event)
|
||||
self.last_fight[StatType.Economy].receive(event)
|
||||
self.visibility.receive(event)
|
||||
|
||||
def reset(self, stat_type):
|
||||
if stat_type == VisibilityType.Zone:
|
||||
for t in (StatType.Combat, StatType.Time, StatType.Fame):
|
||||
for t in (StatType.Combat, StatType.Time, StatType.Fame, StatType.Economy):
|
||||
self.history[t].update(self.zone[t])
|
||||
self._construct_new_stats(
|
||||
(VisibilityType.Zone, VisibilityType.LastFight))
|
||||
@@ -129,8 +136,32 @@ class GameStats():
|
||||
elif stat_type == VisibilityType.Overall:
|
||||
return self.history[StatType.Time].combined(self.zone[StatType.Time]).stats()
|
||||
|
||||
def economy_stats(self, stat_type):
|
||||
if stat_type == VisibilityType.Zone:
|
||||
return self.zone[StatType.Economy].stats()
|
||||
elif stat_type == VisibilityType.LastFight:
|
||||
return self.last_fight[StatType.Economy].stats()
|
||||
elif stat_type == VisibilityType.Overall:
|
||||
return self.history[StatType.Economy].combined(self.zone[StatType.Economy]).stats()
|
||||
|
||||
def item_stats(self, stat_type):
|
||||
if stat_type == VisibilityType.Zone:
|
||||
return self.zone[StatType.Economy].item_list()
|
||||
elif stat_type == VisibilityType.LastFight:
|
||||
return self.last_fight[StatType.Economy].item_list()
|
||||
elif stat_type == VisibilityType.Overall:
|
||||
return self.history[StatType.Economy].combined(self.zone[StatType.Economy]).item_list()
|
||||
|
||||
def silver_stats(self, stat_type):
|
||||
if stat_type == VisibilityType.Zone:
|
||||
return self.zone[StatType.Economy].silver_list()
|
||||
elif stat_type == VisibilityType.LastFight:
|
||||
return self.last_fight[StatType.Economy].silver_list()
|
||||
elif stat_type == VisibilityType.Overall:
|
||||
return self.history[StatType.Economy].combined(self.zone[StatType.Economy]).silver_list()
|
||||
|
||||
def _construct_new_stats(self, scope: Iterable[str]):
|
||||
types = (StatType.Combat, StatType.Time, StatType.Fame)
|
||||
types = (StatType.Combat, StatType.Time, StatType.Fame, StatType.Economy)
|
||||
for s in scope:
|
||||
for t in types:
|
||||
if t == StatType.Time:
|
||||
@@ -140,6 +171,8 @@ class GameStats():
|
||||
getattr(self, s)[t])
|
||||
elif t == StatType.Fame:
|
||||
getattr(self, s)[t] = fame_stats.FameStats()
|
||||
elif t == StatType.Economy:
|
||||
getattr(self, s)[t] = economy_stats.EconomyStats()
|
||||
|
||||
|
||||
game_stats = GameStats()
|
||||
@@ -181,13 +214,17 @@ cached_stat_type = None
|
||||
cached_combat_stat_type = None
|
||||
|
||||
|
||||
def get_stats(stat_type: str, combat_stat_type: str):
|
||||
global cached_players, cached_stat_type, cached_combat_stat_type
|
||||
def _drain_events():
|
||||
new_events = False
|
||||
|
||||
while not event_queue.empty():
|
||||
new_events = True
|
||||
game_stats.register_event(event_queue.get_nowait())
|
||||
return new_events
|
||||
|
||||
|
||||
def get_stats(stat_type: str, combat_stat_type: str):
|
||||
global cached_players, cached_stat_type, cached_combat_stat_type
|
||||
new_events = _drain_events()
|
||||
|
||||
fame = game_stats.fame_stats(stat_type)
|
||||
time = game_stats.time_stats(stat_type)['seconds_in_game']
|
||||
@@ -209,6 +246,21 @@ def get_stats(stat_type: str, combat_stat_type: str):
|
||||
return (cached_players, fame, time)
|
||||
|
||||
|
||||
def economy_stats_for(stat_type: str):
|
||||
_drain_events()
|
||||
return game_stats.economy_stats(stat_type)
|
||||
|
||||
|
||||
def item_stats_for(stat_type: str):
|
||||
_drain_events()
|
||||
return game_stats.item_stats(stat_type)
|
||||
|
||||
|
||||
def silver_stats_for(stat_type: str):
|
||||
_drain_events()
|
||||
return game_stats.silver_stats(stat_type)
|
||||
|
||||
|
||||
def queue_an_event(event):
|
||||
event_queue.put(event)
|
||||
logger.debug("event received: %s", event.get(ev_consts.EvKeyName))
|
||||
|
||||
Reference in New Issue
Block a user