Skip to content

Commit

Permalink
learn pawn skills
Browse files Browse the repository at this point in the history
  • Loading branch information
alborrajo committed Jun 7, 2023
1 parent 1112cf9 commit 8a7ce0c
Show file tree
Hide file tree
Showing 8 changed files with 209 additions and 39 deletions.
86 changes: 86 additions & 0 deletions Arrowgene.Ddon.GameServer/Characters/JobManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
using System.Collections.Generic;
using System.Linq;
using Arrowgene.Ddon.Database;
using Arrowgene.Ddon.GameServer.Handler;
using Arrowgene.Ddon.Server;
using Arrowgene.Ddon.Shared.Entity;
using Arrowgene.Ddon.Shared.Entity.PacketStructure;
Expand Down Expand Up @@ -134,6 +135,52 @@ public void SetJob(DdonServer<GameClient> server, GameClient client, CharacterCo
}
}

public void UnlockSkill(IDatabase database, GameClient client, CharacterCommon character, JobId job, uint skillId, byte skillLv)
{
CustomSkill newSkill = new CustomSkill()
{
Job = job,
SkillId = skillId,
SkillLv = skillLv
};
character.LearnedCustomSkills.Add(newSkill);
database.ReplaceLearnedCustomSkill(character.CommonId, newSkill);

uint jpCost = SkillGetAcquirableSkillListHandler.AllSkills
.Where(skill => skill.Job == job && skill.SkillNo == skillId)
.SelectMany(skill => skill.Params)
.Where(skillParams => skillParams.Lv == skillLv)
.Select(skillParams => skillParams.RequireJobPoint)
.Single();

// TODO: Check that this doesn't end up negative
CDataCharacterJobData activeCharacterJobData = character.ActiveCharacterJobData;
activeCharacterJobData.JobPoint -= jpCost;
database.UpdateCharacterJobData(character.CommonId, activeCharacterJobData);

if(character is Character)
{
client.Send(new S2CSkillLearnSkillRes()
{
Job = job,
NewJobPoint = activeCharacterJobData.JobPoint,
SkillId = skillId,
SkillLv = skillLv
});
}
else if(character is Pawn)
{
client.Send(new S2CSkillLearnPawnSkillRes()
{
PawnId = ((Pawn) character).PawnId,
Job = job,
NewJobPoint = activeCharacterJobData.JobPoint,
SkillId = skillId,
SkillLv = skillLv
});
}
}

public CustomSkill SetSkill(IDatabase database, GameClient client, CharacterCommon character, JobId job, byte slotNo, uint skillId, byte skillLv)
{
// TODO: Check in DB if the skill is unlocked and it's leveled up to what the packet says
Expand Down Expand Up @@ -201,6 +248,45 @@ public void RemoveSkill(IDatabase database, CharacterCommon character, JobId job
// From what I tested it doesn't seem to be necessary
}

public void UnlockAbility(IDatabase database, GameClient client, CharacterCommon character, JobId job, uint abilityId, byte abilityLv)
{
Ability newAbility = new Ability()
{
Job = job,
AbilityId = abilityId,
AbilityLv = abilityLv
};
character.LearnedAbilities.Add(newAbility);
database.ReplaceLearnedAbility(character.CommonId, newAbility);

uint jpCost = SkillGetAcquirableAbilityListHandler.AllAbilities
.Where(aug => aug.Job == job && aug.AbilityNo == abilityId)
.SelectMany(aug => aug.Params)
.Where(augParams => augParams.Lv == abilityLv)
.Select(augParams => augParams.RequireJobPoint)
.Single();

// TODO: Check that this doesn't end up negative
CDataCharacterJobData activeCharacterJobData = character.ActiveCharacterJobData;
activeCharacterJobData.JobPoint -= jpCost;
database.UpdateCharacterJobData(character.CommonId, activeCharacterJobData);

if(character is Character)
{
client.Send(new S2CSkillLearnAbilityRes()
{
Job = job,
NewJobPoint = activeCharacterJobData.JobPoint,
AbilityId = abilityId,
AbilityLv = abilityLv
});
}
else if(character is Pawn)
{
// TODO: S2CSkillLearnPawnAbilityRes
}
}

public Ability SetAbility(IDatabase database, GameClient client, CharacterCommon character, JobId abilityJob, byte slotNo, uint abilityId, byte abilityLv)
{
Ability ability = character.LearnedAbilities
Expand Down
1 change: 1 addition & 0 deletions Arrowgene.Ddon.GameServer/DdonGameServer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -361,6 +361,7 @@ private void LoadPacketHandler()
AddHandler(new SkillGetSetAbilityListHandler(this));
AddHandler(new SkillGetSetSkillListHandler(this));
AddHandler(new SkillLearnAbilityHandler(this));
AddHandler(new SkillLearnPawnSkillHandler(this));
AddHandler(new SkillLearnSkillHandler(this));
AddHandler(new SkillSetAbilityHandler(this));
AddHandler(new SkillSetOffAbilityHandler(this));
Expand Down
26 changes: 5 additions & 21 deletions Arrowgene.Ddon.GameServer/Handler/SkillLearnAbilityHandler.cs
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
using System.Linq;
using Arrowgene.Ddon.GameServer.Characters;
using Arrowgene.Ddon.Server;
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;

Expand All @@ -12,30 +10,16 @@ public class SkillLearnAbilityHandler : GameStructurePacketHandler<C2SSkillLearn
{
private static readonly ServerLogger Logger = LogProvider.Logger<ServerLogger>(typeof(SkillLearnAbilityHandler));

private readonly JobManager jobManager;

public SkillLearnAbilityHandler(DdonGameServer server) : base(server)
{
this.jobManager = server.JobManager;
}

public override void Handle(GameClient client, StructurePacket<C2SSkillLearnAbilityReq> packet)
{
Ability newAbility = new Ability()
{
Job = packet.Structure.Job,
AbilityId = packet.Structure.AbilityId,
AbilityLv = packet.Structure.AbilityLv
};
client.Character.LearnedAbilities.Add(newAbility);
Server.Database.ReplaceLearnedAbility(client.Character.CommonId, newAbility);

// TODO: substract cost, save to db

client.Send(new S2CSkillLearnAbilityRes()
{
Job = packet.Structure.Job,
NewJobPoint = client.Character.ActiveCharacterJobData.JobPoint,
AbilityId = packet.Structure.AbilityId,
AbilityLv = packet.Structure.AbilityLv
});
this.jobManager.UnlockAbility(Server.Database, client, client.Character, packet.Structure.Job, packet.Structure.AbilityId, packet.Structure.AbilityLv);
}
}
}
30 changes: 30 additions & 0 deletions Arrowgene.Ddon.GameServer/Handler/SkillLearnPawnSkillHandler.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
using System.Linq;
using Arrowgene.Ddon.GameServer.Characters;
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 SkillLearnPawnSkillHandler : GameStructurePacketHandler<C2SSkillLearnPawnSkillReq>
{
private static readonly ServerLogger Logger = LogProvider.Logger<ServerLogger>(typeof(SkillLearnPawnSkillHandler));

private readonly JobManager jobManager;

public SkillLearnPawnSkillHandler(DdonGameServer server) : base(server)
{
this.jobManager = server.JobManager;
}

public override void Handle(GameClient client, StructurePacket<C2SSkillLearnPawnSkillReq> packet)
{
Pawn pawn = client.Character.Pawns.Where(pawn => pawn.PawnId == packet.Structure.PawnId).Single();
this.jobManager.UnlockSkill(Server.Database, client, pawn, packet.Structure.Job, packet.Structure.SkillId, packet.Structure.SkillLv);
}
}
}
23 changes: 5 additions & 18 deletions Arrowgene.Ddon.GameServer/Handler/SkillLearnSkillHandler.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System.Linq;
using Arrowgene.Ddon.GameServer.Characters;
using Arrowgene.Ddon.Server;
using Arrowgene.Ddon.Server.Network;
using Arrowgene.Ddon.Shared.Entity.PacketStructure;
Expand All @@ -13,30 +14,16 @@ public class SkillLearnSkillHandler : GameStructurePacketHandler<C2SSkillLearnSk
{
private static readonly ServerLogger Logger = LogProvider.Logger<ServerLogger>(typeof(SkillLearnSkillHandler));

private readonly JobManager jobManager;

public SkillLearnSkillHandler(DdonGameServer server) : base(server)
{
this.jobManager = server.JobManager;
}

public override void Handle(GameClient client, StructurePacket<C2SSkillLearnSkillReq> packet)
{
CustomSkill newSkill = new CustomSkill()
{
Job = packet.Structure.Job,
SkillId = packet.Structure.SkillId,
SkillLv = packet.Structure.SkillLv
};
client.Character.LearnedCustomSkills.Add(newSkill);
Server.Database.ReplaceLearnedCustomSkill(client.Character.CommonId, newSkill);

// TODO: substract cost, save to db

client.Send(new S2CSkillLearnSkillRes()
{
Job = packet.Structure.Job,
NewJobPoint = client.Character.ActiveCharacterJobData.JobPoint,
SkillId = packet.Structure.SkillId,
SkillLv = packet.Structure.SkillLv
});
this.jobManager.UnlockSkill(Server.Database, client, client.Character, packet.Structure.Job, packet.Structure.SkillId, packet.Structure.SkillLv);
}
}
}
2 changes: 2 additions & 0 deletions Arrowgene.Ddon.Shared/Entity/EntitySerializer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -310,6 +310,7 @@ static EntitySerializer()
Create(new C2SSkillGetPresetAbilityListReq.Serializer());
Create(new C2SSkillGetSetAbilityListReq.Serializer());
Create(new C2SSkillGetSetSkillListReq.Serializer());
Create(new C2SSkillLearnPawnSkillReq.Serializer());
Create(new C2SSkillLearnSkillReq.Serializer());
Create(new C2SSkillSetAbilityReq.Serializer());
Create(new C2SSkillSetOffAbilityReq.Serializer());
Expand Down Expand Up @@ -528,6 +529,7 @@ static EntitySerializer()
Create(new S2CSkillGetPresetAbilityListRes.Serializer());
Create(new S2CSkillGetSetAbilityListRes.Serializer());
Create(new S2CSkillGetSetSkillListRes.Serializer());
Create(new S2CSkillLearnPawnSkillRes.Serializer());
Create(new S2CSkillLearnSkillRes.Serializer());
Create(new S2CSkillPawnAbilitySetNtc.Serializer());
Create(new S2CSkillPawnCustomSkillSetNtc.Serializer());
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
using Arrowgene.Buffers;
using Arrowgene.Ddon.Shared.Model;
using Arrowgene.Ddon.Shared.Network;

namespace Arrowgene.Ddon.Shared.Entity.PacketStructure
{
public class C2SSkillLearnPawnSkillReq : IPacketStructure
{
public PacketId Id => PacketId.C2S_SKILL_LEARN_PAWN_SKILL_REQ;

public uint PawnId { get; set; }
public JobId Job { get; set; }
public uint SkillId { get; set; }
public byte SkillLv { get; set; }

public class Serializer : PacketEntitySerializer<C2SSkillLearnPawnSkillReq>
{
public override void Write(IBuffer buffer, C2SSkillLearnPawnSkillReq obj)
{
WriteUInt32(buffer, obj.PawnId);
WriteByte(buffer, (byte) obj.Job);
WriteUInt32(buffer, obj.SkillId);
WriteByte(buffer, obj.SkillLv);
}

public override C2SSkillLearnPawnSkillReq Read(IBuffer buffer)
{
C2SSkillLearnPawnSkillReq obj = new C2SSkillLearnPawnSkillReq();
obj.PawnId = ReadUInt32(buffer);
obj.Job = (JobId) ReadByte(buffer);
obj.SkillId = ReadUInt32(buffer);
obj.SkillLv = ReadByte(buffer);
return obj;
}
}

}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
using Arrowgene.Buffers;
using Arrowgene.Ddon.Shared.Model;
using Arrowgene.Ddon.Shared.Network;

namespace Arrowgene.Ddon.Shared.Entity.PacketStructure
{
public class S2CSkillLearnPawnSkillRes : ServerResponse
{
public override PacketId Id => PacketId.S2C_SKILL_LEARN_PAWN_SKILL_RES;

public uint PawnId { get; set; }
public JobId Job { get; set; }
public uint NewJobPoint { get; set; }
public uint SkillId { get; set; }
public byte SkillLv { get; set; }

public class Serializer : PacketEntitySerializer<S2CSkillLearnPawnSkillRes>
{
public override void Write(IBuffer buffer, S2CSkillLearnPawnSkillRes obj)
{
WriteServerResponse(buffer, obj);
WriteUInt32(buffer, obj.PawnId);
WriteByte(buffer, (byte) obj.Job);
WriteUInt32(buffer, obj.NewJobPoint);
WriteUInt32(buffer, obj.SkillId);
WriteByte(buffer, obj.SkillLv);
}

public override S2CSkillLearnPawnSkillRes Read(IBuffer buffer)
{
S2CSkillLearnPawnSkillRes obj = new S2CSkillLearnPawnSkillRes();
ReadServerResponse(buffer, obj);
obj.PawnId = ReadUInt32(buffer);
obj.Job = (JobId) ReadByte(buffer);
obj.NewJobPoint = ReadUInt32(buffer);
obj.SkillId = ReadUInt32(buffer);
obj.SkillLv = ReadByte(buffer);
return obj;
}
}
}
}

0 comments on commit 8a7ce0c

Please sign in to comment.