mirror of
https://github.com/codeninjasllc/codecombat.git
synced 2025-04-29 23:43:51 -04: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'
|
CocoClass = require 'lib/CocoClass'
|
||||||
utils = require 'lib/utils'
|
utils = require 'lib/utils'
|
||||||
#test
|
|
||||||
module.exports = class GoalManager extends CocoClass
|
module.exports = class GoalManager extends CocoClass
|
||||||
# The Goal Manager is created both on the main thread and
|
# The Goal Manager is created both on the main thread and
|
||||||
# each time the world is generated. The one in world generation
|
# each time the world is generated. The one in world generation
|
||||||
|
@ -105,7 +105,6 @@ module.exports = class GoalManager extends CocoClass
|
||||||
notifyGoalChanges: ->
|
notifyGoalChanges: ->
|
||||||
overallStatus = @checkOverallStatus()
|
overallStatus = @checkOverallStatus()
|
||||||
event = {goalStates: @goalStates, goals: @goals, overallStatus: overallStatus}
|
event = {goalStates: @goalStates, goals: @goals, overallStatus: overallStatus}
|
||||||
#console.log JSON.stringify(event), "new goal states"
|
|
||||||
Backbone.Mediator.publish('goal-manager:new-goal-states', event)
|
Backbone.Mediator.publish('goal-manager:new-goal-states', event)
|
||||||
|
|
||||||
checkOverallStatus: (ignoreIncomplete=false) ->
|
checkOverallStatus: (ignoreIncomplete=false) ->
|
||||||
|
@ -126,6 +125,10 @@ module.exports = class GoalManager extends CocoClass
|
||||||
keyFrame: 0 # when it became a 'success' or 'failure'
|
keyFrame: 0 # when it became a 'success' or 'failure'
|
||||||
}
|
}
|
||||||
@initGoalState(state, [goal.killThangs, goal.saveThangs], 'killed')
|
@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.getToLocations?.who, goal.keepFromLocations?.who], 'arrived')
|
||||||
@initGoalState(state, [goal.leaveOffSides?.who, goal.keepFromLeavingOffSides?.who], 'left')
|
@initGoalState(state, [goal.leaveOffSides?.who, goal.keepFromLeavingOffSides?.who], 'left')
|
||||||
@initGoalState(state, [goal.collectThangs?.who, goal.keepFromCollectingThangs?.who], 'collected')
|
@initGoalState(state, [goal.collectThangs?.who, goal.keepFromCollectingThangs?.who], 'collected')
|
||||||
|
@ -143,7 +146,13 @@ module.exports = class GoalManager extends CocoClass
|
||||||
onThangTouchedGoal: (e, frameNumber) ->
|
onThangTouchedGoal: (e, frameNumber) ->
|
||||||
for goal in @goals ? []
|
for goal in @goals ? []
|
||||||
@checkArrived(goal.id, goal.getToLocations.who, goal.getToLocations.targets, e.actor, e.touched.id, frameNumber) if goal.getToLocations?
|
@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?
|
@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) ->
|
checkArrived: (goalID, who, targets, thang, touchedID, frameNumber) ->
|
||||||
return unless touchedID in targets
|
return unless touchedID in targets
|
||||||
|
@ -191,6 +200,7 @@ module.exports = class GoalManager extends CocoClass
|
||||||
initGoalState: (state, whos, progressObjectName) ->
|
initGoalState: (state, whos, progressObjectName) ->
|
||||||
# 'whos' is an array of goal 'who' values.
|
# 'whos' is an array of goal 'who' values.
|
||||||
# This inits the progress object for the goal tracking.
|
# This inits the progress object for the goal tracking.
|
||||||
|
|
||||||
arrays = (prop for prop in whos when prop?.length)
|
arrays = (prop for prop in whos when prop?.length)
|
||||||
return unless arrays.length
|
return unless arrays.length
|
||||||
state[progressObjectName] = {}
|
state[progressObjectName] = {}
|
||||||
|
@ -240,7 +250,9 @@ module.exports = class GoalManager extends CocoClass
|
||||||
killThangs: 1
|
killThangs: 1
|
||||||
saveThangs: 0
|
saveThangs: 0
|
||||||
getToLocations: 1
|
getToLocations: 1
|
||||||
|
getAllToLocations: 1
|
||||||
keepFromLocations: 0
|
keepFromLocations: 0
|
||||||
|
keepAllFromLocations: 0
|
||||||
leaveOffSides: 1
|
leaveOffSides: 1
|
||||||
keepFromLeavingOffSides: 0
|
keepFromLeavingOffSides: 0
|
||||||
collectThangs: 1
|
collectThangs: 1
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue