using System; using System.Collections.Generic; using KKSG; using UILib; using UnityEngine; using XMainClient.UI; using XMainClient.UI.UICommon; using XUtliPoolLib; namespace XMainClient { internal class XGuildCollectDocument : XDocComponent { public override uint ID { get { return XGuildCollectDocument.uuID; } } public GuildCampPartyReward RewardReader { get { return XGuildCollectDocument._rewardReader; } } public bool ActivityState { get { return this._activityState; } } public new static readonly uint uuID = XSingleton.singleton.XHash("GuildCollectDocument"); public static XTableAsyncLoader AsyncLoader = new XTableAsyncLoader(); private static GuildCampPartyReward _rewardReader = new GuildCampPartyReward(); private bool _activityState = false; private bool _lotteryMachineState = false; public List NpcPool = new List(); public List LotteryMachineList = new List(); public Dictionary NpcIndex = new Dictionary(); public List NpcList = new List(); private int _npcMaxShowNum; private CollectNpcRefreshMode _npcRefreshMode; private uint _lastMeetLotteryUid; private float _lotteryWaitTime; private string _lotteryProcessText; private string _lotteryProcessTips; private uint _lastSendNpcID = 0u; private float _lastSendNpcTime; public Dictionary CollectUseDict = new Dictionary(); public bool MainInterfaceBtnState = false; public List _fxList = new List(); private static readonly string m_fxPath = "Effects/FX_Particle/Scene/Lzg_scene/rwts_05"; public double SignTime; public uint LeftTime; private int SUMMONLEFTTIME = 300; private string NORMALNAME = ""; private string SPECIALNAME = ""; private uint _hallTimeToken; private LinkedList _lotteryFxLink = new LinkedList(); private XFx _lotteryBoxFx; private static readonly string LotteryFlyFXPATH = "Effects/FX_Particle/UIfx/UI_ghpd_rabbit_Clip02"; private static readonly string LotteryBoxFXPATH = "Effects/FX_Particle/UIfx/UI_ghpd_rabbit_Clip01"; public Dictionary LotteryCDInfo = new Dictionary(); public int LotteryTimes = 3; public float GuildCollecLotteryCD = 120f; public static void Execute(OnLoadedCallback callback = null) { XGuildCollectDocument.AsyncLoader.AddTask("Table/GuildCampPartyReward", XGuildCollectDocument._rewardReader, false); XGuildCollectDocument.AsyncLoader.Execute(callback); } protected override void EventSubscribe() { base.EventSubscribe(); } public override void OnAttachToHost(XObject host) { base.OnAttachToHost(host); this._activityState = false; this._lotteryMachineState = false; } public override void OnEnterSceneFinally() { base.OnEnterSceneFinally(); bool flag = XSingleton.singleton.SceneType == SceneType.SCENE_GUILD_HALL; if (flag) { this._lotteryWaitTime = float.Parse(XSingleton.singleton.GetValue("GuildCollecLotteryWaitTime")); this._lotteryProcessText = XStringDefineProxy.GetString("GuildCollectProcessText"); this._lotteryProcessTips = XStringDefineProxy.GetString("GuildCollectProcessTips"); this.LotteryTimes = int.Parse(XSingleton.singleton.GetValue("GuildCollecLotteryTimes")); this.GuildCollecLotteryCD = float.Parse(XSingleton.singleton.GetValue("GuildCollecLotteryCD")); List intList = XSingleton.singleton.GetIntList("GuildCollectNpcShowNum"); XQualitySetting.ESetting quality = (XQualitySetting.ESetting)XQualitySetting.GetQuality(); int num = XFastEnumIntEqualityComparer.ToInt(quality); bool flag2 = num > intList.Count - 1; if (flag2) { num = intList.Count - 1; } this._npcMaxShowNum = intList[num]; this._npcRefreshMode = ((XSingleton.singleton.GetValue("GuildCollectNpcRefreshMode") == "0") ? CollectNpcRefreshMode.Random : CollectNpcRefreshMode.Distance); this.NpcIndex.Clear(); this.NpcList.Clear(); this.NpcPool.Clear(); this.LotteryMachineList.Clear(); bool activityState = this._activityState; if (activityState) { this.RefreshTime(null); this.InitNpcList(); bool lotteryMachineState = this._lotteryMachineState; if (lotteryMachineState) { this.SetLotteryMachineState(true, true); } } this.SetMainInterfaceBtnState(false); } } public int CheckLotteryCD(uint uid) { LotteryCD lotteryCD; bool flag = this.LotteryCDInfo.TryGetValue(uid, out lotteryCD); int result; if (flag) { bool flag2 = lotteryCD.Times < this.LotteryTimes; if (flag2) { lotteryCD.Times++; result = -1; } else { int num = (int)(Time.time - lotteryCD.LastLotteryTime - this.GuildCollecLotteryCD); bool flag3 = num >= 0; if (flag3) { lotteryCD.Times = 1; lotteryCD.LastLotteryTime = Time.time; result = -1; } else { result = -num; } } } else { lotteryCD = new LotteryCD(); lotteryCD.Times = 1; lotteryCD.LastLotteryTime = Time.time; this.LotteryCDInfo[uid] = lotteryCD; result = -1; } return result; } public void SetActivityState(bool state) { bool flag = this._activityState != state; if (flag) { this._activityState = state; XSingleton.singleton.AddGreenLog("set guildcollect state = ", state.ToString(), null, null, null, null); bool flag2 = XSingleton.singleton.SceneType == SceneType.SCENE_GUILD_HALL; if (flag2) { bool activityState = this._activityState; if (activityState) { this.RefreshTime(null); this.InitNpcList(); } else { foreach (KeyValuePair keyValuePair in this.NpcIndex) { XSingleton.singleton.DestroyNpc(keyValuePair.Value); } for (int i = 0; i < this.NpcPool.Count; i++) { XSingleton.singleton.DestroyNpc(this.NpcPool[i]); } this.NpcIndex.Clear(); this.NpcList.Clear(); this.NpcPool.Clear(); } } bool flag3 = DlgBase.singleton.IsVisible(); if (flag3) { DlgBase.singleton.OnGuildSysChange(); } } } public void InitNpcList() { int num = this._npcMaxShowNum; this.NORMALNAME = XStringDefineProxy.GetString("GuildCollectSummonNormal"); this.SPECIALNAME = XStringDefineProxy.GetString("GuildCollectSummonSpecial"); uint num2 = 101u; for (;;) { XNpcInfo.RowData byNPCID = XSingleton.singleton.NpcInfo.GetByNPCID(num2); bool flag = byNPCID == null || byNPCID.NPCType != 4u; if (flag) { break; } XNpc xnpc = XSingleton.singleton.CreateNpc(num2, true); xnpc.EngineObject.Position = XGameUI.Far_Far_Away; this.NpcPool.Add(num2); num--; bool flag2 = num <= 0; if (flag2) { break; } num2 += 1u; } } public void SyncNpcList(List list) { HashSet hashSet = new HashSet(); for (int i = 0; i < list.Count; i++) { hashSet.Add(list[i].sprite_id); } for (int j = this.NpcList.Count - 1; j >= 0; j--) { bool flag = hashSet.Contains(this.NpcList[j].id); if (flag) { hashSet.Remove(this.NpcList[j].id); } else { this.SetNpcInValid(j); this.NpcList.RemoveAt(j); } } bool flag2 = false; for (int k = 0; k < list.Count; k++) { bool flag3 = hashSet.Contains(list[k].sprite_id); if (flag3) { flag2 = true; Vector3 pos; pos= new Vector3((float)(list[k].position >> 16) / 100f, 0f, (float)(list[k].position & 65535) / 100f); string name = string.IsNullOrEmpty(list[k].summoner) ? this.NORMALNAME : string.Format("{0}{1}", list[k].summoner, this.SPECIALNAME); this.NpcList.Add(new CollectNpcInfo(list[k].sprite_id, pos, name)); } } bool flag4 = flag2; if (flag4) { this.SortNpcByMode(this._npcRefreshMode); } this.DealWithNpcList(); } public void OnMeetNpc(uint uid) { bool flag = this.NpcIndex.ContainsValue(uid); if (flag) { foreach (KeyValuePair keyValuePair in this.NpcIndex) { bool flag2 = keyValuePair.Value == uid; if (flag2) { bool flag3 = this._lastSendNpcID == keyValuePair.Key && Time.time < this._lastSendNpcTime; if (flag3) { return; } RpcC2G_GetGuildCamPartyRandItem rpcC2G_GetGuildCamPartyRandItem = new RpcC2G_GetGuildCamPartyRandItem(); rpcC2G_GetGuildCamPartyRandItem.oArg.query_type = 2u; rpcC2G_GetGuildCamPartyRandItem.oArg.npc_id = keyValuePair.Key; XSingleton.singleton.Send(rpcC2G_GetGuildCamPartyRandItem); this._lastSendNpcTime = Time.time + 0.5f; return; } } } XSingleton.singleton.ShowSystemTip(ErrorCode.ERR_GUILDACMPPATY_SPRITE_ONTEXIST, "fece00"); } public void OnMeetLottery(uint uid) { bool flag = DlgBase.singleton.IsVisible(); if (!flag) { int num = this.CheckLotteryCD(uid); bool flag2 = num != -1; if (flag2) { XSingleton.singleton.ShowSystemTip(string.Format(XStringDefineProxy.GetString("GuildCollectLotteryCDTips"), num), "fece00"); } else { this._lastMeetLotteryUid = uid; DlgBase.singleton.ShowProcess(this._lotteryWaitTime, this._lotteryProcessText, this._lotteryProcessTips, new GuildInheritProcessDlg.OnSliderProcessEnd(this.QueryLottery)); this.SetMoveState(false); XNpc npc = XSingleton.singleton.GetNpc(uid); bool flag3 = npc == null; if (!flag3) { npc.ShowUp(null); bool flag4 = npc != null; if (flag4) { XSingleton.singleton.PlaySound(npc, AudioChannel.Motion, "Audio/UI/UI_rabbit"); } XSingleton.singleton.SetTimer(float.Parse(XSingleton.singleton.GetValue("GuildCollecBoxFxTime")), new XTimerMgr.ElapsedEventHandler(this.DelayCreateLotteryBoxFx), uid); string[] array = XSingleton.singleton.GetValue("GuildCollecLotteryFxNum").Split(new char[] { '=' }); bool flag5 = array.Length < 2; if (!flag5) { int num2 = XSingleton.singleton.RandomInt(int.Parse(array[0]), int.Parse(array[1]) + 1); array = XSingleton.singleton.GetValue("GuildCollecLotteryFxProduce").Split(new char[] { '=' }); float min = float.Parse(array[0]); float max = float.Parse(array[1]); for (int i = 0; i < num2; i++) { XSingleton.singleton.SetTimer(XSingleton.singleton.RandomFloat(min, max), new XTimerMgr.ElapsedEventHandler(this.DelayCreateLotteryFlyFx), uid); } } } } } } public void DelayCreateLotteryBoxFx(object o) { uint id = (uint)o; XNpc npc = XSingleton.singleton.GetNpc(id); bool flag = npc == null; if (!flag) { bool flag2 = this._lotteryBoxFx != null; if (flag2) { XSingleton.singleton.DestroyFx(this._lotteryBoxFx, true); } this._lotteryBoxFx = XSingleton.singleton.CreateFx(XGuildCollectDocument.LotteryBoxFXPATH, null, true); this._lotteryBoxFx.Play(npc.EngineObject.Position, Quaternion.identity, Vector3.one, 1f); } } public void DelayCreateLotteryFlyFx(object o) { uint id = (uint)o; XNpc npc = XSingleton.singleton.GetNpc(id); bool flag = npc == null || XSingleton.singleton.Player == null; if (!flag) { this.CreatLotteryFx(npc.EngineObject.Position, XSingleton.singleton.Player.EngineObject.Position + new Vector3(0f, 0.3f)); } } public void QueryLottery() { this.SetMoveState(true); RpcC2G_GetGuildCamPartyRandItem rpcC2G_GetGuildCamPartyRandItem = new RpcC2G_GetGuildCamPartyRandItem(); rpcC2G_GetGuildCamPartyRandItem.oArg.query_type = 1u; rpcC2G_GetGuildCamPartyRandItem.oArg.npc_id = this._lastMeetLotteryUid; XSingleton.singleton.Send(rpcC2G_GetGuildCamPartyRandItem); } public void SetMoveState(bool state) { bool flag = XSingleton.singleton.Player != null && XSingleton.singleton.Player.Nav != null; if (flag) { XSingleton.singleton.Player.Nav.Interrupt(); XSingleton.singleton.Player.Nav.Enabled = state; } XSingleton.singleton.Freezed = !state; } public void DealWithNpcList() { bool flag = this._npcRefreshMode == CollectNpcRefreshMode.Distance; if (flag) { this.NpcList.Sort(new Comparison(this.Compare)); } int num = this._npcMaxShowNum; for (int i = 0; i < this.NpcList.Count; i++) { bool flag2 = this.NpcIndex.ContainsKey(this.NpcList[i].id); if (flag2) { num--; } } bool flag3 = num > 0; if (flag3) { for (int j = 0; j < this.NpcList.Count; j++) { bool use = this.NpcList[j].use; if (!use) { bool flag4 = !this.NpcIndex.ContainsKey(this.NpcList[j].id); if (flag4) { this.CreateNpc(this.NpcList[j].pos, this.NpcList[j].id, this.NpcList[j].name); num--; bool flag5 = num <= 0; if (flag5) { break; } } } } } } private int Compare(CollectNpcInfo x, CollectNpcInfo y) { bool flag = x.id == y.id; int result; if (flag) { result = 0; } else { float num = Vector3.Distance(x.pos, XSingleton.singleton.Player.EngineObject.Position); float num2 = Vector3.Distance(y.pos, XSingleton.singleton.Player.EngineObject.Position); result = ((num > num2) ? 1 : -1); } return result; } public void SortNpcByMode(CollectNpcRefreshMode mode) { bool flag = mode == CollectNpcRefreshMode.Distance; if (flag) { this.NpcList.Sort(new Comparison(this.Compare)); } else { XSingleton.singleton.Shuffle(ref this.NpcList); } } public void SetNpcInValid(int index) { uint num = 0u; bool flag = this.NpcIndex.TryGetValue(this.NpcList[index].id, out num); if (flag) { this.ReturnPool(num); this.NpcIndex.Remove(this.NpcList[index].id); bool flag2 = XSingleton.singleton.LastNpc != null && XSingleton.singleton.LastNpc.TypeID == num; if (flag2) { bool flag3 = XSingleton.singleton.Player != null && XSingleton.singleton.Player.Nav != null; if (flag3) { XSingleton.singleton.Player.Nav.Interrupt(); } XSingleton.singleton.LastNpc = null; } } } public void ReturnPool(uint uid) { XNpc npc = XSingleton.singleton.GetNpc(uid); bool flag = npc != null; if (flag) { npc.EngineObject.Position = XGameUI.Far_Far_Away; this.NpcPool.Add(uid); } } public void CreateNpc(Vector3 pos, uint npcID, string name) { bool flag = this.NpcPool.Count == 0; if (flag) { XSingleton.singleton.AddErrorLog("Get guildcollect Npc by pool error! It's a empty pool.", null, null, null, null, null); } else { int index = this.NpcPool.Count - 1; uint num = this.NpcPool[index]; this.NpcPool.RemoveAt(index); XNpc npc = XSingleton.singleton.GetNpc(num); bool flag2 = npc == null; if (flag2) { XSingleton.singleton.AddErrorLog("create npc by pool error. id = ", num.ToString(), null, null, null, null); } else { bool flag3 = npc.BillBoard != null; if (flag3) { npc.BillBoard.OnGuildCollectNpcNameChange(name); } npc.EngineObject.Position = pos; npc.EngineObject.LocalEulerAngles = new Vector3(0f, XSingleton.singleton.RandomFloat(-180f, 180f), 0f); this.NpcIndex[npcID] = num; } } } public void SetLotteryMachineState(bool state, bool force = false) { bool flag = XSingleton.singleton.SceneType != SceneType.SCENE_GUILD_HALL; if (!flag) { bool flag2 = !force && state == this._lotteryMachineState; if (!flag2) { this._lotteryMachineState = state; bool lotteryMachineState = this._lotteryMachineState; if (lotteryMachineState) { uint num = 100u; for (;;) { XNpcInfo.RowData byNPCID = XSingleton.singleton.NpcInfo.GetByNPCID(num); bool flag3 = byNPCID == null || byNPCID.NPCType != 5u; if (flag3) { break; } XNpc xnpc = XSingleton.singleton.CreateNpc(num, true); this.LotteryMachineList.Add(num); XFx xfx = XSingleton.singleton.CreateFx(XGuildCollectDocument.m_fxPath, null, true); bool flag4 = xfx != null && xnpc != null; if (flag4) { this._fxList.Add(xfx); xfx.Play(xnpc.EngineObject, new Vector3(-0.05f, xnpc.Height + 0.6f, 0f), Vector3.one, 1f, false, false, "", 0f); } num -= 1u; } } else { for (int i = 0; i < this.LotteryMachineList.Count; i++) { XSingleton.singleton.DestroyNpc(this.LotteryMachineList[i]); } for (int j = 0; j < this._fxList.Count; j++) { bool flag5 = this._fxList[j] != null; if (flag5) { XSingleton.singleton.DestroyFx(this._fxList[j], true); } } this._fxList.Clear(); this.LotteryMachineList.Clear(); } } } } public override void OnLeaveScene() { base.OnLeaveScene(); this.NpcIndex.Clear(); this.NpcList.Clear(); this.NpcPool.Clear(); this.LotteryMachineList.Clear(); for (int i = 0; i < this._fxList.Count; i++) { bool flag = this._fxList[i] != null; if (flag) { XSingleton.singleton.DestroyFx(this._fxList[i], true); } } this._fxList.Clear(); bool flag2 = this._lotteryFxLink.Count != 0; if (flag2) { LinkedListNode next; for (LinkedListNode linkedListNode = this._lotteryFxLink.First; linkedListNode != null; linkedListNode = next) { next = linkedListNode.Next; linkedListNode.Value.Destroy(); this._lotteryFxLink.Remove(linkedListNode); } XSingleton.singleton.AddGreenLog("Clear guildcollect fx link, cout = ", this._lotteryFxLink.Count.ToString(), null, null, null, null); } bool flag3 = this._lotteryBoxFx != null; if (flag3) { XSingleton.singleton.DestroyFx(this._lotteryBoxFx, true); this._lotteryBoxFx = null; } } public void SetMainInterfaceBtnState(bool state) { this.MainInterfaceBtnState = state; DlgBase.singleton.RefreshH5ButtonState(XSysDefine.XSys_GuildCollectMainInterface, true); } public void QuerySummon() { SeqList sequenceList = XSingleton.singleton.GetSequenceList("GuildCampSummonSpiritCost", false); string text = string.Format(XStringDefineProxy.GetString("GuildCollectSummonTips"), XLabelSymbolHelper.FormatSmallIcon(sequenceList[0, 0]), sequenceList[0, 1]); text = XSingleton.singleton.ReplaceReturn(text); string @string = XStringDefineProxy.GetString("COMMON_OK"); string string2 = XStringDefineProxy.GetString("COMMON_CANCEL"); XSingleton.singleton.ShowModalDialog(text, @string, string2, new ButtonClickEventHandler(this.OnSummonSure)); } public bool OnSummonSure(IXUIButton btn) { DlgBase.singleton.SetVisible(false, true); RpcC2G_GuildPartySummonSpirit rpc = new RpcC2G_GuildPartySummonSpirit(); XSingleton.singleton.Send(rpc); return true; } public void QueryGetRewardCount() { RpcC2G_GetGuildPartyReceiveInfo rpc = new RpcC2G_GetGuildPartyReceiveInfo(); XSingleton.singleton.Send(rpc); } public void OnUseCountGet(List list) { this.CollectUseDict.Clear(); for (int i = 0; i < list.Count; i++) { this.CollectUseDict[(uint)list[i].key] = (int)list[i].value; } bool flag = DlgBase.singleton.IsVisible(); if (flag) { DlgBase.singleton.Refresh(); } } public void QueryGetReward(uint id) { RpcC2G_GetGuildCampPartyReward rpcC2G_GetGuildCampPartyReward = new RpcC2G_GetGuildCampPartyReward(); rpcC2G_GetGuildCampPartyReward.oArg.reward_id = id; XSingleton.singleton.Send(rpcC2G_GetGuildCampPartyReward); } protected override void OnReconnected(XReconnectedEventArgs arg) { } public void CreatLotteryFx(Vector3 startPos, Vector3 endPos) { string[] array = XSingleton.singleton.GetValue("GuildCollecLotteryFxDuration").Split(new char[] { '=' }); bool flag = array.Length < 2; if (!flag) { float duration = XSingleton.singleton.RandomFloat(float.Parse(array[0]), float.Parse(array[1])); array = XSingleton.singleton.GetValue("GuildCollecLotteryFxSpeed").Split(new char[] { '=' }); bool flag2 = array.Length < 2; if (!flag2) { float speedY = XSingleton.singleton.RandomFloat(float.Parse(array[0]), float.Parse(array[1])); ParabolaFx value = new ParabolaFx(XGuildCollectDocument.LotteryFlyFXPATH, duration, speedY, startPos, endPos); this._lotteryFxLink.AddLast(value); } } } public override void Update(float fDeltaT) { base.Update(fDeltaT); bool flag = !this._activityState; if (!flag) { bool flag2 = this._lotteryFxLink.Count == 0; if (!flag2) { LinkedListNode next; for (LinkedListNode linkedListNode = this._lotteryFxLink.First; linkedListNode != null; linkedListNode = next) { next = linkedListNode.Next; bool flag3 = !linkedListNode.Value.Update(); if (flag3) { this._lotteryFxLink.Remove(linkedListNode); } } } } } public void SetTime(uint leftTime) { this.SignTime = XSingleton.singleton.GetMachineTime(); this.LeftTime = leftTime; this.SUMMONLEFTTIME = XSingleton.singleton.GetInt("GuildCampSummonSpiritTime"); } public void RefreshTime(object o = null) { int num = (int)(XSingleton.singleton.GetMachineTime() - this.SignTime); num = (int)(this.LeftTime - (uint)num); int num2 = num - this.SUMMONLEFTTIME; bool flag = num < 0; if (flag) { num = 0; } bool flag2 = num2 < 0; if (flag2) { num2 = 0; } bool flag3 = DlgBase.singleton.IsVisible(); if (flag3) { DlgBase.singleton.RefreshGuildCollectTime(num, num2); } bool flag4 = DlgBase.singleton.IsVisible(); if (flag4) { DlgBase.singleton.RefreshTime(num); } this._hallTimeToken = XSingleton.singleton.SetTimer(1f, new XTimerMgr.ElapsedEventHandler(this.RefreshTime), null); } } }