#strict 2 global func GetPhysicalFactorStack(object target) { target || FatalError("GetPhysicalFactorStack: no target object given"); return GetEffect("PhysicalFactorStack", target) || AddEffect("PhysicalFactorStack", target, 200); } global func AddPhysicalFactor(string physical, int factor, int precision, object target) { target = target || this || FatalError("AddPhysicalFactor: no target object given"); precision = precision || 100; return EffectCall(target, GetPhysicalFactorStack(target), "AddFactor", physical, factor, precision); } global func RemovePhysicalFactor(int id, object target) { target = target || this || FatalError("AddPhysicalFactor: no target object given"); return EffectCall(target, GetPhysicalFactorStack(target), "RemoveFactor", id); } global func FxPhysicalFactorStackStart(object target, int effectNumber, int temp) { if(!temp) { EffectVar(1, target, effectNumber) = []; } } global func FxPhysicalFactorStackAddFactor(object target, int effectNumber, string physical, int factor, int precision) { EffectVar(1, target, effectNumber)[] = [++EffectVar(0, target, effectNumber), physical, factor, precision]; EffectCall(target, effectNumber, "ApplyPhysical", physical); return EffectVar(0, target, effectNumber); } global func FxPhysicalFactorStackRemoveFactor(object target, int effectNumber, int id) { for(var i = 0; i < GetLength(EffectVar(1, target, effectNumber)); ++i) { if(EffectVar(1, target, effectNumber)[i][0] == id) { var physical = EffectVar(1, target, effectNumber)[i][1]; ArrayErase(EffectVar(1, target, effectNumber), i); EffectCall(target, effectNumber, "ApplyPhysical", physical); return true; } } return 0; } global func FxPhysicalFactorStackApplyPhysical(object target, int effectNumber, string physical) { var phys = GetPhysical(physical, PHYS_Temporary, target); if(phys) { ResetPhysical(target, physical); } phys = GetPhysical(physical, PHYS_Current, target); for(var factor in EffectVar(1, target, effectNumber)) { if(factor[1] == physical) { phys *= factor[2]; phys /= factor[3]; } } SetPhysical(physical, phys, PHYS_StackTemporary, target); return phys; }