mirror of
https://github.com/OpenFusionProject/OpenFusion.git
synced 2024-11-22 05:20:05 +00:00
Tweak mob roaming logic and a few other values
This fixes the crash with mobs with a very small m_iIdleRange and avoids unnecessary looping. Co-authored-by: JadeShrineMaiden <69916714+JadeShrineMaiden@users.noreply.github.com>
This commit is contained in:
parent
618a8d0a9f
commit
f7a6615379
@ -661,19 +661,24 @@ void MobManager::roamingStep(Mob *mob, time_t currTime) {
|
|||||||
if (mob->idleRange == 0 || speed == 0)
|
if (mob->idleRange == 0 || speed == 0)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
int farX, farY;
|
int farX, farY, distance;
|
||||||
int distance; // for short walk detection
|
int minDistance = mob->idleRange / 2;
|
||||||
|
|
||||||
/*
|
// pick a random destination
|
||||||
* We don't want the mob to just take one step and stop, so we make sure
|
farX = xStart + rand() % mob->idleRange;
|
||||||
* it has walked a half-decent distance.
|
farY = yStart + rand() % mob->idleRange;
|
||||||
*/
|
|
||||||
do {
|
|
||||||
farX = xStart + rand() % mob->idleRange;
|
|
||||||
farY = yStart + rand() % mob->idleRange;
|
|
||||||
|
|
||||||
distance = std::hypot(mob->appearanceData.iX - farX, mob->appearanceData.iY - farY);
|
distance = std::abs(std::max(farX - mob->appearanceData.iX, farY - mob->appearanceData.iY));
|
||||||
} while (distance < 500);
|
if (distance == 0)
|
||||||
|
distance += 1; // hack to avoid FPE
|
||||||
|
|
||||||
|
// if it's too short a walk, go further in that direction
|
||||||
|
farX = mob->appearanceData.iX + (farX - mob->appearanceData.iX) * minDistance / distance;
|
||||||
|
farY = mob->appearanceData.iY + (farY - mob->appearanceData.iY) * minDistance / distance;
|
||||||
|
|
||||||
|
// but don't got out of bounds
|
||||||
|
farX = std::clamp(farX, xStart, xStart + mob->idleRange);
|
||||||
|
farY = std::clamp(farY, yStart, yStart + mob->idleRange);
|
||||||
|
|
||||||
// halve movement speed if snared
|
// halve movement speed if snared
|
||||||
if (mob->appearanceData.iConditionBitFlag & CSB_BIT_DN_MOVE_SPEED)
|
if (mob->appearanceData.iConditionBitFlag & CSB_BIT_DN_MOVE_SPEED)
|
||||||
|
@ -70,7 +70,7 @@ struct Mob : public BaseNPC {
|
|||||||
data = d;
|
data = d;
|
||||||
|
|
||||||
regenTime = data["m_iRegenTime"];
|
regenTime = data["m_iRegenTime"];
|
||||||
idleRange = (int)data["m_iIdleRange"] * 2; // TODO: tuning?
|
idleRange = (int)data["m_iIdleRange"];
|
||||||
dropType = data["m_iDropType"];
|
dropType = data["m_iDropType"];
|
||||||
level = data["m_iNpcLevel"];
|
level = data["m_iNpcLevel"];
|
||||||
|
|
||||||
|
@ -908,7 +908,7 @@ std::string PlayerManager::getPlayerName(Player *plr, bool id) {
|
|||||||
return "NOT IN GAME";
|
return "NOT IN GAME";
|
||||||
|
|
||||||
std::string ret = "";
|
std::string ret = "";
|
||||||
if (id && plr->accountLevel <= 10)
|
if (id && plr->accountLevel <= 30)
|
||||||
ret += "(GM) ";
|
ret += "(GM) ";
|
||||||
|
|
||||||
ret += U16toU8(plr->PCStyle.szFirstName) + " " + U16toU8(plr->PCStyle.szLastName);
|
ret += U16toU8(plr->PCStyle.szFirstName) + " " + U16toU8(plr->PCStyle.szLastName);
|
||||||
|
@ -1,4 +1,5 @@
|
|||||||
leak:TableData::init
|
leak:TableData::init
|
||||||
|
leak:ChunkManager::newChunk
|
||||||
leak:NPCManager::updateNPCPosition
|
leak:NPCManager::updateNPCPosition
|
||||||
leak:NPCManager::summonNPC
|
leak:NPCManager::summonNPC
|
||||||
leak:NanoManager::doBuff
|
leak:NanoManager::doBuff
|
||||||
|
2
tdata
2
tdata
@ -1 +1 @@
|
|||||||
Subproject commit daba8a8a622ab9f2f63a72a66c243a49ea926088
|
Subproject commit a36aca30c9ff69b39a1b128227a6e69c77e3c00e
|
Loading…
Reference in New Issue
Block a user