This repository has been archived by the owner on Sep 12, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #20 from SynapseSL/development
Synapse v1.3.0
- Loading branch information
Showing
32 changed files
with
1,099 additions
and
175 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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}"; | ||
} | ||
} |
Oops, something went wrong.