Skip to content

Commit f0f8f71

Browse files
committed
Official pet chat commands
1 parent 7db4cfb commit f0f8f71

File tree

2 files changed

+117
-0
lines changed

2 files changed

+117
-0
lines changed

src/ZoneServer/Commands/ChatCommands.Handlers.cs

+115
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
using Yggdrasil.Network.Communication;
2222
using Yggdrasil.Util;
2323
using Yggdrasil.Util.Commands;
24+
using Melia.Shared.Game.Properties;
2425

2526
namespace Melia.Zone.Commands
2627
{
@@ -42,6 +43,8 @@ public ChatCommands()
4243
this.Add("readcollection", "", "", this.HandleReadCollection);
4344
this.Add("buyabilpoint", "<amount>", "", this.HandleBuyAbilPoint);
4445
this.Add("intewarpByToken", "<destination>", "", this.HandleTokenWarp);
46+
this.Add("pethire", "", "", this.HandlePetHire);
47+
this.Add("petstat", "", "", this.HandlePetStat);
4548

4649
// Custom Client Commands
4750
this.Add("buyshop", "", "", this.HandleBuyShop);
@@ -290,6 +293,118 @@ private CommandResult HandleJump(Character sender, Character target, string mess
290293
return CommandResult.Okay;
291294
}
292295

296+
/// <summary>
297+
/// Official slash command to hire a pet
298+
/// </summary>
299+
/// <example>/pethire 3 Pet</example>
300+
/// <param name="sender"></param>
301+
/// <param name="target"></param>
302+
/// <param name="message"></param>
303+
/// <param name="command"></param>
304+
/// <param name="args"></param>
305+
/// <returns></returns>
306+
private CommandResult HandlePetHire(Character sender, Character target, string message, string command, Arguments args)
307+
{
308+
// Since this command is sent via UI interactions, we'll not
309+
// use any automated command result messages, but we'll leave
310+
// debug messages for now, in case of unexpected values.
311+
if (args.Count < 2)
312+
{
313+
Log.Debug("HandlePetHire: Invalid call by user '{0}': {1}", sender.Username, command);
314+
return CommandResult.Okay;
315+
}
316+
317+
if (sender.Companions.HasCompanions)
318+
return CommandResult.Okay;
319+
320+
if (!int.TryParse(args.Get(0), out var petShopId))
321+
return CommandResult.InvalidArgument;
322+
323+
if (!ZoneServer.Instance.Data.CompanionDb.TryFind(petShopId, out var data))
324+
return CommandResult.InvalidArgument;
325+
326+
if (!ZoneServer.Instance.Data.MonsterDb.TryFind(data.ClassName, out var monData))
327+
return CommandResult.InvalidArgument;
328+
329+
var targetNpcName = "Companion Trader";
330+
var currentNpcName = sender.Connection.CurrentDialog?.Npc.Name;
331+
332+
if (string.IsNullOrEmpty(currentNpcName) || !currentNpcName.Contains(targetNpcName))
333+
return CommandResult.InvalidArgument;
334+
335+
//TODO: Decide if we sell pets that don't have a price defined.
336+
if (data.Price == 0)
337+
return CommandResult.Okay;
338+
339+
if (sender.Inventory.CountItem(ItemId.Silver) < data.Price)
340+
{
341+
sender.SystemMessage("OwnerDontHaveSilver");
342+
return CommandResult.Okay;
343+
}
344+
345+
if (sender.Inventory.Remove(ItemId.Silver, data.Price) != InventoryResult.Success)
346+
return CommandResult.Fail;
347+
348+
var companion = new Companion(sender, monData.Id);
349+
if (args.Count > 1)
350+
companion.Name = args.Get(1);
351+
352+
sender.Companions.CreateCompanion(companion);
353+
354+
return CommandResult.Okay;
355+
}
356+
357+
/// <summary>
358+
/// Official slash command to raise pet stats
359+
/// </summary>
360+
/// <example>/petstat 528525790635969 MHP 1</example>
361+
/// <param name="sender"></param>
362+
/// <param name="target"></param>
363+
/// <param name="message"></param>
364+
/// <param name="command"></param>
365+
/// <param name="args"></param>
366+
/// <returns></returns>
367+
private CommandResult HandlePetStat(Character sender, Character target, string message, string command, Arguments args)
368+
{
369+
// Since this command is sent via UI interactions, we'll not
370+
// use any automated command result messages, but we'll leave
371+
// debug messages for now, in case of unexpected values.
372+
if (args.Count < 2)
373+
{
374+
Log.Debug("HandlePetStat: Invalid call by user '{0}': {1}", sender.Username, command);
375+
return CommandResult.Okay;
376+
}
377+
378+
if (!sender.Companions.HasCompanions)
379+
return CommandResult.Okay;
380+
381+
if (long.TryParse(args.Get(0), out var companionObjectId))
382+
{
383+
var companion = sender.Companions.GetCompanion(companionObjectId);
384+
var propertyName = "Monster_Stat_" + args.Get(1);
385+
386+
if (companion != null && PropertyTable.Exists("Monster", propertyName)
387+
&& int.TryParse(args.Get(2), out var modifierValue))
388+
{
389+
var baseCost = propertyName == PropertyName.Stat_DEF ? 600 : 300;
390+
var totalCost = 0;
391+
var currentValue = companion.Properties.GetFloat(propertyName) - 1;
392+
393+
for (var i = currentValue; i < (currentValue + modifierValue); i++)
394+
totalCost += (int)Math.Floor(baseCost * Math.Pow(1.08, i));
395+
396+
if (sender.Inventory.CountItem(ItemId.Silver) >= totalCost)
397+
{
398+
sender.Inventory.Remove(ItemId.Silver, totalCost);
399+
companion.Properties.Modify(propertyName, modifierValue);
400+
Send.ZC_OBJECT_PROPERTY(sender.Connection, companion);
401+
}
402+
}
403+
}
404+
405+
return CommandResult.Okay;
406+
}
407+
293408
/// <summary>
294409
/// Warps target to the specified map.
295410
/// </summary>

system/conf/commands.conf

+2
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,8 @@ readcollection : 0,-1
3535
buyabilpoint : 0,-1
3636
learnpcabil : 0,-1
3737
intewarpByToken : 0,-1
38+
pethire : 0,-1
39+
petstat : 0,-1
3840

3941
// Custom client commands
4042
// These commands are used by our internal custom scripts to communicate

0 commit comments

Comments
 (0)