1+ from datetime import datetime
2+
3+ import numpy as np
4+
5+ from module .base .decorator import cached_property
16from module .campaign .campaign_base import CampaignBase
27from module .campaign .run import CampaignRun
38from module .combat .assets import BATTLE_PREPARATION
9+ from module .combat .emotion import Emotion
410from module .equipment .assets import *
511from module .equipment .equipment import Equipment
612from module .exception import CampaignEnd
@@ -63,15 +69,56 @@ def handle_combat_low_emotion(self):
6369 raise CampaignEnd ('Emotion withdraw' )
6470
6571
72+ class GemsEmotion (Emotion ):
73+ def check_reduce (self , battle ):
74+ """
75+ Override Emotion.check_reduce to trigger stop condition when emotion is too low before battle.
76+ """
77+ if not self .is_calculate :
78+ return
79+
80+ method = self .config .Fleet_FleetOrder
81+ if method == 'fleet1_all_fleet2_standby' :
82+ battle = (battle , 0 )
83+ elif method == 'fleet1_standby_fleet2_all' :
84+ battle = (0 , battle )
85+
86+ battle = tuple (np .array (battle ) * self .reduce_per_battle_before_entering )
87+ logger .info (f'Expect emotion reduce: { battle } ' )
88+
89+ self .update ()
90+ self .record ()
91+ self .show ()
92+ recovered = max ([f .get_recovered (b ) for f , b in zip (self .fleets , battle )])
93+ if recovered > datetime .now ():
94+ self .config .GEMS_EMOTION_TRIGGERED = True
95+ raise CampaignEnd ('Emotion control' )
96+
97+ def wait (self , fleet_index ):
98+ """
99+ Override Emotion.wait to trigger stop condition when emotion is too low after battle.
100+ """
101+ self .update ()
102+ self .record ()
103+ self .show ()
104+ fleet = self .fleets [fleet_index - 1 ]
105+ recovered = fleet .get_recovered (expected_reduce = self .reduce_per_battle )
106+ if recovered > datetime .now ():
107+ self .config .GEMS_EMOTION_TRIGGERED = True
108+
109+
66110class GemsFarming (CampaignRun , Dock ):
67111 def load_campaign (self , name , folder = 'campaign_main' ):
68112 super ().load_campaign (name , folder )
69113
70114 class GemsCampaign (GemsCampaignOverride , self .module .Campaign ):
71- pass
115+ @cached_property
116+ def emotion (self ):
117+ return GemsEmotion (config = self .config )
72118
73119 self .campaign = GemsCampaign (device = self .campaign .device , config = self .campaign .config )
74- self .campaign .config .override (Emotion_Mode = 'ignore' )
120+ if not self .change_vanguard :
121+ self .campaign .config .override (Emotion_Mode = 'ignore' )
75122 self .campaign .config .override (EnemyPriority_EnemyScaleBalanceWeight = 'S1_enemy_first' )
76123
77124 @property
@@ -97,6 +144,8 @@ def max_level(self):
97144 def min_emotion (self ):
98145 return (2 + self .campaign ._map_battle ) * self .campaign .emotion .reduce_per_battle
99146
147+ _new_fleet_emotion = 0
148+
100149 @property
101150 def fleet_to_attack_index (self ):
102151 if self .config .Fleet_FleetOrder == 'fleet1_standby_fleet2_all' :
@@ -205,16 +254,18 @@ def get_common_rarity_cv(self, max_level=31, min_emotion=0):
205254
206255 def flagship_change_execute (self ):
207256 self .ui_enter_ship (FLEET_ENTER_FLAGSHIP , long_click = False )
208- candidate = self .get_common_rarity_cv ()
257+ candidate = self .get_common_rarity_cv (min_emotion = self . min_emotion )
209258 if candidate :
210259 ship = max (candidate , key = lambda s : (s .level , s .emotion ))
260+ self ._new_fleet_emotion = min (ship .emotion , self ._new_fleet_emotion ) if self ._new_fleet_emotion else ship .emotion
211261 self .dock_select_one (ship .button )
212262 self .dock_reset ()
213263 self .dock_select_confirm (check_button = page_fleet .check_button )
214264 logger .info ('Change flagship success' )
215265 return True
216266
217267 logger .info ('Change flagship failed, no CV in common rarity.' )
268+ self ._new_fleet_emotion = 0
218269 self .dock_reset ()
219270 self .ui_leave_ship ()
220271 return False
@@ -314,13 +365,15 @@ def vanguard_change_execute(self):
314365 candidate = self .get_common_rarity_dd (min_emotion = self .min_emotion )
315366 if candidate :
316367 ship = max (candidate , key = lambda s : s .emotion )
368+ self ._new_fleet_emotion = min (ship .emotion , self ._new_fleet_emotion ) if self ._new_fleet_emotion else ship .emotion
317369 self .dock_select_one (ship .button )
318370 self .dock_reset ()
319371 self .dock_select_confirm (check_button = page_fleet .check_button )
320372 logger .info ('Change vanguard success' )
321373 return True
322374
323375 logger .info ('Change vanguard failed, no DD in common rarity.' )
376+ self ._new_fleet_emotion = 0
324377 self .dock_reset ()
325378 self .ui_leave_ship ()
326379 return False
@@ -363,7 +416,7 @@ def triggered_stop_condition(self, oil_check=True):
363416 logger .hr ('TRIGGERED LV32 LIMIT' )
364417 return True
365418
366- if self .campaign .map_is_auto_search and self . campaign . config .GEMS_EMOTION_TRIGGERED :
419+ if self .campaign .config .GEMS_EMOTION_TRIGGERED :
367420 self ._trigger_emotion = True
368421 logger .hr ('TRIGGERED EMOTION LIMIT' )
369422 return True
@@ -387,17 +440,23 @@ def run(self, name, folder='campaign_main', mode='normal', total=0):
387440 try :
388441 super ().run (name = name , folder = folder , total = total )
389442 except CampaignEnd as e :
390- if e .args [0 ] == 'Emotion withdraw' :
443+ if "Emotion" in e .args [0 ]:
391444 self ._trigger_emotion = True
392445 else :
393446 raise e
394447
395448 # End
396449 if self ._trigger_lv32 or self ._trigger_emotion :
450+ self ._new_fleet_emotion = 150
397451 success = self .flagship_change ()
398452 if self .change_vanguard :
399453 success = success and self .vanguard_change ()
400454
455+ if self .fleet_to_attack == 2 :
456+ self .campaign .config .set_record (Emotion_Fleet2Value = self ._new_fleet_emotion )
457+ else :
458+ self .campaign .config .set_record (Emotion_Fleet1Value = self ._new_fleet_emotion )
459+
401460 if is_limit and self .config .StopCondition_RunCount <= 0 :
402461 logger .hr ('Triggered stop condition: Run count' )
403462 self .config .StopCondition_RunCount = 0
0 commit comments