Skip to content

Commit d42cbd7

Browse files
authored
Merge pull request #290 from coderwilson/coder_nem_4
Attack soft-lock fix
2 parents 9da4ece + 7601b1c commit d42cbd7

File tree

7 files changed

+63
-12
lines changed

7 files changed

+63
-12
lines changed

Diff for: area/kilika.py

+11-5
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,8 @@ def select_best_of_two(coming_battles):
9292
def forest_1():
9393
logger.info("Kilika forest 1")
9494
kilika_battles = 0
95+
best_of_two = 99 # Used to find the best battle coming up.
96+
advances = 2 # Used to find the best battle coming up.
9597
next_battle = []
9698
import rng_track
9799

@@ -117,7 +119,6 @@ def forest_1():
117119
checkpoint = 83
118120
if checkpoint == 83 and not valefor_charge:
119121
checkpoint = 81
120-
best_of_two = 99
121122
if checkpoint == 83 and memory.main.get_map() == 65:
122123
checkpoint = 84
123124
if checkpoint == 37 and game_vars.skip_kilika_luck():
@@ -158,10 +159,15 @@ def forest_1():
158159
if memory.main.battle_active():
159160
if checkpoint < 9:
160161
battle.main.lancet_tutorial()
161-
next_two = rng_track.coming_battles(
162-
area="kilika_woods", battle_count=2
163-
)
164-
best_of_two = select_best_of_two(next_two)
162+
while best_of_two == 99:
163+
next_two = rng_track.coming_battles(
164+
area="kilika_woods", battle_count=advances
165+
)
166+
best_of_two = select_best_of_two(next_two)
167+
advances += 1
168+
if advances > 150:
169+
logger.error("No valid battles in the next 150.")
170+
break
165171
next_battle = rng_track.coming_battles(
166172
area="kilika_woods", battle_count=1
167173
)[0]

Diff for: battle/boss.py

+4-1
Original file line numberDiff line numberDiff line change
@@ -301,12 +301,15 @@ def sin_fin():
301301
logger.debug("Tidus defend")
302302
elif Yuna.is_turn():
303303
battle.main.buddy_swap(Lulu) # Yuna out, Lulu in
304-
CurrentPlayer().cast_black_magic_spell(1, target_id=23, direction="r")
305304
elif Kimahri.is_turn():
306305
battle.main.lancet_target(target=23, direction="r")
307306
kim_turn = True
308307
elif Lulu.is_turn():
309308
CurrentPlayer().cast_black_magic_spell(1, target_id=23, direction="r")
309+
elif not 5 in memory.main.get_active_battle_formation():
310+
battle.main.buddy_swap(Lulu)
311+
elif not 3 in memory.main.get_active_battle_formation():
312+
battle.main.buddy_swap(Kimahri)
310313
else:
311314
CurrentPlayer().defend()
312315
if fin_turns >= 3 and kim_turn:

Diff for: battle/main.py

+4-2
Original file line numberDiff line numberDiff line change
@@ -420,9 +420,11 @@ def kilika_woods(valefor_charge=True, best_charge: int = 99, next_battle=[]):
420420
elif screen.faint_check():
421421
revive()
422422
elif Kimahri.is_turn() or Lulu.is_turn():
423-
if memory.main.get_battle_char_slot(4) >= 3:
423+
if not 1 in memory.main.get_active_battle_formation():
424+
buddy_swap(Yuna)
425+
elif not 4 in memory.main.get_active_battle_formation():
424426
buddy_swap(Wakka)
425-
elif memory.main.get_battle_char_slot(0) >= 3:
427+
elif not 0 in memory.main.get_active_battle_formation():
426428
buddy_swap(Tidus)
427429
else:
428430
buddy_swap(Yuna)

Diff for: json_ai_files/save_load_details.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@
6565
"end_game_version_val": "0",
6666
"nea_zone": "0",
6767
"nem_ap_val": "1",
68-
"special_movement": "none"
68+
"special_movement": "Kilika_rng_manip"
6969
}
7070
}
7171
},

Diff for: load_game.py

+24
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,8 @@ def move_after_load(spec_move: str):
3434
load_miihen_start()
3535
elif spec_move == "MRR":
3636
load_mrr()
37+
elif spec_move == "Kilika_rng_manip":
38+
kilika_rng_manip()
3739

3840

3941
def load_into_game(gamestate: str, step_counter: str):
@@ -547,6 +549,28 @@ def load_baaj():
547549
FFXC.set_neutral()
548550
memory.main.wait_frames(30 * 0.04)
549551

552+
def kilika_rng_manip():
553+
# Kilika start, RNG01
554+
# 1904657448
555+
logger.warning("==== Hard setting value for testing")
556+
rng_value = 1904657448
557+
memory.main.set_rng_by_index(value=rng_value, index=1)
558+
559+
#Basically, hunt until we don't find a good battle in 'advances'
560+
advances = 5
561+
import rng_track
562+
import area.kilika
563+
next_two = rng_track.coming_battles(
564+
area="kilika_woods", battle_count=advances, extra_advances=1
565+
)
566+
while area.kilika.select_best_of_two(next_two) != 99:
567+
rng_value += 1
568+
memory.main.set_rng_by_index(value=rng_value, index=1)
569+
next_two = rng_track.coming_battles(
570+
area="kilika_woods", battle_count=advances, extra_advances=1
571+
)
572+
logger.warning(f"==== Chosen Value: {rng_value}")
573+
550574

551575
def besaid_trials():
552576
# Exit Tent

Diff for: memory/main.py

+6
Original file line numberDiff line numberDiff line change
@@ -2406,6 +2406,12 @@ def reset_battle_end():
24062406
process.write_bytes(key, 1, 1)
24072407

24082408

2409+
def set_rng_by_index(value:int=0, index:int=1):
2410+
global base_value
2411+
global process
2412+
key = base_value + 0x00D35ED8 + (index * 0x4)
2413+
process.write_bytes(key, value, 4)
2414+
24092415
def set_rng_2():
24102416
global base_value
24112417
global process

Diff for: players/base.py

+13-3
Original file line numberDiff line numberDiff line change
@@ -144,8 +144,16 @@ def _target_specific_id(self, target_id: int, direction: str = "l"):
144144
def attack(
145145
self, target_id: Optional[int] = None, direction_hint: Optional[str] = "u"
146146
):
147+
skip_direction = False
147148
if target_id is None:
148-
logger.debug("Attack")
149+
logger.debug("Attack enemy, first targetted.")
150+
elif target_id in range(7):
151+
logger.debug(f"Attack player character {target_id}")
152+
elif memory.main.get_enemy_current_hp()[target_id-20] == 0:
153+
logger.debug(
154+
f"Enemy {target_id} is not attack-able. Resorting to basic attack."
155+
)
156+
skip_direction = True
149157
else:
150158
logger.debug(
151159
f"Attacking a specific target with id {target_id}, direction hint is {direction_hint}"
@@ -159,7 +167,7 @@ def attack(
159167
self.navigate_to_battle_menu(attack_menu_id)
160168
while memory.main.main_battle_menu():
161169
xbox.tap_b()
162-
if target_id is not None:
170+
if target_id is not None and not skip_direction:
163171
self._target_specific_id(target_id, direction_hint)
164172
self._tap_targeting()
165173

@@ -369,7 +377,9 @@ def escaped(self) -> bool:
369377

370378
def is_defending(self) -> bool:
371379
defend_byte = self._read_char_battle_state_address(offset=PlayerMagicNumbers.DEFENDING)
372-
return (defend_byte >> 3) == 1
380+
result = (defend_byte >> 3) & 1 == 1
381+
logger.warning(f"Character is defending: {result}")
382+
return result
373383

374384
def hp(self, combat=False) -> int:
375385
if not combat:

0 commit comments

Comments
 (0)