diff --git a/NwPluginAPI/Core/Player.cs b/NwPluginAPI/Core/Player.cs index 6ca1d72..ddb1145 100644 --- a/NwPluginAPI/Core/Player.cs +++ b/NwPluginAPI/Core/Player.cs @@ -31,6 +31,12 @@ namespace PluginAPI.Core using PlayerRoles.Voice; using InventorySystem.Items.Firearms.Ammo; using CentralAuth; + using Utils; + using InventorySystem.Items.Usables.Scp330; + using InventorySystem.Items.Usables; + using InventorySystem.Items.Firearms; + using InventorySystem.Items.Firearms.BasicMessages; + using InventorySystem.Items.Flashlight; /// /// Represents a player connected to server. @@ -678,28 +684,27 @@ public ItemBase CurrentItem } /// - /// Get player current room. + /// Gets player current room. /// public RoomIdentifier Room => RoomIdUtils.RoomAtPosition(GameObject.transform.position); - /// - /// Get player current zone. + /// Gets player current zone. /// public FacilityZone Zone => Room?.Zone ?? FacilityZone.None; /// - /// Get player items. + /// Gets player items. /// - public IReadOnlyCollection Items => ReferenceHub.inventory.UserInventory.Items.Values; + public IReadOnlyCollection Items => ReferenceHub.inventory.UserInventory.Items.Values.ToList(); /// - /// Get player ammo bag. + /// Gets player ammo bag. /// public Dictionary AmmoBag => ReferenceHub.inventory.UserInventory.ReserveAmmo; /// - /// Get or set server role color. + /// Gets or sets server role color. /// public string RoleColor { @@ -708,7 +713,7 @@ public string RoleColor } /// - /// Get or set server role text. + /// Gets or sets server role text. /// public string RoleName { @@ -757,7 +762,7 @@ public string RoleName public bool IsWithoutItems => ReferenceHub.inventory.UserInventory.Items.Count == 0; /// - /// Get if the player has no ammunition. + /// Gets if the player has no ammunition. /// public bool IsOutOfAmmo => ReferenceHub.inventory.UserInventory.ReserveAmmo.All(ammo => ammo.Value == 0); @@ -837,7 +842,7 @@ public bool IsNoclipEnabled /// /// Gets whether or not the player's inventory is full. /// - public bool IsInventoryFull => ReferenceHub.inventory.UserInventory.Items.Count >= 8; + public bool IsInventoryFull => ReferenceHub.inventory.UserInventory.Items.Count == Inventory.MaxSlots; /// /// Get player role team. @@ -1036,6 +1041,16 @@ public void SendBroadcast(string message, ushort duration, BroadcastFlags type = /// The message color. public void SendConsoleMessage(string message, string color = "green") => ReferenceHub.gameConsoleTransmission.SendToClient(message, color); + /// + /// Opens a reporting window with the specified message. + /// + /// The message to be displayed in the reporting window. + /// The color of the message (default is "green"). + public void OpenReportWindow(string message, string color = "green") + { + SendConsoleMessage($"[REPORTING] {message}", color); + } + /// /// Bans the player from the server. /// @@ -1151,10 +1166,10 @@ public void IntercomUnmute(bool revokeMute) public void RemoveItem(ItemBase item) => ReferenceHub.inventory.UserInventory.Items.Remove(item.ItemSerial); /// - /// Removes all specific items. + /// Removes a specified number of items of a particular type from the player's inventory. /// - /// The item type. - /// The number of items that will be removed. + /// The type of items to be removed. + /// The number of items to remove (default is 1). public void RemoveItems(ItemType itemType, int number = 1) { int removed = 0; @@ -1202,6 +1217,74 @@ public void RemoveItems(ItemType itemType, int number = 1) /// The amount of ammo which the player has. public ushort GetAmmo(ItemType item) => ReferenceHub.inventory.GetCurAmmo(item); + /// + /// Counts the number of items of a specific type in the player's inventory. + /// + /// The type of item to count. + /// The number of items of the specified type in the inventory. + public int CountItem(ItemType type) => Items.Count(i => i.ItemTypeId == type); + + /// + /// Checks if the player has an item of a specific type in their inventory. + /// + /// The type of item to check for. + /// if the player has an item of the specified type, otherwise . + public bool HasItem(ItemType type) => Items.Any(i => i.ItemTypeId == type); + + /// + /// Attempts to reload the currently held firearm, if applicable. + /// + /// if reloading was successful, otherwise . + public bool ReloadFirearm() + { + if (CurrentItem is Firearm firearm) + { + bool value = firearm.AmmoManagerModule.ServerTryReload(); + Connection.Send(new RequestMessage(firearm.ItemSerial, RequestType.Reload)); + return value; + } + + return false; + } + + /// + /// Attempts to unload the currently held firearm, if applicable. + /// + /// if unloading was successful, otherwise . + public bool UnLoadFirearm() + { + if (CurrentItem is Firearm firearm) + { + bool value = firearm.AmmoManagerModule.ServerTryUnload(); + Connection.Send(new RequestMessage(firearm.ItemSerial, RequestType.Unload)); + return value; + } + + return false; + } + + /// + /// Toggles the flashlight on the player's currently held item, if applicable. + /// + /// + /// if the flashlight state was toggled successfully; otherwise, . + /// + public bool ToggleFlashlight() + { + if (CurrentItem is Firearm firearm) + { + Connection.Send(new RequestMessage(firearm.ItemSerial, RequestType.ToggleFlashlight)); + return true; + } + if (CurrentItem is FlashlightItem item) + { + item.IsEmittingLight = !item.IsEmittingLight; + return true; + } + return false; + } + + /// /// Drops ammo. /// @@ -1237,6 +1320,30 @@ public void ClearInventory(bool clearAmmo = true, bool clearItems = true) } } + /// + /// Resets the player's inventory to contain the specified items. + /// + /// An enumerable collection of item types to add to the player's inventory. + public void ResetInventory(IEnumerable items) + { + ClearInventory(false, true); + + foreach (var item in items) + AddItem(item); + } + + /// + /// Resets the player's ammo to the specified values. + /// + /// A dictionary of item types and their corresponding ammo values to set in the player's inventory. + public void ResetAmmo(Dictionary newAmmovalues) + { + ClearInventory(true, false); + + foreach (var ammo in newAmmovalues) + AddAmmo(ammo.Key, ammo.Value); + } + /// /// Set player /// @@ -1246,12 +1353,50 @@ public void SetGroup(UserGroup group) ReferenceHub.serverRoles.SetGroup(group, false); } + /// + /// Gives the player a specific candy. Will give the player a bag if they do not already have one. + /// + /// The to give. + /// if a candy was given. + public bool TryAddCandy(CandyKindID candy) + { + if(Scp330Bag.TryGetBag(ReferenceHub, out var bag)) + { + bool isAdded = bag.TryAddSpecific(candy); + + if (isAdded) + bag.ServerRefreshBag(); + + return isAdded; + } + else + { + if(AddItem(ItemType.SCP330) is Scp330Bag newBag) + { + newBag.Candies.Clear(); + newBag.TryAddSpecific(candy); + newBag.ServerRefreshBag(); + + return true; + } + + return false; + } + } + /// /// Heals the player. /// /// The amount of health to heal. public void Heal(float amount) => ReferenceHub.playerStats.GetModule().ServerHeal(amount); + /// + /// Provides the player with a health regeneration effect at a specified rate and duration. + /// + /// The rate at which health regeneration occurs. + /// The duration of the health regeneration effect. + public void GiveHealthRegen(float rate, float duration) => Scp330Bag.AddSimpleRegeneration(ReferenceHub, rate, duration); + /// /// Sets the players role. /// @@ -1344,6 +1489,17 @@ public void SetGroup(UserGroup group) /// Whether or not damaging was successful. public bool Damage(DamageHandlerBase damageHandlerBase) => ReferenceHub.playerStats.DealDamage(damageHandlerBase); + /// + /// Explode the player. + /// + public void Explode() => ExplosionUtils.ServerExplode(ReferenceHub); + + /// + /// Triggers an explosion effect at the player's position with an optional explosion type. + /// + /// The type of explosion (default is "GrenadeHE"). + public void ExplodeEffect(ItemType explodeType = ItemType.GrenadeHE) => ExplosionUtils.ServerSpawnEffect(Position, explodeType); + /// public virtual void OnStart() { }