fix: Makes NPC active movement half think speed (#1256)

This commit is contained in:
Kamron Batman 2022-11-20 20:05:43 -08:00 committed by GitHub
parent 10446426c0
commit 4c734a23b9
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 38 additions and 28 deletions

View file

@ -1,8 +1,8 @@
[
{
"name": "Slow",
"active": 0.3,
"passive": 0.6,
"level": "Slow",
"active": 0.35,
"passive": 0.5,
"types": [
"AntLion", "ArcticOgreLord", "BogThing",
"Bogle", "BoneKnight", "EarthElemental",
@ -19,9 +19,9 @@
]
},
{
"name": "Medium",
"active": 0.25,
"passive": 0.5,
"level": "Medium",
"active": 0.275,
"passive": 0.45,
"types": [
"AcidElemental", "AgapiteElemental", "Alligator",
"AncientLich", "Betrayer", "Bird",
@ -99,7 +99,7 @@
]
},
{
"name": "Fast",
"level": "Fast",
"active": 0.2,
"passive": 0.4,
"types": [
@ -130,9 +130,9 @@
]
},
{
"name": "Very Fast",
"active": 0.175,
"passive": 0.35,
"level": "VeryFast",
"active": 0.125,
"passive": 0.3,
"types": [
"Barracoon", "Mephitis", "Neira",
"Rikktor", "Semidar", "EnergyVortex",

View file

@ -2033,12 +2033,16 @@ public abstract class BaseAI
}
}
public double TransformMoveDelay(double delay)
public double TransformMoveDelay(double thinkingSpeed)
{
// Monster is passive
if (m_Mobile is { Controlled: false, Summoned: false } && Math.Abs(delay - m_Mobile.PassiveSpeed) < 0.0001)
if (m_Mobile is { Controlled: false, Summoned: false } && Math.Abs(thinkingSpeed - m_Mobile.PassiveSpeed) < 0.0001)
{
delay *= 3;
thinkingSpeed *= 3;
}
else // Movement speed is twice as slow as "thinking"
{
thinkingSpeed *= 2;
}
if (!m_Mobile.IsDeadPet && (m_Mobile.ReduceSpeedWithDamage || m_Mobile.IsSubdued))
@ -2059,11 +2063,11 @@ public abstract class BaseAI
if (offset < 1.0)
{
delay += m_Mobile.PassiveSpeed * (1.0 - offset);
thinkingSpeed += m_Mobile.PassiveSpeed * (1.0 - offset);
}
}
return delay;
return thinkingSpeed;
}
public virtual bool CheckMove() => Core.TickCount - NextMove >= 0;

View file

@ -4828,7 +4828,7 @@ namespace Server.Mobiles
}
// If this needs to be serialized, recommend creating a hash or registry id. Don't serialize strings.
public virtual string SpeedClass => null;
public virtual SpeedLevel SpeedClass => SpeedLevel.None;
public virtual void GetSpeeds(out double activeSpeed, out double passiveSpeed)
{

View file

@ -6,11 +6,20 @@ using Server.Json;
namespace Server.Mobiles;
public enum SpeedLevel
{
None,
Slow,
Medium,
Fast,
VeryFast
}
public static class NPCSpeeds
{
private const string _tablePath = "Data/npc-speeds.json";
private static Dictionary<Type, SpeedClassEntry> _speedsByType = new();
private static Dictionary<string, SpeedClassEntry> _speedsByName = new();
private static Dictionary<SpeedLevel, SpeedClassEntry> _speedsByLevel = new();
// Enabled for pets on HS+
public static bool ScaleSpeedByDex { get; private set; }
@ -38,22 +47,19 @@ public static class NPCSpeeds
return;
}
if (bc.SpeedClass != null && _speedsByName.TryGetValue(bc.SpeedClass, out var sp) ||
_speedsByType.TryGetValue(bc.GetType(), out sp))
if ((bc.SpeedClass == SpeedLevel.None || !_speedsByLevel.TryGetValue(bc.SpeedClass, out var sp)) &&
!_speedsByType.TryGetValue(bc.GetType(), out sp))
{
activeSpeed = sp.ActiveSpeed;
passiveSpeed = sp.PassiveSpeed;
return;
sp = _speedsByLevel[SpeedLevel.Medium];
}
// "Fast"
activeSpeed = 0.2;
passiveSpeed = 0.4;
activeSpeed = sp.ActiveSpeed;
passiveSpeed = sp.PassiveSpeed;
}
public static void RegisterSpeed(SpeedClassEntry entry)
{
_speedsByName[entry.Name] = entry;
_speedsByLevel[entry.Level] = entry;
foreach (var type in entry.Types)
{
@ -87,8 +93,8 @@ public static class NPCSpeeds
public record SpeedClassEntry
{
[JsonPropertyName("name")]
public string Name { get; init; }
[JsonPropertyName("level")]
public SpeedLevel Level { get; init; }
[JsonPropertyName("active")]
public double ActiveSpeed { get; init; }