Skip to content
This repository has been archived by the owner on Aug 9, 2023. It is now read-only.

Commit

Permalink
Merge pull request #23 from SynapseSL/development
Browse files Browse the repository at this point in the history
Development
  • Loading branch information
GrafDimenzio authored Jan 7, 2021
2 parents 35b32fd + 601510e commit df301d6
Show file tree
Hide file tree
Showing 16 changed files with 190 additions and 119 deletions.
79 changes: 57 additions & 22 deletions Synapse/Api/Door.cs
Original file line number Diff line number Diff line change
@@ -1,55 +1,90 @@
using UnityEngine;
using System.Linq;
using Interactables.Interobjects.DoorUtils;
using vDoor = Interactables.Interobjects.DoorUtils.DoorVariant;
using Interactables.Interobjects;

namespace Synapse.Api
{
public class Door
{
internal Door(vDoor vanilladoor) => door = vanilladoor;
internal Door(vDoor vanilladoor)
{
VDoor = vanilladoor;
if (VDoor.TryGetComponent<DoorNametagExtension>(out var nametag))
Name = nametag.GetName;
}

internal vDoor door;
public vDoor VDoor { get; internal set; }

public GameObject GameObject => door.gameObject;
public GameObject GameObject => VDoor.gameObject;

public string Name => string.IsNullOrWhiteSpace(door.name) ? GameObject.name : door.name;
private string name;
public string Name
{
get
{
if (string.IsNullOrEmpty(name)) return GameObject.name;
return name;
}
set => name = value;
}

public Vector3 Position => GameObject.transform.position;

public DoorPermissions DoorPermissions { get => door.RequiredPermissions; set => door.RequiredPermissions = value; }
public DoorPermissions DoorPermissions { get => VDoor.RequiredPermissions; set => VDoor.RequiredPermissions = value; }

private Enum.DoorType doorType;
public Enum.DoorType DoorType
{
get
{
if (door != null)
return doorType;

foreach(var type in (Enum.DoorType[])System.Enum.GetValues(typeof(Enum.DoorType)))
foreach (var type in (Enum.DoorType[])System.Enum.GetValues(typeof(Enum.DoorType)))
{
if (type.ToString().ToUpper().Contains(Name.ToUpper()))
{
doorType = type;
return doorType;
}
}

//if (Name.Contains("Airlocks")) doorType = Enum.DoorType.Airlock;
if (Name.Contains("EZ BreakableDoor")) doorType = Enum.DoorType.EZ_Door;
else if (Name.Contains("LCZ BreakableDoor")) doorType = Enum.DoorType.LCZ_Door;
else if (Name.Contains("HCZ BreakableDoor")) doorType = Enum.DoorType.HCZ_Door;
else if (Name.Contains("Prison BreakableDoor")) doorType = Enum.DoorType.PrisonDoor;
else if (Name.Contains("LCZ PortallessBreakableDoor")) doorType = Enum.DoorType.Airlock;
else if (Name.Contains("Unsecured Pryable GateDoor")) doorType = Enum.DoorType.HCZ_049_Gate;
else doorType = Enum.DoorType.Other;

if (Name.Contains("Airlocks")) doorType = Enum.DoorType.Airlock;

else if (Name.Contains("EntrDoor")) doorType = Enum.DoorType.EZ_Door;

else if (Name.Contains("LightContainmentDoor")) doorType = Enum.DoorType.LCZ_Door;

else if (Name.Contains("HeavyContainmentDoor")) doorType = Enum.DoorType.HCZ_Door;

else if (Name.Contains("PrisonDoor")) doorType = Enum.DoorType.PrisonDoor;
return doorType;
}
}

//else if (Name.Contains("ContDoor")) doorType = Enum.DoorType.ContDoor;
public bool IsBreakable => VDoor is BreakableDoor;

else doorType = Enum.DoorType.Other;
public bool IsOpen { get => VDoor.IsConsideredOpen(); }

return doorType;
public bool TryBreakDoor()
{
if (VDoor is BreakableDoor damageableDoor)
{
damageableDoor.IsDestroyed = true;
return true;
}
else
{
return false;
}
}

public bool TryPry()
{
if (VDoor is PryableDoor pry)
return pry.TryPryGate();
else
return false;
}

public override string ToString() => Name;
}
}
17 changes: 10 additions & 7 deletions Synapse/Api/Enum/DoorType.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,24 +6,26 @@ public enum DoorType
LCZ_012_Bottom,
LCZ_012_Locker,
HCZ_049_Armory,
HCZ_049_Gate,
HCZ_079_First,
HCZ_079_Second,
HCZ_096,
HCZ_106_Bottom,
HCZ_106_Primary,
HCZ_106_Secondary,
LCZ_173,
LCZ_173_Armory,
LCZ_173_Connector,
LCZ_173_Gate,
LCZ_173_Bottom,
LCZ_372,
LCZ_914,
Checkpoint_Ent,
Checkpoint_EZ_HCZ,
Checkpoint_LCZ_A,
Checkpoint_LCZ_B,
Escape,
Escape_Inner,
Escape_Primary,
Escape_Secondary,
Gate_A,
Gate_B,
GR18,
HCZ_Armory,
HID,
HID_Left,
Expand All @@ -33,13 +35,14 @@ public enum DoorType
LCZ_Cafe,
LCZ_Wc,
Nuke_Armory,
Nuke_Surface,
Servers_Bottom,
Surface_Gate,
Surface_Nuke,
LCZ_Door,
HCZ_Door,
EZ_Door,
Airlock,
PrisonDoor,
Airlock,
Other
}
}
21 changes: 21 additions & 0 deletions Synapse/Api/Events/EventHandler.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
using Synapse.Config;
using UnityEngine;
using System.IO;
using System.Collections.Generic;

namespace Synapse.Api.Events
{
Expand All @@ -23,6 +25,25 @@ private void KeyPress(SynapseEventArguments.PlayerKeyPressEventArgs ev)
if (player != ev.Player)
ev.Player.Scp173Controller.IgnoredPlayers.Add(player);
break;

case KeyCode.Alpha2:
var msg = "";
foreach (var door in Api.Map.Get.Doors)
msg += $"Type: {door.DoorType} Name: {door}\n";

var path = Path.Combine(SynapseController.Server.Files.SynapseDirectory, "doors.txt");
if (!File.Exists(path))
File.Create(path).Close();
File.WriteAllText(path, msg);
break;

case KeyCode.Alpha3:
ev.Player.Position = Api.Map.Get.GetDoor(Enum.DoorType.Other).Position;
break;

case KeyCode.Alpha4:
ev.Player.Position = Api.Map.Get.GetDoor(Enum.DoorType.Airlock).Position;
break;
}
}

Expand Down
11 changes: 6 additions & 5 deletions Synapse/Api/Items/SynapseItem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -161,13 +161,14 @@ private void Refresh()
var qua = pickup.rotation;
var pos = Position;
var owner = pickup.ownerPlayer;
pickup.Delete();
pickup = null;

pickup = UnityEngine.Object.Instantiate(Server.Get.Host.VanillaInventory.pickupPrefab).GetComponent<Pickup>();
pickup.transform.localScale = Scale;
NetworkServer.Spawn(pickup.gameObject);
pickup.SetupPickup(ItemType, Durabillity, owner, new Pickup.WeaponModifiers(true, Sight, Barrel, Other), pos, qua);
if(pickup.transform.localScale != Scale)
{
NetworkServer.UnSpawn(pickup.gameObject);
pickup.transform.localScale = Scale;
NetworkServer.Spawn(pickup.gameObject);
}
return;
}

Expand Down
12 changes: 9 additions & 3 deletions Synapse/Api/Logger.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,19 +9,25 @@ public class Logger

internal Logger() { }

public void Info(string message)
public void Info(string message) => Info((object)message);

public void Info(object message)
{
var name = Assembly.GetCallingAssembly().GetName().Name;
Send($"{name}: {message}", ConsoleColor.Cyan);
}

public void Warn(string message)
public void Warn(string message) => Warn((object)message);

public void Warn(object message)
{
var name = Assembly.GetCallingAssembly().GetName().Name;
Send($"{name}: {message}", ConsoleColor.Green);
}

public void Error(string message)
public void Error(string message) => Error((object)message);

public void Error(object message)
{
var name = Assembly.GetCallingAssembly().GetName().Name;
Send($"{name}: {message}", ConsoleColor.Red);
Expand Down
5 changes: 4 additions & 1 deletion Synapse/Api/Map.cs
Original file line number Diff line number Diff line change
Expand Up @@ -136,13 +136,16 @@ public void Explode(Vector3 position, Enum.GrenadeType grenadeType = Enum.Grenad
internal void AddObjects()
{
foreach (var tesla in SynapseController.Server.GetObjectsOf<TeslaGate>())
SynapseController.Server.Map.Teslas.Add(new Tesla(tesla));
Teslas.Add(new Tesla(tesla));

foreach (var room in SynapseController.Server.GetObjectsOf<Transform>().Where(x => x.CompareTag("Room") || x.name == "Root_*&*Outside Cams" || x.name == "PocketWorld"))
Rooms.Add(new Room(room.gameObject));

foreach (var station in Server.Get.GetObjectsOf<global::WorkStation>())
WorkStations.Add(new WorkStation(station));

foreach (var door in SynapseController.Server.GetObjectsOf<Interactables.Interobjects.DoorUtils.DoorVariant>())
Doors.Add(new Door(door));
}

internal void ClearObjects()
Expand Down
2 changes: 1 addition & 1 deletion Synapse/Api/Player.cs
Original file line number Diff line number Diff line change
Expand Up @@ -729,7 +729,7 @@ public CommandSender CommandSender

public Fraction RealFraction => Misc.GetFraction(RealTeam);

public Items.SynapseItem ItemInHand => VanillaInventory.GetItemInHand().GetSynapseItem();
public Items.SynapseItem ItemInHand => Map.Get.Items.FirstOrDefault(x => x.State == ItemState.Inventory && x.itemInfo.uniq == VanillaInventory.itemUniq);

public NetworkConnection Connection => ClassManager.Connection;

Expand Down
6 changes: 3 additions & 3 deletions Synapse/Api/Scp096Controller.cs
Original file line number Diff line number Diff line change
Expand Up @@ -79,8 +79,8 @@ public PlayableScps.Scp096PlayerState RageState
break;

case PlayableScps.Scp096PlayerState.Enraged when RageState != PlayableScps.Scp096PlayerState.Attacking:
if (RageState == PlayableScps.Scp096PlayerState.Docile
|| RageState == PlayableScps.Scp096PlayerState.TryNotToCry
if (RageState == PlayableScps.Scp096PlayerState.Docile
|| RageState == PlayableScps.Scp096PlayerState.TryNotToCry
|| RageState == PlayableScps.Scp096PlayerState.Calming)
RageState = PlayableScps.Scp096PlayerState.Enraging;
Scp096.Enrage();
Expand Down Expand Up @@ -161,7 +161,7 @@ public void RemoveTarget(Player player)
public void ChargeDoor(Door door)
{
if (!Is096) return;
Scp096.ChargeDoor(door.door);
Scp096.ChargeDoor(door.VDoor);
}
}
}
70 changes: 36 additions & 34 deletions Synapse/Patches/EventsPatches/MapPatches/DoorInteractPatch.cs
Original file line number Diff line number Diff line change
@@ -1,23 +1,21 @@
using System;
using HarmonyLib;
using System.Collections.Generic;
using Logger = Synapse.Api.Logger;
using EventHandler = Synapse.Api.Events.EventHandler;
using UnityEngine;
using Synapse.Api;
using System.Linq;
using Mirror;
using Interactables.Interobjects.DoorUtils;
using System.Linq;

namespace Synapse.Patches.EventsPatches.MapPatches
{
[HarmonyPatch(typeof(DoorVariant), nameof(DoorVariant.ServerInteract))]
internal static class DoorInteractPatch
{
private static bool Prefix(DoorVariant __instance, ReferenceHub ply, byte colliderId)
{
try
{
[HarmonyPatch(typeof(DoorVariant), nameof(DoorVariant.ServerInteract))]
internal static class DoorInteractPatch
{
private static bool Prefix(DoorVariant __instance, ReferenceHub ply, byte colliderId)
{
try
{
if (!NetworkServer.active)
{
Debug.LogWarning("[Server] function 'System.Void Interactables.Interobjects.DoorUtils.DoorVariant::ServerInteract(ReferenceHub,System.Byte)' called on client");
Expand All @@ -35,27 +33,31 @@ private static bool Prefix(DoorVariant __instance, ReferenceHub ply, byte collid
if (__instance.AllowInteracting(ply, colliderId))
{
var player = ply.GetPlayer();
var keycardacces = false;
var items = new List<Api.Items.SynapseItem>();
if (Server.Get.Configs.SynapseConfiguration.RemoteKeyCard)
items.AddRange(player.Inventory.Items);
else
items.Add(player.ItemInHand);
var flag = __instance.RequiredPermissions.CheckPermissions(player.VanillaInventory.curItem,ply);
var cardaccess = false;
var item = player.ItemInHand;

if (item != null && item.ItemCategory == ItemCategory.Keycard)
EventHandler.Get.Player.InvokePlayerItemUseEvent(player, item, Api.Events.SynapseEventArguments.ItemInteractState.Finalizing, ref flag);

foreach(var item in items)
{
var allow = __instance.RequiredPermissions.CheckPermissions(item.ItemType, player.Hub);
if (flag) cardaccess = true;
else if (Server.Get.Configs.SynapseConfiguration.RemoteKeyCard)
foreach (var item2 in player.Inventory.Items.Where(x => x != item && x.ItemCategory == ItemCategory.Keycard))
{
var allowcard = __instance.RequiredPermissions.CheckPermissions(item2.ItemType, ply);

Server.Get.Events.Player.InvokePlayerItemUseEvent(player, item, Api.Events.SynapseEventArguments.ItemInteractState.Finalizing, ref allow);
EventHandler.Get.Player.InvokePlayerItemUseEvent(player, item2, Api.Events.SynapseEventArguments.ItemInteractState.Finalizing, ref allowcard);

if (allow)
{
keycardacces = true;
break;
if (allowcard)
{
cardaccess = true;
break;
}
}
}

if (ply.characterClassManager.CurClass == RoleType.Scp079 || keycardacces)
EventHandler.Get.Map.InvokeDoorInteractEvent(player, __instance.GetDoor(), ref cardaccess);

if (ply.characterClassManager.CurClass == RoleType.Scp079 || cardaccess)
{
__instance.NetworkTargetState = !__instance.TargetState;
__instance._triggerPlayer = ply;
Expand All @@ -66,12 +68,12 @@ private static bool Prefix(DoorVariant __instance, ReferenceHub ply, byte collid
}

return false;
}
catch (Exception e)
{
Logger.Get.Error($"Synapse-Event: DoorInteract failed!!\n{e}");
return true;
}
}
}
}
catch (Exception e)
{
Logger.Get.Error($"Synapse-Event: DoorInteract failed!!\n{e}");
return true;
}
}
}
}
Loading

0 comments on commit df301d6

Please sign in to comment.