Skip to content

Commit

Permalink
Merge pull request #568 from MarcusViniciusSS/feat/command-info
Browse files Browse the repository at this point in the history
Create command for get infomation of player on game.
  • Loading branch information
caioavidal committed Nov 6, 2023
2 parents 52012ee + 8cbfe50 commit 3a5b9dd
Show file tree
Hide file tree
Showing 5 changed files with 167 additions and 8 deletions.
65 changes: 65 additions & 0 deletions data/extensions/Spells/Commands/InfoCommand.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
using System;
using System.Linq;
using NeoServer.Game.Combat.Spells;
using NeoServer.Game.Common;
using NeoServer.Game.Common.Contracts.Creatures;
using NeoServer.Game.Common.Contracts.Items;
using NeoServer.Game.Common.Contracts.Items.Types;
using NeoServer.Game.Common.Creatures;
using NeoServer.Game.Items;
using NeoServer.Networking.Packets.Outgoing;
using NeoServer.Server.Common.Contracts;
using NeoServer.Server.Configurations;
using NeoServer.Server.Helpers;

namespace NeoServer.Extensions.Spells.Commands;

public class InfoCommand : CommandSpell
{
public override bool OnCast(ICombatActor actor, string words, out InvalidOperation error)
{
error = InvalidOperation.NotPossible;

if (Params.Length != 1)
return false;

var ctx = IoC.GetInstance<IGameCreatureManager>();
ctx.TryGetPlayer(Params[0].ToString(), out var target);

if (target is null)
return false;

var info = CreateItemInfo();

var message =
$"""
AccountId: {target.AccountId}
Position: {target.Location.X}, {target.Location.Y}, {target.Location.Z}
Capacity: {target.TotalCapacity}
PremiumTime: {target.PremiumTime}
Level: {target.Level}
Skills:
{target.Skills.Where(item => item.Key != SkillType.Level).Select(Item => " * " + Item.Key + ": " + Item.Value.Level + "\n").Aggregate((a, b) => a + b)}
""";

var window = new ListCommandsCommand.TextWindow(info, target.Location, message);
var serverConfiguration = IoC.GetInstance<ServerConfiguration>();

window.WrittenBy = $"{serverConfiguration.ServerName} - SERVER";
window.WrittenOn = DateTime.Now;

var player = actor as IPlayer;

player.Read(window);

return true;
}

private static IItemType CreateItemInfo()
{
var item = new ItemType();
item.SetName("Info Status");
item.SetClientId(2821);
return item;
}
}
21 changes: 14 additions & 7 deletions data/extensions/Spells/Commands/ListCommandsCommand.cs
Original file line number Diff line number Diff line change
Expand Up @@ -53,26 +53,33 @@ private static string BuildTextFromSpells(List<IDictionary<string, object>> spel
var lines = new List<string>();
foreach (var spell in spells)
{
var (words, name) = ExtractSpellAttributes(spell);
var (words, name, description) = ExtractSpellAttributes(spell);

if (string.IsNullOrEmpty(words) || words == command)
continue;

lines.Add($"{words} {name}");
if (string.IsNullOrEmpty(description))
{
lines.Add($"{words} {name}");
continue;
}

lines.Add($"{words} {name} - {description}");
}

return string.Join(Environment.NewLine + Environment.NewLine, lines);
}

private static (string, string) ExtractSpellAttributes(IDictionary<string, object> spell)
private static (string, string, string) ExtractSpellAttributes(IDictionary<string, object> spell)
{
if (spell is null || !spell.ContainsKey("type") || spell["type"]?.ToString() != SPELL_TYPE)
return (string.Empty, string.Empty);
return (string.Empty, string.Empty, string.Empty);

var words = spell["words"].ToString();
var name = spell["name"].ToString();
var description = spell["description"]?.ToString();

return (words, name);
return (words, name, description);
}

private static List<IDictionary<string, object>> LoadSpells()
Expand All @@ -84,7 +91,7 @@ private static List<IDictionary<string, object>> LoadSpells()
new List<IDictionary<string, object>>(0);
}

private sealed class TextWindow : BaseItem, IReadable
public sealed class TextWindow : BaseItem, IReadable
{
public TextWindow(IItemType metadata, Location location, string text) : base(metadata, location)
{
Expand All @@ -94,7 +101,7 @@ public TextWindow(IItemType metadata, Location location, string text) : base(met
public string Text { get; private set; }
public ushort MaxLength => (ushort)(Text?.Length ?? 0);
public bool CanWrite => false;
public string WrittenBy { get; }
public string WrittenBy { get; set; }
public DateTime? WrittenOn { get; set; }

public Result Write(string text, IPlayer writtenBy)
Expand Down
49 changes: 49 additions & 0 deletions data/extensions/Spells/Commands/SpyPlayerCommand.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
using System;
using System.Text;
using NeoServer.Game.Combat.Spells;
using NeoServer.Game.Common;
using NeoServer.Game.Common.Contracts.Creatures;
using NeoServer.Game.Items;
using NeoServer.Server.Common.Contracts;
using NeoServer.Server.Configurations;
using NeoServer.Server.Helpers;

namespace NeoServer.Extensions.Spells.Commands;

public class SpyPlayerCommand : CommandSpell
{
public override bool OnCast(ICombatActor actor, string words, out InvalidOperation error)
{
error = InvalidOperation.NotPossible;

if (Params.Length == 0)
return false;

var ctx = IoC.GetInstance<IGameCreatureManager>();

if (!ctx.TryGetPlayer(Params[0].ToString(), out var player))
return false;

var stringBuilder = new StringBuilder(1000);

stringBuilder.AppendLine($"*** Name: {player.Name} *****");

foreach (var inventoryDressingItem in player.Inventory.DressingItems)
{
stringBuilder.AppendLine($"ClientId: {inventoryDressingItem.Metadata.ClientId}-{inventoryDressingItem.FullName}");
}

var item = new ItemType();
item.SetClientId(2821);

var window = new ListCommandsCommand.TextWindow(item, player.Location, stringBuilder.ToString());
var serverConfiguration = IoC.GetInstance<ServerConfiguration>();

window.WrittenBy = $"{serverConfiguration.ServerName} - SERVER";
window.WrittenOn = DateTime.Now;

player.Read(window);

return true;
}
}
38 changes: 38 additions & 0 deletions data/spells/spells.json
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,7 @@
"name": "Create Item",
"words": "/i",
"script": "ItemCreator",
"description": "",
"mana": 0,
"cooldown": "0",
"level": 1,
Expand All @@ -158,6 +159,7 @@
"name": "Create Monster",
"words": "/m",
"script": "MonsterCreator",
"description": "",
"mana": 0,
"cooldown": "0",
"level": 1,
Expand All @@ -167,6 +169,7 @@
"name": "Up",
"words": "/up",
"script": "UpDownCommand",
"description": "",
"mana": 0,
"cooldown": "0",
"level": 1,
Expand All @@ -176,6 +179,7 @@
"name": "Down",
"words": "/down",
"script": "UpDownCommand",
"description": "",
"mana": 0,
"cooldown": "0",
"level": 1,
Expand All @@ -185,6 +189,7 @@
"name": "Teleport",
"words": "/a",
"script": "TeleportCommand",
"description": "",
"mana": 0,
"cooldown": "0",
"level": 1,
Expand All @@ -194,6 +199,7 @@
"name": "Hide",
"words": "/hide",
"script": "HideCommand",
"description": "",
"mana": 0,
"cooldown": "0",
"level": 1,
Expand All @@ -203,6 +209,7 @@
"name": "Reload",
"words": "/reload",
"script": "ReloadCommand",
"description": "",
"mana": 0,
"cooldown": "0",
"level": 1,
Expand All @@ -212,6 +219,7 @@
"name": "PullPlayer",
"words": "/c",
"script": "PullPlayerCommand",
"description": "",
"mana": 0,
"cooldown": "0",
"level": 1,
Expand All @@ -221,6 +229,7 @@
"name": "TeleportToTemple",
"words": "/t",
"script": "TeleportToTempleCommand",
"description": "For teleport the temple.",
"mana": 0,
"cooldown": "0",
"level": 1,
Expand All @@ -230,6 +239,7 @@
"name": "GoTo",
"words": "/goto",
"script": "GoToCommand",
"description": "For teleport the player for some location.",
"mana": 0,
"cooldown": "0",
"level": 1,
Expand All @@ -239,6 +249,7 @@
"name": "Kick Player",
"words": "/kick",
"script": "KickPlayerCommand",
"description": "To kick an player.",
"mana": 0,
"cooldown": "0",
"level": 1,
Expand All @@ -249,6 +260,7 @@
"name": "Kick All Players",
"words": "/masskick",
"script": "MassKickPlayersCommand",
"description": "To masskick list of player.",
"mana": 0,
"cooldown": "0",
"level": 1,
Expand All @@ -259,6 +271,7 @@
"name": "Ban Player",
"words": "/ban",
"script": "BanPlayerCommand",
"description": "To ban someone player.",
"mana": 0,
"cooldown": "0",
"level": 1,
Expand All @@ -269,6 +282,7 @@
"name": "Attributes on Player",
"words": "/attr",
"script": "AttrPlayerCommand",
"description": "Add attributes for the player.",
"mana": 0,
"cooldown": "0",
"level": 1,
Expand All @@ -279,6 +293,7 @@
"name": "List Commands",
"words": "/commands",
"script": "ListCommandsCommand",
"description": "Get list of server commands.",
"mana": 0,
"cooldown": "0",
"level": 1,
Expand All @@ -289,6 +304,29 @@
"name": "Broadcast",
"words": "/bc",
"script": "BroadcastCommand",
"description": "Send message for everyone on Server.",
"mana": 0,
"cooldown": "0",
"level": 1,
"vocations": [11],
"type": "command"
},
{
"name": "Info",
"words": "/info",
"description": "Get informations about the player!",
"script": "InfoCommand",
"mana": 0,
"cooldown": "0",
"level": 1,
"vocations": [11],
"type": "command"
},
{
"name": "Spy",
"words": "/spy",
"description": "Get informations of Player inventory!",
"script": "SpyPlayerCommand",
"mana": 0,
"cooldown": "0",
"level": 1,
Expand Down
2 changes: 1 addition & 1 deletion src/Standalone/appsettings.Local.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,6 @@
"data": "../../data"
},
"database": {
"active": "SQLITE"
"active": "INMEMORY"
}
}

0 comments on commit 3a5b9dd

Please sign in to comment.