-
Notifications
You must be signed in to change notification settings - Fork 66
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Tombstone implementation #74
Changes from 13 commits
54d1039
e9aaba6
66f1714
ee3e9a2
5e5aea3
89bbcab
b997a3d
b78f101
ef1b319
63673b2
17b65a6
55cce7c
6e552a3
a8a4bc4
dc951b0
55838d0
95194bd
53cd12b
3765726
a1bdabe
63feb7c
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,150 @@ | ||
var utils = require('./../utils'), | ||
rooms = require('./rooms'), | ||
driver = utils.getDriver(), | ||
C = driver.constants, | ||
_ = require('lodash'); | ||
|
||
var runtimeData, intents, register, globals; | ||
|
||
function _storeGetter(o) { | ||
var result = {energy: o.energy}; | ||
|
||
C.RESOURCES_ALL.forEach(resourceType => { | ||
if (o[resourceType]) { | ||
result[resourceType] = o[resourceType]; | ||
} | ||
}); | ||
|
||
return result; | ||
} | ||
|
||
exports.make = function(_runtimeData, _intents, _register, _globals) { | ||
|
||
runtimeData = _runtimeData; | ||
intents = _intents; | ||
register = _register; | ||
globals = _globals; | ||
|
||
if(globals.Tombstone) { | ||
return; | ||
} | ||
|
||
var data = (id) => { | ||
if(!runtimeData.roomObjects[id]) { | ||
throw new Error("Could not find an object with ID "+id); | ||
} | ||
return runtimeData.roomObjects[id]; | ||
}; | ||
|
||
var Tombstone = register.wrapFn(function(id) { | ||
let self = this | ||
var _data = data(id); | ||
globals.RoomObject.call(this, _data.x, _data.y, _data.room); | ||
this.id = id; | ||
}); | ||
|
||
Tombstone.prototype = Object.create(globals.RoomObject.prototype); | ||
Tombstone.prototype.constructor = Tombstone; | ||
utils.defineGameObjectProperties(Tombstone.prototype, data, { | ||
owner: (o) => _.isUndefined(o.user) || o.user === null ? undefined : { | ||
username: runtimeData.users[o.user].username | ||
}, | ||
my: (o) => _.isUndefined(o.user) ? undefined : o.user == runtimeData.user._id, | ||
deathTime: (o) => o.deathTime, | ||
store: _storeGetter, | ||
ticksToDecay: (o) => o.decayTime - runtimeData.time, | ||
creep: (o) => { | ||
let creep = new globals.Creep(); | ||
globals.RoomObject.call(creep, o.x, o.y, o.room); | ||
Object.defineProperties(creep, { | ||
id: { | ||
enumerable: true, | ||
get() { | ||
return o.creepId; | ||
} | ||
}, | ||
name: { | ||
enumerable: true, | ||
get() { | ||
return o.creepName; | ||
} | ||
}, | ||
spawning: { | ||
enumerable: true, | ||
get() { | ||
return false; | ||
} | ||
}, | ||
my: { | ||
enumerable: true, | ||
get() { | ||
return o.user == runtimeData.user._id; | ||
} | ||
}, | ||
body: { | ||
enumerable: true, | ||
get() { | ||
return _.map(o.creepBody, type => ({ type, hits: 0 })) | ||
} | ||
}, | ||
owner: { | ||
enumerable: true, | ||
get() { | ||
return _.isUndefined(o.user) || o.user === null ? undefined : { | ||
username: runtimeData.users[o.user].username | ||
} | ||
} | ||
}, | ||
ticksToLive: { | ||
enumerable: true, | ||
get() { | ||
return o.creepTicksToLive; | ||
} | ||
}, | ||
carryCapacity: { | ||
enumerable: true, | ||
get() { | ||
return _.reduce(o.creepBody, (result, type) => result += type === C.CARRY ? C.CARRY_CAPACITY : 0, 0); | ||
} | ||
}, | ||
carry: { | ||
enumerable: true, | ||
get() { | ||
return { energy: 0 }; | ||
} | ||
}, | ||
fatigue: { | ||
enumerable: true, | ||
get() { | ||
return 0; | ||
} | ||
}, | ||
hits: { | ||
enumerable: true, | ||
get() { | ||
return 0; | ||
} | ||
}, | ||
hitsMax: { | ||
enumerable: true, | ||
get() { | ||
return o.creepBody.length * 100; | ||
} | ||
}, | ||
saying: { | ||
enumerable: true, | ||
get() { | ||
return o.creepSaying; | ||
} | ||
} | ||
}); | ||
return creep; | ||
}, | ||
}); | ||
|
||
Tombstone.prototype.toString = register.wrapFn(function() { | ||
return `[Tombstone #${this.id}]`; | ||
}); | ||
|
||
globals.Tombstone = Tombstone; | ||
}; |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -89,16 +89,7 @@ module.exports = function(object, roomObjects, roomTerrain, bulk, bulkUsers, roo | |
} | ||
|
||
if(gameTime >= object.ageTime-1) { | ||
|
||
C.RESOURCES_ALL.forEach(resourceType => { | ||
var amount = object[resourceType]; | ||
if (amount) { | ||
require('./_create-energy')(object.x, object.y, object.room, amount, roomObjects, bulk, resourceType, object.dropToContainer); | ||
} | ||
}); | ||
|
||
bulk.remove(object._id); | ||
delete roomObjects[object._id]; | ||
require('./_die')(object, roomObjects, bulk, stats, undefined, gameTime); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Right now this will add to the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. hmm, IIRC, somewhere else it also passes undefined as stats, updating now There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. its spawn recycle-creep where it passes undefined |
||
} | ||
} | ||
|
||
|
@@ -121,11 +112,11 @@ module.exports = function(object, roomObjects, roomTerrain, bulk, bulkUsers, roo | |
} | ||
|
||
if(_.isNaN(object.hits) || object.hits <= 0) { | ||
require('./_die')(object, roomObjects, bulk, stats); | ||
require('./_die')(object, roomObjects, bulk, stats, undefined, gameTime); | ||
} | ||
|
||
if(object.userSummoned && _.any(roomObjects, i => i.type == 'creep' && i.user != '2' && i.user != roomController.user)) { | ||
require('./_die')(object, roomObjects, bulk, stats); | ||
require('./_die')(object, roomObjects, bulk, stats, undefined, gameTime); | ||
} | ||
|
||
let oldHits = object.hits; | ||
|
@@ -145,7 +136,7 @@ module.exports = function(object, roomObjects, roomTerrain, bulk, bulkUsers, roo | |
} | ||
|
||
if(object.hits <= 0) { | ||
require('./_die')(object, roomObjects, bulk, stats); | ||
require('./_die')(object, roomObjects, bulk, undefined, undefined, gameTime); | ||
} | ||
else if(object.hits != oldHits) { | ||
|
||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
x
,y
, androom
are the same as in the tombstone, no need to store them.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Those are the tombstone
x
,y
, androom