using System;
|
using vnxbqy.UI;
|
|
using UnityEngine;
|
using System.Collections.Generic;
|
using System.Collections;
|
using System.Text;
|
|
|
public class PlayerDeadModel : Model, IBeforePlayerDataInitialize, IPlayerLoginOk
|
{
|
public int[] dungeonKillArray { get; private set; }
|
public int deadBuffId { get; private set; }
|
public int maxDeadBuffLV { get; private set; }
|
|
public override void Init()
|
{
|
isKillByPlayer = false;
|
FuncConfigConfig funcConfig = FuncConfigConfig.Get("RebornArguments");
|
dungeonKillArray = ConfigParse.GetMultipleStr<int>(funcConfig.Numerical2);
|
RebornConditions = ConfigParse.GetMultipleStr<int>(funcConfig.Numerical1);
|
FuncConfigConfig RebornTime = FuncConfigConfig.Get("DuplicatesRebornTime");
|
duplicatesRebornDict = ConfigParse.GetDic<int, int>(RebornTime.Numerical1);
|
FuncConfigConfig ElderBattlefieldRobot = FuncConfigConfig.Get("ElderBattlefieldRobot");
|
deadBuffId = int.Parse(ElderBattlefieldRobot.Numerical3);
|
maxDeadBuffLV = int.Parse(ElderBattlefieldRobot.Numerical4);
|
SysNotifyMgr.Instance.sysNotifyEvent += RefreshPlayerDieInfo;
|
}
|
|
public void OnBeforePlayerDataInitialize()
|
{
|
npcRealmLv = 0;
|
IsCanReborn = false;
|
isOpenPrompting = true;
|
this.deadCD = 0;
|
localBossState = false;
|
}
|
|
public void OnPlayerLoginOk()
|
{
|
PlayerDatas.Instance.playerDataRefreshEvent -= AddlistenPlayerHP;
|
PlayerDatas.Instance.playerDataRefreshEvent += AddlistenPlayerHP;
|
}
|
|
public override void UnInit()
|
{
|
SysNotifyMgr.Instance.sysNotifyEvent -= RefreshPlayerDieInfo;
|
}
|
|
public Action<int> RefreshDeadCDEvent;
|
public Action<int> RefreshDuplicatesRebornCDEvent; //副本死亡倒计时事件
|
public event Action playerDieEvent;
|
public event Action<uint> AllPlayerDieEvent;
|
public event Action<H0419_tagPlayerReborn> AllPlayerRebornEvent;
|
|
public event Action CloseRebornWinEvent;
|
|
public float autoRebornTime = 0;
|
public float deadCD = 0; //距离复活的时间
|
public float deadTiredCD = 300; //距离清除复活疲劳的时间
|
public int rebornPrice = 20;
|
public int rebornTiredNum = 0;
|
private int playerCoins = 0;
|
private FuncConfigConfig _tagfuncModel;
|
public int[] RebornConditions { get; private set; }
|
private MapConfig _tagMapModel;
|
public bool isBossKill = false;
|
public float duplicatesRebornTime = 0;
|
private Dictionary<int, int> duplicatesRebornDict;
|
public bool playerIsDie {
|
get {
|
|
if (PlayerDatas.Instance.hero != null)
|
{
|
return PlayerDatas.Instance.hero.ActorInfo.serverDie;
|
}
|
return false;
|
}
|
}
|
|
DungeonModel dungeonModel { get { return ModelCenter.Instance.GetModel<DungeonModel>(); } }
|
StoreModel m_storeModel { get { return ModelCenter.Instance.GetModel<StoreModel>(); } }
|
PackModel playerPack { get { return ModelCenter.Instance.GetModel<PackModel>(); } }
|
ActivityModel activityModel { get { return ModelCenter.Instance.GetModel<ActivityModel>(); } }
|
|
private DungeonOpenTimeConfig _dungeonOpenTimeModel;
|
|
public bool IsCanReborn { get; private set; }
|
public bool localBossState { get; private set; }
|
public string killerName { get; private set; }
|
public bool isKillByPlayer { get; private set; }
|
public int npcRealmLv { get; private set; }
|
private void RefreshPlayerDieInfo(string key, ArrayList infolist)
|
{
|
npcRealmLv = 0;
|
localBossState = false;
|
switch (key)
|
{
|
case "PK_lhs_318691":
|
if (infolist.Count > 0)
|
{
|
killerName = infolist[0].ToString();
|
isKillByPlayer = true;
|
}
|
break;
|
case "GeRen_chenxin_279029":
|
if (infolist.Count > 0)
|
{
|
WorldBossConfig bossConfig = WorldBossConfig.Get(int.Parse(infolist[0].ToString()));
|
NPCConfig nPCConfig = NPCConfig.Get(int.Parse(infolist[0].ToString()));
|
if (nPCConfig != null)
|
{
|
killerName = nPCConfig.charName;
|
npcRealmLv = nPCConfig.Realm;
|
}
|
if (bossConfig != null || BossHomeConfig.Get(int.Parse(infolist[0].ToString())) != null)
|
{
|
localBossState = true;
|
}
|
isKillByPlayer = false;
|
}
|
break;
|
case "RobotKill_1":
|
if (infolist.Count > 1)
|
{
|
int objId = int.Parse(infolist[0].ToString());
|
int npcId = int.Parse(infolist[1].ToString());
|
killerName = activityModel.GetAncientRobotName(objId, npcId);
|
isKillByPlayer = false;
|
}
|
|
break;
|
}
|
}
|
|
public bool CheckIsRealmSuppress(out StringBuilder builder)
|
{
|
builder = new StringBuilder();
|
if (npcRealmLv > PlayerDatas.Instance.baseData.realmLevel)
|
{
|
var curRealmConfig = RealmConfig.Get(npcRealmLv);
|
builder.AppendFormat("<Img img={0}/>", curRealmConfig.Img);
|
return true;
|
}
|
|
return false;
|
}
|
|
private void AddlistenPlayerHP(PlayerDataType type)
|
{
|
if (type != PlayerDataType.HP || PlayerDatas.Instance.baseData.HP > 0 || playerIsDie) return;
|
|
PlayerDie(PlayerDatas.Instance.baseData.PlayerID);
|
}
|
|
public void PlayerDie(uint playerId)
|
{
|
IsCanReborn = false;
|
if (AllPlayerDieEvent != null) AllPlayerDieEvent(playerId);
|
|
if (playerId != PlayerDatas.Instance.baseData.PlayerID)
|
{
|
return;
|
}
|
_tagMapModel = MapConfig.Get(PlayerDatas.Instance.baseData.MapID);
|
rebornTiredNum = RebornConditions[0];
|
rebornPrice = RebornConditions[2];
|
if (_tagMapModel.MapFBType == 0 || PlayerDatas.Instance.baseData.MapID == 31020)
|
{
|
IsCanReborn = true;
|
//isBossKill = StatusManager.Instance.IsExist((int)playerId,20022);
|
if (!isKillByPlayer && localBossState)
|
{
|
autoRebornTime = RebornConditions[3];
|
}
|
|
if (!WindowCenter.Instance.IsOpen<RebornWin>())
|
{
|
WindowCenter.Instance.Open<RebornWin>();
|
}
|
|
}
|
else
|
{
|
_dungeonOpenTimeModel = DungeonOpenTimeConfig.Get(dungeonModel.GetDataMapIdByMapId(PlayerDatas.Instance.baseData.MapID));
|
if (_dungeonOpenTimeModel == null)
|
return;
|
|
if (_dungeonOpenTimeModel.DeathTime == 1)
|
{
|
IsCanReborn = true;
|
if (!duplicatesRebornDict.ContainsKey(PlayerDatas.Instance.baseData.MapID))
|
{
|
this.duplicatesRebornTime = duplicatesRebornDict[0];
|
}
|
else
|
{
|
this.duplicatesRebornTime = duplicatesRebornDict[PlayerDatas.Instance.baseData.MapID];
|
}
|
|
TimeDownMgr.Instance.Begin(TimeDownMgr.CoolTimeType.DuplicatesReborn, this.duplicatesRebornTime, RefreshDuplicatesRebornCD);
|
int dataMapID = dungeonModel.GetDataMapIdByMapId(PlayerDatas.Instance.baseData.MapID);
|
switch (dataMapID)
|
{
|
case 31150:
|
if (dungeonModel.mission.score >= 100)
|
{
|
if (!WindowCenter.Instance.IsOpen<ElderGodAreaExitWin>())
|
{
|
WindowCenter.Instance.Open<ElderGodAreaExitWin>();
|
}
|
}
|
else
|
{
|
if (!WindowCenter.Instance.IsOpen<ElderGodAreaRebornWin>())
|
{
|
WindowCenter.Instance.Open<ElderGodAreaRebornWin>();
|
}
|
}
|
break;
|
case 31110:
|
if (dungeonModel.mission.leaderID != playerId)
|
{
|
if (!WindowCenter.Instance.IsOpen<ReliveWin>())
|
{
|
WindowCenter.Instance.Open<ReliveWin>();
|
}
|
}
|
break;
|
case GeneralDefine.CrossBattleFieldMapID:
|
if (!WindowCenter.Instance.IsOpen("CrossServerBattleFieldRebornWin"))
|
{
|
WindowCenter.Instance.Open("CrossServerBattleFieldRebornWin");
|
}
|
break;
|
case GeneralDefine.CrossFamilyBattleMapID:
|
if (!WindowCenter.Instance.IsOpen("CrossServerFamilyBattleRebornWin"))
|
{
|
WindowCenter.Instance.Open("CrossServerFamilyBattleRebornWin");
|
}
|
break;
|
default:
|
if (!WindowCenter.Instance.IsOpen<ReliveWin>())
|
{
|
WindowCenter.Instance.Open<ReliveWin>();
|
}
|
break;
|
|
}
|
}
|
else
|
{
|
IsCanReborn = false;
|
}
|
|
}
|
|
if (playerDieEvent != null)
|
playerDieEvent();
|
|
}
|
|
public void RefreshDeadModel(HB103_tagMCPlayerDeadTime data)
|
{
|
if (data.DeadTime == 0)
|
return;
|
|
double timeOffest = GetTimeOffest(TimeUtility.GetTime(data.DeadTime));
|
if (timeOffest <= RebornConditions[1])
|
{
|
if (timeOffest < 0)
|
timeOffest = 0;
|
|
this.deadCD = RebornConditions[1] - (float)timeOffest;
|
TimeDownMgr.Instance.Begin(TimeDownMgr.CoolTimeType.DeadCD, this.deadCD, RefreshDeadCD);
|
}
|
|
}
|
|
public void RebornSuccess(H0419_tagPlayerReborn data)
|
{
|
if (AllPlayerRebornEvent != null) AllPlayerRebornEvent(data);
|
if (PlayerDatas.Instance.baseData.PlayerID != data.PlayerID)
|
return;
|
|
localBossState = false;
|
this.deadCD = 0;
|
isKillByPlayer = false;
|
TimeDownMgr.Instance.Stop(TimeDownMgr.CoolTimeType.DeadCD);
|
TimeDownMgr.Instance.Stop(TimeDownMgr.CoolTimeType.BossAutoReborn);
|
TimeDownMgr.Instance.Stop(TimeDownMgr.CoolTimeType.DuplicatesReborn);
|
WindowCenter.Instance.Close<RebornWin>();
|
WindowCenter.Instance.Close<ReliveWin>();
|
WindowCenter.Instance.Close<RebornTiredWin>();
|
WindowCenter.Instance.Close<ElderGodAreaRebornWin>();
|
|
if (CloseRebornWinEvent != null)
|
{
|
CloseRebornWinEvent();
|
}
|
}
|
|
private void RefreshDeadCD(float obj)
|
{
|
this.deadCD = obj;
|
|
if (RefreshDeadCDEvent != null)
|
RefreshDeadCDEvent(Mathf.RoundToInt(obj));
|
}
|
|
private void RefreshDuplicatesRebornCD(float obj)
|
{
|
if (RefreshDuplicatesRebornCDEvent != null)
|
RefreshDuplicatesRebornCDEvent(Mathf.RoundToInt(obj));
|
}
|
|
|
public bool IsCanInplaceReborn(int rebornPrice)
|
{
|
playerCoins = (int)PlayerDatas.Instance.baseData.diamond;
|
if (playerCoins >= rebornPrice)
|
return true;
|
else
|
return false;
|
|
}
|
|
public bool IsRebornCoinsEnough()
|
{
|
int rebornCoins = playerPack.GetItemCountByID(PackType.Item, 2107);
|
if (rebornCoins >= 1)
|
{
|
return true;
|
}
|
return false;
|
}
|
|
private bool isOpenPrompting = true;
|
public void InpacleReborn()
|
{
|
ItemConfig itemConfig = ItemConfig.Get(2107);
|
if (isOpenPrompting)
|
{
|
ConfirmCancel.IconConfirmCancel(Language.Get("Mail101"), Language.Get("PlayerReborn102", itemConfig.ItemName), itemConfig.ID,
|
playerPack.GetItemCountByID(PackType.Item, itemConfig.ID), 1, Language.Get("PlayerReborn105", rebornPrice), Language.Get("ConfirmCancel102"), (bool isOk, bool isToggle) =>
|
{
|
if (isOk)
|
{
|
CheckInpacleReborn();
|
}
|
isOpenPrompting = !isToggle;
|
});
|
}
|
else
|
{
|
CheckInpacleReborn();
|
}
|
|
}
|
|
public void CheckInpacleReborn()
|
{
|
if (IsRebornCoinsEnough())
|
{
|
SendRebornQuest(3);
|
}
|
else
|
{
|
if (!IsCanInplaceReborn(rebornPrice))
|
{
|
if (VersionConfig.Get().isBanShu)
|
{
|
SysNotifyMgr.Instance.ShowTip("GoldErr");
|
return;
|
}
|
WindowCenter.Instance.Open<RechargeTipWin>();
|
}
|
else
|
{
|
SendRebornQuest(2);
|
|
}
|
}
|
}
|
|
public double GetTimeOffest(DateTime dieTime)
|
{
|
DebugEx.Log("现在时间" + TimeUtility.ServerNow);
|
TimeSpan t = TimeUtility.ServerNow - dieTime;
|
return t.TotalSeconds;
|
}
|
|
/// <summary>
|
/// 发送复活请求 2 原地复活 0 安全区复活 3 复活币复活
|
/// </summary>
|
/// <param name="rebornType"></param>
|
public void SendRebornQuest(int rebornType)
|
{
|
C0305_tagCCliectReborn reborn = new C0305_tagCCliectReborn();
|
reborn.Type = (byte)rebornType;
|
GameNetSystem.Instance.SendInfo(reborn);
|
}
|
}
|