text: Kiwi.Plugins.DamagePipeline={name:"DamagePipeline",version:"1.0.0",minimumKiwiVersion:"1.1.0"},Kiwi.PluginManager.register(Kiwi.Plugins.DamagePipeline),Kiwi.Plugins.DamagePipeline.create=function(){},Kiwi.Plugins.DamagePipeline.Pack=function(a){return this.exhausted=!1,this._value=0,this.subPacks=[],this.parseParams(a),this},Kiwi.Plugins.DamagePipeline.Pack.prototype.ADD=0,Kiwi.Plugins.DamagePipeline.Pack.prototype.SET=1,Kiwi.Plugins.DamagePipeline.Pack.prototype.SUBTRACT=2,Object.defineProperty(Kiwi.Plugins.DamagePipeline.Pack.prototype,"value",{get:function(){return this._value},set:function(a){this._value=a,this.checkExhaustion()}}),Kiwi.Plugins.DamagePipeline.Pack.prototype.checkExhaustion=function(){return this._value<=0&&(this._value=0,this.exhausted=!0),this.discardExhaustedSubPacks(),this.exhausted},Kiwi.Plugins.DamagePipeline.Pack.prototype.clone=function(){var a,b={value:this.value,mode:this.mode,owner:this.owner,subPacks:[],tags:[]};for(a=0;a<this.subPacks.length;a++)b.subPacks.push(this.subPacks[a].clone());for(a=0;a<this.tags.length;a++)b.tags.push(this.tags[a]);return new Kiwi.Plugins.DamagePipeline.Pack(b)},Kiwi.Plugins.DamagePipeline.Pack.prototype.discardExhaustedSubPacks=function(){var a;for(a=this.subPacks.length-1;a>=0;a--)this.subPacks[a].discardExhaustedSubPacks(),this.subPacks[a].exhausted&&this.subPacks.splice(a,1)},Kiwi.Plugins.DamagePipeline.Pack.prototype.extractSubPack=function(a){var b,c=this.subPacks.indexOf(a);if(-1!==c)return this.subPacks.splice(c,1),a;for(b=0;b<this.subPacks.length;b++)if(this.subPacks[b].extractSubPack(a))return a;return null},Kiwi.Plugins.DamagePipeline.Pack.prototype.getAllPacks=function(){var a,b=[];for(a=0;a<this.subPacks.length;a++)b=b.concat(this.subPacks[a].getAllPacks());return b.push(this),b},Kiwi.Plugins.DamagePipeline.Pack.prototype.hasTag=function(a){return-1!==this.tags.indexOf(a)},Kiwi.Plugins.DamagePipeline.Pack.prototype.hasTagInArray=function(a){var b,c;if(Kiwi.Utils.Common.isArray(a)){if(0===a.length)return!0;for(b=0;b<a.length;b++)if(c=a[b],this.hasTag(c))return!0}return!1},Kiwi.Plugins.DamagePipeline.Pack.prototype.objType=function(){return"Pack"},Kiwi.Plugins.DamagePipeline.Pack.prototype.parseParams=function(a){var b,c;if("number"==typeof a&&(a={value:a}),this.value=a.value,this.subPacks=a.subPacks||[],this.mode=a.mode,this.owner=a.owner||null,this.tags=[],isNaN(this.value)&&(this.value=0),0===this.value&&(this.exhausted=!0),"string"==typeof this.mode&&("ADD"===this.mode.toUpperCase()?this.mode=this.ADD:"SET"===this.mode.toUpperCase()?this.mode=this.SET:"SUBTRACT"===this.mode.toUpperCase()&&(this.mode=this.SUBTRACT)),(isNaN(this.mode)||this.mode!==this.ADD&&this.mode!==this.SET&&this.mode!==this.SUBTRACT)&&(this.mode=this.SUBTRACT),Kiwi.Utils.Common.isArray(this.subPacks))for(b=this.subPacks.length-1;b>=0;b--)this.subPacks[b].objType?"Pack"!==this.subPacks[b].objType()&&this.subPacks.splice(b,1):(this.subPacks.splice(b,1),console.error("Invalid component in params.subPacks"));else this.subPacks&&this.subPacks.objType&&"Pack"===this.subPacks.objType()?this.subPacks=[this.subPacks]:(console.error("Invalid component in params.subPacks"),this.subPacks=[]);if(Kiwi.Utils.Common.isArray(a.tags))for(b=0;b<a.tags.length;b++)c=a.tags[b],("number"==typeof c||"string"==typeof c)&&-1===this.tags.indexOf(c)&&this.tags.push(c);else a.tags&&(c=a.tags,("number"==typeof c||"string"==typeof c)&&this.tags.push(c))},Kiwi.Plugins.DamagePipeline.PipelineNode=function(a){this._parseParams(a)},Kiwi.Plugins.DamagePipeline.PipelineNode.prototype.addChild=function(a){a!==this?a.objType&&a.objType()===this.objType()?this.getChildByName(a.name)?console.error("Could not add child: name was already in use"):this._children.push(a):console.error("Could not add child: was not PipelineNode type"):console.error("Could not add child: child cannot be own parent")},Kiwi.Plugins.DamagePipeline.PipelineNode.prototype.addTag=function(a){("number"==typeof a||"string"==typeof a)&&-1===this._tags.indexOf(a)&&this._tags.push(a)},Kiwi.Plugins.DamagePipeline.PipelineNode.prototype.clearChildren=function(){this._children=[]},Kiwi.Plugins.DamagePipeline.PipelineNode.prototype.clearTags=function(){this._tags=[]},Kiwi.Plugins.DamagePipeline.PipelineNode.prototype.dispatch=function(a,b){this.extractPack(a),a.checkExhaustion()||b&&b.objType&&b.objType()===this.objType()&&(this.onDispatch.dispatch(this,a),b.receive(a))},Kiwi.Plugins.DamagePipeline.PipelineNode.prototype.dispatchDefault=function(a){var b=this._children[0];this.dispatch(a,b)},Kiwi.Plugins.DamagePipeline.PipelineNode.prototype.extractPack=function(a){var b,c=this._currentMasterPack.getAllPacks();for(b=0;b<c.length;b++)c[b].extractSubPack(a);return b=this._packs.indexOf(a),-1!==b&&this._packs.splice(b,1),a},Kiwi.Plugins.DamagePipeline.PipelineNode.prototype.getChildByName=function(a){var b,c;for(c=0;c<this._children.length;c++)if(b=this._children[c],b.name===a)return b;return null},Kiwi.Plugins.DamagePipeline.PipelineNode.prototype.hasTag=function(a){var b=this._tags.indexOf(a);return-1===b?!1:!0},Kiwi.Plugins.DamagePipeline.PipelineNode.prototype.objType=function(){return"Pack Pipeline Node"},Kiwi.Plugins.DamagePipeline.PipelineNode.prototype._operate=function(a){return a},Kiwi.Plugins.DamagePipeline.PipelineNode.prototype._parseParams=function(a){var b;if(a=a||{},this._children=[],Kiwi.Utils.Common.isArray(a.children))for(b=0;b<a.children.length;b++)this.addChild(a.children[b]);else a.children&&this.addChild(a.children);if(this._currentMasterPack=null,this.defaultChildIndex=a.defaultChildIndex||0,this.doDefaultDispatch="boolean"==typeof a.doDefaultDispatch?a.doDefaultDispatch:!0,this.name=a.name||"Unnamed Node","function"==typeof a.operation&&(this._operate=a.operation),this.onDispatch=new Kiwi.Signal,this.onExhaust=new Kiwi.Signal,this._packs=[],this.processOnReceive=a.processOnReceive||!0,this.processTopDown=a.processTopDown||!1,this._tags=[],Kiwi.Utils.Common.isArray(a.tags))for(b=0;b<a.tags.length;b++)this.addTag(a.tags[b]);else a.tags&&this.addTag(a.tags)},Kiwi.Plugins.DamagePipeline.PipelineNode.prototype.process=function(){var a,b,c,d,e;for(a=this._packs.length-1;a>=0;a--){if(c=this._packs[a],this._currentMasterPack=c,this.processTopDown)for(d=c.getAllPacks(),d.reverse(),e=d.length,b=0;e>b;)d[b].hasTagInArray(this._tags)&&(this._operate(d[b]),d[b].checkExhaustion()&&this.onExhaust.dispatch(this,d[b])),d=c.getAllPacks(),d.reverse(),e=d.length,b++;else for(d=c.getAllPacks(),b=0;b<d.length;b++)d[b].hasTagInArray(this._tags)&&(this._operate(d[b]),d[b].checkExhaustion()&&this.onExhaust.dispatch(this,d[b]));this.doDefaultDispatch&&-1!==this._packs.indexOf(c)&&this.dispatchDefault(c)}},Kiwi.Plugins.DamagePipeline.PipelineNode.prototype.receive=function(a){"Pack"===a.objType()&&(a.checkExhaustion()||(this._packs.push(a),this.processOnReceive&&this.process()))},Kiwi.Plugins.DamagePipeline.PipelineNode.prototype.removeChild=function(a){var b=this._children.indexOf(a);-1!==b&&this._children.splice(b,1)},Kiwi.Plugins.DamagePipeline.PipelineNode.prototype.removeTag=function(a){var b=this._tags.indexOf(a);-1!==b&&this._tags.splice(b,1)},Kiwi.Plugins.DamagePipeline.MeterNode=function(a){this.onBreak=new Kiwi.Signal,this.onMax=new Kiwi.Signal,this.onOverflow=new Kiwi.Signal,this.onReceive=new Kiwi.Signal,this.onZero=new Kiwi.Signal,Kiwi.Plugins.DamagePipeline.PipelineNode.call(this,a)},Kiwi.extend(Kiwi.Plugins.DamagePipeline.MeterNode,Kiwi.Plugins.DamagePipeline.PipelineNode),Object.defineProperty(Kiwi.Plugins.DamagePipeline.MeterNode.prototype,"valueNormalized",{get:function(){return this.value/this.valueMax},set:function(a){Kiwi.Utils.GameMath.clamp(a,1,0),this.value=a*this.valueMax}}),Kiwi.Plugins.DamagePipeline.MeterNode.prototype._parseParams=function(a){this.valueMax="number"==typeof a.valueMax?a.valueMax:100,this.value="number"==typeof a.value?Math.min(a.value,this.valueMax):this.valueMax,this.valueLast=this.value,a.operation=void 0,"function"==typeof a.doOnBreak&&(this.doOnBreak=a.doOnBreak),"function"==typeof a.doOnMax&&(this.doOnMax=a.doOnMax),"function"==typeof a.doOnOverflow&&(this.doOnOverflow=a.doOnOverflow),"function"==typeof a.doOnReceive&&(this.doOnReceive=a.doOnReceive),"function"==typeof a.doOnZero&&(this.doOnZero=a.doOnZero),Kiwi.Plugins.DamagePipeline.PipelineNode.prototype._parseParams.call(this,a)},Kiwi.Plugins.DamagePipeline.MeterNode.prototype.doOnBreak=function(){},Kiwi.Plugins.DamagePipeline.MeterNode.prototype.doOnMax=function(){},Kiwi.Plugins.DamagePipeline.MeterNode.prototype.doOnOverflow=function(){},Kiwi.Plugins.DamagePipeline.MeterNode.prototype.doOnReceive=function(a){var b;a.mode===a.SUBTRACT?a.value<=this.value?(this.value-=a.value,a.value=0):(a.value-=this.value,this.value=0):a.mode===a.ADD?(b=this.valueMax-this.value,a.value<=b?(this.value+=a.value,a.value=0):(a.value-=b,this.value=this.valueMax)):a.mode===a.SET&&(this.value=a.value,this.value>this.valueMax?(a.value=this.value-this.valueMax,this.value=this.valueMax):a.value=0)},Kiwi.Plugins.DamagePipeline.MeterNode.prototype.doOnZero=function(){},Kiwi.Plugins.DamagePipeline.MeterNode.prototype._operate=function(a){this.valueLast=this.value,this.doOnReceive(a),this.onReceive.dispatch(this),this.value===this.valueMax&&this.valueLast!==this.valueMax&&(this.doOnMax(a),this.onMax.dispatch(this)),this.value===this.valueMax&&a.value>0&&a.mode===a.ADD&&(this.doOnOverflow(a),this.onOverflow.dispatch(this)),0===this.value&&0!==this.valueLast&&(this.doOnZero(a),this.onZero.dispatch(this)),0===this.value&&a.value>0&&a.mode===a.SUBTRACT&&(this.doOnBreak(a),this.onBreak.dispatch(this))};