_xiaofang/xiaofang/Assets/Script/UI/ZZZZZZ/ZZZPlayer.cs
2024-12-27 21:10:27 +08:00

129 lines
3.5 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 UnityEngine;
public class ZZZPlayer : MonoBehaviour
{
public static ZZZPlayer CSZS;
public JSONReader jSONReader;
public void Start()
{
SetPlayerID("11007");
////遍历字典
//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>
/// 解析以 "|" 分隔的字符串并返回一个 List
/// </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>
/// 判断数字是否存在于字符串中
/// </summary>
/// <param name="data">原始字符串</param>
/// <param name="number">要检查的数字</param>
/// <returns>是否存在</returns>
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
}
}