using System;
|
using System.Collections.Generic;
|
using System.Linq;
|
using System.Text;
|
|
namespace vnxbqy.UI
|
{
|
|
|
public class LuckyTreasureModel : Model, IBeforePlayerDataInitialize, IAfterPlayerDataInitialize, IPlayerLoginOk, IOpenServerActivity
|
{
|
public event Action<int> onStateUpdate;
|
public bool isAutoLuckyTreasure = false;
|
private bool isRefreshLoginRed = true;
|
public override void Init()
|
{
|
ParseFuncConfig();
|
StageLoad.Instance.onStageLoadFinish += OnStageLoadFinish;
|
DTCA003_tagUniversalGameRecInfo.onGetUniversalGameInfo += UpdateLuckyMessage;
|
OperationTimeHepler.Instance.operationStartEvent += OperationStartEvent;
|
OperationTimeHepler.Instance.operationEndEvent += OperationEndEvent;
|
OperationTimeHepler.Instance.operationAdvanceEvent += OperationAdvanceEvent;
|
OpenServerActivityCenter.Instance.Register(20, this);
|
}
|
|
public void OnBeforePlayerDataInitialize()
|
{
|
autoLuckyItems.Clear();
|
isAutoLuckyTreasure = false;
|
curLuckValue = 0;
|
curLuckyItem = null;
|
}
|
|
public void OnAfterPlayerDataInitialize()
|
{
|
|
}
|
|
public void OnPlayerLoginOk()
|
{
|
UpdateFreeLuckyTreasureRedpoint();
|
if(isRefreshLoginRed)
|
{
|
UpdateLoginLuckyTreasureRedPoint(isRefreshLoginRed);
|
}
|
isRefreshLoginRed = false;
|
}
|
|
public override void UnInit()
|
{
|
StageLoad.Instance.onStageLoadFinish -= OnStageLoadFinish;
|
DTCA003_tagUniversalGameRecInfo.onGetUniversalGameInfo -= UpdateLuckyMessage;
|
OperationTimeHepler.Instance.operationStartEvent -= OperationStartEvent;
|
OperationTimeHepler.Instance.operationEndEvent -= OperationEndEvent;
|
OperationTimeHepler.Instance.operationAdvanceEvent -= OperationAdvanceEvent;
|
}
|
|
|
private void OnStageLoadFinish()
|
{
|
if (!(StageLoad.Instance.stageType == Stage.E_StageType.Dungeon))
|
{
|
isRefreshLoginRed = true;
|
}
|
}
|
|
public bool IsOpen
|
{
|
get
|
{
|
return OperationTimeHepler.Instance.SatisfyOpenCondition(Operation.LuckyTreasure);
|
}
|
}
|
|
public bool IsAdvance { get { return false; } }
|
|
public bool priorityOpen
|
{
|
get
|
{
|
return OperationTimeHepler.Instance.SatisfyAdvanceCondition(Operation.LuckyTreasure);
|
}
|
}
|
|
public OperationLuckyTreasure GetOperation()
|
{
|
OperationBase operationBase;
|
if (OperationTimeHepler.Instance.TryGetOperationTime(Operation.LuckyTreasure, out operationBase))
|
{
|
return operationBase as OperationLuckyTreasure;
|
}
|
|
return null;
|
}
|
|
private void OperationAdvanceEvent(Operation type)
|
{
|
if (type == Operation.LuckyTreasure)
|
{
|
if (onStateUpdate != null)
|
{
|
onStateUpdate(20);
|
}
|
}
|
}
|
|
private void OperationStartEvent(Operation type, int state)
|
{
|
if (type == Operation.LuckyTreasure && state == 0)
|
{
|
if (onStateUpdate != null)
|
{
|
onStateUpdate(20);
|
}
|
UpdateFreeLuckyTreasureRedpoint();
|
}
|
}
|
|
private void OperationEndEvent(Operation type, int state)
|
{
|
if (type == Operation.LuckyTreasure && state == 0)
|
{
|
if (onStateUpdate != null)
|
{
|
onStateUpdate(20);
|
}
|
UpdateFreeLuckyTreasureRedpoint();
|
UpdateLoginLuckyTreasureRedPoint(false);
|
}
|
}
|
|
|
#region 表数据
|
public int luckyTreasurePrice { get; private set; }
|
public int luckyTreasurePoint { get; private set; }
|
public void ParseFuncConfig()
|
{
|
var luckyAppraisal = FuncConfigConfig.Get("LuckyAppraisal");
|
luckyTreasurePrice = int.Parse(luckyAppraisal.Numerical1);
|
luckyTreasurePoint = int.Parse(luckyAppraisal.Numerical2);
|
}
|
#endregion
|
|
#region 协议
|
public int curLuckValue { get; private set; }
|
public bool isFree { get; private set; }
|
public OperationLuckyTreasure.LuckyTreasureItem curLuckyItem { get; private set; }
|
public List<OperationLuckyTreasure.LuckyTreasureItem> autoLuckyItems = new List<OperationLuckyTreasure.LuckyTreasureItem>();
|
public event Action UpdateLuckyResultEvent;
|
public event Action UpdateMessageEvent;
|
|
public void UpdateLuckyTreasureResult(HAA1E_tagMCLuckyTreasureResultInfo resultInfo)
|
{
|
curLuckValue = resultInfo.LuckyPoint;
|
isFree = resultInfo.HasFree == 0;
|
if (resultInfo.ItemID != 0)
|
{
|
curLuckyItem = new OperationLuckyTreasure.LuckyTreasureItem((int)resultInfo.ItemID, resultInfo.ItemCnt, resultInfo.IsBind);
|
if (isAutoLuckyTreasure)
|
{
|
var luckyItem = new OperationLuckyTreasure.LuckyTreasureItem((int)resultInfo.ItemID, resultInfo.ItemCnt, resultInfo.IsBind);
|
autoLuckyItems.Add(luckyItem);
|
}
|
}
|
if (UpdateLuckyResultEvent != null)
|
{
|
UpdateLuckyResultEvent();
|
}
|
|
if(IsBigLuckItem())
|
{
|
if (!WindowCenter.Instance.IsOpen<BestLuckyTreasureItemWin>())
|
{
|
WindowCenter.Instance.Open<BestLuckyTreasureItemWin>();
|
}
|
}
|
UpdateFreeLuckyTreasureRedpoint();
|
}
|
|
public List<string> resultInfolist = new List<string>();
|
public void UpdateLuckyMessage(HA003_tagUniversalGameRecInfo recInfo)
|
{
|
if (recInfo.Type != 12) return;
|
|
resultInfolist.Clear();
|
|
for(int i = recInfo.Count - 1; i > -1; i--)
|
{
|
string playerName = recInfo.UniversalGameRec[i].StrValue1;
|
resultInfolist.Add(playerName);
|
}
|
|
if (UpdateMessageEvent != null)
|
{
|
UpdateMessageEvent();
|
}
|
}
|
|
public void SendStartLuckyTreasure()
|
{
|
if (!IsSatifyLuckyTreasure()) return;
|
|
CAA08_tagCMStartLuckyTreasure startLuckyTreasure = new CAA08_tagCMStartLuckyTreasure();
|
GameNetSystem.Instance.SendInfo(startLuckyTreasure);
|
}
|
#endregion
|
|
public bool IsBigLuckItem()
|
{
|
var operation = GetOperation();
|
if (operation != null)
|
{
|
if (curLuckyItem != null)
|
{
|
OperationLuckyTreasure.LuckyTreasureItem luckyItem = null;
|
if (operation.TryGetLuckBigAward(out luckyItem))
|
{
|
return luckyItem.itemId == curLuckyItem.itemId;
|
}
|
}
|
}
|
return false;
|
}
|
|
public bool IsSatifyLuckyTreasure()
|
{
|
if (!IsEnoughMoney()) return false;
|
|
var playerPack = ModelCenter.Instance.GetModel<PackModel>();
|
int remainGrid = playerPack.GetEmptyGridCount(PackType.Item);
|
if (remainGrid < 1)
|
{
|
isAutoLuckyTreasure = false;
|
SysNotifyMgr.Instance.ShowTip("GeRen_chenxin_676165", (int)PackType.Item);
|
return false;
|
}
|
return true;
|
}
|
|
public bool IsEnoughMoney()
|
{
|
if (!isFree)
|
{
|
ulong haveMoney = UIHelper.GetMoneyCnt(1);
|
if (haveMoney < (ulong)luckyTreasurePrice)
|
{
|
isAutoLuckyTreasure = false;
|
WindowCenter.Instance.Open<RechargeTipWin>();
|
return false;
|
}
|
}
|
return true;
|
}
|
|
#region 红点逻辑
|
public const int LuckyTreasureKey = 20920;
|
public Redpoint luckyTreasureRedpoint = new Redpoint(MainRedDot.REDPOINT_OPENSERVER,LuckyTreasureKey);
|
public const int FreeLuckyTreasureKey = 2092001;
|
public Redpoint freeLuckyTreasureRedpoint = new Redpoint(LuckyTreasureKey,FreeLuckyTreasureKey);
|
public const int LoginLuckyTreasureKey = 2092002;
|
public Redpoint LoginLuckyTreasureRedpoint = new Redpoint(LuckyTreasureKey, LoginLuckyTreasureKey);
|
|
public void UpdateLoginLuckyTreasureRedPoint(bool isLogin)
|
{
|
LoginLuckyTreasureRedpoint.state = RedPointState.None;
|
if (!IsOpen) return;
|
|
if (isLogin)
|
{
|
LoginLuckyTreasureRedpoint.state = RedPointState.Simple;
|
}
|
}
|
|
public void UpdateFreeLuckyTreasureRedpoint()
|
{
|
freeLuckyTreasureRedpoint.state = RedPointState.None;
|
if (!IsOpen || !isFree) return;
|
|
freeLuckyTreasureRedpoint.state = RedPointState.Simple;
|
}
|
#endregion
|
}
|
}
|