_xiaofang/xiaofang/Assets/Script/UI/ZZZZZZ/ZZZPlayer.cs

220 lines
6.3 KiB
C#
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

using System.Collections;
using System.Collections.Generic;
using Unity.VisualScripting;
using UnityEngine;
public class ZZZPlayer : MonoBehaviour
{
public static ZZZPlayer CSZS;
public JSONReader jSONReader;
public Dictionary<int, string> CSB1 = new Dictionary<int, string>(); //Key是判断是不是一组string是ID tanchuang1用的
public bool isYou=true;
public void Start()
{
// SetPlayerID("11007");
FindPlayerTaskID(10810, "tanchuang1");
////遍历字典
//foreach (KeyValuePair<string, List<string>> kvp in PlayerID)
//{
// Debug.Log($"职业: {kvp.Key}");
// // 遍历值List<string>
// foreach (string task in kvp.Value)
// {
// Debug.Log($"任务: {task}");
// }
//}
}
public Dictionary<string, List<string>> PlayerID = new Dictionary<string, List<string>>()
{
{ "8000", new List<string>() },
{ "8001", new List<string>() },
{ "8002", new List<string>() },
{ "8003", new List<string>() },
{ "8004", new List<string>() },
{ "8005", new List<string>() },
{ "8006", new List<string>() },
{ "8007", new List<string>() },
{ "8008", new List<string>() },
{ "8009", new List<string>() },
{ "8010", new List<string>() },
{ "8011", new List<string>() }
};
private void Awake()
{
CSZS = this;
}
/// <summary>
/// 接收玩家接受的任务
/// </summary>
public void SetPlayerID(string TaskID)
{
var a=ParseString(jSONReader.GetOcpID(int.Parse(TaskID)));
for (int i=0;i<a.Count;i++)
{
PlayerID[a[i]].Add(TaskID);
}
}
/// <summary>
/// 返回一个职业接取的任务
/// </summary>
public List<string> GetPlayerID(string ID)
{
if (PlayerID.TryGetValue(ID, out List<string> value))
{
return value; // 返回对应的 List<string>
}
else
{
Debug.Log("颠仔找不到");
return new List<string>(); // 返回空列表
}
}
/// <summary>
/// 判断那些角色可以接取任务
/// </summary>
/// <param name="input">输入的字符串</param>
/// <returns>解析后的 List如果输入为空则返回空列表</returns>
public static List<string> ParseString(string input)
{
// 如果输入为空或 null返回空列表
if (string.IsNullOrEmpty(input))
{
return new List<string>();
}
// 按 "|" 分割字符串,并返回结果列表
return new List<string>(input.Split('|'));
}
/// <summary>
/// 判断玩家是否接取这个任务或者(返回是bool)
/// </summary>
/// <param number="number">要检查的数字</param>
/// <param Type="Type">弹窗名</param>
/// <returns>是否存在</returns>
public void FindPlayerTaskID(int number,string Type)
{
foreach (var item in jSONReader.ZZSelectsDictionary)
{
Select data = item.Value;
if (data.AppliedUI == "tanchuang1")
{
var a = GetNumberBeforeComma(data.Group);
Debug.Log("bbbb");
//先用Grop分组
if (!CSB1.ContainsKey(a))
{
CSB1.Add(a, data.ID);// 更新值
}
}
}
TwoFind(number);
}
public void TwoFind(int number)
{
//再一次来判断
if (isYou)
{
Debug.Log("进来了脸脸了了了了了了脸脸了脸脸了了了脸脸了了");
Debug.Log(CSB1.Count);
foreach (KeyValuePair<int, string> kvp in CSB1)
{
Debug.Log("进不来了");
int key = kvp.Key;
string value = kvp.Value;
// 将字符串拆分为 List<string>
List<string> values = new List<string>(value.Split(','));
// 对值列表进行对比
for (int i = 0; i < values.Count; i++)
{
Debug.Log("进不来了11111");
for (int j = i + 1; j < values.Count; j++)
{
Debug.Log("进不来了22222");
isYou = IsNumberInData(values[j], number);
if (isYou)
{
break;
}
}
if (isYou)
{
break;
}
}
}
}
}
public bool IsNumberInData(string data, int number)
{
// 按 # 分割 OR 条件组
string[] orGroups = data.Split('#');
// 遍历每个 OR 条件组
foreach (string orGroup in orGroups)
{
// 按 | 分割 AND 条件
string[] andConditions = orGroup.Split('|');
// 遍历每个 AND 条件,检查是否包含数字
foreach (string condition in andConditions)
{
// 按 , 分割单个条件
string[] numbers = condition.Split(',');
// 确保条件中有数字
if (numbers.Length == 2 && int.TryParse(numbers[1], out int parsedNumber))
{
if (parsedNumber == number)
{
return true; // 如果匹配,则立即返回 true
}
}
}
}
return false; // 如果所有条件都不匹配,返回 false
}
/// <summary>
/// 解析并提取逗号(,)前的数字(判断分组)
/// </summary>
/// <param name="data">输入字符串</param>
/// <returns>返回一个包含数字的列表</returns>
/// <summary>
/// 获取逗号(,或,)前的数字
/// </summary>
/// <param name="data">输入的字符串(例如 "12315"</param>
/// <returns>逗号前的数字,如果解析失败返回 -1</returns>
public int GetNumberBeforeComma(string data)
{
Debug.Log("aaaa");
if (string.IsNullOrEmpty(data))
{
Debug.LogWarning("输入为空或 null");
return -1;
}
// 按逗号分割(支持中文 "" 和英文 ","
string[] parts = data.Split(new char[] { '', ',' });
// 检查分割结果并尝试解析
if (parts.Length > 0 && int.TryParse(parts[0], out int number))
{
return number; // 返回解析成功的数字
}
Debug.LogWarning($"无法解析逗号前的数字:{data}");
return -1; // 解析失败返回 -1
}
}