forked from Zamirathe/ZaupShop
-
Notifications
You must be signed in to change notification settings - Fork 18
/
Copy pathCommandCost.cs
131 lines (119 loc) · 5.24 KB
/
CommandCost.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
122
123
124
125
126
127
128
129
130
131
using System;
using System.Globalization;
using Rocket.API.Commands;
using Rocket.API.Economy;
using Rocket.API.Plugins;
using Rocket.Core.I18N;
using Rocket.Core.User;
using SDG.Unturned;
namespace ZaupShop
{
public class CommandCost : ICommand
{
private readonly IEconomyProvider _economy;
private readonly ZaupShop _parentPlugin;
public CommandCost(IPlugin plugin, IEconomyProvider economy)
{
_economy = economy;
_parentPlugin = (ZaupShop) plugin;
}
public string Name => "cost";
public string Summary => "Tells you the cost of a selected item.";
public string Description => null;
public string Syntax => "[v] <name or id>";
public IChildCommand[] ChildCommands => null;
public string[] Aliases => null;
public string Permission => null;
public bool SupportsUser(Type user)
{
return true;
}
public void Execute(ICommandContext context)
{
var user = context.User;
var parameters = context.Parameters;
string message;
if (parameters.Length == 0 || parameters.Length == 1 && (parameters[0].Trim() == string.Empty || parameters[0].Trim() == "v"))
{
// We are going to print how to use
context.User.SendLocalizedMessage(_parentPlugin.Translations, "cost_command_usage");
return;
}
if (parameters.Length == 2 && (parameters[0] != "v" || parameters[1].Trim() == string.Empty))
{
context.User.SendLocalizedMessage(_parentPlugin.Translations, "cost_command_usage");
return;
}
ushort id;
switch (parameters[0])
{
case "v":
string name = null;
if (!ushort.TryParse(parameters[1], out id))
{
foreach (VehicleAsset vAsset in Assets.find(EAssetType.VEHICLE))
{
if (vAsset != null && vAsset.vehicleName != null && vAsset.vehicleName.ToLower().Contains(parameters[1].ToLower()))
{
id = vAsset.id;
name = vAsset.vehicleName;
break;
}
}
}
if (Assets.find(EAssetType.VEHICLE, id) == null)
{
context.User.SendLocalizedMessage(_parentPlugin.Translations, "could_not_find", parameters[1]);
return;
}
else if (name == null && id != 0)
{
name = ((VehicleAsset)Assets.find(EAssetType.VEHICLE, id)).vehicleName;
}
decimal cost = _parentPlugin.Database.GetVehicleCost(id);
message = _parentPlugin.Translations.Get("vehicle_cost_msg", name, cost.ToString(CultureInfo.CurrentCulture), _economy.DefaultCurrency.Name);
if (cost <= 0m)
{
message = _parentPlugin.Translations.Get("error_getting_cost", name);
}
context.User.SendMessage(message);
break;
default:
name = null;
if (!ushort.TryParse(parameters[0], out id))
{
Asset[] array = Assets.find(EAssetType.ITEM);
Asset[] array2 = array;
for (int i = 0; i < array2.Length; i++)
{
ItemAsset iAsset = (ItemAsset)array2[i];
if (iAsset != null && iAsset.itemName != null && iAsset.itemName.ToLower().Contains(parameters[0].ToLower()))
{
id = iAsset.id;
name = iAsset.itemName;
break;
}
}
}
if (Assets.find(EAssetType.ITEM, id) == null)
{
context.User.SendLocalizedMessage(_parentPlugin.Translations, "could_not_find", parameters[0]);
return;
}
else if (name == null && id != 0)
{
name = ((ItemAsset)Assets.find(EAssetType.ITEM, id)).itemName;
}
cost = _parentPlugin.Database.GetItemCost(id);
decimal bbp = _parentPlugin.Database.GetItemBuyPrice(id);
message = _parentPlugin.Translations.Get("item_cost_msg", name, cost.ToString(CultureInfo.CurrentCulture), _economy.DefaultCurrency.Name, bbp.ToString(CultureInfo.CurrentCulture), _economy.DefaultCurrency.Name);
if (cost <= 0m)
{
message = _parentPlugin.Translations.Get("error_getting_cost", name);
}
context.User.SendMessage(message);
break;
}
}
}
}