mirror of
https://github.com/OpenFusionProject/OpenFusion.git
synced 2024-11-22 21:40:05 +00:00
/summonW now supports summoning non-mob NPCs.
/npcr will now rotate gruntwork NPCs in-place instead of making separate rotation entries that wouldn't have been loaded properly anyway.
This commit is contained in:
parent
deb3e5b897
commit
55be58cc24
@ -216,32 +216,40 @@ void summonWCommand(std::string full, std::vector<std::string>& args, CNSocket*
|
|||||||
|
|
||||||
assert(NPCManager::nextId < INT32_MAX);
|
assert(NPCManager::nextId < INT32_MAX);
|
||||||
|
|
||||||
|
#define EXTRA_HEIGHT 200
|
||||||
BaseNPC *npc = nullptr;
|
BaseNPC *npc = nullptr;
|
||||||
|
int id = NPCManager::nextId++;
|
||||||
if (team == 2) {
|
if (team == 2) {
|
||||||
npc = new Mob(plr->x, plr->y, plr->z + 200, plr->instanceID, type, NPCManager::NPCData[type], NPCManager::nextId++);
|
npc = new Mob(plr->x, plr->y, plr->z + EXTRA_HEIGHT, plr->instanceID, type, NPCManager::NPCData[type], id);
|
||||||
npc->appearanceData.iAngle = (plr->angle + 180) % 360;
|
|
||||||
|
|
||||||
NPCManager::NPCs[npc->appearanceData.iNPC_ID] = npc;
|
|
||||||
MobManager::Mobs[npc->appearanceData.iNPC_ID] = (Mob*)npc;
|
MobManager::Mobs[npc->appearanceData.iNPC_ID] = (Mob*)npc;
|
||||||
|
|
||||||
// re-enable respawning
|
// re-enable respawning
|
||||||
((Mob*)npc)->summoned = false;
|
((Mob*)npc)->summoned = false;
|
||||||
} else {
|
} else {
|
||||||
ChatManager::sendServerMessage(sock, "Error: /summonW only supports Mobs at this time.");
|
npc = new BaseNPC(plr->x, plr->y, plr->z + EXTRA_HEIGHT, 0, plr->instanceID, type, id);
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
npc->appearanceData.iAngle = (plr->angle + 180) % 360;
|
||||||
|
NPCManager::NPCs[npc->appearanceData.iNPC_ID] = npc;
|
||||||
|
|
||||||
NPCManager::updateNPCPosition(npc->appearanceData.iNPC_ID, plr->x, plr->y, plr->z);
|
NPCManager::updateNPCPosition(npc->appearanceData.iNPC_ID, plr->x, plr->y, plr->z);
|
||||||
|
|
||||||
// if we're in a lair, we need to spawn the mob in both the private instance and the template
|
// if we're in a lair, we need to spawn the NPC in both the private instance and the template
|
||||||
if (PLAYERID(plr->instanceID) != 0) {
|
if (PLAYERID(plr->instanceID) != 0) {
|
||||||
npc = new Mob(plr->x, plr->y, plr->z + 200, MAPNUM(plr->instanceID), type, NPCManager::NPCData[type], NPCManager::nextId++);
|
id = NPCManager::nextId++;
|
||||||
npc->appearanceData.iAngle = (plr->angle + 180) % 360;
|
|
||||||
|
if (team == 2) {
|
||||||
|
npc = new Mob(plr->x, plr->y, plr->z + EXTRA_HEIGHT, MAPNUM(plr->instanceID), type, NPCManager::NPCData[type], id);
|
||||||
|
|
||||||
NPCManager::NPCs[npc->appearanceData.iNPC_ID] = npc;
|
|
||||||
MobManager::Mobs[npc->appearanceData.iNPC_ID] = (Mob*)npc;
|
MobManager::Mobs[npc->appearanceData.iNPC_ID] = (Mob*)npc;
|
||||||
|
|
||||||
((Mob*)npc)->summoned = false;
|
((Mob*)npc)->summoned = false;
|
||||||
|
} else {
|
||||||
|
npc = new BaseNPC(plr->x, plr->y, plr->z + EXTRA_HEIGHT, 0, MAPNUM(plr->instanceID), type, id);
|
||||||
|
}
|
||||||
|
|
||||||
|
npc->appearanceData.iAngle = (plr->angle + 180) % 360;
|
||||||
|
NPCManager::NPCs[npc->appearanceData.iNPC_ID] = npc;
|
||||||
|
|
||||||
NPCManager::updateNPCPosition(npc->appearanceData.iNPC_ID, plr->x, plr->y, plr->z);
|
NPCManager::updateNPCPosition(npc->appearanceData.iNPC_ID, plr->x, plr->y, plr->z);
|
||||||
}
|
}
|
||||||
@ -313,14 +321,24 @@ void npcRotateCommand(std::string full, std::vector<std::string>& args, CNSocket
|
|||||||
|
|
||||||
int angle = (plr->angle + 180) % 360;
|
int angle = (plr->angle + 180) % 360;
|
||||||
NPCManager::updateNPCPosition(npc->appearanceData.iNPC_ID, npc->appearanceData.iX, npc->appearanceData.iY, npc->appearanceData.iZ, angle);
|
NPCManager::updateNPCPosition(npc->appearanceData.iNPC_ID, npc->appearanceData.iX, npc->appearanceData.iY, npc->appearanceData.iZ, angle);
|
||||||
|
|
||||||
|
// if it's a gruntwork NPC, rotate in-place
|
||||||
|
if (TableData::RunningMobs.find(npc->appearanceData.iNPC_ID) != TableData::RunningMobs.end()) {
|
||||||
|
NPCManager::updateNPCPosition(npc->appearanceData.iNPC_ID, npc->appearanceData.iX, npc->appearanceData.iY, npc->appearanceData.iZ, angle);
|
||||||
|
|
||||||
|
ChatManager::sendServerMessage(sock, "[NPCR] Successfully set angle to " + std::to_string(angle) + " for gruntwork NPC "
|
||||||
|
+ std::to_string(npc->appearanceData.iNPC_ID));
|
||||||
|
} else {
|
||||||
TableData::RunningNPCRotations[npc->appearanceData.iNPC_ID] = angle;
|
TableData::RunningNPCRotations[npc->appearanceData.iNPC_ID] = angle;
|
||||||
|
|
||||||
|
ChatManager::sendServerMessage(sock, "[NPCR] Successfully set angle to " + std::to_string(angle) + " for NPC "
|
||||||
|
+ std::to_string(npc->appearanceData.iNPC_ID));
|
||||||
|
}
|
||||||
|
|
||||||
// update rotation clientside
|
// update rotation clientside
|
||||||
INITSTRUCT(sP_FE2CL_NPC_ENTER, pkt);
|
INITSTRUCT(sP_FE2CL_NPC_ENTER, pkt);
|
||||||
pkt.NPCAppearanceData = npc->appearanceData;
|
pkt.NPCAppearanceData = npc->appearanceData;
|
||||||
sock->sendPacket((void*)&pkt, P_FE2CL_NPC_ENTER, sizeof(sP_FE2CL_NPC_ENTER));
|
sock->sendPacket((void*)&pkt, P_FE2CL_NPC_ENTER, sizeof(sP_FE2CL_NPC_ENTER));
|
||||||
|
|
||||||
ChatManager::sendServerMessage(sock, "[NPCR] Successfully set angle to " + std::to_string(angle) + " for NPC " + std::to_string(npc->appearanceData.iNPC_ID));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void refreshCommand(std::string full, std::vector<std::string>& args, CNSocket* sock) {
|
void refreshCommand(std::string full, std::vector<std::string>& args, CNSocket* sock) {
|
||||||
|
@ -551,18 +551,25 @@ void TableData::loadGruntwork(int32_t *nextId) {
|
|||||||
auto mobs = gruntwork["mobs"];
|
auto mobs = gruntwork["mobs"];
|
||||||
for (auto _mob = mobs.begin(); _mob != mobs.end(); _mob++) {
|
for (auto _mob = mobs.begin(); _mob != mobs.end(); _mob++) {
|
||||||
auto mob = _mob.value();
|
auto mob = _mob.value();
|
||||||
|
BaseNPC *npc;
|
||||||
|
int id = (*nextId)++;
|
||||||
uint64_t instanceID = mob.find("iMapNum") == mob.end() ? INSTANCE_OVERWORLD : (int)mob["iMapNum"];
|
uint64_t instanceID = mob.find("iMapNum") == mob.end() ? INSTANCE_OVERWORLD : (int)mob["iMapNum"];
|
||||||
Mob *npc = new Mob(mob["iX"], mob["iY"], mob["iZ"], instanceID, mob["iNPCType"],
|
|
||||||
NPCManager::NPCData[(int)mob["iNPCType"]], (*nextId)++);
|
|
||||||
|
|
||||||
NPCManager::NPCs[npc->appearanceData.iNPC_ID] = npc;
|
if (NPCManager::NPCData[(int)mob["iNPCType"]]["m_iTeam"] == 2) {
|
||||||
MobManager::Mobs[npc->appearanceData.iNPC_ID] = npc;
|
npc = new Mob(mob["iX"], mob["iY"], mob["iZ"], instanceID, mob["iNPCType"],
|
||||||
TableData::RunningMobs[npc->appearanceData.iNPC_ID] = npc;
|
NPCManager::NPCData[(int)mob["iNPCType"]], id);
|
||||||
NPCManager::updateNPCPosition(npc->appearanceData.iNPC_ID, mob["iX"], mob["iY"], mob["iZ"]);
|
|
||||||
|
|
||||||
// re-enable respawning
|
// re-enable respawning
|
||||||
npc->summoned = false;
|
((Mob*)npc)->summoned = false;
|
||||||
|
|
||||||
|
MobManager::Mobs[npc->appearanceData.iNPC_ID] = (Mob*)npc;
|
||||||
|
} else {
|
||||||
|
npc = new BaseNPC(mob["iX"], mob["iY"], mob["iZ"], mob["iAngle"], instanceID, mob["iNPCType"], id);
|
||||||
|
}
|
||||||
|
|
||||||
|
NPCManager::NPCs[npc->appearanceData.iNPC_ID] = npc;
|
||||||
|
TableData::RunningMobs[npc->appearanceData.iNPC_ID] = npc;
|
||||||
|
NPCManager::updateNPCPosition(npc->appearanceData.iNPC_ID, mob["iX"], mob["iY"], mob["iZ"]);
|
||||||
}
|
}
|
||||||
|
|
||||||
std::cout << "[INFO] Loaded gruntwork.json" << std::endl;
|
std::cout << "[INFO] Loaded gruntwork.json" << std::endl;
|
||||||
@ -618,21 +625,36 @@ void TableData::flush() {
|
|||||||
|
|
||||||
for (auto& pair : RunningMobs) {
|
for (auto& pair : RunningMobs) {
|
||||||
nlohmann::json mob;
|
nlohmann::json mob;
|
||||||
Mob *m = (Mob*)pair.second; // we need spawnX, etc
|
BaseNPC *npc = pair.second;
|
||||||
|
|
||||||
if (NPCManager::NPCs.find(pair.first) == NPCManager::NPCs.end())
|
if (NPCManager::NPCs.find(pair.first) == NPCManager::NPCs.end())
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
// NOTE: this format deviates slightly from the one in mobs.json
|
int x, y, z, hp;
|
||||||
mob["iNPCType"] = (int)m->appearanceData.iNPCType;
|
if (npc->npcClass == NPC_MOB) {
|
||||||
mob["iHP"] = (int)m->maxHealth;
|
Mob *m = (Mob*)npc;
|
||||||
mob["iX"] = m->spawnX;
|
x = m->spawnX;
|
||||||
mob["iY"] = m->spawnY;
|
y = m->spawnY;
|
||||||
mob["iZ"] = m->spawnZ;
|
z = m->spawnZ;
|
||||||
mob["iMapNum"] = MAPNUM(m->instanceID);
|
hp = m->maxHealth;
|
||||||
// this is a bit imperfect, since this is a live angle, not a spawn angle so it'll change often, but eh
|
} else {
|
||||||
mob["iAngle"] = m->appearanceData.iAngle;
|
x = npc->appearanceData.iX;
|
||||||
|
y = npc->appearanceData.iY;
|
||||||
|
z = npc->appearanceData.iZ;
|
||||||
|
hp = npc->appearanceData.iHP;
|
||||||
|
}
|
||||||
|
|
||||||
|
// NOTE: this format deviates slightly from the one in mobs.json
|
||||||
|
mob["iNPCType"] = (int)npc->appearanceData.iNPCType;
|
||||||
|
mob["iHP"] = hp;
|
||||||
|
mob["iX"] = x;
|
||||||
|
mob["iY"] = y;
|
||||||
|
mob["iZ"] = z;
|
||||||
|
mob["iMapNum"] = MAPNUM(npc->instanceID);
|
||||||
|
// this is a bit imperfect, since this is a live angle, not a spawn angle so it'll change often, but eh
|
||||||
|
mob["iAngle"] = npc->appearanceData.iAngle;
|
||||||
|
|
||||||
|
// it's called mobs, but really it's everything
|
||||||
gruntwork["mobs"].push_back(mob);
|
gruntwork["mobs"].push_back(mob);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user