2021-04-08 20:09:59 +08:00
|
|
|
|
using Cal.DataTable;
|
|
|
|
|
using ET.EventType;
|
|
|
|
|
|
|
|
|
|
using System;
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
|
|
|
|
|
namespace ET
|
|
|
|
|
{
|
|
|
|
|
public class FamilyBossComponentAwakeSystem : AwakeSystem<FamilyBossComponent>
|
|
|
|
|
{
|
|
|
|
|
public override void Awake(FamilyBossComponent self)
|
|
|
|
|
{
|
|
|
|
|
FamilyBossComponent.instance = self;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
public static class FamilyBossComponentSystem
|
|
|
|
|
{
|
|
|
|
|
public class FamilyUpdatePerMinuteEvent : AEvent<EventType.UpdatePer1HourOfDay>
|
|
|
|
|
{
|
|
|
|
|
public override async ETTask Run(UpdatePer1HourOfDay args)
|
|
|
|
|
{
|
2021-04-11 19:50:39 +08:00
|
|
|
|
int time = DateTime.UtcNow.Hour;
|
2021-04-08 20:09:59 +08:00
|
|
|
|
if (time != 14) return;
|
2021-04-11 19:50:39 +08:00
|
|
|
|
List<FamilyBoss> list = await DBComponent.Instance.QueryJson<FamilyBoss>("{}");
|
2021-04-08 20:09:59 +08:00
|
|
|
|
if (list == null || list.Count == 0)
|
|
|
|
|
{
|
|
|
|
|
return;
|
|
|
|
|
}
|
2021-04-11 19:50:39 +08:00
|
|
|
|
IEnumerable<FamilyBossConfig> bossList = DataTableHelper.GetAll<FamilyBossConfig>();
|
|
|
|
|
foreach (FamilyBoss familyBoss in list)
|
2021-04-08 20:09:59 +08:00
|
|
|
|
{
|
|
|
|
|
try
|
|
|
|
|
{
|
2021-04-11 19:50:39 +08:00
|
|
|
|
foreach (FamilyBossConfig config in bossList)
|
2021-04-08 20:09:59 +08:00
|
|
|
|
{
|
|
|
|
|
FamilyBossComponent.instance.SettleReword(familyBoss, config).Coroutine();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
catch (Exception e)
|
|
|
|
|
{
|
|
|
|
|
Log.Error(e);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
await ETTask.CompletedTask;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
public class FamilyUpdatePerDayEvent : AEvent<EventType.UpdatePer1DayOfMonth>
|
|
|
|
|
{
|
|
|
|
|
public override async ETTask Run(UpdatePer1DayOfMonth args)
|
|
|
|
|
{
|
|
|
|
|
|
2021-04-11 19:50:39 +08:00
|
|
|
|
List<FamilyBoss> list = await DBComponent.Instance.QueryJson<FamilyBoss>("{}");
|
2021-04-08 20:09:59 +08:00
|
|
|
|
if (list == null || list.Count == 0)
|
|
|
|
|
{
|
|
|
|
|
return;
|
|
|
|
|
}
|
2021-04-11 19:50:39 +08:00
|
|
|
|
IEnumerable<FamilyBossConfig> bossList = DataTableHelper.GetAll<FamilyBossConfig>();
|
|
|
|
|
foreach (FamilyBoss familyBoss in list)
|
2021-04-08 20:09:59 +08:00
|
|
|
|
{
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
foreach (FamilyBossConfig boss in bossList)
|
|
|
|
|
{
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
familyBoss.SetBossHp((int)boss.Id, boss.Hp);
|
|
|
|
|
}
|
|
|
|
|
catch (Exception e)
|
|
|
|
|
{
|
|
|
|
|
Log.Error(e);
|
|
|
|
|
}
|
|
|
|
|
}
|
2021-04-11 19:50:39 +08:00
|
|
|
|
foreach (KeyValuePair<int, LinkedList<BossDamageMap>> item in familyBoss.rankDic)
|
2021-04-08 20:09:59 +08:00
|
|
|
|
{
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
item.Value.Clear();
|
|
|
|
|
}
|
|
|
|
|
catch (Exception e)
|
|
|
|
|
{
|
|
|
|
|
Log.Error(e);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
await DBComponent.Instance.Save(familyBoss);
|
|
|
|
|
}
|
|
|
|
|
catch (Exception e)
|
|
|
|
|
{
|
|
|
|
|
Log.Error(e);
|
|
|
|
|
}
|
|
|
|
|
}
|
2021-04-11 19:50:39 +08:00
|
|
|
|
Dictionary<string, FamilyBoss> dic = FamilyBossComponent.instance.familyBossDic;
|
|
|
|
|
Dictionary<string, FamilyBoss>.ValueCollection _list = dic.Values;
|
2021-04-08 20:09:59 +08:00
|
|
|
|
dic.Clear();
|
2021-04-11 19:50:39 +08:00
|
|
|
|
foreach (FamilyBoss item in _list)
|
2021-04-08 20:09:59 +08:00
|
|
|
|
{
|
|
|
|
|
item.Dispose();
|
|
|
|
|
}
|
|
|
|
|
Log.Info($"更改boss血量");
|
|
|
|
|
await ETTask.CompletedTask;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public static async ETTask<FamilyBoss> Query(this FamilyBossComponent self, string name)
|
|
|
|
|
{
|
|
|
|
|
if (string.IsNullOrWhiteSpace(name)) return null;
|
2021-04-11 19:50:39 +08:00
|
|
|
|
if (!self.familyBossDic.TryGetValue(name, out FamilyBoss friend))
|
2021-04-08 20:09:59 +08:00
|
|
|
|
{
|
2021-04-11 19:50:39 +08:00
|
|
|
|
List<FamilyBoss> list = await DBComponent.Instance.Query<FamilyBoss>(t => t.name == name);
|
2021-04-08 20:09:59 +08:00
|
|
|
|
if (list == null || list.Count == 0)
|
|
|
|
|
{
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
self.familyBossDic[name] = friend = list[0];
|
|
|
|
|
}
|
|
|
|
|
return friend;
|
|
|
|
|
}
|
|
|
|
|
public static async ETTask Save(this FamilyBossComponent self, FamilyBoss family)
|
|
|
|
|
{
|
|
|
|
|
await DBComponent.Instance.Save(family);
|
|
|
|
|
}
|
|
|
|
|
public static async ETTask Create(this FamilyBossComponent self, string name)
|
|
|
|
|
{
|
|
|
|
|
FamilyBoss familyBoss = EntityFactory.CreateWithParent<FamilyBoss>(self);
|
|
|
|
|
familyBoss.lockedMaxId = 1;
|
|
|
|
|
familyBoss.name = name;
|
|
|
|
|
if (familyBoss.rankDic.Count == 0)
|
|
|
|
|
{
|
2021-04-11 19:50:39 +08:00
|
|
|
|
IEnumerable<FamilyBossConfig> arr = DataTableHelper.GetAll<FamilyBossConfig>();
|
2021-04-08 20:09:59 +08:00
|
|
|
|
foreach (FamilyBossConfig item in arr)
|
|
|
|
|
{
|
|
|
|
|
familyBoss.rankDic.Add((int)item.Id, new LinkedList<BossDamageMap>());
|
|
|
|
|
familyBoss.SetBossHp((int)item.Id, item.Hp);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
self.familyBossDic.Add(name, familyBoss);
|
|
|
|
|
await self.Save(familyBoss);
|
|
|
|
|
}
|
|
|
|
|
public static async ETTask<string> GetFamilyBossInfo(this FamilyBossComponent self, Unit unit, System.Collections.Generic.List<BossInfo> bossInfoList)
|
|
|
|
|
{
|
|
|
|
|
User user = UserComponent.Instance.Get(unit.Id);
|
|
|
|
|
FamilyBoss familyBoss = await self.Query(user.Family);
|
|
|
|
|
if (familyBoss == null)
|
|
|
|
|
{
|
|
|
|
|
return "您还没有加入家族!";
|
|
|
|
|
}
|
|
|
|
|
Family family = await FamilyComponent.Instance.Query(familyBoss.name);
|
|
|
|
|
if (family == null)
|
|
|
|
|
{
|
|
|
|
|
return "您还没有加入家族!";
|
|
|
|
|
}
|
2021-04-11 19:50:39 +08:00
|
|
|
|
foreach (KeyValuePair<int, int> kv in familyBoss.bossHpDic)
|
2021-04-08 20:09:59 +08:00
|
|
|
|
{
|
|
|
|
|
FamilyBossConfig familyBossConfig = DataTableHelper.Get<FamilyBossConfig>(kv.Key);
|
|
|
|
|
bossInfoList.Add(new BossInfo
|
|
|
|
|
{
|
|
|
|
|
Index = kv.Key,
|
|
|
|
|
Hp = kv.Value,
|
|
|
|
|
MaxHp = familyBossConfig.Hp,
|
|
|
|
|
HasReward = family.HasReward(kv.Key, unit.Id)
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
public static async ETTask<string> GetRankList(this FamilyBossComponent self, Unit unit, int bossId, System.Collections.Generic.List<BossDamageMap> rankList)
|
|
|
|
|
{
|
|
|
|
|
User user = UserComponent.Instance.Get(unit.Id);
|
|
|
|
|
FamilyBoss familyBoss = await self.Query(user.Family);
|
|
|
|
|
if (familyBoss == null)
|
|
|
|
|
{
|
|
|
|
|
return "您还没有加入家族!";
|
|
|
|
|
}
|
|
|
|
|
rankList.AddRange(familyBoss.GetRankList(bossId));
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
public static async ETTask<string> SettleReword(this FamilyBossComponent self, FamilyBoss familyBoss, FamilyBossConfig config)
|
|
|
|
|
{
|
|
|
|
|
if (familyBoss == null)
|
|
|
|
|
{
|
|
|
|
|
Log.Error($"familyBoss == null");
|
|
|
|
|
return "系统错误!";
|
|
|
|
|
}
|
|
|
|
|
int bossId = (int)config.Id;
|
2021-04-11 19:50:39 +08:00
|
|
|
|
LinkedList<BossDamageMap> rank = familyBoss.GetRankList(bossId);
|
|
|
|
|
int maxHp = config.Hp;
|
2021-04-08 20:09:59 +08:00
|
|
|
|
LinkedList<(long, float)> contributeList = new LinkedList<(long, float)>();
|
2021-04-11 19:50:39 +08:00
|
|
|
|
foreach (BossDamageMap damageInfo in rank)
|
2021-04-08 20:09:59 +08:00
|
|
|
|
{
|
2021-04-11 19:50:39 +08:00
|
|
|
|
float percent = damageInfo.TotalDamage * 1f / maxHp / damageInfo.DamageList.Count;
|
|
|
|
|
foreach (BossDamagePerMemberMap memberMap in damageInfo.DamageList)
|
2021-04-08 20:09:59 +08:00
|
|
|
|
{
|
|
|
|
|
ModifyList(contributeList, memberMap.Id, percent);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
bool isKilled = familyBoss.GetBossHp(bossId) <= 0;
|
|
|
|
|
Family family = await FamilyComponent.Instance.Query(familyBoss.name);
|
|
|
|
|
|
2021-04-11 19:50:39 +08:00
|
|
|
|
foreach ((long id, float percent) in contributeList)
|
2021-04-08 20:09:59 +08:00
|
|
|
|
{
|
|
|
|
|
if (!family.Caintains(id))
|
|
|
|
|
continue;
|
|
|
|
|
int contribute = MathHelper.RoundToInt(config.Contribute * percent);
|
|
|
|
|
family.AddContribution(id, contribute);
|
|
|
|
|
PlayerData playerData;
|
|
|
|
|
int parentSetId = config.Dropasubset;
|
2021-04-11 19:50:39 +08:00
|
|
|
|
Unit unit = MapUnitComponent.Instance.Get(id);
|
2021-04-08 20:09:59 +08:00
|
|
|
|
if (unit == null)
|
|
|
|
|
{
|
|
|
|
|
playerData = await DBComponent.Instance.Query<PlayerData>(id);
|
|
|
|
|
parentSetId = playerData.UpdateDrop(config.Dropasubset);
|
|
|
|
|
await UnitHelper.SaveComponenet(playerData);
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
playerData = unit.GetComponent<PlayerData>();
|
|
|
|
|
parentSetId = playerData.UpdateDrop(config.Dropasubset);
|
|
|
|
|
await UnitHelper.SaveComponenet(playerData);
|
|
|
|
|
}
|
|
|
|
|
Parentset parentSet = ParentsetCategory.Instance.Get(parentSetId);
|
|
|
|
|
family.ClearReward(bossId, id);
|
2021-04-11 19:50:39 +08:00
|
|
|
|
foreach (Parentset.Subset subSet in parentSet.SubsetArr)
|
2021-04-08 20:09:59 +08:00
|
|
|
|
{
|
|
|
|
|
SonSet sonSet = SonSetCategory.Instance.Get(subSet._Id);
|
|
|
|
|
(int itemId, int itemCount) = GetItemFormSet(sonSet.DropArr, percent, isKilled);
|
|
|
|
|
if (itemId == 0) continue;
|
|
|
|
|
family.AddReward(bossId, id, itemId, itemCount);
|
|
|
|
|
Log.Info($"【{UserComponent.Instance.Get(id)?.NickName}({id})】 掉落了【{BagHelper.GetName(itemId)}】X {itemCount}");
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
FamilyComponent.Instance.Save(family).Coroutine();
|
|
|
|
|
|
|
|
|
|
Log.Info($"是否击杀{bossId}阶boss : {isKilled}");
|
|
|
|
|
int index = 0;
|
2021-04-11 19:50:39 +08:00
|
|
|
|
foreach ((long id, float percent) in contributeList)
|
2021-04-08 20:09:59 +08:00
|
|
|
|
{
|
|
|
|
|
Log.Info($"rank [{++index}] : {id} {percent:p2}");
|
|
|
|
|
}
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
private static (int, int) GetItemFormSet(SonSet.Drop[] arr, float damagePercent, bool isKilled)
|
|
|
|
|
{
|
2021-04-11 19:50:39 +08:00
|
|
|
|
using ListComponent<int> listComponent = ListComponent<int>.Create();
|
2021-04-08 20:09:59 +08:00
|
|
|
|
foreach (SonSet.Drop drop in arr)
|
|
|
|
|
{
|
|
|
|
|
if (drop._Id == 0)
|
|
|
|
|
{
|
|
|
|
|
float weight = isKilled ? 0.5f * drop.Weight : drop.Weight;
|
|
|
|
|
weight *= (2 - damagePercent * damagePercent);
|
|
|
|
|
listComponent.List.Add(MathHelper.RoundToInt(weight));
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
listComponent.List.Add(drop.Weight);
|
|
|
|
|
}
|
|
|
|
|
int index = MathHelper.GetProbabilityIndexByWeight(listComponent.List);
|
2021-04-11 19:50:39 +08:00
|
|
|
|
SonSet.Drop item = arr[index];
|
2021-04-08 20:09:59 +08:00
|
|
|
|
return (item._Id, RandomHelper.RandomNumber(item.MinCount, item.MaxCount + 1));
|
|
|
|
|
}
|
|
|
|
|
private static void ModifyList(LinkedList<(long, float)> list, long id, float addValue)
|
|
|
|
|
{
|
2021-04-11 19:50:39 +08:00
|
|
|
|
float oldScord = 0f;
|
|
|
|
|
for (LinkedListNode<(long, float)>? item = list.First; item != null; item = item.Next)
|
2021-04-08 20:09:59 +08:00
|
|
|
|
{
|
|
|
|
|
if (item.Value.Item1 == id)
|
|
|
|
|
{
|
|
|
|
|
oldScord = item.Value.Item2;
|
|
|
|
|
list.Remove(item);
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
oldScord += addValue;
|
|
|
|
|
LinkedListHelper.InsertToLinkedListAndSort(list, (id, oldScord), (t1, t2) => t1.Item2 > t2.Item2);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|