| 123 | } |
| 124 | |
| 125 | void Monster::init(World* world, EntityId entityId, EntityMode mode) { |
| 126 | Entity::init(world, entityId, mode); |
| 127 | |
| 128 | m_movementController->init(world); |
| 129 | m_movementController->setIgnorePhysicsEntities({entityId}); |
| 130 | m_statusController->init(this, m_movementController.get()); |
| 131 | |
| 132 | if (!m_monsterLevel) |
| 133 | m_monsterLevel = world->threatLevel(); |
| 134 | |
| 135 | if (isMaster()) { |
| 136 | auto functionDatabase = Root::singleton().functionDatabase(); |
| 137 | float healthMultiplier = m_monsterVariant.healthMultiplier * functionDatabase->function(m_monsterVariant.healthLevelFunction)->evaluate(*m_monsterLevel); |
| 138 | m_statusController->setPersistentEffects("innate", {StatModifier(StatBaseMultiplier{"maxHealth", healthMultiplier})}); |
| 139 | |
| 140 | m_scriptComponent.addCallbacks("monster", makeMonsterCallbacks()); |
| 141 | m_scriptComponent.addCallbacks("config", LuaBindings::makeConfigCallbacks([this](String const& name, Json const& def) { |
| 142 | return m_monsterVariant.parameters.query(name, def); |
| 143 | })); |
| 144 | m_scriptComponent.addCallbacks("entity", LuaBindings::makeEntityCallbacks(this)); |
| 145 | m_scriptComponent.addCallbacks("animator", LuaBindings::makeNetworkedAnimatorCallbacks(&m_networkedAnimator)); |
| 146 | m_scriptComponent.addCallbacks("status", LuaBindings::makeStatusControllerCallbacks(m_statusController.get())); |
| 147 | m_scriptComponent.addCallbacks("behavior", LuaBindings::makeBehaviorCallbacks(&m_behaviors)); |
| 148 | m_scriptComponent.addActorMovementCallbacks(m_movementController.get()); |
| 149 | m_scriptComponent.init(world); |
| 150 | } |
| 151 | |
| 152 | if (world->isClient()) { |
| 153 | m_scriptedAnimator.setScripts(m_monsterVariant.animationScripts); |
| 154 | |
| 155 | m_scriptedAnimator.addCallbacks("animationConfig", LuaBindings::makeScriptedAnimatorCallbacks(&m_networkedAnimator, |
| 156 | [this](String const& name, Json const& defaultValue) -> Json { |
| 157 | return m_scriptedAnimationParameters.value(name, defaultValue); |
| 158 | })); |
| 159 | m_scriptedAnimator.addCallbacks("config", LuaBindings::makeConfigCallbacks([this](String const& name, Json const& def) { |
| 160 | return m_monsterVariant.parameters.query(name, def); |
| 161 | })); |
| 162 | m_scriptedAnimator.addCallbacks("entity", LuaBindings::makeEntityCallbacks(this)); |
| 163 | m_scriptedAnimator.init(world); |
| 164 | } |
| 165 | |
| 166 | setPosition(position()); |
| 167 | } |
| 168 | |
| 169 | void Monster::uninit() { |
| 170 | if (isMaster()) { |
nothing calls this directly
no test coverage detected