mirror of
https://github.com/EggLinks/DanhengServer-OpenSource.git
synced 2026-01-02 20:26:03 +08:00
124 lines
4.5 KiB
C#
124 lines
4.5 KiB
C#
using EggLink.DanhengServer.GameServer.Game.Battle;
|
|
using EggLink.DanhengServer.GameServer.Game.GridFight.Component;
|
|
using EggLink.DanhengServer.GameServer.Game.GridFight.Sync;
|
|
using EggLink.DanhengServer.GameServer.Game.Player;
|
|
using EggLink.DanhengServer.GameServer.Server.Packet.Send.GridFight;
|
|
using EggLink.DanhengServer.Proto;
|
|
|
|
namespace EggLink.DanhengServer.GameServer.Game.GridFight;
|
|
|
|
public class GridFightInstance(PlayerInstance player, uint season, uint divisionId, bool isOverLock, uint uniqueId)
|
|
{
|
|
public uint Season { get; } = season;
|
|
public uint DivisionId { get; } = divisionId;
|
|
public bool IsOverLock { get; } = isOverLock;
|
|
public uint UniqueId { get; } = uniqueId;
|
|
public List<BaseGridFightComponent> Components { get; } = [];
|
|
public PlayerInstance Player { get; } = player;
|
|
|
|
public BattleInstance? StartBattle()
|
|
{
|
|
return Player.BattleManager!.StartGridFightBattle(this);
|
|
}
|
|
|
|
public async ValueTask EndBattle(BattleInstance battle, PVEBattleResultCsReq req)
|
|
{
|
|
if (battle.BattleEndStatus == BattleEndStatus.BattleEndQuit) return;
|
|
|
|
List<BaseGridFightSyncData> syncs = [];
|
|
|
|
var basicComp = GetComponent<GridFightBasicComponent>();
|
|
var levelComp = GetComponent<GridFightLevelComponent>();
|
|
var prevData = basicComp.Data.Clone();
|
|
|
|
var expNum = 5u;
|
|
var baseCoin = 3u;
|
|
var interestCoin = basicComp.Data.CurGold / 10;
|
|
|
|
if (battle.BattleEndStatus == BattleEndStatus.BattleEndWin)
|
|
{
|
|
basicComp.Data.ComboNum++;
|
|
}
|
|
else
|
|
{
|
|
basicComp.Data.ComboNum = 0;
|
|
|
|
// cost hp
|
|
await basicComp.UpdateLineupHp(-5, false);
|
|
}
|
|
|
|
var comboCoin = basicComp.Data.ComboNum switch
|
|
{
|
|
>= 5 => 3u,
|
|
2 or 3 or 4 => 2u,
|
|
0 => 0u,
|
|
_ => 1u
|
|
};
|
|
|
|
await basicComp.UpdateGoldNum((int)(baseCoin + interestCoin + comboCoin), false, GridFightSrc.KGridFightSrcNone);
|
|
await basicComp.AddLevelExp(expNum, false);
|
|
|
|
List<GridFightRoleDamageSttInfo> sttList = [];
|
|
foreach (var roleBattleStt in req.Stt.GridFightBattleStt.RoleBattleStt)
|
|
{
|
|
var res = await levelComp.AddRoleDamageStt(roleBattleStt.RoleBasicId, roleBattleStt.Damage, false);
|
|
if (res.Item2 != null)
|
|
sttList.Add(res.Item2);
|
|
}
|
|
|
|
var curData = basicComp.Data.Clone();
|
|
await Player.SendPacket(new PacketGridFightEndBattleStageNotify(this, expNum, prevData, curData,
|
|
sttList, battle.BattleEndStatus == BattleEndStatus.BattleEndWin, baseCoin, interestCoin,
|
|
comboCoin));
|
|
|
|
|
|
syncs.Add(new GridFightGoldSyncData(GridFightSrc.KGridFightSrcBattleEnd, basicComp.Data));
|
|
syncs.Add(new GridFightPlayerLevelSyncData(GridFightSrc.KGridFightSrcBattleEnd, basicComp.Data));
|
|
syncs.Add(new GridFightLineupHpSyncData(GridFightSrc.KGridFightSrcBattleEnd, basicComp.Data));
|
|
syncs.Add(new GridFightComboNumSyncData(GridFightSrc.KGridFightSrcBattleEnd, basicComp.Data));
|
|
syncs.Add(new GridFightRoleDamageSttSyncData(GridFightSrc.KGridFightSrcBattleEnd, levelComp));
|
|
syncs.AddRange(await levelComp.EnterNextSection(false));
|
|
|
|
await Player.SendPacket(new PacketGridFightSyncUpdateResultScNotify(syncs));
|
|
}
|
|
|
|
public void InitializeComponents()
|
|
{
|
|
Components.Add(new GridFightBasicComponent(this));
|
|
Components.Add(new GridFightShopComponent(this));
|
|
Components.Add(new GridFightLevelComponent(this));
|
|
Components.Add(new GridFightRoleComponent(this));
|
|
|
|
_ = GetComponent<GridFightRoleComponent>().AddAvatar(1414, 3, false); // TODO test
|
|
_ = GetComponent<GridFightShopComponent>().RefreshShop(true, false);
|
|
}
|
|
|
|
public T GetComponent<T>() where T : BaseGridFightComponent
|
|
{
|
|
return (T)Components.First(c => c is T);
|
|
}
|
|
|
|
public GridFightCurrentInfo ToProto()
|
|
{
|
|
return new GridFightCurrentInfo
|
|
{
|
|
DivisionId = DivisionId,
|
|
Season = Season,
|
|
IsOverlock = IsOverLock,
|
|
UniqueId = UniqueId,
|
|
PendingAction = new GridFightPendingAction(),
|
|
GridFightGameData = ToGameDataInfo(),
|
|
RogueCurrentGameInfo = { ToGameInfos() }
|
|
};
|
|
}
|
|
|
|
public List<GridFightGameInfo> ToGameInfos()
|
|
{
|
|
return (from c in Components select c.ToProto()).ToList();
|
|
}
|
|
|
|
public GridFightGameData ToGameDataInfo()
|
|
{
|
|
return new GridFightGameData();
|
|
}
|
|
} |