############ GENERAL SETTINGS ############ default_manual_training = true show_more = false use_animations = beam autofight_stop = 70 explore_delay = 1 note_messages += magical essence is drained by the effort ######AUTOPICKUP###### ae := autopickup_exceptions # nullifying the effect of the most annoying 0.24 commit: ae += >ring of (poi|resist cor|fli|see) ae += >amulet of (the acr|fai|the gou|gua|har|mag|rag|ref|reg) ae += >scrolls? of (amn|noise) ae += >wand of rand ae += >ring of (protection from (mag|fire|cold)|mag|ste|ice|fire|pos|wil|wiz) ae += >ring of (dex|int|str) ae ^= staff of ######DROP FILTER###### df := drop_filter df += brilliance df += degeneration df += torment df += amnesia df += ring of positive energy df += ring of magical power df += amulet of magic regeneration df += ring of flight df += wand of charming df += wand of iceblast df += wand of paralysis df += wand of disintegration ############ AUTO INSCRIBES ############ ai := autoinscribe ai += scrolls? of identify:@r1 ai += scrolls? of fog:@r2 ai += scrolls? of teleportation:@r3 ai += scrolls? of blinking:@r4 ai += scrolls? of revelation:@r5 ai += potions? of heal wounds:@q1 ai += potions? of curing:@q2 ai += potions? of might:@q3 ai += potions? of haste:@q5 ai += potions? of berserker rage:@q6 ai += potion of blood:@q9 ai += scrolls? of vulnerability:!r ai += scrolls? of silence:!r ai += scrolls? of summoning:!r ai += staff of conjuration:!a ai += staff of wizardry:Wiz, !a ai += staff of air:rElec !a ai += staff of fire:rF+ !a ai += staff of cold:rC+ !a ai += staff of death:rN+ !a ai += staff of poison:rPois !a item_slot ^= wand of digging:v item_slot ^= wand of acid:c item_slot ^= wand of quicksilver:c item_slot ^= wand of light:c item_slot ^= wand of iceblast:i item_slot ^= wand of roots:i item_slot ^= (condenser vane):V item_slot ^= (tremorstone):B item_slot ^= (lightning rod):R item_slot ^= (box of the beasts):C item_slot ^= (sack of spiders):C ############ FORCE MORES ############ ## General ## more := force_more_message : if you.race == "Mummy" or you.race == "Ghoul" : or you.race == "Vampire" or you.race == "Demonspawn" then more += wielding .*holy : end more += Your body becomes as fragile as glass! more += malevolent more += Your transformation has ended more += You feel weirdly uncertain more += You occasionally lose the ability to read scrolls when taking damage more += You feel firmly anchored in space more += You feel a little pissed off more += You are yanked towards a nearby monster! more += You are yanked towards some nearby monsters! more += You feel more firmly anchored in space more += Found a gateway leading deeper into the Abyss more += A sentinel's mark forms upon you more += You lose the ability to read scrolls when threatened more += You stop ascending the stairs more += wielding .*distort more += watched by something more += mighty Pandemonium lord more += calcifying dust hits you more += you have finished your manual of more += crystal spear hits you more += you have mastered more += feel a terrible chill more += strangely unstable more += power of zot more += expect to remain undetected more += your icy armour evaporates more += come back to life more += revert to your normal more += enter a teleport trap more += Vehumet offers you more += You fall through a shaft more += Your time is quickly running out! more += It guards the demonic rune of Zot more += You turn into a (bat|filthy swine|insubstantial wisp|sentient fungus) ## Enemies entering LOS ## more += guardian serpent.*come more += orbs? of fire .*come more += curse toe.*come more += greater mumm.*come more += hell sentinel.*come more += curse skull.*come more += ghost moth.*come more += swamp worm bursts forth more += floating eye.*come more += zenata.*(comes? into view|opens the). more += parghit.*(comes? into view|opens the). more += josephina.*(comes? into view|opens the). more += vv.*(comes? into view|opens the). more += lodul.*(comes? into view|opens the). more += amaemon.*(comes? into view|opens the). more += Agnes.*(comes? into view|opens the). more += Aizul.*(comes? into view|opens the). more += Antaeus.*(comes? into view|opens the). more += Asmodeus.*(comes? into view|opens the). more += Asterion.*(comes? into view|opens the). more += Azrael.*(comes? into view|opens the). more += Blork the orc.*(comes? into view|opens the). more += Boris.*(comes? into view|opens the). more += Cerebov.*(comes? into view|opens the). more += Dispater.*(comes? into view|opens the). more += Dissolution.*(comes? into view|opens the). more += Donald.*(comes? into view|opens the). more += Dowan.*(comes? into view|opens the). more += Duvessa.*(comes? into view|opens the). more += Edmund.*(comes? into view|opens the). more += Ereshkigal.*(comes? into view|opens the). more += Erica.*(comes? into view|opens the). more += Erolcha.*(comes? into view|opens the). more += Eustachio.*(comes? into view|opens the). more += Fannar.*(comes? into view|opens the). more += Frances.*(comes? into view|opens the). more += Frederick.*(comes? into view|opens the). more += Gastronok.*(comes? into view|opens the). more += Gloorx Vloq.*(comes? into view|opens the). more += Grinder.*(comes? into view|opens the). more += Grum.*(comes? into view|opens the). more += Harold.*(comes? into view|opens the). more += Ignacio.*(comes? into view|opens the). more += Ijyb.*(comes? into view|opens the). more += Ilsuiw.*(comes? into view|opens the). more += Jessica.*(comes? into view|opens the). more += Jorgrun.*(comes? into view|opens the). more += Joseph.*(comes? into view|opens the). more += Josephine.*(comes? into view|opens the). more += Jory.*(comes? into view|opens the). more += Jozef.*(comes? into view|opens the). more += Khufu.*(comes? into view|opens the). more += Kirke.*(comes? into view|opens the). more += Lom Lobon.*(comes? into view|opens the). more += Louise.*(comes? into view|opens the). more += Mara.*(comes? into view|opens the). more += Mioglotl.*(comes? into view|opens the). more += Maggie.*(comes? into view|opens the). more += Margery.*(comes? into view|opens the). more += Maurice.*(comes? into view|opens the). more += Menkaure.*(comes? into view|opens the). more += Mennas.*(comes? into view|opens the). more += Mnoleg.*(comes? into view|opens the). more += Murray.*(comes? into view|opens the). more += Nergalle.*(comes? into view|opens the). more += Nessos.*(comes? into view|opens the). more += Nikola.*(comes? into view|opens the). more += Norris.*(comes? into view|opens the). more += Pikel.*(comes? into view|opens the). more += Polyphemus.*(comes? into view|opens the). more += Prince Ribbit.*(comes? into view|opens the). more += Psyche.*(comes? into view|opens the). more += Purgy.*(comes? into view|opens the). more += Robin.*(comes? into view|opens the). more += Rupert.*(comes? into view|opens the). more += Saint Roka.*(comes? into view|opens the). more += Sigmund.*(comes? into view|opens the). more += Snorg.*(comes? into view|opens the). more += Sonja.*(comes? into view|opens the). more += Terence.*(comes? into view|opens the). more += The Lernaean hydra.*(comes? into view|opens the). more += The royal jelly.*(comes? into view|opens the). more += The Serpent of Hell.*(comes? into view|opens the). more += Tiamat.*(comes? into view|opens the). more += Urug.*(comes? into view|opens the). more += Xtahua.*(comes? into view|opens the). : if you.xl() <= 7 then more += is wielding .*elec #more += orc priest.*come : end : if you.xl() <= 11 then more += two-headed ogre.*come : end : if you.xl() <= 16 then more += sorcerer.*come more += ogre mage.*come : end : if you.xl() <= 18 then more += (a|2|3|4|5|6|7|8|9) wizard.*come more += occultist.*come : end : if you.xl() <= 22 then more += wielding .*distortion more += demonologist.*come ai += weapon .*distort:!w : end : if you.race() == ("Demonspawn" or "Mummy" or "Vampire" or "Ghoul") then more += wielding .*holy : end { function c_answer_prompt(prompt) if prompt:find("vortices") or prompt:find("vortex") or prompt:find("battlesphere") or prompt:find("servitor") or prompt:find("scarab") then return true end if prompt:find("Really.*into that cloud of flame?") and you.res_fire() == 3 then return true end if prompt:find("Really.*into that cloud of freezing vapour?") and you.res_cold() == 3 then return true end if not target and (prompt:find("Really target yourself") or prompt:find("Really fire in your ally")) then crawl.mpr("사격 м·Ём†Њ лђЁ.") return false end end } ############ ITEM AND SPELL SLOTS ############# #islot := item_slot #sslot := spell_slot ## Scrolls ## #islot += scrolls? of identify:+i #islot += scrolls? of remove curse:+r #islot += scrolls? of blinking:+x #islot += scrolls? of teleport:+t #islot += scrolls? of summoning:+s ## Potions ## #islot += potions? of curing:+c #islot += potions? of heal:+h #islot += potions? of haste:+f #islot += potions? of cancel:+l #islot += potions? of blood:+q ## Rings ## #islot += ring of protection from fire:+F #islot += ring of protection from cold:+C #islot += ring of poison resistance:+P #islot += ring of corrosion resistance:+R #islot += ring of protection from magic:+M #islot += ring of see invis:+Z #islot += ring of evasion:+E #islot += ring of protection:+A spell_slot += Airstrike:aAeEiIrRsStTkK spell_slot += Alistair's intoxication:aiAIsnSNlLtToOxXcCrR spell_slot += Animate armour:aAerERnNimIMoOuUtT spell_slot += Animate dead:adADeEnNiImMtT spell_slot += Apportation:aAnNpPoOrRtTiI spell_slot += Blink:bBkKlLiInN spell_slot += Borgnjor's revivification:brBRsnSNoeOEvVgiGIjJfFcCaAtT spell_slot += Borgnjor's vile clutch:bvcBVCsehSEHoilOILruRUgtGTnNjJ spell_slot += Call canine familiar:cfCFlerLERaAnmNMiI spell_slot += Call imp:ciCIlpLPamAM spell_slot += Cause fear:cfCFerERaAuUsS spell_slot += Chain lightning:clCLngNGhiHIaAtT spell_slot += Confusing touch:ctCTghGHoOnuNUfFsSiI spell_slot += Conjure ball lightning:cblCBLegEGoaiOAInNjhJHutUTrR spell_slot += Conjure flame:cfCFeEolOLnaNAjmJMuUrR spell_slot += Dazzling flash:dfDFghGHalALzZsSiInN spell_slot += Death channel:dcDChlHLeEaAtnTN spell_slot += Death's door:dDsrSReoEOaAtThH spell_slot += Discord:dDiIsScCoOrR spell_slot += Disjunction:JdDnNiIsSjJuUcCtToO spell_slot += Dispel undead:duDUlLinINsSpePEaA spell_slot += Dispersal:dDlLiIsSpPeErRaA spell_slot += Dragon's call:dcDCslSLraRAgGoOnN spell_slot += Ensorcelled hibernation:ehEHdnDNiIsbSBoOrRcCaAltLT spell_slot += Eringya's noxious bog:enbENBsgSGroROixIXyuYUaA spell_slot += Fire storm:fsFSemEMitITroRO spell_slot += Fireball:fFlLiIrReEbBaA spell_slot += Foxfire:fFeEoOxXiIrR spell_slot += Freeze:fFeErRzZ spell_slot += Freezing cloud:fcFCgdGDrlRLeoEOuUzZiInN spell_slot += Frozen ramparts:frFRnsNSaAomOMzpZPeEtT spell_slot += Fulminant prism:fpFPtmTMurURliLIsSnNaA spell_slot += Gell's gravitas:gGsSerERlaLAvViItT spell_slot += Hailstorm:hHmMaAiIlLsStToOrR spell_slot += Haunt:hHtTaAuUnN spell_slot += Ignite poison:ipIPenENgoGOsStT spell_slot += Ignition:iInNgGtToO spell_slot += Infestation:iInNfFeEsStTaAoO spell_slot += Inner flame:ifIFreREnlNLaAmM spell_slot += Irradiate:iIeErRaAdDtT spell_slot += Iskenderun's battlesphere:ibIBseSEaAktKTnlNLdDrpRPuhUH spell_slot += Iskenderun's mystic blast:imbIMBsctSCTylYLkaKAeEnNdDrRuU spell_slot += Leda's liquefaction:lLsnSNeiEIdqDQauAUfFcCtToO spell_slot += Lee's rapid deconstruction:lrdLRDsnSNeaEApcPCioIOtTuU spell_slot += Lehudib's crystal spear:lcsLCSrRepEPhyHYuaUAdtDTiIbB spell_slot += Lesser beckoning:lbLBrgRGeEscSCkKoOnNiI spell_slot += Lightning bolt:lbLBgtGTioIOhHnN spell_slot += Magic dart:mdMDctCTaAgrGRiI spell_slot += Malign gateway:mgMGnyNYaAltLTieIEwW spell_slot += Manifold assault:maMAdtDTsSnNiIfuFUolOL spell_slot += Maxwell's capacitive coupling:mcMCsegSEGaoAOxpuXPUwWlLiItnTNvV spell_slot += Mephitic cloud:mcMCdDelELpoPOhuHUiItT spell_slot += Metabolic englaciation:meMEcnCNtgTGalALbBoOiI spell_slot += Monstrous menagerie:mMseSEoOnNaAtgTGrRuiUI spell_slot += Olgreb's toxic radiance:otrOTRsceSCElaLAgxdGXDiIbnBN spell_slot += Orb of destruction:odODbnBNreREsStTuUcCiI spell_slot += Ozocubu's armour:oaOAsrSRzZmMcCuUbB spell_slot += Ozocubu's refrigeration:orORsnSNzeZEfFcCuiUIbgBGaAtT spell_slot += Passage of golubria:pgPGeaEAoOslSLuUbBrRiI spell_slot += Passwall:pPlLaAsSwW spell_slot += Petrify:pPyYeEtTrRiIfF spell_slot += Poisonous vapours:pvPVsSoaOAiIuUnrNR spell_slot += Polar vortex:pvPVrxRXoOlLatATeE spell_slot += Sandblast:sStTaAnNdDbBlL spell_slot += Searing ray:srSRgyGYeaEAiInN spell_slot += Shatter:sSrRhHaAtTeE spell_slot += Shock:sSkKhHoOcC spell_slot += Silence:sSeEiIlLnNcC spell_slot += Slow:sSwWlLoO spell_slot += Spellforged servitor:sSdrDRpePElvLViIftFToOgG spell_slot += Spider form:sfSFrmRMpoPOiIdDeE spell_slot += Starburst:sStTaArRbBuU spell_slot += Static discharge:sdSDceCEtiTIaAhHrRgG spell_slot += Sticky flame:sfSFyeYEtlTLiaIAcmCMkK spell_slot += Sting:sSgGtTiInN spell_slot += Stone arrow:saSAewEWtrTRoOnN spell_slot += Sublimation of blood:sbSBndNDulULoOiImMaAtT spell_slot += Summon forest:sfSFntNTuoUOmrMReE spell_slot += Summon horrible things:shtSHTneNEuoUOmriMRIgGbBlL spell_slot += Summon hydra:shSHnaNAuyUYmdMDrRoO spell_slot += Summon ice beast:sibSIBnetNETucUCmaMAoO spell_slot += Summon lightning spire:slSLngeNGEuipUIPmMhrHRotOT spell_slot += Summon mana viper:smvSMVnarNARuiUIpPeEoO spell_slot += Summon small mammal:smSMnlNLuaUAoO spell_slot += Swiftness:sSwWiIfFtTnNeE spell_slot += Teleport other:toTOrReElhLHpP spell_slot += Tukima's dance:tdTDseSEuaUAknKNicICmM spell_slot += Vampiric draining:vdVDcgCGarARmMpiPInN spell_slot += Yara's violent unravelling:yvuYVUstgSTGainAINroROlLeE ######MACROS AND KEYMAPS###### show_more = false macros += M 1 ===bonsai_smart_cast { local monster_ac={["adder"]=1,["jelly"]=0,["Tiamat"]=30,["Sonja"]=2,["jumping spider"]=6,["spatial vortex"]=0,["formicid"]=3,["queen bee"]=10,["acid dragon"]=5,["rime drake"]=3,["dwarf"]=2,["centaur"]=3,["orb of destruction"]=0,["deep elf zephyrmancer"]=0,["hobgoblin"]=2,["Amaemon"]=3,["deep troll shaman"]=6,["shadow imp"]=3,["human"]=3,["eldritch tentacle segment"]=13,["twister"]=0,["bat"]=1,["glowing shapeshifter"]=0,["Bai Suzhen"]=14,["golden dragon"]=15,["draconian annihilator"]=-1,["ophan"]=10,["white draconian"]=9,["death knight"]=2,["radroach"]=13,["Rupert"]=0,["sky beast"]=3,["ballistomycete spore"]=0,["black mamba"]=4,["the Serpent of Hell"]=30,["Gloorx Vloq"]=10,["Roxanne"]=20,["withered plant"]=0,["white imp"]=4,["Grinder"]=3,["thermic dynamo"]=4,["deep elf sorcerer"]=0,["spectral thing"]=8,["deep elf blademaster"]=0,["bunyip"]=6,["flayed ghost"]=0,["kraken"]=20,["bone dragon"]=20,["bombardier beetle"]=4,["tentacle segment"]=5,["shard shrike"]=2,["yaktaur"]=4,["alligator"]=4,["the Royal Jelly"]=8,["emperor scorpion"]=18,["snake"]=0,["curse skull"]=35,["tentacle"]=5,["Gastronok"]=2,["small abomination"]=0,["minotaur"]=6,["acid blob"]=1,["deep elf master archer"]=0,["orange demon"]=3,["Executioner"]=10,["naga"]=6,["frilled lizard"]=0,["oni"]=1,["Louise"]=0,["Murray"]=30,["water elemental"]=4,["bound soul"]=8,["culicivora"]=2,["mummy priest"]=8,["green draconian"]=9,["tentacled starspawn"]=5,["faun"]=2,["fire crab"]=9,["yaktaur captain"]=5,["pandemonium lord"]=1,["servant of whispers"]=1,["komodo dragon"]=7,["occultist"]=0,["goliath frog"]=3,["hydra"]=0,["hellwing"]=16,["Mara"]=10,["orc"]=0,["dream sheep"]=2,["wolf"]=4,["gargoyle"]=18,["Urug"]=2,["Norris"]=1,["ribbon worm"]=1,["Sojobo"]=2,["boggart"]=0,["skyshark"]=6,["Maggie"]=0,["reaper"]=15,["Lom Lobon"]=10,["large simulacrum"]=10,["small zombie"]=0,["satyr"]=2,["fire vortex"]=0,["ancient champion"]=15,["mutant beast"]=8,["demigod"]=2,["snapping turtle"]=16,["hell hound"]=6,["spark wasp"]=9,["deep troll earth mage"]=12,["draconian"]=10,["deep elf death mage"]=0,["manticore"]=5,["sun demon"]=10,["giant cockroach"]=3,["starspawn tentacle"]=8,["spriggan air mage"]=1,["ice dragon"]=10,["halazid warlock"]=8,["laughing skull"]=4,["will-o-the-wisp"]=4,["very ugly thing"]=6,["Duvessa"]=2,["Ijyb"]=2,["hell lord"]=0,["quicksilver dragon"]=10,["entropy weaver"]=7,["Natasha"]=2,["deep elf high priest"]=3,["ghost moth"]=8,["balrug"]=5,["hellion"]=5,["fire elemental"]=4,["dire elephant"]=13,["silent spectre"]=5,["chaos spawn"]=4,["hell rat"]=7,["walking divine tome"]=10,["fungus"]=0,["Sigmund"]=0,["training dummy"]=0,["demonspawn warmonger"]=3,["foxfire"]=0,["molten gargoyle"]=14,["water moccasin"]=2,["starcursed mass"]=10,["Josephine"]=0,["ogre mage"]=1,["merfolk siren"]=4,["draconian stormcaller"]=0,["polar bear"]=7,["demonspawn corrupter"]=3,["Psyche"]=0,["harpy"]=2,["inugami"]=5,["angel"]=10,["quasit"]=5,["Parghit"]=1,["moth"]=0,["eleionoma"]=2,["spectral weapon"]=5,["Zenata"]=10,["sixfirhy"]=2,["royal mummy"]=10,["orc knight"]=2,["blazeheart golem"]=9,["merfolk avatar"]=4,["vault guard"]=1,["halfling"]=2,["orb of fire"]=20,["iron elemental"]=20,["ancient lich"]=20,["curse toe"]=25,["demonspawn blood saint"]=6,["tengu conjurer"]=2,["boulder"]=10,["orc sorcerer"]=5,["Vv"]=27,["purple draconian"]=9,["guardian mummy"]=6,["draconian monk"]=-3,["eidolon"]=12,["sphinx"]=5,["ynoxinul"]=3,["fire bat"]=1,["ironbound frostheart"]=0,["death drake"]=6,["shadow"]=3,["stone giant"]=12,["wight"]=4,["bloated husk"]=5,["ironbound preserver"]=0,["wyvern"]=5,["broodmother"]=2,["frost giant"]=9,["water nymph"]=2,["hog"]=2,["Mnoleg"]=11,["Nessos"]=4,["mummy"]=3,["armataur"]=15,["Agnes"]=0,["sea snake"]=2,["iron imp"]=6,["golem"]=0,["smoke demon"]=5,["daeva"]=10,["iron golem"]=25,["Grum"]=2,["Mennas"]=15,["ghoul"]=4,["formless jellyfish"]=0,["animated tree"]=0,["pillar of salt"]=1,["lava snake"]=2,["shadow demon"]=7,["lightning spire"]=13,["merfolk javelineer"]=0,["merfolk impaler"]=0,["deep elf demonologist"]=0,["sickly merfolk siren"]=4,["sacred lotus"]=24,["tyrant leech"]=5,["phantasmal warrior"]=12,["djinni"]=5,["naga mage"]=6,["Polyphemus"]=10,["quokka"]=2,["ball lightning"]=0,["deathcap"]=5,["snaplasher vine segment"]=6,["Terence"]=0,["fire dragon"]=10,["hornet"]=6,["wendigo"]=4,["lich"]=10,["briar patch"]=10,["kobold demonologist"]=2,["naga ritualist"]=6,["fire giant"]=8,["Ignacio"]=10,["bennu"]=6,["Crazy Yiuf"]=2,["ufetubus"]=2,["malarious merfolk avatar"]=4,["giant"]=0,["grey draconian"]=16,["hell hog"]=2,["living spell"]=0,["shambling mangrove"]=13,["sleepcap"]=5,["bullfrog"]=0,["death yak"]=9,["Dissolution"]=10,["the Lernaean hydra"]=0,["ballistomycete"]=1,["walking frostbound tome"]=10,["elemental wellspring"]=8,["Jory"]=10,["deep elf annihilator"]=0,["iron giant"]=18,["spriggan"]=1,["pale draconian"]=9,["Joseph"]=0,["ancient zyme"]=6,["Chuck"]=14,["nargun"]=25,["ironbound convoker"]=0,["kobold blastminer"]=4,["peacekeeper"]=20,["dragon"]=0,["deep elf knight"]=0,["small simulacrum"]=10,["shock serpent"]=2,["protean progenitor"]=7,["Margery"]=0,["animated armour"]=8,["Lodul"]=3,["snaplasher vine"]=4,["mana viper"]=3,["goblin"]=0,["imperial myrmidon"]=1,["tengu reaver"]=2,["deep elf elementalist"]=0,["worldbinder"]=12,["orc warrior"]=0,["Frederick"]=0,["Jessica"]=0,["elephant slug"]=2,["moon troll"]=20,["Pikel"]=4,["starspawn tentacle segment"]=8,["Azrael"]=10,["draconian scorcher"]=-1,["Asmodeus"]=30,["seraph"]=10,["soul eater"]=18,["great orb of eyes"]=10,["crystal guardian"]=20,["Khufu"]=10,["salamander"]=5,["golden eye"]=0,["orange crystal statue"]=12,["caustic shrike"]=8,["two-headed ogre"]=3,["rust devil"]=10,["Maurice"]=1,["Nellie"]=13,["naga warrior"]=6,["plant"]=0,["floating eye"]=0,["orc wizard"]=1,["revenant"]=8,["ice beast"]=5,["death cob"]=10,["holy swine"]=2,["fenstrider witch"]=3,["thrashing horror"]=5,["meliai"]=2,["drowned soul"]=0,["demonspawn"]=3,["glowing orange brain"]=2,["war gargoyle"]=25,["pearl dragon"]=10,["spriggan berserker"]=2,["spriggan druid"]=1,["Prince Ribbit"]=0,["vault sentinel"]=1,["Cloud Mage"]=0,["vine stalker"]=2,["Kirke"]=0,["green death"]=5,["centaur warrior"]=4,["basilisk"]=3,["dancing weapon"]=10,["tainted leviathan"]=15,["draconian knight"]=9,["orc warlord"]=3,["raiju"]=4,["diamond obelisk"]=12,["warg"]=9,["electric golem"]=5,["Nergalle"]=9,["fulminant prism"]=3,["scrub nettle"]=8,["martyred shade"]=0,["ugly thing"]=4,["demonspawn black sun"]=9,["Vashnia"]=6,["giant lizard"]=0,["ice devil"]=12,["orc priest"]=1,["Saint Roka"]=3,["storm dragon"]=13,["eldritch tentacle"]=13,["crystal echidna"]=10,["burial acolyte"]=0,["Robin"]=1,["tormentor"]=12,["Jorgrun"]=2,["ironbound thunderhulk"]=1,["glass eye"]=2,["Fannar"]=4,["toenail golem"]=8,["block of ice"]=15,["Hellbinder"]=0,["red devil"]=7,["ancestor"]=5,["giant frog"]=0,["Killer Klown"]=10,["necromancer"]=0,["meteoran"]=2,["torpor snail"]=8,["electric eel"]=1,["juggernaut"]=20,["hell beast"]=5,["apocalypse crab"]=11,["red draconian"]=9,["tengu warrior"]=2,["rat"]=1,["guardian serpent"]=6,["large zombie"]=8,["Arachne"]=3,["creeping inferno"]=0,["spectator"]=0,["slime creature"]=1,["felid"]=2,["merfolk aquamancer"]=0,["demonic plant"]=0,["doom hound"]=6,["earth elemental"]=14,["merfolk"]=4,["iron dragon"]=20,["Blork the orc"]=0,["elephant"]=8,["cacodemon"]=11,["orc high priest"]=1,["hell knight"]=0,["lemure"]=4,["gnoll sergeant"]=2,["shadow dragon"]=15,["Snorg"]=0,["weeping skull"]=7,["Xtahua"]=18,["phantom"]=3,["Ice Fiend"]=15,["antique champion"]=20,["Aizul"]=8,["spellforged servitor"]=10,["crimson imp"]=3,["Ilsuiw"]=5,["hexer"]=5,["river rat"]=5,["yellow draconian"]=9,["titan"]=10,["wolf spider"]=3,["small skeleton"]=0,["Orb Guardian"]=13,["naga sharpshooter"]=6,["vault warden"]=1,["ball python"]=0,["steam dragon"]=5,["salamander tyrant"]=5,["swamp worm"]=3,["Frances"]=0,["battlemage"]=5,["death scarab"]=7,["black bear"]=2,["quicksilver ooze"]=3,["arcanist"]=0,["freezing wraith"]=12,["yak"]=4,["Jeremiah"]=2,["deep elf pyromancer"]=0,["jackal"]=2,["spriggan rider"]=1,["insubstantial wisp"]=0,["necrophage"]=2,["tentacled monstrosity"]=5,["efreet"]=10,["saltling"]=15,["nameless horror"]=8,["lost soul"]=0,["octopode"]=1,["Nikola"]=1,["Edmund"]=0,["ragged hierophant"]=0,["strange machine"]=12,["unseen horror"]=5,["spriggan defender"]=3,["dread lich"]=20,["hound"]=2,["nagaraja"]=6,["Brimstone Fiend"]=15,["jiangshi"]=10,["large skeleton"]=0,["elemental"]=0,["alligator snapping turtle"]=19,["vampire mage"]=10,["drake"]=0,["catoblepas"]=10,["tarantella"]=3,["lindwurm"]=8,["putrid mouth"]=5,["Josephina"]=10,["skeleton"]=0,["swamp dragon"]=7,["vampire mosquito"]=2,["Mlioglotl"]=10,["Donald"]=3,["boulder beetle"]=20,["vampire"]=10,["troll"]=3,["bush"]=15,["ice statue"]=12,["kobold"]=2,["gnoll bouda"]=2,["Geryon"]=15,["eye of devastation"]=12,["cerulean imp"]=3,["cyclops"]=5,["toadstool"]=1,["ghost"]=0,["vampire knight"]=10,["simulacrum"]=10,["kobold brigand"]=3,["Menkaure"]=3,["walking earthen tome"]=20,["shapeshifter"]=0,["bear"]=0,["Ereshkigal"]=10,["scorpion"]=5,["blizzard demon"]=10,["rakshasa"]=6,["orb spider"]=3,["spatial maelstrom"]=0,["Pargi"]=1,["Cerebov"]=30,["black draconian"]=9,["Hell Sentinel"]=25,["Harold"]=0,["neqoxec"]=4,["draconian shifter"]=-1,["gnoll"]=2,["statue"]=12,["rockslime"]=27,["wandering mushroom"]=5,["Antaeus"]=28,["quicksilver elemental"]=1,["battlesphere"]=0,["Head Instructor"]=0,["Grunn"]=6,["salamander mystic"]=5,["the Enchantress"]=1,["Dispater"]=35,["apis"]=9,["hellephant"]=13,["azure jelly"]=5,["Erolcha"]=3,["Asterion"]=4,["zombie"]=0,["cherub"]=10,["lorocyproca"]=10,["orc apostle"]=2,["steelbarb worm"]=11,["obsidian statue"]=12,["deep dwarf"]=2,["blazeheart core"]=0,["cactus giant"]=1,["walking crystal tome"]=15,["shadow wraith"]=7,["iguana"]=5,["pharaoh ant"]=4,["brain worm"]=1,["redback"]=2,["Dowan"]=0,["anaconda"]=4,["wraith"]=10,["killer bee"]=2,["merged slime creature"]=0,["butterfly"]=0,["endoplasm"]=1,["moth of wrath"]=0,["wind drake"]=3,["crab"]=0,["aspiring flesh"]=2,["searing wretch"]=4,["jorogumo"]=4,["crocodile"]=4,["starflower"]=16,["barachi"]=0,["ettin"]=9,["ghost crab"]=9,["profane servitor"]=10,["shining eye"]=3,["dryad"]=6,["thorn hunter"]=9,["demonic crawler"]=10,["bog body"]=1,["stoker"]=5,["wretched star"]=10,["deep troll"]=6,["Eustachio"]=0,["elf"]=1,["vampire bat"]=1,["cane toad"]=6,["tengu"]=2,["oklob plant"]=10,["skeletal warrior"]=15,["swamp drake"]=3,["lurking horror"]=0,["player ghost"]=1,["iron troll"]=20,["ushabti"]=9,["Erica"]=0,["howler monkey"]=1,["blink frog"]=0,["dart slug"]=1,["spider"]=0,["sun moth"]=6,["ogre"]=1,["knight"]=5,["player illusion"]=1,["Tzitzimitl"]=12,["air elemental"]=2,["walking tome"]=0,["large abomination"]=0,["deep elf archer"]=0,["Boris"]=12,["oklob sapling"]=10} function bonsai_smart_cast() local mp,mp_max=_G.you.mp() local mp_regen=math.max(1,math.floor((mp_max or 20)/10)) -- Djinni uses HP as MP local ok_race,race=pcall(function() return you.race() end) if ok_race and race=="Djinni" then mp=you.hp()-10 end -- reserve 10 HP -- Reserve MP for escape spells (Blink, Passage of Golubria, Dispersal, Disjunction) local escape_spells={"Blink","Passage of Golubria","Dispersal","Disjunction"} local reserve_mp=0 local reserve_spell=nil for _,esc in ipairs(escape_spells) do if spells.memorised(esc) then local c=spells.mana_cost(esc) if c and c>reserve_mp then reserve_mp=c;reserve_spell=esc end end end local los=you.los() local t={} local friends={} local found_bsph=false local found_servitor=false local found_star=false local found_mortar=false for x=-los,los do for y=-los,los do local m=monster.get_monster_at(x,y) if m and not m:is_firewood() then if m:attitude()==0 then t[#t+1]={m=m,x=x,y=y} elseif m:attitude()>0 then if m:name()=="battlesphere" then found_bsph=true elseif m:name()=="spellspark servitor" then found_servitor=true elseif string.find(m:name(),"shooting star") then found_star=true;friends[#friends+1]={x=x,y=y} elseif m:name()~="orb of destruction" then friends[#friends+1]={x=x,y=y} end end end if m and string.find(m:name() or "","mortar") then found_mortar=true end end end if #t==0 then crawl.mpr("No")return end local closest_dist=99 local enemy_at={} for _,e in ipairs(t) do local d=math.max(math.abs(e.x),math.abs(e.y)) if d=0 and math.ceil(known/5.0)==pips then return known end return 2.5+(pips-1)*5 end local function get_ev(m) local pips=m:ev() if pips==0 then return 0 end local ev=2.5+(pips-1)*5 -- Status effects that modify EV (source: monster.cc:3345-3360) -- Paralysed/petrified/asleep → EV=0 local ok1,v1=pcall(function() if m:status("paralysed") or m:status("petrified") or m:status("asleep") then return true end return false end) if ok1 and v1 then return 0 end -- Caught/netted → EV/5 local ok2,v2=pcall(function() return m:is_caught() end) if ok2 and v2 then return math.max(0,ev/5) end -- Confused → EV/2 local ok3,v3=pcall(function() return m:status("confused") end) if ok3 and v3 then return math.max(0,ev/2) end -- Constricted → EV-10 local ok4,v4=pcall(function() return m:is_constricted() end) if ok4 and v4 then ev=ev-10 end return math.max(0,ev) end local function get_max_hp(m) local hp_str=tostring(m:max_hp()) hp_str=hp_str:gsub("about ",""):gsub("~","") return tonumber(hp_str) or 20 end local function get_hp(m) local mhp=get_max_hp(m) local dl=m:damage_level() -- damage_level: 0=full, 1=lightly, 2=moderately, 3=heavily, 4=severely, 5=almost dead, 6=dead return math.max(1, mhp*(6-dl)/6) end local function cdist(x,y) return math.max(math.abs(x),math.abs(y)) end local function score_dmg(dmg,m,dist) local hp=get_hp(m) local mhp=get_max_hp(m) local threat=m:threat()+1 -- Overkill waste: only 20% credit for damage beyond kill threshold local effective=dmg if dmg>hp then effective=hp+(dmg-hp)*0.2 end -- Finish-off bonus: killing removes threat entirely local finish=1.0 if dmg>=hp then finish=1.5 end -- Distance urgency: adjacent monsters are most dangerous dist=dist or 4 local urgency=1.0 if dist<=1 then urgency=2.0 elseif dist<=2 then urgency=1.5 elseif dist<=3 then urgency=1.2 end -- Ranged threat: monsters already in attack range are more urgent local ok_rng,mon_rng=pcall(function() return m:range() end) if ok_rng and mon_rng and mon_rng>1 and dist<=mon_rng then urgency=urgency*1.3 end -- Base score: effective damage weighted by threat, finish, urgency, HP ratio local score=effective*finish*urgency*threat/mhp -- Deprioritize summoned monsters (they disappear soon) local desc=m:target_desc() or "" if string.find(desc,"summoned") then score=score*0.2 end -- Deprioritize safe monsters if m:is_safe() then score=score*0.1 end -- Deprioritize stationary monsters (lower threat) local ok_stat,is_stat=pcall(function() return m:is_stationary() end) if ok_stat and is_stat then score=score*0.4 end -- Boost unique/boss targets (high-value kills) local ok_uniq,is_uniq=pcall(function() return m:is_unique() end) if ok_uniq and is_uniq then score=score*1.3 end -- Boost spellcaster threats local ok_sp,mon_sp=pcall(function() return m:spells() end) if ok_sp and mon_sp and #mon_sp>0 then score=score*1.15 end -- Boost regenerating monsters (must kill fast before they heal) local ok_reg,is_reg=pcall(function() return m:status("regenerating") end) if ok_reg and is_reg then score=score*1.3 end return score end local pow_cap={["Foxfire"]=25,["Freeze"]=25,["Magic Dart"]=25,["Poisonous Vapours"]=25,["Shock"]=25, ["Sandblast"]=50,["Mercury Arrow"]=50,["Scorch"]=50,["Searing Ray"]=50,["Static Discharge"]=50,["Frozen Ramparts"]=50,["Stone Arrow"]=50, ["Hailstorm"]=100,["Dispel Undead"]=100,["Flame Wave"]=100,["Iskenderun's Battlesphere"]=100,["Iskenderun's Mystic Blast"]=100, ["Ignite Poison"]=100,["Olgreb's Toxic Radiance"]=100,["Sticky Flame"]=100} local function get_pow(name) local p=spells.power_perc(name) if not p then return 0 end local cap=pow_cap[name] or 200 return p*cap/100 end local function player_res(e_type) if e_type==1 then return you.res_cold()end if e_type==2 then return you.res_shock()end if e_type==3 then return you.res_fire()end if e_type==4 then return you.res_poison()end return 0 end local function calc_dmg(base_dmg,ac,ev,pow,noac,nohit,ac3,halfac) local dmg=base_dmg -- pow is power_perc (0-100), already factored into get_spell_dmg formulas if noac then -- Skip AC reduction elseif ac>0 then -- halfac: electricity gets ac_type::half (saved = random2(1+ac)/2, avg=ac/4) -- ac3: BEAM_FRAG gets ac_type::triple (saved = 3*random2(1+ac), avg=3*ac/2) -- source: actor.cc apply_ac — single subtraction from damage local saved=ac/2 -- normal: avg of random2(1+ac) if ac3 then saved=3*ac/2 -- triple: 3 independent random2(1+ac) summed elseif halfac then saved=ac/4 end -- half: random2(1+ac)/2 dmg=math.max(0,dmg-saved) end if nohit then -- Skip EV reduction (always hits) elseif ev>0 then dmg=dmg*math.max(0,1.0-ev/50.0) end return dmg end -- Shield block: ~50% damage reduction for shielded monsters local function sh_damage(dmg,m) local desc=m:target_desc() or "" if string.find(desc,"shield") then return dmg*0.5 end return dmg end -- Evasion check using game API (more accurate than pip estimation) local function evasion_check(m,spellname) if not spellname then return 1.0 end local ok,desc=pcall(function() return m:target_spell(spellname) end) if ok and desc then local hit=string.match(desc,"(%d+)%% to hit") if hit then return tonumber(hit)/100.0 end end return nil -- fallback to pip-based end -- Calculate average damage using wiki formulas (Nd(X) avg = N*(X+1)/2) local function get_spell_dmg(name,pow) -- Level 1 if name=="Foxfire" then return 2*(4+pow/5+1)/2 end -- 2x 1d(4+pow/5) if name=="Freeze" then return (3+3*pow/10+1)/2 end -- 1d(3+3pow/10), ignores AC if name=="Magic Dart" then return (3+pow/5+1)/2 end -- 1d(3+pow/5) if name=="Sandblast" then return 2*(4+pow/3+1)/2 end -- 2d(4+pow/3), triple AC if name=="Poisonous Vapours" then return (1+pow/8+1)/2 end -- 1d(1+pow/8) if name=="Shock" then return (3+pow/4+1)/2 end -- 1d(3+pow/4) -- Level 2 if name=="Mercury Arrow" then return 2*(5.5+pow/8+1)/2 end -- calcdice<2,11,1,4> = 2d(5.5+pow/8) poison+30% irresist if name=="Scorch" then return 2*(5+pow/12+1)/2 end -- 2d(5+pow/12) if name=="Searing Ray" then return 2*(4.5+pow/14+1)/2 end -- calcdice<2,9,1,7> = 2d(4.5+pow/14) if name=="Static Discharge" then return 3+(2+pow/12)/2 end -- 3+random2(3+pow/12) -- Level 3 if name=="Frozen Ramparts" then return (1+0.3*pow+1)/2 end -- 1d(1+0.3pow) per turn if name=="Hailstorm" then return 3*(5+pow/9+1)/2 end -- 3d(5+pow/9) calcdice<3,15,1,3> 50cold+50phys if name=="Stone Arrow" then return 3*(7+pow/8+1)/2 end -- 3d(7+pow/8) -- Level 4 if name=="Airstrike" then return 2*((pow+13)/14+1)/2 end -- 2d((pow+13)/14), +2/space added separately if name=="Brom's Barrelling Boulder" then return 2*(4+pow/10+1)/2 end -- 2d(4+pow/10) if name=="Dispel Undead" then return 3*(6.66+pow/4+1)/2 end -- 3d(6.66+pow/4), ignores AC, undead only if name=="Flame Wave" then return 3*2*(4.5+pow/6+1)/2 end -- 2d(4.5+pow/6) x 3 turns if name=="Fulminant Prism" then return 3*(5+7*pow/40+1)/2 end -- 3d(5+7pow/40) irresistible; hd=pow/10, 3d(5+hd*7/4) if name=="Iskenderun's Battlesphere" then return 2*(7+pow/9+1)/2 end -- 2d(6+hd) where hd=1+pow/9 → 2d(7+pow/9) if name=="Iskenderun's Mystic Blast" then return 2*(3+pow/6+1)/2 end -- calcdice<2,6,1,3> = 2d(3+pow/6) + collision 2d(1+pow/10) if name=="IMB_collision" then return 2*(1+pow/10+1)/2 end -- 2d(1+pow/10) wall/monster impact if name=="Ignite Poison" then return 4*(12+pow*6/100+1)/2 end -- 2*pois_str d(12+pow*6/100), assume pois=2 if name=="Olgreb's Toxic Radiance" then return 3*(1+pow/20+1)/2 end -- 1d(1+pow/20)/turn x ~3 turns if name=="Sticky Flame" then return 2*(4+pow/9+1)/2 + (3+3*pow/40)*8 end -- 2d(4+pow/9) impact + 2d7/turn DoT -- Level 5 if name=="Arcjolt" then return (10+pow/2+1)/2 end -- 1d(10+pow/2) if name=="Borgnjor's Vile Clutch" then return 2*(4+pow/20+1)/2 end -- 2d(4+pow/20) per turn if name=="Freezing Cloud" then return 14 end -- cloud: 6+r2a(16,2) avg ~14/turn, not pow-scaled if name=="Fireball" then return 3*(3.33+pow/6+1)/2 end -- 3d(3.33+pow/6) if name=="Irradiate" then return 3*(11.66+pow/6+1)/2 end -- 3d(11.66+pow/6) if name=="Lee's Rapid Deconstruction" then return 3*(4+pow/5+1)/2 end -- 3d(4+pow/5) triple AC; needs wall/fraggable target -- Level 6 if name=="Bombard" then return 9*((13+2*pow/3)/9+1)/2 end -- 9d((13+2pow/3)/9) if name=="Permafrost Eruption" then return 2*4*(1.5+3*pow/32+1)/2 end -- 2x 4d(1.5+3pow/32) calcdice<4,6,3,8> if name=="Plasma Beam" then return 2*(10+11*pow/20+1)/2 end -- 2x 1d(10+11pow/20) elec+fire if name=="Starburst" then return 6*(3+pow/9+1)/2 end -- 6d(3+pow/9) per bolt (8 bolts, single target hit once) -- Level 7 if name=="Hellfire Mortar" then local hd=1+pow/10;local zp=hd*12;return 4*(4+zp*2/21+1)/2 end -- 4d(4+hd*12*2/21) per shot if name=="Magnavolt" then return 4*(9+pow/10+1)/2 end -- 4d(9+pow/10) if name=="Orb of Destruction" then return 9*(5+pow/12+1)/2 end -- 9d(5+pow/12) if name=="Ozocubu's Refrigeration" then return 4*(7.5+pow/9+1)/2 end -- 4d(7.5+pow/9) -- Level 8 if name=="Ignition" then return 3*(3.33+pow/9+1)/2 end -- 3d(3.33+pow/9) per enemy if name=="Lehudib's Crystal Spear" then return 10*(2.3+pow/10+1)/2 end -- 10d(2.3+pow/10) if name=="Fulsome Fusillade" then return 3*(5+pow/8+1)/2 end -- 3d(5+pow/8) per explosion if name=="Maxwell's Capacitive Coupling" then return 999 end -- guaranteed kill -- Level 9 if name=="Fire Storm" then return 8*((5+pow)/8+1)/2 end -- 8d((5+pow)/8) 50% bypasses rF if name=="Chain Lightning" then return 3*(2*pow/3+1)/2 end -- 3d(2pow/3) if name=="Polar Vortex" then return 6*12*(pow/45+1)/2 end -- 12d(rpow/15) per turn x6 turns; rpow≈pow/3 avg (open space) if name=="Shatter" then return 3*(5+pow/3+1)/2 end -- 3d(5+pow/3) base; x2 for nonliving return 10 end local function get_res(m,e_type) if e_type==1 then return m:res_cold()end if e_type==2 then return m:res_shock()end if e_type==3 then return m:res_fire()end if e_type==4 then return m:res_poison()end return 0 end local function get_range(name) local r=spells.range(name) if not r then return 0 end return r end local function can_reach(tx,ty,range) local dist=math.max(math.abs(tx),math.abs(ty)) if dist>range then return false end return view.cell_see_cell(0,0,tx,ty) end local function is_solid(x,y) local f=view.feature_at(x,y) return f=="rock wall" or f=="stone wall" or f=="permarock wall" or f=="unnaturally hard rock wall" or f=="metal wall" or f=="crystal wall" or f=="closed door" or f=="runed door" or f=="sealed door" or f=="tree" end local function get_cost(name) local c=spells.mana_cost(name) if not c then return 99 end -- Flame Wave costs 1 MP to continue, full cost to start if name=="Flame Wave" and recently_cast("Flame Wave") then return 1 end return c end local function near_wall(x,y) for dx=-1,1 do for dy=-1,1 do if dx~=0 or dy~=0 then local f=view.feature_at(x+dx,y+dy) if f and (f=="#" or f=="=" or f=="|" or f=="x") then return true end end end end return false end local function count_empty(x,y) local count=0 for dx=-1,1 do for dy=-1,1 do if dx~=0 or dy~=0 then local m=monster.get_monster_at(x+dx,y+dy) local f=view.feature_at(x+dx,y+dy) if not m and f and f~="#" and f~="=" and f~="|" and f~="x" then count=count+1 end end end end return count end local function beam_blocked_by_friendly(spell_name,tx,ty) local path=spells.path(spell_name,tx,ty) if not path then return false end for _,p in ipairs(path) do local m=monster.get_monster_at(p[1],p[2]) if m and m:attitude()>0 and m:name()~="battlesphere" and m:name()~="orb of destruction" then return true end end return false end local function monsters_on_path(spell_name,tx,ty) local result={} local path=spells.path(spell_name,tx,ty) if not path then return result end for _,p in ipairs(path) do if not (p[1]==tx and p[2]==ty) then local m=monster.get_monster_at(p[1],p[2]) if m and m:attitude()==0 and not m:is_firewood() then result[#result+1]={m=m,x=p[1],y=p[2]} end end end return result end -- Shock bounce: get full path with ricochets (aimed_at_spot=false) -- Returns {hit_counts, enemies} where hit_counts[key]=count (max 2), enemies[key]={m,x,y} local function shock_bounce_hits(tx,ty,pow) local path=spells.path("Shock",tx,ty,0,0,false) if not path then return {},{} end local hit_counts={} local enemies={} for _,p in ipairs(path) do local m=monster.get_monster_at(p[1],p[2]) if m and m:attitude()==0 and not m:is_firewood() then local key=p[1]..","..p[2] if not hit_counts[key] then hit_counts[key]=0;enemies[key]={m=m,x=p[1],y=p[2]} end if hit_counts[key]<2 then hit_counts[key]=hit_counts[key]+1 end end end return hit_counts,enemies end local function monsters_on_line(tx,ty) local result={} local dx=tx>0 and 1 or (tx<0 and -1 or 0) local dy=ty>0 and 1 or (ty<0 and -1 or 0) local steps=math.max(math.abs(tx),math.abs(ty)) if steps==0 then return result end local x,y=0,0 for i=1,steps-1 do x=x+dx y=y+dy local m=monster.get_monster_at(x,y) if m and m:attitude()==0 and not m:is_firewood() then result[#result+1]={m=m,x=x,y=y} end end return result end local s={{ -- Level 1 n="Foxfire",e=3,summon=true,nohit=true -- fire, 2 foxfires, never miss },{n="Freeze",e=1,noac=true,nohit=true -- cold, range 1, ignores AC },{n="Magic Dart",e=0,nohit=true -- irresistible, never misses },{n="Poisonous Vapours",e=4,rpois_immune=true -- poison, range 3, rPois>=1 blocks cast },{n="Sandblast",e=0,ac3=true,slow=true -- physical, triple AC, 1.5 turns },{n="Shock",e=2,beam=true,penetrate=true,any_target=true -- elec, bouncing bolt, 1/2 AC via halfac -- Level 2 },{n="Mercury Arrow",e=4 -- poison+30% irresist },{n="Scorch",e=3,nohit=true -- fire, applies rF- },{n="Searing Ray",e=0,penetrate=true,channeled=true -- irresistible, channeled, penetrates, can miss },{n="Static Discharge",e=2,aoe=1,noac=true,nohit=true -- elec, arcs adj, ignores AC -- Level 3 },{n="Frozen Ramparts",e=1,aoe=2,centered=true,nohit=true -- cold, centered, adj walls },{n="Hailstorm",e=1,aoe=3,halfres=true,noadjacent=true -- cold+phys 50/50, donut AoE },{n="Stone Arrow",e=0,beam=true -- physical, bolt -- Level 4 },{n="Airstrike",e=0,nohit=true -- irresistible, smite, AC applies },{n="Brom's Barrelling Boulder",e=0,beam=true -- physical, line, knockback },{n="Dispel Undead",e=0,noac=true,nohit=true,undead=true,no_bsph=true -- ignores AC, undead only },{n="Flame Wave",e=3,aoe=3,nohit=true,channeled=true -- fire, expanding AoE centered, 3 turns },{n="Fulminant Prism",e=0,aoe=2,nohit=true,no_bsph=true,prism=true -- irresistible, smite-placed, delayed 2 turns },{n="Ignite Poison",e=3,aoe=9,noac=true,nohit=true -- fire, smite all poisoned in LOS, ignores AC/EV },{n="Iskenderun's Battlesphere",e=0,summon=true,no_bsph=true -- irresistible, construct },{n="Iskenderun's Mystic Blast",e=0,aoe=2,nohit=true,centered=true -- irresistible, 2-tile AoE },{n="Olgreb's Toxic Radiance",e=4,aoe=9,noac=true,nohit=true,rpois_immune=true -- poison, LOS AoE, ignores AC, rPois>=1 blocks },{n="Sticky Flame",e=3,nohit=true,noac=true -- fire, DoT ignores AC (bulk of dmg) -- Level 5 },{n="Arcjolt",e=2,aoe=2,nohit=true -- elec, arcs, 1/2 AC via halfac },{n="Borgnjor's Vile Clutch",e=0,clutch=true,nohit=true,no_bsph=true -- necro+earth, bolt constricts all on path },{n="Fireball",e=3,aoe=2,nohit=true,any_target=true -- fire, 3x3 explosion },{n="Freezing Cloud",e=1,fcloud=true,nohit=true,no_bsph=true -- cold, smite cloud r2, zone control },{n="Irradiate",e=0,aoe=1,nohit=true -- irresistible, all adjacent },{n="Lee's Rapid Deconstruction",e=0,aoe=1,ac3=true,nohit=true -- physical, triple AC, needs wall/fraggable -- Level 6 },{n="Bombard",e=0,beam=true -- physical, bolt },{n="Conjure Ball Lightning",e=2,summon=true -- elec, 3 autonomous balls },{n="Permafrost Eruption",e=1,aoe=3,halfres=true,centered=true -- phys+cold 50/50 },{n="Plasma Beam",e=2,penetrate=true,halfres=true,auto_target=true -- elec+fire, 2 penetrating bolts, auto-targets farthest },{n="Starburst",e=3,starburst=true -- fire, 8 penetrating bolts from player -- Level 7 },{n="Hellfire Mortar",e=3,mortar=true,halfres=true,no_bsph=true -- fire+earth, bolt path creates lava, summons mortar },{n="Magnavolt",e=2,nohit=true,magnavolt=true -- elec, smite, magnetise chain },{n="Orb of Destruction",e=0,nohit=true,ood=true -- irresistible, homing, distance scaling },{n="Ozocubu's Refrigeration",e=1,aoe=9,nohit=true,auto_target=true -- cold, full LOS, damage reduced by adj enemies },{n="Spellspark Servitor",e=0,summon=true,no_bsph=true -- varies, construct -- Level 8 },{n="Ignition",e=3,aoe=9,nohit=true -- fire, 3x3 on every enemy },{n="Lehudib's Crystal Spear",e=0 -- irresistible, short range },{n="Fulsome Fusillade",e=0,aoe=9,nohit=true -- irresistible (BEAM_MMISSILE), auto-hit, 3 explosions/turn },{n="Maxwell's Capacitive Coupling",e=2,aoe=9,noac=true,nohit=true -- elec, guaranteed kill -- Level 9 },{n="Fire Storm",e=3,aoe=3,nohit=true,halfres=true -- fire 50% irresist, smite },{n="Chain Lightning",e=2,aoe=9,halfres=true,nohit=true -- elec, arcs all in LOS },{n="Polar Vortex",e=1,aoe=5,centered=true,halfres=true,nohit=true -- cold 50% irresist, 6-turn sustained, r5 },{n="Shatter",e=0,aoe=9,nohit=true -- physical, full LOS AoE, ignores EV }} -- === Tactical situation assessment === local hp_now,hp_max=you.hp() local hp_ratio=hp_now/hp_max -- Corridor detection: count solid tiles around player local corridor_walls=0 for cx=-1,1 do for cy=-1,1 do if (cx~=0 or cy~=0) and is_solid(cx,cy) then corridor_walls=corridor_walls+1 end end end local in_corridor=(corridor_walls>=5) -- Threat weighting: parse enemy HP, find min distance, detect boss local total_threat=0 local max_single_threat=0 local min_enemy_dist=99 local adj_hostiles=0 for _,e in ipairs(t) do local d=cdist(e.x,e.y) if dmax_single_threat then max_single_threat=mhp end end -- Boss fight: one enemy has >60% of total threat local boss_fight=(#t<=2 and max_single_threat>total_threat*0.6) -- Swarm fight: many weak enemies local swarm_fight=(#t>=4 and max_single_threat=18 then depth_tier=3 end end -- Retreat mode: low HP, no adjacent enemies local retreating=(hp_ratio<0.3 and adj_hostiles==0) -- Surround detection: boost centered AoE when surrounded local surround_boost=1.0 if adj_hostiles>=3 then surround_boost=1.5 elseif adj_hostiles>=2 then surround_boost=1.2 end -- Low HP panic: prefer nohit burst on closest enemy local panic_mode=(hp_ratio<0.25 and adj_hostiles>0) local candidates={} local almost={} -- spells needing 1 more MP -- Battlesphere detected during initial monster scan (found_bsph) local bsph_bonus=0 local bsph_raw=0 local has_bsph=found_bsph if has_bsph and #t>0 then -- Battlesphere targets most-injured enemy: 2d(7+pow/9), irresistible, auto-hit local bsph_pow=0 if spells.memorised("Iskenderun's Battlesphere") then bsph_pow=get_pow("Iskenderun's Battlesphere") end local bsph_base=2*(7+bsph_pow/9+1)/2 -- Find most-injured enemy (most hp missing) local most_missing=0 local bsph_target=nil for _,e in ipairs(t) do local missing=get_max_hp(e.m)-get_hp(e.m) if missing>most_missing then most_missing=missing;bsph_target=e end end if not bsph_target then bsph_target=t[1] end -- Battlesphere damage: irresistible (e=0), auto-hit, vs AC local ac=get_ac(bsph_target.m) local dmg=calc_dmg(bsph_base,ac,0,0,false,true,false) dmg=sh_damage(dmg,bsph_target.m) bsph_bonus=score_dmg(dmg,bsph_target.m,cdist(bsph_target.x,bsph_target.y)) bsph_raw=dmg end -- Pre-compute magnetised targets for Magnavolt (avoid full LOS scan inside spell loop) local mag_cache={} if spells.memorised("Magnavolt") then local mag_seen={} for x=-los,los do for y=-los,los do local m2=monster.get_monster_at(x,y) if m2 and m2:attitude()==0 and not m2:is_firewood() then local ok,st=pcall(function() return m2:status("covered in magnetic dust") end) if ok and st then mag_cache[#mag_cache+1]={x=x,y=y,m=m2};mag_seen[x..","..y]=true end end local ok2,cl=pcall(function() return view.cloud_at(x,y) end) if ok2 and cl=="magnetised fragments" and not mag_seen[x..","..y] then mag_cache[#mag_cache+1]={x=x,y=y,cloud=true} end end end end for _,sp in ipairs(s) do local mem=spells.memorised(sp.n) local cost=get_cost(sp.n) local fail=spells.fail(sp.n) local ok_sev,sev=pcall(function() return spells.fail_severity(sp.n) end) if mem and fail<20 and (not ok_sev or sev<=2) then -- Chain Lightning requires rElec to safely cast -- Irradiate: avoid if post-cast contamination could reach dangerous glow (>=100) if (sp.n=="Chain Lightning" and you.res_shock()<1) or (sp.n=="Irradiate" and (you.contamination() or 0)+40>100) or (sp.n=="Polar Vortex" and you.status("in a vortex")) or (sp.n=="Frozen Ramparts" and you.status("freezing walls")) or (sp.n=="Fulsome Fusillade" and you.status("raining reagents")) or (sp.n=="Iskenderun's Battlesphere" and (has_bsph or closest_dist<=3)) or (sp.n=="Spellspark Servitor" and found_servitor) or (sp.n=="Hellfire Mortar" and found_mortar) or (sp.n=="Olgreb's Toxic Radiance" and you.status("radiating poison")) then else local range=get_range(sp.n) local pow=get_pow(sp.n) local elec=(sp.e==2) -- electricity: half-AC (beam.cc:4595) local best_val=0 local best_kn=99 local best_tx,best_ty=0,0 if sp.summon then local dmg=get_spell_dmg(sp.n,pow) -- Ball Lightning danger: check enemies nearby if sp.n=="Conjure Ball Lightning" then local adj_count=0 local near_count=0 for _,e in ipairs(t) do local dist=math.max(math.abs(e.x),math.abs(e.y)) if dist==1 then adj_count=adj_count+1 elseif dist<=2 then near_count=near_count+1 end end -- Very dangerous if adjacent enemies if adj_count>0 then dmg=dmg*0.1 -- Dangerous if enemies within 2 tiles elseif near_count>0 then dmg=dmg*0.3 -- Also needs rElec elseif you.res_shock()<1 then dmg=dmg*0.2 end end if sp.n=="Foxfire" then local clear=0 local reachable=0 -- Find closest enemy for pathing check local fx_e=t[1];local fx_d=99 for _,e in ipairs(t) do local d=cdist(e.x,e.y) if d=4 then dmg=dmg*0.3 end end -- Score summon against closest enemy as proxy local best_e=t[1] local best_d=99 for _,e in ipairs(t) do local d=cdist(e.x,e.y) if d0 then local total_dmg=0 local best_tx,best_ty=0,0 if sp.n=="Static Discharge" then for _,e in ipairs(t) do if math.abs(e.x)<=1 and math.abs(e.y)<=1 then local val=0 for _,e2 in ipairs(t) do local dist=math.max(math.abs(e2.x-e.x),math.abs(e2.y-e.y)) if dist<=1 then local r=get_res(e2.m,sp.e) local mult=1.0 if r==-1 then mult=1.5 elseif r==1 then mult=0.5 elseif r==2 then mult=0 elseif r>=3 then mult=0.0 end if mult>0 then local base=get_spell_dmg(sp.n,pow) local ac=get_ac(e2.m) local ev=get_ev(e2.m) local dmg=calc_dmg(base*mult,ac,ev,pow,sp.noac,sp.nohit,sp.ac3,elec) val=val+score_dmg(dmg,e2.m,cdist(e2.x,e2.y)) end end end if val>total_dmg then total_dmg=val;best_tx=e.x;best_ty=e.y end end end best_val=total_dmg*surround_boost elseif sp.n=="Arcjolt" then -- Chain-arc simulation: start from player, expand outward local hit={} hit["0,0"]=true local base=get_spell_dmg(sp.n,pow) local val=0 for ring=1,los do local found=false for _,e2 in ipairs(t) do local key=e2.x..","..e2.y if not hit[key] then -- Check if adjacent to any already-hit cell local adj=false for dx=-1,1 do for dy=-1,1 do if hit[(e2.x+dx)..","..((e2.y+dy))] then adj=true end end end if adj then hit[key]=true found=true local r=get_res(e2.m,sp.e) local mult=1.0 if r==-1 then mult=1.5 elseif r==1 then mult=0.5 elseif r==2 then mult=0 elseif r>=3 then mult=0.0 end if mult>0 then local ac=get_ac(e2.m) local dmg if sp.halfres then local dmg1=calc_dmg(base*0.5*mult,ac,0,pow,sp.noac,sp.nohit,sp.ac3,elec) local dmg2=calc_dmg(base*0.5,ac,0,pow,sp.noac,sp.nohit,sp.ac3,elec) dmg=dmg1+dmg2 else dmg=calc_dmg(base*mult,ac,0,pow,sp.noac,sp.nohit,sp.ac3,elec) end val=val+score_dmg(dmg,e2.m,cdist(e2.x,e2.y)) end end end end if not found then break end end best_val=val*surround_boost elseif sp.centered then -- Special handling for Permafrost Eruption: target largest cluster if sp.n=="Permafrost Eruption" then local best_cluster=0 local best_target=nil for _,e in ipairs(t) do if cdist(e.x,e.y)>=2 then -- source: grid_distance(t,src)<2 skips adjacent local cluster_size=0 for _,e2 in ipairs(t) do if math.abs(e2.x-e.x)<=1 and math.abs(e2.y-e.y)<=1 then cluster_size=cluster_size+1 end end if cluster_size>best_cluster then best_cluster=cluster_size best_target=e end end end if best_target then local dmg=0 for _,e2 in ipairs(t) do if math.abs(e2.x-best_target.x)<=1 and math.abs(e2.y-best_target.y)<=1 then local r=get_res(e2.m,sp.e) local mult=1.0 if r==-1 then mult=1.5 elseif r==1 then mult=0.5 elseif r==2 then mult=0 elseif r>=3 then mult=0.0 end if mult>0 then local base=get_spell_dmg(sp.n,pow) local ac=get_ac(e2.m) local ev=get_ev(e2.m) local tdmg if sp.halfres then local d1=calc_dmg(base*0.5*mult,ac,ev,pow,sp.noac,sp.nohit,sp.ac3,elec) local d2=calc_dmg(base*0.5,ac,ev,pow,sp.noac,sp.nohit,sp.ac3,elec) tdmg=d1+d2 else tdmg=calc_dmg(base*mult,ac,ev,pow,sp.noac,sp.nohit,sp.ac3,elec) end dmg=dmg+score_dmg(tdmg,e2.m,cdist(e2.x,e2.y)) end end end if dmg>0 then if cdist(best_target.x,best_target.y)<=1 then dmg=dmg*surround_boost end best_val=dmg;best_tx=best_target.x;best_ty=best_target.y end end elseif sp.n=="Iskenderun's Mystic Blast" then -- IMB: blast centered on player, hits all in radius 2, knockback bonus local val=0 for _,e in ipairs(t) do if cdist(e.x,e.y)<=range then local r=get_res(e.m,sp.e) local mult=1.0 if r==-1 then mult=1.5 elseif r==1 then mult=0.5 elseif r==2 then mult=0 elseif r>=3 then mult=0.0 end if mult>0 then local base=get_spell_dmg(sp.n,pow) local ac=get_ac(e.m) local ev=get_ev(e.m) local dmg=calc_dmg(base*mult,ac,ev,pow,sp.noac,sp.nohit,sp.ac3,elec) -- knockback collision bonus local dx=e.x>0 and 1 or (e.x<0 and -1 or 0) local dy=e.y>0 and 1 or (e.y<0 and -1 or 0) local kd=2+pow/50 local col_dmg=get_spell_dmg("IMB_collision",pow) local kx,ky=e.x,e.y for _=1,math.floor(kd) do local nx,ny=kx+dx,ky+dy if is_solid(nx,ny) then dmg=dmg+calc_dmg(col_dmg,get_ac(e.m),0,pow,false,true) break end local om=monster.get_monster_at(nx,ny) if om and om:attitude()==0 and not om:is_firewood() then dmg=dmg+calc_dmg(col_dmg,get_ac(e.m),0,pow,false,true) dmg=dmg+calc_dmg(col_dmg,get_ac(om),0,pow,false,true) break end kx=nx;ky=ny end if cdist(e.x,e.y)<=1 then dmg=dmg*1.3 end val=val+score_dmg(dmg,e.m,cdist(e.x,e.y)) end end end best_val=val*surround_boost if best_val>0 then best_tx=0;best_ty=0 end else -- Other centered spells (Starburst, Frozen Ramparts, Polar Vortex) local total_dmg=0 local val=0 for _,e in ipairs(t) do local others=monsters_on_line(e.x,e.y) others[#others+1]={m=e.m,x=e.x,y=e.y} for _,target in ipairs(others) do local r=get_res(target.m,sp.e) local mult=1.0 if r==-1 then mult=1.5 elseif r==1 then mult=0.5 elseif r==2 then mult=0 elseif r>=3 then mult=0.0 end if mult>0 then local base=get_spell_dmg(sp.n,pow) local ac=get_ac(target.m) local ev=get_ev(target.m) local dmg=calc_dmg(base*mult,ac,ev,pow,sp.noac,sp.nohit,sp.ac3,elec) val=val+score_dmg(dmg,target.m,cdist(target.x,target.y)) end end end best_val=val if best_val>0 then best_tx=0;best_ty=0 end end elseif sp.n=="Lee's Rapid Deconstruction" then -- LRD: scan all cells in range for walls or fraggable monsters local best_dmg=0 for x=-range,range do for y=-range,range do if you.see_cell_solid_see(x,y) then local dice=0 local radius=1 local is_ice=false local from_mon=false -- Check monster first (by name-based lookup, matching source fraggable_monsters) local tm=monster.get_monster_at(x,y) if tm and tm:attitude()==0 and not tm:is_firewood() then local md,mr,mi=lrd_dice_mon(tm) if md>0 then dice=md;radius=mr;is_ice=mi;from_mon=true end end -- Then terrain if dice==0 then local f=view.feature_at(x,y) local td,tr=lrd_dice_terrain(f) if td>0 then dice=td;radius=tr end end if dice>0 and not has_friendly(x,y,radius) then local val=0 local dmg_per=4+pow/5 for _,e2 in ipairs(t) do local dist=math.max(math.abs(e2.x-x),math.abs(e2.y-y)) if dist<=radius and (e2.x~=0 or e2.y~=0) then local ac=get_ac(e2.m) local base=dice*(dmg_per+1)/2 local dmg=calc_dmg(base,ac,0,pow,false,true,true) -- Ice explosion: apply cold resistance if is_ice then local cr=e2.m:res_cold() if cr>0 then dmg=dmg/(1+cr) elseif cr<0 then dmg=dmg*1.5 end end local sv=score_dmg(dmg,e2.m,cdist(e2.x,e2.y)) if from_mon and e2.x==x and e2.y==y then sv=sv*1.5 end val=val+sv end end if val>best_dmg then best_dmg=val;best_tx=x;best_ty=y end end end end end best_val=best_dmg else local aoe_centers={} local aoe_seen={} local function add_center(cx,cy) local k=cx..","..cy if not aoe_seen[k] then aoe_seen[k]=true;aoe_centers[#aoe_centers+1]={x=cx,y=cy} end end for _,e in ipairs(t) do add_center(e.x,e.y) end if sp.aoe and sp.aoe>0 and sp.aoe<9 then local p_res=player_res(sp.e) if (sp.n=="Fireball" or sp.n=="Fire Storm") and p_res>=2 then add_center(0,0) end -- For any_target spells, also add empty cells near player as potential targets if sp.any_target then for dx=-sp.aoe,sp.aoe do for dy=-sp.aoe,sp.aoe do if not (dx==0 and dy==0) and not enemy_at[dx..","..dy] and view.cell_see_cell(0,0,dx,dy) then add_center(dx,dy) end end end end -- Add offset centers around each enemy (only for targeted AoE, not full-LOS) for _,e in ipairs(t) do for dx=-sp.aoe,sp.aoe do for dy=-sp.aoe,sp.aoe do if not (dx==0 and dy==0) then local cx,cy=e.x+dx,e.y+dy if not enemy_at[cx..","..cy] and view.cell_see_cell(0,0,cx,cy) then add_center(cx,cy) end end end end end end for _,center in ipairs(aoe_centers) do -- Prism: must target empty non-solid non-self tile local prism_ok=true if sp.prism then if (center.x==0 and center.y==0) or is_solid(center.x,center.y) or monster.get_monster_at(center.x,center.y) then prism_ok=false end end if prism_ok and not has_friendly(center.x,center.y,sp.aoe) then local val=0 for _,e2 in ipairs(t) do local dist=math.max(math.abs(e2.x-center.x),math.abs(e2.y-center.y)) local adj_dist=math.max(math.abs(e2.x),math.abs(e2.y)) if dist<=sp.aoe and (not sp.noadjacent or adj_dist>1) then local r=get_res(e2.m,sp.e) local mult=1.0 if r==-1 then mult=1.5 elseif r==1 then mult=0.5 elseif r==2 then mult=0 elseif r>=3 then mult=0.0 end if sp.undead and e2.m:holiness()~="undead" then mult=0 end if sp.rpois_immune and r>=1 then mult=0 end if sp.n=="Ignite Poison" then local ok,st=pcall(function() return e2.m:status("poisoned") end) if not (ok and st) then mult=0 end end if mult>0 then local base=get_spell_dmg(sp.n,pow) if sp.n=="Shatter" then -- 2x: fraggable (same list as LRD) + petrified/petrifying local lrd_d=lrd_dice_mon(e2.m) if lrd_d>0 then base=base*2 else -- 1/3: airborne or amorphous (jellies, slimes) local hdesc=e2.m:target_desc() or "" if string.find(hdesc,"lying") or string.find(hdesc,"evitat") then base=base/3 end end end local ac=get_ac(e2.m) local ev=get_ev(e2.m) local dmg if sp.halfres then local dmg1=calc_dmg(base*0.5*mult,ac,ev,pow,sp.noac,sp.nohit,sp.ac3,elec) local dmg2=calc_dmg(base*0.5,ac,ev,pow,sp.noac,sp.nohit,sp.ac3,elec) dmg=dmg1+dmg2 else dmg=calc_dmg(base*mult,ac,ev,pow,sp.noac,sp.nohit,sp.ac3,elec) end dmg=sh_damage(dmg,e2.m) val=val+score_dmg(dmg,e2.m,cdist(e2.x,e2.y)) end end end -- Prism: discount for 2-turn delay (enemies may move away) if sp.prism then val=val*0.5 end -- Boost AoE centered on/near player when surrounded if cdist(center.x,center.y)<=1 then val=val*surround_boost end if val>total_dmg then total_dmg=val;best_tx=center.x;best_ty=center.y end end end best_val=total_dmg end elseif sp.auto_target then -- Auto-target spells: Plasma Beam (farthest), Permafrost (largest cluster), Ozocubu (all in LOS) if sp.n=="Plasma Beam" then -- Plasma Beam: targets farthest enemy, hits all on line local farthest_dist=0 local farthest_e=nil for _,e in ipairs(t) do local dist=math.max(math.abs(e.x),math.abs(e.y)) if dist>farthest_dist then farthest_dist=dist;farthest_e=e end end if farthest_e then local val=0 local others=monsters_on_line(farthest_e.x,farthest_e.y) for _,target in ipairs(others) do local r=get_res(target.m,sp.e) local mult=1.0 if r==-1 then mult=1.5 elseif r==1 then mult=0.5 elseif r==2 then mult=0 elseif r>=3 then mult=0.0 end if mult>0 then local base=get_spell_dmg(sp.n,pow) local ac=get_ac(target.m) local ev=get_ev(target.m) local hitC=evasion_check(target.m,sp.n) or math.max(0,1.0-ev/50.0) local tdmg if sp.halfres then local d1=calc_dmg(base*0.5*mult,ac,0,pow,sp.noac,true,sp.ac3,elec) local d2=calc_dmg(base*0.5,ac,0,pow,sp.noac,true,sp.ac3,elec) tdmg=(d1+d2)*hitC else tdmg=calc_dmg(base*mult,ac,0,pow,sp.noac,true,sp.ac3,elec)*hitC end tdmg=sh_damage(tdmg,target.m) val=val+score_dmg(tdmg,target.m,cdist(target.x,target.y)) end end -- Add the farthest target itself local r=get_res(farthest_e.m,sp.e) local mult=1.0 if r==-1 then mult=1.5 elseif r==1 then mult=0.5 elseif r==2 then mult=0 elseif r>=3 then mult=0.0 end if mult>0 then local base=get_spell_dmg(sp.n,pow) local ac=get_ac(farthest_e.m) local ev=get_ev(farthest_e.m) local hitC=evasion_check(farthest_e.m,sp.n) or math.max(0,1.0-ev/50.0) local tdmg if sp.halfres then local d1=calc_dmg(base*0.5*mult,ac,0,pow,sp.noac,true,sp.ac3,elec) local d2=calc_dmg(base*0.5,ac,0,pow,sp.noac,true,sp.ac3,elec) tdmg=(d1+d2)*hitC else tdmg=calc_dmg(base*mult,ac,0,pow,sp.noac,true,sp.ac3,elec)*hitC end tdmg=sh_damage(tdmg,farthest_e.m) val=val+score_dmg(tdmg,farthest_e.m,cdist(farthest_e.x,farthest_e.y)) end -- Lineup bonus for penetrating beam local lineup=#others if lineup>=1 then val=val*(1.0+lineup*0.3) end if val>0 then best_val=val;best_tx=farthest_e.x;best_ty=farthest_e.y end end elseif sp.n=="Permafrost Eruption" then -- Permafrost Eruption: target largest cluster of adjacent enemies local best_cluster=0 local best_target=nil for _,e in ipairs(t) do if cdist(e.x,e.y)>=2 then -- source: grid_distance(t,src)<2 skips adjacent local cluster_size=0 for _,e2 in ipairs(t) do if math.abs(e2.x-e.x)<=1 and math.abs(e2.y-e.y)<=1 then cluster_size=cluster_size+1 end end if cluster_size>best_cluster then best_cluster=cluster_size best_target=e end end end if best_target then local val=0 for _,e2 in ipairs(t) do if math.abs(e2.x-best_target.x)<=1 and math.abs(e2.y-best_target.y)<=1 then local r=get_res(e2.m,sp.e) local mult=1.0 if r==-1 then mult=1.5 elseif r==1 then mult=0.5 elseif r==2 then mult=0 elseif r>=3 then mult=0.0 end if mult>0 then local base=get_spell_dmg(sp.n,pow) local ac=get_ac(e2.m) local ev=get_ev(e2.m) local tdmg if sp.halfres then local d1=calc_dmg(base*0.5*mult,ac,0,pow,sp.noac,true,sp.ac3,elec) local d2=calc_dmg(base*0.5,ac,0,pow,sp.noac,true,sp.ac3,elec) tdmg=d1+d2 else tdmg=calc_dmg(base*mult,ac,ev,pow,sp.noac,sp.nohit,sp.ac3,elec) end tdmg=sh_damage(tdmg,e2.m) val=val+score_dmg(tdmg,e2.m,cdist(e2.x,e2.y)) end end end if val>0 then best_val=val;best_tx=best_target.x;best_ty=best_target.y end end elseif sp.n=="Ozocubu's Refrigeration" then -- Ozocubu's Refrigeration: hits all in LOS, damage reduced by adjacent enemies (max 2) local total_dmg=0 for _,e in ipairs(t) do local adj_count=0 for _,e2 in ipairs(t) do if e2~=e and math.abs(e2.x-e.x)<=1 and math.abs(e2.y-e.y)<=1 then adj_count=adj_count+1 end end local reduction=math.min(adj_count,2)*0.3 local r=get_res(e.m,sp.e) local mult=1.0 if r==-1 then mult=1.5 elseif r==1 then mult=0.5 elseif r==2 then mult=0 elseif r>=3 then mult=0.0 end if mult>0 then local base=get_spell_dmg(sp.n,pow) local ac=get_ac(e.m) local tdmg=calc_dmg(base*mult*(1-reduction),ac,0,pow,sp.noac,sp.nohit,sp.ac3,elec) tdmg=sh_damage(tdmg,e.m) total_dmg=total_dmg+score_dmg(tdmg,e.m,cdist(e.x,e.y)) end end if total_dmg>0 then best_val=total_dmg;best_tx=0;best_ty=0 end end elseif sp.starburst then -- Starburst: 8 rays from player in cardinal+diagonal directions local base=get_spell_dmg(sp.n,pow) local val=0 local dirs={{1,0},{-1,0},{0,1},{0,-1},{1,1},{1,-1},{-1,1},{-1,-1}} for _,d in ipairs(dirs) do for R=1,range do local rx,ry=d[1]*R,d[2]*R if is_solid(rx,ry) then break end local m2=monster.get_monster_at(rx,ry) if m2 and m2:attitude()==0 and not m2:is_firewood() then local r=get_res(m2,sp.e) local mult=1.0 if r==-1 then mult=1.5 elseif r==1 then mult=0.5 elseif r==2 then mult=0 elseif r>=3 then mult=0 end if mult>0 then local ac=get_ac(m2) local ev=get_ev(m2) local dmg=calc_dmg(base*mult,ac,ev,pow,sp.noac,sp.nohit,sp.ac3,elec) dmg=sh_damage(dmg,m2) val=val+score_dmg(dmg,m2,cdist(rx,ry)) end end end end if val>0 then best_val=val;best_tx=0;best_ty=0 end elseif sp.magnavolt then -- Magnavolt: use pre-computed magnetised targets (mag_cache), find best new target local mag_targets=mag_cache -- Calculate damage for a bolt aimed at (tx,ty): hits target + all enemies on path local base=get_spell_dmg(sp.n,pow) local function bolt_dmg_to_mon(m2,mx,my) local r=get_res(m2,sp.e) local mult=1.0 if r==-1 then mult=1.5 elseif r==1 then mult=0.5 elseif r==2 then mult=0 elseif r>=3 then mult=0 end if mult==0 then return 0 end local ac=get_ac(m2) local dmg=calc_dmg(base*mult,ac,0,pow,sp.noac,true,sp.ac3,elec) dmg=sh_damage(dmg,m2) return score_dmg(dmg,m2,cdist(mx,my)) end local function mag_bolt_val(tx,ty) -- Bolt to (tx,ty) penetrates through all enemies on the path local val=0 local path=spells.path(sp.n,tx,ty) if path then for _,p in ipairs(path) do local pm=monster.get_monster_at(p[1],p[2]) if pm and pm:attitude()==0 and not pm:is_firewood() then val=val+bolt_dmg_to_mon(pm,p[1],p[2]) end end end -- Add the endpoint target itself (may not be in path) local tm=monster.get_monster_at(tx,ty) if tm and tm:attitude()==0 and not tm:is_firewood() then -- Check not already counted via path local counted=false if path then for _,p in ipairs(path) do if p[1]==tx and p[2]==ty then counted=true break end end end if not counted then val=val+bolt_dmg_to_mon(tm,tx,ty) end end return val end -- Existing magnetised damage (bolts to all current targets, each penetrating) local existing_val=0 for _,mt in ipairs(mag_targets) do existing_val=existing_val+mag_bolt_val(mt.x,mt.y) end -- Try each non-magnetised enemy as new target for _,e in ipairs(t) do if can_reach(e.x,e.y,range) then local already_mag=false for _,mt in ipairs(mag_targets) do if mt.x==e.x and mt.y==e.y then already_mag=true break end end -- New target gets bolt (penetrating) + all existing magnetised get bolts too local new_bolt=mag_bolt_val(e.x,e.y) local val=existing_val+new_bolt -- Ramp-up bonus: magnetising targets builds future value -- Even vs 1 target, the noise draws enemies who arrive pre-magnetised -- 1.5x base bonus (investing in future stacking) + 0.3 per existing mag target val=val*(1.5+#mag_targets*0.3) if val>best_val then best_val=val;best_tx=e.x;best_ty=e.y end end end -- If all enemies already magnetised, pick highest-damage one as target if best_val==0 and #mag_targets>0 then for _,mt in ipairs(mag_targets) do if not mt.cloud and can_reach(mt.x,mt.y,range) then local val=existing_val if val>best_val then best_val=val;best_tx=mt.x;best_ty=mt.y end end end end elseif sp.clutch then -- Borgnjor's Vile Clutch: bolt constricts all enemies on path -- Score = sum of constriction DoT value for each non-constricted enemy hit -- Prioritize paths that constrict the most dangerous, closest enemies -- Duration: 4 + random_range(pow/35, pow/25+1); avg ~ 4.5 + pow/29 local constr_turns=4.5+pow/29 local constr_dmg=get_spell_dmg(sp.n,pow)*constr_turns -- Try each enemy as a bolt direction; score all enemies on the path for _,e in ipairs(t) do if can_reach(e.x,e.y,range) and not beam_blocked_by_friendly(sp.n,e.x,e.y) then local val=0 local path=spells.path(sp.n,e.x,e.y,0,0,false) local hits={} if path then for _,p in ipairs(path) do local pm=monster.get_monster_at(p[1],p[2]) if pm and pm:attitude()==0 and not pm:is_firewood() then hits[#hits+1]={m=pm,x=p[1],y=p[2]} end end end -- Score each hit: skip already constricted (check target_desc for "onstrict") -- EV synergy now handled globally in get_ev() (-10 EV for constricted monsters) for _,h in ipairs(hits) do local hdesc=h.m:target_desc() or "" if not string.find(hdesc,"onstrict") then local ac=get_ac(h.m) local dmg=calc_dmg(constr_dmg,ac,0,pow,false,true,false) val=val+score_dmg(dmg,h.m,cdist(h.x,h.y)) end end if val>best_val then best_val=val;best_tx=e.x;best_ty=e.y end end end elseif sp.fcloud then -- Freezing Cloud: smite-targeted cloud, radius 2 -- Score by enemies covered + corridor blocking bonus -- Safe to self-cast at rC+3 local cloud_turns=3 local cloud_dmg=get_spell_dmg(sp.n,pow)*cloud_turns local cloud_r=2 local player_immune=(you.res_cold()>=3) -- Gather candidate cloud centers: on enemies, between player and enemies, and on player local centers={} for _,e in ipairs(t) do centers[#centers+1]={x=e.x,y=e.y} -- Also try midpoint between player and enemy (corridor blocking) local mx=math.floor(e.x/2+0.5) local my=math.floor(e.y/2+0.5) if (mx~=0 or my~=0) and not is_solid(mx,my) and cdist(mx,my)<=range then centers[#centers+1]={x=mx,y=my} end end if player_immune then centers[#centers+1]={x=0,y=0} end -- Score each center for _,c in ipairs(centers) do if cdist(c.x,c.y)<=range and not is_solid(c.x,c.y) and (player_immune or cdist(c.x,c.y)>cloud_r) and not has_friendly(c.x,c.y,cloud_r) then local val=0 -- Count enemies in cloud radius, skip those already in freezing cloud for _,e2 in ipairs(t) do local d=math.max(math.abs(e2.x-c.x),math.abs(e2.y-c.y)) local cl=view.cloud_at(e2.x,e2.y) local in_fcloud=cl and string.find(cl,"freezing") if d<=cloud_r and not in_fcloud then local r=get_res(e2.m,sp.e) if r<3 then -- rC+3 immune local mult=1.0 if r==-1 then mult=1.5 elseif r==1 then mult=0.5 elseif r==2 then mult=0.25 end local dmg=cloud_dmg*mult val=val+score_dmg(dmg,e2.m,cdist(e2.x,e2.y)) end end end -- Corridor bonus: count solid tiles adjacent to cloud center -- More walls = narrower passage = better zone control local walls=0 for dx=-1,1 do for dy=-1,1 do if (dx~=0 or dy~=0) and is_solid(c.x+dx,c.y+dy) then walls=walls+1 end end end if walls>=2 then val=val*(1+walls*0.15) end if val>best_val then best_val=val;best_tx=c.x;best_ty=c.y end end end elseif sp.mortar then -- Hellfire Mortar: bolt path creates lava (blocks non-flying), summons mortar -- Score = enemies on path damage + lava blocking bonus for nearby non-flying enemies -- Mortar fires ~path_len*1.5 turns; use conservative 3 shots estimate local shots=3 local base_dmg=get_spell_dmg(sp.n,pow)*shots for _,e in ipairs(t) do if can_reach(e.x,e.y,range) and not beam_blocked_by_friendly(sp.n,e.x,e.y) then local val=0 local path=spells.path(sp.n,e.x,e.y) local path_tiles={} if path then for _,p in ipairs(path) do path_tiles[#path_tiles+1]={x=p[1],y=p[2]} -- Score enemies on the path (mortar will fire at them) local pm=monster.get_monster_at(p[1],p[2]) if pm and pm:attitude()==0 and not pm:is_firewood() then local r=get_res(pm,sp.e) local mult=1.0 if r==-1 then mult=1.5 elseif r==1 then mult=0.5 elseif r==2 then mult=0.25 elseif r>=3 then mult=0 end if sp.halfres then mult=0.5+mult*0.5 end if mult>0 then local ac=get_ac(pm) local ev=get_ev(pm) local dmg=calc_dmg(base_dmg*mult,ac,ev,pow,false,false,false) val=val+score_dmg(dmg,pm,cdist(p[1],p[2])) end end end end -- Also score endpoint enemy local has_end=false if path then for _,p in ipairs(path) do if p[1]==e.x and p[2]==e.y then has_end=true break end end end if not has_end then local r=get_res(e.m,sp.e) local mult=1.0 if r==-1 then mult=1.5 elseif r==1 then mult=0.5 elseif r==2 then mult=0.25 elseif r>=3 then mult=0 end if sp.halfres then mult=0.5+mult*0.5 end if mult>0 then local ac=get_ac(e.m) local ev=get_ev(e.m) local dmg=calc_dmg(base_dmg*mult,ac,ev,pow,false,false,false) val=val+score_dmg(dmg,e.m,cdist(e.x,e.y)) end end -- Lava blocking bonus: count nearby non-path enemies that would be blocked -- Lava blocks ground movement, so non-flying enemies near path get bonus if #path_tiles>=2 then local lava_bonus=0 for _,e2 in ipairs(t) do -- Check if enemy is adjacent to lava path (would be blocked) for _,pt in ipairs(path_tiles) do local d=math.max(math.abs(e2.x-pt.x),math.abs(e2.y-pt.y)) if d<=1 then -- Non-flying enemies blocked by lava get bonus local hdesc=e2.m:target_desc() or "" local flying=string.find(hdesc,"lying") or string.find(hdesc,"evitat") if not flying then lava_bonus=lava_bonus+0.3 end break end end end val=val*(1+lava_bonus) end -- Corridor bonus: lava in narrow passages is more valuable local walls=0 for _,pt in ipairs(path_tiles) do for dx=-1,1 do for dy=-1,1 do if (dx~=0 or dy~=0) and is_solid(pt.x+dx,pt.y+dy) then walls=walls+1 end end end end if #path_tiles>0 then walls=walls/#path_tiles end if walls>=3 then val=val*1.5 elseif walls>=2 then val=val*1.2 end if val>best_val then best_val=val;best_tx=e.x;best_ty=e.y end end end elseif sp.ood then -- Orb of Destruction: distance scaling, obstacle check, adjacent orb check -- Don't fire if there's already an OoD adjacent to player (collision risk) local adj_ood=false for dx=-1,1 do for dy=-1,1 do local m2=monster.get_monster_at(dx,dy) if m2 and m2:name()=="orb of destruction" and m2:attitude()>0 then adj_ood=true end end end if not adj_ood then local base_M=5+pow/12 for _,e in ipairs(t) do if can_reach(e.x,e.y,range) then local dist=math.max(math.abs(e.x),math.abs(e.y)) -- Enemy likely steps toward player before orb arrives if dist>3 then dist=dist-1 end local scale=1.0 if dist<4 then scale=dist*0.3 end local ac=get_ac(e.m) local dmg=calc_dmg(9*(base_M*scale+1)/2,ac,0,pow,false,true,false) dmg=sh_damage(dmg,e.m) -- Check path for obstacles (walls, firewood, other monsters blocking) local blocked=false local path=spells.path(sp.n,e.x,e.y) if path then for _,p in ipairs(path) do if not (p[1]==e.x and p[2]==e.y) then if is_solid(p[1],p[2]) then blocked=true break end local pm=monster.get_monster_at(p[1],p[2]) if pm and pm:is_firewood() then blocked=true break end if pm and pm:attitude()>0 and pm:name()~="battlesphere" and pm:name()~="orb of destruction" then blocked=true break end end end end if not blocked and dmg>0 then local val=score_dmg(dmg,e.m,cdist(e.x,e.y)) if val>best_val then best_val=val;best_tx=e.x;best_ty=e.y end end end end end else -- Shock wall-bounce: try wall tiles near enemies as aim directions for ricochets local shock_wall_targets={} if sp.n=="Shock" then local tried={} for _,e in ipairs(t) do for dx=-2,2 do for dy=-2,2 do local wx,wy=e.x+dx,e.y+dy local wk=wx..","..wy if not tried[wk] and is_solid(wx,wy) and can_reach(wx,wy,range) then tried[wk]=true local wh,we=shock_bounce_hits(wx,wy,pow) local any_hit=false for _ in pairs(we) do any_hit=true break end if any_hit then shock_wall_targets[#shock_wall_targets+1]={x=wx,y=wy,hits=wh,enemies=we} end end end end end end for _,e in ipairs(t) do if can_reach(e.x,e.y,range) and not ((sp.beam or sp.penetrate) and beam_blocked_by_friendly(sp.n,e.x,e.y)) then local r=get_res(e.m,sp.e) local mult=1.0 if r==-1 then mult=1.5 elseif r==1 then mult=0.5 elseif r==2 then mult=0 elseif r>=3 then mult=0.0 end if sp.undead and e.m:holiness()~="undead" then mult=0 end if sp.rpois_immune and r>=1 then mult=0 end local hp=get_hp(e.m) local base=get_spell_dmg(sp.n,pow) -- Sticky Flame: strip DoT if target already burning (doesn't stack) if sp.n=="Sticky Flame" then local ok_burn,is_burn=pcall(function() return e.m:status("covered in liquid flames") end) if ok_burn and is_burn then base=2*(4+pow/9+1)/2 end -- impact only end if sp.n=="Airstrike" then local empty=count_empty(e.x,e.y) base=base+empty*2 end local ac=get_ac(e.m) local ev=get_ev(e.m) -- Use game API evasion if available local hit_pct=evasion_check(e.m,sp.n) local use_ev=ev if hit_pct and not sp.nohit then use_ev=0 end -- will apply hit_pct separately local dmg if sp.halfres then local dmg1=calc_dmg(base*0.5*mult,ac,use_ev,pow,sp.noac,sp.nohit,sp.ac3,elec) local dmg2=calc_dmg(base*0.5,ac,use_ev,pow,sp.noac,sp.nohit,sp.ac3,elec) dmg=dmg1+dmg2 else dmg=calc_dmg(base*mult,ac,use_ev,pow,sp.noac,sp.nohit,sp.ac3,elec) end if hit_pct and not sp.nohit then dmg=dmg*hit_pct end dmg=sh_damage(dmg,e.m) -- Shock bounce: compute full ricochet path once, reuse for scoring local shock_hits,shock_enemies,shock_ekey if sp.n=="Shock" then shock_hits,shock_enemies=shock_bounce_hits(e.x,e.y,pow) shock_ekey=e.x..","..e.y local primary_hits=shock_hits[shock_ekey] or 1 dmg=dmg*primary_hits end if sp.n=="Iskenderun's Mystic Blast" then -- knockback: push enemy up to 2+pow/50 tiles away from player -- collision with wall or another monster deals 2d(1+pow/10) extra local kd=2+pow/50 local dx=e.x>0 and 1 or (e.x<0 and -1 or 0) local dy=e.y>0 and 1 or (e.y<0 and -1 or 0) local kx,ky=e.x,e.y local col_dmg=get_spell_dmg("IMB_collision",pow) for _=1,math.floor(kd) do local nx,ny=kx+dx,ky+dy if is_solid(nx,ny) then dmg=dmg+calc_dmg(col_dmg,get_ac(e.m),0,pow,false,true) break end local om=monster.get_monster_at(nx,ny) if om and om:attitude()==0 and not om:is_firewood() then local cd=calc_dmg(col_dmg,get_ac(e.m),0,pow,false,true) dmg=dmg+cd local cd2=calc_dmg(col_dmg,get_ac(om),0,pow,false,true) dmg=dmg+cd2 break end kx=nx;ky=ny end if cdist(e.x,e.y)<=1 then dmg=dmg*1.3 end end -- Note: penetrate intermediate damage is scored per-monster below, not added to primary dmg if dmg>0 then local val=score_dmg(dmg,e.m,cdist(e.x,e.y)) -- Shock bounce: add score for all enemies hit on bounce path if sp.n=="Shock" and shock_hits then local bounce_count=0 for key,info in pairs(shock_enemies) do if key~=shock_ekey then local hits=shock_hits[key] local r2=get_res(info.m,sp.e) local m2=1.0 if r2==-1 then m2=1.5 elseif r2==1 then m2=0.5 elseif r2==2 then m2=0 elseif r2>=3 then m2=0.0 end if m2>0 then local b2=get_spell_dmg(sp.n,pow) local hitC=evasion_check(info.m,sp.n) or math.max(0,1.0-get_ev(info.m)/50.0) local d2 if sp.halfres then local d2a=calc_dmg(b2*0.5*m2,get_ac(info.m),0,pow,sp.noac,true,sp.ac3,elec) local d2b=calc_dmg(b2*0.5,get_ac(info.m),0,pow,sp.noac,true,sp.ac3,elec) d2=(d2a+d2b)*hitC else d2=calc_dmg(b2*m2,get_ac(info.m),0,pow,sp.noac,true,sp.ac3,elec)*hitC end d2=sh_damage(d2,info.m)*hits val=val+score_dmg(d2,info.m,cdist(info.x,info.y)) bounce_count=bounce_count+1 end end end -- Bounce alignment bonus: more enemies hit = stronger preference if bounce_count>=1 then val=val*(1.0+bounce_count*0.5) end end if sp.penetrate and sp.n~="Shock" then local reachChance2=1.0 local others=found_star and monsters_on_line(e.x,e.y) or monsters_on_path(sp.n,e.x,e.y) local lineup_count=0 for _,other in ipairs(others) do local r2=get_res(other.m,sp.e) local m2=1.0 if r2==-1 then m2=1.5 elseif r2==1 then m2=0.5 elseif r2==2 then m2=0 elseif r2>=3 then m2=0.0 end if m2>0 then local b2=get_spell_dmg(sp.n,pow) local hitC=evasion_check(other.m,sp.n) or math.max(0,1.0-get_ev(other.m)/50.0) local d2=calc_dmg(b2*m2,get_ac(other.m),0,pow,sp.noac,true,sp.ac3,elec)*hitC*reachChance2 d2=sh_damage(d2,other.m) val=val+score_dmg(d2,other.m,cdist(other.x,other.y)) reachChance2=reachChance2*(1-hitC) lineup_count=lineup_count+1 end end -- Bolt alignment bonus: prefer penetrating bolts when enemies line up if lineup_count>=1 then val=val*(1.0+lineup_count*0.3) end end -- Soft penalty for single-target spells needing many casts to kill local kn=1 if not sp.aoe and not sp.penetrate and not sp.beam then local total_dmg=dmg+(has_bsph and not sp.no_bsph and bsph_raw or 0) kn=math.ceil(hp/math.max(total_dmg,1)) if kn>4 then val=val*math.max(0.25,0.8^(kn-4)) end end if val>best_val then best_val=val;best_tx=e.x;best_ty=e.y;best_kn=kn end end end end -- Shock wall-bounce: score wall-aimed ricochets that may outperform direct shots if sp.n=="Shock" and #shock_wall_targets>0 then for _,wt in ipairs(shock_wall_targets) do local val=0 local bounce_count=0 for key,info in pairs(wt.enemies) do local hits=wt.hits[key] local r2=get_res(info.m,sp.e) local m2=1.0 if r2==-1 then m2=1.5 elseif r2==1 then m2=0.5 elseif r2==2 then m2=0 elseif r2>=3 then m2=0.0 end if m2>0 then local b2=get_spell_dmg(sp.n,pow) local hitC=evasion_check(info.m,sp.n) or math.max(0,1.0-get_ev(info.m)/50.0) local d2 if sp.halfres then local d2a=calc_dmg(b2*0.5*m2,get_ac(info.m),0,pow,sp.noac,true,sp.ac3,elec) local d2b=calc_dmg(b2*0.5,get_ac(info.m),0,pow,sp.noac,true,sp.ac3,elec) d2=(d2a+d2b)*hitC else d2=calc_dmg(b2*m2,get_ac(info.m),0,pow,sp.noac,true,sp.ac3,elec)*hitC end d2=sh_damage(d2,info.m)*hits val=val+score_dmg(d2,info.m,cdist(info.x,info.y)) bounce_count=bounce_count+1 end end if bounce_count>=1 then val=val*(1.0+bounce_count*0.5) end if val>best_val then best_val=val;best_tx=wt.x;best_ty=wt.y end end end end if best_val>0 then local penalty=1.0 if sp.channeled and sp.n=="Flame Wave" then penalty=0.33 end if sp.slow then -- 1.5 turn cast: scale penalty by closest enemy distance local min_d=99 for _,e in ipairs(t) do local d=cdist(e.x,e.y) if d2 then best_val=best_val*0.5 end end -- Tactical modifiers: depth, corridor, fight type local tac=1.0 -- Depth scaling: early game penalizes expensive, late game penalizes cheap if depth_tier==1 and cost>=7 then tac=tac*0.6 elseif depth_tier==3 and cost<=3 then tac=tac*0.5 end -- Corridor: boost beam/penetrate, penalize wide AoE if in_corridor then if sp.beam or sp.penetrate then tac=tac*1.3 elseif sp.aoe and sp.aoe>=2 then tac=tac*0.7 end end -- Boss fight: boost single-target burst if boss_fight and not sp.aoe then tac=tac*1.3 end -- Swarm fight: boost AoE if swarm_fight and sp.aoe then tac=tac*1.3 end -- Mana conservation: prefer cheap spells when low MP and no critical threat if mp<=mp_max*0.3 and adj_hostiles==0 and cost>=5 then tac=tac*0.6 end -- Ignite Poison: boost when many enemies already poisoned (OTR synergy) if sp.n=="Ignite Poison" and n_poisoned>0 then local pois_frac=n_poisoned/#t if pois_frac>=0.5 then tac=tac*(1.0+pois_frac) end end local eff_val=best_val*penalty*tac/math.sqrt(cost) local entry={n=sp.n,v=eff_val,x=best_tx,y=best_ty,c=cost,ch=sp.channeled,manual=sp.mortar,ep=not (sp.clutch or sp.penetrate),ki=best_kn} if cost<=mp then table.insert(candidates,entry) elseif cost==mp+1 then table.insert(almost,entry) end end end end end -- 2-Turn Combo Lookahead: boost setup spells if payoff spell benefits next turn -- Poison → Ignite Poison combo local has_ignite=spells.memorised("Ignite Poison") if has_ignite then local ig_pow=get_pow("Ignite Poison") local ig_cost=get_cost("Ignite Poison") local ig_base=get_spell_dmg("Ignite Poison",ig_pow) -- Count how many enemies are NOT currently poisoned (Ignite can't hit them yet) local unpoisoned={} for _,e in ipairs(t) do local r=get_res(e.m,4) -- poison resistance if r<2 then -- not poison-immune local ok,st=pcall(function() return e.m:status("poisoned") end) if not (ok and st) then unpoisoned[#unpoisoned+1]=e end end end if #unpoisoned>0 then -- For each poison-applying candidate, calculate Ignite Poison payoff next turn for _,c in ipairs(candidates) do local is_poison_setup=(c.n=="Poisonous Vapours" or c.n=="Mercury Arrow") local is_aoe_poison=(c.n=="Olgreb's Toxic Radiance") if is_poison_setup or is_aoe_poison then local combo_val=0 local targets_hit=is_aoe_poison and unpoisoned or {} -- Single-target poison: only the targeted enemy gets poisoned if is_poison_setup then for _,e in ipairs(unpoisoned) do if e.x==c.x and e.y==c.y then targets_hit={e};break end end end -- Simulate Ignite Poison damage on newly-poisoned targets for _,e in ipairs(targets_hit) do local r=get_res(e.m,3) -- fire resistance for Ignite local mult=1.0 if r==-1 then mult=1.5 elseif r==1 then mult=0.5 elseif r>=2 then mult=0 end if mult>0 then local ac=get_ac(e.m) local ev=get_ev(e.m) local dmg=calc_dmg(ig_base*mult,ac,ev,ig_pow,false,false,false) combo_val=combo_val+score_dmg(dmg,e.m,cdist(e.x,e.y)) end end -- Add discounted future value (0.7 = next turn uncertainty) -- MP check: can we afford setup + payoff next turn? (mp_regen ≈ mp_max/10) if combo_val>0 and (mp-c.c+mp_regen)>=ig_cost then c.v=c.v+combo_val*0.7/math.sqrt(ig_cost) end end end end end -- BVC → EV reduction combo: constriction helps all future non-nohit spells for _,c in ipairs(candidates) do if c.n=="Borgnjor's Vile Clutch" then -- Find best non-nohit spell for EV synergy calculation local best_followup=0 for _,c2 in ipairs(candidates) do if c2.n~=c.n and c2.v>best_followup then best_followup=c2.v end end -- Constriction gives -10 EV; rough estimate: 10/50 = 20% more hits -- Apply to best follow-up spell score if best_followup>0 then c.v=c.v+best_followup*0.2*0.7 -- 20% hit improvement, 0.7 discount end end end -- Generic 2-turn lookahead: boost cheap spells if expensive finisher available next turn if #candidates>1 then for _,c in ipairs(candidates) do local next_mp=mp-c.c+mp_regen if next_mp>0 then local best_next=0 for _,c2 in ipairs(candidates) do if c2.n~=c.n and c2.c<=next_mp and c2.v>best_next then best_next=c2.v end end if best_next>0 then c.v=c.v+best_next*0.5 end end end end table.sort(candidates,function(a,b) return a.v>b.v end) local b=candidates[1] -- If top candidate is channeled but not significantly better than non-channeled, prefer non-channeled if b and b.ch and #candidates>1 and b.n=="Flame Wave" then local best_non_ch=nil for _,c in ipairs(candidates) do if not c.ch then best_non_ch=c;break end end if best_non_ch and b.v < best_non_ch.v * 1.2 then b=best_non_ch end end -- If already channeling, don't override unless significantly better (2x) if recently_cast("Flame Wave") or recently_cast("Searing Ray") then -- If best option is the channeled spell itself, just continue if b and (b.n == "Flame Wave" or b.n == "Searing Ray") then crawl.mpr("Cont") return end -- Check if any option is significantly better (2x) local has_better = false for _,c in ipairs(candidates) do if c.v > 20 * 2 then -- assume current channel does 20 dmg/turn has_better = true break end end if not has_better then crawl.mpr("Cont") return -- don't interrupt channeling end end if not b then for _,c in ipairs(candidates) do local cost_diff=mp-c.c if cost_diff>=0 or cost_diff>=-1 then b=c break end end end -- Check if a significantly better spell is 1 MP away — wait instead of casting weaker -- Don't wait if current spell is practical (kills in ≤4 casts) if b and #almost>0 then table.sort(almost,function(a,ab) return a.v>ab.v end) if (not b.ki or b.ki>4) and almost[1].v > b.v*1.5 then crawl.mpr("Wait 1MP for "..almost[1].n) return end end if b then -- Check MP reserve for escape spells (override if current spell is lethal: kills ≤3) if reserve_mp>0 and (mp-b.c)3) then crawl.mpr("Reserve "..reserve_mp.."MP for "..reserve_spell) else mark_cast(b.n) crawl.mpr(b.n) if b.manual then crawl.sendkeys("z"..spells.letter(b.n)) else spells.cast(b.n,b.x,b.y,b.ep) end end else crawl.mpr("No") end end } ## macros += M O G> ## macros += M 9 G\{13} bindkey = [f5] CMD_DISPLAY_SPELLS dos_use_background_intensity = true # Add the following to your options file to automatically pick up # armour for non-body armour slots (gloves, boots, etc.), if you don't # already have an item equipped there. { add_autopickup_func(function(it, name) if it.is_useless then return end if it.class(true) == "armour" then local good_slots = {cloak="Cloak", helmet="Helmet", gloves="Gloves", boots="Boots"} st, _ = it.subtype() if good_slots[st] ~= nil and items.equipped_at(good_slots[st]) == nil then return true end end end) }