// PUBLIC STATUS EFFECT METHODS: ---------------------------------------------------------- public void AddStatusEffect(StatusEffectAsset statusEffect, bool informCallbacks = true) { if (!statusEffect) { return; } this.RequireInit(); if (!this.runtimeStefsData.ContainsKey(statusEffect.uniqueID)) { RuntimeStefData data = new RuntimeStefData(statusEffect); this.runtimeStefsData.Add(statusEffect.uniqueID, data); } int currentStack = this.runtimeStefsData[statusEffect.uniqueID].listStatus.Count; if (currentStack >= statusEffect.statusEffect.maxStack) { this.RemoveStatusEffect(statusEffect); } StatusEffect.Runtime item = new StatusEffect.Runtime( Time.time, statusEffect.statusEffect ); this.runtimeStefsData[statusEffect.uniqueID].listStatus.Add(item); item.OnStart(gameObject); if (informCallbacks && this.onChangeStef != null) { this.onChangeStef.Invoke(new EventArgs( statusEffect.statusEffect.uniqueName, EventArgs.Operation.Add )); } }
// UPDATE METHOD: ------------------------------------------------------------------------- private void Update() { if (!Application.isPlaying) { return; } if (this.runtimeStefsData == null) { return; } Dictionary <string, int> removeStatusEffects = new Dictionary <string, int>(); foreach (KeyValuePair <string, RuntimeStefData> item in this.runtimeStefsData) { RuntimeStefData data = item.Value; if (data.statusEffect.statusEffect.hasDuration) { int listStatusIndex = 0; while (listStatusIndex < data.listStatus.Count && data.listStatus[listStatusIndex].time + data.statusEffect.statusEffect.duration < Time.time) { data.listStatus[listStatusIndex].OnEnd(gameObject); if (!removeStatusEffects.ContainsKey(item.Key)) { removeStatusEffects.Add(item.Key, 0); } removeStatusEffects[item.Key] += 1; listStatusIndex += 1; } } int stackCount = data.listStatus.Count; int index = (removeStatusEffects.ContainsKey(item.Key) ? removeStatusEffects[item.Key] : 0 ); while (index < stackCount) { data.listStatus[index].OnUpdate(gameObject); index += 1; } } foreach (KeyValuePair <string, int> item in removeStatusEffects) { this.runtimeStefsData[item.Key].listStatus.RemoveRange(0, item.Value); if (this.onChangeStef != null) { this.onChangeStef.Invoke(new EventArgs( this.runtimeStefsData[item.Key].statusEffect.statusEffect.uniqueName, EventArgs.Operation.Remove )); } } }
public void OnLoad(object generic) { if (generic == null) { return; } SerialData stats = (SerialData)generic; this.RequireInit(); for (int i = 0; i < stats.stats.Length; ++i) { string key = stats.stats[i].statUniqueID; float baseValue = stats.stats[i].baseValue; this.runtimeStatsData[key].baseValue = baseValue; if (this.onChangeStat != null) { this.onChangeStat.Invoke(new EventArgs(key, EventArgs.Operation.Change)); } } for (int i = 0; i < stats.attrs.Length; ++i) { string key = stats.attrs[i].statUniqueID; float value = stats.attrs[i].value; this.runtimeAttrsData[key].value = value; if (this.onChangeAttr != null) { this.onChangeAttr.Invoke(new EventArgs(key, EventArgs.Operation.Change)); } } for (int i = 0; i < stats.stefs.Length; ++i) { string key = stats.stefs[i].stefUniqueID; float[] timeStack = stats.stefs[i].durationStack; for (int j = 0; j < timeStack.Length; ++j) { timeStack[j] = Time.time - timeStack[j]; } RuntimeStefData stefData = new RuntimeStefData(key, timeStack); this.runtimeStefsData.Add(key, stefData); if (this.onChangeStef != null) { this.onChangeStef.Invoke(new EventArgs(key, EventArgs.Operation.Change)); } for (int j = 0; j < timeStack.Length; ++j) { stefData.listStatus[j].OnStart(gameObject); } } }
// UPDATE METHOD: ------------------------------------------------------------------------- private void Update() { if (!Application.isPlaying) { return; } if (this.runtimeStefsData == null) { return; } foreach (KeyValuePair <string, RuntimeStefData> item in this.runtimeStefsData) { RuntimeStefData data = item.Value; if (data.statusEffect.statusEffect.hasDuration) { while (data.listStatus.Count > 0 && data.listStatus[0].time + data.statusEffect.statusEffect.duration < Time.time) { data.listStatus[0].OnEnd(gameObject); data.listStatus.RemoveAt(0); if (this.onChangeStef != null) { this.onChangeStef.Invoke(new EventArgs( data.statusEffect.statusEffect.uniqueName, EventArgs.Operation.Remove )); } } } int stackCount = data.listStatus.Count; for (int i = 0; i < stackCount; ++i) { data.listStatus[i].OnUpdate(gameObject); } } }