702 lines
15 KiB
C#
702 lines
15 KiB
C#
// ***********************************************************************
|
|
// Assembly : Game
|
|
// Author : Kimch
|
|
// Created : 2020-12-08
|
|
// Description :
|
|
// Last Modified By :
|
|
// Last Modified On :
|
|
// ***********************************************************************
|
|
// <copyright file= "ShopProxy" company="Kunpo"></copyright>
|
|
// <summary></summary>
|
|
// ***********************************************************************
|
|
|
|
using F;
|
|
using System.Collections;
|
|
using System.Collections.Generic;
|
|
using UnityEngine;
|
|
|
|
namespace G
|
|
{
|
|
/// <summary>
|
|
/// 商城宝箱
|
|
/// </summary>
|
|
public class ShopProxy : F.GameProxy
|
|
{
|
|
public class TimeBox
|
|
{
|
|
public int id;
|
|
public int time;
|
|
public int recoverSecond;
|
|
|
|
public string name;
|
|
|
|
public bool canOpen
|
|
{
|
|
get { return (time - Launch.Timestamp) <= 0; }
|
|
}
|
|
|
|
public int remainSecond
|
|
{
|
|
get { return Mathf.Max(0, (time - Launch.Timestamp)); }
|
|
}
|
|
|
|
public int unixTimestamp
|
|
{
|
|
get { return time; }
|
|
set { time = value; }
|
|
}
|
|
}
|
|
|
|
public class CoinBox
|
|
{
|
|
public int id;
|
|
public int itemId;
|
|
}
|
|
|
|
public class KeyBox
|
|
{
|
|
public int id;
|
|
public int itemId;
|
|
public int time;
|
|
|
|
public int recoverSecond;
|
|
|
|
public Vector2Int freeCount
|
|
{
|
|
get
|
|
{
|
|
var timeInfo = TimeProxy.Instance.GetTimeInfo2(id + TimeProxy.红颜宝箱);
|
|
return new Vector2Int(timeInfo.remain, timeInfo.max);
|
|
}
|
|
}
|
|
public bool CostFreeCount()
|
|
{
|
|
return TimeProxy.Instance.CostTimes(id + TimeProxy.红颜宝箱);
|
|
}
|
|
|
|
public bool CheckFreeCount()
|
|
{
|
|
return TimeProxy.Instance.CheckTimes(id + TimeProxy.红颜宝箱);
|
|
}
|
|
|
|
public bool canOpen
|
|
{
|
|
get { return (time - Launch.Timestamp) <= 0; }
|
|
}
|
|
|
|
public int remainSecond
|
|
{
|
|
get { return Mathf.Max(0, (time - Launch.Timestamp)); }
|
|
}
|
|
|
|
public int unixTimestamp
|
|
{
|
|
get { return time; }
|
|
set { time = value; }
|
|
}
|
|
}
|
|
|
|
#region Field
|
|
|
|
public readonly TimeBox[] giftBoxes = new TimeBox[3];
|
|
|
|
public readonly CoinBox[] slotBoxes = new CoinBox[3];
|
|
|
|
public readonly KeyBox[] keyBoxes = new KeyBox[3];
|
|
|
|
public readonly CoinBox[] petBoxes = new CoinBox[3];
|
|
|
|
private int _boxShowIndex = 1;
|
|
|
|
public int boxShowIndex
|
|
{
|
|
get { return _boxShowIndex; }
|
|
}
|
|
|
|
/// <summary>
|
|
///
|
|
/// </summary>
|
|
public bool giftUseFree
|
|
{
|
|
get { return TimeProxy.Instance.GetTimeKey(TimeProxy.每日免费加速); }
|
|
set { TimeProxy.Instance.TryTimeKey(TimeProxy.每日免费加速); }
|
|
}
|
|
|
|
/// <summary>
|
|
/// 免费获取次数
|
|
/// </summary>
|
|
public int freeGetTimes
|
|
{
|
|
get { return TimeProxy.Instance.GetTimes(TimeProxy.装备宝箱广告次数); }
|
|
set { TimeProxy.Instance.SetTimes(TimeProxy.装备宝箱广告次数, value); }
|
|
}
|
|
|
|
/// <summary>
|
|
///
|
|
/// </summary>
|
|
public int freeGetMaxTimes
|
|
{
|
|
get { return TimeProxy.Instance.GetMaxTimes(TimeProxy.装备宝箱广告次数); }
|
|
}
|
|
|
|
/// <summary>
|
|
/// 免费获取次数
|
|
/// </summary>
|
|
public int freeGetPetBoxTimes
|
|
{
|
|
get { return TimeProxy.Instance.GetTimes(TimeProxy.宠物重铸丹); }
|
|
set { TimeProxy.Instance.SetTimes(TimeProxy.宠物重铸丹, value); }
|
|
}
|
|
|
|
#endregion
|
|
|
|
#region Method
|
|
|
|
public override void ReadArchive()
|
|
{
|
|
InitShop();
|
|
LoadShop();
|
|
}
|
|
|
|
private void InitShop()
|
|
{
|
|
for (int i = 0; i < giftBoxes.Length; i++)
|
|
{
|
|
giftBoxes[i] = new TimeBox
|
|
{
|
|
id = i,
|
|
time = 0,
|
|
recoverSecond = i < 2 ? (i < 1 ? 12 * 60 * 60 : 24 * 60 * 60) : 48 * 60 * 60,
|
|
};
|
|
}
|
|
|
|
for (int i = 0; i < slotBoxes.Length; i++)
|
|
{
|
|
slotBoxes[i] = new CoinBox
|
|
{
|
|
id = i,
|
|
};
|
|
}
|
|
|
|
for (int i = 0; i < keyBoxes.Length; i++)
|
|
{
|
|
keyBoxes[i] = new KeyBox
|
|
{
|
|
id = i,
|
|
itemId = 2800 + i,
|
|
recoverSecond = i == 0 ? 4 * 60 * 60 : 0,
|
|
};
|
|
}
|
|
|
|
for (int i = 0; i < petBoxes.Length; i++)
|
|
{
|
|
petBoxes[i] = new CoinBox
|
|
{
|
|
id = i,
|
|
};
|
|
}
|
|
}
|
|
|
|
const string ARCHIVE_KEY_V1 = "shop_v1";
|
|
|
|
private void LoadShop()
|
|
{
|
|
var dataList = ArchiveProxy.Instance.GetIntList(ARCHIVE_KEY_V1);
|
|
if (dataList != null && dataList.Count > 0)
|
|
{
|
|
int index = 0;
|
|
int count = dataList[index++];
|
|
for (int i = 0; i < giftBoxes.Length; i++)
|
|
{
|
|
giftBoxes[i].unixTimestamp = dataList[index++];
|
|
}
|
|
|
|
bool resetSlot = false;
|
|
count = dataList[index++];
|
|
for (int i = 0; i < slotBoxes.Length; i++)
|
|
{
|
|
slotBoxes[i].itemId = dataList[index++];
|
|
if (ItemProxy.Instance.GetStaticItem<ItemBox>(slotBoxes[i].itemId) == null)
|
|
{
|
|
resetSlot = true;
|
|
break;
|
|
}
|
|
}
|
|
|
|
count = dataList[index++];
|
|
for (int i = 0; i < keyBoxes.Length; i++)
|
|
{
|
|
keyBoxes[i].unixTimestamp = dataList[index++];
|
|
}
|
|
|
|
bool resetPet = false;
|
|
count = dataList[index++];
|
|
for (int i = 0; i < petBoxes.Length; i++)
|
|
{
|
|
petBoxes[i].itemId = dataList[index++];
|
|
if (ItemProxy.Instance.GetStaticItem<ItemBox>(petBoxes[i].itemId) == null)
|
|
{
|
|
resetPet = true;
|
|
break;
|
|
}
|
|
}
|
|
|
|
if (resetSlot)
|
|
{
|
|
ResetSlot();
|
|
}
|
|
if (resetPet)
|
|
{
|
|
ResetPet();
|
|
}
|
|
return;
|
|
}
|
|
|
|
ResetSlot();
|
|
ResetPet();
|
|
}
|
|
|
|
private void SaveShop()
|
|
{
|
|
var shopList = ArchiveProxy.Instance.GetIntList(ARCHIVE_KEY_V1);
|
|
if (shopList != null)
|
|
{
|
|
shopList.Clear();
|
|
|
|
shopList.Add(giftBoxes.Length);
|
|
for (int i = 0; i < giftBoxes.Length; i++)
|
|
{
|
|
shopList.Add(giftBoxes[i].unixTimestamp);
|
|
}
|
|
|
|
shopList.Add(slotBoxes.Length);
|
|
for (int i = 0; i < slotBoxes.Length; i++)
|
|
{
|
|
shopList.Add(slotBoxes[i].itemId);
|
|
}
|
|
|
|
shopList.Add(keyBoxes.Length);
|
|
for (int i = 0; i < keyBoxes.Length; i++)
|
|
{
|
|
shopList.Add(keyBoxes[i].unixTimestamp);
|
|
}
|
|
|
|
shopList.Add(petBoxes.Length);
|
|
for (int i = 0; i < petBoxes.Length; i++)
|
|
{
|
|
shopList.Add(petBoxes[i].itemId);
|
|
}
|
|
|
|
ArchiveProxy.Instance.SetIntList(ARCHIVE_KEY_V1, shopList);
|
|
}
|
|
}
|
|
|
|
const int GIFT_BOX_INDEX_MAX = 3;
|
|
/// <summary>
|
|
///
|
|
/// </summary>
|
|
/// <param name="index"></param>
|
|
/// <returns></returns>
|
|
public bool OpenGiftBox(int index)
|
|
{
|
|
var giftbox = giftBoxes[index];
|
|
var remain = giftbox.time - Launch.Timestamp;
|
|
if (remain <= 0)
|
|
{
|
|
var lastLevel = LevelProxy.Instance.currentUnlockedLevel;
|
|
var levelItem = ItemProxy.Instance.GetStaticItem<ItemLevel>(lastLevel);
|
|
if (levelItem != null && levelItem.shopBox != null && levelItem.shopBox.Length >= GIFT_BOX_INDEX_MAX)
|
|
{
|
|
var dropBox = BoxProxy.Instance.GetBoxInfo(levelItem.shopBox[index]);
|
|
if (dropBox != null)
|
|
{
|
|
var rnd = dropBox.GetRndItem();
|
|
if (index == 2)
|
|
{
|
|
var q5 = RandomProxy.Instance.GetRandom(2);
|
|
if (q5)
|
|
{
|
|
int rc = 0;
|
|
while (rnd.propItem.quality < 5 && rc++ < 10000)
|
|
{
|
|
rnd = dropBox.GetRndItem();
|
|
}
|
|
}
|
|
}
|
|
RewardProxy.Instance.GetReward(rnd);
|
|
UI.RewardWindow.ShowBox(rnd,
|
|
(error, message) =>
|
|
{
|
|
PostNotification(GlobalDefine.EVENT_MONEY_CHANGED);
|
|
});
|
|
}
|
|
}
|
|
giftbox.time = Launch.Timestamp + (giftbox.recoverSecond);
|
|
SaveShop();
|
|
//开启传奇宝箱次数
|
|
MissionProxy.Instance.OnEvent(MissionProxy.开启宝箱次数, 1, 1);
|
|
return true;
|
|
}
|
|
else
|
|
{
|
|
return false;
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
///
|
|
/// </summary>
|
|
/// <param name="index"></param>
|
|
/// <returns></returns>
|
|
public int OpenShopSlot(int index)
|
|
{
|
|
var coinBox = slotBoxes[index];
|
|
if (coinBox.itemId > 0)
|
|
{
|
|
var boxItem = BoxProxy.Instance.GetBoxInfo(coinBox.itemId);
|
|
if (boxItem == null)
|
|
{
|
|
ResetSlot();
|
|
return 3;
|
|
}
|
|
|
|
if (MoneyProxy.Instance.CheckAndCostMoney(boxItem.item.priceInfo))
|
|
{
|
|
var rndItem = boxItem.GetRndItem();
|
|
RewardProxy.Instance.GetReward(rndItem);
|
|
UI.RewardWindow.ShowBox(rndItem,
|
|
(error, message) =>
|
|
{
|
|
PostNotification(GlobalDefine.EVENT_MONEY_CHANGED);
|
|
});
|
|
//开启精金宝箱次数
|
|
MissionProxy.Instance.OnEvent(MissionProxy.开启宝箱次数, 1, 2);
|
|
ResetSlot();
|
|
SaveShop();
|
|
return 0;
|
|
}
|
|
else
|
|
{
|
|
return 2;
|
|
}
|
|
}
|
|
else
|
|
{
|
|
ResetSlot();
|
|
SaveShop();
|
|
return 4;
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
///
|
|
/// </summary>
|
|
/// <param name="index"></param>
|
|
/// <param name="free"></param>
|
|
/// <returns></returns>
|
|
public int OpenKeyBox(int index, bool free)
|
|
{
|
|
var keyBox = keyBoxes[index];
|
|
if (keyBox.itemId > 0)
|
|
{
|
|
var boxItem = BoxProxy.Instance.GetBoxInfo(keyBox.itemId);
|
|
if (boxItem == null)
|
|
{
|
|
return 3;
|
|
}
|
|
|
|
if (keyBox.recoverSecond > 0)
|
|
{
|
|
var remain = keyBox.time - Launch.Timestamp;
|
|
if (remain <= 0)
|
|
{
|
|
var rnd = boxItem.GetRndItem();
|
|
RewardProxy.Instance.GetReward(rnd);
|
|
UI.RewardWindow.ShowBox(rnd,
|
|
(error, message) =>
|
|
{
|
|
//PostNotification(GlobalDefine.EVENT_MONEY_CHANGED);
|
|
});
|
|
|
|
keyBox.time = Launch.Timestamp + (keyBox.recoverSecond);
|
|
SaveShop();
|
|
//开启钥匙宝箱次数
|
|
MissionProxy.Instance.OnEvent(MissionProxy.开启宝箱次数, 1, 3);
|
|
return 0;
|
|
}
|
|
else
|
|
{
|
|
return 2;
|
|
}
|
|
}
|
|
else if (free || MoneyProxy.Instance.CheckAndCostMoney(boxItem.item.priceInfo))
|
|
{
|
|
var rnd = boxItem.GetRndItem();
|
|
RewardProxy.Instance.GetReward(rnd);
|
|
UI.RewardWindow.ShowBox(rnd,
|
|
(error, message) =>
|
|
{
|
|
//PostNotification(GlobalDefine.EVENT_MONEY_CHANGED);
|
|
});
|
|
SaveShop();
|
|
//开启钥匙宝箱次数
|
|
MissionProxy.Instance.OnEvent(MissionProxy.开启宝箱次数, 1, 3);
|
|
return 0;
|
|
}
|
|
else
|
|
{
|
|
return 1;
|
|
}
|
|
}
|
|
else
|
|
{
|
|
SaveShop();
|
|
return 4;
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
///
|
|
/// </summary>
|
|
/// <param name="index"></param>
|
|
/// <returns></returns>
|
|
public int OpenPetBox(int index)
|
|
{
|
|
int getTimes = this.freeGetPetBoxTimes;
|
|
if (getTimes <= 0)
|
|
return 1;
|
|
this.freeGetPetBoxTimes = getTimes - 1;
|
|
|
|
var petBox = petBoxes[index];
|
|
if (petBox.itemId > 0)
|
|
{
|
|
var boxItem = BoxProxy.Instance.GetBoxInfo(petBox.itemId);
|
|
if (boxItem == null)
|
|
{
|
|
ResetPet();
|
|
return 3;
|
|
}
|
|
|
|
if (MoneyProxy.Instance.CheckAndCostMoney(boxItem.item.priceInfo))
|
|
{
|
|
var rndItems = boxItem.GetRndAndExtraItems();
|
|
RewardProxy.Instance.GetRewards(rndItems);
|
|
UI.RewardWindow.ShowBoxs(rndItems,
|
|
(error, message) =>
|
|
{
|
|
PostNotification(GlobalDefine.EVENT_MONEY_CHANGED);
|
|
});
|
|
|
|
//开启精金宝箱次数
|
|
MissionProxy.Instance.OnEvent(MissionProxy.开启宝箱次数, 1, 4);
|
|
ResetPet();
|
|
SaveShop();
|
|
return 0;
|
|
}
|
|
else
|
|
{
|
|
return 2;
|
|
}
|
|
}
|
|
else
|
|
{
|
|
ResetPet();
|
|
SaveShop();
|
|
return 4;
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// 宝箱加速
|
|
/// </summary>
|
|
public void GiftBoxSpeedUp()
|
|
{
|
|
for (int i = 0; i < giftBoxes.Length; i++)
|
|
{
|
|
giftBoxes[i].time -= 12 * 60 * 60;
|
|
}
|
|
SaveShop();
|
|
MissionProxy.Instance.OnEvent(MissionProxy.饰品宝箱加速次数);
|
|
}
|
|
|
|
/// <summary>
|
|
/// 全部领取
|
|
/// </summary>
|
|
public void SlotFreeGetAll()
|
|
{
|
|
int getTimes = this.freeGetTimes;
|
|
if (getTimes <= 0)
|
|
return;
|
|
this.freeGetTimes = getTimes - 1;
|
|
|
|
var tmpList = ListPool<Item.ItemInfo>.Get();
|
|
foreach (var shopSlot in slotBoxes)
|
|
{
|
|
var dropBox = BoxProxy.Instance.GetBoxInfo(shopSlot.itemId);
|
|
if (dropBox != null)
|
|
{
|
|
var rndItem = dropBox.GetRndItem();
|
|
tmpList.Add(rndItem);
|
|
}
|
|
}
|
|
|
|
RewardProxy.Instance.GetRewards(tmpList);
|
|
UI.RewardWindow.ShowBoxs(tmpList,
|
|
(error, message) =>
|
|
{
|
|
//PostNotification(GlobalDefine.EVENT_MONEY_CHANGED);
|
|
});
|
|
ListPool<Item.ItemInfo>.Release(tmpList);
|
|
ResetSlot();
|
|
SaveShop();
|
|
|
|
//开启装备宝箱次数
|
|
MissionProxy.Instance.OnEvent(MissionProxy.开启宝箱次数, 3, 2);
|
|
MissionProxy.Instance.OnEvent(MissionProxy.装备宝箱加速次数);
|
|
//_shopRefreshTime = System.DateTime.UtcNow.AddSeconds(_shopRecoverTime);
|
|
//SaveShop();
|
|
}
|
|
|
|
/// <summary>
|
|
///
|
|
/// </summary>
|
|
public void SlotPetGetAll()
|
|
{
|
|
int getTimes = this.freeGetPetBoxTimes;
|
|
if (getTimes <= 0)
|
|
return;
|
|
this.freeGetPetBoxTimes = getTimes - 1;
|
|
|
|
var tmpList = ListPool<Item.ItemInfo>.Get();
|
|
foreach (var petBox in petBoxes)
|
|
{
|
|
var dropBox = BoxProxy.Instance.GetBoxInfo(petBox.itemId);
|
|
if (dropBox != null)
|
|
{
|
|
var rndItems = dropBox.GetRndAndExtraItems();
|
|
tmpList.AddRange(rndItems);
|
|
}
|
|
}
|
|
RewardProxy.Instance.GetRewards(tmpList);
|
|
UI.RewardWindow.ShowBoxs(tmpList,
|
|
(error, message) =>
|
|
{
|
|
PostNotification(GlobalDefine.EVENT_MONEY_CHANGED);
|
|
});
|
|
ListPool<Item.ItemInfo>.Release(tmpList);
|
|
|
|
ResetPet();
|
|
SaveShop();
|
|
|
|
//开启装备宝箱次数
|
|
MissionProxy.Instance.OnEvent(MissionProxy.开启宝箱次数, 3, 4);
|
|
MissionProxy.Instance.OnEvent(MissionProxy.装备宝箱加速次数);
|
|
//_shopRefreshTime = System.DateTime.UtcNow.AddSeconds(_shopRecoverTime);
|
|
//SaveShop();
|
|
}
|
|
|
|
const int SLOT_BOX_INDEX = 3;
|
|
/// <summary>
|
|
///
|
|
/// </summary>
|
|
private void ResetSlot()
|
|
{
|
|
var lastLevel = LevelProxy.Instance.currentUnlockedLevel;
|
|
var levelItem = ItemProxy.Instance.GetStaticItem<ItemLevel>(lastLevel);
|
|
if (levelItem != null && levelItem.shopBox != null && levelItem.shopBox.Length > SLOT_BOX_INDEX)
|
|
{
|
|
var dropBox = BoxProxy.Instance.GetBoxInfo(levelItem.shopBox[3]);
|
|
if (dropBox != null)
|
|
{
|
|
for (int i = 0; i < slotBoxes.Length; i++)
|
|
{
|
|
var rnd = dropBox.GetRndItem();
|
|
if (rnd.id > 0)
|
|
{
|
|
slotBoxes[i].itemId = rnd.id;
|
|
//shopSlots[i].itemCount = rnd.count;
|
|
//shopSlots[i].status = 0;
|
|
}
|
|
}
|
|
PostNotification(GlobalDefine.EVENT_SHOP_SLOT_CHANGED);
|
|
}
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
///
|
|
/// </summary>
|
|
private void ResetPet()
|
|
{
|
|
var dropBox = BoxProxy.Instance.GetBoxInfo(50003);
|
|
if (dropBox != null)
|
|
{
|
|
for (int i = 0; i < petBoxes.Length; i++)
|
|
{
|
|
var rnd = dropBox.GetRndItem();
|
|
if (rnd.id > 0)
|
|
{
|
|
petBoxes[i].itemId = rnd.id;
|
|
}
|
|
}
|
|
PostNotification(GlobalDefine.EVENT_SHOP_PET_BOX_CHANGED);
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
///
|
|
/// </summary>
|
|
/// <returns></returns>
|
|
public int GetRedPoint1()
|
|
{
|
|
for (int i = 0; i < giftBoxes.Length; i++)
|
|
{
|
|
var giftBox = giftBoxes[i];
|
|
if (giftBox != null && giftBox.canOpen)
|
|
return 1;
|
|
}
|
|
return 0;
|
|
}
|
|
|
|
public int GetRedPoint2()
|
|
{
|
|
if (freeGetTimes >= freeGetMaxTimes)
|
|
return 1;
|
|
return 0;
|
|
}
|
|
|
|
public int GetRedPoint3()
|
|
{
|
|
if (giftUseFree)
|
|
return 1;
|
|
return 0;
|
|
}
|
|
|
|
public int GetRedPoint4()
|
|
{
|
|
if (FunctionProxy.Instance.GetFunctionUnlock(FunctionProxy.FunctionId.Beauty))
|
|
{
|
|
if (keyBoxes[0].canOpen)
|
|
{
|
|
return 1;
|
|
}
|
|
}
|
|
return 0;
|
|
}
|
|
#endregion
|
|
|
|
#region Unity & PROXY
|
|
|
|
public override int priority => 19;
|
|
|
|
public static ShopProxy Instance;
|
|
// Use this for initialization
|
|
private void Awake()
|
|
{
|
|
Instance = this;
|
|
}
|
|
|
|
#endregion
|
|
}
|
|
}
|