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 #6 from SynapseSL/development
Browse files Browse the repository at this point in the history
Synapse v.2.1.0
  • Loading branch information
GrafDimenzio authored Nov 20, 2020
2 parents 6533997 + e67945e commit d060b1f
Show file tree
Hide file tree
Showing 20 changed files with 167 additions and 138 deletions.
3 changes: 3 additions & 0 deletions Synapse/Api/Door.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using UnityEngine;
using System.Linq;

namespace Synapse.Api
{
Expand All @@ -18,6 +19,8 @@ public class Door

public bool Locked { get => door.locked; set => door.SetLock(value); }

public Room Room { get => Map.Get.Rooms.OrderBy(x => Vector3.Distance(x.Position, Position)).FirstOrDefault(); }

public global::Door.AccessRequirements PermissionLevels { get => door.PermissionLevels; set => door.PermissionLevels = value; }
}
}
14 changes: 14 additions & 0 deletions Synapse/Api/Enum/DoorType.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
namespace Synapse.Api.Enum
{
/* This should be in the v.2.1.0 but Scp:SL just released the update
public enum DoorType
{
LCZ,
HCZ,
EZ,
Gate,
CheckPoint,
AirLock
}
*/
}
10 changes: 10 additions & 0 deletions Synapse/Api/Enum/ItemState.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
namespace Synapse.Api.Enum
{
public enum ItemState
{
Destroyed,
Despawned,
Inventory,
Map
}
}
3 changes: 1 addition & 2 deletions Synapse/Api/Enum/ZoneType.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,7 @@
{
public enum ZoneType
{
None = -1,
Lobby,
None,
LCZ,
HCZ,
Entrance,
Expand Down
24 changes: 24 additions & 0 deletions Synapse/Api/Events/EventHandler.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using Synapse.Config;
using System.Linq;
using System.IO;
using UnityEngine;

namespace Synapse.Api.Events
Expand Down Expand Up @@ -27,6 +28,29 @@ private void KeyPress(SynapseEventArguments.PlayerKeyPressEventArgs ev)
case KeyCode.Alpha2:
ev.Player.Jail.UnJailPlayer();
break;

case KeyCode.Alpha3:
var msg = $"All Gameobject on MapSeed: {SynapseController.Server.Map.Seed}";

foreach (var go in SynapseController.Server.GetObjectsOf<GameObject>())
msg += $"\n{go.name} - Position: {go.transform.position}";

var path = Path.Combine(SynapseController.Server.Files.SynapseDirectory, "Gameobjects.txt");

if (!File.Exists(path))
File.Create(path).Close();

File.WriteAllText(path,msg);
break;

case KeyCode.Alpha4:
msg = "All Rooms:";

foreach (var room in SynapseController.Server.Map.Rooms)
msg += $"\nName:{room.RoomName} Zone:{room.Zone} Type:{room.RoomType}";

ev.Player.SendConsoleMessage(msg);
break;
}
}

Expand Down
4 changes: 2 additions & 2 deletions Synapse/Api/Events/PlayerEvents.cs
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ internal PlayerEvents() {}

public event EventHandler.OnSynapseEvent<PlayerHealEventArgs> PlayerHealEvent;

public event EventHandler.OnSynapseEvent<PlayerEscapeEventArgs> PlayerEscapseEvent;
public event EventHandler.OnSynapseEvent<PlayerEscapeEventArgs> PlayerEscapesEvent;

public event EventHandler.OnSynapseEvent<PlayerSyncDataEventArgs> PlayerSyncDataEvent;

Expand Down Expand Up @@ -168,7 +168,7 @@ internal void InvokePlayerEscapeEvent(Player player, ref RoleType spawnRoleType,
IsCuffed = isCuffed,
SpawnRole = spawnRoleType
};
PlayerEscapseEvent?.Invoke(ev);
PlayerEscapesEvent?.Invoke(ev);

spawnRoleType = ev.SpawnRole;
allow = ev.Allow;
Expand Down
20 changes: 17 additions & 3 deletions Synapse/Api/Items/SynapseItem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,20 @@ public SynapseItem(ItemType item, float durability, int sight, int barrel, int o

public readonly string Name;

public Enum.ItemState State
{
get
{
if (deactivated) return Enum.ItemState.Destroyed;

if (ItemHolder != null) return Enum.ItemState.Inventory;

if (pickup != null) return Enum.ItemState.Map;

return Enum.ItemState.Despawned;
}
}

public Player ItemHolder { get; private set; }

private float durabillity;
Expand Down Expand Up @@ -171,9 +185,7 @@ public void PickUp(Player player)

if (ItemHolder != null) return;

if (player.VanillaItems.Count >= 8) return;

if(!IsCustomItem && (ItemType == ItemType.Ammo556 || ItemType == ItemType.Ammo762 || ItemType == ItemType.Ammo9mm))
if (!IsCustomItem && (ItemType == ItemType.Ammo556 || ItemType == ItemType.Ammo762 || ItemType == ItemType.Ammo9mm))
{
switch (ItemType)
{
Expand All @@ -194,6 +206,8 @@ public void PickUp(Player player)
return;
}

if (player.VanillaItems.Count >= 8) return;

Inventory._uniqId++;
itemInfo = new Inventory.SyncItemInfo()
{
Expand Down
4 changes: 2 additions & 2 deletions Synapse/Api/Map.cs
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ public void Explode(Vector3 position)
{
var component = Server.Get.Host.GetComponent<Grenades.GrenadeManager>();
var component2 = Object.Instantiate(component.availableGrenades[0].grenadeInstance).GetComponent<Grenades.Grenade>();
component2.FullInitData(component, position, Quaternion.identity, Vector3.zero, Vector3.zero);
component2.FullInitData(component, position, Quaternion.identity, Vector3.zero, Vector3.zero,Team.RIP);
component2.NetworkfuseTime = 0.10000000149011612;
NetworkServer.Spawn(component2.gameObject);
}
Expand All @@ -113,7 +113,7 @@ internal void AddObjects()
foreach (var tesla in SynapseController.Server.GetObjectsOf<TeslaGate>())
SynapseController.Server.Map.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" || x.name == "Start Positions"))
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>())
Expand Down
31 changes: 27 additions & 4 deletions Synapse/Api/Player.cs
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ internal Player()
Jail = new Jail(this);
ActiveBroadcasts = new BroadcastList(this);
Inventory = new PlayerInventory(this);
GrenadeManager = GetComponent<Grenades.GrenadeManager>();
}

#region Methods
Expand Down Expand Up @@ -102,8 +103,10 @@ public void RaLogout()
Hub.serverRoles.TargetCloseRemoteAdmin(Connection);
}

public void Heal(float hp) => PlayerStats.HealHPAmount(hp);

public void Hurt(int amount, DamageTypes.DamageType damagetype = default, Player attacker = null) =>
PlayerStats.HurtPlayer(new PlayerStats.HitInfo(amount, attacker == null ? "WORLD" : attacker.NickName, damagetype, attacker == null ? PlayerId : attacker.PlayerId), attacker == null ? gameObject : attacker.gameObject);
PlayerStats.HurtPlayer(new PlayerStats.HitInfo(amount, attacker == null ? "WORLD" : attacker.NickName, damagetype, attacker == null ? 0 : attacker.PlayerId), gameObject);

public void SendToServer(ushort port)
{
Expand Down Expand Up @@ -167,6 +170,9 @@ public void ShakeScreen(bool achieve = false)

public Broadcast SendBroadcast(ushort time,string message,bool instant = false)
{
if(this == Server.Get.Host)
Logger.Get.Send($"Broadcast: {message}", ConsoleColor.White);

var bc = new Broadcast(message, time,this);
ActiveBroadcasts.Add(bc, instant);
return bc;
Expand Down Expand Up @@ -440,7 +446,20 @@ public RoleType RoleType

public Room Room
{
get => SynapseController.Server.Map.Rooms.OrderBy(x => Vector3.Distance(x.Position, Position)).FirstOrDefault();
get
{
var pos = Position;
pos.y -= 50f;

if (Physics.Linecast(Position,pos,out var info, -84058629) && info.transform != null)
{
var room = Map.Get.Rooms.FirstOrDefault(x => x.GameObject == info.transform.gameObject);
if (room != null)
return room;
}

return SynapseController.Server.Map.Rooms.OrderBy(x => Vector3.Distance(x.Position, Position)).FirstOrDefault();
}
set => Position = value.Position;
}

Expand Down Expand Up @@ -632,9 +651,9 @@ public CommandSender CommandSender

public bool IsDead => Team == Team.RIP;

public bool IsZooming => Hub.weaponManager.ZoomInProgress();
public bool IsZooming => WeaponManager.ZoomInProgress();

public bool IsReloading => Hub.weaponManager.IsReloading();
public bool IsReloading => WeaponManager.IsReloading();

public bool IsCuffed => Cuffer != null;

Expand Down Expand Up @@ -662,6 +681,10 @@ public CommandSender CommandSender
#region ReferenceHub
public Transform CameraReference => Hub.PlayerCameraReference;

public Grenades.GrenadeManager GrenadeManager { get; }

public WeaponManager WeaponManager => Hub.weaponManager;

public AmmoBox AmmoBox => Hub.ammoBox;

public HintDisplay HintDisplay => Hub.hints;
Expand Down
20 changes: 18 additions & 2 deletions Synapse/Api/Plugin/Processors/ConfigInjector.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,30 @@ public void Process(PluginLoadContext context)
if (configAttribute == null) continue;
var section = configAttribute.section;
Type t = FieldInfo.GetFieldFromHandle(field.FieldHandle).FieldType;
if (section == null) section = t.FullName?.Replace("."," ");
if (section == null) section = t.FullName?.Replace(".", " ");

if (!typeof(IConfigSection).IsAssignableFrom(t))
continue;

object typeObj = Activator.CreateInstance(t);
object config = SynapseController.Server.Configs.GetOrSetDefault(section, typeObj);
field.SetValue(context.Plugin,config);
field.SetValue(context.Plugin, config);
}

foreach (var property in context.PluginType.GetProperties())
{
var configAttribute = property.GetCustomAttribute<Config>();
if (configAttribute == null) continue;
var section = configAttribute.section;
Type t = property.PropertyType;
if (section == null) section = t.FullName?.Replace(".", " ");

if (!typeof(IConfigSection).IsAssignableFrom(t))
continue;

object typeObj = Activator.CreateInstance(t);
object config = SynapseController.Server.Configs.GetOrSetDefault(section, typeObj);
property.SetValue(context.Plugin, config);
}
}
catch (Exception e)
Expand Down
2 changes: 1 addition & 1 deletion Synapse/Api/Roles/RoleManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ internal RoleManager() { }

internal void Init()
{
SynapseController.Server.Events.Player.PlayerEscapseEvent += OnEscape;
SynapseController.Server.Events.Player.PlayerEscapesEvent += OnEscape;
SynapseController.Server.Events.Player.PlayerLeaveEvent += OnLeave;
SynapseController.Server.Events.Player.PlayerEnterFemurEvent += OnFemur;
SynapseController.Server.Events.Server.RemoteAdminCommandEvent += OnRa;
Expand Down
Loading

0 comments on commit d060b1f

Please sign in to comment.