21
21
using Yggdrasil . Network . Communication ;
22
22
using Yggdrasil . Util ;
23
23
using Yggdrasil . Util . Commands ;
24
+ using Melia . Shared . Game . Properties ;
24
25
25
26
namespace Melia . Zone . Commands
26
27
{
@@ -42,6 +43,8 @@ public ChatCommands()
42
43
this . Add ( "readcollection" , "" , "" , this . HandleReadCollection ) ;
43
44
this . Add ( "buyabilpoint" , "<amount>" , "" , this . HandleBuyAbilPoint ) ;
44
45
this . Add ( "intewarpByToken" , "<destination>" , "" , this . HandleTokenWarp ) ;
46
+ this . Add ( "pethire" , "" , "" , this . HandlePetHire ) ;
47
+ this . Add ( "petstat" , "" , "" , this . HandlePetStat ) ;
45
48
46
49
// Custom Client Commands
47
50
this . Add ( "buyshop" , "" , "" , this . HandleBuyShop ) ;
@@ -290,6 +293,118 @@ private CommandResult HandleJump(Character sender, Character target, string mess
290
293
return CommandResult . Okay ;
291
294
}
292
295
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
+
293
408
/// <summary>
294
409
/// Warps target to the specified map.
295
410
/// </summary>
0 commit comments