Skip to content

Commit

Permalink
Add: control emotion in gemsfarming
Browse files Browse the repository at this point in the history
  • Loading branch information
guoh064 committed Aug 7, 2024
1 parent fdd2c19 commit 1f14d98
Show file tree
Hide file tree
Showing 5 changed files with 181 additions and 5 deletions.
13 changes: 13 additions & 0 deletions config/template.json
Original file line number Diff line number Diff line change
Expand Up @@ -344,6 +344,19 @@
"Fleet2Step": 2,
"FleetOrder": "fleet1_all_fleet2_standby"
},
"Emotion": {
"Mode": "calculate_ignore",
"Fleet1Value": 119,
"Fleet1Record": "2020-01-01 00:00:00",
"Fleet1Control": "prevent_red_face",
"Fleet1Recover": "not_in_dormitory",
"Fleet1Oath": false,
"Fleet2Value": 119,
"Fleet2Record": "2020-01-01 00:00:00",
"Fleet2Control": "prevent_red_face",
"Fleet2Recover": "not_in_dormitory",
"Fleet2Oath": false
},
"Storage": {
"Storage": {}
}
Expand Down
80 changes: 75 additions & 5 deletions module/campaign/gems_farming.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,12 @@
from cached_property import cached_property
from datetime import datetime

import numpy as np

from module.campaign.campaign_base import CampaignBase
from module.campaign.run import CampaignRun
from module.combat.assets import BATTLE_PREPARATION
from module.combat.emotion import Emotion
from module.equipment.assets import *
from module.equipment.fleet_equipment import FleetEquipment
from module.exception import CampaignEnd, ScriptError
Expand All @@ -22,6 +28,48 @@
SIM_VALUE = 0.92


class GemsEmotion(Emotion):

def check_reduce(self, battle):
"""
Overwrite emotion.check_reduce()
Check emotion before entering a campaign.
Args:
battle (int): Battles in this campaign
Raise:
CampaignEnd: Pause current task to prevent emotion control in the future.
"""

if not self.is_calculate:
return

method = self.config.Fleet_FleetOrder

if method == 'fleet1_all_fleet2_standby':
battle = (battle, 0)
elif method == 'fleet1_standby_fleet2_all':
battle = (0, battle)
else:
raise ScriptError(f'Unknown fleet order: {method}')

battle = tuple(np.array(battle) * self.reduce_per_battle_before_entering)
logger.info(f'Expect emotion reduce: {battle}')

self.update()
self.record()
self.show()
recovered = max([f.get_recovered(b) for f, b in zip(self.fleets, battle)])
if recovered > datetime.now():
logger.info('Delay current task to prevent emotion control in the future')
self.config.GEMS_EMOTION_TRIGGRED = True
raise CampaignEnd('Emotion withdraw')

def wait(self, fleet_index):
pass


class GemsCampaignOverride(CampaignBase):

def handle_combat_low_emotion(self):
Expand Down Expand Up @@ -73,10 +121,16 @@ def load_campaign(self, name, folder='campaign_main'):
super().load_campaign(name, folder)

class GemsCampaign(GemsCampaignOverride, self.module.Campaign):
pass

@cached_property
def emotion(self) -> GemsEmotion:
return GemsEmotion(config=self.config)

self.campaign = GemsCampaign(device=self.campaign.device, config=self.campaign.config)
self.campaign.config.override(Emotion_Mode='ignore')
if self.change_flagship or self.change_vanguard:
self.campaign.config.override(Emotion_Mode='ignore_calculate')
else:
self.campaign.config.override(Emotion_Mode='ignore')
self.campaign.config.override(EnemyPriority_EnemyScaleBalanceWeight='S1_enemy_first')

@property
Expand Down Expand Up @@ -308,6 +362,8 @@ def get_templates(common_dd):
logger.error(f'Invalid CommonDD setting: {common_dd}')
raise ScriptError(f'Invalid CommonDD setting: {common_dd}')

_new_emotion: int

def flagship_change_execute(self):
"""
Returns:
Expand All @@ -325,7 +381,9 @@ def flagship_change_execute(self):

ship = self.get_common_rarity_cv()
if ship:
self._ship_change_confirm(min(ship, key=lambda s: (s.level, -s.emotion)).button)
target_ship = min(ship, key=lambda s: (s.level, -s.emotion))
self._new_emotion = target_ship.emotion
self._ship_change_confirm(target_ship.button)

logger.info('Change flagship success')
return True
Expand Down Expand Up @@ -364,7 +422,9 @@ def vanguard_change_execute(self):

ship = self.get_common_rarity_dd()
if ship:
self._ship_change_confirm(max(ship, key=lambda s: s.emotion).button)
target_ship = max(ship, key=lambda s: s.emotion)
self._new_emotion = min(self._new_emotion, target_ship.emotion)
self._ship_change_confirm(target_ship.button)

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

if self.campaign.map_is_auto_search and self.campaign.config.GEMS_EMOTION_TRIGGRED:
if self.campaign.config.GEMS_EMOTION_TRIGGRED:
self._trigger_emotion = True
logger.hr('TRIGGERED EMOTION LIMIT')
return True

return super().triggered_stop_condition(oil_check=oil_check)

def set_emotion(self, emotion):
if self.config.Fleet_FleetOrder == 'fleet1_standby_fleet2_all':
self.campaign.config.set_record(Emotion_Fleet2Value=emotion)
else:
self.campaign.config.set_record(Emotion_Fleet1Value=emotion)

def run(self, name, folder='campaign_main', mode='normal', total=0):
"""
Args:
Expand All @@ -416,11 +482,15 @@ def run(self, name, folder='campaign_main', mode='normal', total=0):
# End
if self._trigger_lv32 or self._trigger_emotion:
success = True
self._new_emotion = 200 # magic value to exceed 150
if self.change_flagship:
success = self.flagship_change()
if self.change_vanguard:
success = success and self.vanguard_change()

if self._new_emotion < 200:
self.set_emotion(self._new_emotion)

if is_limit and self.config.StopCondition_RunCount <= 0:
logger.hr('Triggered stop condition: Run count')
self.config.StopCondition_RunCount = 0
Expand Down
84 changes: 84 additions & 0 deletions module/config/argument/args.json
Original file line number Diff line number Diff line change
Expand Up @@ -1883,6 +1883,90 @@
"display": "display"
}
},
"Emotion": {
"Mode": {
"type": "select",
"value": "calculate_ignore",
"option": [
"calculate",
"ignore",
"calculate_ignore"
],
"display": "hide"
},
"Fleet1Value": {
"type": "input",
"value": 119
},
"Fleet1Record": {
"type": "datetime",
"value": "2020-01-01 00:00:00",
"validate": "datetime",
"display": "disabled"
},
"Fleet1Control": {
"type": "select",
"value": "prevent_red_face",
"option": [
"keep_exp_bonus",
"prevent_green_face",
"prevent_yellow_face",
"prevent_red_face"
],
"display": "hide"
},
"Fleet1Recover": {
"type": "select",
"value": "not_in_dormitory",
"option": [
"not_in_dormitory",
"dormitory_floor_1",
"dormitory_floor_2"
],
"display": "hide"
},
"Fleet1Oath": {
"type": "checkbox",
"value": false,
"display": "hide"
},
"Fleet2Value": {
"type": "input",
"value": 119
},
"Fleet2Record": {
"type": "datetime",
"value": "2020-01-01 00:00:00",
"validate": "datetime",
"display": "disabled"
},
"Fleet2Control": {
"type": "select",
"value": "prevent_red_face",
"option": [
"keep_exp_bonus",
"prevent_green_face",
"prevent_yellow_face",
"prevent_red_face"
],
"display": "hide"
},
"Fleet2Recover": {
"type": "select",
"value": "not_in_dormitory",
"option": [
"not_in_dormitory",
"dormitory_floor_1",
"dormitory_floor_2"
],
"display": "hide"
},
"Fleet2Oath": {
"type": "checkbox",
"value": false,
"display": "hide"
}
},
"Storage": {
"Storage": {
"type": "storage",
Expand Down
8 changes: 8 additions & 0 deletions module/config/argument/override.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,14 @@ GemsFarming:
display: display
value: fleet1_all_fleet2_standby
option: [ fleet1_all_fleet2_standby, fleet1_standby_fleet2_all ]
Emotion:
Mode: calculate_ignore
Fleet1Control: prevent_red_face
Fleet1Recover: not_in_dormitory
Fleet1Oath: false
Fleet2Control: prevent_red_face
Fleet2Recover: not_in_dormitory
Fleet2Oath: false

# ==================== Event ====================

Expand Down
1 change: 1 addition & 0 deletions module/config/argument/task.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ Farm:
- Campaign
- StopCondition
- Fleet
- Emotion

# ==================== Event ====================

Expand Down

0 comments on commit 1f14d98

Please sign in to comment.