//--------------------------------------------------------
|
// [Author]: 第二世界
|
// [ Date ]: Thursday, December 21, 2017
|
//--------------------------------------------------------
|
using LitJson;
|
using System;
|
using System.Collections.Generic;
|
|
namespace vnxbqy.UI
|
{
|
|
|
public class DemonJarModel : Model, IBeforePlayerDataInitialize, IAfterPlayerDataInitialize, ISwitchAccount, IPlayerLoginOk
|
{
|
public const int TOTALTIME_LIMIT = 3;
|
|
public const int SINGLEMAPID = 52020;
|
public const int DATA_MAPID = 52010;
|
public const int DEMONJAR_REDPOINTID = 77001;
|
|
public Redpoint redpoint = new Redpoint(FindPreciousModel.FINDPRECIOUS_REDPOINTID, DEMONJAR_REDPOINTID);
|
|
public bool oldDouble = false;
|
|
bool m_IsDoubleAward = false;
|
public bool isDoubleAward {
|
get { return m_IsDoubleAward; }
|
set {
|
if (m_IsDoubleAward != value)
|
{
|
m_IsDoubleAward = value;
|
|
if (doubleAwardChangeEvent != null)
|
{
|
doubleAwardChangeEvent();
|
}
|
}
|
}
|
}
|
|
bool m_AutoChallenge = false;
|
public bool autoChallenge {
|
get { return m_AutoChallenge; }
|
set {
|
if (m_AutoChallenge != value)
|
{
|
m_AutoChallenge = value;
|
if (autoChallengeChangeEvent != null)
|
{
|
autoChallengeChangeEvent();
|
}
|
}
|
}
|
}
|
|
public int autoChallengeBoss { get; set; }
|
public bool doubleToKillLowerBossHint { get; set; }
|
public bool lockSelectedBoss = false;
|
|
int m_SelectedBoss = 0;
|
public int selectedBoss {
|
get {
|
return this.m_SelectedBoss;
|
}
|
set {
|
if (this.m_SelectedBoss != value)
|
{
|
this.m_SelectedBoss = value;
|
if (bossSelectedEvent != null)
|
{
|
bossSelectedEvent(value);
|
}
|
}
|
}
|
}
|
|
public int demonJarSoulIncreaseDelta { get; set; }
|
|
public event Action<int> bossSelectedEvent;
|
public event Action<int> participantChangeEvent;
|
public event Action doubleAwardChangeEvent;
|
public event Action autoChallengeChangeEvent;
|
|
List<int> sortedBossIds = new List<int>();
|
Dictionary<int, DemonJarBossData> demonBosses = new Dictionary<int, DemonJarBossData>();
|
Dictionary<int, int> lineToBoss = new Dictionary<int, int>();
|
|
List<AutoChallengeLog> autoChallengeLogs = new List<AutoChallengeLog>();
|
|
FindPreciousModel findPreciousModel { get { return ModelCenter.Instance.GetModel<FindPreciousModel>(); } }
|
DungeonModel dungeonModel { get { return ModelCenter.Instance.GetModel<DungeonModel>(); } }
|
|
public override void Init()
|
{
|
doubleToKillLowerBossHint = true;
|
ParseConfig();
|
|
dungeonModel.dungeonRecordChangeEvent += OnDungeonRecordUpdate;
|
dungeonModel.updateDungeonBuyCnt += OnDungeonBuyCount;
|
dungeonModel.countRemainTimeChangeEvent += OnDungeonUpdateRedPoint;
|
}
|
|
public override void UnInit()
|
{
|
dungeonModel.dungeonRecordChangeEvent -= OnDungeonRecordUpdate;
|
dungeonModel.updateDungeonBuyCnt -= OnDungeonBuyCount;
|
dungeonModel.countRemainTimeChangeEvent -= OnDungeonUpdateRedPoint;
|
}
|
|
public void OnBeforePlayerDataInitialize()
|
{
|
PlayerDatas.Instance.playerDataRefreshEvent -= OnPlayerLevelUp;
|
ModelCenter.Instance.GetModel<MapModel>().mapLinesUpdateEvent -= OnMapLineUpdateEvent;
|
}
|
|
public void OnAfterPlayerDataInitialize()
|
{
|
if (!FuncOpen.Instance.IsFuncOpen(76))
|
{
|
return;
|
}
|
var bossId = GetRecommendBoss();
|
if (bossId != 0 && !findPreciousModel.IsBossSubscribed(bossId))
|
{
|
findPreciousModel.RequestSubscribeBoss(bossId, true);
|
}
|
|
PlayerDatas.Instance.playerDataRefreshEvent += OnPlayerLevelUp;
|
ModelCenter.Instance.GetModel<MapModel>().mapLinesUpdateEvent += OnMapLineUpdateEvent;
|
}
|
|
public void OnPlayerLoginOk()
|
{
|
demonJarSoulIncreaseDelta = 0;
|
|
if (FuncOpen.Instance.IsFuncOpen(76))
|
{
|
var bossId = GetLastUnlockBoss();
|
AutoSubscribeLastUnLockBoss(bossId);
|
}
|
|
ParseLocalSaveAutoChallengeLogs();
|
DemonJarAutoChallenge.Instance.Begin();
|
}
|
|
public void OnSwitchAccount()
|
{
|
doubleToKillLowerBossHint = true;
|
autoChallenge = false;
|
}
|
|
public bool TryGetBossData(int _bossId, out DemonJarBossData _data)
|
{
|
return demonBosses.TryGetValue(_bossId, out _data);
|
}
|
|
public void RequestSetDoubleAward(bool _double)
|
{
|
var send = new CB103_tagCMSetFMTDouble();
|
send.IsDouble = (byte)(_double ? 1 : 0);
|
|
GameNetSystem.Instance.SendInfo(send);
|
}
|
|
public List<int> GetDemonJarBosses()
|
{
|
var dungeonModel = ModelCenter.Instance.GetModel<DungeonModel>();
|
var bosses = new List<int>();
|
var lockedCount = 0;
|
for (int i = 0; i < sortedBossIds.Count; i++)
|
{
|
var bossId = sortedBossIds[i];
|
var config = DemonJarConfig.Get(bossId);
|
|
var grade = dungeonModel.GetGrade(new Dungeon(DATA_MAPID, config.LineID));
|
//if (config.CanEnterTimes > 0 && grade > 0)
|
//{
|
// continue;
|
//}
|
|
if (findPreciousModel.IsBossUnlock(bossId))
|
{
|
bosses.Add(bossId);
|
}
|
else
|
{
|
if (lockedCount < FindPreciousModel.ShowLockBossCnt)
|
{
|
bosses.Add(bossId);
|
lockedCount++;
|
}
|
}
|
}
|
|
return bosses;
|
}
|
|
public bool IsBossUnlock(int bossId)
|
{
|
return findPreciousModel.IsBossUnlock(bossId) && IsPlayerLevelEnough(bossId);
|
}
|
|
public bool IsPlayerLevelEnough(int bossId)
|
{
|
var config = NPCConfig.Get(bossId);
|
return PlayerDatas.Instance.baseData.LV >= config.NPCLV;
|
}
|
|
public bool IsPlayerRealmEnough(int bossId)
|
{
|
var config = NPCConfig.Get(bossId);
|
return PlayerDatas.Instance.baseData.realmLevel >= RealmConfig.Get(config.Realm).LvLarge;
|
}
|
|
public int GetBossIdByLine(int _line)
|
{
|
if (lineToBoss.ContainsKey(_line))
|
{
|
return lineToBoss[_line];
|
}
|
else
|
{
|
return 0;
|
}
|
}
|
|
public int GetRecommendBoss()
|
{
|
if (FuncOpen.Instance.IsFuncOpen(76))
|
{
|
var preferBoss = 0;
|
for (int i = sortedBossIds.Count - 1; i >= 0; i--)
|
{
|
var bossId = sortedBossIds[i];
|
if (IsBossUnlock(bossId))
|
{
|
if (preferBoss == 0)
|
{
|
preferBoss = bossId;
|
}
|
|
if (findPreciousModel.IsBossAlive(bossId) && findPreciousModel.IsSameBigRealmStageBoss(bossId))
|
{
|
return bossId;
|
}
|
}
|
}
|
|
if (preferBoss == 0)
|
{
|
preferBoss = sortedBossIds[0];
|
}
|
|
return preferBoss;
|
}
|
else
|
{
|
return sortedBossIds[0];
|
}
|
}
|
|
public int GetLastUnlockBoss()
|
{
|
for (int i = sortedBossIds.Count - 1; i >= 0; i--)
|
{
|
var bossId = sortedBossIds[i];
|
if (IsBossUnlock(bossId))
|
{
|
return bossId;
|
}
|
}
|
|
return 0;
|
}
|
|
public int GetSurplusTimes()
|
{
|
var totalTimes = dungeonModel.GetTotalTimes(DATA_MAPID);
|
var enterTimes = dungeonModel.GetEnterTimes(DATA_MAPID);
|
|
return totalTimes - enterTimes;
|
}
|
|
public bool IsPersonalBoss(int _bossId)
|
{
|
if (DemonJarConfig.Has(_bossId))
|
{
|
var config = DemonJarConfig.Get(_bossId);
|
return config.CanEnterTimes != 0;
|
}
|
else
|
{
|
return false;
|
}
|
}
|
|
public List<JiaBossKillRecord> GetJiaBossKillRecords(int _bossId)
|
{
|
var records = new List<JiaBossKillRecord>();
|
var killTime = DateTime.Now;
|
var config = DemonJarConfig.Get(_bossId);
|
|
for (int i = 0; i < 5; i++)
|
{
|
var playerName = StringUtility.Contact(RandomNameConfig.GetFirstName(1), RandomNameConfig.GetSecondName(1));
|
var exitJiaPlayer = false;
|
for (int j = 0; j < records.Count; j++)
|
{
|
var jiaPlayer = records[j];
|
if (jiaPlayer.playerName == playerName)
|
{
|
exitJiaPlayer = true;
|
break;
|
}
|
}
|
|
if (!exitJiaPlayer)
|
{
|
killTime -= new TimeSpan(UnityEngine.Random.Range(3, 5) * TimeSpan.TicksPerMinute);
|
records.Add(new JiaBossKillRecord(playerName, killTime, UnityEngine.Random.Range(config.KillHurtMin, config.KillHurtMax)));
|
}
|
}
|
|
return records;
|
}
|
|
public void UpdateAutoChallengeLogs()
|
{
|
autoChallengeLogs.Sort(AutoChallengeLog.SortPredicate);
|
}
|
|
private void ParseLocalSaveAutoChallengeLogs()
|
{
|
autoChallengeLogs.Clear();
|
var localSaves = LocalSave.GeStringArray(StringUtility.Contact("DemonJarAutoChallengeLog_", PlayerDatas.Instance.PlayerId));
|
if (localSaves != null)
|
{
|
for (var i = 0; i < localSaves.Length; i++)
|
{
|
var log = JsonMapper.ToObject<AutoChallengeLog>(localSaves[i]);
|
if ((TimeUtility.ServerNow - log.time).TotalDays <= 2)
|
{
|
autoChallengeLogs.Add(JsonMapper.ToObject<AutoChallengeLog>(localSaves[i]));
|
}
|
}
|
}
|
}
|
|
public void AddAutoChallengeLog(int bossId, bool isDouble, int rank)
|
{
|
var newLog = new AutoChallengeLog()
|
{
|
bossId = bossId,
|
isDouble = isDouble,
|
rank = rank,
|
time = TimeUtility.ServerNow
|
};
|
|
autoChallengeLogs.Add(newLog);
|
for (var i = autoChallengeLogs.Count - 1; i >= 0; i--)
|
{
|
var log = autoChallengeLogs[i];
|
if ((TimeUtility.ServerNow - log.time).TotalDays > 2)
|
{
|
autoChallengeLogs.RemoveAt(i);
|
}
|
}
|
|
var jsons = new string[autoChallengeLogs.Count];
|
for (var i = 0; i < autoChallengeLogs.Count; i++)
|
{
|
jsons[i] = JsonMapper.ToJson(autoChallengeLogs[i]);
|
}
|
|
LocalSave.SetStringArray(StringUtility.Contact("DemonJarAutoChallengeLog_", PlayerDatas.Instance.PlayerId), jsons);
|
}
|
|
public List<AutoChallengeLog> GetAutoChallengeLogs()
|
{
|
return new List<AutoChallengeLog>(autoChallengeLogs);
|
}
|
|
private void OnPlayerLevelUp(PlayerDataType _type)
|
{
|
switch (_type)
|
{
|
case PlayerDataType.RealmLevel:
|
if (FuncOpen.Instance.IsFuncOpen(76))
|
{
|
var bossId = GetLastUnlockBoss();
|
AutoSubscribeLastUnLockBoss(bossId);
|
}
|
break;
|
case PlayerDataType.LV:
|
if (FuncOpen.Instance.IsFuncOpen(76))
|
{
|
var bossId = GetLastUnlockBoss();
|
AutoSubscribeLastUnLockBoss(bossId);
|
}
|
|
if (PlayerDatas.Instance.baseData.LV == GeneralDefine.demonJarRedPoint)
|
{
|
UpdateRedpoint();
|
}
|
break;
|
}
|
}
|
|
private void UpdateRedpoint()
|
{
|
if (FuncOpen.Instance.IsFuncOpen(76))
|
{
|
var count = dungeonModel.GetTotalTimes(DATA_MAPID) - dungeonModel.GetEnterTimes(DATA_MAPID);
|
redpoint.count = count;
|
}
|
else
|
{
|
redpoint.count = 0;
|
}
|
|
redpoint.state = redpoint.count > 0 ? RedPointState.Quantity : RedPointState.None;
|
}
|
|
private void OnMapLineUpdateEvent(int _mapId)
|
{
|
if (_mapId != DATA_MAPID)
|
{
|
return;
|
}
|
|
foreach (var boss in demonBosses.Values)
|
{
|
if (boss.participant != 0)
|
{
|
boss.participant = 0;
|
if (participantChangeEvent != null)
|
{
|
participantChangeEvent(boss.id);
|
}
|
}
|
else
|
{
|
boss.participant = 0;
|
}
|
}
|
|
var mapModel = ModelCenter.Instance.GetModel<MapModel>();
|
var lines = mapModel.GetMapLines(DATA_MAPID);
|
for (int i = 0; i < sortedBossIds.Count; i++)
|
{
|
var bossId = sortedBossIds[i];
|
var bossConfig = DemonJarConfig.Get(bossId);
|
if (bossConfig == null)
|
{
|
continue;
|
}
|
|
for (int j = 0; j < lines.Count; j++)
|
{
|
if (lines[j].lineIndex == bossConfig.LineID)
|
{
|
demonBosses[bossId].participant = lines[j].playerCount;
|
if (participantChangeEvent != null)
|
{
|
participantChangeEvent(bossId);
|
}
|
break;
|
}
|
}
|
}
|
|
}
|
|
private void OnDungeonRecordUpdate(int _dataMapId)
|
{
|
if (DATA_MAPID != _dataMapId)
|
{
|
return;
|
}
|
|
if (PlayerDatas.Instance.baseData.LV >= GeneralDefine.demonJarRedPoint)
|
{
|
UpdateRedpoint();
|
}
|
|
foreach (var boss in demonBosses.Values)
|
{
|
if (this.findPreciousModel.IsBossAutoSubscribe(boss.id))
|
{
|
var config = DemonJarConfig.Get(boss.id);
|
var grade = dungeonModel.GetGrade(new Dungeon(DATA_MAPID, config.LineID));
|
if (grade > 0 && config.CancelAttentionAfterKill == 1)
|
{
|
this.findPreciousModel.RequestDeSubscribeBoss(boss.id);
|
}
|
}
|
}
|
}
|
|
|
private void OnDungeonUpdateRedPoint(int mapid)
|
{
|
if (PlayerDatas.Instance.baseData.LV >= GeneralDefine.demonJarRedPoint)
|
{
|
UpdateRedpoint();
|
}
|
}
|
|
private void OnDungeonBuyCount()
|
{
|
if (PlayerDatas.Instance.baseData.LV >= GeneralDefine.demonJarRedPoint)
|
{
|
UpdateRedpoint();
|
}
|
}
|
|
private void AutoSubscribeLastUnLockBoss(int bossId)
|
{
|
if (bossId == 0)
|
{
|
return;
|
}
|
|
foreach (var boss in demonBosses.Values)
|
{
|
if (this.findPreciousModel.IsBossAutoSubscribe(boss.id) && boss.id != bossId)
|
{
|
this.findPreciousModel.RequestDeSubscribeBoss(boss.id);
|
}
|
}
|
|
if (bossId != 0 && this.findPreciousModel.IsBossNeverSubscribe(bossId))
|
{
|
if (IsBossUnlock(bossId))
|
{
|
var config = DemonJarConfig.Get(bossId);
|
if (config.AutoAttention == 1)
|
{
|
this.findPreciousModel.RequestSubscribeBoss(bossId, true);
|
|
var model = ModelCenter.Instance.GetModel<DungeonModel>();
|
var grade = model.GetGrade(new Dungeon(DATA_MAPID, config.LineID));
|
if ((config.CanEnterTimes == 0 || grade == 0) && this.findPreciousModel.IsBossAlive(bossId))
|
{
|
this.findPreciousModel.AddOneBossRebornNotify(bossId);
|
}
|
}
|
}
|
}
|
}
|
void SendInspire(int inspireType)
|
{
|
CA508_tagCMDoFBAction pak = new CA508_tagCMDoFBAction();
|
pak.ActionType = 0;
|
pak.ActionInfo = (uint)inspireType;
|
GameNetSystem.Instance.SendInfo(pak);
|
}
|
|
public void AutoConfirm()
|
{
|
//已经达到鼓舞上限
|
if ((dungeonModel.GetDungeonInspireLevel()) >= dungeonModel.GetInspireMaxCount(PlayerDatas.Instance.baseData.MapID))
|
{
|
SysNotifyMgr.Instance.ShowTip("Xjmj_InspireMaxLevel");
|
return;
|
}
|
var mapId = PlayerDatas.Instance.baseData.MapID;
|
var _list = dungeonModel.GetDungeonInspire(mapId);
|
if (_list == null)
|
{
|
return;
|
}
|
DungeonInspireConfig coinInspireConfig = null;
|
DungeonInspireConfig fairyInspireConfig = null;
|
|
for (int i = 0; i < _list.Count; i++)
|
{
|
if (_list[i].InspireType == 3)
|
{
|
coinInspireConfig = _list[i];
|
}
|
else if (_list[i].InspireType == 2
|
|| _list[i].InspireType == 1 || _list[i].InspireType == 5)
|
{
|
fairyInspireConfig = _list[i];
|
}
|
}
|
if (coinInspireConfig!=null)
|
{
|
//勾选了自动用硬币
|
if (LocalSave.GetBool(StringUtility.Contact("AutoCoinInspire_", dungeonModel.GetDataMapIdByMapId(PlayerDatas.Instance.baseData.MapID), "_", PlayerDatas.Instance.PlayerId)))
|
{
|
if (coinInspireConfig == null)
|
return;
|
int nowLevel = dungeonModel.GetDungeonInspireLevel(3);
|
for (int i = nowLevel; i < coinInspireConfig.InspireCount; i++)
|
{
|
// 达到硬币最高等级限制
|
if (coinInspireConfig == null)
|
break;
|
if (dungeonModel.GetDungeonInspireLevel(3) >= coinInspireConfig.InspireCount)
|
break;
|
// 硬币数量不够
|
if (UIHelper.GetMoneyCnt(3) < (ulong)dungeonModel.GetDungeonInspireCost(coinInspireConfig))
|
{
|
SysNotifyMgr.Instance.ShowTip("Xjmj_InspireNoEnoughGold");
|
break;
|
}
|
SendInspire(coinInspireConfig.InspireType);
|
}
|
}
|
}
|
if (fairyInspireConfig != null)
|
{
|
//勾选了自动用仙玉
|
if (LocalSave.GetBool(StringUtility.Contact("AutoFairyInspire_", dungeonModel.GetDataMapIdByMapId(PlayerDatas.Instance.baseData.MapID), "_", PlayerDatas.Instance.PlayerId)))
|
{
|
int nowLevel = dungeonModel.GetDungeonInspireLevel(3);
|
int maxLevel = dungeonModel.GetInspireMaxCount(PlayerDatas.Instance.baseData.MapID);
|
for (int i = nowLevel; i < maxLevel; i++)
|
{
|
uint money = 0;
|
switch (fairyInspireConfig.InspireType)
|
{
|
case 1:
|
case 5:
|
money += PlayerDatas.Instance.baseData.diamond;
|
break;
|
}
|
var cost = dungeonModel.GetDungeonInspireCost(fairyInspireConfig);
|
// 仙玉数量不够
|
if (money < cost && !(NewBieCenter.Instance.inGuiding
|
&& NewBieCenter.Instance.currentGuide == GeneralDefine.fairyLandGuideId))
|
{
|
SysNotifyMgr.Instance.ShowTip("Xjmj_InspireNoEnoughFairy");
|
break;
|
}
|
SendInspire(fairyInspireConfig.InspireType);
|
}
|
}
|
}
|
}
|
|
private void ParseConfig()
|
{
|
var demonJarConfigs = DemonJarConfig.GetValues();
|
foreach (var config in demonJarConfigs)
|
{
|
var bossData = demonBosses[config.NPCID] = new DemonJarBossData(config.NPCID);
|
var npcConfig = NPCConfig.Get(config.NPCID);
|
bossData.unLockLevel = npcConfig.NPCLV;
|
lineToBoss[config.LineID] = config.NPCID;
|
}
|
|
sortedBossIds.AddRange(demonBosses.Keys);
|
sortedBossIds.Sort(FindPreciousModel.BossCompare);
|
}
|
|
public struct JiaBossKillRecord
|
{
|
public string playerName;
|
public DateTime killTime;
|
public long hurt;
|
|
public JiaBossKillRecord(string _playerName, DateTime _killTime, int _hurt)
|
{
|
playerName = _playerName;
|
killTime = _killTime;
|
hurt = _hurt;
|
}
|
|
public override string ToString()
|
{
|
return Language.Get("FightTreasure_KillTime", killTime.ToString("HH:mm:ss"), playerName);
|
}
|
|
}
|
|
public struct AutoChallengeLog
|
{
|
public int bossId;
|
public DateTime time;
|
public bool isDouble;
|
public int rank;
|
|
public AutoChallengeLog(string dateTime)
|
{
|
this.bossId = 1000000;
|
DateTime.TryParse("", out time);
|
this.isDouble = true;
|
this.rank = 1;
|
}
|
|
public static int SortPredicate(AutoChallengeLog lhs, AutoChallengeLog rhs)
|
{
|
return lhs.time < rhs.time ? -1 : 1;
|
}
|
|
}
|
|
}
|
|
public class DemonJarBossData
|
{
|
public int id { get; private set; }
|
public int unLockLevel { get; set; }
|
public int participant { get; set; }
|
|
public DemonJarBossData(int _id)
|
{
|
this.id = _id;
|
}
|
}
|
|
|
|
}
|
|
|
|
|