mirror of
https://github.com/codeninjasllc/codecombat.git
synced 2024-11-24 08:08:15 -05:00
commit
e08265a725
3 changed files with 16 additions and 0 deletions
|
@ -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.
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Reference in a new issue