Merge branch 'main' of https://github.com/OpenStarbound/OpenStarbound
This commit is contained in:
commit
e6d2f5975b
@ -650,22 +650,26 @@ void StatusController::updateAnimators(float dt) {
|
|||||||
|
|
||||||
void StatusController::updatePersistentUniqueEffects() {
|
void StatusController::updatePersistentUniqueEffects() {
|
||||||
Set<UniqueStatusEffect> activePersistentUniqueEffects;
|
Set<UniqueStatusEffect> activePersistentUniqueEffects;
|
||||||
for (auto const& categoryPair : m_persistentEffects)
|
for (auto & categoryPair : m_persistentEffects) {
|
||||||
activePersistentUniqueEffects.addAll(categoryPair.second.uniqueEffects);
|
for (auto & uniqueEffectName : categoryPair.second.uniqueEffects) {
|
||||||
|
|
||||||
for (auto const& uniqueEffectName : activePersistentUniqueEffects) {
|
|
||||||
// It is important to note here that if a unique effect exists, it *may*
|
// It is important to note here that if a unique effect exists, it *may*
|
||||||
// not come from a persistent effect, it *may* be from an ephemeral effect.
|
// not come from a persistent effect, it *may* be from an ephemeral effect.
|
||||||
// Here, when a persistent effect overrides an ephemeral effect, it is
|
// Here, when a persistent effect overrides an ephemeral effect, it is
|
||||||
// clearing the duration making it into a solely persistent effect. This
|
// clearing the duration making it into a solely persistent effect. This
|
||||||
// means that by applying a persistent effect and then clearing it, you can
|
// means that by applying a persistent effect and then clearing it, you can
|
||||||
// remove an ephemeral effect.
|
// remove an ephemeral effect.
|
||||||
if (auto existingEffect = m_uniqueEffects.ptr(uniqueEffectName))
|
if (auto existingEffect = m_uniqueEffects.ptr(uniqueEffectName)) {
|
||||||
m_uniqueEffectMetadata.getNetElement(existingEffect->metadataId)->duration.reset();
|
m_uniqueEffectMetadata.getNetElement(existingEffect->metadataId)->duration.reset();
|
||||||
else
|
activePersistentUniqueEffects.add(uniqueEffectName);
|
||||||
addUniqueEffect(uniqueEffectName, {}, {});
|
}
|
||||||
|
// we want to make sure the effect it's applying actually exists
|
||||||
|
// if not then it should be removed from the list
|
||||||
|
else if (addUniqueEffect(uniqueEffectName, {}, {}))
|
||||||
|
activePersistentUniqueEffects.add(uniqueEffectName);
|
||||||
|
else
|
||||||
|
categoryPair.second.uniqueEffects.remove(uniqueEffectName);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Again, here we are using "durationless" to mean "persistent"
|
// Again, here we are using "durationless" to mean "persistent"
|
||||||
for (auto const& key : m_uniqueEffects.keys()) {
|
for (auto const& key : m_uniqueEffects.keys()) {
|
||||||
auto metadata = m_uniqueEffectMetadata.getNetElement(m_uniqueEffects[key].metadataId);
|
auto metadata = m_uniqueEffectMetadata.getNetElement(m_uniqueEffects[key].metadataId);
|
||||||
@ -678,13 +682,13 @@ float StatusController::defaultUniqueEffectDuration(UniqueStatusEffect const& ef
|
|||||||
return Root::singleton().statusEffectDatabase()->uniqueEffectConfig(effect).defaultDuration;
|
return Root::singleton().statusEffectDatabase()->uniqueEffectConfig(effect).defaultDuration;
|
||||||
}
|
}
|
||||||
|
|
||||||
void StatusController::addUniqueEffect(
|
bool StatusController::addUniqueEffect(
|
||||||
UniqueStatusEffect const& effect, Maybe<float> duration, Maybe<EntityId> sourceEntityId) {
|
UniqueStatusEffect const& effect, Maybe<float> duration, Maybe<EntityId> sourceEntityId) {
|
||||||
auto statusEffectDatabase = Root::singleton().statusEffectDatabase();
|
auto statusEffectDatabase = Root::singleton().statusEffectDatabase();
|
||||||
if (statusEffectDatabase->isUniqueEffect(effect)) {
|
if (statusEffectDatabase->isUniqueEffect(effect)) {
|
||||||
auto effectConfig = statusEffectDatabase->uniqueEffectConfig(effect);
|
auto effectConfig = statusEffectDatabase->uniqueEffectConfig(effect);
|
||||||
if ((duration && statPositive("statusImmunity")) || (effectConfig.blockingStat && statPositive(*effectConfig.blockingStat)))
|
if ((duration && statPositive("statusImmunity")) || (effectConfig.blockingStat && statPositive(*effectConfig.blockingStat)))
|
||||||
return;
|
return false;
|
||||||
|
|
||||||
auto& uniqueEffect = m_uniqueEffects[effect];
|
auto& uniqueEffect = m_uniqueEffects[effect];
|
||||||
uniqueEffect.effectConfig = effectConfig;
|
uniqueEffect.effectConfig = effectConfig;
|
||||||
@ -701,8 +705,11 @@ void StatusController::addUniqueEffect(
|
|||||||
|
|
||||||
if (m_parentEntity)
|
if (m_parentEntity)
|
||||||
initUniqueEffectScript(uniqueEffect);
|
initUniqueEffectScript(uniqueEffect);
|
||||||
|
|
||||||
|
return true;
|
||||||
} else {
|
} else {
|
||||||
Logger::warn("Unique status effect '{}' not found in status effect database", effect);
|
Logger::warn("Unique status effect '{}' not found in status effect database", effect);
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -190,7 +190,7 @@ private:
|
|||||||
void updatePersistentUniqueEffects();
|
void updatePersistentUniqueEffects();
|
||||||
|
|
||||||
float defaultUniqueEffectDuration(UniqueStatusEffect const& name) const;
|
float defaultUniqueEffectDuration(UniqueStatusEffect const& name) const;
|
||||||
void addUniqueEffect(UniqueStatusEffect const& effect, Maybe<float> duration, Maybe<EntityId> sourceEntityId);
|
bool addUniqueEffect(UniqueStatusEffect const& effect, Maybe<float> duration, Maybe<EntityId> sourceEntityId);
|
||||||
void removeUniqueEffect(UniqueStatusEffect const& name);
|
void removeUniqueEffect(UniqueStatusEffect const& name);
|
||||||
|
|
||||||
void initPrimaryScript();
|
void initPrimaryScript();
|
||||||
|
Loading…
Reference in New Issue
Block a user