2021-04-08 20:09:59 +08:00
|
|
|
|
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<Ranking>
|
|
|
|
|
{
|
|
|
|
|
public override void Destroy(Ranking self)
|
|
|
|
|
{
|
|
|
|
|
self.coinList.Clear();
|
|
|
|
|
self.unitList.Clear();
|
|
|
|
|
self.unitDic.Clear();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
public static class RankingSystem
|
|
|
|
|
{
|
|
|
|
|
public class UpdateRankingSystem : AEvent<ET.EventType.UpdatePer1DayOfMonth>
|
|
|
|
|
{
|
|
|
|
|
public override async ETTask Run(UpdatePer1DayOfMonth args)
|
|
|
|
|
{
|
|
|
|
|
Scene scene = Game.Scene.Get(StartSceneConfigCategory.Instance.GetBySceneName(args.zone,"Map").SceneId);
|
2021-04-11 19:50:39 +08:00
|
|
|
|
Ranking rank = scene.GetComponent<Ranking>();
|
2021-04-08 20:09:59 +08:00
|
|
|
|
await rank.Refresh();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
private const int Ranking_Max_Count = 50;
|
|
|
|
|
public static async ETTask Refresh(this Ranking self)
|
|
|
|
|
{
|
|
|
|
|
self.unitList = await DBComponent.Instance.QueryJson<NumericComponent>($"{{'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<string> GetRanking(this Ranking self, int index, System.Collections.Generic.List<RankingInfo> rankInfoList)
|
|
|
|
|
{
|
|
|
|
|
if (self.unitList == null)
|
|
|
|
|
await self.Refresh();
|
|
|
|
|
switch ((RankingInfo.RankingType)index)
|
|
|
|
|
{
|
|
|
|
|
case RankingInfo.RankingType.Level:
|
|
|
|
|
{
|
2021-04-11 19:50:39 +08:00
|
|
|
|
NumericType nt = NumericType.Level;
|
|
|
|
|
List<NumericComponent> list = self.unitDic[(int)nt];
|
2021-04-08 20:09:59 +08:00
|
|
|
|
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;
|
2021-04-11 19:50:39 +08:00
|
|
|
|
foreach (NumericComponent unit in list)
|
2021-04-08 20:09:59 +08:00
|
|
|
|
{
|
|
|
|
|
if (isNew)
|
|
|
|
|
{
|
|
|
|
|
if (listIndex++ >= Ranking_Max_Count) break;
|
|
|
|
|
self.unitDic.Add((int)nt, unit);
|
|
|
|
|
}
|
2021-04-11 19:50:39 +08:00
|
|
|
|
User user = await UserComponent.Instance.Query(unit.Id);
|
2021-04-08 20:09:59 +08:00
|
|
|
|
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:
|
|
|
|
|
{
|
2021-04-11 19:50:39 +08:00
|
|
|
|
NumericType nt = NumericType.Coin;
|
2021-04-08 20:09:59 +08:00
|
|
|
|
if (self.coinList.Count == 0)
|
|
|
|
|
{
|
2021-04-11 19:50:39 +08:00
|
|
|
|
foreach (NumericComponent num in self.unitList)
|
2021-04-08 20:09:59 +08:00
|
|
|
|
{
|
2021-04-11 19:50:39 +08:00
|
|
|
|
Store store = await StoreComponent.Instance.Query(num.Id);
|
2021-04-08 20:09:59 +08:00
|
|
|
|
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;
|
2021-04-11 19:50:39 +08:00
|
|
|
|
foreach ((long id, long coin) in self.coinList)
|
2021-04-08 20:09:59 +08:00
|
|
|
|
{
|
|
|
|
|
if (listIndex++ >= Ranking_Max_Count) break;
|
2021-04-11 19:50:39 +08:00
|
|
|
|
User user = await UserComponent.Instance.Query(id);
|
2021-04-08 20:09:59 +08:00
|
|
|
|
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)
|
|
|
|
|
{
|
2021-04-11 19:50:39 +08:00
|
|
|
|
List<NumericComponent> list = self.unitDic[(int)nt];
|
2021-04-08 20:09:59 +08:00
|
|
|
|
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;
|
2021-04-11 19:50:39 +08:00
|
|
|
|
foreach (NumericComponent unit in list)
|
2021-04-08 20:09:59 +08:00
|
|
|
|
{
|
|
|
|
|
if (isNew)
|
|
|
|
|
{
|
|
|
|
|
if (listIndex++ >= Ranking_Max_Count) break;
|
|
|
|
|
self.unitDic.Add((int)nt, unit);
|
|
|
|
|
}
|
2021-04-11 19:50:39 +08:00
|
|
|
|
User user = await UserComponent.Instance.Query(unit.Id);
|
2021-04-08 20:09:59 +08:00
|
|
|
|
rankInfoList.Add(new RankingInfo
|
|
|
|
|
{
|
|
|
|
|
Name = user.NickName,
|
|
|
|
|
Value = unit.GetAsInt(nt)
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
async ETTask SetRankongInfoFloatList(NumericType nt)
|
|
|
|
|
{
|
2021-04-11 19:50:39 +08:00
|
|
|
|
List<NumericComponent> list = self.unitDic[(int)nt];
|
2021-04-08 20:09:59 +08:00
|
|
|
|
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;
|
2021-04-11 19:50:39 +08:00
|
|
|
|
foreach (NumericComponent unit in list)
|
2021-04-08 20:09:59 +08:00
|
|
|
|
{
|
|
|
|
|
if (isNew)
|
|
|
|
|
{
|
|
|
|
|
if (listIndex++ >= Ranking_Max_Count) break;
|
|
|
|
|
self.unitDic.Add((int)nt, unit);
|
|
|
|
|
}
|
2021-04-11 19:50:39 +08:00
|
|
|
|
User user = await UserComponent.Instance.Query(unit.Id);
|
2021-04-08 20:09:59 +08:00
|
|
|
|
rankInfoList.Add(new RankingInfo
|
|
|
|
|
{
|
|
|
|
|
Name = user.NickName,
|
|
|
|
|
Value = (float)unit.Get(nt)
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|