示例#1
0
        public OffensiveSpell ApplySpell(LivingEntity caster, SpellSource spellSource)
        {
            var spell = spellSource.CreateSpell(caster);

            if (!gm.UtylizeSpellSource(caster, spellSource, spell))
            {
                return(null);
            }

            if (spell is OffensiveSpell ps)
            {
                if (ps is SkeletonSpell skeletonSpell)
                {
                    gm.AddAlly(skeletonSpell.Ally);
                }
                if (caster is Hero)
                {
                    HandleHeroActionDone();
                }

                return(ps);
            }
            else
            {
                gm.Logger.LogError("!OffensiveSpell " + spellSource);
                gm.ReportFailure("");
            }

            return(null);
        }
示例#2
0
        private void SetResistanceFromScroll(SpellSource activeScroll)
        {
            if (activeScroll == null)
            {
                return;
            }
            var esk = EntityStatKind.Unset;

            if (activeScroll.Kind == SpellKind.FireBall)
            {
                esk = EntityStatKind.ResistFire;
            }
            else if (activeScroll.Kind == SpellKind.PoisonBall)
            {
                esk = EntityStatKind.ResistPoison;
            }
            else if (activeScroll.Kind == SpellKind.IceBall)
            {
                esk = EntityStatKind.ResistCold;
            }

            if (esk != EntityStatKind.Unset)
            {
                SetResist(esk);
            }
        }
示例#3
0
        public void SpellSourcePropertiesTest(bool scroll)
        {
            var         game        = CreateGame();
            var         hero        = game.Hero;
            SpellSource spellSource = null;

            if (scroll)
            {
                spellSource = new Scroll(Roguelike.Spells.SpellKind.FireBall);
            }
            else
            {
                spellSource = new Book(Roguelike.Spells.SpellKind.FireBall);
            }

            {
                var desc      = spellSource.GetDescription();
                var extraDesc = spellSource.GetExtraStatDescription(hero, true);
                Assert.NotNull(extraDesc);
                Assert.Greater(extraDesc.GetDescription().Count(), 0);

                Assert.Greater(extraDesc.Level, 0);
                Assert.Greater(extraDesc.ManaCost, 0);
                Assert.Greater(extraDesc.Damage, 0);
            }
        }
示例#4
0
        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);
        }
示例#5
0
    void PlaceSpellSource()
    {
        spellSource                    = GameUnit.Instantiate <SpellSource>();
        spellSource.name               = "SpellSource Player" + player.playerNumber;
        spellSource.player             = player;
        spellSource.transform.position = transform.position;
        spellSource.transform.rotation = transform.rotation;

        spellSource.transform.Translate(new Vector3(0, 0, -powerSource.bounds.z));
    }
示例#6
0
        static bool Prefix(AbilityData __instance, ref SpellSource __result)
        {
            SpellTypeOverride component = __instance.Blueprint.GetComponent <SpellTypeOverride>();

            if ((bool)((UnityEngine.Object)component))
            {
                __result = component.Type;
                return(false);
            }
            if ((UnityEngine.Object)__instance.SourceItemUsableBlueprint != (UnityEngine.Object)null && __instance.SourceItemUsableBlueprint.Type != UsableItemType.Scroll || __instance.Blueprint.Type != AbilityType.Spell && __instance.Blueprint.Type != AbilityType.SpellLike)
            {
                __result = SpellSource.None;
                return(false);
            }
            if (__instance.Spellbook != null)
            {
                __result = __instance.Spellbook.Blueprint.IsArcane ? SpellSource.Arcane : SpellSource.Divine;
                return(false);
            }

            Kingmaker.UnitLogic.Feature feature = __instance.Caster.Progression.Features.Enumerable.FirstOrDefault <Kingmaker.UnitLogic.Feature>((Func <Kingmaker.UnitLogic.Feature, bool>)(f => f.Blueprint.GetComponents <AddFacts>().Any <AddFacts>((Func <AddFacts, bool>)(af => ((IEnumerable <BlueprintUnitFact>)af.Facts).Contains <BlueprintUnitFact>((BlueprintUnitFact)__instance.Blueprint)))));
            BlueprintCharacterClass     blueprintCharacterClass1;

            if (feature == null)
            {
                blueprintCharacterClass1 = (BlueprintCharacterClass)null;
            }
            else
            {
                BlueprintProgression sourceProgression = feature.SourceProgression;
                blueprintCharacterClass1 = sourceProgression != null ? ((IList <BlueprintCharacterClass>)sourceProgression.Classes).FirstOrDefault <BlueprintCharacterClass>() : (BlueprintCharacterClass)null;
            }
            BlueprintCharacterClass blueprintCharacterClass2 = blueprintCharacterClass1;

            if (!(bool)((UnityEngine.Object)blueprintCharacterClass2))
            {
                __result = SpellSource.Unknown;
                return(false);
            }
            var base_spellbook = __instance.Caster?.GetSpellbook(blueprintCharacterClass2);

            if (base_spellbook == null)
            {
                __result = blueprintCharacterClass2.IsDivineCaster ? SpellSource.Divine : (blueprintCharacterClass2.IsArcaneCaster ? SpellSource.Arcane : SpellSource.None);
                return(false);
            }
            __result = base_spellbook.Blueprint.IsArcane ? SpellSource.Arcane : (base_spellbook.Blueprint.IsAlchemist ? SpellSource.None : SpellSource.Divine);
            return(false);
        }
示例#7
0
        public void SpellSourceEntityStatKindPropertiesTest(bool scroll)
        {
            var         game        = CreateGame();
            var         hero        = game.Hero;
            SpellSource spellSource = null;

            if (scroll)
            {
                spellSource = new Scroll(SpellKind.FireBall);
            }
            else
            {
                spellSource = new Book(Roguelike.Spells.SpellKind.FireBall);
            }

            Assert.True(new Scroll(SpellKind.FireBall).IsOffensive);

            var spell  = spellSource.CreateSpell(hero);
            var stats1 = spell.CreateSpellStatsDescription(true).GetEntityStats();

            Assert.AreEqual(stats1.Count(), 3);
            var mana1 = stats1.SingleOrDefault(i => i.Kind == EntityStatKind.Mana);

            Assert.NotNull(mana1);
            var attack1 = stats1.SingleOrDefault(i => i.Kind == EntityStatKind.ElementalSpellProjectilesAttack);

            Assert.NotNull(attack1);
            var range1 = stats1.SingleOrDefault(i => i.Kind == EntityStatKind.ElementalProjectilesRange);

            Assert.NotNull(range1);

            var stats2 = spell.CreateSpellStatsDescription(false).GetEntityStats();

            Assert.AreEqual(stats2.Count(), 3);
            var mana2 = stats2.SingleOrDefault(i => i.Kind == EntityStatKind.Mana);

            Assert.NotNull(mana2);
            Assert.Greater(mana2.Value.TotalValue, mana1.Value.TotalValue);

            var attack2 = stats2.SingleOrDefault(i => i.Kind == EntityStatKind.ElementalSpellProjectilesAttack);

            Assert.NotNull(attack2);
            Assert.Greater(attack2.Value.TotalValue, attack1.Value.TotalValue);

            var range2 = stats2.SingleOrDefault(i => i.Kind == EntityStatKind.ElementalProjectilesRange);

            Assert.NotNull(range2);
            Assert.GreaterOrEqual(range2.Value.TotalValue, range1.Value.TotalValue);
        }
示例#8
0
    void Start()
    {
        staticFront          = front;
        staticFireProjectile = fireProjectile;
        staticIceProjectile  = iceProjectile;
        staticSpellSource    = spellSource;

        player       = GameManager.Instance.Player.GetComponent <Player>();
        staticPlayer = player;

        bool[] unlockBooleans = GameManager.Instance.spells.GetAll();

        for (int i = 0; i < spells.Length; i++)
        {
            spells[i].unlocked = unlockBooleans[i];
        }

        UIManager.Instance.ToggleSpellCharges(charges);
    }
示例#9
0
文件: ovr023.cs 项目: gowantervo/coab
        internal static byte spell_menu(ref int index, SpellSource spellSource)
        {
            string text;

            switch (spellSource)
            {
                case SpellSource.Cast:
                    text = "Cast";
                    break;

                case SpellSource.Memorize:
                    text = "Memorize";
                    break;

                case SpellSource.Scribe:
                    text = "Scribe";
                    break;

                case SpellSource.Learn:
                    text = "Learn";
                    break;

                default:
                    text = string.Empty;
                    break;
            }

            string prompt_text = text.Length > 0 ? "Choose Spell: " : "";

            int end_y = (spellSource == SpellSource.Memorize) ? 0x0F : 0x16;

            bool show_exit = spellSource != SpellSource.Learn;
            bool var_61 = false;

            if (index < 0)
            {
                var_61 = true;
                index = 0;
            }

            if (spellSource == SpellSource.Learn || spellSource == SpellSource.Cast)
            {
                var_61 = true;
            }

            MenuItem selected;
            char input_key;

            do
            {
                input_key = ovr027.sl_select_item(out selected, ref index, ref var_61, show_exit, gbl.spell_string_list,
                    end_y, 0x26, 5, 1, gbl.defaultMenuColors, text, prompt_text);

            } while (asc_5C1D1.MemberOf(input_key) == false);

            byte spell_id;
            if (unk_5C1F1.MemberOf(input_key) == true)
            {
                spell_id = 0;
            }
            else
            {
                int selected_index = gbl.spell_string_list.GetRange(0, gbl.spell_string_list.IndexOf(selected)).FindAll(mi => mi.Heading == false).Count;
                spell_id = gbl.memorize_spell_id[selected_index];

                if (spellSource == SpellSource.Scribe)
                {
                    gbl.currentScroll = gbl.scribeScrolls[selected_index];
                }
            }
            gbl.spell_string_list.Clear();

            return spell_id;
        }
示例#10
0
        public bool ApplyAttackPolicy
        (
            LivingEntity caster,//hero, enemy, ally
            Tiles.Abstract.IObstacle target,
            SpellSource spellSource,
            Action <Policy> BeforeApply = null,
            Action <Policy> AfterApply  = null,
            bool looped = false
        )
        {
            if (!looped)
            {
                applyingBulk = false;
            }
            var spell = spellSource.CreateSpell(caster) as IProjectileSpell;

            if (spell != null)
            {
                if (!caster.IsInProjectileReach(spell, target.Position))
                {
                    this.gm.SoundManager.PlayBeepSound();
                    this.gm.AppendAction(new GameEvent()
                    {
                        Info = "Target out of range"
                    });
                    return(false);
                }
            }

            if (!looped && !gm.UtylizeSpellSource(caster, spellSource, spell))
            {
                return(false);
            }

            var policy = Container.GetInstance <ProjectileCastPolicy>();

            policy.Target             = target as Dungeons.Tiles.Tile;
            policy.ProjectilesFactory = Container.GetInstance <IProjectilesFactory>();
            policy.Projectile         = spellSource.CreateSpell(caster) as IProjectileSpell;
            if (BeforeApply != null)
            {
                BeforeApply(policy);
            }

            policy.OnApplied += (s, e) =>
            {
                var le = policy.TargetDestroyable is LivingEntity;
                if (!le)//le is handled specially
                {
                    this.gm.LootManager.TryAddForLootSource(policy.Target as ILootSource);
                    //dest.Destroyed = true;
                }


                if (looped)
                {
                    return;
                }
                if (!applyingBulk)
                {
                    var repeatOK = caster.IsStatRandomlyTrue(EntityStatKind.ChanceToRepeatElementalProjectileAttack);
                    if (repeatOK)
                    {
                        ApplyAttackPolicy(caster, target, spellSource, BeforeApply, AfterApply, true);
                    }
                }

                if (caster is Hero)
                {
                    OnHeroPolicyApplied(policy);
                }

                if (AfterApply != null)
                {
                    AfterApply(policy);
                }
            };

            policy.Apply(caster);

            var bulkOK = false;

            if (target is Enemy en && spellSource is WeaponSpellSource)
            {
                bulkOK = HandleBulk(en, EntityStatKind.ChanceToElementalProjectileBulkAttack, (Enemy en1) => {
                    applyingBulk = true;
                    ApplyAttackPolicy(caster, en1, spellSource, BeforeApply, AfterApply, true);
                });
            }

            return(true);
        }
示例#11
0
文件: ovr020.cs 项目: gowantervo/coab
        internal static byte spell_menu2(out bool arg_0, ref int index, SpellSource arg_8, SpellLoc spl_location)
        {
            string text;
            byte result;

            switch (spl_location)
            {
                case SpellLoc.memory:

                    text = "in Memory";
                    break;

                case SpellLoc.grimoire:

                    text = "in Grimoire";
                    break;

                case SpellLoc.scroll:
                    text = "on Scroll";
                    break;

                case SpellLoc.scrolls:
                    text = "on Scrolls";
                    break;

                case SpellLoc.choose:
                    text = "to Choose";
                    break;

                case SpellLoc.memorize:
                    text = "to Memorize";
                    break;

                case SpellLoc.scribe:
                    text = "to Scribe";
                    break;

                default:
                    text = string.Empty;
                    break;
            }

            arg_0 = ovr023.BuildSpellList(spl_location);

            if (arg_0 == true)
            {
                if (index < 0 ||
                    arg_8 == SpellSource.Cast)
                {
                    if (gbl.game_state != GameState.Combat)
                    {
                        if (arg_8 == SpellSource.Memorize)
                        {
                            seg037.draw8x8_05();
                        }
                        else
                        {
                            seg037.draw8x8_07();
                        }
                    }
                    else
                    {
                        seg037.DrawFrame_Outer();
                    }
                }

                ovr025.displayPlayerName(true, 1, 1, gbl.SelectedPlayer);

                seg041.displayString("Spells " + text, 0, 10, 1, gbl.SelectedPlayer.name.Length + 4);

                result = ovr023.spell_menu(ref index, arg_8);
            }
            else
            {
                result = 0;
            }

            return result;
        }
示例#12
0
        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);
        }
示例#13
0
        public ApplyAttackPolicyResult ApplyAttackPolicy
        (
            LivingEntity caster,//hero, enemy, ally
            Tiles.Abstract.IObstacle target,
            SpellSource spellSource,
            Action <Policy> BeforeApply = null,
            Action <Policy> AfterApply  = null,
            bool looped = false
        )
        {
            if (!looped)
            {
                applyingBulk = false;
            }
            var spell = spellSource.CreateSpell(caster) as IProjectileSpell;

            if (spell != null)
            {
                if (!caster.IsInProjectileReach(spell, target.Position))
                {
                    this.gm.SoundManager.PlayBeepSound();
                    this.gm.AppendAction(new GameEvent()
                    {
                        Info = "Target out of range"
                    });
                    return(ApplyAttackPolicyResult.OutOfRange);
                }
            }

            if (!looped && !gm.UtylizeSpellSource(caster, spellSource, spell))
            {
                return(ApplyAttackPolicyResult.NotEnoughResources);
            }

            var policy = Container.GetInstance <ProjectileCastPolicy>();

            policy.AddTarget(target);
            policy.ProjectilesFactory = Container.GetInstance <IProjectilesFactory>();
            policy.Projectile         = spellSource.CreateSpell(caster) as IProjectileSpell;
            if (BeforeApply != null)
            {
                BeforeApply(policy);
            }

            policy.OnApplied += (s, e) =>
            {
                gm.CallTryAddForLootSource(policy.Targets.First());

                if (looped)
                {
                    return;
                }
                if (!applyingBulk)
                {
                    var repeatOK = caster.IsStatRandomlyTrue(EntityStatKind.ChanceToRepeatElementalProjectileAttack);
                    if (repeatOK)
                    {
                        ApplyAttackPolicy(caster, target, spellSource, BeforeApply, AfterApply, true);
                    }
                }

                gm.FinishPolicyApplied(caster, AfterApply, policy);
            };

            policy.Apply(caster);

            var bulkOK = false;

            if (target is Enemy en && spellSource is WeaponSpellSource)
            {
                bulkOK = HandleBulk(en, EntityStatKind.ChanceToElementalProjectileBulkAttack, (Enemy en1) => {
                    applyingBulk = true;
                    ApplyAttackPolicy(caster, en1, spellSource, BeforeApply, AfterApply, true);
                    gm.AppendAction(caster.Name + " used Projectile Bulk Attack", ActionLevel.Important);
                });
            }

            return(ApplyAttackPolicyResult.OK);
        }