Skip to content

Commit 393b11e

Browse files
committed
Merge branch 'main' into dev/logging
2 parents 1e5c4af + 107d877 commit 393b11e

File tree

6 files changed

+111
-109
lines changed

6 files changed

+111
-109
lines changed

Diff for: area/mac_woods.py

+52-17
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
1+
import logging
2+
from typing import List
3+
14
import battle.boss
25
import battle.main
3-
import logging
46
import logs
57
import memory.main
68
import menu
@@ -10,45 +12,69 @@
1012
import vars
1113
import xbox
1214

15+
logger = logging.getLogger(__name__)
16+
1317
logger = logging.getLogger(__name__)
1418
game_vars = vars.vars_handle()
1519

1620
FFXC = xbox.controller_handle()
1721

1822

23+
def wait_for_rng2_weakness(valid_weakness: List[int]):
24+
while True:
25+
current_weakness = memory.main.get_next_rng2() % 4
26+
logger.debug(
27+
f"Valid Weakness: {valid_weakness}, Current Weakness: {current_weakness}"
28+
)
29+
if current_weakness in valid_weakness:
30+
logger.info("Weakness has lined up.")
31+
return
32+
33+
34+
def calculate_possible_weaknesses() -> List[int]:
35+
items_contained = []
36+
for i, item_val in enumerate([27, 24, 30, 32]):
37+
if memory.main.get_use_items_slot(item_val) != 255:
38+
items_contained.append(i)
39+
return items_contained
40+
41+
1942
def arrival(rikku_charged):
2043
logger.info("Arriving at Macalania Woods")
2144
memory.main.click_to_control()
2245
memory.main.full_party_format("mwoodsneedcharge")
2346
memory.main.close_menu()
2447

25-
# Rikkus charge, Fish Scales, and Arctic Winds
26-
woods_vars = [False, False, False]
27-
woods_vars[0] = rikku_charged
28-
2948
last_gil = 0 # for first chest
3049
checkpoint = 0
31-
total_battles = 0
3250
while memory.main.get_map() != 221: # All the way to O'aka
3351
if memory.main.user_control():
3452
# Events
3553
if checkpoint == 14: # First chest
3654
if last_gil != memory.main.get_gil_value():
3755
if last_gil == memory.main.get_gil_value() - 2000:
3856
checkpoint += 1
39-
logger.debug(f"Chest obtained. Updating checkpoint: {checkpoint}")
57+
logger.debug(
58+
f"Chest obtained. Updating checkpoint: {checkpoint}"
59+
)
4060
else:
4161
last_gil = memory.main.get_gil_value()
4262
else:
4363
FFXC.set_movement(1, 1)
4464
xbox.tap_b()
4565
elif checkpoint == 59:
46-
if not woods_vars[0]:
47-
checkpoint -= 2
48-
elif not woods_vars[1] and not woods_vars[2]:
66+
logger.debug(f"Rikku Charge: {rikku_charged}")
67+
if not rikku_charged:
4968
checkpoint -= 2
5069
else: # All good to proceed
5170
checkpoint += 1
71+
elif checkpoint == 60:
72+
logger.info("Waiting for RNG2 to sync up for Sphermiroph Weakness.")
73+
items_contained = calculate_possible_weaknesses()
74+
logger.info(f"We currently can do: {items_contained}")
75+
FFXC.set_neutral()
76+
wait_for_rng2_weakness(items_contained)
77+
checkpoint += 1
5278

5379
# Map changes
5480
elif checkpoint < 18 and memory.main.get_map() == 241:
@@ -63,19 +89,28 @@ def arrival(rikku_charged):
6389
else:
6490
FFXC.set_neutral()
6591
if screen.battle_screen():
66-
logger.debug(f"variable check 1: {woods_vars}")
67-
woods_vars = battle.main.m_woods(woods_vars)
68-
logger.debug(f"variable check 2: {woods_vars}")
69-
if memory.main.overdrive_state()[6] == 100:
92+
battle.main.m_woods()
93+
rikku_charged = memory.main.overdrive_state()[6] == 100
94+
logger.info(
95+
"Rikku charged" if rikku_charged else "Rikku is not charged."
96+
)
97+
party_hp = memory.main.get_hp()
98+
if (
99+
party_hp[0] < 450
100+
or (party_hp[6] < 180 and not rikku_charged)
101+
or party_hp[2] + party_hp[4] < 500
102+
):
103+
battle.main.heal_up(full_menu_close=False)
104+
if rikku_charged:
70105
memory.main.full_party_format("mwoodsgotcharge")
71106
else:
72107
memory.main.full_party_format("mwoodsneedcharge")
73-
total_battles += 1
108+
memory.main.close_menu()
109+
if checkpoint == 61:
110+
checkpoint = 60
74111
elif not memory.main.battle_active() and memory.main.diag_skip_possible():
75112
xbox.tap_b()
76113

77-
# logs.write_stats("Mac Woods battles:")
78-
# logs.write_stats(total_battles)
79114
# Save sphere
80115
FFXC.set_movement(-1, 1)
81116
memory.main.wait_frames(2)

Diff for: battle/boss.py

+13-24
Original file line numberDiff line numberDiff line change
@@ -828,46 +828,35 @@ def spherimorph():
828828
else:
829829
battle.main.defend()
830830
elif turnchar == 6:
831-
if rikkuturns == 0:
832-
logger.debug("Throwing Grenade to check element")
831+
mix_dmg_rolls = sum(memory.main.rikku_mix_damage())
832+
logger.debug(f"Mix will do {mix_dmg_rolls} damage.")
833+
if mix_dmg_rolls < memory.main.get_enemy_current_hp()[0]:
834+
logger.debug("Throwing Grenade because of damage rolls")
833835
grenadeslotnum = memory.main.get_use_items_slot(35)
834836
battle.main.use_item(grenadeslotnum, "none")
835-
if memory.main.get_char_weakness(20) == 1:
836-
spell_num = 4 # Ice
837-
elif memory.main.get_char_weakness(20) == 2:
838-
spell_num = 1 # Fire
839-
elif memory.main.get_char_weakness(20) == 4:
840-
spell_num = 3 # Water
841-
elif memory.main.get_char_weakness(20) == 8:
842-
spell_num = 2 # Thunder
843-
844-
# spell_num = screen.spherimorph_spell()
845837
elif not battle.main.spheri_spell_item_ready():
846838
if 5 not in memory.main.get_active_battle_formation():
847839
battle.main.buddy_swap_lulu()
848840
else:
849841
battle.main.defend()
850-
else:
842+
elif yunaTurn and kimTurn:
851843
logger.debug("Starting Rikkus overdrive")
852-
# logs.write_stats("Spherimorph spell used:")
853-
if spell_num == 1:
854-
# ogs.write_stats("Fire")
844+
logger.debug("Full Damage Values:")
845+
logger.debug(memory.main.rikku_mix_damage())
846+
if spellNum == 1:
855847
logger.debug("Creating Ice")
856848
battle.main.rikku_full_od("spherimorph1")
857-
elif spell_num == 2:
858-
# logs.write_stats("Water")
849+
elif spellNum == 2:
859850
logger.debug("Creating Water")
860851
battle.main.rikku_full_od("spherimorph2")
861-
elif spell_num == 3:
862-
# logs.write_stats("Thunder")
852+
elif spellNum == 3:
863853
logger.debug("Creating Thunder")
864854
battle.main.rikku_full_od("spherimorph3")
865-
elif spell_num == 4:
866-
# logs.write_stats("Ice")
855+
elif spellNum == 4:
867856
logger.debug("Creating Fire")
868857
battle.main.rikku_full_od("spherimorph4")
869-
870-
rikkuturns += 1
858+
else:
859+
battle.main.defend()
871860

872861
if not game_vars.csr():
873862
xbox.skip_dialog(5)

Diff for: battle/main.py

+28-58
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,21 @@
11
import battle.overdrive
22
import battle.utils
33
import logs
4+
import logging
45
import memory.main
56
import rng_track
67
import screen
78
import vars
89
import xbox
910
from memory.main import s32
1011

12+
1113
game_vars = vars.vars_handle()
1214

1315
FFXC = xbox.controller_handle()
1416

17+
logger = logging.getLogger(__name__)
18+
1519

1620
def tap_targeting():
1721
print(
@@ -1566,24 +1570,26 @@ def thunder_plains(section):
15661570
heal_up()
15671571
memory.main.close_menu()
15681572
print("Ready to continue onward.")
1569-
1573+
15701574

15711575
@battle.utils.speedup_decorator
1572-
def m_woods(woods_vars):
1576+
def m_woods():
15731577
print("Logic depends on completion of specific goals. In Order:")
1574-
print("Rikku charged, stolen Fish Scale, stolen Arctic Wind")
1575-
print(woods_vars)
15761578
encounter_id = memory.main.get_encounter_id()
15771579
print("------------- Battle Start - Battle Number:", encounter_id)
1580+
need_arctic_wind, need_fish_scale = False, False
15781581
while not memory.main.battle_complete(): # AKA end of battle screen
15791582
if memory.main.turn_ready():
1583+
if memory.main.get_use_items_slot(24) == 255:
1584+
need_arctic_wind = True
1585+
if memory.main.get_use_items_slot(32) == 255:
1586+
need_fish_scale = True
15801587
turnchar = memory.main.get_battle_char_turn()
1581-
if not woods_vars[1] or not woods_vars[2]:
1582-
if encounter_id in [171, 172, 175]:
1583-
if encounter_id == 175 and memory.main.next_steal_rare():
1584-
print("No steal on Chimera, it will be rare which is no good.")
1585-
flee_all()
1586-
elif (
1588+
rikku_charged = memory.main.get_overdrive_battle(6) == 100
1589+
logging.info(f"Rikku charge state: {rikku_charged}")
1590+
if not rikku_charged:
1591+
if need_arctic_wind or need_fish_scale and encounter_id in [171, 172, 175]:
1592+
if (
15871593
check_petrify_tidus()
15881594
or 6 not in memory.main.get_battle_formation()
15891595
):
@@ -1592,32 +1598,32 @@ def m_woods(woods_vars):
15921598
elif 6 not in memory.main.get_active_battle_formation():
15931599
if (
15941600
encounter_id == 175
1595-
and memory.main.get_use_items_slot(24) == 255
1601+
and need_arctic_wind
15961602
):
15971603
buddy_swap_rikku()
15981604
elif (
15991605
encounter_id in [171, 172]
1600-
and memory.main.get_use_items_slot(32) == 255
1606+
and need_fish_scale
16011607
):
16021608
buddy_swap_rikku()
16031609
else:
16041610
flee_all()
16051611
elif turnchar == 6:
16061612
if (
16071613
encounter_id == 175
1608-
and memory.main.get_use_items_slot(24) == 255
1614+
and need_arctic_wind
16091615
):
16101616
print("Marker 2")
16111617
steal()
16121618
elif (
16131619
encounter_id == 172
1614-
and memory.main.get_use_items_slot(32) == 255
1620+
and need_fish_scale
16151621
):
16161622
print("Marker 3")
16171623
steal_down()
16181624
elif (
16191625
encounter_id == 171
1620-
and memory.main.get_use_items_slot(32) == 255
1626+
and need_fish_scale
16211627
):
16221628
print("Marker 4")
16231629
steal_right()
@@ -1627,36 +1633,18 @@ def m_woods(woods_vars):
16271633
else:
16281634
print("Escaping")
16291635
flee_all()
1636+
elif memory.main.get_overdrive_battle(6) != 100:
1637+
escape_one()
16301638
else:
1631-
if woods_vars[0] or memory.main.get_overdrive_battle(6) == 100:
1632-
if (
1633-
encounter_id in [171, 172]
1634-
and memory.main.get_use_items_slot(32) == 255
1635-
):
1636-
escape_one()
1637-
elif (
1638-
encounter_id == 175
1639-
and memory.main.get_use_items_slot(24) == 255
1640-
):
1641-
escape_one()
1642-
else:
1643-
flee_all()
1644-
else:
1645-
escape_one()
1646-
else:
1647-
print("Fleeing with ", turnchar)
1648-
flee_all()
1649-
elif not woods_vars[0]:
1650-
if turnchar == 6:
1639+
flee_all()
1640+
elif turnchar == 6:
16511641
if memory.main.next_steal_rare(pre_advance=2):
16521642
# Manip for crit
16531643
_steal()
16541644
else:
1655-
attack_by_num(num=6)
1645+
defend()
16561646
elif 6 not in memory.main.get_active_battle_formation():
16571647
buddy_swap_rikku()
1658-
elif memory.main.get_overdrive_battle(6) == 100:
1659-
flee_all()
16601648
else:
16611649
escape_one()
16621650
elif memory.main.next_steal_rare(pre_advance=2):
@@ -1670,27 +1658,9 @@ def m_woods(woods_vars):
16701658
print("##Looking ahead, no need to manip")
16711659
flee_all()
16721660

1673-
print("Battle complete, now to deal with the aftermath.")
1661+
logger.info("Battle complete, now to deal with the aftermath.")
16741662
memory.main.click_to_control_3()
1675-
print("M.woods, back in control")
1676-
if memory.main.overdrive_state()[6] == 100:
1677-
woods_vars[0] = True
1678-
if memory.main.get_use_items_slot(32) != 255:
1679-
woods_vars[1] = True
1680-
if memory.main.get_use_items_slot(24) != 255:
1681-
woods_vars[2] = True
1682-
print("Checking battle formation.")
1683-
print("Party format is now good. Let's check health.")
1684-
# Heal logic
1685-
party_hp = memory.main.get_hp()
1686-
if party_hp[0] < 450 or party_hp[6] < 180 or party_hp[2] + party_hp[4] < 500:
1687-
heal_up()
1688-
memory.main.close_menu()
1689-
print("And last, we'll update variables.")
1690-
print("Rikku charged, stolen Fish Scale, stolen Arctic Wind")
1691-
print(woods_vars)
1692-
print("HP is good. Onward!")
1693-
return woods_vars
1663+
logger.debug("M.woods, back in control")
16941664

16951665

16961666
def spheri_spell_item_ready():

Diff for: battle/utils.py

+1-5
Original file line numberDiff line numberDiff line change
@@ -16,11 +16,7 @@ def _monitor_battle():
1616
pass
1717
fast = False
1818
while memory.main.battle_active():
19-
if (
20-
fast
21-
and memory.main.auditory_dialog_playing()
22-
or memory.main.diag_skip_possible()
23-
):
19+
if fast and memory.main.auditory_dialog_playing():
2420
memory.main.set_game_speed(0)
2521
fast = False
2622
elif not fast:

Diff for: memory/main.py

+10
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
import os.path
55
import struct
66
import time
7+
from typing import List
78
from collections import Counter
89
from math import cos, sin
910

@@ -4159,6 +4160,13 @@ def next_crit(character: int, char_luck: int, enemy_luck: int) -> int:
41594160
return x
41604161
return 255
41614162

4163+
def rikku_mix_damage() -> List[int]:
4164+
initial_rng_vals = rng_array_from_index(index=26, array_len = 9)
4165+
dmg_rng = [(s32(x) & 31) + 0xf0 for x in initial_rng_vals[1:]]
4166+
base_dmg = 18 * 50
4167+
initial_damage = [(x * base_dmg) // 256 for x in dmg_rng]
4168+
weakness_damage = [int(x * 1.5) for x in initial_damage]
4169+
return weakness_damage
41624170

41634171
def future_attack_will_crit(
41644172
character: int, char_luck: int, enemy_luck: int, attack_index: int = 0
@@ -4557,6 +4565,8 @@ def rng_from_index(index: int = 20):
45574565
global base_value
45584566
return process.read(base_value + mem_target)
45594567

4568+
def get_next_rng2():
4569+
return roll_next_rng(rng_from_index(2), 2) & 0x7FFFFFFF & 0xFFFF
45604570

45614571
def rng_array_from_index(index: int = 20, array_len: int = 20):
45624572
ret_val = [rng_from_index(index)] # First value is the current value

0 commit comments

Comments
 (0)