-
Notifications
You must be signed in to change notification settings - Fork 0
/
Effect.cs
147 lines (141 loc) · 4.78 KB
/
Effect.cs
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
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
using System;
using System.Linq;
using TFT_Engine.Components;
namespace TFT_Engine
{
public abstract class Effect
{
public int DurationCounter { get; set; }
public double BaseDuration;
public int MaxStack; //MaxStack = 0 <=> infinite stacks
public Board Board;
public Character Effector;
public Character Effected;
public Set EffectorSet;
public bool IsLoop = false;
public Position EffectedPosition;
protected Effect(double duration, Character effector, Character effected, int stack = 0)
{
MaxStack = stack;
BaseDuration = duration;
DurationCounter = (int)(duration * effected.Board.DefaultTicksPerSec);
Effector = effector;
Effected = effected;
effected.Board.AddRoundEvent(new RoundEvent(effected, EventType.Effects)
{
EffectName = GetType().Name,
LinkedCharacters = new() { effector },
EffectValue = true
});
}
protected Effect(double duration, Set effector, Character effected, int stack = 0)
{
MaxStack = stack;
BaseDuration = duration;
DurationCounter = (int)(duration * effected.Board.DefaultTicksPerSec);
EffectorSet = effector;
Effected = effected;
Board.AddRoundEvent(new RoundEvent(effected, EventType.Effects)
{
EffectName = GetType().Name,
LinkedSet = effector,
EffectValue = true
});
}
protected Effect(double duration, Character effected, int stack = 0)
{
MaxStack = stack;
BaseDuration = duration;
DurationCounter = (int)(duration * effected.Board.DefaultTicksPerSec);
Effected = effected;
effected.Board.AddRoundEvent(new RoundEvent(effected, EventType.Effects)
{
EffectName = GetType().Name,
EffectValue = true
});
}
//Board to get default tick
protected Effect(double duration, Character effector, Position pos, Board Board, int stack = 0)
{
MaxStack = stack;
Effector = effector;
BaseDuration = duration;
DurationCounter = (int)(duration * Board.DefaultTicksPerSec);
EffectedPosition = pos;
Board.AddRoundEvent(new RoundEvent(effector, pos)
{
LinkedPositions = pos,
EffectName = GetType().Name,
EffectValue = true
});
}
protected Effect(double duration, Set effector, Position pos, Board Board, int stack = 0)
{
MaxStack = stack;
EffectorSet = effector;
BaseDuration = duration;
DurationCounter = (int)(duration * Board.DefaultTicksPerSec);
EffectedPosition = pos;
Board.AddRoundEvent(new RoundEvent(effector, pos)
{
LinkedPositions = pos,
EffectName = GetType().Name,
EffectValue = true
});
}
public Effect SetLoop(bool loop)
{
IsLoop = loop;
return this;
}
public void OnTick()
{
DurationCounter--;
OverrideOnTick();
if (DurationCounter == 0)
{
OnElapsed();
}
}
public void Abort()
{
DurationCounter = 0;
}
public void Refresh()
{
DurationCounter = (int)(BaseDuration * Board.DefaultTicksPerSec);
}
public virtual void OverrideOnTick() { }
public virtual void OnElapsed()
{
//Loop
if (IsLoop)
{
DurationCounter = (int)(Board.DefaultTicksPerSec * BaseDuration);
return;
}
if (Effected != null)
Board.AddRoundEvent(new RoundEvent(Effected, EventType.Effects)
{
EffectName = GetType().Name,
LinkedCharacters = new() { Effector },
EffectValue = false
});
else if (EffectorSet != null)
Board.AddRoundEvent(new RoundEvent(Effected, EventType.Effects)
{
EffectName = GetType().Name,
LinkedSet = EffectorSet,
EffectValue = false
});
else
{
Board.AddRoundEvent(new RoundEvent(Effector, EffectedPosition)
{
EffectName = GetType().Name,
EffectValue = false
});
}
}
}
}