Skip to content

Commit

Permalink
Merge pull request #38 from Vapok/vapok/r1.5.8
Browse files Browse the repository at this point in the history
Release 1.5.8
  • Loading branch information
Vapok authored Feb 4, 2023
2 parents dfbcb7c + c4b5735 commit c0e821d
Show file tree
Hide file tree
Showing 31 changed files with 465 additions and 303 deletions.
18 changes: 15 additions & 3 deletions AdventureBackpacks/AdventureBackpacks.cs
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ public class AdventureBackpacks : BaseUnityPlugin, IPluginInfo
//Module Constants
private const string _pluginId = "vapok.mods.adventurebackpacks";
private const string _displayName = "AdventureBackpacks";
private const string _version = "1.5.7";
private const string _version = "1.5.8";

//Interface Properties
public string PluginId => _pluginId;
Expand All @@ -44,6 +44,7 @@ public class AdventureBackpacks : BaseUnityPlugin, IPluginInfo
//Class Properties
public static ILogIt Log => _log;
public static bool ValheimAwake = false;
public static bool PerformYardSale = false;
public static Waiting Waiter;

//Class Privates
Expand Down Expand Up @@ -89,6 +90,13 @@ private void Update()
if (!Player.m_localPlayer || !ZNetScene.instance)
return;

if (PerformYardSale)
{
var backpack = Player.m_localPlayer.GetEquippedBackpack();
if (backpack != null)
Backpacks.PerformYardSale(Player.m_localPlayer, backpack.Item);
}

if (!KeyPressTool.IgnoreKeyPresses(true) && KeyPressTool.CheckKeyDown(ConfigRegistry.HotKeyOpen.Value) && Player.m_localPlayer.CanOpenBackpack())
{
Player.m_localPlayer.OpenBackpack();
Expand All @@ -106,11 +114,15 @@ public void InitializeBackpacks(object send, EventArgs args)
if (ValheimAwake)
return;

//Load Assets
//Register Effects
var effectsFactory = new EffectsFactory(_log, _config);
effectsFactory.RegisterEffects();

//Register Assets
var backpackFactory = new BackpackFactory(_log, _config);
backpackFactory.CreateAssets();

//Setup Types
//Setup Backpack Types
Backpacks.LoadBackpackTypes(BackpackFactory.BackpackTypes());

//Enable BoneReorder
Expand Down
5 changes: 5 additions & 0 deletions AdventureBackpacks/AdventureBackpacks.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -80,10 +80,15 @@
<Compile Include="Assets\Effects\BackpackEffects.cs" />
<Compile Include="Assets\Effects\ColdResistance.cs" />
<Compile Include="Assets\Effects\Demister.cs" />
<Compile Include="Assets\Effects\EffectsBase.cs" />
<Compile Include="Assets\Effects\FeatherFall.cs" />
<Compile Include="Assets\Effects\FrostResistance.cs" />
<Compile Include="Assets\Effects\TrollArmor.cs" />
<Compile Include="Assets\Effects\Waterproof.cs" />
<Compile Include="Assets\Factories\AssetFactory.cs" />
<Compile Include="Assets\Factories\BackpackFactory.cs" />
<Compile Include="Assets\Factories\EffectsFactory.cs" />
<Compile Include="Assets\Factories\FactoryBase.cs" />
<Compile Include="Assets\Items\AssetItem.cs" />
<Compile Include="Assets\Items\BackpackItem.cs" />
<Compile Include="Assets\Items\BackpackItems\BackpackBlackForest.cs" />
Expand Down
90 changes: 87 additions & 3 deletions AdventureBackpacks/Assets/Backpacks.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
using System;
using System.Collections.Generic;
using System.Linq;
using AdventureBackpacks.Assets.Effects;
using AdventureBackpacks.Assets.Factories;
using AdventureBackpacks.Assets.Items;
using AdventureBackpacks.Components;
Expand Down Expand Up @@ -108,18 +109,83 @@ public static bool CheckForInception(Inventory instance, ItemDrop.ItemData item)
if (instance.IsBackPackInventory() && Player.m_localPlayer != null)
{
// If the item is a backpack...
if (item.IsBackpack())
if (item.TryGetBackpackItem(out var backpack))
{
Player.m_localPlayer.Message(MessageHud.MessageType.Center, "$vapok_mod_no_inception");
backpack.InceptionCounter++;

switch (backpack.InceptionCounter)
{
case 1:
Player.m_localPlayer.Message(MessageHud.MessageType.Center, "$vapok_mod_no_inception1");
break;
case 2:
Player.m_localPlayer.Message(MessageHud.MessageType.Center, "$vapok_mod_no_inception2");
break;
case 5:
Player.m_localPlayer.Message(MessageHud.MessageType.Center, "$vapok_mod_no_inception3");
break;
case 10:
Player.m_localPlayer.Message(MessageHud.MessageType.Center, "$vapok_mod_no_inception4");

var interval = new Random(42);
var timeInterval = interval.Next(5000,20000);
backpack.YardSaleTimer = new System.Timers.Timer(timeInterval);
backpack.YardSaleTimer.AutoReset = false;
backpack.YardSaleTimer.Enabled = false;
backpack.YardSaleTimer.Elapsed += (sender,e) => YardSaleEvent(backpack);
backpack.YardSaleTimer.Start();
break;
}

// Nope!
AdventureBackpacks.Log.Message("Odin says, 'You can't put a backpack inside a backpack!'");
return false;
}
}
return true;
}

public static void PerformYardSale(Player mLocalPlayer, ItemDrop.ItemData itemData)
{
if (itemData.IsBackpack())
{
var backpack = itemData.Data().Get<BackpackComponent>();
if (backpack != null)
{

void EmtpyInventory(Inventory inventory)
{
var inventoryCount = inventory.m_inventory.Count;

while (inventory.m_inventory.Count > 0)
{
var item = inventory.m_inventory[0];

var amount = inventory.CountItems(item.m_shared.m_name, -1);

mLocalPlayer.DropItem(inventory,item,amount);
}
}
var inventory = backpack.GetInventory();
var playerInventory = mLocalPlayer.GetInventory();

EmtpyInventory(inventory);
EmtpyInventory(playerInventory);

mLocalPlayer.UnequipAllItems();

EmtpyInventory(playerInventory);
}
}
Player.m_localPlayer.Message(MessageHud.MessageType.Center, "$vapok_mod_no_inception5");
AdventureBackpacks.PerformYardSale = false;
}

private static void YardSaleEvent(BackpackItem backpack)
{
backpack.YardSaleTimer.Stop();
AdventureBackpacks.PerformYardSale = true;
}

public static CustomSE UpdateStatusEffects(ItemDrop.ItemData itemData)
{
if (itemData == null)
Expand All @@ -140,6 +206,24 @@ public static CustomSE UpdateStatusEffects(ItemDrop.ItemData itemData)
if (!itemData.TryGetBackpackItem(out var backpack))
return null;

//Apply Frost Resistance if configured.
if (FrostResistance.ShouldHaveFrostResistance(itemData))
modifierList.Add(BackpackEffects.FrostResistance);

//Apply Troll Armor Set if configured.
if (TrollArmor.ShouldHaveTrollArmorSet(itemData))
{
itemData.m_shared.m_setName = "troll";
itemData.m_shared.m_setSize = 4;
itemData.m_shared.m_setStatusEffect = ObjectDB.instance.GetStatusEffect("SetEffect_TrollArmor");
}
else
{
itemData.m_shared.m_setName = string.Empty;
itemData.m_shared.m_setSize = 0;
itemData.m_shared.m_setStatusEffect = null;
}

backpack.UpdateStatusEffects(backpackQuality, statusEffects, modifierList, itemData);

itemData.m_shared.m_maxDurability = 1000f;
Expand Down
62 changes: 7 additions & 55 deletions AdventureBackpacks/Assets/Effects/ColdResistance.cs
Original file line number Diff line number Diff line change
@@ -1,70 +1,24 @@
using System;
using System.Collections.Generic;
using AdventureBackpacks.Assets.Factories;
using AdventureBackpacks.Configuration;
using AdventureBackpacks.Assets.Factories;
using AdventureBackpacks.Extensions;
using BepInEx.Configuration;
using HarmonyLib;
using JetBrains.Annotations;
using Vapok.Common.Managers.Configuration;
using Vapok.Common.Shared;

namespace AdventureBackpacks.Assets.Effects;

public static class ColdResistance
public class ColdResistance : EffectsBase
{
public static class Configuration
public ColdResistance(string effectName, string effectDesc) : base(effectName, effectDesc)
{
public static ConfigEntry<bool> EnabledEffect { get; private set;}
public static Dictionary<BackpackBiomes,ConfigEntry<int>> BiomeQualityLevels { get; private set;}

public static string _configSection = $"Effect: Cold Resistance";

public static void RegisterEffectConfiguration()
{
BiomeQualityLevels = new();

EnabledEffect = ConfigSyncBase.SyncedConfig(_configSection, "Effect Enabled", true,
new ConfigDescription("Enables the effect.",
null, // range between 0f and 1f will make it display as a percentage slider
new ConfigurationManagerAttributes { Order = 1 }));

//Waiting For Startup
ConfigRegistry.Waiter.StatusChanged += FillBiomeSettings;
}

private static void FillBiomeSettings(object sender, EventArgs e)
{
foreach (BackpackBiomes backpackBiome in Enum.GetValues(typeof(BackpackBiomes)))
{
RegisterEffectBiomeQuality(backpackBiome);
}
}

public static void RegisterEffectBiomeQuality(BackpackBiomes biome, int defaultQuality = 0)
{
if (biome == BackpackBiomes.None)
return;

var qualityLevel = ConfigSyncBase.SyncedConfig(_configSection, $"Effective Quality Level: {biome.ToString()}", defaultQuality,
new ConfigDescription("Quality Level needed to apply effect to backpack. Zero disables effect for Biome.",
new AcceptableValueRange<int>(0, 5),
new ConfigurationManagerAttributes { Order = 2 }));

if (!BiomeQualityLevels.ContainsKey(biome))
{
BiomeQualityLevels.Add(biome, qualityLevel);
}
}
}

public static bool ShouldHaveColdResistance(Humanoid human)
{
var effect = EffectsFactory.EffectList[BackpackEffect.ColdResistance];
if (human is Player player)
{
var equippedBackpack = player.GetEquippedBackpack();

if (equippedBackpack == null || !Configuration.EnabledEffect.Value)
if (equippedBackpack == null || !effect.EnabledEffect.Value)
return false;

var itemData = equippedBackpack.Item;
Expand All @@ -73,9 +27,9 @@ public static bool ShouldHaveColdResistance(Humanoid human)

var backpackBiome = backpack.BackpackBiome.Value;

if (Configuration.BiomeQualityLevels.ContainsKey(backpackBiome))
if (effect.BiomeQualityLevels.ContainsKey(backpackBiome))
{
var configQualityForBiome = Configuration.BiomeQualityLevels[backpackBiome].Value;
var configQualityForBiome = effect.BiomeQualityLevels[backpackBiome].Value;

if (configQualityForBiome == 0 || backpackBiome == BackpackBiomes.None)
return false;
Expand All @@ -86,8 +40,6 @@ public static bool ShouldHaveColdResistance(Humanoid human)

return false;
}



[HarmonyPatch(typeof(EnvMan), nameof(EnvMan.IsCold))]
public static class UpdateStatusEffects
Expand Down
60 changes: 7 additions & 53 deletions AdventureBackpacks/Assets/Effects/Demister.cs
Original file line number Diff line number Diff line change
@@ -1,70 +1,24 @@
using System;
using System.Collections.Generic;
using AdventureBackpacks.Assets.Factories;
using AdventureBackpacks.Configuration;
using AdventureBackpacks.Assets.Factories;
using AdventureBackpacks.Extensions;
using BepInEx.Configuration;
using HarmonyLib;
using JetBrains.Annotations;
using Vapok.Common.Managers.Configuration;
using Vapok.Common.Shared;

namespace AdventureBackpacks.Assets.Effects;

public static class Demister
public class Demister: EffectsBase
{
public static class Configuration
public Demister(string effectName, string effectDesc) : base(effectName, effectDesc)
{
public static ConfigEntry<bool> EnabledEffect { get; private set;}
public static Dictionary<BackpackBiomes,ConfigEntry<int>> BiomeQualityLevels { get; private set;}

public static string _configSection = $"Effect: Demister";

public static void RegisterEffectConfiguration()
{
BiomeQualityLevels = new();

EnabledEffect = ConfigSyncBase.SyncedConfig(_configSection, "Effect Enabled", true,
new ConfigDescription("Enables the effect.",
null, // range between 0f and 1f will make it display as a percentage slider
new ConfigurationManagerAttributes { Order = 1 }));

//Waiting For Startup
ConfigRegistry.Waiter.StatusChanged += FillBiomeSettings;
}

private static void FillBiomeSettings(object sender, EventArgs e)
{
foreach (BackpackBiomes backpackBiome in Enum.GetValues(typeof(BackpackBiomes)))
{
RegisterEffectBiomeQuality(backpackBiome);
}
}

public static void RegisterEffectBiomeQuality(BackpackBiomes biome, int defaultQuality = 0)
{
if (biome == BackpackBiomes.None)
return;

var qualityLevel = ConfigSyncBase.SyncedConfig(_configSection, $"Effective Quality Level: {biome.ToString()}", defaultQuality,
new ConfigDescription("Quality Level needed to apply effect to backpack. Zero disables effect for Biome.",
new AcceptableValueRange<int>(0, 5),
new ConfigurationManagerAttributes { Order = 2 }));

if (!BiomeQualityLevels.ContainsKey(biome))
{
BiomeQualityLevels.Add(biome, qualityLevel);
}
}
}

public static bool ShouldHaveDemister(Humanoid human)
{
var effect = EffectsFactory.EffectList[BackpackEffect.Demister];
if (human is Player player)
{
var equippedBackpack = player.GetEquippedBackpack();

if (equippedBackpack == null || !Configuration.EnabledEffect.Value)
if (equippedBackpack == null || !effect.EnabledEffect.Value)
return false;

var itemData = equippedBackpack.Item;
Expand All @@ -73,9 +27,9 @@ public static bool ShouldHaveDemister(Humanoid human)

var backpackBiome = backpack.BackpackBiome.Value;

if (Configuration.BiomeQualityLevels.ContainsKey(backpackBiome))
if (effect.BiomeQualityLevels.ContainsKey(backpackBiome))
{
var configQualityForBiome = Configuration.BiomeQualityLevels[backpackBiome].Value;
var configQualityForBiome = effect.BiomeQualityLevels[backpackBiome].Value;

if (configQualityForBiome == 0 || backpackBiome == BackpackBiomes.None)
return false;
Expand Down
Loading

0 comments on commit c0e821d

Please sign in to comment.