Misc changes.

The first two fixes were caught by infer. The Big Bug(tm) remains
unfixed.

* Fixed the Leech nano power
* Fixed an unlikely nullptr dereference in ItemManager
* /toggleai now makes mobs retreat immediately, instead of waiting for
their next movement tick
* Static path mobs will now stop in place instead of retreating to
their spawn points when AI is disabled
* Changed the misleading config option name from "chunksize" to
"viewdistance", since it's actually only a third of the chunk size
This commit is contained in:
dongresource 2020-10-14 23:15:02 +02:00
parent 6ee5e6d1ae
commit 5784e77654
7 changed files with 26 additions and 13 deletions

View File

@ -19,8 +19,9 @@ dbsaveinterval=240
[shard]
port=8002
ip=127.0.0.1
# distance at which other players and NPCs become visible
chunksize=30000
# distance at which other players and NPCs become visible.
# this value is used for calculating chunk size
viewdistance=30000
# time, in milliseconds, to wait before kicking a non-responsive client
# default is 1 minute
timeout=60000

View File

@ -279,10 +279,18 @@ void toggleAiCommand(std::string full, std::vector<std::string>& args, CNSocket*
for (auto& pair : MobManager::Mobs) {
pair.second->state = MobState::RETREAT;
pair.second->target = nullptr;
pair.second->nextMovement = getTime();
pair.second->roamX = pair.second->spawnX;
pair.second->roamY = pair.second->spawnY;
pair.second->roamZ = pair.second->spawnZ;
// mobs with static paths can chill where they are
if (pair.second->staticPath) {
pair.second->roamX = pair.second->appearanceData.iX;
pair.second->roamY = pair.second->appearanceData.iY;
pair.second->roamZ = pair.second->appearanceData.iZ;
} else {
pair.second->roamX = pair.second->spawnX;
pair.second->roamY = pair.second->spawnY;
pair.second->roamZ = pair.second->spawnZ;
}
}
}

View File

@ -109,7 +109,7 @@ bool ChunkManager::checkChunk(std::tuple<int, int, int> chunk) {
}
std::tuple<int, int, int> ChunkManager::grabChunk(int posX, int posY, int instanceID) {
return std::make_tuple(posX / (settings::CHUNKSIZE / 3), posY / (settings::CHUNKSIZE / 3), instanceID);
return std::make_tuple(posX / (settings::VIEWDISTANCE / 3), posY / (settings::VIEWDISTANCE / 3), instanceID);
}
std::vector<Chunk*> ChunkManager::grabChunks(std::tuple<int, int, int> chunk) {

View File

@ -5,7 +5,7 @@
#include "NanoManager.hpp"
#include "Player.hpp"
#include <string.h> // for memset() and memcmp()
#include <string.h> // for memset()
#include <assert.h>
std::map<std::pair<int32_t, int32_t>, Item> ItemManager::ItemData;
@ -911,6 +911,10 @@ void ItemManager::setItemStats(Player* plr) {
for (int i = 0; i < 4; i++) {
itemStatsDat = ItemManager::getItemData(plr->Equip[i].iID, plr->Equip[i].iType);
if (itemStatsDat == nullptr) {
std::cout << "[WARN] setItemStats(): getItemData() returned NULL" << std::endl;
continue;
}
plr->pointDamage += itemStatsDat->pointDamage;
plr->groupDamage += itemStatsDat->groupDamage;
plr->defense += itemStatsDat->defense;

View File

@ -625,9 +625,9 @@ void activePower(CNSocket *sock, CNPacketData *data,
return;
pkt->iTargetCnt = otherPlr->groupCnt;
}
resplen = sizeof(sP_FE2CL_NANO_SKILL_USE_SUCC) + pkt->iTargetCnt * sizeof(sPAYLOAD);
resplen = sizeof(sP_FE2CL_NANO_SKILL_USE_SUCC) + pkt->iTargetCnt * sizeof(sPAYLOAD);
} else
resplen = sizeof(sP_FE2CL_NANO_SKILL_USE_SUCC) + pkt->iTargetCnt * sizeof(sPAYLOAD);
// validate response packet
if (!validOutVarPacket(sizeof(sP_FE2CL_NANO_SKILL_USE_SUCC), pkt->iTargetCnt, sizeof(sPAYLOAD))) {

View File

@ -12,7 +12,7 @@ int settings::DBSAVEINTERVAL = 240;
int settings::SHARDPORT = 8002;
std::string settings::SHARDSERVERIP = "127.0.0.1";
time_t settings::TIMEOUT = 60000;
int settings::CHUNKSIZE = 40000;
int settings::VIEWDISTANCE = 40000;
bool settings::SIMULATEMOBS = true;
// default spawn point is Sector V (future)
@ -47,7 +47,7 @@ void settings::init() {
SHARDSERVERIP = reader.Get("shard", "ip", "127.0.0.1");
DBSAVEINTERVAL = reader.GetInteger("shard", "dbsaveinterval", DBSAVEINTERVAL);
TIMEOUT = reader.GetInteger("shard", "timeout", TIMEOUT);
CHUNKSIZE = reader.GetInteger("shard", "chunksize", CHUNKSIZE);
VIEWDISTANCE = reader.GetInteger("shard", "viewdistance", VIEWDISTANCE);
SIMULATEMOBS = reader.GetBoolean("shard", "simulatemobs", SIMULATEMOBS);
SPAWN_X = reader.GetInteger("shard", "spawnx", SPAWN_X);
SPAWN_Y = reader.GetInteger("shard", "spawny", SPAWN_Y);

View File

@ -8,7 +8,7 @@ namespace settings {
extern int SHARDPORT;
extern std::string SHARDSERVERIP;
extern time_t TIMEOUT;
extern int CHUNKSIZE;
extern int VIEWDISTANCE;
extern bool SIMULATEMOBS;
extern int SPAWN_X;
extern int SPAWN_Y;