class GO {
constructor(name){
this.name = name;
}
}
var EffectTypes = { POISON: 0 };
class Effect extends GO {
constructor(name, effectType){
super(name);
this.effectType = effectType;
}
}
class Poison extends Effect {
constructor(strength, maxTick){
super('poison', EffectTypes.POISON);
this.remainingTick = maxTick;
this.defaultStrength = strength;
}
apply(stats){
// poi only effects hp stats
var hp = stats.hp; // grab the hp from stats
if(hp instanceof HP){
var finalPoisonValue = this.defaultStrength;
if(stats.resistance && stats.resistance.poison){
finalPoisonValue -= stats.resistance.poison.value * finalPoisonValue;
finalPoisonValue = finalPoisonValue >= 0 ? finalPoisonValue : 0; // prevent negative value
}
hp.add(finalPoisonValue);
this.remainingTick--;
}
if(this.remainingTick <= 0){
return true; // indicates the the last remaining tick has been used
}
return false;
}
}
class HP extends GO {
constructor(max, name){
super(name + '_hp');
this.max = max;
this.value = this.max;
}
add(value){
this.value += value;
}
}
class Player extends GO {
constructor(name){
super(name + '_player');
this.effects = [];
this.stats = {
hp: new HP(100)
};
}
addEffect(newEffect){
if(this.effects){
this._removeExistingOldEffect(newEffect);
// add the new effect - may need more logic in the future
this.effects.push(newEffect);
} else {
console.error('cannot add, effects is null');
}
}
removeEffect(effect){
var index = this.effects.indexOf(effect);
if(index >= 0){
this.effects.splice(index,1);
}
}
_removeExistingOldEffect(newEffect){
// currently you can only have one type of effect at a time applied
if(this.effects.length){
// remove any old effect of same type
var oldEffect = this.effects.filter((effect) => effect.effectType ===...
Please Whitelist JSFiddle in your content blocker.
Help keep JSFiddle free for always by one of two ways:
Whitelist JSFiddle in your content blocker (two clicks)
Go PRO and get access to additional PRO features →
Join the 4+ million users, and keep the JSFiddle dream alive.
Ad-free
All ads in the editor and listing pages are turned completely off.
Use pre-released features
You get to try and use features (like the Palette Color Generator) months before everyone else.
Fiddle collections
Sort and categorize your Fiddles into multiple collections.
Private collections and fiddles
You can make as many Private Fiddles, and Private Collections as you wish!
Console
Debug your Fiddle with a minimal built-in JavaScript console.