C#:
using Oxide.Core;
using Rust;
using System;
using UnityEngine;
using System.Collections.Generic;
using Oxide.Core.Libraries;
using System.Text;
using UnityEngine.Networking;
using System.Drawing;
using Oxide.Core.Plugins;
using Oxide.Game.Rust.Cui;
using System.Collections;
using System.Linq;
using VLB;
using Newtonsoft.Json;
using Network;
namespace Oxide.Plugins
{
[Info("IQAlcoholFarm", "Mercury", "1.1.12")]
[Description("IQAlcoholFarm")]
internal class IQAlcoholFarm : RustPlugin
{
private void DestroyAllUi(BasePlayer player)
{
CuiHelper.DestroyUi(player, UI_Layer);
CuiHelper.DestroyUi(player, UI_LayerFade);
CuiHelper.DestroyUi(player, UI_LayerTimer);
}
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)
{
FileStorage.server.RemoveExact(sign.textureIDs[0], FileStorage.Type.png, sign.net.ID, 0U);
}
UInt32 idinstorage = FileStorage.server.Store(bytes, FileStorage.Type.png, sign.net.ID);
sign.textureIDs[0] = idinstorage;
sign.SendNetworkUpdate();
UnityEngine.Object.DestroyImmediate(texture);
}
www.Dispose();
yield break;
}
private readonly String[] AlcoholShakeEffect = new[]
{
"assets/bundled/prefabs/fx/takedamage_generic.prefab",
"assets/bundled/prefabs/fx/screen_land.prefab",
"assets/bundled/prefabs/fx/screen_jump.prefab",
"assets/prefabs/tools/jackhammer/effects/strike_screenshake.prefab",
"assets/prefabs/weapons/cake/effects/strike_screenshake.prefab",
"assets/prefabs/weapons/halloween/butcher knife/effects/strike_screenshake.prefab",
"assets/prefabs/weapons/halloween/pitchfork/effects/strike_screenshake.prefab",
"assets/prefabs/weapons/halloween/sickle/effects/strike_screenshake.prefab",
"assets/prefabs/weapons/hatchet/effects/strike_screenshake.prefab",
"assets/prefabs/weapons/knife/effects/strike_screenshake.prefab",
"assets/bundled/prefabs/fx/player/drown.prefab",
};
private void InitControllers()
{
foreach (KeyValuePair<NetworkableId, BaseNetworkable> keyValuePair in BaseNetworkable.serverEntities.entityList)
{
BaseNetworkable entity = keyValuePair.Value;
if (entity is LiquidContainer)
{
LiquidContainer cont = ((LiquidContainer)entity);
Item item = cont.inventory.GetSlot(0);
if (item != null && item.skin != 0)
{
cont.ClearConnections();
}
InitBarrel(entity);
}
}
Puts($"Loaded: {BarrelController.ActiveControllers.Count} custom barrels custom purifiers!");
}
private class BarrelController : MonoBehaviour
{
public static List<BarrelController> ActiveControllers = new List<BarrelController>();
public static List<UInt64> ActiveControllersIds = new List<UInt64>();
private StashContainer _stash;
private LiquidContainer _barrel;
private readonly Single processTickTime = _config.fermentationSettings.BarrelProcessTick;
private readonly Int32 tickConsume = _config.fermentationSettings.BarrelInputTick;
private readonly Int32 tickOutput = _config.fermentationSettings.BarrelOutputTick;
private readonly Int32 barrelCapacity = _config.fermentationSettings.BarrelCapacity;
private readonly String[] acceptAbleItems =
{
"black.berry",
"blue.berry",
"green.berry",
"red.berry",
"white.berry",
"yellow.berry",
};
public UInt64 GetStashId()
{
if (_stash == null)
return 0;
return _stash.net.ID.Value;
}
private void Awake()
{
_barrel = GetComponent<LiquidContainer>();
if (_barrel == null)
{
Debug.LogError($"[{_plugin.Name}] Error! Barrel not found! Deleting...");
Destroy(this);
return;
}
_barrel.maxStackSize = barrelCapacity;
_stash = _barrel.GetComponentInChildren<StashContainer>();
if (_stash == null)
{
Debug.LogError($"[{_plugin.Name}] Error! Stash not found! Deleting...");
Destroy(this);
return;
}
_stash.SetMaxHealth(999999);
_stash.SetHealth(999999);
RegisterBarrel(this);
if (ActiveControllersIds.Contains(_barrel.net.ID.Value) == false)
ActiveControllersIds.Add(_barrel.net.ID.Value);
_stash.inventory.canAcceptItem += CanAcceptItem;
foreach (Item item in _stash.inventory.itemList.ToArray())
{
if (acceptAbleItems.Contains(item.info.shortname) == false)
{
Transform stashTransform = _stash.transform;
item.Drop(stashTransform.position, stashTransform.forward, Quaternion.identity);
continue;
}
}
InvokeRepeating(nameof(ProcessTick), processTickTime, processTickTime);
InvokeRepeating(nameof(PlayProcessEffect), 1f, 1800);
//PhysicsChangeCancel();
InvokeRepeating(nameof(PhysicsChangeCancel), 1f, 1f);
}
private void PhysicsChangeCancel()
{
if (_stash.IsInvoking(new Action(_stash.DoOccludedCheck)) == false)
return;
_stash.CancelInvoke(new Action(_stash.DoOccludedCheck));
//_stash.Invoke(new Action(_stash.DoOccludedCheck), 604800f);
}
private void PlayProcessEffect()
{
Vector3 pos = _barrel.transform.position + new Vector3(0, 0.5f) + _barrel.transform.forward / 2f;
Effect.server.Run(AlcoholWortProcessEffect, pos, Vector3.zero);
}
private Boolean CanAcceptItem(Item item, Int32 i)
{
if (acceptAbleItems.Contains(item.info.shortname))
{
foreach (PluginConfig.ShopStore.CategorySettings.ItemsPair ItemPair in _config.storeNpc.EquipmentCategory.ItemsList)
if (ItemPair.BuyItems.Shortname.Equals(item.info.shortname) && ItemPair.BuyItems.SkinID != item.skin)
return false;
return true;
}
return false;
}
private void OnDestroy()
{
ActiveControllers.Remove(this);
if (_stash != null)
{
_stash.inventory.canAcceptItem -= CanAcceptItem;
}
if (_barrel == null || _barrel.net == null)
return;
ActiveControllersIds.Remove(_barrel.net.ID.Value);
}
private void ProcessTick()
{
Int32 TickOut = tickOutput;
if (_stash.inventory.itemList.Count <= 0)
return;
Item item = _barrel.GetLiquidItem();
if (item?.skin == _config.itemSettings.AlcoholItemSkinId)
return;
Int32 amount = (item?.amount ?? 0);
if (barrelCapacity <= amount)
return;
Item itemToConsume = _stash.inventory.itemList.Last();
TickOut = (tickOutput / tickConsume) * (itemToConsume.amount < tickConsume ? itemToConsume.amount : tickConsume);
itemToConsume.UseItem(tickConsume);
itemToConsume.MarkDirty();
if (item == null)
{
Item water = ItemManager.CreateByName("water", TickOut == 0 ? 1 : TickOut, _config.itemSettings.WortItemSkinId);
if (water == null)
return;
water.MoveToContainer(_barrel.inventory);
return;
}
item.amount += TickOut;
if (item.amount >= barrelCapacity)
item.amount = barrelCapacity;
item.MarkDirty();
}
}
private void ValidateConfig()
{
if (Interface.Oxide.CallHook("OnConfigValidate") != null)
{
PrintWarning("Using default configuration...");
_config = GetDefaultConfig();
}
}
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 System.Object CanBradleyApcTarget(BradleyAPC apc, BaseEntity entity)
{
if (_initiated == false)
return null;
if (apc == null || entity == null) return null;
foreach (BradleyAPC.TargetInfo Targets in apc.targetList.Where(ent => ent.entity != null && ent.entity.OwnerID == 199949458))
NextTick(() => { apc.targetList.Remove(Targets); });
return null;
}
/// <summary>
/// 1.0.10
/// Изменения :
/// - Исправление после обновления игры
/// </summary>
private Boolean FullLoadedNPC = false;
private const String UI_LayerTimer = "UI_AlcoholFarm.Timer";
private void SetupBarrel(BaseEntity entity)
{
BaseEntity stashEntity = GameManager.server.CreateEntity("assets/prefabs/deployable/small stash/small_stash_deployed.prefab");
if (stashEntity == null)
{
PrintError("Failed to spawn small stash on barrel!");
return;
}
stashEntity.Spawn();
stashEntity.SetParent(entity, false);
stashEntity.transform.localPosition += new Vector3(-0.365f, 1.14f, 0.42f);
stashEntity.transform.localRotation = Quaternion.Euler(new Vector3(90f, 0f, 0));
entity.gameObject.AddComponent<BarrelController>();
}
private const String SignImgLeft = "https://i.imgur.com/Vq6uJgI.png";
private Boolean IsAirfield()
{
return _config.storeNpc.TurnedShop.UseAirfield && Airfield != null;
}
private void BuyItem(BasePlayer player, PluginConfig.ShopStore.CategorySettings.ItemsPair BuyItem, CategoryType category, Int32 Page, Int32 Amount)
{
TakeItems(player, BuyItem, Amount: Amount);
player.GiveItem(BuyItem.BuyItems.ToItem(Amount));
DrawUI_Items(player, category, Page);
}
private void FullLoad()
{
_initiated = true;
InitControllers();
PluginData.LoadData();
}
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 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 void DrawUI_Items(BasePlayer player, CategoryType categoryType = CategoryType.Equipment, Int32 Page = 0)
{
Int32 Y = 0;
Int32 YOffset = 75;
List<PluginConfig.ShopStore.CategorySettings.ItemsPair> CategoryItems = categoryType == CategoryType.Equipment ? _config.storeNpc.EquipmentCategory.ItemsList : _config.storeNpc.ExchangerCategory.ItemsList;
foreach (PluginConfig.ShopStore.CategorySettings.ItemsPair Category in CategoryItems.Skip(Page * 5).Take(5))
{
CuiHelper.DestroyUi(player, $"PANEL_ITEM_{Y}");
String Interface = InterfaceBuilder.GetInterface("UI_TRADER_NPC_ITEMPANEL");
if (Interface == null) return;
Interface = Interface.Replace("%Y%", $"{Y}");
Interface = Interface.Replace("%OFFSET_MIN%", $"-180.04 {119.011 - (Y * YOffset)}");
Interface = Interface.Replace("%OFFSET_MAX%", $"180.04 {182.011 - (Y * YOffset)}");
CuiHelper.AddUi(player, Interface);
InterfaceBuilder.BuildingTrader_Items(player,
ItemManager.FindItemDefinition(Category.BuyItems.Shortname).itemid, Category.BuyItems.SkinID,
ItemManager.FindItemDefinition(Category.PriceItems.Shortname).itemid, Category.PriceItems.SkinID, Y);
DrawUI_Items_AmountController(player, Y, Category, Page, categoryType: categoryType);
Y++;
}
}
private static readonly String[] AlcoholColorGradient = new[]
{
"#FFFFFF",
"#F7D358",
"#FAAC58",
"#FA8258",
"#FA5858",
"#B40404",
};
private object OnWireConnect(BasePlayer player, IOEntity entity1, Int32 inputs, IOEntity entity2, Int32 outputs)
{
if (_initiated == false)
return null;
LiquidContainer liquid1 = entity1 as LiquidContainer;
if (liquid1 != null)
{
Item item1 = liquid1.inventory.GetSlot(0);
if (item1 != null && item1.skin != 0)
return false;
}
LiquidContainer liquid2 = entity2 as LiquidContainer;
if (liquid2 != null)
{
Item item2 = liquid2.inventory.GetSlot(0);
if (item2 != null && item2.skin != 0)
return false;
}
if (BarrelController.ActiveControllersIds.Exists(x => x == entity1.net.ID.Value || x == entity2.net.ID.Value))
return false;
return null;
}
private void GetSounds()
{
if (!_config.UseNPCSounds) return;
timer.Once(3f, () =>
{
if (RenderSounds.Values != null && RenderSounds.Values.Count != 0) return;
PrintWarning(LanguageEn ? "Loading sounds.." : "Загружаем звуки..");
try
{
webrequest.Enqueue($"http://iqsystem.skyplugins.ru/iqalcohol/getsound/W5fgSD3dfVBxc", null, (code, response) =>
{
switch (code)
{
case 404:
{
PrintError($"ERROR #63494985 {response} | ERROR #:545445 (Discord - Mercury#5212)");
_initiated = false;
break;
}
case 503:
{
PrintError($"ERROR #45445 Your plugin version is outdated!Upgrade to the latest version! (Discord - Mercury#5212)");
_initiated = false;
break;
}
case 200:
{
Dictionary<String, List<Byte[]>> obj = JsonConvert.DeserializeObject<Dictionary<String, List<Byte[]>>>(response);
RenderSounds = obj;
WriteData();
PrintWarning(LanguageEn ? "Successful data acquisition" : "Звук успешно создан!");
break;
}
}
}, this, RequestMethod.GET);
}
catch (Exception e)
{
PrintError($"ERROR #8573 An error occurred while connecting, please inform the developer Discord - Mercury#5212\nError : {e}");
}
PrintWarning(LanguageEn ? "Sounds uploaded successfully.." : "Звуки загружены успешно..");
});
}
private System.Object OnEntityTakeDamage(BaseEntity entity, HitInfo info)
{
if (_initiated == false)
return null;
if (info == null || entity == null)
return null;
if (entity.OwnerID == 199949458) return false;
return null;
}
private System.Object OnWaterCollect(WaterCatcher waterCatcher)
{
if (_initiated == false)
return null;
Item item = waterCatcher.inventory.GetSlot(0);
if (item == null)
return null;
if (item.skin == _config.itemSettings.AlcoholItemSkinId || item.skin == _config.itemSettings.WortItemSkinId)
{
return false;
}
return null;
}
private System.Object OnLiquidVesselFill(BaseLiquidVessel liquidVessel, BasePlayer player, LiquidContainer facingLiquidContainer)
{
if (_initiated == false)
return null;
Item item = liquidVessel.GetItem()?.contents?.GetSlot(0);
if (item == null)
return null;
if ((item.skin == _config.itemSettings.AlcoholItemSkinId || item.skin == _config.itemSettings.WortItemSkinId))
{
return false;
}
return null;
}
protected override void LoadDefaultConfig()
{
_config = GetDefaultConfig();
}
private System.Object CanHideStash(BasePlayer player, StashContainer stash)
{
if (_initiated == false)
return null;
if (BarrelController.ActiveControllers.Exists(x => x.GetStashId() == stash.net.ID.Value))
return false;
return null;
}
private class DrunkPlayer
{
public String CurrectFade = AlcoholBlur[0];
[JsonIgnore] private Boolean _playerFound = false;
public String CurrectColor = AlcoholColorGradient[0];
public UInt64 UserId = 0;
public Single DrunkRemaining = 0;
[JsonIgnore] private BasePlayer _player;
public Single ModifiersUpdate = 0;
[JsonIgnore]
public BasePlayer Player
{
get
{
if (_playerFound == false)
{
_player = BasePlayer.activePlayerList.FirstOrDefault(x => x != null && x.userID == UserId);
if (_player != null)
{
_playerFound = true;
}
else
{
_data.DrunkPlayers.Remove(this);
}
}
return _player;
}
}
}
public static String GetColor(String hex, Single alpha = 1f)
{
if (hex.Length != 7) hex = "#FFFFFF";
if (alpha < 0 || alpha > 1f) alpha = 1f;
System.Drawing.Color color = ColorTranslator.FromHtml(hex);
Single r = Convert.ToInt16(color.R) / 255f;
Single g = Convert.ToInt16(color.G) / 255f;
Single b = Convert.ToInt16(color.B) / 255f;
return $"{r} {g} {b} {alpha}";
}
void WriteData()
{
Oxide.Core.Interface.Oxide.DataFileSystem.WriteObject("IQSystem/IQAlcoholFarm/Sounds", RenderSounds, true);
}
private new void LoadDefaultMessages()
{
lang.RegisterMessages(new Dictionary<String, String>
{
["NO_RESOURCES_USER"] = "<b>NOT ENOUGHT</b>",
["YES_RESOURCES_USER"] = "<b>BUY</b>",
["UI_BACK_BUTTON"] = "<b>BACK</b>",
["UI_NEXT_BUTTON"] = "<b>NEXT</b>",
["UI_TITLE_EQUIPMENT"] = "<b>EQUIPMENT</b>",
["UI_TITLE_EXCHANGER"] = "<b>EXCHANGER</b>",
["UI_TITLE_ITEM"] = "<b>PRODUCT</b>",
["UI_TITLE_PRICE"] = "<b>PRICE</b>",
["UI_TITLE_AMOUNT"] = "<b>NUMBER</b>",
["UI_EXIT_BUTTON"] = "CLICK ON AN EMPTY SPACE TO EXIT",
}, this);
lang.RegisterMessages(new Dictionary<String, String>
{
["NO_RESOURCES_USER"] = "<b>НЕДОСТАТОЧНО</b>",
["YES_RESOURCES_USER"] = "<b>КУПИТЬ</b>",
["UI_BACK_BUTTON"] = "<b>НАЗАД</b>",
["UI_NEXT_BUTTON"] = "<b>ВПЕРЕД</b>",
["UI_TITLE_EQUIPMENT"] = "<b>ОБОРУДОВАНИЕ</b>",
["UI_TITLE_EXCHANGER"] = "<b>ОБМЕННИК</b>",
["UI_TITLE_ITEM"] = "<b>ТОВАР</b>",
["UI_TITLE_PRICE"] = "<b>ЦЕНА</b>",
["UI_TITLE_AMOUNT"] = "<b>КОЛИЧЕСТВО</b>",
["UI_EXIT_BUTTON"] = "НАЖМИТЕ НА ПУСТОЕ МЕСТО ДЛЯ ВЫХОДА",
}, this, "ru");
}
private void OnServerInitialized()
{
PrintWarning("\n-----------------------------\n" +
" Author - https://devplugins.ru/\n" +
" VK - https://vk.com/dev.plugin\n" +
" Discord - https://discord.gg/eHXBY8hyUJ\n" +
"-----------------------------");
_plugin = this;
BanditTown = TerrainMeta.Path.Monuments.FirstOrDefault(p => p.name.ToLower().Contains("bandit_town"));
Compound = TerrainMeta.Path.Monuments.FirstOrDefault(p => p.name.ToLower().Contains("compound"));
Airfield = TerrainMeta.Path.Monuments.FirstOrDefault(p => p.name.ToLower().Contains("airfield"));
if (_config.itemSettings.AlcoholBottleSkinId == 0)
{
Unsubscribe(nameof(OnItemAddedToContainer));
Unsubscribe(nameof(OnItemRemovedFromContainer));
}
if (IsPVE())
Unsubscribe(nameof(OnEntityTakeDamage));
StartPluginLoad();
}
private ItemContainer.CanAcceptResult? CanAcceptItem(ItemContainer container, Item item, Int32 targetPos)
{
if (_initiated == false)
return null;
if (item.skin != _config.itemSettings.AlcoholItemSkinId && item.skin != _config.itemSettings.WortItemSkinId)
return null;
IOEntity ownerEnt = container.entityOwner as IOEntity;
if (ownerEnt == null)
return null;
ownerEnt.ClearConnections();
return null;
}
[ChatCommand("remove.custom.npc")]
void RemoveCustomPosIvan(BasePlayer player, String cmd, String[] args)
{
if (!player.IsAdmin) return;
if (!_plugin.FullLoadedNPC)
{
SendReply(player, LanguageEn ? "Wait for the plugin to be fully initialized" : "Дождитесь полной инициализации плагина");
return;
}
if (args == null || args.Length < 1)
{
SendReply(player, LanguageEn ? "You didn't specify a name for the position" : "Вы не указали название для позиции");
return;
}
String NamePos = args[0];
if (String.IsNullOrWhiteSpace(NamePos))
{
SendReply(player, LanguageEn ? "You didn't specify a name for the position" : "Вы не указали название для позиции");
return;
}
if (!CustomPosNPC.ContainsKey(NamePos))
{
SendReply(player, LanguageEn ? "A position with this name does not exist" : "Позиция с таким названием не существует");
return;
}
CustomNpcController npcController = NPCList.FirstOrDefault(x => x.transform.position == CustomPosNPC[NamePos].LocalPosition);
UnityEngine.Object.DestroyImmediate(npcController);
Single radius = 5.0f;
foreach (BaseEntity ent in MonumentEntities.Where(x => !x.IsDestroyed))
{
Single distance = Vector3.Distance(ent.transform.position, CustomPosNPC[NamePos].LocalPosition);
if (distance <= radius)
{
ent.Kill();
}
}
CustomPosNPC.Remove(NamePos);
SendReply(player, LanguageEn ? "The position has been successfully deleted!" : "Позиция успешно удалена!");
}
private void DestroyControllers()
{
for (Int32 i = BarrelController.ActiveControllers.Count - 1; i >= 0; i--)
{
BarrelController activeController = BarrelController.ActiveControllers[i];
if(activeController != null)
UnityEngine.Object.Destroy(activeController);
}
}
private Item OnItemSplit(Item item, int amount)
{
if (_initiated == false)
return null;
if (plugins.Find("Stacks") || plugins.Find("CustomSkinsStacksFix") || plugins.Find("SkinBox")) return null;
if(item.info.shortname == "smallwaterbottle" && _config.itemSettings.AlcoholBottleSkinId == item.skin)
{
Item x = ItemManager.CreateByPartialName(item.info.shortname, amount);
x.skin = _config.itemSettings.AlcoholBottleSkinId;
x.amount = amount;
item.amount -= amount;
item.MarkDirty();
return x;
}
if (item.info.shortname == _config.BarrelItem.ShortName && _config.BarrelItem.SkinId == item.skin)
{
Item x = ItemManager.CreateByPartialName(item.info.shortname, amount);
x.name = _config.BarrelItem.DisplayName;
x.skin = _config.BarrelItem.SkinId;
x.amount = amount;
item.amount -= amount;
item.MarkDirty();
return x;
}
return null;
}
private List<CustomNpcController> NPCList = new List<CustomNpcController>();
private void OnEntitySpawned(WaterPurifier entity)
{
if (_initiated == false)
return;
if (entity is PoweredWaterPurifier)
return;
entity.maxStackSize = _config.fermentationSettings.PurifierCapacity;
}
private void OnAlcoholDrink(BasePlayer player, Item item, Int32 amountToUse)
{
if (_initiated == false)
return;
Single time = (amountToUse * _config.drinkedSettings.AlcoholDrinkTime) / _config.drinkedSettings.AlcoholDrinkAmount;
DrunkPlayer drunkPlayer = _data.DrunkPlayers.Find(x => x.Player.userID == player.userID);
if (drunkPlayer == null)
{
drunkPlayer = new DrunkPlayer
{
UserId = player.userID
};
drunkPlayer.DrunkRemaining += 5f;
_data.DrunkPlayers.Add(drunkPlayer);
DrawUI_DrunkBlock(player, drunkPlayer.CurrectColor, drunkPlayer.DrunkRemaining);
DrawUI_DrunkAFade(drunkPlayer.Player, drunkPlayer.CurrectFade);
if (_data.DrunkPlayers.Count == 1)
ServerMgr.Instance.StartCoroutine(PlayersUpdate());
}
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);
}
drunkPlayer.DrunkRemaining += time;
DrawUI_DrunkTimer(player, drunkPlayer.CurrectColor, drunkPlayer.DrunkRemaining);
UpdateModifiers(drunkPlayer);
if (drunkPlayer.DrunkRemaining >= _config.drinkedSettings.AlcoholDrinkLimit)
{
drunkPlayer.Player.modifiers.RemoveAll();
ExecuteNegativeEffect(player);
}
}
object CanStackItem(Item item, Item targetItem)
{
if (_initiated == false)
return null;
if (item.skin != targetItem.skin) return false;
return null;
}
private System.Object OnPlayerAddModifiers(BasePlayer player, Item item, ItemModConsumable consumable)
{
if (item.skin == _config.itemSettings.AlcoholItemSkinId)
{
Int32 oldAmount = item.amount;
NextTick(() =>
{
Int32 consumed = Math.Abs(item.amount - oldAmount);
OnAlcoholDrink(player, item, consumed);
});
return false;
}
if (item.skin == _config.itemSettings.WortItemSkinId)
{
ExecuteNegativeEffect(player);
return false;
}
return null;
}
private Quaternion GetMonumentRotation(Single y, MonumentInfo monument, Single x)
{
Quaternion monumentQT = Quaternion.Euler(monument.transform.rotation.eulerAngles.x - x, monument.transform.rotation.eulerAngles.y - y, 0f);
return monumentQT;
}
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 DrawUI_DrunkAFade(BasePlayer player, String fade)
{
if (_initiated == false)
return;
CuiHelper.DestroyUi(player, UI_LayerFade);
CuiHelper.AddUi(player, DrunkFade.Replace("{C}", fade));
}
private void Init() => ReadData();
private String DrunkFade;
private struct CustomItem
{
public CustomItem(String displayName, String shortName, UInt64 skinId)
{
DisplayName = displayName;
ShortName = shortName;
SkinId = skinId;
}
public String DisplayName;
public String ShortName;
public UInt64 SkinId;
public Item ToItem(Int32 amount = 1)
{
Item item = ItemManager.CreateByName(ShortName, amount, SkinId);
if (item != null && String.IsNullOrEmpty(DisplayName) == false)
item.name = DisplayName;
return item;
}
public Boolean CompareTo(Item item)
{
return SkinId == item?.skin && ShortName == item?.info.shortname;
}
}
private String GetImage(String fileName, UInt64 skin = 0)
{
String imageId = (String)plugins.Find("ImageLibrary").CallHook("ImageUi.GetImage", fileName, skin);
if (!String.IsNullOrEmpty(imageId))
return imageId;
return String.Empty;
}
private System.Object CanLootEntity(BasePlayer player, StorageContainer container)
{
if (_initiated == false)
return null;
if (container.skinID == 23129547)
{
DrawUI_Trade_Main(player);
return false;
}
return null;
}
private void UpdateModifiers(DrunkPlayer drunkPlayer)
{
List<ModifierDefintion> modifiersToAdd = new List<ModifierDefintion>();
for (Int32 i = 0; i < _config.ModifierDefintions.Count; i++)
{
ModifierDefintionConfig modif = _config.ModifierDefintions[i];
if (modif.MinTime > drunkPlayer.DrunkRemaining)
continue;
if (drunkPlayer.ModifiersUpdate < modif.MinTime)
drunkPlayer.ModifiersUpdate = modif.MinTime;
ModifierDefintion modifDef = modif.GetDef();
modifDef.duration = drunkPlayer.DrunkRemaining;
modifiersToAdd.Add(modifDef);
}
if (modifiersToAdd.Count < 1)
return;
drunkPlayer.Player.modifiers.Add(modifiersToAdd);
}
private enum CategoryType
{
Equipment,
Exchanger,
}
private System.Object OnNpcTarget(BaseAnimalNPC animal, BasePlayer target)
{
if (_initiated == false)
return null;
if (animal == null || target == null) return null;
if (target.OwnerID == 199949458)
return false;
return null;
}
private static IQAlcoholFarm _plugin;
private static void RegisterBarrel(BarrelController barrelController)
{
if (BarrelController.ActiveControllers.Contains(barrelController) == false)
BarrelController.ActiveControllers.Add(barrelController);
}
protected override void SaveConfig()
{
Config.WriteObject(_config);
}
public static StringBuilder sb = new StringBuilder();
private const String SignImgRight = "https://i.imgur.com/ZyaqUtT.png";
private void ClearEnt(MonumentInfo monument, Vector3 Pos)
{
List<BaseEntity> obj = new List<BaseEntity>();
Int32 Mask = LayerMask.GetMask("AI", "Player (Server)", "Construction", "Deployable", "Deployed", "Ragdoll", "Transparent");
Vis.Entities(Pos, 1000f, obj, Mask);
foreach (BaseEntity item in obj.Where(x => x.OwnerID == 199949458 || x.skinID == 199949458))
{
if (item == null)
continue;
item.Kill(BaseNetworkable.DestroyMode.None);
}
}
private static Double GetCurrentTime()
{
return new TimeSpan(DateTime.UtcNow.Ticks).TotalSeconds;
}
private Boolean IsPVE()
{
return TruePVE != null || NextGenPVE != null || Imperium != null;
}
private static PluginData _data;
private const String AlcoholConsumeEffect = "assets/bundled/prefabs/fx/gestures/drink_vomit.prefab";
private String FormatTime(TimeSpan timespan)
{
return String.Format(timespan.TotalHours >= 1 ? "{2:00}:{0:00}:{1:00}" : "{0:00}:{1:00}", timespan.Minutes, timespan.Seconds, System.Math.Floor(timespan.TotalHours));
}
protected override void LoadConfig()
{
base.LoadConfig();
try
// ... [Code preview truncated due to length. Full source in attached file] ...