Skip to content

Commit

Permalink
Merge pull request #15 from alborrajo/feature/npcs
Browse files Browse the repository at this point in the history
Data structures and handlers related to enemy spawning
  • Loading branch information
alborrajo authored Feb 1, 2022
2 parents d96300d + 5e19700 commit 63c6365
Show file tree
Hide file tree
Showing 20 changed files with 565 additions and 17 deletions.
12 changes: 12 additions & 0 deletions Arrowgene.Ddon.GameServer/DdonGameServer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,14 @@

using System.Collections.Generic;
using Arrowgene.Ddon.Database;
using Arrowgene.Ddon.GameServer.Dump;
using Arrowgene.Ddon.GameServer.Handler;
using Arrowgene.Ddon.Server;
using Arrowgene.Ddon.Server.Network;
using Arrowgene.Ddon.Shared;
using Arrowgene.Ddon.Shared.Entity;
using Arrowgene.Ddon.Shared.Entity.PacketStructure;
using Arrowgene.Ddon.Shared.Entity.Structure;
using Arrowgene.Logging;
using Arrowgene.Networking.Tcp;

Expand All @@ -37,18 +41,26 @@ public class DdonGameServer : DdonServer<GameClient>

private readonly List<GameClient> _clients;

private readonly List<CDataStageInfo> _stageInfo;

public DdonGameServer(GameServerSetting setting, IDatabase database, AssetRepository assetRepository)
: base(setting.ServerSetting, database, assetRepository)
{
Setting = new GameServerSetting(setting);
_clients = new List<GameClient>();

S2CStageGetStageListRes stageListPacket = EntitySerializer.Get<S2CStageGetStageListRes>().Read(GameDump.data_Dump_19);
_stageInfo = stageListPacket.StageList;

LoadPacketHandler();
}

public GameServerSetting Setting { get; }

public override List<GameClient> Clients => new List<GameClient>(_clients);

public List<CDataStageInfo> StageList => new List<CDataStageInfo>(_stageInfo);

protected override void ClientConnected(GameClient client)
{
client.InitializeChallenge();
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
using Arrowgene.Buffers;
using System.Collections.Generic;
using Arrowgene.Buffers;
using Arrowgene.Ddon.GameServer.Dump;
using Arrowgene.Ddon.Server;
using Arrowgene.Ddon.Server.Network;
using Arrowgene.Ddon.Shared;
using Arrowgene.Ddon.Shared.Entity;
using Arrowgene.Ddon.Shared.Entity.PacketStructure;
using Arrowgene.Ddon.Shared.Network;
Expand All @@ -19,11 +21,22 @@ public InstanceGetEnemySetListHandler(DdonGameServer server) : base(server)

public override void Handle(GameClient client, StructurePacket<C2SInstanceGetEnemySetListReq> request)
{
S2CInstanceGetEnemySetListRes response = new S2CInstanceGetEnemySetListRes(); //note that the enemy array is inside this and is currently hardcoded
S2CInstanceGetEnemySetListRes response = new S2CInstanceGetEnemySetListRes();
response.LayoutId.StageID = request.Structure.LayoutId.StageID;
response.LayoutId.LayerNo = request.Structure.LayoutId.LayerNo;
response.LayoutId.GroupID = request.Structure.LayoutId.GroupID;
response.SubGroupId = request.Structure.SubGroupId;
response.RandomSeed = 0xFFFFFFFF;

CDataLayoutEnemyData layoutEnemyData = new CDataLayoutEnemyData();
layoutEnemyData.EnemyInfo.EnemyId = 0x010314;
layoutEnemyData.EnemyInfo.NamedEnemyParamsId = 0x8FA;
layoutEnemyData.EnemyInfo.Scale = 0x64; // Normal
layoutEnemyData.EnemyInfo.Lv = 0x5E;
layoutEnemyData.EnemyInfo.EnemyTargetTypesId = 1;
response.EnemyList.Add(layoutEnemyData);

Logger.Debug(client, Util.ToXML(response));

client.Send(response);
}
Expand Down
32 changes: 24 additions & 8 deletions Arrowgene.Ddon.GameServer/Handler/StageAreaChangeHandler.cs
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
using System;
using Arrowgene.Ddon.GameServer.Dump;
using Arrowgene.Ddon.Server;
using Arrowgene.Ddon.Server;
using Arrowgene.Ddon.Server.Network;
using Arrowgene.Ddon.Shared.Network;
using Arrowgene.Ddon.Shared.Entity.PacketStructure;
using Arrowgene.Ddon.Shared.Entity.Structure;
using Arrowgene.Logging;
using Arrowgene.Ddon.Shared;

namespace Arrowgene.Ddon.GameServer.Handler
{
public class StageAreaChangeHandler : PacketHandler<GameClient>
public class StageAreaChangeHandler : StructurePacketHandler<GameClient, C2SStageAreaChangeReq>
{
private static readonly ServerLogger Logger = LogProvider.Logger<ServerLogger>(typeof(StageAreaChangeHandler));

Expand All @@ -16,11 +16,27 @@ public StageAreaChangeHandler(DdonGameServer server) : base(server)
{
}

public override PacketId Id => PacketId.C2S_STAGE_AREA_CHANGE_REQ;
public override void Handle(GameClient client, StructurePacket<C2SStageAreaChangeReq> packet)
{
S2CStageAreaChangeRes res = new S2CStageAreaChangeRes();
res.StageNo = convertIdToStageNo(packet.Structure.StageId); // TODO: Convert StageId to StageNo
res.IsBase = false;

Logger.Debug(client, Util.ToXML(res));

public override void Handle(GameClient client, Packet packet)
client.Send(res);
}

private uint convertIdToStageNo(uint stageId)
{
client.Send(GameFull.Dump_109);
foreach(CDataStageInfo stageInfo in (Server as DdonGameServer).StageList)
{
if(stageInfo.ID == stageId)
return stageInfo.StageNo;
}

Logger.Error($"No stage found with ID ${stageId}");
return 0; // TODO: Maybe throw an exception?
}
}
}
13 changes: 7 additions & 6 deletions Arrowgene.Ddon.GameServer/Handler/StageGetStageListHandler.cs
Original file line number Diff line number Diff line change
@@ -1,25 +1,26 @@
using Arrowgene.Ddon.GameServer.Dump;
using Arrowgene.Ddon.Server;
using Arrowgene.Ddon.Server.Network;
using Arrowgene.Ddon.Shared.Entity.PacketStructure;
using Arrowgene.Ddon.Shared.Network;
using Arrowgene.Logging;

namespace Arrowgene.Ddon.GameServer.Handler
{
public class StageGetStageListHandler : PacketHandler<GameClient>
public class StageGetStageListHandler : StructurePacketHandler<GameClient, C2SStageGetStageListReq>
{
private static readonly ServerLogger Logger = LogProvider.Logger<ServerLogger>(typeof(StageGetStageListHandler));


public StageGetStageListHandler(DdonGameServer server) : base(server)
{
}

public override PacketId Id => PacketId.C2S_STAGE_GET_STAGE_LIST_REQ;

public override void Handle(GameClient client, Packet packet)
public override void Handle(GameClient client, StructurePacket<C2SStageGetStageListReq> packet)
{
client.Send(GameDump.Dump_19);
S2CStageGetStageListRes obj = new S2CStageGetStageListRes();
obj.StageList = (Server as DdonGameServer).StageList;

client.Send(obj);
}
}
}
13 changes: 13 additions & 0 deletions Arrowgene.Ddon.Shared/Entity/EntitySerializer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ public abstract class EntitySerializer
Create(new CDataCharacterListInfoSerializer()),
Create(new CDataCharacterMessageSerializer()),
Create(new CDataCharacterMsgSetSerializer()),
Create(new CDataCommonU32.Serializer()),
Create(new CDataCommunicationShortCutSerializer()),
Create(new CDataDropItemSetInfo.Serializer()),
Create(new CDataEditInfoSerializer()),
Expand All @@ -44,8 +45,11 @@ public abstract class EntitySerializer
Create(new CDataOrbPageStatusSerializer()),
Create(new CDataPlayPointDataSerializer()),
Create(new CDataShortCutSerializer()),
Create(new CDataStageAttribute.Serializer()),
Create(new CDataStageInfo.Serializer()),
Create(new CDataStageLayoutEnemyPresetEnemyInfoClient.Serializer()),
Create(new CDataStatusInfoSerializer()),
Create(new CDataTraningRoomEnemyHeader.Serializer()),
Create(new CDataURLInfoSerializer()),
Create(new CDataWarpPointSerializer()),
Create(new CStageLayoutID.Serializer()),
Expand All @@ -70,6 +74,11 @@ public abstract class EntitySerializer
Create(new C2SInstanceGetEnemySetListReqSerializer()),
Create(new C2SLobbyChatMsgReq.Serializer()),
Create(new C2SLobbyJoinReq.Serializer()),
Create(new C2SQuestGetTutorialQuestListRes.Serializer()),
Create(new C2SStageAreaChangeReq.Serializer()),
Create(new C2SStageGetStageListReq.Serializer()),
Create(new C2STraningRoomGetEnemyListReq.Serializer()),
Create(new C2STraningRoomSetEnemyReq.Serializer()),
Create(new C2SWarpGetReturnLocationReq.Serializer()),
Create(new C2SWarpRegisterFavoriteWarpReq.Serializer()),
Create(new C2SWarpWarpReq.Serializer()),
Expand All @@ -95,6 +104,10 @@ public abstract class EntitySerializer
Create(new S2CLobbyChatMsgNotice.Serializer()),
Create(new S2CLobbyChatMsgNoticeCharacterSerializer()),
Create(new S2CLobbyJoinRes.Serializer()),
Create(new S2CStageAreaChangeRes.Serializer()),
Create(new S2CStageGetStageListRes.Serializer()),
Create(new S2CTraningRoomGetEnemyListRes.Serializer()),
Create(new S2CTraningRoomSetEnemyRes.Serializer()),
Create(new S2CWarpGetReturnLocationRes.Serializer()),
Create(new S2CWarpRegisterFavoriteWarpRes.Serializer()),
Create(new S2CWarpWarpRes.Serializer()),
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
using Arrowgene.Buffers;
using Arrowgene.Ddon.Shared.Network;

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

public uint StageNo { get; set; }

public C2SQuestGetTutorialQuestListRes()
{
StageNo = 0;
}

public class Serializer : EntitySerializer<C2SQuestGetTutorialQuestListRes>
{
public override void Write(IBuffer buffer, C2SQuestGetTutorialQuestListRes obj)
{
WriteUInt32(buffer, obj.StageNo);
}

public override C2SQuestGetTutorialQuestListRes Read(IBuffer buffer)
{
C2SQuestGetTutorialQuestListRes obj = new C2SQuestGetTutorialQuestListRes();
obj.StageNo = ReadUInt32(buffer);
return obj;
}
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
using Arrowgene.Buffers;
using Arrowgene.Ddon.Shared.Network;

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

public uint StageId { get; set; }
public uint JumpType { get; set; }

public C2SStageAreaChangeReq() {
StageId=0;
JumpType=0;
}

public class Serializer : EntitySerializer<C2SStageAreaChangeReq>
{
public override void Write(IBuffer buffer, C2SStageAreaChangeReq obj)
{
WriteUInt32(buffer, obj.StageId);
WriteUInt32(buffer, obj.JumpType);
}

public override C2SStageAreaChangeReq Read(IBuffer buffer)
{
C2SStageAreaChangeReq obj = new C2SStageAreaChangeReq();
obj.StageId = ReadUInt32(buffer);
obj.JumpType = ReadUInt32(buffer);
return obj;
}
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
using Arrowgene.Buffers;
using Arrowgene.Ddon.Shared.Network;

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

public class Serializer : EntitySerializer<C2SStageGetStageListReq>
{
public override void Write(IBuffer buffer, C2SStageGetStageListReq obj)
{
}

public override C2SStageGetStageListReq Read(IBuffer buffer)
{
return new C2SStageGetStageListReq();
}
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
using Arrowgene.Buffers;
using Arrowgene.Ddon.Shared.Network;

namespace Arrowgene.Ddon.Shared.Entity.PacketStructure
{
public class C2STraningRoomGetEnemyListReq : IPacketStructure
{
public PacketId Id => PacketId.C2S_INSTANCE_TRANING_ROOM_GET_ENEMY_LIST_REQ;
public class Serializer : EntitySerializer<C2STraningRoomGetEnemyListReq>
{
public override void Write(IBuffer buffer, C2STraningRoomGetEnemyListReq obj)
{
}

public override C2STraningRoomGetEnemyListReq Read(IBuffer buffer)
{
return new C2STraningRoomGetEnemyListReq();
}
}
}

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

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

public uint ID { get; set; }
public uint Lv { get; set; }

public C2STraningRoomSetEnemyReq()
{
ID = 0;
Lv = 0;
}

public class Serializer : EntitySerializer<C2STraningRoomSetEnemyReq>
{
public override void Write(IBuffer buffer, C2STraningRoomSetEnemyReq obj)
{
WriteUInt32(buffer, obj.ID);
WriteUInt32(buffer, obj.Lv);
}

public override C2STraningRoomSetEnemyReq Read(IBuffer buffer)
{
C2STraningRoomSetEnemyReq obj = new C2STraningRoomSetEnemyReq();
obj.ID = ReadUInt32(buffer);
obj.Lv = ReadUInt32(buffer);
return obj;
}
}
}
}
Loading

0 comments on commit 63c6365

Please sign in to comment.