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 #78 from SynapseSL/development
Browse files Browse the repository at this point in the history
Development
  • Loading branch information
GrafDimenzio authored Oct 25, 2021
2 parents 592edc4 + 8ee9b87 commit 669c831
Show file tree
Hide file tree
Showing 12 changed files with 150 additions and 94 deletions.
Binary file modified Refs/Assembly-CSharp-Publicized.dll
Binary file not shown.
139 changes: 76 additions & 63 deletions Synapse/Api/Dummy.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System.Collections.Generic;
using System;
using System.Collections.Generic;
using InventorySystem;
using Mirror;
using RemoteAdmin;
Expand Down Expand Up @@ -99,7 +100,11 @@ public string BadgeColor
public PlayerMovementState Movement
{
get => Player.AnimationController.MoveState;
set => Player.AnimationController.UserCode_CmdChangeSpeedState((byte)value);
set
{
Player.AnimationController.MoveState = Movement;
Player.AnimationController.RpcReceiveState((byte)Movement);
}
}

public MovementDirection Direction { get; set; }
Expand All @@ -116,68 +121,75 @@ private IEnumerator<float> Update()
for(; ; )
{
yield return MEC.Timing.WaitForSeconds(0.1f);
if (GameObject == null) yield break;
if (Direction == MovementDirection.Stop)
{
continue;
}

var wall = false;
var speed = 0f;

switch (Movement)
{
case PlayerMovementState.Sneaking:
speed = SneakSpeed;
break;

case PlayerMovementState.Sprinting:
speed = RunSpeed * Map.Get.SprintSpeed;
break;

case PlayerMovementState.Walking:
speed = WalkSpeed * Map.Get.WalkSpeed;
break;
}

switch (Direction)
try
{
case MovementDirection.Forward:
var pos = Position + Player.CameraReference.forward / 10 * speed;

if (!Physics.Linecast(Position, pos, Player.PlayerMovementSync.CollidableSurfaces))
Player.PlayerMovementSync.OverridePosition(pos, 0f, true);
else wall = true;
break;

case MovementDirection.BackWards:
pos = Position - Player.CameraReference.forward / 10 * speed;

if (!Physics.Linecast(Position, pos, Player.PlayerMovementSync.CollidableSurfaces))
Player.PlayerMovementSync.OverridePosition(pos, 0f, true);
else wall = true;
break;

case MovementDirection.Right:
pos = Position + Quaternion.AngleAxis(90, Vector3.up) * Player.CameraReference.forward / 10 * speed;

if (!Physics.Linecast(Position, pos, Player.PlayerMovementSync.CollidableSurfaces))
Player.PlayerMovementSync.OverridePosition(pos, 0f, true);
else wall = true;
break;

case MovementDirection.Left:
pos = Position - Quaternion.AngleAxis(90, Vector3.up) * Player.CameraReference.forward / 10 * speed;

if (!Physics.Linecast(Position, pos, Player.PlayerMovementSync.CollidableSurfaces))
Player.PlayerMovementSync.OverridePosition(pos, 0f, true);
else wall = true;
break;
if (GameObject == null) yield break;
if (Direction == MovementDirection.Stop)
{
continue;
}

var wall = false;
var speed = 0f;

switch (Movement)
{
case PlayerMovementState.Sneaking:
speed = SneakSpeed;
break;

case PlayerMovementState.Sprinting:
speed = RunSpeed * Map.Get.SprintSpeed;
break;

case PlayerMovementState.Walking:
speed = WalkSpeed * Map.Get.WalkSpeed;
break;
}

switch (Direction)
{
case MovementDirection.Forward:
var pos = Position + Player.CameraReference.forward / 10 * speed;

if (!Physics.Linecast(Position, pos, Player.PlayerMovementSync.CollidableSurfaces))
Player.PlayerMovementSync.OverridePosition(pos, 0f, true);
else wall = true;
break;

case MovementDirection.BackWards:
pos = Position - Player.CameraReference.forward / 10 * speed;

if (!Physics.Linecast(Position, pos, Player.PlayerMovementSync.CollidableSurfaces))
Player.PlayerMovementSync.OverridePosition(pos, 0f, true);
else wall = true;
break;

case MovementDirection.Right:
pos = Position + Quaternion.AngleAxis(90, Vector3.up) * Player.CameraReference.forward / 10 * speed;

if (!Physics.Linecast(Position, pos, Player.PlayerMovementSync.CollidableSurfaces))
Player.PlayerMovementSync.OverridePosition(pos, 0f, true);
else wall = true;
break;

case MovementDirection.Left:
pos = Position - Quaternion.AngleAxis(90, Vector3.up) * Player.CameraReference.forward / 10 * speed;

if (!Physics.Linecast(Position, pos, Player.PlayerMovementSync.CollidableSurfaces))
Player.PlayerMovementSync.OverridePosition(pos, 0f, true);
else wall = true;
break;
}

if (wall)
{
Direction = MovementDirection.Stop;
}
}

if (wall)
catch(Exception e)
{
Direction = MovementDirection.Stop;
Logger.Get.Error($"Synapse-Dummy: Dummy Update Failed:\n{e}");
}
}
}
Expand All @@ -196,7 +208,7 @@ private IEnumerator<float> Update()
public Dummy(Vector3 pos, Vector2 rot, RoleType role = RoleType.ClassD, string name = "(null)", string badgetext = "", string badgecolor = "")
{
GameObject obj =
Object.Instantiate(
UnityEngine.Object.Instantiate(
NetworkManager.singleton.playerPrefab);

GameObject = obj;
Expand All @@ -217,6 +229,7 @@ public Dummy(Vector3 pos, Vector2 rot, RoleType role = RoleType.ClassD, string n
Player.RankName = badgetext;
Player.RankColor = badgecolor;
Player.GodMode = true;
Player.PlayerMovementSync.NetworkGrounded = true;
RunSpeed = CharacterClassManager._staticClasses[(int)role].runSpeed;
WalkSpeed = CharacterClassManager._staticClasses[(int)role].walkSpeed;
MEC.Timing.RunCoroutine(Update());
Expand Down Expand Up @@ -254,7 +267,7 @@ public void Spawn()
/// </summary>
public void Destroy()
{
Object.Destroy(GameObject);
UnityEngine.Object.Destroy(GameObject);
Map.Get.Dummies.Remove(this);
}

Expand Down
5 changes: 4 additions & 1 deletion Synapse/Api/Events/EventHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,10 @@ private void KeyPress(SynapseEventArguments.PlayerKeyPressEventArgs ev)
{
switch (ev.KeyCode)
{

case KeyCode.Alpha1:
Logger.Get.Debug(ev.Player.ItemInHand.ID);

break;
}
}

Expand Down
2 changes: 1 addition & 1 deletion Synapse/Api/Items/ItemManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ public class ItemManager
{
public static ItemManager Get => Server.Get.ItemManager;

public const int HighestItem = (int)ItemType.GunShotgun;
public const int HighestItem = (int)ItemType.SCP2176;

private readonly List<CustomItemInformation> customItems = new List<CustomItemInformation>();

Expand Down
4 changes: 2 additions & 2 deletions Synapse/Api/Items/PlayerInventory.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ public SynapseItem this[int index]
get => Items[index];
}

public List<Items.SynapseItem> Items => player.VanillaInventory.UserInventory.Items.Select(x => x.Value.GetSynapseItem()).ToList();
public List<Items.SynapseItem> Items => player.VanillaInventory.UserInventory.Items.Select(x => x.Value.GetSynapseItem()).Where(x => x != null).ToList();

public void AddItem(SynapseItem item) => item.PickUp(player);

Expand All @@ -36,7 +36,7 @@ public void DropAll()
try
{
foreach (var item in Items)
item.Drop();
item?.Drop();

foreach (var ammo in player.VanillaInventory.UserInventory.ReserveAmmo.ToList())
player.VanillaInventory.ServerDropAmmo(ammo.Key, ammo.Value);
Expand Down
26 changes: 24 additions & 2 deletions Synapse/Api/Items/SynapseItem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -297,6 +297,7 @@ public Vector3 Scale
}
}

private float durabillity = 0;
public float Durabillity
{
get
Expand Down Expand Up @@ -331,10 +332,16 @@ public float Durabillity
break;
}

return 0;
return durabillity;
}
set
{
if(State == ItemState.Despawned)
{
durabillity = value;
return;
}

switch (ItemCategory)
{
case ItemCategory.Radio:
Expand Down Expand Up @@ -372,6 +379,7 @@ public float Durabillity
}
}

private uint attachments = 0;
public uint WeaponAttachments
{
get
Expand All @@ -384,10 +392,16 @@ public uint WeaponAttachments
{
return armpickup.Status.Attachments;
}
return 0;
return attachments;
}
set
{
if (State == ItemState.Despawned)
{
attachments = value;
return;
}

if (ItemBase is Firearm arm)
{
arm.ApplyAttachmentsCode(value,true);
Expand All @@ -412,6 +426,8 @@ public void PickUp(Player player)

case ItemState.Despawned:
player.VanillaInventory.ServerAddItem(ItemType, Serial);
Durabillity = durabillity;
WeaponAttachments = attachments;
break;

case ItemState.Inventory:
Expand Down Expand Up @@ -449,6 +465,9 @@ public void Drop(Vector3 position)
PickupBase.transform.localScale = Scale;
NetworkServer.Spawn(PickupBase.gameObject);
PickupBase.InfoReceived(default, info);

Durabillity = durabillity;
WeaponAttachments = attachments;
}
break;
}
Expand All @@ -465,6 +484,9 @@ public void Drop()

public void Despawn()
{
durabillity = Durabillity;
attachments = WeaponAttachments;

DespawnItemBase();
DespawnPickup();
Throwable.DestroyProjectile();
Expand Down
29 changes: 29 additions & 0 deletions Synapse/Api/MapPoint.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using System;
using System.Linq;
using MapGeneration;
using UnityEngine;

namespace Synapse.Api
Expand Down Expand Up @@ -62,6 +63,34 @@ public MapPoint(string mappointstring)
RelativePosition = new Vector3(x, y, z);
}

/// <summary>
/// Creates a MapPoint
/// </summary>
/// <param name="type"></param>
/// <param name="x"></param>
/// <param name="y"></param>
/// <param name="z"></param>
public MapPoint(RoomName type, float x, float y, float z)
{
var synapseroom = SynapseController.Server.Map.GetRoom(type);
Room = synapseroom ?? throw new Exception("Parsing of string to MapPoint failed because of the roomname");
RelativePosition = new Vector3(x, y, z);
}

/// <summary>
/// Creates a MapPoint
/// </summary>
/// <param name="room"></param>
/// <param name="x"></param>
/// <param name="y"></param>
/// <param name="z"></param>
public MapPoint(string room, float x, float y, float z)
{
var synapseroom = SynapseController.Server.Map.Rooms.FirstOrDefault(r => r.RoomName.ToLower() == room.ToLower());
Room = synapseroom ?? throw new Exception("Parsing of string to MapPoint failed because of the roomname");
RelativePosition = new Vector3(x, y, z);
}


/// <summary>
/// The Room of which the MapPoint is relative too
Expand Down
12 changes: 8 additions & 4 deletions Synapse/Api/Player.cs
Original file line number Diff line number Diff line change
Expand Up @@ -589,7 +589,7 @@ public RoleType RoleType

public Room Room
{
get => RoomIdUtils.RoomAtPosition(Position).GetSynapseRoom();
get => RoomIdUtils.RoomAtPosition(Position).GetSynapseRoom() ?? Map.Get.Rooms.OrderBy(x => Vector3.Distance(x.Position, Position)).FirstOrDefault();
set => Position = value.Position;
}

Expand Down Expand Up @@ -667,7 +667,11 @@ public ushort this[AmmoType ammo]

return 0;
}
set => player.VanillaInventory.UserInventory.ReserveAmmo[(ItemType)ammo] = value;
set
{
player.VanillaInventory.UserInventory.ReserveAmmo[(ItemType)ammo] = value;
player.VanillaInventory.SendAmmoNextFrame = true;
}
}
}

Expand Down Expand Up @@ -771,9 +775,9 @@ public SynapseItem ItemInHand
{
get
{
if (VanillaInventory.CurItem == ItemIdentifier.None) return SynapseItem.None;
if (VanillaInventory.CurItem == ItemIdentifier.None || VanillaInventory.CurInstance == null) return SynapseItem.None;

return VanillaInventory.CurInstance.GetSynapseItem();
return SynapseItem.AllItems[VanillaInventory.CurItem.SerialNumber];
}
set
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ private static bool HurtPlayer(PlayerStats __instance, out bool __result, Player
bool friendlyFire = default;
DamageTypes.DamageType damageType = default;

if (!TryPlayerDamageEvent(killer, victim, out (float artificialHealth, float health, bool friendlyFire, DamageTypes.DamageType damageType) temp))
if (!TryPlayerDamageEvent(ref killer, victim, out (float artificialHealth, float health, bool friendlyFire, DamageTypes.DamageType damageType) temp))
return false;

(artificialHealth, health, friendlyFire, damageType) = (temp.artificialHealth, temp.health, temp.friendlyFire, temp.damageType);
Expand Down Expand Up @@ -367,7 +367,7 @@ void HandleDamage(float artificialHealth, Player victim)
victim.PlayerStats.lastHitInfo = info;

}
bool TryPlayerDamageEvent(Player killer, Player victim, out (float ArtificialHealth, float Health, bool FriendlyFire, DamageTypes.DamageType DamageType) paramInfo)
bool TryPlayerDamageEvent(ref Player killer, Player victim, out (float ArtificialHealth, float Health, bool FriendlyFire, DamageTypes.DamageType DamageType) paramInfo)
{
paramInfo.ArtificialHealth = 0;
paramInfo.Health = 0;
Expand Down
Loading

0 comments on commit 669c831

Please sign in to comment.