2024-12-10 17:46:37 +08:00

62 lines
1.7 KiB
C#

using System.Collections;
using System.Collections.Generic;
using System.Linq;
using cfg.BlacksmithData;
using UnityEngine;
public class RogenPanel : MonoBehaviour
{
[SerializeField] private RogenItem[] _rogenItems;
public void InitData()
{
var skillRogues = new List<SkillRogueData>();
foreach (var skill in JsonTab.Instance.tables.SkillRogue.DataList)
{
foreach (var state in BattleManager.ins.SkillStates)
{
foreach (var c in skill.Carryingprops)
{
if (state.itemData.ID==c&& (skill.Frontend==0||skill.Frontend==state.data.ID) && !skillRogues.Exists(t => t.ID == skill.ID))
{
skillRogues.Add(skill);
}
}
}
}
foreach (var rogueData in skillRogues)
{
BDebug.LogError(rogueData);
}
var skill0 = SkillRandom(ref skillRogues);
_rogenItems[0].SetData(skill0);
var skill1 = SkillRandom(ref skillRogues);
_rogenItems[1].SetData(skill1);
var skill2 = SkillRandom(ref skillRogues);
_rogenItems[2].SetData(skill2);
}
private static SkillRogueData SkillRandom(ref List<SkillRogueData> skillRogues)
{
int weight = skillRogues.Sum(data => data.Weight);
int index = Random.Range(0, weight);
foreach (var data in skillRogues)
{
if (index>data.Weight)
{
index -= data.Weight;
}
else
{
skillRogues.Remove(data);
return data;
}
}
return null;
}
}