using System.Collections; using System.Collections.Generic; using UnityEngine; public class ZZZPlayer : MonoBehaviour { public static ZZZPlayer CSZS; public JSONReader jSONReader; public void Start() { SetPlayerID("11007"); ////遍历字典 //foreach (KeyValuePair> kvp in PlayerID) //{ // Debug.Log($"职业: {kvp.Key}"); // // 遍历值(List) // foreach (string task in kvp.Value) // { // Debug.Log($"任务: {task}"); // } //} } public Dictionary> PlayerID = new Dictionary>() { { "8000", new List() }, { "8001", new List() }, { "8002", new List() }, { "8003", new List() }, { "8004", new List() }, { "8005", new List() }, { "8006", new List() }, { "8007", new List() }, { "8008", new List() }, { "8009", new List() }, { "8010", new List() }, { "8011", new List() } }; private void Awake() { CSZS = this; } /// /// 接收玩家接受的任务 /// public void SetPlayerID(string TaskID) { var a=ParseString(jSONReader.GetOcpID(int.Parse(TaskID))); for (int i=0;i /// 返回一个职业接取的任务 /// public List GetPlayerID(string ID) { if (PlayerID.TryGetValue(ID, out List value)) { return value; // 返回对应的 List } else { Debug.Log("颠仔找不到"); return new List(); // 返回空列表 } } /// /// 解析以 "|" 分隔的字符串并返回一个 List /// /// 输入的字符串 /// 解析后的 List,如果输入为空则返回空列表 public static List ParseString(string input) { // 如果输入为空或 null,返回空列表 if (string.IsNullOrEmpty(input)) { return new List(); } // 按 "|" 分割字符串,并返回结果列表 return new List(input.Split('|')); } /// /// 判断数字是否存在于字符串中 /// /// 原始字符串 /// 要检查的数字 /// 是否存在 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 } }