Skip to content

Commit

Permalink
Merge pull request #241 from alborrajo/feature/repop
Browse files Browse the repository at this point in the history
Help and Repop chat commands
  • Loading branch information
alborrajo authored Jan 20, 2024
2 parents e99aba9 + f9a7594 commit 1150e8d
Show file tree
Hide file tree
Showing 4 changed files with 104 additions and 91 deletions.
4 changes: 2 additions & 2 deletions Arrowgene.Ddon.GameServer/Chat/Command/ChatCommandHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
using System.Collections.Generic;
using Arrowgene.Ddon.GameServer.Chat.Command.Commands;
using Arrowgene.Ddon.Server;
using Arrowgene.Ddon.Shared.Model;
using Arrowgene.Logging;

namespace Arrowgene.Ddon.GameServer.Chat.Command
Expand All @@ -19,8 +18,9 @@ public class ChatCommandHandler : IChatHandler
public ChatCommandHandler(DdonGameServer server)
{
_commands = new Dictionary<string, ChatCommand>();
AddCommand(new HelpCommand(_commands));
AddCommand(new TestCommand());
AddCommand(new EnemyCommand());
AddCommand(new RepopCommand(server));
AddCommand(new InfoCommand());
AddCommand(new JobCommand(server));
AddCommand(new MotherlodeCommand(server));
Expand Down
89 changes: 0 additions & 89 deletions Arrowgene.Ddon.GameServer/Chat/Command/Commands/EnemyCommand.cs

This file was deleted.

28 changes: 28 additions & 0 deletions Arrowgene.Ddon.GameServer/Chat/Command/Commands/HelpCommand.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
using System.Linq;
using System.Collections.Generic;
using Arrowgene.Ddon.Database.Model;

namespace Arrowgene.Ddon.GameServer.Chat.Command.Commands
{
public class HelpCommand : ChatCommand
{
public override AccountStateType AccountState => AccountStateType.User;
public override string Key => "help";
public override string HelpText => "usage: `/help` - Shows this text";

private Dictionary<string, ChatCommand> ChatCommands;

public HelpCommand(Dictionary<string, ChatCommand> chatCommands)
{
ChatCommands = chatCommands;
}

public override void Execute(string[] command, GameClient client, ChatMessage message, List<ChatResponse> responses)
{
this.ChatCommands.Values
.Select(cmd => new ChatResponse() {Message = cmd.HelpText})
.ToList()
.ForEach(response => responses.Add(response));
}
}
}
74 changes: 74 additions & 0 deletions Arrowgene.Ddon.GameServer/Chat/Command/Commands/RepopCommand.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
using System;
using System.Collections.Generic;
using Arrowgene.Ddon.Database.Model;
using Arrowgene.Ddon.Shared.Entity.PacketStructure;
using Arrowgene.Ddon.Shared.Entity.Structure;
using Arrowgene.Ddon.Shared.Model;

namespace Arrowgene.Ddon.GameServer.Chat.Command.Commands
{
public class RepopCommand : ChatCommand
{
public override AccountStateType AccountState => AccountStateType.User;
public override string Key => "repop";
public override string HelpText => "usage: `/repop StageId LayerNo GroupId SubGroupId PositionIndex (WaitSeconds)` - The enemy in the CSV should have RepopCount > 0`";

private DdonGameServer Server;

public RepopCommand(DdonGameServer server) {
Server = server;
}

public override void Execute(string[] command, GameClient client, ChatMessage message, List<ChatResponse> responses)
{
if (command.Length < 5)
{
responses.Add(ChatResponse.CommandError(client, "no arguments provided"));
return;
}

try
{
uint stageNo = uint.Parse(command[0]);
byte layerNo = byte.Parse(command[1]);
uint groupId = uint.Parse(command[2]);
byte subGroupId = byte.Parse(command[3]);
byte positionIndex = byte.Parse(command[4]);
uint waitSeconds = 0;

if (command.Length > 5)
{
waitSeconds = uint.Parse(command[5]);
}


CDataStageLayoutId enemyGroup = new CDataStageLayoutId() //client.Character.EnemyGroupsEntered.First();
{
StageId = stageNo,
LayerNo = layerNo,
GroupId = groupId
};
List<EnemySpawn> enemySpawns = Server.EnemyManager.GetAssets(enemyGroup, subGroupId);

if (enemySpawns.Count <= positionIndex)
{
responses.Add(ChatResponse.CommandError(client, "no enemies to repopulate in this enemy group and position index"));
return;
}

S2CInstanceEnemyRepopNtc ntc = new S2CInstanceEnemyRepopNtc();
ntc.LayoutId = enemyGroup;
ntc.EnemyData.PositionIndex = positionIndex;
ntc.EnemyData.EnemyInfo = enemySpawns[positionIndex].Enemy;
ntc.WaitSecond = waitSeconds;
client.Party.SendToAll(ntc);

responses.Add(ChatResponse.ServerMessage(client, "Command Executed"));
}
catch(Exception)
{
responses.Add(ChatResponse.CommandError(client, "invalid arguments"));
}
}
}
}

0 comments on commit 1150e8d

Please sign in to comment.