summaryrefslogtreecommitdiff
path: root/src/TrainerMod/TrainerMod.cs
blob: c76bb78ce5230ff99348d12b2fde0a814fd79e36 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using Microsoft.Xna.Framework;
using StardewModdingAPI;
using StardewModdingAPI.Events;
using StardewValley;
using StardewValley.Menus;
using StardewValley.Objects;
using StardewValley.Tools;
using TrainerMod.Framework;
using TrainerMod.ItemData;
using Object = StardewValley.Object;

namespace TrainerMod
{
    /// <summary>The main entry point for the mod.</summary>
    public class TrainerMod : Mod
    {
        /*********
        ** Properties
        *********/
        /// <summary>The time of day at which to freeze time.</summary>
        private int FrozenTime;

        /// <summary>Whether to keep the player's health at its maximum.</summary>
        private bool InfiniteHealth;

        /// <summary>Whether to keep the player's stamina at its maximum.</summary>
        private bool InfiniteStamina;

        /// <summary>Whether to keep the player's money at a set value.</summary>
        private bool InfiniteMoney;

        /// <summary>Whether to freeze time.</summary>
        private bool FreezeTime;


        /*********
        ** Public methods
        *********/
        /// <summary>The mod entry point, called after the mod is first loaded.</summary>
        /// <param name="helper">Provides simplified APIs for writing mods.</param>
        public override void Entry(IModHelper helper)
        {
            this.RegisterCommands();
            GameEvents.UpdateTick += this.ReceiveUpdateTick;
        }


        /*********
        ** Private methods
        *********/
        /****
        ** Implementation
        ****/
        /// <summary>The method invoked when the game updates its state.</summary>
        /// <param name="sender">The event sender.</param>
        /// <param name="e">The event arguments.</param>
        private void ReceiveUpdateTick(object sender, EventArgs e)
        {
            if (Game1.player == null)
                return;

            if (this.InfiniteHealth)
                Game1.player.health = Game1.player.maxHealth;
            if (this.InfiniteStamina)
                Game1.player.stamina = Game1.player.MaxStamina;
            if (this.InfiniteMoney)
                Game1.player.money = 999999;
            if (this.FreezeTime)
                Game1.timeOfDay = this.FrozenTime;
        }

        /// <summary>Register all trainer commands.</summary>
        private void RegisterCommands()
        {
            Command.RegisterCommand("types", "Lists all value types | types").CommandFired += this.HandleTypes;

            Command.RegisterCommand("save", "Saves the game? Doesn't seem to work. | save").CommandFired += this.HandleSave;
            Command.RegisterCommand("load", "Shows the load screen | load").CommandFired += this.HandleLoad;

            Command.RegisterCommand("exit", "Closes the game | exit").CommandFired += this.HandleExit;
            Command.RegisterCommand("stop", "Closes the game | stop").CommandFired += this.HandleExit;

            Command.RegisterCommand("player_setname", "Sets the player's name | player_setname <object> <value>", new[] { "(player, pet, farm)<object> (String)<value> The target name" }).CommandFired += this.HandlePlayerSetName;
            Command.RegisterCommand("player_setmoney", "Sets the player's money | player_setmoney <value>|inf", new[] { "(Int32)<value> The target money" }).CommandFired += this.HandlePlayerSetMoney;
            Command.RegisterCommand("player_setstamina", "Sets the player's stamina | player_setstamina <value>|inf", new[] { "(Int32)<value> The target stamina" }).CommandFired += this.HandlePlayerSetStamina;
            Command.RegisterCommand("player_setmaxstamina", "Sets the player's max stamina | player_setmaxstamina <value>", new[] { "(Int32)<value> The target max stamina" }).CommandFired += this.HandlePlayerSetMaxStamina;
            Command.RegisterCommand("player_sethealth", "Sets the player's health | player_sethealth <value>|inf", new[] { "(Int32)<value> The target health" }).CommandFired += this.HandlePlayerSetHealth;
            Command.RegisterCommand("player_setmaxhealth", "Sets the player's max health | player_setmaxhealth <value>", new[] { "(Int32)<value> The target max health" }).CommandFired += this.HandlePlayerSetMaxHealth;
            Command.RegisterCommand("player_setimmunity", "Sets the player's immunity | player_setimmunity <value>", new[] { "(Int32)<value> The target immunity" }).CommandFired += this.HandlePlayerSetImmunity;

            Command.RegisterCommand("player_setlevel", "Sets the player's specified skill to the specified value | player_setlevel <skill> <value>", new[] { "(luck, mining, combat, farming, fishing, foraging)<skill> (1-10)<value> The target level" }).CommandFired += this.HandlePlayerSetLevel;
            Command.RegisterCommand("player_setspeed", "Sets the player's speed to the specified value?", new[] { "(Int32)<value> The target speed [0 is normal]" }).CommandFired += this.HandlePlayerSetSpeed;
            Command.RegisterCommand("player_changecolour", "Sets the player's colour of the specified object | player_changecolor <object> <colour>", new[] { "(hair, eyes, pants)<object> (r,g,b)<colour>" }).CommandFired += this.HandlePlayerChangeColor;
            Command.RegisterCommand("player_changestyle", "Sets the player's style of the specified object | player_changecolor <object> <value>", new[] { "(hair, shirt, skin, acc, shoe, swim, gender)<object> (Int32)<value>" }).CommandFired += this.HandlePlayerChangeStyle;

            Command.RegisterCommand("player_additem", "Gives the player an item | player_additem <item> [count] [quality]", new[] { "(Int32)<id> (Int32)[count] (Int32)[quality]" }).CommandFired += this.HandlePlayerAddItem;
            Command.RegisterCommand("player_addmelee", "Gives the player a melee item | player_addmelee <item>", new[] { "?<item>" }).CommandFired += this.HandlePlayerAddMelee;
            Command.RegisterCommand("player_addring", "Gives the player a ring | player_addring <item>", new[] { "?<item>" }).CommandFired += this.HandlePlayerAddRing;

            Command.RegisterCommand("list_items", "Lists items in the game data | list_items [search]", new[] { "(String)<search>" }).CommandFired += this.HandleListItems;

            Command.RegisterCommand("world_settime", "Sets the time to the specified value | world_settime <value>", new[] { "(Int32)<value> The target time [06:00 AM is 600]" }).CommandFired += this.HandleWorldSetTime;
            Command.RegisterCommand("world_freezetime", "Freezes or thaws time | world_freezetime <value>", new[] { "(0 - 1)<value> Whether or not to freeze time. 0 is thawed, 1 is frozen" }).CommandFired += this.HandleWorldFreezeTime;
            Command.RegisterCommand("world_setday", "Sets the day to the specified value | world_setday <value>", new[] { "(Int32)<value> The target day [1-28]" }).CommandFired += this.world_setDay;
            Command.RegisterCommand("world_setseason", "Sets the season to the specified value | world_setseason <value>", new[] { "(winter, spring, summer, fall)<value> The target season" }).CommandFired += this.HandleWorldSetSeason;
            Command.RegisterCommand("world_downminelevel", "Goes down one mine level? | world_downminelevel", new[] { "" }).CommandFired += this.HandleWorldDownMineLevel;
            Command.RegisterCommand("world_setminelevel", "Sets mine level? | world_setminelevel", new[] { "(Int32)<value> The target level" }).CommandFired += this.HandleWorldSetMineLevel;

            Command.RegisterCommand("show_game_files", "Opens the game folder. | show_game_files").CommandFired += this.HandleShowGameFiles;
            Command.RegisterCommand("show_data_files", "Opens the folder containing the save and log files. | show_data_files").CommandFired += this.HandleShowDataFiles;
        }

        /****
        ** Command handlers
        ****/
        /// <summary>The event raised when the 'types' command is triggered.</summary>
        /// <param name="sender">The event sender.</param>
        /// <param name="e">The event arguments.</param>
        private void HandleTypes(object sender, EventArgsCommand e)
        {
            this.Monitor.Log($"[Int32: {int.MinValue} - {int.MaxValue}], [Int64: {long.MinValue} - {long.MaxValue}], [String: \"raw text\"], [Colour: r,g,b (EG: 128, 32, 255)]", LogLevel.Info);
        }

        /// <summary>The event raised when the 'save' command is triggered.</summary>
        /// <param name="sender">The event sender.</param>
        /// <param name="e">The event arguments.</param>
        private void HandleSave(object sender, EventArgsCommand e)
        {
            SaveGame.Save();
        }

        /// <summary>The event raised when the 'load' command is triggered.</summary>
        /// <param name="sender">The event sender.</param>
        /// <param name="e">The event arguments.</param>
        private void HandleLoad(object sender, EventArgsCommand e)
        {
            Game1.hasLoadedGame = false;
            Game1.activeClickableMenu = new LoadGameMenu();
        }

        /// <summary>The event raised when the 'exit' command is triggered.</summary>
        /// <param name="sender">The event sender.</param>
        /// <param name="e">The event arguments.</param>
        private void HandleExit(object sender, EventArgsCommand e)
        {
            Program.gamePtr.Exit();
            Environment.Exit(0);
        }

        /// <summary>The event raised when the 'player_setName' command is triggered.</summary>
        /// <param name="sender">The event sender.</param>
        /// <param name="e">The event arguments.</param>
        private void HandlePlayerSetName(object sender, EventArgsCommand e)
        {
            if (e.Command.CalledArgs.Length > 1)
            {
                string target = e.Command.CalledArgs[0];
                string[] validTargets = { "player", "pet", "farm" };
                if (validTargets.Contains(target))
                {
                    switch (target)
                    {
                        case "player":
                            Game1.player.Name = e.Command.CalledArgs[1];
                            break;
                        case "pet":
                            this.Monitor.Log("Pets cannot currently be renamed.", LogLevel.Info);
                            break;
                        case "farm":
                            Game1.player.farmName = e.Command.CalledArgs[1];
                            break;
                    }
                }
                else
                    this.LogObjectInvalid();
            }
            else
                this.LogObjectValueNotSpecified();
        }

        /// <summary>The event raised when the 'player_setMoney' command is triggered.</summary>
        /// <param name="sender">The event sender.</param>
        /// <param name="e">The event arguments.</param>
        private void HandlePlayerSetMoney(object sender, EventArgsCommand e)
        {
            if (e.Command.CalledArgs.Length > 0)
            {
                string amountStr = e.Command.CalledArgs[0];
                if (amountStr == "inf")
                    this.InfiniteMoney = true;
                else
                {
                    this.InfiniteMoney = false;
                    int amount;
                    if (int.TryParse(amountStr, out amount))
                    {
                        Game1.player.Money = amount;
                        this.Monitor.Log($"Set {Game1.player.Name}'s money to {Game1.player.Money}", LogLevel.Info);
                    }
                    else
                        this.LogValueNotInt32();
                }
            }
            else
                this.LogValueNotSpecified();
        }

        /// <summary>The event raised when the 'player_setStamina' command is triggered.</summary>
        /// <param name="sender">The event sender.</param>
        /// <param name="e">The event arguments.</param>
        private void HandlePlayerSetStamina(object sender, EventArgsCommand e)
        {
            if (e.Command.CalledArgs.Length > 0)
            {
                string amountStr = e.Command.CalledArgs[0];
                if (amountStr == "inf")
                    this.InfiniteStamina = true;
                else
                {
                    this.InfiniteStamina = false;
                    int amount;
                    if (int.TryParse(amountStr, out amount))
                    {
                        Game1.player.Stamina = amount;
                        this.Monitor.Log($"Set {Game1.player.Name}'s stamina to {Game1.player.Stamina}", LogLevel.Info);
                    }
                    else
                        this.LogValueNotInt32();
                }
            }
            else
                this.LogValueNotSpecified();
        }

        /// <summary>The event raised when the 'player_setMaxStamina' command is triggered.</summary>
        /// <param name="sender">The event sender.</param>
        /// <param name="e">The event arguments.</param>
        private void HandlePlayerSetMaxStamina(object sender, EventArgsCommand e)
        {
            if (e.Command.CalledArgs.Length > 0)
            {
                int amount;
                if (int.TryParse(e.Command.CalledArgs[0], out amount))
                {
                    Game1.player.MaxStamina = amount;
                    this.Monitor.Log($"Set {Game1.player.Name}'s max stamina to {Game1.player.MaxStamina}", LogLevel.Info);
                }
                else
                    this.LogValueNotInt32();
            }
            else
                this.LogValueNotSpecified();
        }

        /// <summary>The event raised when the 'player_setLevel' command is triggered.</summary>
        /// <param name="sender">The event sender.</param>
        /// <param name="e">The event arguments.</param>
        private void HandlePlayerSetLevel(object sender, EventArgsCommand e)
        {
            if (e.Command.CalledArgs.Length > 1)
            {
                string skill = e.Command.CalledArgs[0];
                string[] skills = { "luck", "mining", "combat", "farming", "fishing", "foraging" };
                if (skills.Contains(skill))
                {
                    int level;
                    if (int.TryParse(e.Command.CalledArgs[1], out level))
                    {
                        switch (skill)
                        {
                            case "luck":
                                Game1.player.LuckLevel = level;
                                break;
                            case "mining":
                                Game1.player.MiningLevel = level;
                                break;
                            case "combat":
                                Game1.player.CombatLevel = level;
                                break;
                            case "farming":
                                Game1.player.FarmingLevel = level;
                                break;
                            case "fishing":
                                Game1.player.FishingLevel = level;
                                break;
                            case "foraging":
                                Game1.player.ForagingLevel = level;
                                break;
                        }
                    }
                    else
                        this.LogValueNotInt32();
                }
                else
                    this.Monitor.Log("<skill> is invalid", LogLevel.Error);
            }
            else
                this.Monitor.Log("<skill> and <value> must be specified", LogLevel.Error);
        }

        /// <summary>The event raised when the 'player_setSpeed' command is triggered.</summary>
        /// <param name="sender">The event sender.</param>
        /// <param name="e">The event arguments.</param>
        private void HandlePlayerSetSpeed(object sender, EventArgsCommand e)
        {
            if (e.Command.CalledArgs.Length > 0)
            {
                string amountStr = e.Command.CalledArgs[0];
                if (amountStr.IsInt())
                {
                    Game1.player.addedSpeed = amountStr.ToInt();
                    this.Monitor.Log($"Set {Game1.player.Name}'s added speed to {Game1.player.addedSpeed}", LogLevel.Info);
                }
                else
                    this.LogValueNotInt32();
            }
            else
                this.LogValueNotSpecified();
        }

        /// <summary>The event raised when the 'player_changeColour' command is triggered.</summary>
        /// <param name="sender">The event sender.</param>
        /// <param name="e">The event arguments.</param>
        private void HandlePlayerChangeColor(object sender, EventArgsCommand e)
        {
            if (e.Command.CalledArgs.Length > 1)
            {
                string target = e.Command.CalledArgs[0];
                string[] validTargets = { "hair", "eyes", "pants" };
                if (validTargets.Contains(target))
                {
                    string[] colorHexes = e.Command.CalledArgs[1].Split(new[] { ',' }, 3);
                    if (colorHexes[0].IsInt() && colorHexes[1].IsInt() && colorHexes[2].IsInt())
                    {
                        var color = new Color(colorHexes[0].ToInt(), colorHexes[1].ToInt(), colorHexes[2].ToInt());
                        switch (target)
                        {
                            case "hair":
                                Game1.player.hairstyleColor = color;
                                break;
                            case "eyes":
                                Game1.player.changeEyeColor(color);
                                break;
                            case "pants":
                                Game1.player.pantsColor = color;
                                break;
                        }
                    }
                    else
                        this.Monitor.Log("<colour> is invalid", LogLevel.Error);
                }
                else
                    this.LogObjectInvalid();
            }
            else
                this.Monitor.Log("<object> and <colour> must be specified", LogLevel.Error);
        }

        /// <summary>The event raised when the 'player_changeStyle' command is triggered.</summary>
        /// <param name="sender">The event sender.</param>
        /// <param name="e">The event arguments.</param>
        private void HandlePlayerChangeStyle(object sender, EventArgsCommand e)
        {
            if (e.Command.CalledArgs.Length > 1)
            {
                string target = e.Command.CalledArgs[0];
                string[] validTargets = { "hair", "shirt", "skin", "acc", "shoe", "swim", "gender" };
                if (validTargets.Contains(target))
                {
                    if (e.Command.CalledArgs[1].IsInt())
                    {
                        var styleID = e.Command.CalledArgs[1].ToInt();
                        switch (target)
                        {
                            case "hair":
                                Game1.player.changeHairStyle(styleID);
                                break;
                            case "shirt":
                                Game1.player.changeShirt(styleID);
                                break;
                            case "acc":
                                Game1.player.changeAccessory(styleID);
                                break;
                            case "skin":
                                Game1.player.changeSkinColor(styleID);
                                break;
                            case "shoe":
                                Game1.player.changeShoeColor(styleID);
                                break;
                            case "swim":
                                if (styleID == 0)
                                    Game1.player.changeOutOfSwimSuit();
                                else if (styleID == 1)
                                    Game1.player.changeIntoSwimsuit();
                                else
                                    this.Monitor.Log("<value> must be 0 or 1 for this <object>", LogLevel.Error);
                                break;
                            case "gender":
                                if (styleID == 0)
                                    Game1.player.changeGender(true);
                                else if (styleID == 1)
                                    Game1.player.changeGender(false);
                                else
                                    this.Monitor.Log("<value> must be 0 or 1 for this <object>", LogLevel.Error);
                                break;
                        }
                    }
                    else
                        this.LogValueInvalid();
                }
                else
                    this.LogObjectInvalid();
            }
            else
                this.LogObjectValueNotSpecified();
        }

        /// <summary>The event raised when the 'world_freezeTime' command is triggered.</summary>
        /// <param name="sender">The event sender.</param>
        /// <param name="e">The event arguments.</param>
        private void HandleWorldFreezeTime(object sender, EventArgsCommand e)
        {
            if (e.Command.CalledArgs.Length > 0)
            {
                string valueStr = e.Command.CalledArgs[0];
                if (valueStr.IsInt())
                {
                    int value = valueStr.ToInt();
                    if (value == 0 || value == 1)
                    {
                        this.FreezeTime = value == 1;
                        this.FrozenTime = this.FreezeTime ? Game1.timeOfDay : 0;
                        this.Monitor.Log("Time is now " + (this.FreezeTime ? "frozen" : "thawed"), LogLevel.Info);
                    }
                    else
                        this.Monitor.Log("<value> should be 0 or 1", LogLevel.Error);
                }
                else
                    this.LogValueNotInt32();
            }
            else
                this.LogValueNotSpecified();
        }

        /// <summary>The event raised when the 'world_setTime' command is triggered.</summary>
        /// <param name="sender">The event sender.</param>
        /// <param name="e">The event arguments.</param>
        private void HandleWorldSetTime(object sender, EventArgsCommand e)
        {
            if (e.Command.CalledArgs.Length > 0)
            {
                string timeStr = e.Command.CalledArgs[0];
                if (timeStr.IsInt())
                {
                    int time = timeStr.ToInt();

                    if (time <= 2600 && time >= 600)
                    {
                        Game1.timeOfDay = e.Command.CalledArgs[0].ToInt();
                        this.FrozenTime = this.FreezeTime ? Game1.timeOfDay : 0;
                        this.Monitor.Log($"Time set to: {Game1.timeOfDay}", LogLevel.Info);
                    }
                    else
                        this.Monitor.Log("<value> should be between 600 and 2600 (06:00 AM - 02:00 AM [NEXT DAY])", LogLevel.Error);
                }
                else
                    this.LogValueNotInt32();
            }
            else
                this.LogValueNotSpecified();
        }

        /// <summary>The event raised when the 'world_setDay' command is triggered.</summary>
        /// <param name="sender">The event sender.</param>
        /// <param name="e">The event arguments.</param>
        private void world_setDay(object sender, EventArgsCommand e)
        {
            if (e.Command.CalledArgs.Length > 0)
            {
                string dayStr = e.Command.CalledArgs[0];

                if (dayStr.IsInt())
                {
                    int day = dayStr.ToInt();
                    if (day <= 28 && day > 0)
                        Game1.dayOfMonth = day;
                    else
                        this.Monitor.Log("<value> must be between 1 and 28", LogLevel.Error);
                }
                else
                    this.LogValueNotInt32();
            }
            else
                this.LogValueNotSpecified();
        }

        /// <summary>The event raised when the 'world_setSeason' command is triggered.</summary>
        /// <param name="sender">The event sender.</param>
        /// <param name="e">The event arguments.</param>
        private void HandleWorldSetSeason(object sender, EventArgsCommand e)
        {
            if (e.Command.CalledArgs.Length > 0)
            {
                string season = e.Command.CalledArgs[0];
                string[] validSeasons = { "winter", "spring", "summer", "fall" };
                if (validSeasons.Contains(season))
                    Game1.currentSeason = season;
                else
                    this.LogValueInvalid();
            }
            else
                this.LogValueNotSpecified();
        }

        /// <summary>The event raised when the 'player_setHealth' command is triggered.</summary>
        /// <param name="sender">The event sender.</param>
        /// <param name="e">The event arguments.</param>
        private void HandlePlayerSetHealth(object sender, EventArgsCommand e)
        {
            if (e.Command.CalledArgs.Length > 0)
            {
                string amountStr = e.Command.CalledArgs[0];

                if (amountStr == "inf")
                    this.InfiniteHealth = true;
                else
                {
                    this.InfiniteHealth = false;
                    if (amountStr.IsInt())
                        Game1.player.health = amountStr.ToInt();
                    else
                        this.LogValueNotInt32();
                }
            }
            else
                this.LogValueNotSpecified();
        }

        /// <summary>The event raised when the 'player_setMaxHealth' command is triggered.</summary>
        /// <param name="sender">The event sender.</param>
        /// <param name="e">The event arguments.</param>
        private void HandlePlayerSetMaxHealth(object sender, EventArgsCommand e)
        {
            if (e.Command.CalledArgs.Length > 0)
            {
                string amountStr = e.Command.CalledArgs[0];
                if (amountStr.IsInt())
                    Game1.player.maxHealth = amountStr.ToInt();
                else
                    this.LogValueNotInt32();
            }
            else
                this.LogValueNotSpecified();
        }

        /// <summary>The event raised when the 'player_setImmunity' command is triggered.</summary>
        /// <param name="sender">The event sender.</param>
        /// <param name="e">The event arguments.</param>
        private void HandlePlayerSetImmunity(object sender, EventArgsCommand e)
        {
            if (e.Command.CalledArgs.Length > 0)
            {
                string amountStr = e.Command.CalledArgs[0];
                if (amountStr.IsInt())
                    Game1.player.immunity = amountStr.ToInt();
                else
                    this.LogValueNotInt32();
            }
            else
                this.LogValueNotSpecified();
        }

        /// <summary>The event raised when the 'player_addItem' command is triggered.</summary>
        /// <param name="sender">The event sender.</param>
        /// <param name="e">The event arguments.</param>
        private void HandlePlayerAddItem(object sender, EventArgsCommand e)
        {
            if (e.Command.CalledArgs.Length > 0)
            {
                string itemIdStr = e.Command.CalledArgs[0];
                if (itemIdStr.IsInt())
                {
                    int itemID = itemIdStr.ToInt();
                    int count = 1;
                    int quality = 0;
                    if (e.Command.CalledArgs.Length > 1)
                    {
                        if (e.Command.CalledArgs[1].IsInt())
                            count = e.Command.CalledArgs[1].ToInt();
                        else
                        {
                            this.Monitor.Log("[count] is invalid", LogLevel.Error);
                            return;
                        }

                        if (e.Command.CalledArgs.Length > 2)
                        {
                            if (e.Command.CalledArgs[2].IsInt())
                                quality = e.Command.CalledArgs[2].ToInt();
                            else
                            {
                                this.Monitor.Log("[quality] is invalid", LogLevel.Error);
                                return;
                            }
                        }
                    }

                    var item = new Object(itemID, count) { quality = quality };

                    Game1.player.addItemByMenuIfNecessary(item);
                }
                else
                    this.Monitor.Log("<item> is invalid", LogLevel.Error);
            }
            else
                this.LogObjectValueNotSpecified();
        }

        /// <summary>The event raised when the 'player_addMelee' command is triggered.</summary>
        /// <param name="sender">The event sender.</param>
        /// <param name="e">The event arguments.</param>
        private void HandlePlayerAddMelee(object sender, EventArgsCommand e)
        {
            if (e.Command.CalledArgs.Length > 0)
            {
                if (e.Command.CalledArgs[0].IsInt())
                {
                    MeleeWeapon weapon = new MeleeWeapon(e.Command.CalledArgs[0].ToInt());
                    Game1.player.addItemByMenuIfNecessary(weapon);
                    this.Monitor.Log($"Gave {weapon.Name} to {Game1.player.Name}", LogLevel.Info);
                }
                else
                    this.Monitor.Log("<item> is invalid", LogLevel.Error);
            }
            else
                this.LogObjectValueNotSpecified();
        }

        /// <summary>The event raised when the 'player_addRing' command is triggered.</summary>
        /// <param name="sender">The event sender.</param>
        /// <param name="e">The event arguments.</param>
        private void HandlePlayerAddRing(object sender, EventArgsCommand e)
        {
            if (e.Command.CalledArgs.Length > 0)
            {
                if (e.Command.CalledArgs[0].IsInt())
                {
                    Ring ring = new Ring(e.Command.CalledArgs[0].ToInt());
                    Game1.player.addItemByMenuIfNecessary(ring);
                    this.Monitor.Log($"Gave {ring.Name} to {Game1.player.Name}", LogLevel.Info);
                }
                else
                    this.Monitor.Log("<item> is invalid", LogLevel.Error);
            }
            else
                this.LogObjectValueNotSpecified();
        }

        /// <summary>The event raised when the 'list_items' command is triggered.</summary>
        /// <param name="sender">The event sender.</param>
        /// <param name="e">The event arguments.</param>
        private void HandleListItems(object sender, EventArgsCommand e)
        {
            var matches = this.GetItems(e.Command.CalledArgs).ToArray();

            // show matches
            string summary = "Searching...\n";
            if (matches.Any())
                this.Monitor.Log(summary + this.GetTableString(matches, new[] { "type", "id", "name" }, val => new[] { val.Type.ToString(), val.ID.ToString(), val.Name }), LogLevel.Info);
            else
                this.Monitor.Log(summary + "No items found", LogLevel.Info);
        }

        /// <summary>The event raised when the 'world_downMineLevel' command is triggered.</summary>
        /// <param name="sender">The event sender.</param>
        /// <param name="e">The event arguments.</param>
        private void HandleWorldDownMineLevel(object sender, EventArgsCommand e)
        {
            Game1.nextMineLevel();
        }

        /// <summary>The event raised when the 'world_setMineLevel' command is triggered.</summary>
        /// <param name="sender">The event sender.</param>
        /// <param name="e">The event arguments.</param>
        private void HandleWorldSetMineLevel(object sender, EventArgsCommand e)
        {
            if (e.Command.CalledArgs.Length > 0)
            {
                if (e.Command.CalledArgs[0].IsInt())
                    Game1.enterMine(true, e.Command.CalledArgs[0].ToInt(), "");
                else
                    this.LogValueNotInt32();
            }
            else
                this.LogValueNotSpecified();
        }

        /// <summary>The event raised when the 'show_game_files' command is triggered.</summary>
        /// <param name="sender">The event sender.</param>
        /// <param name="e">The event arguments.</param>
        private void HandleShowGameFiles(object sender, EventArgsCommand e)
        {
            Process.Start(Constants.ExecutionPath);
        }

        /// <summary>The event raised when the 'show_data_files' command is triggered.</summary>
        /// <param name="sender">The event sender.</param>
        /// <param name="e">The event arguments.</param>
        private void HandleShowDataFiles(object sender, EventArgsCommand e)
        {
            Process.Start(Constants.DataPath);
        }

        /****
        ** Helpers
        ****/
        /// <summary>Get all items which can be searched and added to the player's inventory through the console.</summary>
        /// <param name="searchWords">The search string to find.</param>
        private IEnumerable<ISearchItem> GetItems(string[] searchWords)
        {
            // normalise search term
            searchWords = searchWords?.Where(word => !string.IsNullOrWhiteSpace(word)).ToArray();
            if (searchWords?.Any() == false)
                searchWords = null;

            // find matches
            return (
                from item in this.GetItems()
                let term = $"{item.ID}|{item.Type}|{item.Name}"
                where searchWords == null || searchWords.All(word => term.IndexOf(word, StringComparison.CurrentCultureIgnoreCase) != -1)
                select item
            );
        }

        /// <summary>Get all items which can be searched and added to the player's inventory through the console.</summary>
        private IEnumerable<ISearchItem> GetItems()
        {
            // objects
            foreach (int id in Game1.objectInformation.Keys)
            {
                ISearchItem obj = id >= Ring.ringLowerIndexRange && id <= Ring.ringUpperIndexRange
                    ? new SearchableRing(id)
                    : (ISearchItem)new SearchableObject(id);
                if (obj.IsValid)
                    yield return obj;
            }

            // weapons
            foreach (int id in Game1.content.Load<Dictionary<int, string>>("Data\\weapons").Keys)
            {
                ISearchItem weapon = new SearchableWeapon(id);
                if (weapon.IsValid)
                    yield return weapon;
            }
        }

        /// <summary>Get an ASCII table for a set of tabular data.</summary>
        /// <typeparam name="T">The data type.</typeparam>
        /// <param name="data">The data to display.</param>
        /// <param name="header">The table header.</param>
        /// <param name="getRow">Returns a set of fields for a data value.</param>
        private string GetTableString<T>(IEnumerable<T> data, string[] header, Func<T, string[]> getRow)
        {
            // get table data
            int[] widths = header.Select(p => p.Length).ToArray();
            string[][] rows = data
                .Select(item =>
                {
                    string[] fields = getRow(item);
                    if (fields.Length != widths.Length)
                        throw new InvalidOperationException($"Expected {widths.Length} columns, but found {fields.Length}: {string.Join(", ", fields)}");

                    for (int i = 0; i < fields.Length; i++)
                        widths[i] = Math.Max(widths[i], fields[i].Length);

                    return fields;
                })
                .ToArray();

            // render fields
            List<string[]> lines = new List<string[]>(rows.Length + 2)
            {
                header,
                header.Select((value, i) => "".PadRight(widths[i], '-')).ToArray()
            };
            lines.AddRange(rows);

            return string.Join(
                Environment.NewLine,
                lines.Select(line => string.Join(" | ",
                    line.Select((field, i) => field.PadRight(widths[i], ' ')).ToArray())
                )
            );
        }

        /****
        ** Logging
        ****/
        /// <summary>Log an error indicating a value must be specified.</summary>
        public void LogValueNotSpecified()
        {
            this.Monitor.Log("<value> must be specified", LogLevel.Error);
        }

        /// <summary>Log an error indicating a target and value must be specified.</summary>
        public void LogObjectValueNotSpecified()
        {
            this.Monitor.Log("<object> and <value> must be specified", LogLevel.Error);
        }

        /// <summary>Log an error indicating a value is invalid.</summary>
        public void LogValueInvalid()
        {
            this.Monitor.Log("<value> is invalid", LogLevel.Error);
        }

        /// <summary>Log an error indicating a target is invalid.</summary>
        public void LogObjectInvalid()
        {
            this.Monitor.Log("<object> is invalid", LogLevel.Error);
        }

        /// <summary>Log an error indicating a value must be an integer.</summary>
        public void LogValueNotInt32()
        {
            this.Monitor.Log("<value> must be a whole number (Int32)", LogLevel.Error);
        }
    }
}