forked from egametang/ET
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathNumericComponent.cs
More file actions
133 lines (113 loc) · 2.78 KB
/
Copy pathNumericComponent.cs
File metadata and controls
133 lines (113 loc) · 2.78 KB
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
using System.Collections.Generic;
namespace ET
{
namespace EventType
{
public struct NumbericChange
{
public Entity Parent;
public NumericType NumericType;
public long Old;
public long New;
}
}
public class NumericComponentAwakeSystem : AwakeSystem<NumericComponent>
{
public override void Awake(NumericComponent self)
{
self.Awake();
}
}
public class NumericComponent: Entity
{
public Dictionary<int, long> NumericDic = new Dictionary<int, long>();
public void Awake()
{
// 这里初始化base值
}
public float GetAsFloat(NumericType numericType)
{
return (float)GetByKey((int)numericType) / 10000;
}
public float GetAsFloat(int numericType)
{
return (float)GetByKey(numericType) / 10000;
}
public int GetAsInt(NumericType numericType)
{
return (int)GetByKey((int)numericType);
}
public long GetAsLong(NumericType numericType)
{
return GetByKey((int)numericType);
}
public int GetAsInt(int numericType)
{
return (int)GetByKey(numericType);
}
public long GetAsLong(int numericType)
{
return GetByKey(numericType);
}
public void Set(NumericType nt, float value)
{
this[nt] = (int) (value * 10000);
}
public void Set(NumericType nt, int value)
{
this[nt] = value;
}
public void Set(NumericType nt, long value)
{
this[nt] = value;
}
public long this[NumericType numericType]
{
get
{
return this.GetByKey((int) numericType);
}
set
{
long v = this.GetByKey((int) numericType);
if (v == value)
{
return;
}
NumericDic[(int)numericType] = value;
Update(numericType);
}
}
private long GetByKey(int key)
{
long value = 0;
this.NumericDic.TryGetValue(key, out value);
return value;
}
public void Update(NumericType numericType)
{
if (numericType < NumericType.Max)
{
return;
}
int final = (int) numericType / 10;
int bas = final * 10 + 1;
int add = final * 10 + 2;
int pct = final * 10 + 3;
int finalAdd = final * 10 + 4;
int finalPct = final * 10 + 5;
// 一个数值可能会多种情况影响,比如速度,加个buff可能增加速度绝对值100,也有些buff增加10%速度,所以一个值可以由5个值进行控制其最终结果
// final = (((base + add) * (100 + pct) / 100) + finalAdd) * (100 + finalPct) / 100;
long old = this.NumericDic[final];
long result = (long)(((this.GetByKey(bas) + this.GetByKey(add)) * (100 + this.GetAsFloat(pct)) / 100f + this.GetByKey(finalAdd)) * (100 + this.GetAsFloat(finalPct)) / 100f * 10000);
this.NumericDic[final] = result;
Game.EventSystem.Publish(new EventType.NumbericChange()
{
Parent = this.Parent,
NumericType = (NumericType) final,
Old = old,
New = result
}).Coroutine();
}
}
}