Skip to content
This repository has been archived by the owner on Sep 12, 2020. It is now read-only.

Commit

Permalink
Merge pull request #20 from SynapseSL/development
Browse files Browse the repository at this point in the history
Synapse v1.3.0
  • Loading branch information
GrafDimenzio authored Aug 29, 2020
2 parents 3415ce0 + f0a56df commit 60b3a27
Show file tree
Hide file tree
Showing 32 changed files with 1,099 additions and 175 deletions.
9 changes: 9 additions & 0 deletions Synapse/Api/Decontamination.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,14 @@ namespace Synapse.Api
{
public static class Decontamination
{
/// <summary>
/// Gives you the Decontamination Controller
/// </summary>
public static DecontaminationController Controller => DecontaminationController.Singleton;

/// <summary>
/// Is the Decontamination Countdown disabled?
/// </summary>
public static bool IsDecontaminationDisabled
{
get => Controller._disableDecontamination;
Expand All @@ -21,6 +27,9 @@ public static bool IsDecontaminationDisabled
}
}

/// <summary>
/// Is the Decontamination in Progress?
/// </summary>
public static bool IsDecontaminationInProgress => Controller._decontaminationBegun;

/// <summary>
Expand Down
144 changes: 144 additions & 0 deletions Synapse/Api/Dummy.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,144 @@
using Mirror;
using RemoteAdmin;
using System.Linq;
using UnityEngine;

namespace Synapse.Api
{
public class Dummy
{
private ItemType helditem;
private GameObject gameObject;

/// <summary>
/// Get / Set the Current Role of the Dummy
/// </summary>
public RoleType Role
{
get => gameObject.GetComponent<CharacterClassManager>().CurClass;
set
{
Despawn();
gameObject.GetComponent<CharacterClassManager>().CurClass = value;
Spawn();
}
}

/// <summary>
/// Get / Set the Current Name of the Dummy
/// </summary>
public string Name
{
get => gameObject.GetComponent<NicknameSync>().Network_myNickSync;
set => gameObject.GetComponent<NicknameSync>().Network_myNickSync = value;
}

/// <summary>
/// Get / Set the Current Position of the Dummy
/// </summary>
public Vector3 Position
{
get => gameObject.transform.position;
set
{
Despawn();
gameObject.transform.position = value;
Spawn();
}
}

/// <summary>
/// Get / Set the Scale of the Dummy
/// </summary>
public Vector3 Scale
{
get => gameObject.transform.localScale;
set
{
Despawn();
gameObject.transform.localScale = value;
Spawn();
}
}

/// <summary>
/// Get / Set the Current Item the Dummy is holding
/// </summary>
public ItemType HeldItem
{
get => helditem;
set
{
gameObject.GetComponent<Inventory>().SetCurItem(value);
helditem = value;
}
}

/// <summary>
/// Get / Set the BadgeText of the Dummy
/// </summary>
public string BadgeName
{
get => gameObject.GetComponent<ServerRoles>().MyText;
set => gameObject.GetComponent<ServerRoles>().SetText(value);
}

/// <summary>
/// Get / Set the BadgeCOlor of the Dummy
/// </summary>
public string BadgeColor
{
get => gameObject.GetComponent<ServerRoles>().MyColor;
set => gameObject.GetComponent<ServerRoles>().SetColor(value);
}

/// <summary>
/// Creates a New Dummy and Spawn it
/// </summary>
/// <param name="pos">The Position where the Dummy should spawn</param>
/// <param name="rot">The Rotation of the Dummy</param>
/// <param name="role">The Role which the Dummy should be</param>
/// <param name="name">The Name of the Dummy</param>
/// <param name="badgetext">The Displayed BadgeTeyt of the Dummy</param>
/// <param name="badgecolor">The Displayed BadgeColor of the Dummy</param>
public Dummy(Vector3 pos, Quaternion rot, RoleType role = RoleType.ClassD, string name = "(null)",string badgetext = "",string badgecolor = "")
{
GameObject obj =
Object.Instantiate(
NetworkManager.singleton.spawnPrefabs.FirstOrDefault(p => p.gameObject.name == "Player"));

if (obj.GetComponent<Player>() == null)
obj.AddComponent<Player>();

gameObject = obj;

obj.GetComponent<CharacterClassManager>().CurClass = role;
obj.GetComponent<NicknameSync>().Network_myNickSync = name;
gameObject.GetComponent<ServerRoles>().MyText = badgetext;
gameObject.GetComponent<ServerRoles>().MyColor = badgecolor;
obj.transform.localScale = Vector3.one;
obj.transform.position = pos;
obj.transform.rotation = rot;
obj.GetComponent<QueryProcessor>().NetworkPlayerId = 9999;
obj.GetComponent<QueryProcessor>().PlayerId = 9999;

NetworkServer.Spawn(obj);
ReferenceHub.Hubs.Remove(obj);
}

/// <summary>
/// Despawns the Dummy
/// </summary>
public void Despawn() => NetworkServer.UnSpawn(gameObject);

/// <summary>
/// Spawns the Dummy again after Despawning
/// </summary>
public void Spawn() => NetworkServer.Spawn(gameObject);

/// <summary>
/// Destroys the Object
/// </summary>
public void Destroy() => Object.Destroy(gameObject);
}
}
8 changes: 8 additions & 0 deletions Synapse/Api/Extensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -97,5 +97,13 @@ public static Player GetPlayer(this ICommandSender sender)
public static string GetVersionString(this PluginDetails details) => $"{details.SynapseMajor}.{details.SynapseMinor}.{details.SynapsePatch}";

public static int GetVersionNumber(this PluginDetails details) => details.SynapseMajor * 100 + details.SynapseMinor * 10 + details.SynapsePatch;

public static MapPoint GetMapPoint(this YamlConfig config,string key,MapPoint def = null)
{
if (MapPoint.TryParse(config.GetString(key),out var point))
return point;

return def;
}
}
}
1 change: 1 addition & 0 deletions Synapse/Api/Jail.cs
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,7 @@ public void UnJail()
player.Role = Role;
Timing.CallDelayed(0.2f, () => player.Position = Position);
player.Health = Health;
player.ClearInventory();

foreach (var item in Items)
player.Inventory.items.Add(item);
Expand Down
59 changes: 44 additions & 15 deletions Synapse/Api/Map.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,9 @@ namespace Synapse.Api
[SuppressMessage("ReSharper", "UnusedMember.Global")]
public static class Map
{
private static Broadcast BroadcastComponent => Player.Host.GetComponent<Broadcast>();


/// <summary>
/// Activates/Deactivates the FriendlyFire on the server
/// </summary>
Expand All @@ -22,8 +25,6 @@ public static class Map
/// </summary>
public static List<Lift> Lifts => Server.GetObjectsOf<Lift>();

private static Broadcast BroadcastComponent => Player.Host.GetComponent<Broadcast>();

/// <summary>
/// Gives you a list of all rooms
/// </summary>
Expand All @@ -37,6 +38,9 @@ public static IEnumerable<Room> Rooms
}
}

/// <summary>
/// Get/Sets the Text of the Intercom
/// </summary>
public static string IntercomText
{
get => Server.Host.GetComponent<Intercom>().CustomContent;
Expand Down Expand Up @@ -175,6 +179,38 @@ public static Vector3 GetRandomSpawnPoint(this RoleType type)
public static Pickup SpawnItem(ItemType itemType, float durability, Vector3 position, Quaternion rotation = default, int sight = 0, int barrel = 0, int other = 0)
=> Player.Host.Inventory.SetPickup(itemType, durability, position, rotation, sight, barrel, other);

/// <summary>
/// Spawns a Item on the Map with a specific scale
/// </summary>
/// <param name="itemType"></param>
/// <param name="durability"></param>
/// <param name="position"></param>
/// <param name="scale"></param>
/// <param name="rotation"></param>
/// <param name="sight"></param>
/// <param name="barrel"></param>
/// <param name="other"></param>
/// <returns></returns>
public static Pickup SpawnItem(ItemType itemType, float durability, Vector3 position, Vector3 scale, Quaternion rotation = default, int sight = 0, int barrel = 0, int other = 0)
{
var p = Server.Host.Inventory.SetPickup(itemType, -4.656647E+11f, position, Quaternion.identity, 0, 0, 0);

var gameObject = p.gameObject;
gameObject.transform.localScale = scale;

NetworkServer.UnSpawn(gameObject);
NetworkServer.Spawn(p.gameObject);

return p;
}

/// <summary>
/// Spawns a WorkStation on the Map
/// </summary>
/// <param name="position"></param>
/// <param name="rotation"></param>
/// <param name="size"></param>
/// <returns>The Workstation</returns>
public static WorkStation SpawnWorkStation(Vector3 position,Vector3 rotation,Vector3 size)
{
GameObject bench =
Expand All @@ -193,6 +229,12 @@ public static WorkStation SpawnWorkStation(Vector3 position,Vector3 rotation,Vec
return bench.GetComponent<WorkStation>();
}

/// <summary>
/// Spawns a Ragdoll on the Map
/// </summary>
/// <param name="Position"></param>
/// <param name="role"></param>
/// <param name="killer"></param>
public static void SpawnRagdoll(Vector3 Position,RoleType role,string killer = "World")
{
Server.Host.GetComponent<RagdollManager>().SpawnRagdoll(
Expand All @@ -201,19 +243,6 @@ public static void SpawnRagdoll(Vector3 Position,RoleType role,string killer = "
, false, killer, killer, 1);
}

public static Pickup SpawnItem(ItemType itemType, float durability, Vector3 position, Vector3 scale, Quaternion rotation = default, int sight = 0, int barrel = 0, int other = 0)
{
var p = Server.Host.Inventory.SetPickup(itemType, -4.656647E+11f, position,Quaternion.identity, 0, 0, 0);

var gameObject = p.gameObject;
gameObject.transform.localScale = scale;

NetworkServer.UnSpawn(gameObject);
NetworkServer.Spawn(p.gameObject);

return p;
}

/// <summary>
/// Has the group the permission?
/// </summary>
Expand Down
91 changes: 91 additions & 0 deletions Synapse/Api/MapPoint.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
using System;
using System.Linq;
using UnityEngine;

namespace Synapse.Api
{
public class MapPoint
{
/// <summary>
/// Tries to Parse a string to a MapPoint
/// </summary>
/// <param name="mappointstring">The string you try to parse</param>
/// <param name="mapPoint">The MapPoint you Parse</param>
/// <returns>If the Parsing was sucesfully and mapPoint is not null</returns>
public static bool TryParse(string mappointstring, out MapPoint mapPoint)
{
try
{
mapPoint = Parse(mappointstring);
return true;
}
catch
{
mapPoint = null;
return false;
}
}

/// <summary>
/// Parses a string to a MapPoint
/// </summary>
/// <param name="mappointstring">The String you want to Parse</param>
/// <returns>The MapPoint which was parsed</returns>
public static MapPoint Parse(string mappointstring) => new MapPoint(mappointstring);

/// <summary>
/// Creates a MapPoint
/// </summary>
/// <param name="room">The Room the MapPoint is realtive too</param>
/// <param name="position">The Position you want to get the MapPoint of</param>
public MapPoint(Room room, Vector3 position)
{
if (position == null) throw new ArgumentNullException("position", "The Argument position of the Constructor MapPoint(Room room,Vector3 position) is null");
if (room == null) throw new ArgumentNullException("room", "The Argument Room of the Constructor MapPoint(Room room,Vector3 position) is null");

Room = room;
RelativePosition = Room.Transform.InverseTransformPoint(position);
}

/// <summary>
/// Creates a MapPoint
/// </summary>
/// <param name="mappointstring">The String from which you want to create a MapPoint of</param>
public MapPoint(string mappointstring)
{
string[] args = mappointstring.Split(':');
if (args.Count() < 4) throw new IndexOutOfRangeException("Parsing of string to MapPoint failed because there was missing informations!He need to look like this: \"Roomname:1,434:-2,346456:1,6554\"");
var room = Map.Rooms.FirstOrDefault(r => r.Name.ToLower() == args[0].ToLower());
if (room == null) throw new Exception("Parsing of string to MapPoint failed because of the roomname");

if (!float.TryParse(args[1], out var x)) throw new Exception("Parsing of string to MapPoint failed because of the Relative x Position!");
if (!float.TryParse(args[2], out var y)) throw new Exception("Parsing of string to MapPoint failed because of the Relative y Position!");
if (!float.TryParse(args[3], out var z)) throw new Exception("Parsing of string to MapPoint failed because of the Relative z Position!");

Room = room;
RelativePosition = new Vector3(x, y, z);
}


/// <summary>
/// The Room of which the MapPoint is relative too
/// </summary>
public readonly Room Room;

/// <summary>
/// The Relative Position of the MapPoint to the Room
/// </summary>
public readonly Vector3 RelativePosition;

/// <summary>
/// The Calculated end Position on the Map
/// </summary>
public Vector3 Position { get => Room.Transform.TransformPoint(RelativePosition); }

/// <summary>
/// The MapPoint as a String
/// </summary>
/// <returns></returns>
public override string ToString() => $"{Room.Name}:{RelativePosition.x}:{RelativePosition.y}:{RelativePosition.z}";
}
}
Loading

0 comments on commit 60b3a27

Please sign in to comment.