-
Notifications
You must be signed in to change notification settings - Fork 83
Expand file tree
/
Copy pathPawnPawnLostHandler.cs
More file actions
60 lines (49 loc) · 2.17 KB
/
Copy pathPawnPawnLostHandler.cs
File metadata and controls
60 lines (49 loc) · 2.17 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
using Arrowgene.Ddon.Server;
using Arrowgene.Ddon.Server.Network;
using Arrowgene.Ddon.Shared.Entity.PacketStructure;
using Arrowgene.Ddon.Shared.Model;
using Arrowgene.Logging;
using System;
namespace Arrowgene.Ddon.GameServer.Handler
{
public class PawnPawnLostHandler : GameRequestPacketQueueHandler<C2SPawnPawnLostReq, S2CPawnPawnLostRes>
{
private static readonly ServerLogger Logger = LogProvider.Logger<ServerLogger>(typeof(PawnPawnLostHandler));
public PawnPawnLostHandler(DdonGameServer server) : base(server)
{
}
public override PacketQueue Handle(GameClient client, C2SPawnPawnLostReq request)
{
PacketQueue queue = new();
Pawn pawn = client.Character.PawnById(request.PawnId, PawnType.Main);
bool isLost = Random.Shared.NextDouble() > (client.Character.ExtendedParams.MainPawnLostRate / 100.0);
client.Enqueue(new S2CPawnPawnLostRes()
{
PawnId = pawn.PawnId,
PawnName = pawn.Name,
IsLost = isLost
}, queue);
S2CPawnPawnLostNtc ntc = new S2CPawnPawnLostNtc()
{
PawnId = pawn.PawnId,
PawnName = pawn.Name,
IsLost = isLost
};
client.Party.EnqueueToAllExcept(ntc, queue, client);
var pawnMember = client.Party.GetPartyMemberByCharacter(pawn);
if (pawnMember is not null)
{
// Handle serverside tracking. C2SPawnPawnLostReq is only sent to the owner, and only they can kick their own pawn, so it works out.
client.Party.Kick(client, (byte)pawnMember.MemberIndex);
// Free up the party slot so that the client allows new invites, if there are less than 4 people remaining.
client.Party.EnqueueToAll(new S2CPartyPartyMemberLostNtc()
{
MemberIndex = (byte)pawnMember.MemberIndex
}, queue);
}
pawn.PawnState = isLost ? PawnState.Lost : PawnState.None;
Server.Database.UpdatePawnBaseInfo(pawn);
return queue;
}
}
}