Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Lost Pawns #655

Merged
merged 10 commits into from
Dec 11, 2024
2 changes: 1 addition & 1 deletion Arrowgene.Ddon.Database/DdonDatabaseBuilder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ public static class DdonDatabaseBuilder
private static readonly ILogger Logger = LogProvider.Logger<Logger>(typeof(DdonDatabaseBuilder));
private const string DefaultSchemaFile = "Script/schema_sqlite.sql";

public const uint Version = 25;
public const uint Version = 26;

public static IDatabase Build(DatabaseSetting settings)
{
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
ALTER TABLE "ddon_pawn"
ADD COLUMN "pawn_state" SMALLINT NOT NULL DEFAULT 0;
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@ CREATE TABLE IF NOT EXISTS "ddon_pawn"
"name" TEXT NOT NULL,
"hm_type" SMALLINT NOT NULL,
"pawn_type" SMALLINT NOT NULL,
"pawn_state" SMALLINT NOT NULL,
"training_points" INTEGER NOT NULL,
"available_training" INTEGER NOT NULL,
"craft_rank" INTEGER NOT NULL,
Expand Down
3 changes: 3 additions & 0 deletions Arrowgene.Ddon.Database/Sql/Core/DdonSqlDbPawn.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ public abstract partial class DdonSqlDb<TCon, TCom, TReader> : SqlDb<TCon, TCom,
"name",
"hm_type",
"pawn_type",
"pawn_state",
"training_points",
"available_training",
"craft_exp",
Expand Down Expand Up @@ -718,6 +719,7 @@ private Pawn ReadAllPawnData(DbDataReader reader)
pawn.Name = GetString(reader, "name");
pawn.HmType = GetByte(reader, "hm_type");
pawn.PawnType = (PawnType)GetByte(reader, "pawn_type");
pawn.PawnState = (PawnState)GetByte(reader, "pawn_state");
pawn.TrainingPoints = GetUInt32(reader, "training_points");
pawn.AvailableTraining = GetUInt32(reader, "available_training");
pawn.IsOfficialPawn = GetBoolean(reader, "is_official_pawn");
Expand Down Expand Up @@ -765,6 +767,7 @@ private void AddParameter(TCom command, Pawn pawn)
AddParameter(command, "@name", pawn.Name);
AddParameter(command, "@hm_type", pawn.HmType);
AddParameter(command, "@pawn_type", (byte)pawn.PawnType);
AddParameter(command, "@pawn_state", (byte)pawn.PawnState);
AddParameter(command, "@training_points", pawn.TrainingPoints);
AddParameter(command, "@available_training", pawn.AvailableTraining);
AddParameter(command, "@is_official_pawn", false);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
using System.Data.Common;

namespace Arrowgene.Ddon.Database.Sql.Core.Migration
{
public class PawnStateMigration : IMigrationStrategy
{
public uint From => 25;
public uint To => 26;

private readonly DatabaseSetting DatabaseSetting;

public PawnStateMigration(DatabaseSetting databaseSetting)
{
DatabaseSetting = databaseSetting;
}

public bool Migrate(IDatabase db, DbConnection conn)
{
string adaptedSchema = DdonDatabaseBuilder.GetAdaptedSchema(DatabaseSetting, "Script/migration_pawn_state.sql");
db.Execute(conn, adaptedSchema);
return true;
}
}
}
5 changes: 5 additions & 0 deletions Arrowgene.Ddon.GameServer/DdonGameServer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -483,7 +483,12 @@ private void LoadPacketHandler()
AddHandler(new PawnGetRentedPawnDataHandler(this));
AddHandler(new PawnGetRentedPawnListHandler(this));
AddHandler(new PawnJoinPartyMypawnHandler(this));
AddHandler(new PawnLostPawnGoldenReviveHandler(this));
AddHandler(new PawnLostPawnPointReviveHandler(this));
AddHandler(new PawnLostPawnReviveHandler(this));
AddHandler(new PawnLostPawnWalletReviveHandler(this));
AddHandler(new PawnPawnLostHandler(this));
AddHandler(new PawnRentalPawnLostHandler(this));
AddHandler(new PawnSpSkillDeleteStockSkillHandler(this));
AddHandler(new PawnSpSkillGetActiveSkillHandler(this));
AddHandler(new PawnSpSkillGetStockSkillHandler(this));
Expand Down
2 changes: 1 addition & 1 deletion Arrowgene.Ddon.GameServer/GameStructure.cs
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ public static void CDataPawnInfo(CDataPawnInfo cDataPawnInfo, Pawn pawn)
cDataPawnInfo.Version = 0;
cDataPawnInfo.Name = pawn.Name;
cDataPawnInfo.EditInfo = pawn.EditInfo;
cDataPawnInfo.State = 1; // TODO: ?
cDataPawnInfo.State = pawn.PawnState;
cDataPawnInfo.MaxHp = pawn.StatusInfo.MaxHP;
cDataPawnInfo.MaxStamina = pawn.StatusInfo.MaxStamina;
cDataPawnInfo.JobId = pawn.Job;
Expand Down
37 changes: 29 additions & 8 deletions Arrowgene.Ddon.GameServer/Handler/PawnGetLostPawnListHandler.cs
Original file line number Diff line number Diff line change
@@ -1,26 +1,47 @@
using Arrowgene.Ddon.Server;
using Arrowgene.Ddon.Server.Network;
using Arrowgene.Ddon.Shared.Network;
using Arrowgene.Logging;
using Arrowgene.Ddon.Shared.Entity.PacketStructure;
using Arrowgene.Ddon.Shared.Model.Quest;
using Arrowgene.Ddon.Shared.Entity.Structure;
using System.Collections.Generic;
using System.Linq;
using Arrowgene.Ddon.Shared.Model;

namespace Arrowgene.Ddon.GameServer.Handler
{
public class PawnGetLostPawnListHandler : StructurePacketHandler<GameClient, C2SPawnGetLostPawnListReq>
public class PawnGetLostPawnListHandler : GameRequestPacketHandler<C2SPawnGetLostPawnListReq, S2CPawnGetLostPawnListRes>
{
private static readonly ServerLogger Logger = LogProvider.Logger<ServerLogger>(typeof(PawnGetLostPawnListHandler));

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

public override void Handle(GameClient client, StructurePacket<C2SPawnGetLostPawnListReq> req)
public override S2CPawnGetLostPawnListRes Handle(GameClient client, C2SPawnGetLostPawnListReq request)
{
var res = new S2CPawnGetLostPawnListRes();
client.Send(res);
return new S2CPawnGetLostPawnListRes()
{
LostPawnList = client.Character.Pawns
.Select((pawn, index) => new { pawn, slot = index+1 })
.Where(tuple => tuple.pawn.PawnState == PawnState.Lost)
.Select(tuple => new CDataLostPawnList()
{
PawnId = (int) tuple.pawn.PawnId,
SlotNo = (uint) tuple.slot,
Name = tuple.pawn.Name,
Sex = tuple.pawn.EditInfo.Sex,
PawnState = tuple.pawn.PawnState,
// TODO: ShareRange
ReviveCost = 1, // TODO: Make it configurable
PawnListData = new CDataPawnListData()
{
Job = tuple.pawn.Job,
Level = tuple.pawn.ActiveCharacterJobData.Lv,
CraftRank = tuple.pawn.CraftData.CraftRank,
PawnCraftSkillList = tuple.pawn.CraftData.PawnCraftSkillList,
// TODO: CommentSize, LatestReturnDate
}
})
.ToList()
};
}
}
}
5 changes: 3 additions & 2 deletions Arrowgene.Ddon.GameServer/Handler/PawnGetMyPawnListHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -31,15 +31,16 @@ public override void Handle(GameClient client, StructurePacket<C2SPawnGetMyPawnL
SlotNo = index++,
Name = pawn.Name,
Sex = pawn.EditInfo.Sex,
PawnState = pawn.PawnState,
PawnListData = new CDataPawnListData()
{
Job = pawn.Job,
Level = pawn.ActiveCharacterJobData.Lv,
CraftRank = pawn.CraftData.CraftRank,
PawnCraftSkillList = pawn.CraftData.PawnCraftSkillList
// TODO: CommentSize, LatestReturnDate
}
// TODO: PawnState, ShareRange, Unk0, Unk1, Unk2
},
// TODO: ShareRange, Unk0, Unk1, Unk2
};
pawnList.Add(pawnListData);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
using System.Linq;
using Arrowgene.Ddon.Server;
using Arrowgene.Ddon.Server.Network;
using Arrowgene.Ddon.Shared.Entity.PacketStructure;
using Arrowgene.Ddon.Shared.Entity.Structure;
using Arrowgene.Ddon.Shared.Model;
using Arrowgene.Ddon.Shared.Network;
using Arrowgene.Logging;

namespace Arrowgene.Ddon.GameServer.Handler
{
public class PawnLostPawnGoldenReviveHandler : GameRequestPacketHandler<C2SPawnLostPawnGoldenReviveReq, S2CPawnLostPawnGoldenReviveRes>
{
private static readonly ServerLogger Logger = LogProvider.Logger<ServerLogger>(typeof(PawnLostPawnGoldenReviveHandler));

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

public override S2CPawnLostPawnGoldenReviveRes Handle(GameClient client, C2SPawnLostPawnGoldenReviveReq request)
{
Pawn pawn = client.Character.Pawns.Where(pawn => pawn.PawnId == request.PawnId).Single();
pawn.PawnState = PawnState.Wait;
Server.Database.UpdatePawnBaseInfo(pawn);

bool walletUpdate = Server.WalletManager.RemoveFromWalletNtc(client, client.Character, WalletType.GoldenGemstones, 1); // TODO: Get price from settings.
if (!walletUpdate)
{
throw new ResponseErrorException(ErrorCode.ERROR_CODE_GP_LACK_GP);
}
byte updatedGP = (byte) Server.WalletManager.GetWalletAmount(client.Character, WalletType.GoldenGemstones);

return new S2CPawnLostPawnGoldenReviveRes()
{
PawnId = request.PawnId,
GP = updatedGP
};
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
using System;
using System.Linq;
using Arrowgene.Ddon.Server;
using Arrowgene.Ddon.Shared.Entity.PacketStructure;
using Arrowgene.Ddon.Shared.Model;
using Arrowgene.Logging;

namespace Arrowgene.Ddon.GameServer.Handler
{
public class PawnLostPawnPointReviveHandler : GameRequestPacketHandler<C2SPawnLostPawnPointReviveReq, S2CPawnLostPawnPointReviveRes>
{
private static readonly ServerLogger Logger = LogProvider.Logger<ServerLogger>(typeof(PawnLostPawnPointReviveHandler));

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

public override S2CPawnLostPawnPointReviveRes Handle(GameClient client, C2SPawnLostPawnPointReviveReq request)
{
Pawn pawn = client.Character.Pawns.Where(pawn => pawn.PawnId == request.PawnId).Single();
pawn.PawnState = PawnState.Wait;
Server.Database.UpdatePawnBaseInfo(pawn);

client.Character.StatusInfo.RevivePoint = (byte) Math.Max(0, client.Character.StatusInfo.RevivePoint-1);
Database.UpdateStatusInfo(client.Character);

S2CCharacterUpdateRevivePointNtc ntc = new S2CCharacterUpdateRevivePointNtc()
{
CharacterId = client.Character.CharacterId,
RevivePoint = client.Character.StatusInfo.RevivePoint
};
client.Party.SendToAllExcept(ntc, client);

return new S2CPawnLostPawnPointReviveRes()
{
PawnId = request.PawnId,
RevivePoint = client.Character.StatusInfo.RevivePoint
};
}
}
}
29 changes: 29 additions & 0 deletions Arrowgene.Ddon.GameServer/Handler/PawnLostPawnReviveHandler.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
using System.Linq;
using Arrowgene.Ddon.Server;
using Arrowgene.Ddon.Shared.Entity.PacketStructure;
using Arrowgene.Ddon.Shared.Model;
using Arrowgene.Logging;

namespace Arrowgene.Ddon.GameServer.Handler
{
public class PawnLostPawnReviveHandler : GameRequestPacketHandler<C2SPawnLostPawnReviveReq, S2CPawnLostPawnReviveRes>
{
private static readonly ServerLogger Logger = LogProvider.Logger<ServerLogger>(typeof(PawnLostPawnReviveHandler));

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

public override S2CPawnLostPawnReviveRes Handle(GameClient client, C2SPawnLostPawnReviveReq request)
{
Pawn pawn = client.Character.Pawns.Where(pawn => pawn.PawnId == request.PawnId).Single();
pawn.PawnState = PawnState.Wait;
Server.Database.UpdatePawnBaseInfo(pawn);

return new S2CPawnLostPawnReviveRes()
{
PawnId = request.PawnId
};
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
using System;
using System.Linq;
using Arrowgene.Ddon.Server;
using Arrowgene.Ddon.Server.Network;
using Arrowgene.Ddon.Shared.Entity.PacketStructure;
using Arrowgene.Ddon.Shared.Entity.Structure;
using Arrowgene.Ddon.Shared.Model;
using Arrowgene.Ddon.Shared.Network;
using Arrowgene.Logging;

namespace Arrowgene.Ddon.GameServer.Handler
{
public class PawnLostPawnWalletReviveHandler : GameRequestPacketHandler<C2SPawnLostPawnWalletReviveReq, S2CPawnLostPawnWalletReviveRes>
{
private static readonly ServerLogger Logger = LogProvider.Logger<ServerLogger>(typeof(PawnLostPawnWalletReviveHandler));

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

public override S2CPawnLostPawnWalletReviveRes Handle(GameClient client, C2SPawnLostPawnWalletReviveReq request)
{
Pawn pawn = client.Character.Pawns.Where(pawn => pawn.PawnId == request.PawnId).Single();
pawn.PawnState = PawnState.Wait;
Server.Database.UpdatePawnBaseInfo(pawn);

if (request.Type != WalletType.RiftPoints)
{
// As far as im aware it can only be paid with RP
throw new ResponseErrorException(ErrorCode.ERROR_CODE_CLIENT_REQ_ERROR);
}

// TODO: Validate ReviveCost value, validate that the player has the appropriate passport course effect active

bool walletUpdate = Server.WalletManager.RemoveFromWalletNtc(client, client.Character, request.Type, request.ReviveCost);
if (!walletUpdate)
{
throw new ResponseErrorException(ErrorCode.ERROR_CODE_WARP_LACK_RIM);
}
uint updatedValue = Server.WalletManager.GetWalletAmount(client.Character, request.Type);

return new S2CPawnLostPawnWalletReviveRes()
{
PawnId = request.PawnId,
Type = request.Type,
Value = updatedValue
};
}
}
}
14 changes: 12 additions & 2 deletions Arrowgene.Ddon.GameServer/Handler/PawnPawnLostHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,23 @@ 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();
pawn.PawnState = PawnState.Lost;
Server.Database.UpdatePawnBaseInfo(pawn);

S2CPawnPawnLostNtc ntc = new S2CPawnPawnLostNtc()
{
PawnId = pawn.PawnId,
PawnName = pawn.Name,
IsLost = pawn.PawnState == PawnState.Lost
};
client.Party.SendToAll(ntc);

client.Send(new S2CPawnPawnLostRes()
{
PawnId = pawn.PawnId,
PawnName = pawn.Name,
IsLost = false
IsLost = pawn.PawnState == PawnState.Lost
});

int pawnIndex = client.Party.Members.FindIndex(x => x is PawnPartyMember xpawn && xpawn.PawnId == packet.Structure.PawnId);
Expand Down
Loading
Loading