Skip to content

Commit

Permalink
Merge pull request #120 from Vapok/vapok/r1.7.1
Browse files Browse the repository at this point in the history
Release 1.7.1 - Valheim 0.217.28
  • Loading branch information
Vapok authored Nov 3, 2023
2 parents cbc48d1 + 7a1f299 commit a892603
Show file tree
Hide file tree
Showing 38 changed files with 1,283 additions and 258 deletions.
36 changes: 36 additions & 0 deletions AdventureBackpacks/API/ABAPI.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
using System.Collections.Generic;
using JetBrains.Annotations;
#if ! API
using AdventureBackpacks.Assets.Factories;
using AdventureBackpacks.Extensions;
using AdventureBackpacks.Features;
#endif
Expand Down Expand Up @@ -127,6 +128,19 @@ public static HashSet<StatusEffect> GetActiveBackpackStatusEffects()
#endif
}

/// <summary>
/// Retrieves all Status Effects Registered with Adventure Backpacks
/// </summary>
/// <returns>HashSet of Status Effects.</returns>
public static HashSet<StatusEffect> GetRegisterdStatusEffects()
{
#if ! API
return EffectsFactory.GetRegisteredEffects();
#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>
Expand All @@ -137,6 +151,28 @@ public static void OpenBackpack(Player player, InventoryGui gui)
#if ! API
if (player != null)
player.OpenBackpack(gui);
#endif
}

/// <summary>
/// Use this method in the Awake() of your mod to register a Status Effect that can be utilized on Adventure Backpacks
/// </summary>
/// <param name="effectDefinition">Create a new EffectDefinition that contains the overall parameters that are needed to register the new effect.</param>
public static void RegisterEffect(EffectDefinition effectDefinition)
{
#if ! API
EffectsFactory.RegisterExternalEffect(effectDefinition);
#endif
}

/// <summary>
/// Use this method in the Awake() of your mod to register a new Backpack that can be utilized on Adventure Backpacks.
/// </summary>
/// <param name="definition">Create a new BackpackDefinition that contains the overall parameters that are needed to register the new backpack.</param>
public static void RegisterBackpack(BackpackDefinition definition)
{
#if ! API
BackpackFactory.RegisterExternalBackpack(definition);
#endif
}
}
8 changes: 4 additions & 4 deletions AdventureBackpacks/API/Privates.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,14 @@ public partial class ABAPI
private static Backpack? ConvertBackpackItem(BackpackComponent component)
{
var definition = GetBackPackDefinitionFromComponent(component);
if (!definition.HasValue)
if (definition == null)
return null;

var backpackItem = new Backpack
{
Name = definition.Value.ItemName,
Name = definition.ItemName,
ItemData = component.Item,
Definition = definition.Value,
Definition = definition,
Inventory = component.GetInventory()
};
return backpackItem;
Expand All @@ -44,7 +44,7 @@ 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)
private static BackpackDefinition GetBackPackDefinitionFromComponent(BackpackComponent component)
{
var isBackpack = component.Item.TryGetBackpackItem(out var backpack);
if (isBackpack)
Expand Down
232 changes: 222 additions & 10 deletions AdventureBackpacks/API/Structs.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ namespace AdventureBackpacks.API;

/// <summary>
/// This is a Flags enum for determining Backpack Biomes. This is not representative of Heightmap.Biomes.
/// This is instead a way of creating sets of Effects. Default Adventure Backpacks will utilize Biome names.
/// Custom External Effects can pick and choose between the Custom Effect flags as well.
/// </summary>
[Flags]
public enum BackpackBiomes : uint
Expand Down Expand Up @@ -39,9 +41,33 @@ public enum BackpackBiomes : uint
/// </summary>
Mistlands = 1 << 5,
/// <summary>
/// Special Biome configured for Cheb's Necromancy
/// Ashland Backpack Effects
/// </summary>
Necromancy = 1 << 6
Ashlands = 1 << 6,
/// <summary>
/// DeepNorth Backpack Effects
/// </summary>
DeepNorth = 1 << 7,
/// <summary>
/// Custom Biome for use with External Effects
/// </summary>
EffectBiome1 = 1 << 20,
/// <summary>
/// Custom Biome for use with External Effects
/// </summary>
EffectBiome2 = 1 << 21,
/// <summary>
/// Custom Biome for use with External Effects
/// </summary>
EffectBiome3 = 1 << 22,
/// <summary>
/// Custom Biome for use with External Effects
/// </summary>
EffectBiome4 = 1 << 23,
/// <summary>
/// Custom Biome for use with External Effects
/// </summary>
EffectBiome5 = 1 << 24,
}

// ReSharper disable once InconsistentNaming
Expand Down Expand Up @@ -72,41 +98,102 @@ public struct Backpack

/// <summary>
/// Backpack Definition Settings
/// Use this object to create backpack definitions for adding Backpacks to Adventure Backpacks.
/// You can use either the GameObject directly, or provide your AssetBundle object and the PrefabName.
/// </summary>
public struct BackpackDefinition
public class BackpackDefinition
{
/// <summary>
/// Asset Bundle Name
/// Backpack GameObject
/// (Not required if AssetBundle and Prefab Name are provided)
/// </summary>
public string AssetName;
public GameObject BackPackGo;
/// <summary>
/// Folder containing the Asset Bundle
/// Asset Bundle containing the Backpack
/// (Not required if GameObject is provided)
/// </summary>
public string AssetFolderName;
public AssetBundle AssetBundle;
/// <summary>
/// Prefab Name of the Backpack Asset
/// (Not required if GameObject is provided)
/// </summary>
public string PrefabName;
/// <summary>
/// Item Name of the Backpack. Use the $_name localize token.
/// (e.g. $vapok_mod_rugged_backpack)
/// </summary>
public string ItemName;
/// <summary>
/// Custom Configuration Section Name in Adventure Backpacks.
/// If left empty, will use default section name.
/// (e.g. Backpack: {$backpack_itemname} )
/// </summary>
public string ConfigSection = "";
/// <summary>
/// Name of Crafting Table that the Backpack can be crafted at.
/// If left empty, will disable crafting at any table.
/// Can also include custom table names.
/// (e.g. piece_workbench, forge, piece_stonecutter)
/// </summary>
public string CraftingTable;
/// <summary>
/// Minimum Level of Crafting Table Station before Bag can be crafted
/// (e.g. 1, 2, etc.)
/// </summary>
public int StationLevel;
/// <summary>
/// Max Crafting Station Level to upgrade, and repair.
/// (e.g. 1, 2, etc.)
/// </summary>
public int MaxRequiredStationLevel;
/// <summary>
/// List of Recipe Ingredients.
/// </summary>
public readonly List<RecipeIngredient> RecipeIngredients = new ();
/// <summary>
/// List of Ingredients for Upgrading.
/// </summary>
public readonly List<RecipeIngredient> UpgradeIngredients = new ();
/// <summary>
/// List of Ingredients for Upgrading.
/// </summary>
public readonly List<DropTarget> DropsFrom = new ();
/// <summary>
/// Dictionary of StatusEffect's to apply to the backpack when equipped.
/// Dictionary Key is the BackpackBiome that needs to be applied to the Backpack for Effect to be activated.
/// Dictionary Value is a Key Value Pair of a Status Effect to apply:
/// Key of the KVP is the actual Status Effect
/// Value of the KVP is the default int Quality level that of the backpack before the effect is applied.
/// (examples of the quality level: 1 - 4)
/// Use GetRegisteredStatusEffects() to determine which status effect Adventure Backpacks is aware of.
/// Use RegisterEffect() first to register new status effects.
/// </summary>
public readonly Dictionary<BackpackBiomes,KeyValuePair<StatusEffect,int>> EffectsToApply = new ();
/// <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;
public Dictionary<int,Vector2> BackpackSizeByQuality = new ();
/// <summary>
/// When backpack is equipped, set what the Set Effect Status Effect Should.
/// If left empty, none will be equipped.
/// Note: Be sure this is one of the effects included in EffectsToApply.
/// </summary>
public StatusEffect ItemSetStatusEffect;
/// <summary>
/// Provides the configured weight multiplier that reduces the weight of the items in the backpack.
/// For registering a new backpack, this is the default value.
/// </summary>
public float WeightMultiplier;
/// <summary>
/// Provides the additional carry weight bonus applied to backpacks.
/// For registering a new backpack, this is the default value.
/// </summary>
public int CarryBonus;
/// <summary>
/// Provides the Speed Modification that is applied on the backpack.
/// For registering a new backpack, this is the default value.
/// </summary>
public float SpeedMod;
/// <summary>
Expand All @@ -115,8 +202,44 @@ public struct BackpackDefinition
public bool EnableFreezing;
/// <summary>
/// Provides the configured biomes settings applied to the backpack.
/// This is flag enum.
/// (e.g. "BackpackBiomes.Meadows" or "BackpackBiomes.Meadows | BackpackBiomes.BlackForest" to select multiple biomes.
/// </summary>
public BackpackBiomes BackpackBiome;

/// <summary>
/// Default Constructor
/// </summary>
public BackpackDefinition()
{

}

/// <summary>
/// Use this constructor when adding a backpack using the GameObject
/// The item should have ItemDrop.ItemData on the item, and it should be an item that is utilizing the Shoulder slot.
/// Equipped Detection won't detect if not in the shoulder slot.
/// TODO: Make this more flexible for additional slots through AzuEPI
/// </summary>
/// <param name="backPackGo">GameObject of </param>
public BackpackDefinition(GameObject backPackGo)
{
BackPackGo = backPackGo;
}

/// <summary>
/// Use this constructor when adding a backpack using the AssetBundle and Prefab Name
/// The item should have ItemDrop.ItemData on the item, and it should be an item that is utilizing the Shoulder slot.
/// Equipped Detection won't detect if not in the shoulder slot.
/// TODO: Make this more flexible for additional slots through AzuEPI
/// </summary>
/// <param name="assetBundle">Provide the Asset Bundle that contains the backpack prefab</param>
/// <param name="prefabName">Prefab name of the backpack</param>
public BackpackDefinition(AssetBundle assetBundle, string prefabName)
{
AssetBundle = assetBundle;
PrefabName = prefabName;
}

}

Expand All @@ -136,10 +259,99 @@ public struct DropTarget
/// <summary>
/// Maximum number of items that can drop.
/// </summary>
public int Max;
public int? Max;
/// <summary>
/// Configured Drop Chance
/// </summary>
public float Chance;
}

/// <summary>
/// Drop Target Constructor
/// </summary>
/// <param name="creature">Prefab name of Creature</param>
/// <param name="chance">Chance to Drop Float</param>
/// <param name="min">Minimum amount to drop.</param>
/// <param name="max">Max amount to drop.</param>
public DropTarget(string creature, float chance, int min = 1, int? max = null)
{
Creature = creature;
Chance = chance;
Min = min;
Max = max;
}
}

/// <summary>
/// Create anew EffectDefinition in order to register status effects.
/// </summary>
public struct EffectDefinition
{
/// <summary>
/// This is the Effect Name.
/// (e.g. "$some_effect_name").
/// </summary>
public readonly string Name;
/// <summary>
/// This is the Localized Translated Effect Name.
/// This is used in places like the Configuration and in the HUD/GUI
/// (e.g. "Water Resistance").
/// </summary>
public readonly string LocalizedName;
/// <summary>
/// This is the registered Effect name
/// (e.g. SetEffect_NecromancyArmor or SE_Demister)
/// </summary>
public readonly string EffectName;
/// <summary>
/// Description of the Status Effect. Shows up in Configuration.
/// </summary>
public readonly string Description;
/// <summary>
/// This is your actual Status Effect from your own asset bundle or from another source.
/// As long as it's of the type SE_Stats, you can use it.
/// </summary>
public readonly StatusEffect StatusEffect;

/// <summary>
/// Create anew EffectDefinition in order to register status effects.
/// </summary>
/// <param name="name"></param>
/// <param name="localizedName"></param>
/// <param name="effectName"></param>
/// <param name="description"></param>
/// <param name="statusEffect"></param>
public EffectDefinition(string name, string localizedName, string effectName, string description, StatusEffect statusEffect)
{
Name = name;
LocalizedName = localizedName;
EffectName = effectName;
Description = description;
StatusEffect = statusEffect;
}
}
/// <summary>
/// Defines a Recipe Ingredient
/// </summary>
public struct RecipeIngredient
{
/// <summary>
/// Prefab Name of Item to include as a recipe ingredient
/// </summary>
public string ItemPrefabName;
/// <summary>
/// Amount of Item required.
/// </summary>
public int Quantity;

/// <summary>
/// Create Ingredient Object
/// </summary>
/// <param name="itemPrefabName">Item Prefab Name</param>
/// <param name="quantity">Amount of item to consume.</param>
public RecipeIngredient(string itemPrefabName, int quantity)
{
ItemPrefabName = itemPrefabName;
Quantity = quantity;
}
}
}
Loading

0 comments on commit a892603

Please sign in to comment.