codecombat/test/app/lib/world/GoalManager.spec.coffee

174 lines
6.8 KiB
CoffeeScript
Raw Normal View History

describe('GoalManager', ->
2014-01-03 13:32:13 -05:00
GoalManager = require 'lib/world/GoalManager'
2014-06-30 22:16:26 -04:00
killGoal = {name: 'Kill Guy', killThangs: ['Guy1', 'Guy2'], id: 'killguy'}
saveGoal = {name: 'Save Guy', saveThangs: ['Guy1', 'Guy2'], id: 'saveguy'}
getToLocGoal = {name: 'Go there', getToLocation: {target: 'Frying Pan', who: 'Potato'}, id: 'id'}
keepFromLocGoal = {name: 'Go there', keepFromLocation: {target: 'Frying Pan', who: 'Potato'}, id: 'id'}
leaveMapGoal = {name: 'Go away', leaveOffSide: {who: 'Yall'}, id: 'id'}
stayMapGoal = {name: 'Stay here', keepFromLeavingOffSide: {who: 'Yall'}, id: 'id'}
getItemGoal = {name: 'Mine', getItem: {who: 'Grabby', itemID: 'Sandwich'}, id: 'id'}
keepItemGoal = {name: 'Not Yours', keepFromGettingItem: {who: 'Grabby', itemID: 'Sandwich'}, id: 'id'}
2014-01-03 13:32:13 -05:00
it('handles kill goal', ->
2014-01-03 13:32:13 -05:00
gm = new GoalManager()
gm.setGoals([killGoal])
gm.worldGenerationWillBegin()
2014-06-30 22:16:26 -04:00
gm.submitWorldGenerationEvent('world:thang-died', {thang: {id: 'Guy1'}}, 10)
2014-01-03 13:32:13 -05:00
gm.worldGenerationEnded()
goalStates = gm.getGoalStates()
expect(goalStates.killguy.status).toBe('incomplete')
expect(goalStates.killguy.killed.Guy1).toBe(true)
expect(goalStates.killguy.killed.Guy2).toBe(false)
expect(goalStates.killguy.keyFrame).toBe(0)
2014-06-30 22:16:26 -04:00
gm.submitWorldGenerationEvent('world:thang-died', {thang: {id: 'Guy2'}}, 20)
2014-01-03 13:32:13 -05:00
goalStates = gm.getGoalStates()
expect(goalStates.killguy.status).toBe('success')
expect(goalStates.killguy.killed.Guy1).toBe(true)
expect(goalStates.killguy.killed.Guy2).toBe(true)
expect(goalStates.killguy.keyFrame).toBe(20)
)
it('handles save goal', ->
2014-01-03 13:32:13 -05:00
gm = new GoalManager()
gm.setGoals([saveGoal])
gm.worldGenerationWillBegin()
2014-06-30 22:16:26 -04:00
gm.submitWorldGenerationEvent('world:thang-died', {thang: {id: 'Guy1'}}, 10)
2014-01-03 13:32:13 -05:00
gm.worldGenerationEnded()
goalStates = gm.getGoalStates()
expect(goalStates.saveguy.status).toBe('failure')
expect(goalStates.saveguy.killed.Guy1).toBe(true)
expect(goalStates.saveguy.killed.Guy2).toBe(false)
expect(goalStates.saveguy.keyFrame).toBe(10)
gm = new GoalManager()
gm.setGoals([saveGoal])
gm.worldGenerationWillBegin()
gm.worldGenerationEnded()
goalStates = gm.getGoalStates()
expect(goalStates.saveguy.status).toBe('success')
expect(goalStates.saveguy.killed.Guy1).toBe(false)
expect(goalStates.saveguy.killed.Guy2).toBe(false)
expect(goalStates.saveguy.keyFrame).toBe('end')
)
2014-01-27 21:11:33 -05:00
xit 'handles getToLocation', ->
2014-01-03 13:32:13 -05:00
gm = new GoalManager()
gm.setGoals([getToLocGoal])
gm.worldGenerationWillBegin()
gm.worldGenerationEnded()
goalStates = gm.getGoalStates()
expect(goalStates.id.status).toBe('incomplete')
expect(goalStates.id.arrived.Potato).toBe(false)
expect(goalStates.id.keyFrame).toBe(0)
gm = new GoalManager()
gm.setGoals([getToLocGoal])
gm.worldGenerationWillBegin()
2014-06-30 22:16:26 -04:00
gm.submitWorldGenerationEvent('world:thang-touched-goal', {actor: {id: 'Potato'}, touched: {id: 'Frying Pan'}}, 10)
2014-01-03 13:32:13 -05:00
gm.worldGenerationEnded()
goalStates = gm.getGoalStates()
expect(goalStates.id.status).toBe('success')
expect(goalStates.id.arrived.Potato).toBe(true)
expect(goalStates.id.keyFrame).toBe(10)
2014-01-27 21:11:33 -05:00
xit 'handles keepFromLocation', ->
2014-01-03 13:32:13 -05:00
gm = new GoalManager()
gm.setGoals([keepFromLocGoal])
gm.worldGenerationWillBegin()
2014-06-30 22:16:26 -04:00
gm.submitWorldGenerationEvent('world:thang-touched-goal', {actor: {id: 'Potato'}, touched: {id: 'Frying Pan'}}, 10)
2014-01-03 13:32:13 -05:00
gm.worldGenerationEnded()
goalStates = gm.getGoalStates()
expect(goalStates.id.status).toBe('failure')
expect(goalStates.id.arrived.Potato).toBe(true)
expect(goalStates.id.keyFrame).toBe(10)
gm = new GoalManager()
gm.setGoals([keepFromLocGoal])
gm.worldGenerationWillBegin()
gm.worldGenerationEnded()
goalStates = gm.getGoalStates()
expect(goalStates.id.status).toBe('success')
expect(goalStates.id.arrived.Potato).toBe(false)
expect(goalStates.id.keyFrame).toBe('end')
2014-01-27 21:11:33 -05:00
xit 'handles leaveOffSide', ->
2014-01-03 13:32:13 -05:00
gm = new GoalManager()
gm.setGoals([leaveMapGoal])
gm.worldGenerationWillBegin()
gm.worldGenerationEnded()
goalStates = gm.getGoalStates()
expect(goalStates.id.status).toBe('incomplete')
expect(goalStates.id.left.Yall).toBe(false)
expect(goalStates.id.keyFrame).toBe(0)
gm = new GoalManager()
gm.setGoals([leaveMapGoal])
gm.worldGenerationWillBegin()
2014-06-30 22:16:26 -04:00
gm.submitWorldGenerationEvent('world:thang-left-map', {thang: {id: 'Yall'}}, 10)
2014-01-03 13:32:13 -05:00
gm.worldGenerationEnded()
goalStates = gm.getGoalStates()
expect(goalStates.id.status).toBe('success')
expect(goalStates.id.left.Yall).toBe(true)
expect(goalStates.id.keyFrame).toBe(10)
2014-01-27 21:11:33 -05:00
xit 'handles keepFromLeavingOffSide', ->
2014-01-03 13:32:13 -05:00
gm = new GoalManager()
gm.setGoals([stayMapGoal])
gm.worldGenerationWillBegin()
2014-06-30 22:16:26 -04:00
gm.submitWorldGenerationEvent('world:thang-left-map', {thang: {id: 'Yall'}}, 10)
2014-01-03 13:32:13 -05:00
gm.worldGenerationEnded()
goalStates = gm.getGoalStates()
expect(goalStates.id.status).toBe('failure')
expect(goalStates.id.left.Yall).toBe(true)
expect(goalStates.id.keyFrame).toBe(10)
gm = new GoalManager()
gm.setGoals([stayMapGoal])
gm.worldGenerationWillBegin()
gm.worldGenerationEnded()
goalStates = gm.getGoalStates()
expect(goalStates.id.status).toBe('success')
expect(goalStates.id.left.Yall).toBe(false)
expect(goalStates.id.keyFrame).toBe('end')
2014-01-27 21:11:33 -05:00
xit 'handles getItem', ->
2014-01-03 13:32:13 -05:00
gm = new GoalManager()
gm.setGoals([getItemGoal])
gm.worldGenerationWillBegin()
gm.worldGenerationEnded()
goalStates = gm.getGoalStates()
expect(goalStates.id.status).toBe('incomplete')
expect(goalStates.id.collected.Grabby).toBe(false)
expect(goalStates.id.keyFrame).toBe(0)
gm = new GoalManager()
gm.setGoals([getItemGoal])
gm.worldGenerationWillBegin()
2014-06-30 22:16:26 -04:00
gm.submitWorldGenerationEvent('world:thang-collected-item', {actor: {id: 'Grabby'}, item: {id: 'Sandwich'}}, 10)
2014-01-03 13:32:13 -05:00
gm.worldGenerationEnded()
goalStates = gm.getGoalStates()
expect(goalStates.id.status).toBe('success')
expect(goalStates.id.collected.Grabby).toBe(true)
expect(goalStates.id.keyFrame).toBe(10)
2014-01-27 21:11:33 -05:00
xit 'handles keepFromGettingItem', ->
2014-01-03 13:32:13 -05:00
gm = new GoalManager()
gm.setGoals([keepItemGoal])
gm.worldGenerationWillBegin()
2014-06-30 22:16:26 -04:00
gm.submitWorldGenerationEvent('world:thang-collected-item', {actor: {id: 'Grabby'}, item: {id: 'Sandwich'}}, 10)
2014-01-03 13:32:13 -05:00
gm.worldGenerationEnded()
goalStates = gm.getGoalStates()
expect(goalStates.id.status).toBe('failure')
expect(goalStates.id.collected.Grabby).toBe(true)
expect(goalStates.id.keyFrame).toBe(10)
gm = new GoalManager()
gm.setGoals([keepItemGoal])
gm.worldGenerationWillBegin()
gm.worldGenerationEnded()
goalStates = gm.getGoalStates()
expect(goalStates.id.status).toBe('success')
expect(goalStates.id.collected.Grabby).toBe(false)
2014-01-27 21:11:33 -05:00
expect(goalStates.id.keyFrame).toBe('end'))