C#:
// Все права принадлежат дискорд сообществу https://discord.gg/VgNHPpNrz6
using Newtonsoft.Json;
using Oxide.Core;
using System.Collections.Generic;
using System.Linq;
using UnityEngine;
/*
▄▄▄▄ ███▄ ▄███▓ ▄████ ▄▄▄██▀▀▀▓█████▄▄▄█████▓
▓█████▄ ▓██▒▀█▀ ██▒ ██▒ ▀█▒ ▒██ ▓█ ▀▓ ██▒ ▓▒
▒██▒ ▄██▓██ ▓██░▒██░▄▄▄░ ░██ ▒███ ▒ ▓██░ ▒░
▒██░█▀ ▒██ ▒██ ░▓█ ██▓▓██▄██▓ ▒▓█ ▄░ ▓██▓ ░
░▓█ ▀█▓▒██▒ ░██▒░▒▓███▀▒ ▓███▒ ░▒████▒ ▒██▒ ░
░▒▓███▀▒░ ▒░ ░ ░ ░▒ ▒ ▒▓▒▒░ ░░ ▒░ ░ ▒ ░░
▒░▒ ░ ░ ░ ░ ░ ░ ▒ ░▒░ ░ ░ ░ ░
░ ░ ░ ░ ░ ░ ░ ░ ░ ░ ░ ░
░ ░ ░ ░ ░ ░ ░
*/
namespace Oxide.Plugins {
[Info("industrialquarry", "bmgjet", "1.2.1")]
[Description("Connect Industrial pipes up to the quarry.")]
class industrialquarry : RustPlugin {
private StoredData storedData;
private class StoredData {
public List<IQuarry2> LoadedIQuarrys = new List<IQuarry2>();
}
//Permission
private string permallow = "industrialquarry.allow";
//Permission required to use plugin
//Strings
private const string StorageAdapter = "assets/prefabs/deployable/playerioents/industrialadaptors/storageadaptor.deployed.prefab";
private const string Conveyor = "assets/prefabs/deployable/playerioents/industrialconveyor/industrialconveyor.deployed.prefab";
private const string SwitchPrefab = "assets/prefabs/deployable/playerioents/simpleswitch/switch.prefab";
private const string QuarryRock = "assets/bundled/prefabs/modding/admin/admin_rock_quarry_small_a.prefab";
public class IQuarry2 {
public ulong OwnerID;
public ulong ParentQuarry;
public Vector3 ParentPosition;
public ulong StoneNetID;
public ulong FuelAdapterNetID0;
public ulong FuelAdapterNetID1;
public ulong ResourceAdapterNetID0;
public ulong ResourceAdapterNetID1;
public ulong SwitchNetID;
public Vector3[] Pipes0;
public Vector3[] Pipes1;
}
#region Configuration
private PluginConfig _config;
private class PluginConfig {
[JsonProperty("Output Debug Messages In Console")]
public bool DebugMessages = false;
[JsonProperty("Underground Quarry Height Offset (Custom Maps)")]
public float underGroundQuarryHeightOffset = 2;
[JsonProperty("Underground Quarry Forward Offset (Custom Maps)")]
public float underGroundQuarryForwardOffset = 1;
[JsonProperty("Add a conveyor to the quarry output")]
public bool AddOutput = true;
[JsonProperty("Add a conveyor to the fuel tank")]
public bool AddFuelInput = true;
[JsonProperty("Add a IO On/Off Switch")]
public bool AddIOSwitch = true;
[JsonProperty("Attach to monument/map placed quarries")]
public bool AllowOnStaticQuarrys = true;
[JsonProperty("Adjust amount to move each tick, If set -1 will set default (128 default, quarries faster than that so raise to 256).")]
public int MaxStackSizePerMoveAdustment = 256;
[JsonProperty("Block players from switching off the conveyors on the quarry stone.")]
public bool BlockSwitchingOffConveyors = true;
[JsonProperty("Check for missing quarry parts every (sec)")]
public int MissingPartsDelay = 60;
public string ToJson() => JsonConvert.SerializeObject(this);
public Dictionary<string, object> ToDictionary() => JsonConvert.DeserializeObject<Dictionary<string, object>>(ToJson());
}
protected override void LoadDefaultConfig() {
_config = new PluginConfig();
}
protected override void LoadConfig() {
base.LoadConfig();
try {
_config = Config.ReadObject<PluginConfig>();
if (_config == null) {
throw new JsonException();
}
if (!_config.ToDictionary().Keys.SequenceEqual(Config.ToDictionary(x => x.Key, x => x.Value).Keys)) {
PrintWarning("Configuration appears to be outdated; updating and saving");
SaveConfig();
}
}
catch {
PrintWarning($"Configuration file {Name}.json is invalid; using defaults");
LoadDefaultConfig();
}
}
protected override void SaveConfig() {
PrintWarning($"Configuration changes saved to {Name}.json");
Config.WriteObject(_config, true);
}
#endregion Configuration
private void Init() {
Unsubscribe("OnEntityKill");
Unsubscribe("OnEntitySpawned");
storedData = Interface.Oxide.DataFileSystem.ReadObject<StoredData>("industrialquarry");
//Add permissions
permission.RegisterPermission(permallow, this);
}
[ChatCommand("killiq")]
private void ChatKillIndustrialQuarry(BasePlayer player, string command, string[] args) {
if (player.IsAdmin) //limit to admin
{
RaycastHit hit;
var raycast = UnityEngine.Physics.Raycast(player.eyes.HeadRay(), out hit, 10, -1);
BaseEntity entity = raycast ? hit.GetEntity() : null;
if (entity != null) {
entity.skinID = 0;
entity.Kill();
}
}
}
[ChatCommand("cleaniq")]
private void ChatIndustrialQuarry(BasePlayer player, string command, string[] args) {
if (player.IsAdmin) //limit to admin
{
foreach (BaseNetworkable bn in BaseNetworkable.serverEntities.entityList.Values) //Scan all server ents
{
if (bn.PrefabName == QuarryRock) //Found the rock things mounted to
{
List<BaseEntity> list = new List<BaseEntity>();
Vis.Entities<BaseEntity>(bn.transform.position, 6f, list);
//Scan everything within 6f
foreach (BaseEntity be in list) {
if (be is IOEntity && !be.IsDestroyed) {
(bn as BaseEntity).skinID = 0;
be.Kill();
}
}
//Kill io ents
if (!bn.IsDestroyed) {
bn.Kill();
}
//kill rock
continue;
}
try {
if ((bn as BaseEntity).skinID == 1234567890) {
(bn as BaseEntity).skinID = 0;
bn.Kill();
}
}
catch {
}
}
//_SpawnedList.Clear();
player.ChatMessage("Cleaned IQ Ents.Respawning in 5secs");
Startup(10);
//restart plugin so it respawns and reconnects
}
}
[ChatCommand("addiq")]
private void ChatAddIndustrialQuarry(BasePlayer player, string command, string[] args) {
//Check permission
if (!permission.UserHasPermission(player.UserIDString, permallow)) {
player.ChatMessage("You Don't Have The Required Permission!");
return;
}
//Find quarry player looking at
MiningQuarry entity = FindQuarry(player.eyes.HeadRay());
if (entity == null) {
player.ChatMessage("No Quarry Found!");
return;
}
//Check Owner
if (entity.OwnerID != player.userID && !player.IsAdmin) {
player.ChatMessage("You Don't Own This Quarry!");
return;
}
//Check if it already has parts
foreach (var q in storedData.LoadedIQuarrys) {
if (q.ParentQuarry == entity.net.ID.Value) {
player.ChatMessage("Already Set As Industrial Quarry!");
return;
}
}
//Add parts
player.ChatMessage("Adding Industrial Parts.");
AttachIndustrialParts(entity);
}
[ChatCommand("removeiq")]
private void ChatRemoveIndustrialQuarry(BasePlayer player, string command, string[] args) {
//Check permission
if (!permission.UserHasPermission(player.UserIDString, permallow)) {
player.ChatMessage("You Don't Have The Required Permission!");
return;
}
//Find quarry player looking at
MiningQuarry entity = FindQuarry(player.eyes.HeadRay());
if (entity == null) {
player.ChatMessage("No Quarry Found!");
return;
}
//Check Owner
if (entity.OwnerID != player.userID && !player.IsAdmin) {
player.ChatMessage("You Don't Own This Quarry!");
return;
}
//Check if it already has parts
foreach (var q in storedData.LoadedIQuarrys) {
if (q.ParentQuarry == entity.net.ID.Value) {
player.ChatMessage("Removing Industrial Quarry!");
RemoveQuarry(entity, true);
return;
}
}
}
private bool IsIQQuarry(IOEntity conveyor) {
foreach (var q in storedData.LoadedIQuarrys) {
if (q == null) {
continue;
}
if (conveyor.net.ID.Value == q.SwitchNetID || conveyor.net.ID.Value == q.FuelAdapterNetID0 || conveyor.net.ID.Value == q.FuelAdapterNetID1 || conveyor.net.ID.Value == q.ResourceAdapterNetID0 || conveyor.net.ID.Value == q.ResourceAdapterNetID1) {
return true;
}
}
return false;
}
private object OnSwitchToggle(IOEntity conveyor, BasePlayer player) {
//Block players switching off quarry conveyors
if (IsIQQuarry(conveyor) && _config.BlockSwitchingOffConveyors) {
return true;
}
return null;
}
private void OnInputUpdate(IOEntity io, int inputAmount, int inputSlot) {
if (io.skinID != 1234567890) {
return;
}
//Fast exit from function
//Check if quarry switch has been toggled electronically with 1 power or more.if (IsIQQuarry(io))
{
if (inputSlot == 1 && inputAmount >= 1) {
foreach (var q in storedData.LoadedIQuarrys) {
if (q.SwitchNetID == io.net.ID.Value) {
MiningQuarry quarry = (MiningQuarry)BaseNetworkable.serverEntities.Find(new NetworkableId(q.ParentQuarry));
if (quarry != null) {
quarry.EngineSwitch(true);
return;
}
}
}
}
else if (inputSlot == 2 && inputAmount >= 1) {
foreach (var q in storedData.LoadedIQuarrys) {
if (q.SwitchNetID == io.net.ID.Value) {
MiningQuarry quarry = (MiningQuarry)BaseNetworkable.serverEntities.Find(new NetworkableId(q.ParentQuarry));
if (quarry != null) {
quarry.EngineSwitch(false);
return;
}
}
}
}
}
}
private object OnWireClear(BasePlayer player, IOEntity dest, int ssocket, IOEntity source) {
//Null checks
if (source == null || dest == null) {
return null;
}
//Run normal code
//Check if its a switch used for Quarry Toggling.bool isswitch = (dest is ElectricSwitch || source is ElectricSwitch);
//check if industrial part of interest to allow for earlier exit if not.if (dest is IndustrialEntity || source is IndustrialEntity || isswitch)
{
//Check if its a part of interest.if (IsIQQuarry(source) || IsIQQuarry(dest))
{
//Block disconnecting at quarry side
if (IsIQQuarry(dest)) {
if (!isswitch) {
CreateTip("You Can't Disconnect Pipe From Quarry Side.", player);
return true;
}
CreateTip("You Can't Disconnect Wire From Quarry Side.", player);
return true;
}
}
}
//Run normal code
return null;
}
private object OnWireConnect(BasePlayer player, IOEntity dest, int ssocket, IOEntity source, int dsocket) {
//Null checks
if (source == null || dest == null) {
return null;
}
//Run normal code
//Check if its a switch used for Quarry Toggling.bool isswitch = (dest is ElectricSwitch || source is ElectricSwitch);
if (dest is IndustrialEntity || source is IndustrialEntity || isswitch) {
//Check if its a part of intrest.if (IsIQQuarry(source) || IsIQQuarry(dest))
{
//Block hooking into the Wire IO
if (player.GetHeldEntity().ShortPrefabName == "wiretool.entity" && !isswitch) {
CreateTip("You Can't Connect Into Quarry Conveyor IO!", player);
return true;
}
//Block pipe looping
if (IsIQQuarry(source) && IsIQQuarry(dest)) {
CreateTip("You Can't Loop Quarry Pipes!", player);
return true;
}
}
}
return null;
}
//Attach parts after 1 frame to allow it to spawn in
private void OnEntitySpawned(MiningQuarry quarry) {
NextFrame(() => {
AttachIndustrialParts(quarry);
}
);
}
private void OnServerInitialized(bool initial) {
//Wait 30 secs if server reboot to allow things to spawn in.Subscribe("OnEntityKill");
Subscribe("OnEntitySpawned");
Startup(initial ? 30 : 1);
}
private object CanPickupEntity(BasePlayer player, BaseCombatEntity iOEntity) {
//Block pickup of spawned in parts
if (iOEntity.skinID == 1234567890 && iOEntity is IOEntity) {
if (player != null && player.IsConnected) {
CreateTip("You Can't PickUp Quarry Parts!", player);
}
return false;
}
//run normally
return null;
}
private object OnEntityTakeDamage(BaseCombatEntity iOEntity, HitInfo info) {
//Block damage to spawned in parts
if (iOEntity.skinID == 1234567890 && iOEntity is IOEntity) {
BasePlayer player = info?.Initiator?.ToPlayer();
if (player != null && player.IsConnected) {
CreateTip("You Can't Damage Quarry Parts!", player);
}
return true;
}
//run normally
return null;
}
//Admin Kill
private object OnEntityKill(BaseNetworkable bn) {
if (bn == null) return null;
if ((bn as BaseEntity) != null) {
if (bn is IOEntity && (bn as BaseEntity).skinID == 1234567890) {
(bn as IOEntity).Heal(200);
//Set back to max health
return true;
//Block parts being destroyed
}
if (bn is MiningQuarry) {
RemoveQuarry((MiningQuarry)bn);
}
}
return null;
}
//Killed normally
private void OnEntityDeath(BaseCombatEntity baseEntity) {
if (baseEntity is MiningQuarry) {
RemoveQuarry((MiningQuarry)baseEntity);
}
}
//Remove Tool Killed
private void OnNormalRemovedEntity(BasePlayer player, BaseEntity entity) {
if (entity is MiningQuarry) {
RemoveQuarry((MiningQuarry)entity);
}
}
//Remove Tool
private object canRemove(BasePlayer player, BaseEntity entity) {
if (entity.skinID == 1234567890) {
return false;
}
return null;
}
private void Startup(int delay) {
timer.Once(delay, () => {
Vector3 zero = new Vector3(0, 0, 0);
//Find all quarries and attach parts.foreach (BaseNetworkable bn in BaseNetworkable.serverEntities.entityList.Values)
{
if (bn == null) {
continue;
}
if (bn is MiningQuarry) {
AttachIndustrialParts(bn as MiningQuarry);
}
if (bn is IndustrialStorageAdaptor && !bn.IsDestroyed && Vector3.Distance(zero, bn.transform.position) < 10) {
try {
(bn as BaseEntity).skinID = 0;
bn.Kill();
}
catch {
}
}
}
timer.Every(_config.MissingPartsDelay, () => {
CheckParts();
}
);
//Check Quarrys every min to make sure server queue manger not destroyed pipes
}
);
}
void OnNewSave(string filename) {
Puts("Clearing Save Data");
storedData.LoadedIQuarrys.Clear();
}
private void Unload() {
Interface.Oxide.DataFileSystem.WriteObject("industrialquarry", storedData);
}
private void RemoveQuarry(MiningQuarry baseEntity, bool PartsOnly = false) {
if (baseEntity == null || storedData.LoadedIQuarrys.Count == 0) {
return;
}
//Destroy parts and remove from datafile
for (int i = storedData.LoadedIQuarrys.Count - 1; i >= 0; i--) {
IQuarry2 quarry = storedData.LoadedIQuarrys[i];
if (quarry.ParentPosition == baseEntity.transform.position) {
BaseEntity part0 = (BaseEntity)BaseNetworkable.serverEntities.Find(new NetworkableId(quarry.SwitchNetID));
BaseEntity part1 = (BaseEntity)BaseNetworkable.serverEntities.Find(new NetworkableId(quarry.ParentQuarry));
BaseEntity part2 = (BaseEntity)BaseNetworkable.serverEntities.Find(new NetworkableId(quarry.StoneNetID));
BaseEntity part3 = (BaseEntity)BaseNetworkable.serverEntities.Find(new NetworkableId(quarry.FuelAdapterNetID0));
BaseEntity part4 = (BaseEntity)BaseNetworkable.serverEntities.Find(new NetworkableId(quarry.FuelAdapterNetID1));
BaseEntity part5 = (BaseEntity)BaseNetworkable.serverEntities.Find(new NetworkableId(quarry.ResourceAdapterNetID0));
BaseEntity part6 = (BaseEntity)BaseNetworkable.serverEntities.Find(new NetworkableId(quarry.ResourceAdapterNetID1));
storedData.LoadedIQuarrys.Remove(quarry);
if (part0 != null) {
part0.skinID = 0;
part0.Kill();
}
if (part1 != null && !PartsOnly) {
timer.Once(1, () => {
if (part1 != null && !part1.IsDestroyed) {
part1.Kill();
}
}
);
}
if (part2 != null) {
part2.skinID = 0;
part2.Kill();
}
if (part3 != null) {
part3.skinID = 0;
part3.Kill();
}
if (part4 != null) {
part4.skinID = 0;
part4.Kill();
}
if (part5 != null) {
part5.skinID = 0;
part5.Kill();
}
if (part6 != null) {
part6.skinID = 0;
part6.Kill();
}
}
}
}
private MiningQuarry FindQuarry(Ray ray) {
//Ray cast to find quarry
RaycastHit hit;
var raycast = UnityEngine.Physics.Raycast(ray, out hit, 10, -1);
BaseEntity entity = raycast ? hit.GetEntity() : null;
if (entity != null && entity is MiningQuarry) {
return entity as MiningQuarry;
}
if (entity != null && entity?.GetParentEntity() is MiningQuarry) {
return entity.GetParentEntity() as MiningQuarry;
}
return null;
}
private void RUNIO(IOEntity source, IOEntity dest, int dsocket = 0, int ssocket = 0) {
Vector3[] QuarryPipe = new Vector3[2] {
source.transform.InverseTransformPoint(dest.transform.position), new Vector3(0, 0, 0)
}
;
try {
//Clear Connections
try //Try catch since likely to fail if IO hasnt had a markdirty
{
if (source.outputs[ssocket].connectedTo.Get() != null) {
WireTool.AttemptClearSlot(source.outputs[ssocket].connectedTo.Get(), null, ssocket, true);
}
if (dest.inputs[dsocket].connectedTo.Get() != null) {
WireTool.AttemptClearSlot(dest.inputs[dsocket].connectedTo.Get().outputs[dsocket].connectedTo.Get(), null, dsocket, true);
}
}
catch {
}
//Logic to connect the pipe/wire
source.outputs[ssocket].worldSpaceLineEndRotation = source.transform.TransformDirection(source.outputs[ssocket].handleDirection);
source.outputs[ssocket].connectedTo.Set(dest);
source.outputs[ssocket].linePoints = QuarryPipe;
source.outputs[ssocket].connectedToSlot = dsocket;
source.outputs[ssocket].connectedTo.Init();
dest.inputs[dsocket].connectedTo.Set(source);
dest.inputs[dsocket].connectedToSlot = ssocket;
dest.inputs[dsocket].connectedTo.Init();
//Send updates
dest.MarkDirtyForceUpdateOutputs();
source.MarkDirtyForceUpdateOutputs();
source.SendNetworkUpdate(BasePlayer.NetworkQueue.Update);
dest.SendNetworkUpdate(BasePlayer.NetworkQueue.Update);
dest.SendChangedToRoot(true);
source.SendChangedToRoot(true);
source.NotifyIndustrialNetworkChanged();
dest.NotifyIndustrialNetworkChanged();
}
catch {
}
}
//Destroy game objects stuff
private void DestroyMeshCollider(BaseEntity ent) {
foreach (var mesh in ent.GetComponentsInChildren<MeshCollider>()) {
UnityEngine.Object.DestroyImmediate(mesh);
}
}
private void DestroyGroundComp(BaseEntity ent) {
UnityEngine.Object.DestroyImmediate(ent.GetComponent<DestroyOnGroundMissing>());
UnityEngine.Object.DestroyImmediate(ent.GetComponent<GroundWatch>());
}
//Creates a tool tip on players screen
private void CreateTip(string msg, BasePlayer player, int time = 10) {
if (player == null) {
return;
}
player.SendConsoleCommand("gametip.hidegametip");
player.SendConsoleCommand("gametip.showgametip", msg);
timer.Once(time, () => player?.SendConsoleCommand("gametip.hidegametip"));
}
private BaseEntity SpawnPart(string prefab, MiningQuarry quarry, Vector3 pos, Quaternion rot) {
//Spawns in parts of the quarry
BaseEntity baseent = GameManager.server.CreateEntity(prefab, pos, rot);
baseent.OwnerID = quarry.OwnerID;
baseent.Spawn();
baseent.skinID = 1234567890;
baseent.EnableSaving(true);
// _SpawnedList.Add(baseent, quarry);
//Destroy collider and it breaking from not being grounded
DestroyMeshCollider(baseent);
DestroyGroundComp(baseent);
//Power it on
baseent.SetFlag(BaseEntity.Flags.Reserved8, true);
baseent.SetFlag(BaseEntity.Flags.On, true);
if (baseent is BaseCombatEntity) {
(baseent as BaseCombatEntity)?.InitializeHealth(999999999, 999999999);
//Give massive health
}
if (baseent is DecayEntity) {
(baseent as DecayEntity).decay = null;
}
return baseent;
}
public void AttachIndustrialParts(MiningQuarry quarry) {
//Plugins disabled basically with both turned off
if (!_config.AddOutput && !_config.AddFuelInput && !_config.AddIOSwitch) {
return;
}
//Don't run if quarry doesn't exist
if (quarry == null) {
return;
}
//Check if player has perm to use or if its blocked
if ((quarry.OwnerID != 0 && !permission.UserHasPermission(quarry.OwnerID.ToString(), permallow))) {
return;
}
if (quarry.OwnerID == 0 && !_config.AllowOnStaticQuarrys) {
return;
}
//Setup
StorageContainer Outputcontainer = null;
StorageContainer Inputcontainer = null;
bool pumpjack = false;
Vector3 ConvayPoint = Vector3.zero;
Quaternion ConvayerRot = Quaternion.identity;
Quaternion FuelRot = Quaternion.identity;
float BBDistance = 10f;
//Check if quarry underground (likely a custom map one)
bool Underground = (quarry.transform.position.y < TerrainMeta.HeightMap.GetHeight(quarry.transform.position) - 5);
//Adjust position for monument quarries
if (quarry.isStatic && !Underground) {
BBDistance = 35.0f;
}
//Find Quarry Parts
foreach (BaseEntity be in quarry.children) {
//Output has 18 slots
if (be is StorageContainer && (be as StorageContainer).inventorySlots == 18) {
Outputcontainer = be as StorageContainer;
//Check if pumpjack
if (be.ShortPrefabName == "crudeoutput") {
if (quarry.isStatic && TerrainMeta.TopologyMap.GetTopology(quarry.transform.position, TerrainTopology.MONUMENT)) {
return;
}
//Building block too big around pump jacks at monuments
pumpjack = true;
FuelRot = Quaternion.Euler(0, 270, 0);
ConvayerRot = Outputcontainer.transform.rotation * Quaternion.Euler(0, 0, 180);
ConvayPoint = Outputcontainer.transform.position + (Outputcontainer.transform.right * BBDistance) - (Outputcontainer.transform.forward * 1.5f);
}
//Normal Quarry
else {
FuelRot = Quaternion.Euler(0, 180, 0);
ConvayerRot = Outputcontainer.transform.rotation;
ConvayPoint = Outputcontainer.transform.position - (Outputcontainer.transform.right * BBDistance);
}
}
//Fuel tanks have 6
if (be is StorageContainer && (be as StorageContainer).inventorySlots == 6) {
Inputcontainer = be as StorageContainer;
}
}
if (Outputcontainer == null) {
return;
}
//Check ground height
float TerrainHeight = 0;
if (!Underground) {
TerrainHeight = TerrainMeta.HeightMap.GetHeight(ConvayPoint) + 0.7f;
ConvayPoint.y = TerrainHeight;
}
else {
ConvayPoint.y += _config.underGroundQuarryHeightOffset;
ConvayPoint += (Outputcontainer.transform.up * _config.underGroundQuarryHeightOffset);
ConvayPoint += (Outputcontainer.transform.right * _config.underGroundQuarryForwardOffset);
}
List<BaseEntity> list = new List<BaseEntity>();
Vis.Entities<BaseEntity>(ConvayPoint, BBDistance + 5, list);
BaseEntity rock = null;
//Add rock to mount things on
foreach (var scan in list) {
if (scan.transform.position == ConvayPoint) {
rock = scan;
break;
}
}
if (rock == null) {
rock = GameManager.server.CreateEntity(QuarryRock, ConvayPoint, Outputcontainer.transform.rotation * Quaternion.Euler(270, 0, 0));
rock.Spawn();
rock.OwnerID = quarry.OwnerID;
rock.skinID = 1234567890;
rock.EnableSaving(true);
rock.SendNetworkUpdateImmediate();
}
ElectricSwitch quarryswitch = null;
Vector3 qs = rock.transform.position - (rock.transform.up * 0.95f);
if (pumpjack) {
qs += (rock.transform.forward * 1.2f);
}
else {
qs += (rock.transform.forward * -0.85f);
}
IndustrialStorageAdaptor adapterfuel = null;
Vector3 af = Inputcontainer.transform.position + (Inputcontainer.transform.up * 1.1f) - (Inputcontainer.transform.right * 0.55f);
IndustrialConveyor conveyorfuel = null;
Vector3 cf = rock.transform.position + (rock.transform.forward * 0.6f) - (rock.transform.up * 0.85f);
IndustrialStorageAdaptor adapter = null;
Vector3 a = Outputcontainer.transform.position + (Outputcontainer.transform.up * 0.95f);
IndustrialConveyor conveyor = null;
Vector3 c = rock.transform.position + (rock.transform.forward * 1.1f) - (rock.transform.up * 0.85f);
foreach (var scan in list) {
if (scan.transform.position == qs && (ElectricSwitch)scan) {
quarryswitch = scan as ElectricSwitch;
continue;
}
if (scan.transform.position == af && (IndustrialStorageAdaptor)scan) {
adapterfuel = scan as IndustrialStorageAdaptor;
continue;
}
if (scan.transform.position == cf && (IndustrialConveyor)scan) {
conveyorfuel = scan as IndustrialConveyor;
continue;
}
if (scan.transform.position == a && (IndustrialStorageAdaptor)scan) {
adapter = scan as IndustrialStorageAdaptor;
continue;
}
if (scan.transform.position == c && (IndustrialConveyor)scan) {
conveyor = scan as IndustrialConveyor;
}
}
//Spawn IO Switch
if (_config.AddIOSwitch && quarryswitch == null) {
quarryswitch = SpawnPart(SwitchPrefab, quarry, qs, ConvayerRot) as ElectricSwitch;
}
//Add Fuel input stuff
if (_config.AddFuelInput) {
if (adapterfuel == null) {
adapterfuel = SpawnPart(StorageAdapter, quarry, af, Inputcontainer.transform.rotation * FuelRot) as IndustrialStorageAdaptor;
}
if (conveyorfuel == null) {
conveyorfuel = SpawnPart(Conveyor, quarry, cf, ConvayerRot * Quaternion.Euler(0, 0, 180)) as IndustrialConveyor;
}
if (_config.MaxStackSizePerMoveAdustment != -1) {
conveyorfuel.MaxStackSizePerMove = _config.MaxStackSizePerMoveAdustment;
}
RUNIO(conveyorfuel, adapterfuel);
adapterfuel.SetParent(Inputcontainer, true, true);
}
if (_config.AddOutput) {
//Add Quarry output stuff
if (adapter == null) {
adapter = SpawnPart(StorageAdapter, quarry, a, Outputcontainer.transform.rotation) as IndustrialStorageAdaptor;
}
if (conveyor == null) {
conveyor = SpawnPart(Conveyor, quarry, c, ConvayerRot) as IndustrialConveyor;
}
if (_config.MaxStackSizePerMoveAdustment != -1) {
conveyor.MaxStackSizePerMove = _config.MaxStackSizePerMoveAdustment;
}
RUNIO(adapter, conveyor);
adapter.SetParent(Outputcontainer, true, true);
}
//Check not already in data file
if (storedData.LoadedIQuarrys.Count > 0) {
foreach (var q in storedData.LoadedIQuarrys) {
if (q.ParentPosition == quarry.transform.position) {
//Update Datafile
q.ParentPosition = quarry.transform.position;
q.ParentQuarry = quarry.net.ID.Value;
q.OwnerID = quarry.OwnerID;
q.StoneNetID = rock.net.ID.Value;
q.FuelAdapterNetID0 = adapterfuel.net.ID.Value;
q.FuelAdapterNetID1 = conveyorfuel.net.ID.Value;
q.ResourceAdapterNetID0 = adapter.net.ID.Value;
q.ResourceAdapterNetID1 = conveyor.net.ID.Value;
q.SwitchNetID = quarryswitch.net.ID.Value;
q.Pipes0 = adapterfuel.inputs[0].connectedTo.Get().outputs[0].linePoints;
q.Pipes1 = adapter.outputs[0].linePoints;
return;
}
}
}
//Create new datafile
IQuarry2 quarry1 = new IQuarry2();
quarry1.ParentPosition = quarry.transform.position;
quarry1.ParentQuarry = quarry.net.ID.Value;
quarry1.OwnerID = quarry.OwnerID;
quarry1.StoneNetID = rock.net.ID.Value;
quarry1.FuelAdapterNetID0 = adapterfuel.net.ID.Value;
quarry1.FuelAdapterNetID1 = conveyorfuel.net.ID.Value;
quarry1.ResourceAdapterNetID0 = adapter.net.ID.Value;
quarry1.ResourceAdapterNetID1 = conveyor.net.ID.Value;
quarry1.SwitchNetID = quarryswitch.net.ID.Value;
quarry1.Pipes0 = adapterfuel.inputs[0].connectedTo.Get().outputs[0].linePoints;
quarry1.Pipes1 = adapter.outputs[0].linePoints;
storedData.LoadedIQuarrys.Add(quarry1);
Interface.Oxide.DataFileSystem.WriteObject("industrialquarry", storedData);
}
void CheckParts() {
if (storedData.LoadedIQuarrys.Count == 0) {
return;
}
for (int i = storedData.LoadedIQuarrys.Count - 1; i >= 0; i--) {
IQuarry2 quarry = storedData.LoadedIQuarrys[i];
if (quarry == null) {
continue;
}
BaseEntity part0 = (BaseEntity)BaseNetworkable.serverEntities.Find(new NetworkableId(quarry.SwitchNetID));
BaseEntity mainquarry = (BaseEntity)BaseNetworkable.serverEntities.Find(new NetworkableId(quarry.ParentQuarry));
BaseEntity part2 = (BaseEntity)BaseNetworkable.serverEntities.Find(new NetworkableId(quarry.StoneNetID));
BaseEntity part3 = (BaseEntity)BaseNetworkable.serverEntities.Find(new NetworkableId(quarry.FuelAdapterNetID0));
BaseEntity part4 = (BaseEntity)BaseNetworkable.serverEntities.Find(new NetworkableId(quarry.FuelAdapterNetID1));
BaseEntity part5 = (BaseEntity)BaseNetworkable.serverEntities.Find(new NetworkableId(quarry.ResourceAdapterNetID0));
BaseEntity part6 = (BaseEntity)BaseNetworkable.serverEntities.Find(new NetworkableId(quarry.ResourceAdapterNetID1));
if (mainquarry == null) {
if (_config.DebugMessages) Puts("Missing Quarry, Removing Parts");
storedData.LoadedIQuarrys.Remove(quarry);
if (part0 != null) {
part0.skinID = 0;
part0.Kill();
}
if (part2 != null) {
part2.skinID = 0;
part2.Kill();
}
if (part3 != null) {
part3.skinID = 0;
part3.Kill();
}
if (part4 != null) {
part4.skinID = 0;
part4.Kill();
}
if (part5 != null) {
part5.skinID = 0;
part5.Kill();
}
if (part6 != null) {
part6.skinID = 0;
part6.Kill();
}
continue;
}
if (quarry.OwnerID != 0) {
if (!permission.UserHasPermission(quarry.OwnerID.ToString(), permallow)) {
if (_config.DebugMessages) Puts("Owner Lost Permission");
RemoveQuarry(mainquarry as MiningQuarry, true);
continue;
}
}
if (part0 == null) {
if (_config.DebugMessages) Puts("Missing SwitchNetID");
storedData.LoadedIQuarrys.Remove(quarry);
AttachIndustrialParts(mainquarry as MiningQuarry);
continue;
}
if (part2 == null) {
if (_config.DebugMessages) Puts("Missing StoneNetID");
storedData.LoadedIQuarrys.Remove(quarry);
AttachIndustrialParts(mainquarry as MiningQuarry);
continue;
}
if (part3 == null) {
if (_config.DebugMessages) Puts("Missing FuelAdapterNetID0");
storedData.LoadedIQuarrys.Remove(quarry);
AttachIndustrialParts(mainquarry as MiningQuarry);
continue;
}
if (part4 == null) {
if (_config.DebugMessages) Puts("Missing FuelAdapterNetID1");
storedData.LoadedIQuarrys.Remove(quarry);
AttachIndustrialParts(mainquarry as MiningQuarry);
continue;
}
if (part5 == null) {
if (_config.DebugMessages) Puts("Missing ResourceAdapterNetID0");
storedData.LoadedIQuarrys.Remove(quarry);
AttachIndustrialParts(mainquarry as MiningQuarry);
continue;
}
if (part6 == null) {
if (_config.DebugMessages) Puts("Missing ResourceAdapterNetID1");
storedData.LoadedIQuarrys.Remove(quarry);
AttachIndustrialParts(mainquarry as MiningQuarry);
continue;
}
}
}
}
}