; Start of reusable mining script.

; Ore scripts

@MHC
; Autoclicker Protection by Phoenix Star
IF DEAD,@toodeadtomine
COMPARE %R250, 250
IF= @antiautoclick

SET A10,1
; For the checksum.  Without this, the checksum will reset mining level and experience each time you mine something.  
SET A4,#<MXP>

; Mining chance algorithm settings
SET A6,#<MLVL>

; Pickaxe bonuses
@picks
IF I1042,@mythicpick
IF I734,@magestonepick
IF I733,@adamantpick
IF I732,@mithrilpick
IF I731,@steelpick
IF I730,@brasspick
IF I729,@ironpick
IF I728,@bronzepick
H: Oops, a bug!  I don't have a pick!
END

@bronzepick
ADD A6,1
GOTO @endpicks
@ironpick
ADD A6,2
GOTO @endpicks
@brasspick
ADD A6,3
GOTO @endpicks
@steelpick
ADD A6,4
GOTO @endpicks
@mithrilpick
ADD A6,5
GOTO @endpicks
@adamantpick
ADD A6,6
GOTO @endpicks
@magestonepick
ADD A6,7
GOTO @endpicks
@mythicpick
ADD A6,8
GOTO @endpicks

@endpicks
IF E998,@crest
GOTO @endcrest
@crest
ADD A6,2
@endcrest
SET A6,%R#<A6>

; Ores
COMPARE #<Ore>,1
IF= @StoneMining
COMPARE #<Ore>,2
IF= @CopperMining
COMPARE #<Ore>,3
IF= @TinMining
COMPARE #<Ore>,4
IF= @IronMining
COMPARE #<Ore>,5
IF= @CoalMining
COMPARE #<Ore>,6
IF= @SilverMining
COMPARE #<Ore>,7
IF= @MithMining
COMPARE #<Ore>,8
IF= @GoldMining
COMPARE #<Ore>,9
IF= @AddyMining
COMPARE #<Ore>,10
IF= @MageMining
COMPARE #<Ore>,11
IF= @ZincMining
COMPARE #<Ore>,12
IF= @DemonMining
H: This seems to be a new type of ore.  I can't mine it.  
END

@StoneMining
COMPARE #<MLVL>,1
IF< @lowlevel
SOUND Chink.wav
COMPARE #<A6>,1
IF> @StoneMined
GOTO @Miss

@StoneMined
SUB MXP,2
GIVE I718
H: I mined some stone.
GOTO @Checksum

@CopperMining
COMPARE #<MLVL>,3
IF< @lowlevel
SOUND Chink.wav
COMPARE #<A6>,3
IF> @CopperMined
GOTO @Miss

@CopperMined
SUB MXP,5
GIVE I719
H: I mined some copper.
GOTO @Checksum

@TinMining
COMPARE #<MLVL>,5
IF< @lowlevel
SOUND Chink.wav
COMPARE #<A6>,5
IF> @TinMined
GOTO @Miss

@TinMined
SUB MXP,10
GIVE I720
H: I mined some tin.
GOTO @Checksum

@IronMining
COMPARE #<MLVL>,15
IF< @lowlevel
SOUND Chink.wav
COMPARE #<A6>,15
IF> @IronMined
GOTO @Miss

@IronMined
SUB MXP,20
GIVE I721
H: I mined some iron.
GOTO @Checksum

@CoalMining
COMPARE #<MLVL>,30
IF< @lowlevel
SOUND Chink.wav
COMPARE #<A6>,30
IF> @CoalMined
GOTO @Miss

@CoalMined
SUB MXP,40
GIVE I722
H: I mined some coal.
GOTO @Checksum

@SilverMining
COMPARE #<MLVL>,40
IF< @lowlevel
SOUND Chink.wav
COMPARE #<A6>,40
IF> @SilverMined
GOTO @Miss

@SilverMined
SUB MXP,50
GIVE I723
H: I mined some silver.
GOTO @Checksum

@MithMining
COMPARE #<MLVL>,50
IF< @lowlevel
SOUND Chink.wav
COMPARE #<A6>,50
IF> @MithMined
GOTO @Miss

@MithMined
SUB MXP,65
GIVE I724
H: I mined some mithril.
GOTO @Checksum

@GoldMining
COMPARE #<MLVL>,60
IF< @lowlevel
SOUND Chink.wav
COMPARE #<A6>,60
IF> @GoldMined
GOTO @Miss

@GoldMined
SUB MXP,80
GIVE I725
H: I mined some gold.
GOTO @Checksum

@AddyMining
COMPARE #<MLVL>,70
IF< @lowlevel
SOUND Chink.wav
COMPARE #<A6>,70
IF> @AddyMined
GOTO @Miss

@AddyMined
SUB MXP,95
GIVE I726
H: I mined some adamant.
GOTO @Checksum

@MageMining
COMPARE #<MLVL>,85
IF< @lowlevel
SOUND Chink.wav
COMPARE #<A6>,85
IF> @MageMined
GOTO @Miss

@MageMined
SUB MXP,110
GIVE I727
H: I mined some magestone.
GOTO @Checksum

@ZincMining
COMPARE #<MLVL>,35
IF< @lowlevel
SOUND Chink.wav
COMPARE #<A6>,35
IF> @ZincMined
GOTO @Miss

@ZincMined
SUB MXP,45
GIVE I745
H: I mined some zinc.
GOTO @Checksum

@DemonMining
COMPARE #<MLVL>,20
IF< @lowlevel
SOUND Chink.wav
COMPARE #<A6>,20
IF> @DemonMined
GOTO @Miss

@DemonMined
SUB MXP,10
GIVE I746
H: I mined a demonstone.
GOTO @Checksum

; Common Scripts

@Miss
N: You missed the rock.
END

@Checksum
; Checksum protecting mining.  Don't forget that this changed when mining.  
SET A5,#<A4>
SUB A5,#<MXP>
SET A4,0
; Now A5 expresses the experience gained during the latest mine.  

SET CHK2,#<CHK>
SET A2,#<MLVL>
SET A3,#<MXP>

; Since MXP decreases as you mine, you must add A5.
ADD A3,#<A5>

MUL A2,3
MUL A3,2
SET CHK,#<A2>
ADD CHK,#<A3>
MUL CHK,5
MOD CHK,23
SUB CHK2,#<CHK>
COMPARE #<CHK2>,0
IF= @passedchk
SET DoneSet,2
SET CHK2=0
GOTO @mineset
END
@passedchk

COMPARE #<MXP>,1
IF< @LevelUp
GOTO @CHKRefresh
END

@LevelUp
; Yay, a level!
SET A1,#<MLVL>
SET A3,#<A1>
ADD A1,1
SET A2,#<A1>
MUL A1,#<A2>
MUL A1,#<A2>
MUL A3,#<MLVL>
MUL A3,#<MLVL>
SUB A1,#<A3>
SET MXP,#<A1>
ADD MLVL,1
H: I just raised a level!  I'm level #<MLVL> now!

; Mining upgrades
COMPARE #<MLVL>,3
IF= @canminecopper
COMPARE #<MLVL>,5
IF= @canminetin
COMPARE #<MLVL>,15
IF= @canmineiron
COMPARE #<MLVL>,20
IF= @canminedemon
COMPARE #<MLVL>,30
IF= @canminecoal
COMPARE #<MLVL>,35
IF= @canminezinc
COMPARE #<MLVL>,40
IF= @canminesilver
COMPARE #<MLVL>,50
IF= @canminemithril
COMPARE #<MLVL>,60
IF= @canminegold
COMPARE #<MLVL>,70
IF= @canmineadamant
COMPARE #<MLVL>,85
IF= @canminemagestone
GOTO @CHKRefresh

@canminecopper
H: I can mine copper now!
GOTO @CHKRefresh
@canminetin
H: I can mine tin now!
GOTO @CHKRefresh
@canmineiron
H: I can mine iron now!
GOTO @CHKRefresh
@canminedemon
H: I can mine demonstone now!
GOTO @CHKRefresh
@canminecoal
H: I can mine coal now!
GOTO @CHKRefresh
@canminezinc
H: I can mine zinc now!
GOTO @CHKRefresh
@canminesilver
H: I can mine silver now!
GOTO @CHKRefresh
@canminemithril
H: I can mine mithril now!
GOTO @CHKRefresh
@canminegold
H: I can mine gold now!
GOTO @CHKRefresh
@canmineadamant
H: I can mine adamant now!
GOTO @CHKRefresh
@canminemagestone
H: I can mine magestone now!
GOTO @CHKRefresh
H: Oops, a bug!
END

@CHKRefresh
; Checksum refresh.
SET A2,#<MLVL>
SET A3,#<MXP>
MUL A2,3
MUL A3,2
SET CHK,#<A2>
ADD CHK,#<A3>
MUL CHK,5
MOD CHK,23

SET A10,0

END

@getpick
H: I need a pickaxe to mine ores.  
END

@lowlevel
H: My mining level is too low.  I can't mine this yet.  
END

; Mine Settings
@mineset
COMPARE #<DoneSet>,1
IF= @currentxp
COMPARE #<DoneSet>,2
IF= @hacked
SET MLVL, 1
SET A1,#<MLVL>
ADD A1,1
SET A2,#<A1>
MUL A1,#<A2>
MUL A1,#<A2>
SET MXP, #<A1>
SET MHC, 100
; Checksum settings.
SET A2,#<MLVL>
SET A3,#<MXP>
MUL A2,3
MUL A3,2
SET CHK,#<A2>
ADD CHK,#<A3>
MUL CHK,5
MOD CHK,23
SET DoneSet, 1
GOTO @goinmine
END

; Non-banning cheat protection.
@hacked
N: You seem to have changed your mining cookies.  
N: They will be reset to level 1 with nothing mined.
; Take all ores.
TAKE I718,100
TAKE I719,100
TAKE I720,100
TAKE I721,100
TAKE I722,100
TAKE I723,100
TAKE I724,100
TAKE I725,100
TAKE I726,100
TAKE I727,100
TAKE I745,100
TAKE I746,100

; Reset stats.
SET DoneSet,0
GOTO @mineset
END

@currentxp
H: I'm currently level #<MLVL> in mining.  
GOTO @goinmine
END

@antiautoclick
H: Carbon monoxide!  I better get out of here!
GOTO EXIT
END

@toodeadtomine
N: You're too dead to mine.  
END

; Mining Script by Hugna.
; Edited by Phoenix Star for easy expansion, bug fixes, and innovation.
; For use only in Gretok.  All rights reserved.  
; All your base are belong to us.
; Move ZIG.
; Phoenix Star worked for months trying to get this working.  Show some appreciation by not hacking it.  