C#:
// Все права принадлежат дискорд сообществу https://discord.gg/VgNHPpNrz6
using System.Linq;
using Oxide.Core.Plugins;
using UnityEngine;
using Oxide.Core;
using Newtonsoft.Json;
using System.Collections.Generic;
using System;
using Oxide.Game.Rust.Cui;
namespace Oxide.Plugins {
/* Плагин был разыгран дискордом https://discord.gg/8CWJadmA5w */
[Info("XRPG", "https://discord.gg/8CWJadmA5w", "1.1.3")]
class XRPG : RustPlugin {
private void OnNewSave() {
timer.Once(10, () => {
if(config.Setting.ClearData) {
StoredData.Clear();
SaveData();
}
}
);
}
private class RPGConfig {
[JsonProperty("Общее")]
public SSetting Setting = new SSetting();
public static RPGConfig GetNewConfiguration() {
return new RPGConfig {
Panel = new PanelSetting {
AnchorMin = "1 0", AnchorMax = "1 0", OffsetMin = "-402 16", OffsetMax = "-210 98", Progress = true
}
, Setting = new SSetting {
Slow = false, Panel = true, Messages = true, ClearData = false, Boost = 1.0f, TextSize = 13, TextSizeNotify = 10, BlockItem = new List<string> {
"jackhammer", "chainsaw"
}
}
, Permisssion = new Dictionary<string, Permissions> {
["xrpg.default"]
= new Permissions {
WoodRate = 12.5f, OreRate = 12.5f, AnimalRate = 12.5f, Boost = 1.25f
}
}
, Wood = new WoodSetting {
RateMax = 10.0f, RateStart = 2.5f, Bonus = true, Pickup = true, Item = new Dictionary<string, float> {
["wood"]
= 0.05f, ["charcoal"] = 0.05f
}
}
, Ore = new OreSetting {
RateMax = 10.0f, RateStart = 1.75f, Bonus = true, Pickup = true, Item = new Dictionary<string, float> {
["stones"]
= 0.05f, ["metal.ore"] = 0.05f, ["metal.fragments"] = 0.05f, ["sulfur.ore"] = 0.05f, ["sulfur"] = 0.05f
}
}
, Animal = new AnimalSetting {
RateMax = 10.0f, RateStart = 1.5f, Bonus = true, Pickup = true, Kill = true, Item = new Dictionary<string, float> {
["cloth"]
= 0.05f, ["leather"] = 0.05f, ["bone.fragments"] = 0.05f, ["fat.animal"] = 0.05f
}
, Animal = new Dictionary<string, float> {
["boar"]
= 0.75f, ["bear"] = 0.75f, ["stag"] = 0.75f, ["wolf"] = 0.75f, ["testridablehorse"] = 0.75f, ["chicken"] = 0.75f
}
}
}
;
}
internal class WoodSetting {
[JsonProperty("Максимальные рейты лесоруба")]
public float RateMax;
[JsonProperty("Стартовые рейты лесоруба")]
public float RateStart;
[JsonProperty("Включить прокачку рейтов лесоруба добывая ресурсы")]
public bool Bonus;
[JsonProperty("Включить прокачку рейтов лесоруба подбирая ресурсы")]
public bool Pickup;
[JsonProperty("Ресурсы за добычу/подбор которых начислять рейты лесоруба | Ресурсы на которые будут действовать рейты лесоруба")]
public Dictionary<string, float> Item = new Dictionary<string, float>();
}
[JsonProperty("Настройка пермишенов")]
public Dictionary<string, Permissions> Permisssion = new Dictionary<string, Permissions>();
internal class Permissions {
[JsonProperty("Максимальные рейты лесоруба")]
public float WoodRate;
[JsonProperty("Максимальные рейты рудокопа")]
public float OreRate;
[JsonProperty("Максимальные рейты охотника")]
public float AnimalRate;
[JsonProperty("Множитель прокачки рейтов")]
public float Boost;
}
[JsonProperty("Расположение мини-панели")]
public PanelSetting Panel = new PanelSetting();
[JsonProperty("Настройка рудокопа")]
public OreSetting Ore = new OreSetting();
internal class AnimalSetting {
[JsonProperty("Максимальные рейты охотника")]
public float RateMax;
[JsonProperty("Стартовые рейты охотника")]
public float RateStart;
[JsonProperty("Включить прокачку рейтов охотника добывая ресурсы")]
public bool Bonus;
[JsonProperty("Включить прокачку рейтов охотника подбирая ресурсы")]
public bool Pickup;
[JsonProperty("Включить прокачку рейтов охотника убивая животных")]
public bool Kill;
[JsonProperty("Ресурсы за добычу/подбор которых начислять рейты охотника | Ресурсы на которые будут действовать рейты охотника")]
public Dictionary<string, float> Item = new Dictionary<string, float>();
[JsonProperty("Животные за убийство которых начислять рейты охотника")]
public Dictionary<string, float> Animal = new Dictionary<string, float>();
}
[JsonProperty("Настройка лесоруба")]
public WoodSetting Wood = new WoodSetting();
[JsonProperty("Настройка охотника")]
public AnimalSetting Animal = new AnimalSetting();
internal class OreSetting {
[JsonProperty("Максимальные рейты рудокопа")]
public float RateMax;
[JsonProperty("Стартовые рейты рудокопа")]
public float RateStart;
[JsonProperty("Включить прокачку рейтов рудокопа добывая ресурсы")]
public bool Bonus;
[JsonProperty("Включить прокачку рейтов рудокопа подбирая ресурсы")]
public bool Pickup;
[JsonProperty("Ресурсы за добычу/подбор которых начислять рейты рудокопа | Ресурсы на которые будут действовать рейты рудокопа")]
public Dictionary<string, float> Item = new Dictionary<string, float>();
}
internal class PanelSetting {
[JsonProperty("OffsetMin")]
public string OffsetMin;
[JsonProperty("OffsetMax")]
public string OffsetMax;
[JsonProperty("AnchorMax")]
public string AnchorMax;
[JsonProperty("Отображение прогресса: TRUE - от минимальных до максимальных рейтов | FALSE - от 0 до максимальных рейтов ")]
public bool Progress;
[JsonProperty("AnchorMin")]
public string AnchorMin;
}
internal class SSetting {
[JsonProperty("Включить замедление прокачки | Чем больше рейты, тем медленнее прокачка")]
public bool Slow;
[JsonProperty("Включить рпг панель")]
public bool Panel;
[JsonProperty("Включить рпг сообщения")]
public bool Messages;
[JsonProperty("Удалять автоматически дату после вайпа")]
public bool ClearData;
[JsonProperty("Стартовый умножитель прокачки рейтов")]
public float Boost;
[JsonProperty("Размер текста")]
public int TextSize;
[JsonProperty("Размер текста уведомлений")]
public int TextSizeNotify;
[JsonProperty("Список игнорируемых инструментов")]
public List<string> BlockItem;
}
}
private Dictionary<ulong, RPGData> StoredData = new Dictionary<ulong, RPGData>();
private void AnimalUI(BasePlayer player) {
CuiHelper.DestroyUi(player, ".Animal");
CuiElementContainer container = new CuiElementContainer();
float rateanimal = StoredData[player.userID].Animal;
float maxrateanimal = StoredData[player.userID].AnimalRate;
string pregressanimal = rateanimal >= maxrateanimal ? "0.98 0.9" : config.Panel.Progress ? $"{0.13 + ((rateanimal - config.Animal.RateStart) * (0.84 / (maxrateanimal - config.Animal.RateStart)))} 0.9" : $"{0.13 + (rateanimal * (0.84 / maxrateanimal))} 0.9";
string textanimal = rateanimal >= maxrateanimal ? $"{lang.GetMessage("A", this, player.UserIDString)} {maxrateanimal}x" : $"{lang.GetMessage("A", this, player.UserIDString)} {Math.Round(rateanimal, 2)}x";
container.Add(new CuiPanel {
RectTransform = {
AnchorMin = "0 0", AnchorMax = "1 0.31", OffsetMax = "0 0"
}
, Image = {
Color = "0.96 0.91 0.87 0.02", Material = "assets/icons/greyout.mat"
}
}
, ".RPG", ".Animal");
container.Add(new CuiButton {
RectTransform = {
AnchorMin = "0.01 0.15", AnchorMax = "0.11 0.84", OffsetMax = "0 0"
}
, Button = {
Color = "1 1 1 0.5", Sprite = "assets/icons/bite.png"
}
, Text = {
Text = ""
}
}
, ".Animal");
container.Add(new CuiPanel {
RectTransform = {
AnchorMin = "0.13 0.1", AnchorMax = pregressanimal, OffsetMax = "0 0"
}
, Image = {
Color = "0.78 0.44 0.21 0.92", Material = "assets/icons/greyout.mat"
}
}
, ".Animal");
container.Add(new CuiLabel {
RectTransform = {
AnchorMin = "0.17 0", AnchorMax = "1 1", OffsetMax = "0 0"
}
, Text = {
Text = textanimal, Align = TextAnchor.MiddleLeft, FontSize = config.Setting.TextSize, Color = "1 1 1 0.60"
}
}
, ".Animal");
CuiHelper.AddUi(player, container);
}
private void CheckGroup(string id) {
BasePlayer player = BasePlayer.FindByID(ulong.Parse(id));
if(player != null) OnPlayerConnected(player);
}
private void OnCollectiblePickup(CollectibleEntity collectible, BasePlayer player) {
if(collectible?.itemList == null || player == null) return;
if(!permission.UserHasPermission(player.UserIDString, "xrpg.use")) return;
foreach(ItemAmount item in collectible.itemList) {
string shortname = item.itemDef.shortname;
if(config.Wood.Item.ContainsKey(shortname)) {
item.amount = (int)Math.Round(item.amount * StoredData[player.userID].Wood);
if(config.Wood.Pickup) RateWood(player, shortname);
}
if(config.Ore.Item.ContainsKey(shortname)) {
item.amount = (int)Math.Round(item.amount * StoredData[player.userID].Ore);
if(config.Ore.Pickup) RateOre(player, shortname);
}
if(config.Animal.Item.ContainsKey(shortname)) {
item.amount = (int)Math.Round(item.amount * StoredData[player.userID].Animal);
if(config.Animal.Pickup) RateAnimal(player, shortname);
}
}
}
private void UPMessageAnimal(BasePlayer player, string Messages) {
CuiHelper.DestroyUi(player, ".UPMessageAnimal");
CuiElementContainer container = new CuiElementContainer();
container.Add(new CuiLabel {
FadeOut = 0.5f, RectTransform = {
AnchorMin = "0.64 0", AnchorMax = "0.97 1", OffsetMax = "0 0"
}
, Text = {
FadeIn = 0.5f, Text = $"{Messages}", Align = TextAnchor.MiddleRight, Font = "robotocondensed-regular.ttf", FontSize = config.Setting.TextSizeNotify, Color = "1 1 1 0.60"
}
}
, ".Animal", ".UPMessageAnimal");
CuiHelper.AddUi(player, container);
timer.Once(2.5f, () => {
CuiHelper.DestroyUi(player, ".UPMessageAnimal");
}
);
}
private void CheckPermission(string id, string permName) {
BasePlayer player = BasePlayer.FindByID(ulong.Parse(id));
if(player != null) if(config.Permisssion.ContainsKey(permName)) OnPlayerConnected(player);
}
private void OnEntityDeath(BaseCombatEntity entity, HitInfo info) {
if(entity == null) return;
BasePlayer player = info?.InitiatorPlayer;
if(player == null || player.IsNpc) return;
if(!permission.UserHasPermission(player.UserIDString, "xrpg.use")) return;
if(config.Animal.Kill) {
var data = StoredData[player.userID];
if(!(data.Animal >= data.AnimalRate)) if(config.Animal.Animal.ContainsKey(entity.ShortPrefabName)) {
var itema = config.Animal.Animal[entity.ShortPrefabName];
float boost = 0;
if(config.Setting.Slow) boost = (itema - (itema / data.AnimalRate * (int)data.Animal)) * data.Boost;
else boost = itema * data.Boost;
StoredData[player.userID].Animal += boost;
if(config.Setting.Panel) if(data.ActiveUI) {
AnimalUI(player);
if(config.Setting.Messages) UPMessageAnimal(player, $"+ {Math.Round(boost, 5)}");
}
}
}
}
private void RPGUI(BasePlayer player) {
CuiHelper.DestroyUi(player, ".RPG");
CuiElementContainer container = new CuiElementContainer();
container.Add(new CuiPanel {
RectTransform = {
AnchorMin = config.Panel.AnchorMin, AnchorMax = config.Panel.AnchorMax, OffsetMin = config.Panel.OffsetMin, OffsetMax = config.Panel.OffsetMax
}
, Image = {
Color = "0 0 0 0"
}
}
, "Hud", ".RPG");
CuiHelper.AddUi(player, container);
WoodUI(player);
OreUI(player);
AnimalUI(player);
}
private void HideUI(BasePlayer player) {
CuiHelper.DestroyUi(player, ".Hide");
CuiElementContainer container = new CuiElementContainer();
container.Add(new CuiButton {
RectTransform = {
AnchorMin = "-0.14 0", AnchorMax = "-0.01 0.31", OffsetMax = "0 0"
}
, Button = {
Color = "0.96 0.91 0.87 0.02", Material = "assets/icons/greyout.mat", Command = "ui hide"
}
, Text = {
Text = ">>", Align = TextAnchor.MiddleCenter, FontSize = config.Setting.TextSize, Color = "1 1 1 0.6"
}
}
, ".RPG", ".Hide");
CuiHelper.AddUi(player, container);
}
private void RateAnimal(BasePlayer player, string shortname) {
var data = StoredData[player.userID];
if(!(data.Animal >= data.AnimalRate)) {
var itema = config.Animal.Item[shortname];
float arate = 0;
if(config.Setting.Slow) arate = (itema - (itema / data.AnimalRate * (int)data.Animal)) * data.Boost;
else arate = itema * data.Boost;
StoredData[player.userID].Animal += arate;
if(config.Setting.Panel) if(data.ActiveUI) {
AnimalUI(player);
if(config.Setting.Messages) UPMessageAnimal(player, $"+ {Math.Round(arate, 5)}");
}
}
}
[ChatCommand("rank")]
void cmdTOP(BasePlayer player) => TOP(player);
private void ShowUI(BasePlayer player) {
CuiHelper.DestroyUi(player, ".Show");
CuiElementContainer container = new CuiElementContainer();
container.Add(new CuiButton {
RectTransform = {
AnchorMin = "1 0", AnchorMax = "1 0", OffsetMin = "-236 16", OffsetMax = "-210 42"
}
, Button = {
Color = "0.96 0.91 0.87 0.02", Material = "assets/icons/greyout.mat", Command = "ui show"
}
, Text = {
Text = "<<", Align = TextAnchor.MiddleCenter, FontSize = 13, Color = "1 1 1 0.6"
}
}
, "Overlay", ".Show");
CuiHelper.AddUi(player, container);
}
private void OnUserPermissionGranted(string id, string permName) => CheckPermission(id, permName);
private void Unload() {
foreach(BasePlayer player in BasePlayer.activePlayerList) {
CuiHelper.DestroyUi(player, ".RPG");
CuiHelper.DestroyUi(player, ".Hide");
CuiHelper.DestroyUi(player, ".Show");
}
SaveData();
config = null;
}
protected override void LoadConfig() {
base.LoadConfig();
try {
config = Config.ReadObject<RPGConfig>();
}
catch {
PrintWarning("Ошибка чтения конфигурации! Создание дефолтной конфигурации!");
LoadDefaultConfig();
}
SaveConfig();
}
private void MaxRate(BasePlayer player) {
float wrate = 0, orate = 0, arate = 0, boost = 0, x = 0;
foreach(var perm in config.Permisssion) if(permission.UserHasPermission(player.UserIDString, perm.Key)) {
wrate = perm.Value.WoodRate;
orate = perm.Value.OreRate;
arate = perm.Value.AnimalRate;
boost = perm.Value.Boost;
x++;
break;
}
var data = StoredData[player.userID];
if(x == 0) {
if(data.Wood >= config.Wood.RateMax) {
data.Wood = config.Wood.RateMax;
data.WoodRate = config.Wood.RateMax;
}
else data.WoodRate = config.Wood.RateMax;
if(data.Ore >= config.Ore.RateMax) {
data.Ore = config.Ore.RateMax;
data.OreRate = config.Ore.RateMax;
}
else data.OreRate = config.Ore.RateMax;
if(data.Animal >= config.Animal.RateMax) {
data.Animal = config.Animal.RateMax;
data.AnimalRate = config.Animal.RateMax;
}
else data.AnimalRate = config.Animal.RateMax;
data.Boost = config.Setting.Boost;
}
else {
data.WoodRate = wrate;
data.OreRate = orate;
data.AnimalRate = arate;
data.Boost = boost;
}
StoredData[player.userID] = data;
}
private void OnUserPermissionRevoked(string id, string permName) => CheckPermission(id, permName);
protected override void SaveConfig() => Config.WriteObject(config);
private void OnUserGroupAdded(string id) => CheckGroup(id);
[ConsoleCommand("ui")]
void ccmdUI(ConsoleSystem.Arg args) {
BasePlayer player = args.Player();
switch(args.Args[0]) {
case "show" : {
CuiHelper.DestroyUi(player, ".Show");
StoredData[player.userID].ActiveUI = true;
RPGUI(player);
HideUI(player);
break;
}
case "hide" : {
CuiHelper.DestroyUi(player, ".RPG");
CuiHelper.DestroyUi(player, ".Hide");
StoredData[player.userID].ActiveUI = false;
ShowUI(player);
break;
}
}
EffectNetwork.Send(new Effect("assets/bundled/prefabs/fx/notice/loot.drag.grab.fx.prefab", player, 0, new Vector3(), new Vector3()), player.Connection);
}
private void RateOre(BasePlayer player, string shortname) {
var data = StoredData[player.userID];
if(!(data.Ore >= data.OreRate)) {
var itemo = config.Ore.Item[shortname];
float orate = 0;
if(config.Setting.Slow) orate = (itemo - (itemo / data.OreRate * (int)data.Ore)) * data.Boost;
else orate = itemo * data.Boost;
StoredData[player.userID].Ore += orate;
if(config.Setting.Panel) if(data.ActiveUI) {
OreUI(player);
if(config.Setting.Messages) UPMessageOre(player, $"+ {Math.Round(orate, 5)}");
}
}
}
private void OnPlayerConnected(BasePlayer player) {
if(player.IsReceivingSnapshot) {
NextTick(() => OnPlayerConnected(player));
return;
}
if(!StoredData.ContainsKey(player.userID)) {
StoredData.Add(player.userID, new RPGData());
var data = StoredData[player.userID];
data.Wood = config.Wood.RateStart;
data.Ore = config.Ore.RateStart;
data.Animal = config.Animal.RateStart;
data.WoodRate = config.Wood.RateMax;
data.OreRate = config.Ore.RateMax;
data.AnimalRate = config.Animal.RateMax;
StoredData[player.userID] = data;
}
if(permission.UserHasPermission(player.UserIDString, "xrpg.use")) MaxRate(player);
NextTick(() => {
if(config.Setting.Panel && permission.UserHasPermission(player.UserIDString, "xrpg.use")) if(StoredData[player.userID].ActiveUI) {
RPGUI(player);
HideUI(player);
}
else ShowUI(player);
}
);
}
private void UPMessageWood(BasePlayer player, string Messages) {
CuiHelper.DestroyUi(player, ".UPMessageWood");
CuiElementContainer container = new CuiElementContainer();
container.Add(new CuiLabel {
FadeOut = 0.5f, RectTransform = {
AnchorMin = "0.64 0", AnchorMax = "0.97 1", OffsetMax = "0 0"
}
, Text = {
FadeIn = 0.5f, Text = $"{Messages}", Align = TextAnchor.MiddleRight, Font = "robotocondensed-regular.ttf", FontSize = config.Setting.TextSizeNotify, Color = "1 1 1 0.60"
}
}
, ".Wood", ".UPMessageWood");
CuiHelper.AddUi(player, container);
timer.Once(2.5f, () => {
CuiHelper.DestroyUi(player, ".UPMessageWood");
}
);
}
private void UPMessageOre(BasePlayer player, string Messages) {
CuiHelper.DestroyUi(player, ".UPMessageOre");
CuiElementContainer container = new CuiElementContainer();
container.Add(new CuiLabel {
FadeOut = 0.5f, RectTransform = {
AnchorMin = "0.64 0", AnchorMax = "0.97 1", OffsetMax = "0 0"
}
, Text = {
FadeIn = 0.5f, Text = $"{Messages}", Align = TextAnchor.MiddleRight, Font = "robotocondensed-regular.ttf", FontSize = config.Setting.TextSizeNotify, Color = "1 1 1 0.60"
}
}
, ".Ore", ".UPMessageOre");
CuiHelper.AddUi(player, container);
timer.Once(2.5f, () => {
CuiHelper.DestroyUi(player, ".UPMessageOre");
}
);
}
private void SaveData() => Interface.Oxide.DataFileSystem.WriteObject("XRPG", StoredData);
protected override void LoadDefaultConfig() => config = RPGConfig.GetNewConfiguration();
private void OnUserGroupRemoved(string id) => CheckGroup(id);
private RPGConfig config;
private class RPGData {
[JsonProperty("Лесоруб")]
public float Wood;
[JsonProperty("Рудокоп")]
public float Ore;
[JsonProperty("Охотник")]
public float Animal;
[JsonProperty("Максимальные рейты лесоруба")]
public float WoodRate;
[JsonProperty("Максимальные рейты рудокопа")]
public float OreRate;
[JsonProperty("Максимальные рейты охотника")]
public float AnimalRate;
[JsonProperty("Множитель прокачки рейтов")]
public float Boost;
[JsonProperty("Активность UI")]
public bool ActiveUI = true;
}
private void InitializeLang() {
lang.RegisterMessages(new Dictionary<string, string> {
["W"]
= "LUMBERJACK:", ["O"] = "MINER:", ["A"] = "HUNTER:", ["WT"] = "TOP LUMBERJACK:", ["OT"] = "TOP MINER:", ["AT"] = "TOP HUNTER:", ["NP"] = "Недостаточно прав!",
}
, this);
lang.RegisterMessages(new Dictionary<string, string> {
["W"]
= "ЛЕСОРУБ:", ["O"] = "РУДОКОП:", ["A"] = "ОХОТНИК:", ["WT"] = "ТОП ЛЕСОРУБОВ:", ["OT"] = "ТОП РУДОКОПОВ:", ["AT"] = "ТОП ОХОТНИКОВ:", ["NP"] = "Недостаточно прав!",
}
, this, "ru");
}
private void OnDispenserGather(ResourceDispenser dispenser, BaseEntity entity, Item item) {
var player = entity?.ToPlayer();
if(item == null || player == null) return;
if(!permission.UserHasPermission(player.UserIDString, "xrpg.use")) return;
string shortname = item.info.shortname;
if(config.Wood.Item.ContainsKey(shortname)) item.amount = (int)Math.Round(item.amount * StoredData[player.userID].Wood);
if(config.Ore.Item.ContainsKey(shortname)) item.amount = (int)Math.Round(item.amount * StoredData[player.userID].Ore);
if(config.Animal.Item.ContainsKey(shortname)) item.amount = (int)Math.Round(item.amount * StoredData[player.userID].Animal);
}
private void TOP(BasePlayer player) {
if(!permission.UserHasPermission(player.UserIDString, "xrpg.top")) {
SendReply(player, lang.GetMessage("NP", this, player.UserIDString));
return;
}
int x = 1, y = 1, z = 1;
SendReply(player, lang.GetMessage("WT", this, player.UserIDString));
foreach(var i in StoredData.OrderByDescending(h => h.Value.Wood).Take(3)) {
var rplayer = covalence.Players.FindPlayerById(i.Key.ToString());
SendReply(player, $"<color=orange>{x}</color>.{rplayer.Name} | {Math.Round(i.Value.Wood, 2)}");
x++;
}
SendReply(player, lang.GetMessage("OT", this, player.UserIDString));
foreach(var i in StoredData.OrderByDescending(h => h.Value.Ore).Take(3)) {
var rplayer = covalence.Players.FindPlayerById(i.Key.ToString());
SendReply(player, $"<color=orange>{y}</color>.{rplayer.Name} | {Math.Round(i.Value.Ore, 2)}");
y++;
}
SendReply(player, lang.GetMessage("AT", this, player.UserIDString));
foreach(var i in StoredData.OrderByDescending(h => h.Value.Animal).Take(3)) {
var rplayer = covalence.Players.FindPlayerById(i.Key.ToString());
SendReply(player, $"<color=orange>{z}</color>.{rplayer.Name} | {Math.Round(i.Value.Animal, 2)}");
z++;
}
}
private void WoodUI(BasePlayer player) {
CuiHelper.DestroyUi(player, ".Wood");
CuiElementContainer container = new CuiElementContainer();
float ratewood = StoredData[player.userID].Wood;
float maxratewood = StoredData[player.userID].WoodRate;
string pregresswood = ratewood >= maxratewood ? "0.98 0.9" : config.Panel.Progress ? $"{0.13 + ((ratewood - config.Wood.RateStart) * (0.84 / (maxratewood - config.Wood.RateStart)))} 0.9" : $"{0.13 + (ratewood * (0.84 / maxratewood))} 0.9";
string textwood = ratewood >= maxratewood ? $"{lang.GetMessage("W", this, player.UserIDString)} {maxratewood}x" : $"{lang.GetMessage("W", this, player.UserIDString)} {Math.Round(ratewood, 2)}x";
container.Add(new CuiPanel {
RectTransform = {
AnchorMin = "0 0.68", AnchorMax = "1 1", OffsetMax = "0 0"
}
, Image = {
Color = "0.96 0.91 0.87 0.02", Material = "assets/icons/greyout.mat"
}
}
, ".RPG", ".Wood");
container.Add(new CuiButton {
RectTransform = {
AnchorMin = "0.01 0.15", AnchorMax = "0.11 0.84", OffsetMax = "0 0"
}
, Button = {
Color = "1 1 1 0.5", Sprite = "assets/icons/level_wood.png"
}
, Text = {
Text = ""
}
}
, ".Wood");
container.Add(new CuiPanel {
RectTransform = {
AnchorMin = "0.13 0.1", AnchorMax = pregresswood, OffsetMax = "0 0"
}
, Image = {
Color = "0.55 0.73 0.24 0.92", Material = "assets/icons/greyout.mat"
}
}
, ".Wood");
container.Add(new CuiLabel {
RectTransform = {
AnchorMin = "0.17 0", AnchorMax = "1 1", OffsetMax = "0 0"
}
, Text = {
Text = textwood, Align = TextAnchor.MiddleLeft, FontSize = config.Setting.TextSize, Color = "1 1 1 0.60"
}
}
, ".Wood");
CuiHelper.AddUi(player, container);
}
private void RateWood(BasePlayer player, string shortname) {
var data = StoredData[player.userID];
if(!(data.Wood >= data.WoodRate)) {
var itemw = config.Wood.Item[shortname];
float wrate = 0;
if(config.Setting.Slow) wrate = (itemw - (itemw / data.WoodRate * (int)data.Wood)) * data.Boost;
else wrate = itemw * data.Boost;
StoredData[player.userID].Wood += wrate;
if(config.Setting.Panel) if(data.ActiveUI) {
WoodUI(player);
if(config.Setting.Messages) UPMessageWood(player, $"+ {Math.Round(wrate, 5)}");
}
}
}
private void OreUI(BasePlayer player) {
CuiHelper.DestroyUi(player, ".Ore");
CuiElementContainer container = new CuiElementContainer();
float rateore = StoredData[player.userID].Ore;
float maxrateore = StoredData[player.userID].OreRate;
string pregressore = rateore >= maxrateore ? "0.98 0.9" : config.Panel.Progress ? $"{0.13 + ((rateore - config.Ore.RateStart) * (0.84 / (maxrateore - config.Ore.RateStart)))} 0.9" : $"{0.13 + (rateore * (0.84 / maxrateore))} 0.9";
string textore = rateore >= maxrateore ? $"{lang.GetMessage("O", this, player.UserIDString)} {maxrateore}x" : $"{lang.GetMessage("O", this, player.UserIDString)} {Math.Round(rateore, 2)}x";
container.Add(new CuiPanel {
RectTransform = {
AnchorMin = "0 0.34", AnchorMax = "1 0.66", OffsetMax = "0 0"
}
, Image = {
Color = "0.96 0.91 0.87 0.02", Material = "assets/icons/greyout.mat"
}
}
, ".RPG", ".Ore");
container.Add(new CuiButton {
RectTransform = {
AnchorMin = "0.01 0.15", AnchorMax = "0.11 0.84", OffsetMax = "0 0"
}
, Button = {
Color = "1 1 1 0.5", Sprite = "assets/icons/player_carry.png"
}
, Text = {
Text = ""
}
}
, ".Ore");
container.Add(new CuiPanel {
RectTransform = {
AnchorMin = "0.13 0.1", AnchorMax = pregressore, OffsetMax = "0 0"
}
, Image = {
Color = "0.29 0.60 0.83 0.92", Material = "assets/icons/greyout.mat"
}
}
, ".Ore");
container.Add(new CuiLabel {
RectTransform = {
AnchorMin = "0.17 0", AnchorMax = "1 1", OffsetMax = "0 0"
}
, Text = {
Text = textore, Align = TextAnchor.MiddleLeft, FontSize = config.Setting.TextSize, Color = "1 1 1 0.60"
}
}
, ".Ore");
CuiHelper.AddUi(player, container);
}
private void OnDispenserBonus(ResourceDispenser dispenser, BasePlayer player, Item item) {
if(item == null || player == null) return;
if(!permission.UserHasPermission(player.UserIDString, "xrpg.use")) return;
string shortname = item.info.shortname;
if(config.Setting.BlockItem.Contains(player.GetActiveItem().info.shortname)) {
if(config.Wood.Item.ContainsKey(shortname)) item.amount = (int)Math.Round(item.amount * StoredData[player.userID].Wood);
if(config.Ore.Item.ContainsKey(shortname)) item.amount = (int)Math.Round(item.amount * StoredData[player.userID].Ore);
if(config.Animal.Item.ContainsKey(shortname)) item.amount = (int)Math.Round(item.amount * StoredData[player.userID].Animal);
return;
}
if(config.Wood.Item.ContainsKey(shortname)) {
item.amount = (int)Math.Round(item.amount * StoredData[player.userID].Wood);
if(config.Wood.Bonus) RateWood(player, shortname);
}
if(config.Ore.Item.ContainsKey(shortname)) {
item.amount = (int)Math.Round(item.amount * StoredData[player.userID].Ore);
if(config.Ore.Bonus) RateOre(player, shortname);
}
if(config.Animal.Item.ContainsKey(shortname)) {
item.amount = (int)Math.Round(item.amount * StoredData[player.userID].Animal);
if(config.Animal.Bonus) RateAnimal(player, shortname);
}
}
private void OnServerInitialized() {
PrintWarning("\n-----------------------------\n" + " Author - Monster\n" + " VK - vk.com/idannopol\n" + " Discord - Monster#4837\n" + " \n" + "-----------------------------");
if(Interface.Oxide.DataFileSystem.ExistsDatafile("XRPG")) StoredData = Interface.Oxide.DataFileSystem.ReadObject<Dictionary<ulong, RPGData>>("XRPG");
timer.Every(120, () => SaveData());
BasePlayer.activePlayerList.ToList().ForEach(OnPlayerConnected);
foreach(var perm in config.Permisssion) permission.RegisterPermission(perm.Key, this);
permission.RegisterPermission("xrpg.use", this);
permission.RegisterPermission("xrpg.top", this);
InitializeLang();
}
}
}