$include $lib/stats $include $lib/bits $include $lib/rp $include $lib/rps $include $lib/pokedex $include $muf/inline $include $lib/rps $include $lib/alynna $include $lib/phoex $include $lib/quantum $def frand qfrand $def THISFACTOR "statusfactor/" status @ intostr strcat $def THISTARGET "statustarget/" status @ intostr strcat var attacklevel var attacklevel2 var attacktype var origtarget var param var origattack : naturalattack[ dbref:target str:attack -- boolean ] var result target @ iam target ! { "pokemon/" target @ "/attacks/" attack @ }cat getdex { "pokemon/" target @ "/machine/" attack @ }cat getdex or { "pokemon/" target @ "/tutor/" attack @ }cat getdex or { "pokemon/" target @ "/eggmove/" attack @ }cat getdex or result ! begin { "pokemon/" target @ "/evolvesfrom" }cat getdex target ! { "pokemon/byname/" target @ }cat getdex dup target ! if result @ { "pokemon/" target @ "/attacks/" attack @ }cat getdex or { "pokemon/" target @ "/machine/" attack @ }cat getdex or { "pokemon/" target @ "/tutor/" attack @ }cat getdex or { "pokemon/" target @ "/eggmove/" attack @ }cat getdex or result ! else break then repeat result @ ; $libdef addplayerinline : addplayerinline ( s:attack s:inline d:target -- ) var! targ "@rp/ts/inlines/" rot strcat targ @ swap rot setprop ; PUBLIC addplayerinline : isepic ( s i -- s i ) var value var stat var rollx var attacktype attacktype ! 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 { "types/attack/bynumber/" attacktype @ }cat getdex smatch if value @ level toint nd5 rollx ! { "Equipment '" stat @ "' enhanced attack '" target @ "'! (+" rollx @ ")" }cat "Equip" pretty rollx @ exit then then repeat "" 0 ; : assimilate[ ref:source ref:target -- ] ( Assimilate the DNA of a pokemon ) target @ "assimilation/" source @ pokenumber strcat "1" setstat ; : stathandler ( target.d -- abort?.i ) var target var status var factor var rtg var roll var halt var inlinemsg target ! ( Status ailments ) target @ "status" getstat toint status ! target @ THISFACTOR getstat toint factor ! target @ THISTARGET getstat dup if name rtg ! else pop then ( Non stacking statuses) ( Frozen ) status @ STATUS_FREEZE bitget if target @ dup "statusfactor/" STATUS_FREEZE intostr strcat getstat toint 1 - dup factor ! "statusfactor/" STATUS_FREEZE intostr strcat swap setstat factor @ if { target @ " is frozen! They cannot attack!" }cat "PokeBattle" pretty target @ tellthere 1 halt ! else target @ STATUS_FREEZE clearstatus { target @ " unfroze!" }cat "PokeBattle" pretty target @ tellthere then then ( Burn ) status @ STATUS_BURN bitget halt @ not and if target @ "statusfactor/" STATUS_BURN intostr strcat getstat toint factor ! random 20 % 90 + tofloat 100.0 / factor @ * 0 round ++ toint roll ! { target @ " is hurt by the burn! ^RED^" roll @ "^NORMAL^ damage!" }cat "PokeBattle" pretty target @ tellthere target @ 0 roll @ - adjusthp target @ isfainted? if { target @ " has fainted!" }cat "PokeBattle" pretty target @ tellthere 1 halt ! then then ( Sleep ) status @ STATUS_SLEEP bitget halt @ not and if target @ dup "statusfactor/" STATUS_SLEEP intostr strcat getstat toint 1 - dup factor ! "statusfactor/" STATUS_SLEEP intostr strcat swap setstat factor @ if param @ "=" explode -- dup if swap rot rot popn else pop then { "attack/" rot "/useduringsleep" }cat getdex not if { target @ " is asleep! They cannot attack!" }cat "PokeBattle" pretty target @ tellthere 1 halt ! else { target @ " is asleep!" }cat "PokeBattle" pretty target @ tellthere then else target @ STATUS_SLEEP clearstatus { target @ " woke up!" }cat "PokeBattle" pretty target @ tellthere then then ( Sleep only attacks ) status @ STATUS_SLEEP bitget not halt @ not and param @ "=" explode -- dup if swap rot rot popn else pop then { "attack/" rot "/useduringsleep" }cat getdex tostr "only" smatch and if "This attack may only be used while asleep!" "PokeBattle" pretty target @ tellthere 1 halt ! then ( Paralyze ) status @ STATUS_PARALYZE bitget halt @ not and if random 100 % 25 < if { target @ " is paralyzed! They cannot attack!" }cat "PokeBattle" pretty target @ tellthere 1 halt ! then then ( Poison ) status @ STATUS_POISON bitget halt @ not and if target @ "statusfactor/" STATUS_POISON intostr strcat getstat toint factor ! random 20 % 90 + tofloat 100.0 / factor @ * 0 round ++ toint roll ! { target @ " is hurt by the poison! ^RED^" roll @ "^NORMAL^ damage!" }cat "PokeBattle" pretty target @ tellthere target @ 0 roll @ - adjusthp target @ isfainted? if { target @ " has fainted!" }cat "PokeBattle" pretty target @ tellthere then then ( Stacking conditions ) ( Confuse ) status @ COND_CONFUSED bitget halt @ not and if target @ dup "statusfactor/" COND_CONFUSED intostr strcat getstat toint 1 - dup factor ! "statusfactor/" COND_CONFUSED intostr strcat swap setstat factor @ if random 100 % 50 < if random target @ "attack" getpokestat 16 / toint % ++ roll ! target @ { target @ " is confused! %S hurt %r in the confusion! ^RED^" roll @ "^NORMAL^ damage!" }cat pronoun_sub "PokeBattle" pretty target @ tellthere target @ 0 roll @ - adjusthp target @ isfainted? if { target @ " has fainted!" }cat "PokeBattle" pretty target @ tellthere then 1 halt ! else { target @ " is confused!" }cat "PokeBattle" pretty target @ tellthere then else target @ COND_CONFUSED clearstatus { target @ " is confused no more!" }cat "PokeBattle" pretty target @ tellthere then then ( Leech ) status @ COND_LEECH bitget halt @ not and if target @ "statusfactor/" COND_LEECH intostr strcat getstat toint factor ! target @ "statustarget/" COND_LEECH intostr strcat getstat rtg ! { target @ " is being leeched! ^RED^" factor @ "^NORMAL^ HP was sent to " rtg @ }cat "PokeBattle" pretty target @ tellthere target @ 0 factor @ - adjusthp target @ isfainted? if { target @ " has fainted!" }cat "PokeBattle" pretty target @ tellthere pop 1 then rtg @ factor @ adjusthp then ( Trap ) status @ COND_TRAP bitget halt @ not and if target @ "statusfactor/" COND_TRAP intostr strcat over over getstat toint 1 - dup factor ! setstat factor @ if { target @ " is trapped! ^RED^" random 20 % 90 + tofloat 100 / factor @ * 0 round toint ++ dup roll ! "^NORMAL^ damage!" }cat "PokeBattle" pretty target @ tellthere target @ 0 roll @ - adjusthp target @ isfainted? if { target @ " has fainted!" }cat "PokeBattle" pretty target @ tellthere 1 halt ! then else target @ COND_TRAP clearstatus { target @ " is no longer trapped!" }cat "PokeBattle" pretty target @ tellthere then then status @ COND_CHARM bitget halt @ not and if target @ "statustarget/" COND_CHARM intostr strcat getstat dup rtg ! isfainted? not if random 100 % 50 < if { target @ " is totally taken by " rtg @ "'s charm, and doesnt attack!" }cat "PokeBattle" pretty target @ tellthere 1 halt ! then else target @ COND_CHARM clearstatus { rtg @ " has fainted! " target @ " is no longer charmed by " rtg @ }cat "PokeBattle" pretty target @ tellthere then then ( Fainted ) status @ STATUS_FAINTED bitget halt @ not and if { 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 @ tellthere 1 halt ! then ( Handle type 13 statuses ) target @ "ts/status" getstat halt @ not and 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 target @ tellthere then then then halt @ ; 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 ! ({ "types/attack/bynumber/" attacktype @ }cat getdex attacktype !) { "attack/" attack @ "/class" }cat getdex attacktype ! attacktype @ case "physical" smatch when (physical) me @ "Attack" getpokestat tmp1 ! target @ "Defense" getpokestat tmp2 ! message @ if { "Physical damage mods: Original(" orig @ "%) + (" message @ " = " tmp1 @ tmp2 @ - toint "% damage modifier) = new target " damage @ toint "% damage." }cat message ! then end "special" smatch when (special) me @ "Special" getpokestat tmp1 ! target @ "Special-Def" getpokestat tmp2 ! message @ if { "Special damage mods: Original(" orig @ "%) + (" message @ " = " tmp1 @ tmp2 @ - toint "% damage modifier) = new target " damage @ toint "% damage." }cat message ! then end default (other,none) me @ "Attack" getpokestat tmp1 ! target @ "Defense" getpokestat tmp2 ! me @ "Special" getpokestat tmp1 @ + 2 / tmp1 ! target @ "Special-Def" getpokestat tmp2 @ + 2 / tmp2 ! message @ if { "Other damage mods: Original(" orig @ "%) + (" message @ " = " tmp1 @ tmp2 @ - toint "% damage modifier) = new target " damage @ toint "% damage." }cat message ! then pop end endcase damage @ tmp1 @ tmp2 @ - level 2 * nd5 + damage ! me @ "xp" getstat level nd5 3 / dup damage @ > if damage ! else pop 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 target @ tellthere ) damage @ morphpower @ * damage ! then me @ mon? if me @ wild? if "$pokedex" match "wildmon-power" getstat morphpower ! ( { me @ " is a wild-pokemon, attack power is reduced by " 1 morphpower @ - 100 * "%." }cat "PokeBattle" pretty target @ tellthere ) damage @ morphpower @ * damage ! else "$pokedex" match "mon-power" getstat morphpower ! ( { me @ " is a pokemon, attack power is reduced by " 1 morphpower @ - 100 * "%." }cat "PokeBattle" pretty target @ tellthere ) damage @ morphpower @ * damage ! then 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 target @ tellthere ) damage @ morphpower @ * damage ! then me @ attack @ naturalattack not me @ "origpokemon" getstatint 132 = me @ "freebies/speciesmorph" getstatint or and if "$pokedex" match "ditto-power" getstat morphpower ! damage @ morphpower @ * damage ! { me @ " is using a ditto attack, attack power is reduced by " 1 morphpower @ - 100 * "%." }cat "PokeBattle" pretty target @ tellthere 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 stattarget var subtype var factor var value var attackfactor var attacklevel var chance var statuschance "" var! inlinemsg param ! stat ! damage ! target ! attackfactor ! attacklevel ! { "attack/" param @ "/statchance" }cat getdex toint dup not if pop 100 then chance ! { "attack/" param @ "/statuschance" }cat getdex toint dup not if pop 100 then statuschance ! { "attack/" param @ "/subtype" }cat getdex tostr subtype ! { "attack/" param @ "/factor" }cat getdex tostr factor ! { "attack/" param @ "/stattarget" }cat getdex if me @ stattarget ! else target @ stattarget ! then ( begin handling ) target @ damage @ param @ damagemodifiers toint damage ! pop ( Inline handler ) { "/attack/" param @ "/inline" }cat getdex if origattack @ param @ stat @ damage @ target @ origtarget @ subtype @ factor @ attackfactor @ attacklevel2 @ { "var! attacklevel var! attackfactor var! factor var! subtype var! origtarget var! target var! damage var! stat var! param var! origattack \"\" var! inlinemsg " { "/attack/" param @ "/inline" }cat getdex " inlinemsg @ param @ stat @ damage @ target @ subtype @ factor @ attackfactor @ attacklevel @" }cat inline attacklevel2 ! attackfactor ! factor ! subtype ! target ! damage ! stat ! param ! inlinemsg ! inlinemsg @ if inlinemsg @ "PokeInline" pretty target @ tellthere then then { "attack/" param @ "/stattarget" }cat getdex dup string? if "self" smatch else pop 0 then if me @ stattarget ! then random 100 % chance @ <= if ( learn handler ) subtype @ "*{Assimilate}*" smatch if me @ "/@Rp/assimilation/" array_get_propvals array_count me @ "freebies/speciesmorph" getstatint 3 * me @ "origpokemon" getstatint 132 = if 12 + then < if target @ "origpokemon" getstat toint 132 = target @ "c/speciesmorph" getstat or not target @ owner me @ dbcmp not or if target @ me @ assimilate { me @ " just assimilated " target @ "'s genetic code!" }cat "PokeBattle" pretty target @ tellthere else { me @ " cannot assimilate" target @ "'s genetic code!" }cat "PokeBattle" pretty target @ tellthere then else { me @ " cannot learn any new forms!" }cat "Assimilation" pretty target @ tellthere then then ( tempstat handler ) subtype @ "*{Attack|Defense|Special|Special-Def|Accuracy|EVADE|Speed}*" smatch if factor @ toint value ! value @ stat @ 40.0 / dup 2.5 > if pop 2.5 then * toint value ! ( Removed Stat Caps stattarget @ "xp" getstat level -10 * var! minval stattarget @ "xp" getstat level 5 * var! maxval ) -999 var! minval 999 var! maxval then subtype @ "*{Attack}*" smatch if stattarget @ "t/Attack" over over getstat value @ + dup minval @ < if pop minval @ { stattarget @ "'s Attack cannot fall any further!" }cat "PokeBattle" pretty stattarget @ tellthere then dup maxval @ > if pop maxval @ { stattarget @ "'s Attack cannot rise any further!" }cat "PokeBattle" pretty stattarget @ tellthere then setstat value @ 0 > if { stattarget @ "'s attack power raised by " value @ dup float? if toint then "!" }cat "PokeBattle" pretty stattarget @ tellthere then value @ 0 < if { stattarget @ "'s attack power fell by " value @ dup float? if toint then abs "!" }cat "PokeBattle" pretty stattarget @ tellthere then then subtype @ "*{Defense}*" smatch if stattarget @ "t/Defense" over over getstat value @ + dup minval @ < if pop minval @ { stattarget @ "'s Defense cannot fall any further!" }cat "PokeBattle" pretty stattarget @ tellthere then dup maxval @ > if pop maxval @ { stattarget @ "'s Defense cannot rise any further!" }cat "PokeBattle" pretty stattarget @ tellthere then setstat value @ 0 > if { stattarget @ "'s defense power raised by " value @ dup float? if toint then "!" }cat "PokeBattle" pretty stattarget @ tellthere then value @ 0 < if { stattarget @ "'s defense power fell by " value @ dup float? if toint then abs "!" }cat "PokeBattle" pretty stattarget @ tellthere then then subtype @ "*{Special}*" smatch if stattarget @ "t/Special" over over getstat value @ + dup minval @ < if pop minval @ { stattarget @ "'s Special cannot fall any further!" }cat "PokeBattle" pretty stattarget @ tellthere then dup maxval @ > if pop maxval @ { stattarget @ "'s Special cannot rise any further!" }cat "PokeBattle" pretty stattarget @ tellthere then setstat value @ 0 > if { stattarget @ "'s special power rose by " value @ dup float? if toint then "!" }cat "PokeBattle" pretty stattarget @ tellthere then value @ 0 < if { stattarget @ "'s special power fell by " value @ dup float? if toint then abs "!" }cat "PokeBattle" pretty stattarget @ tellthere then then subtype @ "*{Special-Def}*" smatch if stattarget @ "t/Special-Def" over over getstat value @ + dup minval @ < if pop minval @ { stattarget @ "'s Special-Def cannot fall any further!" }cat "PokeBattle" pretty stattarget @ tellthere then dup maxval @ > if pop maxval @ { stattarget @ "'s Special-Def cannot rise any further!" }cat "PokeBattle" pretty stattarget @ tellthere then setstat value @ 0 > if { stattarget @ "'s special defense rose by " value @ dup float? if toint then "!" }cat "PokeBattle" pretty stattarget @ tellthere then value @ 0 < if { stattarget @ "'s special defense fell by " value @ dup float? if toint then abs "!" }cat "PokeBattle" pretty stattarget @ tellthere then then subtype @ "*{Accuracy}*" smatch if stattarget @ "t/Accuracy" over over getstat value @ + dup minval @ < if pop minval @ { stattarget @ "'s Accuracy cannot fall any further!" }cat "PokeBattle" pretty stattarget @ tellthere then dup maxval @ > if pop maxval @ { stattarget @ "'s Accuracy cannot rise any further!" }cat "PokeBattle" pretty stattarget @ tellthere then setstat value @ 0 > if { stattarget @ "'s accuracy rose by " value @ dup float? if toint then "!" }cat "PokeBattle" pretty stattarget @ tellthere then value @ 0 < if { stattarget @ "'s accuracy fell by " value @ dup float? if toint then abs "!" }cat "PokeBattle" pretty stattarget @ tellthere then then subtype @ "*{Evade}*" smatch if stattarget @ "t/Evade" over over getstat value @ + dup minval @ < if pop minval @ { stattarget @ "'s Evasion cannot fall any further!" }cat "PokeBattle" pretty stattarget @ tellthere then dup maxval @ > if pop maxval @ { stattarget @ "'s Evasion cannot rise any further!" }cat "PokeBattle" pretty stattarget @ tellthere then setstat value @ 0 > if { stattarget @ "'s evasion rose by " value @ dup float? if toint then "!" }cat "PokeBattle" pretty stattarget @ tellthere then value @ 0 < if { stattarget @ "'s evasion fell by " value @ dup float? if toint then abs "!" }cat "PokeBattle" pretty stattarget @ tellthere then then subtype @ "*{Speed}*" smatch if stattarget @ "t/Speed" over over getstat value @ + dup minval @ < if pop minval @ { stattarget @ "'s Speed cannot fall any further!" }cat "PokeBattle" pretty stattarget @ tellthere then dup maxval @ > if pop maxval @ { stattarget @ "'s Speed cannot rise any further!" }cat "PokeBattle" pretty stattarget @ tellthere then setstat value @ 0 > if { stattarget @ "'s speed rose by " value @ dup float? if toint then "!" }cat "PokeBattle" pretty stattarget @ tellthere then value @ 0 < if { stattarget @ "'s speed fell by " value @ dup float? if toint then abs "!" }cat "PokeBattle" pretty stattarget @ tellthere then then subtype @ "*{Critical}*" smatch if factor @ toint value ! "Critical" { value @ " critadjst ! " }cat stattarget @ addplayerinline { stattarget @ " had their critical hit chance raised!" }cat "PokeBattle" pretty stattarget @ tellthere then then ( Status effects ) random 100 % statuschance @ toint <= if subtype @ "*{Confuse|Freeze|Burn|Sleep|Poison|Paralyze|Flinch|Leech|Trap}*" smatch target @ "ts/substitute" getstat not and if subtype @ case "*Confuse*" smatch if stattarget @ COND_CONFUSED setstatus stattarget @ { "statusfactor/" COND_CONFUSED }join random 4 % 2 + setstat { stattarget @ " is confused!" }cat "PokeBattle" pretty stattarget @ tellthere then dup "*Freeze*" smatch if stattarget @ STATUS_FREEZE setstatus stattarget @ { "statusfactor/" STATUS_FREEZE }join random 4 % 2 + setstat { stattarget @ " is frozen! It wont be able to attack!" }cat "PokeBattle" pretty stattarget @ tellthere then dup "*Burn*" smatch if var statreduce stattarget @ "status" getstatint STATUS_BURN bitget not if stattarget @ "Attack" getplainstat 2 / toint statreduce ! stattarget @ "t/Attack" over over getstat statreduce @ - setstat { stattarget @ " had its attack reduced by " statreduce @ "!" }cat "PokeBattle" pretty stattarget @ tellthere then stattarget @ STATUS_BURN setstatus stattarget @ { "statusfactor/" STATUS_BURN }join stattarget @ "Max-hp" getplainstat 8 / "attack/" param @ strcat "/subfactor" strcat getdex toint dup if else pop 1 then * setstat { stattarget @ " is burned!" }cat "PokeBattle" pretty stattarget @ tellthere then dup "*Sleep*" smatch if stattarget @ STATUS_SLEEP setstatus stattarget @ { "statusfactor/" STATUS_SLEEP }join random 4 % 2 + setstat { stattarget @ " has been put to sleep!" }cat "PokeBattle" pretty stattarget @ tellthere then dup "*Paralyze*" smatch if var statreduce stattarget @ "status" getstatint STATUS_PARALYZE bitget not if stattarget @ "Speed" getplainstat 2 / toint statreduce ! stattarget @ "t/Speed" over over getstat statreduce @ - setstat { stattarget @ " had its speed reduced by " statreduce @ "!" }cat "PokeBattle" pretty stattarget @ tellthere then stattarget @ STATUS_PARALYZE setstatus { stattarget @ " is paralyzed! It may not be able to attack!" }cat "PokeBattle" pretty stattarget @ tellthere then dup "*Poison*" smatch if stattarget @ STATUS_POISON setstatus stattarget @ { "statusfactor/" STATUS_POISON }join stattarget @ "Max-hp" getplainstat 8 / "attack/" param @ strcat "/subfactor" strcat getdex toint dup if else pop 1 then * setstat { stattarget @ " is poisoned!" }cat "PokeBattle" pretty stattarget @ tellthere then dup "*Flinch*" smatch if stattarget @ COND_FLINCH setstatus { "^Red^" stattarget @ " flinched! " me @ " gets to attack again!" }cat "PokeBattle" pretty stattarget @ tellthere then dup "*Leech*" smatch if stattarget @ COND_LEECH setstatus stattarget @ "Max-hp" getplainstat 16 / toint value ! stattarget @ { "statusfactor/" COND_LEECH }join value @ setstat stattarget @ { "statusstattarget/" COND_LEECH }join me @ setstat { stattarget @ " is being leeched for " value @ " HP! " }cat "PokeBattle" pretty stattarget @ tellthere then dup "*Trap*" smatch if stattarget @ COND_TRAP setstatus stattarget @ { "statusfactor/" COND_TRAP }join random 4 % 2 + setstat { stattarget @ " has been trapped!" }cat "PokeBattle" pretty stattarget @ tellthere then dup endcase then subtype @ "*{Charm}*" smatch if me @ "gender" getstatstr capitalize 1 strcut pop var! cmpme stattarget @ "gender" getstatstr capitalize 1 strcut pop var! 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 stattarget @ COND_CHARM setstatus stattarget @ { "statustarget/" COND_CHARM }join me @ setstat { stattarget @ " has been charmed by " me @ "!" }cat "PokeBattle" pretty stattarget @ tellthere then then then damage @ attackfactor @ * toint damage ! damage @ stat @ param @ attackfactor @ attacklevel @ ; PUBLIC attackhandler : dostab me @ "ts/type" getstat dup if tostr else pop me @ "/@rp/pokemon" getprop "$pokedex" match swap "/pokemon/" swap strcat "/type" strcat getprop then ":" explode array_make 0 swap foreach swap pop "$pokedex" match swap "/types/attack/byname/" swap strcat getprop attacktype @ stringcmp if else 1 break then repeat if else exit then pop .5 + "(STAB) Attack is the same type as the pokemon using it." "PokeBattle" pretty tellhere ; : doAddMulti[ str:targettype -- str:attacklevel ] var resistlevel "" var! resistarray targettype @ ":" explode depth rotate pop 1 - array_make (This will give us an array of all set types) foreach swap pop targettype ! { "/types/attack/" attacktype @ "/" targettype @ }cat getdex ":" strcat resistarray @ swap strcat resistarray ! repeat (This leaves the various numerical values in val:val:val: format) resistarray @ ":" explode depth rotate pop 1 - array_make 0 swap foreach swap pop atoi + repeat resistlevel ! resistarray @ ":" explode array_make foreach swap pop dup string? if "-3" smatch if -3 resistlevel ! break then else pop then repeat resistlevel @ -3 < if "-3" resistlevel ! then resistlevel @ 3 > if "3" resistlevel ! then { "/attack/" param @ "/typeless" }cat getdex resistlevel @ -3 != and if 0 resistlevel ! then resistlevel @ intostr ("DEBUG! " attacklevel @ strcat target @ tellthere) ; : targetcheck[ x:target -- dbref:result ] #-1 var! result target @ dbref? not if target @ match if target @ match target ! then then target @ if target @ player? target @ .puppet? or if target @ awake? if target @ result ! then else target @ me @ location dbcmp if target @ result ! then then then result @ ; : PokeBattle ( -- ) (IC Idle timer set) me @ "@rp/ICtime/2" over "@rp/ICtime/1" getprop setprop me @ "@rp/ICtime/1" systime setprop me @ "@rp/ICtime/diff" me @ "@rp/ICtime/1" getprop me @ "@rp/ICtime/2" getprop - param @ strlen 7 / - setprop var targetarray var accuracy var attackfactor var critadjst var critlevel var critstat var critvalue var damage var inlinemsg var initattackfactor var initstat var params var rollx var stat var status var target var targettype var equip var type var value 0 dup stat ! value ! ( Check targets ) param @ "=" explode params ! params @ 1 < if "You must specify a target!" "PokeBattle" pretty tellme then params @ 1 = if param ! "me" targetarray ! then params @ 1 > if param ! params @ -- array_make targetarray ! then param @ origattack ! ( Housekeeping ) me @ { "a/" param @ "/pp" }cat getstatint 0 <= if { "You are out of PP in the attack [" param @ "]." }cat "PokeBattle" pretty tellme exit then { "attack/" param @ "/xp" }cat getdex toint me @ { "a/" param @ }cat getstatint > if { "You do not have enough xp in the attack [" param @ "]." }cat "PokeBattle" pretty tellme exit then ( Player Inline list handler ) me @ "@rp/ts/inlines" array_get_propvals foreach swap pop { "var critadjst \"\" var! inlinemsg " rot " critadjst @ inlinemsg @" }cat inline inlinemsg ! critadjst ! inlinemsg @ if inlinemsg @ "PokeInline" pretty tellhere then repeat ( Critical Equipment handler ) me @ "@rp/e/" array_get_propvals foreach critvalue ! critstat ! { "item/" critstat @ "/type" }cat getdex tostr "Equip" smatch if { "item/" critstat @ "/subtype" }cat getdex tostr "*{Critical}*" smatch if { "item/" critstat @ "/factor" }cat getdex toint dup not if pop 1 then critvalue @ level toint 2 + * rollx ! { "Equipment '" critstat @ "' enhanced critical '" critadjst @ "'! (+" rollx @ ")" }cat "Equip" pretty equip ! break then then repeat rollx @ 0 > if critadjst @ + critadjst ! then ( Stat handler. If it returns true, abort now. ) me @ stathandler if exit then me @ "ts/lastmove" param @ setstat ( And take a PP away ) me @ { "a/" param @ "/pp" }cat me @ { "a/" param @ "/pp" }cat getstatint 1 - setstat ( Sleep talk ) param @ "Sleep Talk" smatch if me @ "@rp/a/" array_get_propdirs dup "Sleep Talk" array_findval 0 array_getitem array_delitem SORTTYPE_SHUFFLE array_sort 0 array_getitem param ! { me @ " used Sleep Talk! Attacked with " param @ }cat "PokeBattle" pretty tellhere then ( Roll initial damage ) me @ "ts/attacks/" param @ strcat getstatint if me @ "ts/attacks/" param @ strcat getstatint level toint 1 + nd4 initstat ! else 1 var! xpvalue me @ "ts/xp" getstatint tofloat me @ "xp" getstatint tofloat / 0 = if me @ "a/" param @ strcat getstatint level toint xpvalue ! else me @ "ts/xp" getstatint 6 / dup 100 < if pop 100 then xpvalue ! me @ "a/" param @ strcat getstatint xpvalue @ < if me @ "a/" param @ strcat getstatint level xpvalue ! else xpvalue @ level toint xpvalue ! { param @ " is pulled back to level " xpvalue @ "!" }cat "PokeBattle" pretty tellhere then then xpvalue @ 1 + nd4 initstat ! then ( Metronome ) param @ "metronome" smatch if var currattack { }array var! attacklist "$pokedex" match "attack/" array_get_propdirs foreach currattack ! pop { "attack/" currattack @ "/randomexclude" }cat getdex not if currattack @ attacklist @ array_appenditem attacklist ! then repeat attacklist @ SORTTYPE_SHUFFLE array_sort 0 array_getitem param ! { me @ " used Metronome! Attacked with " param @ }cat "PokeBattle" pretty tellhere then ( Check for attack scope) { "attack/" param @ "/target" }cat getdex "user" smatch if "me" 1 array_make targetarray ! then { "attack/" param @ "/target" }cat getdex "enemy" smatch if targetarray @ 0 array_getitem 1 array_make targetarray ! then { "attack/" param @ "/target" }cat getdex "others" smatch if { }array targetarray ! me @ location contents_array foreach swap pop dup dup dup player? swap .puppet? or swap "~status" getprop tostr "IIC" smatch and if dup dup me @ dbcmp not swap awake? and if targetarray @ array_appenditem targetarray ! else pop then else pop then repeat targetarray @ not if "me" 1 array_make targetarray ! then targetarray @ array_count 1 > if initstat @ 2 / initstat ! then then ( Attack type ) "/types/attack/byname/" { "attack/" param @ "/type" }cat getdex dup not if pop "Normal" then strcat getdex attacktype ! ( Factor in any equip bonuses ) initstat @ param @ attacktype @ isepic swap equip @ if equip @ "\n" strcat swap strcat then equip ! + initstat ! { "attack/" param @ "/damage" }cat getdex initattackfactor ! targetarray @ foreach initstat @ stat ! initattackfactor @ attackfactor ! target ! pop ( If the target is not ok, continue with next target ) target @ targetcheck dup if target ! else pop { "Target: \'" target @ "\' not found" }cat "PokeBattle" pretty tellme continue then target @ origtarget ! target @ COND_FLINCH clearstatus ( Show the attack name and target ) { me @ " rolled [^GREEN^" param @ "^NORMAL^] against [^GREEN^" target @ "^NORMAL^]: ^CYAN^" stat @ " (" stat @ successlevel ")" }cat "PokeBattle" pretty target @ tellthere ( Show equipment bonuses, if any ) equip @ if equip @ target @ tellthere then ( Notify attack types and target type) target @ "ts/type" getstat if target @ "ts/type" getstatstr type ! else { "pokemon/" target @ "pokemon" getstat "/type" }cat getdex type ! then { "Attack type [^GREEN^" { "attack/" param @ "/type" }cat getdex dup not if pop "Normal" then "^NORMAL^], " "class [^GREEN^" { "attack/" param @ "/class" }cat getdex dup not if pop "Normal" then "^NORMAL^] " "against pokemon type [^GREEN^" type @ "^NORMAL^], " { "attack/" param @ "/contact?" }dex "y*" smatch if "^RED^Attack requires contact." else "^BLUE^Attack does not require contact." then }cat "PokeBattle" pretty target @ tellthere ( Compare the pokemon to see if its No effect, Not effective, normal or effective ) type @ dup not if pop "Normal" then ":" explode array_make "" targettype ! foreach swap pop "/types/attack/byname/" swap strcat getdex ":" strcat targettype @ swap strcat targettype ! repeat (type:type:type: setup for ttype) ( Inline-Pre handler ) { "/attack/" param @ "/inline-pre" }cat getdex if param @ stat @ attackfactor @ target @ attacktype @ targettype @ { "var! targettype var! attacktype var! target var! attackfactor var! stat var! param \"\" var! inlinemsg " { "/attack/" param @ "/inline-pre" }cat getdex " inlinemsg @ param @ stat @ attackfactor @ target @ attacktype @ targettype @ " }cat inline targettype ! attacktype ! target ! attackfactor ! stat ! param ! inlinemsg ! inlinemsg @ if inlinemsg @ "PokeInline" pretty target @ tellthere then param @ "then" smatch if continue then param @ "end" smatch if exit then then ( Test for a critical hit or a critical miss ) { "/attack/" param @ "/critadjust" }cat getdex toint critadjst @ + critadjst ! random 100 % toint dup critlevel ! critadjst @ 50 > if 50 critadjst ! then critlevel @ critadjst @ + critlevel ! { "attack/" param @ "/target" }cat getdex "user" smatch if 50 critlevel ! then critlevel @ 90 >= if { "Critical hit! (+" stat @ critlevel @ 8 / toint nd5 100 + 100 / * stat ! ") (" critlevel @ ")" }cat "CritCheck" pretty target @ tellthere then ( Do an accuracy test on the attack ) random 100 % target @ "speed" getpokestat me @ "speed" getpokestat { "/attack/" param @ "/class" }cat getdex "{physical|other|none}" smatch if me @ "attack" getpokestat then { "/attack/" param @ "/class" }cat getdex "{special|other|none}" smatch if me @ "special" getpokestat then { "/attack/" param @ "/class" }cat getdex "{other|none}" smatch if + 2.0 / then + 2 / - level 1.5 * + me @ "t/accuracy" getstat 4 / target @ "t/evade" getstat 4 / - dup -80 < if pop -80 then - critlevel ! { "attack/" param @ "/target" }cat getdex "user" smatch if { "attack/" param @ "/accuracy" }cat getdex toint -- critlevel ! then critlevel @ toint { "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 @ toint ")" }cat "PokeBattle" pretty target @ tellthere ( Inline-Post handler ) { "/attack/" param @ "/inline-post" }cat getdex if param @ stat @ target @ attacktype @ targettype @ { "var! targettype var! attacktype var! target var! stat var! param \"\" var! inlinemsg \"1\" var! missed " { "/attack/" param @ "/inline-post" }cat getdex " inlinemsg @ param @ stat @ target @ attacktype @ targettype @ " }cat inline targettype ! attacktype ! target ! stat ! param ! inlinemsg ! inlinemsg @ if inlinemsg @ "PokeInline" pretty target @ tellthere 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 ! then inlinemsg @ if { inlinemsg @ }cat "PokeInline" pretty target @ tellthere then then target @ "ts/lastdamage" damage @ setstat continue then { "Rolling 1d100 against " { "attack/" param @ "/accuracy" }cat getdex toint dup 0 = if pop 100 then "... Hit! (" critlevel @ toint ")" }cat "PokeBattle" pretty target @ tellthere ( If this attack has no damage factor, indicate so ) attackfactor @ toint dup attackfactor ! not if "This attack does no damage." "PokeBattle" pretty target @ tellthere ( 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 ) ( Damage modifiers ) attackfactor @ 100.0 / attackfactor ! ( And the attack level as a string based number ) targettype @ doAddMulti attacklevel ! ( 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 target @ tellthere else ( Its not very effective... ) attacklevel @ "-2" smatch if ( Calculate damage and store ) "It's not very effective (x2)^Red^" 0.5 then ( Its not very effective... ) attacklevel @ "-1" smatch if ( Calculate damage and store ) "It's not very effective, ^Red^" 0.7071 then ( Normal attack... ) attacklevel @ "0" smatch if ( Calculate damage and store ) "Normal attack, ^Red^" 1 then ( Its super-effective... ) attacklevel @ "1" smatch if ( Calculate damage and store ) "It's super-effective! ^Red^" 1.4142 then ( Its super-effective... ) attacklevel @ "2" smatch if ( Calculate damage and store ) "It's super-effective! (x2) ^Red^" 2 then ( Its super-effective... ) attacklevel @ "3" smatch if { "It's super-effective! (x2.5) ^Red^" 2.5 then dostab attacklevel2 ! stat @ attacklevel2 @ random 20 % 100.0 / + * toint damage ! ( Call the attackhandler ) attacklevel2 @ attackfactor @ target @ damage @ stat @ param @ attackhandler attacklevel2 ! attackfactor ! param ! stat ! damage ! ( Display final call ) { swap damage @ "^ ^ damage. (Attack power is " attackfactor @ 100.0 * toint "%)" }cat "PokeBattle" pretty target @ tellthere ( hurt them ) target @ "ts/substitute" getstat if target @ "ts/substitute" getstatint damage @ - dup 0 < if pop 0 then target @ "ts/substitute" rot setstat { "Damage hit the substitute, it is at " target @ "ts/substitute" getstat "hp!" }cat "PokeBattle" pretty target @ tellthere else target @ 0 damage @ - adjusthp then target @ "ts/lastdamage" damage @ setstat then ( Describe the attack ) { "Notes on this attack: " { "attack/" param @ "/desc" }cat getdex tostr }cat "PokeBattle" pretty target @ tellthere ( 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 target @ tellthere then then then ( Inline-Post handler ) { "/attack/" param @ "/inline-post" }cat getdex if param @ stat @ target @ attacktype @ targettype @ { "var! targettype var! attacktype var! target var! stat var! param \"\" var! inlinemsg \"\" var! missed " { "/attack/" param @ "/inline-post" }cat getdex " inlinemsg @ param @ stat @ target @ attacktype @ targettype @ " }cat inline targettype ! attacktype ! target ! stat ! param ! inlinemsg ! inlinemsg @ if inlinemsg @ "PokeInline" pretty target @ tellthere then then then ( Faint check ) target @ isfainted? if { target @ " has fainted!!!" }cat "PokeBattle" pretty target @ tellthere then repeat ; PUBLIC PokeBattle $libdef PokeBattle : main param ! command @ "{+roll|+check}" smatch if PokeBattle exit then ;