using System.Collections;
|
using System.Collections.Generic;
|
using UnityEngine;
|
|
using System;
|
|
namespace vnxbqy.UI
|
{
|
|
|
public class JadeDynastyBossModel : Model, IBeforePlayerDataInitialize, IPlayerLoginOk, IAfterPlayerDataInitialize
|
{
|
List<JadeDynastyBossData> jadeDynastyBosses = new List<JadeDynastyBossData>();
|
Dictionary<int, JadeDynastyBossLine> jadeDynastyBossLineDict = new Dictionary<int, JadeDynastyBossLine>();
|
Dictionary<int, List<Item>> dropItemDict = new Dictionary<int, List<Item>>();
|
|
public const int JADEDYNASTY_MAP = 31380;
|
public const int FUNCTIONID = 163;
|
public const int JADEDYNASTY_REDPOINTID = 77003;
|
|
public event Action<int> selectBossRefresh;
|
public event Action bossLineRefresh;
|
public event Action jadeDynastyScoreRefresh;
|
|
public int challengeLimitCount { get; private set; }
|
public int challengeTimes { get; private set; }
|
|
int m_SelectBossId = 0;
|
public int selectBossId
|
{
|
get { return m_SelectBossId; }
|
set
|
{
|
if (m_SelectBossId != value)
|
{
|
m_SelectBossId = value;
|
if (selectBossRefresh != null)
|
{
|
selectBossRefresh(value);
|
}
|
}
|
}
|
}
|
|
public int assginSelectBossId { get; set; }
|
|
public readonly Redpoint redpoint = new Redpoint(FindPreciousModel.FINDPRECIOUS_REDPOINTID, JADEDYNASTY_REDPOINTID);
|
|
MapModel mapModel { get { return ModelCenter.Instance.GetModel<MapModel>(); } }
|
DungeonModel dungeonModel { get { return ModelCenter.Instance.GetModel<DungeonModel>(); } }
|
FindPreciousModel findPreciousModel { get { return ModelCenter.Instance.GetModel<FindPreciousModel>(); } }
|
PackModel packModel { get { return ModelCenter.Instance.GetModel<PackModel>(); } }
|
public override void Init()
|
{
|
//ParseConfig();
|
|
}
|
|
public void OnBeforePlayerDataInitialize()
|
{
|
jadeDynastyBossLineDict.Clear();
|
challengeTimes = 0;
|
}
|
|
public void OnAfterPlayerDataInitialize()
|
{
|
}
|
|
public void OnPlayerLoginOk()
|
{
|
//UpdateRedpoint();
|
|
//var bossId = GetLatestUnLockBoss();
|
//AutoSubscribeLastUnLockBoss(bossId);
|
}
|
|
public override void UnInit()
|
{
|
|
}
|
|
void ParseConfig()
|
{
|
{
|
var configs = JadeDynastyBossConfig.GetValues();
|
foreach (var config in configs)
|
{
|
var dungeonId = dungeonModel.GetDungeonId(JADEDYNASTY_MAP, config.LineID);
|
var dungeonConfig = DungeonConfig.Get(dungeonId);
|
jadeDynastyBosses.Add(new JadeDynastyBossData()
|
{
|
bossNpcId = config.NPCID,
|
lineId = config.LineID,
|
challengeCondition = new JadeDynastyBossCondition()
|
{
|
level = dungeonConfig.LVLimitMin,
|
realmLevel = config.RealmLV,
|
},
|
conditionSorts = new List<int>(config.conditionSorts),
|
});
|
|
var itemArray = LitJson.JsonMapper.ToObject<int[][]>(config.dropItems);
|
List<Item> list = new List<Item>();
|
for (int k = 0; k < itemArray.Length; k++)
|
{
|
Item item = new Item()
|
{
|
id = itemArray[k][0],
|
count = itemArray[k][1],
|
};
|
list.Add(item);
|
}
|
dropItemDict.Add(config.NPCID, list);
|
}
|
|
jadeDynastyBosses.Sort(SortCompare);
|
}
|
|
{
|
var config = FuncConfigConfig.Get("ZhuXianBossCntCfg");
|
challengeLimitCount = int.Parse(config.Numerical2);
|
}
|
}
|
|
private void AutoSubscribeLastUnLockBoss(int _bossId)
|
{
|
if (_bossId == 0)
|
{
|
return;
|
}
|
|
foreach (var boss in jadeDynastyBosses)
|
{
|
if (findPreciousModel.IsBossAutoSubscribe(boss.bossNpcId) && boss.bossNpcId != _bossId)
|
{
|
findPreciousModel.RequestDeSubscribeBoss(boss.bossNpcId);
|
}
|
}
|
|
if (_bossId != 0 && findPreciousModel.IsBossNeverSubscribe((int)_bossId))
|
{
|
var condition = 0;
|
if (IsBossUnLocked(_bossId, out condition))
|
{
|
var config = JadeDynastyBossConfig.Get(_bossId);
|
if (config.AutoAttention == 1)
|
{
|
findPreciousModel.RequestSubscribeBoss((int)_bossId, true);
|
if (findPreciousModel.IsBossAlive((int)_bossId))
|
{
|
findPreciousModel.AddOneBossRebornNotify(_bossId);
|
}
|
}
|
}
|
}
|
}
|
|
public bool IsJadeDynastyBoss(int bossNpcId)
|
{
|
var index = jadeDynastyBosses.FindIndex((x) =>
|
{
|
return x.bossNpcId == bossNpcId;
|
});
|
return index >= 0;
|
}
|
|
public bool IsBossUnLocked(int bossNpcId, out int condition)
|
{
|
condition = 0;
|
var index = jadeDynastyBosses.FindIndex((x) =>
|
{
|
return x.bossNpcId == bossNpcId;
|
});
|
if (index != -1)
|
{
|
var boss = jadeDynastyBosses[index];
|
var challengeCondition = jadeDynastyBosses[index].challengeCondition;
|
foreach (var code in boss.conditionSorts)
|
{
|
switch (code)
|
{
|
case 1:
|
if (PlayerDatas.Instance.baseData.LV < challengeCondition.level)
|
{
|
condition = 1;
|
return false;
|
}
|
break;
|
case 2:
|
if (PlayerDatas.Instance.baseData.realmLevel < challengeCondition.realmLevel)
|
{
|
condition = 2;
|
return false;
|
}
|
break;
|
}
|
}
|
if (PlayerDatas.Instance.baseData.LV < challengeCondition.level)
|
{
|
condition = 1;
|
return false;
|
}
|
if (PlayerDatas.Instance.baseData.realmLevel < challengeCondition.realmLevel)
|
{
|
condition = 2;
|
return false;
|
}
|
}
|
else
|
{
|
return false;
|
}
|
return true;
|
}
|
|
public List<int> GetJadeDynastyBosses()
|
{
|
List<int> list = new List<int>();
|
foreach (var boss in jadeDynastyBosses)
|
{
|
list.Add(boss.bossNpcId);
|
}
|
return list;
|
}
|
|
public int GetParticipantCount(int bossId)
|
{
|
var index = jadeDynastyBosses.FindIndex((x) =>
|
{
|
return x.bossNpcId == bossId;
|
});
|
var lineId = -1;
|
if (index != -1)
|
{
|
lineId = jadeDynastyBosses[index].lineId;
|
}
|
if (jadeDynastyBossLineDict.ContainsKey(lineId))
|
{
|
return jadeDynastyBossLineDict[lineId].playerCount;
|
}
|
return 0;
|
}
|
|
public int GetLatestUnLockBoss()
|
{
|
if (FuncOpen.Instance.IsFuncOpen(FUNCTIONID))
|
{
|
var latestBossId = jadeDynastyBosses[0].bossNpcId;
|
foreach (var boss in jadeDynastyBosses)
|
{
|
var condition = 0;
|
if (IsBossUnLocked(boss.bossNpcId, out condition))
|
{
|
latestBossId = boss.bossNpcId;
|
}
|
}
|
return latestBossId;
|
}
|
else
|
{
|
return jadeDynastyBosses[0].bossNpcId;
|
}
|
}
|
|
public int GetRecommandBoss()
|
{
|
var bosses = new List<int>();
|
foreach (var boss in jadeDynastyBosses)
|
{
|
bosses.Add(boss.bossNpcId);
|
}
|
bosses.Sort(FindPreciousModel.BossCompare);
|
|
var preferBoss = 0;
|
for (int i = bosses.Count - 1; i >= 0; i--)
|
{
|
var bossId = bosses[i];
|
var condition = 0;
|
if (IsBossUnLocked(bossId, out condition)
|
&& findPreciousModel.IsPlayerLevelLargerOrBiggerThanBoss(bossId))
|
{
|
if (preferBoss == 0)
|
{
|
preferBoss = bossId;
|
}
|
|
if (findPreciousModel.IsBossAlive(bossId)
|
&& findPreciousModel.IsSameBigRealmStageBoss(bossId))
|
{
|
return bossId;
|
}
|
}
|
}
|
|
if (preferBoss == 0)
|
{
|
preferBoss = bosses[0];
|
}
|
|
return preferBoss;
|
}
|
|
public bool TryGetDropItems(int bossId, out List<Item> dropItems)
|
{
|
return dropItemDict.TryGetValue(bossId, out dropItems);
|
}
|
|
public bool TryGetCondition(int bossId, out JadeDynastyBossCondition condition)
|
{
|
var index = jadeDynastyBosses.FindIndex((x) =>
|
{
|
return x.bossNpcId == bossId;
|
});
|
condition = default(JadeDynastyBossCondition);
|
if (index != -1)
|
{
|
condition = jadeDynastyBosses[index].challengeCondition;
|
}
|
return index != -1;
|
}
|
|
public bool TryGetBossLine(int bossId, out JadeDynastyBossLine mapLineState)
|
{
|
var index = jadeDynastyBosses.FindIndex((x) =>
|
{
|
return x.bossNpcId == bossId;
|
});
|
var lineId = -1;
|
if (index != -1)
|
{
|
lineId = jadeDynastyBosses[index].lineId;
|
}
|
return jadeDynastyBossLineDict.TryGetValue(lineId, out mapLineState);
|
}
|
|
public bool TryEnterDungeon(int bossId,out int error)
|
{
|
var condition = 0;
|
error = 0;
|
if (!IsBossUnLocked(bossId, out condition))
|
{
|
switch (condition)
|
{
|
case 1:
|
error = 1;
|
break;
|
case 2:
|
error = 2;
|
break;
|
case 3:
|
error = 3;
|
break;
|
}
|
return false;
|
}
|
|
var totalTimes = dungeonModel.GetTotalTimes(JADEDYNASTY_MAP);
|
var enterTimes = dungeonModel.GetEnterTimes(JADEDYNASTY_MAP);
|
if (enterTimes >= totalTimes)
|
{
|
error = 4;
|
return false;
|
}
|
|
if (!findPreciousModel.IsBossAlive(bossId))
|
{
|
error = 5;
|
return false;
|
}
|
|
if (CrossServerUtility.IsCrossServer())
|
{
|
error = 6;
|
return false;
|
}
|
return true;
|
}
|
|
public void DisplayErrorTip(int error)
|
{
|
switch (error)
|
{
|
case 1:
|
SysNotifyMgr.Instance.ShowTip("TryEnterJadeDynastyBossError_1");
|
break;
|
case 2:
|
SysNotifyMgr.Instance.ShowTip("TryEnterJadeDynastyBossError_2");
|
break;
|
case 3:
|
SysNotifyMgr.Instance.ShowTip("TryEnterJadeDynastyBossError_3");
|
break;
|
case 4:
|
SysNotifyMgr.Instance.ShowTip("TryEnterJadeDynastyBossError_4");
|
break;
|
case 5:
|
SysNotifyMgr.Instance.ShowTip("TryEnterJadeDynastyBossError_5");
|
break;
|
case 6:
|
SysNotifyMgr.Instance.ShowTip("CrossMap10");
|
break;
|
}
|
}
|
|
public void OnReceivePackage(HA007_tagGCFBLinePlayerCnt package)
|
{
|
if (package.MapID != JADEDYNASTY_MAP)
|
{
|
return;
|
}
|
|
jadeDynastyBossLineDict.Clear();
|
for (int i = 0; i < package.Count; i++)
|
{
|
var mapState = package.FBLineInfoList[i];
|
jadeDynastyBossLineDict[mapState.FBLineID] = new JadeDynastyBossLine()
|
{
|
playerCount = mapState.PlayerCnt,
|
belongToPlayerName = mapState.ExtraStr,
|
};
|
}
|
|
if (bossLineRefresh != null)
|
{
|
bossLineRefresh();
|
}
|
}
|
|
public static int SortCompare(JadeDynastyBossData lhs, JadeDynastyBossData rhs)
|
{
|
if (lhs.challengeCondition.level != rhs.challengeCondition.level)
|
{
|
return lhs.challengeCondition.level.CompareTo(rhs.challengeCondition.level);
|
}
|
if (lhs.challengeCondition.realmLevel != rhs.challengeCondition.realmLevel)
|
{
|
return lhs.challengeCondition.realmLevel.CompareTo(rhs.challengeCondition.realmLevel);
|
}
|
return 0;
|
}
|
|
private void OnDungeonRecordUpdate(int _dataMapId)
|
{
|
if (JADEDYNASTY_MAP == _dataMapId)
|
{
|
UpdateRedpoint();
|
}
|
}
|
|
private void OnDungeonBuyCount()
|
{
|
UpdateRedpoint();
|
}
|
|
private void OnFuncStateChangeEvent(int id)
|
{
|
if (id == FUNCTIONID)
|
{
|
UpdateRedpoint();
|
var bossId = GetLatestUnLockBoss();
|
AutoSubscribeLastUnLockBoss(bossId);
|
}
|
}
|
|
private void PlayerDataRefreshInfoEvent(PlayerDataType refreshType)
|
{
|
if(refreshType==PlayerDataType.RealmLevel
|
|| refreshType == PlayerDataType.LV)
|
{
|
UpdateRedpoint();
|
if (FuncOpen.Instance.IsFuncOpen(FUNCTIONID))
|
{
|
var bossId = GetLatestUnLockBoss();
|
AutoSubscribeLastUnLockBoss(bossId);
|
}
|
}
|
}
|
|
private void RefreshItemCountAct(PackType packType, int arg2, int arg3)
|
{
|
}
|
|
void UpdateRedpoint()
|
{
|
if (FuncOpen.Instance.IsFuncOpen(FUNCTIONID))
|
{
|
var existAnyChallengeable = false;
|
var condition = 0;
|
foreach (var boss in jadeDynastyBosses)
|
{
|
if (IsBossUnLocked(boss.bossNpcId, out condition))
|
{
|
existAnyChallengeable = true;
|
break;
|
}
|
}
|
if (existAnyChallengeable)
|
{
|
var count = dungeonModel.GetTotalTimes(JADEDYNASTY_MAP) - dungeonModel.GetEnterTimes(JADEDYNASTY_MAP);
|
redpoint.count = count;
|
}
|
else
|
{
|
redpoint.count = 0;
|
}
|
}
|
else
|
{
|
redpoint.count = 0;
|
}
|
|
redpoint.state = redpoint.count > 0 ? RedPointState.Quantity : RedPointState.None;
|
}
|
}
|
|
public struct JadeDynastyBossData
|
{
|
public int bossNpcId;
|
public int lineId;
|
public JadeDynastyBossCondition challengeCondition;
|
public List<int> conditionSorts;
|
}
|
|
public struct JadeDynastyBossCondition
|
{
|
public int level;
|
public int realmLevel;
|
}
|
|
public struct JadeDynastyBossLine
|
{
|
public int playerCount;
|
public string belongToPlayerName;
|
}
|
}
|
|