public void UpdateAtbTreeUp() { if (!Dirty) { return; } Queue <AtbNode> qParents = new Queue <AtbNode>(); qParents.Enqueue(this); while (qParents.Count > 0) { AtbNode node = qParents.Dequeue(); if (node.Dirty) { if (mCalcFunc != null) { mCalcFunc(node); } node.Dirty = false; } for (int i = 0; i < node.parents.Count; ++i) { AtbNode parent = node.parents[i]; if (!parent.Dirty) { continue; } qParents.Enqueue(parent); } } }
public int GetAtb(AtbType atb) { AtbNode node = null; if (!atbNodes.TryGetValue(atb, out node)) { return(0); } return(node.GetValue()); }
public float GetAtbPct(AtbType atb) { AtbNode node = null; if (!atbNodes.TryGetValue(atb, out node)) { return(0.0f); } int v = node.GetValue(); return((float)v * 0.0001f); }
public static void DefaultCalcFunc(AtbNode node) { int value = node.GetValue(); for (int i = 0; i < node.children.Count; ++i) { if (i == 0) { value = 0; } AtbNode child = node.children[i]; excel_atb_data excel = child.excel; value += child.GetValue(); } node.SetValue(value); }
public void SetAtb(AtbType atb, int value) { AtbNode node = null; if (!atbNodes.TryGetValue(atb, out node)) { return; } int oldValue = node.GetValue(); if (oldValue == value) { return; } node.SetValue(value); node.Dirty = true; node.UpdateAtbTreeUp(); }
public void UpdateAtbTreeDown() { Stack <AtbNode> nodes = new Stack <AtbNode>(); Queue <AtbNode> qChildrens = new Queue <AtbNode>(); qChildrens.Enqueue(this); while (qChildrens.Count > 0) { AtbNode node = qChildrens.Dequeue(); nodes.Push(node); for (int i = 0; i < node.children.Count; ++i) { AtbNode child = node.children[i]; if (!child.Dirty) { continue; } qChildrens.Enqueue(child); } } while (nodes.Count > 0) { AtbNode node = nodes.Pop(); if (node == null) { continue; } if (node.Dirty) { if (mCalcFunc != null) { mCalcFunc(node); } node.Dirty = false; } } }
public void PacketToMsg() { if (mAtbMsgAround == null) { mAtbMsgAround = new NotifyAtb(); mAtbMsgAround.uid = mCharacter.gid; } if (mAtbMsgSelf == null) { mAtbMsgSelf = new NotifyAtb(); mAtbMsgSelf.uid = mCharacter.gid; } foreach (var kv in atbNodes) { AtbNode node = kv.Value; if (node == null) { return; } node.PacketToMsg(); } }
public AtbTree(Character cha) { mCharacter = cha; List <AtbNode> nodes = new List <AtbNode>(); List <bool> token = new List <bool>(); for (int i = 0; i < excel_atb_data.Count; ++i) { excel_atb_data excel = excel_atb_data.GetByIndex(i); AtbNode node = new AtbNode(excel, this); AtbNode.CalcFunc func = null; if (AtbCalcFuncRegister.mFuncs.TryGetValue(node.AtbType, out func)) { node.mCalcFunc = func; } else { node.mCalcFunc = AtbCalcFuncRegister.DefaultCalcFunc; } atbNodes.Add(node.AtbType, node); nodes.Add(node); token.Add(false); } // Build Tree for (int i = 0; i < nodes.Count; ++i) { AtbNode node = nodes[i]; if (node.excel.inflAtbs == null) { continue; } for (int j = 0; j < node.excel.inflAtbs.Length; ++j) { int inflID = node.excel.inflAtbs[j]; AtbType childAtb = (AtbType)inflID; // 获取被影响节点; AtbNode inflNode = null; if (!atbNodes.TryGetValue(childAtb, out inflNode)) { continue; } inflNode.children.Add(node); node.parents.Add(inflNode); } } // Update Tree for (int i = 0; i < nodes.Count; ++i) { AtbNode node = nodes[i]; if (node.parents.Count == 0) { node.UpdateAtbTreeDown(); } } }