|
|
|
@ -1,17 +1,22 @@ |
|
|
|
using System; |
|
|
|
using System.Collections; |
|
|
|
using System.Collections.Generic; |
|
|
|
using System.Text; |
|
|
|
using Unity.VisualScripting; |
|
|
|
using UnityEngine; |
|
|
|
using UnityEngine.EventSystems; |
|
|
|
using UnityEngine.InputSystem; |
|
|
|
using UnityEngine.UI; |
|
|
|
|
|
|
|
public class CardEntity : MonoBehaviour, IBeginDragHandler, IDragHandler, IEndDragHandler |
|
|
|
public class CardEntity : MonoBehaviour |
|
|
|
{ |
|
|
|
public CardOriginalData cardOriginalData; |
|
|
|
//public CardOriginalData cardData;
|
|
|
|
public List<MapUnity> influencePreviewPool;//卡牌的影响范围
|
|
|
|
|
|
|
|
public int cardId; |
|
|
|
|
|
|
|
public Text cost; |
|
|
|
public int CardId |
|
|
|
{ |
|
|
|
get { return cardId; } |
|
|
|
@ -20,54 +25,22 @@ public class CardEntity : MonoBehaviour, IBeginDragHandler, IDragHandler, IEndDr |
|
|
|
|
|
|
|
// public Vector3 OriginTransform;
|
|
|
|
//private Vector3 EndTransform;
|
|
|
|
[Header("拖拽参数")] |
|
|
|
public Transform originalParent; |
|
|
|
public Vector3 originalpoint; |
|
|
|
public EventSystem eventSystem; |
|
|
|
bool canUse=true;//决定卡牌是否可以释放
|
|
|
|
bool choosed;//标识卡牌是否被选中
|
|
|
|
|
|
|
|
[Header("贝塞尔曲线瞄准")] |
|
|
|
public GameObject ainPanle; |
|
|
|
|
|
|
|
[Header("影响格参数")] |
|
|
|
public MapUnity currentNode;//瞄准的格子
|
|
|
|
public List<MapUnity> influencePreviewPool;//卡牌的影响范围
|
|
|
|
|
|
|
|
|
|
|
|
public Text cardDescription; |
|
|
|
public Text cardName; |
|
|
|
|
|
|
|
public bool costEnough=true; |
|
|
|
|
|
|
|
|
|
|
|
public void Start() |
|
|
|
{ |
|
|
|
//cardData = GetComponent<CardOriginalData>();
|
|
|
|
eventSystem = GameObject.FindObjectOfType<EventSystem>(); |
|
|
|
} |
|
|
|
private void Update() |
|
|
|
{ |
|
|
|
//右键取消释放
|
|
|
|
if (choosed && Mouse.current.rightButton.wasPressedThisFrame) |
|
|
|
{ |
|
|
|
Debug.Log("1"); |
|
|
|
canUse = false;//取消释放
|
|
|
|
ainPanle.SetActive(false); |
|
|
|
//遍历范围预览池消除影响色
|
|
|
|
for (int i = 0; i < GameManager.Instance.player.influencePreviewPool.Count; i++) |
|
|
|
{ |
|
|
|
GameManager.Instance.player.influencePreviewPool[i].influenced = false; |
|
|
|
//eventSystem = GameObject.FindObjectOfType<EventSystem>();
|
|
|
|
} |
|
|
|
GameManager.Instance.player.influencePreviewPool.Clear(); |
|
|
|
//遍历影响池变色
|
|
|
|
for (int i = 0; i < influencePreviewPool.Count; i++) |
|
|
|
{ |
|
|
|
influencePreviewPool[i].influenced = false; |
|
|
|
} |
|
|
|
influencePreviewPool.Clear(); |
|
|
|
|
|
|
|
|
|
|
|
//其他位置都归位
|
|
|
|
transform.SetParent(originalParent); |
|
|
|
transform.localPosition = originalpoint; |
|
|
|
GetComponent<CanvasGroup>().blocksRaycasts = true; |
|
|
|
return; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
public void createCard(int cardId) |
|
|
|
{ |
|
|
|
@ -75,6 +48,9 @@ public class CardEntity : MonoBehaviour, IBeginDragHandler, IDragHandler, IEndDr |
|
|
|
Debug.Log(cardId + "-" + CardOriginalDataList.Instance.cardOriginalDataList[cardId]); |
|
|
|
cardOriginalData = CardOriginalDataList.Instance.cardOriginalDataList[cardId]; |
|
|
|
settleForStart(SettlementManager.settleTurn); |
|
|
|
createCardDescription(); |
|
|
|
createCardName(); |
|
|
|
createCardCost(); |
|
|
|
} |
|
|
|
|
|
|
|
//不应该为void,返回值为作用的地块
|
|
|
|
@ -114,9 +90,65 @@ public class CardEntity : MonoBehaviour, IBeginDragHandler, IDragHandler, IEndDr |
|
|
|
break; |
|
|
|
} |
|
|
|
} |
|
|
|
TurnMaster.Instance.currentCost-=cardOriginalData.Cost; |
|
|
|
|
|
|
|
} |
|
|
|
//获取卡牌名字
|
|
|
|
public void createCardName() |
|
|
|
{ |
|
|
|
cardName.text = cardOriginalData.ChineseName; |
|
|
|
} |
|
|
|
|
|
|
|
public void createCardCost() |
|
|
|
{ |
|
|
|
cost.text = cardOriginalData.Cost.ToString(); |
|
|
|
} |
|
|
|
//获取卡牌描述
|
|
|
|
public void createCardDescription() |
|
|
|
{ |
|
|
|
StringBuilder sb = new StringBuilder(); |
|
|
|
for (int i = 0; i < cardOriginalData.Function.Length; i++) |
|
|
|
{ |
|
|
|
switch (cardOriginalData.Function[i]) |
|
|
|
{ |
|
|
|
case CardFunction.cardDamage: |
|
|
|
sb.Append("造成" + cardOriginalData.FunctionVal[i]+"点伤害;"); |
|
|
|
break; |
|
|
|
case CardFunction.cardShield: |
|
|
|
sb.Append("获得" + cardOriginalData.FunctionVal[i] + "点护盾;"); |
|
|
|
break; |
|
|
|
case CardFunction.posion: |
|
|
|
sb.Append("造成" + cardOriginalData.FunctionVal[i] + "层流血;"); |
|
|
|
break; |
|
|
|
case CardFunction.weak: |
|
|
|
sb.Append("造成" + cardOriginalData.FunctionVal[i] + "层虚弱;"); |
|
|
|
break; |
|
|
|
case CardFunction.coma: |
|
|
|
sb.Append("造成" + cardOriginalData.FunctionVal[i] + "层昏迷;"); |
|
|
|
break; |
|
|
|
case CardFunction.disarm: |
|
|
|
sb.Append("造成" + cardOriginalData.FunctionVal[i] + "层缴械;"); |
|
|
|
break; |
|
|
|
case CardFunction.sleep: |
|
|
|
sb.Append("造成" + cardOriginalData.FunctionVal[i] + "层睡眠;"); |
|
|
|
break; |
|
|
|
case CardFunction.bleed: |
|
|
|
sb.Append("造成" + cardOriginalData.FunctionVal[i] + "层流血;"); |
|
|
|
break; |
|
|
|
case CardFunction.thorn: |
|
|
|
sb.Append("获得" + cardOriginalData.FunctionVal[i] + "层荆棘;"); |
|
|
|
break; |
|
|
|
case CardFunction.costRestore: |
|
|
|
sb.Append("获得" + cardOriginalData.FunctionVal[i] + "点费用;"); |
|
|
|
break; |
|
|
|
case CardFunction.dyeing: |
|
|
|
sb.Append("染色;"); |
|
|
|
break; |
|
|
|
} |
|
|
|
} |
|
|
|
cardDescription.text = sb.ToString(); |
|
|
|
} |
|
|
|
//造成异常状态
|
|
|
|
public void abnormalConditionWork(string condition, int stackVak) |
|
|
|
{ |
|
|
|
for (int i = 0; i < influencePreviewPool.Count; i++) |
|
|
|
@ -128,7 +160,7 @@ public class CardEntity : MonoBehaviour, IBeginDragHandler, IDragHandler, IEndDr |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
//造成伤害
|
|
|
|
private void damageWork(int damageVal) |
|
|
|
{ |
|
|
|
for (int i = 0; i < influencePreviewPool.Count; i++) |
|
|
|
@ -140,7 +172,7 @@ public class CardEntity : MonoBehaviour, IBeginDragHandler, IDragHandler, IEndDr |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
//染色
|
|
|
|
private void dyeingWork() |
|
|
|
{ |
|
|
|
Debug.Log(influencePreviewPool.Count); |
|
|
|
@ -150,15 +182,7 @@ public class CardEntity : MonoBehaviour, IBeginDragHandler, IDragHandler, IEndDr |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
private void dyeing() |
|
|
|
{ |
|
|
|
//遍历影响池变色
|
|
|
|
for (int i = 0; i < influencePreviewPool.Count; i++) |
|
|
|
{ |
|
|
|
influencePreviewPool[i].influenced = true; |
|
|
|
influencePreviewPool[i].choossedMark.GetComponent<Renderer>().material = influencePreviewPool[i].yellow; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//生成卡牌时候遗物的结算
|
|
|
|
@ -172,265 +196,12 @@ public class CardEntity : MonoBehaviour, IBeginDragHandler, IDragHandler, IEndDr |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
public void OnBeginDrag(PointerEventData eventData) |
|
|
|
{ |
|
|
|
// if (GameObject.Find("CardPanel") != null)
|
|
|
|
// graphicRaycaster = GameObject.Find("CardPanel").GetComponent<GraphicRaycaster>();
|
|
|
|
choosed = true; |
|
|
|
|
|
|
|
GetComponent<CanvasGroup>().blocksRaycasts = false; |
|
|
|
|
|
|
|
originalParent = this.gameObject.transform.parent; |
|
|
|
originalpoint = this.transform.localPosition; |
|
|
|
|
|
|
|
transform.SetParent(transform.parent.parent); |
|
|
|
transform.position = eventData.position; |
|
|
|
|
|
|
|
//根据卡牌数据决定是否调用曲线
|
|
|
|
if (cardOriginalData.CastingRange != 0) |
|
|
|
{ |
|
|
|
//释放范围为0则不需要调用曲线
|
|
|
|
ainPanle.SetActive(true); |
|
|
|
} |
|
|
|
else |
|
|
|
{ |
|
|
|
ainPanle.SetActive(false); |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//todo-统一确定锚点位置
|
|
|
|
|
|
|
|
//重新调用范围预览--以后要写到卡牌效果里,现在默认影响1格
|
|
|
|
//GameManager.Instance.player.StepPreviewInfluencedNode(1);
|
|
|
|
} |
|
|
|
|
|
|
|
public void OnDrag(PointerEventData eventData) |
|
|
|
{ |
|
|
|
|
|
|
|
if (cardOriginalData.CastingRange != 0) |
|
|
|
{ |
|
|
|
ainPanleWork(eventData); |
|
|
|
} |
|
|
|
else |
|
|
|
{ |
|
|
|
//没有范围不需要射线吧,因为不需要指定目标点?
|
|
|
|
// noAinPanleWork(eventData);
|
|
|
|
} |
|
|
|
dyeing(); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
private void ainPanleWork(PointerEventData eventData) |
|
|
|
{ |
|
|
|
//射线检测瞄准的地图节点,判断是否可放置和改变放置影响区
|
|
|
|
Ray ray = Camera.main.ScreenPointToRay(Mouse.current.position.value); |
|
|
|
if (eventData.pointerCurrentRaycast.gameObject != null) |
|
|
|
{ |
|
|
|
if (Physics.Raycast(ray, out RaycastHit raycastHit)) |
|
|
|
{ |
|
|
|
// Debug.Log(raycastHit.collider.gameObject.name);
|
|
|
|
//检测到跟上次瞄准地方不同,更新
|
|
|
|
if (currentNode == null || raycastHit.collider.transform.gameObject != currentNode.gameObject) |
|
|
|
{ |
|
|
|
for (int i = 0; i < influencePreviewPool.Count; i++) |
|
|
|
{ |
|
|
|
influencePreviewPool[i].influenced = false; |
|
|
|
} |
|
|
|
influencePreviewPool.Clear(); |
|
|
|
currentNode = raycastHit.collider.transform.GetComponent<MapUnity>(); |
|
|
|
|
|
|
|
//重新调用范围预览
|
|
|
|
GameManager.Instance.player.StepPreviewInfluencedNode(cardOriginalData.CastingRange); |
|
|
|
Debug.Log(cardOriginalData.CastingRange); |
|
|
|
//预览影响范围
|
|
|
|
if (currentNode.influenced) |
|
|
|
{ |
|
|
|
//根据卡牌属性改变影响池
|
|
|
|
influencePreviewPool.Add(currentNode); |
|
|
|
Vector3 face = currentNode.transform.position - GameManager.Instance.playerOn.transform.position; |
|
|
|
float euler = Vector3.SignedAngle(-GameManager.Instance.playerOn.transform.forward, face, GameManager.Instance.playerOn.transform.up) + 180; |
|
|
|
Debug.Log(euler); |
|
|
|
if (euler > 0 && euler < 45) |
|
|
|
{ |
|
|
|
if (currentNode.unitPool[0] != null) |
|
|
|
influencePreviewPool.Add(currentNode.unitPool[0]); |
|
|
|
if (currentNode.unitPool[4] != null) |
|
|
|
influencePreviewPool.Add(currentNode.unitPool[4]); |
|
|
|
} |
|
|
|
else if (euler > 45 && euler < 135) |
|
|
|
{ |
|
|
|
if (currentNode.unitPool[1] != null) |
|
|
|
influencePreviewPool.Add(currentNode.unitPool[1]); |
|
|
|
if (currentNode.unitPool[5] != null) |
|
|
|
influencePreviewPool.Add(currentNode.unitPool[5]); |
|
|
|
} |
|
|
|
else if (euler > 135 && euler < 180) |
|
|
|
{ |
|
|
|
if (currentNode.unitPool[2] != null) |
|
|
|
influencePreviewPool.Add(currentNode.unitPool[2]); |
|
|
|
if (currentNode.unitPool[0] != null) |
|
|
|
influencePreviewPool.Add(currentNode.unitPool[0]); |
|
|
|
} |
|
|
|
else if (euler > 180 && euler < 225) |
|
|
|
{ |
|
|
|
if (currentNode.unitPool[1] != null) |
|
|
|
influencePreviewPool.Add(currentNode.unitPool[1]); |
|
|
|
if (currentNode.unitPool[3] != null) |
|
|
|
influencePreviewPool.Add(currentNode.unitPool[3]); |
|
|
|
} |
|
|
|
else if (euler > 225 && euler < 315) |
|
|
|
{ |
|
|
|
if (currentNode.unitPool[2] != null) |
|
|
|
influencePreviewPool.Add(currentNode.unitPool[2]); |
|
|
|
if (currentNode.unitPool[4] != null) |
|
|
|
influencePreviewPool.Add(currentNode.unitPool[4]); |
|
|
|
} |
|
|
|
else if (euler > 315 && euler < 360) |
|
|
|
{ |
|
|
|
if (currentNode.unitPool[3] != null) |
|
|
|
influencePreviewPool.Add(currentNode.unitPool[3]); |
|
|
|
if (currentNode.unitPool[5] != null) |
|
|
|
influencePreviewPool.Add(currentNode.unitPool[5]); |
|
|
|
} |
|
|
|
//influencePreviewPool.Add(currentNode);
|
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
Debug.Log("结束影响数值" + influencePreviewPool.Count); |
|
|
|
} |
|
|
|
|
|
|
|
private void noAinPanleWork(PointerEventData eventData) |
|
|
|
{ |
|
|
|
|
|
|
|
Ray ray = Camera.main.ScreenPointToRay(Mouse.current.position.value); |
|
|
|
if (eventData.pointerCurrentRaycast.gameObject != null) |
|
|
|
{ |
|
|
|
if (Physics.Raycast(ray, out RaycastHit raycastHit)) |
|
|
|
{ |
|
|
|
currentNode = raycastHit.collider.transform.GetComponent<MapUnity>(); |
|
|
|
influencePreviewPool.Add(currentNode); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
public void OnEndDrag(PointerEventData eventData) |
|
|
|
{ |
|
|
|
choosed = false; |
|
|
|
if(canUse ) |
|
|
|
{ |
|
|
|
Debug.Log("进入影响数值" + influencePreviewPool.Count); |
|
|
|
if (eventData.pointerCurrentRaycast.gameObject != null) |
|
|
|
{ |
|
|
|
if (eventData.pointerCurrentRaycast.gameObject.name == "Card") |
|
|
|
{ |
|
|
|
transform.SetParent(eventData.pointerCurrentRaycast.gameObject.transform.parent); |
|
|
|
transform.position = eventData.pointerCurrentRaycast.gameObject.transform.position; |
|
|
|
eventData.pointerCurrentRaycast.gameObject.transform.position = originalParent.position; |
|
|
|
eventData.pointerCurrentRaycast.gameObject.transform.SetParent(originalParent); |
|
|
|
|
|
|
|
GetComponent<CanvasGroup>().blocksRaycasts = true; |
|
|
|
|
|
|
|
ainPanle.SetActive(false);//关闭贝塞尔曲线
|
|
|
|
//遍历范围预览池消除影响色
|
|
|
|
for (int i = 0; i < GameManager.Instance.player.influencePreviewPool.Count; i++) |
|
|
|
{ |
|
|
|
GameManager.Instance.player.influencePreviewPool[i].influenced = false; |
|
|
|
} |
|
|
|
//GameManager.Instance.player.influencePreviewPool.Clear();
|
|
|
|
|
|
|
|
return; |
|
|
|
} |
|
|
|
else if (eventData.pointerCurrentRaycast.gameObject.name == "cardSlot") |
|
|
|
{ |
|
|
|
transform.SetParent(eventData.pointerCurrentRaycast.gameObject.transform); |
|
|
|
transform.position = eventData.pointerCurrentRaycast.gameObject.transform.position; |
|
|
|
GetComponent<CanvasGroup>().blocksRaycasts = true; |
|
|
|
|
|
|
|
ainPanle.SetActive(false);//关闭贝塞尔曲线
|
|
|
|
//遍历范围预览池消除影响色
|
|
|
|
for (int i = 0; i < GameManager.Instance.player.influencePreviewPool.Count; i++) |
|
|
|
{ |
|
|
|
GameManager.Instance.player.influencePreviewPool[i].influenced = false; |
|
|
|
} |
|
|
|
//GameManager.Instance.player.influencePreviewPool.Clear();
|
|
|
|
|
|
|
|
return; |
|
|
|
} |
|
|
|
} |
|
|
|
if (ainPanle.activeSelf) |
|
|
|
{ |
|
|
|
ainPanle.SetActive(false);//关闭贝塞尔曲线
|
|
|
|
} |
|
|
|
|
|
|
|
//先判断该卡牌的类型是否是需要范围
|
|
|
|
if (cardOriginalData.CastingRange != 0) |
|
|
|
{ |
|
|
|
//检测碰撞的地图节点是否被影响(可释放)
|
|
|
|
if (currentNode == null || currentNode.influenced == false) |
|
|
|
{ |
|
|
|
//遍历范围预览池消除影响色(红色,卡牌的释放范围)
|
|
|
|
for (int i = 0; i < GameManager.Instance.player.influencePreviewPool.Count; i++) |
|
|
|
{ |
|
|
|
GameManager.Instance.player.influencePreviewPool[i].influenced = false; |
|
|
|
} |
|
|
|
//GameManager.Instance.player.influencePreviewPool.Clear();
|
|
|
|
} |
|
|
|
else if (currentNode.influenced) |
|
|
|
{ |
|
|
|
|
|
|
|
//卡牌释放效果
|
|
|
|
use(); |
|
|
|
Debug.Log("玩家盾量:" + Usermanager.Instance.Shield); |
|
|
|
|
|
|
|
//临时效果--将其加入墓地并销毁实体
|
|
|
|
TurnMaster.Instance.usedCard.usedCardList.Add(this.gameObject.GetComponent<CardEntity>().CardId); |
|
|
|
Destroy(this.gameObject); |
|
|
|
} |
|
|
|
//遍历范围预览池消除影响色
|
|
|
|
for (int i = 0; i < GameManager.Instance.player.influencePreviewPool.Count; i++) |
|
|
|
{ |
|
|
|
GameManager.Instance.player.influencePreviewPool[i].influenced = false; |
|
|
|
} |
|
|
|
GameManager.Instance.player.influencePreviewPool.Clear(); |
|
|
|
//遍历影响池变色
|
|
|
|
for (int i = 0; i < influencePreviewPool.Count; i++) |
|
|
|
{ |
|
|
|
influencePreviewPool[i].influenced = false; |
|
|
|
} |
|
|
|
influencePreviewPool.Clear(); |
|
|
|
GetComponent<CanvasGroup>().blocksRaycasts = true; |
|
|
|
|
|
|
|
//其他位置都归位
|
|
|
|
transform.SetParent(originalParent); |
|
|
|
transform.localPosition = originalpoint; |
|
|
|
return; |
|
|
|
}//范围类,需要指定被影响的节点才能释放
|
|
|
|
else |
|
|
|
{ |
|
|
|
//卡牌释放效果
|
|
|
|
use(); |
|
|
|
Debug.Log("玩家盾量:" + Usermanager.Instance.Shield); |
|
|
|
|
|
|
|
//临时效果--将其加入墓地并销毁实体
|
|
|
|
TurnMaster.Instance.usedCard.usedCardList.Add(this.gameObject.GetComponent<CardEntity>().CardId); |
|
|
|
Destroy(this.gameObject); |
|
|
|
|
|
|
|
return; |
|
|
|
|
|
|
|
}//无范围类,直接释放
|
|
|
|
|
|
|
|
} |
|
|
|
else |
|
|
|
{ |
|
|
|
canUse = true; |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|