public void App(IPropUnit src) { int addCount = 0; foreach (Prop prop in props) { if (float.IsNaN(prop.value)) { Debug.Log(string.Format("<color=red>AttachPropData App prop.Value=NaN prop={0}</color>", prop)); } if (prop.type == PropType.Final) { Debug.Log(string.Format("<color=red>AttachPropData App 附加属性不可以是‘最终类型’ prop={0}</color>", prop)); } src.Props[prop.id] += prop.value; if (prop.additive == 0) { addCount++; } // 如果是状态 且值小于0.就把值设置为0 if (prop.type == PropType.State && src.Props[prop.id] < 0) { src.Props[prop.id] = 0; } } if (addCount > 0) { src.AttachProps.Add(uid, this); } }
/** 属性实体--清空 */ public static void RevokeAll(this IPropUnit src) { if (src.sClearProp != null) { src.sClearProp(src); } src.Props.PropClear(); src.AttachProps.Clear(); }
/** 属性实体--移除附加 */ public static void RevokeProps(this IPropUnit src, int attachPropUid, bool calculate = false) { AttachPropData attachPropData; if (src.AttachProps.TryGetValue(attachPropUid, out attachPropData)) { RevokeProps(src, attachPropData, calculate); } }
/** 销毁属性节点 */ public void Destroy() { foreach (KeyValuePair <int, IPropUnit> kvp in unitDict) { IPropUnit unit = kvp.Value; unit.RevokeProps(attachPropData, true); unit.sClearProp -= OnUnitCleanProp; } unitDict.Clear(); }
/** 单位--应用附加属性 */ public void UnitApp(IPropUnit unit, bool calculate = false) { if (unitDict.ContainsKey(unit.uid)) { UnitRevoke(unit); } unit.AppProps(attachPropData, calculate); unitDict.Add(unit.uid, unit); unit.sClearProp += OnUnitCleanProp; }
/** 单位--应用所有节点 */ public void UnitApp(IPropUnit unit, bool calculate = false) { int i = 0; int count = nodeDict.Count; bool isCalculate = false; foreach (KeyValuePair <int, PropNdoe> kvp in nodeDict) { i++; isCalculate = calculate && i == count; kvp.Value.UnitApp(unit, isCalculate); } }
/** 属性实体--移除附加 */ public static void RevokeProps(this IPropUnit src, AttachPropData attachPropData, bool calculate = false) { if (attachPropData == null) { return; } if (src.AttachProps.ContainsKey(attachPropData.uid)) { attachPropData.Revoke(src); } if (calculate) { src.Props.Calculate(); } }
/** 属性实体--添加附加 */ public static void AppProps(this IPropUnit src, AttachPropData attachPropData, bool calculate = false) { if (attachPropData == null) { return; } if (src.AttachProps.ContainsKey(attachPropData.uid)) { src.RevokeProps(attachPropData.uid); } //Debug.Log(string.Format("<color=0x33DD55> attachPropData={0}, calculate={1}</color>", attachPropData, calculate)); attachPropData.App(src); if (calculate) { src.Props.Calculate(); } }
public void Revoke(IPropUnit src) { foreach (Prop prop in props) { if (float.IsNaN(prop.value)) { Debug.Log(string.Format("<color=red>AttachPropData Revoke prop.Value=NaN prop={0}</color>", prop)); } if (prop.additive == 0) { src.Props[prop.id] -= prop.value; // 如果是状态 且值小于0.就把值设置为0 if (prop.type == PropType.State && src.Props[prop.id] < 0) { src.Props[prop.id] = 0; } } } src.AttachProps.Remove(uid); }
/** 单位清除属性事件,一般士兵死亡时、建筑换势力时调用 */ private void OnUnitCleanProp(IPropUnit unit) { UnitRevoke(unit, false); }
/** 单位--移除附加属性 */ public void UnitRevoke(IPropUnit unit, bool calculate = false) { unit.RevokeProps(attachPropData, calculate); unit.sClearProp -= OnUnitCleanProp; unitDict.Remove(unit.uid); }