446 lines
18 KiB
C#
446 lines
18 KiB
C#
using Cal.DataTable;
|
|
using ET.EventType;
|
|
using System;
|
|
using System.Collections.Generic;
|
|
|
|
namespace ET
|
|
{
|
|
public class BattleEndEvent : AEvent<BattleEnd>
|
|
{
|
|
public override async ETTask Run(BattleEnd args)
|
|
{
|
|
var unit = args.unit;
|
|
var team = args.team;
|
|
try
|
|
{
|
|
//清理modifier
|
|
ModifierContainerComponent modifierContainerComponent = unit.GetComponent<ModifierContainerComponent>();
|
|
|
|
}
|
|
catch (Exception e)
|
|
{
|
|
Log.Error(e);
|
|
}
|
|
if (unit.UnitType != UnitType.Player)
|
|
return;
|
|
var brocastComponent = unit.GetComponent<BrocastComponent>();
|
|
var aoi = brocastComponent.GetInternalAll();
|
|
using var listComponent = ListComponent<long>.Create();
|
|
foreach (var u in aoi)
|
|
{
|
|
if (!team.Contains(u))
|
|
listComponent.List.Add(u);
|
|
}
|
|
foreach (var item in listComponent.List)
|
|
{
|
|
brocastComponent.RemoveInternal(item);
|
|
Log.Info($"{unit.Id}去除{item}");
|
|
}
|
|
await ETTask.CompletedTask;
|
|
}
|
|
}
|
|
|
|
public class BattleEnd_AddHpEvent : AEvent<EventType.BattleEnd_AddHp>
|
|
{
|
|
public override async ETTask Run(EventType.BattleEnd_AddHp args)
|
|
{
|
|
var unit = args.unit;
|
|
PlayerData data = unit.GetComponent<PlayerData>();
|
|
var num = unit.GetComponent<NumericComponent>();
|
|
AddHp(num, data);
|
|
AddMp(num, data);
|
|
UnitHelper.SaveComponenet(data).Coroutine();
|
|
UnitHelper.SaveComponenet(num).Coroutine();
|
|
await ETTask.CompletedTask;
|
|
}
|
|
|
|
private void AddHp(NumericComponent num, PlayerData data)
|
|
{
|
|
var hpKV = data.hpAutoFullCapatial;
|
|
int hp = MathHelper.RoundToInt(hpKV.Value / 10000f * num.GetAsInt(NumericType.MaxHp)) - num.GetAsInt(NumericType.Hp);
|
|
if (hp < 0) hp = 0;
|
|
int capacity = hpKV.Key;
|
|
if (capacity <= 0)
|
|
{
|
|
return;
|
|
}
|
|
if (hp > capacity)
|
|
{
|
|
hp = capacity;
|
|
}
|
|
capacity -= hp;
|
|
data.hpAutoFullCapatial = KeyValuePair.Create(capacity, hpKV.Value);
|
|
num.AddSet(NumericType.Hp, hp);
|
|
}
|
|
private void AddMp(NumericComponent num, PlayerData data)
|
|
{
|
|
var hpKV = data.mpAutoFullCapatial;
|
|
int mp = MathHelper.RoundToInt(hpKV.Value / 10000f * num.GetAsInt(NumericType.MaxMp) - num.GetAsInt(NumericType.Mp));
|
|
if (mp < 0) mp = 0;
|
|
int capacity = hpKV.Key;
|
|
if (capacity <= 0)
|
|
{
|
|
return;
|
|
}
|
|
if (mp > capacity)
|
|
{
|
|
mp = capacity;
|
|
}
|
|
capacity -= mp;
|
|
data.mpAutoFullCapatial = KeyValuePair.Create(capacity, hpKV.Value);
|
|
num.AddSet(NumericType.Mp, mp);
|
|
}
|
|
}
|
|
public class BattleEnd_GetRewordEvent : AEvent<EventType.BattleEnd_Reword>
|
|
{
|
|
//15 8 5 3
|
|
private readonly static float[] expAddtionArr = { 0, 0.15f, 0.23f, 0.28f, 0.31f };
|
|
//20 13 8 5
|
|
private readonly static float[] coinAddtionArr = { 0, 0.20f, 0.33f, 0.41f, 0.46f };
|
|
|
|
private const float TeamLeaderAddExp = 1.2f;
|
|
public override async ETTask Run(EventType.BattleEnd_Reword args)
|
|
{
|
|
var unit = args.unit;
|
|
var rewordMap = args.rewordMap;
|
|
var battleType = args.battleType;
|
|
|
|
if (unit.UnitType != UnitType.Player)
|
|
return;
|
|
try
|
|
{
|
|
var playerData = unit.GetComponent<PlayerData>();
|
|
var now = TimeHelper.ClientNow();
|
|
if (playerData.BattleExpSpeed != 1 && playerData.battleExpSpeedLeastTime < now)
|
|
{
|
|
playerData.BattleExpSpeed = 1;
|
|
UnitHelper.Save<PlayerData>(unit).Coroutine();
|
|
}
|
|
|
|
var battleInteractiveInfo = MainStoryMap.Instance.GetBattleInteractiveInfo(unit.TeamLeaderId);
|
|
int monsterId = battleInteractiveInfo.LeaderMonsterId;
|
|
//!不触发奖励
|
|
if (monsterId == 0) return;
|
|
|
|
switch (battleType)
|
|
{
|
|
default:
|
|
Log.ErrorDetail($"【{ UserComponent.Instance.Get(unit.Id)?.NickName} ({ unit.Id})】 battle type is {battleType}");
|
|
break;
|
|
case BattleType.TrialCopy:
|
|
await TrialCopyReward(unit, monsterId, rewordMap);
|
|
return;
|
|
case BattleType.MainStory:
|
|
await MainStoryReward(unit, monsterId, args.configid, rewordMap);
|
|
return;
|
|
case BattleType.Boss:
|
|
await BossReword(unit, monsterId, rewordMap);
|
|
return;
|
|
case BattleType.IdleBattle:
|
|
await BattleIdleReword(unit, args.configid, monsterId, rewordMap);
|
|
return;
|
|
case BattleType.ManulEquip:
|
|
await ManulEquipReward(unit, monsterId, rewordMap);
|
|
return;
|
|
}
|
|
}
|
|
catch (Exception e)
|
|
{
|
|
Log.Error(e);
|
|
}
|
|
|
|
}
|
|
|
|
private async ETTask MainStoryReward(Unit unit, int monsterId, long configid,UnOrderMultiMap<long, (int, int)> rewordMap)
|
|
{
|
|
await ETTask.CompletedTask;
|
|
MonsterBase monsterBase = DataTableHelper.Get<MonsterBase>(monsterId);
|
|
if (monsterBase == null)
|
|
{
|
|
Log.Error($"monsterBase ==null where id = {monsterId}");
|
|
return;
|
|
}
|
|
//队长
|
|
float drop = 1;
|
|
float expAddtion = 1, coinAddtion = 1;
|
|
var playerData = unit.GetComponent<PlayerData>();
|
|
Team team = TeamComponent.Instance.Get(unit.TeamLeaderId);
|
|
if (unit.IsTeamLeader && team.MemberCount > 1) expAddtion *= TeamLeaderAddExp;
|
|
int addtionIndex = team.MemberCount - 1;
|
|
expAddtion += expAddtionArr[addtionIndex];
|
|
coinAddtion += coinAddtionArr[addtionIndex];
|
|
Unit leader = team.GetLeader();
|
|
if (playerData.ForbidExp || (leader.isAI && (!playerData.HasMainstoryAITime() && !playerData.HasMainstoryVIPAITime())))
|
|
{
|
|
expAddtion = 0;
|
|
drop = 0;
|
|
}
|
|
MainStory mainStory = MainStoryCategory.Instance.Get(configid);
|
|
if (mainStory != null && mainStory.Layer != 10) expAddtion /= 5f;
|
|
|
|
var num = unit.GetComponent<NumericComponent>();
|
|
if (!unit.IsAlive)
|
|
{
|
|
expAddtion *= 0.5f;
|
|
drop *= 0.5f;
|
|
}
|
|
//!Exp
|
|
long exp = MathHelper.RoundToLong(monsterBase.Exp * playerData.BattleExpSpeed * expAddtion);
|
|
num.AddSet(NumericType.Exp, exp);
|
|
|
|
if (drop != 0)
|
|
{
|
|
var rewardRet = Drop(unit, playerData, BattleType.MainStory, monsterBase.Dropasubset, rewordMap, drop, "主线掉落" );
|
|
SendMessage(unit, num, rewardRet, exp, 0);
|
|
}
|
|
|
|
UnitHelper.Save<Bag>(unit).Coroutine();
|
|
}
|
|
private async ETTask TrialCopyReward(Unit unit, int monsterId, UnOrderMultiMap<long, (int, int)> rewordMap)
|
|
{
|
|
await ETTask.CompletedTask;
|
|
MonsterBase monsterBase = DataTableHelper.Get<MonsterBase>(monsterId);
|
|
if (monsterBase == null)
|
|
{
|
|
Log.Error($"monsterBase ==null where id = {monsterId}");
|
|
return;
|
|
}
|
|
float expAddtion = 1;
|
|
var playerData = unit.GetComponent<PlayerData>();
|
|
float drop = 1;
|
|
var num = unit.GetComponent<NumericComponent>();
|
|
if (!unit.IsAlive)
|
|
{
|
|
expAddtion *= 0.5f;
|
|
drop *= 0.5f;
|
|
}
|
|
//!Exp
|
|
long exp = MathHelper.RoundToLong(monsterBase.Exp * playerData.BattleExpSpeed * expAddtion);
|
|
num.AddSet(NumericType.Exp, exp);
|
|
|
|
if (drop != 0)
|
|
{
|
|
var rewardRet = Drop(unit, playerData, BattleType.TrialCopy, monsterBase.Dropasubset, rewordMap, drop, "试炼掉落");
|
|
SendMessage(unit, num, rewardRet, exp, 0);
|
|
}
|
|
|
|
UnitHelper.Save<Bag>(unit).Coroutine();
|
|
}
|
|
|
|
private async ETTask BattleIdleReword(Unit unit, long configid, int monsterId, UnOrderMultiMap<long, (int, int)> rewordMap)
|
|
{
|
|
await ETTask.CompletedTask;
|
|
MonsterBase monsterBase = DataTableHelper.Get<MonsterBase>(monsterId);
|
|
if (monsterBase == null)
|
|
{
|
|
Log.Error($"monsterBase ==null where id = {monsterId}");
|
|
return;
|
|
}
|
|
float expAddtion = 1, coinAddtion = 1;
|
|
float reduceDrop = 0.2f;
|
|
var playerData = unit.GetComponent<PlayerData>();
|
|
Team team = TeamComponent.Instance.Get(unit.TeamLeaderId);
|
|
int addtionIndex = team.MemberCount - 1;
|
|
expAddtion += expAddtionArr[addtionIndex];
|
|
coinAddtion += coinAddtionArr[addtionIndex];
|
|
if (playerData.ForbidExp)
|
|
{
|
|
expAddtion = 0;
|
|
reduceDrop = 0;
|
|
}
|
|
//!经验铜币减半
|
|
float reduce = 0.7f;
|
|
expAddtion *= reduce;
|
|
|
|
var num = unit.GetComponent<NumericComponent>();
|
|
if (!unit.IsAlive)
|
|
{
|
|
expAddtion *= 0.2f;
|
|
reduceDrop *= 0;
|
|
}
|
|
else
|
|
{
|
|
try
|
|
{
|
|
if (!playerData.ForbidExp)
|
|
{
|
|
MainStory mainStory = MainStoryCategory.Instance.Get(configid);
|
|
float coin = ConstDefine.IdleBattleAddCoinArr.RandomArray_Len2();
|
|
int coinIndex = mainStory.SceneId - Sys_SceneId.Scene_MainStory1;
|
|
coin *= ConstDefine.MainstoryAddCoeconfident[coinIndex];
|
|
StatisticsHelper.AddInfo(unit.Id, StatisticComponent.StatisticType.Coin, StatisticsTypes.CoinSources_IdleBattle, (long)coin);
|
|
CharacterHelper.AddMoney(unit, CharacterHelper.MoneyType.Coin, (long)coin);
|
|
}
|
|
}
|
|
catch (Exception e)
|
|
{
|
|
Log.Error(e);
|
|
}
|
|
|
|
}
|
|
//!Exp
|
|
long exp = MathHelper.RoundToLong(monsterBase.Exp * playerData.BattleExpSpeed * expAddtion);
|
|
num.AddSet(NumericType.Exp, exp);
|
|
|
|
//if (reduceDrop != 0)
|
|
//{
|
|
// var rewardRet = Drop(unit, playerData, monsterBase.Dropasubset, rewordMap, reduceDrop, "挂机掉落");
|
|
// SendMessage(unit, num, rewardRet, exp, 0);
|
|
//}
|
|
}
|
|
|
|
private async ETTask BossReword(Unit unit, int monsterId, UnOrderMultiMap<long, (int, int)> rewordMap)
|
|
{
|
|
await ETTask.CompletedTask;
|
|
MonsterBase monsterBase = MonsterBaseCategory.Instance.Get(monsterId);
|
|
if (monsterBase == null)
|
|
{
|
|
return;
|
|
}
|
|
Team team = TeamComponent.Instance.Get(unit.TeamLeaderId);
|
|
int addtionIndex = team.MemberCount - 1;
|
|
float expAddtion = 1 + expAddtionArr[addtionIndex];
|
|
float coinAddtion = 1 + coinAddtionArr[addtionIndex];
|
|
|
|
if (!unit.IsAlive)
|
|
expAddtion /= 2;
|
|
var num = unit.GetComponent<NumericComponent>();
|
|
var playerData = unit.GetComponent<PlayerData>();
|
|
//!Exp
|
|
long exp = MathHelper.RoundToLong(monsterBase.Exp * playerData.BattleExpSpeed * expAddtion);
|
|
num.AddSet(NumericType.Exp, exp);
|
|
|
|
var rewardRet = Drop(unit, playerData, BattleType.Boss, monsterBase.Dropasubset, rewordMap, 1, "Boss掉落");
|
|
SendMessage(unit, num, rewardRet, exp, 0);
|
|
}
|
|
private async ETTask ManulEquipReward(Unit unit, int monsterId, UnOrderMultiMap<long, (int, int)> rewordMap)
|
|
{
|
|
await ETTask.CompletedTask;
|
|
ManulEquipMonsterConfig manulEquipMonsterConfig = ManulEquipMonsterConfigCategory.Instance.Get(monsterId);
|
|
if (manulEquipMonsterConfig == null)
|
|
{
|
|
Log.Error($"manulEquipMonsterConfig ==null where id = {monsterId}");
|
|
return;
|
|
}
|
|
|
|
float reduceDrop = 1;
|
|
if (!unit.IsAlive)
|
|
{
|
|
reduceDrop *= 0.3f;
|
|
}
|
|
var num = unit.GetComponent<NumericComponent>();
|
|
var playerData = unit.GetComponent<PlayerData>();
|
|
|
|
var rewardRet = Drop(unit, playerData, BattleType.ManulEquip, manulEquipMonsterConfig.Dropasubset, rewordMap, reduceDrop, "手工副本掉落", true);
|
|
SendMessage(unit, num, rewardRet, 0, 0);
|
|
}
|
|
private M2C_SendReward Drop(Unit unit, PlayerData playerData, BattleType battleType, int parentId, UnOrderMultiMap<long, (int, int)> rewordMap, float dropProperbility, string getSource, bool isLock = false)
|
|
{
|
|
try
|
|
{
|
|
var rewardRet = new M2C_SendReward();
|
|
if (parentId == 0) return rewardRet;
|
|
Parentset parentSet = ParentsetCategory.Instance.Get(parentId);
|
|
foreach (var subSet in parentSet.SubsetArr)
|
|
{
|
|
var sonSetId = playerData.UpdateDrop(subSet._Id);
|
|
SonSet sonSet = SonSetCategory.Instance.Get(sonSetId);
|
|
(int itemId, int itemCount) = GetItemFormSet(sonSet.DropArr, dropProperbility, false);
|
|
if (itemId == 0) continue;
|
|
if (!isLock)
|
|
{
|
|
isLock = sonSet.IsLock;
|
|
}
|
|
BagHelper.AddItem(unit, itemId, itemCount, isLock, getSource: getSource);
|
|
UpdateTask(unit, itemId).Coroutine();
|
|
rewardRet.ItemList.Add(new RewardItem() { Id = itemId, Count = 1, ItemType = BagHelper.GetItemType(itemId) });
|
|
rewordMap.Add(unit.Id, (itemId, itemCount));
|
|
try
|
|
{
|
|
if (itemId == BagHelper.CoinId)
|
|
{
|
|
string sources = battleType switch
|
|
{
|
|
BattleType.MainStory => StatisticsTypes.CoinSources_MainStory,
|
|
BattleType.TrialCopy => StatisticsTypes.CoinSources_TrialCopy,
|
|
BattleType.Boss => StatisticsTypes.CoinSources_Boss,
|
|
BattleType.IdleBattle => StatisticsTypes.CoinSources_IdleBattle,
|
|
_ => null,
|
|
};
|
|
if (sources != null)
|
|
StatisticsHelper.AddInfo(unit.Id, StatisticComponent.StatisticType.Coin, sources, (long)itemCount);
|
|
}
|
|
else if (itemId == BagHelper.GemId)
|
|
{
|
|
string sources = battleType switch
|
|
{
|
|
BattleType.MainStory => StatisticsTypes.GemSources_MainStory,
|
|
BattleType.TrialCopy => StatisticsTypes.GemSources_TrialCopy,
|
|
BattleType.Boss => StatisticsTypes.GemSources_Boss,
|
|
_ => null,
|
|
};
|
|
if (sources != null)
|
|
StatisticsHelper.AddInfo(unit.Id, StatisticComponent.StatisticType.Gem, sources, (long)itemCount);
|
|
}
|
|
}
|
|
catch (Exception)
|
|
{
|
|
|
|
}
|
|
if (AppConfig.inst.isTest)
|
|
Log.Info($"【{UserComponent.Instance.Get(unit.Id)?.NickName}({unit.Id})】 掉落了【{BagHelper.GetName(itemId)}】X {itemCount}");
|
|
}
|
|
return rewardRet;
|
|
}
|
|
catch (Exception e)
|
|
{
|
|
Log.Error(e);
|
|
return new M2C_SendReward();
|
|
}
|
|
}
|
|
|
|
private static (int, int) GetItemFormSet(SonSet.Drop[] arr, float damagePercent, bool isKilled)
|
|
{
|
|
using var listComponent = ListComponent<int>.Create();
|
|
List<int> weightList = listComponent.List;
|
|
foreach (SonSet.Drop drop in arr)
|
|
{
|
|
if (drop._Id == 0)
|
|
{
|
|
float weight = isKilled ? 0.5f * drop.Weight : drop.Weight;
|
|
weight /= (damagePercent * damagePercent);
|
|
weightList.Add(MathHelper.RoundToInt(weight));
|
|
}
|
|
else
|
|
weightList.Add(drop.Weight);
|
|
}
|
|
int index = MathHelper.GetProbabilityIndexByWeight(weightList);
|
|
var item = arr[index];
|
|
return (item._Id, RandomHelper.RandomNumber(item.MinCount, item.MaxCount + 1));
|
|
}
|
|
private void SendMessage(Unit unit, NumericComponent num, M2C_SendReward rewardRet, long exp, long coin)
|
|
{
|
|
|
|
var bagRet = new M2C_SendBag();
|
|
BagHelper.GetBagInfo(unit, bagRet.BagMapList);
|
|
MessageHelper.SendActor(unit, bagRet);
|
|
//!发送奖励信息
|
|
rewardRet.Exp = exp;
|
|
rewardRet.Coin = coin;
|
|
MessageHelper.SendActor(unit, rewardRet);
|
|
}
|
|
|
|
private async ETTask UpdateTask(Unit unit, int itemId)
|
|
{
|
|
await Game.EventSystem.Publish(new EventType.UpdateTaskState
|
|
{
|
|
unit = unit,
|
|
type = TaskTargetType.CollectionTask,
|
|
value = itemId
|
|
});
|
|
}
|
|
|
|
}
|
|
|
|
|
|
} |