Gather Manager v2.2.75 - Quarry Patch

Created Diff never expires
64 removals
Lines
Total
Removed
Words
Total
Removed
To continue using this feature, upgrade to
Diffchecker logo
Diffchecker Pro
529 lines
68 additions
Lines
Total
Added
Words
Total
Added
To continue using this feature, upgrade to
Diffchecker logo
Diffchecker Pro
533 lines
using System;
using System;
using System.Collections.Generic;
using System.Collections.Generic;
using System.Linq;
using System.Linq;
using UnityEngine;
using UnityEngine;


namespace Oxide.Plugins
namespace Oxide.Plugins
{
{


[Info("Gathering Manager", "Mughisi", "2.2.75", ResourceId = 675)]
[Info("Gathering Manager", "Mughisi", "2.2.75", ResourceId = 675)]
class GatherManager : RustPlugin
class GatherManager : RustPlugin
{
{
#region Configuration Data
#region Configuration Data
// Do not modify these values because this will not change anything, the values listed below are only used to create
// Do not modify these values because this will not change anything, the values listed below are only used to create
// the initial configuration file. If you wish changes to the configuration file you should edit 'GatherManager.json'
// the initial configuration file. If you wish changes to the configuration file you should edit 'GatherManager.json'
// which is located in your server's config folder: <drive>:\...\server\<your_server_identity>\oxide\config\
// which is located in your server's config folder: <drive>:\...\server\<your_server_identity>\oxide\config\


private bool configChanged;
private bool configChanged;


// Plugin settings
// Plugin settings
private const string DefaultChatPrefix = "Gather Manager";
private const string DefaultChatPrefix = "Gather Manager";
private const string DefaultChatPrefixColor = "#008000ff";
private const string DefaultChatPrefixColor = "#008000ff";


public string ChatPrefix { get; private set; }
public string ChatPrefix { get; private set; }
public string ChatPrefixColor { get; private set; }
public string ChatPrefixColor { get; private set; }


// Plugin options
// Plugin options
private static readonly Dictionary<string, object> DefaultGatherResourceModifiers = new Dictionary<string, object>();
private static readonly Dictionary<string, object> DefaultGatherResourceModifiers = new Dictionary<string, object>();
private static readonly Dictionary<string, object> DefaultGatherDispenserModifiers = new Dictionary<string, object>();
private static readonly Dictionary<string, object> DefaultGatherDispenserModifiers = new Dictionary<string, object>();
private static readonly Dictionary<string, object> DefaultQuarryResourceModifiers = new Dictionary<string, object>();
private static readonly Dictionary<string, object> DefaultQuarryResourceModifiers = new Dictionary<string, object>();
private static readonly Dictionary<string, object> DefaultPickupResourceModifiers = new Dictionary<string, object>();
private static readonly Dictionary<string, object> DefaultPickupResourceModifiers = new Dictionary<string, object>();
private static readonly Dictionary<string, object> DefaultSurveyResourceModifiers = new Dictionary<string, object>();
private static readonly Dictionary<string, object> DefaultSurveyResourceModifiers = new Dictionary<string, object>();


// Defaults
// Defaults
private const float DefaultMiningQuarryResourceTickRate = 5f;
private const float DefaultMiningQuarryResourceTickRate = 5f;
private const float DefaultExcavatorResourceTickRate = 3f;
private const float DefaultExcavatorResourceTickRate = 3f;
private const float DefaultExcavatorTimeForFullResources = 120f;
private const float DefaultExcavatorTimeForFullResources = 120f;
private const float DefaultExcavatorBeltSpeedMax = 0.1f;
private const float DefaultExcavatorBeltSpeedMax = 0.1f;


public Dictionary<string, float> GatherResourceModifiers { get; private set; }
public Dictionary<string, float> GatherResourceModifiers { get; private set; }
public Dictionary<string, float> GatherDispenserModifiers { get; private set; }
public Dictionary<string, float> GatherDispenserModifiers { get; private set; }
public Dictionary<string, float> QuarryResourceModifiers { get; private set; }
public Dictionary<string, float> QuarryResourceModifiers { get; private set; }
public Dictionary<string, float> ExcavatorResourceModifiers { get; private set; }
public Dictionary<string, float> ExcavatorResourceModifiers { get; private set; }
public Dictionary<string, float> PickupResourceModifiers { get; private set; }
public Dictionary<string, float> PickupResourceModifiers { get; private set; }
public Dictionary<string, float> SurveyResourceModifiers { get; private set; }
public Dictionary<string, float> SurveyResourceModifiers { get; private set; }
public float MiningQuarryResourceTickRate { get; private set; }
public float MiningQuarryResourceTickRate { get; private set; }
public float ExcavatorResourceTickRate { get; private set; }
public float ExcavatorResourceTickRate { get; private set; }
public float ExcavatorTimeForFullResources { get; private set; }
public float ExcavatorTimeForFullResources { get; private set; }
public float ExcavatorBeltSpeedMax { get; private set; }
public float ExcavatorBeltSpeedMax { get; private set; }


// Plugin messages
// Plugin messages
private const string DefaultNotAllowed = "You don't have permission to use this command.";
private const string DefaultNotAllowed = "You don't have permission to use this command.";
private const string DefaultInvalidArgumentsGather =
private const string DefaultInvalidArgumentsGather =
"Invalid arguments supplied! Use gather.rate <type:dispenser|pickup|quarry|survey> <resource> <multiplier>";
"Invalid arguments supplied! Use gather.rate <type:dispenser|pickup|quarry|survey> <resource> <multiplier>";
private const string DefaultInvalidArgumentsDispenser =
private const string DefaultInvalidArgumentsDispenser =
"Invalid arguments supplied! Use dispenser.scale <dispenser:tree|ore|corpse> <multiplier>";
"Invalid arguments supplied! Use dispenser.scale <dispenser:tree|ore|corpse> <multiplier>";
private const string DefaultInvalidArgumentsSpeed =
private const string DefaultInvalidArgumentsSpeed =
"Invalid arguments supplied! Use quarry.rate <time between gathers in seconds>";
"Invalid arguments supplied! Use quarry.rate <time between gathers in seconds>";
private const string DefaultInvalidModifier =
private const string DefaultInvalidModifier =
"Invalid modifier supplied! The new modifier always needs to be bigger than 0!";
"Invalid modifier supplied! The new modifier always needs to be bigger than 0!";
private const string DefaultInvalidSpeed = "You can't set the speed lower than 1 second!";
private const string DefaultInvalidSpeed = "You can't set the speed lower than 1 second!";
private const string DefaultModifyResource = "You have set the gather rate for {0} to x{1} from {2}.";
private const string DefaultModifyResource = "You have set the gather rate for {0} to x{1} from {2}.";
private const string DefaultModifyResourceRemove = "You have reset the gather rate for {0} from {1}.";
private const string DefaultModifyResourceRemove = "You have reset the gather rate for {0} from {1}.";
private const string DefaultModifySpeed = "The Mining Quarry will now provide resources every {0} seconds.";
private const string DefaultModifySpeed = "The Mining Quarry will now provide resources every {0} seconds.";
private const string DefaultInvalidResource =
private const string DefaultInvalidResource =
"{0} is not a valid resource. Check gather.resources for a list of available options.";
"{0} is not a valid resource. Check gather.resources for a list of available options.";
private const string DefaultModifyDispenser = "You have set the resource amount for {0} dispensers to x{1}";
private const string DefaultModifyDispenser = "You have set the resource amount for {0} dispensers to x{1}";
private const string DefaultInvalidDispenser =
private const string DefaultInvalidDispenser =
"{0} is not a valid dispenser. Check gather.dispensers for a list of available options.";
"{0} is not a valid dispenser. Check gather.dispensers for a list of available options.";


private const string DefaultHelpText = "/gather - Shows you detailed gather information.";
private const string DefaultHelpText = "/gather - Shows you detailed gather information.";
private const string DefaultHelpTextPlayer = "Resources gained from gathering have been scaled to the following:";
private const string DefaultHelpTextPlayer = "Resources gained from gathering have been scaled to the following:";
private const string DefaultHelpTextAdmin = "To change the resources gained by gathering use the command:\r\ngather.rate <type:dispenser|pickup|quarry|survey> <resource> <multiplier>\r\nTo change the amount of resources in a dispenser type use the command:\r\ndispenser.scale <dispenser:tree|ore|corpse> <multiplier>\r\nTo change the time between Mining Quarry gathers:\r\nquarry.tickrate <seconds>";
private const string DefaultHelpTextAdmin = "To change the resources gained by gathering use the command:\r\ngather.rate <type:dispenser|pickup|quarry|survey> <resource> <multiplier>\r\nTo change the amount of resources in a dispenser type use the command:\r\ndispenser.scale <dispenser:tree|ore|corpse> <multiplier>\r\nTo change the time between Mining Quarry gathers:\r\nquarry.tickrate <seconds>";
private const string DefaultHelpTextPlayerGains = "Resources gained from {0}:";
private const string DefaultHelpTextPlayerGains = "Resources gained from {0}:";
private const string DefaultHelpTextPlayerMiningQuarrySpeed = "Time between Mining Quarry gathers: {0} second(s).";
private const string DefaultHelpTextPlayerMiningQuarrySpeed = "Time between Mining Quarry gathers: {0} second(s).";
private const string DefaultHelpTextPlayerDefault = "Default values.";
private const string DefaultHelpTextPlayerDefault = "Default values.";
private const string DefaultDispensers = "Resource Dispensers";
private const string DefaultDispensers = "Resource Dispensers";
private const string DefaultCharges = "Survey Charges";
private const string DefaultCharges = "Survey Charges";
private const string DefaultQuarries = "Mining Quarries";
private const string DefaultQuarries = "Mining Quarries";
private const string DefaultExcavators = "Excavators";
private const string DefaultExcavators = "Excavators";
private const string DefaultPickups = "pickups";
private const string DefaultPickups = "pickups";


public string NotAllowed { get; private set; }
public string NotAllowed { get; private set; }
public string InvalidArgumentsGather { get; private set; }
public string InvalidArgumentsGather { get; private set; }
public string InvalidArgumentsDispenser { get; private set; }
public string InvalidArgumentsDispenser { get; private set; }
public string InvalidArgumentsSpeed { get; private set; }
public string InvalidArgumentsSpeed { get; private set; }
public string InvalidModifier { get; private set; }
public string InvalidModifier { get; private set; }
public string InvalidSpeed { get; private set; }
public string InvalidSpeed { get; private set; }
public string ModifyResource { get; private set; }
public string ModifyResource { get; private set; }
public string ModifyResourceRemove { get; private set; }
public string ModifyResourceRemove { get; private set; }
public string ModifySpeed { get; private set; }
public string ModifySpeed { get; private set; }
public string InvalidResource { get; private set; }
public string InvalidResource { get; private set; }
public string ModifyDispenser { get; private set; }
public string ModifyDispenser { get; private set; }
public string InvalidDispenser { get; private set; }
public string InvalidDispenser { get; private set; }
public string HelpText { get; private set; }
public string HelpText { get; private set; }
public string HelpTextPlayer { get; private set; }
public string HelpTextPlayer { get; private set; }
public string HelpTextAdmin { get; private set; }
public string HelpTextAdmin { get; private set; }
public string HelpTextPlayerGains { get; private set; }
public string HelpTextPlayerGains { get; private set; }
public string HelpTextPlayerDefault { get; private set; }
public string HelpTextPlayerDefault { get; private set; }
public string HelpTextPlayerMiningQuarrySpeed { get; private set; }
public string HelpTextPlayerMiningQuarrySpeed { get; private set; }
public string Dispensers { get; private set; }
public string Dispensers { get; private set; }
public string Charges { get; private set; }
public string Charges { get; private set; }
public string Quarries { get; private set; }
public string Quarries { get; private set; }
public string Excavators { get; private set; }
public string Excavators { get; private set; }
public string Pickups { get; private set; }
public string Pickups { get; private set; }


#endregion
#endregion


private readonly List<string> subcommands = new List<string>() { "dispenser", "pickup", "quarry", "survey" };
private readonly List<string> subcommands = new List<string>() { "dispenser", "pickup", "quarry", "survey" };


private readonly Hash<string, ItemDefinition> validResources = new Hash<string, ItemDefinition>();
private readonly Hash<string, ItemDefinition> validResources = new Hash<string, ItemDefinition>();


private readonly Hash<string, ResourceDispenser.GatherType> validDispensers = new Hash<string, ResourceDispenser.GatherType>();
private readonly Hash<string, ResourceDispenser.GatherType> validDispensers = new Hash<string, ResourceDispenser.GatherType>();


private void Init() => LoadConfigValues();
private void Init() => LoadConfigValues();


private void OnServerInitialized()
private void OnServerInitialized()
{
{
var resourceDefinitions = ItemManager.itemList;
var resourceDefinitions = ItemManager.itemList;
foreach (var def in resourceDefinitions.Where(def => def.category == ItemCategory.Food || def.category == ItemCategory.Resources))
foreach (var def in resourceDefinitions.Where(def => def.category == ItemCategory.Food || def.category == ItemCategory.Resources))
validResources.Add(def.displayName.english.ToLower(), def);
validResources.Add(def.displayName.english.ToLower(), def);


validDispensers.Add("tree", ResourceDispenser.GatherType.Tree);
validDispensers.Add("tree", ResourceDispenser.GatherType.Tree);
validDispensers.Add("ore", ResourceDispenser.GatherType.Ore);
validDispensers.Add("ore", ResourceDispenser.GatherType.Ore);
validDispensers.Add("corpse", ResourceDispenser.GatherType.Flesh);
validDispensers.Add("corpse", ResourceDispenser.GatherType.Flesh);
validDispensers.Add("flesh", ResourceDispenser.GatherType.Flesh);
validDispensers.Add("flesh", ResourceDispenser.GatherType.Flesh);


foreach (var excavator in UnityEngine.Object.FindObjectsOfType<ExcavatorArm>())
updateQuarries();
{
updateExcavators();
if (ExcavatorResourceTickRate != DefaultMiningQuarryResourceTickRate)
{
excavator.CancelInvoke("ProcessResources");
excavator.InvokeRepeating("ProcessResources", ExcavatorResourceTickRate, ExcavatorResourceTickRate);
}

if (ExcavatorBeltSpeedMax != DefaultExcavatorBeltSpeedMax)
{
excavator.beltSpeedMax = ExcavatorBeltSpeedMax;
}

if (ExcavatorTimeForFullResources != DefaultExcavatorTimeForFullResources)
{
excavator.timeForFullResources = ExcavatorTimeForFullResources;
}
}
}
}


private void Unload()
private void Unload()
{
{
foreach (var excavator in UnityEngine.Object.FindObjectsOfType<ExcavatorArm>())
restoreQuarries();
{
restoreExcavators();
if (ExcavatorResourceTickRate != DefaultMiningQuarryResourceTickRate)
{
excavator.CancelInvoke("ProcessResources");
excavator.InvokeRepeating("ProcessResources", DefaultMiningQuarryResourceTickRate, DefaultMiningQuarryResourceTickRate);
}

if (ExcavatorBeltSpeedMax != DefaultExcavatorBeltSpeedMax)
{
excavator.beltSpeedMax = DefaultExcavatorBeltSpeedMax;
}

if (ExcavatorTimeForFullResources != DefaultExcavatorTimeForFullResources)
{
excavator.timeForFullResources = DefaultExcavatorTimeForFullResources;
}
}
}
}


protected override void LoadDefaultConfig() => PrintWarning("New configuration file created.");
protected override void LoadDefaultConfig() => PrintWarning("New configuration file created.");


[ChatCommand("gather")]
[ChatCommand("gather")]
private void Gather(BasePlayer player, string command, string[] args)
private void Gather(BasePlayer player, string command, string[] args)
{
{
var help = HelpTextPlayer;
var help = HelpTextPlayer;
if (GatherResourceModifiers.Count == 0 && SurveyResourceModifiers.Count == 0 && PickupResourceModifiers.Count == 0 && QuarryResourceModifiers.Count == 0)
if (GatherResourceModifiers.Count == 0 && SurveyResourceModifiers.Count == 0 && PickupResourceModifiers.Count == 0 && QuarryResourceModifiers.Count == 0)
help += HelpTextPlayerDefault;
help += HelpTextPlayerDefault;
else
else
{
{
if (GatherResourceModifiers.Count > 0)
if (GatherResourceModifiers.Count > 0)
{
{
var dispensers = string.Format(HelpTextPlayerGains, Dispensers);
var dispensers = string.Format(HelpTextPlayerGains, Dispensers);
dispensers = GatherResourceModifiers.Aggregate(dispensers, (current, entry) => current + ("\r\n " + entry.Key + ": x" + entry.Value));
dispensers = GatherResourceModifiers.Aggregate(dispensers, (current, entry) => current + ("\r\n " + entry.Key + ": x" + entry.Value));
help += "\r\n" + dispensers;
help += "\r\n" + dispensers;
}
}
if (PickupResourceModifiers.Count > 0)
if (PickupResourceModifiers.Count > 0)
{
{
var pickups = string.Format(HelpTextPlayerGains, Pickups);
var pickups = string.Format(HelpTextPlayerGains, Pickups);
pickups = PickupResourceModifiers.Aggregate(pickups, (current, entry) => current + ("\r\n " + entry.Key + ": x" + entry.Value));
pickups = PickupResourceModifiers.Aggregate(pickups, (current, entry) => current + ("\r\n " + entry.Key + ": x" + entry.Value));
help += "\r\n" + pickups;
help += "\r\n" + pickups;
}
}
if (QuarryResourceModifiers.Count > 0)
if (QuarryResourceModifiers.Count > 0)
{
{
var quarries = string.Format(HelpTextPlayerGains, Quarries);
var quarries = string.Format(HelpTextPlayerGains, Quarries);
quarries = QuarryResourceModifiers.Aggregate(quarries, (current, entry) => current + ("\r\n " + entry.Key + ": x" + entry.Value));
quarries = QuarryResourceModifiers.Aggregate(quarries, (current, entry) => current + ("\r\n " + entry.Key + ": x" + entry.Value));
help += "\r\n" + quarries;
help += "\r\n" + quarries;
}
}
if (ExcavatorResourceModifiers.Count > 0)
if (ExcavatorResourceModifiers.Count > 0)
{
{
var excavators = string.Format(HelpTextPlayerGains, Excavators);
var excavators = string.Format(HelpTextPlayerGains, Excavators);
excavators = ExcavatorResourceModifiers.Aggregate(excavators, (current, entry) => current + ("\r\n " + entry.Key + ": x" + entry.Value));
excavators = ExcavatorResourceModifiers.Aggregate(excavators, (current, entry) => current + ("\r\n " + entry.Key + ": x" + entry.Value));
help += "\r\n" + excavators;
help += "\r\n" + excavators;
}
}
if (SurveyResourceModifiers.Count > 0)
if (SurveyResourceModifiers.Count > 0)
{
{
var charges = string.Format(HelpTextPlayerGains, Charges);
var charges = string.Format(HelpTextPlayerGains, Charges);
charges = SurveyResourceModifiers.Aggregate(charges, (current, entry) => current + ("\r\n " + entry.Key + ": x" + entry.Value));
charges = SurveyResourceModifiers.Aggregate(charges, (current, entry) => current + ("\r\n " + entry.Key + ": x" + entry.Value));
help += "\r\n" + charges;
help += "\r\n" + charges;
}
}
}
}


if (MiningQuarryResourceTickRate != DefaultMiningQuarryResourceTickRate)
if (MiningQuarryResourceTickRate != DefaultMiningQuarryResourceTickRate)
help += "\r\n" + string.Format(HelpTextPlayerMiningQuarrySpeed, MiningQuarryResourceTickRate);
help += "\r\n" + string.Format(HelpTextPlayerMiningQuarrySpeed, MiningQuarryResourceTickRate);


SendMessage(player, help);
SendMessage(player, help);
if (!player.IsAdmin) return;
if (!player.IsAdmin) return;
SendMessage(player, HelpTextAdmin);
SendMessage(player, HelpTextAdmin);
}
}


private void SendHelpText(BasePlayer player) => SendMessage(player, HelpText);
private void SendHelpText(BasePlayer player) => SendMessage(player, HelpText);


[ConsoleCommand("gather.rate")]
[ConsoleCommand("gather.rate")]
private void GatherRate(ConsoleSystem.Arg arg)
private void GatherRate(ConsoleSystem.Arg arg)
{
{
if (arg.Player() != null && !arg.Player().IsAdmin)
if (arg.Player() != null && !arg.Player().IsAdmin)
{
{
arg.ReplyWith(NotAllowed);
arg.ReplyWith(NotAllowed);
return;
return;
}
}


var subcommand = arg.GetString(0).ToLower();
var subcommand = arg.GetString(0).ToLower();
if (!arg.HasArgs(3) || !subcommands.Contains(subcommand))
if (!arg.HasArgs(3) || !subcommands.Contains(subcommand))
{
{
arg.ReplyWith(InvalidArgumentsGather);
arg.ReplyWith(InvalidArgumentsGather);
return;
return;
}
}


if (!validResources[arg.GetString(1).ToLower()] && arg.GetString(1) != "*")
if (!validResources[arg.GetString(1).ToLower()] && arg.GetString(1) != "*")
{
{
arg.ReplyWith(string.Format(InvalidResource, arg.GetString(1)));
arg.ReplyWith(string.Format(InvalidResource, arg.GetString(1)));
return;
return;
}
}


var resource = validResources[arg.GetString(1).ToLower()]?.displayName.english ?? "*";
var resource = validResources[arg.GetString(1).ToLower()]?.displayName.english ?? "*";
var modifier = arg.GetFloat(2, -1);
var modifier = arg.GetFloat(2, -1);
var remove = false;
var remove = false;
if (modifier < 0)
if (modifier < 0)
{
{
if (arg.GetString(2).ToLower() == "remove")
if (arg.GetString(2).ToLower() == "remove")
remove = true;
remove = true;
else
else
{
{
arg.ReplyWith(InvalidModifier);
arg.ReplyWith(InvalidModifier);
return;
return;
}
}
}
}


switch (subcommand)
switch (subcommand)
{
{
case "dispenser":
case "dispenser":
if (remove)
if (remove)
{
{
if (GatherResourceModifiers.ContainsKey(resource))
if (GatherResourceModifiers.ContainsKey(resource))
GatherResourceModifiers.Remove(resource);
GatherResourceModifiers.Remove(resource);
arg.ReplyWith(string.Format(ModifyResourceRemove, resource, Dispensers));
arg.ReplyWith(string.Format(ModifyResourceRemove, resource, Dispensers));
}
}
else
else
{
{
if (GatherResourceModifiers.ContainsKey(resource))
if (GatherResourceModifiers.ContainsKey(resource))
GatherResourceModifiers[resource] = modifier;
GatherResourceModifiers[resource] = modifier;
else
else
GatherResourceModifiers.Add(resource, modifier);
GatherResourceModifiers.Add(resource, modifier);
arg.ReplyWith(string.Format(ModifyResource, resource, modifier, Dispensers));
arg.ReplyWith(string.Format(ModifyResource, resource, modifier, Dispensers));
}
}
SetConfigValue("Options", "GatherResourceModifiers", GatherResourceModifiers);
SetConfigValue("Options", "GatherResourceModifiers", GatherResourceModifiers);
break;
break;
case "pickup":
case "pickup":
if (remove)
if (remove)
{
{
if (PickupResourceModifiers.ContainsKey(resource))
if (PickupResourceModifiers.ContainsKey(resource))
PickupResourceModifiers.Remove(resource);
PickupResourceModifiers.Remove(resource);
arg.ReplyWith(string.Format(ModifyResourceRemove, resource, Pickups));
arg.ReplyWith(string.Format(ModifyResourceRemove, resource, Pickups));
}
}
else
else
{
{
if (PickupResourceModifiers.ContainsKey(resource))
if (PickupResourceModifiers.ContainsKey(resource))
PickupResourceModifiers[resource] = modifier;
PickupResourceModifiers[resource] = modifier;
else
else
PickupResourceModifiers.Add(resource, modifier);
PickupResourceModifiers.Add(resource, modifier);
arg.ReplyWith(string.Format(ModifyResource, resource, modifier, Pickups));
arg.ReplyWith(string.Format(ModifyResource, resource, modifier, Pickups));
}
}
SetConfigValue("Options", "PickupResourceModifiers", PickupResourceModifiers);
SetConfigValue("Options", "PickupResourceModifiers", PickupResourceModifiers);
break;
break;
case "quarry":
case "quarry":
if (remove)
if (remove)
{
{
if (QuarryResourceModifiers.ContainsKey(resource))
if (QuarryResourceModifiers.ContainsKey(resource))
QuarryResourceModifiers.Remove(resource);
QuarryResourceModifiers.Remove(resource);
arg.ReplyWith(string.Format(ModifyResourceRemove, resource, Quarries));
arg.ReplyWith(string.Format(ModifyResourceRemove, resource, Quarries));
}
}
else
else
{
{
if (QuarryResourceModifiers.ContainsKey(resource))
if (QuarryResourceModifiers.ContainsKey(resource))
QuarryResourceModifiers[resource] = modifier;
QuarryResourceModifiers[resource] = modifier;
else
else
QuarryResourceModifiers.Add(resource, modifier);
QuarryResourceModifiers.Add(resource, modifier);
arg.ReplyWith(string.Format(ModifyResource, resource, modifier, Quarries));
arg.ReplyWith(string.Format(ModifyResource, resource, modifier, Quarries));
}
}
SetConfigValue("Options", "QuarryResourceModifiers", QuarryResourceModifiers);
SetConfigValue("Options", "QuarryResourceModifiers", QuarryResourceModifiers);
break;
break;
case "excavator":
case "excavator":
if (remove)
if (remove)
{
{
if (ExcavatorResourceModifiers.ContainsKey(resource))
if (ExcavatorResourceModifiers.ContainsKey(resource))
ExcavatorResourceModifiers.Remove(resource);
ExcavatorResourceModifiers.Remove(resource);
arg.ReplyWith(string.Format(ModifyResourceRemove, resource, Excavators));
arg.ReplyWith(string.Format(ModifyResourceRemove, resource, Excavators));
}
}
else
else
{
{
if (ExcavatorResourceModifiers.ContainsKey(resource))
if (ExcavatorResourceModifiers.ContainsKey(resource))
ExcavatorResourceModifiers[resource] = modifier;
ExcavatorResourceModifiers[resource] = modifier;
else
else
ExcavatorResourceModifiers.Add(resource, modifier);
ExcavatorResourceModifiers.Add(resource, modifier);
arg.ReplyWith(string.Format(ModifyResource, resource, modifier, Excavators));
arg.ReplyWith(string.Format(ModifyResource, resource, modifier, Excavators));
}
}
SetConfigValue("Options", "ExcavatorResourceModifiers", ExcavatorResourceModifiers);
SetConfigValue("Options", "ExcavatorResourceModifiers", ExcavatorResourceModifiers);
break;
break;
case "survey":
case "survey":
if (remove)
if (remove)
{
{
if (SurveyResourceModifiers.ContainsKey(resource))
if (SurveyResourceModifiers.ContainsKey(resource))
SurveyResourceModifiers.Remove(resource);
SurveyResourceModifiers.Remove(resource);
arg.ReplyWith(string.Format(ModifyResourceRemove, resource, Charges));
arg.ReplyWith(string.Format(ModifyResourceRemove, resource, Charges));
}
}
else
else
{
{
if (SurveyResourceModifiers.ContainsKey(resource))
if (SurveyResourceModifiers.ContainsKey(resource))
SurveyResourceModifiers[resource] = modifier;
SurveyResourceModifiers[resource] = modifier;
else
else
SurveyResourceModifiers.Add(resource, modifier);
SurveyResourceModifiers.Add(resource, modifier);
arg.ReplyWith(string.Format(ModifyResource, resource, modifier, Charges));
arg.ReplyWith(string.Format(ModifyResource, resource, modifier, Charges));
}
}
SetConfigValue("Options", "SurveyResourceModifiers", SurveyResourceModifiers);
SetConfigValue("Options", "SurveyResourceModifiers", SurveyResourceModifiers);
break;
break;
}
}
}
}


[ConsoleCommand("gather.resources")]
[ConsoleCommand("gather.resources")]
private void GatherResources(ConsoleSystem.Arg arg)
private void GatherResources(ConsoleSystem.Arg arg)
{
{
if (arg.Player() != null && !arg.Player().IsAdmin)
if (arg.Player() != null && !arg.Player().IsAdmin)
{
{
arg.ReplyWith(NotAllowed);
arg.ReplyWith(NotAllowed);
return;
return;
}
}


arg.ReplyWith(validResources.Aggregate("Available resources:\r\n", (current, resource) => current + (resource.Value.displayName.english + "\r\n")) + "* (For all resources that are not setup separately)");
arg.ReplyWith(validResources.Aggregate("Available resources:\r\n", (current, resource) => current + (resource.Value.displayName.english + "\r\n")) + "* (For all resources that are not setup separately)");
}
}


[ConsoleCommand("gather.dispensers")]
[ConsoleCommand("gather.dispensers")]
private void GatherDispensers(ConsoleSystem.Arg arg)
private void GatherDispensers(ConsoleSystem.Arg arg)
{
{
if (arg.Player() != null && !arg.Player().IsAdmin)
if (arg.Player() != null && !arg.Player().IsAdmin)
{
{
arg.ReplyWith(NotAllowed);
arg.ReplyWith(NotAllowed);
return;
return;
}
}


arg.ReplyWith(validDispensers.Aggregate("Available dispensers:\r\n", (current, dispenser) => current + (dispenser.Value.ToString("G") + "\r\n")));
arg.ReplyWith(validDispensers.Aggregate("Available dispensers:\r\n", (current, dispenser) => current + (dispenser.Value.ToString("G") + "\r\n")));
}
}




[ConsoleCommand("dispenser.scale")]
[ConsoleCommand("dispenser.scale")]
private void DispenserRate(ConsoleSystem.Arg arg)
private void DispenserRate(ConsoleSystem.Arg arg)
{
{
if (arg.Player() != null && !arg.Player().IsAdmin)
if (arg.Player() != null && !arg.Player().IsAdmin)
{
{
arg.ReplyWith(NotAllowed);
arg.ReplyWith(NotAllowed);
return;
return;
}
}


if (!arg.HasArgs(2))
if (!arg.HasArgs(2))
{
{
arg.ReplyWith(InvalidArgumentsDispenser);
arg.ReplyWith(InvalidArgumentsDispenser);
return;
return;
}
}


if (!validDispensers.ContainsKey(arg.GetString(0).ToLower()))
if (!validDispensers.ContainsKey(arg.GetString(0).ToLower()))
{
{
arg.ReplyWith(string.Format(InvalidDispenser, arg.GetString(0)));
arg.ReplyWith(string.Format(InvalidDispenser, arg.GetString(0)));
return;
return;
}
}


var dispenser = validDispensers[arg.GetString(0).ToLower()].ToString("G");
var dispenser = validDispensers[arg.GetString(0).ToLower()].ToString("G");
var modifier = arg.GetFloat(1, -1);
var modifier = arg.GetFloat(1, -1);
if (modifier < 0)
if (modifier < 0)
{
{
arg.ReplyWith(InvalidModifier);
arg.ReplyWith(InvalidModifier);
return;
return;
}
}


if (GatherDispenserModifiers.ContainsKey(dispenser))
if (GatherDispenserModifiers.ContainsKey(dispenser))
GatherDispenserModifiers[dispenser] = modifier;
GatherDispenserModifiers[dispenser] = modifier;
else
else
GatherDispenserModifiers.Add(dispenser, modifier);
GatherDispenserModifiers.Add(dispenser, modifier);
SetConfigValue("Options", "GatherDispenserModifiers", GatherDispenserModifiers);
SetConfigValue("Options", "GatherDispenserModifiers", GatherDispenserModifiers);
arg.ReplyWith(string.Format(ModifyDispenser, dispenser, modifier));
arg.ReplyWith(string.Format(ModifyDispenser, dispenser, modifier));
}
}


[ConsoleCommand("quarry.tickrate")]
[ConsoleCommand("quarry.tickrate")]
private void MiningQuarryTickRate(ConsoleSystem.Arg arg)
private void MiningQuarryTickRate(ConsoleSystem.Arg arg)
{
{
if (arg.Player() != null && !arg.Player().IsAdmin)
if (arg.Player() != null && !arg.Player().IsAdmin)
{
{
arg.ReplyWith(NotAllowed);
arg.ReplyWith(NotAllowed);
return;
return;
}
}


if (!arg.HasArgs())
if (!arg.HasArgs())
{
{
arg.ReplyWith(InvalidArgumentsSpeed);
arg.ReplyWith(InvalidArgumentsSpeed);
return;
return;
}
}


var modifier = arg.GetFloat(0, -1);
var modifier = arg.GetFloat(0, -1);
if (modifier < 1)
if (modifier < 1)
{
{
arg.ReplyWith(InvalidSpeed);
arg.ReplyWith(InvalidSpeed);
return;
return;
}
}


MiningQuarryResourceTickRate = modifier;
MiningQuarryResourceTickRate = modifier;
SetConfigValue("Options", "MiningQuarryResourceTickRate", MiningQuarryResourceTickRate);
SetConfigValue("Options", "MiningQuarryResourceTickRate", MiningQuarryResourceTickRate);
arg.ReplyWith(string.Format(ModifySpeed, modifier));
arg.ReplyWith(string.Format(ModifySpeed, modifier));
updateQuarries();
}
private void updateQuarries()
{
var quarries = UnityEngine.Object.FindObjectsOfType<MiningQuarry>();
var quarries = UnityEngine.Object.FindObjectsOfType<MiningQuarry>();
foreach (var quarry in quarries.Where(quarry => quarry.IsOn()))
foreach (var quarry in quarries)
{
{
quarry.CancelInvoke("ProcessResources");
if (quarry.IsOn() && quarry.processRate != MiningQuarryResourceTickRate)
quarry.InvokeRepeating("ProcessResources", MiningQuarryResourceTickRate, MiningQuarryResourceTickRate);
{
quarry.CancelInvoke(quarry.ProcessResources);
quarry.InvokeRepeating(quarry.ProcessResources, MiningQuarryResourceTickRate, MiningQuarryResourceTickRate);
}
quarry.processRate = MiningQuarryResourceTickRate;
}
}
private void restoreQuarries()
{
var quarries = UnityEngine.Object.FindObjectsOfType<MiningQuarry>();
foreach (var quarry in quarries)
{
if (quarry.IsOn() && quarry.processRate != DefaultMiningQuarryResourceTickRate)
{
quarry.CancelInvoke(quarry.ProcessResources);
quarry.InvokeRepeating(quarry.ProcessResources, DefaultMiningQuarryResourceTickRate, DefaultMiningQuarryResourceTickRate);
}
quarry.processRate = DefaultMiningQuarryResourceTickRate;
}
}
}
}


[ConsoleCommand("excavator.tickrate")]
[ConsoleCommand("excavator.tickrate")]
private void ExcavatorTickRate(ConsoleSystem.Arg arg)
private void ExcavatorTickRate(ConsoleSystem.Arg arg)
{
{
if (arg.Player() != null && !arg.Player().IsAdmin)
if (arg.Player() != null && !arg.Player().IsAdmin)
{
{
arg.ReplyWith(NotAllowed);
arg.ReplyWith(NotAllowed);
return;
return;
}
}


if (!arg.HasArgs())
if (!arg.HasArgs())
{
{
arg.ReplyWith(InvalidArgumentsSpeed);
arg.ReplyWith(InvalidArgumentsSpeed);
return;
return;
}
}


var modifier = arg.GetFloat(0, -1);
var modifier = arg.GetFloat(0, -1);
if (modifier < 1)
if (modifier < 1)
{
{
arg.ReplyWith(InvalidSpeed);
arg.ReplyWith(InvalidSpeed);
return;
return;
}
}


ExcavatorResourceTickRate = modifier;
ExcavatorResourceTickRate = modifier;
SetConfigValue("Options", "ExcavatorResourceTickRate", ExcavatorResourceTickRate);
SetConfigValue("Options", "ExcavatorResourceTickRate", ExcavatorResourceTickRate);
arg.ReplyWith(string.Format(ModifySpeed, modifier));
arg.ReplyWith(string.Format(ModifySpeed, modifier));
var excavators = UnityEngine.Object.FindObjectsOfType<MiningQuarry>();
updateExcavators();
foreach (var excavator in excavators.Where(excavator => excavator.IsOn()))
}
private void updateExcavators()
{
var excavators = UnityEngine.Object.FindObjectsOfType<ExcavatorArm>();
foreach (var excavator in excavators)
{
{
excavator.CancelInvoke("ProcessResources");
if (excavator.IsOn() && excavator.resourceProductionTickRate != MiningQuarryResourceTickRate)
excavator.InvokeRepeating("ProcessResources", ExcavatorResourceTickRate, ExcavatorResourceTickRate);
{
excavator.CancelInvoke(excavator.ProduceResources);
excavator.InvokeRepeating(excavator.ProduceResources, ExcavatorResourceTickRate, ExcavatorResourceTickRate);
}
excavator.resourceProductionTickRate = MiningQuarryResourceTickRate;

excavator.beltSpeedMax = ExcavatorBeltSpeedMax;

excavator.timeForFullResources = ExcavatorTimeForFullResources;
}
}
private void restoreExcavators()
{
var excavators = UnityEngine.Object.FindObjectsOfType<ExcavatorArm>();
foreach (var excavator in excavators)
{
if (excavator.IsOn() && excavator.resourceProductionTickRate != MiningQuarryResourceTickRate)
{
excavator.CancelInvoke(excavator.ProduceResources);
excavator.InvokeRepeating(excavator.ProduceResources, DefaultExcavatorResourceTickRate, DefaultExcavatorResourceTickRate);
}
excavator.resourceProductionTickRate = MiningQuarryResourceTickRate;

excavator.beltSpeedMax = DefaultExcavatorBeltSpeedMax;

excavator.timeForFullResources = DefaultExcavatorTimeForFullResources;
}
}
}
}


private void OnDispenserGather(ResourceDispenser dispenser, BaseEntity entity, Item item)
private void OnDispenserGather(ResourceDispenser dispenser, BaseEntity entity, Item item)
{
{
if (!entity.ToPlayer())
if (!entity.ToPlayer())
{
{
return;
return;
}
}


var gatherType = dispenser.gatherType.ToString("G");
var gatherType = dispenser.gatherType.ToString("G");
var amount = item.amount;
var amount = item.amount;


float modifier;
float modifier;
if (GatherResourceModifiers.TryGetValue(item.info.displayName.english, out modifier))
if (GatherResourceModifiers.TryGetValue(item.info.displayName.english, out modifier))
{
{
item.amount = (int)(item.amount * modifier);
item.amount = (int)(item.amount * modifier);
}
}
else if (GatherResourceModifiers.TryGetValue("*", out modifier))
else if (GatherResourceModifiers.TryGetValue("*", out modifier))
{
{
item.amount = (int)(item.amount * modifier);
item.amount = (int)(item.amount * modifier);
}
}


if (!GatherResourceModifiers.ContainsKey(gatherType))
if (!GatherResourceModifiers.ContainsKey(gatherType))
{
{
return;
return;
}
}


var dispenserModifier = GatherDispenserModifiers[gatherType];
var dispenserModifier = GatherDispenserModifiers[gatherType];


try
try
{
{
dispenser.containedItems.Single(x => x.itemid == item.info.itemid).amount += amount - item.amount / dispenserModifier;
dispenser.containedItems.Single(x => x.itemid == item.info.itemid).amount += amount - item.amount / dispenserModifier;


if (dispenser.containedItems.Single(x => x.itemid == item.info.itemid).amount < 0)
if (dispenser.containedItems.Single(x => x.itemid == item.info.itemid).amount < 0)
{
{
item.amount += (int)dispenser.containedItems.Single(x => x.itemid == item.info.itemid).amount;
item.amount += (int)dispenser.containedItems.Single(x => x.itemid == item.info.itemid).amount;
}
}
}
}
catch { }
catch
}

private void OnDispenserBonus(ResourceDispenser dispenser, BaseEntity entity, Item item)
{
OnDispenserGather(dispenser, entity, item);
}

private void OnGrowableGathered(GrowableEntity growable, Item item, BasePlayer player)
{
float modifier;
if ( GatherResourceModifiers.TryGetValue(item.info.displayName.english, out modifier) )
{
item.amount = (int)(item.amount * modifier);
}
else if ( GatherResourceModifiers.TryGetValue("*", out modifier) )
{
item.amount = (int)(item.amount * modifier);