Skip to content

Commit

Permalink
Merge branch 'development' into sleep_without_spawn
Browse files Browse the repository at this point in the history
  • Loading branch information
DANTHEEMAN90 committed Apr 12, 2021
2 parents 29a8ff7 + f3cd40c commit e3aada9
Show file tree
Hide file tree
Showing 36 changed files with 1,211 additions and 466 deletions.
11 changes: 9 additions & 2 deletions CONTRIBUTING.md
Expand Up @@ -56,14 +56,16 @@ Thanks to mono and unity-mono being open source, we patched and compiled our own
- It is recommended when testing to test value inline with your code instead of altering the values on the .cfg/class to prevent this issue. If an inline hardcoded value gets pushed, it's easier to spot this mistake than a inaccurate cfg setting.
1. Try to find an appropriate existing configuration section before adding a new one. Generally, if your configuration changes something related to the player, for example, then add it to the `[Player]` section. Look at it from the perspective of a user who's looking for a specific configuration instead of the perspective of someone who's coding and looking for a class.
1. Add any new configuration Sections (`[Section]`) to the bottom of the .cfg file so that we're less likely to break existing config.
3. Check out our helpers in the /Utilities/ folder and use them where appropriate
4. For configuration modifiers that add a modifcation to the base value, always use a percentage configuration and use the `applyModifier()` utility.
1. Check out our helpers in the /Utilities/ folder and use them where appropriate
1. For configuration modifiers that add a modifcation to the base value, always use a percentage configuration and use the `applyModifier()` utility.
1. For configuration modifier values make sure to add `"modifier": "true"` as entry stat to the vplusconfig.json.

## Making a Pull Request
1. Only make a pull request for finished work. Otherwise, if we pull the work down to test it and it doesn't work, we don't know if it's because it's unfinished or if there's an unintentional bug.
- If you'd like a review on your work before something it's finished, send us a link to a compare via Discord or make a "Draft" PR.
1. If you want credit, add your credit to the `README.md` in your pull request if the work is more than a documentation update. We will not be able to track this ourselves and rely on you to add your preferred way of being credited.
1. After you have made a GitHub contribution, reach out to one of the V+ devs on Discord if you'd like the "GitHub contributor" role.
2. Make sure that if your pull requests takes care of a suggestion from our website at https://valheim.plus/todo that you also remove it from the `vplusSuggestions/todo.json`

## Pull Request labels
1. pending merge - This work has been reviewed and accepted and will be merged after the coming release
Expand All @@ -72,3 +74,8 @@ Thanks to mono and unity-mono being open source, we patched and compiled our own
1. merge conflicts - This pr has merge conflicts that need to be resolved
1. question - The author of the PR needs to answer a question before the PR can move forward
1. in discussion - We want to implement the PR but have to make more preparations and tests before we can do so.

## Files
1. valheim_plus.cfg - the file responsible for loading the configuration on game start.
2. vplusconfig.json - the file responsible to generate the website documentation that can be found here https://valheim.plus/documentation
3. vplusSuggestions/todo.json - the file responsible to generate the website page https://valheim.plus/todo
367 changes: 264 additions & 103 deletions README.bbcode

Large diffs are not rendered by default.

215 changes: 112 additions & 103 deletions README.md

Large diffs are not rendered by default.

Binary file added ValheimPlus/Assets/Bundles/map-pin-ui
Binary file not shown.
1 change: 1 addition & 0 deletions ValheimPlus/Configurations/Configuration.cs
Expand Up @@ -50,5 +50,6 @@ public class Configuration
public PlayerProjectileConfiguration PlayerProjectile { get; set; }
public MonsterProjectileConfiguration MonsterProjectile { get; set; }
public GameClockConfiguration GameClock { get; set; }
public BrightnessConfiguration Brightness { get; set; }
}
}
46 changes: 44 additions & 2 deletions ValheimPlus/Configurations/ConfigurationExtra.cs
Expand Up @@ -4,6 +4,7 @@
using System;
using System.Globalization;
using System.IO;
using System.Net;
using System.Linq;
using System.Reflection;
using UnityEngine;
Expand Down Expand Up @@ -39,11 +40,52 @@ public static bool LoadSettings()
try
{
if (File.Exists(ConfigIniPath))
{
FileIniDataParser parser = new FileIniDataParser();
IniData configdata = parser.ReadFile(ConfigIniPath);

string compareIni = null;
try
{
// get the current versions ini data
compareIni = ValheimPlusPlugin.getCurrentWebIniFile();
}
catch (Exception e) { }

if (compareIni != null)
{
StreamReader reader = new StreamReader(new MemoryStream(System.Text.Encoding.ASCII.GetBytes(compareIni)));
IniData webConfig = parser.ReadData(reader);

// Duplication of comments otherwise with this merge function.
configdata.ClearAllComments();

webConfig.Merge(configdata);
parser.WriteFile(ConfigIniPath, webConfig);
}

Configuration.Current = LoadFromIni(ConfigIniPath);
}
else
{
Debug.LogError("Error: Configuration not found. Plugin not loaded.");
return false;
Debug.LogError("Error: Configuration not found. Trying to download latest config.");

// download latest ini if not present
bool status = false;
try
{
string defaultIni = ValheimPlusPlugin.getCurrentWebIniFile();
if(defaultIni != null)
{
System.IO.File.WriteAllText(ConfigIniPath, defaultIni);
Debug.Log("Default Configuration downloaded. Loading downloaded default settings.");
Configuration.Current = LoadFromIni(ConfigIniPath);
status = true;
}
}
catch (Exception e) { }

return status;
}
}
catch (Exception ex)
Expand Down
12 changes: 12 additions & 0 deletions ValheimPlus/Configurations/Sections/BrightnessConfiguration.cs
@@ -0,0 +1,12 @@
namespace ValheimPlus.Configurations.Sections
{
public class BrightnessConfiguration : BaseConfig<BrightnessConfiguration>
{
/* changing brightness during a period of day had a coupling affect with other period, need further development
public float morningBrightnessMultiplier { get; set; } = 0f;
public float dayBrightnessMultiplier { get; set; } = 0f;
public float eveningBrightnessMultiplier { get; set; } = 0f;
*/
public float nightBrightnessMultiplier { get; set; } = 0f;
}
}
Expand Up @@ -5,7 +5,7 @@ public class CraftFromChestConfiguration : ServerSyncConfig<CraftFromChestConfig
public float range { get; internal set; } = 20;
public bool disableCookingStation { get; internal set; } = false;
public bool checkFromWorkbench { get; internal set; } = true;
public bool ignorePrivateAreaCheck { get; internal set; } = true;
public bool ignorePrivateAreaCheck { get; internal set; } = false;
public int lookupInterval { get; internal set; } = 3;
}
}
1 change: 1 addition & 0 deletions ValheimPlus/Configurations/Sections/GameConfiguration.cs
Expand Up @@ -10,5 +10,6 @@ public class GameConfiguration : ServerSyncConfig<GameConfiguration>
public bool disablePortals { get; internal set; } = false;
public bool forceConsole { get; internal set; } = false;
public bool bigPortalNames { get; internal set; } = false;
public bool disableFog { get; internal set; } = false;
}
}
2 changes: 1 addition & 1 deletion ValheimPlus/Configurations/Sections/HudConfiguration.cs
Expand Up @@ -4,8 +4,8 @@ public class HudConfiguration : BaseConfig<HudConfiguration>
{
public bool showRequiredItems { get; internal set; } = false;
public bool experienceGainedNotifications { get; internal set; } = false;
public float chatMessageDistance { get; internal set; }
public bool displayStaminaValue { get; internal set; } = false;
public bool removeDamageFlash { get; internal set; } = false;
public int displayBowAmmoCounts { get; internal set; } = 0;
}
}
2 changes: 2 additions & 0 deletions ValheimPlus/Configurations/Sections/MapConfiguration.cs
Expand Up @@ -5,5 +5,7 @@ public class MapConfiguration : BaseConfig<MapConfiguration>
public bool shareMapProgression { get; internal set; } = false;
public float exploreRadius { get; internal set; } = 100;
public bool preventPlayerFromTurningOffPublicPosition { get; internal set; } = false;
//public bool useImprovedPinEditorUI { get; internal set; } = false;
public bool shareablePins { get; internal set; } = false;
}
}
Expand Up @@ -2,7 +2,7 @@
{
public class SpinningWheelConfiguration : ServerSyncConfig<SpinningWheelConfiguration>
{
public int maximumFlax { get; internal set; } = 40;
public int maximumFlax { get; internal set; } = 50;
public float productionSpeed { get; internal set; } = 30;
public bool autoDeposit { get; internal set; } = true;
public bool autoFuel { get; internal set; } = true;
Expand Down
Expand Up @@ -8,7 +8,7 @@ namespace ValheimPlus.Configurations.Sections
public class TameableConfiguration : ServerSyncConfig<TameableConfiguration>
{
public int mortality { get; internal set; } = 0;
public bool onlyOwnerCanHurt { get; internal set; } = false;
public bool ownerDamageOverride { get; internal set; } = false;
public float stunRecoveryTime { get; internal set; } = 10f;
}
}
1 change: 1 addition & 0 deletions ValheimPlus/Configurations/Sections/WardConfiguration.cs
Expand Up @@ -3,5 +3,6 @@
public class WardConfiguration : ServerSyncConfig<WardConfiguration>
{
public float wardRange { get; internal set; } = 20;
public float wardEnemySpawnRange { get; internal set; } = 0;
}
}
Expand Up @@ -3,6 +3,7 @@
public class WorkbenchConfiguration : ServerSyncConfig<WorkbenchConfiguration>
{
public float workbenchRange { get; internal set; } = 20;
public float workbenchEnemySpawnRange { get; internal set; } = 0;
public float workbenchAttachmentRange { get; internal set; } = 5.0f;
public bool disableRoofCheck { get; internal set; } = false;
}
Expand Down
66 changes: 36 additions & 30 deletions ValheimPlus/GameClasses/Character.cs
Expand Up @@ -12,61 +12,67 @@
namespace ValheimPlus.GameClasses
{
/// <summary>
/// Determines how a creature should behave if it should be dead based on Tameable options.
/// Determines what happens when a tamed creature takes damage.
/// </summary>
[HarmonyPatch(typeof(Character), "CheckDeath")]
public static class Character_CheckDeath_Patch
[HarmonyPatch(typeof(Character), "Damage")]
public static class Character_Damage_Patch
{
public static void Prefix(Character __instance)
public static void Prefix(Character __instance, ref HitData hit, out Tameable __state)
{
__state = null;
if (Configuration.Current.Tameable.IsEnabled)
{
Character character = __instance;
ZDO zdo = character.m_nview.GetZDO();
__state = character.GetComponent<Tameable>();

if (!character.IsTamed() || zdo == null)
if (!character.IsTamed() || zdo == null || hit == null || __state)
return;

if (ShouldSetStunned(character))
{
character.SetHealth(character.GetMaxHealth());
character.m_animator.SetBool("sleeping", true);
zdo.Set("sleeping", true);
zdo.Set("isRecoveringFromStun", true);
}
if (ShouldIgnoreDamage(character, __state, hit, zdo))
hit = new HitData();
}
}

private static bool ShouldSetStunned(Character character)
{
return (TameableMortalityTypes)Configuration.Current.Tameable.mortality == TameableMortalityTypes.Essential && character.GetHealth() <= 0f && !Configuration.Current.Tameable.onlyOwnerCanHurt;
}
}

/// <summary>
/// Determines whether a tamed creature should take damage or not based on Tameable options.
/// </summary>
[HarmonyPatch(typeof(Character), "Damage")]
public static class Character_Damage_Patch
{
public static void Prefix(Character __instance, ref HitData hit)
public static void Postfix(Character __instance, HitData hit, Tameable __state)
{
if (Configuration.Current.Tameable.IsEnabled)
{
Character character = __instance;
ZDO zdo = character.m_nview.GetZDO();
Tameable tameable = __state;

if (!character.IsTamed() || zdo == null)
if (!character.IsTamed() || zdo == null || tameable == null)
return;

if (ShouldIgnoreDamage(hit, zdo))
hit = new HitData();
if (ShouldSetStunned(character, tameable, hit))
{
character.SetHealth(character.GetMaxHealth());
character.m_animator.SetBool("sleeping", true);
zdo.Set("sleeping", true);
zdo.Set("isRecoveringFromStun", true);
}
}
}

private static bool ShouldIgnoreDamage(HitData hit, ZDO zdo)
private static bool ShouldIgnoreDamage(Character tame, Tameable tameable, HitData hit, ZDO zdo)
{
bool tameIsImmortal = (TameableMortalityTypes)Configuration.Current.Tameable.mortality == TameableMortalityTypes.Immortal;
bool tameOwnerDamageOverride = Configuration.Current.Tameable.ownerDamageOverride;
Character attacker = hit.GetAttacker();
bool tameAttackerIsOwner = attacker == tameable.GetPlayer(attacker.GetZDOID());
bool tameIsRecoveringFromStun = zdo.GetBool("isRecoveringFromStun");
return (tameIsImmortal && !(tameOwnerDamageOverride && tameAttackerIsOwner)) || tameIsRecoveringFromStun;
}

private static bool ShouldSetStunned(Character character, Tameable tameable, HitData hit)
{
return ((TameableMortalityTypes)Configuration.Current.Tameable.mortality == TameableMortalityTypes.Immortal || (Configuration.Current.Tameable.onlyOwnerCanHurt && hit.GetAttacker().m_nview.GetZDO().m_owner != zdo.m_owner) || zdo.GetBool("isRecoveringFromStun")) && !Configuration.Current.Tameable.onlyOwnerCanHurt;
bool tameIsEssential = (TameableMortalityTypes)Configuration.Current.Tameable.mortality == TameableMortalityTypes.Essential;
bool tameShouldBeDead = character.GetHealth() <= 0f;
bool tameOwnerDamageOverride = Configuration.Current.Tameable.ownerDamageOverride;
Character attacker = hit.GetAttacker();
bool tameAttackerIsOwner = attacker == tameable.GetPlayer(attacker.GetZDOID());
return tameIsEssential && tameShouldBeDead && !(tameOwnerDamageOverride && tameAttackerIsOwner);
}
}

Expand Down
2 changes: 1 addition & 1 deletion ValheimPlus/GameClasses/CookingStation.cs
Expand Up @@ -24,7 +24,7 @@ public static class CookingStation_FindCookableItem_Transpiler
[HarmonyTranspiler]
public static IEnumerable<CodeInstruction> Transpiler(IEnumerable<CodeInstruction> instructions)
{
if (!Configuration.Current.CraftFromChest.IsEnabled || !Configuration.Current.CraftFromChest.disableCookingStation) return instructions;
if (!Configuration.Current.CraftFromChest.IsEnabled || Configuration.Current.CraftFromChest.disableCookingStation) return instructions;

List<CodeInstruction> il = instructions.ToList();
int endIdx = -1;
Expand Down
2 changes: 1 addition & 1 deletion ValheimPlus/GameClasses/CraftingStation.cs
Expand Up @@ -25,7 +25,7 @@ private static void Prefix(ref CraftingStation __instance, ref float ___m_rangeB

// Apply this change to the child GameObject's EffectArea collision.
// Various other systems query this collision instead of the PrivateArea radius for permissions (notably, enemy spawning).
Helper.ResizeChildEffectArea(__instance, EffectArea.Type.PlayerBase, Configuration.Current.Workbench.workbenchRange);
Helper.ResizeChildEffectArea(__instance, EffectArea.Type.PlayerBase, Configuration.Current.Workbench.workbenchEnemySpawnRange > 0 ? Configuration.Current.Workbench.workbenchEnemySpawnRange : Configuration.Current.Workbench.workbenchRange);
}
catch
{
Expand Down
60 changes: 60 additions & 0 deletions ValheimPlus/GameClasses/EnvMan.cs
Expand Up @@ -66,4 +66,64 @@ private static void Prefix(ref EnvMan __instance)
}
*/
}

[HarmonyPatch(typeof(EnvMan), "SetEnv")]
public static class EnvMan_SetEnv_Patch
{
private static void Prefix(ref EnvMan __instance, ref EnvSetup env)
{
if (Configuration.Current.Game.IsEnabled && Configuration.Current.Game.disableFog)
{
env.m_fogDensityNight = 0.0001f;
env.m_fogDensityMorning = 0.0001f;
env.m_fogDensityDay = 0.0001f;
env.m_fogDensityEvening = 0.0001f;
}

if (Configuration.Current.Brightness.IsEnabled)
{
applyEnvModifier(env);
}
}

private static void applyEnvModifier(EnvSetup env)
{
/* changing brightness during a period of day had a coupling affect with other period, need further development
env.m_fogColorMorning = applyBrightnessModifier(env.m_fogColorMorning, Configuration.Current.Brightness.morningBrightnessMultiplier);
env.m_fogColorSunMorning = applyBrightnessModifier(env.m_fogColorSunMorning, Configuration.Current.Brightness.morningBrightnessMultiplier);
env.m_sunColorMorning = applyBrightnessModifier(env.m_sunColorMorning, Configuration.Current.Brightness.morningBrightnessMultiplier);
env.m_ambColorDay = applyBrightnessModifier(env.m_ambColorDay, Configuration.Current.Brightness.dayBrightnessMultiplier);
env.m_fogColorDay = applyBrightnessModifier(env.m_fogColorDay, Configuration.Current.Brightness.dayBrightnessMultiplier);
env.m_fogColorSunDay = applyBrightnessModifier(env.m_fogColorSunDay, Configuration.Current.Brightness.dayBrightnessMultiplier);
env.m_sunColorDay = applyBrightnessModifier(env.m_sunColorDay, Configuration.Current.Brightness.dayBrightnessMultiplier);
env.m_fogColorEvening = applyBrightnessModifier(env.m_fogColorEvening, Configuration.Current.Brightness.eveningBrightnessMultiplier);
env.m_fogColorSunEvening = applyBrightnessModifier(env.m_fogColorSunEvening, Configuration.Current.Brightness.eveningBrightnessMultiplier);
env.m_sunColorEvening = applyBrightnessModifier(env.m_sunColorEvening, Configuration.Current.Brightness.eveningBrightnessMultiplier);
*/

env.m_ambColorNight = applyBrightnessModifier(env.m_ambColorNight, Configuration.Current.Brightness.nightBrightnessMultiplier);
env.m_fogColorNight = applyBrightnessModifier(env.m_fogColorNight, Configuration.Current.Brightness.nightBrightnessMultiplier);
env.m_fogColorSunNight = applyBrightnessModifier(env.m_fogColorSunNight, Configuration.Current.Brightness.nightBrightnessMultiplier);
env.m_sunColorNight = applyBrightnessModifier(env.m_sunColorNight, Configuration.Current.Brightness.nightBrightnessMultiplier);
}

private static Color applyBrightnessModifier(Color color, float multiplier)
{
float h, s, v;
Color.RGBToHSV(color, out h, out s, out v);
float scaleFunc;
if (multiplier >= 0)
{
scaleFunc = (Mathf.Sqrt(multiplier) * 1.069952679E-4f) + 1f;
}
else
{
scaleFunc = 1f - (Mathf.Sqrt(Mathf.Abs(multiplier)) * 1.069952679E-4f);
}
v = Mathf.Clamp01(v * scaleFunc);
return Color.HSVToRGB(h, s, v);
}
}
}

0 comments on commit e3aada9

Please sign in to comment.