(ns advent.screens.rooms.inside-antique (:require [advent.screens.rooms :as rooms] [advent.actions :as actions] [advent.screens.items :as items] [advent.utils :as utils] [clojure.zip :as zip] [play-clj.core :refer :all] [play-clj.ui :refer :all] [play-clj.utils :refer :all] [play-clj.g2d :refer :all])) (defn do-antique-dialogue [entities] (actions/do-dialogue entities :shopkeep "Welcome to my antique shop!" :shopkeep "Can I help you?") (actions/present-choices entities {:choices ["What do you have for sale here?" {:run #(actions/respond entities % :shopkeep "For sale?" :shopkeep "This is a very UNIQUE antique shop." :shopkeep "Nothing's for sale, sonny." :shopkeep "It's more like a museum." :shopkeep "You can take look around at some of my items, but nothing is for sale.") :choices ["How do you make money then?" {:run #(actions/respond entities % :shopkeep "Mostly insurance claims." :shopkeep "When you run such an impressive shop as I do, items sometimes just go missing.") :choices actions/previous-choices} "Is there anything here you will sell?" {:run #(actions/respond entities % :shopkeep "No." :shopkeep "But I do have some free magical lava mints that Gandarf brewed up." :shopkeep "Careful! They're spicy.") :choices actions/previous-choices} "So in order to continue on my quest, I'll need to solve some puzzle here?" {:run #(actions/respond entities % :shopkeep "I have no idea what you're talking about, sonny.") :choices actions/previous-choices} "Something else." {:choices actions/something-else}]} (when (and (get-in @entities [:state :wants-toy]) (not (get-in @entities [:state :allowed-to-keep-teddy?]))) "Listen, I really need that teddy bear you have.") {:run #(actions/respond entities % :shopkeep "Why?" :shopkeep "It belonged to my long lost son." :shopkeep "Why should I give it to you?") :choices ["Because it's the choicest toy I've ever seen!" {:run #(actions/respond entities % :shopkeep "I'm sorry, it's not for sale.") :choices actions/something-else} "Your long lost son said I could have it." {:run #(do (actions/respond entities % :shopkeep "REALLY? You've met him?" :ego "... erm. Yes!" :shopkeep "If you really met him, you'll have to prove it." :shopkeep "What is my son's name?")) :choices ["... Bud?" {:run #(do (actions/respond entities % :shopkeep "No. That's not it.") (actions/play-animation entities :shopkeep :sigh) (actions/do-dialogue entities :ego "Oh. I must be thinking of another long lost son."))} "... Steve?" {:run #(do (actions/respond entities % :shopkeep "No. That's not it.") (actions/play-animation entities :shopkeep :sigh) (actions/do-dialogue entities :ego "Oh. I must be thinking of another long lost son."))} "... Bob?" {:run #(do (actions/respond entities % :shopkeep "No. That's not it.") (actions/play-animation entities :shopkeep :sigh) (actions/do-dialogue entities :ego "Oh. I must be thinking of another long lost son."))} (when ((get-in @entities [:state :clues]) :name) "Herb.") {:run #(do (actions/respond entities % :shopkeep "Yes, that's it!" :shopkeep "You must have really met my son!" :shopkeep "Of course you can keep the teddy bear.") (actions/update-state entities (fn [s] (assoc s :allowed-to-keep-teddy? true))))}]}]} "How's life in the antique shop biz?" {:run #(do (actions/respond entities % :shopkeep "Pretty lonely." :shopkeep "My long lost son used to help me run this shop, but he's been gone for five years now." :shopkeep "I've been couped up in here by myself ever since.") (actions/play-animation entities :shopkeep :sigh) (actions/do-dialogue entities :shopkeep "Now all I have is this grandfather clock to keep me company.")) :choices actions/previous-choices} "Nevermind." {:run #(actions/respond entities % :shopkeep "Feel free to look around.")}]})) (defn has-to-return-teddy? [entities] (and (actions/has-item? entities :teddy) (not (get-in @entities [:state :allowed-to-keep-teddy?])))) (defn make [screen] (let [shopkeep-sheet (texture! (texture "inside-antique/shopkeep-talk.png") :split 18 21) shopkeep-stand (animation 0.1 (for [i (flatten [(repeat 30 0) 1 (repeat 50 0) 1 0 1 0 1])] (aget shopkeep-sheet 0 i))) shopkeep-talk (animation 0.15 (for [i [0 2 0 2 0 3 1 0]] (aget shopkeep-sheet 0 i))) shopkeep-sigh (utils/make-anim "inside-antique/antique-sigh.png" [22 21] 0.2 (flatten [ (range 9) 0 0 0 0 0 0 ])) portrait (rooms/make-entity :portrait (assoc (texture "inside-antique/portrait.png") :x 112 :y 114 :baseline 120 :script (actions/get-script entities (actions/walk-to entities :ego [140 61] :face :left) (actions/play-animation entities :ego :reach) (actions/talk entities :ego "It's a portrait. There's something on the back but it's too dim to read.") (actions/remove-entity entities :portrait) (actions/give entities :portrait)))) beard (utils/make-anim "inside-antique/beard.png" [26 52] 0.5 [0 1 0 2]) teddy (assoc (texture "inside-antique/teddy.png") :x 255 :y 95 :baseline 160 :script (actions/get-script entities (actions/walk-to entities :ego [242 49] :face :right) (actions/play-animation entities :ego :reach) (actions/give entities :teddy) (actions/remove-entity entities :teddy) (when (not (get-in @entities [:state :allowed-to-keep-teddy?])) (actions/do-dialogue entities :ego "Aww, a cute teddy bear!" :shopkeep "Don't get any fast ideas." :shopkeep "That teddy bear does not leave my store."))))] (rooms/make :music :inside-antique :interactions {:right {:box [250 0 320 75] :cursor :right :script (actions/get-script entities (when (or (actions/has-item? entities :portrait) (has-to-return-teddy? entities)) (actions/walk-to entities :ego [235 15]) (actions/talk entities :shopkeep "Excuse me sonny. Please return my belongings before you leave.") (when (actions/has-item? entities :portrait) (actions/walk-to entities :ego [143 64] :face :left) (actions/play-animation entities :ego :reach) (actions/add-entity entities :portrait portrait) (actions/remove-item entities :portrait)) (when (has-to-return-teddy? entities) (actions/walk-to entities :ego [242 49] :face :right) (actions/play-animation entities :ego :reach) (actions/add-entity entities :teddy teddy) (actions/remove-item entities :teddy))) (actions/walk-to entities :ego [235 15] :stop? false :skip-type :end) (actions/walk-straight-to entities :ego [320 -5]) (actions/transition-background entities :inside-castle [182 90]) (actions/walk-to entities :ego [187 75]))} :window {:box [210 125 256 183] :script (actions/get-script entities (actions/talk entities :ego "It's a nice, big window.")) :scripts {:portrait (actions/get-script entities (actions/walk-to entities :ego [142 49] :face :left) (actions/play-animation entities :ego :hold-up-to-window) (actions/talk entities :ego "The portrait says 'Herb' on the back.") (actions/update-state entities (fn [state] (update-in state [:clues] #(conj % :name)) )))}} :grandfather-clock {:box [55 70 103 185] :script (actions/get-script entities (actions/do-dialogue entities :ego "Cool grandfather clock!" :shopkeep "It's quite the exquisit piece, isn't it?"))} :shelf {:box [0 60 52 199] :script (actions/get-script entities (actions/walk-to entities :ego [48 58]) (actions/talk entities :ego "All of these trinkets seem too bulky to fit in my pack."))} :flowers {:box [178 115 188 143] :script (actions/get-script entities (actions/update-state entities (fn [s] (assoc s :mints-eaten 0))) (actions/talk entities :ego "I've never been a fan of flowers."))} :lian {:box [264 103 317 198] :script (actions/get-script entities (actions/walk-to entities :ego [220 35] :face :right) (actions/do-dialogue entities :ego "It's a tapestry of Rupert the Lion!" :ego "He's the town of Remington's mascot."))} } :layers [(assoc (texture "inside-antique/background.png") :x 0 :y 0 :baseline 0) (assoc (texture "inside-antique/desk.png") :x 0 :y 0 :baseline 113) (assoc (texture "inside-antique/fg.png") :x 0 :y 0 :baseline 320 :parallax 1.5) (assoc (texture "inside-antique/glow.png") :x 0 :y 0 :baseline 240 :additive? true :opacity 0.3)] :entities {:shopkeep (actions/start-animation screen (assoc (animation->texture screen shopkeep-stand) :x 148 :y 122 :baseline 112 :stand shopkeep-stand :scale-x 1.6 :scale-y 1.6 :talk-color (color 0.2 1.0 0.2 1.0) :talk shopkeep-talk :sigh shopkeep-sigh :anim-merges {shopkeep-sigh {:origin-x 9} :default {:origin-x 9}} :script (actions/get-script entities (do-antique-dialogue entities)) :scripts #(condp = % :teddy (actions/get-script entities (if (get-in @entities [:state :allowed-to-keep-teddy?]) (actions/talk entities :shopkeep "Please give the teddy bear to Herb when you see him.") (actions/talk entities :shopkeep "That belonged to my long lost son."))) :portrait (actions/get-script entities (if (get-in @entities [:state :allowed-to-keep-teddy?]) (actions/talk entities :shopkeep "That's a portrait of my little Herb. " :shopkeep "Please put it back before you leave." ) (actions/talk entities :shopkeep "That's a portrait of my long lost son. " :shopkeep "Please put it back before you leave."))) (actions/get-script entities (actions/talk entities :shopkeep "No thanks, sonny."))) ) :stand) :portrait portrait :beard (assoc (animation->texture screen beard) :anim beard :anim-start 0 :x 70 :y 86 :baseline 120) :smoke-particle (doto (assoc (particle-effect "inside-antique/smoke-particle") :x 162 :y 108 :baseline 240) (particle-effect! :set-position 162 108)) :fire-particle (doto (assoc (particle-effect "inside-antique/fire-particle") :x 162 :y 108 :baseline 240) (particle-effect! :set-position 162 108)) :bowl (assoc (texture "inside-antique/bowl.png") :x 165 :y 110 :baseline 125 :script (actions/get-script entities (if (= 3 (get-in @entities [:state :mints-eaten])) (do (actions/walk-to entities :ego [159 62] :face :right) #_(actions/update-state entities (fn [s] (assoc s :mints-eaten 0))) (actions/do-dialogue entities :ego "She's all out." :shopkeep "That's right I'm all out." :shopkeep "Go tell Gandarf that I need some more brewed up." :shopkeep "Pronto!")) (do (actions/walk-to entities :ego [159 62] :face :right) (actions/talk entities :ego "I'll just try one of these mints.") (actions/play-animation entities :ego :reach) (actions/update-state entities (fn [s] (assoc s :mints-eaten (inc (s :mints-eaten))))) (sound! (sound (str "inside-antique/fire-" (get-in @entities [:state :mints-eaten]) ".ogg")) :play (utils/current-sound-volume)) (cond (= 2 (get-in @entities [:state :mints-eaten])) (do (particle-effect! (get-in @entities [:room :entities :smoke-particle]) :reset) (particle-effect! (get-in @entities [:room :entities :smoke-particle]) :start)) (= 3 (get-in @entities [:state :mints-eaten])) (do (particle-effect! (get-in @entities [:room :entities :fire-particle]) :reset) (particle-effect! (get-in @entities [:room :entities :fire-particle]) :start))) (actions/play-animation entities :ego [:fire (get-in @entities [:state :mints-eaten])]) (actions/talk entities :ego "WOWZA! Those are hot.") (when (= 3 (get-in @entities [:state :mints-eaten])) (actions/do-dialogue entities :shopkeep "Oh drat! You ate the last mint." :shopkeep "It seems like I'm always running out." :shopkeep "Now be a good lad and tell Gandarf that I need some more brewed up." :shopkeep "Pronto!")))))) :teddy teddy} :collision "inside-antique/collision.png" :apply-state (fn [_ entities] (as-> entities entities (if (or (actions/has-item? entities :teddy) (actions/has-obtained? entities :balloon)) (update-in entities [:room :entities] #(dissoc % :teddy)) entities) (if (actions/has-item? entities :portrait ) (update-in entities [:room :entities] #(dissoc % :portrait)) entities))) :scale-fn (utils/scaler-fn-with-baseline 110 0.10 1.75) :start-pos [222 3])))