diff --git a/app/lib/world/GoalManager.coffee b/app/lib/world/GoalManager.coffee index d524a0386..3bebeca92 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. diff --git a/app/lib/world/thang.coffee b/app/lib/world/thang.coffee index 0cd586412..41544cbca 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 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