C#:
// Все права принадлежат дискорд сообществу https://discord.gg/VgNHPpNrz6
using Newtonsoft.Json;
using Oxide.Core.Libraries.Covalence;
using Oxide.Game.Rust.Cui;
using Oxide.Core;
using System;
using System.Linq;
using System.Globalization;
using System.Collections.Generic;
using UnityEngine;
using Rust;
namespace Oxide.Plugins {
[Info("CRaidController", "Crazy (edit by Raul-Sorin Sorban)", "3.2.0")]
[Description("System for managing raid schedules")]
class CRaidController : RustPlugin {
#region Fields
private static CRaidController _ins;
private static string _sound = "assets/prefabs/locks/keypad/effects/lock.code.unlock.prefab";
private static int _cupboardRadius = 20;
private static int _timezone;
private static int _uiCount = 6;
private static float _radiusFireball = 5f;
private static DateTime _lastWipe;
private static string _permChange = "craidcontroller.change";
private static string _permHide = "craidcontroller.hide";
#endregion
#region Server
private void OnServerInitialized() => _lastWipe = SaveRestore.SaveCreatedTime.ToLocalTime();
private void Loaded() {
_ins = this;
_timezone = int.Parse(cfg.config.timezone);
LoadData();
cmd.AddChatCommand(cfg.ui.command, this, nameof(PlayerConfCommand));
permission.RegisterPermission(_permChange, this);
permission.RegisterPermission(_permHide, this);
if (!cfg.raid.ContainsKey("default")) {
PrintError("Raid Schedules [default] don't exist !");
return;
}
_controller = new Dictionary<ulong, RaidController>();
foreach (var player in BasePlayer.activePlayerList) OnPlayerConnected(player);
}
private void Unload() {
if (BasePlayer.activePlayerList.Count == 0) return;
RaidController[] objects = UnityEngine.Object.FindObjectsOfType<RaidController>();
if (objects != null) {
foreach (var obj in objects) UnityEngine.Object.Destroy(obj);
}
}
private void OnPlayerConnected(BasePlayer player) {
if (player.IsReceivingSnapshot || player.IsSleeping()) {
timer.In(2, () => OnPlayerConnected(player));
return;
}
if (!player.GetComponent<RaidController>()) _controller[player.userID] = player.gameObject.AddComponent<RaidController>();
}
private void OnPlayerDisconnected(BasePlayer player) {
if (_controller.ContainsKey(player.userID)) UnityEngine.Object.Destroy(_controller[player.userID]);
}
// Method updated by Death 06/04/2021
private void OnEntityTakeDamage(BaseCombatEntity entity, HitInfo info) {
if (!cfg.config.nullify || entity == null || info == null || info.Initiator == null) {
return;
}
if (info.Initiator is FireBall || info.damageTypes.GetMajorityDamageType().ToString() == "heat") {
var creator = info.Initiator.creatorEntity as BasePlayer;
var controller = creator.GetComponent<RaidController>();
if (creator != null && !TakeDamage(creator, entity, info, controller.CheckCanRaid(), controller.wipeCooldown) && !cfg.config.playerFire) {
Nullify(info);
return;
}
foreach (var x in fireBall.Where(x => x.Key.TotalSeconds >= 30)) {
if (!IsNear(x.Value.radius, info.HitPositionWorld) || info.damageTypes.GetMajorityDamageType() != DamageType.Heat) {
continue;
}
var p = BasePlayer.FindByID(x.Value.player);
if (p == null) {
continue;
}
var pController = p.GetComponent<RaidController>();
if (pController == null) {
continue;
}
if (!TakeDamage(p, entity, info, pController.CheckCanRaid(), pController.wipeCooldown)) {
info.damageTypes.ScaleAll(0f);
}
}
}
if (!info.Initiator is BasePlayer) {
return;
}
var player = info.InitiatorPlayer;
if (player == null || player.IsNpc || player.net?.connection == null) {
return;
}
var playerController = player.GetComponent<RaidController>();
if (!TakeDamage(player, entity, info, playerController.CheckCanRaid(), playerController.wipeCooldown)) {
Nullify(info);
CatchFireball(player, entity, info);
Refund(player, info);
if (cfg.config.tryDamageMessage == null) {
PrintError("The last update of the plugin requires you to delete your configuration file.");
return;
}
if (cfg.config.tryDamageMessage.enabled) {
if (pCd.ContainsKey($"damageCanRaid:{player.userID}")) {
return;
}
int totalSeconds = (int)(ToTimeSpan(playerController.schedulesActual[1]) - playerController.time).TotalSeconds;
int minutes = (totalSeconds / 60) % 60;
int hours = (totalSeconds / (60 * 60));
if (minutes == 0 && hours == 0) {
return;
}
if (playerController.schedulesNext[0] == string.Empty) {
Message(player, "FinishTodayMessage");
}
else {
Message(player, "AlertMessage", hours.ToString(), minutes.ToString());
}
if (cfg.config.tryDamageMessage.effect) {
SendEffect(player, _sound);
}
pCd.Add($"damageCanRaid:{player.userID}", 5f);
RemoveCd("damageCanRaid", player.userID);
}
}
}
#endregion
#region Component
private class RaidController : FacepunchBehaviour {
private BasePlayer player;
private DayOfWeek dayOfWeek;
private DateTime timeNow;
public TimeSpan time;
private List<SchedulesList> schedules;
private string[] schedulesPrev;
public string[] schedulesNext;
public string[] schedulesActual;
private string lang;
private bool needUpdate;
private bool allDayNoRaid;
private bool allDayRaid;
public bool wipeCooldown;
private bool firstAlert;
private void Awake() {
player = GetComponent<BasePlayer>();
Instance();
InvokeRepeating(Refresh, 0f, cfg.ui.rate);
InvokeRepeating(Create, 0f, cfg.ui.rate);
if (cfg.config.alertMessage.enabled) InvokeRepeating(AlertMessage, 0f, cfg.config.alertMessage.countdown * 60);
}
private void Instance() {
lang = GetLanguage();
time = DateTime.UtcNow.AddHours(_timezone).TimeOfDay;
dayOfWeek = DateTime.UtcNow.AddHours(_timezone).DayOfWeek;
timeNow = DateTime.UtcNow.AddHours(_timezone);
schedules = GetDaySchedules();
schedulesPrev = GetPrevSchedules();
schedulesNext = GetNextSchedules();
schedulesActual = GetActualSchedules();
wipeCooldown = CheckWipeCooldown();
allDayNoRaid = CheckAllDayNoRaid();
allDayRaid = CheckAllDayRaid();
needUpdate = false;
if (CheckCanRaid()) {
if (!cfg.config.timeMessage.enabled) return;
Message(player, "TimeMessage", GetTime(schedulesActual[1]));
if (cfg.config.alertMessage.effect) SendEffect(player, _sound);
}
else {
if (!cfg.config.timeFinishMessage.enabled) return;
if (schedulesNext[0] == string.Empty) Message(player, "FinishTodayMessage");
else Message(player, "FinishMessage", GetTime(schedulesActual[1]));
if (cfg.config.alertMessage.effect) SendEffect(player, _sound);
}
DestroyUI(true);
if (player.IsAdmin && pConf.ContainsKey(player.userID)) if (pConf[player.userID].hide) return;
if (cfg.ui.allowPlayerhide && player.IPlayer.HasPermission(_permHide) && pConf.ContainsKey(player.userID)) if (pConf[player.userID].hide) return;
if (cfg.ui.hide) return;
CreateUI(true);
}
private void Refresh() {
time = DateTime.UtcNow.AddHours(_timezone).TimeOfDay;
CheckNeedUpdate();
if (needUpdate) {
Instance();
return;
}
}
private void AlertMessage() {
if (!firstAlert) {
firstAlert = true;
return;
}
if (CheckCanRaid()) return;
int totalSeconds = (int)(ToTimeSpan(schedulesActual[1]) - time).TotalSeconds;
int minutes = (totalSeconds / 60) % 60;
int hours = (totalSeconds / (60 * 60));
if (minutes == 0 && hours == 0) return;
Message(player, "AlertMessage", hours.ToString(), minutes.ToString());
if (cfg.config.alertMessage.effect) SendEffect(player, _sound);
}
private string GetLanguage() {
string default_lang = "en";
if (_ins.lang.GetLanguage(player.IPlayer.Id) == "en-PT") return default_lang;
return _ins.lang.GetLanguage(player.IPlayer.Id);
}
private List<SchedulesList> GetDaySchedules() {
List<SchedulesList> ret = new List<SchedulesList>();
var schedules = cfg.raid.LastOrDefault(x => x.Key == player.userID.ToString() || CheckInGroup(player, x.Key));
switch (dayOfWeek) {
case DayOfWeek.Monday : foreach (var x in schedules.Value.monday.schedules) ret.Add(new SchedulesList() {
start = x.start, end = x.end, allday = schedules.Value.monday.allday, noallday = schedules.Value.monday.noallday
}
);
break;
case DayOfWeek.Tuesday : foreach (var x in schedules.Value.tuesday.schedules) ret.Add(new SchedulesList() {
start = x.start, end = x.end, allday = schedules.Value.tuesday.allday, noallday = schedules.Value.tuesday.noallday
}
);
break;
case DayOfWeek.Wednesday : foreach (var x in schedules.Value.wednesday.schedules) ret.Add(new SchedulesList() {
start = x.start, end = x.end, allday = schedules.Value.wednesday.allday, noallday = schedules.Value.wednesday.noallday
}
);
break;
case DayOfWeek.Thursday : foreach (var x in schedules.Value.thursday.schedules) ret.Add(new SchedulesList() {
start = x.start, end = x.end, allday = schedules.Value.thursday.allday, noallday = schedules.Value.thursday.noallday
}
);
break;
case DayOfWeek.Friday : foreach (var x in schedules.Value.friday.schedules) ret.Add(new SchedulesList() {
start = x.start, end = x.end, allday = schedules.Value.friday.allday, noallday = schedules.Value.friday.noallday
}
);
break;
case DayOfWeek.Saturday : foreach (var x in schedules.Value.saturday.schedules) ret.Add(new SchedulesList() {
start = x.start, end = x.end, allday = schedules.Value.saturday.allday, noallday = schedules.Value.saturday.noallday
}
);
break;
case DayOfWeek.Sunday : foreach (var x in schedules.Value.sunday.schedules) ret.Add(new SchedulesList() {
start = x.start, end = x.end, allday = schedules.Value.sunday.allday, noallday = schedules.Value.sunday.noallday
}
);
break;
}
foreach (var x in ret.Where(x => x.end == "00:00")) x.end = "23:59:59";
return ret;
}
private string[] GetPrevSchedules() {
string[] ret = new string[] {
string.Empty, string.Empty
}
;
if (schedules.Exists(x => time > ToTimeSpan(x.end))) {
var _sch = schedules.FindLast(x => time > ToTimeSpan(x.end));
return new string[] {
_sch.start, _sch.end
}
;
}
return ret;
}
private string[] GetActualSchedules() {
string[] ret = new string[] {
string.Empty, string.Empty, string.Empty
}
;
if (!schedules.Any()) return ret;
if (allDayNoRaid || allDayRaid) return new string[] {
"00:00", "23:59:59", string.Empty
}
;
else if (schedules.Exists(x => time > ToTimeSpan(x.start) && time < ToTimeSpan(x.end))) {
var _sch = schedules.FirstOrDefault(x => time > ToTimeSpan(x.start) && time < ToTimeSpan(x.end));
return new string[] {
_sch.start, _sch.end, "true"
}
;
}
else {
string retStart = string.Empty;
string retEnd = string.Empty;
if (schedulesPrev[1] == string.Empty) retStart = "00:00";
else retStart = schedulesPrev[1];
if (schedulesNext[0] == string.Empty) retEnd = "23:59:59";
else retEnd = schedulesNext[0];
return new string[] {
retStart, retEnd, "false"
}
;
}
return ret;
}
private string[] GetNextSchedules() {
string[] ret = new string[] {
string.Empty, string.Empty
}
;
if (schedules.Exists(x => time < ToTimeSpan(x.start))) {
var _sch = schedules.Find(x => time < ToTimeSpan(x.start));
return new string[] {
_sch.start, _sch.end
}
;
}
return ret;
}
private DateTime GetWipeCd() {
var select = cfg.raid.LastOrDefault(x => x.Key == player.userID.ToString() || CheckInGroup(player, x.Key)).Value.wipeCooldown;
DateTime parsedDate = DateTime.UtcNow.AddHours(_timezone);
if (select.custom != null) {
string pattern = "dd-MM-yy HH:mm";
if (DateTime.TryParseExact(select.custom, pattern, null, DateTimeStyles.None, out parsedDate)) return parsedDate;
else return parsedDate;
}
else if (select.days > 0) {
DateTime _lastWipeTime = _lastWipe.AddDays(select.days);
DateTime dateNew = new DateTime(_lastWipeTime.Year, _lastWipeTime.Month, _lastWipeTime.Day, 0, 0, 0);
return dateNew;
}
else return parsedDate;
}
private string GetColor(string key) => color.FirstOrDefault(x => key == x.Key).Value;
private string GetTitle() {
if (wipeCooldown) return _ins.GetLang("NoRaidCooldown", player.IPlayer.Id);
else if (!CheckCanRaid()) return _ins.GetLang("NoRaidTime", player.IPlayer.Id);
else return _ins.GetLang("RaidTime", player.IPlayer.Id);
}
private string GetTime(string t) {
if (lang == "en" && cfg.ui.time12) return ToTime12(t);
else return ToTime24(t);
}
private void CheckNeedUpdate() {
if (CheckLangChanged() || CheckDayChanged() || CheckSchedulesChanged()) needUpdate = true;
if (needRefresh.Contains(player.userID)) {
needRefresh.Remove(player.userID);
needUpdate = true;
}
}
private bool CheckLangChanged() {
var currentLang = GetLanguage();
if (lang == currentLang) return false;
return true;
}
private bool CheckDayChanged() {
DayOfWeek currentDay = DateTime.UtcNow.AddHours(_timezone).DayOfWeek;
if (dayOfWeek == currentDay) return false;
return true;
}
private bool CheckSchedulesChanged() {
if (time > ToTimeSpan(schedulesActual[1])) return true;
return false;
}
private bool CheckWipeCooldown() {
var select = cfg.raid.LastOrDefault(x => x.Key == player.userID.ToString() || CheckInGroup(player, x.Key)).Value.wipeCooldown;
if (select == null) return false;
if (select.enabled) {
if (select.custom != null) {
string pattern = "dd-MM-yy HH:mm";
DateTime parsedDate;
if (DateTime.TryParseExact(select.custom, pattern, null, DateTimeStyles.None, out parsedDate)) {
if (DateTime.Now > parsedDate) return false;
return true;
}
else _ins.PrintError("Unable to convert '{0}' to a date and time.Pattern 'dd-MM HH:mm'", select.custom);
}
if (select.days == 0) return false;
if (DateTime.Today > _lastWipe.AddDays(select.days)) return false;
return true;
}
return false;
}
private bool CheckAllDayRaid() {
if (schedules[0].allday) return true;
return false;
}
private bool CheckAllDayNoRaid() {
if (schedules[0].noallday) return true;
return false;
}
public bool CheckCanRaid() {
if (allDayNoRaid) return false;
if (allDayRaid) return true;
if (schedulesActual[0] == string.Empty || schedulesActual[2] == "false") return false;
if (schedulesActual[2] == "true") return true;
TimeSpan start = ToTimeSpan(schedulesActual[0]);
TimeSpan end = ToTimeSpan(schedulesActual[1]);
if (time >= start && time < end) return true;
return false;
}
private void Create() {
if (player.IsAdmin && pConf.ContainsKey(player.userID)) if (pConf[player.userID].hide) return;
if (cfg.ui.allowPlayerhide && player.IPlayer.HasPermission(_permHide) && pConf.ContainsKey(player.userID)) if (pConf[player.userID].hide) return;
if (!cfg.ui.hide) {
DestroyUI();
CreateUI();
if (cfg.ui.hideIfNotTime && !CheckCanRaid()) DestroyUI(true);
if (cfg.ui.hideIsTime && CheckCanRaid()) DestroyUI(true);
}
}
private void CreateUI(bool all = false) {
int uiChoice = 0;
string start = schedulesActual[0];
string end = schedulesActual[1];
string color = string.Empty;
string elapsedMinutes = "0";
string totalMinutes = string.Empty;
float progressCount = 0;
DateTimeFormatInfo dateLang = (new CultureInfo(lang)).DateTimeFormat;
if (wipeCooldown) {
elapsedMinutes = (timeNow - _lastWipe).TotalMinutes.ToString();
totalMinutes = (GetWipeCd() - _lastWipe).TotalMinutes.ToString();
progressCount = (float)float.Parse(elapsedMinutes) / float.Parse(totalMinutes);
}
else {
if (time < ToTimeSpan(end) && time >= ToTimeSpan(start)) elapsedMinutes = (time - ToTimeSpan(start)).TotalMinutes.ToString();
totalMinutes = (ToTimeSpan(end) - ToTimeSpan(start)).TotalMinutes.ToString();
progressCount = (float)float.Parse(elapsedMinutes) / float.Parse(totalMinutes);
}
if (!CheckCanRaid()) color = HexToRustFormat(GetColor("red"));
else color = HexToRustFormat(GetColor("green"));
if (!cfg.ui.allowPlayerChange && !player.IPlayer.HasPermission(_permChange) || !pConf.ContainsKey(player.userID)) uiChoice = cfg.ui.uiChoice;
else if (pConf[player.userID].choose > 0 && pConf[player.userID].choose <= _uiCount) uiChoice = pConf[player.userID].choose;
else uiChoice = cfg.ui.uiChoice;
switch (uiChoice) {
#region UI #1
case 1 : if (all) {
var container = UI.CreateElementContainer("craidcontroller.static.txt", cfg.ui.background, "0.78 0.89", "0.99 0.99");
UI.AddText(ref container, "craidcontroller.static.txt", GetTitle(), 14, "robotocondensed-regular.ttf", "1 1 1 0.6", TextAnchor.MiddleLeft, "0.05 0.6", "1.0 1");
UI.AddText(ref container, "craidcontroller.static.txt", DateTime.UtcNow.AddHours(_timezone).ToString("dddd", dateLang).ToUpper(), 18, "robotocondensed-bold.ttf", "1 1 1 1", TextAnchor.MiddleLeft, "0.05 0", "1.0 1");
if (allDayRaid) UI.AddText(ref container, "craidcontroller.static.txt", _ins.GetLang("RaidAllDay", player.IPlayer.Id).ToUpper(), 17, "robotocondensed-bold.ttf", "1 1 1 0.4", TextAnchor.MiddleLeft, "0.7 0.10", "1.0 1");
else if (allDayNoRaid) UI.AddText(ref container, "craidcontroller.static.txt", _ins.GetLang("RaidNoDay", player.IPlayer.Id).ToUpper(), 17, "robotocondensed-bold.ttf", "1 1 1 0.4", TextAnchor.MiddleLeft, "0.7 0.10", "1.0 1");
else if (wipeCooldown) {
UI.AddText(ref container, "craidcontroller.static.txt", _ins.GetLang("Until", player.IPlayer.Id, string.Empty).ToUpper(), 15, "robotocondensed-bold.ttf", "1 1 1 0.4", TextAnchor.UpperCenter, "0.7 0", "1.0 0.9");
UI.AddText(ref container, "craidcontroller.static.txt", GetWipeCd().ToString("dd-MM", CultureInfo.InvariantCulture), 13, "robotocondensed-regular.ttf", "1 1 1 0.4", TextAnchor.MiddleCenter, "0.7 0.20", "1.0 1");
UI.AddText(ref container, "craidcontroller.static.txt", GetWipeCd().ToString("HH:mm", CultureInfo.InvariantCulture), 13, "robotocondensed-regular.ttf", "1 1 1 0.4", TextAnchor.LowerCenter, "0.7 0.30", "1.0 1");
}
else UI.AddText(ref container, "craidcontroller.static.txt", $"{GetTime(start)} / {GetTime(end)}", 18, "robotocondensed-regular.ttf", "1 1 1 0.4", TextAnchor.MiddleCenter, "0.4 0.10", "1.0 1.1");
UI.AddImageColor(ref container, "craidcontroller.static.txt", HexToRustFormat(GetColor("blacklight")), "0 0", "1 0", "14 16", "0 22");
CuiHelper.AddUi(player, container);
}
else {
var container = UI.CreateElementContainer("craidcontroller.progress.txt", "0 0 0 0", "0.78 0.89", "0.99 0.99");
UI.AddImageColor(ref container, "craidcontroller.progress.txt", color, "0 0", $"{progressCount} 0", "14 16", "14 22");
CuiHelper.AddUi(player, container);
}
break;
#endregion
#region UI #2
case 2 : if (all) {
var container = UI.CreateElementContainer("craidcontroller.static.txt", cfg.ui.background, "0.01 0.89", "0.22 0.99");
UI.AddText(ref container, "craidcontroller.static.txt", GetTitle(), 14, "robotocondensed-regular.ttf", "1 1 1 0.6", TextAnchor.MiddleLeft, "0.05 0.6", "1.0 1");
UI.AddText(ref container, "craidcontroller.static.txt", DateTime.UtcNow.AddHours(_timezone).ToString("dddd", dateLang).ToUpper(), 18, "robotocondensed-bold.ttf", "1 1 1 1", TextAnchor.MiddleLeft, "0.05 0", "1.0 1");
if (allDayRaid) UI.AddText(ref container, "craidcontroller.static.txt", _ins.GetLang("RaidAllDay", player.IPlayer.Id).ToUpper(), 17, "robotocondensed-bold.ttf", "1 1 1 0.4", TextAnchor.MiddleLeft, "0.7 0.10", "1.0 1");
else if (allDayNoRaid) UI.AddText(ref container, "craidcontroller.static.txt", _ins.GetLang("RaidNoDay", player.IPlayer.Id).ToUpper(), 17, "robotocondensed-bold.ttf", "1 1 1 0.4", TextAnchor.MiddleLeft, "0.7 0.10", "1.0 1");
else if (wipeCooldown) {
UI.AddText(ref container, "craidcontroller.static.txt", _ins.GetLang("Until", player.IPlayer.Id, string.Empty).ToUpper(), 15, "robotocondensed-bold.ttf", "1 1 1 0.4", TextAnchor.UpperCenter, "0.7 0", "1.0 0.9");
UI.AddText(ref container, "craidcontroller.static.txt", GetWipeCd().ToString("dd-MM", CultureInfo.InvariantCulture), 13, "robotocondensed-regular.ttf", "1 1 1 0.4", TextAnchor.MiddleCenter, "0.7 0.20", "1.0 1");
UI.AddText(ref container, "craidcontroller.static.txt", GetWipeCd().ToString("HH:mm", CultureInfo.InvariantCulture), 13, "robotocondensed-regular.ttf", "1 1 1 0.4", TextAnchor.LowerCenter, "0.7 0.30", "1.0 1");
}
else UI.AddText(ref container, "craidcontroller.static.txt", $"{GetTime(start)} / {GetTime(end)}", 18, "robotocondensed-regular.ttf", "1 1 1 0.4", TextAnchor.MiddleCenter, "0.4 0.10", "1.0 1.1");
UI.AddImageColor(ref container, "craidcontroller.static.txt", HexToRustFormat(GetColor("blacklight")), "0 0", "1 0", "14 16", "0 22");
CuiHelper.AddUi(player, container);
}
else {
var container = UI.CreateElementContainer("craidcontroller.progress.txt", "0 0 0 0", "0.01 0.89", "0.22 0.99");
UI.AddImageColor(ref container, "craidcontroller.progress.txt", color, "0 0", $"{progressCount} 0", "14 16", "14 22");
CuiHelper.AddUi(player, container);
}
break;
#endregion
#region UI #3
case 3 : if (all) {
var container = UI.CreateElementContainer("craidcontroller.static.txt", cfg.ui.background, "0.80 0.92", "0.99 0.99");
UI.AddText(ref container, "craidcontroller.static.txt", GetTitle(), 14, "robotocondensed-regular.ttf", "1 1 1 0.6", TextAnchor.MiddleLeft, "0.05 0.5", "1.0 1");
UI.AddText(ref container, "craidcontroller.static.txt", DateTime.UtcNow.AddHours(_timezone).ToString("dddd", dateLang).ToUpper(), 18, "robotocondensed-bold.ttf", "1 1 1 1", TextAnchor.MiddleLeft, "0.05 0", "1.0 0.8");
if (allDayRaid) UI.AddText(ref container, "craidcontroller.static.txt", _ins.GetLang("RaidAllDay", player.IPlayer.Id).ToUpper(), 17, "robotocondensed-bold.ttf", HexToRustFormat(GetColor("green")), TextAnchor.MiddleCenter, "0.7 0.10", "1.0 1");
else if (allDayNoRaid) UI.AddText(ref container, "craidcontroller.static.txt", _ins.GetLang("RaidNoDay", player.IPlayer.Id).ToUpper(), 17, "robotocondensed-bold.ttf", HexToRustFormat(GetColor("red")), TextAnchor.MiddleCenter, "0.7 0.10", "1.0 1");
else if (wipeCooldown) {
UI.AddText(ref container, "craidcontroller.static.txt", _ins.GetLang("Until", player.IPlayer.Id, string.Empty).ToUpper(), 15, "robotocondensed-bold.ttf", "1 1 1 0.4", TextAnchor.UpperCenter, "0.7 0", "1.0 0.9");
UI.AddText(ref container, "craidcontroller.static.txt", GetWipeCd().ToString("dd-MM", CultureInfo.InvariantCulture), 13, "robotocondensed-regular.ttf", "1 1 1 0.4", TextAnchor.MiddleCenter, "0.7 0", "1.0 1");
UI.AddText(ref container, "craidcontroller.static.txt", GetWipeCd().ToString("HH:mm", CultureInfo.InvariantCulture), 13, "robotocondensed-regular.ttf", "1 1 1 0.4", TextAnchor.LowerCenter, "0.7 0.15", "1.0 1");
}
else {
UI.AddText(ref container, "craidcontroller.static.txt", $"{GetTime(start)}", 18, "robotocondensed-regular.ttf", "1 1 1 0.4", TextAnchor.UpperCenter, "0.7 0", "1.0 0.95");
UI.AddText(ref container, "craidcontroller.static.txt", $"________", 10, "robotocondensed-regular.ttf", "1 1 1 0.3", TextAnchor.MiddleCenter, "0.7 0.24", "1.0 1");
UI.AddText(ref container, "craidcontroller.static.txt", $"{GetTime(end)}", 18, "robotocondensed-regular.ttf", "1 1 1 0.4", TextAnchor.LowerCenter, "0.7 0.15", "1.0 1");
}
UI.AddText(ref container, "craidcontroller.static.txt", _ins.GetLang("Rest", player.IPlayer.Id), 10, "robotocondensed-regular.ttf", "1 1 1 0.6", TextAnchor.LowerLeft, "0.05 0", "1.0 1");
UI.AddImageColor(ref container, "craidcontroller.static.txt", HexToRustFormat(GetColor("blacklight")), "0.20 0", "1 0", "10 3", "0 7.5");
CuiHelper.AddUi(player, container);
}
else {
var container = UI.CreateElementContainer("craidcontroller.progress.txt", "0 0 0 0", "0.846 0.92", "0.99 0.99");
UI.AddImageColor(ref container, "craidcontroller.progress.txt", color, "0 0", $"{progressCount} 0", "0 3.5", "0 7");
CuiHelper.AddUi(player, container);
}
break;
#endregion
#region UI #4
case 4 : if (all) {
var container = UI.CreateElementContainer("craidcontroller.static.txt", cfg.ui.background, "0.01 0.92", "0.20 0.99");
UI.AddText(ref container, "craidcontroller.static.txt", GetTitle(), 14, "robotocondensed-regular.ttf", "1 1 1 0.6", TextAnchor.MiddleLeft, "0.05 0.5", "1.0 1");
UI.AddText(ref container, "craidcontroller.static.txt", DateTime.UtcNow.AddHours(_timezone).ToString("dddd", dateLang).ToUpper(), 18, "robotocondensed-bold.ttf", "1 1 1 1", TextAnchor.MiddleLeft, "0.05 0", "1.0 0.8");
if (allDayRaid) UI.AddText(ref container, "craidcontroller.static.txt", _ins.GetLang("RaidAllDay", player.IPlayer.Id).ToUpper(), 17, "robotocondensed-bold.ttf", HexToRustFormat(GetColor("green")), TextAnchor.MiddleCenter, "0.7 0.10", "1.0 1");
else if (allDayNoRaid) UI.AddText(ref container, "craidcontroller.static.txt", _ins.GetLang("RaidNoDay", player.IPlayer.Id).ToUpper(), 17, "robotocondensed-bold.ttf", HexToRustFormat(GetColor("red")), TextAnchor.MiddleCenter, "0.7 0.10", "1.0 1");
else if (wipeCooldown) {
UI.AddText(ref container, "craidcontroller.static.txt", _ins.GetLang("Until", player.IPlayer.Id, string.Empty).ToUpper(), 15, "robotocondensed-bold.ttf", "1 1 1 0.4", TextAnchor.UpperCenter, "0.7 0", "1.0 0.9");
UI.AddText(ref container, "craidcontroller.static.txt", GetWipeCd().ToString("dd-MM", CultureInfo.InvariantCulture), 13, "robotocondensed-regular.ttf", "1 1 1 0.4", TextAnchor.MiddleCenter, "0.7 0", "1.0 1");
UI.AddText(ref container, "craidcontroller.static.txt", GetWipeCd().ToString("HH:mm", CultureInfo.InvariantCulture), 13, "robotocondensed-regular.ttf", "1 1 1 0.4", TextAnchor.LowerCenter, "0.7 0.15", "1.0 1");
}
else {
UI.AddText(ref container, "craidcontroller.static.txt", $"{GetTime(start)}", 18, "robotocondensed-regular.ttf", "1 1 1 0.4", TextAnchor.UpperCenter, "0.7 0", "1.0 0.95");
UI.AddText(ref container, "craidcontroller.static.txt", $"________", 10, "robotocondensed-regular.ttf", "1 1 1 0.3", TextAnchor.MiddleCenter, "0.7 0.24", "1.0 1");
UI.AddText(ref container, "craidcontroller.static.txt", $"{GetTime(end)}", 18, "robotocondensed-regular.ttf", "1 1 1 0.4", TextAnchor.LowerCenter, "0.7 0.15", "1.0 1");
}
UI.AddText(ref container, "craidcontroller.static.txt", _ins.GetLang("Rest", player.IPlayer.Id), 10, "robotocondensed-regular.ttf", "1 1 1 0.6", TextAnchor.LowerLeft, "0.05 0", "1.0 1");
UI.AddImageColor(ref container, "craidcontroller.static.txt", HexToRustFormat(GetColor("blacklight")), "0.20 0", "1 0", "10 3", "0 7.5");
CuiHelper.AddUi(player, container);
}
else {
var container = UI.CreateElementContainer("craidcontroller.progress.txt", "0 0 0 0", "0.056 0.92", "0.20 0.99");
UI.AddImageColor(ref container, "craidcontroller.progress.txt", color, "0 0", $"{progressCount} 0", "0 3.5", "0 7");
CuiHelper.AddUi(player, container);
}
break;
#endregion
#region UI #5
case 5 : if (all) {
var container = UI.CreateElementContainer("craidcontroller.static.txt", cfg.ui.background, "0.371 0.11", "0.615 0.18");
UI.AddText(ref container, "craidcontroller.static.txt", GetTitle(), 14, "robotocondensed-regular.ttf", "1 1 1 0.6", TextAnchor.MiddleLeft, "0.05 0.5", "1.0 1");
UI.AddText(ref container, "craidcontroller.static.txt", DateTime.UtcNow.AddHours(_timezone).ToString("dddd", dateLang).ToUpper(), 18, "robotocondensed-bold.ttf", "1 1 1 1", TextAnchor.MiddleLeft, "0.05 0", "1.0 0.8");
if (allDayRaid) UI.AddText(ref container, "craidcontroller.static.txt", _ins.GetLang("RaidAllDay", player.IPlayer.Id).ToUpper(), 17, "robotocondensed-bold.ttf", HexToRustFormat(GetColor("green")), TextAnchor.MiddleCenter, "0.6 0.10", "1.0 1");
else if (allDayNoRaid) UI.AddText(ref container, "craidcontroller.static.txt", _ins.GetLang("RaidNoDay", player.IPlayer.Id).ToUpper(), 17, "robotocondensed-bold.ttf", HexToRustFormat(GetColor("red")), TextAnchor.MiddleCenter, "0.6 0.10", "1.0 1");
else if (wipeCooldown) {
UI.AddText(ref container, "craidcontroller.static.txt", _ins.GetLang("Until", player.IPlayer.Id, string.Empty).ToUpper(), 17, "robotocondensed-bold.ttf", "1 1 1 0.4", TextAnchor.MiddleLeft, "0.6 0", "1.0 1");
UI.AddText(ref container, "craidcontroller.static.txt", GetWipeCd().ToString("dd-MM", CultureInfo.InvariantCulture), 15, "robotocondensed-regular.ttf", "1 1 1 0.4", TextAnchor.UpperCenter, "0.8 0", "1.0 0.85");
UI.AddText(ref container, "craidcontroller.static.txt", $"________", 10, "robotocondensed-regular.ttf", "1 1 1 0.3", TextAnchor.MiddleCenter, "0.8 0.14", "1 1");
UI.AddText(ref container, "craidcontroller.static.txt", GetWipeCd().ToString("HH:mm", CultureInfo.InvariantCulture), 15, "robotocondensed-regular.ttf", "1 1 1 0.4", TextAnchor.LowerCenter, "0.8 0.15", "1.0 1");
}
else UI.AddText(ref container, "craidcontroller.static.txt", $"{GetTime(start)} / {GetTime(end)}", 21, "robotocondensed-regular.ttf", "1 1 1 0.4", TextAnchor.MiddleCenter, "0.4 0", "1.0 1.0");
UI.AddText(ref container, "craidcontroller.static.txt", _ins.GetLang("Rest", player.IPlayer.Id), 10, "robotocondensed-regular.ttf", "1 1 1 0.6", TextAnchor.LowerLeft, "0.05 0", "1.0 1");
UI.AddImageColor(ref container, "craidcontroller.static.txt", HexToRustFormat(GetColor("blacklight")), "0.20 0", "1 0", "10 3", "0 7.5");
CuiHelper.AddUi(player, container);
}
else {
var container = UI.CreateElementContainer("craidcontroller.progress.txt", "0 0 0 0", "0.428 0.11", "0.615 0.18");
UI.AddImageColor(ref container, "craidcontroller.progress.txt", color, "0 0", $"{progressCount} 0", "0 3.5", "0 7");
CuiHelper.AddUi(player, container);
}
break;
#endregion
#region UI #6
case 6 : if (all) {
var container = UI.CreateElementContainer("craidcontroller.static.txt", cfg.ui.background, "0.371 0.003", "0.615 0.02");
UI.AddText(ref container, "craidcontroller.static.txt", $"{GetTitle().ToUpper()} • {_ins.GetLang("Rest", player.IPlayer.Id)}", 10, "robotocondensed-regular.ttf", "1 1 1 0.6", TextAnchor.LowerLeft, "-0.1 0", "1.0 1");
UI.AddImageColor(ref container, "craidcontroller.static.txt", HexToRustFormat(GetColor("blacklight")), "0.40 0", "1 0", "10 3", "0 7.5");
CuiHelper.AddUi(player, container);
}
else {
var container = UI.CreateElementContainer("craidcontroller.progress.txt", "0 0 0 0", "0.477 0.0035", "0.615 0.02");
UI.AddImageColor(ref container, "craidcontroller.progress.txt", color, "0 0", $"{progressCount} 0", "0 3.5", "0 6");
CuiHelper.AddUi(player, container);
}
break;
#endregion
default : goto case 1;
}
}
private void DestroyUI(bool all = false) {
int uiChoice = 0;
if (!pConf.ContainsKey(player.userID)) uiChoice = cfg.ui.uiChoice;
else if (pConf[player.userID].choose > 0 && pConf[player.userID].choose <= _uiCount) uiChoice = pConf[player.userID].choose;
else uiChoice = cfg.ui.uiChoice;
if (all) {
CuiHelper.DestroyUi(player, "craidcontroller.static.txt");
CuiHelper.DestroyUi(player, "craidcontroller.progress.txt");
}
else CuiHelper.DestroyUi(player, "craidcontroller.progress.txt");
}
private void OnDestroy() => DestroyUI(true);
}
#endregion
#region Function
internal List<string> shortPrefabName = new List<string>() {
"ammo.rifle.incendiary", "ammo.rifle.explosive", "ammo.pistol.fire", "ammo.shotgun.fire"
}
;
public void RemoveCd(string t, ulong i) {
if (!pCd.ContainsKey($"{t}:{i}")) return;
timer.In(pCd[$"{t}:{i}"], () => {
pCd.Remove(($"{t}:{i}"));
}
);
}
private void Nullify(HitInfo info) {
info.damageTypes = new DamageTypeList();
info.HitEntity = null;
info.HitMaterial = 0;
info.PointStart = Vector3.zero;
}
private void CatchFireball(BasePlayer player, BaseCombatEntity entity, HitInfo info) {
var weapon = player.GetHeldEntity() as BaseProjectile;
if (weapon == null) return;
foreach (var x in shortPrefabName.Where(x => x == weapon.primaryMagazine.ammoType.shortname)) {
if (!fireBall.ContainsKey(DateTime.Now.TimeOfDay)) fireBall.Add(DateTime.Now.TimeOfDay, new FireBallList() {
entity = entity.net.ID, player = player.userID, radius = info.HitPositionWorld
}
);
}
}
internal Dictionary<string, string[]> prefabList = new Dictionary<string, string[]>() {
{
"explosive.timed", new string[] {
"explosive.timed.deployed", "explosive"
}
}
, {
"explosive.satchel", new string[] {
"explosive.satchel.deployed", "explosive"
}
}
, {
"grenade.beancan", new string[] {
"grenade.beancan.deployed", "grenade"
}
}
, {
"grenade.f1", new string[] {
"grenade.f1.deployed", "grenade"
}
}
, {
"grenade.molotov", new string[] {
"grenade.molotov.deployed", "grenade"
}
}
, {
"ammo.rocket.fire", new string[] {
"rocket_fire", "rocket"
}
}
, {
"ammo.rocket.hv", new string[] {
"rocket_hv", "rocket"
}
}
, {
"ammo.rocket.basic", new string[] {
"rocket_basic", "rocket"
}
}
, {
"ammo.grenadelauncher.he", new string[] {
"40mm_grenade_he", "grenadelauncher"
}
}
, {
"ammo.rifle", new string[] {
"riflebullet", "rifle"
}
}
, {
"ammo.rifle.explosive", new string[] {
"riflebullet_explosive", "rifle"
}
}
, {
"ammo.rifle.incendiary", new string[] {
"riflebullet_fire", "rifle"
}
}
, {
"ammo.pistol", new string[] {
"pistolbullet", "pistol"
}
}
, {
"ammo.pistol.fire", new string[] {
"pistolbullet_fire", "pistol"
}
}
, {
"ammo.shotgun", new string[] {
"shotgunbullet", "shotgun"
}
}
, {
"ammo.shotgun.fire", new string[] {
"shotgunbullet_fire", "shotgun"
}
}
, {
"ammo.shotgun.slug", new string[] {
"shotgunslug", "shotgun"
}
}
,
}
;
internal List<string> explosiveList = new List<string>() {
"rocket_fire", "rocket_hv", "rocket_basic", "explosive.timed.deployed", "survey_charge.deployed", "explosive.satchel.deployed", "grenade.beancan.deployed", "grenade.f1.deployed", "grenade.molotov.deployed", "40mm_grenade_he"
}
;
private void Refund(BasePlayer player, HitInfo info) {
if (cfg.config.refundAmmo.enabled) {
string name = string.Empty;
if (explosiveList.Contains(info?.WeaponPrefab?.ShortPrefabName)) name = info?.WeaponPrefab?.ShortPrefabName;
else name = info?.ProjectilePrefab?.name.ToString();
foreach (var x in prefabList) {
if (name == x.Value[0]) {
if (!cfg.config.refundAmmo.list.explosive && x.Value[1] == "explosive") return;
if (!cfg.config.refundAmmo.list.grenade && x.Value[1] == "grenade") return;
if (!cfg.config.refundAmmo.list.rocket && x.Value[1] == "rocket") return;
if (!cfg.config.refundAmmo.list.grenadelauncher && x.Value[1] == "grenadelauncher") return;
if (!cfg.config.refundAmmo.list.rifle && x.Value[1] == "rifle") return;
if (!cfg.config.refundAmmo.list.pistol && x.Value[1] == "pistol") return;
if (!cfg.config.refundAmmo.list.shotgun && x.Value[1] == "shotgun") return;
if (pCd.ContainsKey($"refund:{player.userID}")) return;
Item item = ItemManager.CreateByName(x.Key, 1);
player.GiveItem(item);
pCd.Add($"refund:{player.userID}", 0.1f);
RemoveCd("refund", player.userID);
}
}
}
}
private bool TakeDamage(BasePlayer player, BaseCombatEntity entity, HitInfo info, bool canRaid, bool wipeCooldown) {
if (wipeCooldown) canRaid = false;
if (!canRaid && (entity is BuildingBlock || entity is SimpleBuildingBlock || entity is Door || entity is ShopFront || entity.PrefabName.Contains("deploy"))) {
if (cfg.config.isAdmin && player.IsAdmin) return true;
if (cfg.config.isTwigs && entity is BuildingBlock) {
BuildingBlock ent = entity as BuildingBlock;
if (ent.grade.ToString() == "Twigs") return true;
}
if (cfg.config.isOwner && IsOwner(player.userID, entity.OwnerID)) return true;
if (cfg.config.isNoOwner && IsNoOwner(entity.OwnerID)) return true;
if (cfg.config.itemBypass.Contains(entity.PrefabName) && !IsTcProtected(entity, info)) return true;
if (cfg.config.itemBypassTcProtect.Contains(entity.PrefabName) && IsTcProtected(entity, info)) return true;
if (cfg.config.isDecay && IsDecay(entity, info) && IsTcProtected(entity, info)) return true;
if (cfg.config.isEmpty && IsDecay(entity, info) && !IsTcProtected(entity, info)) return true;
if (cfg.config.isMate && IsMate(player, entity.OwnerID)) return true;
if (entity.OwnerID == null || entity.OwnerID == 0) return true;
return false;
}
return true;
}
#endregion
#region UI
static class UI {
static public CuiElementContainer CreateElementContainer(string panel, string color, string aMin, string aMax) {
// ... [Code preview truncated due to length. Full source in attached file] ...