MCPcopy Create free account
hub / github.com/OpenStarbound/OpenStarbound / init

Method init

source/game/StarMonster.cpp:125–167  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

123}
124
125void 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
169void Monster::uninit() {
170 if (isMaster()) {

Callers

nothing calls this directly

Calls 15

initFunction · 0.85
singletonClass · 0.85
functionDatabaseMethod · 0.80
functionMethod · 0.80
isClientMethod · 0.80
setScriptsMethod · 0.80
getMethod · 0.45
threatLevelMethod · 0.45
evaluateMethod · 0.45
setPersistentEffectsMethod · 0.45

Tested by

no test coverage detected