From e060d4b73de2b3814be11de0553bcb9884dfaf9d Mon Sep 17 00:00:00 2001 From: Darredevil Date: Sat, 29 Mar 2014 03:52:02 +0200 Subject: [PATCH 1/3] Added setGoalState --- app/lib/world/GoalManager.coffee | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/app/lib/world/GoalManager.coffee b/app/lib/world/GoalManager.coffee index b017482b8..24fd443ec 100644 --- a/app/lib/world/GoalManager.coffee +++ b/app/lib/world/GoalManager.coffee @@ -212,6 +212,16 @@ module.exports = class GoalManager extends CocoClass else state[progressObjectName][thang] = false + setGoalState: (goalID, status) -> + state = @goalStates[goalID] + state.status = status + if overallStatus = @checkOverallStatus true + matchedGoals = (_.find(@goals, {id: goalID}) for goalID, goalState of @goalStates when goalState.status is overallStatus) + mostEagerGoal = _.min matchedGoals, 'worldEndsAfter' + victory = overallStatus is "success" + tentative = overallStatus is "success" + @world.endWorld victory, mostEagerGoal.worldEndsAfter, tentative if mostEagerGoal isnt Infinity + updateGoalState: (goalID, thangID, progressObjectName, frameNumber) -> # A thang has done something related to the goal! # Mark it down and update the goal state. From 0a969bb103382bcd3194f55e8a6a6850d8f96e53 Mon Sep 17 00:00:00 2001 From: Darredevil Date: Sat, 29 Mar 2014 03:53:19 +0200 Subject: [PATCH 2/3] Added setGoalState --- app/lib/world/thang.coffee | 3 +++ 1 file changed, 3 insertions(+) diff --git a/app/lib/world/thang.coffee b/app/lib/world/thang.coffee index 6e909cb2f..4dc08269b 100644 --- a/app/lib/world/thang.coffee +++ b/app/lib/world/thang.coffee @@ -38,6 +38,9 @@ module.exports = class Thang publishNote: (channel, event) -> event.thang = @ @world.publishNote channel, event + + setGoalState: (goalID, status) -> + @world.setGoalState goalID, status addComponents: (components...) -> # We don't need to keep the components around after attaching them, but we will keep their initial config for recreating Thangs From c4de6ef996dae2d6773d56536076a6904c2285ca Mon Sep 17 00:00:00 2001 From: Darredevil Date: Sat, 29 Mar 2014 03:54:16 +0200 Subject: [PATCH 3/3] Added setGoalState --- app/lib/world/world.coffee | 3 +++ 1 file changed, 3 insertions(+) diff --git a/app/lib/world/world.coffee b/app/lib/world/world.coffee index 87d6e3d9a..f209f82d3 100644 --- a/app/lib/world/world.coffee +++ b/app/lib/world/world.coffee @@ -221,6 +221,9 @@ module.exports = class World @scriptNotes.push scriptNote return unless @goalManager @goalManager.submitWorldGenerationEvent(channel, event, @frames.length) + + setGoalState: (goalID, status) -> + @goalManager.setGoalState(goalID, status) endWorld: (victory=false, delay=3, tentative=false) -> @totalFrames = Math.min(@totalFrames, @frames.length + Math.floor(delay / @dt)) - 1 # end a few seconds later