mirror of
https://github.com/OpenFusionProject/OpenFusion.git
synced 2024-11-22 13:30:06 +00:00
Initialize all members of all Entity-derived classes
Also moved some logic out of Mob into CombatNPC.
This commit is contained in:
parent
0c8e209360
commit
22678fcfc2
@ -6,6 +6,7 @@
|
|||||||
#include <set>
|
#include <set>
|
||||||
|
|
||||||
enum class EntityType {
|
enum class EntityType {
|
||||||
|
INVALID,
|
||||||
PLAYER,
|
PLAYER,
|
||||||
SIMPLE_NPC,
|
SIMPLE_NPC,
|
||||||
COMBAT_NPC,
|
COMBAT_NPC,
|
||||||
@ -17,11 +18,11 @@ enum class EntityType {
|
|||||||
class Chunk;
|
class Chunk;
|
||||||
|
|
||||||
struct Entity {
|
struct Entity {
|
||||||
EntityType type;
|
EntityType type = EntityType::INVALID;
|
||||||
int x, y, z;
|
int x = 0, y = 0, z = 0;
|
||||||
uint64_t instanceID;
|
uint64_t instanceID = 0;
|
||||||
ChunkPos chunkPos;
|
ChunkPos chunkPos = {};
|
||||||
std::set<Chunk*> viewableChunks;
|
std::set<Chunk*> viewableChunks = {};
|
||||||
|
|
||||||
// destructor must be virtual, apparently
|
// destructor must be virtual, apparently
|
||||||
virtual ~Entity() {}
|
virtual ~Entity() {}
|
||||||
@ -74,12 +75,11 @@ struct EntityRef {
|
|||||||
*/
|
*/
|
||||||
class BaseNPC : public Entity {
|
class BaseNPC : public Entity {
|
||||||
public:
|
public:
|
||||||
sNPCAppearanceData appearanceData;
|
sNPCAppearanceData appearanceData = {};
|
||||||
//NPCClass npcClass;
|
//NPCClass npcClass;
|
||||||
|
|
||||||
int playersInView;
|
int playersInView = 0;
|
||||||
|
|
||||||
BaseNPC() {};
|
|
||||||
BaseNPC(int x, int y, int z, int angle, uint64_t iID, int t, int id) { // XXX
|
BaseNPC(int x, int y, int z, int angle, uint64_t iID, int t, int id) { // XXX
|
||||||
appearanceData.iX = x;
|
appearanceData.iX = x;
|
||||||
appearanceData.iY = y;
|
appearanceData.iY = y;
|
||||||
@ -109,9 +109,32 @@ public:
|
|||||||
virtual void disappearFromViewOf(CNSocket *sock) override;
|
virtual void disappearFromViewOf(CNSocket *sock) override;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
struct CombatNPC : public BaseNPC {
|
||||||
|
int maxHealth = 0;
|
||||||
|
int spawnX = 0;
|
||||||
|
int spawnY = 0;
|
||||||
|
int spawnZ = 0;
|
||||||
|
int level = 0;
|
||||||
|
|
||||||
|
void (*_stepAI)() = nullptr;
|
||||||
|
|
||||||
|
// XXX
|
||||||
|
CombatNPC(int x, int y, int z, int angle, uint64_t iID, int t, int id, int maxHP) :
|
||||||
|
BaseNPC(x, y, z, angle, iID, t, id),
|
||||||
|
maxHealth(maxHP)
|
||||||
|
{}
|
||||||
|
|
||||||
|
virtual void stepAI() {
|
||||||
|
if (_stepAI != nullptr)
|
||||||
|
_stepAI();
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
// Mob is in MobAI.hpp, Player is in Player.hpp
|
||||||
|
|
||||||
// TODO: decouple from BaseNPC
|
// TODO: decouple from BaseNPC
|
||||||
struct Egg : public BaseNPC {
|
struct Egg : public BaseNPC {
|
||||||
bool summoned;
|
bool summoned = false;
|
||||||
bool dead = false;
|
bool dead = false;
|
||||||
time_t deadUntil;
|
time_t deadUntil;
|
||||||
|
|
||||||
@ -132,17 +155,3 @@ struct Bus : public BaseNPC {
|
|||||||
virtual void enterIntoViewOf(CNSocket *sock) override;
|
virtual void enterIntoViewOf(CNSocket *sock) override;
|
||||||
virtual void disappearFromViewOf(CNSocket *sock) override;
|
virtual void disappearFromViewOf(CNSocket *sock) override;
|
||||||
};
|
};
|
||||||
|
|
||||||
#if 0
|
|
||||||
struct NPC : public Entity {
|
|
||||||
void (*_stepAI)();
|
|
||||||
|
|
||||||
virtual void stepAI() {}
|
|
||||||
};
|
|
||||||
|
|
||||||
struct CombatNPC : public Entity {
|
|
||||||
};
|
|
||||||
|
|
||||||
struct Mob : public CombatNPC {
|
|
||||||
};
|
|
||||||
#endif
|
|
||||||
|
@ -11,51 +11,45 @@ enum class MobState {
|
|||||||
DEAD
|
DEAD
|
||||||
};
|
};
|
||||||
|
|
||||||
struct Mob : public BaseNPC {
|
struct Mob : public CombatNPC {
|
||||||
// general
|
// general
|
||||||
MobState state;
|
MobState state = MobState::INACTIVE;
|
||||||
int maxHealth;
|
|
||||||
int spawnX;
|
|
||||||
int spawnY;
|
|
||||||
int spawnZ;
|
|
||||||
int level;
|
|
||||||
|
|
||||||
std::unordered_map<int32_t,time_t> unbuffTimes;
|
std::unordered_map<int32_t,time_t> unbuffTimes = {};
|
||||||
|
|
||||||
// dead
|
// dead
|
||||||
time_t killedTime = 0;
|
time_t killedTime = 0;
|
||||||
time_t regenTime;
|
time_t regenTime = 0;
|
||||||
bool summoned = false;
|
bool summoned = false;
|
||||||
bool despawned = false; // for the sake of death animations
|
bool despawned = false; // for the sake of death animations
|
||||||
|
|
||||||
// roaming
|
// roaming
|
||||||
int idleRange;
|
int idleRange = 0;
|
||||||
const int sightRange;
|
const int sightRange = 0;
|
||||||
time_t nextMovement = 0;
|
time_t nextMovement = 0;
|
||||||
bool staticPath = false;
|
bool staticPath = false;
|
||||||
int roamX, roamY, roamZ;
|
int roamX = 0, roamY = 0, roamZ = 0;
|
||||||
|
|
||||||
// combat
|
// combat
|
||||||
CNSocket *target = nullptr;
|
CNSocket *target = nullptr;
|
||||||
time_t nextAttack = 0;
|
time_t nextAttack = 0;
|
||||||
time_t lastDrainTime = 0;
|
time_t lastDrainTime = 0;
|
||||||
int skillStyle = -1; // -1 for nothing, 0-2 for corruption, -2 for eruption
|
int skillStyle = -1; // -1 for nothing, 0-2 for corruption, -2 for eruption
|
||||||
int hitX, hitY, hitZ; // for use in ability targeting
|
int hitX = 0, hitY = 0, hitZ = 0; // for use in ability targeting
|
||||||
|
|
||||||
// drop
|
// drop
|
||||||
int dropType;
|
int dropType = 0;
|
||||||
|
|
||||||
// group
|
// group
|
||||||
int groupLeader = 0;
|
int groupLeader = 0;
|
||||||
int offsetX, offsetY;
|
int offsetX = 0, offsetY = 0;
|
||||||
int groupMember[4] = {0, 0, 0, 0};
|
int groupMember[4] = {};
|
||||||
|
|
||||||
// temporary; until we're sure what's what
|
// temporary; until we're sure what's what
|
||||||
nlohmann::json data;
|
nlohmann::json data = {};
|
||||||
|
|
||||||
Mob(int x, int y, int z, int angle, uint64_t iID, int t, nlohmann::json d, int32_t id)
|
Mob(int x, int y, int z, int angle, uint64_t iID, int t, nlohmann::json d, int32_t id)
|
||||||
: BaseNPC(x, y, z, angle, iID, t, id),
|
: CombatNPC(x, y, z, angle, iID, t, id, d["m_iHP"]),
|
||||||
maxHealth(d["m_iHP"]),
|
|
||||||
sightRange(d["m_iSightRange"]) {
|
sightRange(d["m_iSightRange"]) {
|
||||||
state = MobState::ROAMING;
|
state = MobState::ROAMING;
|
||||||
|
|
||||||
|
132
src/Player.hpp
132
src/Player.hpp
@ -12,86 +12,80 @@
|
|||||||
#define PC_MAXHEALTH(level) (925 + 75 * (level))
|
#define PC_MAXHEALTH(level) (925 + 75 * (level))
|
||||||
|
|
||||||
struct Player : public Entity {
|
struct Player : public Entity {
|
||||||
int accountId;
|
int accountId = 0;
|
||||||
int accountLevel; // permission level (see CN_ACCOUNT_LEVEL enums)
|
int accountLevel = 0; // permission level (see CN_ACCOUNT_LEVEL enums)
|
||||||
int64_t SerialKey;
|
int64_t SerialKey = 0;
|
||||||
int32_t iID;
|
int32_t iID = 0;
|
||||||
uint64_t FEKey;
|
uint64_t FEKey = 0;
|
||||||
|
|
||||||
int level;
|
int level = 0;
|
||||||
int HP;
|
int HP = 0;
|
||||||
int slot; // player slot, not nano slot
|
int slot = 0; // player slot, not nano slot
|
||||||
int16_t mentor;
|
int16_t mentor = 0;
|
||||||
int32_t money;
|
int32_t money = 0;
|
||||||
int32_t fusionmatter;
|
int32_t fusionmatter = 0;
|
||||||
int32_t batteryW;
|
int32_t batteryW = 0;
|
||||||
int32_t batteryN;
|
int32_t batteryN = 0;
|
||||||
sPCStyle PCStyle;
|
sPCStyle PCStyle = {};
|
||||||
sPCStyle2 PCStyle2;
|
sPCStyle2 PCStyle2 = {};
|
||||||
sNano Nanos[NANO_COUNT]; // acquired nanos
|
sNano Nanos[NANO_COUNT] = {}; // acquired nanos
|
||||||
int equippedNanos[3];
|
int equippedNanos[3] = {};
|
||||||
int activeNano; // active nano (index into Nanos)
|
int activeNano = 0; // active nano (index into Nanos)
|
||||||
int8_t iPCState;
|
int8_t iPCState = 0;
|
||||||
int32_t iWarpLocationFlag;
|
int32_t iWarpLocationFlag = 0;
|
||||||
int64_t aSkywayLocationFlag[2];
|
int64_t aSkywayLocationFlag[2] = {};
|
||||||
int32_t iConditionBitFlag;
|
int32_t iConditionBitFlag = 0;
|
||||||
int32_t iSelfConditionBitFlag;
|
int32_t iSelfConditionBitFlag = 0;
|
||||||
int8_t iSpecialState;
|
int8_t iSpecialState = 0;
|
||||||
|
|
||||||
//int x, y, z; in superclass
|
int angle = 0;
|
||||||
int angle;
|
int lastX = 0, lastY = 0, lastZ = 0, lastAngle = 0;
|
||||||
int lastX, lastY, lastZ, lastAngle;
|
int recallX = 0, recallY = 0, recallZ = 0, recallInstance = 0; // also Lair entrances
|
||||||
int recallX, recallY, recallZ, recallInstance; // also Lair entrances
|
sItemBase Equip[AEQUIP_COUNT] = {};
|
||||||
//uint64_t instanceID; in superclass
|
sItemBase Inven[AINVEN_COUNT] = {};
|
||||||
sItemBase Equip[AEQUIP_COUNT];
|
sItemBase Bank[ABANK_COUNT] = {};
|
||||||
sItemBase Inven[AINVEN_COUNT];
|
sItemTrade Trade[12] = {};
|
||||||
sItemBase Bank[ABANK_COUNT];
|
int32_t moneyInTrade = 0;
|
||||||
sItemTrade Trade[12];
|
bool isTrading = false;
|
||||||
int32_t moneyInTrade;
|
bool isTradeConfirm = false;
|
||||||
bool isTrading;
|
|
||||||
bool isTradeConfirm;
|
|
||||||
|
|
||||||
bool inCombat;
|
bool inCombat = false;
|
||||||
bool onMonkey;
|
bool onMonkey = false;
|
||||||
int nanoDrainRate;
|
int nanoDrainRate = 0;
|
||||||
int healCooldown;
|
int healCooldown = 0;
|
||||||
|
|
||||||
int pointDamage;
|
int pointDamage = 0;
|
||||||
int groupDamage;
|
int groupDamage = 0;
|
||||||
int fireRate;
|
int fireRate = 0;
|
||||||
int defense;
|
int defense = 0;
|
||||||
|
|
||||||
int64_t aQuestFlag[16];
|
int64_t aQuestFlag[16] = {};
|
||||||
int tasks[ACTIVE_MISSION_COUNT];
|
int tasks[ACTIVE_MISSION_COUNT] = {};
|
||||||
int RemainingNPCCount[ACTIVE_MISSION_COUNT][3];
|
int RemainingNPCCount[ACTIVE_MISSION_COUNT][3] = {};
|
||||||
sItemBase QInven[AQINVEN_COUNT];
|
sItemBase QInven[AQINVEN_COUNT] = {};
|
||||||
int32_t CurrentMissionID;
|
int32_t CurrentMissionID = 0;
|
||||||
|
|
||||||
sTimeLimitItemDeleteInfo2CL toRemoveVehicle;
|
sTimeLimitItemDeleteInfo2CL toRemoveVehicle = {};
|
||||||
|
|
||||||
int32_t iIDGroup;
|
int32_t iIDGroup = 0;
|
||||||
int groupCnt;
|
int groupCnt = 0;
|
||||||
int32_t groupIDs[4];
|
int32_t groupIDs[4] = {};
|
||||||
int32_t iGroupConditionBitFlag;
|
int32_t iGroupConditionBitFlag = 0;
|
||||||
|
|
||||||
bool notify;
|
bool notify = false;
|
||||||
bool hidden;
|
bool hidden = false;
|
||||||
bool unwarpable;
|
bool unwarpable = false;
|
||||||
|
|
||||||
bool buddiesSynced;
|
bool buddiesSynced = false;
|
||||||
int64_t buddyIDs[50];
|
int64_t buddyIDs[50] = {};
|
||||||
bool isBuddyBlocked[50];
|
bool isBuddyBlocked[50] = {};
|
||||||
|
|
||||||
uint64_t iFirstUseFlag[2];
|
uint64_t iFirstUseFlag[2] = {};
|
||||||
|
time_t lastHeartbeat = 0;
|
||||||
|
|
||||||
// in superclass:
|
int suspicionRating = 0;
|
||||||
//ChunkPos chunkPos;
|
time_t lastShot = 0;
|
||||||
//std::set<Chunk*> viewableChunks;
|
std::vector<sItemBase> buyback = {};
|
||||||
time_t lastHeartbeat;
|
|
||||||
|
|
||||||
int suspicionRating;
|
|
||||||
time_t lastShot;
|
|
||||||
std::vector<sItemBase> buyback;
|
|
||||||
|
|
||||||
Player() { type = EntityType::PLAYER; }
|
Player() { type = EntityType::PLAYER; }
|
||||||
|
|
||||||
|
@ -57,8 +57,8 @@ void PlayerManager::removePlayer(CNSocket* key) {
|
|||||||
// save player to DB
|
// save player to DB
|
||||||
Database::updatePlayer(plr);
|
Database::updatePlayer(plr);
|
||||||
|
|
||||||
EntityRef ref = {key};
|
|
||||||
// remove player visually and untrack
|
// remove player visually and untrack
|
||||||
|
EntityRef ref = {key};
|
||||||
Chunking::removeEntityFromChunks(Chunking::getViewableChunks(plr->chunkPos), ref);
|
Chunking::removeEntityFromChunks(Chunking::getViewableChunks(plr->chunkPos), ref);
|
||||||
Chunking::untrackEntity(plr->chunkPos, ref);
|
Chunking::untrackEntity(plr->chunkPos, ref);
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user