Survivalcraft API 1.8.2.3 v1.8.2.3
Survivalcraft 2.4
载入中...
搜索中...
未找到
ComponentFactors.cs
浏览该文件的文档.
3using static Game.ComponentLevel;
4
5namespace Game {
7 public Random m_random = new();
8
10
12
14
18 public Dictionary<string, List<Factor>> OtherFactors = new();
19
20 public Dictionary<string, float> OtherFactorsResults = new();
21
25 public List<Factor> m_strengthFactors = [];
26
27 public List<Factor> m_speedFactors = [];
28 public List<Factor> m_hungerFactors = [];
29 public List<Factor> m_resilienceFactors = [];
31
32 public static string fName = "ComponentFactors";
33
34 public virtual float GetOtherFactorResult(string factorName, bool recalculate = false, bool throwIfNotFound = false) {
35 if (!recalculate
36 && OtherFactorsResults.TryGetValue(factorName, out float result)) {
37 return result;
38 }
39 if (!recalculate && throwIfNotFound) {
40 throw new KeyNotFoundException($"Required factor result with name {factorName} is not found.");
41 }
42 bool factorsGotten = OtherFactors.TryGetValue(factorName, out List<Factor> factors);
43 if (!factorsGotten) {
44 if (throwIfNotFound) {
45 throw new KeyNotFoundException($"Required factor key with name {factorName} is not found.");
46 }
47 return 1f;
48 }
49 return CalculateFactorsResult(factors);
50 }
51
52 public float StrengthFactor {
53 get;
54 [Obsolete("模组调整StrengthFactor的具体数值,需要通过m_strengthFactors里面增删改里面的Factor")]
55 set;
56 } = 1f;
57
58 public float ResilienceFactor {
59 get;
60 [Obsolete("模组调整ResilienceFactor的具体数值,需要通过m_resilienceFactors里面增删改里面的Factor")]
61 set;
62 } = 1f;
63
64 public float SpeedFactor {
65 get;
66 [Obsolete("模组调整SpeedFactor的具体数值,需要通过m_speedFactors里面增删改里面的Factor")]
67 set;
68 } = 1f;
69
70 public float HungerFactor {
71 get;
72 [Obsolete("模组调整HungerFactor的具体数值,需要通过m_hungerFactors里面增删改里面的Factor")]
73 set;
74 } = 1f;
75
83 public override void Load(ValuesDictionary valuesDictionary, IdToEntityMap idToEntityMap) {
84 m_subsystemGameInfo = Project.FindSubsystem<SubsystemGameInfo>(true);
85 m_subsystemTime = Project.FindSubsystem<SubsystemTime>(true);
86 m_subsystemAudio = Project.FindSubsystem<SubsystemAudio>(true);
87 OtherFactors["AttackSpeed"] = new List<Factor>();
88 OtherFactors["DigSpeed"] = new List<Factor>();
89 OtherFactors["ChaseRange"] = new List<Factor>();
91 }
92
93 public static float CalculateFactorsResult(ICollection<Factor> factors) {
94 float ans = 1f;
95 foreach (var factor in factors) {
96 if (float.IsNaN(factor.Value) || float.IsInfinity(factor.Value)) {
97 continue;
98 }
99 switch (factor.FactorAdditionType) {
100 case FactorAdditionType.Multiply: {
101 ans *= factor.Value;
102 break;
103 }
104 case FactorAdditionType.Add: {
105 ans += factor.Value;
106 break;
107 }
108 }
109 }
110 if (float.IsNaN(ans) || float.IsInfinity(ans)) {
111 ans = 1f;
112 }
113 return ans;
114 }
115
116 public virtual void CalculateOtherFactorsResult() {
117 foreach ((string key, List<Factor> factors) in OtherFactors) {
119 }
120 }
121
122 public virtual void GenerateStrengthFactors() {
123 m_strengthFactors.Clear();
124 }
125
126 public virtual void GenerateResilienceFactors() {
127 m_resilienceFactors.Clear();
128 }
129
130 public virtual void GenerateSpeedFactors() {
131 m_speedFactors.Clear();
132 }
133
134 public virtual void GenerateHungerFactors() {
135 m_hungerFactors.Clear();
136 }
137
138 public virtual void GenerateOtherFactors() {
139 foreach (string key in OtherFactors.Keys) {
140 OtherFactors[key].Clear();
141 }
142 }
143
144 #region Obsolete CalculateFactor
145
146 [Obsolete("Get m_strengthFactors and StrengthFactor instead.")]
147 public virtual float CalculateStrengthFactor(ICollection<Factor> factors) {
148 if (factors is List<Factor> factorsList) {
149 factorsList.AddRange(m_strengthFactors);
150 }
152 }
153
154 [Obsolete("Get m_resilienceFactors and ResilienceFactor instead.")]
155 public virtual float CalculateResilienceFactor(ICollection<Factor> factors) {
156 if (factors is List<Factor> factorsList) {
157 factorsList.AddRange(m_resilienceFactors);
158 }
160 }
161
162 [Obsolete("Get m_speedFactors and SpeedFactor instead.")]
163 public virtual float CalculateSpeedFactor(ICollection<Factor> factors) {
164 if (factors is List<Factor> factorsList) {
165 factorsList.AddRange(m_speedFactors);
166 }
168 }
169
170 [Obsolete("Get m_hungerFactors and HungerFactor instead.")]
171 public virtual float CalculateHungerFactor(ICollection<Factor> factors) {
172 if (factors is List<Factor> factorsList) {
173 factorsList.AddRange(m_hungerFactors);
174 }
176 }
177
178 #endregion
179
187 public virtual void Update(float dt) {
188#pragma warning disable CS0618
193#pragma warning restore CS0618
201 "OnFactorsUpdate",
202 Loader => {
203#pragma warning disable CS0618
204 Loader.OnFactorsUpdate(this, dt);
205#pragma warning restore CS0618
206 return false;
207 }
208 );
209 }
210 }
211}
override void Load(ValuesDictionary valuesDictionary, IdToEntityMap idToEntityMap)
AttackSpeed: 生物攻速 DigSpeed: 挖掘速度 ChaseRange: 非玩家生物的仇恨距离
static float CalculateFactorsResult(ICollection< Factor > factors)
virtual void CalculateOtherFactorsResult()
virtual void GenerateResilienceFactors()
virtual float GetOtherFactorResult(string factorName, bool recalculate=false, bool throwIfNotFound=false)
Dictionary< string, List< Factor > > OtherFactors
模组如果有自定义的Factors,可以使用这个OtherFactors。例如使用OtherFactors["AttackRate"]来定义攻击频率。
SubsystemGameInfo m_subsystemGameInfo
List< Factor > m_strengthFactors
这四个Factors是可以调整的影响因素
virtual float CalculateSpeedFactor(ICollection< Factor > factors)
virtual float CalculateStrengthFactor(ICollection< Factor > factors)
virtual void Update(float dt)
对等级系统的更新进行了调整。 第一步是计算上一帧Factors的最终结果,并进行赋值。此时已经经过了所有模组的修改。 第二步是GenerateFactors对四个属性进行生成,此时四个m_xxxFact...
virtual float CalculateHungerFactor(ICollection< Factor > factors)
Dictionary< string, float > OtherFactorsResults
virtual float CalculateResilienceFactor(ICollection< Factor > factors)
ValuesDictionary ValuesDictionary
static void HookAction(string HookName, Func< ModLoader, bool > action)
执行Hook