From c8a804d0b13d47898c75959caafb2d4eada3c856 Mon Sep 17 00:00:00 2001 From: Kamron Batman <3953314+kamronbatman@users.noreply.github.com> Date: Mon, 28 Nov 2022 20:46:10 -0800 Subject: [PATCH] feat: Adds allow skill gain to regions (#1286) --- Projects/Server/Regions/Region.cs | 2 + Projects/UOContent/Misc/SkillCheck.cs | 56 +++++++++++++----------- Projects/UOContent/Regions/JailRegion.cs | 2 + 3 files changed, 35 insertions(+), 25 deletions(-) diff --git a/Projects/Server/Regions/Region.cs b/Projects/Server/Regions/Region.cs index e36c509b1..e32115e06 100644 --- a/Projects/Server/Regions/Region.cs +++ b/Projects/Server/Regions/Region.cs @@ -758,6 +758,8 @@ public class Region : IComparable Parent?.OnSpeech(args); } + public virtual bool AllowGain(Mobile m, Skill skill, object obj) => Parent?.AllowGain(m, skill, obj) ?? true; + public virtual bool OnSkillUse(Mobile m, int skill) => Parent?.OnSkillUse(m, skill) ?? true; public virtual bool OnBeginSpellCast(Mobile m, ISpell s) => Parent?.OnBeginSpellCast(m, s) ?? true; diff --git a/Projects/UOContent/Misc/SkillCheck.cs b/Projects/UOContent/Misc/SkillCheck.cs index c037b7739..60b7cb120 100644 --- a/Projects/UOContent/Misc/SkillCheck.cs +++ b/Projects/UOContent/Misc/SkillCheck.cs @@ -160,29 +160,40 @@ public static class SkillCheck } var success = chance >= Utility.RandomDouble(); - var gc = (double)(from.Skills.Cap - from.Skills.Total) / from.Skills.Cap; - gc += (skill.Cap - skill.Base) / skill.Cap; - gc /= 2; - gc += (1.0 - chance) * (success ? 0.5 : - Core.AOS ? 0.0 : 0.2); - gc /= 2; - - gc *= skill.Info.GainFactor; - - if (gc < 0.01) + var region = from.Region; + if (from.Alive && region.AllowGain(from, skill, amObj)) { - gc = 0.01; - } + if (skill.Base < 10.0) // Gain regardless of the AllowGain check + { + Gain(from, skill); + } + else if (AllowGain(from, skill, amObj)) + { + var gc = (double)(from.Skills.Cap - from.Skills.Total) / from.Skills.Cap; + gc += (skill.Cap - skill.Base) / skill.Cap; + gc /= 2; - if (from is BaseCreature creature && creature.Controlled) - { - gc *= 2; - } + gc += (1.0 - chance) * (success ? 0.5 : Core.AOS ? 0.0 : 0.2); + gc /= 2; - if (from.Alive && (gc >= Utility.RandomDouble() && AllowGain(from, skill, amObj) || skill.Base < 10.0)) - { - Gain(from, skill); + gc *= skill.Info.GainFactor; + + if (gc < 0.01) + { + gc = 0.01; + } + + if (from is BaseCreature { Controlled: true }) + { + gc *= 2; + } + + if (gc >= Utility.RandomDouble()) + { + Gain(from, skill); + } + } } return success; @@ -256,12 +267,7 @@ public static class SkillCheck public static void Gain(Mobile from, Skill skill) { - if (from.Region.IsPartOf()) - { - return; - } - - if (from is BaseCreature creature && creature.IsDeadPet) + if (from is BaseCreature { IsDeadPet: true }) { return; } diff --git a/Projects/UOContent/Regions/JailRegion.cs b/Projects/UOContent/Regions/JailRegion.cs index b6ba508b6..5f15aee09 100644 --- a/Projects/UOContent/Regions/JailRegion.cs +++ b/Projects/UOContent/Regions/JailRegion.cs @@ -14,6 +14,8 @@ public class JailRegion : BaseRegion { } + public override bool AllowGain(Mobile m, Skill skill, object obj) => m.AccessLevel > AccessLevel.Player; + public override bool AllowBeneficial(Mobile from, Mobile target) { if (from.AccessLevel == AccessLevel.Player)