diff --git a/ColorlessWorld-2024-4-2/Assets/GameDate/Enemy/SkeletonArcher.asset b/ColorlessWorld-2024-4-2/Assets/GameDate/Enemy/SkeletonArcher.asset index 54ca9958..05c60c60 100644 --- a/ColorlessWorld-2024-4-2/Assets/GameDate/Enemy/SkeletonArcher.asset +++ b/ColorlessWorld-2024-4-2/Assets/GameDate/Enemy/SkeletonArcher.asset @@ -14,7 +14,7 @@ MonoBehaviour: m_EditorClassIdentifier: enemyName: skeletonArcher enemyIcon: {fileID: 21300000, guid: 99d6cfcd8d628454989abc09534f0b64, type: 3} - stepRange: 2 + stepRange: 4 stepRangeMultiplier: 1 speed: 2 maxMoveCoolDown: 0 @@ -28,4 +28,4 @@ MonoBehaviour: currentSkillCoolDown: 3 damageMultiplier: 1 damage: 4 - attackRange: 5 + attackRange: 3 diff --git a/ColorlessWorld-2024-4-2/Assets/Scenes/SampleScene.unity b/ColorlessWorld-2024-4-2/Assets/Scenes/SampleScene.unity index 8f806f85..721af530 100644 --- a/ColorlessWorld-2024-4-2/Assets/Scenes/SampleScene.unity +++ b/ColorlessWorld-2024-4-2/Assets/Scenes/SampleScene.unity @@ -6479,7 +6479,6 @@ MonoBehaviour: m_Script: {fileID: 11500000, guid: d344126aa8082fa48b7e5f19eff09202, type: 3} m_Name: m_EditorClassIdentifier: - castPool: [] --- !u!1 &680060074 GameObject: m_ObjectHideFlags: 0 @@ -14314,8 +14313,8 @@ BoxCollider: m_ProvidesContacts: 0 m_Enabled: 1 serializedVersion: 3 - m_Size: {x: 1, y: 1, z: 1} - m_Center: {x: 0, y: 0, z: 0} + m_Size: {x: 1, y: 2.5280278, z: 1} + m_Center: {x: 0, y: -0.76401204, z: 0} --- !u!23 &1809205614 MeshRenderer: m_ObjectHideFlags: 0 @@ -14400,7 +14399,6 @@ MonoBehaviour: step: 2 startPositionX: 1 startPositionY: 1 - influencePreviewPool: [] chooseNodeLayerMask: serializedVersion: 2 m_Bits: 64 diff --git a/ColorlessWorld-2024-4-2/Assets/Scripts/Card/CardOriginalDataList.cs b/ColorlessWorld-2024-4-2/Assets/Scripts/Card/CardOriginalDataList.cs index 3e91a734..cfd8f4b0 100644 --- a/ColorlessWorld-2024-4-2/Assets/Scripts/Card/CardOriginalDataList.cs +++ b/ColorlessWorld-2024-4-2/Assets/Scripts/Card/CardOriginalDataList.cs @@ -62,7 +62,6 @@ public class CardOriginalDataList : Singleton private void getDictionaryFromString(string[] values, CardOriginalData cardOriginalData) { - Debug.Log("卡牌是:" + cardOriginalData.ChineseName); string[] function = values[4].Split(";"); string[] functionVal = values[5].Split(";"); string[] advantagefunction = values[9].Split(";"); diff --git a/ColorlessWorld-2024-4-2/Assets/Scripts/Card/TurnMaster.cs b/ColorlessWorld-2024-4-2/Assets/Scripts/Card/TurnMaster.cs index ac1c0308..ea19fb8d 100644 --- a/ColorlessWorld-2024-4-2/Assets/Scripts/Card/TurnMaster.cs +++ b/ColorlessWorld-2024-4-2/Assets/Scripts/Card/TurnMaster.cs @@ -169,9 +169,7 @@ public class TurnMaster : Singleton var card = handCard.cardSlotList[cardIndex].transform.GetChild(0).gameObject; TurnMaster.Instance.usedCard.usedCardList.Add(card.GetComponent().CardId); bool a = card == null; - Debug.Log(a); Destroy(card); - Debug.Log("结束了"); } } @@ -179,9 +177,6 @@ public class TurnMaster : Singleton { int handCardCount = handCard.getHandCardList().Count; int actualCardsToDraw = Mathf.Min(handCard.maxHandCard - handCardCount, drawNum); - Debug.Log("抽卡前手牌数:" + handCardCount); - Debug.Log("真正抽卡数:" + actualCardsToDraw); - Debug.Log("ccc"); for (int i = handCardCount; i < handCardCount + actualCardsToDraw; i++) { diff --git a/ColorlessWorld-2024-4-2/Assets/Scripts/Enemy/EnemyNode.cs b/ColorlessWorld-2024-4-2/Assets/Scripts/Enemy/EnemyNode.cs index d7cb624f..3c92c825 100644 --- a/ColorlessWorld-2024-4-2/Assets/Scripts/Enemy/EnemyNode.cs +++ b/ColorlessWorld-2024-4-2/Assets/Scripts/Enemy/EnemyNode.cs @@ -1,8 +1,10 @@ +using System; using System.Collections; using System.Collections.Generic; using System.Linq; using System.Xml; using UnityEngine; +using UnityEngine.Assertions; public class EnemyNode : MonoBehaviour,IEnemyObserver { @@ -215,12 +217,142 @@ public class EnemyNode : MonoBehaviour,IEnemyObserver pasth = AStarManager.Instance.FindPath(currentNode, GameManager.Instance.playerOn); } - public void FindPathForRemoteAttacker() + private MapUnity getEndNodeTowardsPlayer() + { + MapUnity currentMapUnity = GameManager.Instance.X[positionX].Y[positionY]; + HashSet shootAbleMapUnity = new HashSet(); + HashSet reachAbleMapUnity = new HashSet(); + HashSet endNodeMapUnityList = new HashSet(); + Dictionary endNodeMapUnityMap = new Dictionary(); + for (int i = 0; i < GameManager.Instance.X.Count; i++) + { + for (int j = 0; j < GameManager.Instance.X[i].Y.Count; j++) + { + shootAbleMapUnity.Add(GameManager.Instance.X[i].Y[j]); + } + } + getNodeTools.checkListShootPass(shootAbleMapUnity,EnemyState.attackRange); + Debug.Log("可射击集合大小:" + shootAbleMapUnity.Count); + shootAbleMapUnity.Remove(currentMapUnity); + getNodeTools.exceptWithEnemyNode(shootAbleMapUnity); + //reachAbleMapUnity.UnionWith(MapUnityManager.Instance.findReachableTiles(currentMapUnity, EnemyState.getStepRange())); + //取交集 + //shootAbleMapUnity.IntersectWith(reachAbleMapUnity); + //交集中找到移动距离最小的点作为最终目的地 + foreach(MapUnity mapUnity in shootAbleMapUnity) + { + try + { + List mapUnities = AStarManager.Instance.FindPathWithEndNode(currentMapUnity, mapUnity); + int step; + if (mapUnities != null) + { + step = mapUnities.Count; + } + else + { + step = 10000; + } + + endNodeMapUnityMap.Add(mapUnity, step); + } + catch(Exception e) + { + Debug.Log("寻路错误地块是X:" + mapUnity.locationX + "Y:" + mapUnity.locationY); + } + + } + endNodeMapUnityList.UnionWith(GetKeysWithMinValue(endNodeMapUnityMap)); + //hashset无法随机,变成数组 + MapUnity[] setArray = new MapUnity[endNodeMapUnityList.Count]; + endNodeMapUnityList.CopyTo(setArray); + Debug.Log("交集大小:" + endNodeMapUnityList.Count); + // 生成随机索引 + System.Random random = new System.Random(); + int randomIndex = random.Next(setArray.Length); + MapUnity randomMapUnity = setArray[randomIndex]; + Debug.Log("目的地是:" + "X:" + randomMapUnity.locationX + "Y:" + randomMapUnity.locationY); + randomMapUnity.influenced=true; + return randomMapUnity; + } + + private MapUnity getEndNodeAwayFromPlayer() + { + MapUnity currentMapUnity = GameManager.Instance.X[positionX].Y[positionY]; + HashSet nearestMapUnity = new HashSet(); + HashSet endNodeMapUnityList = new HashSet(); + Dictionary endNodeMapUnityMap = new Dictionary(); + endNodeMapUnityList.Add(GameManager.Instance.playerOn); + getNodeTools.getArcNode(endNodeMapUnityList, EnemyState.attackRange); + getNodeTools.exceptWithEnemyNode(endNodeMapUnityList); + foreach (MapUnity mapUnity in endNodeMapUnityList) + { + try + { + List mapUnities = AStarManager.Instance.FindPathWithEndNode(currentMapUnity, mapUnity); + int step; + if (mapUnities != null) + { + step = mapUnities.Count; + } + else + { + step = 10000; + } + + endNodeMapUnityMap.Add(mapUnity, step); + } + catch (Exception e) + { + Debug.Log("寻路错误地块是X:" + mapUnity.locationX + "Y:" + mapUnity.locationY); + } + + } + nearestMapUnity.UnionWith(GetKeysWithMinValue(endNodeMapUnityMap)); + //hashset无法随机,变成数组 + MapUnity[] setArray = new MapUnity[nearestMapUnity.Count]; + nearestMapUnity.CopyTo(setArray); + Debug.Log("交集大小:" + nearestMapUnity.Count); + // 生成随机索引 + System.Random random = new System.Random(); + int randomIndex = random.Next(setArray.Length); + MapUnity randomMapUnity = setArray[randomIndex]; + Debug.Log("目的地是:" + "X:" + randomMapUnity.locationX + "Y:" + randomMapUnity.locationY); + randomMapUnity.influenced = true; + return randomMapUnity; + } + + public List GetKeysWithMinValue(Dictionary map) + { + if (map == null || map.Count == 0) + { + return new List(); + } + + int minValue = map.Values.Min(); + + List keysWithMinValue = map + .Where(kv => kv.Value == minValue) + .Select(kv => kv.Key) + .ToList(); + + return keysWithMinValue; + } + + public void FindPathTowardsPlayer() + { + MapUnity currentNode = GameManager.Instance.X[positionX].Y[positionY]; + pasth.Clear(); + + pasth = AStarManager.Instance.FindPathWithEndNode(currentNode, getEndNodeTowardsPlayer()); + } + + public void FindPathAwayFromPlayer() { MapUnity currentNode = GameManager.Instance.X[positionX].Y[positionY]; pasth.Clear(); - pasth = AStarManager.Instance.FindPath(currentNode, GameManager.Instance.playerOn); + pasth = AStarManager.Instance.FindPathWithEndNode(currentNode, getEndNodeAwayFromPlayer()); } public void Move(MapUnity currentNode , int step) { diff --git a/ColorlessWorld-2024-4-2/Assets/Scripts/Enemy/SkeletonArcher.cs b/ColorlessWorld-2024-4-2/Assets/Scripts/Enemy/SkeletonArcher.cs index f6e4ae4b..4d0d8986 100644 --- a/ColorlessWorld-2024-4-2/Assets/Scripts/Enemy/SkeletonArcher.cs +++ b/ColorlessWorld-2024-4-2/Assets/Scripts/Enemy/SkeletonArcher.cs @@ -22,7 +22,7 @@ public class SkeletonArcher : MonoBehaviour private void Update() { - //时时寻路 + /*//时时寻路 if (GameManager.Instance.complete == true && TurnMaster.Instance.turn == TurnMaster.Turn.playerTurn) { if (lastTime > 0) @@ -84,7 +84,7 @@ public class SkeletonArcher : MonoBehaviour //重置时间标量 lastTime = time; } - } + }*/ } @@ -96,70 +96,71 @@ public class SkeletonArcher : MonoBehaviour IEnumerator JudgeActionCoroutine()//等移动到位置就判断是否还能走 { - - for (int i = 0; i < enemyNode.EnemyState.stepRange * enemyNode.EnemyState.stepRangeMultiplier; i++) - { - - Debug.Log(enemyNode.pasth.Count); - if (enemyNode.pasth.Count > enemyNode.EnemyState .attackRange ) - { - enemyNode.FindPath(); - MapUnity currentNode = enemyNode.pasth[0]; - MapUnity disNode = enemyNode.pasth[1]; - currentNode.blocked = false; - currentNode.enemyNode = null; - enemyNode.positionX = disNode.locationX; - enemyNode.positionY = disNode.locationY; - disNode.enemyNode = enemyNode; - yield return StartCoroutine(SkeletonArcherMoveCoroutine(disNode)); - } - else if (enemyNode.pasth.Count == enemyNode.EnemyState.attackRange) - { - /* Vector3 dir = GameManager.Instance.player.transform.position - this.transform.position; - Ray ray = new Ray(this.transform.position, dir); - if (Physics.Raycast(ray, out RaycastHit raycastHit, 500, layerMask.value)) - { - if(raycastHit .collider .tag != "Player") - { - float angleBlock = Vector3.SignedAngle (GameManager.Instance.playerOn.transform.position-this.transform.position, raycastHit.collider.transform.position-this.transform.position,enemyNode .pasth [0].transform .up); - float anglePlayer= Vector3.SignedAngle(this.transform.position - GameManager.Instance.playerOn.transform.position, GameManager.Instance.playerOn.transform.forward, GameManager.Instance.playerOn.transform.up); - if(angleBlock <=0) - { + yield return StartCoroutine(RemoteAttackAction()); - } - else - { + } - } - } - } - */ - SkeletonArcherAction(); - yield break; + + IEnumerator moveTowardsPlayer() + { + enemyNode.FindPathTowardsPlayer(); + for (int i = 1; i < getMoveStep(); i++) + { + if (enemyNode.pasth.Count > 1) + { + yield return StartCoroutine(moveOneStep(enemyNode.pasth[i])); } - else + } + } + + IEnumerator moveAwayFromPlayer() + { + enemyNode.FindPathAwayFromPlayer(); + for (int i = 1; i < getMoveStep(); i++) + { + if (enemyNode.pasth.Count > 1) { - //反向运动 - MapUnity currentNode = enemyNode.pasth[0]; - enemyNode.oppositePasth.Clear(); - enemyNode.oppositePasth = AStarManager.Instance.FindOppositePath(currentNode, GameManager.Instance.playerOn, enemyNode.EnemyState.stepRange); - - if(enemyNode . oppositePasth.Count >1) - { - MapUnity disNode = enemyNode.oppositePasth[1]; - currentNode.blocked = false; - currentNode.enemyNode = null; - enemyNode.positionX = disNode.locationX; - enemyNode.positionY = disNode.locationY; - disNode.enemyNode = enemyNode; - yield return StartCoroutine(SkeletonArcherMoveCoroutine(disNode)); - } - + yield return StartCoroutine(moveOneStep(enemyNode.pasth[i])); } } + } - SkeletonArcherAction(); + private int getMoveStep() + { + if(enemyNode.EnemyState.getStepRange() + 1<= enemyNode.pasth.Count) + { + return enemyNode.EnemyState.getStepRange() + 1; + } + else + { + return enemyNode.pasth.Count; + } + } + IEnumerator moveOneStep(MapUnity nexMapUnity) + { + MapUnity currentNode = GameManager.Instance.X[enemyNode.positionX].Y[enemyNode.positionY]; + MapUnity disNode = nexMapUnity; + currentNode.blocked = false; + currentNode.enemyNode = null; + enemyNode.positionX = disNode.locationX; + enemyNode.positionY = disNode.locationY; + disNode.enemyNode = enemyNode; + yield return StartCoroutine(SkeletonArcherMoveCoroutine(disNode)); + } + + IEnumerator RemoteAttackAction() + { + MapUnity currentNode = GameManager.Instance.X[enemyNode.positionX].Y[enemyNode.positionY]; + if (getNodeTools.canRemoteAttack(currentNode,enemyNode.EnemyState.attackRange)) + { + AttackDamage(); + yield return StartCoroutine(moveAwayFromPlayer()); + } + else + { + yield return StartCoroutine(moveTowardsPlayer()); + } } IEnumerator JudgNextActionCoroutine() @@ -167,8 +168,6 @@ public class SkeletonArcher : MonoBehaviour yield return StartCoroutine(JudgeActionCoroutine()); //下回合意图 ArcherAim(); - enemyNode.SettlementSkill(); - NextTurnIntention(); //让下一个敌人运动 EnemyManager.Instance.enemyTurnState = EnemyManager.EnemyTurnState.runing; @@ -190,6 +189,8 @@ public class SkeletonArcher : MonoBehaviour } + + public void SkeletonArcherAction() { float distance = Vector3.Distance(this.transform.position, GameManager.Instance.player.transform.position); diff --git a/ColorlessWorld-2024-4-2/Assets/Scripts/Enemy/SkullGuardian.cs b/ColorlessWorld-2024-4-2/Assets/Scripts/Enemy/SkullGuardian.cs index 7caa11d4..ef01c51c 100644 --- a/ColorlessWorld-2024-4-2/Assets/Scripts/Enemy/SkullGuardian.cs +++ b/ColorlessWorld-2024-4-2/Assets/Scripts/Enemy/SkullGuardian.cs @@ -28,7 +28,7 @@ public class SkullGuardian : MonoBehaviour } else { - enemyNode.FindPath(); + /*enemyNode.FindPath(); if(enemyNode .pasth .Count >1) { @@ -37,7 +37,7 @@ public class SkullGuardian : MonoBehaviour else { enemyNode.canMove = false; - } + }*/ enemyNode.enemyUIBar.RefreshEnemyBuffIcon(); //重置时间标量 @@ -48,7 +48,7 @@ public class SkullGuardian : MonoBehaviour public void SkullGuardianTurn() { - StartCoroutine(JudgNextActionCoroutine ()); + StartCoroutine(JudgNextActionCoroutine()); } public void SkullGuardianAction() @@ -82,41 +82,70 @@ public class SkullGuardian : MonoBehaviour } IEnumerator JudgeActionCoroutine()//等移动到位置就判断是否还能走 { - for(int i = 0;i< enemyNode .EnemyState .stepRange * enemyNode.EnemyState.stepRangeMultiplier;i++) + yield return StartCoroutine(MeleeAttackAction()); + } + + IEnumerator JudgNextActionCoroutine() + { + yield return StartCoroutine(JudgeActionCoroutine()); + //下回合意图 + + //让下一个敌人运动 + EnemyManager.Instance.enemyTurnState = EnemyManager.EnemyTurnState.runing; + Debug.Log(1); + } + + IEnumerator MeleeAttackAction() + { + MapUnity currentNode = GameManager.Instance.X[enemyNode.positionX].Y[enemyNode.positionY]; + if (getNodeTools.canRemoteAttack(currentNode, enemyNode.EnemyState.attackRange)) { - enemyNode.FindPath(); - if (enemyNode.pasth.Count > 1) + AttackDamage(); + } + else + { + yield return StartCoroutine(moveTowardsPlayer()); + currentNode = GameManager.Instance.X[enemyNode.positionX].Y[enemyNode.positionY]; + if (getNodeTools.canRemoteAttack(currentNode, enemyNode.EnemyState.attackRange)) { - MapUnity currentNode = enemyNode.pasth[0]; - MapUnity disNode = enemyNode.pasth[1]; - currentNode.blocked = false; - currentNode.enemyNode = null; - enemyNode.positionX = disNode.locationX; - enemyNode.positionY = disNode.locationY; - disNode.enemyNode = enemyNode; - yield return StartCoroutine(SkullGuardianMoveCoroutine(disNode)); + AttackDamage(); } - else if(enemyNode.pasth.Count == 1&& enemyNode.planAction == EnemyNode.PlanAction.attack ) + } + } + + IEnumerator moveTowardsPlayer() + { + enemyNode.FindPathTowardsPlayer(); + for (int i = 1; i < getMoveStep(); i++) + { + if (enemyNode.pasth.Count > 1) { - SkullGuardianAction(); - yield break; + yield return StartCoroutine(moveOneStep(enemyNode.pasth[i])); } } - if (enemyNode.planAction == EnemyNode.PlanAction.sheield) + } + private int getMoveStep() + { + if (enemyNode.EnemyState.getStepRange() + 1 <= enemyNode.pasth.Count) + { + return enemyNode.EnemyState.getStepRange() + 1; + } + else { - SkullGuardianAction(); + return enemyNode.pasth.Count; } } - IEnumerator JudgNextActionCoroutine() + IEnumerator moveOneStep(MapUnity nexMapUnity) { - yield return StartCoroutine(JudgeActionCoroutine()); - //下回合意图 - enemyNode.SettlementSkill(); - NextTurnIntention(); - //让下一个敌人运动 - EnemyManager.Instance.enemyTurnState = EnemyManager.EnemyTurnState.runing; - Debug.Log(1); + MapUnity currentNode = GameManager.Instance.X[enemyNode.positionX].Y[enemyNode.positionY]; + MapUnity disNode = nexMapUnity; + currentNode.blocked = false; + currentNode.enemyNode = null; + enemyNode.positionX = disNode.locationX; + enemyNode.positionY = disNode.locationY; + disNode.enemyNode = enemyNode; + yield return StartCoroutine(SkullGuardianMoveCoroutine(disNode)); } IEnumerator SkullGuardianMoveCoroutine( MapUnity endMapUnity )//移动到位置 { diff --git a/ColorlessWorld-2024-4-2/Assets/Scripts/Tool/AStar/AStarManager.cs b/ColorlessWorld-2024-4-2/Assets/Scripts/Tool/AStar/AStarManager.cs index f6692620..20a458f2 100644 --- a/ColorlessWorld-2024-4-2/Assets/Scripts/Tool/AStar/AStarManager.cs +++ b/ColorlessWorld-2024-4-2/Assets/Scripts/Tool/AStar/AStarManager.cs @@ -75,6 +75,71 @@ public class AStarManager : Singleton } } + public List FindPathWithEndNode(MapUnity starNode, MapUnity endNode) + { + //判断传入的点是否合法 + //1.在地图范围内 2.不是阻挡,不合法返回null不能寻路 + if (endNode.blocked == true) + { + return null; + } + if (starNode == endNode) + { + return null; + } + //得到起点和终点对应的格子 + + //清空上一次列表数据 + closeList.Clear(); + openList.Clear(); + + //把起点放到关闭列表中 + starNode.aStarNode.fatherNode = null; + starNode.aStarNode.f = 0; + starNode.aStarNode.g = 0; + starNode.aStarNode.h = 0; + closeList.Add(starNode); + + while (true) + { + //从起点开始找周围的点放入开启列表中 + //判断这些点是否是边界是否是阻挡,是否在开启列表或者关闭列表中,都不是才能放入 + FindNodeToOpenList(starNode, endNode); + + //选出开启列表中寻路消耗最小的点 + openList.Sort(SortOpenList); + + //死路判断 + if (openList.Count == 0) + { + Debug.Log("无法找到路径"); + return null; + } + + //放入关闭列表中,再从开启列表中移除 + closeList.Add(openList[0]); + starNode = openList[0]; + openList.RemoveAt(0); + + //如果已经是终点,返回路径 + //如果不是结果,继续寻路 + if (starNode == endNode) + { + //找到路径,回溯路径 + List path = new List(); + path.Add(endNode); + while (endNode.aStarNode.fatherNode != null) + { + path.Add(endNode.aStarNode.fatherNode); + endNode = endNode.aStarNode.fatherNode; + } + //列表反置 + path.Reverse(); + return path; + } + } + } + public List FindOppositePath(MapUnity starNode, MapUnity endNode ,int step) { //判断传入的点是否合法 diff --git a/ColorlessWorld-2024-4-2/Assets/Scripts/Tool/CardData_SO/EnemyState_SO.cs b/ColorlessWorld-2024-4-2/Assets/Scripts/Tool/CardData_SO/EnemyState_SO.cs index 7e326d26..5ddd0b72 100644 --- a/ColorlessWorld-2024-4-2/Assets/Scripts/Tool/CardData_SO/EnemyState_SO.cs +++ b/ColorlessWorld-2024-4-2/Assets/Scripts/Tool/CardData_SO/EnemyState_SO.cs @@ -36,4 +36,9 @@ public class EnemyState_SO : ScriptableObject public int damage;//攻击力 public int attackRange;//攻击范围 + + public int getStepRange() + { + return (int)(stepRange * stepRangeMultiplier); + } } diff --git a/ColorlessWorld-2024-4-2/Assets/Scripts/Tool/getNodeTools.cs b/ColorlessWorld-2024-4-2/Assets/Scripts/Tool/getNodeTools.cs index fa56d882..22fcb60e 100644 --- a/ColorlessWorld-2024-4-2/Assets/Scripts/Tool/getNodeTools.cs +++ b/ColorlessWorld-2024-4-2/Assets/Scripts/Tool/getNodeTools.cs @@ -35,7 +35,7 @@ public class getNodeTools MapUnity currentCheckNode = currentNode; for (int i = 0; i < range; i++) { - if (tryGetNode(currentCheckNode.unitPool[angle], results)) + if (tryGetNodeFroPlayer(currentCheckNode.unitPool[angle], results)) { currentCheckNode = currentCheckNode.unitPool[angle]; } @@ -46,7 +46,7 @@ public class getNodeTools } } - public static bool tryGetNode(MapUnity currentNode, HashSet results) + public static bool tryGetNodeFroPlayer(MapUnity currentNode, HashSet results) { bool canPass = true; if (currentNode == null) @@ -71,6 +71,30 @@ public class getNodeTools return canPass; } + public static bool tryGetNodeForEnemy(MapUnity currentNode, HashSet results) + { + bool canPass = true; + if (currentNode == null) + { + canPass = false; + return canPass; + } + /*if (currentNode.TryGetComponent(out EnemyNode enemyNode))*/ + if (currentNode.enemyNode != null) + { + if (currentNode.enemyNode.enemyType.Equals(EnemyNode.EnemyType.block)) + { + canPass = false; + } + } + + if (canPass) + { + results.Add(currentNode); + } + return canPass; + } + public static void getCircleNode(HashSet nodeList,int range) { for (int i = 0;i < range;i++) @@ -78,6 +102,38 @@ public class getNodeTools getNearbyNode(nodeList); } } + + public static void getCircleNodeForEnemy(HashSet nodeList, int range) + { + for (int i = 0; i < range; i++) + { + getNearbyNodeFroEnemy(nodeList); + } + } + + public static void exceptWithEnemyNode(HashSet nodeList) + { + List mapUnityList = new List(nodeList); + + for (int i = mapUnityList.Count - 1; i >= 0; i--) + { + if (mapUnityList[i].enemyNode!=null) + { + mapUnityList.RemoveAt(i); + } + } + nodeList.Clear(); + nodeList.UnionWith(mapUnityList); + } + + + public static void getArcNode(HashSet nodeList, int range) + { + HashSet smallCircleNodeSet=new HashSet(nodeList); + getCircleNodeForEnemy(smallCircleNodeSet, range-1); + getCircleNodeForEnemy(nodeList, range); + nodeList.ExceptWith(smallCircleNodeSet); + } public static void getNearbyNode(HashSet nodeList) { // 创建一个副本以避免遍历时修改原集合 @@ -88,7 +144,26 @@ public class getNodeTools { for (int i = 0; i < 6; i++) { - tryGetNode(node.unitPool[i], nodesToAdd); + tryGetNodeFroPlayer(node.unitPool[i], nodesToAdd); + } + } + + // 遍历完成后统一修改原集合 + nodeList.AddRange(nodesToAdd); + + } + + public static void getNearbyNodeFroEnemy(HashSet nodeList) + { + // 创建一个副本以避免遍历时修改原集合 + HashSet nodesCopy = new HashSet(nodeList); + HashSet nodesToAdd = new HashSet(); // 临时列表存储要添加的节点 + + foreach (var node in nodesCopy) + { + for (int i = 0; i < 6; i++) + { + tryGetNodeForEnemy(node.unitPool[i], nodesToAdd); } } @@ -97,6 +172,46 @@ public class getNodeTools } + public static void getCircleNodeForRemoteAttack(HashSet nodeList, int range) + { + for (int i = 0; i < range; i++) + { + getNearbyNodeForRemoteAttack(nodeList); + } + } + + public static void getNearbyNodeForRemoteAttack(HashSet nodeList) + { + // 创建一个副本以避免遍历时修改原集合 + HashSet nodesCopy = new HashSet(nodeList); + HashSet nodesToAdd = new HashSet(); // 临时列表存储要添加的节点 + + foreach (var node in nodesCopy) + { + for (int i = 0; i < 6; i++) + { + tryGetNodeForRemoteAttack(node.unitPool[i], nodesToAdd); + } + } + // 遍历完成后统一修改原集合 + nodeList.AddRange(nodesToAdd); + + } + + public static bool tryGetNodeForRemoteAttack(MapUnity currentNode, HashSet results) + { + bool canPass = true; + if (currentNode == null) + { + canPass = false; + } + if (canPass) + { + results.Add(currentNode); + } + return canPass; + } + public static void checkListPass(HashSet mapUnitySet, MapUnity mapUnity) { List mapUnityList=new List(mapUnitySet); @@ -112,6 +227,21 @@ public class getNodeTools mapUnitySet.UnionWith(mapUnityList); } + public static void checkListShootPass(HashSet mapUnitySet,int range) + { + List mapUnityList = new List(mapUnitySet); + + for (int i = mapUnityList.Count - 1; i >= 0; i--) + { + if (!canRemoteAttack(mapUnityList[i],range)) + { + mapUnityList.RemoveAt(i); + } + } + mapUnitySet.Clear(); + mapUnitySet.UnionWith(mapUnityList); + } + public static bool checkNodePass(MapUnity mapUnity, MapUnity centerMapUnity) { LayerMask layerMask=new LayerMask(); @@ -127,13 +257,54 @@ public class getNodeTools { canPass = false; } - if (mapUnity.locationX==1&& mapUnity.locationY==5) + return canPass; + + } + + /*public static bool checkNodeShootPass(MapUnity mapUnity, MapUnity centerMapUnity,int range) + { + LayerMask layerMask = new LayerMask(); + int blockLayer = LayerMask.NameToLayer("Block"); + layerMask |= (1 << blockLayer); + int playerLayer = LayerMask.NameToLayer("Player"); + layerMask |= (1 << playerLayer); + bool canPass = false; + //MapUnity playerOnNode = GameManager.Instance.playerOn.transform.GetComponent(); + //var playerOnNode=GameManager.Instance.player; + float distance = Vector3.Distance(mapUnity.transform.position, centerMapUnity.transform.position); + Vector3 dir = centerMapUnity.transform.position - mapUnity.transform.position; + Ray ray = new Ray(mapUnity.transform.position, dir); + if (Physics.Raycast(ray, out RaycastHit raycastHit, 500, layerMask.value)) { - Debug.Log("距离是" + distance + ",结果是:" + canPass + ",角度是:" + dir + " " + layerMask.value + "ray是" + ray + "X是:" + mapUnity.locationX + "Y是:" + mapUnity.locationY); + if (raycastHit.collider.tag == "Player" && distance <= range + 0.5f) + { + canPass = true; + } } return canPass; - } + }*/ + + public static bool canRemoteAttack(MapUnity currentNode,int attackRange) + { + + bool canAttack = false; + bool inShootRange = false; + bool canPass = false; + HashSet shootAbleSet = new HashSet(); + shootAbleSet.Add(currentNode); + getCircleNodeForRemoteAttack(shootAbleSet,attackRange); + if (shootAbleSet.Contains(GameManager.Instance.playerOn)) + { + inShootRange = true; + } + canPass = getNodeTools.checkNodePass(currentNode, GameManager.Instance.playerOn); + if (canPass && inShootRange) + { + canAttack = true; + } + return canAttack; + } } diff --git a/ColorlessWorld-2024-4-2/Assets/Scripts/manager/DestructionManager.cs b/ColorlessWorld-2024-4-2/Assets/Scripts/manager/DestructionManager.cs index eef06f52..aae6d4c6 100644 --- a/ColorlessWorld-2024-4-2/Assets/Scripts/manager/DestructionManager.cs +++ b/ColorlessWorld-2024-4-2/Assets/Scripts/manager/DestructionManager.cs @@ -44,14 +44,12 @@ public class DestructionManager : Singleton /*transform.SetParent(originalParent); transform.localPosition = originalpoint;*/ yield return StartCoroutine(SettlementManager.Instance.settle(cardOriginalData, influencePreviewPool, cardIndex)); - Debug.Log("执行结束1"); } public IEnumerator startDestoryAndUseCard(GameObject target, CardOriginalData cardOriginalData, HashSet influencePreviewPool, int cardIndex) { yield return StartCoroutine(destoryAndUseCard(target, cardOriginalData, influencePreviewPool, cardIndex)); - Debug.Log("执行结束2"); }