using System; using System.Collections; using System.Collections.Generic; using UnityEngine; namespace Snxxz.UI { [XLua.Hotfix] [XLua.LuaCallCSharp] public class GatherSoulDungeonModel : Model, IBeforePlayerDataInitialize, IPlayerLoginOk { public const int DUNGEON_MAPID = 31340; GatherSoulDungeonHelp m_Mission; public GatherSoulDungeonHelp mission { get { return m_Mission; } private set { m_Mission = value; } } public int attckDefendNpcId { get; private set; } public int iceDefendNpcId { get; private set; } public int defendPointNpcId { get; private set; } public int attackDefendCountLimit { get; private set; } public int iceDefendCountLimit { get; private set; } public int generateBossCost { get; private set; } public int dungeonWeelCount { get; private set; } public bool clickGenerateMonster { get; set; } Dictionary> dungeonItemDict = new Dictionary>(); readonly List itemTypeSort = new List() { GatheringSoulModel.GATHERSOUL_CORE_TYPE, GatheringSoulModel.GATHERSOUL_SOUL_TYPE,GatheringSoulModel.GATHERSOUL_ESSENCE_TYPE}; public event Action missionHelpUpdate; public event Action monsterAppearEvent; public override void Init() { ParseConfig(); } public void OnBeforePlayerDataInitialize() { ResetDungeonMessage(); } public void OnPlayerLoginOk() { } public override void UnInit() { } public int GetAttackDefendSurplusCount() { var count = GetDefendNpcCount(attckDefendNpcId); return attackDefendCountLimit - count; } public int GetIceDefendSurplusCount() { var count = GetDefendNpcCount(iceDefendNpcId); return iceDefendCountLimit - count; } void ParseConfig() { var funcConfig = FuncConfigConfig.Get("GatherSoulDungeon"); if (funcConfig != null) { attckDefendNpcId = int.Parse(funcConfig.Numerical1); iceDefendNpcId = int.Parse(funcConfig.Numerical2); defendPointNpcId = int.Parse(funcConfig.Numerical3); } funcConfig = FuncConfigConfig.Get("GatherSoulAttacker"); if (funcConfig != null) { attackDefendCountLimit = int.Parse(funcConfig.Numerical1); iceDefendCountLimit = int.Parse(funcConfig.Numerical2); } funcConfig = FuncConfigConfig.Get("GatherSoulGoldBoss"); if (funcConfig != null) { generateBossCost = int.Parse(funcConfig.Numerical1); } funcConfig = FuncConfigConfig.Get("GatherSoulDungeonTurn"); if (funcConfig != null) { dungeonWeelCount = int.Parse(funcConfig.Numerical1); } } public void OnReceiveDungeonMessage(string _mission) { mission = LitJson.JsonMapper.ToObject(_mission); if (clickGenerateMonster && mission.step == 2) { if (monsterAppearEvent != null) { monsterAppearEvent(); } } dungeonItemDict.Clear(); if (mission.gsItemInfo != null) { foreach (var key in mission.gsItemInfo.Keys) { var weel = int.Parse(key); List list; if (!dungeonItemDict.TryGetValue(weel, out list)) { list = new List(); dungeonItemDict.Add(weel, list); } if (mission.gsItemInfo[key] != null) { list.AddRange(mission.gsItemInfo[key]); list.Sort(Compare); } } } clickGenerateMonster = false; bool requreStepHint = mission.step == 1 && (GetDefendNpcCount(attckDefendNpcId) < attackDefendCountLimit || GetDefendNpcCount(iceDefendNpcId) < iceDefendCountLimit); if (requreStepHint && !WindowCenter.Instance.IsOpen()) { WindowCenter.Instance.Open(); } else if (!requreStepHint && WindowCenter.Instance.IsOpen()) { WindowCenter.Instance.Close(); } if (missionHelpUpdate != null) { missionHelpUpdate(); } } public bool TryGetDungeonItems(int weel, out List list) { return dungeonItemDict.TryGetValue(weel, out list); } public int GetDefendNpcCount(int npcId) { if (mission.npc != null) { for (int i = 0; i < mission.npc.Length; i++) { var npcInfo = mission.npc[i]; if (npcInfo.NPCID == npcId) { return npcInfo.killCnt; } } } return 0; } public void ResetDungeonMessage() { mission = default(GatherSoulDungeonHelp); clickGenerateMonster = false; dungeonItemDict.Clear(); } int Compare(ItemInfo lhs, ItemInfo rhs) { var lhsConfig = ItemConfig.Get(lhs.ItemID); var rhsConfig = ItemConfig.Get(rhs.ItemID); var lhsTypeSort = itemTypeSort.IndexOf(lhsConfig.Type); var rhsTypeSort = itemTypeSort.IndexOf(rhsConfig.Type); if (lhsTypeSort != rhsTypeSort) { return lhsTypeSort.CompareTo(rhsTypeSort); } if (lhsConfig.ItemColor != rhsConfig.ItemColor) { return -lhsConfig.ItemColor.CompareTo(rhsConfig.ItemColor); } return 0; } public struct ItemInfo { public int ItemID; public int Count; } } public struct GatherSoulDungeonHelp { public int lineID; public int wheel; public int step; public DungeonNPCInfo[] npc; public int isAuto; public int hasRefreshBoss; public Dictionary gsItemInfo; } }