Project_WL/Assets/Script/UI/Roullette/EventRoulletteUI.cs

149 lines
5.3 KiB
C#

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using Random = UnityEngine.Random;
public class EventRoulletteUI : LobbyNonMenuBase
{
public UISprite[] sprites; // 0 룰렛 보드, 1 룰렛 뽑기권 버튼, 2 광고 버튼
public UILabel[] labels; // 0 가지고 있는 뽑기권, 1 필요 뽑기권, 2 설명, 3 광고
public GameObject[] gos; // 0 뽑기권 버튼, 1 보너스 버튼, 2 뽑기권 충돌박스, 3 젬 충돌박스, 4 광고로 뽑기 버튼
string m_SelectItem;
string[] arr_desc = new string[]
{
"[98AFC0]몬스터 처치 시, 낮은 확률로 룰렛 뽑기권 획득\n챕터 클리어 시, 룰렛 뽑기권 1장 지급\n돌릴 때 마다 소모되는 뽑기권 개수 증가 (최고 15)[-]\n[3CD0FF]5회마다 보너스 룰렛 등장",
"[98AFC0]몬스터 처치 시, 낮은 확률로 룰렛 뽑기권 획득\n챕터 클리어 시, 룰렛 뽑기권 1장 지급\n돌릴 때 마다 소모되는 뽑기권 개수 증가 (최고 15)[-]\n[ff00ff]룰렛 진행 중 게임 종료 시 보상 획득 불가"
};
public override void Set()
{
base.Set();
Set_Board();
Set_RoulletteTicket();
}
void Set_Board()
{
var sdata = ServerInfo.Ins.m_ServerData;
if (sdata.Get_Common(eCommon.Roullette_Count) < (sdata.Get_Common(eCommon.Roullette_LuckyCount) + 1) * 5)
{
sprites[0].spriteName = "roullette1";
labels[2].text = arr_desc[0];
gos[0].SetActive(true);
gos[2].SetActive(true);
gos[4].SetActive(true);
gos[1].SetActive(false);
gos[3].SetActive(false);
}
else
{
sprites[0].spriteName = "roullette2";
sprites[0].transform.rotation = Quaternion.identity;
labels[2].text = arr_desc[1];
gos[0].SetActive(false);
gos[2].SetActive(false);
gos[4].SetActive(false);
gos[1].SetActive(true);
gos[3].SetActive(true);
}
}
void Set_RoulletteTicket()
{
var sdata = ServerInfo.Ins.m_ServerData;
var ticket = sdata.Get_Common(eCommon.Roullette_Ticket);
labels[0].text = ticket.ToString();
var needticket = sdata.Get_Common(eCommon.Roullette_Count) + 1;
labels[1].text = needticket < 15 ? needticket.ToString() : "15";
sprites[1].spriteName = ticket >= needticket ? "button1" : MyValue.OffButtonName;
labels[3].text = DSUtil.Format("({0}/2)", sdata.Get_Common(eCommon.Roullette_ADCount));
sprites[2].spriteName = sdata.Get_Common(eCommon.Roullette_ADCount) < 2 ? "button3" : MyValue.OffButtonName;
}
public void Set_SelectItem(string item)
{
m_SelectItem = item;
if (DontBack) SoundInfo.Ins.Play_OneShot(eSound.s027_randomwheel, 0.1f);
}
IEnumerator Anim_Roullette(float powmin, float powmax)
{
m_SelectItem = "";
var pow = Random.Range(powmin, powmax);
int i = 0;
while (pow > 0.075f)
{
sprites[0].transform.Rotate(0, 0, pow);
pow *= 1 - Time.deltaTime;
if (pow > 2)
++i;
yield return null;
}
if (!string.IsNullOrEmpty(m_SelectItem))
{
var split = m_SelectItem.Split(',');
var item = new ItemData(DSUtil.StringToEnum<eItem>(split[0]), 0, int.Parse(split[1]), "roul", eUICardType.GetItem);
var obtain = ServerInfo.Ins.m_ServerData.Add_Item(item);
GetItemUI.Ins.Set(obtain);
ServerInfo.Ins.Write(() =>
{
if (item.ItemType == eItem.Gem && item.Amount == 1500)
MessageInfo.Ins.Add_NotiToChatServer(DSUtil.Format("{0} 행운 뽑기에서 1,500젬 획득", ServerInfo.Ins.UserName));
GetItemUI.Ins.Show_Items();
Set_Board();
Set_RoulletteTicket();
});
}
DontBack = false;
}
public void OnClick_Roullete()
{
if (DontBack) return;
var sdata = ServerInfo.Ins.m_ServerData;
var count = sdata.Get_Common(eCommon.Roullette_Count) + 1;
if (count > 15) count = 15;
if (sdata.Get_Common(eCommon.Roullette_Ticket) >= count)
{
DontBack = true;
sdata.Sub_Common(eCommon.Roullette_Ticket, count);
sdata.Add_Common(eCommon.Roullette_Count);
StartCoroutine(Anim_Roullette(27f, 32f));
}
}
public void OnClick_RoulletteAD()
{
if (DontBack) return;
var sdata = ServerInfo.Ins.m_ServerData;
if (sdata.Get_Common(eCommon.Roullette_ADCount) < 2)
{
DontBack = true;
sdata.Add_Common(eCommon.Roullette_ADCount);
sdata.Add_Common(eCommon.Roullette_Count);
StartCoroutine(Anim_Roullette(27f, 32f));
}
}
public void OnClick_Bonus()
{
if (DontBack) return;
DontBack = true;
var sdata = ServerInfo.Ins.m_ServerData;
sdata.Add_Common(eCommon.Roullette_LuckyCount);
ServerInfo.Ins.Write(() => { StartCoroutine(Anim_Roullette(27f, 32f)); });
}
public override void OnClick_Back()
{
base.OnClick_Back();
GameUI.Ins.LobbyUI.Set_Noti();
}
}