-
Notifications
You must be signed in to change notification settings - Fork 12
/
GameContext.cs
83 lines (68 loc) · 2.29 KB
/
GameContext.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
using System;
namespace RogueEssence.Dungeon
{
public class AbortStatus
{
public bool Cancel;
public AbortStatus() { }
public AbortStatus(bool cancel) { Cancel = cancel; }
public AbortStatus(AbortStatus other) { Cancel = other.Cancel; }
}
public abstract class UserTargetGameContext : GameContext
{
public Character Target { get; set; }
public UserTargetGameContext() : base()
{
}
protected UserTargetGameContext(UserTargetGameContext other) : base(other)
{
Target = other.Target;
}
}
public abstract class GameContext
{
//passes contextual info
public StateCollection<ContextState> ContextStates;
public Character User { get; set; }
public AbortStatus CancelState;
protected GameContext()
{
ContextStates = new StateCollection<ContextState>();
CancelState = new AbortStatus();
}
protected GameContext(GameContext other)
{
ContextStates = other.ContextStates.Clone();
User = other.User;
CancelState = other.CancelState;
}
public int GetContextStateInt<T>(int defaultVal) where T : ContextIntState
{
return GetContextStateInt(typeof(T), defaultVal);
}
public int GetContextStateInt(Type type, int defaultVal)
{
ContextIntState countState = (ContextIntState)ContextStates.GetWithDefault(type);
if (countState == null)
return defaultVal;
else
return countState.Count;
}
public void AddContextStateInt<T>(int addedVal) where T : ContextIntState
{
AddContextStateInt(typeof(T), addedVal);
}
public void AddContextStateInt(Type type, int addedVal)
{
ContextIntState countState = (ContextIntState)ContextStates.GetWithDefault(type);
if (countState == null)
{
ContextIntState newCount = (ContextIntState)Activator.CreateInstance(type);
newCount.Count = addedVal;
ContextStates.Set(newCount);
}
else
countState.Count += addedVal;
}
}
}