MCPcopy Create free account
hub / github.com/TurningWheel/Barony / sustainedSpellProcess

Function sustainedSpellProcess

src/entity.cpp:692–758  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

690-------------------------------------------------------------------------------*/
691
692void sustainedSpellProcess(Entity& entity, Stat& myStats, int effectID, std::map<int, spell_t*>& sustainedSpell_hijacked,
693 bool& bOutDissipated, spell_t*& outUnsustainSpell)
694{
695 if ( sustainedSpell_hijacked.find(effectID) != sustainedSpell_hijacked.end() )
696 {
697 bool sustained = false;
698 Entity* caster = uidToEntity(sustainedSpell_hijacked[effectID]->caster);
699 if ( caster == &entity )
700 {
701 //Deduct mana from caster. Cancel spell if not enough mana (simply leave sustained at false).
702 int oldMP = caster->getMP();
703 int sustainCost = getSustainCostOfSpell(sustainedSpell_hijacked[effectID], &entity);
704 if ( effectID == EFF_FLAME_CLOAK && entity.flags[BURNING] )
705 {
706 sustainCost *= 2;
707 }
708 else if ( effectID == EFF_GUARD_BODY || effectID == EFF_GUARD_SPIRIT || effectID == EFF_DIVINE_GUARD )
709 {
710 int spellID = SPELL_GUARD_BODY;
711 if ( effectID == EFF_GUARD_SPIRIT )
712 {
713 spellID = SPELL_GUARD_SPIRIT;
714 }
715 else if ( effectID == EFF_DIVINE_GUARD )
716 {
717 spellID = SPELL_DIVINE_GUARD;
718 }
719
720 int currentStrength = sustainedSpell_hijacked[effectID]->channel_effectStrength;
721 int effectStrengthMax = getSpellDamageSecondaryFromID(spellID, caster, nullptr, caster);
722 effectStrengthMax = std::min(effectStrengthMax, getSpellEffectDurationSecondaryFromID(spellID, caster, nullptr, caster));
723
724 int increment = std::max(1, getSpellDamageFromID(spellID, caster, nullptr, caster));
725
726 sustainedSpell_hijacked[effectID]->channel_effectStrength += increment;
727 sustainedSpell_hijacked[effectID]->channel_effectStrength = std::min(effectStrengthMax, sustainedSpell_hijacked[effectID]->channel_effectStrength);
728 if ( sustainedSpell_hijacked[effectID]->channel_effectStrength > currentStrength )
729 {
730 sustainCost *= sustainedSpell_hijacked[effectID]->channel_effectStrength - currentStrength;
731 }
732 }
733 bool deducted = caster->safeConsumeMP(sustainCost); //Consume X mana ever duration / mana seconds
734 if ( deducted )
735 {
736 sustained = true;
737 myStats.setEffectActive(effectID, sustainedSpell_hijacked[effectID]->channel_effectStrength);
738 myStats.EFFECTS_TIMERS[effectID] = sustainedSpell_hijacked[effectID]->channel_duration;
739
740 if ( caster->behavior == &actPlayer )
741 {
742 players[caster->skill[2]]->mechanics.sustainedSpellIncrementMP(oldMP - caster->getMP(), sustainedSpell_hijacked[effectID]->skillID);
743 }
744 }
745 else
746 {
747 messagePlayer(caster->isEntityPlayer(), MESSAGE_STATUS, Language::get(6504), sustainedSpell_hijacked[effectID]->getSpellName());
748 //outUnsustainSpell = sustainedSpell_hijacked[effectID];
749 list_RemoveNode(sustainedSpell_hijacked[effectID]->magic_effects_node); //Remove it from the entity's magic effects. This has the side effect of removing it from the sustained spells list too.

Callers 1

effectTimesMethod · 0.85

Calls 14

getSustainCostOfSpellFunction · 0.85
getSpellDamageFromIDFunction · 0.85
list_RemoveNodeFunction · 0.85
getMPMethod · 0.80
safeConsumeMPMethod · 0.80
setEffectActiveMethod · 0.80
isEntityPlayerMethod · 0.80
getSpellNameMethod · 0.80
uidToEntityFunction · 0.70

Tested by

no test coverage detected