2020-09-09 17:06:22 +00:00
|
|
|
#include "TableData.hpp"
|
|
|
|
#include "NPCManager.hpp"
|
2021-03-16 22:29:13 +00:00
|
|
|
#include "Transport.hpp"
|
|
|
|
#include "Items.hpp"
|
2020-09-09 17:06:22 +00:00
|
|
|
#include "settings.hpp"
|
2021-03-16 22:29:13 +00:00
|
|
|
#include "Missions.hpp"
|
|
|
|
#include "Chunking.hpp"
|
|
|
|
#include "Nanos.hpp"
|
|
|
|
#include "Racing.hpp"
|
2021-04-16 17:28:59 +00:00
|
|
|
#include "Vendors.hpp"
|
2021-03-13 20:22:29 +00:00
|
|
|
#include "Abilities.hpp"
|
2021-03-17 21:28:24 +00:00
|
|
|
#include "Eggs.hpp"
|
2020-09-09 19:09:01 +00:00
|
|
|
|
2021-03-12 17:50:21 +00:00
|
|
|
#include "JSON.hpp"
|
2020-09-09 17:06:22 +00:00
|
|
|
|
|
|
|
#include <fstream>
|
2021-05-07 19:29:18 +00:00
|
|
|
#include <sstream>
|
2020-12-19 00:18:39 +00:00
|
|
|
#include <cmath>
|
2020-09-09 17:06:22 +00:00
|
|
|
|
2021-03-16 21:06:10 +00:00
|
|
|
using namespace TableData;
|
|
|
|
|
2021-05-01 15:04:28 +00:00
|
|
|
std::map<int32_t, std::vector<Vec3>> TableData::RunningSkywayRoutes;
|
2020-10-06 21:59:12 +00:00
|
|
|
std::map<int32_t, int> TableData::RunningNPCRotations;
|
2020-10-12 01:53:01 +00:00
|
|
|
std::map<int32_t, int> TableData::RunningNPCMapNumbers;
|
2021-05-04 23:57:06 +00:00
|
|
|
std::unordered_map<int32_t, std::pair<BaseNPC*, std::vector<BaseNPC*>>> TableData::RunningNPCPaths;
|
|
|
|
std::vector<NPCPath> TableData::FinishedNPCPaths;
|
2020-10-07 17:29:59 +00:00
|
|
|
std::map<int32_t, BaseNPC*> TableData::RunningMobs;
|
2020-11-25 15:41:10 +00:00
|
|
|
std::map<int32_t, BaseNPC*> TableData::RunningGroups;
|
2020-11-08 08:42:49 +00:00
|
|
|
std::map<int32_t, BaseNPC*> TableData::RunningEggs;
|
2020-10-03 02:05:20 +00:00
|
|
|
|
2020-10-16 19:47:43 +00:00
|
|
|
class TableException : public std::exception {
|
|
|
|
public:
|
|
|
|
std::string msg;
|
|
|
|
|
|
|
|
TableException(std::string m) : std::exception() { msg = m; }
|
|
|
|
|
|
|
|
const char *what() const throw() { return msg.c_str(); }
|
|
|
|
};
|
|
|
|
|
2023-06-22 00:27:28 +00:00
|
|
|
/*
|
|
|
|
* We must refuse to run if an invalid NPC type is found in the JSONs, especially
|
|
|
|
* the gruntwork file. If we were to just skip loading invalid NPCs, they would get
|
|
|
|
* silently dropped from the gruntwork file, which would be confusing in situations
|
|
|
|
* where a gruntwork file for the wrong game build was accidentally loaded.
|
|
|
|
*/
|
|
|
|
static void ensureValidNPCType(int type, std::string filename) {
|
|
|
|
// last known NPC type
|
|
|
|
int npcLimit = NPCManager::NPCData.back()["m_iNpcNumber"];
|
|
|
|
|
|
|
|
if (type > npcLimit) {
|
|
|
|
std::cout << "[FATAL] " << filename << " contains an invalid NPC type: " << type << std::endl;
|
|
|
|
exit(1);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-03-16 21:06:10 +00:00
|
|
|
/*
|
|
|
|
* Create a full and properly-paced path by interpolating between keyframes.
|
|
|
|
*/
|
2021-05-01 15:24:53 +00:00
|
|
|
static void constructPathSkyway(json& pathData) {
|
2021-03-16 21:06:10 +00:00
|
|
|
// Interpolate
|
2021-05-03 19:29:33 +00:00
|
|
|
json pathPoints = pathData["aPoints"];
|
2021-05-01 15:04:28 +00:00
|
|
|
std::queue<Vec3> points;
|
2021-04-29 15:01:44 +00:00
|
|
|
json::iterator _point = pathPoints.begin();
|
2021-03-16 21:06:10 +00:00
|
|
|
auto point = _point.value();
|
2021-05-01 15:04:28 +00:00
|
|
|
Vec3 last = { point["iX"] , point["iY"] , point["iZ"] }; // start pos
|
2021-03-16 21:06:10 +00:00
|
|
|
// use some for loop trickery; start position should not be a point
|
|
|
|
for (_point++; _point != pathPoints.end(); _point++) {
|
|
|
|
point = _point.value();
|
2021-05-01 15:04:28 +00:00
|
|
|
Vec3 coords = { point["iX"] , point["iY"] , point["iZ"] };
|
2021-03-16 22:29:13 +00:00
|
|
|
Transport::lerp(&points, last, coords, pathData["iMonkeySpeed"]);
|
2021-03-16 21:06:10 +00:00
|
|
|
points.push(coords); // add keyframe to the queue
|
|
|
|
last = coords; // update start pos
|
|
|
|
}
|
2021-03-16 22:29:13 +00:00
|
|
|
Transport::SkywayPaths[pathData["iRouteID"]] = points;
|
2021-03-16 21:06:10 +00:00
|
|
|
}
|
2020-09-09 17:06:22 +00:00
|
|
|
|
2021-03-16 21:06:10 +00:00
|
|
|
/*
|
2021-04-29 16:33:17 +00:00
|
|
|
* Load all relevant data from the XDT into memory
|
|
|
|
* This should be called first, before any of the other load functions
|
2021-03-16 21:06:10 +00:00
|
|
|
*/
|
2021-04-29 16:33:17 +00:00
|
|
|
static void loadXDT(json& xdtData) {
|
|
|
|
// data we'll need for summoned mobs
|
|
|
|
NPCManager::NPCData = xdtData["m_pNpcTable"]["m_pNpcData"];
|
|
|
|
|
2020-09-09 17:06:22 +00:00
|
|
|
try {
|
2021-04-29 16:33:17 +00:00
|
|
|
// load warps
|
|
|
|
json warpData = xdtData["m_pInstanceTable"]["m_pWarpData"];
|
|
|
|
|
|
|
|
for (json::iterator _warp = warpData.begin(); _warp != warpData.end(); _warp++) {
|
|
|
|
auto warp = _warp.value();
|
|
|
|
WarpLocation warpLoc = { warp["m_iToX"], warp["m_iToY"], warp["m_iToZ"], warp["m_iToMapNum"], warp["m_iIsInstance"], warp["m_iLimit_TaskID"], warp["m_iNpcNumber"] };
|
|
|
|
int warpID = warp["m_iWarpNumber"];
|
|
|
|
NPCManager::Warps[warpID] = warpLoc;
|
|
|
|
}
|
|
|
|
|
|
|
|
std::cout << "[INFO] Loaded " << NPCManager::Warps.size() << " Warps" << std::endl;
|
|
|
|
|
|
|
|
// load transport routes and locations
|
|
|
|
json transRouteData = xdtData["m_pTransportationTable"]["m_pTransportationData"];
|
|
|
|
json transLocData = xdtData["m_pTransportationTable"]["m_pTransportationWarpLocation"];
|
|
|
|
|
|
|
|
for (json::iterator _tLoc = transLocData.begin(); _tLoc != transLocData.end(); _tLoc++) {
|
|
|
|
auto tLoc = _tLoc.value();
|
|
|
|
TransportLocation transLoc = { tLoc["m_iNPCID"], tLoc["m_iXpos"], tLoc["m_iYpos"], tLoc["m_iZpos"] };
|
|
|
|
Transport::Locations[tLoc["m_iLocationID"]] = transLoc;
|
|
|
|
}
|
|
|
|
std::cout << "[INFO] Loaded " << Transport::Locations.size() << " S.C.A.M.P.E.R. locations" << std::endl;
|
|
|
|
|
|
|
|
for (json::iterator _tRoute = transRouteData.begin(); _tRoute != transRouteData.end(); _tRoute++) {
|
|
|
|
auto tRoute = _tRoute.value();
|
|
|
|
TransportRoute transRoute = { tRoute["m_iMoveType"], tRoute["m_iStartLocation"], tRoute["m_iEndLocation"],
|
|
|
|
tRoute["m_iCost"] , tRoute["m_iSpeed"], tRoute["m_iRouteNum"] };
|
|
|
|
Transport::Routes[tRoute["m_iVehicleID"]] = transRoute;
|
|
|
|
}
|
|
|
|
std::cout << "[INFO] Loaded " << Transport::Routes.size() << " transportation routes" << std::endl;
|
|
|
|
|
|
|
|
// load mission-related data
|
|
|
|
json tasks = xdtData["m_pMissionTable"]["m_pMissionData"];
|
|
|
|
|
|
|
|
for (auto _task = tasks.begin(); _task != tasks.end(); _task++) {
|
|
|
|
auto task = _task.value();
|
|
|
|
|
|
|
|
// rewards
|
|
|
|
if (task["m_iSUReward"] != 0) {
|
|
|
|
auto _rew = xdtData["m_pMissionTable"]["m_pRewardData"][(int)task["m_iSUReward"]];
|
|
|
|
Reward* rew = new Reward(_rew["m_iMissionRewardID"], _rew["m_iMissionRewarItemType"],
|
|
|
|
_rew["m_iMissionRewardItemID"], _rew["m_iCash"], _rew["m_iFusionMatter"]);
|
|
|
|
|
|
|
|
Missions::Rewards[task["m_iHTaskID"]] = rew;
|
|
|
|
}
|
|
|
|
|
|
|
|
// everything else lol. see TaskData comment.
|
|
|
|
Missions::Tasks[task["m_iHTaskID"]] = new TaskData(task);
|
|
|
|
}
|
|
|
|
|
|
|
|
std::cout << "[INFO] Loaded mission-related data" << std::endl;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* load all equipment data. i'm sorry. it has to be done
|
|
|
|
* NOTE: please don't change the ordering. it determines the types, since type and equipLoc are used inconsistently
|
|
|
|
*/
|
|
|
|
const char* setNames[11] = { "m_pWeaponItemTable", "m_pShirtsItemTable", "m_pPantsItemTable", "m_pShoesItemTable",
|
|
|
|
"m_pHatItemTable", "m_pGlassItemTable", "m_pBackItemTable", "m_pGeneralItemTable", "",
|
|
|
|
"m_pChestItemTable", "m_pVehicleItemTable" };
|
|
|
|
json itemSet;
|
|
|
|
for (int i = 0; i < 11; i++) {
|
|
|
|
if (i == 8)
|
|
|
|
continue; // there is no type 8, of course
|
|
|
|
|
|
|
|
itemSet = xdtData[setNames[i]]["m_pItemData"];
|
|
|
|
for (json::iterator _item = itemSet.begin(); _item != itemSet.end(); _item++) {
|
|
|
|
auto item = _item.value();
|
|
|
|
int itemID = item["m_iItemNumber"];
|
|
|
|
INITSTRUCT(Items::Item, itemData);
|
|
|
|
itemData.tradeable = item["m_iTradeAble"] == 1;
|
|
|
|
itemData.sellable = item["m_iSellAble"] == 1;
|
|
|
|
itemData.buyPrice = item["m_iItemPrice"];
|
|
|
|
itemData.sellPrice = item["m_iItemSellPrice"];
|
|
|
|
itemData.stackSize = item["m_iStackNumber"];
|
|
|
|
if (i != 7 && i != 9) {
|
|
|
|
itemData.rarity = item["m_iRarity"];
|
|
|
|
itemData.level = item["m_iMinReqLev"];
|
|
|
|
itemData.pointDamage = item["m_iPointRat"];
|
|
|
|
itemData.groupDamage = item["m_iGroupRat"];
|
|
|
|
itemData.fireRate = item["m_iDelayTime"];
|
|
|
|
itemData.defense = item["m_iDefenseRat"];
|
|
|
|
itemData.gender = item["m_iReqSex"];
|
|
|
|
itemData.weaponType = item["m_iEquipType"];
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
itemData.rarity = 1;
|
|
|
|
}
|
|
|
|
Items::ItemData[std::make_pair(itemID, i)] = itemData;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
std::cout << "[INFO] Loaded " << Items::ItemData.size() << " items" << std::endl;
|
|
|
|
|
|
|
|
// load player limits from m_pAvatarTable.m_pAvatarGrowData
|
|
|
|
|
|
|
|
json growth = xdtData["m_pAvatarTable"]["m_pAvatarGrowData"];
|
|
|
|
|
|
|
|
for (int i = 0; i < 37; i++) {
|
|
|
|
Missions::AvatarGrowth[i] = growth[i];
|
|
|
|
}
|
|
|
|
|
|
|
|
// load vendor listings
|
|
|
|
json listings = xdtData["m_pVendorTable"]["m_pItemData"];
|
|
|
|
|
|
|
|
for (json::iterator _lst = listings.begin(); _lst != listings.end(); _lst++) {
|
|
|
|
auto lst = _lst.value();
|
|
|
|
VendorListing vListing = { lst["m_iSortNumber"], lst["m_iItemType"], lst["m_iitemID"] };
|
|
|
|
Vendors::VendorTables[lst["m_iNpcNumber"]].push_back(vListing);
|
|
|
|
}
|
|
|
|
|
|
|
|
std::cout << "[INFO] Loaded " << Vendors::VendorTables.size() << " vendor tables" << std::endl;
|
|
|
|
|
|
|
|
// load crocpot entries
|
|
|
|
json crocs = xdtData["m_pCombiningTable"]["m_pCombiningData"];
|
2020-09-09 17:06:22 +00:00
|
|
|
|
2021-04-29 16:33:17 +00:00
|
|
|
for (json::iterator croc = crocs.begin(); croc != crocs.end(); croc++) {
|
|
|
|
CrocPotEntry crocEntry = { croc.value()["m_iStatConstant"], croc.value()["m_iLookConstant"], croc.value()["m_fLevelGapStandard"],
|
|
|
|
croc.value()["m_fSameGrade"], croc.value()["m_fOneGrade"], croc.value()["m_fTwoGrade"], croc.value()["m_fThreeGrade"] };
|
|
|
|
Items::CrocPotTable[croc.value()["m_iLevelGap"]] = crocEntry;
|
|
|
|
}
|
2021-03-16 21:06:10 +00:00
|
|
|
|
2021-04-29 16:33:17 +00:00
|
|
|
std::cout << "[INFO] Loaded " << Items::CrocPotTable.size() << " croc pot value sets" << std::endl;
|
|
|
|
|
|
|
|
// load nano info
|
|
|
|
json nanoInfo = xdtData["m_pNanoTable"]["m_pNanoData"];
|
|
|
|
for (json::iterator _nano = nanoInfo.begin(); _nano != nanoInfo.end(); _nano++) {
|
|
|
|
auto nano = _nano.value();
|
|
|
|
NanoData nanoData;
|
|
|
|
nanoData.style = nano["m_iStyle"];
|
|
|
|
Nanos::NanoTable[Nanos::NanoTable.size()] = nanoData;
|
|
|
|
}
|
|
|
|
|
|
|
|
std::cout << "[INFO] Loaded " << Nanos::NanoTable.size() << " nanos" << std::endl;
|
|
|
|
|
|
|
|
json nanoTuneInfo = xdtData["m_pNanoTable"]["m_pNanoTuneData"];
|
|
|
|
for (json::iterator _nano = nanoTuneInfo.begin(); _nano != nanoTuneInfo.end(); _nano++) {
|
|
|
|
auto nano = _nano.value();
|
|
|
|
NanoTuning nanoData;
|
|
|
|
nanoData.reqItems = nano["m_iReqItemID"];
|
|
|
|
nanoData.reqItemCount = nano["m_iReqItemCount"];
|
|
|
|
Nanos::NanoTunings[nano["m_iSkillID"]] = nanoData;
|
|
|
|
}
|
|
|
|
|
|
|
|
std::cout << "[INFO] Loaded " << Nanos::NanoTable.size() << " nano tunings" << std::endl;
|
|
|
|
|
|
|
|
// load nano powers
|
|
|
|
json skills = xdtData["m_pSkillTable"]["m_pSkillData"];
|
|
|
|
|
|
|
|
for (json::iterator _skills = skills.begin(); _skills != skills.end(); _skills++) {
|
|
|
|
auto skills = _skills.value();
|
|
|
|
SkillData skillData = { skills["m_iSkillType"], skills["m_iTargetType"], skills["m_iBatteryDrainType"], skills["m_iEffectArea"] };
|
|
|
|
for (int i = 0; i < 4; i++) {
|
|
|
|
skillData.batteryUse[i] = skills["m_iBatteryDrainUse"][i];
|
|
|
|
skillData.durationTime[i] = skills["m_iDurationTime"][i];
|
|
|
|
skillData.powerIntensity[i] = skills["m_iValueA"][i];
|
|
|
|
}
|
2021-06-20 17:05:10 +00:00
|
|
|
Abilities::SkillTable[skills["m_iSkillNumber"]] = skillData;
|
2021-04-29 16:33:17 +00:00
|
|
|
}
|
|
|
|
|
2021-06-20 17:05:10 +00:00
|
|
|
std::cout << "[INFO] Loaded " << Abilities::SkillTable.size() << " nano skills" << std::endl;
|
2021-04-29 16:33:17 +00:00
|
|
|
|
|
|
|
// load EP data
|
|
|
|
json instances = xdtData["m_pInstanceTable"]["m_pInstanceData"];
|
|
|
|
|
|
|
|
for (json::iterator _instance = instances.begin(); _instance != instances.end(); _instance++) {
|
|
|
|
auto instance = _instance.value();
|
|
|
|
EPInfo epInfo = { instance["m_iZoneX"], instance["m_iZoneY"], instance["m_iIsEP"], (int)instance["m_ScoreMax"] };
|
|
|
|
Racing::EPData[instance["m_iInstanceNameID"]] = epInfo;
|
|
|
|
}
|
|
|
|
|
|
|
|
std::cout << "[INFO] Loaded " << Racing::EPData.size() << " instances" << std::endl;
|
|
|
|
|
|
|
|
}
|
|
|
|
catch (const std::exception& err) {
|
|
|
|
std::cerr << "[FATAL] Malformed xdt.json file! Reason:" << err.what() << std::endl;
|
|
|
|
exit(1);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Load paths from JSON
|
|
|
|
*/
|
|
|
|
static void loadPaths(json& pathData, int32_t* nextId) {
|
|
|
|
try {
|
2021-03-16 21:06:10 +00:00
|
|
|
// skyway paths
|
2021-04-29 15:01:44 +00:00
|
|
|
json pathDataSkyway = pathData["skyway"];
|
|
|
|
for (json::iterator skywayPath = pathDataSkyway.begin(); skywayPath != pathDataSkyway.end(); skywayPath++) {
|
2021-05-01 15:24:53 +00:00
|
|
|
constructPathSkyway(*skywayPath);
|
2021-03-16 21:06:10 +00:00
|
|
|
}
|
2021-03-16 22:29:13 +00:00
|
|
|
std::cout << "[INFO] Loaded " << Transport::SkywayPaths.size() << " skyway paths" << std::endl;
|
2021-03-16 21:06:10 +00:00
|
|
|
|
|
|
|
// slider circuit
|
2021-04-29 15:01:44 +00:00
|
|
|
json pathDataSlider = pathData["slider"];
|
2021-03-16 21:06:10 +00:00
|
|
|
// lerp between keyframes
|
2021-05-01 15:04:28 +00:00
|
|
|
std::queue<Vec3> route;
|
2021-03-16 21:06:10 +00:00
|
|
|
// initial point
|
2021-04-29 15:01:44 +00:00
|
|
|
json::iterator _point = pathDataSlider.begin(); // iterator
|
2021-03-16 21:06:10 +00:00
|
|
|
auto point = _point.value();
|
2021-05-01 15:04:28 +00:00
|
|
|
Vec3 from = { point["iX"] , point["iY"] , point["iZ"] }; // point A coords
|
2021-05-03 19:29:33 +00:00
|
|
|
int stopTime = point["bStop"] ? SLIDER_STOP_TICKS : 0; // arbitrary stop length
|
2021-03-16 21:06:10 +00:00
|
|
|
// remaining points
|
|
|
|
for (_point++; _point != pathDataSlider.end(); _point++) { // loop through all point Bs
|
|
|
|
point = _point.value();
|
|
|
|
for (int i = 0; i < stopTime + 1; i++) { // repeat point if it's a stop
|
|
|
|
route.push(from); // add point A to the queue
|
2020-12-31 16:26:17 +00:00
|
|
|
}
|
2021-05-01 15:04:28 +00:00
|
|
|
Vec3 to = { point["iX"] , point["iY"] , point["iZ"] }; // point B coords
|
2021-03-16 21:06:10 +00:00
|
|
|
// we may need to change this later; right now, the speed is cut before and after stops (no accel)
|
|
|
|
float curve = 1;
|
|
|
|
if (stopTime > 0) { // point A is a stop
|
|
|
|
curve = 0.375f;//2.0f;
|
2021-05-03 19:29:33 +00:00
|
|
|
} else if (point["bStop"]) { // point B is a stop
|
2021-03-16 21:06:10 +00:00
|
|
|
curve = 0.375f;//0.35f;
|
|
|
|
}
|
2021-03-16 22:29:13 +00:00
|
|
|
Transport::lerp(&route, from, to, SLIDER_SPEED * curve, 1); // lerp from A to B (arbitrary speed)
|
2021-03-16 21:06:10 +00:00
|
|
|
from = to; // update point A
|
2021-05-03 19:29:33 +00:00
|
|
|
stopTime = point["bStop"] ? SLIDER_STOP_TICKS : 0; // set stop ticks for next point A
|
2021-03-16 21:06:10 +00:00
|
|
|
}
|
|
|
|
// Uniform distance calculation
|
|
|
|
int passedDistance = 0;
|
|
|
|
// initial point
|
|
|
|
int pos = 0;
|
2021-05-01 15:04:28 +00:00
|
|
|
Vec3 lastPoint = route.front();
|
2021-03-16 21:06:10 +00:00
|
|
|
route.pop();
|
|
|
|
route.push(lastPoint);
|
|
|
|
for (pos = 1; pos < route.size(); pos++) {
|
2021-05-01 15:04:28 +00:00
|
|
|
Vec3 point = route.front();
|
2021-03-16 21:06:10 +00:00
|
|
|
passedDistance += hypot(point.x - lastPoint.x, point.y - lastPoint.y);
|
|
|
|
if (passedDistance >= SLIDER_GAP_SIZE) { // space them out uniformaly
|
|
|
|
passedDistance -= SLIDER_GAP_SIZE; // step down
|
|
|
|
// spawn a slider
|
2021-10-19 22:30:53 +00:00
|
|
|
Bus* slider = new Bus(0, INSTANCE_OVERWORLD, 1, (*nextId)--);
|
2021-06-20 18:37:37 +00:00
|
|
|
NPCManager::NPCs[slider->id] = slider;
|
2021-10-19 22:30:53 +00:00
|
|
|
NPCManager::updateNPCPosition(slider->id, point.x, point.y, point.z, INSTANCE_OVERWORLD, 0);
|
2021-06-20 18:37:37 +00:00
|
|
|
Transport::NPCQueues[slider->id] = route;
|
2021-03-16 21:06:10 +00:00
|
|
|
}
|
|
|
|
// rotate
|
|
|
|
route.pop();
|
|
|
|
route.push(point);
|
|
|
|
lastPoint = point;
|
|
|
|
}
|
2020-09-14 13:53:48 +00:00
|
|
|
|
2021-05-03 19:29:33 +00:00
|
|
|
// preset npc paths
|
2021-04-29 15:01:44 +00:00
|
|
|
json pathDataNPC = pathData["npc"];
|
|
|
|
for (json::iterator npcPath = pathDataNPC.begin(); npcPath != pathDataNPC.end(); npcPath++) {
|
2021-05-03 19:29:33 +00:00
|
|
|
json pathVal = npcPath.value();
|
|
|
|
|
|
|
|
std::vector<int32_t> targetIDs;
|
|
|
|
std::vector<int32_t> targetTypes;
|
|
|
|
std::vector<Vec3> pathPoints;
|
2021-05-04 17:42:16 +00:00
|
|
|
int speed = pathVal.find("iBaseSpeed") == pathVal.end() ? NPC_DEFAULT_SPEED : (int)pathVal["iBaseSpeed"];
|
|
|
|
int taskID = pathVal.find("iTaskID") == pathVal.end() ? -1 : (int)pathVal["iTaskID"];
|
|
|
|
bool relative = pathVal.find("bRelative") == pathVal.end() ? false : (bool)pathVal["bRelative"];
|
2021-05-09 12:37:36 +00:00
|
|
|
bool loop = pathVal.find("bLoop") == pathVal.end() ? true : (bool)pathVal["bLoop"]; // loop by default
|
2021-05-03 19:29:33 +00:00
|
|
|
|
|
|
|
// target IDs
|
|
|
|
for (json::iterator _tID = pathVal["aNPCIDs"].begin(); _tID != pathVal["aNPCIDs"].end(); _tID++)
|
|
|
|
targetIDs.push_back(_tID.value());
|
|
|
|
// target types
|
|
|
|
for (json::iterator _tType = pathVal["aNPCTypes"].begin(); _tType != pathVal["aNPCTypes"].end(); _tType++)
|
|
|
|
targetTypes.push_back(_tType.value());
|
|
|
|
// points
|
|
|
|
for (json::iterator _point = pathVal["aPoints"].begin(); _point != pathVal["aPoints"].end(); _point++) {
|
|
|
|
json point = _point.value();
|
2021-05-04 17:42:16 +00:00
|
|
|
for (int stopTicks = 0; stopTicks < (int)point["iStopTicks"] + 1; stopTicks++)
|
2021-05-03 19:29:33 +00:00
|
|
|
pathPoints.push_back({point["iX"], point["iY"], point["iZ"]});
|
|
|
|
}
|
|
|
|
|
|
|
|
NPCPath pathTemplate;
|
|
|
|
pathTemplate.targetIDs = targetIDs;
|
|
|
|
pathTemplate.targetTypes = targetTypes;
|
|
|
|
pathTemplate.points = pathPoints;
|
|
|
|
pathTemplate.speed = speed;
|
|
|
|
pathTemplate.isRelative = relative;
|
2021-05-09 12:37:36 +00:00
|
|
|
pathTemplate.isLoop = loop;
|
2021-05-03 19:29:33 +00:00
|
|
|
pathTemplate.escortTaskID = taskID;
|
|
|
|
|
|
|
|
Transport::NPCPaths.push_back(pathTemplate);
|
2021-03-16 21:06:10 +00:00
|
|
|
}
|
2021-05-03 19:29:33 +00:00
|
|
|
std::cout << "[INFO] Loaded " << Transport::NPCPaths.size() << " NPC paths" << std::endl;
|
|
|
|
|
2020-09-09 17:06:22 +00:00
|
|
|
}
|
|
|
|
catch (const std::exception& err) {
|
2021-03-16 21:06:10 +00:00
|
|
|
std::cerr << "[FATAL] Malformed paths.json file! Reason:" << err.what() << std::endl;
|
2020-12-06 04:25:23 +00:00
|
|
|
exit(1);
|
2020-09-09 17:06:22 +00:00
|
|
|
}
|
2021-03-16 21:06:10 +00:00
|
|
|
}
|
2020-09-09 17:06:22 +00:00
|
|
|
|
2021-03-16 21:06:10 +00:00
|
|
|
/*
|
2021-04-29 16:33:17 +00:00
|
|
|
* Load drops data from JSON
|
2021-03-16 21:06:10 +00:00
|
|
|
* This has to be called after reading xdt because it reffers to ItemData!!!
|
|
|
|
*/
|
2021-04-29 16:33:17 +00:00
|
|
|
static void loadDrops(json& dropData) {
|
2020-09-09 19:09:01 +00:00
|
|
|
try {
|
2021-03-28 20:57:43 +00:00
|
|
|
// CrateDropChances
|
2021-04-29 15:01:44 +00:00
|
|
|
json crateDropChances = dropData["CrateDropChances"];
|
|
|
|
for (json::iterator _crateDropChance = crateDropChances.begin(); _crateDropChance != crateDropChances.end(); _crateDropChance++) {
|
2021-03-28 20:57:43 +00:00
|
|
|
auto crateDropChance = _crateDropChance.value();
|
|
|
|
CrateDropChance toAdd = {};
|
|
|
|
|
|
|
|
toAdd.dropChance = (int)crateDropChance["DropChance"];
|
|
|
|
toAdd.dropChanceTotal = (int)crateDropChance["DropChanceTotal"];
|
|
|
|
|
2021-04-29 15:01:44 +00:00
|
|
|
json crateWeights = crateDropChance["CrateTypeDropWeights"];
|
|
|
|
for (json::iterator _crateWeight = crateWeights.begin(); _crateWeight != crateWeights.end(); _crateWeight++)
|
2021-03-29 06:22:23 +00:00
|
|
|
toAdd.crateTypeDropWeights.push_back((int)_crateWeight.value());
|
2021-03-28 20:57:43 +00:00
|
|
|
|
|
|
|
Items::CrateDropChances[(int)crateDropChance["CrateDropChanceID"]] = toAdd;
|
|
|
|
}
|
|
|
|
|
|
|
|
// CrateDropTypes
|
2021-04-29 15:01:44 +00:00
|
|
|
json crateDropTypes = dropData["CrateDropTypes"];
|
|
|
|
for (json::iterator _crateDropType = crateDropTypes.begin(); _crateDropType != crateDropTypes.end(); _crateDropType++) {
|
2021-03-28 20:57:43 +00:00
|
|
|
auto crateDropType = _crateDropType.value();
|
|
|
|
std::vector<int> toAdd;
|
|
|
|
|
2021-04-29 15:01:44 +00:00
|
|
|
json crateIds = crateDropType["CrateIDs"];
|
|
|
|
for (json::iterator _crateId = crateIds.begin(); _crateId != crateIds.end(); _crateId++)
|
2021-03-28 20:57:43 +00:00
|
|
|
toAdd.push_back((int)_crateId.value());
|
|
|
|
|
|
|
|
Items::CrateDropTypes[(int)crateDropType["CrateDropTypeID"]] = toAdd;
|
|
|
|
}
|
|
|
|
|
|
|
|
// MiscDropChances
|
2021-04-29 15:01:44 +00:00
|
|
|
json miscDropChances = dropData["MiscDropChances"];
|
|
|
|
for (json::iterator _miscDropChance = miscDropChances.begin(); _miscDropChance != miscDropChances.end(); _miscDropChance++) {
|
2021-03-28 20:57:43 +00:00
|
|
|
auto miscDropChance = _miscDropChance.value();
|
|
|
|
|
|
|
|
Items::MiscDropChances[(int)miscDropChance["MiscDropChanceID"]] = {
|
|
|
|
(int)miscDropChance["PotionDropChance"],
|
|
|
|
(int)miscDropChance["PotionDropChanceTotal"],
|
|
|
|
(int)miscDropChance["BoostDropChance"],
|
|
|
|
(int)miscDropChance["BoostDropChanceTotal"],
|
|
|
|
(int)miscDropChance["TaroDropChance"],
|
|
|
|
(int)miscDropChance["TaroDropChanceTotal"],
|
|
|
|
(int)miscDropChance["FMDropChance"],
|
|
|
|
(int)miscDropChance["FMDropChanceTotal"]
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
// MiscDropTypes
|
2021-04-29 15:01:44 +00:00
|
|
|
json miscDropTypes = dropData["MiscDropTypes"];
|
|
|
|
for (json::iterator _miscDropType = miscDropTypes.begin(); _miscDropType != miscDropTypes.end(); _miscDropType++) {
|
2021-03-28 20:57:43 +00:00
|
|
|
auto miscDropType = _miscDropType.value();
|
|
|
|
|
|
|
|
Items::MiscDropTypes[(int)miscDropType["MiscDropTypeID"]] = {
|
|
|
|
(int)miscDropType["PotionAmount"],
|
|
|
|
(int)miscDropType["BoostAmount"],
|
|
|
|
(int)miscDropType["TaroAmount"],
|
|
|
|
(int)miscDropType["FMAmount"]
|
|
|
|
};
|
2020-09-13 20:26:16 +00:00
|
|
|
}
|
|
|
|
|
2021-03-16 21:06:10 +00:00
|
|
|
// MobDrops
|
2021-04-29 15:01:44 +00:00
|
|
|
json mobDrops = dropData["MobDrops"];
|
|
|
|
for (json::iterator _mobDrop = mobDrops.begin(); _mobDrop != mobDrops.end(); _mobDrop++) {
|
2021-03-28 20:57:43 +00:00
|
|
|
auto mobDrop = _mobDrop.value();
|
|
|
|
|
|
|
|
Items::MobDrops[(int)mobDrop["MobDropID"]] = {
|
|
|
|
(int)mobDrop["CrateDropChanceID"],
|
|
|
|
(int)mobDrop["CrateDropTypeID"],
|
|
|
|
(int)mobDrop["MiscDropChanceID"],
|
|
|
|
(int)mobDrop["MiscDropTypeID"],
|
|
|
|
};
|
|
|
|
}
|
2020-09-09 19:09:01 +00:00
|
|
|
|
2021-04-04 10:45:57 +00:00
|
|
|
// Events
|
2021-04-29 15:01:44 +00:00
|
|
|
json events = dropData["Events"];
|
|
|
|
for (json::iterator _event = events.begin(); _event != events.end(); _event++) {
|
2021-04-04 10:45:57 +00:00
|
|
|
auto event = _event.value();
|
|
|
|
|
|
|
|
Items::EventToDropMap[(int)event["EventID"]] = (int)event["MobDropID"];
|
|
|
|
}
|
|
|
|
|
2021-04-03 06:34:20 +00:00
|
|
|
// Mobs
|
2021-04-29 15:01:44 +00:00
|
|
|
json mobs = dropData["Mobs"];
|
|
|
|
for (json::iterator _mob = mobs.begin(); _mob != mobs.end(); _mob++) {
|
2021-04-03 06:34:20 +00:00
|
|
|
auto mob = _mob.value();
|
|
|
|
|
|
|
|
Items::MobToDropMap[(int)mob["MobID"]] = (int)mob["MobDropID"];
|
|
|
|
}
|
|
|
|
|
2021-03-28 20:57:43 +00:00
|
|
|
// RarityWeights
|
2021-04-29 15:01:44 +00:00
|
|
|
json rarityWeights = dropData["RarityWeights"];
|
|
|
|
for (json::iterator _rarityWeightsObject = rarityWeights.begin(); _rarityWeightsObject != rarityWeights.end(); _rarityWeightsObject++) {
|
2021-03-28 20:57:43 +00:00
|
|
|
auto rarityWeightsObject = _rarityWeightsObject.value();
|
|
|
|
std::vector<int> toAdd;
|
2020-09-09 22:31:09 +00:00
|
|
|
|
2021-04-29 15:01:44 +00:00
|
|
|
json weights = rarityWeightsObject["Weights"];
|
|
|
|
for (json::iterator _weight = weights.begin(); _weight != weights.end(); _weight++)
|
2021-03-28 20:57:43 +00:00
|
|
|
toAdd.push_back((int)_weight.value());
|
|
|
|
|
|
|
|
Items::RarityWeights[(int)rarityWeightsObject["RarityWeightID"]] = toAdd;
|
2020-09-09 19:09:01 +00:00
|
|
|
}
|
|
|
|
|
2021-03-30 02:48:31 +00:00
|
|
|
// ItemSets
|
2021-04-29 15:01:44 +00:00
|
|
|
json itemSets = dropData["ItemSets"];
|
|
|
|
for (json::iterator _itemSet = itemSets.begin(); _itemSet != itemSets.end(); _itemSet++) {
|
2021-03-30 02:48:31 +00:00
|
|
|
auto itemSet = _itemSet.value();
|
|
|
|
ItemSet toAdd = {};
|
2020-09-13 22:54:47 +00:00
|
|
|
|
2021-03-30 02:48:31 +00:00
|
|
|
toAdd.ignoreRarity = (bool)itemSet["IgnoreRarity"];
|
|
|
|
toAdd.ignoreGender = (bool)itemSet["IgnoreGender"];
|
|
|
|
toAdd.defaultItemWeight = (int)itemSet["DefaultItemWeight"];
|
2021-03-28 20:57:43 +00:00
|
|
|
|
2021-04-29 15:01:44 +00:00
|
|
|
json alterRarityMap = itemSet["AlterRarityMap"];
|
|
|
|
for (json::iterator _alterRarityMapEntry = alterRarityMap.begin(); _alterRarityMapEntry != alterRarityMap.end(); _alterRarityMapEntry++)
|
2021-03-30 02:48:31 +00:00
|
|
|
toAdd.alterRarityMap[std::atoi(_alterRarityMapEntry.key().c_str())] = (int)_alterRarityMapEntry.value();
|
2021-03-28 20:57:43 +00:00
|
|
|
|
2021-04-29 15:01:44 +00:00
|
|
|
json alterGenderMap = itemSet["AlterGenderMap"];
|
|
|
|
for (json::iterator _alterGenderMapEntry = alterGenderMap.begin(); _alterGenderMapEntry != alterGenderMap.end(); _alterGenderMapEntry++)
|
2021-03-30 02:48:31 +00:00
|
|
|
toAdd.alterGenderMap[std::atoi(_alterGenderMapEntry.key().c_str())] = (int)_alterGenderMapEntry.value();
|
2021-03-28 20:57:43 +00:00
|
|
|
|
2021-04-29 15:01:44 +00:00
|
|
|
json alterItemWeightMap = itemSet["AlterItemWeightMap"];
|
|
|
|
for (json::iterator _alterItemWeightMapEntry = alterItemWeightMap.begin(); _alterItemWeightMapEntry != alterItemWeightMap.end(); _alterItemWeightMapEntry++)
|
2021-03-30 02:48:31 +00:00
|
|
|
toAdd.alterItemWeightMap[std::atoi(_alterItemWeightMapEntry.key().c_str())] = (int)_alterItemWeightMapEntry.value();
|
2021-03-28 20:57:43 +00:00
|
|
|
|
2021-04-29 15:01:44 +00:00
|
|
|
json itemReferenceIds = itemSet["ItemReferenceIDs"];
|
|
|
|
for (json::iterator itemReferenceId = itemReferenceIds.begin(); itemReferenceId != itemReferenceIds.end(); itemReferenceId++)
|
2021-03-30 02:48:31 +00:00
|
|
|
toAdd.itemReferenceIds.push_back((int)itemReferenceId.value());
|
2021-03-28 20:57:43 +00:00
|
|
|
|
2021-03-30 02:48:31 +00:00
|
|
|
Items::ItemSets[(int)itemSet["ItemSetID"]] = toAdd;
|
2020-09-14 04:25:14 +00:00
|
|
|
}
|
|
|
|
|
2021-03-16 21:06:10 +00:00
|
|
|
// Crates
|
2021-04-29 15:01:44 +00:00
|
|
|
json crates = dropData["Crates"];
|
|
|
|
for (json::iterator _crate = crates.begin(); _crate != crates.end(); _crate++) {
|
2021-03-16 21:06:10 +00:00
|
|
|
auto crate = _crate.value();
|
2020-09-23 19:44:27 +00:00
|
|
|
|
2021-03-28 20:57:43 +00:00
|
|
|
Items::Crates[(int)crate["CrateID"]] = {
|
2021-03-30 02:48:31 +00:00
|
|
|
(int)crate["ItemSetID"],
|
2021-03-28 20:57:43 +00:00
|
|
|
(int)crate["RarityWeightID"]
|
|
|
|
};
|
|
|
|
}
|
2020-09-23 19:44:27 +00:00
|
|
|
|
2021-03-29 06:22:23 +00:00
|
|
|
// ItemReferences
|
2021-04-29 15:01:44 +00:00
|
|
|
json itemReferences = dropData["ItemReferences"];
|
|
|
|
for (json::iterator _itemReference = itemReferences.begin(); _itemReference != itemReferences.end(); _itemReference++) {
|
2021-03-29 06:22:23 +00:00
|
|
|
auto itemReference = _itemReference.value();
|
2020-09-13 22:54:47 +00:00
|
|
|
|
2021-03-29 06:22:23 +00:00
|
|
|
int itemReferenceId = (int)itemReference["ItemReferenceID"];
|
|
|
|
int itemId = (int)itemReference["ItemID"];
|
|
|
|
int type = (int)itemReference["Type"];
|
|
|
|
|
|
|
|
// validate and fetch relevant fields as they're loaded
|
|
|
|
auto key = std::make_pair(itemId, type);
|
|
|
|
if (Items::ItemData.find(key) == Items::ItemData.end()) {
|
|
|
|
std::cout << "[WARN] Item-Type pair (" << key.first << ", " << key.second << ") specified by item reference "
|
|
|
|
<< itemReferenceId << " was not found, skipping..." << std::endl;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
Items::Item& item = Items::ItemData[key];
|
|
|
|
|
|
|
|
Items::ItemReferences[itemReferenceId] = {
|
|
|
|
itemId,
|
|
|
|
type,
|
|
|
|
item.rarity,
|
|
|
|
item.gender
|
2021-03-28 20:57:43 +00:00
|
|
|
};
|
2020-09-13 22:54:47 +00:00
|
|
|
}
|
|
|
|
|
2021-03-16 21:06:10 +00:00
|
|
|
#ifdef ACADEMY
|
2021-03-28 20:57:43 +00:00
|
|
|
// NanoCapsules
|
2021-04-29 15:01:44 +00:00
|
|
|
json capsules = dropData["NanoCapsules"];
|
|
|
|
for (json::iterator _capsule = capsules.begin(); _capsule != capsules.end(); _capsule++) {
|
2021-03-16 21:06:10 +00:00
|
|
|
auto capsule = _capsule.value();
|
2021-03-28 20:57:43 +00:00
|
|
|
Items::NanoCapsules[(int)capsule["CrateID"]] = (int)capsule["Nano"];
|
2020-09-16 00:30:01 +00:00
|
|
|
}
|
2021-03-16 21:06:10 +00:00
|
|
|
#endif
|
2020-10-24 20:28:35 +00:00
|
|
|
|
2021-03-16 21:06:10 +00:00
|
|
|
// Racing rewards
|
2021-04-29 15:01:44 +00:00
|
|
|
json racing = dropData["Racing"];
|
|
|
|
for (json::iterator _race = racing.begin(); _race != racing.end(); _race++) {
|
2021-03-16 21:06:10 +00:00
|
|
|
auto race = _race.value();
|
|
|
|
int raceEPID = race["EPID"];
|
2020-10-24 20:28:35 +00:00
|
|
|
|
2021-03-16 21:06:10 +00:00
|
|
|
// find the instance data corresponding to the EPID
|
|
|
|
int EPMap = -1;
|
2021-03-16 22:29:13 +00:00
|
|
|
for (auto it = Racing::EPData.begin(); it != Racing::EPData.end(); it++) {
|
2021-03-16 21:06:10 +00:00
|
|
|
if (it->second.EPID == raceEPID) {
|
|
|
|
EPMap = it->first;
|
|
|
|
}
|
|
|
|
}
|
2020-10-24 20:28:35 +00:00
|
|
|
|
2021-03-16 21:06:10 +00:00
|
|
|
if (EPMap == -1) { // not found
|
|
|
|
std::cout << "[WARN] EP with ID " << raceEPID << " not found, skipping" << std::endl;
|
|
|
|
continue;
|
|
|
|
}
|
2020-11-07 23:22:48 +00:00
|
|
|
|
2021-03-16 21:06:10 +00:00
|
|
|
// time limit isn't stored in the XDT, so we include it in the reward table instead
|
2021-03-16 22:29:13 +00:00
|
|
|
Racing::EPData[EPMap].maxTime = race["TimeLimit"];
|
2021-03-16 21:06:10 +00:00
|
|
|
|
|
|
|
// score cutoffs
|
|
|
|
std::vector<int> rankScores;
|
2021-04-29 15:01:44 +00:00
|
|
|
for (json::iterator _rankScore = race["RankScores"].begin(); _rankScore != race["RankScores"].end(); _rankScore++) {
|
2021-03-16 21:06:10 +00:00
|
|
|
rankScores.push_back((int)_rankScore.value());
|
2020-11-07 23:22:48 +00:00
|
|
|
}
|
|
|
|
|
2021-03-16 21:06:10 +00:00
|
|
|
// reward IDs for each rank
|
|
|
|
std::vector<int> rankRewards;
|
2021-04-29 15:01:44 +00:00
|
|
|
for (json::iterator _rankReward = race["Rewards"].begin(); _rankReward != race["Rewards"].end(); _rankReward++) {
|
2021-03-16 21:06:10 +00:00
|
|
|
rankRewards.push_back((int)_rankReward.value());
|
|
|
|
}
|
2020-11-07 23:22:48 +00:00
|
|
|
|
2021-03-16 21:06:10 +00:00
|
|
|
if (rankScores.size() != 5 || rankScores.size() != rankRewards.size()) {
|
|
|
|
char buff[255];
|
|
|
|
sprintf(buff, "Race in EP %d doesn't have exactly 5 score/reward pairs", raceEPID);
|
|
|
|
throw TableException(std::string(buff));
|
|
|
|
}
|
2020-11-28 14:16:14 +00:00
|
|
|
|
2021-03-16 22:29:13 +00:00
|
|
|
Racing::EPRewards[raceEPID] = std::make_pair(rankScores, rankRewards);
|
2020-11-28 14:16:14 +00:00
|
|
|
}
|
|
|
|
|
2021-03-16 22:29:13 +00:00
|
|
|
std::cout << "[INFO] Loaded rewards for " << Racing::EPRewards.size() << " IZ races" << std::endl;
|
2020-11-28 14:16:14 +00:00
|
|
|
|
2021-03-28 20:57:43 +00:00
|
|
|
// CodeItems
|
2021-04-29 15:01:44 +00:00
|
|
|
json codes = dropData["CodeItems"];
|
|
|
|
for (json::iterator _code = codes.begin(); _code != codes.end(); _code++) {
|
2021-03-28 20:57:43 +00:00
|
|
|
auto code = _code.value();
|
|
|
|
std::string codeStr = code["Code"];
|
|
|
|
std::vector<std::pair<int32_t, int32_t>> itemVector;
|
|
|
|
|
2021-04-29 15:01:44 +00:00
|
|
|
json itemReferenceIds = code["ItemReferenceIDs"];
|
|
|
|
for (json::iterator _itemReferenceId = itemReferenceIds.begin(); _itemReferenceId != itemReferenceIds.end(); _itemReferenceId++) {
|
2021-03-29 06:22:23 +00:00
|
|
|
int itemReferenceId = (int)_itemReferenceId.value();
|
|
|
|
|
|
|
|
// validate and convert here
|
|
|
|
if (Items::ItemReferences.find(itemReferenceId) == Items::ItemReferences.end()) {
|
|
|
|
std::cout << "[WARN] Item reference " << itemReferenceId << " for code "
|
|
|
|
<< codeStr << " was not found, skipping..." << std::endl;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
// no need to further check whether this is a real item or not, we already did this!
|
|
|
|
ItemReference& itemReference = Items::ItemReferences[itemReferenceId];
|
|
|
|
itemVector.push_back(std::make_pair(itemReference.itemId, itemReference.type));
|
|
|
|
}
|
2021-03-28 20:57:43 +00:00
|
|
|
|
|
|
|
Items::CodeItems[codeStr] = itemVector;
|
|
|
|
}
|
|
|
|
|
|
|
|
std::cout << "[INFO] Loaded " << Items::Crates.size() << " Crates containing "
|
2021-03-29 06:22:23 +00:00
|
|
|
<< Items::ItemReferences.size() << " unique items" << std::endl;
|
2021-03-28 20:57:43 +00:00
|
|
|
|
2020-09-09 17:06:22 +00:00
|
|
|
}
|
|
|
|
catch (const std::exception& err) {
|
2021-03-16 21:06:10 +00:00
|
|
|
std::cerr << "[FATAL] Malformed drops.json file! Reason:" << err.what() << std::endl;
|
2020-12-06 04:25:23 +00:00
|
|
|
exit(1);
|
2020-09-09 17:06:22 +00:00
|
|
|
}
|
2021-03-16 21:06:10 +00:00
|
|
|
}
|
2020-09-16 23:43:48 +00:00
|
|
|
|
2021-04-29 16:33:17 +00:00
|
|
|
/*
|
|
|
|
* Load eggs from JSON
|
|
|
|
*/
|
|
|
|
static void loadEggs(json& eggData, int32_t* nextId) {
|
2020-09-16 23:43:48 +00:00
|
|
|
try {
|
2021-03-16 21:06:10 +00:00
|
|
|
// EggTypes
|
2021-04-29 15:01:44 +00:00
|
|
|
json eggTypes = eggData["EggTypes"];
|
|
|
|
for (json::iterator _eggType = eggTypes.begin(); _eggType != eggTypes.end(); _eggType++) {
|
2021-03-16 21:06:10 +00:00
|
|
|
auto eggType = _eggType.value();
|
|
|
|
EggType toAdd = {};
|
|
|
|
toAdd.dropCrateId = (int)eggType["DropCrateId"];
|
|
|
|
toAdd.effectId = (int)eggType["EffectId"];
|
|
|
|
toAdd.duration = (int)eggType["Duration"];
|
|
|
|
toAdd.regen= (int)eggType["Regen"];
|
2021-03-17 21:28:24 +00:00
|
|
|
Eggs::EggTypes[(int)eggType["Id"]] = toAdd;
|
2021-03-16 21:06:10 +00:00
|
|
|
}
|
2020-09-16 23:43:48 +00:00
|
|
|
|
2021-03-16 21:06:10 +00:00
|
|
|
// Egg instances
|
|
|
|
auto eggs = eggData["Eggs"];
|
2021-03-22 16:53:46 +00:00
|
|
|
int eggCount = 0;
|
2021-03-16 21:06:10 +00:00
|
|
|
for (auto _egg = eggs.begin(); _egg != eggs.end(); _egg++) {
|
|
|
|
auto egg = _egg.value();
|
2021-04-26 17:50:51 +00:00
|
|
|
int id = (*nextId)--;
|
2021-03-16 21:06:10 +00:00
|
|
|
uint64_t instanceID = egg.find("iMapNum") == egg.end() ? INSTANCE_OVERWORLD : (int)egg["iMapNum"];
|
2020-09-16 23:43:48 +00:00
|
|
|
|
2021-10-19 22:30:53 +00:00
|
|
|
Egg* addEgg = new Egg(instanceID, (int)egg["iType"], id, false);
|
2021-03-16 21:06:10 +00:00
|
|
|
NPCManager::NPCs[id] = addEgg;
|
2021-03-22 16:53:46 +00:00
|
|
|
eggCount++;
|
2021-03-16 21:06:10 +00:00
|
|
|
NPCManager::updateNPCPosition(id, (int)egg["iX"], (int)egg["iY"], (int)egg["iZ"], instanceID, 0);
|
2020-11-24 00:28:22 +00:00
|
|
|
}
|
2020-11-15 07:06:29 +00:00
|
|
|
|
2021-03-22 16:53:46 +00:00
|
|
|
std::cout << "[INFO] Loaded " << eggCount << " eggs" <<std::endl;
|
2020-12-31 01:44:02 +00:00
|
|
|
|
2021-03-16 21:06:10 +00:00
|
|
|
}
|
|
|
|
catch (const std::exception& err) {
|
|
|
|
std::cerr << "[FATAL] Malformed eggs.json file! Reason:" << err.what() << std::endl;
|
|
|
|
exit(1);
|
|
|
|
}
|
|
|
|
}
|
2020-11-24 00:28:22 +00:00
|
|
|
|
2021-04-29 16:33:17 +00:00
|
|
|
/*
|
2021-05-05 00:39:43 +00:00
|
|
|
* Load gruntwork output, if it exists
|
2021-04-29 16:33:17 +00:00
|
|
|
*/
|
2021-05-05 00:39:43 +00:00
|
|
|
static void loadGruntworkPre(json& gruntwork, int32_t* nextId) {
|
2023-03-13 04:58:49 +00:00
|
|
|
if (gruntwork.is_null())
|
|
|
|
return;
|
2021-05-05 00:39:43 +00:00
|
|
|
|
|
|
|
try {
|
|
|
|
auto paths = gruntwork["paths"];
|
|
|
|
for (auto _path = paths.begin(); _path != paths.end(); _path++) {
|
|
|
|
auto path = _path.value();
|
|
|
|
|
|
|
|
std::vector<int32_t> targetIDs;
|
2021-05-05 17:36:53 +00:00
|
|
|
std::vector<int32_t> targetTypes; // target types are not exportable from gw, but load them anyway
|
2021-05-05 00:39:43 +00:00
|
|
|
std::vector<Vec3> pathPoints;
|
2021-12-31 01:40:32 +00:00
|
|
|
int speed = path.find("iBaseSpeed") == path.end() ? NPC_DEFAULT_SPEED : (int)path["iBaseSpeed"];
|
|
|
|
int taskID = path.find("iTaskID") == path.end() ? -1 : (int)path["iTaskID"];
|
|
|
|
bool relative = path.find("bRelative") == path.end() ? false : (bool)path["bRelative"];
|
|
|
|
bool loop = path.find("bLoop") == path.end() ? true : (bool)path["bLoop"]; // loop by default
|
2021-05-05 00:39:43 +00:00
|
|
|
|
|
|
|
// target IDs
|
|
|
|
for (json::iterator _tID = path["aNPCIDs"].begin(); _tID != path["aNPCIDs"].end(); _tID++)
|
|
|
|
targetIDs.push_back(_tID.value());
|
2021-05-05 17:36:53 +00:00
|
|
|
// target types
|
|
|
|
for (json::iterator _tType = path["aNPCTypes"].begin(); _tType != path["aNPCTypes"].end(); _tType++)
|
|
|
|
targetTypes.push_back(_tType.value());
|
2021-05-05 00:39:43 +00:00
|
|
|
// points
|
|
|
|
for (json::iterator _point = path["aPoints"].begin(); _point != path["aPoints"].end(); _point++) {
|
|
|
|
json point = _point.value();
|
|
|
|
for (int stopTicks = 0; stopTicks < (int)point["iStopTicks"] + 1; stopTicks++)
|
|
|
|
pathPoints.push_back({ point["iX"], point["iY"], point["iZ"] });
|
|
|
|
}
|
|
|
|
|
|
|
|
NPCPath pathTemplate;
|
|
|
|
pathTemplate.targetIDs = targetIDs;
|
2021-05-05 17:36:53 +00:00
|
|
|
pathTemplate.targetTypes = targetTypes;
|
2021-05-05 00:39:43 +00:00
|
|
|
pathTemplate.points = pathPoints;
|
|
|
|
pathTemplate.speed = speed;
|
|
|
|
pathTemplate.isRelative = relative;
|
|
|
|
pathTemplate.escortTaskID = taskID;
|
2021-05-09 12:37:36 +00:00
|
|
|
pathTemplate.isLoop = loop;
|
2021-05-05 00:39:43 +00:00
|
|
|
|
|
|
|
Transport::NPCPaths.push_back(pathTemplate);
|
2021-05-05 17:36:53 +00:00
|
|
|
TableData::FinishedNPCPaths.push_back(pathTemplate); // keep in gruntwork
|
2021-05-05 00:39:43 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
std::cout << "[INFO] Loaded gruntwork.json (pre)" << std::endl;
|
|
|
|
}
|
|
|
|
catch (const std::exception& err) {
|
|
|
|
std::cerr << "[FATAL] Malformed gruntwork.json file! Reason:" << err.what() << std::endl;
|
|
|
|
exit(1);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void loadGruntworkPost(json& gruntwork, int32_t* nextId) {
|
2023-03-13 04:58:49 +00:00
|
|
|
if (gruntwork.is_null())
|
|
|
|
return;
|
2021-03-16 21:06:10 +00:00
|
|
|
|
2021-04-29 16:33:17 +00:00
|
|
|
try {
|
2021-03-16 21:06:10 +00:00
|
|
|
// skyway paths
|
|
|
|
auto skyway = gruntwork["skyway"];
|
|
|
|
for (auto _route = skyway.begin(); _route != skyway.end(); _route++) {
|
|
|
|
auto route = _route.value();
|
2021-05-01 15:04:28 +00:00
|
|
|
std::vector<Vec3> points;
|
2021-03-16 21:06:10 +00:00
|
|
|
|
|
|
|
for (auto _point = route["points"].begin(); _point != route["points"].end(); _point++) {
|
|
|
|
auto point = _point.value();
|
2021-05-01 15:04:28 +00:00
|
|
|
points.push_back(Vec3{point["x"], point["y"], point["z"]});
|
2021-03-16 21:06:10 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
RunningSkywayRoutes[(int)route["iRouteID"]] = points;
|
|
|
|
}
|
|
|
|
|
|
|
|
// npc rotations
|
|
|
|
auto npcRot = gruntwork["rotations"];
|
|
|
|
for (auto _rot = npcRot.begin(); _rot != npcRot.end(); _rot++) {
|
|
|
|
int32_t npcID = _rot.value()["iNPCID"];
|
|
|
|
int angle = _rot.value()["iAngle"];
|
|
|
|
if (NPCManager::NPCs.find(npcID) == NPCManager::NPCs.end())
|
|
|
|
continue; // NPC not found
|
|
|
|
BaseNPC* npc = NPCManager::NPCs[npcID];
|
2021-06-20 18:37:37 +00:00
|
|
|
npc->angle = angle;
|
2021-03-16 21:06:10 +00:00
|
|
|
|
|
|
|
RunningNPCRotations[npcID] = angle;
|
|
|
|
}
|
|
|
|
|
|
|
|
// npc map numbers
|
|
|
|
auto npcMap = gruntwork["instances"];
|
|
|
|
for (auto _map = npcMap.begin(); _map != npcMap.end(); _map++) {
|
|
|
|
int32_t npcID = _map.value()["iNPCID"];
|
|
|
|
uint64_t instanceID = _map.value()["iMapNum"];
|
|
|
|
if (NPCManager::NPCs.find(npcID) == NPCManager::NPCs.end())
|
|
|
|
continue; // NPC not found
|
|
|
|
BaseNPC* npc = NPCManager::NPCs[npcID];
|
2021-06-20 18:37:37 +00:00
|
|
|
NPCManager::updateNPCPosition(npc->id, npc->x, npc->y,
|
|
|
|
npc->z, instanceID, npc->angle);
|
2021-03-16 21:06:10 +00:00
|
|
|
|
|
|
|
RunningNPCMapNumbers[npcID] = instanceID;
|
|
|
|
}
|
|
|
|
|
|
|
|
// mobs
|
|
|
|
auto mobs = gruntwork["mobs"];
|
|
|
|
for (auto _mob = mobs.begin(); _mob != mobs.end(); _mob++) {
|
|
|
|
auto mob = _mob.value();
|
|
|
|
BaseNPC *npc;
|
2021-04-26 17:50:51 +00:00
|
|
|
int id = (*nextId)--;
|
2021-03-16 21:06:10 +00:00
|
|
|
uint64_t instanceID = mob.find("iMapNum") == mob.end() ? INSTANCE_OVERWORLD : (int)mob["iMapNum"];
|
|
|
|
|
2023-06-22 00:27:28 +00:00
|
|
|
ensureValidNPCType((int)mob["iNPCType"], settings::GRUNTWORKJSON);
|
|
|
|
|
2021-03-16 21:06:10 +00:00
|
|
|
if (NPCManager::NPCData[(int)mob["iNPCType"]]["m_iTeam"] == 2) {
|
|
|
|
npc = new Mob(mob["iX"], mob["iY"], mob["iZ"], instanceID, mob["iNPCType"],
|
|
|
|
NPCManager::NPCData[(int)mob["iNPCType"]], id);
|
|
|
|
|
|
|
|
// re-enable respawning
|
|
|
|
((Mob*)npc)->summoned = false;
|
|
|
|
} else {
|
2021-10-19 22:30:53 +00:00
|
|
|
npc = new BaseNPC(mob["iAngle"], instanceID, mob["iNPCType"], id);
|
2021-03-16 21:06:10 +00:00
|
|
|
}
|
|
|
|
|
2021-06-20 18:37:37 +00:00
|
|
|
NPCManager::NPCs[npc->id] = npc;
|
|
|
|
RunningMobs[npc->id] = npc;
|
|
|
|
NPCManager::updateNPCPosition(npc->id, mob["iX"], mob["iY"], mob["iZ"], instanceID, mob["iAngle"]);
|
2021-03-16 21:06:10 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// mob groups
|
|
|
|
auto groups = gruntwork["groups"];
|
|
|
|
for (auto _group = groups.begin(); _group != groups.end(); _group++) {
|
|
|
|
auto leader = _group.value();
|
2023-06-22 00:27:28 +00:00
|
|
|
|
|
|
|
ensureValidNPCType((int)leader["iNPCType"], settings::GRUNTWORKJSON);
|
|
|
|
|
2021-03-16 21:06:10 +00:00
|
|
|
auto td = NPCManager::NPCData[(int)leader["iNPCType"]];
|
|
|
|
uint64_t instanceID = leader.find("iMapNum") == leader.end() ? INSTANCE_OVERWORLD : (int)leader["iMapNum"];
|
|
|
|
|
|
|
|
Mob* tmp = new Mob(leader["iX"], leader["iY"], leader["iZ"], leader["iAngle"], instanceID, leader["iNPCType"], td, *nextId);
|
|
|
|
|
|
|
|
// re-enable respawning
|
|
|
|
((Mob*)tmp)->summoned = false;
|
|
|
|
|
|
|
|
NPCManager::NPCs[*nextId] = tmp;
|
|
|
|
NPCManager::updateNPCPosition(*nextId, leader["iX"], leader["iY"], leader["iZ"], instanceID, leader["iAngle"]);
|
|
|
|
|
|
|
|
tmp->groupLeader = *nextId;
|
|
|
|
|
2021-04-26 17:50:51 +00:00
|
|
|
(*nextId)--;
|
2020-11-24 00:28:22 +00:00
|
|
|
|
2021-03-16 21:06:10 +00:00
|
|
|
auto followers = leader["aFollowers"];
|
2020-11-24 00:28:22 +00:00
|
|
|
if (followers.size() < 5) {
|
|
|
|
int followerCount = 0;
|
2021-04-29 15:01:44 +00:00
|
|
|
for (json::iterator _fol = followers.begin(); _fol != followers.end(); _fol++) {
|
2020-11-24 00:28:22 +00:00
|
|
|
auto follower = _fol.value();
|
2023-06-22 00:27:28 +00:00
|
|
|
|
|
|
|
ensureValidNPCType((int)follower["iNPCType"], settings::GRUNTWORKJSON);
|
|
|
|
|
2020-11-24 00:28:22 +00:00
|
|
|
auto tdFol = NPCManager::NPCData[(int)follower["iNPCType"]];
|
2021-03-16 21:06:10 +00:00
|
|
|
Mob* tmpFol = new Mob((int)leader["iX"] + (int)follower["iOffsetX"], (int)leader["iY"] + (int)follower["iOffsetY"], leader["iZ"], leader["iAngle"], instanceID, follower["iNPCType"], tdFol, *nextId);
|
2020-11-24 00:28:22 +00:00
|
|
|
|
2021-03-16 21:06:10 +00:00
|
|
|
// re-enable respawning
|
|
|
|
((Mob*)tmp)->summoned = false;
|
|
|
|
|
|
|
|
NPCManager::NPCs[*nextId] = tmpFol;
|
|
|
|
NPCManager::updateNPCPosition(*nextId, (int)leader["iX"] + (int)follower["iOffsetX"], (int)leader["iY"] + (int)follower["iOffsetY"], leader["iZ"], instanceID, leader["iAngle"]);
|
2020-11-24 00:28:22 +00:00
|
|
|
|
|
|
|
tmpFol->offsetX = follower.find("iOffsetX") == follower.end() ? 0 : (int)follower["iOffsetX"];
|
|
|
|
tmpFol->offsetY = follower.find("iOffsetY") == follower.end() ? 0 : (int)follower["iOffsetY"];
|
2021-06-20 18:37:37 +00:00
|
|
|
tmpFol->groupLeader = tmp->id;
|
2021-03-16 21:06:10 +00:00
|
|
|
tmp->groupMember[followerCount++] = *nextId;
|
2020-11-24 00:28:22 +00:00
|
|
|
|
2021-04-26 17:50:51 +00:00
|
|
|
(*nextId)--;
|
2020-11-24 00:28:22 +00:00
|
|
|
}
|
|
|
|
}
|
2021-03-16 21:06:10 +00:00
|
|
|
else {
|
|
|
|
std::cout << "[WARN] Mob group leader with ID " << *nextId << " has too many followers (" << followers.size() << ")\n";
|
|
|
|
}
|
|
|
|
|
2021-06-20 18:37:37 +00:00
|
|
|
RunningGroups[tmp->id] = tmp; // store as running
|
2020-09-16 23:43:48 +00:00
|
|
|
}
|
|
|
|
|
2021-03-16 21:06:10 +00:00
|
|
|
auto eggs = gruntwork["eggs"];
|
|
|
|
for (auto _egg = eggs.begin(); _egg != eggs.end(); _egg++) {
|
|
|
|
auto egg = _egg.value();
|
2021-04-26 17:50:51 +00:00
|
|
|
int id = (*nextId)--;
|
2021-03-16 21:06:10 +00:00
|
|
|
uint64_t instanceID = egg.find("iMapNum") == egg.end() ? INSTANCE_OVERWORLD : (int)egg["iMapNum"];
|
|
|
|
|
2021-10-19 22:30:53 +00:00
|
|
|
Egg* addEgg = new Egg(instanceID, (int)egg["iType"], id, false);
|
2021-03-16 21:06:10 +00:00
|
|
|
NPCManager::NPCs[id] = addEgg;
|
|
|
|
NPCManager::updateNPCPosition(id, (int)egg["iX"], (int)egg["iY"], (int)egg["iZ"], instanceID, 0);
|
|
|
|
RunningEggs[id] = addEgg;
|
|
|
|
}
|
|
|
|
|
2021-05-05 00:39:43 +00:00
|
|
|
std::cout << "[INFO] Loaded gruntwork.json (post)" << std::endl;
|
2020-09-16 23:43:48 +00:00
|
|
|
}
|
|
|
|
catch (const std::exception& err) {
|
2021-03-16 21:06:10 +00:00
|
|
|
std::cerr << "[FATAL] Malformed gruntwork.json file! Reason:" << err.what() << std::endl;
|
2020-12-06 04:25:23 +00:00
|
|
|
exit(1);
|
2020-09-16 23:43:48 +00:00
|
|
|
}
|
2021-03-16 21:06:10 +00:00
|
|
|
}
|
2020-09-24 22:36:25 +00:00
|
|
|
|
2021-04-29 16:33:17 +00:00
|
|
|
/*
|
|
|
|
* Load NPCs from JSON
|
|
|
|
*/
|
2021-04-29 17:34:53 +00:00
|
|
|
static void loadNPCs(json& npcData) {
|
2020-12-12 21:21:55 +00:00
|
|
|
try {
|
|
|
|
npcData = npcData["NPCs"];
|
2021-04-29 15:01:44 +00:00
|
|
|
for (json::iterator _npc = npcData.begin(); _npc != npcData.end(); _npc++) {
|
2020-12-12 21:21:55 +00:00
|
|
|
auto npc = _npc.value();
|
2021-04-29 17:34:53 +00:00
|
|
|
int npcID = std::strtol(_npc.key().c_str(), nullptr, 10); // parse ID string to integer
|
|
|
|
npcID += NPC_ID_OFFSET;
|
2021-04-24 15:36:33 +00:00
|
|
|
int instanceID = npc.find("iMapNum") == npc.end() ? INSTANCE_OVERWORLD : (int)npc["iMapNum"];
|
2021-05-05 07:52:51 +00:00
|
|
|
int type = (int)npc["iNPCType"];
|
2023-06-22 00:27:28 +00:00
|
|
|
|
|
|
|
ensureValidNPCType(type, settings::NPCJSON);
|
|
|
|
|
2021-03-16 21:06:10 +00:00
|
|
|
#ifdef ACADEMY
|
|
|
|
// do not spawn NPCs in the future
|
2021-04-29 17:34:53 +00:00
|
|
|
if (npc["iX"] > 512000 && npc["iY"] < 256000)
|
2021-03-16 21:06:10 +00:00
|
|
|
continue;
|
|
|
|
#endif
|
2021-10-19 22:30:53 +00:00
|
|
|
BaseNPC* tmp = new BaseNPC(npc["iAngle"], instanceID, type, npcID);
|
2020-12-12 21:21:55 +00:00
|
|
|
|
2021-04-29 17:34:53 +00:00
|
|
|
NPCManager::NPCs[npcID] = tmp;
|
|
|
|
NPCManager::updateNPCPosition(npcID, npc["iX"], npc["iY"], npc["iZ"], instanceID, npc["iAngle"]);
|
2020-12-12 21:21:55 +00:00
|
|
|
|
2021-05-05 07:52:51 +00:00
|
|
|
if (type == 641 || type == 642)
|
2021-04-24 15:36:33 +00:00
|
|
|
NPCManager::RespawnPoints.push_back({ npc["iX"], npc["iY"], ((int)npc["iZ"]) + RESURRECT_HEIGHT, instanceID });
|
2021-05-03 22:46:43 +00:00
|
|
|
|
|
|
|
// see if any paths target this NPC
|
2021-05-06 01:17:06 +00:00
|
|
|
NPCPath* npcPath = Transport::findApplicablePath(npcID, type);
|
2021-05-03 22:46:43 +00:00
|
|
|
if (npcPath != nullptr) {
|
|
|
|
//std::cout << "[INFO] Found path for NPC " << npcID << std::endl;
|
2021-05-06 01:22:11 +00:00
|
|
|
Transport::constructPathNPC(npcID, npcPath);
|
2021-05-03 22:46:43 +00:00
|
|
|
}
|
2020-12-12 21:21:55 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
catch (const std::exception& err) {
|
2021-03-16 21:06:10 +00:00
|
|
|
std::cerr << "[FATAL] Malformed NPCs.json file! Reason:" << err.what() << std::endl;
|
2020-12-12 21:21:55 +00:00
|
|
|
exit(1);
|
|
|
|
}
|
2021-04-29 16:33:17 +00:00
|
|
|
}
|
2020-12-12 21:21:55 +00:00
|
|
|
|
2021-04-29 16:33:17 +00:00
|
|
|
/*
|
|
|
|
* Load mobs from JSON
|
|
|
|
*/
|
|
|
|
static void loadMobs(json& npcData, int32_t* nextId) {
|
2021-03-16 21:06:10 +00:00
|
|
|
try {
|
2021-04-29 16:33:17 +00:00
|
|
|
json groupData = npcData["groups"];
|
2021-03-16 21:06:10 +00:00
|
|
|
npcData = npcData["mobs"];
|
|
|
|
|
|
|
|
// single mobs
|
2021-04-29 15:01:44 +00:00
|
|
|
for (json::iterator _npc = npcData.begin(); _npc != npcData.end(); _npc++) {
|
2021-03-16 21:06:10 +00:00
|
|
|
auto npc = _npc.value();
|
2021-04-29 17:34:53 +00:00
|
|
|
int npcID = std::strtol(_npc.key().c_str(), nullptr, 10); // parse ID string to integer
|
|
|
|
npcID += MOB_ID_OFFSET;
|
2021-05-05 07:52:51 +00:00
|
|
|
int type = (int)npc["iNPCType"];
|
2023-06-22 00:27:28 +00:00
|
|
|
|
|
|
|
ensureValidNPCType(type, settings::MOBJSON);
|
|
|
|
|
2021-05-05 07:52:51 +00:00
|
|
|
auto td = NPCManager::NPCData[type];
|
2021-03-16 21:06:10 +00:00
|
|
|
uint64_t instanceID = npc.find("iMapNum") == npc.end() ? INSTANCE_OVERWORLD : (int)npc["iMapNum"];
|
|
|
|
|
|
|
|
#ifdef ACADEMY
|
|
|
|
// do not spawn NPCs in the future
|
2021-04-29 17:34:53 +00:00
|
|
|
if (npc["iX"] > 512000 && npc["iY"] < 256000)
|
2021-03-16 21:06:10 +00:00
|
|
|
continue;
|
|
|
|
#endif
|
2020-10-07 17:29:59 +00:00
|
|
|
|
2021-04-29 17:34:53 +00:00
|
|
|
Mob* tmp = new Mob(npc["iX"], npc["iY"], npc["iZ"], npc["iAngle"], instanceID, npc["iNPCType"], td, npcID);
|
2021-03-16 21:06:10 +00:00
|
|
|
|
2021-04-29 17:34:53 +00:00
|
|
|
NPCManager::NPCs[npcID] = tmp;
|
|
|
|
NPCManager::updateNPCPosition(npcID, npc["iX"], npc["iY"], npc["iZ"], instanceID, npc["iAngle"]);
|
2021-05-03 22:46:43 +00:00
|
|
|
|
|
|
|
// see if any paths target this mob
|
2021-05-06 01:17:06 +00:00
|
|
|
NPCPath* npcPath = Transport::findApplicablePath(npcID, npc["iNPCType"]);
|
2021-05-03 22:46:43 +00:00
|
|
|
if (npcPath != nullptr) {
|
|
|
|
//std::cout << "[INFO] Found path for mob " << npcID << std::endl;
|
2021-05-06 01:22:11 +00:00
|
|
|
Transport::constructPathNPC(npcID, npcPath);
|
2021-05-03 22:46:43 +00:00
|
|
|
}
|
2020-10-07 17:29:59 +00:00
|
|
|
}
|
|
|
|
|
2020-11-25 16:09:05 +00:00
|
|
|
// mob groups
|
2021-04-29 17:34:53 +00:00
|
|
|
// single mobs (have static IDs)
|
2021-04-29 15:01:44 +00:00
|
|
|
for (json::iterator _group = groupData.begin(); _group != groupData.end(); _group++) {
|
2020-11-25 16:09:05 +00:00
|
|
|
auto leader = _group.value();
|
2021-04-29 17:34:53 +00:00
|
|
|
int leadID = std::strtol(_group.key().c_str(), nullptr, 10); // parse ID string to integer
|
2023-06-22 00:27:28 +00:00
|
|
|
|
2021-04-29 17:34:53 +00:00
|
|
|
leadID += MOB_GROUP_ID_OFFSET;
|
2023-06-22 00:27:28 +00:00
|
|
|
ensureValidNPCType(leader["iNPCType"], settings::MOBJSON);
|
|
|
|
|
2020-11-25 16:09:05 +00:00
|
|
|
auto td = NPCManager::NPCData[(int)leader["iNPCType"]];
|
|
|
|
uint64_t instanceID = leader.find("iMapNum") == leader.end() ? INSTANCE_OVERWORLD : (int)leader["iMapNum"];
|
2021-03-16 21:06:10 +00:00
|
|
|
auto followers = leader["aFollowers"];
|
2020-11-25 16:09:05 +00:00
|
|
|
|
2021-03-16 21:06:10 +00:00
|
|
|
#ifdef ACADEMY
|
|
|
|
// do not spawn NPCs in the future
|
2021-04-29 17:34:53 +00:00
|
|
|
if (leader["iX"] > 512000 && leader["iY"] < 256000)
|
2021-03-16 21:06:10 +00:00
|
|
|
continue;
|
|
|
|
#endif
|
2020-11-25 16:09:05 +00:00
|
|
|
|
2021-04-29 17:34:53 +00:00
|
|
|
Mob* tmp = new Mob(leader["iX"], leader["iY"], leader["iZ"], leader["iAngle"], instanceID, leader["iNPCType"], td, leadID);
|
2020-11-25 16:09:05 +00:00
|
|
|
|
2021-04-29 17:34:53 +00:00
|
|
|
NPCManager::NPCs[leadID] = tmp;
|
|
|
|
NPCManager::updateNPCPosition(leadID, leader["iX"], leader["iY"], leader["iZ"], instanceID, leader["iAngle"]);
|
2020-11-25 16:09:05 +00:00
|
|
|
|
2021-05-03 22:46:43 +00:00
|
|
|
// see if any paths target this group leader
|
2021-05-06 01:17:06 +00:00
|
|
|
NPCPath* npcPath = Transport::findApplicablePath(leadID, leader["iNPCType"]);
|
2021-05-03 22:46:43 +00:00
|
|
|
if (npcPath != nullptr) {
|
|
|
|
//std::cout << "[INFO] Found path for mob " << leadID << std::endl;
|
2021-05-06 01:22:11 +00:00
|
|
|
Transport::constructPathNPC(leadID, npcPath);
|
2021-05-03 22:46:43 +00:00
|
|
|
}
|
|
|
|
|
2021-04-29 17:34:53 +00:00
|
|
|
tmp->groupLeader = leadID;
|
2020-11-25 16:09:05 +00:00
|
|
|
|
2021-04-29 17:34:53 +00:00
|
|
|
// followers (have dynamic IDs)
|
2020-11-25 16:09:05 +00:00
|
|
|
if (followers.size() < 5) {
|
|
|
|
int followerCount = 0;
|
2021-04-29 15:01:44 +00:00
|
|
|
for (json::iterator _fol = followers.begin(); _fol != followers.end(); _fol++) {
|
2020-11-25 16:09:05 +00:00
|
|
|
auto follower = _fol.value();
|
2023-06-22 00:27:28 +00:00
|
|
|
|
|
|
|
ensureValidNPCType(follower["iNPCType"], settings::MOBJSON);
|
|
|
|
|
2020-11-25 16:09:05 +00:00
|
|
|
auto tdFol = NPCManager::NPCData[(int)follower["iNPCType"]];
|
2021-04-29 16:33:17 +00:00
|
|
|
Mob* tmpFol = new Mob((int)leader["iX"] + (int)follower["iOffsetX"], (int)leader["iY"] + (int)follower["iOffsetY"], leader["iZ"], leader["iAngle"], instanceID, follower["iNPCType"], tdFol, *nextId);
|
2020-11-25 16:09:05 +00:00
|
|
|
|
2021-04-29 16:33:17 +00:00
|
|
|
NPCManager::NPCs[*nextId] = tmpFol;
|
|
|
|
NPCManager::updateNPCPosition(*nextId, (int)leader["iX"] + (int)follower["iOffsetX"], (int)leader["iY"] + (int)follower["iOffsetY"], leader["iZ"], instanceID, leader["iAngle"]);
|
2020-11-25 16:09:05 +00:00
|
|
|
|
|
|
|
tmpFol->offsetX = follower.find("iOffsetX") == follower.end() ? 0 : (int)follower["iOffsetX"];
|
|
|
|
tmpFol->offsetY = follower.find("iOffsetY") == follower.end() ? 0 : (int)follower["iOffsetY"];
|
2021-06-20 18:37:37 +00:00
|
|
|
tmpFol->groupLeader = tmp->id;
|
2021-04-29 16:33:17 +00:00
|
|
|
tmp->groupMember[followerCount++] = *nextId;
|
2020-11-25 16:09:05 +00:00
|
|
|
|
2021-04-29 16:33:17 +00:00
|
|
|
(*nextId)--;
|
2020-11-25 16:09:05 +00:00
|
|
|
}
|
2021-04-29 16:33:17 +00:00
|
|
|
}
|
|
|
|
else {
|
2021-04-29 17:34:53 +00:00
|
|
|
std::cout << "[WARN] Mob group leader with ID " << leadID << " has too many followers (" << followers.size() << ")\n";
|
2020-11-25 16:09:05 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-04-29 16:33:17 +00:00
|
|
|
std::cout << "[INFO] Loaded " << NPCManager::NPCs.size() << " NPCs" << std::endl;
|
2021-03-16 21:06:10 +00:00
|
|
|
}
|
|
|
|
catch (const std::exception& err) {
|
|
|
|
std::cerr << "[FATAL] Malformed mobs.json file! Reason:" << err.what() << std::endl;
|
|
|
|
exit(1);
|
|
|
|
}
|
2021-04-29 16:33:17 +00:00
|
|
|
}
|
2020-11-09 09:34:11 +00:00
|
|
|
|
2021-05-01 15:52:45 +00:00
|
|
|
/*
|
2021-05-01 22:01:38 +00:00
|
|
|
* Transform `base` based on the value of `patch`.
|
|
|
|
* Parameters must be of the same type and must not be null.
|
|
|
|
* Array <- Array: All elements in patch array get added to base array.
|
|
|
|
* Object <- Object: Combine properties recursively and save to base.
|
|
|
|
* All other types <- Same type: Base value gets overwritten by patch value.
|
2021-05-01 15:52:45 +00:00
|
|
|
*/
|
2021-05-01 22:01:38 +00:00
|
|
|
static void patchJSON(json* base, json* patch) {
|
|
|
|
if (patch->is_null() || base->is_null())
|
|
|
|
return; // no nulls allowed!!
|
|
|
|
|
2021-05-02 00:50:48 +00:00
|
|
|
if ((json::value_t)(*base) != (json::value_t)(*patch)) {
|
|
|
|
// verify type mismatch. unsigned <-> integer is ok.
|
|
|
|
if (!((base->is_number_integer() && patch->is_number_unsigned())
|
|
|
|
|| (base->is_number_unsigned() && patch->is_number_integer())))
|
|
|
|
return;
|
|
|
|
}
|
2021-05-01 22:01:38 +00:00
|
|
|
|
|
|
|
// case 1: type is array
|
|
|
|
if (patch->is_array()) {
|
|
|
|
// loop through all array elements
|
|
|
|
for (json::iterator _element = patch->begin(); _element != patch->end(); _element++)
|
|
|
|
base->push_back(*_element); // add element to base
|
|
|
|
}
|
|
|
|
// case 2: type is object
|
|
|
|
else if (patch->is_object()) {
|
|
|
|
// loop through all object properties
|
|
|
|
for (json::iterator _prop = patch->begin(); _prop != patch->end(); _prop++) {
|
|
|
|
std::string key = _prop.key(); // static identifier
|
|
|
|
json* valLoc = &(*_prop); // pointer to json data
|
|
|
|
|
2021-05-02 04:14:35 +00:00
|
|
|
// special casing for forced replacement.
|
|
|
|
// the ! is stripped, then the property is forcibly replaced without a recursive call
|
|
|
|
// that means no type checking, so use at your own risk
|
|
|
|
if (key.c_str()[0] == '!') {
|
|
|
|
key = key.substr(1, key.length() - 1);
|
|
|
|
(*base)[key] = *valLoc;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2021-05-01 22:01:38 +00:00
|
|
|
// search for matching property in base object
|
|
|
|
json::iterator _match = base->find(key);
|
|
|
|
if (_match != base->end()) {
|
|
|
|
// match found
|
|
|
|
if (valLoc->is_null()) // prop value is null; erase match
|
|
|
|
base->erase(key);
|
|
|
|
else { // combine objects
|
|
|
|
json* match = &(*_match);
|
|
|
|
patchJSON(match, valLoc);
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
// no match found; add the property to the base object
|
|
|
|
(*base)[key] = *valLoc;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
// case 3: all other types
|
|
|
|
else {
|
|
|
|
*base = *patch; // complete overwrite
|
|
|
|
}
|
2021-04-29 17:34:53 +00:00
|
|
|
}
|
|
|
|
|
2021-04-29 16:33:17 +00:00
|
|
|
void TableData::init() {
|
|
|
|
int32_t nextId = INT32_MAX; // next dynamic ID to hand out
|
2021-03-16 21:06:10 +00:00
|
|
|
|
2021-04-29 16:33:17 +00:00
|
|
|
// base JSON tables
|
2021-05-01 15:24:53 +00:00
|
|
|
json xdt, paths, drops, eggs, npcs, mobs, gruntwork;
|
2021-05-01 15:52:45 +00:00
|
|
|
std::pair<json*, std::string> tables[7] = {
|
2021-05-02 03:17:18 +00:00
|
|
|
std::make_pair(&xdt, settings::XDTJSON),
|
|
|
|
std::make_pair(&paths, settings::PATHJSON),
|
|
|
|
std::make_pair(&drops, settings::DROPSJSON),
|
|
|
|
std::make_pair(&eggs, settings::EGGSJSON),
|
|
|
|
std::make_pair(&npcs, settings::NPCJSON),
|
|
|
|
std::make_pair(&mobs, settings::MOBJSON),
|
|
|
|
std::make_pair(&gruntwork, settings::GRUNTWORKJSON)
|
2021-05-01 15:52:45 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
// load JSON data into tables
|
|
|
|
for (int i = 0; i < 7; i++) {
|
|
|
|
std::pair<json*, std::string>& table = tables[i];
|
2023-03-13 20:42:59 +00:00
|
|
|
|
|
|
|
// scope for fstream
|
|
|
|
{
|
|
|
|
std::ifstream fstream;
|
|
|
|
fstream.open(settings::TDATADIR + "/" + table.second); // open file
|
|
|
|
|
|
|
|
// did we fail to open the file?
|
|
|
|
if (fstream.fail()) {
|
|
|
|
// gruntwork isn't critical
|
|
|
|
if (table.first == &gruntwork)
|
|
|
|
continue;
|
|
|
|
|
2021-11-06 05:01:14 +00:00
|
|
|
std::cerr << "[FATAL] Critical tdata file missing: " << table.second << std::endl;
|
2021-05-01 15:52:45 +00:00
|
|
|
exit(1);
|
|
|
|
}
|
2023-03-13 20:42:59 +00:00
|
|
|
|
|
|
|
// is the file empty?
|
|
|
|
if (fstream.peek() == std::ifstream::traits_type::eof()) {
|
|
|
|
// tolerate empty gruntwork file
|
|
|
|
if (table.first == &gruntwork) {
|
|
|
|
std::cout << "[WARN] The gruntwork file is empty" << std::endl;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
std::cerr << "[FATAL] Critical tdata file is empty: " << table.second << std::endl;
|
|
|
|
exit(1);
|
|
|
|
}
|
|
|
|
|
|
|
|
// load file contents into table
|
|
|
|
fstream >> *table.first;
|
2021-05-01 15:52:45 +00:00
|
|
|
}
|
2021-04-29 16:33:17 +00:00
|
|
|
|
2021-05-07 19:29:18 +00:00
|
|
|
// patching: load each patch directory specified in the config file
|
|
|
|
|
|
|
|
// split config field into individual patch entries
|
|
|
|
std::stringstream ss(settings::ENABLEDPATCHES);
|
|
|
|
std::istream_iterator<std::string> begin(ss);
|
|
|
|
std::istream_iterator<std::string> end;
|
|
|
|
|
2021-05-02 01:19:36 +00:00
|
|
|
json patch;
|
2021-05-07 19:29:18 +00:00
|
|
|
for (auto it = begin; it != end; it++) {
|
2021-05-02 01:19:36 +00:00
|
|
|
// this is the theoretical path of a corresponding patch for this file
|
2021-05-07 19:29:18 +00:00
|
|
|
std::string patchModuleName = *it;
|
|
|
|
std::string patchFile = settings::PATCHDIR + patchModuleName + "/" + table.second;
|
|
|
|
try {
|
2023-03-13 20:42:59 +00:00
|
|
|
std::ifstream fstream;
|
2021-05-02 01:19:36 +00:00
|
|
|
fstream.open(patchFile);
|
|
|
|
fstream >> patch; // load into temporary json object
|
2021-05-07 19:29:18 +00:00
|
|
|
std::cout << "[INFO] Patching " << patchFile << std::endl;
|
2021-05-02 01:19:36 +00:00
|
|
|
patchJSON(table.first, &patch); // patch
|
2021-05-07 19:29:18 +00:00
|
|
|
} catch (const std::exception& err) {
|
|
|
|
// no-op
|
2021-05-02 01:19:36 +00:00
|
|
|
}
|
|
|
|
}
|
2021-05-01 22:01:38 +00:00
|
|
|
}
|
2021-04-29 16:33:17 +00:00
|
|
|
|
|
|
|
// fetch data from patched tables and load them appropriately
|
|
|
|
// note: the order of these is important
|
2021-05-02 03:17:18 +00:00
|
|
|
std::cout << "[INFO] Loading tabledata..." << std::endl;
|
2021-04-29 16:33:17 +00:00
|
|
|
loadXDT(xdt);
|
2021-05-05 00:39:43 +00:00
|
|
|
loadGruntworkPre(gruntwork, &nextId);
|
2021-05-03 19:29:33 +00:00
|
|
|
loadPaths(paths, &nextId);
|
2021-04-29 17:34:53 +00:00
|
|
|
loadNPCs(npcs);
|
2021-04-29 16:33:17 +00:00
|
|
|
loadMobs(mobs, &nextId);
|
|
|
|
loadDrops(drops);
|
|
|
|
loadEggs(eggs, &nextId);
|
2021-05-05 00:39:43 +00:00
|
|
|
loadGruntworkPost(gruntwork, &nextId);
|
2021-03-16 21:06:10 +00:00
|
|
|
|
|
|
|
NPCManager::nextId = nextId;
|
2020-10-06 19:53:21 +00:00
|
|
|
}
|
|
|
|
|
2021-04-29 16:33:17 +00:00
|
|
|
/*
|
|
|
|
* Write gruntwork output to file
|
|
|
|
*/
|
2020-10-06 19:53:21 +00:00
|
|
|
void TableData::flush() {
|
2021-11-06 05:01:14 +00:00
|
|
|
std::ofstream file(settings::TDATADIR + "/" + settings::GRUNTWORKJSON);
|
2021-04-29 15:01:44 +00:00
|
|
|
json gruntwork;
|
2020-10-06 19:53:21 +00:00
|
|
|
|
|
|
|
for (auto& pair : RunningSkywayRoutes) {
|
2021-04-29 15:01:44 +00:00
|
|
|
json route;
|
2020-10-06 19:53:21 +00:00
|
|
|
|
|
|
|
route["iRouteID"] = (int)pair.first;
|
2020-10-12 01:53:01 +00:00
|
|
|
route["iMonkeySpeed"] = 1500;
|
2020-10-06 19:53:21 +00:00
|
|
|
|
|
|
|
std::cout << "serializing mss route " << (int)pair.first << std::endl;
|
2021-05-01 15:04:28 +00:00
|
|
|
for (Vec3& point : pair.second) {
|
2021-04-29 15:01:44 +00:00
|
|
|
json tmp;
|
2020-10-06 19:53:21 +00:00
|
|
|
|
|
|
|
tmp["x"] = point.x;
|
|
|
|
tmp["y"] = point.y;
|
|
|
|
tmp["z"] = point.z;
|
|
|
|
|
|
|
|
route["points"].push_back(tmp);
|
|
|
|
}
|
|
|
|
|
|
|
|
gruntwork["skyway"].push_back(route);
|
|
|
|
}
|
|
|
|
|
2020-10-06 21:59:12 +00:00
|
|
|
for (auto& pair : RunningNPCRotations) {
|
2021-04-29 15:01:44 +00:00
|
|
|
json rotation;
|
2020-10-06 21:59:12 +00:00
|
|
|
|
|
|
|
rotation["iNPCID"] = (int)pair.first;
|
|
|
|
rotation["iAngle"] = pair.second;
|
|
|
|
|
|
|
|
gruntwork["rotations"].push_back(rotation);
|
|
|
|
}
|
|
|
|
|
2020-10-12 01:53:01 +00:00
|
|
|
for (auto& pair : RunningNPCMapNumbers) {
|
2021-04-29 15:01:44 +00:00
|
|
|
json mapNumber;
|
2020-10-12 01:53:01 +00:00
|
|
|
|
|
|
|
mapNumber["iNPCID"] = (int)pair.first;
|
|
|
|
mapNumber["iMapNum"] = pair.second;
|
|
|
|
|
|
|
|
gruntwork["instances"].push_back(mapNumber);
|
|
|
|
}
|
|
|
|
|
2020-10-07 17:29:59 +00:00
|
|
|
for (auto& pair : RunningMobs) {
|
2021-04-29 15:01:44 +00:00
|
|
|
json mob;
|
2020-10-19 01:45:58 +00:00
|
|
|
BaseNPC *npc = pair.second;
|
2020-10-07 17:29:59 +00:00
|
|
|
|
|
|
|
if (NPCManager::NPCs.find(pair.first) == NPCManager::NPCs.end())
|
|
|
|
continue;
|
|
|
|
|
2020-12-14 15:00:07 +00:00
|
|
|
int x, y, z;
|
2021-06-20 18:12:40 +00:00
|
|
|
if (npc->kind == EntityType::MOB) {
|
2020-10-19 01:45:58 +00:00
|
|
|
Mob *m = (Mob*)npc;
|
|
|
|
x = m->spawnX;
|
|
|
|
y = m->spawnY;
|
|
|
|
z = m->spawnZ;
|
|
|
|
} else {
|
2021-04-14 00:57:24 +00:00
|
|
|
x = npc->x;
|
|
|
|
y = npc->y;
|
|
|
|
z = npc->z;
|
2020-10-19 01:45:58 +00:00
|
|
|
}
|
|
|
|
|
2020-10-07 17:29:59 +00:00
|
|
|
// NOTE: this format deviates slightly from the one in mobs.json
|
2021-06-20 18:37:37 +00:00
|
|
|
mob["iNPCType"] = (int)npc->type;
|
2020-10-19 01:45:58 +00:00
|
|
|
mob["iX"] = x;
|
|
|
|
mob["iY"] = y;
|
|
|
|
mob["iZ"] = z;
|
|
|
|
mob["iMapNum"] = MAPNUM(npc->instanceID);
|
2020-10-07 17:29:59 +00:00
|
|
|
// this is a bit imperfect, since this is a live angle, not a spawn angle so it'll change often, but eh
|
2021-06-20 18:37:37 +00:00
|
|
|
mob["iAngle"] = npc->angle;
|
2020-10-07 17:29:59 +00:00
|
|
|
|
2020-11-25 15:41:10 +00:00
|
|
|
// it's called mobs, but really it's everything
|
|
|
|
gruntwork["mobs"].push_back(mob);
|
|
|
|
}
|
|
|
|
|
|
|
|
for (auto& pair : RunningGroups) {
|
2021-04-29 15:01:44 +00:00
|
|
|
json mob;
|
2020-11-25 15:41:10 +00:00
|
|
|
BaseNPC* npc = pair.second;
|
|
|
|
|
|
|
|
if (NPCManager::NPCs.find(pair.first) == NPCManager::NPCs.end())
|
|
|
|
continue;
|
|
|
|
|
2020-12-14 15:00:07 +00:00
|
|
|
int x, y, z;
|
2020-11-25 15:41:10 +00:00
|
|
|
std::vector<Mob*> followers;
|
2021-06-20 18:12:40 +00:00
|
|
|
if (npc->kind == EntityType::MOB) {
|
2020-11-25 15:41:10 +00:00
|
|
|
Mob* m = (Mob*)npc;
|
|
|
|
x = m->spawnX;
|
|
|
|
y = m->spawnY;
|
|
|
|
z = m->spawnZ;
|
2021-06-20 18:37:37 +00:00
|
|
|
if (m->groupLeader != m->id) { // make sure this is a leader
|
2020-11-25 15:41:10 +00:00
|
|
|
std::cout << "[WARN] Non-leader mob found in running groups; ignoring\n";
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
// add follower data to vector; go until OOB or until follower ID is 0
|
|
|
|
for (int i = 0; i < 4 && m->groupMember[i] > 0; i++) {
|
2021-06-20 18:12:40 +00:00
|
|
|
if (NPCManager::NPCs.find(m->groupMember[i]) == NPCManager::NPCs.end() || NPCManager::NPCs[m->groupMember[i]]->kind != EntityType::MOB) {
|
2020-11-25 15:41:10 +00:00
|
|
|
std::cout << "[WARN] Follower with ID " << m->groupMember[i] << " not found; skipping\n";
|
|
|
|
continue;
|
|
|
|
}
|
2021-04-07 00:43:43 +00:00
|
|
|
followers.push_back((Mob*)NPCManager::NPCs[m->groupMember[i]]);
|
2020-11-25 15:41:10 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
else {
|
2021-04-14 00:57:24 +00:00
|
|
|
x = npc->x;
|
|
|
|
y = npc->y;
|
|
|
|
z = npc->z;
|
2020-11-25 15:41:10 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// NOTE: this format deviates slightly from the one in mobs.json
|
2021-06-20 18:37:37 +00:00
|
|
|
mob["iNPCType"] = (int)npc->type;
|
2020-11-25 15:41:10 +00:00
|
|
|
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
|
2021-06-20 18:37:37 +00:00
|
|
|
mob["iAngle"] = npc->angle;
|
2020-11-25 15:41:10 +00:00
|
|
|
|
|
|
|
// followers
|
|
|
|
while (followers.size() > 0) {
|
|
|
|
Mob* follower = followers.back();
|
|
|
|
followers.pop_back(); // remove from vector
|
|
|
|
|
|
|
|
// populate JSON entry
|
2021-04-29 15:01:44 +00:00
|
|
|
json fol;
|
2021-06-20 18:37:37 +00:00
|
|
|
fol["iNPCType"] = follower->type;
|
2020-11-25 15:41:10 +00:00
|
|
|
fol["iOffsetX"] = follower->offsetX;
|
|
|
|
fol["iOffsetY"] = follower->offsetY;
|
|
|
|
|
|
|
|
mob["aFollowers"].push_back(fol); // add to follower array
|
2020-11-15 18:19:34 +00:00
|
|
|
}
|
|
|
|
|
2020-10-19 01:45:58 +00:00
|
|
|
// it's called mobs, but really it's everything
|
2020-11-25 15:41:10 +00:00
|
|
|
gruntwork["groups"].push_back(mob);
|
2020-10-07 17:29:59 +00:00
|
|
|
}
|
|
|
|
|
2020-11-08 08:42:49 +00:00
|
|
|
for (auto& pair : RunningEggs) {
|
2021-04-29 15:01:44 +00:00
|
|
|
json egg;
|
2020-11-08 08:42:49 +00:00
|
|
|
BaseNPC* npc = pair.second;
|
|
|
|
|
2021-03-22 16:53:46 +00:00
|
|
|
if (NPCManager::NPCs.find(pair.first) == NPCManager::NPCs.end())
|
2020-11-08 08:42:49 +00:00
|
|
|
continue;
|
2021-03-22 16:53:46 +00:00
|
|
|
// we can trust that if it exists, it probably is indeed an egg
|
|
|
|
|
2021-04-14 00:57:24 +00:00
|
|
|
egg["iX"] = npc->x;
|
|
|
|
egg["iY"] = npc->y;
|
|
|
|
egg["iZ"] = npc->z;
|
2020-11-09 09:34:11 +00:00
|
|
|
int mapnum = MAPNUM(npc->instanceID);
|
|
|
|
if (mapnum != 0)
|
|
|
|
egg["iMapNum"] = mapnum;
|
2021-06-20 18:37:37 +00:00
|
|
|
egg["iType"] = npc->type;
|
2020-11-08 08:42:49 +00:00
|
|
|
|
|
|
|
gruntwork["eggs"].push_back(egg);
|
|
|
|
}
|
|
|
|
|
2021-05-05 00:23:06 +00:00
|
|
|
for (auto& path : FinishedNPCPaths) {
|
|
|
|
json pathObj;
|
|
|
|
json points;
|
2021-05-05 17:36:53 +00:00
|
|
|
json targetIDs;
|
|
|
|
json targetTypes;
|
2021-05-05 00:23:06 +00:00
|
|
|
|
|
|
|
for (Vec3& coord : path.points) {
|
|
|
|
json point;
|
|
|
|
point["iX"] = coord.x;
|
|
|
|
point["iY"] = coord.y;
|
|
|
|
point["iZ"] = coord.z;
|
|
|
|
point["iStopTicks"] = 0;
|
|
|
|
points.push_back(point);
|
|
|
|
}
|
|
|
|
|
|
|
|
for (int32_t tID : path.targetIDs)
|
2021-05-05 17:36:53 +00:00
|
|
|
targetIDs.push_back(tID);
|
|
|
|
for (int32_t tType : path.targetTypes)
|
|
|
|
targetTypes.push_back(tType);
|
2021-05-05 00:23:06 +00:00
|
|
|
|
|
|
|
pathObj["iBaseSpeed"] = path.speed;
|
|
|
|
pathObj["iTaskID"] = path.escortTaskID;
|
|
|
|
pathObj["bRelative"] = path.isRelative;
|
|
|
|
pathObj["aPoints"] = points;
|
2021-05-09 12:37:36 +00:00
|
|
|
pathObj["bLoop"] = path.isLoop;
|
2021-05-05 17:36:53 +00:00
|
|
|
|
|
|
|
// don't write 'null' if there aren't any targets
|
|
|
|
if(targetIDs.size() > 0)
|
|
|
|
pathObj["aNPCIDs"] = targetIDs;
|
|
|
|
if (targetTypes.size() > 0)
|
|
|
|
pathObj["aNPCTypes"] = targetTypes;
|
2021-05-05 00:23:06 +00:00
|
|
|
|
|
|
|
gruntwork["paths"].push_back(pathObj);
|
|
|
|
}
|
|
|
|
|
2020-10-06 19:53:21 +00:00
|
|
|
file << gruntwork << std::endl;
|
|
|
|
}
|