Began implementing features that change stats
This commit is contained in:
@@ -2,46 +2,4 @@ Effect = function(stat, value){
|
||||
this.stat = stat;
|
||||
this.value = value;
|
||||
this._id = new Mongo.ObjectID()._str;
|
||||
}
|
||||
|
||||
|
||||
pushEffects = function(characterId, effectName, effectsArray){
|
||||
//check that the arguments are of the right form
|
||||
check(characterId, String);
|
||||
check(effectName, String);
|
||||
check(effectsArray, [{ _id: String, stat: String, value: Number}]);
|
||||
|
||||
for(var i = 0; i < effectsArray.length; i++){
|
||||
var effect = effectsArray[i];
|
||||
|
||||
//check if the character exists with the field we are changing
|
||||
var chk = {_id: characterId}; //right id
|
||||
chk[effect.stat] = {$exists: true}; //has a field for the stat already
|
||||
if(Characters.findOne(chk)){
|
||||
var newEffect = {};
|
||||
newEffect[effect.stat] = {_id: effect.id, name: effectName, value: effect.value};
|
||||
//update the field
|
||||
Characters.update(characterId, {$push: newEffect});
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
pullEffects = function(characterId, effectsArray){
|
||||
//check that the arguments are of the right form
|
||||
check(characterId, String);
|
||||
check(effectsArray, [{ _id: String, stat: String, value: Number}]);
|
||||
|
||||
for(var i = 0; i < effectsArray.length; i++){
|
||||
var effect = effectsArray[i];
|
||||
|
||||
//check if the character exists with the field we are changing
|
||||
var chk = {_id: characterId}; //right id
|
||||
chk[effect.stat] = {$exists: true}; //has a field for the stat already
|
||||
if(Characters.findOne(chk)){
|
||||
var effectToPull = {};
|
||||
effectToPull[effect.stat] = {_id: effect.id};
|
||||
//update the field
|
||||
Characters.update(characterId, {$pull: effectToPull});
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,4 +0,0 @@
|
||||
Feature = function(name){
|
||||
this.name = name;
|
||||
this.description = description;
|
||||
}
|
||||
Reference in New Issue
Block a user