Skip to content

Commit

Permalink
Merge pull request #239 from alborrajo/feature/lostpawn
Browse files Browse the repository at this point in the history
Handlers for pawn death requests
  • Loading branch information
alborrajo authored Jan 13, 2024
2 parents 05e3836 + 2cf5391 commit e99aba9
Show file tree
Hide file tree
Showing 7 changed files with 120 additions and 10 deletions.
1 change: 1 addition & 0 deletions Arrowgene.Ddon.GameServer/DdonGameServer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -322,6 +322,7 @@ private void LoadPacketHandler()
AddHandler(new PawnGetRegisteredPawnDataHandler(this));
AddHandler(new PawnGetRentedPawnListHandler(this));
AddHandler(new PawnJoinPartyMypawnHandler(this));
AddHandler(new PawnPawnLostHandler(this));
AddHandler(new PawnTrainingGetPreparetionInfoToAdviceHandler(this));

AddHandler(new ProfileGetCharacterProfileHandler(this));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
using Arrowgene.Ddon.Shared.Network;
using Arrowgene.Logging;
using Arrowgene.Ddon.Shared.Entity.PacketStructure;
using System;

namespace Arrowgene.Ddon.GameServer.Handler
{
Expand All @@ -18,9 +19,19 @@ public CharacterPawnPointReviveHandler(DdonGameServer server) : base(server)

public override void Handle(GameClient client, StructurePacket<C2SCharacterPawnPointReviveReq> req)
{
S2CCharacterPawnPointReviveRes res = new S2CCharacterPawnPointReviveRes(req.Structure);
res.RevivePoint = 3;
client.Character.StatusInfo.RevivePoint = (byte) Math.Max(0, client.Character.StatusInfo.RevivePoint-1);
Database.UpdateStatusInfo(client.Character);

S2CCharacterPawnPointReviveRes res = new S2CCharacterPawnPointReviveRes();
res.RevivePoint = client.Character.StatusInfo.RevivePoint;
client.Send(res);

S2CCharacterUpdateRevivePointNtc ntc = new S2CCharacterUpdateRevivePointNtc()
{
CharacterId = client.Character.CharacterId,
RevivePoint = client.Character.StatusInfo.RevivePoint
};
client.Party.SendToAllExcept(ntc, client);
}
}
}
30 changes: 30 additions & 0 deletions Arrowgene.Ddon.GameServer/Handler/PawnPawnLostHandler.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
using System.Linq;
using Arrowgene.Ddon.Server;
using Arrowgene.Ddon.Shared.Entity.PacketStructure;
using Arrowgene.Ddon.Shared.Model;
using Arrowgene.Ddon.Shared.Network;
using Arrowgene.Logging;

namespace Arrowgene.Ddon.GameServer.Handler
{
public class PawnPawnLostHandler : GameStructurePacketHandler<C2SPawnPawnLostReq>
{
private static readonly ServerLogger Logger = LogProvider.Logger<ServerLogger>(typeof(PawnPawnLostHandler));

public PawnPawnLostHandler(DdonGameServer server) : base(server)
{
}

public override void Handle(GameClient client, StructurePacket<C2SPawnPawnLostReq> packet)
{
// TODO: Lost pawns system
Pawn pawn = client.Character.Pawns.Where(pawn => pawn.PawnId == packet.Structure.PawnId).Single();
client.Send(new S2CPawnPawnLostRes()
{
PawnId = pawn.PawnId,
PawnName = pawn.Name,
IsLost = false
});
}
}
}
2 changes: 2 additions & 0 deletions Arrowgene.Ddon.Shared/Entity/EntitySerializer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -311,6 +311,7 @@ static EntitySerializer()
Create(new C2SPawnGetPawnTotalScoreReq.Serializer());
Create(new C2SPawnGetRegisteredPawnDataReq.Serializer());
Create(new C2SPawnJoinPartyMypawnReq.Serializer());
Create(new C2SPawnPawnLostReq.Serializer());
Create(new C2SPawnTrainingGetPreparetionInfoToAdviceReq.Serializer());
Create(new C2SProfileGetCharacterProfileReq.Serializer());
Create(new C2SProfileGetMyCharacterProfileReq.Serializer());
Expand Down Expand Up @@ -541,6 +542,7 @@ static EntitySerializer()
Create(new S2CPawnGetPawnTotalScoreRes.Serializer());
Create(new S2CPawnGetRegisteredPawnDataRes.Serializer());
Create(new S2CPawnJoinPartyMypawnRes.Serializer());
Create(new S2CPawnPawnLostRes.Serializer());
Create(new S2CPawnTrainingGetPreparetionInfoToAdviceRes.Serializer());
Create(new S2CProfileGetCharacterProfileRes.Serializer());
Create(new S2CProfileGetMyCharacterProfileRes.Serializer());
Expand Down
28 changes: 28 additions & 0 deletions Arrowgene.Ddon.Shared/Entity/PacketStructure/C2SPawnPawnLostReq.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
using Arrowgene.Buffers;
using Arrowgene.Ddon.Shared.Network;

namespace Arrowgene.Ddon.Shared.Entity.PacketStructure
{
public class C2SPawnPawnLostReq : IPacketStructure
{
public PacketId Id => PacketId.C2S_PAWN_PAWN_LOST_REQ;

public uint PawnId { get; set; }

public class Serializer : PacketEntitySerializer<C2SPawnPawnLostReq>
{
public override void Write(IBuffer buffer, C2SPawnPawnLostReq obj)
{
WriteUInt32(buffer, obj.PawnId);
}

public override C2SPawnPawnLostReq Read(IBuffer buffer)
{
C2SPawnPawnLostReq obj = new C2SPawnPawnLostReq();
obj.PawnId = ReadUInt32(buffer);
return obj;
}
}

}
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,33 +7,31 @@ public class S2CCharacterPawnPointReviveRes : ServerResponse
{
public override PacketId Id => PacketId.S2C_CHARACTER_PAWN_POINT_REVIVE_RES;

public uint PawnId { get; set; }
public byte RevivePoint { get; set; }
public C2SCharacterPawnPointReviveReq PawnId { get; set; }

public S2CCharacterPawnPointReviveRes()
{
PawnId = 0;
RevivePoint = 0;
}

public S2CCharacterPawnPointReviveRes(C2SCharacterPawnPointReviveReq req)
{
PawnId = req;
}

public class Serializer : PacketEntitySerializer<S2CCharacterPawnPointReviveRes>
{

public override void Write(IBuffer buffer, S2CCharacterPawnPointReviveRes obj)
{
C2SCharacterPawnPointReviveReq req = obj.PawnId;
WriteServerResponse(buffer, obj);
WriteUInt32(buffer, req.PawnId);
WriteUInt32(buffer, obj.PawnId);
WriteByte(buffer, obj.RevivePoint);
}

public override S2CCharacterPawnPointReviveRes Read(IBuffer buffer)
{
S2CCharacterPawnPointReviveRes obj = new S2CCharacterPawnPointReviveRes();
ReadServerResponse(buffer, obj);
obj.PawnId = ReadUInt32(buffer);
obj.RevivePoint = ReadByte(buffer);
return obj;
}
}
Expand Down
40 changes: 40 additions & 0 deletions Arrowgene.Ddon.Shared/Entity/PacketStructure/S2CPawnPawnLostRes.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
using Arrowgene.Buffers;
using Arrowgene.Ddon.Shared.Network;

namespace Arrowgene.Ddon.Shared.Entity.PacketStructure
{
public class S2CPawnPawnLostRes : ServerResponse
{
public override PacketId Id => PacketId.S2C_PAWN_PAWN_LOST_RES;

public S2CPawnPawnLostRes()
{
PawnName = string.Empty;
}

public uint PawnId { get; set; }
public string PawnName { get; set; }
public bool IsLost { get; set; }

public class Serializer : PacketEntitySerializer<S2CPawnPawnLostRes>
{
public override void Write(IBuffer buffer, S2CPawnPawnLostRes obj)
{
WriteServerResponse(buffer, obj);
WriteUInt32(buffer, obj.PawnId);
WriteMtString(buffer, obj.PawnName);
WriteBool(buffer, obj.IsLost);
}

public override S2CPawnPawnLostRes Read(IBuffer buffer)
{
S2CPawnPawnLostRes obj = new S2CPawnPawnLostRes();
ReadServerResponse(buffer, obj);
obj.PawnId = ReadUInt32(buffer);
obj.PawnName = ReadMtString(buffer);
obj.IsLost = ReadBool(buffer);
return obj;
}
}
}
}

0 comments on commit e99aba9

Please sign in to comment.