(WIP) Initial ICombatant draft

This commit is contained in:
gsemaj 2022-04-11 10:26:57 -04:00
parent 4494ba5932
commit 5ab0112298
4 changed files with 47 additions and 8 deletions

View File

@ -77,7 +77,7 @@ void Chunking::untrackEntity(ChunkPos chunkPos, const EntityRef& ref) {
void Chunking::addEntityToChunks(std::set<Chunk*> chnks, const EntityRef& ref) { void Chunking::addEntityToChunks(std::set<Chunk*> chnks, const EntityRef& ref) {
Entity *ent = ref.getEntity(); Entity *ent = ref.getEntity();
bool alive = ent->isAlive(); bool alive = ent->isExtant();
// TODO: maybe optimize this, potentially using AROUND packets? // TODO: maybe optimize this, potentially using AROUND packets?
for (Chunk *chunk : chnks) { for (Chunk *chunk : chnks) {
@ -94,7 +94,7 @@ void Chunking::addEntityToChunks(std::set<Chunk*> chnks, const EntityRef& ref) {
} }
// notify this *player* of the existence of all visible Entities // notify this *player* of the existence of all visible Entities
if (ref.type == EntityType::PLAYER && other->isAlive()) { if (ref.type == EntityType::PLAYER && other->isExtant()) {
other->enterIntoViewOf(ref.sock); other->enterIntoViewOf(ref.sock);
} }
@ -109,7 +109,7 @@ void Chunking::addEntityToChunks(std::set<Chunk*> chnks, const EntityRef& ref) {
void Chunking::removeEntityFromChunks(std::set<Chunk*> chnks, const EntityRef& ref) { void Chunking::removeEntityFromChunks(std::set<Chunk*> chnks, const EntityRef& ref) {
Entity *ent = ref.getEntity(); Entity *ent = ref.getEntity();
bool alive = ent->isAlive(); bool alive = ent->isExtant();
// TODO: same as above // TODO: same as above
for (Chunk *chunk : chnks) { for (Chunk *chunk : chnks) {
@ -126,7 +126,7 @@ void Chunking::removeEntityFromChunks(std::set<Chunk*> chnks, const EntityRef& r
} }
// notify this *player* of the departure of all visible Entities // notify this *player* of the departure of all visible Entities
if (ref.type == EntityType::PLAYER && other->isAlive()) { if (ref.type == EntityType::PLAYER && other->isExtant()) {
other->disappearFromViewOf(ref.sock); other->disappearFromViewOf(ref.sock);
} }

View File

@ -103,6 +103,19 @@ sPCAppearanceData Player::getAppearanceData() {
return data; return data;
} }
// player combat methods; not sure if this is the right place to put them
void Player::takeDamage(EntityRef src, int amt) {
// stubbed
}
void Player::heal(EntityRef src, int amt) {
// stubbed
}
bool Player::isAlive() {
return HP > 0;
}
// TODO: this is less effiecient than it was, because of memset() // TODO: this is less effiecient than it was, because of memset()
void Player::enterIntoViewOf(CNSocket *sock) { void Player::enterIntoViewOf(CNSocket *sock) {
INITSTRUCT(sP_FE2CL_PC_NEW, pkt); INITSTRUCT(sP_FE2CL_PC_NEW, pkt);

View File

@ -26,7 +26,7 @@ struct Entity {
// destructor must be virtual, apparently // destructor must be virtual, apparently
virtual ~Entity() {} virtual ~Entity() {}
virtual bool isAlive() { return true; } virtual bool isExtant() { return true; }
// stubs // stubs
virtual void enterIntoViewOf(CNSocket *sock) = 0; virtual void enterIntoViewOf(CNSocket *sock) = 0;
@ -69,6 +69,20 @@ struct EntityRef {
} }
}; };
/*
* Interfaces
*/
class ICombatant {
public:
ICombatant() {}
virtual ~ICombatant() {}
virtual void takeDamage(EntityRef, int) = 0;
virtual void heal(EntityRef, int) = 0;
virtual bool isAlive() = 0;
};
/* /*
* Subclasses * Subclasses
*/ */
@ -98,7 +112,7 @@ public:
sNPCAppearanceData getAppearanceData(); sNPCAppearanceData getAppearanceData();
}; };
struct CombatNPC : public BaseNPC { struct CombatNPC : public BaseNPC, public ICombatant {
int maxHealth = 0; int maxHealth = 0;
int spawnX = 0; int spawnX = 0;
int spawnY = 0; int spawnY = 0;
@ -120,6 +134,14 @@ struct CombatNPC : public BaseNPC {
_stepAI(this, currTime); _stepAI(this, currTime);
} }
virtual void takeDamage(EntityRef src, int amt) override {
// stubbed
}
virtual void heal(EntityRef src, int amt) override {
// stubbed
}
virtual bool isAlive() override { return hp > 0; } virtual bool isAlive() override { return hp > 0; }
}; };
@ -137,7 +159,7 @@ struct Egg : public BaseNPC {
kind = EntityType::EGG; kind = EntityType::EGG;
} }
virtual bool isAlive() override { return !dead; } virtual bool isExtant() override { return !dead; }
virtual void enterIntoViewOf(CNSocket *sock) override; virtual void enterIntoViewOf(CNSocket *sock) override;
virtual void disappearFromViewOf(CNSocket *sock) override; virtual void disappearFromViewOf(CNSocket *sock) override;

View File

@ -11,7 +11,7 @@
#define PC_MAXHEALTH(level) (925 + 75 * (level)) #define PC_MAXHEALTH(level) (925 + 75 * (level))
struct Player : public Entity { struct Player : public Entity, public ICombatant {
int accountId = 0; int accountId = 0;
int accountLevel = 0; // permission level (see CN_ACCOUNT_LEVEL enums) int accountLevel = 0; // permission level (see CN_ACCOUNT_LEVEL enums)
int32_t iID = 0; int32_t iID = 0;
@ -90,5 +90,9 @@ struct Player : public Entity {
virtual void enterIntoViewOf(CNSocket *sock) override; virtual void enterIntoViewOf(CNSocket *sock) override;
virtual void disappearFromViewOf(CNSocket *sock) override; virtual void disappearFromViewOf(CNSocket *sock) override;
virtual void takeDamage(EntityRef src, int amt) override;
virtual void heal(EntityRef src, int amt) override;
virtual bool isAlive() override;
sPCAppearanceData getAppearanceData(); sPCAppearanceData getAppearanceData();
}; };