Skip to content

Commit

Permalink
Review comments; use a Task.Delay to properly space out the training …
Browse files Browse the repository at this point in the history
…reset.
  • Loading branch information
RyanYappert committed Sep 2, 2024
1 parent a337f60 commit 1644f59
Show file tree
Hide file tree
Showing 2 changed files with 109 additions and 105 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -10,22 +10,14 @@ public class InstanceTraningRoomGetEnemyListHandler : GameRequestPacketHandler<C
{
private static readonly ServerLogger Logger = LogProvider.Logger<ServerLogger>(typeof(QuestGetQuestCompletedListHandler));

public static readonly CDataStageLayoutId TrainingRoomLayout = new CDataStageLayoutId(349, 0, 1);

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

public override S2CInstanceTraningRoomGetEnemyListRes Handle(GameClient client, C2SInstanceTraningRoomGetEnemyListReq request)
{
// TODO: Figure out a better way to do this.
// If the reset notice is too soon before the repop notice (in InstanceTraningRoomSetEnemyHandler),
// the repop sometimes fails to happen.
client.Party.SendToAll(new S2CInstanceEnemyGroupResetNtc()
{
LayoutId = TrainingRoomLayout
});

{
// These OptionIds are intepreted in InstanceTraningRoomSetEnemyHandler.
return new S2CInstanceTraningRoomGetEnemyListRes()
{
MaxLv = 100,
Expand Down
202 changes: 107 additions & 95 deletions Arrowgene.Ddon.GameServer/Handler/InstanceTraningRoomSetEnemyHandler.cs
Original file line number Diff line number Diff line change
@@ -1,126 +1,138 @@
using Arrowgene.Ddon.Shared.Entity.PacketStructure;
using Arrowgene.Ddon.Shared.Entity.Structure;
using Arrowgene.Ddon.Shared.Network;
using System.Threading.Tasks;

namespace Arrowgene.Ddon.GameServer.Handler
{
public class InstanceTraningRoomSetEnemyHandler : GameRequestPacketHandler<C2SInstanceTraningRoomSetEnemyReq, S2CInstanceTraningRoomSetEnemyRes>
public class InstanceTraningRoomSetEnemyHandler : GameStructurePacketHandler<C2SInstanceTraningRoomSetEnemyReq>
{
public InstanceTraningRoomSetEnemyHandler(DdonGameServer server) : base(server)
{
}

public override S2CInstanceTraningRoomSetEnemyRes Handle(GameClient client, C2SInstanceTraningRoomSetEnemyReq request)
private static readonly CDataStageLayoutId TrainingRoomLayout = new CDataStageLayoutId(349, 0, 1);
private static readonly int RepopDelay = 2000; // ms

public override void Handle(GameClient client, StructurePacket<C2SInstanceTraningRoomSetEnemyReq> packet)
{

// TODO: Enemies that share the same positionIndex sometimes spawn with the wrong HP.
// To avoid this in the meantime, each enemy must have its own unique positionIndex.
// But the training room layout only has 6 (0-5) indices, so you can only have six different spawns.

var layoutId = InstanceTraningRoomGetEnemyListHandler.TrainingRoomLayout;
client.Send(new S2CInstanceTraningRoomSetEnemyRes());

switch (request.OptionId)
client.Party.SendToAll(new S2CInstanceEnemyGroupResetNtc()
{
case 1: // Two orc soldiers
client.Party.SendToAll(new S2CInstanceEnemyRepopNtc()
{
LayoutId = layoutId,
EnemyData = new CDataLayoutEnemyData()
LayoutId = TrainingRoomLayout
});

ushort level = (ushort)packet.Structure.Lv;

Task.Delay(RepopDelay).ContinueWith(_ => {
switch (packet.Structure.OptionId)
{
case 1: // Two orc soldiers
client.Party.SendToAll(new S2CInstanceEnemyRepopNtc()
{
PositionIndex = 0,
EnemyInfo = new CDataStageLayoutEnemyPresetEnemyInfoClient()
LayoutId = TrainingRoomLayout,
EnemyData = new CDataLayoutEnemyData()
{
EnemyId = 0x15800,
NamedEnemyParamsId = 47, // Training <name>
Lv = (ushort)request.Lv,
RepopCount = 10,
Scale = 100,
IsBossGauge = true,
}
},
WaitSecond = 1,
});
client.Party.SendToAll(new S2CInstanceEnemyRepopNtc()
{
LayoutId = layoutId,
EnemyData = new CDataLayoutEnemyData()
PositionIndex = 0,
EnemyInfo = new CDataStageLayoutEnemyPresetEnemyInfoClient()
{
EnemyId = 0x15800,
NamedEnemyParamsId = 47, // Training <name>
Lv = level,
RepopCount = 10,
Scale = 100,
IsBossGauge = true,
}
},
WaitSecond = 0,
});
client.Party.SendToAll(new S2CInstanceEnemyRepopNtc()
{
PositionIndex = 1,
EnemyInfo = new CDataStageLayoutEnemyPresetEnemyInfoClient()
LayoutId = TrainingRoomLayout,
EnemyData = new CDataLayoutEnemyData()
{
EnemyId = 0x15800,
NamedEnemyParamsId = 47, // Training <name>
Lv = (ushort)request.Lv,
RepopCount = 10,
Scale = 100,
IsBossGauge = true,
}
},
WaitSecond = 1,
});
break;
case 2: // Cyclops
client.Party.SendToAll(new S2CInstanceEnemyRepopNtc()
{
LayoutId = layoutId,
EnemyData = new CDataLayoutEnemyData()
PositionIndex = 1,
EnemyInfo = new CDataStageLayoutEnemyPresetEnemyInfoClient()
{
EnemyId = 0x15800,
NamedEnemyParamsId = 47, // Training <name>
Lv = level,
RepopCount = 10,
Scale = 100,
IsBossGauge = true,
}
},
WaitSecond = 0,
});
break;
case 2: // Cyclops
client.Party.SendToAll(new S2CInstanceEnemyRepopNtc()
{
PositionIndex = 2,
EnemyInfo = new CDataStageLayoutEnemyPresetEnemyInfoClient()
LayoutId = TrainingRoomLayout,
EnemyData = new CDataLayoutEnemyData()
{
EnemyId = 0x15000,
NamedEnemyParamsId = 47, // Training <name>
Lv = (ushort)request.Lv,
RepopCount = 10,
Scale = 100,
IsBossGauge = true,
}
},
WaitSecond = 1,
});
break;
case 3: //Ogre
client.Party.SendToAll(new S2CInstanceEnemyRepopNtc()
{
LayoutId = layoutId,
EnemyData = new CDataLayoutEnemyData()
PositionIndex = 2,
EnemyInfo = new CDataStageLayoutEnemyPresetEnemyInfoClient()
{
EnemyId = 0x15000,
NamedEnemyParamsId = 47, // Training <name>
Lv = level,
RepopCount = 10,
Scale = 100,
IsBossGauge = true,
}
},
WaitSecond = 0,
});
break;
case 3: //Ogre
client.Party.SendToAll(new S2CInstanceEnemyRepopNtc()
{
PositionIndex = 3,
EnemyInfo = new CDataStageLayoutEnemyPresetEnemyInfoClient()
LayoutId = TrainingRoomLayout,
EnemyData = new CDataLayoutEnemyData()
{
EnemyId = 0x15500,
NamedEnemyParamsId = 47, // Training <name>
Lv = (ushort)request.Lv,
RepopCount = 10,
Scale = 100,
IsBossGauge = true,
}
},
WaitSecond = 1,
});
break;
case 4: //Passive Zuhl
client.Party.SendToAll(new S2CInstanceEnemyRepopNtc()
{
LayoutId = layoutId,
EnemyData = new CDataLayoutEnemyData()
PositionIndex = 3,
EnemyInfo = new CDataStageLayoutEnemyPresetEnemyInfoClient()
{
EnemyId = 0x15500,
NamedEnemyParamsId = 47, // Training <name>
Lv = level,
RepopCount = 10,
Scale = 100,
IsBossGauge = true,
}
},
WaitSecond = 0,
});
break;
case 4: //Passive Zuhl
client.Party.SendToAll(new S2CInstanceEnemyRepopNtc()
{
PositionIndex = 4,
EnemyInfo = new CDataStageLayoutEnemyPresetEnemyInfoClient()
LayoutId = TrainingRoomLayout,
EnemyData = new CDataLayoutEnemyData()
{
EnemyId = 0x100101,
NamedEnemyParamsId = 722, // Practice <name>, has extra HP.
Lv = (ushort)request.Lv,
RepopCount = 10,
Scale = 75,
IsBossGauge = true,
}
},
WaitSecond = 1,
});
break;
}

return new S2CInstanceTraningRoomSetEnemyRes();
PositionIndex = 4,
EnemyInfo = new CDataStageLayoutEnemyPresetEnemyInfoClient()
{
EnemyId = 0x100101,
NamedEnemyParamsId = 722, // Practice <name>, has extra HP.
Lv = level,
RepopCount = 10,
Scale = 75,
IsBossGauge = true,
}
},
WaitSecond = 0,
});
break;
}
});
}
}
}

0 comments on commit 1644f59

Please sign in to comment.