Browse Source

怪物逻辑重做合并

pull/19/head
yjm484 2 years ago
parent
commit
edf0b42107
  1. 4
      ColorlessWorld-2024-4-2/Assets/GameDate/Enemy/SkeletonArcher.asset
  2. 4
      ColorlessWorld-2024-4-2/Assets/Scenes/SampleScene.unity
  3. 1
      ColorlessWorld-2024-4-2/Assets/Scripts/Card/CardOriginalDataList.cs
  4. 5
      ColorlessWorld-2024-4-2/Assets/Scripts/Card/TurnMaster.cs
  5. 136
      ColorlessWorld-2024-4-2/Assets/Scripts/Enemy/EnemyNode.cs
  6. 86
      ColorlessWorld-2024-4-2/Assets/Scripts/Enemy/SkeletonArcher.cs
  7. 84
      ColorlessWorld-2024-4-2/Assets/Scripts/Enemy/SkullGuardian.cs
  8. 65
      ColorlessWorld-2024-4-2/Assets/Scripts/Tool/AStar/AStarManager.cs
  9. 5
      ColorlessWorld-2024-4-2/Assets/Scripts/Tool/Data_SO/EnemyState_SO.cs
  10. 182
      ColorlessWorld-2024-4-2/Assets/Scripts/Tool/getNodeTools.cs
  11. 2
      ColorlessWorld-2024-4-2/Assets/Scripts/manager/DestructionManager.cs

4
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

4
ColorlessWorld-2024-4-2/Assets/Scenes/SampleScene.unity

@ -17624,8 +17624,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

1
ColorlessWorld-2024-4-2/Assets/Scripts/Card/CardOriginalDataList.cs

@ -62,7 +62,6 @@ public class CardOriginalDataList : Singleton<CardOriginalDataList>
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(";");

5
ColorlessWorld-2024-4-2/Assets/Scripts/Card/TurnMaster.cs

@ -173,9 +173,7 @@ public class TurnMaster : Singleton<TurnMaster>
var card = handCard.cardSlotList[cardIndex].transform.GetChild(0).gameObject;
TurnMaster.Instance.usedCard.usedCardList.Add(card.GetComponent<CardEntity>().CardId);
bool a = card == null;
Debug.Log(a);
Destroy(card);
Debug.Log("结束了");
}
}
@ -183,9 +181,6 @@ public class TurnMaster : Singleton<TurnMaster>
{
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++)
{

136
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<MapUnity> shootAbleMapUnity = new HashSet<MapUnity>();
HashSet<MapUnity> reachAbleMapUnity = new HashSet<MapUnity>();
HashSet<MapUnity> endNodeMapUnityList = new HashSet<MapUnity>();
Dictionary<MapUnity,int> endNodeMapUnityMap = new Dictionary<MapUnity, int>();
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<MapUnity> 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<MapUnity> nearestMapUnity = new HashSet<MapUnity>();
HashSet<MapUnity> endNodeMapUnityList = new HashSet<MapUnity>();
Dictionary<MapUnity, int> endNodeMapUnityMap = new Dictionary<MapUnity, int>();
endNodeMapUnityList.Add(GameManager.Instance.playerOn);
getNodeTools.getArcNode(endNodeMapUnityList, EnemyState.attackRange);
getNodeTools.exceptWithEnemyNode(endNodeMapUnityList);
foreach (MapUnity mapUnity in endNodeMapUnityList)
{
try
{
List<MapUnity> 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<MapUnity> GetKeysWithMinValue(Dictionary<MapUnity, int> map)
{
if (map == null || map.Count == 0)
{
return new List<MapUnity>();
}
int minValue = map.Values.Min();
List<MapUnity> 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.FindPath(currentNode, GameManager.Instance.playerOn);
pasth = AStarManager.Instance.FindPathWithEndNode(currentNode, getEndNodeTowardsPlayer());
}
public void FindPathAwayFromPlayer()
{
MapUnity currentNode = GameManager.Instance.X[positionX].Y[positionY];
pasth.Clear();
pasth = AStarManager.Instance.FindPathWithEndNode(currentNode, getEndNodeAwayFromPlayer());
}
public void Move(MapUnity currentNode , int step)
{

86
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,57 +96,51 @@ public class SkeletonArcher : MonoBehaviour
IEnumerator JudgeActionCoroutine()//等移动到位置就判断是否还能走
{
yield return StartCoroutine(RemoteAttackAction());
for (int i = 0; i < enemyNode.EnemyState.stepRange * enemyNode.EnemyState.stepRangeMultiplier; i++)
{
}
Debug.Log(enemyNode.pasth.Count);
if (enemyNode.pasth.Count > enemyNode.EnemyState .attackRange )
IEnumerator moveTowardsPlayer()
{
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)
enemyNode.FindPathTowardsPlayer();
for (int i = 1; i < getMoveStep(); i++)
{
/* 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 (enemyNode.pasth.Count > 1)
{
if(raycastHit .collider .tag != "Player")
yield return StartCoroutine(moveOneStep(enemyNode.pasth[i]));
}
}
}
IEnumerator moveAwayFromPlayer()
{
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)
enemyNode.FindPathAwayFromPlayer();
for (int i = 1; i < getMoveStep(); i++)
{
}
else
if (enemyNode.pasth.Count > 1)
{
yield return StartCoroutine(moveOneStep(enemyNode.pasth[i]));
}
}
}
*/
SkeletonArcherAction();
yield break;
private int getMoveStep()
{
if(enemyNode.EnemyState.getStepRange() + 1<= enemyNode.pasth.Count)
{
return enemyNode.EnemyState.getStepRange() + 1;
}
else
{
//·´ÏòÔ˶¯
MapUnity currentNode = enemyNode.pasth[0];
enemyNode.oppositePasth.Clear();
enemyNode.oppositePasth = AStarManager.Instance.FindOppositePath(currentNode, GameManager.Instance.playerOn, enemyNode.EnemyState.stepRange);
return enemyNode.pasth.Count;
}
}
if(enemyNode . oppositePasth.Count >1)
IEnumerator moveOneStep(MapUnity nexMapUnity)
{
MapUnity disNode = enemyNode.oppositePasth[1];
MapUnity currentNode = GameManager.Instance.X[enemyNode.positionX].Y[enemyNode.positionY];
MapUnity disNode = nexMapUnity;
currentNode.blocked = false;
currentNode.enemyNode = null;
enemyNode.positionX = disNode.locationX;
@ -155,11 +149,19 @@ public class SkeletonArcher : MonoBehaviour
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 new WaitForSeconds(1);
yield return StartCoroutine(moveAwayFromPlayer());
}
else
{
yield return StartCoroutine(moveTowardsPlayer());
}
SkeletonArcherAction();
}
IEnumerator JudgNextActionCoroutine()
@ -167,8 +169,6 @@ public class SkeletonArcher : MonoBehaviour
yield return StartCoroutine(JudgeActionCoroutine());
//下回合意图
ArcherAim();
enemyNode.SettlementSkill();
NextTurnIntention();
//让下一个敌人运动
EnemyManager.Instance.enemyTurnState = EnemyManager.EnemyTurnState.runing;
@ -190,6 +190,8 @@ public class SkeletonArcher : MonoBehaviour
}
public void SkeletonArcherAction()
{
float distance = Vector3.Distance(this.transform.position, GameManager.Instance.player.transform.position);

84
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,71 @@ public class SkullGuardian : MonoBehaviour
}
IEnumerator JudgeActionCoroutine()//等移动到位置就判断是否还能走
{
for(int i = 0;i< enemyNode .EnemyState .stepRange * enemyNode.EnemyState.stepRangeMultiplier;i++)
yield return StartCoroutine(MeleeAttackAction());
}
IEnumerator JudgNextActionCoroutine()
{
enemyNode.FindPath();
if (enemyNode.pasth.Count > 1)
yield return StartCoroutine(JudgeActionCoroutine());
//下回合意图
//让下一个敌人运动
EnemyManager.Instance.enemyTurnState = EnemyManager.EnemyTurnState.runing;
Debug.Log(1);
}
IEnumerator MeleeAttackAction()
{
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));
MapUnity currentNode = GameManager.Instance.X[enemyNode.positionX].Y[enemyNode.positionY];
if (getNodeTools.canRemoteAttack(currentNode, enemyNode.EnemyState.attackRange))
{
AttackDamage();
}
else if(enemyNode.pasth.Count == 1&& enemyNode.planAction == EnemyNode.PlanAction.attack )
else
{
SkullGuardianAction();
yield break;
yield return StartCoroutine(moveTowardsPlayer());
yield return new WaitForSeconds(1);
currentNode = GameManager.Instance.X[enemyNode.positionX].Y[enemyNode.positionY];
if (getNodeTools.canRemoteAttack(currentNode, enemyNode.EnemyState.attackRange))
{
AttackDamage();
}
}
}
if (enemyNode.planAction == EnemyNode.PlanAction.sheield)
IEnumerator moveTowardsPlayer()
{
enemyNode.FindPathTowardsPlayer();
for (int i = 1; i < getMoveStep(); i++)
{
if (enemyNode.pasth.Count > 1)
{
yield return StartCoroutine(moveOneStep(enemyNode.pasth[i]));
}
}
}
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 )//移动到位置
{

65
ColorlessWorld-2024-4-2/Assets/Scripts/Tool/AStar/AStarManager.cs

@ -75,6 +75,71 @@ public class AStarManager : Singleton<AStarManager>
}
}
public List<MapUnity> 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<MapUnity> path = new List<MapUnity>();
path.Add(endNode);
while (endNode.aStarNode.fatherNode != null)
{
path.Add(endNode.aStarNode.fatherNode);
endNode = endNode.aStarNode.fatherNode;
}
//列表反置
path.Reverse();
return path;
}
}
}
public List<MapUnity> FindOppositePath(MapUnity starNode, MapUnity endNode ,int step)
{
//判断传入的点是否合法

5
ColorlessWorld-2024-4-2/Assets/Scripts/Tool/Data_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);
}
}

182
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<MapUnity> results)
public static bool tryGetNodeFroPlayer(MapUnity currentNode, HashSet<MapUnity> results)
{
bool canPass = true;
if (currentNode == null)
@ -71,6 +71,30 @@ public class getNodeTools
return canPass;
}
public static bool tryGetNodeForEnemy(MapUnity currentNode, HashSet<MapUnity> results)
{
bool canPass = true;
if (currentNode == null)
{
canPass = false;
return canPass;
}
/*if (currentNode.TryGetComponent<EnemyNode>(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<MapUnity> nodeList,int range)
{
for (int i = 0;i < range;i++)
@ -78,6 +102,38 @@ public class getNodeTools
getNearbyNode(nodeList);
}
}
public static void getCircleNodeForEnemy(HashSet<MapUnity> nodeList, int range)
{
for (int i = 0; i < range; i++)
{
getNearbyNodeFroEnemy(nodeList);
}
}
public static void exceptWithEnemyNode(HashSet<MapUnity> nodeList)
{
List<MapUnity> mapUnityList = new List<MapUnity>(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<MapUnity> nodeList, int range)
{
HashSet<MapUnity> smallCircleNodeSet=new HashSet<MapUnity>(nodeList);
getCircleNodeForEnemy(smallCircleNodeSet, range-1);
getCircleNodeForEnemy(nodeList, range);
nodeList.ExceptWith(smallCircleNodeSet);
}
public static void getNearbyNode(HashSet<MapUnity> nodeList)
{
// 创建一个副本以避免遍历时修改原集合
@ -88,15 +144,74 @@ 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<MapUnity> nodeList)
{
// 创建一个副本以避免遍历时修改原集合
HashSet<MapUnity> nodesCopy = new HashSet<MapUnity>(nodeList);
HashSet<MapUnity> nodesToAdd = new HashSet<MapUnity>(); // 临时列表存储要添加的节点
foreach (var node in nodesCopy)
{
for (int i = 0; i < 6; i++)
{
tryGetNodeForEnemy(node.unitPool[i], nodesToAdd);
}
}
// 遍历完成后统一修改原集合
nodeList.AddRange(nodesToAdd);
}
public static void getCircleNodeForRemoteAttack(HashSet<MapUnity> nodeList, int range)
{
for (int i = 0; i < range; i++)
{
getNearbyNodeForRemoteAttack(nodeList);
}
}
public static void getNearbyNodeForRemoteAttack(HashSet<MapUnity> nodeList)
{
// 创建一个副本以避免遍历时修改原集合
HashSet<MapUnity> nodesCopy = new HashSet<MapUnity>(nodeList);
HashSet<MapUnity> nodesToAdd = new HashSet<MapUnity>(); // 临时列表存储要添加的节点
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<MapUnity> results)
{
bool canPass = true;
if (currentNode == null)
{
canPass = false;
}
if (canPass)
{
results.Add(currentNode);
}
return canPass;
}
public static void checkListPass(HashSet<MapUnity> mapUnitySet, MapUnity mapUnity)
{
List<MapUnity> mapUnityList=new List<MapUnity>(mapUnitySet);
@ -112,6 +227,21 @@ public class getNodeTools
mapUnitySet.UnionWith(mapUnityList);
}
public static void checkListShootPass(HashSet<MapUnity> mapUnitySet,int range)
{
List<MapUnity> mapUnityList = new List<MapUnity>(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();
@ -145,11 +275,55 @@ public class getNodeTools
}
}
// Debug.Log("距离是" + distance + ",结果是:" + canPass + ",角度是:" + dir + " " + layerMask.value + "ray是" + ray + "X是:" + mapUnity.locationX + "Y是:" + mapUnity.locationY);
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<MapUnity>();
//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))
{
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<MapUnity> shootAbleSet = new HashSet<MapUnity>();
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;
}
}

2
ColorlessWorld-2024-4-2/Assets/Scripts/manager/DestructionManager.cs

@ -44,14 +44,12 @@ public class DestructionManager : Singleton<DestructionManager>
/*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<MapUnity> influencePreviewPool, int cardIndex)
{
yield return StartCoroutine(destoryAndUseCard(target, cardOriginalData, influencePreviewPool, cardIndex));
Debug.Log("执行结束2");
}

Loading…
Cancel
Save