-
Notifications
You must be signed in to change notification settings - Fork 0
/
CheeseTravel.cs
121 lines (111 loc) · 4.02 KB
/
CheeseTravel.cs
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
using Terraria;
using Terraria.ID;
using TerrariaApi.Server;
using TShockAPI;
/// <summary>
/// Plugin that allows cheesing the Traveling Merchant's RNG.
///
/// <para>Defines the following commands:</para>
///
/// <list type="table">
/// <item>
/// <term><c>/resettravel</c></term>
/// <description>Re-randomizes the Traveling Merchant's inventory, if present.</description>
/// </item>
/// <item>
/// <term><c>/spawntravel</c></term>
/// <description>Spawns the Traveling Merchant, if not already present.</description>
/// </item>
/// </list>
///
/// <para>Uses the following permissions:</para>
///
/// <list type="table">
/// <item>
/// <term><c>bcat.cheesetravel.reset</c></term>
/// <description>Use the <c>/resettravel</c> command.</description>
/// </item>
/// <item>
/// <term><c>bcat.cheesetravel.spawn</c></term>
/// <description>Use the <c>/spawntravel</c> command.</description>
/// </item>
/// </list>
/// </summary>
namespace Bcat.TShockPlugins
{
[ApiVersion(2, 1)]
public class CheeseTravel : TerrariaPlugin
{
/// <summary>
/// TShock permission to use the <c>/resettravel</c> command.
/// </summary>
private const string PERMISSION_RESET = "bcat.cheesetravel.reset";
/// <summary>
/// TShock permission to use the <c>/spawntravel</c> command.
/// </summary>
private const string PERMISSION_SPAWN = "bcat.cheesetravel.spawn";
public override string Name => "CheeseTravel";
public override Version Version => new(1, 0);
public override string Author => "Jonathan Rascher";
public override string Description
=> "Plugin that allows cheesing the Traveling Merchant's RNG.";
public CheeseTravel(Main game) : base(game) { }
public override void Initialize()
{
Commands.ChatCommands.Add(new Command(PERMISSION_RESET, OnResetTravel, "resettravel")
{
HelpText = "Re-randomizes the Traveling Merchant's inventory, if present.",
});
Commands.ChatCommands.Add(new Command(PERMISSION_SPAWN, OnSpawnTravel, "spawntravel")
{
HelpText = "Spawns the Traveling Merchant, if not already present.",
}); ;
}
/// <summary>
/// Re-randomizes the Traveling Merchant's inventory, if present.
/// </summary>
///
/// <param name="e">arguments passed to the command.</param>
private static void OnResetTravel(CommandArgs e)
{
if (!HasTravelNpc())
{
e.Player.SendErrorMessage(
$"Traveling Merchant not present. Try {Commands.Specifier}spawntravel.");
return;
}
Chest.SetupTravelShop();
NetMessage.SendTravelShop(-1);
e.Player.SendSuccessMessage("Reset the Traveling Merchant's inventory.");
}
/// <summary>
/// Spawns the Traveling Merchant, if not already present.
/// </summary>
///
/// <param name="e">arguments passed to the command.</param>
private static void OnSpawnTravel(CommandArgs e)
{
if (HasTravelNpc())
{
e.Player.SendErrorMessage(
$"Traveling Merchant already present. Try {Commands.Specifier}resettravel.");
return;
}
WorldGen.SpawnTravelNPC();
if (!HasTravelNpc())
{
e.Player.SendErrorMessage(
"Couldn't spawn Traveling Merchant. Ensure it's not night, an eclipse, or an invasion.");
}
}
/// <summary>
/// Determines if the Traveling Merchant is currently alive in the world.
/// </summary>
///
/// <returns>true if the Traveling Merchant is present, false otherwise.</returns>
private static bool HasTravelNpc()
{
return Main.npc.Any(n => n.active && n.type == NPCID.TravellingMerchant);
}
}
}