summaryrefslogtreecommitdiffstats
path: root/DTPhysicalStack.c
blob: c0aa7ad13fa7bd869eca7fc5941583d2431ecf81 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
#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)
{
	ArrayAppend(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;
}