//--------------------------------------------------------
|
// [Author]: 第二世界
|
// [ Date ]: Wednesday, July 18, 2018
|
//--------------------------------------------------------
|
using vnxbqy.UI;
|
using System;
|
using System.Collections.Generic;
|
using LitJson;
|
using System.Linq;
|
|
public class DayPackageItemClassModel : Model, IPlayerLoginOk, IOpenServerActivity, IBeforePlayerDataInitialize
|
{
|
VipModel vipModel
|
{
|
get { return ModelCenter.Instance.GetModel<VipModel>(); }
|
}
|
|
StoreModel storeModel
|
{
|
get { return ModelCenter.Instance.GetModel<StoreModel>(); }
|
}
|
|
// 每日礼包由服务端通知,每周/月礼包取充值表和商城表
|
// 0 每日礼包 1 每周礼包 2 每月礼包
|
int m_SelectIndex = 0;
|
public int selectIndex
|
{
|
get { return m_SelectIndex; }
|
set
|
{
|
if (m_SelectIndex != value)
|
{
|
m_SelectIndex = value;
|
if (selectUpdate != null)
|
{
|
selectUpdate();
|
}
|
}
|
}
|
}
|
|
public class DayGift
|
{
|
public int getCount; // 已获得次数
|
public List<int[]> items;
|
public float money; //orderInfo是数字字符串代表货币类型,否则代表充值 单位分
|
public string orderInfo;
|
public int buyCountLimit;
|
public int onSalePer; //打折
|
}
|
|
|
public List<int> recordIDs = new List<int>();
|
public Dictionary<int, DayGift> m_RechargeDict = new Dictionary<int, DayGift>();
|
public Dictionary<int, DayGift> m_WeekRechargeDict = new Dictionary<int, DayGift>();
|
public Dictionary<int, DayGift> m_MonthRechargeDict = new Dictionary<int, DayGift>();
|
|
public int weekBuyType = 0;
|
public int monthBuyType = 0;
|
public List<int> weekStoreListSort = new List<int>(); //显示顺序
|
public List<int> monthStoreListSort = new List<int>();
|
|
|
public event Action selectUpdate;
|
public event Action<int> onStateUpdate;
|
public event Action onDayGoodsUpdate;
|
public override void Init()
|
{
|
OpenServerActivityCenter.Instance.Register(23, this);
|
ParseConfig();
|
}
|
private const int Redpoint_key1 = 20923;
|
public Redpoint redPointStre1 = new Redpoint(209, Redpoint_key1);
|
public Redpoint redPoint1 = new Redpoint(Redpoint_key1, Redpoint_key1 * 10); //每日免费礼包
|
public Redpoint redPoint2 = new Redpoint(Redpoint_key1, Redpoint_key1 * 10 + 1); //每周免费礼包
|
public Redpoint redPoint3 = new Redpoint(Redpoint_key1, Redpoint_key1 * 10 + 2); //每月免费礼包
|
public bool IsOpen
|
{
|
get
|
{
|
return FuncOpen.Instance.IsFuncOpen(185);
|
}
|
}
|
|
public bool priorityOpen
|
{
|
get
|
{
|
return redPointStre1.state == RedPointState.Simple || redPointStre1.state == RedPointState.GetReward;
|
}
|
}
|
|
public bool IsAdvance
|
{
|
get
|
{
|
return false;
|
}
|
}
|
|
public void OnBeforePlayerDataInitialize()
|
{
|
m_RechargeDict.Clear();
|
recordIDs.Clear();
|
|
foreach (var item in m_WeekRechargeDict)
|
{
|
item.Value.getCount = 0;
|
}
|
|
foreach (var item in m_MonthRechargeDict)
|
{
|
item.Value.getCount = 0;
|
}
|
}
|
|
|
public override void UnInit()
|
{
|
}
|
public void OnPlayerLoginOk()
|
{
|
IsShowTip();
|
|
}
|
|
public DayGift GetDayGift(int index)
|
{
|
return m_RechargeDict[recordIDs[index]];
|
}
|
|
|
public void IsShowTip()
|
{
|
if (!FuncOpen.Instance.IsFuncOpen(185)) return;
|
|
if (m_RechargeDict.ContainsKey(0) && m_RechargeDict[0].getCount == 0)
|
redPointStre1.state = RedPointState.Simple;
|
else
|
redPointStre1.state = RedPointState.None;
|
|
}
|
|
|
|
void ParseConfig()
|
{
|
// 礼包数据包含了价格 购买数量等动态信息 切换账号和打折时刷新
|
weekStoreListSort.Clear();
|
monthStoreListSort.Clear();
|
m_MonthRechargeDict.Clear();
|
m_WeekRechargeDict.Clear();
|
|
|
var config = FuncConfigConfig.Get("BuyPackage");
|
var weekStoreList = JsonMapper.ToObject<int[]>(config.Numerical1);
|
var monthStoreList = JsonMapper.ToObject<int[]>(config.Numerical2);
|
weekBuyType = int.Parse(config.Numerical3);
|
monthBuyType = int.Parse(config.Numerical4);
|
|
// 商店购买也存入充值 orderInfo存储货币类型
|
foreach (var id in weekStoreList)
|
{
|
weekStoreListSort.Add(id + 100000000);
|
StoreConfig storeCfg = StoreConfig.Get(id);
|
m_WeekRechargeDict[id + 100000000] = new DayGift()
|
{
|
money = storeCfg.MoneyNumber,
|
orderInfo = storeCfg.MoneyType.ToString(),
|
items = storeModel.GetShopItemlistEx(storeCfg),
|
buyCountLimit = storeCfg.GoumaiNumber[0],
|
};
|
}
|
foreach (var id in monthStoreList)
|
{
|
monthStoreListSort.Add(id + 100000000);
|
StoreConfig storeCfg = StoreConfig.Get(id);
|
m_MonthRechargeDict[id + 100000000] = new DayGift()
|
{
|
money = storeCfg.MoneyNumber,
|
orderInfo = storeCfg.MoneyType.ToString(),
|
items = storeModel.GetShopItemlistEx(storeCfg),
|
buyCountLimit = storeCfg.GoumaiNumber[0],
|
};
|
}
|
|
var list = vipModel.GetCTGConfigs(VersionConfig.Get().appId);
|
for (int i = 0; i < list.Count; i++)
|
{
|
var ctgConfig = CTGConfig.Get(list[i]);
|
if (ctgConfig.PayType == weekBuyType)
|
{
|
OrderInfoConfig orderCfg;
|
vipModel.TryGetOrderInfo(ctgConfig.RecordID, out orderCfg);
|
|
m_WeekRechargeDict[ctgConfig.RecordID] = new DayGift()
|
{
|
money = orderCfg.m_PayRMBNum,
|
orderInfo = orderCfg.OrderInfo,
|
items = JsonMapper.ToObject<int[][]>(ctgConfig.GainItemList).ToList(),
|
buyCountLimit = ctgConfig.WeekBuyCount,
|
onSalePer = ctgConfig.Percentage,
|
};
|
weekStoreListSort.Add(ctgConfig.RecordID);
|
}
|
else if (ctgConfig.PayType == monthBuyType)
|
{
|
OrderInfoConfig orderCfg;
|
vipModel.TryGetOrderInfo(ctgConfig.RecordID, out orderCfg);
|
m_MonthRechargeDict[ctgConfig.RecordID] = new DayGift()
|
{
|
money = orderCfg.m_PayRMBNum,
|
orderInfo = orderCfg.OrderInfo,
|
items = JsonMapper.ToObject<int[][]>(ctgConfig.GainItemList).ToList(),
|
buyCountLimit = ctgConfig.MonthBuyCount,
|
onSalePer = ctgConfig.Percentage,
|
};
|
monthStoreListSort.Add(ctgConfig.RecordID);
|
}
|
}
|
|
monthStoreListSort.Sort(SortMonthList);
|
weekStoreListSort.Sort(SortWeekList);
|
}
|
|
|
int SortMonthList(int a, int b)
|
{
|
int ida = a > 100000000 ? 0 : 1;
|
int idb = b > 100000000 ? 0 : 1;
|
if (ida != idb)
|
return ida.CompareTo(idb);
|
|
return m_MonthRechargeDict[a].money.CompareTo(m_MonthRechargeDict[b].money);
|
|
}
|
|
int SortWeekList(int a, int b)
|
{
|
int ida = a > 100000000 ? 0 : 1;
|
int idb = b > 100000000 ? 0 : 1;
|
if (ida != idb)
|
return ida.CompareTo(idb);
|
|
return m_WeekRechargeDict[a].money.CompareTo(m_WeekRechargeDict[b].money);
|
|
}
|
|
|
public void DayGoodsInfo(HAA25_tagMCDailyGiftbagInfo pack)
|
{
|
recordIDs = new List<int>();
|
foreach (var goods in pack.GiftbagInfo)
|
{
|
recordIDs.Add((int)goods.GiftID);
|
List<int[]> tmpItems = new List<int[]>();
|
foreach (var itemInfo in goods.ItemInfo)
|
{
|
tmpItems.Add(new int[] { (int)itemInfo.ItemID, itemInfo.ItemCount });
|
}
|
|
int count = 0;
|
if (m_RechargeDict.ContainsKey((int)goods.GiftID))
|
{
|
count = m_RechargeDict[(int)goods.GiftID].getCount;
|
}
|
|
m_RechargeDict[(int)goods.GiftID] = new DayGift()
|
{
|
getCount = count,
|
money = UIHelper.GetRealCoin((int)goods.RMB),
|
orderInfo = goods.OrderInfo,
|
items = tmpItems,
|
buyCountLimit = (int)goods.BuyCountLimit,
|
onSalePer = PlayerDatas.Instance.baseData.IsActive90Off ? goods.Discount * 100 : goods.Discount,
|
};
|
|
|
}
|
|
recordIDs.Sort();
|
|
if (onDayGoodsUpdate != null) onDayGoodsUpdate();
|
}
|
|
|
public void DayGoodsPurchasing(HAA26_tagMCDailyGiftbagPlayerInfo pack)
|
{
|
//每次回报都会把所有已购买物品下发,先清空购买数量,再赋值
|
foreach(int giftID in m_RechargeDict.Keys)
|
{
|
m_RechargeDict[giftID].getCount = 0;
|
}
|
foreach (var goods in pack.BuyCountList)
|
{
|
if (m_RechargeDict.ContainsKey((int)goods.GiftbagID))
|
{
|
m_RechargeDict[(int)goods.GiftbagID].getCount = goods.BuyCount;
|
}
|
else
|
{
|
m_RechargeDict[(int)goods.GiftbagID] = new DayGift()
|
{
|
getCount = goods.BuyCount,
|
};
|
}
|
}
|
|
if (onDayGoodsUpdate != null) onDayGoodsUpdate();
|
|
IsShowTip();
|
}
|
|
|
public void RequestReward()
|
{
|
var sendInfo = new CA504_tagCMPlayerGetReward();
|
sendInfo.RewardType = (int)GotServerRewardType.Def_RewardType_DayPackageFree;
|
sendInfo.DataEx = 0;
|
sendInfo.DataExStrLen = 0;
|
sendInfo.DataExStr = string.Empty;
|
GameNetSystem.Instance.SendInfo(sendInfo);
|
}
|
|
|
}
|