Project_WL/Assets/Script/UI/Shop/ShopCardBase.cs

267 lines
10 KiB
C#

using UnityEngine;
public class ShopCardBase : CardBase
{
public UILabel[] labels; // 0 이름, 1 수량, 2 가격, 3 구매 제한, 4 클로버, 5 번호, 6 구매 조건
public UISprite[] sprites; // 0 아이콘, 1 가격
public GameObject[] gos; // 0 노티, 1 광고 버튼, 2 배경 제외 모두, 3 구매 완료, 4 로켓배송
public GameObject go_guidearrow;
protected ShopTableData m_ShopTableData;
protected virtual void Awake()
{
Set_Repeat_for1sec(Set_ADTime);
}
public override void Set<T>(T _base)
{
base.Set(_base);
if (go_guidearrow) go_guidearrow.SetActive(false);
if (DSUtil.CheckNull(_base))
{
if (!DSUtil.CheckNull(_base))
{
StopCoroutine(m_Co_for1Sec);
m_Co_for1Sec = null;
}
DSUtil.InActivateGameObjects(gos);
return;
}
m_ShopTableData = _base as ShopTableData;
var sdata = ServerInfo.Ins.m_ServerData;
labels[0].text = m_ShopTableData.Get_Name();
if (m_ShopTableData.GoldKillMul > 0)
{
m_ShopTableData.Amount = table_monsterappear.Ins.Get_Data_orNull(1).n_DropGold * m_ShopTableData.GoldKillMul; // TODO 정인호 : 정상적인 스폰 ID 입력 필요
var ainfo = MyValue.Get_ActorStatInfoorNull(eRole.PC);
m_ShopTableData.Amount += m_ShopTableData.Amount * ainfo.Get_Stat(eStat.GOLD_Multiplier) * 0.5d;
}
labels[1].text = DSUtil.GetThousandCommaText(m_ShopTableData.Amount);
if (string.IsNullOrEmpty(m_ShopTableData.InappID))
{
if (m_ShopTableData.PriceType == ePriceType.Review)
labels[2].text = "리뷰 쓰기";
else
labels[2].text = DSUtil.GetThousandCommaText(m_ShopTableData.Price);
}
else
{
var price = InappInfo.Ins.Get_Price_orNull(m_ShopTableData.InappID);
if (price != null)
labels[2].text = price;
else
gameObject.SetActive(false);
}
Set_ADTime();
Set_Limit();
if (m_ShopTableData.Mileage > 0)
{
labels[4].transform.parent.gameObject.SetActive(true);
labels[4].text = DSUtil.GetThousandCommaText(m_ShopTableData.Mileage);
}
else
labels[4].transform.parent.gameObject.SetActive(false);
sprites[0].spriteName = m_ShopTableData.Get_Icon();
sprites[1].spriteName = Get_MoneyIcon();
gos[0].SetActive(sdata.CanShow_ShopAD(m_ShopTableData.ID));
if (gos.Length > 4) gos[4].SetActive(m_ShopTableData.IsRocket);
//if (go_guidearrow) go_guidearrow.SetActive(m_ShopTableData.PriceType == ePriceType.AD && m_ShopTableData.BuyLimit_Day == 1 && NewGameUI.Ins.m_GuideQuestUI.Get_Purpose() == ePurpose.FreePackage && sdata.Get_Common(eCommon.GuideClear) == 0);
}
void Set_Limit()
{
var sdata = ServerInfo.Ins.m_ServerData;
if (m_ShopTableData.BuyLimit > 0)
{
labels[3].text = DSUtil.Format("[687c94]구매 제한[-]\n({0}/{1})", sdata.Get_ShopBuyCount(m_ShopTableData.ID, 1), m_ShopTableData.BuyLimit);
gos[3].SetActive(sdata.Get_ShopBuyCount(m_ShopTableData.ID, 1) >= m_ShopTableData.BuyLimit);
}
else if (m_ShopTableData.BuyLimit_Day > 0)
{
labels[3].text = DSUtil.Format("[687c94]일일 구매[-]\n({0}/{1})", sdata.Get_ShopBuyCount(m_ShopTableData.ID, 2), m_ShopTableData.BuyLimit_Day);
gos[3].SetActive(sdata.Get_ShopBuyCount(m_ShopTableData.ID, 2) >= m_ShopTableData.BuyLimit_Day);
}
else if (m_ShopTableData.BuyLimit_Week > 0)
{
labels[3].text = DSUtil.Format("[687c94]주간 구매[-]\n({0}/{1})", sdata.Get_ShopBuyCount(m_ShopTableData.ID, 3), m_ShopTableData.BuyLimit_Week);
gos[3].SetActive(sdata.Get_ShopBuyCount(m_ShopTableData.ID, 3) >= m_ShopTableData.BuyLimit_Week);
}
else if (m_ShopTableData.BuyLimit_Month > 0)
{
labels[3].text = DSUtil.Format("[687c94]월간 구매[-]\n({0}/{1})", sdata.Get_ShopBuyCount(m_ShopTableData.ID, 4), m_ShopTableData.BuyLimit_Month);
gos[3].SetActive(sdata.Get_ShopBuyCount(m_ShopTableData.ID, 4) >= m_ShopTableData.BuyLimit_Month);
}
else
{
labels[3].text = "";
gos[3].SetActive(false);
}
// 게임 조건에 따른 구매 체크
if (!gos[3].activeSelf)
{
var buycondition = sdata.Can_BuyShopItem(m_ShopTableData);
if (!string.IsNullOrEmpty(buycondition))
{
gos[3].SetActive(true);
if (labels.Length > 6) labels[6].text = buycondition;
else gos[3].GetComponentInChildren<UILabel>().text = buycondition;
}
}
else
{
if (labels.Length > 6) labels[6].text = "구매 완료";
else gos[3].GetComponentInChildren<UILabel>().text = "구매 완료";
}
}
void Set_ADTime()
{
if (m_ShopTableData.PriceType == ePriceType.AD)
{
sprites[1].gameObject.SetActive(false);
var sdata = ServerInfo.Ins.m_ServerData;
var time = sdata.Get_ShopADTime(m_ShopTableData.ID);
var buyCondition = sdata.Can_BuyShopItem(m_ShopTableData);
if (!string.IsNullOrEmpty(buyCondition))
{
gos[1].SetActive(false);
labels[2].text = buyCondition;
labels[2].transform.localPosition = Vector3.zero;
}
else if (time > 0)
{
gos[1].SetActive(false);
labels[2].text = DSUtil.Get_TimeText_MS(time);
labels[2].transform.localPosition = Vector3.zero;
}
else
{
gos[1].SetActive(true);
labels[2].text = "";
}
}
else
gos[1].SetActive(false);
}
string Get_MoneyIcon()
{
switch (m_ShopTableData.PriceType)
{
case ePriceType.AD:
return "icon_ad";
case ePriceType.Cash:
case ePriceType.Review:
labels[2].transform.localPosition = Vector3.zero;
return "empty";
default:
return DSUtil.Get_ItemSpriteInfo((eItem)m_ShopTableData.PriceType).Icon;
}
}
public void OnClick_Buy()
{
var sdata = ServerInfo.Ins.m_ServerData;
var buycondition = sdata.Can_BuyShopItem(m_ShopTableData);
if (!string.IsNullOrEmpty(m_ShopTableData.InappID))
{
if (string.IsNullOrEmpty(buycondition))
InappInfo.Ins.Buy_InappItem(m_ShopTableData.InappID, Set_Limit);
}
else if (m_ShopTableData.PriceType == ePriceType.AD)
{
//if (m_ShopTableData.BuyLimit_Day == 1 && NewGameUI.Ins.m_GuideQuestUI.Get_Purpose() == ePurpose.FreePackage && sdata.Get_Common(eCommon.GuideClear) < 1)
//{
// NewGameUI.Ins.m_GuideQuestUI.Add_GuideQuest(ePurpose.FreePackage);
// if (go_guidearrow) go_guidearrow.SetActive(false);
// Buy_ShopAD();
//}
//else if (sdata.CanShow_ShopAD(m_ShopTableData.ID))
// ADInfo.Ins.Show_AD(Buy_ShopAD);
}
else if (m_ShopTableData.PriceType == ePriceType.Review)
{
if (string.IsNullOrEmpty(buycondition))
{
DataCheckMgr.Ins.Show_Review(() =>
{
GetItemUI.Ins.Set(sdata.Add_Item(new ItemData(m_ShopTableData.Item, m_ShopTableData.ItemID, m_ShopTableData.Amount, "review", eUICardType.GetItem)));
GetItemUI.Ins.Show_Items();
});
Add_BuyCount();
Set_Limit();
}
}
else
{
if (Get_PriceItem() != eItem.None && sdata.Check_ItemAmount(Get_PriceItem(), m_ShopTableData.Price))
{
if (string.IsNullOrEmpty(buycondition))
{
if (m_ShopTableData.Item == eItem.Gold)
{
}
else
{
var cause = DSUtil.Format("shop {0}", m_ShopTableData.ID);
sdata.Use_Item(Get_PriceItem(), m_ShopTableData.Price, 0, cause);
Add_BuyCount();
GetItemUI.Ins.Set(sdata.Add_Item(new ItemData(m_ShopTableData.Item, m_ShopTableData.ItemID, m_ShopTableData.Amount, cause, eUICardType.GetItem)));
GetItemUI.Ins.Show_Items();
Set_Limit();
}
}
else
ToastUI.Ins.Set(173);
}
}
}
void Buy_ShopAD()
{
var sdata = ServerInfo.Ins.m_ServerData;
Add_BuyCount();
sdata.Sub_ShopADTime(m_ShopTableData.ID, -m_ShopTableData.ADGapTime);
GetItemUI.Ins.Set(sdata.Add_Item(new ItemData(m_ShopTableData.Item, m_ShopTableData.ItemID, m_ShopTableData.Amount, "shop ad", eUICardType.GetItem)));
GetItemUI.Ins.Show_Items();
gos[0].SetActive(sdata.CanShow_ShopAD(m_ShopTableData.ID));
Set_ADTime();
Set_Limit();
}
void Add_BuyCount()
{
if (m_ShopTableData.BuyLimit_Day > 0) ServerInfo.Ins.m_ServerData.Add_ShopBuyCount(m_ShopTableData.ID, 1, 2);
else if (m_ShopTableData.BuyLimit_Week > 0) ServerInfo.Ins.m_ServerData.Add_ShopBuyCount(m_ShopTableData.ID, 1, 3);
else if (m_ShopTableData.BuyLimit_Month > 0) ServerInfo.Ins.m_ServerData.Add_ShopBuyCount(m_ShopTableData.ID, 1, 4);
else ServerInfo.Ins.m_ServerData.Add_ShopBuyCount(m_ShopTableData.ID, 1);
}
eItem Get_PriceItem()
{
switch (m_ShopTableData.PriceType)
{
case ePriceType.AD:
case ePriceType.Cash:
case ePriceType.Review:
return eItem.None;
default: return (eItem)m_ShopTableData.PriceType;
}
}
public void OnClick_ItemInfo()
{
if (m_ShopTableData != null)
{
if (m_ShopTableData.Tab == eShopTab.Package)
ItemDescUI.Ins.Set(sprites[0].spriteName, m_ShopTableData.Get_Name(), m_ShopTableData.Desc);
else
ItemDescUI.Ins.Set(new ItemData(m_ShopTableData.Item, m_ShopTableData.ItemID, 0, "", eUICardType.GetItem));
}
}
}