diff --git a/Arrowgene.Ddon.GameServer/Characters/PlayPointManager.cs b/Arrowgene.Ddon.GameServer/Characters/PlayPointManager.cs index 20fd7d14c..81047e724 100644 --- a/Arrowgene.Ddon.GameServer/Characters/PlayPointManager.cs +++ b/Arrowgene.Ddon.GameServer/Characters/PlayPointManager.cs @@ -1,9 +1,10 @@ -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 { @@ -11,7 +12,7 @@ public class PlayPointManager { private static readonly ServerLogger Logger = LogProvider.Logger(typeof(PlayPointManager)); - private static uint PP_MAX = 2000; + private static readonly uint PP_MAX = 2000; public PlayPointManager(DdonGameServer server) { @@ -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); } } } diff --git a/Arrowgene.Ddon.GameServer/Handler/InstanceEnemyKillHandler.cs b/Arrowgene.Ddon.GameServer/Handler/InstanceEnemyKillHandler.cs index 75ae55846..7ac4fca55 100644 --- a/Arrowgene.Ddon.GameServer/Handler/InstanceEnemyKillHandler.cs +++ b/Arrowgene.Ddon.GameServer/Handler/InstanceEnemyKillHandler.cs @@ -196,7 +196,7 @@ public override void Handle(GameClient client, StructurePacket 0) { - _gameServer.PPManager.AddPlayPoint(memberClient, gainedPP, 1); + _gameServer.PPManager.AddPlayPoint(memberClient, gainedPP, type: 1); } if (gainedExp > 0) diff --git a/Arrowgene.Ddon.GameServer/Handler/JobJobValueShopBuyItemHandler.cs b/Arrowgene.Ddon.GameServer/Handler/JobJobValueShopBuyItemHandler.cs index 5aa619ea1..ec79afa66 100644 --- a/Arrowgene.Ddon.GameServer/Handler/JobJobValueShopBuyItemHandler.cs +++ b/Arrowgene.Ddon.GameServer/Handler/JobJobValueShopBuyItemHandler.cs @@ -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() diff --git a/Arrowgene.Ddon.GameServer/Party/PartyQuestState.cs b/Arrowgene.Ddon.GameServer/Party/PartyQuestState.cs index 8886dcd14..085f10477 100644 --- a/Arrowgene.Ddon.GameServer/Party/PartyQuestState.cs +++ b/Arrowgene.Ddon.GameServer/Party/PartyQuestState.cs @@ -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); } } }