1- from cached_property import cached_property
21from datetime import datetime
32
43import numpy as np
54
5+ from module .base .decorator import cached_property
66from module .campaign .campaign_base import CampaignBase
77from module .campaign .run import CampaignRun
88from module .combat .assets import BATTLE_PREPARATION
99from module .combat .emotion import Emotion
1010from module .equipment .assets import *
1111from module .equipment .fleet_equipment import FleetEquipment
12- from module .exception import CampaignEnd , ScriptError
12+ from module .exception import CampaignEnd , ScriptEnd , ScriptError
1313from module .handler .assets import AUTO_SEARCH_MAP_OPTION_OFF
1414from module .logger import logger
1515from module .map .assets import FLEET_PREPARATION , MAP_PREPARATION
@@ -42,29 +42,12 @@ def check_reduce(self, battle):
4242 CampaignEnd: Pause current task to prevent emotion control in the future.
4343 """
4444
45- if not self .is_calculate :
46- return
47-
48- method = self .config .Fleet_FleetOrder
49-
50- if method == 'fleet1_all_fleet2_standby' :
51- battle = (battle , 0 )
52- elif method == 'fleet1_standby_fleet2_all' :
53- battle = (0 , battle )
54- else :
55- raise ScriptError (f'Unknown fleet order: { method } ' )
56-
57- battle = tuple (np .array (battle ) * self .reduce_per_battle_before_entering )
58- logger .info (f'Expect emotion reduce: { battle } ' )
59-
60- self .update ()
61- self .record ()
62- self .show ()
63- recovered = max ([f .get_recovered (b ) for f , b in zip (self .fleets , battle )])
64- if recovered > datetime .now ():
65- logger .info ('Delay current task to prevent emotion control in the future' )
66- self .config .GEMS_EMOTION_TRIGGRED = True
67- raise CampaignEnd ('Emotion withdraw' )
45+ try :
46+ super ().check_reduce (battle )
47+ except ScriptEnd :
48+ self .config .GEMS_EMOTION_TRIGGERED = True
49+ self .config .task_delay (minute = - 30 ) # to undo emotion delay
50+ raise CampaignEnd ('Emotion control' )
6851
6952 def wait (self , fleet_index ):
7053 pass
@@ -362,8 +345,6 @@ def get_templates(common_dd):
362345 logger .error (f'Invalid CommonDD setting: { common_dd } ' )
363346 raise ScriptError (f'Invalid CommonDD setting: { common_dd } ' )
364347
365- _new_emotion : int
366-
367348 def flagship_change_execute (self ):
368349 """
369350 Returns:
@@ -382,7 +363,7 @@ def flagship_change_execute(self):
382363 ship = self .get_common_rarity_cv ()
383364 if ship :
384365 target_ship = min (ship , key = lambda s : (s .level , - s .emotion ))
385- self ._new_emotion = target_ship .emotion
366+ self .set_emotion ( target_ship .emotion )
386367 self ._ship_change_confirm (target_ship .button )
387368
388369 logger .info ('Change flagship success' )
@@ -423,13 +404,14 @@ def vanguard_change_execute(self):
423404 ship = self .get_common_rarity_dd ()
424405 if ship :
425406 target_ship = max (ship , key = lambda s : s .emotion )
426- self ._new_emotion = min (self ._new_emotion , target_ship .emotion )
407+ self .set_emotion ( min (self .get_emotion () , target_ship .emotion ) )
427408 self ._ship_change_confirm (target_ship .button )
428409
429410 logger .info ('Change vanguard ship success' )
430411 return True
431412 else :
432413 logger .info ('Change vanguard ship failed, no DD in common rarity.' )
414+ self .set_emotion (0 ) # a failure in vanguard change means low emotion DD, assuming 0.
433415 self ._dock_reset ()
434416 self .ui_back (check_button = page_fleet .check_button )
435417 return False
@@ -451,6 +433,12 @@ def triggered_stop_condition(self, oil_check=True):
451433
452434 return super ().triggered_stop_condition (oil_check = oil_check )
453435
436+ def get_emotion (self ):
437+ if self .config .Fleet_FleetOrder == 'fleet1_standby_fleet2_all' :
438+ return self .campaign .config .Emotion_Fleet2Value
439+ else :
440+ return self .campaign .config .Emotion_Fleet1Value
441+
454442 def set_emotion (self , emotion ):
455443 if self .config .Fleet_FleetOrder == 'fleet1_standby_fleet2_all' :
456444 self .campaign .config .set_record (Emotion_Fleet2Value = emotion )
@@ -474,23 +462,19 @@ def run(self, name, folder='campaign_main', mode='normal', total=0):
474462 try :
475463 super ().run (name = name , folder = folder , total = total )
476464 except CampaignEnd as e :
477- if e .args [0 ] == 'Emotion withdraw' :
465+ if e .args [0 ] in [ 'Emotion withdraw' , 'Emotion control' ] :
478466 self ._trigger_emotion = True
479467 else :
480468 raise e
481469
482470 # End
483471 if self ._trigger_lv32 or self ._trigger_emotion :
484472 success = True
485- self ._new_emotion = 200 # magic value to exceed 150
486473 if self .change_flagship :
487474 success = self .flagship_change ()
488475 if self .change_vanguard :
489476 success = success and self .vanguard_change ()
490477
491- if self ._new_emotion < 200 :
492- self .set_emotion (self ._new_emotion )
493-
494478 if is_limit and self .config .StopCondition_RunCount <= 0 :
495479 logger .hr ('Triggered stop condition: Run count' )
496480 self .config .StopCondition_RunCount = 0
0 commit comments