Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Help and Repop chat commands #241

Merged
merged 2 commits into from
Jan 20, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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"));
}
}
}
}
Loading