mirror of
https://github.com/OpenFusionProject/OpenFusion.git
synced 2024-11-22 05:20:05 +00:00
Merge pull request #37 from dongresource/work1
Respawn points, NPC spawning, misc stuff.
This commit is contained in:
commit
b187d4b65f
@ -23,6 +23,10 @@ view=20000
|
||||
motd=Welcome to OpenFusion!
|
||||
# NPC json data
|
||||
npcdata=NPCs.json
|
||||
# warp target json data
|
||||
warpdata=warps.json
|
||||
# is everyone a GM?
|
||||
gm=true
|
||||
|
||||
# spawn coordinates (Z is height)
|
||||
# the supplied defaults are at City Hall
|
||||
|
@ -58,7 +58,7 @@ void CNLoginServer::handlePacket(CNSocket* sock, CNPacketData* data) {
|
||||
for (int i = 0; i < charCount; i++) {
|
||||
sP_LS2CL_REP_CHAR_INFO charInfo = sP_LS2CL_REP_CHAR_INFO();
|
||||
charInfo.iSlot = (int8_t)i + 1;
|
||||
charInfo.iLevel = (int16_t)1;
|
||||
charInfo.iLevel = (int16_t)36;
|
||||
charInfo.sPC_Style.iPC_UID = rand(); // unique identifier for the character
|
||||
charInfo.sPC_Style.iNameCheck = 1;
|
||||
charInfo.sPC_Style.iGender = (i%2)+1; // can be 1(boy) or 2(girl)
|
||||
@ -92,7 +92,7 @@ void CNLoginServer::handlePacket(CNSocket* sock, CNPacketData* data) {
|
||||
loginSessions[sock].characters[UID].z = charInfo.iZ;
|
||||
loginSessions[sock].characters[UID].PCStyle = charInfo.sPC_Style;
|
||||
loginSessions[sock].characters[UID].PCStyle2 = charInfo.sPC_Style2;
|
||||
loginSessions[sock].characters[UID].IsGM = false;
|
||||
loginSessions[sock].characters[UID].IsGM = settings::GM;
|
||||
|
||||
for (int i = 0; i < AEQUIP_COUNT; i++) {
|
||||
// setup equips
|
||||
@ -227,7 +227,7 @@ void CNLoginServer::handlePacket(CNSocket* sock, CNPacketData* data) {
|
||||
loginSessions[sock].characters[UID].Equip[2].iType = 2;
|
||||
loginSessions[sock].characters[UID].Equip[3].iID = character->sOn_Item.iEquipFootID; // foot!
|
||||
loginSessions[sock].characters[UID].Equip[3].iType = 3;
|
||||
loginSessions[sock].characters[UID].IsGM = false;
|
||||
loginSessions[sock].characters[UID].IsGM = settings::GM;
|
||||
|
||||
sock->sendPacket((void*)&resp, P_LS2CL_REP_CHAR_CREATE_SUCC, sizeof(sP_LS2CL_REP_CHAR_CREATE_SUCC));
|
||||
break;
|
||||
|
@ -5,17 +5,19 @@
|
||||
#include <algorithm>
|
||||
#include <list>
|
||||
#include <fstream>
|
||||
#include <vector>
|
||||
|
||||
#include "contrib/JSON.hpp"
|
||||
|
||||
std::map<int32_t, BaseNPC> NPCManager::NPCs;
|
||||
std::map<int32_t, WarpLocation> NPCManager::Warps;
|
||||
std::vector<WarpLocation> NPCManager::RespawnPoints;
|
||||
|
||||
void NPCManager::init() {
|
||||
// load NPCs from NPCs.json into our NPC manager
|
||||
|
||||
try {
|
||||
std::ifstream inFile("NPCs.json");
|
||||
std::ifstream inFile(settings::NPCJSON);
|
||||
nlohmann::json npcData;
|
||||
|
||||
// read file into json
|
||||
@ -24,6 +26,9 @@ void NPCManager::init() {
|
||||
for (nlohmann::json::iterator npc = npcData.begin(); npc != npcData.end(); npc++) {
|
||||
BaseNPC tmp(npc.value()["x"], npc.value()["y"], npc.value()["z"], npc.value()["id"]);
|
||||
NPCs[tmp.appearanceData.iNPC_ID] = tmp;
|
||||
|
||||
if (npc.value()["id"] == 641 || npc.value()["id"] == 642)
|
||||
RespawnPoints.push_back({npc.value()["x"], npc.value()["y"], ((int)npc.value()["z"]) + RESURRECT_HEIGHT});
|
||||
}
|
||||
|
||||
std::cout << "[INFO] populated " << NPCs.size() << " NPCs" << std::endl;
|
||||
@ -32,7 +37,7 @@ void NPCManager::init() {
|
||||
}
|
||||
|
||||
try {
|
||||
std::ifstream infile("warps.json");
|
||||
std::ifstream infile(settings::WARPJSON);
|
||||
nlohmann::json warpData;
|
||||
|
||||
// read file into json
|
||||
@ -50,7 +55,8 @@ void NPCManager::init() {
|
||||
}
|
||||
|
||||
|
||||
REGISTER_SHARD_PACKET(P_CL2FE_REQ_PC_WARP_USE_NPC, npcWarpManager);
|
||||
REGISTER_SHARD_PACKET(P_CL2FE_REQ_PC_WARP_USE_NPC, npcWarpHandler);
|
||||
REGISTER_SHARD_PACKET(P_CL2FE_REQ_NPC_SUMMON, npcSummonHandler);
|
||||
}
|
||||
|
||||
void NPCManager::updatePlayerNPCS(CNSocket* sock, PlayerView& view) {
|
||||
@ -102,8 +108,7 @@ void NPCManager::updatePlayerNPCS(CNSocket* sock, PlayerView& view) {
|
||||
PlayerManager::players[sock].viewableNPCs = view.viewableNPCs;
|
||||
}
|
||||
|
||||
void NPCManager::npcWarpManager(CNSocket* sock, CNPacketData* data)
|
||||
{
|
||||
void NPCManager::npcWarpHandler(CNSocket* sock, CNPacketData* data) {
|
||||
if (data->size != sizeof(sP_CL2FE_REQ_PC_WARP_USE_NPC))
|
||||
return; // malformed packet
|
||||
|
||||
@ -122,3 +127,25 @@ void NPCManager::npcWarpManager(CNSocket* sock, CNPacketData* data)
|
||||
sock->sendPacket((void*)&resp, P_FE2CL_REP_PC_WARP_USE_NPC_SUCC, sizeof(sP_FE2CL_REP_PC_WARP_USE_NPC_SUCC));
|
||||
|
||||
}
|
||||
|
||||
void NPCManager::npcSummonHandler(CNSocket *sock, CNPacketData *data) {
|
||||
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;
|
||||
INITSTRUCT(sP_FE2CL_NPC_ENTER, resp);
|
||||
Player *plr = PlayerManager::getPlayer(sock);
|
||||
|
||||
// permission & sanity check
|
||||
if (!plr->IsGM || req->iNPCType >= NPCs.size())
|
||||
return;
|
||||
|
||||
resp.NPCAppearanceData.iNPC_ID = rand(); // cpunch-style
|
||||
resp.NPCAppearanceData.iNPCType = req->iNPCType;
|
||||
resp.NPCAppearanceData.iHP = 1000; // TODO: placeholder
|
||||
resp.NPCAppearanceData.iX = plr->x;
|
||||
resp.NPCAppearanceData.iY = plr->y;
|
||||
resp.NPCAppearanceData.iZ = plr->z;
|
||||
|
||||
sock->sendPacket((void*)&resp, P_FE2CL_NPC_ENTER, sizeof(sP_FE2CL_NPC_ENTER));
|
||||
}
|
||||
|
@ -5,7 +5,11 @@
|
||||
#include "NPC.hpp"
|
||||
|
||||
#include <map>
|
||||
#include <vector>
|
||||
|
||||
#define RESURRECT_HEIGHT 400
|
||||
|
||||
// this should really be called vec3 or something...
|
||||
struct WarpLocation {
|
||||
int x, y, z;
|
||||
};
|
||||
@ -13,9 +17,10 @@ struct WarpLocation {
|
||||
namespace NPCManager {
|
||||
extern std::map<int32_t, BaseNPC> NPCs;
|
||||
extern std::map<int32_t, WarpLocation> Warps;
|
||||
extern std::vector<WarpLocation> RespawnPoints;
|
||||
void init();
|
||||
|
||||
void updatePlayerNPCS(CNSocket* sock, PlayerView& plr);
|
||||
void npcWarpManager(CNSocket* sock, CNPacketData* data);
|
||||
|
||||
void npcWarpHandler(CNSocket* sock, CNPacketData* data);
|
||||
void npcSummonHandler(CNSocket* sock, CNPacketData* data);
|
||||
}
|
||||
|
@ -227,6 +227,10 @@ void PlayerManager::enterPlayer(CNSocket* sock, CNPacketData* data) {
|
||||
|
||||
response.PCLoadData2CL.aQuestFlag[0] = -1;
|
||||
|
||||
// shut computress up
|
||||
response.PCLoadData2CL.iFirstUseFlag1 = UINT64_MAX;
|
||||
response.PCLoadData2CL.iFirstUseFlag2 = UINT64_MAX;
|
||||
|
||||
plr.iID = response.iID;
|
||||
plr.SerialKey = enter->iEnterSerialKey;
|
||||
plr.HP = response.PCLoadData2CL.iHP;
|
||||
@ -575,6 +579,7 @@ void PlayerManager::revivePlayer(CNSocket* sock, CNPacketData* data) {
|
||||
return;
|
||||
|
||||
Player *plr = PlayerManager::getPlayer(sock);
|
||||
WarpLocation target = PlayerManager::getRespawnPoint(plr);
|
||||
|
||||
// players respawn at same spot they died at for now...
|
||||
sP_CL2FE_REQ_PC_REGEN* reviveData = (sP_CL2FE_REQ_PC_REGEN*)data->buf;
|
||||
@ -582,9 +587,9 @@ void PlayerManager::revivePlayer(CNSocket* sock, CNPacketData* data) {
|
||||
response.bMoveLocation = reviveData->eIL;
|
||||
response.PCRegenData.iMapNum = reviveData->iIndex;
|
||||
response.PCRegenData.iHP = 1000 * plr->level;
|
||||
response.PCRegenData.iX = plr->x;
|
||||
response.PCRegenData.iY = plr->y;
|
||||
response.PCRegenData.iZ = plr->z;
|
||||
response.PCRegenData.iX = target.x;
|
||||
response.PCRegenData.iY = target.y;
|
||||
response.PCRegenData.iZ = target.z;
|
||||
|
||||
sock->sendPacket((void*)&response, P_FE2CL_REP_PC_REGEN_SUCC, sizeof(sP_FE2CL_REP_PC_REGEN_SUCC));
|
||||
}
|
||||
@ -636,4 +641,19 @@ void PlayerManager::setSpecialSwitchPlayer(CNSocket* sock, CNPacketData* data) {
|
||||
Player *PlayerManager::getPlayer(CNSocket* key) {
|
||||
return players[key].plr;
|
||||
}
|
||||
|
||||
WarpLocation PlayerManager::getRespawnPoint(Player *plr) {
|
||||
WarpLocation best;
|
||||
uint32_t curDist, bestDist = UINT32_MAX;
|
||||
|
||||
for (auto targ : NPCManager::RespawnPoints) {
|
||||
curDist = sqrt(pow(plr->x - targ.x, 2) + pow(plr->y - targ.y, 2));
|
||||
if (curDist < bestDist) {
|
||||
best = targ;
|
||||
bestDist = curDist;
|
||||
}
|
||||
}
|
||||
|
||||
return best;
|
||||
}
|
||||
#pragma endregion
|
||||
|
@ -8,6 +8,8 @@
|
||||
#include <map>
|
||||
#include <list>
|
||||
|
||||
struct WarpLocation;
|
||||
|
||||
struct PlayerView {
|
||||
std::list<CNSocket*> viewable;
|
||||
std::list<int32_t> viewableNPCs;
|
||||
@ -22,7 +24,6 @@ namespace PlayerManager {
|
||||
|
||||
void addPlayer(CNSocket* key, Player plr);
|
||||
void removePlayer(CNSocket* key);
|
||||
Player *getPlayer(CNSocket* key);
|
||||
|
||||
void updatePlayerPosition(CNSocket* sock, int X, int Y, int Z);
|
||||
std::list<CNSocket*> getNearbyPlayers(int X, int Y, int dist);
|
||||
@ -47,4 +48,7 @@ namespace PlayerManager {
|
||||
|
||||
void enterPlayerVehicle(CNSocket* sock, CNPacketData* data);
|
||||
void exitPlayerVehicle(CNSocket* sock, CNPacketData* data);
|
||||
|
||||
Player *getPlayer(CNSocket* key);
|
||||
WarpLocation getRespawnPoint(Player *plr);
|
||||
}
|
||||
|
@ -18,7 +18,9 @@ int settings::SPAWN_Y = 268451;
|
||||
int settings::SPAWN_Z = -4210;
|
||||
std::string settings::GMPASS = "pass";
|
||||
std::string settings::NPCJSON = "NPCs.json";
|
||||
std::string settings::WARPJSON = "warps.json";
|
||||
std::string settings::MOTDSTRING = "Welcome to OpenFusion!";
|
||||
bool settings::GM = false;
|
||||
|
||||
void settings::init() {
|
||||
INIReader reader("config.ini");
|
||||
@ -43,6 +45,7 @@ void settings::init() {
|
||||
SPAWN_Z = reader.GetInteger("shard", "spawnz", SPAWN_Z);
|
||||
GMPASS = reader.Get("login", "pass", GMPASS);
|
||||
NPCJSON = reader.Get("shard", "npcdata", NPCJSON);
|
||||
WARPJSON = reader.Get("shard", "warpdata", WARPJSON);
|
||||
MOTDSTRING = reader.Get("shard", "motd", MOTDSTRING);
|
||||
|
||||
GM = reader.GetBoolean("shard", "gm", GM);
|
||||
}
|
||||
|
@ -12,7 +12,9 @@ namespace settings {
|
||||
extern int SPAWN_Z;
|
||||
extern std::string MOTDSTRING;
|
||||
extern std::string NPCJSON;
|
||||
extern std::string WARPJSON;
|
||||
extern std::string GMPASS;
|
||||
extern bool GM;
|
||||
|
||||
void init();
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user