From 553dc31bebc2c3baa8cb3e9038dca3be7186c48c Mon Sep 17 00:00:00 2001 From: Kodi Arfer Date: Sun, 21 Jan 2024 19:49:52 -0500 Subject: [PATCH] Implemented earthquake bombs. --- simalq/tile/__init__.hy | 7 +++--- simalq/tile/item.hy | 41 ++++++++++++++++++++++++++++++++++++ simalq/tile/unimplemented.hy | 1 - simalq/util.hy | 8 +++++-- tests/test_item.hy | 25 ++++++++++++++++++++++ 5 files changed, 76 insertions(+), 6 deletions(-) diff --git a/simalq/tile/__init__.hy b/simalq/tile/__init__.hy index bda5ba2..ec0dbc2 100644 --- a/simalq/tile/__init__.hy +++ b/simalq/tile/__init__.hy @@ -97,8 +97,8 @@ (.insert (at pos) 0 @) (object.__setattr__ @ "pos" pos)) - (defmeth replace [new-stem] - (setv t ((get Tile.types new-stem) :pos @pos)) + (defmeth replace [new-stem #** kwargs] + (setv t ((get Tile.types new-stem) :pos @pos #** kwargs)) (setv (get (at @pos) (.index (at @pos) @)) t) (object.__setattr__ @ "pos" None) (@hook-pos-set t.pos None)) @@ -224,6 +224,7 @@ (un! k)))) ~@(gfor [k v] (.items (dict :mapsym mapsym #** kwargs)) + :setv k (un! k) ; Treat `(meth …)` and `(property-meth …)` forms specially. (cond (and (isinstance v hy.models.Expression) (= (get v 0) 'meth)) @@ -233,7 +234,7 @@ `(hy.R.simalq/macros.defmeth [property] ~(hy.models.Symbol k) ~@(cut v 1 None)) True - `(setv ~(hy.models.Symbol (un! k)) ~v))))) + `(setv ~(hy.models.Symbol k) ~v))))) (defn tiletype [cls] diff --git a/simalq/tile/item.hy b/simalq/tile/item.hy index 1d4ba63..42c3f59 100644 --- a/simalq/tile/item.hy +++ b/simalq/tile/item.hy @@ -1,4 +1,5 @@ (require + hyrule [branch] simalq.macros [unless defmeth] simalq.tile [deftile]) (import @@ -444,6 +445,46 @@ :flavor "Heavy ordnance. Kills monsters dead, with a bomb pattern that would put a feather in Colonel Cathcart's cap.\n\n \"Kaboom?\"\n \"Yes, Rico. Kaboom.\"") +(deftile "0 " "an earthquake bomb" Usable + :color 'dark-orange + :iq-ix 157 + :acquirement-points 200 + + :!quake-damage-monster 3 + :!quake-damage-wall 2 + :!new-cracked-wall-starting-hp 4 + :!use-burst-size 2 + :!shot-burst-size 1 + + :!bomb-burst (meth [target size] + (for [ + p (burst-damage target :damage-type DamageType.Fire + :amount (* [@quake-damage-monster] (+ size 1)) + :color 'dark-orange) + tile (list (at p))] + ; Contra IQ, we leave empty floor alone and don't create holes. + (branch (in tile.stem it) + ["wall" "trapped wall"] + (.replace tile "cracked wall" :hp @new-cracked-wall-starting-hp) + ["cracked wall"] + (.damage tile @quake-damage-wall None) + ["breakable wall (meridional)" "breakable wall (zonal)" "fading wall"] + (.rm-from-map tile) + ["pillar"] + (.replace tile "broken pillar")))) + + :use (meth [target] + (doc f"Explodes in a size-{@use-burst-size} burst that does {@quake-damage-monster} fire damage to monsters and {@quake-damage-wall} damage to cracked walls. Furthermore, the blast turns normal walls and trapped walls into cracked walls with {@new-cracked-wall-starting-hp} HP, instantly destroys breakable walls and fading walls, and breaks pillars.") + (@bomb-burst target @use-burst-size)) + + :hook-player-shot (meth [] + (doc f"As when used, but with a smaller size-{@shot-burst-size} burst.") + (@bomb-burst @pos @shot-burst-size) + (@rm-from-map)) + + :flavor "Magic and technology have combined into an explosive that can make the earth itself tremble in a limited area. The methodology was originally developed as an alternative to fracking, but it proved more useful in military applications.\n\n You were too tricky for your own good, Thanos!") + + (defclass Artifact [Item] (setv color-bg 'magenta) diff --git a/simalq/tile/unimplemented.hy b/simalq/tile/unimplemented.hy index c5d40e9..7b342cc 100644 --- a/simalq/tile/unimplemented.hy +++ b/simalq/tile/unimplemented.hy @@ -25,7 +25,6 @@ [151 "passwall_amulet"] [152 "random_gate"] [154 "wand_of_flame"] - [157 "earthquake_bomb"] [158 "ring_of_protection"] [159 "amulet_of_poisonous_touch"] [163 "archmage"] diff --git a/simalq/util.hy b/simalq/util.hy index 845cd8a..d991b64 100644 --- a/simalq/util.hy +++ b/simalq/util.hy @@ -155,7 +155,9 @@ 1]`, which means that 3 damage is dealt at the center, 2 damage is dealt at distance 1 from the center, and so on. But note that this damage is only dealt to non-player tiles. The player gets the - separate number `player-amount`, regardless of distance." + separate number `player-amount`, regardless of distance. + + Return the result from `burst`." (import simalq.geometry [burst at dist] @@ -172,4 +174,6 @@ (for [p b tile (at p) :if (isinstance tile Damageable)] (.damage tile (if (is tile G.player) player-amount (get amount (dist center p))) - damage-type))) + damage-type)) + + b) diff --git a/tests/test_item.hy b/tests/test_item.hy index d4ddd1a..beccf21 100644 --- a/tests/test_item.hy +++ b/tests/test_item.hy @@ -442,6 +442,31 @@ (check "super-bomb" 'use 3 3 2 2 1 1 0)) +(defn test-earthquake-bomb [] + (init [ + :map " + ██| #2█1 + ↑↓#1←→. + @ ╷ o ." + :map-marks { + "o " ["orc" :hp 10] + "#1" ["cracked wall" :hp 10] + "#2" ["cracked wall" :hp 2] + "█1" "trapped wall"}]) + + ; An earthquake bomb does 3 damage to monsters and 2 to cracked + ; walls. + (use-item "earthquake bomb" 1 1) + (assert-textmap :map-marks {"##" "cracked wall"} :text " + ##╷ . ## + . ##. . + @ ╷ o .") + (assert-hp [2 0] 7) + (assert-hp [1 1] 8) + (assert-hp [0 2] 4) + (assert-hp [3 2] 4)) + + (defn test-artifact-weapon [] ; The sword artifact increases melee damage to 3. Multiple copies