C#:
using System.Collections.Generic;
using System.Linq;
using UnityEngine;
using Facepunch;
using Oxide.Core;
namespace Oxide.Plugins
{
[Info("PuzzleChainRepair", "bazuka5801", "1.0.0")]
public class PuzzleChainRepair : RustPlugin
{
private object OnEntityTakeDamage(BaseCombatEntity entity, HitInfo info)
{
if (entity is ORSwitch)
{
info.damageTypes.ScaleAll(0);
return false;
}
return null;
}
[ConsoleCommand("puzzlerepair")]
void cmdPuzzleFix(ConsoleSystem.Arg arg)
{
if (arg.Connection != null)
{
return;
}
Dictionary<string, int> repairedEntities = new Dictionary<string, int>();
foreach (BaseNetworkable serverIOEntity in (
from x in BaseNetworkable.serverEntities
where x is IOEntity
select x).ToList())
{
serverIOEntity.Kill();
string shortname = serverIOEntity.ShortPrefabName;
if (repairedEntities.ContainsKey(shortname) == false)
{
repairedEntities[shortname] = -1;
}
else
{
repairedEntities[shortname]--;
}
}
foreach (MonumentInfo monument in TerrainMeta.Path.Monuments)
{
GameObject gameObject = GameManager.server.FindPrefab(monument.gameObject.name);
if (gameObject != null)
{
Dictionary<IOEntity, IOEntity> dPrefab_ServerComponents = new Dictionary<IOEntity, IOEntity>();
IOEntity[] prefabIOComponentList = gameObject.GetComponentsInChildren<IOEntity>(true);
for (int i = 0; i < (int)prefabIOComponentList.Length; i++)
{
IOEntity prefabIOComponent = prefabIOComponentList[i];
Quaternion quaternion = monument.transform.rotation * prefabIOComponent.transform.rotation;
Vector3 pos = monument.transform.TransformPoint(prefabIOComponent.transform.position);
BaseEntity serverEntity = GameManager.server.CreateEntity(prefabIOComponent.PrefabName, pos, quaternion);
IOEntity serverIOEntity = serverEntity as IOEntity;
if (serverIOEntity != null)
{
dPrefab_ServerComponents.Add(prefabIOComponent, serverIOEntity);
DoorManipulator serverDoorManipulator = serverEntity as DoorManipulator;
if (serverDoorManipulator != null)
{
List<Door> doors = Pool.GetList<Door>();
Vis.Entities(serverEntity.transform.position, 10f, doors);
Door door = (
from x in doors
orderby x.Distance(serverEntity.transform.position)
select x).FirstOrDefault();
if (door != null)
{
serverDoorManipulator.targetDoor = door;
}
Pool.FreeList(ref doors);
}
CardReader serverCardReader = serverEntity as CardReader;
if (serverCardReader != null)
{
CardReader prefabCardReader = prefabIOComponent as CardReader;
if (prefabCardReader != null)
{
serverCardReader.accessLevel = prefabCardReader.accessLevel;
serverCardReader.accessDuration = prefabCardReader.accessDuration;
}
}
TimerSwitch serverTimerSwitch = serverEntity as TimerSwitch;
if (serverTimerSwitch != null)
{
TimerSwitch prefabTimerSwitch = prefabIOComponent as TimerSwitch;
if (prefabTimerSwitch != null)
{
serverTimerSwitch.timerLength = prefabTimerSwitch.timerLength;
}
}
}
}
foreach (var pPrefab_Server in dPrefab_ServerComponents)
{
IOEntity prefabIOComponent = pPrefab_Server.Key;
IOEntity serverIOComponent = pPrefab_Server.Value;
for (int j = 0; j < prefabIOComponent.outputs.Length; j++)
{
if (prefabIOComponent.outputs[j].connectedTo.ioEnt != null)
{
serverIOComponent.outputs[j].connectedTo.ioEnt = dPrefab_ServerComponents[prefabIOComponent.outputs[j].connectedTo.ioEnt];
serverIOComponent.outputs[j].connectedToSlot = prefabIOComponent.outputs[j].connectedToSlot;
}
}
}
foreach (IOEntity serverIOEntity in dPrefab_ServerComponents.Values)
{
serverIOEntity.Spawn();
string shortname = serverIOEntity.ShortPrefabName;
if (repairedEntities.ContainsKey(shortname) == false)
{
repairedEntities[shortname] = 1;
}
else
{
repairedEntities[shortname]++;
}
}
}
}
Interface.Oxide.LogWarning("===================================");
Interface.Oxide.LogWarning("= PuzzleChainRepair by bazuka5801 =");
var repairedItems = repairedEntities.Where(ent => ent.Value > 0).ToList();
if (repairedItems.Count == 0)
{
Interface.Oxide.LogWarning("===================================");
Interface.Oxide.LogWarning(" No broken electrical chains found ");
}
else
{
Interface.Oxide.LogWarning("===== Repaired entities list =====");
foreach (var repairedItem in repairedItems)
{
int count = repairedItem.Value;
string shortname = repairedItem.Key;
Interface.Oxide.LogWarning($"[{count}] {shortname}");
}
Interface.Oxide.LogWarning("====== End of repaired list =======");
}
Interface.Oxide.LogWarning("===================================");
Interface.Oxide.LogWarning("===== Thanks <Hougan> for help ====");
Interface.Oxide.LogWarning("===================================");
}
}
}