-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
048531c
commit 7252791
Showing
18 changed files
with
655 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
|
||
Microsoft Visual Studio Solution File, Format Version 12.00 | ||
# Visual Studio 15 | ||
VisualStudioVersion = 15.0.26730.16 | ||
MinimumVisualStudioVersion = 10.0.40219.1 | ||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ItemCurrency", "ItemCurrency\ItemCurrency.csproj", "{2FD6A38A-F464-4653-BEFF-850F1EE80079}" | ||
EndProject | ||
Global | ||
GlobalSection(SolutionConfigurationPlatforms) = preSolution | ||
Debug|Any CPU = Debug|Any CPU | ||
Release|Any CPU = Release|Any CPU | ||
EndGlobalSection | ||
GlobalSection(ProjectConfigurationPlatforms) = postSolution | ||
{2FD6A38A-F464-4653-BEFF-850F1EE80079}.Debug|Any CPU.ActiveCfg = Debug|Any CPU | ||
{2FD6A38A-F464-4653-BEFF-850F1EE80079}.Debug|Any CPU.Build.0 = Debug|Any CPU | ||
{2FD6A38A-F464-4653-BEFF-850F1EE80079}.Release|Any CPU.ActiveCfg = Release|Any CPU | ||
{2FD6A38A-F464-4653-BEFF-850F1EE80079}.Release|Any CPU.Build.0 = Release|Any CPU | ||
EndGlobalSection | ||
GlobalSection(SolutionProperties) = preSolution | ||
HideSolutionNode = FALSE | ||
EndGlobalSection | ||
GlobalSection(ExtensibilityGlobals) = postSolution | ||
SolutionGuid = {5CE73152-2C67-4977-A6C0-D179D50FFEAB} | ||
EndGlobalSection | ||
EndGlobal |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
using ExtraConcentratedJuice.ItemCurrency.Entities; | ||
using Rocket.API; | ||
using Rocket.Unturned.Chat; | ||
using Rocket.Unturned.Player; | ||
using SDG.Unturned; | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Text; | ||
using UnityEngine; | ||
|
||
namespace ExtraConcentratedJuice.ItemCurrency.Commands | ||
{ | ||
public class CommandBalance : IRocketCommand | ||
{ | ||
#region Properties | ||
public AllowedCaller AllowedCaller => AllowedCaller.Player; | ||
|
||
public string Name => "balance"; | ||
|
||
public string Help => "Gets your inventory's total worth."; | ||
|
||
public string Syntax => "/balance"; | ||
|
||
public List<string> Aliases => new List<string> { "bal" }; | ||
|
||
public List<string> Permissions => new List<string> { "itemcurrency.buy" }; | ||
#endregion | ||
|
||
public void Execute(IRocketPlayer caller, string[] args) | ||
{ | ||
UnturnedPlayer player = (UnturnedPlayer)caller; | ||
UnturnedChat.Say(caller, Util.Translate("inventory_value", Util.FindMoney(player.Inventory).Sum(x => x.Value), Util.Config().CurrencySymbol)); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,112 @@ | ||
using ExtraConcentratedJuice.ItemCurrency.Entities; | ||
using Rocket.API; | ||
using Rocket.Unturned.Chat; | ||
using Rocket.Unturned.Player; | ||
using SDG.Unturned; | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Text; | ||
using UnityEngine; | ||
|
||
namespace ExtraConcentratedJuice.ItemCurrency.Commands | ||
{ | ||
public class CommandBuy : IRocketCommand | ||
{ | ||
#region Properties | ||
public AllowedCaller AllowedCaller => AllowedCaller.Player; | ||
|
||
public string Name => "buy"; | ||
|
||
public string Help => "Buys an item from the shop."; | ||
|
||
public string Syntax => "/buy <item> <amt>"; | ||
|
||
public List<string> Aliases => new List<string> { "purchase" }; | ||
|
||
public List<string> Permissions => new List<string> { "itemcurrency.buy" }; | ||
#endregion | ||
|
||
public void Execute(IRocketPlayer caller, string[] args) | ||
{ | ||
if (args.Length < 1) | ||
{ | ||
UnturnedChat.Say(caller, Syntax, Color.red); | ||
return; | ||
} | ||
|
||
int amt = 1; | ||
|
||
if (!ushort.TryParse(args[0], out ushort id)) | ||
{ | ||
var items = new List<ItemAsset>(Assets.find(EAssetType.ITEM).Cast<ItemAsset>()); | ||
var a = items.Where(x => x.itemName != null) | ||
.OrderBy(x => x.itemName.Length) | ||
.FirstOrDefault(x => x.itemName.IndexOf(args[0], StringComparison.OrdinalIgnoreCase) >= 0); | ||
|
||
if (a == null) | ||
{ | ||
UnturnedChat.Say(caller, Util.Translate("item_not_found"), Color.red); | ||
return; | ||
} | ||
|
||
id = a.id; | ||
} | ||
|
||
if (args.Length > 1 && !int.TryParse(args[1], out amt)) | ||
{ | ||
UnturnedChat.Say(caller, Syntax, Color.red); | ||
return; | ||
} | ||
|
||
var item = Util.Config().Prices.Where(x => x.BuyPrice > 0).FirstOrDefault(x => x.Id == id); | ||
|
||
if (item == null) | ||
{ | ||
UnturnedChat.Say(caller, Util.Translate("not_for_buy"), Color.red); | ||
return; | ||
} | ||
|
||
UnturnedPlayer player = (UnturnedPlayer)caller; | ||
ItemAsset asset = (ItemAsset)Assets.find(EAssetType.ITEM, (ushort)id); | ||
|
||
var money = Util.FindMoney(player.Inventory); | ||
var cost = new List<MoneyValue>(); | ||
|
||
decimal price = item.BuyPrice * amt; | ||
|
||
if (price > money.Sum(x => x.Value)) | ||
{ | ||
UnturnedChat.Say(caller, Util.Translate("cannot_afford", amt), Color.red); | ||
return; | ||
} | ||
|
||
foreach (MoneyValue i in money) | ||
{ | ||
cost.Add(i); | ||
|
||
if (cost.Sum(x => x.Value) >= price) | ||
break; | ||
} | ||
|
||
foreach (MoneyValue i in cost) | ||
Util.RemoveFromInventory(player.Inventory, i.Id); | ||
|
||
decimal change = cost.Sum(x => x.Value) - price; | ||
|
||
foreach (var x in Util.Config().Money.OrderByDescending(x => x.Value)) | ||
{ | ||
int count = (int)(change / x.Value); | ||
change -= count * x.Value; | ||
|
||
for (int i = 0; i < count; i++) | ||
player.Inventory.forceAddItem(new Item(x.Id, true), true); | ||
} | ||
|
||
for (int i = 0; i < amt; i++) | ||
player.Inventory.forceAddItem(new Item(item.Id, true), true); | ||
|
||
UnturnedChat.Say(caller, Util.Translate("purchase_success", amt, asset.itemName, Util.Config().CurrencySymbol, price)); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,98 @@ | ||
using ExtraConcentratedJuice.ItemCurrency.Entities; | ||
using Rocket.API; | ||
using Rocket.Unturned.Chat; | ||
using Rocket.Unturned.Player; | ||
using SDG.Unturned; | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Text; | ||
using UnityEngine; | ||
|
||
namespace ExtraConcentratedJuice.ItemCurrency.Commands | ||
{ | ||
public class CommandSell : IRocketCommand | ||
{ | ||
#region Properties | ||
public AllowedCaller AllowedCaller => AllowedCaller.Player; | ||
|
||
public string Name => "sell"; | ||
|
||
public string Help => "Allows you to sell some items."; | ||
|
||
public string Syntax => "/sell <item> <amt>"; | ||
|
||
public List<string> Aliases => new List<string>(); | ||
|
||
public List<string> Permissions => new List<string> { "itemcurrency.sell" }; | ||
#endregion | ||
|
||
public void Execute(IRocketPlayer caller, string[] args) | ||
{ | ||
if (args.Length < 1) | ||
{ | ||
UnturnedChat.Say(caller, Syntax, Color.red); | ||
return; | ||
} | ||
|
||
int amt = 1; | ||
|
||
if (!ushort.TryParse(args[0], out ushort id)) | ||
{ | ||
var items = new List<ItemAsset>(Assets.find(EAssetType.ITEM).Cast<ItemAsset>()); | ||
var a = items.Where(x => x.itemName != null) | ||
.OrderBy(x => x.itemName.Length) | ||
.FirstOrDefault(x => x.itemName.IndexOf(args[0], StringComparison.OrdinalIgnoreCase) >= 0); | ||
|
||
if (a == null) | ||
{ | ||
UnturnedChat.Say(caller, Util.Translate("item_not_found"), Color.red); | ||
return; | ||
} | ||
|
||
id = a.id; | ||
} | ||
|
||
if (args.Length > 1 && !int.TryParse(args[1], out amt)) | ||
{ | ||
UnturnedChat.Say(caller, Syntax, Color.red); | ||
return; | ||
} | ||
|
||
var item = Util.Config().Prices.Where(x => x.SellPrice > 0).FirstOrDefault(x => x.Id == id); | ||
|
||
if (item == null) | ||
{ | ||
UnturnedChat.Say(caller, Util.Translate("not_for_sell"), Color.red); | ||
return; | ||
} | ||
|
||
UnturnedPlayer player = (UnturnedPlayer)caller; | ||
ItemAsset asset = (ItemAsset)Assets.find(EAssetType.ITEM, (ushort)id); | ||
|
||
int count = Util.CountItems(player.Inventory, item.Id); | ||
|
||
if (count < amt) | ||
{ | ||
UnturnedChat.Say(caller, Util.Translate("not_enough_items"), Color.red); | ||
return; | ||
} | ||
|
||
for (int i = 0; i < amt; i++) | ||
Util.RemoveFromInventory(player.Inventory, item.Id); | ||
|
||
decimal price = item.SellPrice * amt; | ||
|
||
foreach (var x in Util.Config().Money.OrderByDescending(x => x.Value)) | ||
{ | ||
int c = (int)(price / x.Value); | ||
price -= c * x.Value; | ||
|
||
for (int i = 0; i < c; i++) | ||
player.Inventory.forceAddItem(new Item(x.Id, true), true); | ||
} | ||
|
||
UnturnedChat.Say(caller, Util.Translate("sell_success", amt, asset.itemName, Util.Config().CurrencySymbol, price)); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
using ExtraConcentratedJuice.ItemCurrency.Entities; | ||
using Rocket.API; | ||
using Rocket.Unturned.Chat; | ||
using Rocket.Unturned.Player; | ||
using SDG.Unturned; | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Text; | ||
using UnityEngine; | ||
|
||
namespace ExtraConcentratedJuice.ItemCurrency.Commands | ||
{ | ||
public class CommandValue : IRocketCommand | ||
{ | ||
#region Properties | ||
public AllowedCaller AllowedCaller => AllowedCaller.Player; | ||
|
||
public string Name => "value"; | ||
|
||
public string Help => "Tells you the monetary value of a certain item."; | ||
|
||
public string Syntax => "/value <item>"; | ||
|
||
public List<string> Aliases => new List<string>(); | ||
|
||
public List<string> Permissions => new List<string> { "itemcurrency.value" }; | ||
#endregion | ||
|
||
public void Execute(IRocketPlayer caller, string[] args) | ||
{ | ||
if (args.Length < 1) | ||
{ | ||
UnturnedChat.Say(caller, Syntax, Color.red); | ||
return; | ||
} | ||
|
||
if (!ushort.TryParse(args[0], out ushort id)) | ||
{ | ||
var items = new List<ItemAsset>(Assets.find(EAssetType.ITEM).Cast<ItemAsset>()); | ||
var a = items.Where(x => x.itemName != null) | ||
.OrderBy(x => x.itemName.Length) | ||
.FirstOrDefault(x => x.itemName.IndexOf(args[0], StringComparison.OrdinalIgnoreCase) >= 0); | ||
|
||
if (a == null) | ||
{ | ||
UnturnedChat.Say(caller, Util.Translate("item_not_found"), Color.red); | ||
return; | ||
} | ||
|
||
id = a.id; | ||
} | ||
|
||
var moneyItem = Util.Config().Money.FirstOrDefault(x => x.Id == id); | ||
ItemAsset asset = (ItemAsset)Assets.find(EAssetType.ITEM, id); | ||
|
||
if (moneyItem == null) | ||
{ | ||
UnturnedChat.Say(caller, Util.Translate("no_value", asset.itemName)); | ||
return; | ||
} | ||
|
||
UnturnedChat.Say(caller, Util.Translate("value", asset.itemName, Util.Config().CurrencySymbol, moneyItem.Value)); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Text; | ||
using System.Xml.Serialization; | ||
|
||
namespace ExtraConcentratedJuice.ItemCurrency.Entities | ||
{ | ||
public class ItemPrice | ||
{ | ||
[XmlAttribute] | ||
public ushort Id { get; set; } | ||
[XmlAttribute] | ||
public string Name { get; set; } | ||
[XmlAttribute] | ||
public decimal BuyPrice { get; set; } | ||
[XmlAttribute] | ||
public decimal SellPrice { get; set; } | ||
|
||
public ItemPrice() { } | ||
public ItemPrice(ushort id, string name, decimal buyPrice, decimal sellPrice) | ||
{ | ||
Id = id; | ||
Name = name; | ||
BuyPrice = buyPrice; | ||
SellPrice = sellPrice; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Text; | ||
using System.Xml.Serialization; | ||
|
||
namespace ExtraConcentratedJuice.ItemCurrency.Entities | ||
{ | ||
public class MoneyValue | ||
{ | ||
[XmlAttribute] | ||
public ushort Id { get; set; } | ||
[XmlAttribute] | ||
public decimal Value { get; set; } | ||
|
||
public MoneyValue() {} | ||
|
||
public MoneyValue(ushort id, decimal value) | ||
{ | ||
Id = id; | ||
Value = value; | ||
} | ||
} | ||
} |
Oops, something went wrong.