|
| 1 | +from module.base.utils import location2node |
| 2 | +from module.exception import RequestHumanTakeover, ScriptError |
| 3 | +from .campaign_base import CampaignBase |
| 4 | +from .config_base import ConfigBase |
| 5 | +from module.map.map_base import CampaignMap |
| 6 | +from module.map.map_grids import SelectedGrids, RoadGrids |
| 7 | +from module.logger import logger |
| 8 | + |
| 9 | +MAP = CampaignMap('SP') |
| 10 | +MAP.shape = 'J8' |
| 11 | + |
| 12 | +MAP.camera_data_spawn_point = ['E6'] |
| 13 | +MAP.map_data = """ |
| 14 | + ++ ++ ++ ME ME ME ME ++ ++ ++ |
| 15 | + ++ ME ME ME ME ME ME ME ME ++ |
| 16 | + ME ME ME ME ++ ++ ME ME ME ME |
| 17 | + ME ME ME ME ++ ++ ME ME ME ME |
| 18 | + ME ME ME ME MB MB ME ME ME ME |
| 19 | + ME ++ ME ME __ __ ME ME ++ ME |
| 20 | + ME ++ ME ME ME ME ME ME ++ ME |
| 21 | + ME ME ME ME SP SP ME ME ME ME |
| 22 | +""" |
| 23 | +MAP.weight_data = """ |
| 24 | + 50 50 50 50 50 50 50 50 50 50 |
| 25 | + 50 50 50 50 50 50 50 50 50 50 |
| 26 | + 50 50 50 50 50 50 50 50 50 50 |
| 27 | + 50 50 50 50 50 50 50 50 50 50 |
| 28 | + 50 50 50 50 50 50 50 50 50 50 |
| 29 | + 50 50 50 50 50 50 50 50 50 50 |
| 30 | + 50 50 50 50 50 50 50 50 50 50 |
| 31 | + 50 50 50 50 50 50 50 50 50 50 |
| 32 | +""" |
| 33 | +MAP.spawn_data = [ |
| 34 | + {'battle': 0, 'siren': 4}, |
| 35 | + {'battle': 1}, |
| 36 | + {'battle': 2}, |
| 37 | + {'battle': 3}, |
| 38 | + {'battle': 4, 'enemy': 14}, |
| 39 | + {'battle': 5}, |
| 40 | + {'battle': 6}, |
| 41 | + {'battle': 7, 'boss': 1}, |
| 42 | +] |
| 43 | +A1, B1, C1, D1, E1, F1, G1, H1, I1, J1, \ |
| 44 | +A2, B2, C2, D2, E2, F2, G2, H2, I2, J2, \ |
| 45 | +A3, B3, C3, D3, E3, F3, G3, H3, I3, J3, \ |
| 46 | +A4, B4, C4, D4, E4, F4, G4, H4, I4, J4, \ |
| 47 | +A5, B5, C5, D5, E5, F5, G5, H5, I5, J5, \ |
| 48 | +A6, B6, C6, D6, E6, F6, G6, H6, I6, J6, \ |
| 49 | +A7, B7, C7, D7, E7, F7, G7, H7, I7, J7, \ |
| 50 | +A8, B8, C8, D8, E8, F8, G8, H8, I8, J8, \ |
| 51 | + = MAP.flatten() |
| 52 | + |
| 53 | + |
| 54 | +class Config(ConfigBase): |
| 55 | + # ===== Start of generated config ===== |
| 56 | + MAP_HAS_SIREN = False |
| 57 | + MAP_HAS_MOVABLE_ENEMY = False |
| 58 | + MAP_HAS_MOVABLE_NORMAL_ENEMY = False |
| 59 | + MAP_HAS_MAP_STORY = True |
| 60 | + MAP_HAS_FLEET_STEP = True |
| 61 | + MAP_HAS_AMBUSH = False |
| 62 | + MAP_HAS_MYSTERY = False |
| 63 | + STAR_REQUIRE_1 = 0 |
| 64 | + STAR_REQUIRE_2 = 0 |
| 65 | + STAR_REQUIRE_3 = 0 |
| 66 | + # ===== End of generated config ===== |
| 67 | + |
| 68 | + MAP_IS_ONE_TIME_STAGE = True |
| 69 | + |
| 70 | + |
| 71 | +# hard to find a dynamic solution |
| 72 | +# therefore overwrite all MAP girds with ME |
| 73 | +# and use a serial of static actions |
| 74 | +actions = { |
| 75 | + 4: [ |
| 76 | + ['1_R_2_', '1_L_2_', '1_R_2_B'], |
| 77 | + ['2_U_2_', '1_S_0_B'], |
| 78 | + ['1_L_1_B'], |
| 79 | + ['1_U_1_B'], |
| 80 | + ['1_U_2_', '1_R_1_B'], |
| 81 | + ['1_L_2_', '1_L_1_B'], |
| 82 | + ['1_R_2_', '1_R_1_B'] |
| 83 | + ], |
| 84 | + 5: [ |
| 85 | + ['1_L_2_', '1_R_2_', '1_L_2_B'], |
| 86 | + ['2_U_2_', '1_S_0_B'], |
| 87 | + ['1_RU_2_', '1_RU_2_B'], |
| 88 | + ['1_RD_2_B'], |
| 89 | + ['1_U_2_B'], |
| 90 | + ['1_L_2_', '1_L_1_B'], |
| 91 | + ['1_R_2_', '1_L_2_B'] |
| 92 | + ] |
| 93 | +} |
| 94 | + |
| 95 | + |
| 96 | +def parse_move(movement: str, step: int): |
| 97 | + if step % len(movement) != 0: |
| 98 | + raise ScriptError('Invalid movement') |
| 99 | + |
| 100 | + movement = movement * int(step / len(movement)) |
| 101 | + dx, dy = 0, 0 |
| 102 | + for direction in movement: |
| 103 | + dx += 1 if direction == 'R' else 0 |
| 104 | + dx -= 1 if direction == 'L' else 0 |
| 105 | + dy += 1 if direction == 'D' else 0 |
| 106 | + dy -= 1 if direction == 'U' else 0 |
| 107 | + return dx, dy |
| 108 | + |
| 109 | + |
| 110 | +class Campaign(CampaignBase): |
| 111 | + MAP = MAP |
| 112 | + ENEMY_FILTER = '1L > 1M > 1E > 1C > 2L > 2M > 2E > 2C > 3L > 3M > 3E > 3C' |
| 113 | + |
| 114 | + def execute_actions(self, step): |
| 115 | + for action in self.action[step]: |
| 116 | + fleet_index, movement, step, battle = action.split('_') |
| 117 | + src = self.__getattribute__(f'fleet_{fleet_index}_location') |
| 118 | + fleet = self.__getattribute__(f'fleet_{fleet_index}') |
| 119 | + step = int(step) |
| 120 | + dx, dy = parse_move(movement, step) |
| 121 | + dst = (src[0] + dx, src[1] + dy) |
| 122 | + |
| 123 | + logger.info(f'{fleet_index}{movement}({step}): {src} -> {dst}') |
| 124 | + |
| 125 | + for _ in range(3): |
| 126 | + if battle: |
| 127 | + fleet.clear_chosen_enemy(location2node(dst)) |
| 128 | + else: |
| 129 | + fleet.goto(location2node(dst)) |
| 130 | + |
| 131 | + fleet_location = self.__getattribute__(f'fleet_{fleet_index}_location') |
| 132 | + if fleet_location not in [src, dst]: |
| 133 | + raise RequestHumanTakeover( |
| 134 | + f'Fleet{fleet_index} fail to move {src} -> {dst}, now on {fleet_location}') |
| 135 | + elif fleet_location == dst: |
| 136 | + break |
| 137 | + else: |
| 138 | + logger.warning(f'Fleet{fleet_index} did not move, retry') |
| 139 | + |
| 140 | + return True |
| 141 | + |
| 142 | + def battle_0(self): |
| 143 | + self.action = actions[self.fleet_1_location[0]] |
| 144 | + return self.execute_actions(0) |
| 145 | + |
| 146 | + def battle_1(self): |
| 147 | + return self.execute_actions(1) |
| 148 | + |
| 149 | + def battle_2(self): |
| 150 | + return self.execute_actions(2) |
| 151 | + |
| 152 | + def battle_3(self): |
| 153 | + return self.execute_actions(3) |
| 154 | + |
| 155 | + def battle_4(self): |
| 156 | + return self.execute_actions(4) |
| 157 | + |
| 158 | + def battle_5(self): |
| 159 | + return self.execute_actions(5) |
| 160 | + |
| 161 | + def battle_6(self): |
| 162 | + return self.execute_actions(6) |
| 163 | + |
| 164 | + def battle_7(self): |
| 165 | + return self.fleet_boss.clear_boss() |
0 commit comments