using Cal.DataTable; using ET.EventType; using System; using System.Collections.Generic; using System.Diagnostics.CodeAnalysis; using System.Text; namespace ET { public class RankingDestroySystem : DestroySystem { public override void Destroy(Ranking self) { self.coinList.Clear(); self.unitList.Clear(); self.unitDic.Clear(); } } public static class RankingSystem { public class UpdateRankingSystem : AEvent { public override async ETTask Run(UpdatePer1DayOfMonth args) { Scene scene = Game.Scene.Get(StartSceneConfigCategory.Instance.GetBySceneName(args.zone,"Map").SceneId); Ranking rank = scene.GetComponent(); await rank.Refresh(); } } private const int Ranking_Max_Count = 50; public static async ETTask Refresh(this Ranking self) { self.unitList = await DBComponent.Instance.QueryJson($"{{'NumericDic':{{ $elemMatch : {{'k':{(int)NumericType.Level},'v':{{ $gte:100}}}}}}}}"); if (self.unitList != null && self.unitList.Count > 0) { self.unitDic.Clear(); self.coinList.Clear(); } self.unitList.RemoveAll(t => t.Id == 10001); } public static async ETTask GetRanking(this Ranking self, int index, System.Collections.Generic.List rankInfoList) { if (self.unitList == null) await self.Refresh(); switch ((RankingInfo.RankingType)index) { case RankingInfo.RankingType.Level: { NumericType nt = NumericType.Level; List list = self.unitDic[(int)nt]; bool isNew = false; if (list == null || list.Count == 0) { isNew = true; self.unitList.Sort((a, b) => -a.GetAsInt(nt).CompareTo(b.GetAsInt(nt))); list = self.unitList; } int listIndex = 0; foreach (NumericComponent unit in list) { if (isNew) { if (listIndex++ >= Ranking_Max_Count) break; self.unitDic.Add((int)nt, unit); } User user = await UserComponent.Instance.Query(unit.Id); rankInfoList.Add(new RankingInfo { Name = user.NickName, Job = JobHelper.GetStrJob(user.JobId,unit.GetAsInt(NumericType.Transmigration)), Value = unit.GetAsInt(nt) }); } } break; case RankingInfo.RankingType.Coin: { NumericType nt = NumericType.Coin; if (self.coinList.Count == 0) { foreach (NumericComponent num in self.unitList) { Store store = await StoreComponent.Instance.Query(num.Id); long storeCoin = 0; if (store != null) storeCoin = store.CoinCount; self.coinList.Add((num.Id, num.GetAsLong(nt) + storeCoin)); } self.coinList.Sort((a, b) => { return -a.Item2.CompareTo(b.Item2); }); } int listIndex = 0; foreach ((long id, long coin) in self.coinList) { if (listIndex++ >= Ranking_Max_Count) break; User user = await UserComponent.Instance.Query(id); rankInfoList.Add(new RankingInfo { Name = user.NickName, Value = coin }); } } break; case RankingInfo.RankingType.Hp: await SetRankongInfoList(NumericType.MaxHp); break; case RankingInfo.RankingType.Mp: await SetRankongInfoList(NumericType.MaxMp); break; case RankingInfo.RankingType.Pet: break; case RankingInfo.RankingType.Dvo: await SetRankongInfoFloatList(NumericType.Dvo); break; case RankingInfo.RankingType.PAtk: await SetRankongInfoList(NumericType.PhyAtk); break; case RankingInfo.RankingType.MAtk: await SetRankongInfoList(NumericType.SpiAtk); break; case RankingInfo.RankingType.PDef: await SetRankongInfoList(NumericType.PhyDef); break; case RankingInfo.RankingType.MDef: await SetRankongInfoList(NumericType.SpiDef); break; case RankingInfo.RankingType.PCriR: await SetRankongInfoFloatList(NumericType.Pcrir); break; case RankingInfo.RankingType.PCri: await SetRankongInfoFloatList(NumericType.Pcri); break; case RankingInfo.RankingType.MCriR: await SetRankongInfoFloatList(NumericType.Mcrir); break; case RankingInfo.RankingType.MCri: await SetRankongInfoFloatList(NumericType.Mcri); break; case RankingInfo.RankingType.PRed: await SetRankongInfoFloatList(NumericType.Nphyi); break; case RankingInfo.RankingType.MRed: await SetRankongInfoFloatList(NumericType.Nmeni); break; default: break; } return string.Empty; async ETTask SetRankongInfoList(NumericType nt) { List list = self.unitDic[(int)nt]; bool isNew = false; if (list == null || list.Count == 0) { isNew = true; self.unitList.Sort((a, b) => -a.GetAsInt(nt).CompareTo(b.GetAsInt(nt))); list = self.unitList; } int listIndex = 0; foreach (NumericComponent unit in list) { if (isNew) { if (listIndex++ >= Ranking_Max_Count) break; self.unitDic.Add((int)nt, unit); } User user = await UserComponent.Instance.Query(unit.Id); rankInfoList.Add(new RankingInfo { Name = user.NickName, Value = unit.GetAsInt(nt) }); } } async ETTask SetRankongInfoFloatList(NumericType nt) { List list = self.unitDic[(int)nt]; bool isNew = false; if (list == null || list.Count == 0) { isNew = true; self.unitList.Sort((a, b) => -a.Get(nt).CompareTo(b.Get(nt))); list = self.unitList; } int listIndex = 0; foreach (NumericComponent unit in list) { if (isNew) { if (listIndex++ >= Ranking_Max_Count) break; self.unitDic.Add((int)nt, unit); } User user = await UserComponent.Instance.Query(unit.Id); rankInfoList.Add(new RankingInfo { Name = user.NickName, Value = (float)unit.Get(nt) }); } } } } }