Skip to content

Commit

Permalink
Review comments.
Browse files Browse the repository at this point in the history
  • Loading branch information
RyanYappert committed Oct 3, 2024
1 parent ed32423 commit 348b186
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 10 deletions.
39 changes: 32 additions & 7 deletions Arrowgene.Ddon.GameServer/Characters/JobManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -31,17 +31,12 @@ public JobManager(DdonGameServer server)
_Server = server;
}

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

var totalSlots = common.Equipment.GetItems(EquipType.Performance)
.Concat(common.Equipment.GetItems(EquipType.Visual))
.Where(x => x != null)
.ToList()
.Count;
if (totalSlots > client.Character.Storage.GetStorage(StorageType.StorageBoxNormal).EmptySlots())
if (!HasEmptySlotsForTemplateSwap(client, common, common.Job, jobId))
{
return (new S2CJobChangeJobRes()
{
Expand Down Expand Up @@ -293,6 +288,36 @@ private List<CDataItemUpdateResult> SwapEquipmentAndStorage(GameClient client, C
return itemUpdateResultList;
}

private static bool HasEmptySlotsForTemplateSwap(GameClient client, CharacterCommon common, JobId oldJobId, JobId newJobId)
{
var availableSlots = client.Character.Storage.GetStorage(StorageType.StorageBoxNormal).EmptySlots();

var neededSlots = common.Equipment.GetItems(EquipType.Performance)
.Concat(common.Equipment.GetItems(EquipType.Visual))
.Where(x => x != null)
.ToList()
.Count;

// If the item isn't moving, it doesn't need a space in the box.
foreach (var equipType in new List<EquipType>(){ EquipType.Performance, EquipType.Visual })
{
List<Item?> oldEquipment = common.Equipment.GetItems(equipType);
List<Item?> newEquipmentTemplate = common.EquipmentTemplate.GetEquipment(newJobId, equipType);

for (int i = 0; i < oldEquipment.Count; i++)
{
if (oldEquipment[i] != null && newEquipmentTemplate[i] != null && oldEquipment[i] == newEquipmentTemplate[i])
{
neededSlots--;
}
}
}

// TODO: Account for one-to-one swaps, as well as jewelry shuffling order.

return neededSlots <= availableSlots;
}

public void UnlockSkill(IDatabase database, GameClient client, CharacterCommon character, JobId job, uint skillId, byte skillLv)
{
// Check if there is a learned skill of the same ID (This unlock is a level upgrade)
Expand Down
14 changes: 11 additions & 3 deletions Arrowgene.Ddon.GameServer/Handler/JobChangePawnJobHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -30,11 +30,19 @@ public override void Handle(GameClient client, StructurePacket<C2SJobChangePawnJ
jobManager.SetJob(client, pawn, packet.Structure.JobId, connection);
});

foreach (GameClient otherClient in Server.ClientLookup.GetAll())
if (jobResult.jobNtc != null)
{
otherClient.Send(jobResult.jobNtc);
foreach (GameClient otherClient in Server.ClientLookup.GetAll())
{
otherClient.Send(jobResult.jobNtc);
}
}
client.Send(jobResult.itemNtc);

if (jobResult.itemNtc != null)
{
client.Send(jobResult.itemNtc);
}

client.Send(jobResult.jobRes);
}
}
Expand Down

0 comments on commit 348b186

Please sign in to comment.