예제 #1
0
 internal bool CastSpell(Player caster, Spell spell, Point target)
 {
     if (caster.CouldCastSpell(spell))
     {
         string effectString = string.Format("{0} casts {1}.", caster.Name, spell.Name);
         if (DoEffect(caster, spell, spell, caster.SpellStrength(spell.School), true, target, effectString))
         {
             caster.SpendMP(spell.Cost);
             return true;
         }
     }
     return false;
 }
예제 #2
0
 private static int CalculateDamgeFromSpell(Spell spell, int strength)
 {
     int damage = spell.BaseDamage.Roll();
     for (int i = 1; i < strength; ++i)
         damage += spell.DamagePerLevel.Roll();
     return damage;
 }
예제 #3
0
 internal bool CastSpell(Player caster, Spell spell, Point target)
 {
     bool didAnything = m_magicEffects.CastSpell(caster, spell, target);
     if (didAnything)
         m_timingEngine.ActorDidAction(caster);
     return didAnything;
 }
예제 #4
0
        private bool DoEffect(Character invoker, object invokingMethod, Spell spell, int strength, bool couldBeLongTerm, Point target, string printOnEffect)
        {
            switch (spell.EffectType)
            {                
                case "HealCaster":
                {
                    CoreGameEngine.Instance.SendTextOutput(printOnEffect);
                    int amountToHeal = (new DiceRoll(20, 3, 0)).Roll();
                    for (int i = 1 ; i < strength ; ++i)
                        amountToHeal += (new DiceRoll(6, 3, 0)).Roll();
                    int healAmount = invoker.Heal(amountToHeal, true);
                    CoreGameEngine.Instance.SendTextOutput(string.Format("{0} was healed for {1} health.", invoker.Name, healAmount));
                    return true;
                }
                case "HealMPCaster":
                {
                    CoreGameEngine.Instance.SendTextOutput(printOnEffect);
                    Player player = invoker as Player;
                    if (player != null)
                    {
                        player.GainMP((new DiceRoll(strength, 3, 4)).Roll());
                    }
                    return true;
                }
                case "RangedSingleTarget":
                {
                    // This will call ShowRangedAttack inside.
                    CoreGameEngine.Instance.SendTextOutput(printOnEffect);
                    return m_combatEngine.RangedBoltToLocation(invoker, target, CalculateDamgeFromSpell(spell, strength), invokingMethod, DamageDoneDelegate);
                }
                case "Stream":
                {
                    CoreGameEngine.Instance.SendTextOutput(printOnEffect);
                    List<Point> pathOfBlast = m_physicsEngine.GenerateBlastListOfPoints(CoreGameEngine.Instance.Map, invoker.Position, target, false);
                    TrimPath(5, pathOfBlast);

                    List<Point> blastToShow = new List<Point>(pathOfBlast);
                    m_physicsEngine.FilterNotTargetablePointsFromList(blastToShow, invoker.Position, CoreGameEngine.Instance.Player.Vision, true);

                    bool targetAtLastPoint = m_combatEngine.FindTargetAtPosition(pathOfBlast.Last()) != null;
                    CoreGameEngine.Instance.ShowRangedAttack(invokingMethod, ShowRangedAttackType.Stream, blastToShow, targetAtLastPoint);
                    foreach (Point p in pathOfBlast)
                    {
                        Character hitCharacter = m_combatEngine.FindTargetAtPosition(p);
                        if (hitCharacter != null)
                            m_combatEngine.DamageTarget(invoker, CalculateDamgeFromSpell(spell, strength), hitCharacter, DamageDoneDelegate);
                    }
                    return true;
                }
                case "RangedBlast":
                {
                    CoreGameEngine.Instance.SendTextOutput(printOnEffect);
                    List<Point> pathOfBlast = m_physicsEngine.GenerateBlastListOfPoints(CoreGameEngine.Instance.Map, invoker.Position, target, true);
                    TrimPathDueToSpellLength(strength, pathOfBlast);

                    List<Point> blastToShow = new List<Point>(pathOfBlast);
                    m_physicsEngine.FilterNotTargetablePointsFromList(blastToShow, invoker.Position, CoreGameEngine.Instance.Player.Vision, true);

                    CoreGameEngine.Instance.ShowRangedAttack(invokingMethod, ShowRangedAttackType.RangedBlast, blastToShow, false);
                    foreach (Point p in pathOfBlast)
                    {
                        Character hitCharacter = m_combatEngine.FindTargetAtPosition(p);
                        if (hitCharacter != null)
                            m_combatEngine.DamageTarget(invoker, CalculateDamgeFromSpell(spell, strength), hitCharacter, DamageDoneDelegate);
                    }
                    return true;
                }
                case "ConeAttack":
                {
                    CoreGameEngine.Instance.SendTextOutput(printOnEffect);

                    Direction direction = PointDirectionUtils.ConvertTwoPointsToDirection(invoker.Position, target);
                    List<Point> pointsInConeAttack = PointListUtils.PointListFromCone(invoker.Position, direction, 3);
                    CoreGameEngine.Instance.FilterNotVisibleBothWaysFromList(target, pointsInConeAttack);

                    if (pointsInConeAttack == null || pointsInConeAttack.Count == 0)
                        throw new InvalidOperationException("Cone magical attack with nothing to roast?");

                    ShowConeAttack(invoker, invokingMethod, pointsInConeAttack);

                    foreach (Point p in pointsInConeAttack)
                    {
                        Character hitCharacter = m_combatEngine.FindTargetAtPosition(p);
                        if (hitCharacter != null)
                            m_combatEngine.DamageTarget(invoker, CalculateDamgeFromSpell(spell, strength), hitCharacter, DamageDoneDelegate);
                    }
                    return true;
                }
                case "ExplodingRangedPoint":
                {
                    CoreGameEngine.Instance.SendTextOutput(printOnEffect);

                    const int BurstWidth = 2;
                    
                    ShowExplodingRangedPointAttack(invoker, invokingMethod, target, BurstWidth);

                    List<Point> pointsToEffect = PointListUtils.PointListFromBurstPosition(target, BurstWidth);
                    CoreGameEngine.Instance.FilterNotVisibleBothWaysFromList(target, pointsToEffect);
                    foreach (Point p in pointsToEffect)
                    {
                        Character hitCharacter = m_combatEngine.FindTargetAtPosition(p);
                        if (hitCharacter != null)
                            m_combatEngine.DamageTarget(invoker, CalculateDamgeFromSpell(spell, strength), hitCharacter, DamageDoneDelegate);
                    }

                    return true;
                }
                case "Haste":   // Should also be added to GetLongTermEffectSpellWouldProduce()
                case "Light":
                case "ArmorOfLight":
                {
                    // These spells can be long term
                    return m_effectEngine.AddEffectToTarget(spell.EffectType, invoker, strength, couldBeLongTerm, target, printOnEffect);                    
                }
                case "Regeneration":
                case "WordOfHope":
                {
                    // These spells can't be long term
                    return m_effectEngine.AddEffectToTarget(spell.EffectType, invoker, strength, false, target, printOnEffect);
                }
                case "Poison Bolt":
                {
                    CoreGameEngine.Instance.SendTextOutput(printOnEffect);
                    bool successInRangedBolt = m_combatEngine.RangedBoltToLocation(invoker, target, 1, invokingMethod, DamageDoneDelegate);
                    if (successInRangedBolt)
                        m_effectEngine.AddEffectToTarget("Poison", invoker, strength, false, target);
                    return successInRangedBolt;
                }
                case "Slow":
                {
                    return m_effectEngine.AddEffectToTarget("Slow", invoker, strength, false, target, printOnEffect);
                }
                case "Blink":
                {
                    CoreGameEngine.Instance.SendTextOutput(printOnEffect);
                    HandleRandomTeleport(invoker, 5);
                    return true;
                }
                case "Teleport":
                {
                    CoreGameEngine.Instance.SendTextOutput(printOnEffect);
                    HandleRandomTeleport(invoker, 25);
                    return true;
                }
                default:
                    throw new InvalidOperationException("MagicEffectsEngine::DoEffect - don't know how to do: " + spell.EffectType);
            }
        }
예제 #5
0
 internal bool CastSpell(Player caster, Spell spell, Point target)
 {
     return m_physicsEngine.CastSpell(caster, spell, target);
 }