using System;
|
using System.Collections;
|
using System.Collections.Generic;
|
using UnityEngine;
|
namespace vnxbqy.UI
|
{
|
|
|
public class AllianceBossModel : Model, IBeforePlayerDataInitialize, IPlayerLoginOk
|
{
|
List<int> m_BossIds = new List<int>();
|
Dictionary<int, List<Item>> m_Items = new Dictionary<int, List<Item>>();
|
Dictionary<int, AllianceBossLine> m_AllianceBossLines = new Dictionary<int, AllianceBossLine>();
|
|
public const int DATAMAPID = 31260;
|
public bool isActivityOver { get; private set; }
|
public int participateLimit { get; private set; }
|
|
public List<Item> inspireRewards { get; private set; }
|
|
public int personalInspireCount { get; private set; }
|
|
public readonly Redpoint redpoint = new Redpoint(218, 21802);
|
|
public event Action allianceBossStateRefresh;
|
public event Action allianceBossLineRefresh;
|
|
DailyQuestModel dailyQuestModel { get { return ModelCenter.Instance.GetModel<DailyQuestModel>(); } }
|
|
public override void Init()
|
{
|
ParseConfig();
|
DailyQuestActionTimer.Instance.RefreshDailyQuestState += RefreshDailyQuestState;
|
PlayerDatas.Instance.fairyData.OnRefreshFairyMine += OnRefreshFairyMine;
|
}
|
|
public void OnBeforePlayerDataInitialize()
|
{
|
isActivityOver = false;
|
m_AllianceBossLines.Clear();
|
}
|
|
public void OnPlayerLoginOk()
|
{
|
UpdateRedpoint();
|
}
|
|
public override void UnInit()
|
{
|
DailyQuestActionTimer.Instance.RefreshDailyQuestState -= RefreshDailyQuestState;
|
PlayerDatas.Instance.fairyData.OnRefreshFairyMine -= OnRefreshFairyMine;
|
}
|
|
private void OnRefreshFairyMine()
|
{
|
UpdateRedpoint();
|
}
|
|
private void RefreshDailyQuestState()
|
{
|
UpdateRedpoint();
|
}
|
|
public int GetBossNpcId(int index)
|
{
|
return index < m_BossIds.Count ? m_BossIds[index] : 0;
|
}
|
|
public bool TryGetItems(int index, out List<Item> items)
|
{
|
return m_Items.TryGetValue(index, out items);
|
}
|
|
public bool TryGetBossLine(int index, out AllianceBossLine bossLine)
|
{
|
return m_AllianceBossLines.TryGetValue(index, out bossLine);
|
}
|
|
void ParseConfig()
|
{
|
var config = FuncConfigConfig.Get("LeagueBOSSNumber1");
|
participateLimit = int.Parse(config.Numerical1);
|
|
inspireRewards = new List<Item>();
|
config = FuncConfigConfig.Get("LeagueBOSSReward1");
|
var itemArray = LitJson.JsonMapper.ToObject<int[][]>(config.Numerical1);
|
for (int i = 0; i < itemArray.Length; i++)
|
{
|
var item = itemArray[i];
|
inspireRewards.Add(new Item()
|
{
|
id = item[0],
|
count = item[1],
|
});
|
}
|
|
personalInspireCount = int.Parse(config.Numerical2);
|
|
config = FuncConfigConfig.Get("AllianceBoss");
|
m_BossIds.AddRange(ConfigParse.GetMultipleStr<int>(config.Numerical1));
|
m_Items.Add(0, new List<Item>());
|
var itemsArray = ConfigParse.GetMultipleStr<int>(config.Numerical2);
|
for (int i = 0; i < itemsArray.Length; i++)
|
{
|
m_Items[0].Add(new Item()
|
{
|
id = itemsArray[i],
|
count = 1,
|
});
|
}
|
|
m_Items.Add(1, new List<Item>());
|
itemsArray = ConfigParse.GetMultipleStr<int>(config.Numerical3);
|
for (int i = 0; i < itemsArray.Length; i++)
|
{
|
m_Items[1].Add(new Item()
|
{
|
id = itemsArray[i],
|
count = 1,
|
});
|
}
|
}
|
|
public void ReceivePackage(HA40C_tagGCAllFamilyBossInfo package)
|
{
|
isActivityOver = package.IsEnd == 1;
|
if (allianceBossStateRefresh != null)
|
{
|
allianceBossStateRefresh();
|
}
|
|
UpdateRedpoint();
|
}
|
|
public void ReceivePackage(HA007_tagGCFBLinePlayerCnt package)
|
{
|
if (package.MapID != DATAMAPID)
|
{
|
return;
|
}
|
|
m_AllianceBossLines.Clear();
|
|
for (int i = 0; i < package.Count; i++)
|
{
|
var data = package.FBLineInfoList[i];
|
m_AllianceBossLines[data.FBLineID] = new AllianceBossLine()
|
{
|
playerCount = data.PlayerCnt,
|
hp = int.Parse(data.ExtraStr)
|
};
|
}
|
|
if (allianceBossLineRefresh != null)
|
{
|
allianceBossLineRefresh();
|
}
|
}
|
|
void UpdateRedpoint()
|
{
|
var redpointable = false;
|
if (dailyQuestModel.GetQuestState((int)DailyQuestType.AllianceBoss) == DailyQuestModel.DailyQuestState.Normal)
|
{
|
if (!isActivityOver)
|
{
|
redpointable = true;
|
}
|
}
|
redpoint.state = redpointable ? RedPointState.Simple : RedPointState.None;
|
}
|
|
public struct AllianceBossLine
|
{
|
public int playerCount;
|
public int hp;
|
}
|
}
|
}
|
|