Skip to content
This repository has been archived by the owner on Feb 21, 2023. It is now read-only.

Commit

Permalink
Merge pull request #178 from ServerMod/API-Changes
Browse files Browse the repository at this point in the history
Quick API changes
  • Loading branch information
MrMith authored Oct 21, 2020
2 parents 86d837b + 9a0477e commit 6e86599
Show file tree
Hide file tree
Showing 5 changed files with 130 additions and 6 deletions.
35 changes: 34 additions & 1 deletion Smod2/API/Item.cs
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
using System;
using System.Collections.Generic;

namespace Smod2.API
{
public enum ItemType
Expand Down Expand Up @@ -77,7 +80,7 @@ public enum KnobSetting
VERY_FINE = 4
}

public abstract class Item
public abstract class Item : IEquatable<Item>
{
public abstract bool InWorld { get; }
public abstract ItemType ItemType { get; }
Expand All @@ -89,6 +92,36 @@ public abstract class Item
public abstract bool GetKinematic();
public abstract object GetComponent();
public abstract bool IsWeapon { get; }
/// <summary>
/// Used so IEquatable is possible so you can compare items.
/// </summary>
public abstract int UniqueIdentifier { get; }
public abstract Weapon ToWeapon();

public override bool Equals(object obj)
{
return Equals(obj as Item);
}

public bool Equals(Item other)
{
return other != null && UniqueIdentifier != 0 && other.UniqueIdentifier != 0 &&
UniqueIdentifier == other.UniqueIdentifier;
}

public override int GetHashCode()
{
return 1780733181 + UniqueIdentifier.GetHashCode();
}

public static bool operator ==(Item left, Item right)
{
return EqualityComparer<Item>.Default.Equals(left, right);
}

public static bool operator !=(Item left, Item right)
{
return !(left == right);
}
}
}
34 changes: 32 additions & 2 deletions Smod2/API/Map.cs
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,17 @@ public abstract class Map
public abstract bool WarheadLeverEnabled { get; set; }
public abstract bool WarheadKeycardEntered { get; set; }
public abstract void OverchargeLights(float forceDuration, bool onlyHeavy);

/// <summary>
/// Spawns an item for everyone then returns that object.
/// </summary>
/// <param name="ThingToSpawn">Which prefab to use</param>
/// <param name="position">Global position</param>
/// <param name="rotation">Rotation</param>
/// <param name="size">Scale the prefab</param>
/// <param name="spawnRightAway">Should it spawn the Spawnable right away or let the plugin do it.</param>
/// <returns>Gameobject that has been spawned</returns>
public abstract object SpawnSpawnable(Spawnable ThingToSpawn, Vector position, Vector rotation, Vector size, bool spawnRightAway = true);
}

public abstract class Door
Expand Down Expand Up @@ -124,6 +135,27 @@ public abstract class PocketDimensionExit
public abstract Vector Position { get; }
}

public enum Spawnable //1st is player and 2nd is Lobby_Playback and I don't know how spawning these would break/destroy existance itself.
{
Pickup = 2,
Work_Station = 3,
Ragdoll_SCP173 = 4,
Ragdoll_DClass = 5,
Ragdoll_SCP106 = 6,
Ragdoll_MTF = 7,
Ragdoll_SCIENTIST = 8,
Ragdoll_SCP049 = 9,
Ragdoll_CHAOS = 10,
SCP_096_Ragdoll = 11,
Ragdoll_SCP049_2 = 12,
Ragdoll_GUARD = 13,
Ragdoll_SCP939_53 = 14,
Ragdoll_SCP939_89 = 15,
Grenade_Flash = 16,
Grenade_Frag = 17,
Grenade_SCP_018 = 18
}

public enum ZoneType
{
UNDEFINED = 0,
Expand Down Expand Up @@ -185,7 +217,6 @@ public abstract class Room
public abstract Vector Position { get; }
public abstract Vector Forward { get; }
public abstract Vector SpeakerPosition { get; }

public abstract void FlickerLights(float duration = 8f);
[Obsolete("Use FlickerLights(float duration = 8f) instead of FlickerLights()")]
public abstract void FlickerLights();
Expand All @@ -203,7 +234,6 @@ public abstract class Generator
public abstract float TimeLeft { get; set; }
public abstract Vector Position { get; }
public abstract Room Room { get; }

public abstract void Unlock();
public abstract object GetComponent();
}
Expand Down
33 changes: 32 additions & 1 deletion Smod2/API/Player.cs
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ public enum StatusEffect
INVIGORATED = 20,
}

public abstract class Player : ICommandSender
public abstract class Player : ICommandSender, IEquatable<Player>
{
internal bool CallSetRoleEvent { get; set; }
protected bool ShouldCallSetRoleEvent { get => CallSetRoleEvent; } // used in the game
Expand Down Expand Up @@ -175,6 +175,7 @@ public string GetParsedUserID()
public abstract float HP { get; set; }
public abstract float Stamina { get; set; }
public abstract void Damage(float amount, DamageType type = DamageType.NUKE);
[Obsolete("Use HP property instead.")]
public abstract void SetHealth(float amount, DamageType type = DamageType.NUKE);
public abstract int GetAmmo(AmmoType type);
public abstract void SetAmmo(AmmoType type, int amount);
Expand All @@ -195,13 +196,17 @@ public string GetParsedUserID()
public abstract void SetCurrentItemIndex(int index);
public abstract bool HasItem(ItemType type);
public abstract int GetItemIndex(ItemType type);
public abstract void ClearInventory();
public abstract bool IsHandcuffed();
public abstract void ChangeRole(RoleType role, bool full = true, bool spawnTeleport = true, bool spawnProtect = true, bool removeHandcuffs = false);
public abstract object GetGameObject();
public abstract UserGroup GetUserGroup();
public abstract string[] RunCommand(string command, string[] args);
[Obsolete("Use GodMode property instead.")]
public abstract bool GetGodmode();
[Obsolete("Use GodMode property instead.")]
public abstract void SetGodmode(bool godmode);
public abstract bool GodMode { get; set; }
public abstract Vector GetRotation();
public abstract void SendConsoleMessage(string message, string color = "green");
public abstract void Infect(float time);
Expand Down Expand Up @@ -232,6 +237,32 @@ public bool HasPermission(string permissionName)
public abstract void RemoveHandcuffs();
public abstract bool GetGhostMode();
public abstract void SetGhostMode(bool ghostMode, bool visibleToSpec = true, bool visibleWhenTalking = true);

public override bool Equals(object obj)
{
return Equals(obj as Player);
}

public bool Equals(Player other)
{
return other != null &&
PlayerId == other.PlayerId;
}

public override int GetHashCode()
{
return 956575109 + PlayerId.GetHashCode();
}

public static bool operator ==(Player left, Player right)
{
return EqualityComparer<Player>.Default.Equals(left, right);
}

public static bool operator !=(Player left, Player right)
{
return !(left == right);
}
}

public abstract class Scp079Data
Expand Down
32 changes: 31 additions & 1 deletion Smod2/API/Weapon.cs
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
using System;
using System.Collections.Generic;

namespace Smod2.API
{
public enum WeaponType
Expand Down Expand Up @@ -58,7 +61,7 @@ public enum AttachmentType
OTHER = 2
}

public abstract class Weapon
public abstract class Weapon : IEquatable<Weapon>
{
public abstract WeaponType WeaponType { get; }
public abstract WeaponSight Sight { get; set; }
Expand All @@ -69,6 +72,33 @@ public abstract class Weapon
public abstract AmmoType AmmoType { get; }
public abstract DamageType DamageType { get; }
public abstract object GetComponent();
public abstract int UniqueIdentifier { get; }
public abstract Item ToItem();

public override bool Equals(object obj)
{
return Equals(obj as Weapon);
}

public bool Equals(Weapon other)
{
return other != null &&
UniqueIdentifier == other.UniqueIdentifier;
}

public override int GetHashCode()
{
return 1780733181 + UniqueIdentifier.GetHashCode();
}

public static bool operator ==(Weapon left, Weapon right)
{
return EqualityComparer<Weapon>.Default.Equals(left, right);
}

public static bool operator !=(Weapon left, Weapon right)
{
return !(left == right);
}
}
}
2 changes: 1 addition & 1 deletion Smod2/PluginManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ public class PluginManager
{
public static readonly int SMOD_MAJOR = 3;
public static readonly int SMOD_MINOR = 9;
public static readonly int SMOD_REVISION = 1;
public static readonly int SMOD_REVISION = 2;

public static readonly string SMOD_BUILD = "A";

Expand Down

0 comments on commit 6e86599

Please sign in to comment.