249 lines
6.7 KiB
C#
249 lines
6.7 KiB
C#
using System;
|
||
using System.Collections;
|
||
using System.Collections.Generic;
|
||
using System.Xml;
|
||
using Unity.VisualScripting;
|
||
using UnityEngine;
|
||
|
||
public class ZZZPlayer : MonoBehaviour
|
||
{
|
||
|
||
public static ZZZPlayer CSZS;
|
||
public JSONReader jSONReader;
|
||
public Dictionary<int, List<string>> CSB1 = new Dictionary<int,List<string>>(); //Key是判断是不是一组,string是ID tanchuang1用的
|
||
public bool isYou = true;
|
||
public bool isHYL=false;
|
||
|
||
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 void Update()
|
||
{
|
||
isHYL=ReadRoom.instance.iszongzhihui;
|
||
}
|
||
|
||
private void Awake()
|
||
{
|
||
CSZS = this;
|
||
}
|
||
//初始化字典
|
||
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>() }
|
||
};
|
||
|
||
/// <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 == Type)
|
||
{
|
||
var a = GetNumberBeforeComma(data.Group);
|
||
|
||
// 检查并初始化键
|
||
if (!CSB1.ContainsKey(a))
|
||
{
|
||
CSB1[a] = new List<string>(); // 初始化键对应的列表
|
||
}
|
||
|
||
// 添加值到键对应的列表
|
||
CSB1[a].Add(data.ID);
|
||
}
|
||
}
|
||
|
||
// 执行后续对比逻辑
|
||
CompareValues(number);
|
||
}
|
||
/// <summary>
|
||
/// 第二次筛选
|
||
/// </summary>
|
||
private void CompareValues(int number)
|
||
{
|
||
// 获取所有 Key
|
||
List<int> allKeys = GetAllKeys(CSB1);
|
||
Debug.Log("所有的 Key: " + string.Join(", ", allKeys));
|
||
|
||
// 获取所有 Value
|
||
List<string> allValues = GetAllValues(CSB1);
|
||
Debug.Log("所有的 Values: " + string.Join(", ", allValues));
|
||
|
||
|
||
}
|
||
#region 测试
|
||
/// <summary>
|
||
/// 获取所有 Key
|
||
/// </summary>
|
||
private List<int> GetAllKeys(Dictionary<int, List<string>> dictionary)
|
||
{
|
||
return new List<int>(dictionary.Keys);
|
||
}
|
||
|
||
/// <summary>
|
||
/// 获取所有 Value
|
||
/// </summary>
|
||
private List<string> GetAllValues(Dictionary<int, List<string>> dictionary)
|
||
{
|
||
List<string> allValues = new List<string>();
|
||
|
||
foreach (var values in dictionary.Values)
|
||
{
|
||
allValues.AddRange(values); // 合并所有值
|
||
}
|
||
|
||
return allValues;
|
||
}
|
||
/// <summary>
|
||
/// 获取指定 Key 对应的所有 Value
|
||
/// </summary>
|
||
private List<string> GetValuesForKey(int key)
|
||
{
|
||
if (CSB1.ContainsKey(key))
|
||
{
|
||
return CSB1[key]; // 返回对应的值列表
|
||
}
|
||
else
|
||
{
|
||
Debug.LogWarning($"Key {key} 不存在于字典中!");
|
||
return null;
|
||
}
|
||
}
|
||
#endregion
|
||
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">输入的字符串(例如 "123,15")</param>
|
||
/// <returns>逗号前的数字,如果解析失败返回 -1</returns>
|
||
public int GetNumberBeforeComma(string data)
|
||
{
|
||
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
|
||
}
|
||
|
||
}
|