Skip to content

Commit 1f14d98

Browse files
committed
Add: control emotion in gemsfarming
1 parent fdd2c19 commit 1f14d98

File tree

5 files changed

+181
-5
lines changed

5 files changed

+181
-5
lines changed

config/template.json

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -344,6 +344,19 @@
344344
"Fleet2Step": 2,
345345
"FleetOrder": "fleet1_all_fleet2_standby"
346346
},
347+
"Emotion": {
348+
"Mode": "calculate_ignore",
349+
"Fleet1Value": 119,
350+
"Fleet1Record": "2020-01-01 00:00:00",
351+
"Fleet1Control": "prevent_red_face",
352+
"Fleet1Recover": "not_in_dormitory",
353+
"Fleet1Oath": false,
354+
"Fleet2Value": 119,
355+
"Fleet2Record": "2020-01-01 00:00:00",
356+
"Fleet2Control": "prevent_red_face",
357+
"Fleet2Recover": "not_in_dormitory",
358+
"Fleet2Oath": false
359+
},
347360
"Storage": {
348361
"Storage": {}
349362
}

module/campaign/gems_farming.py

Lines changed: 75 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,12 @@
1+
from cached_property import cached_property
2+
from datetime import datetime
3+
4+
import numpy as np
5+
16
from module.campaign.campaign_base import CampaignBase
27
from module.campaign.run import CampaignRun
38
from module.combat.assets import BATTLE_PREPARATION
9+
from module.combat.emotion import Emotion
410
from module.equipment.assets import *
511
from module.equipment.fleet_equipment import FleetEquipment
612
from module.exception import CampaignEnd, ScriptError
@@ -22,6 +28,48 @@
2228
SIM_VALUE = 0.92
2329

2430

31+
class GemsEmotion(Emotion):
32+
33+
def check_reduce(self, battle):
34+
"""
35+
Overwrite emotion.check_reduce()
36+
Check emotion before entering a campaign.
37+
38+
Args:
39+
battle (int): Battles in this campaign
40+
41+
Raise:
42+
CampaignEnd: Pause current task to prevent emotion control in the future.
43+
"""
44+
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')
68+
69+
def wait(self, fleet_index):
70+
pass
71+
72+
2573
class GemsCampaignOverride(CampaignBase):
2674

2775
def handle_combat_low_emotion(self):
@@ -73,10 +121,16 @@ def load_campaign(self, name, folder='campaign_main'):
73121
super().load_campaign(name, folder)
74122

75123
class GemsCampaign(GemsCampaignOverride, self.module.Campaign):
76-
pass
124+
125+
@cached_property
126+
def emotion(self) -> GemsEmotion:
127+
return GemsEmotion(config=self.config)
77128

78129
self.campaign = GemsCampaign(device=self.campaign.device, config=self.campaign.config)
79-
self.campaign.config.override(Emotion_Mode='ignore')
130+
if self.change_flagship or self.change_vanguard:
131+
self.campaign.config.override(Emotion_Mode='ignore_calculate')
132+
else:
133+
self.campaign.config.override(Emotion_Mode='ignore')
80134
self.campaign.config.override(EnemyPriority_EnemyScaleBalanceWeight='S1_enemy_first')
81135

82136
@property
@@ -308,6 +362,8 @@ def get_templates(common_dd):
308362
logger.error(f'Invalid CommonDD setting: {common_dd}')
309363
raise ScriptError(f'Invalid CommonDD setting: {common_dd}')
310364

365+
_new_emotion: int
366+
311367
def flagship_change_execute(self):
312368
"""
313369
Returns:
@@ -325,7 +381,9 @@ def flagship_change_execute(self):
325381

326382
ship = self.get_common_rarity_cv()
327383
if ship:
328-
self._ship_change_confirm(min(ship, key=lambda s: (s.level, -s.emotion)).button)
384+
target_ship = min(ship, key=lambda s: (s.level, -s.emotion))
385+
self._new_emotion = target_ship.emotion
386+
self._ship_change_confirm(target_ship.button)
329387

330388
logger.info('Change flagship success')
331389
return True
@@ -364,7 +422,9 @@ def vanguard_change_execute(self):
364422

365423
ship = self.get_common_rarity_dd()
366424
if ship:
367-
self._ship_change_confirm(max(ship, key=lambda s: s.emotion).button)
425+
target_ship = max(ship, key=lambda s: s.emotion)
426+
self._new_emotion = min(self._new_emotion, target_ship.emotion)
427+
self._ship_change_confirm(target_ship.button)
368428

369429
logger.info('Change vanguard ship success')
370430
return True
@@ -384,13 +444,19 @@ def triggered_stop_condition(self, oil_check=True):
384444
logger.hr('TRIGGERED LV32 LIMIT')
385445
return True
386446

387-
if self.campaign.map_is_auto_search and self.campaign.config.GEMS_EMOTION_TRIGGRED:
447+
if self.campaign.config.GEMS_EMOTION_TRIGGRED:
388448
self._trigger_emotion = True
389449
logger.hr('TRIGGERED EMOTION LIMIT')
390450
return True
391451

392452
return super().triggered_stop_condition(oil_check=oil_check)
393453

454+
def set_emotion(self, emotion):
455+
if self.config.Fleet_FleetOrder == 'fleet1_standby_fleet2_all':
456+
self.campaign.config.set_record(Emotion_Fleet2Value=emotion)
457+
else:
458+
self.campaign.config.set_record(Emotion_Fleet1Value=emotion)
459+
394460
def run(self, name, folder='campaign_main', mode='normal', total=0):
395461
"""
396462
Args:
@@ -416,11 +482,15 @@ def run(self, name, folder='campaign_main', mode='normal', total=0):
416482
# End
417483
if self._trigger_lv32 or self._trigger_emotion:
418484
success = True
485+
self._new_emotion = 200 # magic value to exceed 150
419486
if self.change_flagship:
420487
success = self.flagship_change()
421488
if self.change_vanguard:
422489
success = success and self.vanguard_change()
423490

491+
if self._new_emotion < 200:
492+
self.set_emotion(self._new_emotion)
493+
424494
if is_limit and self.config.StopCondition_RunCount <= 0:
425495
logger.hr('Triggered stop condition: Run count')
426496
self.config.StopCondition_RunCount = 0

module/config/argument/args.json

Lines changed: 84 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1883,6 +1883,90 @@
18831883
"display": "display"
18841884
}
18851885
},
1886+
"Emotion": {
1887+
"Mode": {
1888+
"type": "select",
1889+
"value": "calculate_ignore",
1890+
"option": [
1891+
"calculate",
1892+
"ignore",
1893+
"calculate_ignore"
1894+
],
1895+
"display": "hide"
1896+
},
1897+
"Fleet1Value": {
1898+
"type": "input",
1899+
"value": 119
1900+
},
1901+
"Fleet1Record": {
1902+
"type": "datetime",
1903+
"value": "2020-01-01 00:00:00",
1904+
"validate": "datetime",
1905+
"display": "disabled"
1906+
},
1907+
"Fleet1Control": {
1908+
"type": "select",
1909+
"value": "prevent_red_face",
1910+
"option": [
1911+
"keep_exp_bonus",
1912+
"prevent_green_face",
1913+
"prevent_yellow_face",
1914+
"prevent_red_face"
1915+
],
1916+
"display": "hide"
1917+
},
1918+
"Fleet1Recover": {
1919+
"type": "select",
1920+
"value": "not_in_dormitory",
1921+
"option": [
1922+
"not_in_dormitory",
1923+
"dormitory_floor_1",
1924+
"dormitory_floor_2"
1925+
],
1926+
"display": "hide"
1927+
},
1928+
"Fleet1Oath": {
1929+
"type": "checkbox",
1930+
"value": false,
1931+
"display": "hide"
1932+
},
1933+
"Fleet2Value": {
1934+
"type": "input",
1935+
"value": 119
1936+
},
1937+
"Fleet2Record": {
1938+
"type": "datetime",
1939+
"value": "2020-01-01 00:00:00",
1940+
"validate": "datetime",
1941+
"display": "disabled"
1942+
},
1943+
"Fleet2Control": {
1944+
"type": "select",
1945+
"value": "prevent_red_face",
1946+
"option": [
1947+
"keep_exp_bonus",
1948+
"prevent_green_face",
1949+
"prevent_yellow_face",
1950+
"prevent_red_face"
1951+
],
1952+
"display": "hide"
1953+
},
1954+
"Fleet2Recover": {
1955+
"type": "select",
1956+
"value": "not_in_dormitory",
1957+
"option": [
1958+
"not_in_dormitory",
1959+
"dormitory_floor_1",
1960+
"dormitory_floor_2"
1961+
],
1962+
"display": "hide"
1963+
},
1964+
"Fleet2Oath": {
1965+
"type": "checkbox",
1966+
"value": false,
1967+
"display": "hide"
1968+
}
1969+
},
18861970
"Storage": {
18871971
"Storage": {
18881972
"type": "storage",

module/config/argument/override.yaml

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,14 @@ GemsFarming:
4646
display: display
4747
value: fleet1_all_fleet2_standby
4848
option: [ fleet1_all_fleet2_standby, fleet1_standby_fleet2_all ]
49+
Emotion:
50+
Mode: calculate_ignore
51+
Fleet1Control: prevent_red_face
52+
Fleet1Recover: not_in_dormitory
53+
Fleet1Oath: false
54+
Fleet2Control: prevent_red_face
55+
Fleet2Recover: not_in_dormitory
56+
Fleet2Oath: false
4957

5058
# ==================== Event ====================
5159

module/config/argument/task.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,7 @@ Farm:
6161
- Campaign
6262
- StopCondition
6363
- Fleet
64+
- Emotion
6465

6566
# ==================== Event ====================
6667

0 commit comments

Comments
 (0)