|
| 1 | +from module.base.decorator import cached_property |
1 | 2 | from module.campaign.campaign_base import CampaignBase |
2 | 3 | from module.campaign.run import CampaignRun |
3 | 4 | from module.combat.assets import BATTLE_PREPARATION |
| 5 | +from module.combat.emotion import Emotion |
4 | 6 | from module.equipment.assets import * |
5 | 7 | from module.equipment.fleet_equipment import FleetEquipment |
6 | 8 | from module.exception import CampaignEnd, ScriptError |
|
22 | 24 | SIM_VALUE = 0.92 |
23 | 25 |
|
24 | 26 |
|
| 27 | +class GemsEmotion(Emotion): |
| 28 | + |
| 29 | + def check_reduce(self, battle): |
| 30 | + """ |
| 31 | + Overwrite emotion.check_reduce() |
| 32 | + Check emotion before entering a campaign. |
| 33 | +
|
| 34 | + Args: |
| 35 | + battle (int): Battles in this campaign |
| 36 | +
|
| 37 | + Raise: |
| 38 | + CampaignEnd: Pause current task to prevent emotion control in the future. |
| 39 | + """ |
| 40 | + if not self.is_calculate: |
| 41 | + return |
| 42 | + |
| 43 | + recovered, delay = self._check_reduce(battle) |
| 44 | + if delay: |
| 45 | + self.config.GEMS_EMOTION_TRIGGERED = True |
| 46 | + logger.info('Detect low emotion, pause current task') |
| 47 | + raise CampaignEnd('Emotion control') |
| 48 | + |
| 49 | + def wait(self, fleet_index): |
| 50 | + pass |
| 51 | + |
| 52 | + |
25 | 53 | class GemsCampaignOverride(CampaignBase): |
26 | 54 |
|
27 | 55 | def handle_combat_low_emotion(self): |
@@ -73,12 +101,30 @@ def load_campaign(self, name, folder='campaign_main'): |
73 | 101 | super().load_campaign(name, folder) |
74 | 102 |
|
75 | 103 | class GemsCampaign(GemsCampaignOverride, self.module.Campaign): |
76 | | - pass |
| 104 | + @cached_property |
| 105 | + def emotion(self) -> GemsEmotion: |
| 106 | + return GemsEmotion(config=self.config) |
77 | 107 |
|
78 | 108 | self.campaign = GemsCampaign(device=self.campaign.device, config=self.campaign.config) |
79 | | - self.campaign.config.override(Emotion_Mode='ignore') |
| 109 | + self.campaign.config.override(Emotion_Mode='ignore_calculate') |
80 | 110 | self.campaign.config.override(EnemyPriority_EnemyScaleBalanceWeight='S1_enemy_first') |
81 | 111 |
|
| 112 | + @property |
| 113 | + def emotion_lower_bound(self): |
| 114 | + return 4 + self.campaign._map_battle * 2 |
| 115 | + |
| 116 | + def get_emotion(self): |
| 117 | + if self.config.Fleet_FleetOrder == 'fleet1_standby_fleet2_all': |
| 118 | + return self.campaign.config.Emotion_Fleet2Value |
| 119 | + else: |
| 120 | + return self.campaign.config.Emotion_Fleet1Value |
| 121 | + |
| 122 | + def set_emotion(self, emotion): |
| 123 | + if self.config.Fleet_FleetOrder == 'fleet1_standby_fleet2_all': |
| 124 | + self.campaign.config.set_record(Emotion_Fleet2Value=emotion) |
| 125 | + else: |
| 126 | + self.campaign.config.set_record(Emotion_Fleet1Value=emotion) |
| 127 | + |
82 | 128 | @property |
83 | 129 | def change_vanguard(self): |
84 | 130 | return 'ship' in self.config.GemsFarming_ChangeVanguard |
@@ -150,7 +196,7 @@ def get_common_rarity_cv(self): |
150 | 196 |
|
151 | 197 | logger.hr('FINDING FLAGSHIP') |
152 | 198 |
|
153 | | - scanner = ShipScanner(level=(1, 31), emotion=(10, 150), |
| 199 | + scanner = ShipScanner(level=(1, 31), emotion=(self.emotion_lower_bound, 150), |
154 | 200 | fleet=self.fleet_to_attack, status='free') |
155 | 201 | scanner.disable('rarity') |
156 | 202 |
|
@@ -196,7 +242,7 @@ def get_common_rarity_cv(self): |
196 | 242 |
|
197 | 243 | def get_common_rarity_dd(self): |
198 | 244 | """ |
199 | | - Get a common rarity dd with level is 100 (70 for servers except CN) and emotion > 10 |
| 245 | + Get a common rarity dd with level is 100 (70 for servers except CN) and emotion > self.emotion_lower_bound |
200 | 246 |
|
201 | 247 | _dock_reset() needs to be called later. |
202 | 248 |
|
@@ -228,7 +274,7 @@ def get_common_rarity_dd(self): |
228 | 274 | else: |
229 | 275 | max_level = 70 |
230 | 276 |
|
231 | | - scanner = ShipScanner(level=(max_level, max_level), emotion=(10, 150), |
| 277 | + scanner = ShipScanner(level=(max_level, max_level), emotion=(self.emotion_lower_bound, 150), |
232 | 278 | fleet=[0, self.fleet_to_attack], status='free') |
233 | 279 | scanner.disable('rarity') |
234 | 280 |
|
@@ -301,8 +347,9 @@ def flagship_change_execute(self): |
301 | 347 |
|
302 | 348 | ship = self.get_common_rarity_cv() |
303 | 349 | if ship: |
304 | | - self._ship_change_confirm(min(ship, key=lambda s: (s.level, -s.emotion)).button) |
305 | | - |
| 350 | + target_ship = min(ship, key=lambda s: (s.level, -s.emotion)) |
| 351 | + self.set_emotion(target_ship.emotion) |
| 352 | + self._ship_change_confirm(target_ship.button) |
306 | 353 | logger.info('Change flagship success') |
307 | 354 | return True |
308 | 355 | else: |
@@ -332,12 +379,14 @@ def vanguard_change_execute(self): |
332 | 379 |
|
333 | 380 | ship = self.get_common_rarity_dd() |
334 | 381 | if ship: |
335 | | - self._ship_change_confirm(max(ship, key=lambda s: s.emotion).button) |
336 | | - |
| 382 | + target_ship = max(ship, key=lambda s: s.emotion) |
| 383 | + self.set_emotion(min(self.get_emotion(), target_ship.emotion)) |
| 384 | + self._ship_change_confirm(target_ship.button) |
337 | 385 | logger.info('Change vanguard ship success') |
338 | 386 | return True |
339 | 387 | else: |
340 | 388 | logger.info('Change vanguard ship failed, no DD in common rarity.') |
| 389 | + self.set_emotion(0) # a failure in vanguard change means low emotion DD, assuming 0. |
341 | 390 | self._dock_reset() |
342 | 391 | self.ui_back(check_button=page_fleet.check_button) |
343 | 392 | return False |
@@ -376,7 +425,7 @@ def run(self, name, folder='campaign_main', mode='normal', total=0): |
376 | 425 | try: |
377 | 426 | super().run(name=name, folder=folder, total=total) |
378 | 427 | except CampaignEnd as e: |
379 | | - if e.args[0] == 'Emotion withdraw': |
| 428 | + if e.args[0] in ['Emotion withdraw', 'Emotion control']: |
380 | 429 | self._trigger_emotion = True |
381 | 430 | else: |
382 | 431 | raise e |
|
0 commit comments