(ns advent.screens.rooms.inside-cafeteria (:require [advent.saves :as saves] [advent.screens.rooms :as rooms] [advent.screens.items :as items] [advent.actions :as actions] [advent.steam :as steam] [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 make-fight-entity [global-atlas] (assoc (utils/atlas->texture global-atlas "black.png") :x 0 :y 0 :scale-x 21 :scale-y 21 :baseline 1000)) (defn play-battle [entities anim] (actions/transition-music entities :fight) (actions/pause-camera entities) (actions/add-entity entities :fight (get-in @entities [:room :fight])) (actions/add-entity entities :hands-fight (get-in @entities [:room :hands-fight])) (actions/play-animation entities :hands-fight anim) (actions/transition-music entities nil) (actions/remove-entity entities :hands-fight) (actions/remove-entity entities :fight) (actions/resume-camera entities)) (defn do-warrior-dialogue [entities] (actions/walk-to entities :ego [150 45] :face :left) (actions/talk entities :ego "Hey, guys!") (actions/talk entities :warriors "Hark! Good day, young esquire.") (actions/present-choices entities {:choices ["Can I have some of your food?" {:run #(actions/respond entities % :warriors "Verily I say unto you: no." :warriors "We art filled with hunger." :warriors "And we musteth replenish our strength." :warriors "Get ye your own food!") :choices actions/previous-choices} "Shouldn't you be guarding something?" {:run #(actions/respond entities % :warriors "Even the mightiest of knights musteth replenish their strength." :warriors "And geteth some R and R.") :choices actions/previous-choices} "Why dost thou speaketh in this manner?" {:run #(actions/respond entities % :warriors "`Tis a tradition!" :warriors "All knights speaketh in such a manner." :warriors "As my father instructedeth unto me as a mere lad: " :warriors "\"Son, thou must speaketh in this manner.\"" :warriors "And I asketh unto him:" :warriors "\"But, Father, why musteth I speaketh in this manner?\"" :warriors "\"Yea, my son, for thou art a knight. And thou musteth speaketh in this manner.\"" :warriors "And I toldeth unto him:" :warriors "\"Thou art my father, and I am thy son. Therefore I will speaketh in this manner.\"" :ego "... I think I've got the idea.") :choices actions/previous-choices} (when (not (actions/has-obtained? entities :medal)) "Can I be a knight like you guys?") {:run #(actions/respond entities % :warriors "We thinketh not, young esquire." :warriors "Thou lacketh the strength and vigor required for such a task." :warriors "To becometh a knight, thou wouldst have to best Captain McHulk in battle." :warriors "And no one durst challenge him!") :choices ["But I'm on a quest to become a knight!" {:run #(actions/respond entities % :warriors "Young esquire, thou art valiant in heart. " :warriors "Departeth henceforth and go hitherto, unto the gym.")} "I challenge Captain McHulk to an arm wrestling match to prove my strength." {:run (fn [msg] (actions/respond entities msg :warriors "Prepare thyself, thy task is not for the faint of heart.") (if (actions/has-item? @entities :flask-1-strength) (do (actions/do-dialogue entities :ego "One sec.") (actions/play-animation entities :ego :grow :stop? false) (play-battle entities :win) (actions/do-dialogue entities :warriors "Congratulations, young master. Thou art worthy in might." :warriors "Take thy servant's medal of strength.") (actions/give entities :medal) (actions/glad entities) (steam/set-achievement "PRO_WRESTLER")) (do (play-battle entities :lose) (actions/do-dialogue entities :warriors "You lost, young master. Go hitherto, unto thy gym.") (actions/walk-to entities :ego [160 45]) (actions/do-dialogue entities :ego "Dang! If I only I had some kind of potion to make me strong..."))))} "Something else." {:choices actions/something-else}] } "Goodbye." {:run #(actions/respond entities % :warriors "Fare thee well, and godspeed.")}]})) (defn do-ladder-guard-dialogue [entities] (actions/walk-to entities :ego [170 45] :face :right) (actions/do-dialogue entities :ego "Hello." :ladder-guard "'Ello, young sire.") (actions/present-choices entities {:choices [(when (not (actions/has-obtained? entities :ladder)) "Nice ladder.") {:run #(actions/respond entities % :ladder-guard "'Tis nice, indeed!" :ladder-guard "Belongeth to the Duke of Remington, it doth.") :choices ["Can I have it?" {:run #(actions/respond entities % :ladder-guard "No.") :choices ["Please?" {:run #(actions/respond entities % :ladder-guard "No.") :choices ["Pretty please?" {:run #(actions/respond entities % :ladder-guard "No.") :choices ["Pretty pretty please?" {:run #(actions/respond entities % :ladder-guard "No.") :choices ["Pretty pretty pretty please?" {:run #(do (actions/respond entities % :ladder-guard "Well, okay." :ladder-guard "Do not durst telleth a soul, or thou wilst bring my family dishonor!" :ladder-guard "I will shame the name of my father, Luke, and his father, Puke." :ladder-guard "Not to mention, the duke will have my head!") (actions/walk-to entities :ego [211 63] :face :right) (actions/play-animation entities :ego :reach) (actions/remove-entity entities :ladder) (actions/give entities :ladder))} "Nevermind." {:run #(actions/respond entities %)}]} "Nevermind." {:run #(actions/respond entities %)}]} "Nevermind." {:run #(actions/respond entities %)}]} "Nevermind." {:run #(actions/respond entities %)}]} "Something else." {:choices actions/something-else}]} (when (and (actions/has-obtained? entities :ladder)) "About that ladder...") {:run #(if (actions/has-item? entities :ladder?) (actions/respond entities % :ladder-guard "I trusteth it is safe in thy possession?" :ego "Yes, it sure is!" :ego "Can I borrow it a while longer?" :ladder-guard "Yes, but do not durst telleth a soul!") (actions/respond entities % :ladder-guard "I trusteth it is safe in thy possession?" :ego "Ahem..." :ego "... Yes, it sure is!" :ladder-guard "I senseth some uncertainty in thine voice." :ego "No uncertainty here!")) :choices actions/previous-choices} "Why aren't you sitting and eating?" {:run #(do (actions/respond entities % :ladder-guard "I'm on duty, young sire.") (when (not (actions/has-obtained? entities :ladder)) (actions/do-dialogue entities :ladder-guard "Dost thou seeth this ladder?" :ladder-guard "'Tis my duty to guardeth it." :ladder-guard "Why, if I didst sit and dineth with my friends, a hoodlum wouldst steal it."))) :choices actions/previous-choices} "What's your name?" {:run #(actions/respond entities % :ladder-guard "I am Took, son of Luke, son of Puke.") :choices actions/previous-choices} "Goodbye." {:run #(actions/respond entities % :ladder-guard "Goodbye.")}]})) (defn pace [xs speed] (mapcat #(repeat (- 4 speed) %) xs)) (defn make [screen atlas global-atlas] (let [ladder-guard-stand (animation 0.1 [(utils/atlas->texture atlas "ladder-guard-2")]) ladder-guard-talk (animation 0.1 [ (utils/atlas->texture atlas "ladder-guard-2")]) warriors-stand (utils/make-anim atlas "knights-stand" [49 80] 0.6 (take 100 (repeatedly #(rand-int 10)))) knight-a-stand (utils/make-anim atlas "knight-a" [70 85] 0.2 (flatten [(repeat 3 [(repeat 7 0) (repeat 7 1) (repeat 7 0) (repeat 7 2)]) [3 4 5 6 7 8 9]])) hands-fight-win (utils/make-anim-seq atlas "fight-new-assets/fight" [256 192] 0.025 (flatten [(pace [0 1 0 4 0 1 0 4 0 1 0 4 0 1 0 4 0 1 0 4 0 0 1 1 1 1 0 0 0 4 0 1 1 1 1 1 1 1 1 4 0 4 0 4 0 4 5 5 5 5 5 4 4 4] 0) (pace (flatten (repeat 6 [12 13])) 0) (pace (flatten (repeat 15 [7 8])) 0) (pace (flatten (repeat 15 [9])) 0) (pace (flatten (repeat 6 [12 13])) 0) (pace (flatten (repeat 15 [7 8])) 1) (pace (flatten (repeat 15 [9])) 0) (pace (flatten (repeat 6 [12 13])) 0) (pace (flatten (repeat 15 [7 8])) 2) (pace (flatten (repeat 15 [9])) 0) (pace (flatten (repeat 6 [12 13])) 0) (pace (flatten (repeat 15 [10 11])) 2) (pace (flatten (repeat 15 [9])) 0) (pace (flatten (repeat 6 [12 13])) 0) (pace [0 0 0 0 2 1 1 2 2 1 1 2 2 2 1 1 2 2 2 2 2 2 2 2 2 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3] 0)])) hands-fight-lose (utils/make-anim-seq atlas "fight-new-assets/fight" [256 192] 0.1 (flatten [4 4 4 4 4 4 0 0 0 0 4 4 4 0 0 0 5 5 5 6 6 6 6 6 6]))] (rooms/make :music :town-1 :name "Cafeteria" :interactions {:right-dir {:box [272 45 320 120] :only-script (actions/get-script entities (actions/walk-to entities :ego [319 50] :skip-type :end) (actions/transition-background entities :inside-castle [65 150]) (actions/walk-to entities :ego [126 80] :skip-type :end)) :cursor :right} } :layers [(assoc (utils/atlas->texture atlas "background") :x 0 :y 0 :baseline 0) (assoc (utils/atlas->texture atlas "doorway") :x 306 :y 34 :baseline 202) (assoc (utils/atlas->texture atlas "glow") :y 0 :baseline 240 :additive? true :opacity 0.3) (assoc (utils/atlas->texture atlas "fg") :x 10 :y 0 :scale-x 1.1 :scale-y 1.0 :baseline 320 :parallax 1.5) ] :entities {:warriors (actions/start-animation screen (assoc (animation->texture screen warriors-stand) :x 31 :y 36 :baseline 180 :cursor :talk :label "Knights" :left {:stand (utils/flip warriors-stand) :talk (utils/flip warriors-stand)} :right {:stand warriors-stand :talk warriors-stand} :facing :right :talk-color (color 1.0 0.2 0.3 1.0) :script (actions/get-script entities (do-warrior-dialogue entities)) :scripts (constantly (actions/get-script entities (actions/walk-to entities :ego [150 45] :face :left) (actions/do-dialogue entities :warriors "We are warriors. We coveteth not earthly possessions.")))) :stand) :knight-a (assoc (animation->texture screen knight-a-stand) :x 0 :y 21 :baseline 181 :anim knight-a-stand :anim-start 0 :talk knight-a-stand :stand knight-a-stand :label "Knights" :cursor :talk :talk-color (color 1.0 0.2 0.3 1.0) :script (actions/get-script entities (do-warrior-dialogue entities)) :scripts (constantly (actions/get-script entities (actions/walk-to entities :ego [150 45] :face :left) (actions/do-dialogue entities :warriors "We are warriors. We coveteth not earthly possessions.")))) :ladder-guard (actions/start-animation screen (assoc (animation->texture screen ladder-guard-stand) :x 180 :y 70 :baseline 170 :cursor :talk :label "On-duty knight" :stand ladder-guard-stand :talk ladder-guard-talk :talk-color (color 0.2 0.6 1.0 1.0) :script (actions/get-script entities (do-ladder-guard-dialogue entities)) :scripts #(actions/get-script entities (actions/walk-to entities :ego [170 45] :face :right) (actions/do-dialogue entities :ladder-guard (if (= :ladder %) "Do not durst telleth a soul about that ladder!" "No thank you, young sire.")))) :stand) :ladder (assoc (utils/atlas->texture atlas "ladder") :x 205 :y 70 :baseline 170 :cursor :hand :label "Ladder" :script (actions/get-script entities (actions/talk entities :ladder-guard "Do not toucheth, young sire.")))} :collision "inside-cafeteria/collision.png" :fight (make-fight-entity global-atlas) :hands-fight (assoc (utils/atlas->texture atlas "fight-new-assets/fight" 0) :origin-x 128 :origin-y 96 :x 150 :y 120 :baseline 1001 :win hands-fight-win :lose hands-fight-lose) :scale-fn (utils/scaler-fn-with-baseline 110 0.10 1.3) :apply-state (fn [_ entities] (as-> entities entities (if (actions/has-obtained? entities :ladder) (update-in entities [:room :entities] #(dissoc % :ladder)) entities))) :start-pos [300 55])))