using System.Collections;
|
using System.Collections.Generic;
|
using UnityEngine;
|
using System;
|
|
using LitJson;
|
|
|
namespace vnxbqy.UI
|
{
|
|
public class PushCoinModel : Model, IBeforePlayerDataInitialize
|
{
|
public int[][] awardsTab; //推金币奖励面板
|
public int[][] superAward; //超级大奖
|
public int[][] redPackAward; //红包奖励
|
public int guideID; //引导ID
|
public Dictionary<string, int> freeSuperPushRateInfo = new Dictionary<string, int>(); //免费超级大推金币概率
|
public int ctgID; //超级推
|
public int limit90OffCardDays; //90折卡限制免费获得的创角天数
|
public int[] superPushGiftGoinInfo; //购买超级推持续登录金币奖励
|
|
public const float pushEndPos = 11.5f; //默认情况下推的位置
|
public const float superPushEndPos = 9.8f; //超级推的最终位置
|
public const string COINKEY = "MiniGameCoin"; //金币key
|
|
public int stopIndex = 0; //抽中停止的位置
|
public int lastStopIndex = 0;
|
|
public Dictionary<int, int> modelCoinInfo = new Dictionary<int, int>(); // 台面模型币数量 类型: 1-金币;2-仙玉币
|
public event Action<int> OnGetAwardResult;
|
|
|
VipModel vipModel { get { return ModelCenter.Instance.GetModel<VipModel>(); } }
|
InSevenDayModel inSevenDayModel { get { return ModelCenter.Instance.GetModel<InSevenDayModel>(); } }
|
|
public override void Init()
|
{
|
PlayerDatas.Instance.playerDataRefreshEvent += OnPlayerDataRefreshEvent;
|
GlobalTimeEvent.Instance.secondEvent += OnSecondEvent;
|
ParseConfig();
|
}
|
|
|
void ParseConfig()
|
{
|
var config = FuncConfigConfig.Get("PushCoin");
|
awardsTab = JsonMapper.ToObject<int[][]>(config.Numerical1);
|
|
superAward = JsonMapper.ToObject<int[][]>(config.Numerical2);
|
redPackAward = JsonMapper.ToObject<int[][]>(config.Numerical3);
|
guideID = int.Parse(config.Numerical4);
|
freeSuperPushRateInfo = JsonMapper.ToObject<Dictionary<string, int>>(config.Numerical5);
|
|
config = FuncConfigConfig.Get("EnSuperDiscount");
|
ctgID = int.Parse(config.Numerical1);
|
limit90OffCardDays = int.Parse(config.Numerical2);
|
superPushGiftGoinInfo = GeneralDefine.GetIntArray("EnSuperDiscount", 4);
|
|
}
|
|
//创角8天内或者还有次数
|
public bool IsOpen()
|
{
|
if (!FuncOpen.Instance.IsFuncOpen(238))
|
{
|
return false;
|
}
|
|
if (!PlayerDatas.Instance.baseData.IsActive90Off)
|
{
|
return true;
|
}
|
|
if (TimeUtility.CreateDays <= 8)
|
{
|
return true;
|
}
|
|
if (UIHelper.GetMoneyCnt(48) > 0)
|
return true;
|
return false;
|
}
|
|
|
|
public override void UnInit()
|
{
|
PlayerDatas.Instance.playerDataRefreshEvent -= OnPlayerDataRefreshEvent;
|
GlobalTimeEvent.Instance.secondEvent -= OnSecondEvent;
|
}
|
|
|
public void OnBeforePlayerDataInitialize()
|
{
|
stopIndex = 0;
|
lastStopIndex = 0;
|
if (UI3DPushCoinStage.IsCreated() && !WindowCenter.Instance.IsOpen<PushCoinWin>())
|
{
|
//如果是在界面打开的情况下 说明还是同一个账号的数据,此时不处理
|
UI3DPushCoinStage.Instance?.DestroyCois();
|
}
|
modelCoinInfo.Clear();
|
}
|
|
void OnPlayerDataRefreshEvent(PlayerDataType type)
|
{
|
if (type == PlayerDataType.default40)
|
{
|
UpdateRedpoint();
|
}
|
}
|
|
|
|
Redpoint redpoint = new Redpoint(MainRedDot.PushCoinRepoint);
|
void UpdateRedpoint()
|
{
|
redpoint.state = RedPointState.None;
|
if (UIHelper.GetMoneyCnt(48) > 0)
|
{
|
redpoint.state = RedPointState.Simple;
|
}
|
}
|
|
|
//是否激活超级推金币 登录奖励第七天或者已购买
|
public bool IsActiveSuperPush()
|
{
|
VipModel.RechargeCount rechargeCount;
|
vipModel.TryGetRechargeCount(ctgID, out rechargeCount);
|
if (rechargeCount.totalCount > 0)
|
{
|
return true;
|
}
|
int type = inSevenDayModel.RewardForDic[7];
|
if (type == 1)
|
{
|
return true;
|
}
|
|
return false;
|
}
|
|
public bool IsActiveEnterEffect()
|
{
|
if (IsActiveSuperPush())
|
{
|
return false;
|
}
|
|
if (UIHelper.GetMoneyCnt(48) > 0 && PlayerDatas.Instance.baseData.LV < 100)
|
{
|
return true;
|
}
|
return false;
|
}
|
|
|
//public void ShowRedPackAwards()
|
//{
|
// List<Item> items = new List<Item>();
|
|
// foreach (var arr in redPackAward)
|
// {
|
// var moneyType = arr[0];
|
// if (GeneralDefine.moneyDisplayIds.ContainsKey(moneyType))
|
// {
|
// items.Add(new Item()
|
// {
|
// id = GeneralDefine.moneyDisplayIds[moneyType],
|
// count = arr[1],
|
// });
|
|
// PushCoinPack(1, moneyType, arr[1]);
|
// }
|
// }
|
|
// ItemLogicUtility.Instance.ShowGetItem(items, "", 0);
|
//}
|
|
//public byte OpType; // 操作类型: 0-抽奖;1-获得金币;2-激活至尊卡
|
public void PushCoinPack(int opType, int moneyType = 0, int value = 0)
|
{
|
var pack = new CAA02_tagCMTuijinbi();
|
pack.OpType = (byte)opType;
|
pack.Value1 = (uint)moneyType;
|
pack.Value2 = (uint)value;
|
GameNetSystem.Instance.SendInfo(pack);
|
|
}
|
|
void OnSecondEvent()
|
{
|
if (dropCoins.Count == 0)
|
return;
|
|
foreach (var key in dropCoins.Keys)
|
{
|
PushCoinPack(1, key, dropCoins[key]);
|
}
|
NoteCoin();
|
dropCoins.Clear();
|
}
|
|
Dictionary<int, int> dropCoins = new Dictionary<int, int>(); //推下去的币 汇总后汇报
|
|
//public byte OpType; // 操作类型: 0-抽奖;1-获得金币;2-激活至尊卡
|
//moneyType 1 金币 2 仙玉币
|
public void DropCoin(int opType, int moneyType = 0, int value = 0)
|
{
|
if (opType == 1)
|
{
|
if (dropCoins.ContainsKey(moneyType))
|
{
|
dropCoins[moneyType] = dropCoins[moneyType] + value;
|
}
|
else
|
{
|
dropCoins[moneyType] = value;
|
}
|
}
|
else
|
{
|
PushCoinPack(opType, moneyType, value);
|
NoteCoin();
|
}
|
|
SoundPlayer.Instance.PlayUIAudio(854);
|
}
|
|
public void UpdateJinbiInfo(HAA05_tagMCTuijinbiInfo netPack)
|
{
|
modelCoinInfo.Clear();
|
|
//登录后初始数量由 DrawNum = 0决定,其他情况为抽奖索引
|
for (int i = 0; i < netPack.PoolPrizeCnt; i++)
|
{
|
var prize = netPack.PoolPrizeList[i];
|
modelCoinInfo[prize.PrizeType] = (int)prize.PrizeCount;
|
}
|
|
OnGetAwardResult?.Invoke(netPack.DrawNum);
|
}
|
|
|
//记录所有币的位置, 下次同设备打开恢复,如果是不同设备则重新掉落
|
public void NoteCoin()
|
{
|
if (UI3DPushCoinStage.Instance == null)
|
return;
|
|
if (UI3DPushCoinStage.Instance.coinParent == null)
|
return;
|
|
Dictionary<int, List<float>> coinsInfo = new Dictionary<int, List<float>>();
|
//位置和数量
|
var coins = UI3DPushCoinStage.Instance.coinParent.GetComponentsInChildren<Transform>();
|
foreach (var coin in coins)
|
{
|
int key = 0;
|
if (coin.name == COINKEY + 1)
|
{
|
key = 1;
|
}
|
else if (coin.name == COINKEY + 2)
|
{
|
key = 2;
|
}
|
else if (coin.name == COINKEY + 4)
|
{
|
key = 4;
|
}
|
else
|
{
|
continue;
|
}
|
//Debug.Log(coin.name + " " + coin.localRotation + " " + coin.localPosition);
|
if (!coinsInfo.ContainsKey(key))
|
{
|
coinsInfo[key] = new List<float>();
|
}
|
|
coinsInfo[key].Add(Mathf.Round(coin.localPosition.x * 100) / 100f);
|
coinsInfo[key].Add(Mathf.Round(coin.localPosition.y * 100) / 100f);
|
coinsInfo[key].Add(Mathf.Round(coin.localPosition.z * 100) / 100f);
|
coinsInfo[key].Add(Mathf.Round(coin.localRotation.x * 100) / 100f);
|
coinsInfo[key].Add(Mathf.Round(coin.localRotation.y * 100) / 100f);
|
coinsInfo[key].Add(Mathf.Round(coin.localRotation.z * 100) / 100f);
|
}
|
|
List<int> ints = new List<int>() { 1, 2, 4};
|
foreach (var key in ints)
|
{
|
int index = ints.IndexOf(key);
|
if (coinsInfo.ContainsKey(key))
|
{
|
var list = coinsInfo[key];
|
var json = JsonMapper.ToJson(list);
|
LocalSave.SetString(PlayerDatas.Instance.baseData.PlayerID + COINKEY + key, json);
|
|
if (key == 4)
|
{
|
int value = (int)Math.Abs(list[2]*100);
|
//Debug.Log(COINKEY + key + ":" + value + "-" + json);
|
//服务端只记录1折币的z距离位置
|
QuickSetting.Instance.SetQuickSetting(QuickSetting.QuickSettingType.PushCoin, string.Format("{0:D3}", value), index);
|
QuickSetting.Instance.SendPackage();
|
}
|
}
|
else
|
{
|
LocalSave.DeleteKey(PlayerDatas.Instance.baseData.PlayerID + COINKEY + key);
|
if (key == 4)
|
{
|
QuickSetting.Instance.SetQuickSetting(QuickSetting.QuickSettingType.PushCoin, "***", index);
|
QuickSetting.Instance.SendPackage();
|
}
|
}
|
}
|
}
|
|
//类型: 1-金币;2-仙玉币
|
public int GetCoinCount(int type)
|
{
|
if (modelCoinInfo.ContainsKey(type))
|
{
|
return modelCoinInfo[type];
|
}
|
return 0;
|
}
|
|
}
|
|
}
|
|