|
|
@ -1,7 +1,11 @@ |
|
|
|
|
|
using System; |
|
|
using System.Collections; |
|
|
using System.Collections; |
|
|
using System.Collections.Generic; |
|
|
using System.Collections.Generic; |
|
|
|
|
|
using System.Text.RegularExpressions; |
|
|
using UnityEngine; |
|
|
using UnityEngine; |
|
|
using UnityEngine.EventSystems; |
|
|
using UnityEngine.EventSystems; |
|
|
|
|
|
using static UnityEngine.InputSystem.InputControlScheme.MatchResult; |
|
|
|
|
|
using Match = System.Text.RegularExpressions.Match; |
|
|
|
|
|
|
|
|
public class WeaponNode : MonoBehaviour,IDragHandler, IBeginDragHandler, IEndDragHandler |
|
|
public class WeaponNode : MonoBehaviour,IDragHandler, IBeginDragHandler, IEndDragHandler |
|
|
{ |
|
|
{ |
|
|
@ -13,14 +17,260 @@ public class WeaponNode : MonoBehaviour,IDragHandler, IBeginDragHandler, IEndDra |
|
|
Vector3 mousePositionOnScreen;//获取到点击屏幕的屏幕坐标
|
|
|
Vector3 mousePositionOnScreen;//获取到点击屏幕的屏幕坐标
|
|
|
Vector3 mousePositionInWorld;//将点击屏幕的屏幕坐标转换为世界坐标
|
|
|
Vector3 mousePositionInWorld;//将点击屏幕的屏幕坐标转换为世界坐标
|
|
|
|
|
|
|
|
|
|
|
|
public string condition; |
|
|
|
|
|
public string result; |
|
|
|
|
|
public string[] nodesMark; |
|
|
|
|
|
public string[] nodesColor; |
|
|
|
|
|
|
|
|
private void Update() |
|
|
private void Update() |
|
|
{ |
|
|
{ |
|
|
SettleScore(); |
|
|
//SettleScore();
|
|
|
|
|
|
} |
|
|
|
|
|
public virtual void SettleWeaponNode(int position) |
|
|
|
|
|
{ |
|
|
|
|
|
Debug.Log("结算成功节点1"); |
|
|
|
|
|
if (ConditionCheck(position)) |
|
|
|
|
|
{ |
|
|
|
|
|
Debug.Log("结算成功节点2"); |
|
|
|
|
|
SettleFunction(position, result); |
|
|
|
|
|
} |
|
|
|
|
|
else |
|
|
|
|
|
{ |
|
|
|
|
|
score = 0; |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
public virtual void SettleFunction(int position,string result) |
|
|
|
|
|
{ |
|
|
|
|
|
Debug.Log("结算成功节点3"); |
|
|
|
|
|
string[] keys = result.Split("_"); |
|
|
|
|
|
for (int j = 0; j < keys.Length; j++) |
|
|
|
|
|
{ |
|
|
|
|
|
|
|
|
|
|
|
SingleFunctionSettle(keys[j]); |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
public virtual bool ConditionCheck(int position) |
|
|
|
|
|
{ |
|
|
|
|
|
bool result = true; |
|
|
|
|
|
string[] keys = condition.Split("_"); |
|
|
|
|
|
List<bool> matchList = new List<bool>(); |
|
|
|
|
|
for (int j = 0; j < keys.Length; j++) |
|
|
|
|
|
{ |
|
|
|
|
|
|
|
|
|
|
|
if (keys[j].Equals(Name.Condition.None)) |
|
|
|
|
|
{ |
|
|
|
|
|
//cardFunToLose.Remove(keys[j]);
|
|
|
|
|
|
matchList.Add(true); |
|
|
|
|
|
} |
|
|
|
|
|
else |
|
|
|
|
|
{ |
|
|
|
|
|
matchList.Add(SingleConditionCheck(keys[j])); |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
for (int k = 0; k < matchList.Count; k++) |
|
|
|
|
|
{ |
|
|
|
|
|
Debug.Log("matchList是" + matchList[k]); |
|
|
|
|
|
if (!matchList[k]) |
|
|
|
|
|
{ |
|
|
|
|
|
result = false; |
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
return result; |
|
|
|
|
|
} |
|
|
|
|
|
public void SingleFunctionSettle(string result) |
|
|
|
|
|
{ |
|
|
|
|
|
//Debug.Log("结算成功节点4");
|
|
|
|
|
|
Match match = Regex.Match(result, Name.Regex.cardConditionPattern); |
|
|
|
|
|
if (match.Success) |
|
|
|
|
|
{ |
|
|
|
|
|
string firstPart = match.Groups[1].Value; // 第一部分
|
|
|
|
|
|
string op = match.Groups[2].Value; // 运算符部分
|
|
|
|
|
|
string secondPart = match.Groups[3].Value; // 第二部分
|
|
|
|
|
|
//Debug.Log("结算成功节点10:" + secondPart);
|
|
|
|
|
|
if (firstPart.Equals(Name.WeaponNodeFunction.score)) |
|
|
|
|
|
{ |
|
|
|
|
|
//Debug.Log("结算成功节点5");
|
|
|
|
|
|
score =int.Parse(secondPart); |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
else |
|
|
|
|
|
//不需要运算符号的结算
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
public bool SingleConditionCheck(string condition) |
|
|
|
|
|
{ |
|
|
|
|
|
bool check = false; |
|
|
|
|
|
//cardOriginalData.originFunctionVal.Clear();
|
|
|
|
|
|
//Debug.Log("外面condition是" + kvp.Key);
|
|
|
|
|
|
Match match = Regex.Match(condition, Name.Regex.cardConditionPattern); |
|
|
|
|
|
if (match.Success) |
|
|
|
|
|
{ |
|
|
|
|
|
Debug.Log("结算成功节点6"); |
|
|
|
|
|
string firstPart = match.Groups[1].Value; // 第一部分
|
|
|
|
|
|
string op = match.Groups[2].Value; // 运算符部分
|
|
|
|
|
|
string secondPart = match.Groups[3].Value; // 第二部分
|
|
|
|
|
|
int firstPartCount = CardManager.Instance.evaluateExpression(firstPart); |
|
|
|
|
|
int secondPartCount = CardManager.Instance.evaluateExpression(secondPart); |
|
|
|
|
|
int thresholdShift = 0; |
|
|
|
|
|
Debug.Log("结算成功节点8:"+firstPart + op + secondPart); |
|
|
|
|
|
Debug.Log("结算成功节点9:" + firstPartCount + op + secondPartCount); |
|
|
|
|
|
if (performComparison(firstPartCount, op, secondPartCount, thresholdShift)) |
|
|
|
|
|
{ |
|
|
|
|
|
Debug.Log("结算成功节点7"); |
|
|
|
|
|
check = true; |
|
|
|
|
|
} |
|
|
|
|
|
else |
|
|
|
|
|
{ |
|
|
|
|
|
//MathTool.AddOrUpdateDictionary(cardFunToLose, kvp.Value.Item1, kvp.Value.Item2);
|
|
|
|
|
|
/*Image condition = conditionList[conditionListindex].GetComponent<Image>(); |
|
|
|
|
|
|
|
|
|
|
|
cardFunToLose.TryAdd(conditon, tuple);*/ |
|
|
|
|
|
//MathTool.SubtractOrUpdateDictionary(cardOriginalData.originFunctionVal, kvp.Value.Item1, kvp.Value.Item2);
|
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
else if (condition.Equals(Name.Condition.Node)) |
|
|
|
|
|
{ |
|
|
|
|
|
check = checkConditionNode(nodesMark, nodesColor); |
|
|
} |
|
|
} |
|
|
public virtual void SettleScore() |
|
|
return check; |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
public bool checkConditionNode(string[] nodesMark, string[] nodesColor) |
|
|
|
|
|
{ |
|
|
|
|
|
bool result = false; |
|
|
|
|
|
if (basicCheck(nodesColor)) |
|
|
|
|
|
{ |
|
|
|
|
|
if (primeCheck(nodesMark, nodesColor)) |
|
|
|
|
|
{ |
|
|
|
|
|
result = true; |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
else |
|
|
|
|
|
{ |
|
|
|
|
|
return result; |
|
|
|
|
|
} |
|
|
|
|
|
return result; |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
public bool primeCheck(string[] nodesMark, string[] nodesColor) |
|
|
|
|
|
{ |
|
|
|
|
|
bool result = false; |
|
|
|
|
|
bool haveOrigin=false; |
|
|
|
|
|
HashSet <MapUnity> targetNodes= new HashSet <MapUnity>(); |
|
|
|
|
|
for (int i = 0; i < nodesMark.Length; i++) |
|
|
{ |
|
|
{ |
|
|
score =2; |
|
|
if (nodesMark[i].Equals("0_0")) |
|
|
|
|
|
{ |
|
|
|
|
|
Debug.Log("haveOrigin"); |
|
|
|
|
|
haveOrigin= true; |
|
|
|
|
|
targetNodes =getNodeTools.getNodesWithColor(nodesColor[i]); |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
if (!haveOrigin) |
|
|
|
|
|
{ |
|
|
|
|
|
targetNodes = getNodeTools.getAllNodes(); |
|
|
|
|
|
} |
|
|
|
|
|
string nodesMarkCsv = string.Join(",", nodesMark); |
|
|
|
|
|
string nodesColorCsv = string.Join(",", nodesColor); |
|
|
|
|
|
char[] buffer = new char[nodesMarkCsv.Length + nodesColorCsv.Length]; |
|
|
|
|
|
nodesMarkCsv.CopyTo(0, buffer, 0, nodesMarkCsv.Length); |
|
|
|
|
|
nodesColorCsv.CopyTo(0, buffer, nodesMarkCsv.Length, nodesColorCsv.Length); |
|
|
|
|
|
string onlyTapForWeaponNode = new string(buffer); |
|
|
|
|
|
Debug.Log("onlyTapForWeaponNode是" + onlyTapForWeaponNode); |
|
|
|
|
|
foreach (MapUnity mapUnity in targetNodes) |
|
|
|
|
|
{ |
|
|
|
|
|
if (mapUnity.isCaledDictionary.TryGetValue(onlyTapForWeaponNode, out bool isChecked)) |
|
|
|
|
|
{ |
|
|
|
|
|
Debug.Log("isChecked是"+ isChecked+"x是"+mapUnity.locationX+"y是"+mapUnity.locationY); |
|
|
|
|
|
if (!isChecked) |
|
|
|
|
|
{ |
|
|
|
|
|
Debug.Log("false进行check"); |
|
|
|
|
|
mapUnity.isCaledDictionary[onlyTapForWeaponNode] = true; |
|
|
|
|
|
if (getNodeTools.CheckWeaponConditionColorForSingleNode(nodesMark, nodesColor, mapUnity, onlyTapForWeaponNode)) |
|
|
|
|
|
{ |
|
|
|
|
|
Debug.Log("check成功"); |
|
|
|
|
|
result = true; |
|
|
|
|
|
mapUnity.isCaledDictionary[onlyTapForWeaponNode]=false; |
|
|
|
|
|
return result; |
|
|
} |
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
else |
|
|
|
|
|
{ |
|
|
|
|
|
Debug.Log("add了true"); |
|
|
|
|
|
mapUnity.isCaledDictionary[onlyTapForWeaponNode]=true; |
|
|
|
|
|
if (getNodeTools.CheckWeaponConditionColorForSingleNode(nodesMark, nodesColor, mapUnity, onlyTapForWeaponNode)) |
|
|
|
|
|
{ |
|
|
|
|
|
result = true; |
|
|
|
|
|
return result; |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
|
|
|
return result; |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
public bool basicCheck(string[] nodesColor) |
|
|
|
|
|
{ |
|
|
|
|
|
bool result = false; |
|
|
|
|
|
int redNodeCount = 0; |
|
|
|
|
|
int blueNodeCount = 0; |
|
|
|
|
|
int greenNodeCount = 0; |
|
|
|
|
|
int whiteNodeCount = 0; |
|
|
|
|
|
int blackNodeCount = 0; |
|
|
|
|
|
int yellowNodeCount = 0; |
|
|
|
|
|
for (int i = 0; i < nodesColor.Length; i++) |
|
|
|
|
|
{ |
|
|
|
|
|
switch (nodesColor[i]) |
|
|
|
|
|
{ |
|
|
|
|
|
case Name.Color.White: |
|
|
|
|
|
whiteNodeCount++; |
|
|
|
|
|
break; |
|
|
|
|
|
case Name.Color.Red: |
|
|
|
|
|
redNodeCount++; |
|
|
|
|
|
break; |
|
|
|
|
|
case Name.Color.Black: |
|
|
|
|
|
blackNodeCount++; |
|
|
|
|
|
break; |
|
|
|
|
|
case Name.Color.Yellow: |
|
|
|
|
|
yellowNodeCount++; |
|
|
|
|
|
break; |
|
|
|
|
|
case Name.Color.Blue: |
|
|
|
|
|
blueNodeCount++; |
|
|
|
|
|
break; |
|
|
|
|
|
case Name.Color.Green: |
|
|
|
|
|
greenNodeCount++; |
|
|
|
|
|
break; |
|
|
|
|
|
} |
|
|
|
|
|
if(whiteNodeCount>MapUnityManager.Instance.whiteNodeCount|| redNodeCount > MapUnityManager.Instance.redNodeCount || blackNodeCount > MapUnityManager.Instance.blackNodeCount || yellowNodeCount > MapUnityManager.Instance.yellowNodeCount || blueNodeCount > MapUnityManager.Instance.blueNodeCount|| greenNodeCount > MapUnityManager.Instance.greenNodeCount) |
|
|
|
|
|
{ |
|
|
|
|
|
return result; |
|
|
|
|
|
} |
|
|
|
|
|
else |
|
|
|
|
|
{ |
|
|
|
|
|
result = true; |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
return result; |
|
|
|
|
|
} |
|
|
|
|
|
private bool performComparison(int colorValue, string op, int number, int thresholdShift) |
|
|
|
|
|
{ |
|
|
|
|
|
return op switch |
|
|
|
|
|
{ |
|
|
|
|
|
">" => colorValue > number - thresholdShift, |
|
|
|
|
|
"<" => colorValue < number + thresholdShift, |
|
|
|
|
|
"=" => colorValue == number, |
|
|
|
|
|
_ => false |
|
|
|
|
|
}; |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public void OnBeginDrag(PointerEventData eventData) |
|
|
public void OnBeginDrag(PointerEventData eventData) |
|
|
{ |
|
|
{ |
|
|
|