/// <summary> /// 得到一个可以攻击的点 /// </summary> /// <returns></returns> public Vector3 GetCurFirstAtkPos() { Vector3 ret = Vector3.zero; if (root != null) { Queue <AtkNode> queue = new Queue <AtkNode>(); queue.Enqueue(root); while (queue.Count > 0) { AtkNode node = queue.Dequeue(); if (node.CouldAtk) { if (!node.IsTaken) { return(node.AtkPos); } } else { foreach (AtkNode n in node.subNodes) { if (!n.IsTaken) { queue.Enqueue(n); } } } } } return(ret); }
/// <summary> /// 添加一个进攻点 /// </summary> /// <param name="id"></param> /// <param name="parentId"></param> /// <param name="pos"></param> /// <param name="cost"></param> /// <param name="value"></param> /// <param name="couldAtkOnAllPass"></param> public void AddAtkNode(int id, int parentId, Vector3 pos, float cost, float value, bool couldAtkOnAllPass) { if (!atkNodeDic.ContainsKey(id)) { AtkNode node = new AtkNode(id, pos, cost, value, couldAtkOnAllPass); if (atkNodeDic.ContainsKey(parentId)) { atkNodeDic[parentId].subNodes.Add(node); } else { if (root == null) { root = node; } } atkNodeDic.Add(id, node); } }
/// <summary> /// 得到所有可用的进攻点 /// </summary> /// <returns></returns> public List <AtkNode> GetAttackableNodes() { List <AtkNode> nodes = new List <AtkNode>(); if (root != null) { Queue <AtkNode> queue = new Queue <AtkNode>(); queue.Enqueue(root); while (queue.Count > 0) { AtkNode node = queue.Dequeue(); if (!node.IsTaken && node.CouldAtk) { nodes.Add(node); } foreach (AtkNode n in node.subNodes) { queue.Enqueue(n); } } } return(nodes); }