mirror of
https://github.com/codeninjasllc/codecombat.git
synced 2024-11-30 19:06:59 -05:00
Added GetALLToLocations and KeepALLFromLocations
This commit is contained in:
parent
5f2587da18
commit
012c25a817
1 changed files with 14 additions and 2 deletions
|
@ -1,6 +1,6 @@
|
|||
CocoClass = require 'lib/CocoClass'
|
||||
utils = require 'lib/utils'
|
||||
#test
|
||||
|
||||
module.exports = class GoalManager extends CocoClass
|
||||
# The Goal Manager is created both on the main thread and
|
||||
# each time the world is generated. The one in world generation
|
||||
|
@ -105,7 +105,6 @@ module.exports = class GoalManager extends CocoClass
|
|||
notifyGoalChanges: ->
|
||||
overallStatus = @checkOverallStatus()
|
||||
event = {goalStates: @goalStates, goals: @goals, overallStatus: overallStatus}
|
||||
#console.log JSON.stringify(event), "new goal states"
|
||||
Backbone.Mediator.publish('goal-manager:new-goal-states', event)
|
||||
|
||||
checkOverallStatus: (ignoreIncomplete=false) ->
|
||||
|
@ -126,6 +125,10 @@ module.exports = class GoalManager extends CocoClass
|
|||
keyFrame: 0 # when it became a 'success' or 'failure'
|
||||
}
|
||||
@initGoalState(state, [goal.killThangs, goal.saveThangs], 'killed')
|
||||
for getTo in goal.getAllToLocations ? []
|
||||
@initGoalState(state,[ getTo.getToLocation?.who , [] ], 'arrived')
|
||||
for keepFrom in goal.keepAllFromLocations ? []
|
||||
@initGoalState(state,[ [] , keepFrom.keepFromLocation?.who], 'arrived')
|
||||
@initGoalState(state, [goal.getToLocations?.who, goal.keepFromLocations?.who], 'arrived')
|
||||
@initGoalState(state, [goal.leaveOffSides?.who, goal.keepFromLeavingOffSides?.who], 'left')
|
||||
@initGoalState(state, [goal.collectThangs?.who, goal.keepFromCollectingThangs?.who], 'collected')
|
||||
|
@ -143,7 +146,13 @@ module.exports = class GoalManager extends CocoClass
|
|||
onThangTouchedGoal: (e, frameNumber) ->
|
||||
for goal in @goals ? []
|
||||
@checkArrived(goal.id, goal.getToLocations.who, goal.getToLocations.targets, e.actor, e.touched.id, frameNumber) if goal.getToLocations?
|
||||
if goal.getAllToLocations?
|
||||
for getTo in goal.getAllToLocations
|
||||
@checkArrived(goal.id, getTo.getToLocation.who, getTo.getToLocation.targets, e.actor, e.touched.id, frameNumber)
|
||||
@checkArrived(goal.id, goal.keepFromLocations.who, goal.keepFromLocations.targets, e.actor, e.touched.id, frameNumber) if goal.keepFromLocations?
|
||||
if goal.keepAllFromLocations?
|
||||
for keepFrom in goal.keepAllFromLocations
|
||||
@checkArrived(goal.id, keepFrom.keepFromLocation.who , keepFrom.keepFromLocation.targets, e.actor, e.touched.id, frameNumber )
|
||||
|
||||
checkArrived: (goalID, who, targets, thang, touchedID, frameNumber) ->
|
||||
return unless touchedID in targets
|
||||
|
@ -191,6 +200,7 @@ module.exports = class GoalManager extends CocoClass
|
|||
initGoalState: (state, whos, progressObjectName) ->
|
||||
# 'whos' is an array of goal 'who' values.
|
||||
# This inits the progress object for the goal tracking.
|
||||
|
||||
arrays = (prop for prop in whos when prop?.length)
|
||||
return unless arrays.length
|
||||
state[progressObjectName] = {}
|
||||
|
@ -240,7 +250,9 @@ module.exports = class GoalManager extends CocoClass
|
|||
killThangs: 1
|
||||
saveThangs: 0
|
||||
getToLocations: 1
|
||||
getAllToLocations: 1
|
||||
keepFromLocations: 0
|
||||
keepAllFromLocations: 0
|
||||
leaveOffSides: 1
|
||||
keepFromLeavingOffSides: 0
|
||||
collectThangs: 1
|
||||
|
|
Loading…
Reference in a new issue