dimanche 28 août 2016

Condition on a function

I'm trying to create a condition on the following function, but can't figure out a way.

"mods" can be from level 1 to 15, and a mod level can be checked with ".level"

I need that if a set of mods(can be 2 or 4 pieces) has a non level 15 mod, then it calls for allsets[2] and if all mods on a set are level 15 then it calls for allsets[3]

var allSets = {
"Health": [2, "HP%", 5, 10], //0
"Offense": [4, "OFF%", 5, 10], //1
"Crit Chance": [2, "CRate", 2.5, 5], //2
"Crit Damage": [4, "CDmg", 15, 30], //3
"Speed": [4, "SPD%", 5, 10], //4
"Potency": [2, "POT", 5, 10], //5
"Defense": [2, "DEF%", 5], //6
"Tenacity": [2, "TEN", 10] }; //7



function determineCompleteSetsAndEffects(character, mods){
var setCounter = {"Health": 0,"Offense":0,"Crit Chance":0,"Crit Damage":0,"Speed":0,"Potency":0,"Defense":0,"Tenacity":0,};
for(i=0; i<mods.length; i++) {
    setCounter[mods[i].set]++;
}
for (var setName in setCounter) {
    while( setCounter[setName] >= allSets[setName][0]) {
        if(character.sets != "")
            character.sets += ",";
        character.sets += setName;
        // insert condition here {
        character = addStat(character, allSets[setName][1], allSets[setName][2], false, null);
        setCounter[setName] -= allSets[setName][0];
        } else {
        character = addStat(character, allSets[setName][1], allSets[setName][3], false, null);
        setCounter[setName] -= allSets[setName][0];
        }
    }
}
return character;

}

Aucun commentaire:

Enregistrer un commentaire