2024-12-16 17:25:10 +08:00
|
|
|
using System;
|
2024-12-04 17:26:27 +08:00
|
|
|
using System.Collections;
|
|
|
|
using System.Collections.Generic;
|
2024-12-16 17:25:10 +08:00
|
|
|
using System.Linq;
|
2024-12-04 17:26:27 +08:00
|
|
|
using UnityEngine;
|
2024-12-16 17:25:10 +08:00
|
|
|
using UnityEngine.UI;
|
|
|
|
using Random = UnityEngine.Random;
|
2024-12-04 17:26:27 +08:00
|
|
|
|
|
|
|
public class StorePanel : MonoBehaviour
|
|
|
|
{
|
2024-12-16 17:25:10 +08:00
|
|
|
public static StorePanel ins;
|
|
|
|
[SerializeField] private List<StoreItem> dayStoreItems;
|
|
|
|
[SerializeField] private List<PrizeDrawItem> _prizeDrawItems;
|
|
|
|
[SerializeField] private RewardPanel _panel;
|
|
|
|
[SerializeField] private GameObject storeParent;
|
|
|
|
[SerializeField] private GameObject lotteryParent;
|
|
|
|
[SerializeField] private Button stroe;
|
2024-12-22 20:35:00 +08:00
|
|
|
[SerializeField] private GameObject stroeback;
|
2024-12-16 17:25:10 +08:00
|
|
|
[SerializeField] private Button lottery;
|
2024-12-22 20:35:00 +08:00
|
|
|
[SerializeField] private GameObject lotteryback;
|
2024-12-16 17:25:10 +08:00
|
|
|
|
|
|
|
private void Awake()
|
|
|
|
{
|
|
|
|
ins = this;
|
|
|
|
}
|
|
|
|
|
|
|
|
private void OnEnable()
|
|
|
|
{
|
|
|
|
stroe.onClick.AddListener(StartPanel);
|
|
|
|
lottery.onClick.AddListener(ResetLottery);
|
|
|
|
}
|
|
|
|
|
|
|
|
private void OnDisable()
|
|
|
|
{
|
|
|
|
stroe.onClick.RemoveListener(StartPanel);
|
|
|
|
lottery.onClick.RemoveListener(ResetLottery);
|
|
|
|
}
|
|
|
|
|
2024-12-10 17:46:37 +08:00
|
|
|
public void StartPanel()
|
2024-12-04 17:26:27 +08:00
|
|
|
{
|
2024-12-11 13:58:55 +08:00
|
|
|
if (DataManager.NextDay("open"))
|
2024-12-10 17:46:37 +08:00
|
|
|
{
|
2024-12-16 17:25:10 +08:00
|
|
|
SetRandomData(1);
|
|
|
|
SetRandomData(2);
|
|
|
|
SetRandomData(3);
|
|
|
|
SetRandomData(4);
|
|
|
|
SetRandomData(5);
|
|
|
|
SetRandomData(6);
|
|
|
|
SetRandomData(101);
|
|
|
|
SetRandomData(102);
|
|
|
|
SetRandomData(103);
|
|
|
|
SetRandomData(104);
|
2024-12-11 13:58:55 +08:00
|
|
|
DataManager.SetTime("open");
|
2024-12-10 17:46:37 +08:00
|
|
|
}
|
2024-12-16 17:25:10 +08:00
|
|
|
|
|
|
|
foreach (var s in dayStoreItems)
|
|
|
|
{
|
|
|
|
s.ResetItem();
|
|
|
|
}
|
|
|
|
_panel.gameObject.SetActive(false);
|
|
|
|
storeParent.SetActive(true);
|
|
|
|
lotteryParent.SetActive(false);
|
2024-12-22 20:35:00 +08:00
|
|
|
stroeback.gameObject.SetActive(true);
|
|
|
|
lotteryback.gameObject.SetActive(false);
|
2024-12-16 17:25:10 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
public void ResetLottery()
|
|
|
|
{
|
|
|
|
foreach (var prize in _prizeDrawItems)
|
|
|
|
{
|
|
|
|
prize.SetData();
|
|
|
|
}
|
|
|
|
_panel.gameObject.SetActive(false);
|
|
|
|
storeParent.SetActive(false);
|
|
|
|
lotteryParent.SetActive(true);
|
2024-12-22 20:35:00 +08:00
|
|
|
stroeback.gameObject.SetActive(false);
|
|
|
|
lotteryback.gameObject.SetActive(true);
|
2024-12-16 17:25:10 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
public void SetRandomData(int id)
|
|
|
|
{
|
|
|
|
var data = JsonTab.Instance.tables.Store.Get(id);
|
|
|
|
var rID = data.Itemrefresh[Random.Range(0, data.Itemrefresh.Count)];
|
|
|
|
DataManager.SetDStore(id,rID);
|
|
|
|
var dataRandom = JsonTab.Instance.tables.StoreRandom.Get(rID);
|
|
|
|
var dis = data.Discountweight.Sum();
|
|
|
|
var r = Random.Range(0, dis);
|
|
|
|
for (var i = 0; i < dataRandom.Discountweight.Count; i++)
|
|
|
|
{
|
|
|
|
r -= dataRandom.Discountweight[i];
|
|
|
|
if (r > 0) continue;
|
|
|
|
DataManager.SetDDiscount(id,dataRandom.Discount[i]);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public void OpenRewardPanel(List<ItemDataNum> itemDatas)
|
|
|
|
{
|
|
|
|
_panel.gameObject.SetActive(true);
|
|
|
|
_panel.SaveData(itemDatas);
|
2024-12-04 17:26:27 +08:00
|
|
|
}
|
|
|
|
}
|