2024-12-13 20:38:15 +08:00

98 lines
2.5 KiB
C#

using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using cfg.BlacksmithData;
using UnityEngine;
using UnityEngine.UI;
using Random = UnityEngine.Random;
public class RogenPanel : MonoBehaviour
{
[SerializeField] private RogenItem[] _rogenItems;
[SerializeField] private int resetNum = 0;
[SerializeField] private Button resetButton;
[SerializeField] private Button getAllButton;
private void OnEnable()
{
resetButton.onClick.AddListener(InitData);
getAllButton.onClick.AddListener(SendAll);
}
private void OnDisable()
{
resetButton.onClick.RemoveListener(InitData);
getAllButton.onClick.RemoveListener(SendAll);
}
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);
}
}
}
}
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);
if (resetNum<=0)
{
resetButton.gameObject.SetActive(false);
}
else
{
resetButton.gameObject.SetActive(true);
}
resetNum--;
}
public void SetResetIndex(int num)
{
resetNum = num;
}
public void SendAll()
{
foreach (var item in _rogenItems)
{
BattleManager.ins.SetRogen(item.SkillRogueData);
}
UIMgr.ins.CloseRogenPanel();
}
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;
}
}