From aa220e7947372fccc2657a15d550408737ad1db7 Mon Sep 17 00:00:00 2001 From: Kae <80987908+Novaenia@users.noreply.github.com> Date: Wed, 26 Jul 2023 16:45:01 +1000 Subject: [PATCH] client-side NPCs --- source/game/StarMovementController.cpp | 4 ++++ source/game/StarMovementController.hpp | 1 + source/game/StarNpc.cpp | 18 ++++++++++++++++++ source/game/StarNpc.hpp | 3 +++ 4 files changed, 26 insertions(+) diff --git a/source/game/StarMovementController.cpp b/source/game/StarMovementController.cpp index facf3c5..dd171c1 100644 --- a/source/game/StarMovementController.cpp +++ b/source/game/StarMovementController.cpp @@ -246,6 +246,10 @@ PolyF const& MovementController::collisionPoly() const { return m_collisionPoly.get(); } +void MovementController::setCollisionPoly(PolyF const& poly) { + m_collisionPoly.set(poly); +} + Vec2F MovementController::position() const { return {m_xPosition.get(), m_yPosition.get()}; } diff --git a/source/game/StarMovementController.hpp b/source/game/StarMovementController.hpp index f13e3e5..f5930cb 100644 --- a/source/game/StarMovementController.hpp +++ b/source/game/StarMovementController.hpp @@ -97,6 +97,7 @@ public: // Currently active collisionPoly parameter PolyF const& collisionPoly() const; + void setCollisionPoly(PolyF const& poly); Vec2F position() const; float xPosition() const; diff --git a/source/game/StarNpc.cpp b/source/game/StarNpc.cpp index b5fb690..bd2aa55 100644 --- a/source/game/StarNpc.cpp +++ b/source/game/StarNpc.cpp @@ -46,6 +46,8 @@ Npc::Npc(NpcVariant const& npcVariant) m_questIndicatorOffset = jsonToVec2F(assets->json("/quests/quests.config:defaultIndicatorOffset")); + m_clientEntityMode = ClientEntityModeNames.getLeft(npcVariant.overrides.getString("clientEntityMode", "ClientSlaveOnly")); + m_isInteractive.set(false); m_shifting.set(false); @@ -157,6 +159,10 @@ EntityType Npc::entityType() const { return EntityType::Npc; } +ClientEntityMode Npc::clientEntityMode() const { + return m_clientEntityMode; +} + void Npc::init(World* world, EntityId entityId, EntityMode mode) { Entity::init(world, entityId, mode); m_movementController->init(world); @@ -246,6 +252,18 @@ RectF Npc::collisionArea() const { } pair 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); } diff --git a/source/game/StarNpc.hpp b/source/game/StarNpc.hpp index b4fc21e..02a6ae1 100644 --- a/source/game/StarNpc.hpp +++ b/source/game/StarNpc.hpp @@ -50,6 +50,7 @@ public: ByteArray netStore(); EntityType entityType() const override; + ClientEntityMode clientEntityMode() const override; void init(World* world, EntityId entityId, EntityMode mode) override; void uninit() override; @@ -201,6 +202,8 @@ private: NetElementData> m_uniqueIdNetState; NetElementData m_teamNetState; + ClientEntityMode m_clientEntityMode; + Humanoid m_humanoid; NetElementEnum m_humanoidStateNetState; NetElementEnum m_humanoidEmoteStateNetState;