feat: Adds allow skill gain to regions (#1286)

This commit is contained in:
Kamron Batman 2022-11-28 20:46:10 -08:00 committed by GitHub
parent 537526a328
commit c8a804d0b1
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 35 additions and 25 deletions

View file

@ -758,6 +758,8 @@ public class Region : IComparable<Region>
Parent?.OnSpeech(args); 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 OnSkillUse(Mobile m, int skill) => Parent?.OnSkillUse(m, skill) ?? true;
public virtual bool OnBeginSpellCast(Mobile m, ISpell s) => Parent?.OnBeginSpellCast(m, s) ?? true; public virtual bool OnBeginSpellCast(Mobile m, ISpell s) => Parent?.OnBeginSpellCast(m, s) ?? true;

View file

@ -160,29 +160,40 @@ public static class SkillCheck
} }
var success = chance >= Utility.RandomDouble(); 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 : var region = from.Region;
Core.AOS ? 0.0 : 0.2); if (from.Alive && region.AllowGain(from, skill, amObj))
gc /= 2;
gc *= skill.Info.GainFactor;
if (gc < 0.01)
{ {
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 += (1.0 - chance) * (success ? 0.5 : Core.AOS ? 0.0 : 0.2);
{ gc /= 2;
gc *= 2;
}
if (from.Alive && (gc >= Utility.RandomDouble() && AllowGain(from, skill, amObj) || skill.Base < 10.0)) gc *= skill.Info.GainFactor;
{
Gain(from, skill); if (gc < 0.01)
{
gc = 0.01;
}
if (from is BaseCreature { Controlled: true })
{
gc *= 2;
}
if (gc >= Utility.RandomDouble())
{
Gain(from, skill);
}
}
} }
return success; return success;
@ -256,12 +267,7 @@ public static class SkillCheck
public static void Gain(Mobile from, Skill skill) public static void Gain(Mobile from, Skill skill)
{ {
if (from.Region.IsPartOf<JailRegion>()) if (from is BaseCreature { IsDeadPet: true })
{
return;
}
if (from is BaseCreature creature && creature.IsDeadPet)
{ {
return; return;
} }

View file

@ -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) public override bool AllowBeneficial(Mobile from, Mobile target)
{ {
if (from.AccessLevel == AccessLevel.Player) if (from.AccessLevel == AccessLevel.Player)