2021-04-08 20:09:59 +08:00
|
|
|
|
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)
|
|
|
|
|
{
|
2021-04-11 19:50:39 +08:00
|
|
|
|
Unit unit = args.unit;
|
|
|
|
|
Team team = args.team;
|
2021-04-08 20:09:59 +08:00
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
//清理modifier
|
|
|
|
|
ModifierContainerComponent modifierContainerComponent = unit.GetComponent<ModifierContainerComponent>();
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
catch (Exception e)
|
|
|
|
|
{
|
|
|
|
|
Log.Error(e);
|
|
|
|
|
}
|
|
|
|
|
if (unit.UnitType != UnitType.Player)
|
|
|
|
|
return;
|
2021-04-11 19:50:39 +08:00
|
|
|
|
BrocastComponent brocastComponent = unit.GetComponent<BrocastComponent>();
|
|
|
|
|
HashSet<long> aoi = brocastComponent.GetInternalAll();
|
|
|
|
|
using ListComponent<long> listComponent = ListComponent<long>.Create();
|
|
|
|
|
foreach (long u in aoi)
|
2021-04-08 20:09:59 +08:00
|
|
|
|
{
|
|
|
|
|
if (!team.Contains(u))
|
|
|
|
|
listComponent.List.Add(u);
|
|
|
|
|
}
|
2021-04-11 19:50:39 +08:00
|
|
|
|
foreach (long item in listComponent.List)
|
2021-04-08 20:09:59 +08:00
|
|
|
|
{
|
|
|
|
|
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)
|
|
|
|
|
{
|
2021-04-11 19:50:39 +08:00
|
|
|
|
Unit unit = args.unit;
|
2021-04-08 20:09:59 +08:00
|
|
|
|
PlayerData data = unit.GetComponent<PlayerData>();
|
2021-04-11 19:50:39 +08:00
|
|
|
|
NumericComponent num = unit.GetComponent<NumericComponent>();
|
2021-04-08 20:09:59 +08:00
|
|
|
|
AddHp(num, data);
|
|
|
|
|
AddMp(num, data);
|
|
|
|
|
UnitHelper.SaveComponenet(data).Coroutine();
|
|
|
|
|
UnitHelper.SaveComponenet(num).Coroutine();
|
|
|
|
|
await ETTask.CompletedTask;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void AddHp(NumericComponent num, PlayerData data)
|
|
|
|
|
{
|
2021-04-11 19:50:39 +08:00
|
|
|
|
KeyValuePair<int, int> hpKV = data.hpAutoFullCapatial;
|
2021-04-08 20:09:59 +08:00
|
|
|
|
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)
|
|
|
|
|
{
|
2021-04-11 19:50:39 +08:00
|
|
|
|
KeyValuePair<int, int> hpKV = data.mpAutoFullCapatial;
|
2021-04-08 20:09:59 +08:00
|
|
|
|
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
|
2021-04-13 20:39:32 +08:00
|
|
|
|
private static readonly float[] expAddtionArr = { 0, 0.15f, 0.23f, 0.28f, 0.31f };
|
2021-04-08 20:09:59 +08:00
|
|
|
|
//20 13 8 5
|
2021-04-13 20:39:32 +08:00
|
|
|
|
private static readonly float[] coinAddtionArr = { 0, 0.20f, 0.33f, 0.41f, 0.46f };
|
2021-04-08 20:09:59 +08:00
|
|
|
|
|
|
|
|
|
private const float TeamLeaderAddExp = 1.2f;
|
|
|
|
|
public override async ETTask Run(EventType.BattleEnd_Reword args)
|
|
|
|
|
{
|
2021-04-11 19:50:39 +08:00
|
|
|
|
Unit unit = args.unit;
|
|
|
|
|
UnOrderMultiMap<long, (int, int)> rewordMap = args.rewordMap;
|
|
|
|
|
BattleType battleType = args.battleType;
|
2021-04-08 20:09:59 +08:00
|
|
|
|
|
|
|
|
|
if (unit.UnitType != UnitType.Player)
|
|
|
|
|
return;
|
|
|
|
|
try
|
|
|
|
|
{
|
2021-04-11 19:50:39 +08:00
|
|
|
|
PlayerData playerData = unit.GetComponent<PlayerData>();
|
|
|
|
|
long now = TimeHelper.ClientNow();
|
2021-04-13 20:39:32 +08:00
|
|
|
|
if (playerData.BattleExpSpeed > 1 && playerData.battleExpSpeedLeastTime < now)
|
2021-04-08 20:09:59 +08:00
|
|
|
|
{
|
|
|
|
|
playerData.BattleExpSpeed = 1;
|
|
|
|
|
UnitHelper.Save<PlayerData>(unit).Coroutine();
|
|
|
|
|
}
|
|
|
|
|
|
2021-04-11 19:50:39 +08:00
|
|
|
|
MainStoryInteractive battleInteractiveInfo = MainStoryMap.Instance.GetBattleInteractiveInfo(unit.TeamLeaderId);
|
2021-04-08 20:09:59 +08:00
|
|
|
|
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:
|
2021-04-13 20:39:32 +08:00
|
|
|
|
await TrialCopyHelper.GetReword(unit, monsterId, rewordMap);
|
2021-04-08 20:09:59 +08:00
|
|
|
|
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;
|
2021-04-11 19:50:39 +08:00
|
|
|
|
PlayerData playerData = unit.GetComponent<PlayerData>();
|
2021-04-08 20:09:59 +08:00
|
|
|
|
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;
|
|
|
|
|
|
2021-04-11 19:50:39 +08:00
|
|
|
|
NumericComponent num = unit.GetComponent<NumericComponent>();
|
2021-04-08 20:09:59 +08:00
|
|
|
|
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)
|
|
|
|
|
{
|
2021-04-15 00:12:07 +08:00
|
|
|
|
M2C_SendReward rewardRet = new M2C_SendReward() ;
|
|
|
|
|
DropHelper.Drop(unit, playerData, BattleType.MainStory, monsterBase.Dropasubset, rewordMap, drop, "主线掉落", list:rewardRet.ItemList );
|
2021-04-08 20:09:59 +08:00
|
|
|
|
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;
|
2021-04-11 19:50:39 +08:00
|
|
|
|
PlayerData playerData = unit.GetComponent<PlayerData>();
|
2021-04-08 20:09:59 +08:00
|
|
|
|
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;
|
|
|
|
|
|
2021-04-11 19:50:39 +08:00
|
|
|
|
NumericComponent num = unit.GetComponent<NumericComponent>();
|
2021-04-08 20:09:59 +08:00
|
|
|
|
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;
|
2021-04-11 19:50:39 +08:00
|
|
|
|
NumericComponent num = unit.GetComponent<NumericComponent>();
|
|
|
|
|
PlayerData playerData = unit.GetComponent<PlayerData>();
|
2021-04-08 20:09:59 +08:00
|
|
|
|
//!Exp
|
|
|
|
|
long exp = MathHelper.RoundToLong(monsterBase.Exp * playerData.BattleExpSpeed * expAddtion);
|
|
|
|
|
num.AddSet(NumericType.Exp, exp);
|
|
|
|
|
|
2021-04-15 00:12:07 +08:00
|
|
|
|
M2C_SendReward rewardRet = new M2C_SendReward();
|
|
|
|
|
DropHelper.Drop(unit, playerData, BattleType.Boss, monsterBase.Dropasubset, rewordMap, 1, "Boss掉落", list:rewardRet.ItemList);
|
2021-04-08 20:09:59 +08:00
|
|
|
|
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;
|
|
|
|
|
}
|
2021-04-11 19:50:39 +08:00
|
|
|
|
NumericComponent num = unit.GetComponent<NumericComponent>();
|
|
|
|
|
PlayerData playerData = unit.GetComponent<PlayerData>();
|
2021-04-08 20:09:59 +08:00
|
|
|
|
|
2021-04-15 00:12:07 +08:00
|
|
|
|
M2C_SendReward rewardRet = new M2C_SendReward();
|
|
|
|
|
DropHelper. Drop(unit, playerData, BattleType.ManulEquip, manulEquipMonsterConfig.Dropasubset, rewordMap, reduceDrop, "手工副本掉落", true, list:rewardRet.ItemList);
|
2021-04-08 20:09:59 +08:00
|
|
|
|
SendMessage(unit, num, rewardRet, 0, 0);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2021-04-13 20:39:32 +08:00
|
|
|
|
|
|
|
|
|
private static void SendMessage(Unit unit, NumericComponent num, M2C_SendReward rewardRet, long exp, long coin)
|
2021-04-08 20:09:59 +08:00
|
|
|
|
{
|
|
|
|
|
|
2021-04-11 19:50:39 +08:00
|
|
|
|
M2C_SendBag bagRet = new M2C_SendBag();
|
2021-04-08 20:09:59 +08:00
|
|
|
|
BagHelper.GetBagInfo(unit, bagRet.BagMapList);
|
|
|
|
|
MessageHelper.SendActor(unit, bagRet);
|
|
|
|
|
//!发送奖励信息
|
|
|
|
|
rewardRet.Exp = exp;
|
|
|
|
|
rewardRet.Coin = coin;
|
|
|
|
|
MessageHelper.SendActor(unit, rewardRet);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
}
|