client-side NPCs

This commit is contained in:
Kae 2023-07-26 16:45:01 +10:00
parent 76f78c4b20
commit aa220e7947
4 changed files with 26 additions and 0 deletions

View File

@ -246,6 +246,10 @@ PolyF const& MovementController::collisionPoly() const {
return m_collisionPoly.get(); return m_collisionPoly.get();
} }
void MovementController::setCollisionPoly(PolyF const& poly) {
m_collisionPoly.set(poly);
}
Vec2F MovementController::position() const { Vec2F MovementController::position() const {
return {m_xPosition.get(), m_yPosition.get()}; return {m_xPosition.get(), m_yPosition.get()};
} }

View File

@ -97,6 +97,7 @@ public:
// Currently active collisionPoly parameter // Currently active collisionPoly parameter
PolyF const& collisionPoly() const; PolyF const& collisionPoly() const;
void setCollisionPoly(PolyF const& poly);
Vec2F position() const; Vec2F position() const;
float xPosition() const; float xPosition() const;

View File

@ -46,6 +46,8 @@ Npc::Npc(NpcVariant const& npcVariant)
m_questIndicatorOffset = jsonToVec2F(assets->json("/quests/quests.config:defaultIndicatorOffset")); m_questIndicatorOffset = jsonToVec2F(assets->json("/quests/quests.config:defaultIndicatorOffset"));
m_clientEntityMode = ClientEntityModeNames.getLeft(npcVariant.overrides.getString("clientEntityMode", "ClientSlaveOnly"));
m_isInteractive.set(false); m_isInteractive.set(false);
m_shifting.set(false); m_shifting.set(false);
@ -157,6 +159,10 @@ EntityType Npc::entityType() const {
return EntityType::Npc; return EntityType::Npc;
} }
ClientEntityMode Npc::clientEntityMode() const {
return m_clientEntityMode;
}
void Npc::init(World* world, EntityId entityId, EntityMode mode) { void Npc::init(World* world, EntityId entityId, EntityMode mode) {
Entity::init(world, entityId, mode); Entity::init(world, entityId, mode);
m_movementController->init(world); m_movementController->init(world);
@ -246,6 +252,18 @@ RectF Npc::collisionArea() const {
} }
pair<ByteArray, uint64_t> Npc::writeNetState(uint64_t fromVersion) { pair<ByteArray, uint64_t> Npc::writeNetState(uint64_t fromVersion) {
// client-side npcs error nearby vanilla NPC scripts because callScriptedEntity
// for now, scrungle the collision poly to avoid their queries. hacky :(
if (auto mode = entityMode()) {
if (*mode == EntityMode::Master && connectionForEntity(entityId()) != ServerConnectionId) {
PolyF poly = m_movementController->collisionPoly();
m_movementController->setCollisionPoly({});
auto result = m_netGroup.writeNetState(fromVersion);
m_movementController->setCollisionPoly(poly);
return result;
}
}
return m_netGroup.writeNetState(fromVersion); return m_netGroup.writeNetState(fromVersion);
} }

View File

@ -50,6 +50,7 @@ public:
ByteArray netStore(); ByteArray netStore();
EntityType entityType() const override; EntityType entityType() const override;
ClientEntityMode clientEntityMode() const override;
void init(World* world, EntityId entityId, EntityMode mode) override; void init(World* world, EntityId entityId, EntityMode mode) override;
void uninit() override; void uninit() override;
@ -201,6 +202,8 @@ private:
NetElementData<Maybe<String>> m_uniqueIdNetState; NetElementData<Maybe<String>> m_uniqueIdNetState;
NetElementData<EntityDamageTeam> m_teamNetState; NetElementData<EntityDamageTeam> m_teamNetState;
ClientEntityMode m_clientEntityMode;
Humanoid m_humanoid; Humanoid m_humanoid;
NetElementEnum<Humanoid::State> m_humanoidStateNetState; NetElementEnum<Humanoid::State> m_humanoidStateNetState;
NetElementEnum<HumanoidEmote> m_humanoidEmoteStateNetState; NetElementEnum<HumanoidEmote> m_humanoidEmoteStateNetState;