-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy pathCommandCost.cs
167 lines (166 loc) · 6.38 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
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
using Rocket.API;
using Rocket.Core.Logging;
using Rocket.Unturned.Chat;
using Rocket.Unturned.Player;
using SDG.Unturned;
using System;
using System.Collections.Generic;
using fr34kyn01535.Uconomy;
namespace LIGHT
{
public class CommandCost : IRocketCommand
{
public AllowedCaller AllowedCaller
{
get
{
return AllowedCaller.Player;
}
}
public string Name
{
get
{
return "cost";
}
}
public string Help
{
get
{
return "Tells you the cost of a selected item.";
}
}
public string Syntax
{
get
{
return "[v.]<name or id>";
}
}
public List<string> Aliases
{
get { return new List<string>(); }
}
public List<string> Permissions
{
get
{
return new List<string>() { "cost" };
}
}
public void Execute(IRocketPlayer caller, params string[] command)
{
if (!LIGHT.Instance.Configuration.Instance.EnableShop)
{
UnturnedChat.Say(caller, LIGHT.Instance.Translate("shop_disable"));
return;
}
UnturnedPlayer player = (UnturnedPlayer)caller;
string message;
if (command.Length == 0)
{
UnturnedChat.Say(player, LIGHT.Instance.Translate("cost_command_usage"));
return;
}
if (command.Length == 2 && command[0] != "v")
{
UnturnedChat.Say(player, LIGHT.Instance.Translate("cost_command_usage"));
return;
}
ushort id;
switch (command[0])
{
case "v":
string name = null;
if (!ushort.TryParse(command[1], out id))
{
Asset[] array = Assets.find(EAssetType.VEHICLE);
Asset[] array2 = array;
for (int i = 0; i < array2.Length; i++)
{
VehicleAsset vAsset = (VehicleAsset)array2[i];
if (vAsset != null && vAsset.Name != null && vAsset.Name.ToLower().Contains(command[1].ToLower()))
{
id = vAsset.Id;
name = vAsset.Name;
break;
}
}
}
if (name == null && id == 0)
{
UnturnedChat.Say(player, LIGHT.Instance.Translate("could_not_find",command[1]));
return;
}
else if (name == null && id != 0)
{
try
{
name = ((VehicleAsset)Assets.find(EAssetType.VEHICLE, id)).Name;
}
catch
{
UnturnedChat.Say(player, LIGHT.Instance.Translate("could_not_find", command[1]));
return;
}
}
decimal cost = LIGHT.Instance.ShopDB.GetVehicleCost(id);
message = LIGHT.Instance.Translate("vehicle_cost_msg", new object[] { name, cost.ToString(), Uconomy.Instance.Configuration.Instance.MoneyName });
if (cost <= 0m)
{
message = LIGHT.Instance.Translate("error_getting_cost", new object[] { name });
}
UnturnedChat.Say(player, message);
break;
default:
name = null;
if (!ushort.TryParse(command[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.Name != null && iAsset.Name.ToLower().Contains(command[0].ToLower()))
{
id = iAsset.Id;
name = iAsset.Name;
break;
}
}
}
if (name == null && id == 0)
{
UnturnedChat.Say(player, LIGHT.Instance.Translate("could_not_find",command[0]));
return;
}
else if (name == null && id != 0)
{
try
{
name = ((ItemAsset)Assets.find(EAssetType.ITEM, id)).Name;
}
catch
{
UnturnedChat.Say(player, LIGHT.Instance.Translate("could_not_find", command[0]));
return;
}
}
cost = LIGHT.Instance.ShopDB.GetItemCost(id);
decimal bbp = LIGHT.Instance.ShopDB.GetItemBuyPrice(id);
if (LIGHT.Instance.Configuration.Instance.SaleEnable)
{
decimal saleprice = Convert.ToDecimal(Convert.ToDouble(LIGHT.Instance.Configuration.Instance.SalePercentage) / 100.00);
if (LIGHT.Instance.sale.salesStart == true)
cost = (cost * (Convert.ToDecimal(1.00) - saleprice));
}
message = LIGHT.Instance.Translate("item_cost_msg", new object[] { name, cost.ToString(), Uconomy.Instance.Configuration.Instance.MoneyName, bbp.ToString(), Uconomy.Instance.Configuration.Instance.MoneyName });
if (cost <= 0m)
message = LIGHT.Instance.Translate("error_getting_cost", new object[] { name });
UnturnedChat.Say(player, message);
break;
}
}
}
}