Users browsing this thread: 1 Guest(s)
Breakable Tools - Need Help

#22
Posts: 617
Threads: 49
Thanks Received: 0
Thanks Given: 5
Joined: Feb 2017
Reputation: 25
Status
None
Okay, I've had a chance to look at my "Steal Twice" code, and I remember what I did. Don't feel bad for not understanding it. Even Assassin had to look at it 3 different times to figure out what it was actually doing.

From what I understand, the PHY/PLY has to do with the enemy counterattacking correctly. The problem with where it was placed in the original code is that it blows away the INY at C2/39E0 for which item you're targeting (common or rare). This doesn't matter in vanilla, because 1 successful steal blanks out both slots. However, by moving the PLY to AFTER the "LDA #$FF/STA $3308,Y", the INY from the item slot targeting is retained, and the function to empty that slot simply targets whichever slot you actually stole from.

The only catch was that if you successfully stole, but the slot you were targeting was empty, Y got pushed, but never pulled. Because of that, I put a 2nd PLY at C2/3A00. All other branches to the "Fail to steal" jump to C2/3A01, but that specific case needed a PLY first.

Code:
Steal function

C2/399E: A3 05        LDA $05,S      (Attacker)
C2/39A0: AA           TAX
C2/39A1: A9 01        LDA #$01
C2/39A3: 8D 01 34     STA $3401      (=1) (Sets message to "Doesn't have anything!")
C2/39A6: E0 08        CPX #$08       (Check if attacker is monster)
C2/39A8: B0 5F        BCS $3A09      (Branch if monster)
C2/39AA: C2 20        REP #$20       (Set 16-bit accumulator)
C2/39AC: B9 08 33     LDA $3308,Y    (Target's stolen items)
C2/39AF: 1A           INC
C2/39B0: E2 21        SEP #$21       (Set 8-bit Accumulator AND Carry Flag)
C2/39B2: F0 4D        BEQ $3A01      (Fail to steal if no items)
C2/39B4: EE 01 34     INC $3401      (now = 2) (Sets message to "Couldn't steal!!")
C2/39B7: BD 18 3B     LDA $3B18,X    (Attacker's Level)
C2/39BA: 69 32        ADC #$32       (adding 51, since Carry Flag was set)
C2/39BC: B0 1A        BCS $39D8      (Automatically steal if level >= 205)
C2/39BE: F9 18 3B     SBC $3B18,Y    (Subtract Target's Level, along with an extra 1 because
                                     Carry Flag is unset at this point.  Don't worry; this
                                     cancels out with the extra 1 from C2/39BA.)
                                    (StealValue = [attacker level + 51] - [target lvl + 1]
                                     = Attacker level + 50 - Target level )
C2/39C1: 90 3E        BCC $3A01      (Fail to steal if StealValue < 0)
C2/39C3: 30 13        BMI $39D8      (Automatically steal if StealValue >= 128)
C2/39C5: 85 EE        STA $EE        (save StealValue)
C2/39C7: BD 45 3C     LDA $3C45,X
C2/39CA: 4A           LSR
C2/39CB: 90 02        BCC $39CF      (Branch if no sneak ring)
C2/39CD: 06 EE        ASL $EE        (Double value)
C2/39CF: A9 64        LDA #$64
C2/39D1: 20 65 4B     JSR $4B65      (Random: 0 to 99)
C2/39D4: C5 EE        CMP $EE
C2/39D6: B0 29        BCS $3A01      (Fail to steal if the random number >= StealValue)
C2/39D8: 5A           PHY
C2/39D9: 20 5A 4B     JSR $4B5A      (Random: 0 to 255)
C2/39DC: C9 20        CMP #$20
C2/39DE: 90 01        BCC $39E1      (branch 1/8 of the time, so Rare steal slot
                                     will be checked)
C2/39E0: C8           INY            (Check the 2nd [Common] slot 7/8 of the time)
C2/39E1: B9 08 33     LDA $3308,Y    (Target's stolen item)
*C2/39E4: EA          NOP            (This is not where we restore Y, as that will blow away our item slot targeting)
C2/39E5: C9 FF        CMP #$FF       (If no item)
*C2/39E7: F0 17       BEQ $3A00      (Restore Y and the fail to steal)
C2/39E9: 8D 35 2F     STA $2F35      (save Item stolen for message purposes in
                                     parameter 1, bottom byte)
C2/39EC: 9D F4 32     STA $32F4,X    (Store in "Acquired item")
C2/39EF: BD 18 30     LDA $3018,X
C2/39F2: 0C 8C 3A     TSB $3A8C      (flag character to have any applicable item in
                                     $32F4,X added to inventory when turn is over.)
C2/39F5: A9 FF        LDA #$FF
C2/39F7: 99 08 33     STA $3308,Y    (Set to no item to steal)
*C2/39FA: EE 01 34    INC $3401         (now = 3) (Sets message to "Stole #whatever ")    
*C2/39FD: 7A           PLY              (HERE is where we restore Y, now that we no longer need to hold onto our item slot)
*C2/39FE: 60          RTS
*C2/39FF: EA          NOP             (No function; simply 1 left-over byte)

Restore Y for Counterattack
*C2/3A00: 7A          PLY              (Restore Y and continue on to fail to steal)

Fail to steal
C2/3A01: E2 20        SEP #$20
C2/3A03: A9 00        LDA #$00
C2/3A05: 99 48 3D     STA $3D48,Y    (save Fight as command for counterattack purposes)
C2/3A08: 60           RTS

I'll take a look at Bropedia's code in about an hour.

Looked at Bropedia's code, and added it to my rom. Now I need to figure out how to call it from both branches (The item broke, or the item didn't break).

The item breaking is easy, because it's an exact copy of the Metamorph code.
Code:
***ORIGINAL***
STA $32F4,X    ;  null item index to add to inventory. This means the item will stay deducted from your inventory.
LDA $3018,X
BRA check_break_end
(...)
check_break_end
TSB $3A8C      ;  flag character to have any applicable item in $32F4,X added back to inventory when turn is over.

***CHANGED TO FIT WITH BROPEDIA'S CODE***
XBA               ; store item in B (in this case $FF, Empty)
LDA $3018,X       ; character's unique bit
BRA check_break_end
(...)
check_break_end
JSR SaveItem      ; save new item to buffer

What I don't know iis how to fit this into the No_Break branch:
Code:
no_break:
LDA #$10
TSB $B1        ;  set flag to re-add item to inventory at the end of the character's turn

check_break_end:
TSB $3A8C      ;  !!THIS LINE WAS CHANGED ABOVE TO "JSR SaveItem"!!
PLP
PLA
SBC #$A2       ;  carry was clear, so subtract 163
STA $B6        ;  save unique Tool index.  0 = NoiseBlaster, 1 = Bio Blaster, etc.
RTS

On this branch, XBA never happened. I also don't know what the 4 bytes exclusive to the "no_break" section do.

Oh, one last note: Subtraction, I reverted to a 1 in 32 chance (AND #$1F instead of my bugged AND #$2A).


Projects:
FFVI: Divergent Paths (Completed) - a complete storyline and gameplay hack of FF6 that adds Leo as a playable character
  Find
Quote  



Messages In This Thread
Breakable Tools - Need Help - by PowerPanda - 07-05-2021, 02:36 PM
RE: Breakable Tools - Need Help - by C-Dude - 07-05-2021, 03:31 PM
RE: Breakable Tools - Need Help - by PowerPanda - 07-05-2021, 05:36 PM
RE: Breakable Tools - Need Help - by C-Dude - 07-05-2021, 06:10 PM
RE: Breakable Tools - Need Help - by SirNewtonFig - 07-05-2021, 06:50 PM
RE: Breakable Tools - Need Help - by PowerPanda - 07-05-2021, 09:42 PM
RE: Breakable Tools - Need Help - by C-Dude - 07-06-2021, 12:00 AM
RE: Breakable Tools - Need Help - by Gi Nattak - 07-06-2021, 12:41 AM
RE: Breakable Tools - Need Help - by C-Dude - 07-06-2021, 01:27 AM
RE: Breakable Tools - Need Help - by PowerPanda - 07-06-2021, 10:31 AM
RE: Breakable Tools - Need Help - by Gi Nattak - 07-06-2021, 10:45 AM
RE: Breakable Tools - Need Help - by C-Dude - 07-06-2021, 03:16 PM
RE: Breakable Tools - Need Help - by SirNewtonFig - 07-07-2021, 06:54 AM
RE: Breakable Tools - Need Help - by PowerPanda - 07-07-2021, 09:51 AM
RE: Breakable Tools - Need Help - by Bropedio - 07-07-2021, 10:31 AM
RE: Breakable Tools - Need Help - by SirNewtonFig - 07-07-2021, 01:28 PM
RE: Breakable Tools - Need Help - by Subtraction - 07-07-2021, 11:38 AM
RE: Breakable Tools - Need Help - by PowerPanda - 07-07-2021, 04:10 PM
RE: Breakable Tools - Need Help - by C-Dude - 07-07-2021, 05:33 PM
RE: Breakable Tools - Need Help - by SirNewtonFig - 07-08-2021, 08:21 AM
RE: Breakable Tools - Need Help - by SirNewtonFig - 07-08-2021, 02:16 PM
RE: Breakable Tools - Need Help - by C-Dude - 07-08-2021, 05:31 PM
RE: Breakable Tools - Need Help - by Bropedio - 07-07-2021, 05:46 PM
RE: Breakable Tools - Need Help - by C-Dude - 07-07-2021, 06:18 PM
RE: Breakable Tools - Need Help - by PowerPanda - 07-07-2021, 09:24 PM
RE: Breakable Tools - Need Help - by C-Dude - 07-08-2021, 01:40 AM
RE: Breakable Tools - Need Help - by PowerPanda - 07-08-2021, 11:14 AM

Forum Jump:

Users browsing this thread: 1 Guest(s)


Theme by Madsiur2017Custom Graphics by JamesWhite