1.0 compatibility
This commit is contained in:
parent
5104f86ede
commit
6193b3ee2d
33 changed files with 712 additions and 49 deletions
|
|
@ -282,7 +282,9 @@ namespace RacesOfValheim
|
|||
HitData hitData = new HitData();
|
||||
hitData.m_damage = staffDrop.m_itemData.m_shared.m_damages;
|
||||
hitData.SetAttacker(Player.m_localPlayer);
|
||||
|
||||
// The Drake breath is a fixed three-shard volley, so one third each.
|
||||
SkadiMagicSkill.TagCast(hitData, 3);
|
||||
|
||||
proj.Setup(Player.m_localPlayer, targetDir * vel, -1f, hitData, staffDrop.m_itemData, null);
|
||||
}
|
||||
|
||||
|
|
@ -376,6 +378,7 @@ namespace RacesOfValheim
|
|||
HitData hitData = new HitData();
|
||||
hitData.m_damage = staffDrop.m_itemData.m_shared.m_damages;
|
||||
hitData.SetAttacker(Player.m_localPlayer);
|
||||
SkadiMagicSkill.TagCast(hitData, projCount);
|
||||
proj.Setup(Player.m_localPlayer, targetDir * vel, -1f, hitData, staffDrop.m_itemData, null);
|
||||
}
|
||||
|
||||
|
|
@ -484,6 +487,7 @@ namespace RacesOfValheim
|
|||
hitData.m_damage.m_frost += hitData.m_damage.m_fire;
|
||||
hitData.m_damage.m_fire = 0f;
|
||||
hitData.SetAttacker(Player.m_localPlayer);
|
||||
SkadiMagicSkill.TagCast(hitData, projCount);
|
||||
|
||||
if (proj != null)
|
||||
{
|
||||
|
|
|
|||
|
|
@ -45,6 +45,12 @@ namespace RacesOfValheim
|
|||
public static ConfigEntry<float> AuraDamagePerTick;
|
||||
public static ConfigEntry<float> AuraTickInterval;
|
||||
|
||||
// ─── Elemental Magic experience ─────────────────────────────────────────
|
||||
// See SkadiMagicSkill for why a cast's budget is split across its projectiles and why the
|
||||
// aura's share is a fraction of a cast's.
|
||||
public static ConfigEntry<float> MagicSkillGainPerCast;
|
||||
public static ConfigEntry<float> AuraSkillGainPerTick;
|
||||
|
||||
// ─── Passive combat ──────────────────────────────────────────────────
|
||||
public static ConfigEntry<float> BonusFrostDamagePerState;
|
||||
|
||||
|
|
@ -126,6 +132,12 @@ namespace RacesOfValheim
|
|||
AuraTickInterval = config.Bind(aura, "Tick Interval", 1f,
|
||||
new ConfigDescription("Seconds between aura damage ticks.", new AcceptableValueRange<float>(0.1f, 5f)));
|
||||
|
||||
const string magicSkill = "Skadi - Elemental Magic Skill";
|
||||
MagicSkillGainPerCast = config.Bind(magicSkill, "Gain Per Cast", 1f,
|
||||
new ConfigDescription("Elemental Magic experience for one cast that connects - the Cold Spell and all three dragon breaths. Split across the projectiles a cast throws, so a ten-shard burst is worth the same as one shard. Nothing is earned by a shot that hits no one. 0 turns spell experience off.", new AcceptableValueRange<float>(0f, 5f)));
|
||||
AuraSkillGainPerTick = config.Bind(magicSkill, "Aura Gain Per Tick", 0.1f,
|
||||
new ConfigDescription("Elemental Magic experience for one Frost Aura tick that burned at least one enemy - once per tick, not once per enemy. Deliberately a fraction of a cast: the aura ticks every second on its own. 0 turns aura experience off.", new AcceptableValueRange<float>(0f, 1f)));
|
||||
|
||||
const string scale = "Skadi - Dragon Form Scale";
|
||||
DrakeScale = config.Bind(scale, "Drake Scale", 0.9f,
|
||||
new ConfigDescription("Model scale while transformed into the Drake (tier 3-4).", new AcceptableValueRange<float>(0.1f, 2f)));
|
||||
|
|
|
|||
83
JotunnModStub/Skadi/SkadiMagicSkill.cs
Normal file
83
JotunnModStub/Skadi/SkadiMagicSkill.cs
Normal file
|
|
@ -0,0 +1,83 @@
|
|||
namespace RacesOfValheim
|
||||
{
|
||||
/// <summary>
|
||||
/// Elemental Magic experience for Skadi's spellcasting, in one place because four call sites
|
||||
/// need the same two lines and the same piece of arithmetic.
|
||||
///
|
||||
/// WHY NOTHING WAS LEVELLING BEFORE. Every one of Skadi's casts builds its HitData by hand and
|
||||
/// never touched HitData.m_skill, which leaves it at SkillType.None. Vanilla's Skills.RaiseSkill
|
||||
/// returns on its first instruction when the type is None, so the experience was not merely
|
||||
/// small - it was structurally impossible. Read out of assembly_valheim, along with the path
|
||||
/// that makes the fix a one-liner:
|
||||
///
|
||||
/// Projectile.Setup copies hitData.m_skill into Projectile.m_skill, and
|
||||
/// hitData.m_skillRaiseAmount into Projectile.m_raiseSkillAmount.
|
||||
/// Projectile.OnHit calls owner.RaiseSkill(m_skill, m_raiseSkillAmount) - once, and only
|
||||
/// on the branch where the projectile actually damaged something.
|
||||
///
|
||||
/// So a tagged HitData gets vanilla's own behaviour for free: experience on a hit that lands,
|
||||
/// nothing for a shot into a hillside, and no double-counting. That is better than raising the
|
||||
/// skill at cast time, which would pay a player for missing.
|
||||
///
|
||||
/// WHY THE AMOUNT IS DIVIDED. A cast is one spell however many things leave the hand. The
|
||||
/// improved Cold Spell throws ten shards and the dragon breaths throw up to a volley each, and
|
||||
/// every one of those is its own Projectile with its own OnHit - so an untouched
|
||||
/// m_skillRaiseAmount of 1 would pay ten times for one cast. The budget is split the same way
|
||||
/// ColdSpellKickCoroutine already splits its damage budget across shards, for the same reason.
|
||||
///
|
||||
/// WHAT IS DELIBERATELY NOT HERE. The dragon forms' melee (DrakeFormBehavior.ExecuteMeleeDamage)
|
||||
/// stays on Unarmed: it already tags itself that way and already scales off the Unarmed skill
|
||||
/// level - it is a maul, not a spell. And the Crystal Golem is a hammer piece, not a cast, so it
|
||||
/// pays Building experience through vanilla's own placement path.
|
||||
/// </summary>
|
||||
public static class SkadiMagicSkill
|
||||
{
|
||||
/// <summary>
|
||||
/// Marks a cast's HitData as Elemental Magic and gives it its share of the cast's
|
||||
/// experience. Call it before Projectile.Setup - Setup is what copies both fields onto the
|
||||
/// projectile, so anything written afterwards is never read.
|
||||
/// </summary>
|
||||
/// <param name="hit">The HitData about to be handed to Projectile.Setup.</param>
|
||||
/// <param name="projectilesInCast">
|
||||
/// How many projectiles this one cast throws. The cast's whole experience budget is divided
|
||||
/// by it, so a ten-shard burst and a single shard are worth the same.
|
||||
/// </param>
|
||||
public static void TagCast(HitData hit, int projectilesInCast)
|
||||
{
|
||||
if (hit == null) return;
|
||||
|
||||
float perCast = SkadiConfig.MagicSkillGainPerCast != null
|
||||
? SkadiConfig.MagicSkillGainPerCast.Value
|
||||
: 1f;
|
||||
|
||||
// Zero is the off switch, and it has to leave m_skill alone as well as the amount:
|
||||
// Skills.RaiseSkill would still be entered with a real type and a zero factor, and
|
||||
// Skill.Raise does its own bookkeeping before it looks at the number.
|
||||
if (perCast <= 0f) return;
|
||||
|
||||
if (projectilesInCast < 1) projectilesInCast = 1;
|
||||
|
||||
hit.m_skill = Skills.SkillType.ElementalMagic;
|
||||
hit.m_skillRaiseAmount = perCast / projectilesInCast;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// The Frost Aura's share. Unlike a cast the aura has no projectile to hang experience on,
|
||||
/// so it is raised directly - once per tick that actually burned something, never once per
|
||||
/// enemy. A three metre aura ticking every second through a pack would otherwise pay out
|
||||
/// several times a second and take the skill to cap on a single fight, which is why the
|
||||
/// default is a fraction rather than the 1 a cast is worth.
|
||||
/// </summary>
|
||||
public static void RaiseForAuraTick()
|
||||
{
|
||||
if (Player.m_localPlayer == null) return;
|
||||
|
||||
float gain = SkadiConfig.AuraSkillGainPerTick != null
|
||||
? SkadiConfig.AuraSkillGainPerTick.Value
|
||||
: 0f;
|
||||
if (gain <= 0f) return;
|
||||
|
||||
Player.m_localPlayer.RaiseSkill(Skills.SkillType.ElementalMagic, gain);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -118,7 +118,9 @@ namespace RacesOfValheim
|
|||
}
|
||||
}
|
||||
|
||||
[HarmonyPatch(typeof(SEMan), "AddStatusEffect", new System.Type[] { typeof(int), typeof(bool), typeof(int), typeof(float) })]
|
||||
// Valheim 1.0 appended a 'short variant' parameter to this overload. The type array has to
|
||||
// match it exactly or the patch silently fails to bind and PatchAll throws.
|
||||
[HarmonyPatch(typeof(SEMan), "AddStatusEffect", new System.Type[] { typeof(int), typeof(bool), typeof(int), typeof(float), typeof(short) })]
|
||||
public static class SkadiSEManPatch
|
||||
{
|
||||
public static bool Prefix(SEMan __instance, ref int nameHash)
|
||||
|
|
|
|||
|
|
@ -431,6 +431,9 @@ namespace RacesOfValheim
|
|||
HitData hitData = new HitData();
|
||||
hitData.m_damage.m_frost = shardDamage;
|
||||
hitData.SetAttacker(Player.m_localPlayer);
|
||||
// Before Setup, which is what copies the skill and its amount onto the
|
||||
// projectile. Same split as the damage budget above, and for the same reason.
|
||||
SkadiMagicSkill.TagCast(hitData, count);
|
||||
proj.Setup(Player.m_localPlayer, lookDir * staffDrop.m_itemData.m_shared.m_attack.m_projectileVel, -1f, hitData, staffDrop.m_itemData, null);
|
||||
}
|
||||
|
||||
|
|
@ -509,11 +512,15 @@ namespace RacesOfValheim
|
|||
{
|
||||
if (Player.m_localPlayer == null) return;
|
||||
Vector3 center = Player.m_localPlayer.transform.position;
|
||||
|
||||
// Once per tick, not once per enemy - see SkadiMagicSkill.RaiseForAuraTick.
|
||||
bool burnedSomething = false;
|
||||
|
||||
foreach (Character c in Character.GetAllCharacters())
|
||||
{
|
||||
if (c == Player.m_localPlayer) continue;
|
||||
if (c.IsTamed() || c.IsPlayer()) continue;
|
||||
|
||||
|
||||
if (Vector3.Distance(center, c.transform.position) <= SkadiConfig.AuraRadius.Value)
|
||||
{
|
||||
HitData hit = new HitData();
|
||||
|
|
@ -522,8 +529,11 @@ namespace RacesOfValheim
|
|||
hit.m_dir = (c.transform.position - center).normalized;
|
||||
hit.SetAttacker(Player.m_localPlayer);
|
||||
c.ApplyDamage(hit, true, false);
|
||||
burnedSomething = true;
|
||||
}
|
||||
}
|
||||
|
||||
if (burnedSomething) SkadiMagicSkill.RaiseForAuraTick();
|
||||
}
|
||||
|
||||
private void TryTransformWithRules(SkadiProgression.FormRules rules)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue