C#:
using Oxide.Core.Plugins;
using Network;
using Rust;
using Newtonsoft.Json;
using Oxide.Core.Libraries;
using System.Linq;
using VLB;
using System.Collections.Generic;
using System.Text;
using System.Drawing;
using System.Collections;
using System;
using UnityEngine.Networking;
using Oxide.Game.Rust.Cui;
using UnityEngine;
using Oxide.Core;
namespace Oxide.Plugins
{
[Info("IQAlcoholFarm", "Sempai#3239", "1.0.2")]
[Description("IQAlcoholFarm")]
internal class IQAlcoholFarm : RustPlugin
{
private void DestroyControllers()
{
for (Int32 i = BarrelController.ActiveControllers.Count - 1; i >= 0; i--)
{
BarrelController activeController = BarrelController.ActiveControllers[i];
UnityEngine.Object.Destroy(activeController);
}
}
[PluginReference] private readonly Plugin ImageLibrary;
private readonly List<BaseEntity> MonumentEntities = new List<BaseEntity>();
private void DestroyAllUi(BasePlayer player)
{
CuiHelper.DestroyUi(player, UI_Layer);
CuiHelper.DestroyUi(player, UI_LayerFade);
CuiHelper.DestroyUi(player, UI_LayerTimer);
}
private class ImageUi
{
private static Coroutine coroutineImg = null;
private static Dictionary<String, String> Images = new Dictionary<String, String>();
internal struct ImageStruct
{
public ImageStruct(String URL, UInt64 SkinID = 0)
{
this.URL = URL;
this.SkinID = SkinID;
}
public String URL;
public UInt64 SkinID;
}
private static List<ImageStruct> KeyImages = new List<ImageStruct>
{
};
public static void DownloadImages() { coroutineImg = ServerMgr.Instance.StartCoroutine(AddImage()); }
private static IEnumerator AddImage()
{
if (_plugin == null)
yield break;
_plugin.PrintWarning(LanguageEn ? "We generate the interface, wait ~10-15 seconds!" : "Генерируем интерфейс, ожидайте ~10-15 секунд!");
foreach (ImageStruct Icons in KeyImages)
{
String URL = String.Empty;
String KeyName = String.Empty;
if (Icons.URL.Contains("UI_"))
URL = $"http://iqsystem.skyplugins.ru/iqalcohol/getimageui/{Icons.URL}/W5fgSD3dfVBxc";
else
{
if (Icons.SkinID != 0)
URL = $"http://api.skyplugins.ru/api/getskin/{Icons.SkinID}/64";
else URL = $"https://api.skyplugins.ru/api/getimage/{Icons.URL}/64";
}
KeyName = $"{Icons.URL}_{Icons.SkinID}";
UnityWebRequest www = UnityWebRequestTexture.GetTexture(URL);
yield return www.SendWebRequest();
if (www.isNetworkError || www.isHttpError)
{
_plugin.PrintWarning(String.Format("Image download error! Error: {0}, Image name: {1}", www.error, KeyName));
www.Dispose();
coroutineImg = null;
yield break;
}
Texture2D texture = DownloadHandlerTexture.GetContent(www);
if (texture != null)
{
Byte[] bytes = texture.EncodeToPNG();
String image = FileStorage.server.Store(bytes, FileStorage.Type.png, CommunityEntity.ServerInstance.net.ID).ToString();
if (!Images.ContainsKey(KeyName))
Images.Add(KeyName, image);
else
Images[KeyName] = image;
UnityEngine.Object.DestroyImmediate(texture);
}
www.Dispose();
yield return CoroutineEx.waitForSeconds(0.02f);
}
coroutineImg = null;
_interface = new InterfaceBuilder();
_plugin.BuildInterface();
_plugin.PrintWarning(LanguageEn ? "Interface loaded successfully!" : "Интерфейс успешно загружен!");
_plugin.GetSounds();
_plugin.CheckStatus();
if (!_plugin.IsInitializeNPCShop())
{
_plugin.Unsubscribe(nameof(OnEntityTakeDamage));
_plugin.Unsubscribe(nameof(CanBradleyApcTarget));
_plugin.Unsubscribe(nameof(OnNpcTarget));
}
else
{
if (_plugin.IsCompound())
_plugin.SpawnPreset(Compound, _plugin.PointsList["COMPOUND"]);
if (_plugin.IsBanitTown())
_plugin.SpawnPreset(BanditTown, _plugin.PointsList["BANDIT_TOWN"]);
if (_plugin.IsAirfield())
_plugin.SpawnPreset(Airfield, _plugin.PointsList["AIRFIELD"]);
}
}
public static String GetImage(String ImgKey)
{
if (Images.ContainsKey(ImgKey))
return Images[ImgKey];
return _plugin.GetImage("LOADING");
}
public static void Initialize()
{
KeyImages = new List<ImageStruct>();
Images = new Dictionary<string, string>();
ImageStruct BackItem = new ImageStruct("UI_IQALCOHOL_BACK_ITEM");
if (!KeyImages.Contains(BackItem))
KeyImages.Add(BackItem);
ImageStruct Background = new ImageStruct("UI_IQALCOHOL_BACKGORUND");
if (!KeyImages.Contains(Background))
KeyImages.Add(Background);
ImageStruct BackItemLine = new ImageStruct("UI_IQALCOHOL_LINE");
if (!KeyImages.Contains(BackItemLine))
KeyImages.Add(BackItemLine);
ImageStruct DrunkIcon = new ImageStruct("UI_ALCOHOL_TIME");
if (!KeyImages.Contains(DrunkIcon))
KeyImages.Add(DrunkIcon);
foreach (PluginConfig.ShopStore.CategorySettings.ItemsPair Image in _config.storeNpc.EquipmentCategory.ItemsList)
{
ImageStruct BuyItem = new ImageStruct(Image.BuyItems.Shortname, Image.BuyItems.SkinID);
if (!KeyImages.Contains(BuyItem))
KeyImages.Add(BuyItem);
ImageStruct PriceItem = new ImageStruct(Image.PriceItems.Shortname, Image.PriceItems.SkinID);
if (!KeyImages.Contains(PriceItem))
KeyImages.Add(PriceItem);
}
foreach (PluginConfig.ShopStore.CategorySettings.ItemsPair Image in _config.storeNpc.ExchangerCategory.ItemsList)
{
ImageStruct BuyItem = new ImageStruct(Image.BuyItems.Shortname, Image.BuyItems.SkinID);
if (!KeyImages.Contains(BuyItem))
KeyImages.Add(BuyItem);
ImageStruct PriceItem = new ImageStruct(Image.PriceItems.Shortname, Image.PriceItems.SkinID);
if (!KeyImages.Contains(PriceItem))
KeyImages.Add(PriceItem);
}
}
public static void Unload()
{
coroutineImg = null;
foreach (KeyValuePair<String, String> item in Images)
FileStorage.server.RemoveExact(UInt32.Parse(item.Value), FileStorage.Type.png, CommunityEntity.ServerInstance.net.ID, 0U);
KeyImages.Clear();
KeyImages = null;
Images.Clear();
Images = null;
}
}
public Dictionary<String, List<Byte[]>> RenderSounds = new Dictionary<string, List<byte[]>>()
{
["welcome"] = new List<byte[]> { },
["bye"] = new List<byte[]> { },
};
private void DrawUI_ItemPanel(BasePlayer player, CategoryType categoryType = CategoryType.Equipment, Int32 Page = 0)
{
CuiHelper.DestroyUi(player, InterfaceBuilder.UI_PANEL_ITEMS);
CuiHelper.DestroyUi(player, "NextButton");
CuiHelper.DestroyUi(player, "BackButton");
CuiHelper.DestroyUi(player, "TitlePage");
String Interface = InterfaceBuilder.GetInterface("UI_TRADER_NPC_ITEMPANEL_TEMPLATE");
if (Interface == null) return;
List<PluginConfig.ShopStore.CategorySettings.ItemsPair> CategoryItems = categoryType == CategoryType.Equipment ? _config.storeNpc.EquipmentCategory.ItemsList : _config.storeNpc.ExchangerCategory.ItemsList;
Interface = Interface.Replace("%COMMAND_NEXT%", CategoryItems.Count >= (Page + 1) * 5 ? $"func.alcohol category page {categoryType} next {Page}" : String.Empty);
Interface = Interface.Replace("%COLOR_NEXT%", CategoryItems.Count >= (Page + 1) * 5 ? "1 1 1 1" : "1 1 1 0.5");
Interface = Interface.Replace("%COMMAND_BACK%", Page != 0 ? $"func.alcohol category page {categoryType} back {Page}" : String.Empty);
Interface = Interface.Replace("%COLOR_BACK%", Page != 0 ? "1 1 1 1" : "1 1 1 0.5");
Interface = Interface.Replace("%COUNT_PAGE%", $"{Page + 1} из {(CategoryItems.Count / 5) + 1}");
Interface = Interface.Replace("%BACK_BUTTON%", GetLang("UI_BACK_BUTTON", player.UserIDString));
Interface = Interface.Replace("%NEXT_BUTTON%", GetLang("UI_NEXT_BUTTON", player.UserIDString));
CuiHelper.AddUi(player, Interface);
DrawUI_Items(player, categoryType, Page);
}
private class PluginData
{
private const String DataPath = "IQSystem/IQAlcoholFarm/Data";
[JsonProperty(ObjectCreationHandling = ObjectCreationHandling.Replace)]
public List<DrunkPlayer> DrunkPlayers = new List<DrunkPlayer>();
public static void SaveData()
{
if (_data == null) return;
Interface.Oxide.DataFileSystem.WriteObject(DataPath, _data);
}
public static void LoadData()
{
if (Interface.Oxide.DataFileSystem.ExistsDatafile(DataPath))
{
_data = Interface.Oxide.DataFileSystem.ReadObject<PluginData>(DataPath);
}
else
{
_data = new PluginData()
{
};
}
if (_data == null)
{
_data = new PluginData()
{
};
}
if (_data.DrunkPlayers.Count == 1)
ServerMgr.Instance.StartCoroutine(_plugin.PlayersUpdate(true));
}
}
private String DrunkFade;
public String GetLang(String LangKey, String userID = null, params System.Object[] args)
{
sb.Clear();
if (args != null)
{
sb.AppendFormat(lang.GetMessage(LangKey, this, userID), args);
return sb.ToString();
}
return lang.GetMessage(LangKey, this, userID);
}
private void OnPlayerDisconnected(BasePlayer player, String reason)
{
if (_initiated == false)
return;
_data.DrunkPlayers.RemoveAll(x => x.Player.userID == player.userID);
DestroyAllUi(player);
}
private void OnItemRemovedFromContainer(ItemContainer container, Item item)
{
if (_initiated == false)
return;
if (item.skin != _config.itemSettings.AlcoholItemSkinId)
return;
if (container == null)
return;
if (container.parent == null)
return;
if (container.parent.skin != _config.itemSettings.AlcoholBottleSkinId)
return;
container.parent.skin = 0;
}
private IEnumerator PlayersUpdate(Boolean afterReload = false)
{
while (_data.DrunkPlayers.Count > 0)
{
try
{
for (Int32 i = _data.DrunkPlayers.Count - 1; i >= 0; i--)
{
DrunkPlayer drunkPlayer = _data.DrunkPlayers[i];
if (--drunkPlayer.DrunkRemaining <= 0)
{
_data.DrunkPlayers.Remove(drunkPlayer);
DestroyAllUi(drunkPlayer.Player);
continue;
}
if (afterReload)
{
DrawUI_DrunkBlock(drunkPlayer.Player, drunkPlayer.CurrectColor, drunkPlayer.DrunkRemaining);
DrawUI_DrunkAFade(drunkPlayer.Player, drunkPlayer.CurrectFade);
}
Int32 index = GetIndexFromGradient(AlcoholColorGradient.Length, (Int32)drunkPlayer.DrunkRemaining, (Int32)_config.drinkedSettings.AlcoholDrinkLimit);
String color = AlcoholColorGradient[index];
if (color != drunkPlayer.CurrectColor)
{
drunkPlayer.CurrectColor = color;
DrawUI_DrunkBlock(drunkPlayer.Player, drunkPlayer.CurrectColor, drunkPlayer.DrunkRemaining);
}
color = AlcoholBlur[index];
if (color != drunkPlayer.CurrectFade)
{
drunkPlayer.CurrectFade = color;
DrawUI_DrunkAFade(drunkPlayer.Player, drunkPlayer.CurrectFade);
}
if (drunkPlayer.DrunkRemaining >= _config.drinkedSettings.AlcoholDrinkLimit)
{
if (Core.Random.Range(0, 100) <= _config.drinkedSettings.AlcoholDrunkNegativeChance)
ExecuteNegativeEffect(drunkPlayer.Player);
}
else
{
drunkPlayer.Player.Heal(_config.drinkedSettings.AlcoholDrunkHeal);
}
if (drunkPlayer.ModifiersUpdate > drunkPlayer.DrunkRemaining)
UpdateModifiers(drunkPlayer);
drunkPlayer.Player.metabolism.temperature.SetValue(40f);
DrawUI_DrunkTimer(drunkPlayer.Player, drunkPlayer.CurrectColor, drunkPlayer.DrunkRemaining);
if (Core.Random.Range(0, 100) <= _config.RareEffect)
EffectNetwork.Send(new Effect(AlcoholShakeEffect.GetRandom(), drunkPlayer.Player.transform.position, Vector3.zero), drunkPlayer.Player.net.connection);
}
}
catch (Exception)
{
//PrintError(e.ToString());
}
afterReload = false;
yield return new WaitForSeconds(1f);
}
yield break;
}
void ReadData()
{
try { RenderSounds = Oxide.Core.Interface.GetMod().DataFileSystem.ReadObject<Dictionary<String, List<Byte[]>>>("IQSystem/IQAlcoholFarm/Sounds"); }
catch { PrintWarning("Error reading the data file"); }
}
private readonly Dictionary<String, List<Point>> PointsList = new Dictionary<String, List<Point>>
{
["COMPOUND"] = new List<Point>
{
new Point
{
Name = "NPC.POINT",
Y = 40f,
X = 0f,
Pos = new Vector3(21.7f, 0.3f, 7.4f),
LinkImage = String.Empty,
},
new Point
{
Name = "TABLES.POINT",
Y = -90f,
X = 30f,
Pos = new Vector3(17.9f, 0.3f, 11f),
LinkImage = SignImgLeft,
},
new Point
{
Name = "TABLES.POINT",
Y = 0,
X = 0f,
Pos = new Vector3(3.7f, 3f, 16.2f),
LinkImage = SignImgLeft,
},
},
["BANDIT_TOWN"] = new List<Point>
{
new Point
{
Name = "NPC.POINT",
Y = 180f,
X = 0f,
Pos = new Vector3(-28.8f, 1.78f, 35f),
LinkImage = String.Empty,
},
new Point
{
Name = "TABLES.POINT",
Y = 180f,
X = 0,
Pos = new Vector3(-24.8f, 3.78f, 35.5f),
LinkImage = SignImgLeft,
},
},
["AIRFIELD"] = new List<Point>
{
new Point
{
Name = "NPC.POINT",
Y = 200f,
X = 0f,
Pos = new Vector3(-10.5f, 3.31f, -93.3f),
LinkImage = String.Empty,
},
new Point
{
Name = "TABLES.POINT",
Y = 0f,
X = 0f,
Pos = new Vector3(-7.5f, 2.8f, -75.8f),
LinkImage = SignImgLeft,
},
new Point
{
Name = "TABLES.POINT",
Y = -90f,
X = 0f,
Pos = new Vector3(-0.86f, 4.5f, -92f),
LinkImage = SignImgLeft,
},
new Point
{
Name = "TABLES.POINT",
Y = -30f,
X = 30f,
Pos = new Vector3(-59.3f, 0.3f, -72.7f),
LinkImage = SignImgLeft,
},
new Point
{
Name = "TABLES.POINT",
Y = 180f,
X = 13f,
Pos = new Vector3(-154.5f, 0.22f, -76.8f),
LinkImage = SignImgRight,
},
},
};
private Boolean HaveItem(BasePlayer player, String Shortname, Int32 Amount, UInt64 SkinID = 0, ItemContainer contaner = null)
{
Int32 ItemAmount = 0;
foreach (Item ItemRequires in contaner == null ? player.inventory.AllItems().ToList() : contaner.itemList)
{
if (ItemRequires == null) continue;
if (ItemRequires.skin != SkinID || ItemRequires.info.shortname != Shortname)
{
if (ItemRequires.contents != null)
{
foreach (Item item1 in ItemRequires.contents.itemList)
{
if (item1.info.shortname == Shortname && item1.skin == SkinID)
ItemAmount += item1.amount;
}
}
continue;
}
ItemAmount += ItemRequires.amount;
}
return ItemAmount >= Amount;
}
private void StartPluginLoad()
{
if (ImageLibrary != null)
{
//Load your images here
ImageUi.Initialize();
ImageUi.DownloadImages();
}
else
{
PrintError($"ImageLibrary not found! Please, check your plugins list.");
}
}
private void ValidateConfig()
{
if (Interface.Oxide.CallHook("OnConfigValidate") != null)
{
PrintWarning("Using default configuration...");
_config = GetDefaultConfig();
}
}
private static MonumentInfo Airfield;
private class InterfaceBuilder
{
public static InterfaceBuilder Instance;
public const String UI_TRADER = "UI_TRADER";
public const String UI_PANEL_ITEMS = "UI_PANEL_ITEMS";
public Dictionary<String, String> Interfaces;
public InterfaceBuilder()
{
Instance = this;
Interfaces = new Dictionary<String, String>();
BuildingTrader();
BuildingTrader_Category();
BuildingTrader_Panel();
BuildingTrader_ItemPanel();
BuildingTrader_ItemPanel_ControllerAmount();
}
public static void AddInterface(String name, String json)
{
if (Instance.Interfaces.ContainsKey(name))
{
_plugin.PrintError($"Error! Tried to add existing cui elements! -> {name}");
return;
}
Instance.Interfaces.Add(name, json);
}
public static String GetInterface(String name)
{
String json = String.Empty;
if (Instance.Interfaces.TryGetValue(name, out json) == false)
{
_plugin.PrintWarning($"Warning! UI elements not found by name! -> {name}");
}
return json;
}
public static void DestroyAll()
{
for (Int32 i = 0; i < BasePlayer.activePlayerList.Count; i++)
{
BasePlayer player = BasePlayer.activePlayerList[i];
CuiHelper.DestroyUi(player, UI_TRADER);
CuiHelper.DestroyUi(player, UI_PANEL_ITEMS);
}
}
private void BuildingTrader()
{
CuiElementContainer container = new CuiElementContainer
{
{
new CuiPanel
{
CursorEnabled = true,
Image = { Color = "1 1 1 0.0627451" },
RectTransform = { AnchorMin = "0 0", AnchorMax = "1 1" }
},
"Overlay",
UI_TRADER
},
new CuiElement
{
Name = "BACKGROUND_IMAGE",
Parent = UI_TRADER,
Components = {
new CuiRawImageComponent { Color = "1 1 1 1", Png = ImageUi.GetImage("UI_IQALCOHOL_BACKGORUND_0") },
new CuiRectTransformComponent { AnchorMin = "0 0", AnchorMax = "1 1" }
}
},
{
new CuiButton
{
Button = { Color = "0 0 0 0", Close = UI_TRADER },
Text = { Text = "", Font = "robotocondensed-regular.ttf", FontSize = 17, Align = TextAnchor.MiddleCenter, Color = "1 1 1 1" },
RectTransform = { AnchorMin = "0 0", AnchorMax = "1 1" }
},
UI_TRADER,
"CloseButton"
},
new CuiElement
{
Name = "TitleProduct",
Parent = UI_TRADER,
Components = {
new CuiTextComponent { Text = "%UI_TITLE_ITEM%", Font = "robotocondensed-regular.ttf", FontSize = 12, Align = TextAnchor.UpperCenter, Color = "1 1 1 1" },
new CuiRectTransformComponent { AnchorMin = "0.5 0.5", AnchorMax = "0.5 0.5", OffsetMin = "-181.062 216.907", OffsetMax = "-123.298 235.8930949" }
}
},
new CuiElement
{
Name = "TitlePrice",
Parent = UI_TRADER,
Components = {
new CuiTextComponent { Text = "%UI_TITLE_PRICE%", Font = "robotocondensed-regular.ttf", FontSize = 12, Align = TextAnchor.UpperCenter, Color = "1 1 1 1" },
new CuiRectTransformComponent { AnchorMin = "0.5 0.5", AnchorMax = "0.5 0.5", OffsetMin = "-50.482 216.907", OffsetMax = "7.282 235.8930949" }
}
},
new CuiElement
{
Name = "TitleAmount",
Parent = UI_TRADER,
Components = {
new CuiTextComponent { Text = "%UI_TITLE_AMOUNT%", Font = "robotocondensed-regular.ttf", FontSize = 12, Align = TextAnchor.UpperCenter, Color = "1 1 1 1" },
new CuiRectTransformComponent { AnchorMin = "0.5 0.5", AnchorMax = "0.5 0.5", OffsetMin = "76.648 216.907", OffsetMax = "162.199 235.893" }
}
},
new CuiElement
{
Name = "TitleInformationClose",
Parent = UI_TRADER,
Components = {
new CuiTextComponent { Text = "%UI_EXIT_BUTTON%", Font = "robotocondensed-regular.ttf", FontSize = 13, Align = TextAnchor.UpperCenter, Color = "1 1 1 1" },
new CuiRectTransformComponent { AnchorMin = "0.5 0", AnchorMax = "0.5 0", OffsetMin = "-136.344 40.032", OffsetMax = "136.344 61.568" }
}
},
{
new CuiPanel
{
CursorEnabled = false,
Image = { Color = "0.4156863 0.4196079 0.4352942 1" },
RectTransform = { AnchorMin = "0.5 0.5", AnchorMax = "0.5 0.5", OffsetMin = "-31.3 -193.46", OffsetMax = "25.777 -173.66" }
},
UI_TRADER,
"InfromationPagePanel"
},
};
AddInterface("UI_TRADER_NPC", container.ToJson());
}
private void BuildingTrader_Category()
{
CuiElementContainer container = new CuiElementContainer
{
{
new CuiButton
{
Button = { Color = "0 0 0 0", Command = $"func.alcohol category select {CategoryType.Equipment}" },
Text = { Text = "%UI_TITLE_EQUIPMENT%", Font = "robotocondensed-regular.ttf", FontSize = 17, Align = TextAnchor.MiddleCenter, Color = "%COLOR_EQUIPMENT%"},
RectTransform = { AnchorMin = "0.5 0.5", AnchorMax = "0.5 0.5", OffsetMin = "-121.284 300.498", OffsetMax = "1.982 323.902" }
},
UI_TRADER,
"CategoryTool"
},
{
new CuiButton
{
Button = { Color = "0 0 0 0", Command = $"func.alcohol category select {CategoryType.Exchanger}" },
Text = { Text = "%UI_TITLE_EXCHANGER%", Font = "robotocondensed-regular.ttf", FontSize = 17, Align = TextAnchor.MiddleCenter, Color = "%COLOR_EXCHANGER%" },
RectTransform = { AnchorMin = "0.5 0.5", AnchorMax = "0.5 0.5", OffsetMin = "15.843 300.499", OffsetMax = "116.445 323.901" }
},
UI_TRADER,
"CategoryTrade"
},
};
AddInterface("UI_TRADER_NPC_CATEGORY_MENU", container.ToJson());
}
private void BuildingTrader_Panel()
{
CuiElementContainer container = new CuiElementContainer
{
{
new CuiPanel
{
CursorEnabled = false,
Image = { Color = "0 0 0 0" },
RectTransform = { AnchorMin = "0.5 0.5", AnchorMax = "0.5 0.5", OffsetMin = "-183.682 -158.742", OffsetMax = "176.398 205.28" }
},
UI_TRADER,
UI_PANEL_ITEMS
},
new CuiElement
{
Name = "TitlePage",
Parent = "InfromationPagePanel",
Components = {
new CuiTextComponent { Text = "%COUNT_PAGE%", Font = "robotocondensed-regular.ttf", FontSize = 10, Align = TextAnchor.MiddleCenter, Color = "1 1 1 1" },
new CuiRectTransformComponent { AnchorMin = "0.5 0.5", AnchorMax = "0.5 0.5", OffsetMin = "-28.538 -9.9", OffsetMax = "28.539 9.9" }
}
},
{
new CuiButton
{
Button = { Color = "0.4156863 0.4196079 0.4352942 1", Command = "%COMMAND_BACK%" },
Text = { Text = "%BACK_BUTTON%", Font = "robotocondensed-regular.ttf", FontSize = 10, Align = TextAnchor.MiddleCenter, Color = "%COLOR_BACK%" },
RectTransform = { AnchorMin = "0.5 0.5", AnchorMax = "0.5 0.5", OffsetMin = "-182.78 -193.459", OffsetMax = "-126.069 -173.66" },
},
UI_TRADER,
"BackButton"
},
{
new CuiButton
{
Button = { Color = "0.4156863 0.4196079 0.4352942 1", Command = "%COMMAND_NEXT%" },
Text = { Text = "%NEXT_BUTTON%", Font = "robotocondensed-regular.ttf", FontSize = 10, Align = TextAnchor.MiddleCenter, Color = "%COLOR_NEXT%" },
RectTransform = { AnchorMin = "0.5 0.5", AnchorMax = "0.5 0.5", OffsetMin = "119.684 -193.459", OffsetMax = "176.396 -173.66" }
},
UI_TRADER,
"NextButton"
},
};
AddInterface("UI_TRADER_NPC_ITEMPANEL_TEMPLATE", container.ToJson());
}
private void BuildingTrader_ItemPanel()
{
CuiElementContainer container = new CuiElementContainer
{
{
new CuiPanel
{
CursorEnabled = false,
Image = { Color = "0 0 0 0" },
RectTransform = { AnchorMin = "0.5 0.5", AnchorMax = "0.5 0.5", OffsetMin = "%OFFSET_MIN%", OffsetMax = "%OFFSET_MAX%" }
},
UI_PANEL_ITEMS,
"PANEL_ITEM_%Y%"
},
new CuiElement
{
Name = "ItemContainerIn_%Y%",
Parent = "PANEL_ITEM_%Y%",
Components = {
new CuiRawImageComponent { Color = "1 1 1 1", Png = ImageUi.GetImage("UI_IQALCOHOL_BACK_ITEM_0") },
new CuiRectTransformComponent { AnchorMin = "0.5 0.5", AnchorMax = "0.5 0.5", OffsetMin = "-180.04 -31.5", OffsetMax = "-117.04 31.5" }
}
},
new CuiElement
{
Name = "Item",
Parent = "ItemContainerIn_%Y%",
Components = {
new CuiRawImageComponent { Color = "1 1 1 1", Png = "%BUY_ITEM_IMG%" },
new CuiRectTransformComponent { AnchorMin = "0.5 0.5", AnchorMax = "0.5 0.5", OffsetMin = "-24 -21.3", OffsetMax = "24 26.7" }
}
},
new CuiElement
{
Name = "Line",
Parent = "ItemContainerIn_%Y%",
Components = {
new CuiRawImageComponent { Color = "0.9647059 0.9019608 0.372549 1", Png = ImageUi.GetImage("UI_IQALCOHOL_LINE_0") },
new CuiRectTransformComponent { AnchorMin = "0.5 0.5", AnchorMax = "0.5 0.5", OffsetMin = "-23.267 -32.64", OffsetMax = "1.607 -28.64" }
}
},
new CuiElement
{
Name = "ItemContainerTo_%Y%",
Parent = "PANEL_ITEM_%Y%",
Components = {
new CuiRawImageComponent { Color = "1 1 1 1", Png = ImageUi.GetImage("UI_IQALCOHOL_BACK_ITEM_0") },
new CuiRectTransformComponent { AnchorMin = "0.5 0.5", AnchorMax = "0.5 0.5", OffsetMin = "-49.46 -31.5", OffsetMax = "13.54 31.5" }
}
},
new CuiElement
{
Name = "Item",
Parent = "ItemContainerTo_%Y%",
Components = {
new CuiRawImageComponent { Color = "1 1 1 1", Png = "%PRICE_ITEM_IMG%" },
new CuiRectTransformComponent { AnchorMin = "0.5 0.5", AnchorMax = "0.5 0.5", OffsetMin = "-24 -21.3", OffsetMax = "24 26.7" }
}
},
new CuiElement
{
Name = "Line",
Parent = "ItemContainerTo_%Y%",
Components = {
new CuiRawImageComponent { Color = "0.9647059 0.9019608 0.372549 1", Png = ImageUi.GetImage("UI_IQALCOHOL_LINE_0") },
new CuiRectTransformComponent { AnchorMin = "0.5 0.5", AnchorMax = "0.5 0.5", OffsetMin = "-23.267 -32.64", OffsetMax = "1.607 -28.64" }
}
},
};
AddInterface("UI_TRADER_NPC_ITEMPANEL", container.ToJson());
}
private void BuildingTrader_ItemPanel_ControllerAmount()
{
CuiElementContainer container = new CuiElementContainer
{
new CuiElement
{
Name = "ItemAmount_In_%Y%",
Parent = "ItemContainerIn_%Y%",
Components = {
new CuiTextComponent { Text = "<b>x%AMOUNT_IN%</b>", Font = "robotocondensed-regular.ttf", FontSize = 9, Align = TextAnchor.UpperRight, Color = "1 1 1 1" },
new CuiOutlineComponent { Color = "0 0 0 0.5", Distance = "1 -1" },
new CuiRectTransformComponent { AnchorMin = "0.5 0.5", AnchorMax = "0.5 0.5", OffsetMin = "-10.68 -29.946", OffsetMax = "26.548 -16.534" }
}
},
new CuiElement
{
Name = "ItemAmount_To_%Y%",
Parent = "ItemContainerTo_%Y%",
Components = {
new CuiTextComponent { Text = "<b>x%AMOUNT_TO%</b>", Font = "robotocondensed-regular.ttf", FontSize = 9, Align = TextAnchor.UpperRight, Color = "1 1 1 1" },
new CuiOutlineComponent { Color = "0 0 0 0.5", Distance = "1 -1" },
new CuiRectTransformComponent { AnchorMin = "0.5 0.5", AnchorMax = "0.5 0.5", OffsetMin = "-10.68 -29.946", OffsetMax = "26.548 -16.534" }
}
},
{
new CuiButton
{
Button = { Color = "%BUY_BUTTON_COLOR%", Command = "%BUY_BUTTON_COMMAND%" },
Text = { Text = "%BUY_TITLE%", Font = "robotocondensed-regular.ttf", FontSize = 10, Align = TextAnchor.MiddleCenter, Color = "1 1 1 1" },
RectTransform = { AnchorMin = "0.5 0.5", AnchorMax = "0.5 0.5", OffsetMin = "79.658 -15.471", OffsetMax = "164.803 15.471" }
},
"PANEL_ITEM_%Y%",
"ButtonBuy_%Y%"
},
{
new CuiButton
{
Button = { Color = "%COLOR_BTN%", Command = "%CMD_MINUS%" },
Text = { Text = "<b>-</b>", Font = "robotocondensed-regular.ttf", FontSize = 10, Align = TextAnchor.MiddleCenter, Color = "1 1 1 1" },
RectTransform = { AnchorMin = "0.5 0.5", AnchorMax = "0.5 0.5", OffsetMin = "64.427 -15.471", OffsetMax = "79.657 15.471" }
},
"PANEL_ITEM_%Y%",
"ButtonPlusAmount_%Y%"
},
{
new CuiButton
{
Button = { Color = "%COLOR_BTN%", Command = "%CMD_PLUS%"},
Text = { Text = "<b>+</b>", Font = "robotocondensed-regular.ttf", FontSize = 10, Align = TextAnchor.MiddleCenter, Color = "1 1 1 1" },
RectTransform = { AnchorMin = "0.5 0.5", AnchorMax = "0.5 0.5", OffsetMin = "164.805 -15.471", OffsetMax = "180.035 15.471" }
},
"PANEL_ITEM_%Y%",
"ButtonMinusAmount_%Y%"
},
};
AddInterface("UI_TRADER_NPC_ITEMPANEL_CONTROLLER_AMOUNT", container.ToJson());
}
}
private void OnServerSave()
{
PluginData.SaveData();
}
private void OnItemAddedToContainer(ItemContainer container, Item item)
{
if (_initiated == false)
return;
if (item.skin != _config.itemSettings.AlcoholItemSkinId)
return;
if (container == null)
return;
if (container.parent == null)
return;
if (container.parent.info.shortname != "smallwaterbottle")
return;
container.parent.skin = _config.itemSettings.AlcoholBottleSkinId;
}
private PluginConfig GetDefaultConfig()
{
return new PluginConfig
{
RareEffect = 50,
UseNPCSounds = true,
storeNpc = new PluginConfig.ShopStore
{
NPCShopSetting = new PluginConfig.ShopStore.NPCShop
{
Name = "Ivan",
userID = 19384,
Wear = new List<PluginConfig.ShopStore.NPCShop.ItemsNpc>
{
new PluginConfig.ShopStore.NPCShop.ItemsNpc
{
ShortName = "shoes.boots",
SkinId = 2570215282,
},
new PluginConfig.ShopStore.NPCShop.ItemsNpc
{
ShortName = "burlap.trousers",
SkinId = 2040706598,
},
new PluginConfig.ShopStore.NPCShop.ItemsNpc
{
ShortName = "burlap.shirt",
SkinId = 2040707769,
},
new PluginConfig.ShopStore.NPCShop.ItemsNpc
{
ShortName = "hat.boonie",
SkinId = 503202816,
},
}
},
ShopName = "Ivan Store - Sale and purchase of alcohol",
TurnedShop = new PluginConfig.ShopStore.TurnedShopSpawn
{
UseAirfield = true,
UseBanditTown = true,
UseCompound = true,
},
EquipmentCategory = new PluginConfig.ShopStore.CategorySettings
{
ItemsList = new List<PluginConfig.ShopStore.CategorySettings.ItemsPair>
{
new PluginConfig.ShopStore.CategorySettings.ItemsPair("water.barrel", 1, 2477175239, LanguageEn? "Fermentation barrel" : "Бродильная бочка", "scrap", 250, 0, String.Empty),
new PluginConfig.ShopStore.CategorySettings.ItemsPair("water.purifier", 1, 0, String.Empty, "scrap", 100, 0, String.Empty),
new PluginConfig.ShopStore.CategorySettings.ItemsPair("planter.large", 1, 0, String.Empty, "scrap", 30, 0, String.Empty),
new PluginConfig.ShopStore.CategorySettings.ItemsPair("planter.small", 1, 0, String.Empty, "scrap", 10, 0, String.Empty),
new PluginConfig.ShopStore.CategorySettings.ItemsPair("fertilizer", 1, 0, String.Empty, "scrap", 10, 0, String.Empty),
new PluginConfig.ShopStore.CategorySettings.ItemsPair("waterjug", 1, 0, String.Empty, "scrap", 5, 0, String.Empty),
new PluginConfig.ShopStore.CategorySettings.ItemsPair("black.berry", 3, 0, String.Empty, "scrap", 15, 0, String.Empty),
new PluginConfig.ShopStore.CategorySettings.ItemsPair("blue.berry", 3, 0, String.Empty, "scrap", 15, 0, String.Empty),
new PluginConfig.ShopStore.CategorySettings.ItemsPair("red.berry", 3, 0, String.Empty, "scrap", 15, 0, String.Empty),
new PluginConfig.ShopStore.CategorySettings.ItemsPair("yellow.berry", 3, 0, String.Empty, "scrap", 15, 0, String.Empty),
new PluginConfig.ShopStore.CategorySettings.ItemsPair("white.berry", 3, 0, String.Empty, "scrap", 15, 0, String.Empty),
}
},
ExchangerCategory = new PluginConfig.ShopStore.CategorySettings
{
ItemsList = new List<PluginConfig.ShopStore.CategorySettings.ItemsPair>
{
new PluginConfig.ShopStore.CategorySettings.ItemsPair("hazmatsuit.arcticsuit", 1, 0, String.Empty, "water", 2500, 2469834291, String.Empty),
new PluginConfig.ShopStore.CategorySettings.ItemsPair("rifle.ak.ice", 1, 0, String.Empty, "water", 3500, 2469834291, String.Empty),
new PluginConfig.ShopStore.CategorySettings.ItemsPair("stones", 1000, 0, String.Empty, "water", 350, 2469834291, String.Empty),
new PluginConfig.ShopStore.CategorySettings.ItemsPair("wood", 1000, 0, String.Empty, "water", 150, 2469834291, String.Empty),
new PluginConfig.ShopStore.CategorySettings.ItemsPair("metal.fragments", 1000, 0, String.Empty, "water", 700, 2469834291, String.Empty),
new PluginConfig.ShopStore.CategorySettings.ItemsPair("lowgradefuel", 500, 0, String.Empty, "water", 950, 2469834291, String.Empty),
new PluginConfig.ShopStore.CategorySettings.ItemsPair("sulfur", 1000, 0, String.Empty, "water", 1250, 2469834291, String.Empty),
new PluginConfig.ShopStore.CategorySettings.ItemsPair("metal.refined", 25, 0, String.Empty, "water", 950, 2469834291, String.Empty),
new PluginConfig.ShopStore.CategorySettings.ItemsPair("charcoal", 100, 0, String.Empty, "water", 750, 2469834291, String.Empty),
new PluginConfig.ShopStore.CategorySettings.ItemsPair("cloth", 500, 0, String.Empty, "water", 250, 2469834291, String.Empty),
new PluginConfig.ShopStore.CategorySettings.ItemsPair("leather", 100, 0, String.Empty, "water", 950, 2469834291, String.Empty),
new PluginConfig.ShopStore.CategorySettings.ItemsPair("targeting.computer", 1, 0, String.Empty, "water", 650, 2469834291, String.Empty),
new PluginConfig.ShopStore.CategorySettings.ItemsPair("cctv.camera", 1, 0, String.Empty, "water", 450, 2469834291, String.Empty),
}
}
}
};
}
private void DrawUI_DrunkTimer(BasePlayer player, String color, Single timeLeft)
{
if (_initiated == false)
return;
String gui = DrunkTimer;
gui = gui.Replace("{T}", FormatTime(TimeSpan.FromSeconds(timeLeft)));
gui = gui.Replace("{C}", GetColor(color));
CuiHelper.DestroyUi(player, UI_LayerTimer);
CuiHelper.AddUi(player, gui);
}
private static IEnumerator DownloadImage(String url, Signage sign, String name)
{
UnityWebRequest www = UnityWebRequest.Get(url);
yield return www.SendWebRequest();
if (_plugin == null)
yield break;
if (www.isNetworkError || www.isHttpError)
{
_plugin.PrintWarning(String.Format("Image download error! Error: {0}, Image name: {1}", www.error, name));
www.Dispose();
yield break;
}
Texture2D texture = new Texture2D(2, 2);
texture.LoadImage(www.downloadHandler.data);
if (texture != null)
{
Byte[] bytes = texture.EncodeToPNG();
String image = FileStorage.server.Store(bytes, FileStorage.Type.png, CommunityEntity.ServerInstance.net.ID).ToString();
Int32 size = Math.Max(sign.paintableSources.Length, 1);
if (sign.textureIDs == null || sign.textureIDs.Length != size)
{
Array.Resize(ref sign.textureIDs, size);
}
if (sign.textureIDs[0] > 0)
{
// ... [Code preview truncated due to length. Full source in attached file] ...