Skip to content

Commit

Permalink
1.1.1
Browse files Browse the repository at this point in the history
  • Loading branch information
Bonjemus authored Jul 5, 2023
1 parent 7dd2a9c commit 3a37842
Show file tree
Hide file tree
Showing 10 changed files with 199 additions and 186 deletions.
59 changes: 29 additions & 30 deletions CustomDoors/Commands/AttachmentsCommand.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,49 +4,48 @@
using InventorySystem.Items;
using InventorySystem.Items.Firearms;

namespace CustomDoors.Commands
{
[CommandHandler(typeof(RemoteAdminCommandHandler))]
public class AttachmentsCommand : ICommand
{
public string Command { get; } = "Attachments";
namespace CustomDoors.Commands;

public string[] Aliases { get; } = new string[] { };
[CommandHandler(typeof(RemoteAdminCommandHandler))]
public sealed class AttachmentsCommand : ICommand
{
public string Command { get; } = "Attachments";

public string Description { get; } = "Display your weapon's attachments value.";
public string[] Aliases { get; } = new string[] { };

public bool Execute(ArraySegment<string> arguments, ICommandSender sender, out string response)
{
ItemBase itemBase = Player.Get(((CommandSender)sender).SenderId).CurrentItem;
public string Description { get; } = "Display your weapon's attachments value.";

response = "Error.";
bool allow = false;
public bool Execute(ArraySegment<string> arguments, ICommandSender sender, out string response)
{
ItemBase itemBase = Player.Get(((CommandSender)sender).SenderId).CurrentItem;

response = "Error.";
bool allow = false;

if (itemBase is not Firearm firearm)
response = "You're not holding a weapon.";

if (itemBase is not Firearm firearm)
response = "You're not holding a weapon.";

/*else if (arguments.Count > 0) forceattachments exists actually
{
if (uint.TryParse(arguments.FirstOrDefault(), out uint attachment))
{
firearm.Status = new FirearmStatus(firearm.Status.Ammo, firearm.Status.Flags, attachment);
allow = true;
}
else
response = "The argument must be a number (uint).";
}*/

else
/*else if (arguments.Count > 0) forceattachments exists actually
{
if (uint.TryParse(arguments.FirstOrDefault(), out uint attachment))
{
response = firearm.Status.Attachments.ToString();
firearm.Status = new FirearmStatus(firearm.Status.Ammo, firearm.Status.Flags, attachment);
allow = true;
}
else
response = "The argument must be a number (uint).";
}*/

if (PluginClass.Singleton.config.InfoAttachmentsCommand)
Log.Info(response);
return allow;
else
{
response = firearm.Status.Attachments.ToString();
allow = true;
}

if (PluginClass.Singleton.config.InfoAttachmentsCommand)
Log.Info(response);
return allow;
}
}
50 changes: 23 additions & 27 deletions CustomDoors/Commands/PositionCommand.cs
Original file line number Diff line number Diff line change
@@ -1,42 +1,38 @@
using CommandSystem;
using InventorySystem.Items.Pickups;
using InventorySystem;
using MapGeneration;
using Mirror;
using PluginAPI.Core;
using System;
using System.Linq;
using UnityEngine;

namespace CustomDoors.Commands
{
[CommandHandler(typeof(RemoteAdminCommandHandler))]
public class PositionCommand : ICommand
{
public string Command { get; } = "Position";
namespace CustomDoors.Commands;

public string[] Aliases { get; } = new string[] { };
[CommandHandler(typeof(RemoteAdminCommandHandler))]
public sealed class PositionCommand : ICommand
{
public string Command { get; } = "Position";

public string Description { get; } = "Gives you your position.";
public string[] Aliases { get; } = new string[] { };

public bool Execute(ArraySegment<string> arguments, ICommandSender sender, out string response)
{
Player player = Player.Get(((CommandSender)sender).SenderId);
RoomIdentifier room = player.Room;
Vector3 position = player.Position;
public string Description { get; } = "Gives you your position.";

if (arguments.Count > 0 && bool.TryParse(arguments.First(), out bool doRaycast) && doRaycast && Physics.Raycast(player.Camera.position, player.Camera.forward, out RaycastHit hitInfo, 50))
{
position = hitInfo.point;
if (RoomIdentifier.RoomsByCoordinates.TryGetValue(new Vector3Int(Mathf.RoundToInt(hitInfo.point.x / RoomIdentifier.GridScale.x), Mathf.RoundToInt(hitInfo.point.y / 100f), Mathf.RoundToInt(hitInfo.point.z / RoomIdentifier.GridScale.z)), out RoomIdentifier value))
room = value;
}

response = $"{room.name} :\nRoom position : {room.transform.position}\nRoom rotation : {room.transform.rotation.eulerAngles}\nPosition : {position}\nRelative position to room :\nx = {(position - room.transform.position).x}\ny = {(position - room.transform.position).y}\nz = {(position - room.transform.position).z}";
public bool Execute(ArraySegment<string> arguments, ICommandSender sender, out string response)
{
Player player = Player.Get(((CommandSender)sender).SenderId);
RoomIdentifier room = player.Room;
Vector3 position = player.Position;

if (PluginClass.Singleton.config.InfoPositionCommand)
Log.Info(response);
return true;
if (arguments.Count > 0 && bool.TryParse(arguments.First(), out bool doRaycast) && doRaycast && Physics.Raycast(player.Camera.position, player.Camera.forward, out RaycastHit hitInfo, 50))
{
position = hitInfo.point;
if (RoomIdentifier.RoomsByCoordinates.TryGetValue(new Vector3Int(Mathf.RoundToInt(hitInfo.point.x / RoomIdentifier.GridScale.x), Mathf.RoundToInt(hitInfo.point.y / 100f), Mathf.RoundToInt(hitInfo.point.z / RoomIdentifier.GridScale.z)), out RoomIdentifier value))
room = value;
}

response = $"{room.name} :\nRoom position : {room.transform.position}\nRoom rotation : {room.transform.rotation.eulerAngles}\nPosition : {position}\nRelative position to room :\nx = {(position - room.transform.position).x}\ny = {(position - room.transform.position).y}\nz = {(position - room.transform.position).z}";

if (PluginClass.Singleton.config.InfoPositionCommand)
Log.Info(response);
return true;
}
}
143 changes: 71 additions & 72 deletions CustomDoors/Config.cs
Original file line number Diff line number Diff line change
@@ -1,87 +1,86 @@
using Interactables.Interobjects.DoorUtils;
using System.ComponentModel;

namespace CustomDoors
namespace CustomDoors;

public sealed class Config
{
public class Config
[Description("Inform of position command's response ? (sends a debug message to the server console when using position command) :")]
public bool InfoPositionCommand { get; set; } = false;

[Description("Inform of attachments command's response ? (sends a debug message to the server console when using attachments command) :")]
public bool InfoAttachmentsCommand { get; set; } = false;

/*[Description("List of spawnable objects and their caracteristics")] Doesn't work : if you restart your server configs get changed to a useless config file that only contains SpawnableConfig but no DoorConfig nor ItemConfig
public SpawnableConfig[] SpawnableObjects { get; set; } = new SpawnableConfig[5]
{
[Description("Inform of position command's response ? (sends a debug message to the server console when using position command) :")]
public bool InfoPositionCommand { get; set; } = false;

[Description("Inform of attachments command's response ? (sends a debug message to the server console when using attachments command) :")]
public bool InfoAttachmentsCommand { get; set; } = false;

/*[Description("List of spawnable objects and their caracteristics")] Doesn't work : if you restart your server configs get changed to a useless config file that only contains SpawnableConfig but no DoorConfig nor ItemConfig
public SpawnableConfig[] SpawnableObjects { get; set; } = new SpawnableConfig[5]
{
new DoorConfig() { Type = "HCZ", RoomName = "Outside", RelativePositionX =29, RelativePositionY = -8.35f, RelativePositionZ = -42.8f, ScaleX = 1, ScaleY =1, ScaleZ = 1, KeycardPermissions = KeycardPermissions.ExitGates },
new DoorConfig() { Type = "EZ", RoomName = "LCZ_Airlock (1)", DefaultRoomRotationYAxis = 90, RelativePositionX = -3.5f, RelativePositionY = 0.9685f, RelativePositionZ= 0, ScaleX = 1, ScaleY =1, ScaleZ = 1, KeycardPermissions = KeycardPermissions.ContainmentLevelOne, Opened = true },
new ItemConfig() { Item = ItemType.Medkit, RoomName = "LCZ_ClassDSpawn (1)", ScaleX = 1, ScaleY = 1, ScaleZ = 1 },
new ItemConfig() { Item = ItemType.Medkit, RoomName = "LCZ_ClassDSpawn (1)", ScaleX = 1, ScaleY = 1, ScaleZ = 1, RelativeRotationY = 90 },
new ItemConfig() { Item = ItemType.Medkit, RoomName = "LCZ_ClassDSpawn (1)", ScaleX = 2, ScaleY = 1, ScaleZ = 2 },
};*/

[Description("List of doors and their caracteristics")]
public DoorConfig[] Doors { get; set; } = new DoorConfig[2]
{
new DoorConfig() { Type = "HCZ", RoomName = "Outside", RelativePositionX =29, RelativePositionY = -8.35f, RelativePositionZ = -42.8f, ScaleX = 1, ScaleY =1, ScaleZ = 1, KeycardPermissions = KeycardPermissions.ExitGates },
new DoorConfig() { Type = "EZ", RoomName = "LCZ_Airlock (1)", DefaultRoomRotationYAxis = 90, RelativePositionX = -3.5f, RelativePositionY = 0, RelativePositionZ = 0, ScaleX = 1, ScaleY =1, ScaleZ = 1, KeycardPermissions = KeycardPermissions.ContainmentLevelOne, Opened = false }
};

[Description("List of items and their caracteristics")]
public ItemConfig[] Items { get; set; } = new ItemConfig[3]
{
new ItemConfig() { RelativePositionY = 1, Item = ItemType.Medkit, RoomName = "LCZ_ClassDSpawn (1)", ScaleX = 1, ScaleY = 1, ScaleZ = 1 },
new ItemConfig() { RelativePositionY = 1, Item = ItemType.Medkit, RoomName = "LCZ_ClassDSpawn (1)", ScaleX = 1, ScaleY = 1, ScaleZ = 1, RelativeRotationY = 90 },
new ItemConfig() { RelativePositionY = 1, Item = ItemType.Medkit, RoomName = "LCZ_ClassDSpawn (1)", ScaleX = 2, ScaleY = 1, ScaleZ = 2 },
};
}

public class SpawnableConfig
new DoorConfig() { Type = "HCZ", RoomName = "Outside", RelativePositionX =29, RelativePositionY = -8.35f, RelativePositionZ = -42.8f, ScaleX = 1, ScaleY =1, ScaleZ = 1, KeycardPermissions = KeycardPermissions.ExitGates },
new DoorConfig() { Type = "EZ", RoomName = "LCZ_Airlock (1)", DefaultRoomRotationYAxis = 90, RelativePositionX = -3.5f, RelativePositionY = 0.9685f, RelativePositionZ= 0, ScaleX = 1, ScaleY =1, ScaleZ = 1, KeycardPermissions = KeycardPermissions.ContainmentLevelOne, Opened = true },
new ItemConfig() { Item = ItemType.Medkit, RoomName = "LCZ_ClassDSpawn (1)", ScaleX = 1, ScaleY = 1, ScaleZ = 1 },
new ItemConfig() { Item = ItemType.Medkit, RoomName = "LCZ_ClassDSpawn (1)", ScaleX = 1, ScaleY = 1, ScaleZ = 1, RelativeRotationY = 90 },
new ItemConfig() { Item = ItemType.Medkit, RoomName = "LCZ_ClassDSpawn (1)", ScaleX = 2, ScaleY = 1, ScaleZ = 2 },
};*/

[Description("List of doors and their caracteristics")]
public DoorConfig[] Doors { get; set; } = new DoorConfig[2]
{
public string RoomName { get; set; }
new DoorConfig() { Type = "HCZ", RoomName = "Outside", RelativePositionX =29, RelativePositionY = -8.35f, RelativePositionZ = -42.8f, ScaleX = 1, ScaleY =1, ScaleZ = 1, KeycardPermissions = KeycardPermissions.ExitGates },
new DoorConfig() { Type = "EZ", RoomName = "LCZ_Airlock (1)", DefaultRoomRotationYAxis = 90, RelativePositionX = -3.5f, RelativePositionY = 0, RelativePositionZ = 0, ScaleX = 1, ScaleY =1, ScaleZ = 1, KeycardPermissions = KeycardPermissions.ContainmentLevelOne, Opened = false }
};

public float DefaultRoomRotationYAxis { get; set; }
[Description("List of items and their caracteristics")]
public ItemConfig[] Items { get; set; } = new ItemConfig[3]
{
new ItemConfig() { RelativePositionY = 1, Item = ItemType.Medkit, RoomName = "LCZ_ClassDSpawn (1)", ScaleX = 1, ScaleY = 1, ScaleZ = 1 },
new ItemConfig() { RelativePositionY = 1, Item = ItemType.Medkit, RoomName = "LCZ_ClassDSpawn (1)", ScaleX = 1, ScaleY = 1, ScaleZ = 1, RelativeRotationY = 90 },
new ItemConfig() { RelativePositionY = 1, Item = ItemType.Medkit, RoomName = "LCZ_ClassDSpawn (1)", ScaleX = 2, ScaleY = 1, ScaleZ = 2 },
};
}

public float RelativePositionX { get; set; }
public float RelativePositionY { get; set; }
public float RelativePositionZ { get; set; }
public abstract class SpawnableConfig
{
public string RoomName { get; set; }

public float ScaleX { get; set; }
public float ScaleY { get; set; }
public float ScaleZ { get; set; }
public float DefaultRoomRotationYAxis { get; set; }

public float RelativeRotationX { get; set; }
public float RelativeRotationY { get; set; }
public float RelativeRotationZ { get; set; }
}
public float RelativePositionX { get; set; }
public float RelativePositionY { get; set; }
public float RelativePositionZ { get; set; }

public class DoorConfig : SpawnableConfig
{
public string Type { get; set; }
public float ScaleX { get; set; }
public float ScaleY { get; set; }
public float ScaleZ { get; set; }

public KeycardPermissions KeycardPermissions { get; set; }
public bool Opened { get; set; }
public bool Locked { get; set; }
}
public float RelativeRotationX { get; set; }
public float RelativeRotationY { get; set; }
public float RelativeRotationZ { get; set; }
}

public class ItemConfig : SpawnableConfig
{
public ItemType Item { get; set; }
public ushort Ammo { get; set; }
public uint Attachments { get; set; }
}
public sealed class DoorConfig : SpawnableConfig
{
public string Type { get; set; }

/*public class PrimitiveConfig : SpawnableConfig
{
public PrimitiveType PrimitiveType { get; set; }
public Color Color { get; set; }
}
public KeycardPermissions KeycardPermissions { get; set; }
public bool Opened { get; set; }
public bool Locked { get; set; }
}

public class LightConfig : SpawnableConfig
{
public PrimitiveType PrimitiveType { get; set; }
public Color Color { get; set; }
public float Range { get; set; }
}*/
}
public sealed class ItemConfig : SpawnableConfig
{
public ItemType Item { get; set; }
public ushort Ammo { get; set; }
public uint Attachments { get; set; }
}

/*public class PrimitiveConfig : SpawnableConfig
{
public PrimitiveType PrimitiveType { get; set; }
public Color Color { get; set; }
}
public class LightConfig : SpawnableConfig
{
public PrimitiveType PrimitiveType { get; set; }
public Color Color { get; set; }
public float Range { get; set; }
}*/
Loading

0 comments on commit 3a37842

Please sign in to comment.