mirror of
https://github.com/codeninjasllc/codecombat.git
synced 2024-11-30 19:06:59 -05:00
commit
e08265a725
3 changed files with 16 additions and 0 deletions
|
@ -212,6 +212,16 @@ module.exports = class GoalManager extends CocoClass
|
||||||
else
|
else
|
||||||
state[progressObjectName][thang] = false
|
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) ->
|
updateGoalState: (goalID, thangID, progressObjectName, frameNumber) ->
|
||||||
# A thang has done something related to the goal!
|
# A thang has done something related to the goal!
|
||||||
# Mark it down and update the goal state.
|
# Mark it down and update the goal state.
|
||||||
|
|
|
@ -39,6 +39,9 @@ module.exports = class Thang
|
||||||
event.thang = @
|
event.thang = @
|
||||||
@world.publishNote channel, event
|
@world.publishNote channel, event
|
||||||
|
|
||||||
|
setGoalState: (goalID, status) ->
|
||||||
|
@world.setGoalState goalID, status
|
||||||
|
|
||||||
addComponents: (components...) ->
|
addComponents: (components...) ->
|
||||||
# We don't need to keep the components around after attaching them, but we will keep their initial config for recreating Thangs
|
# We don't need to keep the components around after attaching them, but we will keep their initial config for recreating Thangs
|
||||||
@components ?= []
|
@components ?= []
|
||||||
|
|
|
@ -222,6 +222,9 @@ module.exports = class World
|
||||||
return unless @goalManager
|
return unless @goalManager
|
||||||
@goalManager.submitWorldGenerationEvent(channel, event, @frames.length)
|
@goalManager.submitWorldGenerationEvent(channel, event, @frames.length)
|
||||||
|
|
||||||
|
setGoalState: (goalID, status) ->
|
||||||
|
@goalManager.setGoalState(goalID, status)
|
||||||
|
|
||||||
endWorld: (victory=false, delay=3, tentative=false) ->
|
endWorld: (victory=false, delay=3, tentative=false) ->
|
||||||
@totalFrames = Math.min(@totalFrames, @frames.length + Math.floor(delay / @dt)) - 1 # end a few seconds later
|
@totalFrames = Math.min(@totalFrames, @frames.length + Math.floor(delay / @dt)) - 1 # end a few seconds later
|
||||||
@victory = victory # TODO: should just make this signify the winning superteam
|
@victory = victory # TODO: should just make this signify the winning superteam
|
||||||
|
|
Loading…
Reference in a new issue