2020-08-19 22:21:35 +00:00
|
|
|
#include "NPCManager.hpp"
|
2020-09-09 01:15:25 +00:00
|
|
|
#include "ItemManager.hpp"
|
2020-08-20 21:43:48 +00:00
|
|
|
#include "settings.hpp"
|
2020-09-16 23:43:48 +00:00
|
|
|
#include "MobManager.hpp"
|
2020-10-12 23:29:00 +00:00
|
|
|
#include "MissionManager.hpp"
|
2020-10-13 03:42:47 +00:00
|
|
|
#include "ChunkManager.hpp"
|
2020-10-22 08:23:12 +00:00
|
|
|
#include "NanoManager.hpp"
|
2020-11-08 08:42:49 +00:00
|
|
|
#include "TableData.hpp"
|
2020-11-13 03:20:51 +00:00
|
|
|
#include "GroupManager.hpp"
|
2020-12-28 16:51:57 +00:00
|
|
|
#include "RacingManager.hpp"
|
2021-03-13 02:09:36 +00:00
|
|
|
#include "Vendor.hpp"
|
2021-03-13 20:22:29 +00:00
|
|
|
#include "Abilities.hpp"
|
2020-08-20 21:43:48 +00:00
|
|
|
|
|
|
|
#include <cmath>
|
|
|
|
#include <algorithm>
|
|
|
|
#include <list>
|
2020-08-21 22:14:11 +00:00
|
|
|
#include <fstream>
|
2020-08-25 01:34:53 +00:00
|
|
|
#include <vector>
|
2020-09-24 22:36:25 +00:00
|
|
|
#include <assert.h>
|
2020-10-11 03:12:12 +00:00
|
|
|
#include <limits.h>
|
2020-08-21 22:14:11 +00:00
|
|
|
|
2021-03-12 17:50:21 +00:00
|
|
|
#include "JSON.hpp"
|
2020-08-20 21:43:48 +00:00
|
|
|
|
2020-09-16 23:43:48 +00:00
|
|
|
std::map<int32_t, BaseNPC*> NPCManager::NPCs;
|
2020-08-23 16:26:25 +00:00
|
|
|
std::map<int32_t, WarpLocation> NPCManager::Warps;
|
2020-08-25 01:34:53 +00:00
|
|
|
std::vector<WarpLocation> NPCManager::RespawnPoints;
|
2020-10-22 09:28:18 +00:00
|
|
|
/// sock, CBFlag -> until
|
2020-10-22 09:09:50 +00:00
|
|
|
std::map<std::pair<CNSocket*, int32_t>, time_t> NPCManager::EggBuffs;
|
2020-10-24 19:48:55 +00:00
|
|
|
std::unordered_map<int, EggType> NPCManager::EggTypes;
|
|
|
|
std::unordered_map<int, Egg*> NPCManager::Eggs;
|
2020-09-24 22:36:25 +00:00
|
|
|
nlohmann::json NPCManager::NPCData;
|
2020-08-19 22:21:35 +00:00
|
|
|
|
2020-11-08 08:42:49 +00:00
|
|
|
|
|
|
|
|
2020-09-24 22:36:25 +00:00
|
|
|
/*
|
|
|
|
* Initialized at the end of TableData::init().
|
|
|
|
* This allows us to summon and kill mobs in arbitrary order without
|
|
|
|
* NPC ID collisions.
|
|
|
|
*/
|
|
|
|
int32_t NPCManager::nextId;
|
2020-09-18 21:24:15 +00:00
|
|
|
|
2020-08-19 22:21:35 +00:00
|
|
|
void NPCManager::init() {
|
2020-08-25 02:28:42 +00:00
|
|
|
REGISTER_SHARD_PACKET(P_CL2FE_REQ_PC_WARP_USE_NPC, npcWarpHandler);
|
2020-09-25 05:35:27 +00:00
|
|
|
REGISTER_SHARD_PACKET(P_CL2FE_REQ_PC_TIME_TO_GO_WARP, npcWarpTimeMachine);
|
2020-08-25 02:28:42 +00:00
|
|
|
REGISTER_SHARD_PACKET(P_CL2FE_REQ_NPC_SUMMON, npcSummonHandler);
|
2020-09-18 21:24:15 +00:00
|
|
|
REGISTER_SHARD_PACKET(P_CL2FE_REQ_NPC_UNSUMMON, npcUnsummonHandler);
|
2020-08-29 11:14:21 +00:00
|
|
|
REGISTER_SHARD_PACKET(P_CL2FE_REQ_BARKER, npcBarkHandler);
|
2020-09-09 01:15:25 +00:00
|
|
|
REGISTER_SHARD_PACKET(P_CL2FE_REQ_PC_VENDOR_START, npcVendorStart);
|
|
|
|
REGISTER_SHARD_PACKET(P_CL2FE_REQ_PC_VENDOR_TABLE_UPDATE, npcVendorTable);
|
|
|
|
REGISTER_SHARD_PACKET(P_CL2FE_REQ_PC_VENDOR_ITEM_BUY, npcVendorBuy);
|
2020-09-12 02:04:23 +00:00
|
|
|
REGISTER_SHARD_PACKET(P_CL2FE_REQ_PC_VENDOR_ITEM_SELL, npcVendorSell);
|
2020-09-14 14:27:52 +00:00
|
|
|
REGISTER_SHARD_PACKET(P_CL2FE_REQ_PC_VENDOR_ITEM_RESTORE_BUY, npcVendorBuyback);
|
|
|
|
REGISTER_SHARD_PACKET(P_CL2FE_REQ_PC_VENDOR_BATTERY_BUY, npcVendorBuyBattery);
|
2020-09-16 00:30:01 +00:00
|
|
|
REGISTER_SHARD_PACKET(P_CL2FE_REQ_PC_ITEM_COMBINATION, npcCombineItems);
|
2020-10-24 19:48:55 +00:00
|
|
|
REGISTER_SHARD_PACKET(P_CL2FE_REQ_SHINY_PICKUP, eggPickup);
|
2020-10-22 09:09:50 +00:00
|
|
|
|
2020-10-24 19:48:55 +00:00
|
|
|
REGISTER_SHARD_TIMER(eggStep, 1000);
|
2020-09-09 01:15:25 +00:00
|
|
|
}
|
|
|
|
|
2020-09-25 01:58:20 +00:00
|
|
|
void NPCManager::destroyNPC(int32_t id) {
|
2020-09-18 21:24:15 +00:00
|
|
|
// sanity check
|
|
|
|
if (NPCs.find(id) == NPCs.end()) {
|
2020-10-20 22:55:58 +00:00
|
|
|
std::cout << "npc not found: " << id << std::endl;
|
2020-09-18 21:24:15 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
BaseNPC* entity = NPCs[id];
|
|
|
|
|
|
|
|
// sanity check
|
2020-11-19 01:37:58 +00:00
|
|
|
if (!ChunkManager::chunkExists(entity->chunkPos)) {
|
2020-09-18 21:24:15 +00:00
|
|
|
std::cout << "chunk not found!" << std::endl;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
// remove NPC from the chunk
|
2020-11-19 01:37:58 +00:00
|
|
|
ChunkManager::untrackNPC(entity->chunkPos, id);
|
2020-10-05 00:03:13 +00:00
|
|
|
|
2020-09-25 01:58:20 +00:00
|
|
|
// remove from viewable chunks
|
2020-11-19 01:37:58 +00:00
|
|
|
ChunkManager::removeNPCFromChunks(ChunkManager::getViewableChunks(entity->chunkPos), id);
|
2020-09-23 04:08:51 +00:00
|
|
|
|
2020-09-25 01:58:20 +00:00
|
|
|
// remove from mob manager
|
|
|
|
if (MobManager::Mobs.find(id) != MobManager::Mobs.end())
|
2020-10-15 02:36:38 +00:00
|
|
|
MobManager::Mobs.erase(id);
|
2020-10-05 00:03:13 +00:00
|
|
|
|
2020-10-24 19:48:55 +00:00
|
|
|
// remove from eggs
|
|
|
|
if (Eggs.find(id) != Eggs.end())
|
|
|
|
Eggs.erase(id);
|
|
|
|
|
2020-09-18 21:24:15 +00:00
|
|
|
// finally, remove it from the map and free it
|
2020-11-26 03:49:37 +00:00
|
|
|
delete entity->viewableChunks;
|
2020-09-18 21:24:15 +00:00
|
|
|
NPCs.erase(id);
|
|
|
|
delete entity;
|
2020-09-17 22:45:43 +00:00
|
|
|
}
|
|
|
|
|
2020-11-18 00:07:04 +00:00
|
|
|
void NPCManager::updateNPCPosition(int32_t id, int X, int Y, int Z, uint64_t I, int angle) {
|
2020-09-23 14:53:06 +00:00
|
|
|
BaseNPC* npc = NPCs[id];
|
2020-11-18 00:07:04 +00:00
|
|
|
npc->appearanceData.iAngle = angle;
|
2020-11-19 01:37:58 +00:00
|
|
|
ChunkPos oldChunk = npc->chunkPos;
|
2020-11-18 00:07:04 +00:00
|
|
|
ChunkPos newChunk = ChunkManager::chunkPosAt(X, Y, I);
|
2020-09-23 14:53:06 +00:00
|
|
|
npc->appearanceData.iX = X;
|
|
|
|
npc->appearanceData.iY = Y;
|
|
|
|
npc->appearanceData.iZ = Z;
|
2020-11-18 00:07:04 +00:00
|
|
|
npc->instanceID = I;
|
|
|
|
if (oldChunk == newChunk)
|
|
|
|
return; // didn't change chunks
|
|
|
|
ChunkManager::updateNPCChunk(id, oldChunk, newChunk);
|
2020-10-02 20:17:24 +00:00
|
|
|
}
|
|
|
|
|
2020-09-25 00:00:26 +00:00
|
|
|
void NPCManager::sendToViewable(BaseNPC *npc, void *buf, uint32_t type, size_t size) {
|
2020-11-19 22:19:46 +00:00
|
|
|
for (auto it = npc->viewableChunks->begin(); it != npc->viewableChunks->end(); it++) {
|
|
|
|
Chunk* chunk = *it;
|
2020-09-25 00:00:26 +00:00
|
|
|
for (CNSocket *s : chunk->players) {
|
|
|
|
s->sendPacket(buf, type, size);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-09-09 01:15:25 +00:00
|
|
|
void NPCManager::npcVendorBuy(CNSocket* sock, CNPacketData* data) {
|
|
|
|
if (data->size != sizeof(sP_CL2FE_REQ_PC_VENDOR_ITEM_BUY))
|
|
|
|
return; // malformed packet
|
|
|
|
|
|
|
|
sP_CL2FE_REQ_PC_VENDOR_ITEM_BUY* req = (sP_CL2FE_REQ_PC_VENDOR_ITEM_BUY*)data->buf;
|
|
|
|
Player *plr = PlayerManager::getPlayer(sock);
|
2020-09-28 18:11:13 +00:00
|
|
|
|
2021-03-09 02:40:23 +00:00
|
|
|
// prepare fail packet
|
|
|
|
INITSTRUCT(sP_FE2CL_REP_PC_VENDOR_ITEM_BUY_FAIL, failResp);
|
|
|
|
failResp.iErrorCode = 0;
|
|
|
|
|
|
|
|
ItemManager::Item* itemDat = ItemManager::getItemData(req->Item.iID, req->Item.iType);
|
2020-09-09 01:15:25 +00:00
|
|
|
|
2021-03-09 02:40:23 +00:00
|
|
|
if (itemDat == nullptr) {
|
2020-09-14 05:27:20 +00:00
|
|
|
std::cout << "[WARN] Item id " << req->Item.iID << " with type " << req->Item.iType << " not found (buy)" << std::endl;
|
2020-09-14 04:25:14 +00:00
|
|
|
sock->sendPacket((void*)&failResp, P_FE2CL_REP_PC_VENDOR_ITEM_BUY_FAIL, sizeof(sP_FE2CL_REP_PC_VENDOR_ITEM_BUY_FAIL));
|
|
|
|
return;
|
|
|
|
}
|
2020-09-09 01:15:25 +00:00
|
|
|
|
2021-03-09 02:40:23 +00:00
|
|
|
int itemCost = itemDat->buyPrice * (itemDat->stackSize > 1 ? req->Item.iOpt : 1);
|
2020-09-09 01:15:25 +00:00
|
|
|
int slot = ItemManager::findFreeSlot(plr);
|
2021-03-09 21:26:07 +00:00
|
|
|
if (itemCost > plr->money || slot == -1) {
|
|
|
|
sock->sendPacket((void*)&failResp, P_FE2CL_REP_PC_VENDOR_ITEM_BUY_FAIL, sizeof(sP_FE2CL_REP_PC_VENDOR_ITEM_BUY_FAIL));
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
// crates don't have a stack size in TableData, so we can't check those
|
|
|
|
if (itemDat->stackSize != 0 && req->Item.iOpt > itemDat->stackSize) {
|
2020-09-09 01:15:25 +00:00
|
|
|
sock->sendPacket((void*)&failResp, P_FE2CL_REP_PC_VENDOR_ITEM_BUY_FAIL, sizeof(sP_FE2CL_REP_PC_VENDOR_ITEM_BUY_FAIL));
|
|
|
|
return;
|
|
|
|
}
|
2021-03-09 02:40:23 +00:00
|
|
|
|
2020-09-22 11:16:09 +00:00
|
|
|
// if vehicle
|
2021-01-17 21:50:49 +00:00
|
|
|
if (req->Item.iType == 10) {
|
2020-09-22 11:16:09 +00:00
|
|
|
// set time limit: current time + 7days
|
2020-09-23 09:05:18 +00:00
|
|
|
req->Item.iTimeLimit = getTimestamp() + 604800;
|
2021-01-17 21:50:49 +00:00
|
|
|
}
|
2020-09-09 01:15:25 +00:00
|
|
|
|
|
|
|
if (slot != req->iInvenSlotNum) {
|
|
|
|
// possible item stacking?
|
2020-09-12 00:25:45 +00:00
|
|
|
std::cout << "[WARN] Client and server disagree on bought item slot (" << req->iInvenSlotNum << " vs " << slot << ")" << std::endl;
|
2020-09-09 01:15:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
INITSTRUCT(sP_FE2CL_REP_PC_VENDOR_ITEM_BUY_SUCC, resp);
|
|
|
|
|
|
|
|
plr->money = plr->money - itemCost;
|
|
|
|
plr->Inven[slot] = req->Item;
|
|
|
|
|
|
|
|
resp.iCandy = plr->money;
|
|
|
|
resp.iInvenSlotNum = slot;
|
|
|
|
resp.Item = req->Item;
|
|
|
|
|
|
|
|
sock->sendPacket((void*)&resp, P_FE2CL_REP_PC_VENDOR_ITEM_BUY_SUCC, sizeof(sP_FE2CL_REP_PC_VENDOR_ITEM_BUY_SUCC));
|
|
|
|
}
|
|
|
|
|
2020-09-12 02:04:23 +00:00
|
|
|
void NPCManager::npcVendorSell(CNSocket* sock, CNPacketData* data) {
|
|
|
|
if (data->size != sizeof(sP_CL2FE_REQ_PC_VENDOR_ITEM_SELL))
|
|
|
|
return; // malformed packet
|
|
|
|
|
|
|
|
sP_CL2FE_REQ_PC_VENDOR_ITEM_SELL* req = (sP_CL2FE_REQ_PC_VENDOR_ITEM_SELL*)data->buf;
|
|
|
|
Player* plr = PlayerManager::getPlayer(sock);
|
|
|
|
|
2021-03-06 18:55:37 +00:00
|
|
|
// prepare a fail packet
|
|
|
|
INITSTRUCT(sP_FE2CL_REP_PC_VENDOR_ITEM_SELL_FAIL, failResp);
|
|
|
|
failResp.iErrorCode = 0;
|
|
|
|
|
2020-09-12 14:10:53 +00:00
|
|
|
if (req->iInvenSlotNum < 0 || req->iInvenSlotNum >= AINVEN_COUNT || req->iItemCnt < 0) {
|
2020-09-12 02:04:23 +00:00
|
|
|
std::cout << "[WARN] Client failed to sell item in slot " << req->iInvenSlotNum << std::endl;
|
|
|
|
sock->sendPacket((void*)&failResp, P_FE2CL_REP_PC_VENDOR_ITEM_SELL_FAIL, sizeof(sP_FE2CL_REP_PC_VENDOR_ITEM_SELL_FAIL));
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2020-09-12 14:10:53 +00:00
|
|
|
sItemBase* item = &plr->Inven[req->iInvenSlotNum];
|
2020-12-04 18:57:08 +00:00
|
|
|
ItemManager::Item* itemData = ItemManager::getItemData(item->iID, item->iType);
|
2020-09-12 14:10:53 +00:00
|
|
|
|
2021-03-09 02:40:23 +00:00
|
|
|
if (itemData == nullptr || !itemData->sellable || item->iOpt < req->iItemCnt) { // sanity + sellable check
|
2020-09-14 05:27:20 +00:00
|
|
|
std::cout << "[WARN] Item id " << item->iID << " with type " << item->iType << " not found (sell)" << std::endl;
|
2021-03-06 18:55:37 +00:00
|
|
|
sock->sendPacket((void*)&failResp, P_FE2CL_REP_PC_VENDOR_ITEM_SELL_FAIL, sizeof(sP_FE2CL_REP_PC_VENDOR_ITEM_SELL_FAIL));
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
// fail to sell croc-potted items
|
2021-03-09 02:40:23 +00:00
|
|
|
if (item->iOpt >= 1 << 16) {
|
2020-09-14 05:27:20 +00:00
|
|
|
sock->sendPacket((void*)&failResp, P_FE2CL_REP_PC_VENDOR_ITEM_SELL_FAIL, sizeof(sP_FE2CL_REP_PC_VENDOR_ITEM_SELL_FAIL));
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
sItemBase original;
|
|
|
|
memcpy(&original, item, sizeof(sItemBase));
|
|
|
|
|
2020-09-12 02:04:23 +00:00
|
|
|
INITSTRUCT(sP_FE2CL_REP_PC_VENDOR_ITEM_SELL_SUCC, resp);
|
2020-10-05 00:03:13 +00:00
|
|
|
|
2020-09-12 02:04:23 +00:00
|
|
|
// increment taros
|
2021-03-09 02:40:23 +00:00
|
|
|
plr->money += itemData->sellPrice * req->iItemCnt;
|
2020-09-12 02:04:23 +00:00
|
|
|
|
2020-09-14 05:52:15 +00:00
|
|
|
// modify item
|
2021-03-09 02:40:23 +00:00
|
|
|
if (item->iOpt - req->iItemCnt > 0) { // selling part of a stack
|
2020-09-14 05:52:15 +00:00
|
|
|
item->iOpt -= req->iItemCnt;
|
|
|
|
original.iOpt = req->iItemCnt;
|
2020-10-19 17:26:14 +00:00
|
|
|
} else { // selling entire slot
|
2021-03-09 02:40:23 +00:00
|
|
|
// make sure it's fully zeroed, even the padding and non-104 members
|
|
|
|
memset(item, 0, sizeof(*item));
|
2020-09-14 05:52:15 +00:00
|
|
|
}
|
2020-09-12 02:04:23 +00:00
|
|
|
|
2021-03-09 02:40:23 +00:00
|
|
|
// add to buyback list
|
|
|
|
plr->buyback->push_back(original);
|
|
|
|
// forget oldest member if there's more than 5
|
|
|
|
if (plr->buyback->size() > 5)
|
|
|
|
plr->buyback->erase(plr->buyback->begin());
|
|
|
|
//std::cout << (int)plr->buyback->size() << " items in buyback\n";
|
|
|
|
|
2020-09-12 02:04:23 +00:00
|
|
|
// response parameters
|
|
|
|
resp.iInvenSlotNum = req->iInvenSlotNum;
|
|
|
|
resp.iCandy = plr->money;
|
2020-09-14 05:27:20 +00:00
|
|
|
resp.Item = original; // the item that gets sent to buyback
|
|
|
|
resp.ItemStay = *item; // the void item that gets put in the slot
|
2020-09-12 02:04:23 +00:00
|
|
|
|
|
|
|
sock->sendPacket((void*)&resp, P_FE2CL_REP_PC_VENDOR_ITEM_SELL_SUCC, sizeof(sP_FE2CL_REP_PC_VENDOR_ITEM_SELL_SUCC));
|
|
|
|
}
|
|
|
|
|
2020-09-14 14:27:52 +00:00
|
|
|
void NPCManager::npcVendorBuyback(CNSocket* sock, CNPacketData* data) {
|
2020-09-14 05:27:20 +00:00
|
|
|
if (data->size != sizeof(sP_CL2FE_REQ_PC_VENDOR_ITEM_RESTORE_BUY))
|
|
|
|
return; // malformed packet
|
|
|
|
|
|
|
|
sP_CL2FE_REQ_PC_VENDOR_ITEM_RESTORE_BUY* req = (sP_CL2FE_REQ_PC_VENDOR_ITEM_RESTORE_BUY*)data->buf;
|
|
|
|
Player* plr = PlayerManager::getPlayer(sock);
|
2020-09-28 18:11:13 +00:00
|
|
|
|
2021-03-09 02:40:23 +00:00
|
|
|
// prepare fail packet
|
|
|
|
INITSTRUCT(sP_FE2CL_REP_PC_VENDOR_ITEM_RESTORE_BUY_FAIL, failResp);
|
|
|
|
failResp.iErrorCode = 0;
|
|
|
|
|
|
|
|
//std::cout << "buying back from index " << (int)req->iListID << " into " << (int)req->iInvenSlotNum <<
|
|
|
|
// " from " << (int)req->iNPC_ID << " (vendor = " << (int)req->iVendorID << ")\n";
|
|
|
|
|
|
|
|
int idx = req->iListID - 1;
|
|
|
|
|
|
|
|
// sanity check
|
|
|
|
if (idx < 0 || idx >= plr->buyback->size()) {
|
|
|
|
sock->sendPacket((void*)&failResp, P_FE2CL_REP_PC_VENDOR_ITEM_RESTORE_BUY_FAIL, sizeof(sP_FE2CL_REP_PC_VENDOR_ITEM_RESTORE_BUY_FAIL));
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
// get the item out of the buyback list
|
|
|
|
sItemBase item = (*plr->buyback)[idx];
|
|
|
|
/*
|
|
|
|
* NOTE: The client sends the index of the exact item the user clicked on.
|
|
|
|
* We then operate on that item, but we remove the *first* identical item
|
|
|
|
* from the buyback list, instead of the one at the supplied index.
|
|
|
|
*
|
|
|
|
* This was originally a mistake on my part, but it turns out the client
|
|
|
|
* does the exact same thing, so this *is* the correct thing to do to keep
|
|
|
|
* them in sync.
|
|
|
|
*/
|
|
|
|
for (auto it = plr->buyback->begin(); it != plr->buyback->end(); it++) {
|
|
|
|
/*
|
|
|
|
* XXX: we really need a standard item comparison function that
|
|
|
|
* will work properly across all builds (ex. with iSerial)
|
|
|
|
*/
|
|
|
|
if (it->iType == item.iType && it->iID == item.iID && it->iOpt == item.iOpt
|
|
|
|
&& it->iTimeLimit == item.iTimeLimit) {
|
|
|
|
plr->buyback->erase(it);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
//std::cout << (int)plr->buyback->size() << " items in buyback\n";
|
|
|
|
|
|
|
|
ItemManager::Item* itemDat = ItemManager::getItemData(item.iID, item.iType);
|
2020-09-14 05:27:20 +00:00
|
|
|
|
2021-03-09 02:40:23 +00:00
|
|
|
if (itemDat == nullptr) {
|
|
|
|
std::cout << "[WARN] Item id " << item.iID << " with type " << item.iType << " not found (rebuy)" << std::endl;
|
2020-09-14 05:27:20 +00:00
|
|
|
sock->sendPacket((void*)&failResp, P_FE2CL_REP_PC_VENDOR_ITEM_RESTORE_BUY_FAIL, sizeof(sP_FE2CL_REP_PC_VENDOR_ITEM_RESTORE_BUY_FAIL));
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2020-09-14 14:27:52 +00:00
|
|
|
// sell price is used on rebuy. ternary identifies stacked items
|
2021-03-09 02:40:23 +00:00
|
|
|
int itemCost = itemDat->sellPrice * (itemDat->stackSize > 1 ? item.iOpt : 1);
|
2020-09-14 05:27:20 +00:00
|
|
|
int slot = ItemManager::findFreeSlot(plr);
|
|
|
|
if (itemCost > plr->money || slot == -1) {
|
|
|
|
sock->sendPacket((void*)&failResp, P_FE2CL_REP_PC_VENDOR_ITEM_RESTORE_BUY_FAIL, sizeof(sP_FE2CL_REP_PC_VENDOR_ITEM_RESTORE_BUY_FAIL));
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (slot != req->iInvenSlotNum) {
|
|
|
|
// possible item stacking?
|
|
|
|
std::cout << "[WARN] Client and server disagree on bought item slot (" << req->iInvenSlotNum << " vs " << slot << ")" << std::endl;
|
|
|
|
}
|
|
|
|
|
|
|
|
plr->money = plr->money - itemCost;
|
2021-03-09 02:40:23 +00:00
|
|
|
plr->Inven[slot] = item;
|
2020-09-14 05:27:20 +00:00
|
|
|
|
|
|
|
INITSTRUCT(sP_FE2CL_REP_PC_VENDOR_ITEM_RESTORE_BUY_SUCC, resp);
|
|
|
|
// response parameters
|
|
|
|
resp.iCandy = plr->money;
|
|
|
|
resp.iInvenSlotNum = slot;
|
2021-03-09 02:40:23 +00:00
|
|
|
resp.Item = item;
|
2020-09-14 05:27:20 +00:00
|
|
|
|
|
|
|
sock->sendPacket((void*)&resp, P_FE2CL_REP_PC_VENDOR_ITEM_RESTORE_BUY_SUCC, sizeof(sP_FE2CL_REP_PC_VENDOR_ITEM_RESTORE_BUY_SUCC));
|
|
|
|
}
|
|
|
|
|
2020-09-09 01:15:25 +00:00
|
|
|
void NPCManager::npcVendorTable(CNSocket* sock, CNPacketData* data) {
|
|
|
|
if (data->size != sizeof(sP_CL2FE_REQ_PC_VENDOR_TABLE_UPDATE))
|
|
|
|
return; // malformed packet
|
|
|
|
|
2020-09-13 22:54:47 +00:00
|
|
|
sP_CL2FE_REQ_PC_VENDOR_TABLE_UPDATE* req = (sP_CL2FE_REQ_PC_VENDOR_TABLE_UPDATE*)data->buf;
|
2020-10-05 00:03:13 +00:00
|
|
|
|
2021-03-13 02:09:36 +00:00
|
|
|
if (req->iVendorID != req->iNPC_ID || Vendor::VendorTables.find(req->iVendorID) == Vendor::VendorTables.end())
|
2020-09-13 22:54:47 +00:00
|
|
|
return;
|
|
|
|
|
2021-03-13 02:09:36 +00:00
|
|
|
std::vector<VendorListing> listings = Vendor::VendorTables[req->iVendorID];
|
2020-09-13 22:54:47 +00:00
|
|
|
|
2020-09-09 01:15:25 +00:00
|
|
|
INITSTRUCT(sP_FE2CL_REP_PC_VENDOR_TABLE_UPDATE_SUCC, resp);
|
2020-09-13 22:54:47 +00:00
|
|
|
|
2020-10-07 17:03:00 +00:00
|
|
|
for (int i = 0; i < (int)listings.size() && i < 20; i++) { // 20 is the max
|
2020-09-14 14:27:52 +00:00
|
|
|
sItemBase base;
|
|
|
|
base.iID = listings[i].iID;
|
|
|
|
base.iOpt = 0;
|
|
|
|
base.iTimeLimit = 0;
|
|
|
|
base.iType = listings[i].type;
|
2020-09-13 22:54:47 +00:00
|
|
|
|
2020-09-14 14:27:52 +00:00
|
|
|
sItemVendor vItem;
|
|
|
|
vItem.item = base;
|
|
|
|
vItem.iSortNum = listings[i].sort;
|
|
|
|
vItem.iVendorID = req->iVendorID;
|
2020-10-19 17:26:14 +00:00
|
|
|
//vItem.fBuyCost = listings[i].price; // this value is not actually the one that is used
|
2020-09-13 22:54:47 +00:00
|
|
|
|
2020-09-14 14:27:52 +00:00
|
|
|
resp.item[i] = vItem;
|
2020-09-13 22:54:47 +00:00
|
|
|
}
|
2020-09-09 01:15:25 +00:00
|
|
|
|
|
|
|
sock->sendPacket((void*)&resp, P_FE2CL_REP_PC_VENDOR_TABLE_UPDATE_SUCC, sizeof(sP_FE2CL_REP_PC_VENDOR_TABLE_UPDATE_SUCC));
|
|
|
|
}
|
|
|
|
|
|
|
|
void NPCManager::npcVendorStart(CNSocket* sock, CNPacketData* data) {
|
|
|
|
if (data->size != sizeof(sP_CL2FE_REQ_PC_VENDOR_START))
|
|
|
|
return; // malformed packet
|
|
|
|
|
|
|
|
sP_CL2FE_REQ_PC_VENDOR_START* req = (sP_CL2FE_REQ_PC_VENDOR_START*)data->buf;
|
|
|
|
INITSTRUCT(sP_FE2CL_REP_PC_VENDOR_START_SUCC, resp);
|
|
|
|
|
|
|
|
resp.iNPC_ID = req->iNPC_ID;
|
|
|
|
resp.iVendorID = req->iVendorID;
|
|
|
|
|
|
|
|
sock->sendPacket((void*)&resp, P_FE2CL_REP_PC_VENDOR_START_SUCC, sizeof(sP_FE2CL_REP_PC_VENDOR_START_SUCC));
|
2020-08-20 21:43:48 +00:00
|
|
|
}
|
|
|
|
|
2020-09-14 14:27:52 +00:00
|
|
|
void NPCManager::npcVendorBuyBattery(CNSocket* sock, CNPacketData* data) {
|
|
|
|
if (data->size != sizeof(sP_CL2FE_REQ_PC_VENDOR_BATTERY_BUY))
|
|
|
|
return; // malformed packet
|
|
|
|
|
|
|
|
sP_CL2FE_REQ_PC_VENDOR_BATTERY_BUY* req = (sP_CL2FE_REQ_PC_VENDOR_BATTERY_BUY*)data->buf;
|
|
|
|
Player* plr = PlayerManager::getPlayer(sock);
|
|
|
|
|
2020-10-28 21:05:01 +00:00
|
|
|
int cost = req->Item.iOpt * 100;
|
2021-01-06 10:42:23 +00:00
|
|
|
if ((req->Item.iID == 3 ? (plr->batteryW >= 9999) : (plr->batteryN >= 9999)) || plr->money < cost || req->Item.iOpt < 0) { // sanity check
|
2020-09-14 14:27:52 +00:00
|
|
|
INITSTRUCT(sP_FE2CL_REP_PC_VENDOR_BATTERY_BUY_FAIL, failResp);
|
|
|
|
failResp.iErrorCode = 0;
|
|
|
|
sock->sendPacket((void*)&failResp, P_FE2CL_REP_PC_VENDOR_BATTERY_BUY_FAIL, sizeof(sP_FE2CL_REP_PC_VENDOR_BATTERY_BUY_FAIL));
|
2021-01-06 10:42:23 +00:00
|
|
|
return;
|
2020-09-14 14:27:52 +00:00
|
|
|
}
|
|
|
|
|
2020-10-28 21:05:01 +00:00
|
|
|
cost = plr->batteryW + plr->batteryN;
|
|
|
|
plr->batteryW += req->Item.iID == 3 ? req->Item.iOpt * 100 : 0;
|
|
|
|
plr->batteryN += req->Item.iID == 4 ? req->Item.iOpt * 100 : 0;
|
2020-09-14 14:27:52 +00:00
|
|
|
|
|
|
|
// caps
|
|
|
|
if (plr->batteryW > 9999)
|
|
|
|
plr->batteryW = 9999;
|
|
|
|
if (plr->batteryN > 9999)
|
|
|
|
plr->batteryN = 9999;
|
|
|
|
|
2020-10-28 21:05:01 +00:00
|
|
|
cost = plr->batteryW + plr->batteryN - cost;
|
|
|
|
plr->money -= cost;
|
|
|
|
|
2020-09-14 14:27:52 +00:00
|
|
|
INITSTRUCT(sP_FE2CL_REP_PC_VENDOR_BATTERY_BUY_SUCC, resp);
|
|
|
|
|
|
|
|
resp.iCandy = plr->money;
|
|
|
|
resp.iBatteryW = plr->batteryW;
|
|
|
|
resp.iBatteryN = plr->batteryN;
|
|
|
|
|
|
|
|
sock->sendPacket((void*)&resp, P_FE2CL_REP_PC_VENDOR_BATTERY_BUY_SUCC, sizeof(sP_FE2CL_REP_PC_VENDOR_BATTERY_BUY_SUCC));
|
|
|
|
}
|
|
|
|
|
2020-09-16 00:30:01 +00:00
|
|
|
void NPCManager::npcCombineItems(CNSocket* sock, CNPacketData* data) {
|
|
|
|
if (data->size != sizeof(sP_CL2FE_REQ_PC_ITEM_COMBINATION))
|
|
|
|
return; // malformed packet
|
|
|
|
|
|
|
|
sP_CL2FE_REQ_PC_ITEM_COMBINATION* req = (sP_CL2FE_REQ_PC_ITEM_COMBINATION*)data->buf;
|
|
|
|
Player* plr = PlayerManager::getPlayer(sock);
|
2020-09-28 18:11:13 +00:00
|
|
|
|
2021-03-08 21:29:21 +00:00
|
|
|
// prepare fail packet
|
|
|
|
INITSTRUCT(sP_FE2CL_REP_PC_ITEM_COMBINATION_FAIL, failResp);
|
|
|
|
failResp.iCostumeItemSlot = req->iCostumeItemSlot;
|
|
|
|
failResp.iStatItemSlot = req->iStatItemSlot;
|
|
|
|
failResp.iErrorCode = 0;
|
|
|
|
|
|
|
|
// sanity check slot indices
|
|
|
|
if (req->iCostumeItemSlot < 0 || req->iCostumeItemSlot >= AINVEN_COUNT || req->iStatItemSlot < 0 || req->iStatItemSlot >= AINVEN_COUNT) {
|
2020-09-16 00:30:01 +00:00
|
|
|
std::cout << "[WARN] Inventory slot(s) out of range (" << req->iStatItemSlot << " and " << req->iCostumeItemSlot << ")" << std::endl;
|
2021-03-08 21:29:21 +00:00
|
|
|
sock->sendPacket((void*)&failResp, P_FE2CL_REP_PC_ITEM_COMBINATION_FAIL, sizeof(sP_FE2CL_REP_PC_ITEM_COMBINATION_FAIL));
|
2020-09-16 00:30:01 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
sItemBase* itemStats = &plr->Inven[req->iStatItemSlot];
|
|
|
|
sItemBase* itemLooks = &plr->Inven[req->iCostumeItemSlot];
|
2020-12-04 18:57:08 +00:00
|
|
|
ItemManager::Item* itemStatsDat = ItemManager::getItemData(itemStats->iID, itemStats->iType);
|
|
|
|
ItemManager::Item* itemLooksDat = ItemManager::getItemData(itemLooks->iID, itemLooks->iType);
|
2020-09-16 00:30:01 +00:00
|
|
|
|
2021-03-08 21:29:21 +00:00
|
|
|
// sanity check item and combination entry existence
|
2020-09-16 00:30:01 +00:00
|
|
|
if (itemStatsDat == nullptr || itemLooksDat == nullptr
|
2021-03-08 21:29:21 +00:00
|
|
|
|| ItemManager::CrocPotTable.find(abs(itemStatsDat->level - itemLooksDat->level)) == ItemManager::CrocPotTable.end()) {
|
2020-09-16 00:30:01 +00:00
|
|
|
std::cout << "[WARN] Either item ids or croc pot value set not found" << std::endl;
|
|
|
|
sock->sendPacket((void*)&failResp, P_FE2CL_REP_PC_ITEM_COMBINATION_FAIL, sizeof(sP_FE2CL_REP_PC_ITEM_COMBINATION_FAIL));
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2021-03-08 21:29:21 +00:00
|
|
|
// sanity check matching item types
|
|
|
|
if (itemStats->iType != itemLooks->iType
|
|
|
|
|| (itemStats->iType == 0 && itemStatsDat->weaponType != itemLooksDat->weaponType)) {
|
|
|
|
std::cout << "[WARN] Player attempted to combine mismatched items" << std::endl;
|
|
|
|
sock->sendPacket((void*)&failResp, P_FE2CL_REP_PC_ITEM_COMBINATION_FAIL, sizeof(sP_FE2CL_REP_PC_ITEM_COMBINATION_FAIL));
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2020-09-16 00:30:01 +00:00
|
|
|
CrocPotEntry* recipe = &ItemManager::CrocPotTable[abs(itemStatsDat->level - itemLooksDat->level)];
|
|
|
|
int cost = itemStatsDat->buyPrice * recipe->multStats + itemLooksDat->buyPrice * recipe->multLooks;
|
2020-09-19 20:22:28 +00:00
|
|
|
float successChance = recipe->base / 100.0f; // base success chance
|
2020-09-16 00:30:01 +00:00
|
|
|
|
|
|
|
// rarity gap multiplier
|
2020-10-19 17:26:14 +00:00
|
|
|
switch(abs(itemStatsDat->rarity - itemLooksDat->rarity)) {
|
2020-09-16 00:30:01 +00:00
|
|
|
case 0:
|
|
|
|
successChance *= recipe->rd0;
|
|
|
|
break;
|
|
|
|
case 1:
|
|
|
|
successChance *= recipe->rd1;
|
|
|
|
break;
|
|
|
|
case 2:
|
|
|
|
successChance *= recipe->rd2;
|
|
|
|
break;
|
|
|
|
case 3:
|
|
|
|
successChance *= recipe->rd3;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2020-09-19 20:22:28 +00:00
|
|
|
float rolled = (rand() * 1.0f / RAND_MAX) * 100.0f; // success chance out of 100
|
|
|
|
//std::cout << rolled << " vs " << successChance << std::endl;
|
2020-09-16 00:30:01 +00:00
|
|
|
plr->money -= cost;
|
|
|
|
|
|
|
|
|
|
|
|
INITSTRUCT(sP_FE2CL_REP_PC_ITEM_COMBINATION_SUCC, resp);
|
|
|
|
if (rolled < successChance) {
|
|
|
|
// success
|
|
|
|
resp.iSuccessFlag = 1;
|
|
|
|
|
|
|
|
// modify the looks item with the new stats and set the appearance through iOpt
|
2020-10-16 23:54:05 +00:00
|
|
|
itemLooks->iOpt = (int32_t)((itemLooks->iOpt) >> 16 > 0 ? (itemLooks->iOpt >> 16) : itemLooks->iID) << 16;
|
2020-09-16 00:30:01 +00:00
|
|
|
itemLooks->iID = itemStats->iID;
|
|
|
|
|
|
|
|
// delete stats item
|
|
|
|
itemStats->iID = 0;
|
|
|
|
itemStats->iOpt = 0;
|
|
|
|
itemStats->iTimeLimit = 0;
|
|
|
|
itemStats->iType = 0;
|
2020-10-19 17:26:14 +00:00
|
|
|
} else {
|
2020-09-16 00:30:01 +00:00
|
|
|
// failure; don't do anything?
|
|
|
|
resp.iSuccessFlag = 0;
|
|
|
|
}
|
|
|
|
resp.iCandy = plr->money;
|
|
|
|
resp.iNewItemSlot = req->iCostumeItemSlot;
|
|
|
|
resp.iStatItemSlot = req->iStatItemSlot;
|
|
|
|
resp.sNewItem = *itemLooks;
|
2020-10-05 00:03:13 +00:00
|
|
|
|
2020-09-16 00:30:01 +00:00
|
|
|
sock->sendPacket((void*)&resp, P_FE2CL_REP_PC_ITEM_COMBINATION_SUCC, sizeof(sP_FE2CL_REP_PC_ITEM_COMBINATION_SUCC));
|
|
|
|
}
|
|
|
|
|
2020-12-15 23:42:22 +00:00
|
|
|
void NPCManager::npcBarkHandler(CNSocket* sock, CNPacketData* data) {
|
|
|
|
if (data->size != sizeof(sP_CL2FE_REQ_BARKER))
|
|
|
|
return; // malformed packet
|
|
|
|
|
|
|
|
sP_CL2FE_REQ_BARKER* req = (sP_CL2FE_REQ_BARKER*)data->buf;
|
|
|
|
|
|
|
|
// get bark IDs from task data
|
|
|
|
TaskData* td = MissionManager::Tasks[req->iMissionTaskID];
|
|
|
|
std::vector<int> barks;
|
|
|
|
for (int i = 0; i < 4; i++) {
|
|
|
|
if (td->task["m_iHBarkerTextID"][i] != 0) // non-zeroes only
|
|
|
|
barks.push_back(td->task["m_iHBarkerTextID"][i]);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (barks.empty())
|
|
|
|
return; // no barks
|
|
|
|
|
|
|
|
INITSTRUCT(sP_FE2CL_REP_BARKER, resp);
|
|
|
|
resp.iNPC_ID = req->iNPC_ID;
|
|
|
|
resp.iMissionStringID = barks[rand() % barks.size()];
|
|
|
|
sock->sendPacket((void*)&resp, P_FE2CL_REP_BARKER, sizeof(sP_FE2CL_REP_BARKER));
|
|
|
|
}
|
2020-08-25 02:28:42 +00:00
|
|
|
|
2020-09-18 21:24:15 +00:00
|
|
|
void NPCManager::npcUnsummonHandler(CNSocket* sock, CNPacketData* data) {
|
|
|
|
if (data->size != sizeof(sP_CL2FE_REQ_NPC_UNSUMMON))
|
|
|
|
return; // malformed packet
|
|
|
|
|
2020-09-28 18:11:13 +00:00
|
|
|
Player* plr = PlayerManager::getPlayer(sock);
|
|
|
|
|
2020-12-01 19:18:01 +00:00
|
|
|
if (plr->accountLevel > 30)
|
2020-09-18 21:24:15 +00:00
|
|
|
return;
|
2020-10-05 00:03:13 +00:00
|
|
|
|
2020-09-18 21:24:15 +00:00
|
|
|
sP_CL2FE_REQ_NPC_UNSUMMON* req = (sP_CL2FE_REQ_NPC_UNSUMMON*)data->buf;
|
2020-09-25 01:58:20 +00:00
|
|
|
NPCManager::destroyNPC(req->iNPC_ID);
|
2020-09-18 21:24:15 +00:00
|
|
|
}
|
|
|
|
|
2020-12-15 22:15:39 +00:00
|
|
|
// type must already be checked and updateNPCPosition() must be called on the result
|
|
|
|
BaseNPC *NPCManager::summonNPC(int x, int y, int z, uint64_t instance, int type, bool respawn, bool baseInstance) {
|
|
|
|
uint64_t inst = baseInstance ? MAPNUM(instance) : instance;
|
|
|
|
#define EXTRA_HEIGHT 0
|
|
|
|
|
|
|
|
assert(nextId < INT32_MAX);
|
|
|
|
int id = nextId++;
|
|
|
|
int team = NPCData[type]["m_iTeam"];
|
|
|
|
BaseNPC *npc = nullptr;
|
|
|
|
|
|
|
|
if (team == 2) {
|
|
|
|
npc = new Mob(x, y, z + EXTRA_HEIGHT, inst, type, NPCData[type], id);
|
|
|
|
MobManager::Mobs[id] = (Mob*)npc;
|
|
|
|
|
|
|
|
// re-enable respawning, if desired
|
|
|
|
((Mob*)npc)->summoned = !respawn;
|
|
|
|
} else
|
|
|
|
npc = new BaseNPC(x, y, z + EXTRA_HEIGHT, 0, inst, type, id);
|
|
|
|
|
|
|
|
NPCs[id] = npc;
|
|
|
|
|
|
|
|
return npc;
|
|
|
|
}
|
|
|
|
|
2020-08-29 11:14:21 +00:00
|
|
|
void NPCManager::npcSummonHandler(CNSocket* sock, CNPacketData* data) {
|
2020-08-25 02:28:42 +00:00
|
|
|
if (data->size != sizeof(sP_CL2FE_REQ_NPC_SUMMON))
|
|
|
|
return; // malformed packet
|
|
|
|
|
|
|
|
sP_CL2FE_REQ_NPC_SUMMON* req = (sP_CL2FE_REQ_NPC_SUMMON*)data->buf;
|
2020-08-29 11:14:21 +00:00
|
|
|
Player* plr = PlayerManager::getPlayer(sock);
|
2020-08-25 02:28:42 +00:00
|
|
|
|
2020-12-21 00:57:56 +00:00
|
|
|
int limit = NPCData.back()["m_iNpcNumber"];
|
|
|
|
|
2020-08-25 02:28:42 +00:00
|
|
|
// permission & sanity check
|
2021-03-03 22:17:36 +00:00
|
|
|
if (plr->accountLevel > 30 || req->iNPCType > limit || req->iNPCCnt > 100)
|
2020-08-25 02:28:42 +00:00
|
|
|
return;
|
|
|
|
|
2020-10-13 19:50:14 +00:00
|
|
|
for (int i = 0; i < req->iNPCCnt; i++) {
|
2020-12-15 22:15:39 +00:00
|
|
|
BaseNPC *npc = summonNPC(plr->x, plr->y, plr->z, plr->instanceID, req->iNPCType);
|
|
|
|
updateNPCPosition(npc->appearanceData.iNPC_ID, plr->x, plr->y, plr->z, plr->instanceID, 0);
|
2020-10-13 19:50:14 +00:00
|
|
|
}
|
2020-08-25 02:28:42 +00:00
|
|
|
}
|
2020-08-29 11:14:21 +00:00
|
|
|
|
|
|
|
void NPCManager::npcWarpHandler(CNSocket* sock, CNPacketData* data) {
|
|
|
|
if (data->size != sizeof(sP_CL2FE_REQ_PC_WARP_USE_NPC))
|
|
|
|
return; // malformed packet
|
|
|
|
|
|
|
|
sP_CL2FE_REQ_PC_WARP_USE_NPC* warpNpc = (sP_CL2FE_REQ_PC_WARP_USE_NPC*)data->buf;
|
2020-09-25 05:35:27 +00:00
|
|
|
handleWarp(sock, warpNpc->iWarpID);
|
|
|
|
}
|
2020-08-29 11:14:21 +00:00
|
|
|
|
2020-09-25 05:35:27 +00:00
|
|
|
void NPCManager::npcWarpTimeMachine(CNSocket* sock, CNPacketData* data) {
|
|
|
|
if (data->size != sizeof(sP_CL2FE_REQ_PC_TIME_TO_GO_WARP))
|
|
|
|
return; // malformed packet
|
|
|
|
// this is just a warp request
|
|
|
|
handleWarp(sock, 28);
|
|
|
|
}
|
|
|
|
|
|
|
|
void NPCManager::handleWarp(CNSocket* sock, int32_t warpId) {
|
2020-11-17 23:16:16 +00:00
|
|
|
Player* plr = PlayerManager::getPlayer(sock);
|
2020-08-29 11:14:21 +00:00
|
|
|
// sanity check
|
2020-09-25 05:35:27 +00:00
|
|
|
if (Warps.find(warpId) == Warps.end())
|
2020-08-29 11:14:21 +00:00
|
|
|
return;
|
|
|
|
|
2020-12-29 13:31:48 +00:00
|
|
|
if (plr->iPCState & 8) {
|
2020-12-28 16:39:08 +00:00
|
|
|
// remove the player's vehicle
|
|
|
|
plr->iPCState &= ~8;
|
|
|
|
|
|
|
|
// send to self
|
|
|
|
INITSTRUCT(sP_FE2CL_PC_VEHICLE_OFF_SUCC, off);
|
|
|
|
sock->sendPacket((void*)&off, P_FE2CL_PC_VEHICLE_OFF_SUCC, sizeof(sP_FE2CL_PC_VEHICLE_OFF_SUCC));
|
|
|
|
|
|
|
|
// send to others
|
|
|
|
INITSTRUCT(sP_FE2CL_PC_STATE_CHANGE, chg);
|
|
|
|
chg.iPC_ID = plr->iID;
|
|
|
|
chg.iState = plr->iPCState;
|
|
|
|
PlayerManager::sendToViewable(sock, (void*)&chg, P_FE2CL_PC_STATE_CHANGE, sizeof(sP_FE2CL_PC_STATE_CHANGE));
|
|
|
|
}
|
2020-12-27 23:42:29 +00:00
|
|
|
|
2020-10-02 20:17:24 +00:00
|
|
|
// std::cerr << "Warped to Map Num:" << Warps[warpId].instanceID << " NPC ID " << Warps[warpId].npcID << std::endl;
|
2020-10-19 17:26:14 +00:00
|
|
|
if (Warps[warpId].isInstance) {
|
2020-10-12 16:55:41 +00:00
|
|
|
uint64_t instanceID = Warps[warpId].instanceID;
|
2020-10-20 22:55:58 +00:00
|
|
|
|
|
|
|
// if warp requires you to be on a mission, it's gotta be a unique instance
|
|
|
|
if (Warps[warpId].limitTaskID != 0 || instanceID == 14) { // 14 is a special case for the Time Lab
|
2020-11-17 23:16:16 +00:00
|
|
|
instanceID += ((uint64_t)plr->iIDGroup << 32); // upper 32 bits are leader ID
|
2020-10-13 03:42:47 +00:00
|
|
|
ChunkManager::createInstance(instanceID);
|
2020-12-14 23:22:27 +00:00
|
|
|
|
|
|
|
// save Lair entrance coords as a pseudo-Resurrect 'Em
|
|
|
|
plr->recallX = Warps[warpId].x;
|
|
|
|
plr->recallY = Warps[warpId].y;
|
2020-12-15 22:11:10 +00:00
|
|
|
plr->recallZ = Warps[warpId].z + RESURRECT_HEIGHT;
|
|
|
|
plr->recallInstance = instanceID;
|
2020-10-12 16:55:41 +00:00
|
|
|
}
|
2020-10-19 17:26:14 +00:00
|
|
|
|
2020-11-17 23:16:16 +00:00
|
|
|
if (plr->iID == plr->iIDGroup && plr->groupCnt == 1)
|
2020-10-17 04:58:51 +00:00
|
|
|
PlayerManager::sendPlayerTo(sock, Warps[warpId].x, Warps[warpId].y, Warps[warpId].z, instanceID);
|
|
|
|
else {
|
2020-11-17 23:16:16 +00:00
|
|
|
Player* leaderPlr = PlayerManager::getPlayerFromID(plr->iIDGroup);
|
2020-10-17 04:58:51 +00:00
|
|
|
|
|
|
|
for (int i = 0; i < leaderPlr->groupCnt; i++) {
|
|
|
|
Player* otherPlr = PlayerManager::getPlayerFromID(leaderPlr->groupIDs[i]);
|
|
|
|
CNSocket* sockTo = PlayerManager::getSockFromID(leaderPlr->groupIDs[i]);
|
|
|
|
|
|
|
|
if (otherPlr == nullptr || sockTo == nullptr)
|
|
|
|
continue;
|
|
|
|
|
2020-12-24 04:22:46 +00:00
|
|
|
// save Lair entrance coords for everyone else as well
|
|
|
|
otherPlr->recallX = Warps[warpId].x;
|
|
|
|
otherPlr->recallY = Warps[warpId].y;
|
|
|
|
otherPlr->recallZ = Warps[warpId].z + RESURRECT_HEIGHT;
|
|
|
|
otherPlr->recallInstance = instanceID;
|
|
|
|
|
2020-12-27 23:42:29 +00:00
|
|
|
// remove their vehicle if they're on one
|
2020-12-29 13:31:48 +00:00
|
|
|
if (otherPlr->iPCState & 8) {
|
2020-12-28 16:39:08 +00:00
|
|
|
// remove the player's vehicle
|
|
|
|
otherPlr->iPCState &= ~8;
|
|
|
|
|
|
|
|
// send to self
|
|
|
|
INITSTRUCT(sP_FE2CL_PC_VEHICLE_OFF_SUCC, off);
|
|
|
|
sockTo->sendPacket((void*)&off, P_FE2CL_PC_VEHICLE_OFF_SUCC, sizeof(sP_FE2CL_PC_VEHICLE_OFF_SUCC));
|
|
|
|
|
|
|
|
// send to others
|
|
|
|
INITSTRUCT(sP_FE2CL_PC_STATE_CHANGE, chg);
|
|
|
|
chg.iPC_ID = otherPlr->iID;
|
|
|
|
chg.iState = otherPlr->iPCState;
|
|
|
|
PlayerManager::sendToViewable(sockTo, (void*)&chg, P_FE2CL_PC_STATE_CHANGE, sizeof(sP_FE2CL_PC_STATE_CHANGE));
|
|
|
|
}
|
2020-12-27 23:42:29 +00:00
|
|
|
|
2020-10-17 04:58:51 +00:00
|
|
|
PlayerManager::sendPlayerTo(sockTo, Warps[warpId].x, Warps[warpId].y, Warps[warpId].z, instanceID);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2020-11-18 00:07:04 +00:00
|
|
|
INITSTRUCT(sP_FE2CL_REP_PC_WARP_USE_NPC_SUCC, resp); // Can only be used for exiting instances because it sets the instance flag to false
|
2020-10-02 20:17:24 +00:00
|
|
|
resp.iX = Warps[warpId].x;
|
|
|
|
resp.iY = Warps[warpId].y;
|
|
|
|
resp.iZ = Warps[warpId].z;
|
2020-11-17 23:16:16 +00:00
|
|
|
resp.iCandy = plr->money;
|
2020-10-02 20:17:24 +00:00
|
|
|
resp.eIL = 4; // do not take away any items
|
2020-12-31 02:31:46 +00:00
|
|
|
uint64_t fromInstance = plr->instanceID; // pre-warp instance, saved for post-warp
|
2020-11-17 23:16:16 +00:00
|
|
|
plr->instanceID = INSTANCE_OVERWORLD;
|
2020-12-16 02:25:52 +00:00
|
|
|
MissionManager::failInstancedMissions(sock); // fail any instanced missions
|
2020-10-02 20:17:24 +00:00
|
|
|
sock->sendPacket((void*)&resp, P_FE2CL_REP_PC_WARP_USE_NPC_SUCC, sizeof(sP_FE2CL_REP_PC_WARP_USE_NPC_SUCC));
|
2020-12-28 16:51:57 +00:00
|
|
|
|
2020-11-25 22:42:46 +00:00
|
|
|
ChunkManager::updatePlayerChunk(sock, plr->chunkPos, std::make_tuple(0, 0, 0)); // force player to reload chunks
|
2020-11-18 00:07:04 +00:00
|
|
|
PlayerManager::updatePlayerPosition(sock, resp.iX, resp.iY, resp.iZ, INSTANCE_OVERWORLD, plr->angle);
|
2020-12-28 16:51:57 +00:00
|
|
|
|
|
|
|
// remove the player's ongoing race, if any
|
|
|
|
if (RacingManager::EPRaces.find(sock) != RacingManager::EPRaces.end())
|
|
|
|
RacingManager::EPRaces.erase(sock);
|
2020-12-31 02:31:46 +00:00
|
|
|
|
|
|
|
// post-warp: check if the source instance has no more players in it and delete it if so
|
|
|
|
ChunkManager::destroyInstanceIfEmpty(fromInstance);
|
2020-10-02 20:17:24 +00:00
|
|
|
}
|
2020-09-07 20:12:53 +00:00
|
|
|
}
|
2020-10-11 03:12:12 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Helper function to get NPC closest to coordinates in specified chunks
|
|
|
|
*/
|
2020-11-23 00:14:46 +00:00
|
|
|
BaseNPC* NPCManager::getNearestNPC(std::set<Chunk*>* chunks, int X, int Y, int Z) {
|
2020-10-11 03:12:12 +00:00
|
|
|
BaseNPC* npc = nullptr;
|
|
|
|
int lastDist = INT_MAX;
|
2020-11-23 00:14:46 +00:00
|
|
|
for (auto c = chunks->begin(); c != chunks->end(); c++) { // haha get it
|
2020-10-11 03:12:12 +00:00
|
|
|
Chunk* chunk = *c;
|
|
|
|
for (auto _npc = chunk->NPCs.begin(); _npc != chunk->NPCs.end(); _npc++) {
|
|
|
|
BaseNPC* npcTemp = NPCs[*_npc];
|
|
|
|
int distXY = std::hypot(X - npcTemp->appearanceData.iX, Y - npcTemp->appearanceData.iY);
|
|
|
|
int dist = std::hypot(distXY, Z - npcTemp->appearanceData.iZ);
|
|
|
|
if (dist < lastDist) {
|
|
|
|
npc = npcTemp;
|
|
|
|
lastDist = dist;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return npc;
|
|
|
|
}
|
2020-10-22 08:23:12 +00:00
|
|
|
|
2021-01-06 11:55:55 +00:00
|
|
|
int NPCManager::eggBuffPlayer(CNSocket* sock, int skillId, int eggId, int duration) {
|
2020-10-22 08:23:12 +00:00
|
|
|
Player* plr = PlayerManager::getPlayer(sock);
|
2020-11-13 03:20:51 +00:00
|
|
|
Player* otherPlr = PlayerManager::getPlayerFromID(plr->iIDGroup);
|
2020-10-22 08:23:12 +00:00
|
|
|
|
2020-11-13 03:20:51 +00:00
|
|
|
int bitFlag = GroupManager::getGroupFlags(otherPlr);
|
2020-11-26 02:33:57 +00:00
|
|
|
int CBFlag = NanoManager::applyBuff(sock, skillId, 1, 3, bitFlag);
|
2020-11-17 03:30:01 +00:00
|
|
|
|
2020-11-23 23:42:34 +00:00
|
|
|
size_t resplen;
|
2020-10-22 08:23:12 +00:00
|
|
|
|
2020-11-23 23:42:34 +00:00
|
|
|
if (skillId == 183) {
|
|
|
|
resplen = sizeof(sP_FE2CL_NPC_SKILL_HIT) + sizeof(sSkillResult_Damage);
|
2020-12-12 22:22:22 +00:00
|
|
|
} else if (skillId == 150) {
|
2020-11-23 23:42:34 +00:00
|
|
|
resplen = sizeof(sP_FE2CL_NPC_SKILL_HIT) + sizeof(sSkillResult_Heal_HP);
|
2020-11-26 02:33:57 +00:00
|
|
|
} else {
|
|
|
|
resplen = sizeof(sP_FE2CL_NPC_SKILL_HIT) + sizeof(sSkillResult_Buff);
|
|
|
|
}
|
2020-10-25 21:57:03 +00:00
|
|
|
assert(resplen < CN_PACKET_BUFFER_SIZE - 8);
|
|
|
|
// we know it's only one trailing struct, so we can skip full validation
|
|
|
|
|
2020-11-23 23:42:34 +00:00
|
|
|
uint8_t respbuf[CN_PACKET_BUFFER_SIZE];
|
2020-11-13 03:20:51 +00:00
|
|
|
sP_FE2CL_NPC_SKILL_HIT* skillUse = (sP_FE2CL_NPC_SKILL_HIT*)respbuf;
|
2020-10-25 21:57:03 +00:00
|
|
|
|
2020-11-23 23:42:34 +00:00
|
|
|
if (skillId == 183) { // damage egg
|
|
|
|
sSkillResult_Damage* skill = (sSkillResult_Damage*)(respbuf + sizeof(sP_FE2CL_NPC_SKILL_HIT));
|
|
|
|
memset(respbuf, 0, resplen);
|
|
|
|
skill->eCT = 1;
|
|
|
|
skill->iID = plr->iID;
|
|
|
|
skill->iDamage = PC_MAXHEALTH(plr->level) * NanoManager::SkillTable[skillId].powerIntensity[0] / 1000;
|
|
|
|
plr->HP -= skill->iDamage;
|
2020-11-26 02:33:57 +00:00
|
|
|
if (plr->HP < 0)
|
|
|
|
plr->HP = 0;
|
2020-11-23 23:42:34 +00:00
|
|
|
skill->iHP = plr->HP;
|
2020-12-12 22:22:22 +00:00
|
|
|
} else if (skillId == 150) { // heal egg
|
2020-11-23 23:42:34 +00:00
|
|
|
sSkillResult_Heal_HP* skill = (sSkillResult_Heal_HP*)(respbuf + sizeof(sP_FE2CL_NPC_SKILL_HIT));
|
|
|
|
memset(respbuf, 0, resplen);
|
|
|
|
skill->eCT = 1;
|
|
|
|
skill->iID = plr->iID;
|
|
|
|
skill->iHealHP = PC_MAXHEALTH(plr->level) * NanoManager::SkillTable[skillId].powerIntensity[0] / 1000;
|
|
|
|
plr->HP += skill->iHealHP;
|
|
|
|
if (plr->HP > PC_MAXHEALTH(plr->level))
|
|
|
|
plr->HP = PC_MAXHEALTH(plr->level);
|
|
|
|
skill->iHP = plr->HP;
|
|
|
|
} else { // regular buff egg
|
|
|
|
sSkillResult_Buff* skill = (sSkillResult_Buff*)(respbuf + sizeof(sP_FE2CL_NPC_SKILL_HIT));
|
|
|
|
memset(respbuf, 0, resplen);
|
|
|
|
skill->eCT = 1;
|
|
|
|
skill->iID = plr->iID;
|
|
|
|
skill->iConditionBitFlag = plr->iConditionBitFlag;
|
|
|
|
}
|
|
|
|
|
2020-11-13 03:20:51 +00:00
|
|
|
skillUse->iNPC_ID = eggId;
|
2020-10-25 21:57:03 +00:00
|
|
|
skillUse->iSkillID = skillId;
|
2020-11-23 23:42:34 +00:00
|
|
|
skillUse->eST = NanoManager::SkillTable[skillId].skillType;
|
2020-10-25 21:57:03 +00:00
|
|
|
skillUse->iTargetCnt = 1;
|
|
|
|
|
2020-11-13 03:20:51 +00:00
|
|
|
sock->sendPacket((void*)&respbuf, P_FE2CL_NPC_SKILL_HIT, resplen);
|
|
|
|
PlayerManager::sendToViewable(sock, (void*)&respbuf, P_FE2CL_NPC_SKILL_HIT, resplen);
|
2020-10-25 21:57:03 +00:00
|
|
|
|
2020-11-23 23:42:34 +00:00
|
|
|
if (CBFlag == 0)
|
|
|
|
return -1;
|
|
|
|
|
|
|
|
std::pair<CNSocket*, int32_t> key = std::make_pair(sock, CBFlag);
|
|
|
|
|
|
|
|
// save the buff serverside;
|
|
|
|
// if you get the same buff again, new duration will override the previous one
|
2021-01-06 11:55:55 +00:00
|
|
|
time_t until = getTime() + (time_t)duration * 1000;
|
2020-11-23 23:42:34 +00:00
|
|
|
EggBuffs[key] = until;
|
|
|
|
|
2020-10-22 08:23:12 +00:00
|
|
|
return 0;
|
|
|
|
}
|
2020-10-22 09:09:50 +00:00
|
|
|
|
2020-10-24 19:48:55 +00:00
|
|
|
void NPCManager::eggStep(CNServer* serv, time_t currTime) {
|
|
|
|
// tick buffs
|
2020-11-12 04:49:57 +00:00
|
|
|
time_t timeStamp = currTime;
|
2020-10-22 09:09:50 +00:00
|
|
|
auto it = EggBuffs.begin();
|
|
|
|
while (it != EggBuffs.end()) {
|
2020-10-22 09:28:18 +00:00
|
|
|
// check remaining time
|
2020-10-24 20:57:50 +00:00
|
|
|
if (it->second > timeStamp)
|
2020-10-22 09:09:50 +00:00
|
|
|
it++;
|
2020-11-26 02:33:57 +00:00
|
|
|
else { // if time reached 0
|
2020-10-22 09:09:50 +00:00
|
|
|
CNSocket* sock = it->first.first;
|
2020-11-17 03:30:01 +00:00
|
|
|
int32_t CBFlag = it->first.second;
|
2020-10-22 09:09:50 +00:00
|
|
|
Player* plr = PlayerManager::getPlayer(sock);
|
2020-11-13 03:20:51 +00:00
|
|
|
Player* otherPlr = PlayerManager::getPlayerFromID(plr->iIDGroup);
|
|
|
|
|
2020-11-17 03:30:01 +00:00
|
|
|
int groupFlags = GroupManager::getGroupFlags(otherPlr);
|
|
|
|
for (auto& pwr : NanoManager::NanoPowers) {
|
2020-11-23 23:42:34 +00:00
|
|
|
if (pwr.bitFlag == CBFlag) { // pick the power with the right flag and unbuff
|
2020-11-17 03:30:01 +00:00
|
|
|
INITSTRUCT(sP_FE2CL_PC_BUFF_UPDATE, resp);
|
|
|
|
resp.eCSTB = pwr.timeBuffID;
|
|
|
|
resp.eTBU = 2;
|
|
|
|
resp.eTBT = 3; // for egg buffs
|
|
|
|
plr->iConditionBitFlag &= ~CBFlag;
|
|
|
|
resp.iConditionBitFlag = plr->iConditionBitFlag |= groupFlags | plr->iSelfConditionBitFlag;
|
|
|
|
sock->sendPacket((void*)&resp, P_FE2CL_PC_BUFF_UPDATE, sizeof(sP_FE2CL_PC_BUFF_UPDATE));
|
2020-12-12 22:22:22 +00:00
|
|
|
|
|
|
|
INITSTRUCT(sP_FE2CL_CHAR_TIME_BUFF_TIME_OUT, resp2); // send a buff timeout to other players
|
|
|
|
resp2.eCT = 1;
|
|
|
|
resp2.iID = plr->iID;
|
|
|
|
resp2.iConditionBitFlag = plr->iConditionBitFlag;
|
|
|
|
PlayerManager::sendToViewable(sock, (void*)&resp2, P_FE2CL_CHAR_TIME_BUFF_TIME_OUT, sizeof(sP_FE2CL_CHAR_TIME_BUFF_TIME_OUT));
|
2020-11-17 03:30:01 +00:00
|
|
|
}
|
|
|
|
}
|
2020-10-22 09:09:50 +00:00
|
|
|
// remove buff from the map
|
|
|
|
it = EggBuffs.erase(it);
|
|
|
|
}
|
|
|
|
}
|
2020-10-24 19:48:55 +00:00
|
|
|
|
2020-11-12 04:03:08 +00:00
|
|
|
// check dead eggs and eggs in inactive chunks
|
2020-10-24 19:48:55 +00:00
|
|
|
for (auto egg : Eggs) {
|
2020-11-19 22:19:46 +00:00
|
|
|
if (!egg.second->dead || !ChunkManager::inPopulatedChunks(egg.second->viewableChunks))
|
2020-10-24 20:57:50 +00:00
|
|
|
continue;
|
|
|
|
if (egg.second->deadUntil <= timeStamp) {
|
2020-10-24 19:48:55 +00:00
|
|
|
// respawn it
|
|
|
|
egg.second->dead = false;
|
2020-10-24 20:57:50 +00:00
|
|
|
egg.second->deadUntil = 0;
|
|
|
|
egg.second->appearanceData.iHP = 400;
|
2020-11-18 00:07:04 +00:00
|
|
|
|
2020-11-26 02:33:57 +00:00
|
|
|
ChunkManager::addNPCToChunks(ChunkManager::getViewableChunks(egg.second->chunkPos), egg.first);
|
2020-10-24 19:48:55 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
void NPCManager::npcDataToEggData(sNPCAppearanceData* npc, sShinyAppearanceData* egg) {
|
|
|
|
egg->iX = npc->iX;
|
|
|
|
egg->iY = npc->iY;
|
|
|
|
egg->iZ = npc->iZ;
|
|
|
|
// client doesn't care about egg->iMapNum
|
|
|
|
egg->iShinyType = npc->iNPCType;
|
|
|
|
egg->iShiny_ID = npc->iNPC_ID;
|
|
|
|
}
|
|
|
|
|
|
|
|
void NPCManager::eggPickup(CNSocket* sock, CNPacketData* data) {
|
|
|
|
if (data->size != sizeof(sP_CL2FE_REQ_SHINY_PICKUP))
|
|
|
|
return; // malformed packet
|
|
|
|
|
|
|
|
sP_CL2FE_REQ_SHINY_PICKUP* pickup = (sP_CL2FE_REQ_SHINY_PICKUP*)data->buf;
|
|
|
|
Player* plr = PlayerManager::getPlayer(sock);
|
|
|
|
|
|
|
|
int eggId = pickup->iShinyID;
|
|
|
|
|
|
|
|
if (Eggs.find(eggId) == Eggs.end()) {
|
|
|
|
std::cout << "[WARN] Player tried to open non existing egg?!" << std::endl;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
Egg* egg = Eggs[eggId];
|
|
|
|
|
|
|
|
if (egg->dead) {
|
|
|
|
std::cout << "[WARN] Player tried to open a dead egg?!" << std::endl;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2020-11-17 18:51:35 +00:00
|
|
|
/* this has some issues with position desync, leaving it out for now
|
2020-11-12 04:03:08 +00:00
|
|
|
if (abs(egg->appearanceData.iX - plr->x)>500 || abs(egg->appearanceData.iY - plr->y) > 500) {
|
2020-11-08 09:08:22 +00:00
|
|
|
std::cout << "[WARN] Player tried to open an egg from the other chunk?!" << std::endl;
|
|
|
|
return;
|
|
|
|
}
|
2020-11-17 18:51:35 +00:00
|
|
|
*/
|
2020-11-08 09:08:22 +00:00
|
|
|
|
2020-10-24 19:48:55 +00:00
|
|
|
int typeId = egg->appearanceData.iNPCType;
|
|
|
|
if (EggTypes.find(typeId) == EggTypes.end()) {
|
2020-11-22 21:46:09 +00:00
|
|
|
std::cout << "[WARN] Egg Type " << typeId << " not found!" << std::endl;
|
|
|
|
return;
|
2020-10-24 19:48:55 +00:00
|
|
|
}
|
2020-11-22 21:46:09 +00:00
|
|
|
|
2020-10-24 19:48:55 +00:00
|
|
|
EggType* type = &EggTypes[typeId];
|
|
|
|
|
2020-10-25 21:57:03 +00:00
|
|
|
// buff the player
|
|
|
|
if (type->effectId != 0)
|
2021-01-06 11:55:55 +00:00
|
|
|
eggBuffPlayer(sock, type->effectId, eggId, type->duration);
|
2020-10-25 21:57:03 +00:00
|
|
|
|
|
|
|
/*
|
2020-11-12 04:03:08 +00:00
|
|
|
* SHINY_PICKUP_SUCC is only causing a GUI effect in the client
|
2020-10-25 21:57:03 +00:00
|
|
|
* (buff icon pops up in the bottom of the screen)
|
|
|
|
* so we don't send it for non-effect
|
|
|
|
*/
|
|
|
|
|
|
|
|
if (type->effectId != 0)
|
|
|
|
{
|
2020-11-12 04:03:08 +00:00
|
|
|
INITSTRUCT(sP_FE2CL_REP_SHINY_PICKUP_SUCC, resp);
|
|
|
|
resp.iSkillID = type->effectId;
|
2020-10-24 19:48:55 +00:00
|
|
|
|
2020-11-12 04:03:08 +00:00
|
|
|
// in general client finds correct icon on it's own,
|
|
|
|
// but for damage we have to supply correct CSTB
|
|
|
|
if (resp.iSkillID == 183)
|
|
|
|
resp.eCSTB = ECSB_INFECTION;
|
2020-10-25 21:57:03 +00:00
|
|
|
|
2020-11-12 04:03:08 +00:00
|
|
|
sock->sendPacket((void*)&resp, P_FE2CL_REP_SHINY_PICKUP_SUCC, sizeof(sP_FE2CL_REP_SHINY_PICKUP_SUCC));
|
2020-10-25 21:57:03 +00:00
|
|
|
}
|
2020-10-24 19:48:55 +00:00
|
|
|
|
|
|
|
// drop
|
|
|
|
if (type->dropCrateId != 0) {
|
|
|
|
const size_t resplen = sizeof(sP_FE2CL_REP_REWARD_ITEM) + sizeof(sItemReward);
|
|
|
|
assert(resplen < CN_PACKET_BUFFER_SIZE - 8);
|
|
|
|
// we know it's only one trailing struct, so we can skip full validation
|
|
|
|
|
|
|
|
uint8_t respbuf[resplen]; // not a variable length array, don't worry
|
|
|
|
sP_FE2CL_REP_REWARD_ITEM* reward = (sP_FE2CL_REP_REWARD_ITEM*)respbuf;
|
|
|
|
sItemReward* item = (sItemReward*)(respbuf + sizeof(sP_FE2CL_REP_REWARD_ITEM));
|
|
|
|
|
|
|
|
// don't forget to zero the buffer!
|
|
|
|
memset(respbuf, 0, resplen);
|
|
|
|
|
|
|
|
// send back player's stats
|
|
|
|
reward->m_iCandy = plr->money;
|
|
|
|
reward->m_iFusionMatter = plr->fusionmatter;
|
|
|
|
reward->m_iBatteryN = plr->batteryN;
|
|
|
|
reward->m_iBatteryW = plr->batteryW;
|
|
|
|
reward->iFatigue = 100; // prevents warning message
|
|
|
|
reward->iFatigue_Level = 1;
|
|
|
|
reward->iItemCnt = 1; // remember to update resplen if you change this
|
|
|
|
|
|
|
|
int slot = ItemManager::findFreeSlot(plr);
|
|
|
|
|
|
|
|
// no space for drop
|
|
|
|
if (slot != -1) {
|
|
|
|
|
|
|
|
// item reward
|
|
|
|
item->sItem.iType = 9;
|
|
|
|
item->sItem.iOpt = 1;
|
|
|
|
item->sItem.iID = type->dropCrateId;
|
|
|
|
item->iSlotNum = slot;
|
|
|
|
item->eIL = 1; // Inventory Location. 1 means player inventory.
|
|
|
|
|
|
|
|
// update player
|
|
|
|
plr->Inven[slot] = item->sItem;
|
|
|
|
sock->sendPacket((void*)respbuf, P_FE2CL_REP_REWARD_ITEM, resplen);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (egg->summoned)
|
|
|
|
destroyNPC(eggId);
|
|
|
|
else {
|
2020-11-19 01:37:58 +00:00
|
|
|
ChunkManager::removeNPCFromChunks(ChunkManager::getViewableChunks(egg->chunkPos), eggId);
|
2020-10-24 19:48:55 +00:00
|
|
|
egg->dead = true;
|
2020-11-12 04:49:57 +00:00
|
|
|
egg->deadUntil = getTime() + (time_t)type->regen * 1000;
|
2020-10-24 20:57:50 +00:00
|
|
|
egg->appearanceData.iHP = 0;
|
2020-10-24 19:48:55 +00:00
|
|
|
}
|
2020-10-22 09:09:50 +00:00
|
|
|
}
|
2020-12-15 22:16:18 +00:00
|
|
|
|
|
|
|
#pragma region NPCEvents
|
|
|
|
|
|
|
|
// summon right arm and stage 2 body
|
|
|
|
static void lordFuseStageTwo(CNSocket *sock, BaseNPC *npc) {
|
|
|
|
Mob *oldbody = (Mob*)npc; // adaptium, stun
|
|
|
|
Player *plr = PlayerManager::getPlayer(sock);
|
|
|
|
|
|
|
|
std::cout << "Lord Fuse stage two" << std::endl;
|
|
|
|
|
|
|
|
// Fuse doesn't move; spawnX, etc. is shorter to write than *appearanceData*
|
|
|
|
// Blastons, Heal
|
|
|
|
Mob *newbody = (Mob*)NPCManager::summonNPC(oldbody->spawnX, oldbody->spawnY, oldbody->spawnZ, plr->instanceID, 2467);
|
|
|
|
|
|
|
|
newbody->appearanceData.iAngle = oldbody->appearanceData.iAngle;
|
|
|
|
NPCManager::updateNPCPosition(newbody->appearanceData.iNPC_ID, newbody->spawnX, newbody->spawnY, newbody->spawnZ,
|
|
|
|
plr->instanceID, oldbody->appearanceData.iAngle);
|
|
|
|
|
|
|
|
// right arm, Adaptium, Stun
|
|
|
|
Mob *arm = (Mob*)NPCManager::summonNPC(oldbody->spawnX - 600, oldbody->spawnY, oldbody->spawnZ, plr->instanceID, 2469);
|
|
|
|
|
|
|
|
arm->appearanceData.iAngle = oldbody->appearanceData.iAngle;
|
|
|
|
NPCManager::updateNPCPosition(arm->appearanceData.iNPC_ID, arm->spawnX, arm->spawnY, arm->spawnZ,
|
|
|
|
plr->instanceID, oldbody->appearanceData.iAngle);
|
|
|
|
}
|
|
|
|
|
|
|
|
// summon left arm and stage 3 body
|
|
|
|
static void lordFuseStageThree(CNSocket *sock, BaseNPC *npc) {
|
|
|
|
Mob *oldbody = (Mob*)npc;
|
|
|
|
Player *plr = PlayerManager::getPlayer(sock);
|
|
|
|
|
|
|
|
std::cout << "Lord Fuse stage three" << std::endl;
|
|
|
|
|
2021-01-17 21:50:49 +00:00
|
|
|
// Cosmix, Damage Point
|
2020-12-15 22:16:18 +00:00
|
|
|
Mob *newbody = (Mob*)NPCManager::summonNPC(oldbody->spawnX, oldbody->spawnY, oldbody->spawnZ, plr->instanceID, 2468);
|
|
|
|
|
|
|
|
newbody->appearanceData.iAngle = oldbody->appearanceData.iAngle;
|
|
|
|
NPCManager::updateNPCPosition(newbody->appearanceData.iNPC_ID, newbody->spawnX, newbody->spawnY, newbody->spawnZ,
|
|
|
|
plr->instanceID, oldbody->appearanceData.iAngle);
|
|
|
|
|
|
|
|
// Blastons, Heal
|
|
|
|
Mob *arm = (Mob*)NPCManager::summonNPC(oldbody->spawnX + 600, oldbody->spawnY, oldbody->spawnZ, plr->instanceID, 2470);
|
|
|
|
|
|
|
|
arm->appearanceData.iAngle = oldbody->appearanceData.iAngle;
|
|
|
|
NPCManager::updateNPCPosition(arm->appearanceData.iNPC_ID, arm->spawnX, arm->spawnY, arm->spawnZ,
|
|
|
|
plr->instanceID, oldbody->appearanceData.iAngle);
|
|
|
|
}
|
|
|
|
|
|
|
|
std::vector<NPCEvent> NPCManager::NPCEvents = {
|
|
|
|
NPCEvent(2466, ON_KILLED, lordFuseStageTwo),
|
|
|
|
NPCEvent(2467, ON_KILLED, lordFuseStageThree),
|
|
|
|
};
|
|
|
|
|
|
|
|
#pragma endregion NPCEvents
|