From 08780dad536eb5d0544eb2ea70e5443dc237976f Mon Sep 17 00:00:00 2001 From: fusion32 Date: Fri, 30 May 2025 20:12:36 -0300 Subject: more work on `crcombat.cc` --- src/magic.cc | 74 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 74 insertions(+) create mode 100644 src/magic.cc (limited to 'src/magic.cc') diff --git a/src/magic.cc b/src/magic.cc new file mode 100644 index 0000000..f8f0505 --- /dev/null +++ b/src/magic.cc @@ -0,0 +1,74 @@ +#include "magic.hh" +#include "creature.hh" + +// TImpact +// ============================================================================= +void TImpact::handleField(int a, int b, int c){ + // no-op +} + +void TImpact::handleCreature(TCreature *Victim){ + // no-op +} + +bool TImpact::isAggressive(void){ + return true; +} + +// TDamageImpact +// ============================================================================= +void TDamageImpact::TDamageImpact(TCreature *Actor, int DamageType, int Power, bool AllowDefense){ + if(Actor == NULL){ + error("TDamageImpact::TDamageImpact: Actor ist NULL.\n"); + } + + this->Actor = Actor; + this->DamageType = DamageType; + this->Power = Power; + this->AllowDefense = AllowDefense; +} + +// Magic Related Functions +// ============================================================================= +void CheckMana(TCreature *Creature, int ManaPoints, int SoulPoints, int Delay){ + if(Creature == NULL){ + error("CheckMana: Übergebene Kreatur existiert nicht.\n"); + throw ERROR; + } + + if(Creature->Type != PLAYER || ManaPoints < 0) + return; + + TSkill *Mana = Creature->Skills[SKILL_MANA]; + if(Mana == NULL){ + error("CheckMana: Kein Skill MANA!\n"); + throw ERROR; + } + + TSkill *Soul = Creature->Skills[SKILL_SOUL]; + if(Soul == NULL){ + error("CheckMana: Kein Skill SOULPOINTS!\n"); + throw ERROR; + } + + if(!CheckRight(Creature->ID, UNLIMITED_MANA)){ + if(Mana->Get() < ManaPoints) + throw NOTENOUGHMANA; + + if(Soul->Get() < SoulPoints) + throw NOTENOUGHSOULPOINTS; + + Mana->Change(-ManaPoints); + Soul->Change(-SoulPoints); + } + + if(ManaPoints > 0){ + Creature->Skills[SKILL_MAGIC_LEVEL]->Increase(ManaPoints); + } + + // NOTE(fusion): Maintain largest exhaust? + uint32 EarliestSpellTime = ServerMilliseconds + Delay; + if(Creature->EarliestSpellTime < EarliestSpellTime){ + Creature->EarliestSpellTime = EarliestSpellTime; + } +} -- cgit v1.2.3