public PassiveSpell ApplyPassiveSpell(LivingEntity caster, SpellSource spellSource, Point?destPoint = null) { var spell = spellSource.CreateSpell(caster); string preventReason = ""; if (!gm.Context.CanUseScroll(caster, spellSource, spell, ref preventReason)) { gm.ReportFailure(preventReason); return(null); } if (spell is PassiveSpell ps) { if (ps.Kind == SpellKind.Teleport) { if (destPoint != null) { var currentTile = gm.CurrentNode.GetTile(destPoint.Value); var teleportSpell = ps as TeleportSpell; if (teleportSpell.Range < gm.Hero.DistanceFrom(currentTile)) { gm.ReportFailure("Range of spell is too small (max:" + teleportSpell.Range + ")"); return(null); } if (currentTile.IsEmpty || currentTile is Loot) { gm.CurrentNode.SetTile(gm.Hero, destPoint.Value); } else { gm.ReportFailure("Can not cast on the pointed tile"); return(null); } } } else { caster.ApplyPassiveSpell(ps); } gm.UtylizeSpellSource(caster, spellSource, spell); gm.AppendAction <LivingEntityAction>((LivingEntityAction ac) => { ac.Kind = LivingEntityActionKind.Teleported; ac.Info = gm.Hero.Name + " used " + spellSource.Kind.ToDescription() + " scroll"; ac.InvolvedEntity = caster; }); if (caster is Hero) { HandleHeroActionDone(); } return(ps); } else { gm.Logger.LogError("!PassiveSpell " + spellSource); gm.ReportFailure(""); } return(null); }
public PassiveSpell ApplyPassiveSpell(LivingEntity caster, SpellSource spellSource, Point?destPoint = null) { var spell = spellSource.CreateSpell(caster); string preventReason = ""; if (!gm.Context.CanUseScroll(caster, spellSource, spell, ref preventReason)) { gm.ReportFailure(preventReason); return(null); } if (spell is PassiveSpell ps) { if (ps.Kind == SpellKind.Teleport) { if (destPoint != null) { var currentTile = gm.CurrentNode.GetTile(destPoint.Value); var teleportSpell = ps as TeleportSpell; if (teleportSpell.Range < gm.Hero.DistanceFrom(currentTile)) { gm.ReportFailure("Range of spell is too small (max:" + teleportSpell.Range + ")"); return(null); } if (currentTile.IsEmpty || currentTile is Loot) { gm.CurrentNode.SetTile(gm.Hero, destPoint.Value); } else { gm.ReportFailure("Can not cast on the pointed tile"); return(null); } } } else if (ps.Kind == SpellKind.Dziewanna) { int maxApples = 1; if (RandHelper.GetRandomDouble() > 0.5) { maxApples += 1; } for (int appleIndex = 0; appleIndex < maxApples; appleIndex++) { var enemies = gm.CurrentNode.GetNeighborTiles <Enemy>(gm.Hero); bool added = false; foreach (var en in enemies) { var emptyOnes = gm.CurrentNode.GetEmptyNeighborhoodTiles(en, false); if (emptyOnes.Any()) { AddApple(emptyOnes.First()); added = true; break; } } if (!added) { var emp = gm.CurrentNode.GetClosestEmpty(gm.Hero); AddApple(emp); } } } else { caster.ApplyPassiveSpell(ps); } gm.UtylizeSpellSource(caster, spellSource, spell); gm.AppendAction <LivingEntityAction>((LivingEntityAction ac) => { ac.Kind = LivingEntityActionKind.Teleported; ac.Info = gm.Hero.Name + " used " + spellSource.Kind.ToDescription() + " scroll"; ac.InvolvedEntity = caster; }); if (caster is Hero) { HandleHeroActionDone(); } return(ps); } else { gm.Logger.LogError("!PassiveSpell " + spellSource); gm.ReportFailure(""); } return(null); }