-
Notifications
You must be signed in to change notification settings - Fork 12
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 #118 from Vapok/vapok/r1.7.0
Release of the Adventure Backpacks API
- Loading branch information
Showing
28 changed files
with
913 additions
and
64 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,2 @@ | ||
<wpf:ResourceDictionary xml:space="preserve" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:s="clr-namespace:System;assembly=mscorlib" xmlns:ss="urn:shemas-jetbrains-com:settings-storage-xaml" xmlns:wpf="http://schemas.microsoft.com/winfx/2006/xaml/presentation"> | ||
<s:Boolean x:Key="/Default/UserDictionary/Words/=ABAPI/@EntryIndexedValue">True</s:Boolean></wpf:ResourceDictionary> |
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,142 @@ | ||
using System.Collections.Generic; | ||
using JetBrains.Annotations; | ||
#if ! API | ||
using AdventureBackpacks.Extensions; | ||
using AdventureBackpacks.Features; | ||
#endif | ||
|
||
namespace AdventureBackpacks.API; | ||
|
||
/// <summary> | ||
/// Adventure Backpacks API. Be sure to include the AdventureBackpacksAPI.dll as a dependency to your project. | ||
/// </summary> | ||
[PublicAPI] | ||
// ReSharper disable once InconsistentNaming | ||
public partial class ABAPI | ||
{ | ||
/// <summary> | ||
/// Notifies if the ABAPI is active or not. | ||
/// </summary> | ||
/// <returns>true of false</returns> | ||
public static bool IsLoaded() | ||
{ | ||
#if ! API | ||
return true; | ||
#else | ||
return false; | ||
#endif | ||
} | ||
|
||
/// <summary> | ||
/// When provided with an ItemData object, will detect whether the Item is an Adventure Backpack or not. | ||
/// </summary> | ||
/// <param name="itemData">This is the ItemDrop.ItemData object of the item.</param> | ||
/// <returns>true or false</returns> | ||
public static bool IsBackpack(ItemDrop.ItemData itemData) | ||
{ | ||
#if ! API | ||
return itemData != null && itemData.IsBackpack(); | ||
#else | ||
return false; | ||
#endif | ||
} | ||
|
||
|
||
/// <summary> | ||
/// Determines if the Player provided is currently wearing a backpack. | ||
/// </summary> | ||
/// <param name="player">Player, usually Player.m_localPlayer</param> | ||
/// <returns>true or false</returns> | ||
public static bool IsBackpackEquipped(Player player) | ||
{ | ||
#if ! API | ||
return player != null && player.IsBackpackEquipped(); | ||
#else | ||
return false; | ||
#endif | ||
} | ||
|
||
/// <summary> | ||
/// Determines if the player is capable of currently opening the equipped backpack. | ||
/// </summary> | ||
/// <param name="player">Player, usually Player.m_localPlayer</param> | ||
/// <returns>true or false</returns> | ||
public static bool CanOpenBackpack(Player player) | ||
{ | ||
#if ! API | ||
return player != null && player.CanOpenBackpack(); | ||
#else | ||
return false; | ||
#endif | ||
} | ||
|
||
/// <summary> | ||
/// Determines if the player provided is wearing the item provided and that it's a backpack. | ||
/// </summary> | ||
/// <param name="player">Player, usually Player.m_localPlayer</param> | ||
/// <param name="itemData">Any ItemData</param> | ||
/// <returns>true or false. If item provided is not a backpack, will return false.</returns> | ||
public static bool IsThisBackpackEquipped(Player player, ItemDrop.ItemData itemData) | ||
{ | ||
#if ! API | ||
return player != null && player.IsThisBackpackEquipped(itemData); | ||
#else | ||
return false; | ||
#endif | ||
} | ||
|
||
/// <summary> | ||
/// Returns a Backpack object if the provided Player is currently wearing a backpack. | ||
/// </summary> | ||
/// <param name="player">Player, usually Player.m_localPlayer</param> | ||
/// <returns>Nullable Backpack Object</returns> | ||
public static Backpack? GetEquippedBackpack(Player player) | ||
{ | ||
#if ! API | ||
var backpackComponent = player.GetEquippedBackpack(); | ||
return ConvertBackpackItem(backpackComponent); | ||
#else | ||
return null; | ||
#endif | ||
} | ||
|
||
/// <summary> | ||
/// Returns Backpack object of the provided itemData. Operates similarly to a TryGet but with a nullable type. | ||
/// </summary> | ||
/// <param name="itemData">ItemDrop.ItemData object</param> | ||
/// <returns>Nullable Backpack Object. Check HasValue.</returns> | ||
public static Backpack? GetBackpack(ItemDrop.ItemData itemData) | ||
{ | ||
#if ! API | ||
return ConvertBackpackItem(itemData); | ||
#else | ||
return null; | ||
#endif | ||
} | ||
|
||
/// <summary> | ||
/// Retrieves the current Active Backpack StatusEffects running in the local players game. | ||
/// </summary> | ||
/// <returns>HashSet of Status Effects.</returns> | ||
public static HashSet<StatusEffect> GetActiveBackpackStatusEffects() | ||
{ | ||
#if ! API | ||
return EquipmentEffectCache.ActiveEffects; | ||
#else | ||
return null; | ||
#endif | ||
} | ||
|
||
/// <summary> | ||
/// Method to activate the backpack on the local player's GUI and open it. Use in conjunction with CanOpenBackpack() | ||
/// </summary> | ||
/// <param name="player">Player, usually Player.m_localPlayer</param> | ||
/// <param name="gui">The instance of InventoryGui</param> | ||
public static void OpenBackpack(Player player, InventoryGui gui) | ||
{ | ||
#if ! API | ||
if (player != null) | ||
player.OpenBackpack(gui); | ||
#endif | ||
} | ||
} |
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,72 @@ | ||
#if ! API | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using UnityEngine; | ||
using Vapok.Common.Managers;using AdventureBackpacks.Assets; | ||
using AdventureBackpacks.Assets.Items; | ||
using AdventureBackpacks.Components; | ||
using AdventureBackpacks.Extensions; | ||
|
||
|
||
namespace AdventureBackpacks.API; | ||
|
||
|
||
// ReSharper disable once InconsistentNaming | ||
public partial class ABAPI | ||
{ | ||
private static Backpack? ConvertBackpackItem(BackpackComponent component) | ||
{ | ||
var definition = GetBackPackDefinitionFromComponent(component); | ||
if (!definition.HasValue) | ||
return null; | ||
|
||
var backpackItem = new Backpack | ||
{ | ||
Name = definition.Value.ItemName, | ||
ItemData = component.Item, | ||
Definition = definition.Value, | ||
Inventory = component.GetInventory() | ||
}; | ||
return backpackItem; | ||
} | ||
|
||
private static Backpack? ConvertBackpackItem(ItemDrop.ItemData itemData) | ||
{ | ||
if (!itemData.IsBackpack()) | ||
return null; | ||
|
||
var component = itemData.Data().GetOrCreate<BackpackComponent>(); | ||
return ConvertBackpackItem(component); | ||
} | ||
|
||
private static Dictionary<int, Vector2> GetBackpackSizing(BackpackItem backpack) | ||
{ | ||
return backpack.BackpackSize.ToDictionary(entry => entry.Key, entry => entry.Value.Value); | ||
} | ||
|
||
private static BackpackDefinition? GetBackPackDefinitionFromComponent(BackpackComponent component) | ||
{ | ||
var isBackpack = component.Item.TryGetBackpackItem(out var backpack); | ||
if (isBackpack) | ||
return null; | ||
|
||
return GetBackPackDefinition(backpack); | ||
} | ||
|
||
private static BackpackDefinition GetBackPackDefinition(BackpackItem backpack) | ||
{ | ||
var definition = new BackpackDefinition | ||
{ | ||
ItemName = backpack.ItemName, | ||
PrefabName = backpack.PrefabName, | ||
BackpackSizeByQuality = GetBackpackSizing(backpack), | ||
WeightMultiplier = backpack.WeightMultiplier.Value, | ||
CarryBonus = backpack.CarryBonus.Value, | ||
SpeedMod = backpack.SpeedMod.Value, | ||
EnableFreezing = backpack.EnableFreezing.Value, | ||
BackpackBiome = backpack.BackpackBiome.Value | ||
}; | ||
return definition; | ||
} | ||
} | ||
#endif |
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,145 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using UnityEngine; | ||
|
||
namespace AdventureBackpacks.API; | ||
|
||
/// <summary> | ||
/// This is a Flags enum for determining Backpack Biomes. This is not representative of Heightmap.Biomes. | ||
/// </summary> | ||
[Flags] | ||
public enum BackpackBiomes : uint | ||
{ | ||
/// <summary> | ||
/// None, no backpack effects are applied. | ||
/// </summary> | ||
None = 0, | ||
/// <summary> | ||
/// Meadows Backpack Effects | ||
/// </summary> | ||
Meadows = 1 << 0, | ||
/// <summary> | ||
/// Black Forest Backpack Effects | ||
/// </summary> | ||
BlackForest = 1 << 1, | ||
/// <summary> | ||
/// Swamp Backpack Effects | ||
/// </summary> | ||
Swamp = 1 << 2, | ||
/// <summary> | ||
/// Mountains Backpack Effects | ||
/// </summary> | ||
Mountains = 1 << 3, | ||
/// <summary> | ||
/// Plains Backpack Effects | ||
/// </summary> | ||
Plains = 1 << 4, | ||
/// <summary> | ||
/// Mistlands Backpack Effects | ||
/// </summary> | ||
Mistlands = 1 << 5, | ||
/// <summary> | ||
/// Special Biome configured for Cheb's Necromancy | ||
/// </summary> | ||
Necromancy = 1 << 6 | ||
} | ||
|
||
// ReSharper disable once InconsistentNaming | ||
public partial class ABAPI | ||
{ | ||
/// <summary> | ||
/// Instanced Backpack Information | ||
/// </summary> | ||
public struct Backpack | ||
{ | ||
/// <summary> | ||
/// Backpack Name | ||
/// </summary> | ||
public string Name; | ||
/// <summary> | ||
/// ItemData representative of the Backpack | ||
/// </summary> | ||
public ItemDrop.ItemData ItemData; | ||
/// <summary> | ||
/// Inventory object of the configured backpack | ||
/// </summary> | ||
public Inventory Inventory; | ||
/// <summary> | ||
/// Definition of the Backpack item | ||
/// </summary> | ||
public BackpackDefinition Definition; | ||
} | ||
|
||
/// <summary> | ||
/// Backpack Definition Settings | ||
/// </summary> | ||
public struct BackpackDefinition | ||
{ | ||
/// <summary> | ||
/// Asset Bundle Name | ||
/// </summary> | ||
public string AssetName; | ||
/// <summary> | ||
/// Folder containing the Asset Bundle | ||
/// </summary> | ||
public string AssetFolderName; | ||
/// <summary> | ||
/// Prefab Name of the Backpack Asset | ||
/// </summary> | ||
public string PrefabName; | ||
/// <summary> | ||
/// Item Name of the Backpack. Use the $_name localize token. | ||
/// </summary> | ||
public string ItemName; | ||
/// <summary> | ||
/// Dictionary of Vector2's that contain the x and y sizing of the backpack at each Quality level' | ||
/// Dictionary key is the Item's Quality level. | ||
/// Dictionary value is the Vector2 object. | ||
/// </summary> | ||
public Dictionary<int,Vector2> BackpackSizeByQuality; | ||
/// <summary> | ||
/// Provides the configured weight multiplier that reduces the weight of the items in the backpack. | ||
/// </summary> | ||
public float WeightMultiplier; | ||
/// <summary> | ||
/// Provides the additional carry weight bonus applied to backpacks. | ||
/// </summary> | ||
public int CarryBonus; | ||
/// <summary> | ||
/// Provides the Speed Modification that is applied on the backpack. | ||
/// </summary> | ||
public float SpeedMod; | ||
/// <summary> | ||
/// Provides whether the wearer of the backpack will freeze or not. | ||
/// </summary> | ||
public bool EnableFreezing; | ||
/// <summary> | ||
/// Provides the configured biomes settings applied to the backpack. | ||
/// </summary> | ||
public BackpackBiomes BackpackBiome; | ||
|
||
} | ||
|
||
/// <summary> | ||
/// Configuration of Drop Target | ||
/// </summary> | ||
public struct DropTarget | ||
{ | ||
/// <summary> | ||
/// Prefab name of creature | ||
/// </summary> | ||
public string Creature; | ||
/// <summary> | ||
/// Min number of items that can drop. | ||
/// </summary> | ||
public int Min; | ||
/// <summary> | ||
/// Maximum number of items that can drop. | ||
/// </summary> | ||
public int Max; | ||
/// <summary> | ||
/// Configured Drop Chance | ||
/// </summary> | ||
public float Chance; | ||
} | ||
} |
Oops, something went wrong.