@program $lib/rps2 1 10000 d i $include $lib/rp $include $lib/rps $include $lib/alynna $include $lib/pokedex $include $muf/inline var param var target var stat var value var dicestore var dicestore4 var attacklevel var attacklevel2 var mytemp var thestat var metype $def INFORM "PokeRP" pretty tellme $def AVATAR #21 $def MAXVOTES me @ staff? if 256 else me @ "maxvotes" getstatint if me @ "maxvotes" getstatint else 4 then then $libdef getpokestat : getpokestat ( d s -- ? ) var target var item item ! target ! target @ "s/" item @ strcat getstat toint level dup 2 * swap nd4 + target @ "t/" item @ strcat getstat toint + ; PUBLIC getpokestat $libdef levelhandler : levelhandler ( d -- i ) var target var lastlevel var curlevel target ! target @ "lastlevel" getstat toint lastlevel ! target @ "xp" getstatint level toint curlevel ! curlevel @ lastlevel @ > if { target @ " grew to level " curlevel @ "!" }cat "Level" pretty target @ swap ansi_notify target @ "lastlevel" target @ "xp" getstatint level setstat 1 else 0 then ; PUBLIC levelhandler $libdef ballhandler : ballhandler ( i s d s -- i ) var item var target var isubtype var ballpower var roll var stat var value var tmp var cmpme var cmptgt var speed var accuracy item ! target ! Isubtype ! isubtype @ toint 0 > if isubtype @ tofloat ballpower ! else 10.0 ballpower ! then { "Ball power of '" item @ "': " ballpower @ 2 fchop }cat "Pokeball" pretty tellhere me @ "xp" getstatint target @ "xp" getstatint - level tmp ! ballpower @ tmp @ 100.0 / 1.0 + * ballpower ! { "Level factor of '" me @ "', trying to capture '" target @ "': " tmp @ toint "%%, new ball power [" ballpower @ 2 fchop "]" }cat "Pokeball" pretty tellhere target @ "hp" getstatint 1.0 * target @ maxhp 1.0 * / tmp ! tmp @ 1.0 < if ballpower @ 1 tmp @ / * ballpower ! { "Weakness factor of '" target @ "': " 100 tmp @ 100 * - toint "%%, new ball power [" ballpower @ 2 fchop "]" }cat "Pokeball" pretty tellhere then target @ "pokemorph" getstatint case 0 = when ballpower @ 0.00 * ballpower ! { "Pokeballs cannot be used on humans: new ball power [" ballpower @ 2 fchop "]" }cat "Pokeball" pretty tellhere end 1 = when end 2 = when ballpower @ 0.10 * ballpower ! { "Pokemorph strength against ball, 90%% penalty: new ball power [" ballpower @ 2 fchop "]" }cat "Pokeball" pretty tellhere end 3 = when ballpower @ 0.02 * ballpower ! { "Pokemorph strength against ball, 98%% penalty: new ball power [" ballpower @ 2 fchop "]" }cat "Pokeball" pretty tellhere end endcase ( Now factor in different ball types ) { "pokemon/" target @ iam "/type" }cat getdex tostr isubtype @ tostr smatch if ballpower @ 50 + ballpower ! { "Pokemon type match using '" item @ "' to capture '" target @ "': +50 to ballpower, new ball power [" ballpower @ 2 fchop "]" }cat "Pokeball" pretty tellhere then ( Love ball ) isubtype @ "Love" smatch if me @ "sex" getpropstr capitalize 1 strcut pop cmpme ! target @ "sex" getpropstr capitalize 1 strcut pop cmptgt ! 0 cmpme @ "M" smatch cmptgt @ "F" smatch and if pop 1 then cmpme @ "F" smatch cmptgt @ "M" smatch and if pop 1 then cmpme @ "H" smatch cmptgt @ "H" smatch or if pop 1 then if ballpower @ 50 + ballpower ! { "Pokemon ball type match using '" item @ "' to capture '" target @ "': +50 to ballpower, new ball power [" ballpower @ 2 fchop "]" }cat "Pokeball" pretty tellhere then then ( Level ball ) isubtype @ "Level" smatch if target @ "xp" getstatint level 20 < if ballpower @ 50 + ballpower ! { "Pokemon ball type match using '" item @ "' to capture '" target @ "': +50 to ballpower, new ball power [" ballpower @ 2 fchop "]" }cat "Pokeball" pretty tellhere then then ( Friend ball ) isubtype @ "Friend" smatch if 0 ballpower ! { "Pokemon ball type match using '" item @ "' to capture '" target @ "': New ball power [" ballpower @ 2 fchop "]" }cat "Pokeball" pretty tellhere then ( Try to capture ) isubtype @ "Friend" smatch not if me @ "accuracy" getpokestat toint accuracy ! target @ "speed" getpokestat toint speed ! accuracy @ 0 > if { me @ "'s accuracy modifier increased chances of capture by " accuracy @ "!" }cat "Pokeball" pretty tellme then accuracy @ 0 < if { me @ "'s accuracy modifier decreased chances of capture by " accuracy @ abs "!" }cat "Pokeball" pretty tellme then speed @ 0 > if { me @ "'s speed modifier decreased chances of capture by " speed @ "!" }cat "Pokeball" pretty tellme then speed @ 0 < if { me @ "'s speed modifier increased chances of capture by " speed @ abs "!" }cat "Pokeball" pretty tellme then { "Attempting to capture '" target @ "'... rolling 1d100-" accuracy @ speed @ - " against " ballpower @ toint }cat "Pokeball" pretty tellhere random 100 % accuracy @ - speed @ + roll ! roll @ ballpower @ <= if { target @ " was captured! " me @ " now owns " target @ ". (" roll @ ")" }cat "Pokeball" pretty tellhere me @ "p/" target @ name strcat target @ setstat target @ "q/" me @ name strcat me @ setstat else { target @ " got away! (" roll @ ")" }cat "Pokeball" pretty tellhere then else target @ { me @ " just dropped a friend ball in front of you! If you wish to be owned by them type '+pokemon/owner " me @ "'" }cat "Pokeball" pretty notify then pop 1 ; PUBLIC ballhandler $libdef itemhandler : itemhandler ( d s -- i ) var target var item var itype var isubtype var stat var value item ! target ! { "item/" item @ "/type" }cat getdex tostr itype ! { "item/" item @ "/subtype" }cat getdex tostr isubtype ! 0 ( Ball handler, pass off to ball handler ) itype @ "Ball" smatch if isubtype @ target @ item @ ballhandler then ( Key item handler ) itype @ "Key" smatch if target @ "k/" item @ strcat isubtype @ setstat { target @ " just received key item " item @ "!" }cat "Item" pretty tellhere pop 1 then ( Lucky Egg ) itype @ "XP" smatch if target @ "xp" over over getstat isubtype @ tofloat + setstat { target @ " just received " isubtype @ "xp from " item @ "!" }cat "Item" pretty tellhere pop 1 then ( Apricorn handler ) itype @ "Apricorn" smatch if target @ "m/" isubtype @ " Ball" strcat strcat over over getstat 1 + setstat { target @ " just refined a " item @ " into an " isubtype @ " Ball!" }cat "Item" pretty tellhere pop 1 then ( TM handler ) itype @ "TM" smatch if isubtype @ toint 100 <= if isubtype @ { "{" { "pokemon/" target @ iam "/tmhm" }cat getdex { "pokemon/" target @ iam "/tmhm2" }cat getdex dup if tostr "|" swap strcat strcat else pop then "|" ":" subst "}" }cat smatch if target @ { "a/" { "tm/" isubtype @ "/name" }cat getdex tostr }cat over over getstat 1 + setstat { "TM" isubtype @ " was installed on " target @ "." }cat "Item/TM" pretty tellhere pop 1 else { "TM" isubtype @ " is incompatible with " target @ "!" }cat "Item/TM" pretty tellhere then else target @ { "a/" { "tm/" isubtype @ "/name" }cat getdex tostr }cat over over getstat 1 + setstat { "TM" isubtype @ " was installed on " target @ "." }cat "Item/TM" pretty tellhere pop 1 then then ( HM handler ) itype @ "HM" smatch if isubtype @ toint 100 <= if "H" isubtype @ strcat { "{" { "pokemon/" target @ iam "/tmhm" }cat getdex { "pokemon/" target @ iam "/tmhm2" }cat getdex dup if tostr "|" swap strcat strcat else pop then "|" ":" subst "}" }cat smatch if target @ { "a/" { "hm/" isubtype @ "/name" }cat getdex tostr }cat over over getstat 1 + setstat { "HM" isubtype @ " was installed on " target @ "." }cat "Item/HM" pretty tellhere pop 1 else { "HM" isubtype @ " is incompatible with " target @ "!" }cat "Item/HM" pretty tellhere then else target @ { "a/" { "hm/" isubtype @ "/name" }cat getdex tostr }cat over over getstat 1 + setstat { "HM" isubtype @ " was installed on " target @ "." }cat "Item/HM" pretty tellhere pop 1 then then ( Cure Handler ) itype @ "Cure" smatch if isubtype @ toint 0 > if target @ "HP" getstatint isubtype @ toint + dup target @ maxhp > if pop target @ maxhp then target @ "HP" rot setstat { target @ "'s HP was raised by " isubtype @ "." }cat "Item/Cure" pretty tellhere pop 1 else isubtype @ "All" smatch if target @ "hp" target @ maxhp setstat target @ "status" 0 setstat target @ "@rp/a/" array_get_propvals foreach value ! stat ! target @ { "a/" stat @ "/pp" }cat { "attack/" stat @ "/pp" }cat getdex toint setstat repeat { target @ " was completely healed and all PP restored!" }cat "Item/Cure" pretty tellhere pop 1 then isubtype @ "PP" smatch if target @ "@rp/a/" array_get_propvals foreach value ! stat ! target @ { "a/" stat @ "/pp" }cat { "attack/" stat @ "/pp" }cat getdex toint setstat repeat { target @ "'s PP was completely restored!" }cat "Item/Cure" pretty tellhere pop 1 then isubtype @ "Confusion" smatch if target @ "status" getstat 1 = if target @ "status" 0 setstat { target @ "'s confused no more!" }cat "Item/Cure" pretty tellhere pop 1 else { "It had no effect on " target @ "!" }cat "Item/Cure" pretty tellhere pop 1 then then isubtype @ "Frozen" smatch if target @ "status" getstat 2 = if target @ "status" 0 setstat { target @ "'s not frozen anymore!" }cat "Item/Cure" pretty tellhere pop 1 else { "It had no effect on " target @ "!" }cat "Item/Cure" pretty tellhere pop 1 then then isubtype @ "Burn" smatch if target @ "status" getstatint 3 = if target @ "status" 0 setstat { target @ " is no longer burned!" }cat "Item/Cure" pretty tellhere pop 1 else { "It had no effect on " target @ "!" }cat "Item/Cure" pretty tellhere pop 1 then then isubtype @ "Sleep" smatch if target @ "status" getstatint 4 = if target @ "status" 0 setstat { target @ " woke up!" }cat "Item/Cure" pretty tellhere pop 1 else { "It had no effect on " target @ "!" }cat "Item/Cure" pretty tellhere pop 1 then then isubtype @ "Paralyze" smatch if target @ "status" getstat 5 = if target @ "status" 0 setstat { target @ " can move again!" }cat "Item/Cure" pretty tellhere pop 1 else { "It had no effect on " target @ "!" }cat "Item/Cure" pretty tellhere pop 1 then then isubtype @ "Poison" smatch if target @ "status" getstat 6 = if target @ "status" 0 setstat { target @ " is no longer poisoned!" }cat "Item/Cure" pretty tellhere pop 1 else { "It had no effect on " target @ "!" }cat "Item/Cure" pretty tellhere pop 1 then then then then ( Moo Handler ) itype @ "Moo" smatch if isubtype @ toint 0 > if target @ "HP" getstatint target @ maxhp isubtype @ toint 100 / * + dup target @ maxhp > if pop target @ maxhp then target @ "HP" rot setstat { target @ "'s HP was raised by " isubtype @ "." }cat "Item/Cure" pretty tellhere pop 1 then then ( Equip handler ) itype @ "Equip" smatch if target @ { "e/" item @ capitalize }cat tostr over over getstat 1 + setstat { "Equip " item @ "(type " isubtype @ ") was set up on " target @ "." }cat "Item/Equip" pretty tellhere pop 1 then ( permstat handler ) itype @ "Attack" smatch if isubtype @ atoi value ! target @ "s/Attack" over over getstat level value @ + level2xp dup -256 < if pop -256 then dup 256 > if pop 256 then setstat value @ 0 < if { "Item " item @ " has lowered " target @ "'s level in " itype @ " by " value @ abs "." }cat "Item" pretty tellhere else { "Item " item @ " has raised " target @ "'s level in " itype @ " by " value @ abs "." }cat "Item" pretty tellhere then pop 1 then itype @ "Defense" smatch if isubtype @ atoi value ! target @ "s/Defense" over over getstat level value @ + level2xp dup -256 < if pop -256 then dup 256 > if pop 256 then setstat value @ 0 < if { "Item " item @ " has lowered " target @ "'s level in " itype @ " by " value @ abs "." }cat "Item" pretty tellhere else { "Item " item @ " has raised " target @ "'s level in " itype @ " by " value @ abs "." }cat "Item" pretty tellhere then pop 1 then itype @ "Special" smatch if isubtype @ atoi value ! target @ "s/Special" over over getstat level value @ + level2xp dup -256 < if pop -256 then dup 256 > if pop 256 then setstat value @ 0 < if { "Item " item @ " has lowered " target @ "'s level in " itype @ " by " value @ abs "." }cat "Item" pretty tellhere else { "Item " item @ " has raised " target @ "'s level in " itype @ " by " value @ abs "." }cat "Item" pretty tellhere then pop 1 then itype @ "Special-Def" smatch if isubtype @ atoi value ! target @ "s/Special-Def" over over getstat level value @ + level2xp dup -256 < if pop -256 then dup 256 > if pop 256 then setstat value @ 0 < if { "Item " item @ " has lowered " target @ "'s level in " itype @ " by " value @ abs "." }cat "Item" pretty tellhere else { "Item " item @ " has raised " target @ "'s level in " itype @ " by " value @ abs "." }cat "Item" pretty tellhere then pop 1 then itype @ "Accuracy" smatch if isubtype @ atoi value ! target @ "s/Accuracy" over over getstat level value @ + level2xp dup -256 < if pop -256 then dup 256 > if pop 256 then setstat value @ 0 < if { "Item " item @ " has lowered " target @ "'s level in " itype @ " by " value @ abs "." }cat "Item" pretty tellhere else { "Item " item @ " has raised " target @ "'s level in " itype @ " by " value @ abs "." }cat "Item" pretty tellhere then pop 1 then itype @ "Speed" smatch if isubtype @ atoi value ! target @ "s/Speed" over over getstat level value @ + level2xp dup -256 < if pop -256 then dup 256 > if pop 256 then setstat value @ 0 < if { "Item " item @ " has lowered " target @ "'s level in " itype @ " by " value @ abs "." }cat "Item" pretty tellhere else { "Item " item @ " has raised " target @ "'s level in " itype @ " by " value @ abs "." }cat "Item" pretty tellhere then pop 1 then itype @ "Fertility" smatch if isubtype @ atoi value ! target @ "s/Fertility" over over getstat level value @ + level2xp dup -256 < if pop -256 then dup 256 > if pop 256 then setstat value @ 0 < if { "Item " item @ " has lowered " target @ "'s level in " itype @ " by " value @ abs "." }cat "Item" pretty tellhere else { "Item " item @ " has raised " target @ "'s level in " itype @ " by " value @ abs "." }cat "Item" pretty tellhere then pop 1 then itype @ "Max-HP" smatch if isubtype @ atoi value ! target @ "s/Max-HP" over over getstat level value @ + level2xp dup -256 < if pop -256 then dup 256 > if pop 256 then setstat value @ 0 < if { "Item " item @ " has lowered " target @ "'s level in " itype @ " by " value @ abs "." }cat "Item" pretty tellhere else { "Item " item @ " has raised " target @ "'s level in " itype @ " by " value @ abs "." }cat "Item" pretty tellhere then pop 1 then itype @ "Temp-Attack" smatch if isubtype @ atoi value ! target @ "t/Attack" over over getstat value @ + dup -100 < if pop -100 then dup 100 > if pop 100 then setstat value @ 0 < if { "Item " item @ " has lowered " target @ "'s " itype @ " by " value @ abs " temporarily!" }cat "Item" pretty tellhere else { "Item " item @ " has raised " target @ "'s " itype @ " by " value @ abs " temporarily!" }cat "Item" pretty tellhere then pop 1 then itype @ "Temp-Defense" smatch if isubtype @ atoi value ! target @ "t/Defense" over over getstat value @ + dup -100 < if pop -100 then dup 100 > if pop 100 then setstat value @ 0 < if { "Item " item @ " has lowered " target @ "'s " itype @ " by " value @ abs " temporarily!" }cat "Item" pretty tellhere else { "Item " item @ " has raised " target @ "'s " itype @ " by " value @ abs " temporarily!" }cat "Item" pretty tellhere then pop 1 then itype @ "Temp-Special" smatch if isubtype @ atoi value ! target @ "t/Special" over over getstat value @ + dup -100 < if pop -100 then dup 100 > if pop 100 then setstat value @ 0 < if { "Item " item @ " has lowered " target @ "'s " itype @ " by " value @ abs " temporarily!" }cat "Item" pretty tellhere else { "Item " item @ " has raised " target @ "'s " itype @ " by " value @ abs " temporarily!" }cat "Item" pretty tellhere then pop 1 then itype @ "Temp-Special-Def" smatch if isubtype @ atoi value ! target @ "t/Special-Def" over over getstat value @ + dup -100 < if pop -100 then dup 100 > if pop 100 then setstat value @ 0 < if { "Item " item @ " has lowered " target @ "'s " itype @ " by " value @ abs " temporarily!" }cat "Item" pretty tellhere else { "Item " item @ " has raised " target @ "'s " itype @ " by " value @ abs " temporarily!" }cat "Item" pretty tellhere then pop 1 then itype @ "Temp-Accuracy" smatch if isubtype @ atoi value ! target @ "t/Accuracy" over over getstat value @ + dup -100 < if pop -100 then dup 100 > if pop 100 then setstat value @ 0 < if { "Item " item @ " has lowered " target @ "'s " itype @ " by " value @ abs " temporarily!" }cat "Item" pretty tellhere else { "Item " item @ " has raised " target @ "'s " itype @ " by " value @ abs " temporarily!" }cat "Item" pretty tellhere then pop 1 then itype @ "Temp-Speed" smatch if isubtype @ atoi value ! target @ "t/Speed" over over getstat value @ + dup -100 < if pop -100 then dup 100 > if pop 100 then setstat value @ 0 < if { "Item " item @ " has lowered " target @ "'s " itype @ " by " value @ abs " temporarily!" }cat "Item" pretty tellhere else { "Item " item @ " has raised " target @ "'s " itype @ " by " value @ abs " temporarily!" }cat "Item" pretty tellhere then pop 1 then itype @ "Temp-Fertility" smatch if isubtype @ atoi value ! target @ "t/Fertility" over over getstat value @ + dup -100 < if pop -100 then dup 100 > if pop 100 then setstat value @ 0 < if { "Item " item @ " has lowered " target @ "'s " itype @ " by " value @ abs " temporarily!" }cat "Item" pretty tellhere else { "Item " item @ " has raised " target @ "'s " itype @ " by " value @ abs " temporarily!" }cat "Item" pretty tellhere then pop 1 then itype @ "Temp-Max-HP" smatch if isubtype @ atoi value ! target @ "t/Max-HP" over over getstat value @ + dup -100 < if pop -100 then dup 100 > if pop 100 then setstat value @ 0 < if { "Item " item @ " has lowered " target @ "'s " itype @ " by " value @ abs " temporarily!" }cat "Item" pretty tellhere else { "Item " item @ " has raised " target @ "'s " itype @ " by " value @ abs " temporarily!" }cat "Item" pretty tellhere then pop 1 then ( NEW item: Pokeblocks ) itype @ "Pokeblock" smatch if { "/Pokeblock/" isubtype @ }cat getdex dup not if pop { "Invalid pokeblock type!" }cat "Item" pretty tellme pop 1 else "|" explode_array foreach value ! pop target @ { "c/" value @ }cat over over getstat ++ 0 9 limit setstat { "/item/" isubtype @ " pokeblock/desc" }cat getdex "Item" pretty tellhere { target @ "'s condition in " value @ toupper " rose by 1!" }cat "Item" pretty tellhere repeat pop 1 then then ( Inline handler ) itype @ "Inline" smatch if isubtype @ target @ { "var! target var! isubtype" { "/item/" item @ "/inline" }cat getdex }cat inline pop 1 then ( handle virtual items ) "$pokedex" match "/item/" item @ "/" strcat strcat propdir? not if pop 1 then ; PUBLIC itemhandler : isepic ( s -- i ) var value var stat var rollx var target target ! me @ "@rp/e/" array_get_propvals foreach value ! stat ! { "item/" stat @ "/type" }cat getdex tostr "Equip" smatch if { "item/" stat @ "/subtype" }cat getdex tostr { "attack/" target @ "/type" }cat getdex tostr smatch if value @ level toint nd4 rollx ! { "Equipment '" stat @ "' enhanced attack '" target @ "'! (+" rollx @ ")" }cat "Equip" pretty tellhere rollx @ exit then then repeat 0 ; $libdef stathandler : stathandler ( target.d -- abort?.i ) var target var status var factor var rtg var roll var halt var inlinemsg target ! ( by default, dont abort ) 0 ( Status ailments ) target @ "status" getstatint 0 > if target @ "status" getstat toint status ! target @ "statusfactor" getstat toint factor ! target @ "statustarget" getstat rtg ! status @ case ( Confuse ) 1 = when target @ "statusfactor" factor @ 1 - dup factor ! setstat factor @ if random 100 % 50 < if { target @ " is confused! It hurt itself in the confusion! ^RED^" random target @ "xp" getstat toint level 2 * int % dup roll ! "^NORMAL^ damage!" }cat "PokeBattle" pretty target @ location #-1 rot ansi_notify_except target @ 0 roll @ - adjusthp target @ isfainted? if { target @ " has fainted!" }cat "PokeBattle" pretty target @ location #-1 rot ansi_notify_except pop 1 then pop 1 else { target @ " is confused!" }cat "PokeBattle" pretty target @ location #-1 rot ansi_notify_except then else target @ "status" 0 setstat { target @ " is confused no more!" }cat "PokeBattle" pretty target @ location #-1 rot ansi_notify_except then end ( Frozen ) 2 = when { target @ " is frozen! They cannot attack!" }cat "PokeBattle" pretty target @ location #-1 rot ansi_notify_except pop 1 end ( Burn ) 3 = when { target @ " is hurt by the burn! ^RED^" random factor @ % dup roll ! "^NORMAL^ damage!" }cat "PokeBattle" pretty target @ location #-1 rot ansi_notify_except target @ 0 roll @ - adjusthp target @ isfainted? if { target @ " has fainted!" }cat "PokeBattle" pretty target @ location #-1 rot ansi_notify_except pop 1 then end ( Sleep ) 4 = when target @ "statusfactor" factor @ 1 - dup factor ! setstat factor @ if { target @ " is asleep! They cannot attack!" }cat "PokeBattle" pretty target @ location #-1 rot ansi_notify_except pop 1 else target @ "status" 0 setstat { target @ " woke up!" }cat "PokeBattle" pretty target @ location #-1 rot ansi_notify_except then end ( Paralyze ) 5 = when random 100 % 50 < if { target @ " is paralyzed! They cannot attack!" }cat "PokeBattle" pretty target @ location #-1 rot ansi_notify_except pop 1 then end ( Poison ) 6 = when { target @ " is hurt by the poison! ^RED^" random factor @ % dup roll ! "^NORMAL^ damage!" }cat "PokeBattle" pretty target @ location #-1 rot ansi_notify_except target @ 0 roll @ - adjusthp target @ isfainted? if { target @ " has fainted!" }cat "PokeBattle" pretty target @ location #-1 rot ansi_notify_except pop 1 then end ( Leech ) 7 = when { target @ " is being leeched! ^RED^" factor @ "^NORMAL^ HP was sent to " rtg @ }cat "PokeBattle" pretty target @ location #-1 rot ansi_notify_except target @ 0 factor @ - adjusthp target @ isfainted? if { target @ " has fainted!" }cat "PokeBattle" pretty target @ location #-1 rot ansi_notify_except pop 1 then rtg @ factor @ adjusthp end ( Trap ) 8 = when target @ "statusfactor" factor @ 1 - dup factor ! setstat factor @ if { target @ " is trapped! ^RED^" random factor @ % dup roll ! "^NORMAL^ damage!" }cat "PokeBattle" pretty target @ location #-1 rot ansi_notify_except target @ 0 roll @ - adjusthp target @ isfainted? if { target @ " has fainted!" }cat "PokeBattle" pretty target @ location #-1 rot ansi_notify_except pop 1 then else target @ "status" 0 setstat { target @ " is no longer trapped!" }cat "PokeBattle" pretty target @ location #-1 rot ansi_notify_except then end ( Fainted ) 9 = when { target @ " is fainted! They cannot attack! Heck, they shouldn't even be here, they should be at a pokemon center recovering!" }cat "PokeBattle" pretty target @ location #-1 rot ansi_notify_except pop 1 end endcase then ( Handle type 13 statuses ) target @ "ts/status" getstat if target @ "ts/status" getstat status ! { "/attack/" status @ "/inline-status" }cat getdex if rtg @ factor @ status @ target @ { "var! target var! status var! factor var! rtg \"\" var! inlinemsg var halt " { "/attack/" status @ "/inline-status" }cat getdex " inlinemsg @ halt @" }cat inline halt ! inlinemsg ! inlinemsg @ if { inlinemsg @ }cat "PokeInline" pretty tellhere then halt @ if pop 1 then then then ; PUBLIC stathandler : damagemodifiers ( d i s -- s i ) var target var attack var attacktype var message var orig var damage var tmp1 var tmp2 var morphpower attack ! dup orig ! damage ! target ! "" message ! { "attack/" param @ "/type" }cat getdex attacktype ! attacktype @ "{Bug|Fighting|Flying|Ghost|Ground|Normal|Poison|Rock|Steel}" smatch if (physical) me @ "Attack" getpokestat if damage @ me @ "Attack" getpokestat dup tmp1 ! + damage ! { message @ me @ "(" tmp1 @ int "%%)" }cat message ! then target @ "Defense" getpokestat if damage @ target @ "Defense" getpokestat dup tmp2 ! - damage ! { message @ " - " target @ "(" tmp2 @ int "%%)" }cat message ! then message @ if { "Physical damage mods: Original(" orig @ "%%) + (" message @ " = " tmp1 @ tmp2 @ - int "%% damage modifier) = new target " damage @ int "%% damage." }cat message ! then else (special) me @ "Special" getpokestat if damage @ me @ "Special" getpokestat dup tmp1 ! + damage ! { message @ me @ "(" tmp1 @ int "%%)" }cat message ! then target @ "Special-Def" getpokestat if damage @ target @ "Special-Def" getpokestat dup tmp2 ! - damage ! { message @ " - " target @ "(" tmp2 @ int "%%)" }cat message ! then message @ if { "Special damage mods: Original(" orig @ "%%) + (" message @ " = " tmp1 @ tmp2 @ - int "%% damage modifier) = new target " damage @ int "%% damage." }cat message ! then then damage @ 0 < if random 10 % 1 + damage ! then me @ morph? if "$pokedex" match "morph-power" getstat morphpower ! ( { me @ " is a morph, attack power is reduced by " 1 morphpower @ - 100 * "%%." }cat "PokeBattle" pretty tellhere ) damage @ morphpower @ * damage ! then me @ meta? if "$pokedex" match "meta-power" getstat morphpower ! ( { me @ " is a meta, attack power is reduced by " 1 morphpower @ - 100 * "%%." }cat "PokeBattle" pretty tellhere ) damage @ morphpower @ * damage ! then message @ damage @ ; $libdef attackhandler : attackhandler ( attackfactor.i target.d damage.i stat.i param.s -- damage.i stat.i ) var stat var param var damage var target var subtype var factor var tmp var value var rawdmg var attackfactor var attacklevel "" var! inlinemsg param ! stat ! damage ! target ! attackfactor ! attacklevel ! { "attack/" param @ "/subtype" }cat getdex tostr subtype ! { "attack/" param @ "/factor" }cat getdex tostr factor ! { "attack/" param @ "/damage" }cat getdex tostr rawdmg ! ( begin handling ) ( Inline handler ) { "/attack/" param @ "/inline" }cat getdex if param @ stat @ damage @ target @ subtype @ factor @ rawdmg @ attackfactor @ attacklevel2 @ { "var! attacklevel var! attackfactor var! rawdmg var! factor var! subtype var! target var! damage var! stat var! param \"\" var! inlinemsg " { "/attack/" param @ "/inline" }cat getdex " inlinemsg @ param @ stat @ damage @ target @ subtype @ factor @ rawdmg @ attackfactor @ attacklevel @" }cat inline attacklevel2 ! attackfactor ! rawdmg ! factor ! subtype ! target ! damage ! stat ! param ! inlinemsg ! inlinemsg @ if inlinemsg @ "PokeInline" pretty tellhere then target @ damage @ param @ damagemodifiers toint damage ! pop then ( tempstat handler ) subtype @ "Attack" smatch if factor @ toint value ! value @ stat @ 50.0 / dup 2.0 > if pop 2.0 then * toint value ! target @ "t/Attack" over over getstat value @ + dup -64 < if pop -64 then dup 64 > if pop 64 then setstat value @ 0 > if { target @ "'s attack power raised by " value @ dup float? if int then "!" }cat "PokeBattle" pretty tellhere then value @ 0 < if { target @ "'s attack power fell by " value @ dup float? if int then abs "!" }cat "PokeBattle" pretty tellhere then then subtype @ "Defense" smatch if factor @ toint value ! value @ stat @ 50.0 / dup 2.0 > if pop 2.0 then * toint value ! target @ "t/Defense" over over getstat value @ + dup -64 < if pop -64 then dup 64 > if pop 64 then setstat value @ 0 > if { target @ "'s defense power raised by " value @ dup float? if int then "!" }cat "PokeBattle" pretty tellhere then value @ 0 < if { target @ "'s defense power fell by " value @ dup float? if int then abs "!" }cat "PokeBattle" pretty tellhere then then subtype @ "Special" smatch if factor @ toint value ! value @ stat @ 50.0 / dup 2.0 > if pop 2.0 then * toint value ! target @ "t/Special" over over getstat value @ + dup -64 < if pop -64 then dup 64 > if pop 64 then setstat value @ 0 > if { target @ "'s special power rose by " value @ dup float? if int then "!" }cat "PokeBattle" pretty tellhere then value @ 0 < if { target @ "'s special power fell by " value @ dup float? if int then abs "!" }cat "PokeBattle" pretty tellhere then then subtype @ "Special-Def" smatch if factor @ toint value ! value @ stat @ 50.0 / dup 2.0 > if pop 2.0 then * toint value ! target @ "t/Special-Def" over over getstat value @ + dup -64 < if pop -64 then dup 64 > if pop 64 then setstat value @ 0 > if { target @ "'s special defense rose by " value @ dup float? if int then "!" }cat "PokeBattle" pretty tellhere then value @ 0 < if { target @ "'s special defense fell by " value @ dup float? if int then abs "!" }cat "PokeBattle" pretty tellhere then then subtype @ "SpecialDef" smatch if factor @ toint value ! value @ stat @ 50.0 / dup 2.0 > if pop 2.0 then * toint value ! target @ "t/Special-Def" over over getstat value @ + dup -64 < if pop -64 then dup 64 > if pop 64 then setstat value @ 0 > if { target @ "'s special defense rose by " value @ dup float? if int then "!" }cat "PokeBattle" pretty tellhere then value @ 0 < if { target @ "'s special defense fell by " value @ dup float? if int then abs "!" }cat "PokeBattle" pretty tellhere then then subtype @ "Accuracy" smatch if factor @ toint value ! value @ stat @ 50.0 / dup 2.0 > if pop 2.0 then * toint value ! target @ "t/Accuracy" over over getstat value @ + dup -64 < if pop -64 then dup 64 > if pop 64 then setstat value @ 0 > if { target @ "'s accuracy rose by " value @ dup float? if int then "!" }cat "PokeBattle" pretty tellhere then value @ 0 < if { target @ "'s accuracy fell by " value @ dup float? if int then abs "!" }cat "PokeBattle" pretty tellhere then then subtype @ "Speed" smatch if factor @ toint value ! value @ stat @ 50.0 / dup 2.0 > if pop 2.0 then * toint value ! target @ "t/Speed" over over getstat value @ + dup -64 < if pop -64 then dup 64 > if pop 64 then setstat value @ 0 > if { target @ "'s speed rose by " value @ dup float? if int then "!" }cat "PokeBattle" pretty tellhere then value @ 0 < if { target @ "'s speed fell by " value @ dup float? if int then abs "!" }cat "PokeBattle" pretty tellhere then then ( Status effects ) subtype @ "{Confuse|Freeze|Burn|Sleep|Poison|Paralyze|Flinch|Leech|Trap}" smatch if random 100 % dup tmp ! factor @ atoi < if subtype @ case "Confuse" smatch when target @ "status" 1 setstat target @ "statusfactor" random 4 % 2 + setstat { target @ " is confused! (" factor @ "/" tmp @ ")" }cat "PokeBattle" pretty tellhere end "Freeze" smatch when target @ "status" 2 setstat { target @ " is frozen! It wont be able to attack! (" factor @ "/" tmp @ ")" }cat "PokeBattle" pretty tellhere end "Burn" smatch when target @ "status" 3 setstat target @ "statusfactor" damage @ setstat { target @ " is burned! (" factor @ "/" tmp @ ")" }cat "PokeBattle" pretty tellhere end "Sleep" smatch when target @ "status" 4 setstat target @ "statusfactor" random 4 % 2 + setstat { target @ " has been put to sleep! (" factor @ "/" tmp @ ")" }cat "PokeBattle" pretty tellhere end "Paralyze" smatch when target @ "status" 5 setstat { target @ " is paralyzed! It may not be able to attacked! (" factor @ "/" tmp @ ")" }cat "Pokebattle" pretty tellhere end "Poison" smatch when target @ "status" 6 setstat target @ "statusfactor" damage @ setstat { target @ " is poisoned! (" factor @ "/" tmp @ ")" }cat "PokeBattle" pretty tellhere end "Flinch" smatch when { target @ " flinched! " me @ " gets to attack again! (" factor @ "/" tmp @ ")" }cat "Pokebattle" pretty tellhere end "Leech" smatch when target @ "status" 7 setstat target @ maxhp rawdmg @ toint 100.0 / * dup value ! target @ "statusfactor" value @ setstat target @ "statustarget" me @ setstat { target @ " is being leeched for " value @ " HP! (" damage @ "/" value @ ")" }cat "Pokebattle" pretty tellhere end "Trap" smatch when target @ "status" 8 setstat target @ "statusfactor" random 4 % 2 + setstat { target @ " has been trapped! (" factor @ "/" tmp @ ")" }cat "PokeBattle" pretty tellhere end endcase then then damage @ stat @ param @ attackfactor @ attacklevel @ ; PUBLIC attackhandler : dostab me @ "/@rp/pokemon" getprop "$pokedex" match swap "/pokemon/" swap strcat "/type" strcat getprop ":" explode array_make 0 swap foreach swap pop "$pokedex" match swap "/types/attack/byname/" swap strcat getprop metype @ stringcmp if else 1 break then repeat if else exit then pop .2 + "(STAB) Attack is the same type as the pokemon using it." "PokeBattle" pretty tellhere ; : doAddMulti attacklevel @ ":" explode array_make foreach swap pop dup string? if "-3" smatch if "-3" attacklevel ! exit then else pop then repeat thestat @ -3 < if "-3" attacklevel ! exit then thestat @ 3 > if "3" attacklevel ! exit then thestat @ intostr attacklevel ! ("DEBUG! " attacklevel @ strcat tellhere) ; : pokebattle ( -- ) var params var target var targettype var accuracy var critical var canattack var attackfactor var damage var critlevel var tmp var inlinemsg var status 0 dup stat ! value ! ( Stat handler. If it returns true, abort now. ) me @ stathandler if exit then param @ "=" explode params ! params @ 1 = if ( Using attack on myself ) param ! me @ target ! me @ "ts/lastmove" param @ setstat ( PP check ) me @ { "a/" param @ "/pp" }cat getstatint 0 <= if { "You are out of PP in the attack [" param @ "]." }cat "Battle" pretty tellme exit then ( Roll it ) me @ "a/" param @ strcat getstatint level toint 1 + nd6 stat ! ( Show it ) { me @ " rolled [^GREEN^" param @ "^NORMAL^]: ^CYAN^" stat @ " (" stat @ successlevel ")" }cat "PokeBattle" pretty tellhere ( Factor in any equip bonuses ) stat @ param @ isepic dup tmp ! + stat ! ( And if there were any show those ) tmp @ if { "[^GREEN^" param @ "^NORMAL^]: ^CYAN^" stat @ " (" stat @ successlevel ")" }cat "PokeBattle" pretty tellhere then 0 0 target @ 0 stat @ param @ attackhandler attacklevel ! attackfactor ! param ! stat ! damage ! ( Describe the attack ) { "attack/" param @ "/desc" }cat getdex tostr "PokeBattle" pretty tellme ( And take a PP away ) me @ { "a/" param @ "/pp" }cat me @ { "a/" param @ "/pp" }cat getstatint 1 - setstat then params @ 2 = if param ! target ! me @ "ts/lastmove" param @ setstat ( Using attack on someone else ) me @ { "a/" param @ "/pp" }cat getstatint 0 <= if { "You are out of PP in the attack [" param @ "]." }cat "PokeBattle" pretty tellme exit then ( Check for 'self' attacks ) ({ "attack/" param @ "/accuracy" }cat getdex tostr "--" smatch if { "You can only use this ability on yourself!" }cat "PokeBattle" pretty tellme exit then) ( Roll it ) me @ "a/" param @ strcat getstatint level toint 1 + nd6 stat ! ( If the target is not ok, roll it on myself ) target @ match target ! target @ ok? not if me @ target ! { me @ " rolled [^GREEN^" param @ "^NORMAL^]: ^CYAN^" stat @ " (" stat @ successlevel ")" }cat "PokeBattle" pretty tellhere ( Factor in any equip bonuses ) stat @ param @ isepic dup tmp ! + stat ! ( Show them if there are any ) tmp @ if { "[^GREEN^" param @ "^NORMAL^]: ^CYAN^" stat @ " (" stat @ successlevel ")" }cat "PokeBattle" pretty tellhere then ( Describe the attack ) { "attack/" param @ "/desc" }cat getdex tostr "PokeBattle" pretty tellme ( Else If the target is ok, roll it them ) else ( Show the roll ) { me @ " rolled [^GREEN^" param @ "^NORMAL^] against [^GREEN^" target @ "^NORMAL^]: ^CYAN^" stat @ " (" stat @ successlevel ")" }cat "PokeBattle" pretty tellhere ( Factor in any equip bonuses ) stat @ param @ isepic dup tmp ! + stat ! ( And show them, if any ) tmp @ if { "[^GREEN^" param @ "^NORMAL^]: ^CYAN^" stat @ " (" stat @ successlevel ")" }cat "PokeBattle" pretty tellhere then ( And compare the pokemon to see if its No effect, Not effective, normal or effective ) target @ "ts/type" getstatstr "0" smatch if { "Attack type [^GREEN^" { "attack/" param @ "/type" }cat getdex dup not if pop "Normal" then "^NORMAL^] " "against pokemon type [^GREEN^" { "pokemon/" target @ "pokemon" getstat "/type" }cat getdex "^NORMAL^] " }cat "PokeBattle" pretty tellhere "/types/attack/byname/" { "attack/" param @ "/type" }cat getdex dup not if pop "Normal" then strcat getdex metype ! "/types/attack/byname/" { "pokemon/" target @ "pokemon" getstat "/type" }cat getdex dup not if pop "Normal" then ":" explode array_make "" mytemp ! foreach swap pop swap dup rot strcat getdex mytemp @ swap ":" strcat strcat mytemp ! repeat mytemp @ targettype ! pop (type:type:type: setup for ttype) else { "Attack type [^GREEN^" { "attack/" param @ "/type" }cat getdex dup not if pop "Normal" then "^NORMAL^] " "against pokemon type [^GREEN^" target @ "ts/type" getstatstr "^NORMAL^] " }cat "PokeBattle" pretty tellhere "/types/attack/byname/" { "attack/" param @ "/type" }cat getdex dup not if pop "Normal" then strcat getdex metype ! "/types/attack/byname/" target @ "ts/type" getstatstr dup not if pop "Normal" then ":" explode array_make "" mytemp ! foreach swap pop swap dup rot strcat getdex mytemp @ swap ":" strcat strcat mytemp ! repeat mytemp @ targettype ! pop (type:type:type: setup for ttype) then ( Inline-Pre handler ) { "/attack/" param @ "/inline-pre" }cat getdex if param @ stat @ target @ metype @ targettype @ { "var! targettype var! metype var! target var! stat var! param \"\" var! inlinemsg " { "/attack/" param @ "/inline-pre" }cat getdex " inlinemsg @ param @ stat @ target @ metype @ targettype @ " }cat inline targettype ! metype ! target ! stat ! param ! inlinemsg ! inlinemsg @ if inlinemsg @ "PokeInline" pretty tellhere then then ( Test for a critical hit or a critical miss ) random 100 % me @ "Speed" getpokestat + target @ "Speed" getpokestat - int { "attack/" param @ "/accuracy" }cat getdex toint dup 0 = if pop 100 then 100 - + critlevel ! critlevel @ 10 <= if { target @ " evades! (" critlevel @ ")" }cat "Pokebattle" pretty tellhere ( And take a PP away ) me @ { "a/" param @ "/pp" }cat me @ { "a/" param @ "/pp" }cat getstatint 1 - setstat ( Inline-Post handler ) { "/attack/" param @ "/inline-post" }cat getdex if param @ stat @ target @ metype @ targettype @ { "var! targettype var! metype var! target var! stat var! param \"\" var! inlinemsg " { "/attack/" param @ "/inline-post" }cat getdex " inlinemsg @ param @ stat @ target @ metype @ targettype @ " }cat inline targettype ! metype ! target ! stat ! param ! inlinemsg ! inlinemsg @ if inlinemsg @ "PokeInline" pretty tellhere then then ( Handle type 12 statuses ) target @ "ts/defense" getstat if target @ "ts/defense" getstat status ! { "/attack/" status @ "/inline-defense" }cat getdex if param @ status @ target @ damage @ { "var! damage var! target var! status var! param \"\" var! inlinemsg " { "/attack/" status @ "/inline-defense" }cat getdex " inlinemsg @" }cat inline inlinemsg ! inlinemsg @ if { inlinemsg @ }cat "PokeInline" pretty tellhere then then then exit then critlevel @ 90 >= if { "Critical hit! (+" stat @ random critlevel @ 50 - % dup tmp ! + stat ! tmp @ ") (" critlevel @ ")" }cat "CritCheck" pretty tellhere then ( Do an accuracy test on the attack ) random 100 % me @ "Accuracy" getpokestat - critlevel ! critlevel @ { "attack/" param @ "/accuracy" }cat getdex toint dup 0 = if pop 100 then >= if { "Rolling 1d100 against " { "attack/" param @ "/accuracy" }cat getdex toint dup 0 = if pop 100 then "... Missed! (" critlevel @ int ") (Accuracy: " me @ "Accuracy" getpokestat int ")" }cat "PokeBattle" pretty tellhere ( And take a PP away ) me @ { "a/" param @ "/pp" }cat me @ { "a/" param @ "/pp" }cat getstatint 1 - setstat ( Inline-Post handler ) { "/attack/" param @ "/inline-post" }cat getdex if param @ stat @ target @ metype @ targettype @ { "var! targettype var! metype var! target var! stat var! param \"\" var! inlinemsg " { "/attack/" param @ "/inline-post" }cat getdex " inlinemsg @ param @ stat @ target @ metype @ targettype @ " }cat inline targettype ! metype ! target ! stat ! param ! inlinemsg ! inlinemsg @ if inlinemsg @ "PokeInline" pretty tellhere then then ( Handle type 12 statuses ) target @ "ts/defense" getstat if target @ "ts/defense" getstat status ! { "/attack/" status @ "/inline-defense" }cat getdex if param @ status @ target @ damage @ { "var! damage var! target var! status var! param \"\" var! inlinemsg " { "/attack/" status @ "/inline-defense" }cat getdex " inlinemsg @" }cat inline inlinemsg ! inlinemsg @ if { inlinemsg @ }cat "PokeInline" pretty tellhere then then then exit else { "Rolling 1d100 against " { "attack/" param @ "/accuracy" }cat getdex toint dup 0 = if pop 100 then "... Hit! (" critlevel @ int ") (Accuracy: " me @ "Accuracy" getpokestat int ")" }cat "PokeBattle" pretty tellhere then ( If this attack has no damage factor, indicate so ) { "attack/" param @ "/damage" }cat getdex tostr "--" smatch if "This attack does no damage." "PokeBattle" pretty tellhere ( Call the attackhandler ) attacklevel2 @ attackfactor @ target @ 0 stat @ param @ attackhandler attacklevel2 ! attackfactor ! param ! stat ! damage ! target @ "ts/lastdamage" 0 setstat ( or else lets do an attack by the attack type ) else ( Save the attack factor as a percentage ) { "attack/" param @ "/damage" }cat getdex toint attackfactor ! ( Damage modifiers ) target @ attackfactor @ param @ damagemodifiers attackfactor ! dup if "PokeBattle" pretty tellhere else pop then attackfactor @ 100.0 / attackfactor ! ( And the attack level as a string based number ) ( **BEGIN MULTITYPE CODE** ) ({ "/types/attack/" metype @ "/" targettype @ }cat getdex attacklevel !) (<-- Old code) "" mytemp ! targettype @ ":" explode depth rotate pop 1 - array_make (This will give us an array of all set types) foreach swap pop thestat ! { "/types/attack/" metype @ "/" thestat @ }cat getdex ":" strcat mytemp @ swap strcat mytemp ! repeat (This leaves the various numerical values in val:val:val: format) mytemp @ attacklevel ! attacklevel @ ":" explode depth rotate pop 1 - array_make 0 swap foreach swap pop atoi + repeat thestat ! doAddMulti ( ** END MULTITYPE CODE** ) ( No effect! ) attacklevel @ "-3" smatch if ( Calculate damage and store ) 0 damage ! { "It has no effect! ^Red^" damage @ "^ ^ damage. (Attack power is " attackfactor @ 100.0 * toint "%%)" }cat "PokeBattle" pretty tellhere then ( Its not very effective... ) attacklevel @ "-2" smatch if ( Calculate damage and store ) stat @ 0.25 dostab dup attacklevel2 ! random 50 % 100.0 / + * attackfactor @ * toint damage ! ( Call the attackhandler ) attacklevel2 @ attackfactor @ target @ damage @ stat @ param @ attackhandler attacklevel2 ! attackfactor ! param ! stat ! damage ! ( Display final call ) { "It's not very effective (x2), ^Red^" damage @ "^ ^ damage. (Attack power is " attackfactor @ 100.0 * toint "%%)" }cat "PokeBattle" pretty tellhere ( hurt them ) target @ 0 damage @ - adjusthp target @ "ts/lastdamage" damage @ setstat then ( Its not very effective... ) attacklevel @ "-1" smatch if ( Calculate damage and store ) stat @ 0.5 dostab dup attacklevel2 ! random 50 % 100.0 / + * attackfactor @ * toint damage ! ( Call the attackhandler ) attacklevel2 @ attackfactor @ target @ damage @ stat @ param @ attackhandler attacklevel2 ! attackfactor ! param ! stat ! damage ! ( Display final call ) { "It's not very effective, ^Red^" damage @ "^ ^ damage. (Attack power is " attackfactor @ 100.0 * toint "%%)" }cat "PokeBattle" pretty tellhere ( hurt them ) target @ 0 damage @ - adjusthp target @ "ts/lastdamage" damage @ setstat then ( Normal attack... ) attacklevel @ "0" smatch if ( Calculate damage and store ) stat @ 1 dostab dup attacklevel2 ! random 50 % 100.0 / + * attackfactor @ * toint damage ! ( Call the attackhandler ) attacklevel2 @ attackfactor @ target @ damage @ stat @ param @ attackhandler attacklevel2 ! attackfactor ! param ! stat ! damage ! ( Display final call ) { "Normal attack, ^Red^" damage @ "^ ^ damage. (Attack power is " attackfactor @ 100.0 * toint "%%)" }cat "PokeBattle" pretty tellhere ( hurt them ) target @ 0 damage @ - adjusthp target @ "ts/lastdamage" damage @ setstat then ( Its super-effective... ) attacklevel @ "1" smatch if ( Calculate damage and store ) stat @ 1.5 dostab dup attacklevel2 ! random 50 % 100.0 / + * attackfactor @ * toint damage ! ( Call the attackhandler ) attacklevel2 @ attackfactor @ target @ damage @ stat @ param @ attackhandler attacklevel2 ! attackfactor ! param ! stat ! damage ! ( Display final call ) { "It's super-effective! ^Red^" damage @ "^ ^ damage. (Attack power is " attackfactor @ 100.0 * toint "%%)" }cat "PokeBattle" pretty tellhere ( hurt them ) target @ 0 damage @ - adjusthp target @ "ts/lastdamage" damage @ setstat then ( Its super-effective... ) attacklevel @ "2" smatch if ( Calculate damage and store ) stat @ 2 dostab dup attacklevel2 ! random 50 % 100.0 / + * attackfactor @ * toint damage ! ( Call the attackhandler ) attacklevel2 @ attackfactor @ target @ damage @ stat @ param @ attackhandler attacklevel2 ! attackfactor ! param ! stat ! damage ! ( Display final call ) { "It's super-effective! (x2) ^Red^" damage @ "^ ^ damage. (Attack power is " attackfactor @ 100.0 * toint "%%)" }cat "PokeBattle" pretty tellhere ( hurt them ) target @ 0 damage @ - adjusthp target @ "ts/lastdamage" damage @ setstat then ( Its super-effective... ) attacklevel @ "3" smatch if ( Calculate damage and store ) stat @ 2.5 dostab dup attacklevel2 ! random 50 % 100.0 / + * attackfactor @ * toint damage ! ( Call the attackhandler ) attacklevel2 @ attackfactor @ target @ damage @ stat @ param @ attackhandler attacklevel2 ! attackfactor ! param ! stat ! damage ! ( Display final call ) { "It's super-effective! (x2.5) ^Red^" damage @ "^ ^ damage. (Attack power is " attackfactor @ 100.0 * toint "%%)" }cat "PokeBattle" pretty tellhere ( hurt them ) target @ 0 damage @ - adjusthp target @ "ts/lastdamage" damage @ setstat then then ( Describe the attack ) { "Notes on this attack: " { "attack/" param @ "/desc" }cat getdex tostr }cat "%%" "%" subst "PokeBattle" pretty tellhere then ( And take a PP away ) me @ { "a/" param @ "/pp" }cat me @ { "a/" param @ "/pp" }cat getstatint 1 - setstat ( Faint check ) target @ isfainted? if { target @ " has fainted!!!" }cat "PokeBattle" pretty tellhere then then ( Inline-Post handler ) { "/attack/" param @ "/inline-post" }cat getdex if param @ stat @ target @ metype @ targettype @ { "var! targettype var! metype var! target var! stat var! param \"\" var! inlinemsg " { "/attack/" param @ "/inline-post" }cat getdex " inlinemsg @ param @ stat @ target @ metype @ targettype @ " }cat inline targettype ! metype ! target ! stat ! param ! inlinemsg ! inlinemsg @ if inlinemsg @ "PokeInline" pretty tellhere then then ( Handle type 12 statuses ) target @ "ts/defense" getstat if target @ "ts/defense" getstat status ! { "/attack/" status @ "/inline-defense" }cat getdex if param @ status @ target @ damage @ { "var! damage var! target var! status var! param \"\" var! inlinemsg " { "/attack/" status @ "/inline-defense" }cat getdex " inlinemsg @" }cat inline inlinemsg ! inlinemsg @ if { inlinemsg @ }cat "PokeInline" pretty tellhere then then then ; PUBLIC pokebattle : coststr ( f -- s ) dup 0.001 = if pop "FREE " exit then dup -0.001 = if pop "FREE*" exit then dup -0.001 < if 2 fchop "*" strcat exit then 2 fchop " " strcat ; : pokestore ( -- ) var stat var value var icost var item var qty var target me @ location target ! me @ mon? if "Pokemon cant buy things at stores!" "Store" pretty tellme exit then command @ case "+store" stringcmp not when "^YELLOW^+--------------------------------+----------+----------+^NORMAL^" tellme "^YELLOW^|^NORMAL^Items available ^YELLOW^|^NORMAL^ Buy$ ^YELLOW^|^NORMAL^ Sell $ ^YELLOW^|^NORMAL^" tellme "^YELLOW^+--------------------------------+----------+----------+^NORMAL^" tellme target @ "@rp/m/" array_get_propvals foreach value ! stat ! { "^YELLOW^|^NORMAL^" stat @ 32 lj "^YELLOW^|^NORMAL^" value @ coststr 10 rj "^YELLOW^|^NORMAL^" value @ 2 / coststr 10 rj "^YELLOW^|^NORMAL^" }cat tellme repeat "^YELLOW^+--------------------------------+----------+----------+^NORMAL^" tellme end "+store/buy" stringcmp not when param @ "=" explode case 2 = when item ! toint qty ! end 1 = when item ! 1 qty ! end default "+store/buy [=]" "$" pretty tellme exit end endcase me @ target ! qty @ 1 < if "You cannot buy zero or negative amount of an item." "$" pretty tellme exit then me @ location "m/" item @ strcat getstatfloat icost ! icost @ 0 = if { "Item [" item @ "] not available in the store." }cat "$" pretty tellme exit then ( Handle free items ) icost @ -0.001 = if me @ "m/" item @ strcat -1 setstat { me @ " got item [^YELLOW^" item @ "^NORMAL^] for ^GREEN^FREE^NORMAL^ for unlimited use." }cat "$" pretty tellhere exit then icost @ 0.001 = if me @ "m/" item @ strcat getstatint 1 + me @ "m/" item @ strcat rot setstat { me @ " got item [^YELLOW^" item @ "^NORMAL^] for ^GREEN^FREE^NORMAL^." }cat "$" pretty tellhere exit then ( Handle items that manipulate money ) icost @ 0 < if ( Pay for unlimited use ) 0 icost @ - icost ! me @ "yen" getstatfloat icost @ >= if me @ "yen" getstatfloat icost @ - me @ swap "yen" swap setstat me @ "m/" item @ strcat -1 setstat { me @ " buys [^YELLOW^" item @ "^NORMAL^] for ^GREEN^$" icost @ qty @ * 2 fchop "^NORMAL^ for unlimited uses" }cat "$" pretty tellhere else { "You dont have enough yen! Cost: [$" icost @ qty @ * 2 fchop "]." }cat "$" pretty tellme then else ( pay per use ) me @ "yen" getstatfloat icost @ qty @ * >= if me @ "yen" getstatfloat icost @ qty @ * - me @ swap "yen" swap setstat me @ "m/" item @ strcat getstatint qty @ + me @ "m/" item @ strcat rot setstat { me @ " buys " qty @ " [^YELLOW^" item @ "^NORMAL^](s) for ^GREEN^$" icost @ qty @ * 2 fchop "^NORMAL^." }cat "$" pretty tellhere else { "You dont have enough yen! Cost: [$" icost @ qty @ * 2 fchop "]." }cat "$" pretty tellme then then end "+store/sell" stringcmp not when param @ "=" explode case 2 = when item ! toint qty ! end 1 = when item ! 1 qty ! end default "+store/sell [=]" "$" pretty tellme exit end endcase me @ target ! qty @ 1 < if "You cannot sell zero or negative amount of an item." "$" pretty tellme exit then me @ location "m/" item @ strcat getstatfloat icost ! icost @ 0 = if { "Item [" item @ "] not sellable in the store." }cat "$" pretty tellme exit then me @ "m/" item @ strcat getstatint if ( Handle free items ) icost @ 0.001 <= if me @ "m/" item @ strcat 0 setstat { me @ " trashes item [^YELLOW^" item @ "^NORMAL^]. (Sold for FREE)." }cat "$" pretty tellme exit then ( Handle items that manipulate money ) me @ "m/" item @ strcat getstatint qty @ >= if me @ "yen" getstatfloat icost @ qty @ * 2 / + me @ swap "yen" swap setstat me @ "m/" item @ strcat getstatint qty @ - me @ "m/" item @ strcat rot setstat { me @ " sells " qty @ " [^YELLOW^" item @ "^NORMAL^](s) for ^GREEN^$" icost @ qty @ * 2 / 2 fchop "^NORMAL^." }cat "$" pretty tellhere else { "You dont have enough of these!" }cat "$" pretty tellme then then end "+store/trash" stringcmp not when param @ item ! me @ "m/" item @ strcat getstatint 0 = if "None of that item to trash." "$" pretty tellme else me @ "m/" item @ strcat 0 setstat { "Item(s) " item @ " trashed." }cat "$" pretty tellme then end default "Invalid command." "Store" pretty tellme end endcase ; PUBLIC pokestore : pokeheal ( -- ) var target var stat var value param @ "" stringcmp not if me @ target ! else param @ pmatch target ! then target @ #-1 dbcmp if param @ match target ! target @ #-1 dbcmp if { "Target " param @ " not found." }cat "PokeHeal" pretty tellme exit then then target @ #-2 dbcmp if { "Target " param @ " matched more than once, be more specific." }cat "PokeHeal" pretty tellme exit then me @ "pokecenter" envstat toint not if "This isnt a PokeCenter!" "PokeHeal" pretty tellme exit then { "Welcome to our PokeCenter, " me @ ", would you like us to heal your pokemon?" }cat "PokeHeal" pretty tellhere { "We will need your pokemon (" target @ ") for a moment..." }cat "PokeHeal" pretty tellhere { "( Now healing " target @ "... )" }cat "PokeHeal" pretty tellhere target @ "hp" target @ maxhp setstat target @ "status" 0 setstat target @ "statusfactor" 0 setstat target @ "statustarget" 0 setstat target @ "@rp/a/" array_get_propvals foreach value ! stat ! target @ { "a/" stat @ "/pp" }cat { "attack/" stat @ "/pp" }cat getdex toint setstat repeat target @ "@rp/t/" array_get_propvals foreach value ! stat ! target @ { "t/" stat @ }cat 0 setstat repeat target @ "@rp/ts" remove_prop { "Your pokemon (" target @ ") are healed, please come again. Bye!" }cat "PokeHeal" pretty tellhere ; PUBLIC pokeheal : pokeown ( -- ) var source var target var tmp param @ "" stringcmp not if { "Format: " command @ " " }cat "PokeOwn" pretty tellme exit then command @ "+pokemon/trade" smatch if param @ "=" explode tmp ! tmp @ 2 = not if { "Format: " command @ " =" }cat "PokeOwn" pretty tellme exit then source ! target ! source @ tmp ! tmp @ pmatch source ! source @ #-1 dbcmp if tmp @ match source ! source @ #-1 dbcmp if { "Source " tmp @ " not found." }cat "PokeOwn" pretty tellme exit then then source @ #-2 dbcmp if { "Target " tmp @ " matched more than once, be more specific." }cat "PokeOwn" pretty tellme exit then target @ tmp ! tmp @ pmatch target ! target @ #-1 dbcmp if tmp @ match target ! target @ #-1 dbcmp if { "Target " param @ " not found." }cat "PokeOwn" pretty tellme exit then then target @ #-2 dbcmp if { "Target " tmp @ " matched more than once, be more specific." }cat "PokeOwn" pretty tellme exit then me @ { "p/" source @ name }cat getstat not if { "Gee, you dont own " source @ "!" }cat "PokeOwn" pretty tellme exit then target @ "p/" source @ name strcat source @ setstat source @ "q/" target @ name strcat target @ setstat source @ "q/" me @ name strcat 0 setstat me @ "p/" source @ name strcat 0 setstat { me @ " just traded " source @ " to " target @ "." }cat "PokeOwn" pretty tellhere { "pokemon/" source @ iam "/evomethod" }cat getdex tostr "Trade" smatch if { source @ " can evolve when traded! This, if you are trying to evolve this pokemon, occurs now." }cat "PokeOwn" pretty tellhere then exit then param @ pmatch target ! target @ #-1 dbcmp if param @ match target ! target @ #-1 dbcmp if { "Target " param @ " not found." }cat "PokeOwn" pretty tellme exit then then target @ #-2 dbcmp if { "Target " param @ " matched more than once, be more specific." }cat "Pokedex" pretty tellme exit then command @ "+pokemon/owner" smatch if target @ "p/" me @ name strcat me @ setstat me @ "q/" target @ name strcat target @ setstat { target @ " now owns you." }cat "PokeOwn" pretty tellme target @ { me @ " just let you own them." }cat "PokeOwn" pretty ansi_notify then command @ "+pokemon/leave" smatch if target @ "p/" me @ name strcat 0 setstat me @ "q/" target @ name strcat 0 setstat { "You just left " target @ "!" }cat "PokeOwn" pretty tellme target @ { me @ " just left you!" }cat "PokeOwn" pretty ansi_notify then command @ "+pokemon/disown" smatch if target @ "q/" me @ name strcat 0 setstat me @ "p/" target @ name strcat 0 setstat { "You just disowned " target @ "!" }cat "PokeOwn" pretty tellme target @ { me @ " just disowned you!" }cat "PokeOwn" pretty ansi_notify then ; PUBLIC pokeown : main pop ; . c q