Exemplo n.º 1
0
        public override void Apply(AbilityExecutionContext context, TargetWrapper target)
        {
            UnitDescriptor unit       = context.MaybeOwner.Descriptor;
            AbilityData    spell      = context.Ability.ParamSpellSlot.Spell;
            Spellbook      spellbook  = context.Ability.ParamSpellbook;
            int            spellLevel = context.Ability.ParamSpellLevel.Value;

            if (spellLevel < 1 || spellLevel > spellbook.MaxSpellLevel)
            {
                return;
            }
            foreach (var slot in spellbook.GetMemorizedSpells(spellLevel))
            {
                if (slot.Spell == spell)
                {
                    spellbook.ForgetMemorized(slot);
                }
            }
            unit.AddBuff(flagBuff, unit.Unit);
            UnityModManager.Logger.Log("Rua1?");
            FastStudy.RefreshSubAbls(spellbook, spellLevel);
            UnityModManager.Logger.Log("Rua1?>");
            FastStudy.AddMasterAbls(unit);
        }
Exemplo n.º 2
0
        static public bool Prefix(UnitUseAbility __instance, UnitCommand.CommandType commandType, ref AbilityData spell, TargetWrapper target)
        {
            //base ctor

            /*this.Type = commandType;
             * this.Target = target;
             * this.Cutscene = (ElementsContext.GetData<CutsceneParametersContext.ContextData>() != null);*/

            //modify spell
            if (spell == null)
            {
                return(true);
            }
            if (spell.Spellbook == null)
            {
                return(true);
            }
            if (spell.Spellbook.Blueprint.CharacterClass != ArcanistClass.arcanist)
            {
                return(true);
            }
            UnitDescriptor unit          = spell.Caster;
            bool           hadMetamagic  = spell.MetamagicData != null;
            bool           hadMetamixing = unit.Buffs.HasFact(Metamixing.buff);

            //An arcanist can't combine prepared metamagic and spontaneous metamagic, if she doesn't have
            //the Metamixing exploit.
            if (hadMetamagic && !hadMetamixing)
            {
                return(true);
            }
            //UnityModManager.Logger.Log($"spell {spell.Name} has metamagic {(spell.MetamagicData!=null?spell.MetamagicData.MetamagicMask:0)}");
            MetamagicBuilder builder = new MetamagicBuilder(spell.Spellbook, spell);
            Dictionary <Metamagic, Feature> meta_feat = new Dictionary <Metamagic, Feature>();

            foreach (var ft in builder.SpellMetamagicFeatures)
            {
                AddMetamagicFeat comp = ft.Get <AddMetamagicFeat>();
                if (comp == null)
                {
                    continue;
                }
                Metamagic metaId = comp.Metamagic;
                meta_feat[metaId] = ft;
            }
            bool flag = false;

            foreach (var kv in SponMetamagic.buffDict)
            {
                Metamagic metaId        = (Metamagic)(kv.Key.first);
                int       HeightenLevel = kv.Key.second;
                if (!meta_feat.ContainsKey(metaId))
                {
                    continue;
                }
                BlueprintBuff buff = kv.Value;
                if (!unit.HasFact(buff))
                {
                    continue;
                }

                //If the arcanist has the Metamixing exploit, she can add ONE
                //metamagic feat to a prepared spell, without using extra time to cast.
                //(regardless if the spell had metamagic feats when prepared)
                if (metaId == Metamagic.Heighten)
                {
                    int originalLevel = spell.Spellbook.GetSpellLevel(spell.Blueprint);
                    if (HeightenLevel <= originalLevel)
                    {
                        continue;
                    }
                    builder.AddHeightenMetamagic(meta_feat[metaId], HeightenLevel - originalLevel);
                    unit.RemoveFact(buff);
                    flag = true;
                    if (hadMetamixing)
                    {
                        unit.Resources.Spend(ArcaneReservoir.resource, 1);
                        break;
                    }
                }
                else
                {
                    builder.AddMetamagic(meta_feat[metaId]);
                    unit.RemoveFact(buff);
                    flag = true;
                    if (hadMetamixing)
                    {
                        unit.Resources.Spend(ArcaneReservoir.resource, 1);
                        break;
                    }
                }
            }
            if (flag && !hadMetamixing)
            {
                unit.AddBuff(SponMetamagic.flagBuff, unit.Unit);
            }
            //fix ConvertedFrom. this is used in checking if a subspell is existed in memorized spells.
            //if spell is a subspell, spell.IsAvailableInSpellbook will use its m_ConvertedFrom(which is its master spell)
            //to get the return value.
            var newSpell = builder.ResultAbilityData;

            newSpell.ConvertedFrom = spell.ConvertedFrom;
            spell = newSpell;
            //UnityModManager.Logger.Log($"new spell {spell.Name} has metamagic {(spell.MetamagicData != null ? spell.MetamagicData.MetamagicMask : 0)}");
            return(true);
        }