Skip to content

Commit 348b186

Browse files
committed
Review comments.
1 parent ed32423 commit 348b186

2 files changed

Lines changed: 43 additions & 10 deletions

File tree

Arrowgene.Ddon.GameServer/Characters/JobManager.cs

Lines changed: 32 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -31,17 +31,12 @@ public JobManager(DdonGameServer server)
3131
_Server = server;
3232
}
3333

34-
public (IPacketStructure? jobRes, IPacketStructure? itemNtc, IPacketStructure? jobNtc) SetJob(GameClient client, CharacterCommon common, JobId jobId, DbConnection? connectionIn = null)
34+
public (IPacketStructure jobRes, IPacketStructure? itemNtc, IPacketStructure? jobNtc) SetJob(GameClient client, CharacterCommon common, JobId jobId, DbConnection? connectionIn = null)
3535
{
3636
// TODO: Reject job change if there's no primary and secondary weapon for the new job in storage
3737
// (or give a lvl 1 weapon for free?)
3838

39-
var totalSlots = common.Equipment.GetItems(EquipType.Performance)
40-
.Concat(common.Equipment.GetItems(EquipType.Visual))
41-
.Where(x => x != null)
42-
.ToList()
43-
.Count;
44-
if (totalSlots > client.Character.Storage.GetStorage(StorageType.StorageBoxNormal).EmptySlots())
39+
if (!HasEmptySlotsForTemplateSwap(client, common, common.Job, jobId))
4540
{
4641
return (new S2CJobChangeJobRes()
4742
{
@@ -293,6 +288,36 @@ private List<CDataItemUpdateResult> SwapEquipmentAndStorage(GameClient client, C
293288
return itemUpdateResultList;
294289
}
295290

291+
private static bool HasEmptySlotsForTemplateSwap(GameClient client, CharacterCommon common, JobId oldJobId, JobId newJobId)
292+
{
293+
var availableSlots = client.Character.Storage.GetStorage(StorageType.StorageBoxNormal).EmptySlots();
294+
295+
var neededSlots = common.Equipment.GetItems(EquipType.Performance)
296+
.Concat(common.Equipment.GetItems(EquipType.Visual))
297+
.Where(x => x != null)
298+
.ToList()
299+
.Count;
300+
301+
// If the item isn't moving, it doesn't need a space in the box.
302+
foreach (var equipType in new List<EquipType>(){ EquipType.Performance, EquipType.Visual })
303+
{
304+
List<Item?> oldEquipment = common.Equipment.GetItems(equipType);
305+
List<Item?> newEquipmentTemplate = common.EquipmentTemplate.GetEquipment(newJobId, equipType);
306+
307+
for (int i = 0; i < oldEquipment.Count; i++)
308+
{
309+
if (oldEquipment[i] != null && newEquipmentTemplate[i] != null && oldEquipment[i] == newEquipmentTemplate[i])
310+
{
311+
neededSlots--;
312+
}
313+
}
314+
}
315+
316+
// TODO: Account for one-to-one swaps, as well as jewelry shuffling order.
317+
318+
return neededSlots <= availableSlots;
319+
}
320+
296321
public void UnlockSkill(IDatabase database, GameClient client, CharacterCommon character, JobId job, uint skillId, byte skillLv)
297322
{
298323
// Check if there is a learned skill of the same ID (This unlock is a level upgrade)

Arrowgene.Ddon.GameServer/Handler/JobChangePawnJobHandler.cs

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,11 +30,19 @@ public override void Handle(GameClient client, StructurePacket<C2SJobChangePawnJ
3030
jobManager.SetJob(client, pawn, packet.Structure.JobId, connection);
3131
});
3232

33-
foreach (GameClient otherClient in Server.ClientLookup.GetAll())
33+
if (jobResult.jobNtc != null)
3434
{
35-
otherClient.Send(jobResult.jobNtc);
35+
foreach (GameClient otherClient in Server.ClientLookup.GetAll())
36+
{
37+
otherClient.Send(jobResult.jobNtc);
38+
}
3639
}
37-
client.Send(jobResult.itemNtc);
40+
41+
if (jobResult.itemNtc != null)
42+
{
43+
client.Send(jobResult.itemNtc);
44+
}
45+
3846
client.Send(jobResult.jobRes);
3947
}
4048
}

0 commit comments

Comments
 (0)