Skip to content

Commit

Permalink
Fix PP shop taking PP from the currently equipped job, even if you're…
Browse files Browse the repository at this point in the history
… buying from another job's shop.
  • Loading branch information
RyanYappert committed Sep 2, 2024
1 parent bb69387 commit 7e10e34
Show file tree
Hide file tree
Showing 4 changed files with 43 additions and 22 deletions.
59 changes: 40 additions & 19 deletions Arrowgene.Ddon.GameServer/Characters/PlayPointManager.cs
Original file line number Diff line number Diff line change
@@ -1,17 +1,18 @@
using Arrowgene.Ddon.Database;
using Arrowgene.Ddon.Server;
using Arrowgene.Ddon.Shared.Entity.PacketStructure;
using Arrowgene.Ddon.Shared.Entity.Structure;
using Arrowgene.Ddon.Shared.Model;
using Arrowgene.Logging;
using System;
using System.Linq;

namespace Arrowgene.Ddon.GameServer.Characters
{
public class PlayPointManager
{
private static readonly ServerLogger Logger = LogProvider.Logger<ServerLogger>(typeof(PlayPointManager));

private static uint PP_MAX = 2000;
private static readonly uint PP_MAX = 2000;

public PlayPointManager(DdonGameServer server)
{
Expand All @@ -20,52 +21,72 @@ public PlayPointManager(DdonGameServer server)

private readonly DdonGameServer _Server;

public void AddPlayPoint(GameClient client, uint gainedPoints, byte type = 1)
public void AddPlayPoint(GameClient client, uint gainedPoints, JobId? job = null, byte type = 1)
{
CDataJobPlayPoint? activeCharacterPlayPoint = client.Character.ActiveCharacterPlayPointData;
CDataJobPlayPoint? targetPlayPoint;
if (job is null)
{
targetPlayPoint = client.Character.ActiveCharacterPlayPointData;
}
else
{
targetPlayPoint = client.Character.PlayPointList.Where(x => x.Job == job)
.FirstOrDefault()
?? throw new ResponseErrorException(ErrorCode.ERROR_CODE_JOB_VALUE_SHOP_INVALID_JOB);
}

uint extraBonusPoints = (uint) (_Server.GpCourseManager.EnemyPlayPointBonus() * gainedPoints);
if (activeCharacterPlayPoint != null && activeCharacterPlayPoint.PlayPoint.PlayPoint < PP_MAX)
if (targetPlayPoint != null && targetPlayPoint.PlayPoint.PlayPoint < PP_MAX)
{
uint clampedNew = Math.Min(activeCharacterPlayPoint.PlayPoint.PlayPoint + gainedPoints + extraBonusPoints, PP_MAX);
activeCharacterPlayPoint.PlayPoint.PlayPoint = clampedNew;
uint clampedNew = Math.Min(targetPlayPoint.PlayPoint.PlayPoint + gainedPoints + extraBonusPoints, PP_MAX);
targetPlayPoint.PlayPoint.PlayPoint = clampedNew;

S2CJobUpdatePlayPointNtc ppNtc = new S2CJobUpdatePlayPointNtc()
{
JobId = activeCharacterPlayPoint.Job,
JobId = targetPlayPoint.Job,
UpdatePoint = gainedPoints + extraBonusPoints,
ExtraBonusPoint = extraBonusPoints,
TotalPoint = activeCharacterPlayPoint.PlayPoint.PlayPoint,
TotalPoint = targetPlayPoint.PlayPoint.PlayPoint,
Type = type //Type == 1 (default) is "loud" and will show the UpdatePoint amount to the user, as both a chat log and floating text.
};

client.Send(ppNtc);

_Server.Database.UpdateCharacterPlayPointData(client.Character.CharacterId, activeCharacterPlayPoint);
_Server.Database.UpdateCharacterPlayPointData(client.Character.CharacterId, targetPlayPoint);
}
}

public void RemovePlayPoint(GameClient client, uint removedPoints, byte type = 0)
public void RemovePlayPoint(GameClient client, uint removedPoints, JobId? job = null, byte type = 0)
{
CDataJobPlayPoint? activeCharacterPlayPoint = client.Character.ActiveCharacterPlayPointData;

if (activeCharacterPlayPoint != null && activeCharacterPlayPoint.PlayPoint.PlayPoint > 0)
CDataJobPlayPoint? targetPlayPoint;
if (job is null)
{
targetPlayPoint = client.Character.ActiveCharacterPlayPointData;
}
else
{
targetPlayPoint = client.Character.PlayPointList.Where(x => x.Job == job)
.FirstOrDefault()
?? throw new ResponseErrorException(ErrorCode.ERROR_CODE_JOB_VALUE_SHOP_INVALID_JOB);
}

if (targetPlayPoint != null && targetPlayPoint.PlayPoint.PlayPoint > 0)
{
uint clampedNew = Math.Min(activeCharacterPlayPoint.PlayPoint.PlayPoint - removedPoints, PP_MAX);
activeCharacterPlayPoint.PlayPoint.PlayPoint = clampedNew;
uint clampedNew = Math.Min(targetPlayPoint.PlayPoint.PlayPoint - removedPoints, PP_MAX);
targetPlayPoint.PlayPoint.PlayPoint = clampedNew;

S2CJobUpdatePlayPointNtc ppNtc = new S2CJobUpdatePlayPointNtc()
{
JobId = activeCharacterPlayPoint.Job,
JobId = targetPlayPoint.Job,
UpdatePoint = 0,
ExtraBonusPoint = 0,
TotalPoint = activeCharacterPlayPoint.PlayPoint.PlayPoint,
TotalPoint = targetPlayPoint.PlayPoint.PlayPoint,
Type = type //Type == 0 (default) is "silent" and will not notify the player, aside from updating some UI elements.
};

client.Send(ppNtc);

_Server.Database.UpdateCharacterPlayPointData(client.Character.CharacterId, activeCharacterPlayPoint);
_Server.Database.UpdateCharacterPlayPointData(client.Character.CharacterId, targetPlayPoint);
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -196,7 +196,7 @@ public override void Handle(GameClient client, StructurePacket<C2SInstanceEnemyK

if (gainedPP > 0)
{
_gameServer.PPManager.AddPlayPoint(memberClient, gainedPP, 1);
_gameServer.PPManager.AddPlayPoint(memberClient, gainedPP, type: 1);
}

if (gainedExp > 0)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ public override S2CJobJobValueShopBuyItemRes Handle(GameClient client, C2SJobJob

if (packet.Price > 0)
{
_playPointManager.RemovePlayPoint(client, packet.Price);
_playPointManager.RemovePlayPoint(client, packet.Price, packet.JobId);
}

return new S2CJobJobValueShopBuyItemRes()
Expand Down
2 changes: 1 addition & 1 deletion Arrowgene.Ddon.GameServer/Party/PartyQuestState.cs
Original file line number Diff line number Diff line change
Expand Up @@ -513,7 +513,7 @@ private void SendWalletRewards(DdonGameServer server, GameClient client, Quest q
}
else if (expPoint.Type == ExpType.PlayPoints)
{
server.PPManager.AddPlayPoint(client, expPoint.Reward, 2);
server.PPManager.AddPlayPoint(client, expPoint.Reward, type: 2);
}
}
}
Expand Down

0 comments on commit 7e10e34

Please sign in to comment.