using System;
|
using System.Collections;
|
using System.Collections.Generic;
|
using System.Linq;
|
using System.Text.RegularExpressions;
|
using LitJson;
|
|
using UnityEngine;
|
using UnityEngine.UI;
|
|
namespace vnxbqy.UI
|
{
|
|
public class FairyLeagueModel : Model, IAfterPlayerDataInitialize, IBeforePlayerDataInitialize, IPlayerLoginOk, IOpenServerActivity
|
{
|
public event Action OnRefreshFairyLeagueEvent;
|
|
public FairyLeagueWeekTime currentWeekTime
|
{
|
get
|
{
|
if (TimeUtility.IsMixServer && TimeUtility.MixOpenDay < GeneralDefine.mixServerCustomDays)
|
{
|
var week = GetMixServerWeek(TimeUtility.MixOpenDay);
|
var lastWeek = GetMixServerWeek(GeneralDefine.mixServerCustomDays - 1);
|
if (mixServerWeekTimes.ContainsKey(week)
|
&& (week < lastWeek || TimeUtility.MixOpenDay <= mixServerWeekTimes[week].lastMixServerDay))
|
{
|
return mixServerWeekTimes[week];
|
}
|
if (week < lastWeek)
|
{
|
return null;
|
}
|
else if (week == lastWeek)
|
{
|
var date = TimeUtility.ServerNow.AddTicks(-TimeUtility.MixOpenDay * TimeSpan.TicksPerDay);
|
var lastDayOfWeek = date.AddTicks((GeneralDefine.mixServerCustomDays - 1) * TimeSpan.TicksPerDay).DayOfWeek;
|
var dayOfWeek = lastDayOfWeek == DayOfWeek.Sunday ? 7 : (int)lastDayOfWeek;
|
if (dayOfWeek >= fairyLeagueWeekTime.rings[0].dayOfWeek)
|
{
|
return null;
|
}
|
}
|
}
|
var openServerWeekDay = TimeUtility.openServerDayOfWeek == DayOfWeek.Sunday ? 7 : (int)TimeUtility.openServerDayOfWeek;
|
if (specialLeagueTimes.ContainsKey(openServerWeekDay))
|
{
|
var dict = specialLeagueTimes[openServerWeekDay];
|
var weekCount = TimeUtility.OpenWeekCnt;
|
if (dict.ContainsKey(weekCount))
|
{
|
return dict[weekCount];
|
}
|
}
|
if (TimeUtility.OpenWeekCnt < 1)
|
{
|
return null;
|
}
|
return fairyLeagueWeekTime;
|
}
|
}
|
|
public FairyLeagueWeekTime nextWeekTime
|
{
|
get
|
{
|
if (TimeUtility.IsMixServer && TimeUtility.MixOpenDay < GeneralDefine.mixServerCustomDays)
|
{
|
var week = GetMixServerWeek(TimeUtility.MixOpenDay);
|
if (mixServerWeekTimes.ContainsKey(week + 1))
|
{
|
return mixServerWeekTimes[week + 1];
|
}
|
}
|
var openServerWeekDay = TimeUtility.openServerDayOfWeek == DayOfWeek.Sunday ? 7 : (int)TimeUtility.openServerDayOfWeek;
|
if (specialLeagueTimes.ContainsKey(openServerWeekDay))
|
{
|
var dict = specialLeagueTimes[openServerWeekDay];
|
var weekCount = TimeUtility.OpenWeekCnt + 1;
|
if (dict.ContainsKey(weekCount))
|
{
|
return dict[weekCount];
|
}
|
}
|
return fairyLeagueWeekTime;
|
}
|
}
|
|
FairyLeagueStage cacheLeagueStage = FairyLeagueStage.Prepare;
|
|
public FairyLeagueStage fairyLeagueStage
|
{
|
get
|
{
|
if (currentWeekTime == null)
|
{
|
return FairyLeagueStage.Prepare;
|
}
|
return currentWeekTime.fairyLeagueStage;
|
}
|
}
|
|
public int fairyLeagueSession
|
{
|
get
|
{
|
if (currentWeekTime == null)
|
{
|
return 0;
|
}
|
return currentWeekTime.currentSession;
|
}
|
}
|
|
public int fairyLeagueRing
|
{
|
get
|
{
|
if (currentWeekTime == null)
|
{
|
return 0;
|
}
|
return currentWeekTime.currentRing;
|
}
|
}
|
|
public int OpenServerWeek
|
{
|
get;
|
private set;
|
}
|
|
public bool IsNextWeek
|
{
|
get
|
{
|
if (currentWeekTime == null)
|
{
|
return true;
|
}
|
return currentWeekTime.IsNextWeek;
|
}
|
}
|
|
bool serverInited = false;
|
|
FairyModel fairyModel { get { return ModelCenter.Instance.GetModel<FairyModel>(); } }
|
|
public override void Init()
|
{
|
ParseConfig();
|
m_JoinFairyLeagueRedpoint = new Redpoint(10704, 1070401);
|
TimeUtility.OnServerOpenDayRefresh += OnServerOpenDayRefresh;
|
DTCA003_tagUniversalGameRecInfo.onGetUniversalGameInfo += OnGetUniversalGameInfo;
|
PlayerDatas.Instance.playerDataRefreshEvent += PlayerDataRefreshInfoEvent;
|
StageLoad.Instance.onStageLoadFinish += OnStageLoadFinish;
|
FuncOpen.Instance.OnFuncStateChangeEvent += OnFuncStateChangeEvent;
|
TimeMgr.Instance.OnMinuteEvent += MinuteEvent;
|
TimeMgr.Instance.OnDayEvent += DayEvent;
|
fairyLeagueHelp = new FairyLeagueHelp();
|
OpenServerActivityCenter.Instance.Register(12, this);
|
}
|
|
public override void UnInit()
|
{
|
DTCA003_tagUniversalGameRecInfo.onGetUniversalGameInfo -= OnGetUniversalGameInfo;
|
TimeMgr.Instance.OnMinuteEvent -= MinuteEvent;
|
TimeMgr.Instance.OnDayEvent -= DayEvent;
|
}
|
|
public void OnBeforePlayerDataInitialize()
|
{
|
ClearFairyWarHelp();
|
frontFairyList.Clear();
|
mixServerWeekTimes.Clear();
|
fairyLeagueFairyId = 0;
|
fairyLeagueFairyName = string.Empty;
|
afterGroupWorldLevel = 0;
|
serverInited = false;
|
}
|
|
public void OnAfterPlayerDataInitialize()
|
{
|
}
|
|
public void OnPlayerLoginOk()
|
{
|
ParseMixServerLeagueTimes();
|
ResetFairyLeagueTime();
|
cacheLeagueStage = fairyLeagueStage;
|
CheckFairyLeagueData();
|
UpdateRedpoint();
|
UpdateNoticeRedpoint();
|
serverInited = true;
|
}
|
|
private void OnServerOpenDayRefresh()
|
{
|
ParseMixServerLeagueTimes();
|
ResetFairyLeagueTime();
|
cacheLeagueStage = fairyLeagueStage;
|
CheckFairyLeagueData();
|
UpdateRedpoint();
|
}
|
|
private void DayEvent()
|
{
|
ResetFairyLeagueTime();
|
}
|
|
private void MinuteEvent()
|
{
|
if (!(StageLoad.Instance.currentStage is DungeonStage) || !serverInited)
|
{
|
return;
|
}
|
if (cacheLeagueStage != fairyLeagueStage)
|
{
|
cacheLeagueStage = fairyLeagueStage;
|
if (cacheLeagueStage != FairyLeagueStage.Prepare)
|
{
|
CheckFairyLeagueData();
|
}
|
if (OnRefreshFairyLeagueEvent != null)
|
{
|
OnRefreshFairyLeagueEvent();
|
}
|
UpdateNoticeRedpoint();
|
}
|
}
|
|
void ResetFairyLeagueTime()
|
{
|
if (OnRefreshFairyLeagueEvent != null)
|
{
|
OnRefreshFairyLeagueEvent();
|
}
|
}
|
|
private void PlayerDataRefreshInfoEvent(PlayerDataType _type)
|
{
|
if (_type == PlayerDataType.MapID)
|
{
|
UpdateRedpoint();
|
}
|
}
|
|
private void OnStageLoadFinish()
|
{
|
if (StageLoad.Instance.currentStage is DungeonStage &&
|
PlayerDatas.Instance.baseData.MapID == FAIRY_LEAGUE_DUNGEON)
|
{
|
UpdateRedpoint();
|
}
|
}
|
|
#region 配置
|
public const int FAIRY_LEAGUE_DUNGEON = 31220;
|
public const int FAIRY_LEAGUE_BATTLE = 68;
|
private string[] guideImgKeys;
|
public string[] GuideImgKeys
|
{
|
get
|
{
|
return guideImgKeys;
|
}
|
}
|
|
public int fairyWarResUpperLimit
|
{
|
get;
|
private set;
|
}
|
public readonly int buffTypeId = 22203;
|
public Dictionary<int, List<IntegralRankItem>> integralRankAwardDict = new Dictionary<int, List<IntegralRankItem>>();
|
public int[] integralRankAwardPer { get; private set; }
|
public int integralAddition { get; private set; }
|
public Dictionary<int, int[]> crystalSortDict { get; private set; }
|
/// <summary>
|
/// key----世界等级
|
/// </summary>
|
public Dictionary<int, List<Item>> finalWarWinAwardDict = new Dictionary<int, List<Item>>();
|
public Dictionary<int, List<Item>> finalWarChampionWinAwardDict = new Dictionary<int, List<Item>>();
|
public Dictionary<int, List<Item>> finalWarDefeatAwardDict = new Dictionary<int, List<Item>>();
|
public Dictionary<int, List<Item>> finalWarChampionDefeatAwardDict = new Dictionary<int, List<Item>>();
|
private Dictionary<int, float> crystalRateDict = new Dictionary<int, float>();
|
readonly List<int> fairyLeagueStateValues = new List<int>() { 11, 12, 13, 21, 22, 23 };
|
FairyLeagueWeekTime fairyLeagueWeekTime = new FairyLeagueWeekTime();
|
Dictionary<int, Dictionary<int, FairyLeagueWeekTime>> specialLeagueTimes = new Dictionary<int, Dictionary<int, FairyLeagueWeekTime>>();
|
Dictionary<int, FairyLeagueWeekTime> mixServerWeekTimes = new Dictionary<int, FairyLeagueWeekTime>();
|
public Dictionary<int, int> leagueNoticeWeapons { get; private set; }
|
private void ParseConfig()
|
{
|
var funcConfig = FuncConfigConfig.Get("FamilyMatchGuide");
|
if (funcConfig != null)
|
{
|
guideImgKeys = ConfigParse.GetMultipleStr(funcConfig.Numerical1);
|
}
|
var configs = DungeonStateTimeConfig.GetValues();
|
for (int i = 0; i < configs.Count; i++)
|
{
|
if (configs[i].DataMapID == FAIRY_LEAGUE_DUNGEON && fairyLeagueStateValues.Contains(configs[i].StateValue))
|
{
|
fairyLeagueWeekTime.AddStage(configs[i]);
|
}
|
}
|
fairyLeagueWeekTime.Sort();
|
var specialStateTimes = DungeonSpecialStateTimeConfig.GetDungeonTimes(FAIRY_LEAGUE_DUNGEON);
|
for (int i = 0; i < specialStateTimes.Count; i++)
|
{
|
var specialConfig = specialStateTimes[i];
|
if (fairyLeagueStateValues.Contains(specialConfig.StateValue))
|
{
|
Dictionary<int, FairyLeagueWeekTime> dict;
|
if (!specialLeagueTimes.TryGetValue(specialConfig.OpenServerWeek, out dict))
|
{
|
dict = new Dictionary<int, FairyLeagueWeekTime>();
|
specialLeagueTimes.Add(specialConfig.OpenServerWeek, dict);
|
}
|
var dayOfWeek = 0;
|
var index = GetIndexOfWeek(specialConfig.OpenServerWeek, specialConfig.OpenServerDay, out dayOfWeek);
|
FairyLeagueWeekTime leagueTime;
|
if (!dict.TryGetValue(index, out leagueTime))
|
{
|
leagueTime = new FairyLeagueWeekTime();
|
dict.Add(index, leagueTime);
|
}
|
leagueTime.AddStage(specialConfig, dayOfWeek);
|
}
|
}
|
foreach (var dict in specialLeagueTimes.Values)
|
{
|
foreach (var leagueTime in dict.Values)
|
{
|
leagueTime.Sort();
|
}
|
}
|
funcConfig = FuncConfigConfig.Get("FamilyMatchResourcePoint");
|
if (funcConfig != null)
|
{
|
crystalSortDict = new Dictionary<int, int[]>();
|
var _sortArray = JsonMapper.ToObject<int[][]>(funcConfig.Numerical3);
|
for (int i = 0; i < _sortArray.Length; i++)
|
{
|
crystalSortDict.Add(i + 1, _sortArray[i]);
|
}
|
fairyLeagueCrystals = JsonMapper.ToObject<int[]>(funcConfig.Numerical2);
|
fairyWarResUpperLimit = int.Parse(funcConfig.Numerical5);
|
}
|
funcConfig = FuncConfigConfig.Get("FamilyMatchRandomBuff");
|
if (funcConfig != null)
|
{
|
if (RandomBuffPos_Regex.IsMatch(funcConfig.Numerical1))
|
{
|
foreach (Match match in RandomBuffPos_Regex.Matches(funcConfig.Numerical1))
|
{
|
crystalPosList.Add(new Vector2(float.Parse(match.Groups[1].Value) / 2,
|
float.Parse(match.Groups[2].Value) / 2));
|
}
|
}
|
}
|
Regex _regex = new Regex(@"([0-9]+):\[(.*?\])\]");
|
funcConfig = FuncConfigConfig.Get("FamilyMatchRankReward");
|
if (_regex.IsMatch(funcConfig.Numerical1))
|
{
|
foreach (Match match in _regex.Matches(funcConfig.Numerical1))
|
{
|
var _rank = int.Parse(match.Groups[1].Value);
|
var _value = StringUtility.Contact('[', match.Groups[2].Value, ']');
|
List<IntegralRankItem> _list = ParseAward(LitJson.JsonMapper.ToObject<int[][]>(_value));
|
integralRankAwardDict.Add(_rank, _list);
|
}
|
integralRankAwardPer = JsonMapper.ToObject<int[]>(funcConfig.Numerical2);
|
}
|
funcConfig = FuncConfigConfig.Get("FamilyMatchRankOneReward");
|
if (_regex.IsMatch(funcConfig.Numerical1))
|
{
|
foreach (Match match in _regex.Matches(funcConfig.Numerical1))
|
{
|
var _worldLv = int.Parse(match.Groups[1].Value);
|
List<Item> _list = ParseAward(StringUtility.Contact('[', match.Groups[2].Value, ']'));
|
finalWarWinAwardDict.Add(_worldLv, _list);
|
}
|
}
|
if (_regex.IsMatch(funcConfig.Numerical2))
|
{
|
foreach (Match match in _regex.Matches(funcConfig.Numerical2))
|
{
|
var _worldLv = int.Parse(match.Groups[1].Value);
|
List<Item> _list = ParseAward(StringUtility.Contact('[', match.Groups[2].Value, ']'));
|
finalWarDefeatAwardDict.Add(_worldLv, _list);
|
}
|
}
|
funcConfig = FuncConfigConfig.Get("FamilyMatchSRankOneReward");
|
if (_regex.IsMatch(funcConfig.Numerical1))
|
{
|
foreach (Match match in _regex.Matches(funcConfig.Numerical1))
|
{
|
var _worldLv = int.Parse(match.Groups[1].Value);
|
List<Item> _list = ParseAward(StringUtility.Contact('[', match.Groups[2].Value, ']'));
|
finalWarChampionWinAwardDict.Add(_worldLv, _list);
|
}
|
}
|
if (_regex.IsMatch(funcConfig.Numerical2))
|
{
|
foreach (Match match in _regex.Matches(funcConfig.Numerical2))
|
{
|
var _worldLv = int.Parse(match.Groups[1].Value);
|
List<Item> _list = ParseAward(StringUtility.Contact('[', match.Groups[2].Value, ']'));
|
finalWarChampionDefeatAwardDict.Add(_worldLv, _list);
|
}
|
}
|
funcConfig = FuncConfigConfig.Get("FamilyMatchPersonalScore");
|
integralAddition = int.Parse(funcConfig.Numerical5);
|
funcConfig = FuncConfigConfig.Get("FamilyMatchResourcePoint1");
|
crystalRateDict = ConfigParse.GetDic<int, float>(funcConfig.Numerical1);
|
funcConfig = FuncConfigConfig.Get("FamilyForcast");
|
leagueNoticeWeapons = ConfigParse.GetDic<int, int>(funcConfig.Numerical1);
|
|
var leagueRankAwards = FairyLeagueRankAwardConfig.GetValues();
|
foreach (var rankAwardConfig in leagueRankAwards)
|
{
|
Dictionary<int, List<Item>> rankAwards;
|
if (!m_FairyLeagueRankRewards.TryGetValue(rankAwardConfig.WorldLV, out rankAwards))
|
{
|
rankAwards = new Dictionary<int, List<Item>>();
|
m_FairyLeagueRankRewards.Add(rankAwardConfig.WorldLV, rankAwards);
|
}
|
List<Item> awardItems;
|
if (!rankAwards.TryGetValue(rankAwardConfig.Rank, out awardItems))
|
{
|
awardItems = new List<Item>();
|
rankAwards.Add(rankAwardConfig.Rank, awardItems);
|
}
|
var itemArray = LitJson.JsonMapper.ToObject<int[][]>(rankAwardConfig.RankAuctionItem);
|
for (int i = 0; i < itemArray.Length; i++)
|
{
|
awardItems.Add(new Item()
|
{
|
id = itemArray[i][0],
|
count = itemArray[i][1],
|
});
|
}
|
|
awardItems.Reverse();
|
//awardItems.Sort((x, y) =>
|
//{
|
// var config_x = ItemConfig.Get(x.id);
|
// var config_y = ItemConfig.Get(y.id);
|
// if (config_x.ItemColor != config_y.ItemColor)
|
// {
|
// return -config_x.ItemColor.CompareTo(config_y.ItemColor);
|
// }
|
// return 0;
|
//});
|
|
if (rankAwardConfig.Rank > fairyLeagueRankAwardMaxRank)
|
{
|
fairyLeagueRankAwardMaxRank = rankAwardConfig.Rank;
|
}
|
}
|
}
|
|
int GetIndexOfWeek(int _openWeekDay, int _openDays, out int dayOfWeek)
|
{
|
var index = (_openWeekDay + _openDays - 2) / 7;
|
dayOfWeek = (_openWeekDay + _openDays - 1) % 7;
|
dayOfWeek = dayOfWeek == 0 ? 7 : dayOfWeek;
|
return index;
|
}
|
|
private List<Item> ParseAward(string _config)
|
{
|
List<Item> _list = new List<Item>();
|
var _array = JsonMapper.ToObject<int[][]>(_config);
|
if (_array != null)
|
{
|
for (int i = 0; i < _array.Length; i++)
|
{
|
Item _item = new Item();
|
_item.id = _array[i][0];
|
_item.count = _array[i][1];
|
_list.Add(_item);
|
}
|
}
|
return _list;
|
}
|
|
private List<IntegralRankItem> ParseAward(int[][] itemsArray)
|
{
|
List<IntegralRankItem> _list = new List<IntegralRankItem>();
|
if (itemsArray != null)
|
{
|
for (int i = 0; i < itemsArray.Length; i++)
|
{
|
IntegralRankItem _item = new IntegralRankItem();
|
_item.id = itemsArray[i][0];
|
_item.count = itemsArray[i][1];
|
_item.bind = itemsArray[i][2];
|
_item.isPer = itemsArray[i].Length > 3 ? itemsArray[i][3] : 1;
|
_list.Add(_item);
|
}
|
}
|
return _list;
|
}
|
public SkillConfig GetRandomAttrBuff(int _lv)
|
{
|
SkillConfig _buffTypeCfg = SkillConfig.Get(buffTypeId);
|
_lv = Mathf.Min(_lv, _buffTypeCfg.SkillMaxLV);
|
return SkillConfig.Get(buffTypeId + _lv - 1);
|
}
|
|
public bool TryGetCrystalRate(int _npcId, out float _rate)
|
{
|
return crystalRateDict.TryGetValue(_npcId, out _rate);
|
}
|
|
void ParseMixServerLeagueTimes()
|
{
|
mixServerWeekTimes.Clear();
|
if (!TimeUtility.IsMixServer)
|
{
|
return;
|
}
|
var configs = DungeonMixServerStateTimeConfig.GetDungeonTimes(FAIRY_LEAGUE_DUNGEON);
|
foreach (var config in configs)
|
{
|
var week = GetMixServerWeek(config.MixServerDay - 1);
|
FairyLeagueWeekTime leagueTime;
|
if (!mixServerWeekTimes.TryGetValue(week, out leagueTime))
|
{
|
leagueTime = new FairyLeagueWeekTime();
|
mixServerWeekTimes.Add(week, leagueTime);
|
}
|
var date = TimeUtility.ServerNow.AddTicks(-TimeUtility.MixOpenDay * TimeSpan.TicksPerDay);
|
var dayOfWeek = date.AddTicks((config.MixServerDay - 1) * TimeSpan.TicksPerDay).DayOfWeek;
|
leagueTime.AddStage(config, dayOfWeek == DayOfWeek.Sunday ? 7 : (int)dayOfWeek);
|
}
|
foreach (var weekTime in mixServerWeekTimes.Values)
|
{
|
weekTime.Sort();
|
}
|
}
|
|
int GetMixServerWeek(int mixDays)
|
{
|
var date = TimeUtility.ServerNow.AddTicks(-TimeUtility.MixOpenDay * TimeSpan.TicksPerDay);
|
var dayOfWeek = date.DayOfWeek == DayOfWeek.Sunday ? 7 : (int)date.DayOfWeek;
|
var week = Mathf.CeilToInt((mixDays - (7 - dayOfWeek)) / (float)7);
|
return week;
|
}
|
#endregion
|
|
#region 仙盟联赛副本
|
public int[] fairyLeagueCrystals
|
{
|
get;
|
private set;
|
}
|
public int fairyLeagueWinFaction
|
{
|
get;
|
private set;
|
}
|
public int fairyLeagueTotalTime
|
{
|
get;
|
private set;
|
}
|
public int fairyLeagueGroupId
|
{
|
get;
|
private set;
|
}
|
|
public uint fairyLeagueFairyId { get; private set; }//仙盟联赛第一轮分配时玩家所在仙盟,默认0代表本仙盟
|
|
public string fairyLeagueFairyName { get; private set; }
|
|
public event Action UpdateWarRankEvent;
|
|
public List<FairyLeagueResultData> fairyLeagueResults = new List<FairyLeagueResultData>();
|
public void UpdateFairyResult(HB210_tagMCFamilyWarBillboard _package)
|
{
|
fairyLeagueResults.Clear();
|
fairyLeagueGroupId = _package.GroupID;
|
for (int i = 0; i < _package.BillboardCount; i++)
|
{
|
var _sResult = _package.FBBillboardPlayer[i];
|
var _cResult = new FairyLeagueResultData(
|
(int)_sResult.PlayerID, _sResult.PlayerName,
|
(int)_sResult.CrystalCount, (int)_sResult.KillPlayerCount,
|
(int)_sResult.RandBuffCount, (int)_sResult.FightTime,
|
(int)_sResult.Point, _sResult.Faction == _package.WinFaction,
|
_sResult.Faction
|
);
|
fairyLeagueResults.Add(_cResult);
|
}
|
if (UpdateWarRankEvent != null)
|
{
|
UpdateWarRankEvent();
|
}
|
if (_package.WinFaction != 0 && _package.TotalFightTime > 0)
|
{
|
fairyLeagueTotalTime = _package.TotalFightTime;
|
fairyLeagueWinFaction = _package.WinFaction;
|
WindowCenter.Instance.CloseAll(WindowCenter.CloseAllIgnoreType.BaseAndCustom);
|
WindowCenter.Instance.Open<MainInterfaceWin>();
|
WindowCenter.Instance.Open<FairyLeagueDungeonSettleWin>();
|
}
|
}
|
|
public void UpdateFairyLeagueFairy(HA40B_tagGCPlayerJoinFamilyWarInfo package)
|
{
|
fairyLeagueFairyId = package.JoinFamilyID;
|
fairyLeagueFairyName = UIHelper.ServerStringTrim(package.JoinFamilyName);
|
UpdateRedpoint();
|
}
|
public int GetCrystalIndex(int _npcId)
|
{
|
var _array = crystalSortDict[1];
|
if (crystalSortDict.ContainsKey((int)PlayerDatas.Instance.baseData.faction))
|
{
|
_array = crystalSortDict[(int)PlayerDatas.Instance.baseData.faction];
|
}
|
for (int i = 0; i < _array.Length; i++)
|
{
|
if (fairyLeagueCrystals[_array[i] - 1] == _npcId)
|
{
|
return i;
|
}
|
}
|
return -1;
|
}
|
|
public bool BattleChampion()
|
{
|
var _session = fairyLeagueSession;
|
if (_session == 0 &&
|
fairyLeagueBattleDict.ContainsKey(_session)
|
&& fairyLeagueBattleDict[_session].ContainsKey(5))
|
{
|
var _list = fairyLeagueBattleDict[_session][5];
|
return _list.Count == 1;
|
}
|
return false;
|
}
|
public List<Vector2> crystalPosList = new List<Vector2>();
|
private readonly Regex RandomBuffPos_Regex = new Regex(@"\[([0-9]+),([0-9]+)\]");
|
#endregion
|
#region 协议
|
public event Action onFairyLeagueBattleEvent;
|
private Dictionary<int, Dictionary<int, List<FairyLeagueBattleData>>> fairyLeagueBattleDict = new Dictionary<int, Dictionary<int, List<FairyLeagueBattleData>>>();
|
private void OnGetUniversalGameInfo(HA003_tagUniversalGameRecInfo package)
|
{
|
if (package.Type == FAIRY_LEAGUE_BATTLE)
|
{
|
fairyLeagueBattleDict.Clear();
|
if (package.Count > 0)
|
{
|
for (int i = 0; i < package.Count; i++)
|
{
|
var _pakData = package.UniversalGameRec[i];
|
Dictionary<int, List<FairyLeagueBattleData>> dic = null;
|
fairyLeagueBattleDict.TryGetValue((int)_pakData.Value2 - 1, out dic);
|
if (dic == null)
|
{
|
dic = new Dictionary<int, List<FairyLeagueBattleData>>();
|
fairyLeagueBattleDict.Add((int)_pakData.Value2 - 1, dic);
|
}
|
List<FairyLeagueBattleData> list = null;
|
if (dic.TryGetValue((int)_pakData.Value1, out list) == false)
|
{
|
list = new List<FairyLeagueBattleData>();
|
dic.Add((int)_pakData.Value1, list);
|
}
|
FairyLeagueBattleData battleData = new FairyLeagueBattleData()
|
{
|
grade = (int)_pakData.Value1,
|
session = (int)_pakData.Value2 - 1,
|
fairyId1 = (int)_pakData.Value3,
|
fairyId2 = (int)_pakData.Value4,
|
winFairyId = (int)_pakData.Value5,
|
fairyName1 = _pakData.StrValue1,
|
fairyName2 = _pakData.StrValue2,
|
dissolveFairys = JsonMapper.ToObject<int[]>(_pakData.StrValue3),
|
};
|
list.Add(battleData);
|
}
|
}
|
if (onFairyLeagueBattleEvent != null)
|
{
|
onFairyLeagueBattleEvent();
|
}
|
UpdateRedpoint();
|
}
|
}
|
public bool SelfFairyInBattle(out int _error)
|
{
|
_error = 3;
|
var _session = fairyLeagueSession;
|
var _fairyId = PlayerDatas.Instance.fairyData.fairy.FamilyID;
|
if (!fairyLeagueBattleDict.ContainsKey(_session))
|
{
|
return false;
|
}
|
var _dict = fairyLeagueBattleDict[_session];
|
foreach (var _grade in _dict.Keys)
|
{
|
if (_dict[_grade] == null)
|
{
|
continue;
|
}
|
foreach (var _fairyBattle in _dict[_grade])
|
{
|
if (_fairyBattle.fairyId1 == _fairyId || _fairyBattle.fairyId2 == _fairyId)
|
{
|
var _battleFairyId = _fairyBattle.fairyId1 == _fairyId ? _fairyBattle.fairyId2 : _fairyBattle.fairyId1;
|
if (_battleFairyId == 0 || _fairyBattle.IsFairyDissolve(_battleFairyId))
|
{
|
_error = 4;
|
return false;
|
}
|
if (_fairyBattle.winFairyId != 0)
|
{
|
_error = 5;
|
}
|
return _fairyBattle.winFairyId == 0;
|
}
|
}
|
}
|
return false;
|
}
|
|
public bool RequireFairyLeagueRemind(int session)
|
{
|
if (!FuncOpen.Instance.IsFuncOpen((int)FuncOpenEnum.FairyLeague))
|
{
|
return false;
|
}
|
if (!PlayerDatas.Instance.fairyData.HasFairy)
|
{
|
return false;
|
}
|
var _fairyId = PlayerDatas.Instance.baseData.FamilyId;
|
if (!fairyLeagueBattleDict.ContainsKey(session))
|
{
|
return false;
|
}
|
var dict = fairyLeagueBattleDict[session];
|
foreach (var grade in dict.Keys)
|
{
|
if (dict[grade] == null)
|
{
|
continue;
|
}
|
foreach (var battleList in dict[grade])
|
{
|
if (battleList.fairyId1 == _fairyId
|
|| battleList.fairyId2 == _fairyId)
|
{
|
return battleList.fairyId1 != 0 && battleList.fairyId2 != 0;
|
}
|
}
|
}
|
return false;
|
}
|
|
public bool SatisfyEnterLeague(out int _error)
|
{
|
_error = 0;
|
if (!PlayerDatas.Instance.fairyData.HasFairy)
|
{
|
_error = 1;
|
return false;
|
}
|
if (fairyLeagueStage != FairyLeagueStage.Fight)
|
{
|
return false;
|
}
|
if (!SelfFairyInBattle(out _error))
|
{
|
return false;
|
}
|
if (!FuncOpen.Instance.IsFuncOpen((int)FuncOpenEnum.FairyLeague))
|
{
|
_error = 2;
|
return false;
|
}
|
if (fairyLeagueFairyId != 0 && fairyLeagueFairyId != PlayerDatas.Instance.baseData.FamilyId)
|
{
|
_error = 6;
|
return false;
|
}
|
return true;
|
}
|
|
public void DisplayErrorTip(int _error)
|
{
|
switch (_error)
|
{
|
case 1:
|
SysNotifyMgr.Instance.ShowTip("LeagueCannotGo5");
|
break;
|
case 2:
|
FuncOpen.Instance.ProcessorFuncErrorTip((int)FuncOpenEnum.FairyLeague);
|
break;
|
case 3:
|
SysNotifyMgr.Instance.ShowTip("LeagueCannotGo3");
|
break;
|
case 4:
|
SysNotifyMgr.Instance.ShowTip("LeagueCannotGo4");
|
break;
|
case 5:
|
var _session = fairyLeagueSession;
|
var isNextWeek = IsNextWeek;
|
FairyLeagueWeekTime.Session session;
|
var weekTime = isNextWeek ? nextWeekTime : currentWeekTime;
|
weekTime.TryGetSession(fairyLeagueRing, 1 - _session, out session);
|
var fightStage = session.stages.Find((x) =>
|
{
|
return x.stage == FairyLeagueStage.Fight;
|
});
|
if (_session == 0)
|
{
|
var _param = StringUtility.Contact(Language.Get(StringUtility.Contact("Weekday", weekTime.GetDayOfWeek(fairyLeagueRing))),
|
fightStage.startHour.ToString("D2"), ":", fightStage.startMinute.ToString("D2"));
|
SysNotifyMgr.Instance.ShowTip("LeagueCannotGo1", _param);
|
}
|
else
|
{
|
var _param = StringUtility.Contact(isNextWeek ? Language.Get("Next") : Language.Get("ThisTime"),
|
Language.Get(StringUtility.Contact("Weekday", weekTime.GetDayOfWeek(fairyLeagueRing))),
|
fightStage.startHour.ToString("D2"), ":", fightStage.startMinute.ToString("D2"));
|
SysNotifyMgr.Instance.ShowTip("LeagueCannotGo2", _param);
|
}
|
break;
|
case 6:
|
SysNotifyMgr.Instance.ShowTip("PlayerWarFamilyIDIsChange");
|
break;
|
}
|
}
|
|
public void CheckFairyLeagueData()
|
{
|
CA001_tagViewUniversalGameRec _pak = new CA001_tagViewUniversalGameRec();
|
_pak.ViewType = (byte)FAIRY_LEAGUE_BATTLE;
|
GameNetSystem.Instance.SendInfo(_pak);
|
}
|
|
public List<FairyLeagueBattleData> GetFairyLeague(int _ring, int _grade)
|
{
|
Dictionary<int, List<FairyLeagueBattleData>> dic = null;
|
List<FairyLeagueBattleData> list = null;
|
fairyLeagueBattleDict.TryGetValue(_ring, out dic);
|
if (dic != null)
|
{
|
dic.TryGetValue(_grade, out list);
|
}
|
return list;
|
}
|
public event Action UpdateFairyWarHelpEvent;
|
public event Action UpdateWarBuffEvent;
|
public event Action UpdateWarCrystalEvent;
|
public event Action CrystalBelongChangeEvent;
|
public FairyLeagueHelp fairyLeagueHelp
|
{
|
get;
|
private set;
|
}
|
private const string FairyWarBuffHelpKey = "familyWar_Buff";
|
private const string FairyWarCrystalAtkHelpKey = "familyWar_CrystalAtk";
|
private const string FairyWarCrystalKey = "familyWar_Crystal";
|
private const string FairyWarHelpInfoKey = "familyWar_HelpInfo";
|
private const string FairyWarEnterHelpKey = "familyWar_Enter";
|
public void UpdateFairyWarHelp(string _mission)
|
{
|
var _jsonData = JsonMapper.ToObject(_mission);
|
foreach (var _key in _jsonData.Keys)
|
{
|
switch (_key)
|
{
|
case FairyWarBuffHelpKey:
|
fairyLeagueHelp.fairyWarBuffs = JsonMapper.ToObject<FairyLeagueHelp.FairyWarBuff[]>(_jsonData[_key].ToJson());
|
if (UpdateWarBuffEvent != null)
|
{
|
UpdateWarBuffEvent();
|
}
|
break;
|
case FairyWarCrystalAtkHelpKey:
|
fairyLeagueHelp.FairyWarCrystalAtks = JsonMapper.ToObject<int[]>(_jsonData[_key].ToJson());
|
if (UpdateWarCrystalEvent != null)
|
{
|
UpdateWarCrystalEvent();
|
}
|
break;
|
case FairyWarCrystalKey:
|
fairyLeagueHelp.fairyWarCrystalDict.Clear();
|
var json = _jsonData[_key];
|
foreach (var _camp in json.Keys)
|
{
|
fairyLeagueHelp.fairyWarCrystalDict.Add(int.Parse(_camp), JsonMapper.ToObject<int[]>(json[_camp].ToJson()));
|
}
|
if (UpdateWarCrystalEvent != null)
|
{
|
UpdateWarCrystalEvent();
|
}
|
if (CrystalBelongChangeEvent != null)
|
{
|
CrystalBelongChangeEvent();
|
}
|
break;
|
case FairyWarHelpInfoKey:
|
fairyLeagueHelp.fairyWarHelpInfos =
|
JsonMapper.ToObject<FairyLeagueHelp.FairyWarHelpInfo[]>(_jsonData[_key].ToJson());
|
break;
|
case FairyWarEnterHelpKey:
|
fairyLeagueHelp.fairyWarEnter = JsonMapper.ToObject<FairyLeagueHelp.FairyWarEnter>(_jsonData[_key].ToJson());
|
break;
|
}
|
}
|
if (UpdateFairyWarHelpEvent != null)
|
{
|
UpdateFairyWarHelpEvent();
|
}
|
}
|
private void ClearFairyWarHelp()
|
{
|
fairyLeagueGroupId = 0;
|
fairyLeagueTotalTime = 0;
|
fairyLeagueWinFaction = 0;
|
fairyLeagueHelp.fairyWarBuffs = null;
|
fairyLeagueHelp.FairyWarCrystalAtks = null;
|
fairyLeagueHelp.fairyWarCrystalDict.Clear();
|
fairyLeagueHelp.fairyWarHelpInfos = null;
|
fairyLeagueHelp.fairyWarEnter = default(FairyLeagueHelp.FairyWarEnter);
|
}
|
|
public FairyLeagueBattleData GetSelfBattleInfo()
|
{
|
var _session = fairyLeagueSession;
|
var _fairyId = PlayerDatas.Instance.fairyData.fairy.FamilyID;
|
if (!fairyLeagueBattleDict.ContainsKey(_session))
|
{
|
return null;
|
}
|
var _dict = fairyLeagueBattleDict[_session];
|
foreach (var _grade in _dict.Keys)
|
{
|
if (_dict[_grade] == null)
|
{
|
continue;
|
}
|
foreach (var _fairyBattle in _dict[_grade])
|
{
|
if (_fairyBattle.fairyId1 == _fairyId || _fairyBattle.fairyId2 == _fairyId)
|
{
|
return _fairyBattle;
|
}
|
}
|
}
|
return null;
|
}
|
|
public bool IsSessionOneWinGroup()
|
{
|
var _fairyId = PlayerDatas.Instance.baseData.FamilyId;
|
|
var battleDatas = GetFairyLeague(0, fairyLeagueGroupId);
|
for (int i = 0; i < battleDatas.Count; i++)
|
{
|
if (battleDatas[i].fairyId1 == _fairyId
|
|| battleDatas[i].fairyId2 == _fairyId)
|
{
|
return battleDatas[i].winFairyId == _fairyId;
|
}
|
}
|
return false;
|
}
|
|
public bool StepSession(int _grade = 5)
|
{
|
if (fairyLeagueSession == 1)
|
{
|
if (!fairyLeagueBattleDict.ContainsKey(1))
|
{
|
return true;
|
}
|
if (fairyLeagueBattleDict.ContainsKey(0) &&
|
fairyLeagueBattleDict[0].ContainsKey(_grade) && fairyLeagueBattleDict[0][_grade].Count == 1)
|
{
|
return true;
|
}
|
else if (!fairyLeagueBattleDict[0].ContainsKey(_grade))
|
{
|
return true;
|
}
|
}
|
return false;
|
}
|
|
public string GetBattleFairyName(int _playerId)
|
{
|
var _fairy = PlayerDatas.Instance.fairyData.fairy;
|
if (PlayerDatas.Instance.PlayerId == _playerId)
|
{
|
return _fairy == null ? string.Empty : _fairy.FamilyName;
|
}
|
else if (PlayerDatas.Instance.fairyData.GetMember(_playerId) != null)
|
{
|
return _fairy == null ? string.Empty : _fairy.FamilyName;
|
}
|
else
|
{
|
FairyLeagueBattleData _battle = GetSelfBattleInfo();
|
return _battle.fairyId1 == _fairy.FamilyID ? _battle.fairyName2 : _battle.fairyName1;
|
}
|
}
|
|
public FairyCampType GetBattleCampType(int _playerId)
|
{
|
if (_playerId == PlayerDatas.Instance.PlayerId ||
|
PlayerDatas.Instance.fairyData.GetMember(_playerId) != null)
|
{
|
return (FairyCampType)PlayerDatas.Instance.baseData.faction;
|
}
|
return PlayerDatas.Instance.baseData.faction == 1 ? (FairyCampType)2 : (FairyCampType)1;
|
}
|
|
public string GetFairyFlagKey(int _playerId)
|
{
|
var _camp = GetBattleCampType(_playerId);
|
return _camp == FairyCampType.Blue ? "FlagBlue" : "FlagRed";
|
}
|
|
public int GetBattleWinFirstPlayer()
|
{
|
if (fairyLeagueResults.Count == 0)
|
{
|
return -1;
|
}
|
for (int i = 0; i < fairyLeagueResults.Count; i++)
|
{
|
if (fairyLeagueResults[i].IsWin)
|
{
|
return i;
|
}
|
}
|
return 0;
|
}
|
|
public int GetBattleDefeatFirstPlayer()
|
{
|
if (fairyLeagueResults.Count == 0)
|
{
|
return -1;
|
}
|
for (int i = 0; i < fairyLeagueResults.Count; i++)
|
{
|
if (!fairyLeagueResults[i].IsWin)
|
{
|
return i;
|
}
|
}
|
return 0;
|
}
|
|
#region 前16名仙盟列表
|
List<PlayerFairyData.FairyData> frontFairyList = new List<PlayerFairyData.FairyData>();
|
public event Action frontFairyUpdate;
|
public void SearchLeagueFrontFairy()
|
{
|
CA412_tagCGPySearchFamily pak = new CA412_tagCGPySearchFamily();
|
pak.MsgLen = 0;
|
pak.Msg = string.Empty;
|
pak.IsSearching = 100;
|
pak.LV = (byte)fairyModel.fairyLeagueLimit;
|
pak.MaxCount = 16;
|
GameNetSystem.Instance.SendInfo(pak);
|
}
|
|
public void UpdateFrontLeagueFairy(HA408_tagGCPyAllFamilyView package)
|
{
|
if (package.IsSearching == 100)
|
{
|
frontFairyList.Clear();
|
for (int i = 0; i < package.PageCount; i++)
|
{
|
PlayerFairyData.FairyData data = new PlayerFairyData.FairyData();
|
frontFairyList.Add(data);
|
PlayerFairyData.SetFairyViewData(data, package.Family[i]);
|
}
|
if (frontFairyUpdate != null)
|
{
|
frontFairyUpdate();
|
}
|
}
|
}
|
|
public List<PlayerFairyData.FairyData> frontLeagueFairy
|
{
|
get { return frontFairyList; }
|
}
|
#endregion
|
#endregion
|
#region 红点
|
private Redpoint m_LeagueRedpoint = new Redpoint(107, 10704);
|
public Redpoint m_JoinFairyLeagueRedpoint { get; private set; }
|
|
public void UpdateRedpoint()
|
{
|
m_JoinFairyLeagueRedpoint.state = RedPointState.None;
|
int _error = 0;
|
if (!SatisfyEnterLeague(out _error))
|
{
|
return;
|
}
|
if (PlayerDatas.Instance.baseData.MapID == FAIRY_LEAGUE_DUNGEON)
|
{
|
return;
|
}
|
m_JoinFairyLeagueRedpoint.state = RedPointState.Simple;
|
}
|
#endregion
|
|
#region 仙盟联赛预告
|
private void OnFuncStateChangeEvent(int func)
|
{
|
if (func == 142)
|
{
|
if (onStateUpdate != null)
|
{
|
onStateUpdate(12);
|
}
|
UpdateNoticeRedpoint();
|
}
|
}
|
|
public event Action<int> onStateUpdate;
|
public bool IsOpen
|
{
|
get
|
{
|
return FuncOpen.Instance.IsFuncOpen(142) && !IsAfterFirstLeague();
|
}
|
}
|
public bool IsAdvance
|
{
|
get { return false; }
|
}
|
|
public bool priorityOpen
|
{
|
get { return false; }
|
}
|
|
public int GetBeforeFirstLeagueTime()
|
{
|
var seconds = 0;
|
if (TimeUtility.OpenWeekCnt < 1)
|
{
|
if (IsAfterFirstLeague())
|
{
|
return 0;
|
}
|
var weekTime = currentWeekTime == null ? nextWeekTime : currentWeekTime;
|
var ring = weekTime.rings[0];
|
var session = ring.sessions[0];
|
var fightStage = session.stages.Find((x) =>
|
{
|
return x.stage == FairyLeagueStage.Fight;
|
});
|
var time = TimeUtility.ServerNow.AddTicks((weekTime.rings[0].openServerDay - TimeUtility.OpenDay - 1) * TimeSpan.TicksPerDay);
|
time = new DateTime(time.Year, time.Month, time.Day, fightStage.startHour, fightStage.startMinute, 0);
|
seconds = (int)(time - TimeUtility.ServerNow).TotalSeconds;
|
seconds = Mathf.Max(seconds, 0);
|
}
|
return seconds;
|
}
|
|
public bool IsAfterFirstLeague()
|
{
|
if (TimeUtility.OpenWeekCnt < 1)
|
{
|
var openServerWeekDay = TimeUtility.openServerDayOfWeek == DayOfWeek.Sunday ? 7 : (int)TimeUtility.openServerDayOfWeek;
|
if (specialLeagueTimes.ContainsKey(openServerWeekDay))
|
{
|
var dict = specialLeagueTimes[openServerWeekDay];
|
var weekCount = TimeUtility.OpenWeekCnt;
|
if (dict.ContainsKey(0) && weekCount > 0)
|
{
|
return true;
|
}
|
if (currentWeekTime == null)
|
{
|
return false;
|
}
|
var weekTime = currentWeekTime == null ? nextWeekTime : currentWeekTime;
|
if (weekTime.IsNextWeek)
|
{
|
return true;
|
}
|
if (weekTime.rings.Count > 1 && weekTime.currentRing == 1)
|
{
|
return true;
|
}
|
return weekTime.currentSession == 1 && weekTime.fairyLeagueStage == FairyLeagueStage.Over;
|
}
|
}
|
return true;
|
}
|
|
Redpoint fairyLeagueNoticeRedpoint = new Redpoint(MainRedDot.REDPOINT_OPENSERVER, 20912);
|
void UpdateNoticeRedpoint()
|
{
|
fairyLeagueNoticeRedpoint.state = RedPointState.None;
|
if (!DayRemind.Instance.GetDayRemind(DayRemind.LEAGUE_NOTICE_REDPOINT)
|
&& IsOpen)
|
{
|
fairyLeagueNoticeRedpoint.state = RedPointState.Simple;
|
}
|
}
|
|
public void SetViewLeagueNotice()
|
{
|
if (fairyLeagueNoticeRedpoint.state == RedPointState.Simple)
|
{
|
DayRemind.Instance.SetDayRemind(DayRemind.LEAGUE_NOTICE_REDPOINT, true);
|
UpdateNoticeRedpoint();
|
}
|
}
|
#endregion
|
|
#region 仙盟联赛排名奖励
|
Dictionary<int, Dictionary<int, List<Item>>> m_FairyLeagueRankRewards = new Dictionary<int, Dictionary<int, List<Item>>>();
|
|
public int afterGroupWorldLevel { get; private set; }
|
public int fairyLeagueRankAwardMaxRank { get; private set; }
|
public List<Item> GetFairyLeagueRankReward(int worldLevel, int rank)
|
{
|
List<Item> items = null;
|
|
var maxWorldLevel = m_FairyLeagueRankRewards.Keys.Last();
|
if (worldLevel >= maxWorldLevel)
|
{
|
foreach (var _rank in m_FairyLeagueRankRewards[maxWorldLevel].Keys)
|
{
|
if (rank <= _rank)
|
{
|
items = m_FairyLeagueRankRewards[maxWorldLevel][_rank];
|
return items;
|
}
|
}
|
}
|
|
foreach (var _worldLevel in m_FairyLeagueRankRewards.Keys)
|
{
|
if (worldLevel <= _worldLevel)
|
{
|
foreach (var _rank in m_FairyLeagueRankRewards[_worldLevel].Keys)
|
{
|
if (rank <= _rank)
|
{
|
items = m_FairyLeagueRankRewards[_worldLevel][_rank];
|
return items;
|
}
|
}
|
}
|
}
|
return items;
|
}
|
|
public void OnReceivePackage(HAC01_tagGCFamilyWarInfo package)
|
{
|
afterGroupWorldLevel = package.WorldLV;
|
}
|
#endregion
|
}
|
|
public class FairyLeagueWeekTime
|
{
|
public List<Ring> rings = new List<Ring>();
|
|
public bool IsNextWeek
|
{
|
get
|
{
|
return rings.Count == 0 || rings[rings.Count - 1].IsOver(TimeUtility.ServerNow);
|
}
|
}
|
|
public FairyLeagueStage fairyLeagueStage
|
{
|
get
|
{
|
if (IsNextWeek)
|
{
|
return FairyLeagueStage.Prepare;
|
}
|
Ring ring;
|
if (TryGetCurrentRing(out ring))
|
{
|
Session session;
|
if (ring.TryGetSession(TimeUtility.ServerNow, out session))
|
{
|
Stage stage;
|
if (session.TryGetStage(TimeUtility.ServerNow, out stage))
|
{
|
return stage.stage;
|
}
|
}
|
}
|
return FairyLeagueStage.Prepare;
|
}
|
}
|
|
public int currentRing
|
{
|
get
|
{
|
var ring = 0;
|
for (int i = 0; i < rings.Count; i++)
|
{
|
if (rings[i].InRing(TimeUtility.ServerNow))
|
{
|
return i;
|
}
|
if (rings[i].IsOver(TimeUtility.ServerNow))
|
{
|
ring++;
|
}
|
}
|
return Mathf.Min(ring, rings.Count - 1);
|
}
|
}
|
|
public int GetDayOfWeek(int _index)
|
{
|
if (_index >= 0 && _index < rings.Count)
|
{
|
return rings[_index].dayOfWeek;
|
}
|
return 0;
|
}
|
|
public int currentSession
|
{
|
get
|
{
|
Ring ring;
|
if (TryGetCurrentRing(out ring))
|
{
|
return ring.currentSession;
|
}
|
return 0;
|
}
|
}
|
|
public int lastMixServerDay
|
{
|
get
|
{
|
return rings[rings.Count - 1].mixServerDay;
|
}
|
}
|
|
public void AddStage(DungeonStateTimeConfig config)
|
{
|
var ring = rings.Find((x) =>
|
{
|
return x.dayOfWeek == config.StartWeekday;
|
});
|
if (ring == null)
|
{
|
ring = new Ring();
|
rings.Add(ring);
|
ring.dayOfWeek = config.StartWeekday;
|
}
|
ring.ParseConfig(config);
|
}
|
|
public void AddStage(DungeonSpecialStateTimeConfig config, int dayOfWeek)
|
{
|
var ring = rings.Find((x) =>
|
{
|
return x.dayOfWeek == dayOfWeek;
|
});
|
|
if (ring == null)
|
{
|
ring = new Ring();
|
rings.Add(ring);
|
ring.dayOfWeek = dayOfWeek;
|
}
|
ring.ParseConfig(config, dayOfWeek);
|
}
|
|
public void AddStage(DungeonMixServerStateTimeConfig config, int dayOfWeek)
|
{
|
var ring = rings.Find((x) =>
|
{
|
return x.dayOfWeek == dayOfWeek;
|
});
|
|
if (ring == null)
|
{
|
ring = new Ring();
|
rings.Add(ring);
|
ring.dayOfWeek = dayOfWeek;
|
}
|
ring.ParseConfig(config, dayOfWeek);
|
}
|
|
public void Sort()
|
{
|
rings.Sort((Ring x, Ring y) =>
|
{
|
return x.dayOfWeek.CompareTo(y.dayOfWeek);
|
});
|
for (int i = 0; i < rings.Count; i++)
|
{
|
rings[i].Sort();
|
}
|
}
|
|
public bool TryGetCurrentRing(out Ring ring)
|
{
|
ring = null;
|
for (int i = 0; i < rings.Count; i++)
|
{
|
if (rings[i].InRing(TimeUtility.ServerNow))
|
{
|
ring = rings[i];
|
return true;
|
}
|
}
|
return false;
|
}
|
|
public bool TryGetSession(int _ring, int _session, out Session session)
|
{
|
session = null;
|
if (_ring >= 0 && _ring < rings.Count)
|
{
|
if (_session >= 0 && _session < rings[_ring].sessions.Count)
|
{
|
session = rings[_ring].sessions[_session];
|
return true;
|
}
|
}
|
return false;
|
}
|
|
public class Ring
|
{
|
public List<Session> sessions = new List<Session>();
|
|
public int currentSession
|
{
|
get
|
{
|
for (int i = 0; i < sessions.Count; i++)
|
{
|
if (sessions[i].InSession(TimeUtility.ServerNow))
|
{
|
return i;
|
}
|
}
|
return 0;
|
}
|
}
|
|
public int dayOfWeek { get; set; }
|
|
public int openServerDay { get; private set; }
|
|
public int mixServerDay { get; private set; }
|
|
public void Sort()
|
{
|
sessions.Sort((Session x, Session y) =>
|
{
|
return x.session.CompareTo(y.session);
|
});
|
for (int i = 0; i < sessions.Count; i++)
|
{
|
sessions[i].Sort();
|
}
|
}
|
|
public void ParseConfig(DungeonStateTimeConfig config)
|
{
|
var session = sessions.Find((x) =>
|
{
|
return x.session == (config.StateValue < 20 ? 0 : 1);
|
});
|
if (session == null)
|
{
|
session = new Session();
|
session.session = config.StateValue < 20 ? 0 : 1;
|
sessions.Add(session);
|
}
|
session.ParseConfig(config);
|
}
|
|
public void ParseConfig(DungeonSpecialStateTimeConfig config, int dayOfWeek)
|
{
|
openServerDay = config.OpenServerDay;
|
|
var session = sessions.Find((x) =>
|
{
|
return x.session == (config.StateValue < 20 ? 0 : 1);
|
});
|
if (session == null)
|
{
|
session = new Session();
|
session.session = config.StateValue < 20 ? 0 : 1;
|
sessions.Add(session);
|
}
|
session.ParseConfig(config, dayOfWeek);
|
}
|
|
public void ParseConfig(DungeonMixServerStateTimeConfig config, int dayOfWeek)
|
{
|
mixServerDay = config.MixServerDay - 1;
|
|
var session = sessions.Find((x) =>
|
{
|
return x.session == (config.StateValue < 20 ? 0 : 1);
|
});
|
if (session == null)
|
{
|
session = new Session();
|
session.session = config.StateValue < 20 ? 0 : 1;
|
sessions.Add(session);
|
}
|
session.ParseConfig(config, dayOfWeek);
|
}
|
|
public bool InRing(DateTime time)
|
{
|
for (int i = 0; i < sessions.Count; i++)
|
{
|
if (sessions[i].InSession(time))
|
{
|
return true;
|
}
|
}
|
return false;
|
}
|
|
public bool TryGetSession(DateTime time, out Session session)
|
{
|
session = null;
|
for (int i = 0; i < sessions.Count; i++)
|
{
|
if (sessions[i].InSession(time))
|
{
|
session = sessions[i];
|
return true;
|
}
|
}
|
return false;
|
}
|
public bool IsOver(DateTime time)
|
{
|
bool allOver = true;
|
for (int i = 0; i < sessions.Count; i++)
|
{
|
if (!sessions[i].IsOver(time))
|
{
|
allOver = false;
|
break;
|
}
|
}
|
return allOver;
|
}
|
}
|
|
public class Session
|
{
|
public List<Stage> stages = new List<Stage>();
|
|
public int session { get; set; }
|
|
public void Sort()
|
{
|
var fightStage = stages.Find((x) =>
|
{
|
return x.stage == FairyLeagueStage.Fight;
|
});
|
var overStage = stages.Find((x) =>
|
{
|
return x.stage == FairyLeagueStage.Over;
|
});
|
overStage.startHour = fightStage.endHour;
|
overStage.startMinute = fightStage.endMinute;
|
stages.Sort(Compare);
|
}
|
|
public void ParseConfig(DungeonStateTimeConfig config)
|
{
|
var state = config.StateValue % 10;
|
var stage = new Stage()
|
{
|
stage = state == 1 ? FairyLeagueStage.Grouping : (state == 2 ? FairyLeagueStage.Fight : FairyLeagueStage.Over),
|
dayOfWeek = config.StartWeekday,
|
startHour = config.StartHour,
|
endHour = config.EndHour,
|
startMinute = config.StartMinute,
|
endMinute = config.EndMinute
|
};
|
stages.Add(stage);
|
}
|
|
public void ParseConfig(DungeonSpecialStateTimeConfig config, int dayOfWeek)
|
{
|
var state = config.StateValue % 10;
|
var stage = new Stage()
|
{
|
stage = state == 1 ? FairyLeagueStage.Grouping : (state == 2 ? FairyLeagueStage.Fight : FairyLeagueStage.Over),
|
dayOfWeek = dayOfWeek,
|
startHour = config.StartHour,
|
endHour = config.EndHour,
|
startMinute = config.StartMinute,
|
endMinute = config.EndMinute
|
};
|
stages.Add(stage);
|
}
|
|
public void ParseConfig(DungeonMixServerStateTimeConfig config, int dayOfWeek)
|
{
|
var state = config.StateValue % 10;
|
var stage = new Stage()
|
{
|
stage = state == 1 ? FairyLeagueStage.Grouping : (state == 2 ? FairyLeagueStage.Fight : FairyLeagueStage.Over),
|
dayOfWeek = dayOfWeek,
|
startHour = config.StartHour,
|
endHour = config.EndHour,
|
startMinute = config.StartMinute,
|
endMinute = config.EndMinute
|
};
|
stages.Add(stage);
|
}
|
|
public bool InSession(DateTime time)
|
{
|
var groupStage = stages.Find((x) =>
|
{
|
return x.stage == FairyLeagueStage.Grouping;
|
});
|
var overStage = stages.Find((x) =>
|
{
|
return x.stage == FairyLeagueStage.Over;
|
});
|
var _dayOfWeek = time.DayOfWeek == DayOfWeek.Sunday ? 7 : (int)time.DayOfWeek;
|
if (_dayOfWeek != groupStage.dayOfWeek)
|
{
|
return false;
|
}
|
if (time.Hour < groupStage.startHour || time.Hour > overStage.endHour)
|
{
|
return false;
|
}
|
if (time.Hour == groupStage.startHour && time.Minute < groupStage.startMinute)
|
{
|
return false;
|
}
|
if (time.Hour == overStage.endHour && time.Minute >= overStage.endMinute)
|
{
|
return false;
|
}
|
return true;
|
}
|
|
public bool TryGetStage(DateTime time, out Stage stage)
|
{
|
stage = default(Stage);
|
for (int i = 0; i < stages.Count; i++)
|
{
|
if (stages[i].InStage(time))
|
{
|
stage = stages[i];
|
return true;
|
}
|
if (stages[i].IsOver(time))
|
{
|
stage = stages[i];
|
}
|
}
|
return !stage.Equals(default(Stage));
|
}
|
|
public bool IsOver(DateTime time)
|
{
|
var stage = stages.Find((x) =>
|
{
|
return x.stage == FairyLeagueStage.Over;
|
});
|
return stage.IsOver(time);
|
}
|
|
int Compare(Stage x, Stage y)
|
{
|
return x.stage.CompareTo(y.stage);
|
}
|
}
|
|
public class Stage
|
{
|
public FairyLeagueStage stage;
|
public int dayOfWeek;
|
public int startHour;
|
public int endHour;
|
public int startMinute;
|
public int endMinute;
|
|
public bool InStage(DateTime time)
|
{
|
var _dayOfWeek = time.DayOfWeek == DayOfWeek.Sunday ? 7 : (int)time.DayOfWeek;
|
if (dayOfWeek != _dayOfWeek)
|
{
|
return false;
|
}
|
if (time.Hour < startHour || time.Hour > endHour)
|
{
|
return false;
|
}
|
if (time.Hour == startHour && time.Minute < startMinute)
|
{
|
return false;
|
}
|
if (time.Hour == endHour && time.Minute >= endMinute)
|
{
|
return false;
|
}
|
return true;
|
}
|
|
public bool IsOver(DateTime time)
|
{
|
var _dayOfWeek = time.DayOfWeek == DayOfWeek.Sunday ? 7 : (int)time.DayOfWeek;
|
if (_dayOfWeek > dayOfWeek)
|
{
|
return true;
|
}
|
if (dayOfWeek == _dayOfWeek)
|
{
|
if (time.Hour > endHour)
|
{
|
return true;
|
}
|
if (time.Hour == endHour && time.Minute >= endMinute)
|
{
|
return true;
|
}
|
}
|
return false;
|
}
|
}
|
}
|
|
public enum FairyLeagueStage
|
{
|
Prepare,
|
Grouping,
|
Fight,
|
Over,
|
}
|
public enum FairyCampType
|
{
|
None,
|
Red = 1,
|
Blue = 2
|
}
|
public class FairyLeagueBattleData
|
{
|
public int grade;
|
public int session;
|
public int fairyId1;
|
public int fairyId2;
|
public int winFairyId;
|
public int[] dissolveFairys;
|
public string fairyName1;
|
public string fairyName2;
|
|
public bool IsFairyDissolve(int _fairyId)
|
{
|
if (dissolveFairys == null || dissolveFairys.Length == 0)
|
{
|
return false;
|
}
|
for (int i = 0; i < dissolveFairys.Length; i++)
|
{
|
if (dissolveFairys[i] == _fairyId)
|
{
|
return true;
|
}
|
}
|
return false;
|
}
|
public bool IsFairyWin(int _fairyId)
|
{
|
return _fairyId == winFairyId;
|
}
|
public string GetWinFairyName()
|
{
|
return fairyId1 == winFairyId ? fairyName1 : fairyId2 == winFairyId ? fairyName2 : string.Empty;
|
}
|
public int GetWinFairyId()
|
{
|
return fairyId1 == winFairyId ? fairyId1 : fairyId2 == winFairyId ? fairyId2 : 0;
|
}
|
public string GetLoserFairyName()
|
{
|
return fairyId1 == winFairyId ? fairyName2 : fairyName1;
|
}
|
public int GetLoserFairyId()
|
{
|
return fairyId1 == winFairyId ? fairyId2 : fairyId1;
|
}
|
}
|
public struct FairyLeagueResultData
|
{
|
public int PlayerId
|
{
|
get;
|
private set;
|
}
|
public string PlayerName
|
{
|
get;
|
private set;
|
}
|
public int TakeCrystals
|
{
|
get;
|
private set;
|
}
|
public int KillNums
|
{
|
get;
|
private set;
|
}
|
public int TakeBuffs
|
{
|
get;
|
private set;
|
}
|
public int FightTime
|
{
|
get;
|
private set;
|
}
|
public int Integral
|
{
|
get;
|
private set;
|
}
|
public bool IsWin
|
{
|
get;
|
private set;
|
}
|
public int Faction
|
{
|
get;
|
private set;
|
}
|
|
public FairyLeagueResultData(int _playerId, string _playerName, int _crystal, int _killNum,
|
int _buffs, int _fightTime, int _integral, bool _isWin, int _faction)
|
{
|
PlayerId = _playerId;
|
PlayerName = _playerName;
|
TakeCrystals = _crystal;
|
KillNums = _killNum;
|
TakeBuffs = _buffs;
|
FightTime = _fightTime;
|
Integral = _integral;
|
IsWin = _isWin;
|
Faction = _faction;
|
}
|
}
|
public class FairyLeagueHelp
|
{
|
public FairyWarBuff[] fairyWarBuffs;
|
public int[] FairyWarCrystalAtks;
|
public Dictionary<int, int[]> fairyWarCrystalDict = new Dictionary<int, int[]>();
|
public FairyWarHelpInfo[] fairyWarHelpInfos;
|
public FairyWarEnter fairyWarEnter;
|
|
public int GetCrystalBelongCamp(int _npcId)
|
{
|
foreach (var _camp in fairyWarCrystalDict.Keys)
|
{
|
if (fairyWarCrystalDict[_camp] == null)
|
{
|
continue;
|
}
|
for (int i = 0; i < fairyWarCrystalDict[_camp].Length; i++)
|
{
|
if (_npcId == fairyWarCrystalDict[_camp][i])
|
{
|
return _camp;
|
}
|
}
|
}
|
return 0;
|
}
|
public struct FairyWarBuff
|
{
|
public int PosIndex;
|
public int NPCID;
|
public int Atk;
|
}
|
public struct FairyWarHelpInfo
|
{
|
public double ResPoint;
|
public int MemCount;
|
public int BuffResPoint;
|
public int BuffResPointPer;
|
public int BuffAttrLV;
|
}
|
public struct FairyWarEnter
|
{
|
public int[] WinCount;
|
public int IsFinalMatch;
|
}
|
}
|
|
public struct IntegralRankItem
|
{
|
public int id;
|
public int count;
|
public int bind;
|
public int isPer;
|
}
|
|
[Serializable]
|
public class AwardItemUI
|
{
|
[SerializeField] Image m_ItemIcon;
|
[SerializeField] Image m_BindIcon;
|
[SerializeField] Image m_ItemBg;
|
[SerializeField] Text m_ItemCnt;
|
|
public Text itemCnt { get { return m_ItemCnt; } }
|
|
public void Init(int _itemId, int _itemCnt, int _isBind = 0)
|
{
|
ItemConfig _itemCfg = ItemConfig.Get(_itemId);
|
m_ItemIcon.SetActive(_itemCfg != null);
|
if (_itemCfg != null)
|
{
|
m_ItemIcon.SetSprite(_itemCfg.IconKey);
|
if (m_ItemBg != null)
|
{
|
m_ItemBg.SetItemBackGround(_itemCfg.ItemColor);
|
}
|
}
|
m_ItemCnt.text = _itemCnt <= 1 ? string.Empty : _itemCnt.ToString();
|
if (m_BindIcon != null)
|
{
|
m_BindIcon.SetActive(_isBind == 1);
|
}
|
}
|
}
|
}
|