Changed how effects are applied and removed to enable effects expiring after a set duration.
This commit is contained in:
@@ -1,11 +1,42 @@
|
||||
pushBuffs = function(id, buffArray){
|
||||
//give a character a set of buffs that expire after [duration]
|
||||
pushBuffs = function(id, buffArray, duration){
|
||||
_.each(buffArray, function(buff){
|
||||
Characters.update(id, {$push: {"buff.stat": buff.effect}});
|
||||
var pushObject = {};
|
||||
if(duration > 0){
|
||||
//expiry time is now plus duration
|
||||
var expiry = Characters.findOne(id, {fields: {time: 1}}).time + duration;
|
||||
//ensure the effect has an id
|
||||
buff.effect._id = buff.effect._id || Random.id();
|
||||
//build the expiration object
|
||||
var expiration = {
|
||||
stat: buff.stat,
|
||||
effectId: buff.effect._id,
|
||||
expiry: expiry
|
||||
};
|
||||
//push expiration object to character
|
||||
Characters.update(id, {$push: {expirations: expiration } });
|
||||
}
|
||||
//push the effect to the character
|
||||
pushObject[buff.stat] = buff.effect;
|
||||
Characters.update(id, {$push: pushObject});
|
||||
});
|
||||
};
|
||||
|
||||
//pull all the buffs listed in the buffArray
|
||||
pullBuffs = function(id, buffArray){
|
||||
_.each(buffArray, function(buff){
|
||||
Characters.update(id, {$pull: {"buff.stat": {_id: buff.effect._id} } });
|
||||
pullEffect(id, buff.effect._id);
|
||||
});
|
||||
};
|
||||
};
|
||||
|
||||
//pull a single effect by stat and id
|
||||
pullEffect = function(id, stat, effectId){
|
||||
var pullObject = {};
|
||||
pullObject[stat] = {_id: effectId};
|
||||
Characters.update(id, {$pull: pullObject });
|
||||
}
|
||||
|
||||
//pull an expiry by id
|
||||
pullExpiry = function(id, expiryId){
|
||||
Characters.update(id, {$pull: {expirations: {_id: expiryId} } });
|
||||
}
|
||||
7
rpg-docs/lib/functions/characterUtility.js
Normal file
7
rpg-docs/lib/functions/characterUtility.js
Normal file
@@ -0,0 +1,7 @@
|
||||
getMod = function(score){
|
||||
return Math.floor((score-10)/2);
|
||||
}
|
||||
|
||||
signedString = function(number){
|
||||
return number > 0? "+" + number : "" + number;
|
||||
}
|
||||
@@ -1,6 +1,6 @@
|
||||
// turns dot notation strings into keys of root
|
||||
// argument formats:
|
||||
// 157, anything -> 157
|
||||
// 157, object -> 157
|
||||
// "some.number", object -> object.some.number
|
||||
// "some.function", object -> object.some.function()
|
||||
// "some.function arg1 arg2", object -> object.some.function(arg1, arg2)
|
||||
|
||||
Reference in New Issue
Block a user