C#:
using Newtonsoft.Json;
using Newtonsoft.Json.Linq;
using Oxide.Core;
using Oxide.Core.Libraries;
using Oxide.Core.Plugins;
using Oxide.Game.Rust.Cui;
using System;
using System.Collections.Generic;
using System.Linq;
using UnityEngine;
namespace Oxide.Plugins
{
[Info("Autcion", "Anathar", "0.1.94")]
[Description("Аукцион")]
class Auction : RustPlugin
{
[PluginReference] Plugin ImageLibrary, Economics, ServerRewards;
System.Random random = new System.Random();
string matterial = "assets/content/ui/uibackgroundblur-ingamemenu.mat";
#region Data
private StoredData DataBase = new StoredData();
private LocalizationStored LocData = new LocalizationStored();
public class LocalizationStored
{
public Dictionary<string, string> TranslatedItems = new Dictionary<string, string>();
}
public class StoredData
{
public Dictionary<ulong, PlayerInfo> PlayerDatabase = new Dictionary<ulong, PlayerInfo>();
public List<AuctionLot> Lots = new List<AuctionLot>();
}
public class PlayerInfo
{
public int Balance { get; set; }
public List<ItemInv> Inventory { get; set; }
}
public class ItemInv
{
public int ItemId { get; set; }
public string ShortName { get; set; }
public int Ammount { get; set; }
public ulong Skin { get; set; }
}
public class AuctionLot
{
public int LotId { get; set; }
public ulong Owner { get; set; }
public int Hours { get; set; }
public ulong LastBitPlayer { get; set; }
public string ShortName { get; set; }
public DateTime Date { get; set; }
public int Count { get; set; }
public ulong skin { get; set; }
public int StartBit { get; set; }
public int LastBit { get; set; }
public int Bid { get; set; }
public int Buyout { get; set; }
}
private void SaveData() => Interface.Oxide.DataFileSystem.WriteObject(Name, DataBase);
private void LoadData()
{
try
{
DataBase = Interface.GetMod().DataFileSystem.ReadObject<StoredData>(Name);
}
catch (Exception e)
{
DataBase = new StoredData();
}
}
#endregion
#region Config
private static ConfigFile config;
public class ConfigFile
{
[JsonProperty(PropertyName = "Использовать баланс GameStore?")]
public bool UseGameStores { get; set; }
[JsonProperty(PropertyName = "Использовать баланс Economics?")]
public bool UseEconomics { get; set; }
[JsonProperty(PropertyName = "Разрешить открытие только в Building Зоне ?")]
public bool OnlyBuilding { get; set; }
[JsonProperty(PropertyName = "Использовать баланс ServerRewards?")]
public bool UseServerRwards { get; set; }
[JsonProperty(PropertyName = "GameStore Id Магазина")]
public string GSId { get; set; } = "";
[JsonProperty(PropertyName = "GameStore Api Ключ")]
public string GSApi { get; set; }
[JsonProperty(PropertyName = "Сколько предметов может добавить игрок ?")]
public int HowCanAddItems { get; set; }
[JsonProperty(PropertyName = "Сколько предметов может выставить на аукцион игрок?")]
public int HowCanAddLots { get; set; }
[JsonProperty(PropertyName = "На сколько будет выставлен лот ? (В часах)")]
public int HowHoursForLots { get; set; }
[JsonProperty(PropertyName = "Минимальная сумма для выставления лота")]
public int MinimumCostForAddLot { get; set; }
[JsonProperty(PropertyName = "Включить взятие процента за сделку ?")]
public bool TakePercent { get; set; }
[JsonProperty(PropertyName = "Процент за сделку")]
public int PercentForMoney { get; set; }
[JsonProperty(PropertyName = "Название валюты")]
public string TugrickName { get; set; }
}
protected override void SaveConfig() => Config.WriteObject(config);
protected override void LoadConfig()
{
base.LoadConfig();
try
{
config = Config.ReadObject<ConfigFile>();
if (config == null)
Regenerate();
}
catch
{
Regenerate();
}
}
private void Regenerate()
{
LoadDefaultConfig();
}
private ConfigFile GetDefaultSettings()
{
return new ConfigFile
{
UseGameStores = false,
UseEconomics = false,
UseServerRwards = false,
OnlyBuilding = true,
GSApi = "",
GSId = "",
HowCanAddItems = 4,
HowCanAddLots = 4,
HowHoursForLots = 12,
MinimumCostForAddLot = 1,
TakePercent = false,
PercentForMoney = 30,
TugrickName = "р"
};
}
protected override void LoadDefaultConfig()
{
PrintWarning("Attempting to create default config...");
Config.Clear();
Config.WriteObject(GetDefaultSettings(), true);
Config.Save();
}
#endregion
#region Hooks
private void OnServerInitialized()
{
GetLocData();
LoadData();
foreach (BasePlayer player in BasePlayer.activePlayerList)
CheckDb(player);
}
void Unload()
{
SaveData();
}
void OnServerSave()
{
List<AuctionLot> RemoveLots = new List<AuctionLot>();
foreach (AuctionLot GetLot in DataBase.Lots)
{
if (DateTime.Now.Subtract(GetLot.Date).TotalHours >= GetLot.Hours)
{
if (GetLot.LastBitPlayer == 0)
{
ItemInv data = new ItemInv()
{
ItemId = random.Next(1, 100000),
Ammount = GetLot.Count,
ShortName = GetLot.ShortName,
Skin = GetLot.skin
};
DataBase.PlayerDatabase[GetLot.Owner].Inventory.Add(data);
RemoveLots.Add(GetLot);
}
else
{
if (config.UseGameStores)
{
DataBase.PlayerDatabase[GetLot.Owner].Balance += GetLot.Bid;
float GetBid = GetLot.Buyout;
if (config.TakePercent) GetBid -= GetBid / 100 * config.PercentForMoney;
GiveGsMoney(GetLot.Owner, GetBid, (code, status) =>
{
if (code != 200 || status == "fail")
{
PrintError($"Ошибка api GameStores, причина:{status}");
return;
}
});
ItemInv data = new ItemInv()
{
ItemId = random.Next(1, 100000),
Ammount = GetLot.Count,
ShortName = GetLot.ShortName,
Skin = GetLot.skin
};
DataBase.PlayerDatabase[GetLot.LastBitPlayer].Inventory.Add(data);
RemoveLots.Add(GetLot);
}
if (config.UseEconomics)
{
DataBase.PlayerDatabase[GetLot.Owner].Balance += GetLot.Bid;
float GetBid = GetLot.Buyout;
if (config.TakePercent) GetBid -= GetBid / 100 * config.PercentForMoney;
GiveEconomycsMoney(GetLot.Owner, GetBid);
ItemInv data = new ItemInv()
{
ItemId = random.Next(1, 100000),
Ammount = GetLot.Count,
ShortName = GetLot.ShortName,
Skin = GetLot.skin
};
DataBase.PlayerDatabase[GetLot.LastBitPlayer].Inventory.Add(data);
RemoveLots.Add(GetLot);
}
if (config.UseServerRwards)
{
DataBase.PlayerDatabase[GetLot.Owner].Balance += GetLot.Bid;
float GetBid = GetLot.Buyout;
if (config.TakePercent) GetBid -= GetBid / 100 * config.PercentForMoney;
GiveServerRewardMoney(GetLot.Owner, GetBid);
ItemInv data = new ItemInv()
{
ItemId = random.Next(1, 100000),
Ammount = GetLot.Count,
ShortName = GetLot.ShortName,
Skin = GetLot.skin
};
DataBase.PlayerDatabase[GetLot.LastBitPlayer].Inventory.Add(data);
RemoveLots.Add(GetLot);
}
}
}
}
if (RemoveLots.Count != 0)
{
foreach (AuctionLot GetRemoveLots in RemoveLots)
{
DataBase.Lots.Remove(GetRemoveLots);
}
}
}
void GetLocData()
{
if (Interface.GetMod().DataFileSystem.ReadObject<LocalizationStored>("Auction/Loc").TranslatedItems.Count == 0)
{
PrintWarning("Загружена локализация");
webrequest.Enqueue("https://darkplugins.ru/engine/engine.json",null, (i, s) => {
if (i == 200) WriteData(s);
else PrintError("Ошибка загрузки локализации,обратитесь к разработчику!");
}, this, RequestMethod.GET);
}
else
{
LocData = Interface.GetMod().DataFileSystem.ReadObject<LocalizationStored>("Auction/Loc");
}
}
void WriteData(string s)
{
LocData.TranslatedItems = JsonConvert.DeserializeObject<Dictionary<string, string>>(s);
Interface.GetMod().DataFileSystem.WriteObject("Auction/Loc", LocData);
}
void OnPlayerInit(BasePlayer player) => CheckDb(player);
#endregion
#region Command
void CheckDb(BasePlayer player)
{
if (!DataBase.PlayerDatabase.ContainsKey(player.userID))
DataBase.PlayerDatabase.Add(player.userID, new PlayerInfo() { Inventory = new List<ItemInv>() });
}
[ChatCommand("ac")]
void accmd(BasePlayer player, string command, string[] args)
{
if (config.OnlyBuilding == true)
{
BuildingPrivlidge Privlidge = player.GetBuildingPrivilege();
if (Privlidge != null && Privlidge.authorizedPlayers.Any(x => x.userid == player.userID))
DrawAuction(player, 0);
else
SendReply(player, "Для открытия аукциона вам необходимо быть в зоне вашего шкафа");
}
else
{
DrawAuction(player, 0);
}
}
[ChatCommand("Auction")]
void Auctioncmd(BasePlayer player, string command, string[] args)
{
if (config.OnlyBuilding == true)
{
BuildingPrivlidge Privlidge = player.GetBuildingPrivilege();
if (Privlidge != null && Privlidge.authorizedPlayers.Any(x => x.userid == player.userID))
DrawAuction(player, 0);
else
SendReply(player, "Для открытия аукциона вам необходимо быть в зоне вашего шкафа");
}
else
{
DrawAuction(player, 0);
}
}
[ConsoleCommand("OpenAddInv")]
void OpenAddInv(ConsoleSystem.Arg arg)
{
int Page = int.Parse(arg.Args[0]);
DrawAddInInvetory(arg.Player(), Page);
}
[ConsoleCommand("OpenBit")]
void OpenBit(ConsoleSystem.Arg arg)
{
if (config.UseGameStores)
{
GetBalanceGameStore(arg.Player(), (code, balance) =>
{
int GetBalance = int.Parse(balance.Split('.')[0]);
DataBase.PlayerDatabase[arg.Player().userID].Balance = GetBalance;
});
}
if (config.UseEconomics)
{
double GetBalance = GetBalanceEconomycs(arg.Player().userID);
DataBase.PlayerDatabase[arg.Player().userID].Balance = Convert.ToInt32(GetBalance);
}
if (config.UseServerRwards)
{
int GetBalance = GetBalanceServerReward(arg.Player().userID);
DataBase.PlayerDatabase[arg.Player().userID].Balance = GetBalance;
}
int LotId = int.Parse(arg.Args[0]);
int Page = int.Parse(arg.Args[1]);
DrawBit(arg.Player(), LotId, 0, 0, Page);
}
[ConsoleCommand("OpenConfirm")]
void OpenConfirm(ConsoleSystem.Arg arg)
{
string FromGui = arg.Args[0];
string Parent = arg.Args[1];
int LotId = int.Parse(arg.Args[2]);
DrawConfirm(arg.Player(), FromGui, Parent, LotId);
}
[ConsoleCommand("OpenYourLots")]
void OpenYourLots(ConsoleSystem.Arg arg)
{
CuiHelper.DestroyUi(arg.Player(), "AuctionMainGui");
DrawYourAuction(arg.Player());
}
[ConsoleCommand("OpenCountMenu")]
void OpenCountMenu(ConsoleSystem.Arg arg)
{
DrawSelectCountItem(arg.Player(), arg.Args[0], int.Parse(arg.Args[1]), ulong.Parse(arg.Args[2]), int.Parse(arg.Args[3]));
}
[ConsoleCommand("OpenInventory")]
void OpenInventory(ConsoleSystem.Arg arg)
{
CuiHelper.DestroyUi(arg.Player(), "AuctionMainGui");
DrawInvenoty(arg.Player());
}
[ConsoleCommand("UpdateAddInv")]
void UpdateAddInv(ConsoleSystem.Arg arg)
{
BasePlayer player = arg.Player();
int Ammount = int.Parse(arg.Args[1]);
string ShortName = arg.Args[2];
ulong Skin = ulong.Parse(arg.Args[3]);
int Page = int.Parse(arg.Args[4]);
ItemDefinition GetItemID = ItemManager.FindItemDefinition(ShortName);
int GetAmmount = player.inventory.GetAmount(GetItemID.itemid);
switch (arg.Args[0])
{
case "plus":
{
if (Ammount < GetAmmount)
Ammount++;
DrawSelectCountItem(player, ShortName, Ammount, Skin, Page);
break;
}
case "minus":
{
if (Ammount > 1)
Ammount--;
DrawSelectCountItem(player, ShortName, Ammount, Skin, Page);
break;
}
}
}
[ConsoleCommand("UpdateBit")]
void UpdateBit(ConsoleSystem.Arg arg)
{
int LotId = int.Parse(arg.Args[1]);
int Bit = int.Parse(arg.Args[2]);
int Buyout = int.Parse(arg.Args[3]);
int Page = int.Parse(arg.Args[4]);
int Balance = DataBase.PlayerDatabase[arg.Player().userID].Balance;
switch (arg.Args[0])
{
case "plus":
{
if (Bit < Balance)
{
Bit++;
if (Buyout < Bit)
{
Buyout = Bit;
DrawBit(arg.Player(), LotId, Bit, Buyout, Page, true);
}
else
DrawBit(arg.Player(), LotId, Bit, Buyout, Page, true);
}
break;
}
}
}
[ConsoleCommand("OpenPublish")]
void OpenPublish(ConsoleSystem.Arg arg)
{
int ItemID = int.Parse(arg.Args[0]);
ulong Skin = ulong.Parse(arg.Args[1]);
int Ammount = int.Parse(arg.Args[2]);
string ShortName = arg.Args[3];
int page = int.Parse(arg.Args[4]);
DrawPublicItem(arg.Player(), ItemID, Skin, Ammount, ShortName, page, config.MinimumCostForAddLot, config.MinimumCostForAddLot);
}
[ConsoleCommand("UpdatePublish")]
void UpdatePublish(ConsoleSystem.Arg arg)
{
BasePlayer player = arg.Player();
string Type = arg.Args[0];
int ItemId = int.Parse(arg.Args[2]);
ulong Skin = ulong.Parse(arg.Args[3]);
int Ammount = int.Parse(arg.Args[4]);
string ShortName = arg.Args[5];
int page = int.Parse(arg.Args[6]);
int Bit = int.Parse(arg.Args[7]);
int Buyout = int.Parse(arg.Args[8]);
ItemDefinition GetItemID = ItemManager.FindItemDefinition(ShortName);
int GetAmmount = player.inventory.GetAmount(GetItemID.itemid);
if (Type == "Ammount")
{
switch (arg.Args[1])
{
case "plus":
{
if (Ammount < GetAmmount)
Ammount++;
DrawPublicItem(player, ItemId, Skin, Ammount, ShortName, page, Bit, Buyout);
break;
}
case "minus":
{
if (Ammount > 1)
Ammount--;
DrawPublicItem(player, ItemId, Skin, Ammount, ShortName, page, Bit, Buyout);
break;
}
}
}
if (Type == "Bit")
{
switch (arg.Args[1])
{
case "plus":
{
Bit++;
DrawPublicItem(player, ItemId, Skin, Ammount, ShortName, page, Bit, Buyout);
break;
}
case "minus":
{
if (Bit > config.MinimumCostForAddLot)
Bit--;
DrawPublicItem(player, ItemId, Skin, Ammount, ShortName, page, Bit, Buyout);
break;
}
}
}
if (Type == "Buyout")
{
switch (arg.Args[1])
{
case "plus":
{
Buyout++;
DrawPublicItem(player, ItemId, Skin, Ammount, ShortName, page, Bit, Buyout);
break;
}
case "minus":
{
if (Buyout > config.MinimumCostForAddLot)
Buyout--;
DrawPublicItem(player, ItemId, Skin, Ammount, ShortName, page, Bit, Buyout);
break;
}
}
}
}
[ConsoleCommand("AddInInventory")]
void AddInInventory(ConsoleSystem.Arg arg)
{
string ShortName = arg.Args[0];
int Ammount = int.Parse(arg.Args[1]);
ulong Skin = ulong.Parse(arg.Args[2]);
int Page = int.Parse(arg.Args[3]);
BasePlayer player = arg.Player();
if (DataBase.PlayerDatabase[player.userID].Inventory.Count >= config.HowCanAddItems)
{
CuiHelper.DestroyUi(player, "AuctionAddInvGui");
DrawMessage(player, "AuctionInvGui" + "BackGround", "У вас максимум предметов");
return;
}
ItemDefinition GetItemID = ItemManager.FindItemDefinition(ShortName);
player.inventory.Take(null, GetItemID.itemid, Ammount);
ItemInv Data = new ItemInv
{
ItemId = random.Next(1, 100000),
Ammount = Ammount,
Skin = Skin,
ShortName = ShortName
};
DataBase.PlayerDatabase[player.userID].Inventory.Add(Data);
SaveData();
CuiHelper.DestroyUi(player, "AuctionAddInvGui");
DrawInvenoty(player, Page);
}
[ConsoleCommand("InventoryPage")]
void InventoryPage(ConsoleSystem.Arg arg)
{
int page = int.Parse(arg.Args[1]);
switch (arg.Args[0])
{
case "Next":
{
page++;
DrawAuction(arg.Player(), page);
break;
}
case "Back":
{
page--;
DrawAuction(arg.Player(), page);
break;
}
}
}
[ConsoleCommand("AuctionPage")]
void AuctionPage(ConsoleSystem.Arg arg)
{
int page = int.Parse(arg.Args[1]);
switch (arg.Args[0])
{
case "Next":
{
page++;
DrawAuction(arg.Player(), page);
break;
}
case "Back":
{
page--;
DrawAuction(arg.Player(), page);
break;
}
}
}
[ConsoleCommand("TakeFromInv")]
void TakeFromInv(ConsoleSystem.Arg arg)
{
BasePlayer player = arg.Player();
int ItemId = int.Parse(arg.Args[0]);
int Ammount = int.Parse(arg.Args[1]);
ulong Skin = ulong.Parse(arg.Args[2]);
int Page = int.Parse(arg.Args[3]);
ItemInv GetItem = DataBase.PlayerDatabase[player.userID].Inventory.Find(d => d.ItemId == ItemId);
DataBase.PlayerDatabase[player.userID].Inventory.Remove(GetItem);
Item x = ItemManager.CreateByPartialName(GetItem.ShortName, GetItem.Ammount);
if (Skin != 0) x.skin = Skin;
player.GiveItem(x, BaseEntity.GiveItemReason.PickedUp);
DrawInvenoty(player, Page);
}
[ConsoleCommand("SetBit")]
void SetBit(ConsoleSystem.Arg arg)
{
BasePlayer player = arg.Player();
int LotId = int.Parse(arg.Args[0]);
int Bid = int.Parse(arg.Args[1]);
int Buyout = int.Parse(arg.Args[2]);
int Page = int.Parse(arg.Args[3]);
AuctionLot GetLot = DataBase.Lots.Find(x => x.LotId == LotId);
if (config.UseGameStores)
{
GetBalanceGameStore(player, (code, balance) =>
{
AuctionLot GetLotGS = DataBase.Lots.Find(x => x.LotId == LotId);
int GetBalance = int.Parse(balance.Split('.')[0]);
if (GetBalance < GetLotGS.Buyout)
{
CuiHelper.DestroyUi(player, "AuctionConfirmGui");
DrawMessage(player, "AuctionMainGui" + "BackGround", "У вас не хватает средств");
return;
}
if (GetLot.LastBitPlayer == 0)
{
TakeGsMoney(player.userID, Bid, (code2, status) =>
{
if (code2 != 200 || status == "fail")
{
CuiHelper.DestroyUi(player, "AuctionConfirmGui");
DrawMessage(player, "AuctionMainGui" + "BackGround", "Ошибка");
return;
}
});
GetLot.LastBitPlayer = player.userID;
GetLot.Bid = Bid;
GetLot.Buyout = Buyout;
DrawAuction(player, Page);
}
else
{
GiveGsMoney(GetLotGS.LastBitPlayer, GetLotGS.Bid, (code2, status) =>
{
if (code2 != 200 || status == "fail")
{
CuiHelper.DestroyUi(player, "AuctionConfirmGui");
DrawMessage(player, "AuctionMainGui" + "BackGround", "Ошибка");
return;
}
});
TakeGsMoney(player.userID, Bid, (code2, status) =>
{
if (code2 != 200 || status == "fail")
{
CuiHelper.DestroyUi(player, "AuctionConfirmGui");
DrawMessage(player, "AuctionMainGui" + "BackGround", "Ошибка");
return;
}
});
DataBase.PlayerDatabase[GetLot.LastBitPlayer].Balance += GetLot.Bid;
GetLot.LastBit = GetLot.Bid;
GetLot.Bid = Bid;
GetLot.Buyout = Buyout;
DrawAuction(player, Page);
}
});
}
if (config.UseEconomics)
{
double GetBalance = GetBalanceEconomycs(player.userID);
if (Convert.ToInt32(GetBalance) < Bid)
{
CuiHelper.DestroyUi(player, "AuctionMainGui" + "Count");
DrawMessage(player, "AuctionMainGui" + "BackGround", "У вас не хватает средств");
return;
}
if (GetLot.LastBitPlayer == 0)
{
if (config.UseEconomics)
TakeEconomycsMoney(player.userID, Bid);
GetLot.LastBitPlayer = player.userID;
GetLot.Bid = Bid;
GetLot.Buyout = Buyout;
DrawAuction(player, Page);
}
else
{
if (config.UseEconomics)
{
GiveEconomycsMoney(GetLot.LastBitPlayer, GetLot.Bid);
TakeEconomycsMoney(player.userID, Bid);
}
GetLot.LastBit = GetLot.Bid;
GetLot.Bid = Bid;
GetLot.Buyout = Buyout;
DrawAuction(player, Page);
}
}
if (config.UseServerRwards)
{
int GetBalance = GetBalanceServerReward(player.userID);
if (GetBalance < Bid)
{
CuiHelper.DestroyUi(player, "AuctionMainGui" + "Count");
DrawMessage(player, "AuctionMainGui" + "BackGround", "У вас не хватает средств");
return;
}
if (GetLot.LastBitPlayer == 0)
{
if (config.UseServerRwards)
TakeServerRewardMoney(player.userID, Bid);
GetLot.LastBitPlayer = player.userID;
GetLot.Bid = Bid;
GetLot.Buyout = Buyout;
DrawAuction(player, Page);
}
else
{
if (config.UseServerRwards)
{
GiveServerRewardMoney(GetLot.LastBitPlayer, GetLot.Bid);
TakeServerRewardMoney(player.userID, Bid);
}
GetLot.LastBit = GetLot.Bid;
GetLot.Bid = Bid;
GetLot.Buyout = Buyout;
DrawAuction(player, Page);
}
}
}
[ConsoleCommand("DelLot")]
void DelLot(ConsoleSystem.Arg arg)
{
BasePlayer player = arg.Player();
int LotId = int.Parse(arg.Args[0]);
int TypePage = int.Parse(arg.Args[1]);
int Page = int.Parse(arg.Args[2]);
AuctionLot GetLot = DataBase.Lots.Find(x => x.LotId == LotId);
ItemInv data = new ItemInv()
{
ItemId = random.Next(1, 100000),
Ammount = GetLot.Count,
ShortName = GetLot.ShortName,
Skin = GetLot.skin
};
if (GetLot.LastBitPlayer == 0)
{
DataBase.PlayerDatabase[player.userID].Inventory.Add(data);
DataBase.Lots.Remove(GetLot);
}
else
{
if (config.UseGameStores)
{
GiveGsMoney(GetLot.LastBitPlayer, GetLot.Bid, (code, status) =>
{
if (code != 200 || status == "fail")
{
DrawMessage(player, "AuctionYourMainGui" + "BackGround" + "BackGround", "Ошибка");
return;
}
});
}
if (config.UseEconomics)
GiveEconomycsMoney(GetLot.LastBitPlayer, GetLot.Bid);
if (config.UseServerRwards)
GiveServerRewardMoney(GetLot.LastBitPlayer, GetLot.Bid);
DataBase.PlayerDatabase[player.userID].Inventory.Add(data);
DataBase.Lots.Remove(GetLot);
}
if (TypePage == 1)
DrawYourAuction(player, Page);
if (TypePage == 0)
DrawAuction(player, Page);
}
[ConsoleCommand("UI_Buyout")]
void UI_Buyout(ConsoleSystem.Arg arg)
{
BasePlayer player = arg.Player();
int LotId = int.Parse(arg.Args[0]);
AuctionLot GetLot = DataBase.Lots.Find(x => x.LotId == LotId);
if (config.UseGameStores)
{
GetBalanceGameStore(player, (code, balance) =>
{
int GetBalance = int.Parse(balance.Split('.')[0]);
if (GetBalance < GetLot.Buyout)
{
CuiHelper.DestroyUi(player, "AuctionConfirmGui");
DrawMessage(player, "AuctionMainGui" + "BackGround", "У вас не хватает средств");
return;
}
if (GetLot.LastBitPlayer == 0)
{
float GetBuyout = GetLot.Buyout;
if (config.TakePercent) GetBuyout -= GetBuyout / 100 * config.PercentForMoney;
TakeGsMoney(player.userID, GetBuyout, (code2, status) =>
{
if (code2 != 200 || status == "fail")
{
CuiHelper.DestroyUi(player, "AuctionConfirmGui");
DrawMessage(player, "AuctionMainGui" + "BackGround", "Ошибка");
return;
}
});
GiveGsMoney(GetLot.Owner, GetBuyout, (code2, status) =>
{
if (code2 != 200 || status == "fail")
{
CuiHelper.DestroyUi(player, "AuctionConfirmGui");
DrawMessage(player, "AuctionMainGui" + "BackGround", "Ошибка");
return;
}
});
ItemInv data = new ItemInv()
{
ItemId = random.Next(1, 100000),
Ammount = GetLot.Count,
ShortName = GetLot.ShortName,
Skin = GetLot.skin,
};
DataBase.PlayerDatabase[player.userID].Inventory.Add(data);
DataBase.Lots.Remove(GetLot);
CuiHelper.DestroyUi(player, "AuctionConfirmGui");
DrawAuction(player);
}
else
{
float GetBuyout = GetLot.Buyout;
if (config.TakePercent) GetBuyout -= GetBuyout / 100 * config.PercentForMoney;
if (GetLot.LastBitPlayer != player.userID)
{
GiveGsMoney(GetLot.LastBitPlayer, GetLot.Bid, (code2, status) =>
{
if (code2 != 200 || status == "fail")
{
CuiHelper.DestroyUi(player, "AuctionConfirmGui");
DrawMessage(player, "AuctionMainGui" + "BackGround", "Ошибка");
return;
}
});
}
TakeGsMoney(player.userID, GetBuyout, (code2, status) =>
{
if (code2 != 200 || status == "fail")
{
CuiHelper.DestroyUi(player, "AuctionConfirmGui");
DrawMessage(player, "AuctionMainGui" + "BackGround", "Ошибка");
return;
}
});
GiveGsMoney(GetLot.Owner, GetBuyout, (code2, status) =>
{
if (code2 != 200 || status == "fail")
{
CuiHelper.DestroyUi(player, "AuctionConfirmGui");
DrawMessage(player, "AuctionMainGui" + "BackGround", "Ошибка");
return;
}
});
ItemInv data = new ItemInv()
{
ItemId = random.Next(1, 100000),
Ammount = GetLot.Count,
ShortName = GetLot.ShortName,
Skin = GetLot.skin,
};
DataBase.Lots.Remove(GetLot);
DataBase.PlayerDatabase[player.userID].Inventory.Add(data);
CuiHelper.DestroyUi(player, "AuctionConfirmGui");
DrawAuction(player);
}
});
}
if (config.UseEconomics)
{
double GetBalance = GetBalanceEconomycs(player.userID);
if (Convert.ToInt32(GetBalance) < GetLot.Buyout)
{
CuiHelper.DestroyUi(player, "AuctionConfirmGui");
DrawMessage(player, "AuctionMainGui" + "BackGround", "У вас не хватает средств");
return;
}
if (GetLot.LastBitPlayer == 0)
{
float GetBuyout = GetLot.Buyout;
if (config.TakePercent) GetBuyout -= GetBuyout / 100 * config.PercentForMoney;
TakeEconomycsMoney(player.userID, GetBuyout);
GiveEconomycsMoney(GetLot.Owner, GetBuyout);
ItemInv data = new ItemInv()
{
ItemId = random.Next(1, 100000),
Ammount = GetLot.Count,
ShortName = GetLot.ShortName,
Skin = GetLot.skin,
};
DataBase.Lots.Remove(GetLot);
DataBase.PlayerDatabase[player.userID].Inventory.Add(data);
CuiHelper.DestroyUi(player, "AuctionConfirmGui");
DrawAuction(player);
}
else
{
float GetBuyout = GetLot.Buyout;
if (config.TakePercent) GetBuyout -= GetBuyout / 100 * config.PercentForMoney;
if (GetLot.LastBitPlayer != player.userID) GiveEconomycsMoney(GetLot.LastBitPlayer, GetLot.Bid);
TakeEconomycsMoney(player.userID, GetBuyout);
GiveEconomycsMoney(GetLot.Owner, GetBuyout);
ItemInv data = new ItemInv()
{
ItemId = random.Next(1, 100000),
Ammount = GetLot.Count,
ShortName = GetLot.ShortName,
Skin = GetLot.skin,
};
DataBase.Lots.Remove(GetLot);
DataBase.PlayerDatabase[player.userID].Inventory.Add(data);
CuiHelper.DestroyUi(player, "AuctionConfirmGui");
DrawAuction(player);
}
}
if (config.UseServerRwards)
{
double GetBalance = GetBalanceEconomycs(player.userID);
if (Convert.ToInt32(GetBalance) < GetLot.Buyout)
{
CuiHelper.DestroyUi(player, "AuctionConfirmGui");
DrawMessage(player, "AuctionMainGui" + "BackGround", "У вас не хватает средств");
return;
}
if (GetLot.LastBitPlayer == 0)
{
float GetBuyout = GetLot.Buyout;
if (config.TakePercent) GetBuyout -= GetBuyout / 100 * config.PercentForMoney;
TakeServerRewardMoney(player.userID, GetBuyout);
GiveServerRewardMoney(GetLot.Owner, GetBuyout);
ItemInv data = new ItemInv()
{
ItemId = random.Next(1, 100000),
Ammount = GetLot.Count,
ShortName = GetLot.ShortName,
Skin = GetLot.skin,
};
DataBase.Lots.Remove(GetLot);
DataBase.PlayerDatabase[player.userID].Inventory.Add(data);
CuiHelper.DestroyUi(player, "AuctionConfirmGui");
DrawAuction(player);
}
else
{
float GetBuyout = GetLot.Buyout;
if (config.TakePercent) GetBuyout -= GetBuyout / 100 * config.PercentForMoney;
if (GetLot.LastBitPlayer != player.userID) GiveServerRewardMoney(GetLot.LastBitPlayer, GetLot.Bid);
TakeServerRewardMoney(player.userID, GetBuyout);
GiveServerRewardMoney(GetLot.Owner, GetBuyout);
ItemInv data = new ItemInv()
{
ItemId = random.Next(1, 100000),
Ammount = GetLot.Count,
ShortName = GetLot.ShortName,
Skin = GetLot.skin,
};
DataBase.Lots.Remove(GetLot);
DataBase.PlayerDatabase[player.userID].Inventory.Add(data);
CuiHelper.DestroyUi(player, "AuctionConfirmGui");
DrawAuction(player);
}
}
}
[ConsoleCommand("AddAuction")]
void AddAuction(ConsoleSystem.Arg arg)
{
BasePlayer player = arg.Player();
int ItemId = int.Parse(arg.Args[0]);
ulong Skin = ulong.Parse(arg.Args[1]);
int Ammount = int.Parse(arg.Args[2]);
string ShortName = arg.Args[3];
int Page = int.Parse(arg.Args[4]);
int Bit = int.Parse(arg.Args[5]);
int Buyout = int.Parse(arg.Args[6]);
List<AuctionLot> GetLotsList = DataBase.Lots.FindAll(x => x.Owner == player.userID);
if (GetLotsList.Count!=0)
{
if (GetLotsList.Count >= config.HowCanAddLots)
{
CuiHelper.DestroyUi(player, "AuctionAddInvGui");
DrawMessage(player, "AuctionInvGui" + "BackGround", "У вас максимум лотов");
return;
}
}
AuctionLot Data = new AuctionLot
{
LotId = random.Next(1, 10000),
Owner = arg.Player().userID,
ShortName = ShortName,
Count = Ammount,
Hours = config.HowHoursForLots,
skin = Skin,
StartBit = Bit,
LastBit = Bit,
LastBitPlayer = 0,
Bid = Bit,
Buyout = Buyout,
Date = DateTime.Now
};
DataBase.Lots.Add(Data);
ItemInv GetItem = DataBase.PlayerDatabase[player.userID].Inventory.Find(x => x.ItemId == ItemId);
DataBase.PlayerDatabase[player.userID].Inventory.Remove(GetItem);
CuiHelper.DestroyUi(player, "AuctionAddGui" + "Count");
DrawInvenoty(player, Page);
SaveData();
}
[ConsoleCommand("UI_BackToMainAuc")]
void BackToMain(ConsoleSystem.Arg arg)
{
CuiHelper.DestroyUi(arg.Player(), arg.Args[0]);
DrawAuction(arg.Player());
}
#endregion
#region Gui
void DrawAuction(BasePlayer player, int page = 0)
{
CuiHelper.DestroyUi(player, "AuctionMainGui");
var AuctionMainGui = new CuiElementContainer();
AuctionMainGui.Add(new CuiElement()
{
Parent = "Overlay",
Name = "AuctionMainGui",
Components =
{
new CuiImageComponent()
{
Color = "0.2 0.2 0.2 0.8",
Material = matterial
},
new CuiNeedsCursorComponent()
{
},
new CuiRectTransformComponent()
{
AnchorMin = "0 0",
AnchorMax = "1 1",
}
}
});
AuctionMainGui.Add(new CuiButton
{
Button = { Close = "AuctionMainGui", Color = "0 0 0 0" },
Text = { Text = "" },
RectTransform = { AnchorMax = "1 1", AnchorMin = "0 0" }
}, "AuctionMainGui");
AuctionMainGui.Add(new CuiElement()
{
Parent = "AuctionMainGui",
Components =
{
new CuiTextComponent()
{
Text = "Аукцион",
Align = TextAnchor.MiddleCenter,
FontSize= 35
},
new CuiRectTransformComponent()
{
AnchorMin = "0.5 0.5",
AnchorMax = "0.5 0.5",
OffsetMin = "-336.85 241.6",
OffsetMax = "336.85 326.4"
}
}
});
AuctionMainGui.Add(new CuiElement()
{
Parent = "AuctionMainGui",
Name = "AuctionMainGui" + "BackGround",
Components =
{
new CuiImageComponent()
{
Color = "0.3 0.3 0.3 0.7",
Material = matterial
},
new CuiRectTransformComponent()
{
AnchorMin = "0.5 0.5",
AnchorMax = "0.5 0.5",
OffsetMin = "-395.5 -263.36",
OffsetMax = "395.5 231.8"
}
}
});
AuctionMainGui.Add(new CuiElement()
{
Parent = "AuctionMainGui" + "BackGround",
Components =
{
new CuiTextComponent()
{
Text = "Лоты",
Align = TextAnchor.UpperCenter,
FontSize = 22
},
new CuiRectTransformComponent()
{
AnchorMin = "0 1",
AnchorMax = "0 1",
OffsetMin = "0 -40",
OffsetMax = "800 0"
}
}
});
AuctionMainGui.Add(new CuiElement()
{
Parent = "AuctionMainGui" + "BackGround",
Name = "AuctionMainGui" + "BackGround" + "Balance",
Components =
{
new CuiImageComponent()
{
Color = "0.5 0.5 0.5 0.9",
Material = matterial
},
new C
// ... [Code preview truncated due to length. Full source in attached file] ...