From 33ea5af8b71673d90abee2b6ecd30ee0623b5b90 Mon Sep 17 00:00:00 2001 From: CPunch Date: Thu, 29 Apr 2021 19:20:53 -0500 Subject: [PATCH] Added speed to CombatNPC - Mob's constructor sets speed - MobAI.cpp now uses mob->speed --- src/Entities.hpp | 1 + src/MobAI.cpp | 8 ++++---- src/MobAI.hpp | 1 + 3 files changed, 6 insertions(+), 4 deletions(-) diff --git a/src/Entities.hpp b/src/Entities.hpp index cf4b003..e66bb4c 100644 --- a/src/Entities.hpp +++ b/src/Entities.hpp @@ -101,6 +101,7 @@ struct CombatNPC : public BaseNPC { int spawnY = 0; int spawnZ = 0; int level = 0; + int speed = 300; void (*_stepAI)(CombatNPC*, time_t) = nullptr; diff --git a/src/MobAI.cpp b/src/MobAI.cpp index c6d546b..5101a8b 100644 --- a/src/MobAI.cpp +++ b/src/MobAI.cpp @@ -571,7 +571,7 @@ static void combatStep(Mob *mob, time_t currTime) { } int distanceToTravel = INT_MAX; - int speed = mob->data["m_iRunSpeed"]; + int speed = mob->speed; // movement logic: move when out of range but don't move while casting a skill if (distance > mobRange && mob->skillStyle == -1) { if (mob->nextMovement != 0 && currTime < mob->nextMovement) @@ -672,7 +672,7 @@ static void roamingStep(Mob *mob, time_t currTime) { int xStart = mob->spawnX - mob->idleRange/2; int yStart = mob->spawnY - mob->idleRange/2; - int speed = mob->data["m_iWalkSpeed"]; + int speed = mob->speed; // some mobs don't move (and we mustn't divide/modulus by zero) if (mob->idleRange == 0 || speed == 0) @@ -743,10 +743,10 @@ static void retreatStep(Mob *mob, time_t currTime) { if (distance > 10) { INITSTRUCT(sP_FE2CL_NPC_MOVE, pkt); - auto targ = lerp(mob->x, mob->y, mob->roamX, mob->roamY, (int)mob->data["m_iRunSpeed"]*4/5); + auto targ = lerp(mob->x, mob->y, mob->roamX, mob->roamY, (int)mob->speed*4/5); pkt.iNPC_ID = mob->appearanceData.iNPC_ID; - pkt.iSpeed = (int)mob->data["m_iRunSpeed"] * 2; + pkt.iSpeed = (int)mob->speed * 2; pkt.iToX = mob->x = targ.first; pkt.iToY = mob->y = targ.second; pkt.iToZ = mob->z = mob->spawnZ; diff --git a/src/MobAI.hpp b/src/MobAI.hpp index f0bf2b1..c526561 100644 --- a/src/MobAI.hpp +++ b/src/MobAI.hpp @@ -60,6 +60,7 @@ struct Mob : public CombatNPC { data = d; + speed = data["m_iRunSpeed"]; regenTime = data["m_iRegenTime"]; idleRange = (int)data["m_iIdleRange"]; level = data["m_iNpcLevel"];