diff --git a/desktop/src-common/advent/actions.clj b/desktop/src-common/advent/actions.clj index 949b2284..72c8bdd2 100644 --- a/desktop/src-common/advent/actions.clj +++ b/desktop/src-common/advent/actions.clj @@ -25,7 +25,9 @@ (get-channel [this])) (defn has-item? [entities item] - ((set (get-in entities [:state :inventory])) item)) + (if (map? entities) + ((set (get-in entities [:state :inventory])) item) + ((set (get-in @entities [:state :inventory])) item))) (defn has-one-of? [entities items] (seq (set/intersection (set (get-in entities [:state :inventory])) (set items)))) @@ -339,7 +341,7 @@ (-> entities (update-in [:state :inventory] #(conj % item)) - (assoc-in [:cursor :current] (:cursor item)))) + (assoc-in [:cursor :current] ((:all-items entities) item)))) (continue [this screen entities] entities) diff --git a/desktop/src-common/advent/screens/items.clj b/desktop/src-common/advent/screens/items.clj index 7dbdc055..02457fff 100644 --- a/desktop/src-common/advent/screens/items.clj +++ b/desktop/src-common/advent/screens/items.clj @@ -12,9 +12,9 @@ (def make-cat-toy (actions/get-script entities - (actions/remove-item entities stick) - (actions/remove-item entities wool) - (actions/give entities cat-toy) + (actions/remove-item entities :stick) + (actions/remove-item entities :wool) + (actions/give entities :cat-toy) (actions/talk entities :ego "It makes a little cat toy!"))) (def wool {:name "Wool" :value :wool :cursor :wool :scripts {:stick make-cat-toy}}) @@ -25,10 +25,10 @@ (defn make-cream-of-mushroom [] (actions/get-script entities - (actions/remove-item entities flask-1-with-mushrooms) - (actions/remove-item entities flask-1-with-milk) - (actions/remove-item entities mushrooms) - (actions/give entities flask-1-with-cream-of-mushroom) + (actions/remove-item entities :flask-1-with-mushrooms) + (actions/remove-item entities :flask-1-with-milk) + (actions/remove-item entities :mushrooms) + (actions/give entities :flask-1-with-cream-of-mushroom) (actions/talk entities :ego "It's just like cream of mushroom soup."))) (def flask-1-with-milk {:name "Flask with milk" :value :flask-1-with-milk :cursor :flask-with-contents @@ -37,9 +37,9 @@ (def flask-1-strength {:name "Strength potion" :value :flask-1-strength :cursor :flask-with-strength}) (def flask-1 {:name "Flask" :value :flask-1 :cursor :flask :scripts {:mushrooms (actions/get-script entities - (actions/remove-item entities flask-1) - (actions/remove-item entities mushrooms) - (actions/give entities flask-1-with-mushrooms) + (actions/remove-item entities :flask-1) + (actions/remove-item entities :mushrooms) + (actions/give entities :flask-1-with-mushrooms) (actions/talk entities :ego "I'll just put a few of these in here."))}}) (def trophy {:name "Trophy of wisdom" :value :trophy :cursor :trophy}) @@ -61,9 +61,9 @@ (defn make-strength-potion [] (actions/get-script entities - (actions/remove-item entities flask-1-with-cream-of-mushroom) - (actions/remove-item entities slobber) - (actions/give entities flask-1-strength) + (actions/remove-item entities :flask-1-with-cream-of-mushroom) + (actions/remove-item entities :slobber) + (actions/give entities :flask-1-strength) (actions/talk entities :ego "It's the completed potion of strength!"))) (def slobber {:name "Bull slobber" :value :slobber :cursor :slobber :scripts {:flask-1-with-cream-of-mushroom (make-strength-potion)}}) @@ -73,3 +73,40 @@ (def medal {:name "Medal of strength" :value :medal :cursor :medal}) (def certificate {:name "Certificate of courage" :value :certificate :cursor :certificate}) + + +(def items + {:wool {:name "Wool" :value :wool :cursor :wool :scripts {:stick make-cat-toy}} + :mushrooms {:name "Mushrooms" :value :mushrooms :cursor :mushrooms} + :carrot {:name "Carrot" :value :carrot :cursor :carrot} + :flask-1-with-mushrooms {:name "Flask with mushrooms" :value :flask-1-with-mushrooms :cursor :flask-with-contents} + :flask-1-with-milk {:name "Flask with milk" :value :flask-1-with-milk :cursor :flask-with-contents + :scripts {:mushrooms (make-cream-of-mushroom)}} + + :flask-1-strength {:name "Strength potion" :value :flask-1-strength :cursor :flask-with-strength} + :flask-1 {:name "Flask" :value :flask-1 :cursor :flask + :scripts {:mushrooms (actions/get-script entities + (actions/remove-item entities :flask-1) + (actions/remove-item entities :mushrooms) + (actions/give entities :flask-1-with-mushrooms) + (actions/talk entities :ego "I'll just put a few of these in here."))}} + :trophy {:name "Trophy of wisdom" :value :trophy :cursor :trophy} + :cheat-deck {:name "Warlock's Tower cheat deck" :value :cheat-deck :cursor :cheat-deck} + :cat-toy {:name "Cat toy" :value :cat-toy :cursor :cat-toy} + :stick {:name "Stick" :value :stick :cursor :stick :scripts {:wool make-cat-toy}} + :balloon {:name "Choicest of balloons" :value :balloon :cursor :balloon} + :frog-legs {:name "Frog legs" :value :frog-legs :cursor :frog-legs} + :ladder {:name "ladder" :value :ladder :cursor :ladder} + :teddy {:name "Teddy Bear" :value :teddy :cursor :teddy} + :portrait {:name "Portrait" :value :portrait :cursor :portrait} + :recipe {:name "Strength potion recipe" :value :recipe :cursor :recipe} + :glass-eye {:name "Choicest of glass eyes" :value :glass-eye :cursor :glass-eye} + :motivational-tapes {:name "Choicest motivational tapes" :value :motivational-tapes :cursor :motivational-tapes} + :used-earplugs {:name "Choicest used earplugs" :value :used-earplugs :cursor :used-earplugs} + :grass {:name "Huge grass" :value :grass :cursor :grass} + :slobber {:name "Bull slobber" :value :slobber :cursor :slobber :scripts {:flask-1-with-cream-of-mushroom (make-strength-potion)}} + :flask-1-with-cream-of-mushroom {:name "Flask with cream of mushrooms soup" :value :flask-1-with-cream-of-mushroom :cursor :flask-with-contents + :scripts {:slobber (make-strength-potion)}} + :medal {:name "Medal of strength" :value :medal :cursor :medal} + :certificate {:name "Certificate of courage" :value :certificate :cursor :certificate} + }) diff --git a/desktop/src-common/advent/screens/rooms/behind_house.clj b/desktop/src-common/advent/screens/rooms/behind_house.clj index 8877073a..03454cf6 100644 --- a/desktop/src-common/advent/screens/rooms/behind_house.clj +++ b/desktop/src-common/advent/screens/rooms/behind_house.clj @@ -26,12 +26,12 @@ :mushrooms {:box [247 59 269 76] :script (actions/get-script entities - (if (actions/has-item? @entities items/mushrooms) + (if (actions/has-item? entities :mushrooms) (actions/talk entities :ego "I've already got a junk ton of mushrooms.") (do (actions/walk-to entities :ego [242 75]) (actions/play-animation entities :ego :squat) - (actions/give entities items/mushrooms) + (actions/give entities :mushrooms) (actions/talk entities :ego "Perfectly ripe mushrooms!"))))} :window {:box [103 44 130 140] :script (actions/get-script @@ -47,7 +47,7 @@ (actions/walk-to entities :ego [50 80]) (actions/play-animation entities :ego :reach) (actions/remove-entity entities :stick) - (actions/give entities items/stick) + (actions/give entities :stick) (actions/talk entities :ego "This stick might be useful.") )) :peeling (assoc (texture "behindhouse/house-cover.png") @@ -74,6 +74,6 @@ (if (get-in entities [:state :opened-crack?]) (assoc-in entities [:room :entities :peeling :opacity] 0) entities) - (if (actions/has-one-of? entities [items/stick items/cat-toy]) + (if (actions/has-one-of? entities [:stick :cat-toy]) (update-in entities [:room :entities] #(dissoc % :stick)) entities))))) diff --git a/desktop/src-common/advent/screens/rooms/cat_tree.clj b/desktop/src-common/advent/screens/rooms/cat_tree.clj index 988c183e..0c651def 100644 --- a/desktop/src-common/advent/screens/rooms/cat_tree.clj +++ b/desktop/src-common/advent/screens/rooms/cat_tree.clj @@ -14,7 +14,7 @@ (actions/play-animation entities :ego :reach) (actions/remove-entity entities :blank) (actions/remove-entity entities :ladder) - (actions/give entities items/ladder)) + (actions/give entities :ladder)) (defn make [screen] (let [cat-stand-sheet (texture! (texture "cat-tree/cat-stand.png") :split 22 10) @@ -34,7 +34,7 @@ (actions/talk entities :ego "I'll just set this up.") (actions/walk-to entities :ego [151 50] :face :left) (actions/play-animation entities :ego :reach) - (actions/remove-item entities items/ladder) + (actions/remove-item entities :ladder) (actions/add-entity entities :ladder ladder-entity) (actions/walk-straight-to entities :ego [140 85] :face :right :update-baseline? false) (actions/add-entity entities :blank (rooms/make-entity :blank @@ -60,13 +60,13 @@ (actions/remove-entity entities :cat) (get-down entities) (actions/talk entities :ego "TODO: get award from little old lady in this room") - (actions/give entities items/certificate)) + (actions/give entities :certificate)) (actions/talk entities :ego "I guess I'm too far away.")))}) cat-stand)} :collision "cat-tree/collision.png" :scale-fn (utils/scaler-fn-with-baseline 110 0.10 1.20) :apply-state (fn [entities] (as-> entities entities - (if (actions/has-item? entities items/certificate) + (if (actions/has-item? entities :certificate) (update-in entities [:room :entities] #(dissoc % :cat)) entities)))))) diff --git a/desktop/src-common/advent/screens/rooms/inside_antique.clj b/desktop/src-common/advent/screens/rooms/inside_antique.clj index 72325219..e124c2cc 100644 --- a/desktop/src-common/advent/screens/rooms/inside_antique.clj +++ b/desktop/src-common/advent/screens/rooms/inside_antique.clj @@ -67,7 +67,7 @@ :shopkeep "Yes, that's it!" :shopkeep "You must have really met my son!" :shopkeep "Of course you can keep the teddy bear.") - (actions/give entities items/teddy))}]}]} + (actions/give entities :teddy))}]}]} "How's life in the antique shop biz?" {:run #(actions/respond entities % :shopkeep "Pretty lonely." @@ -89,12 +89,12 @@ {:down {:box [60 0 290 25] :cursor :down :script (actions/get-script entities - (when ((set (get-in @entities [:state :inventory])) items/portrait) + (when (actions/has-item? entities :portrait) (actions/walk-to entities :ego [222 3]) (actions/talk entities :shopkeep "Excuse me sonny. Please return my belongings before you leave.") (actions/walk-to entities :ego [136 80] :face :left) (actions/play-animation entities :ego :reach) - (actions/remove-item entities items/portrait)) + (actions/remove-item entities :portrait)) (actions/walk-to entities :ego [222 3]) (actions/transition-background entities :inside-castle [182 90]))} :window {:box [212 130 256 180] @@ -120,7 +120,7 @@ (actions/play-animation entities :ego :reach) (actions/talk entities :ego "It's a portrait. There's something on the back but I can't read it.") (actions/remove-entity entities :portrait) - (actions/give entities items/portrait))) + (actions/give entities :portrait))) :bowl (assoc (texture "inside-antique/bowl.png") :x 155 :y 125 diff --git a/desktop/src-common/advent/screens/rooms/inside_cafeteria.clj b/desktop/src-common/advent/screens/rooms/inside_cafeteria.clj index 415b56f5..7fac75cc 100644 --- a/desktop/src-common/advent/screens/rooms/inside_cafeteria.clj +++ b/desktop/src-common/advent/screens/rooms/inside_cafeteria.clj @@ -37,7 +37,7 @@ "I challenge you to a arm wrestling match to prove my strength." {:run (fn [msg] (actions/respond entities msg :warriors "Prepare thyself, thy task is not for the feint of heart") - (if ((set (get-in @entities [:state :inventory])) items/flask-1-strength) + (if (actions/has-item? @entities :flask-1-strength) (do (actions/do-dialogue entities :ego "One sec.") (actions/play-animation entities :ego :grow) @@ -45,7 +45,7 @@ :warriors "[Todo animation here]" :warriors "Congratulations young master. Thou art worthy in might." :warriors "Take my medal of strength.") - (actions/give entities items/medal)) + (actions/give entities :medal)) (do (actions/do-dialogue entities :warriors "[Todo animation here]" @@ -83,7 +83,7 @@ (actions/walk-to entities :ego [245 75] :face :right) (actions/play-animation entities :ego :reach) (actions/remove-entity entities :ladder) - (actions/give entities items/ladder))} + (actions/give entities :ladder))} "Nevermind." {:run #(actions/respond entities %)}]} "Nevermind." @@ -150,6 +150,6 @@ :scale-fn (utils/scaler-fn-with-baseline 110 0.10 1.50) :apply-state (fn [entities] (as-> entities entities - (if (actions/has-item? entities items/ladder) + (if (actions/has-item? entities :ladder) (update-in entities [:room :entities] #(dissoc % :ladder)) entities)))))) diff --git a/desktop/src-common/advent/screens/rooms/inside_castle.clj b/desktop/src-common/advent/screens/rooms/inside_castle.clj index 9138491a..ea2a4912 100644 --- a/desktop/src-common/advent/screens/rooms/inside_castle.clj +++ b/desktop/src-common/advent/screens/rooms/inside_castle.clj @@ -137,7 +137,7 @@ :scripts {:wool (actions/get-script entities (if (= :wool (get-in @entities [:state :current-riddle])) (do (actions/update-state entities #(assoc % :current-riddle :balloon)) - (actions/remove-item entities items/wool) + (actions/remove-item entities :wool) (actions/do-dialogue entities :game-player "That's right! Now for your second riddle:" :game-player "Filled with air, light as a feather," @@ -146,7 +146,7 @@ :balloon (actions/get-script entities (if (= :balloon (get-in @entities [:state :current-riddle])) (do (actions/update-state entities #(assoc % :current-riddle :frog-legs)) - (actions/remove-item entities items/balloon) + (actions/remove-item entities :balloon) (actions/do-dialogue entities :game-player "That's right! Now for your third riddle:" :game-player "Hippity-hop, I jump really far," @@ -156,12 +156,12 @@ (if (= :frog-legs (get-in @entities [:state :current-riddle])) (do (actions/update-state entities #(assoc % :current-riddle :done)) - (actions/remove-item entities items/frog-legs) + (actions/remove-item entities :frog-legs) (actions/do-dialogue entities :game-player "Wow! That's right!" :game-player "I guess I'm not the wisest person in Remington." :game-player "You have earned my trophy.") - (actions/give entities items/trophy)) + (actions/give entities :trophy)) (actions/talk entities :ego "He doesn't need it.")))} :anim nil :talk game-player-talk)} @@ -169,6 +169,6 @@ :scale-fn (utils/scaler-fn-from-image "inside-castle/scale.png" 0.25 1.00) :apply-state (fn [entities] (as-> entities entities - (if (actions/has-item? entities items/ladder) + (if (actions/has-item? entities :ladder) (update-in entities [:room :entities] #(dissoc % :ladder)) entities)))))) diff --git a/desktop/src-common/advent/screens/rooms/inside_house.clj b/desktop/src-common/advent/screens/rooms/inside_house.clj index 7337d68d..855aeb02 100644 --- a/desktop/src-common/advent/screens/rooms/inside_house.clj +++ b/desktop/src-common/advent/screens/rooms/inside_house.clj @@ -15,11 +15,11 @@ :success (actions/get-script entities (actions/talk entities :ego "Yes! That worked.") (actions/play-animation entities :ego :squat) - (actions/give entities items/recipe) + (actions/give entities :recipe) (actions/talk entities :ego "I found a recipe for a strength potion!") (actions/talk entities :ego "Looks like there's something else in here too...") (actions/play-animation entities :ego :squat) - (actions/give entities items/frog-legs) + (actions/give entities :frog-legs) (actions/talk entities :ego "Eww. Frog legs.")) :failure (actions/get-script entities (actions/talk entities :ego "I don't think that worked..."))) @@ -78,13 +78,13 @@ :x 265 :y 80 :baseline 240 :script (actions/get-script entities (actions/remove-entity entities :flask) - (actions/give entities items/flask-1) + (actions/give entities :flask-1) (actions/do-dialogue entities :ego "Hey you think I could have this flask?" :wizard "Sure.")))} :collision "inside-house/collision.png" :scale-fn (utils/scaler-fn-with-baseline 110 0.10 1.75) :apply-state (fn [entities] (as-> entities entities - (if (actions/has-one-of? entities [items/flask-1 items/flask-1-with-cream-of-mushroom items/flask-1-strength items/flask-1-with-mushrooms items/flask-1-with-milk]) + (if (actions/has-one-of? entities [:flask-1 :flask-1-with-cream-of-mushroom :flask-1-strength :flask-1-with-mushrooms :flask-1-with-milk]) (update-in entities [:room :entities] #(dissoc % :flask)) entities)))))) diff --git a/desktop/src-common/advent/screens/rooms/outside_castle.clj b/desktop/src-common/advent/screens/rooms/outside_castle.clj index f4bcad67..fd0dc1fe 100644 --- a/desktop/src-common/advent/screens/rooms/outside_castle.clj +++ b/desktop/src-common/advent/screens/rooms/outside_castle.clj @@ -33,14 +33,14 @@ :garden {:box [103 170 178 200] :script (actions/get-script entities - (if (actions/has-item? @entities items/carrot) + (if (actions/has-item? entities :carrot) (actions/talk entities :ego "If I steal any more, I might get caught.") (do (actions/walk-to entities :ego [128 180]) (actions/talk entities :ego "Hey! Carrots.") (actions/play-animation entities :ego :squat) (actions/talk entities :ego "No one will notice one missing.") - (actions/give entities items/carrot))))} + (actions/give entities :carrot))))} :peddler {:box [110 90 128 146] :script (actions/get-script entities @@ -95,7 +95,7 @@ :peddler "If you can bring me a nice kid's toy, I will give you the tapes."))} "Nevermind." {:run #(actions/respond entities % :peddler "Goodbye, sir.")}]})) :scripts {:teddy (actions/get-script entities - (actions/remove-item entities items/teddy) + (actions/remove-item entities :teddy) (actions/do-dialogue entities :peddler "That is the choicest of teddy bears!" :peddler "True to my word, I will give you one of my wares." @@ -103,15 +103,15 @@ (actions/present-choices entities {:choices ["The glass eye." {:run #(do (actions/respond entities % :peddler "Of course sir. Here you go.") - (actions/give entities items/glass-eye))} + (actions/give entities :glass-eye))} "The motivational tapes." {:run #(do (actions/respond entities % :peddler "Of course sir. Here you go.") - (actions/give entities items/motivational-tapes))} + (actions/give entities :motivational-tapes))} "The used earplugs." {:run #(do (actions/respond entities % :peddler "Of course sir. Here you go.") - (actions/give entities items/used-earplugs))}]}) + (actions/give entities :used-earplugs))}]}) (actions/talk entities :peddler "And, of course, here is your balloon.") - (actions/give entities items/balloon) + (actions/give entities :balloon) (actions/talk entities :peddler "Thank you for your business!"))}}} :layers [(assoc (texture "outside-castle/background.png") :x 0 :y 0 :baseline 0)] :entities {:peddler (actions/start-animation screen @@ -124,8 +124,8 @@ :scripts {:grass (actions/get-script entities (actions/walk-to entities :ego [168 150] :face :right) (actions/play-animation entities :ego :reach) - (actions/remove-item entities items/grass) + (actions/remove-item entities :grass) (actions/talk entities :ego "Eww! He slobbered on my hand.") - (actions/give entities items/slobber))})} + (actions/give entities :slobber))})} :collision "outside-castle/collision.png" :scale-fn (utils/scaler-fn-with-baseline 110 0.10 1.00)))) diff --git a/desktop/src-common/advent/screens/rooms/outside_house.clj b/desktop/src-common/advent/screens/rooms/outside_house.clj index 66594584..fea1133e 100644 --- a/desktop/src-common/advent/screens/rooms/outside_house.clj +++ b/desktop/src-common/advent/screens/rooms/outside_house.clj @@ -166,12 +166,12 @@ :script (actions/get-script entities - (if (actions/has-item? @entities items/wool) + (if (actions/has-item? entities :wool) (actions/talk entities :ego "The sheep has given me enough wool.") (if (is-sheep-close? @entities) (do (actions/walk-to entities :ego ego-sheep-loc :face :left) (actions/play-animation entities :ego :reach) - (actions/give entities items/wool) + (actions/give entities :wool) (actions/talk entities :ego "I guess her wool is shedding.")) (actions/talk entities :ego "She's too far away for me to pet her.")))) :scripts {:wool (actions/get-script entities @@ -181,14 +181,14 @@ (actions/talk entities :ego "Come on girl, get the carrot!") (actions/walk-straight-to entities :sheep [95 150]) (actions/play-animation entities :ego :reach) - (actions/remove-item entities items/carrot) + (actions/remove-item entities :carrot) (actions/update-state entities #(assoc % :coaxed-sheep? true))) :flask-1 (actions/get-script entities (if (is-sheep-close? @entities) (do (actions/walk-to entities :ego ego-sheep-loc :face :left) (actions/play-animation entities :ego :reach) - (actions/remove-item entities items/flask-1) - (actions/give entities items/flask-1-with-milk) + (actions/remove-item entities :flask-1) + (actions/give entities :flask-1-with-milk) (actions/talk entities :ego "Sheeps milk.")) (actions/talk entities :ego "She's too far away."))) :flask-1-with-mushrooms (items/make-cream-of-mushroom)} diff --git a/desktop/src-common/advent/screens/scene.clj b/desktop/src-common/advent/screens/scene.clj index c3558f2d..3267cf71 100644 --- a/desktop/src-common/advent/screens/scene.clj +++ b/desktop/src-common/advent/screens/scene.clj @@ -43,7 +43,7 @@ (get-in entities [:room :interactions])))) (defn open-inventory [screen entities] - (screen! inventory-screen :show-screen :items (get-in entities [:state :inventory])) + (screen! inventory-screen :show-screen :items (map (entities :all-items) (get-in entities [:state :inventory]))) (assoc-in entities [:state :active?] false)) @@ -150,12 +150,12 @@ ((zone/box (- entity-x half-width) entity-y (+ entity-x half-width) (+ entity-y height)) x y))) :get-script (fn [cursor [x y]] - (condp = cursor - items/flask-1-with-cream-of-mushroom (actions/get-script entities (actions/talk entities :ego "Blegh! Gross!")) - items/flask-1-strength (actions/get-script entities + (condp = (:value cursor) + :flask-1-with-cream-of-mushroom (actions/get-script entities (actions/talk entities :ego "Blegh! Gross!")) + :flask-1-strength (actions/get-script entities (actions/talk entities :ego "I'll just take a sip!") (actions/play-animation entities :ego :grow :stop? false)) - items/recipe (actions/get-script entities (actions/do-dialogue entities + :recipe (actions/get-script entities (actions/do-dialogue entities :ego "The recipe says:" :ego "'For strength beyond measure,'" :ego "'you must mix, at your leisure:'" @@ -210,7 +210,7 @@ (utils/load) {:object nil :active? true - :inventory [items/grass items/carrot] + :inventory [:grass :carrot] :clues #{} :mints-eaten 0})) (defscreen scene @@ -242,6 +242,7 @@ :current :main :last :main :override nil} + :all-items (assoc items/items :object nil) :room (assoc-in (:outside-house rooms) [:entities :ego] (get-ego screen)) :inventory (assoc (texture "inventory.png") :x 278 :y 0 :baseline 9000