From 18852ba2837da829fcd9f6edfe058c91ac3e50ed Mon Sep 17 00:00:00 2001 From: Bryce Covert Date: Sat, 27 Dec 2014 15:26:22 -0800 Subject: [PATCH] can't open chest twice. --- desktop/src-common/advent/actions.clj | 1 + .../advent/screens/rooms/inside_jail.clj | 59 +++++++++++-------- .../src-common/advent/screens/rooms/space.clj | 4 +- 3 files changed, 38 insertions(+), 26 deletions(-) diff --git a/desktop/src-common/advent/actions.clj b/desktop/src-common/advent/actions.clj index 4b5dc291..35d0ea61 100644 --- a/desktop/src-common/advent/actions.clj +++ b/desktop/src-common/advent/actions.clj @@ -563,3 +563,4 @@ (defn respond [entities line & more] (apply do-dialogue entities :ego line more)) + diff --git a/desktop/src-common/advent/screens/rooms/inside_jail.clj b/desktop/src-common/advent/screens/rooms/inside_jail.clj index 79e81b82..9b35c81c 100644 --- a/desktop/src-common/advent/screens/rooms/inside_jail.clj +++ b/desktop/src-common/advent/screens/rooms/inside_jail.clj @@ -1,6 +1,7 @@ (ns advent.screens.rooms.inside-jail (:require [clojure.core.async :refer [chan]] [advent.screens.rooms :as rooms] + [advent.screens.rooms.common :as common] [advent.actions :as actions] [advent.screens.items :as items] [advent.utils :as utils] @@ -24,25 +25,35 @@ (actions/update-entities entities #(remove-lock %)) (actions/update-state entities #(assoc % :opened-bars? true))) -(defn touch-chest [entities] - (if (get-in @entities [:state :opened-bars?]) - (do (actions/walk-to entities :ego [192 66] :face :right) - (actions/play-animation entities :ego :reach) - (actions/do-dialogue entities - :ego "Hey!" - :ego "All my possessions are in here!") - (actions/update-state entities #(-> % - (assoc :inventory (concat (:inventory %) (:chest-contents %))) - (assoc :chest-contents []))) - (when (not (actions/has-obtained? entities :rope)) - (actions/do-dialogue entities :ego "Looks like there's some rope in here too."))) +(defn chest-full? [entities] + (seq (get-in @entities [:state :chest-contents]))) - (do (actions/walk-to entities :ego [179 81] :face :right) - (actions/play-animation entities :ego :reach) - (actions/do-dialogue entities :ego "I can't reach it!") - (when (not (get-in @entities [:state :warden-sleeping?])) - (actions/do-dialogue entities :warden "Quit yer yappin'!" - :warden "You're not escaping while I'm on watch, so just give it up."))))) +(defn touch-chest [entities] + (cond + (not (chest-full? entities)) + (do (actions/walk-to entities :ego [192 66] :face :right) + (actions/play-animation entities :ego :reach) + (actions/do-dialogue entities :ego "It's empty now.")) + + (get-in @entities [:state :opened-bars?]) + (do (actions/walk-to entities :ego [192 66] :face :right) + (actions/play-animation entities :ego :reach) + (actions/do-dialogue entities + :ego "Hey!" + :ego "All my possessions are in here!") + (actions/update-state entities #(-> % + (assoc :inventory (concat (:inventory %) (:chest-contents %))) + (assoc :chest-contents []))) + (when (not (actions/has-obtained? entities :rope)) + (actions/do-dialogue entities :ego "Looks like there's some rope in here too."))) + + :else + (do (actions/walk-to entities :ego [179 81] :face :right) + (actions/play-animation entities :ego :reach) + (actions/do-dialogue entities :ego "I can't reach it!") + (when (not (get-in @entities [:state :warden-sleeping?])) + (actions/do-dialogue entities :warden "Quit yer yappin'!" + :warden "You're not escaping while I'm on watch, so just give it up."))))) (defn do-warden-dialogue [entities] @@ -125,11 +136,7 @@ :ego "Maybe you should give it a rest."))) (actions/update-state entities #(assoc % :hay-searches (inc hay-searches))))) -(defn go-to-jail [entities] - (actions/update-state entities #(assoc % :chest-contents (remove #{:key} (:inventory %)))) - (actions/update-state entities #(assoc % :inventory [])) - (actions/update-state entities #(assoc % :opened-bars? false)) - (actions/transition-background entities :inside-jail [130 85])) + (defn make [screen] @@ -168,7 +175,9 @@ (if (get-in @entities [:state :opened-bars?]) (do (actions/walk-to entities :ego [279 57]) - (actions/transition-background entities :outside-jail [50 46] )) + (if (chest-full? entities) + (actions/talk entities :ego "I probably shouldn't leave without my belongings.") + (actions/transition-background entities :outside-jail [50 46] ))) (actions/talk entities :ego "Do you really think I can walk down those steps while I'm locked up?")))}} :layers [(assoc (texture "inside-jail/background.png") :x 0 :y 0 :baseline 0) (assoc (texture "inside-jail/bars.png") :x 0 :y 0 :baseline 165) @@ -189,7 +198,7 @@ :ego "Oops!" :warden "Hey! What are you doing?" :warden "Get back in jail.") - (go-to-jail entities) + (common/go-to-jail entities) (actions/do-dialogue entities :warden "Now don't let me catch you trying to escape again.") (actions/play-animation entities :warden :fall-asleep :stop? false) (actions/begin-animation entities :warden :sleep)) entities) diff --git a/desktop/src-common/advent/screens/rooms/space.clj b/desktop/src-common/advent/screens/rooms/space.clj index f52300c7..e22fc198 100644 --- a/desktop/src-common/advent/screens/rooms/space.clj +++ b/desktop/src-common/advent/screens/rooms/space.clj @@ -1,5 +1,6 @@ (ns advent.screens.rooms.space (:require [advent.screens.rooms :as rooms] + [advent.screens.rooms.common :as common] [advent.actions :as actions] [advent.screens.items :as items] [advent.utils :as utils] @@ -53,7 +54,8 @@ (actions/walk-straight-to entities :ego [100 45] :anim :squat :override-dir :right :speed 3.0) (actions/do-dialogue entities :ego "Ouch!" :blergh "My turn.") - (actions/transition-background entities :inside-jail [130 85]) + + (common/go-to-jail entities) (actions/do-dialogue entities :ego "Hey!" :ego "What's going on? I was just about to teach Blergh a lesson!"))})) :entities {}