static public void Postfix(Spellbook __instance)
 {
     if (__instance.Blueprint.CharacterClass == Main.arcanist)
     {
         for (int i = 1; i <= __instance.MaxSpellLevel; i++)
         {
             var memorizedSlots = __instance.GetMemorizedSpellSlots(i);
             int j = 0;
             foreach (SpellSlot slot in memorizedSlots)
             {
                 int ind = slot.Index;
                 if (slot.Type == SpellSlotType.Common && ind >= ArcanistPatch_Helpers.getArcanistMemorizeSlotCnt(i, __instance))
                 {
                     slot.Available    = false;
                     slot.Spell        = null;
                     slot.LinkedSlots  = null;
                     slot.IsOpposition = false;
                 }
                 j++;
             }
         }
         __instance.Blueprint.Spontaneous = true;
     }
 }
Ejemplo n.º 2
0
        static public bool Prefix(SpellBookMemorizingPanel __instance, ref bool ___m_IsInit, ref List <SpellSlotItem> ___m_CommonSpellSlots, ref SpellSlotItem[] ___m_SpecialSpellSlots, ref Transform ___m_SpecialSlotsContainer, ref TextMeshProUGUI ___m_LabelSpecialSlots, ref Image ___m_SpecialSlotsBackground)
        {
            // *******************
            // This check: check if this spellbook belongs to arcanist.
            // *******************
            if (Game.Instance.UI.SpellBookController.CurrentSpellbook.Blueprint.CharacterClass != Main.arcanist)
            {
                return(true);
            }

            var        spellBookController = Game.Instance.UI.SpellBookController;
            var        spellBook           = spellBookController.CurrentSpellbook;
            var        currentLevel        = spellBookController.CurrentBookLevel;
            var        t = Game.Instance.BlueprintRoot.LocalizedTexts.UserInterfacesText.SpellBookTexts;
            FastInvoke SubstituteText_Invoker = Helpers.CreateInvoker <SpellBookMemorizingPanel>("SubstituteText");

            spellBook.Blueprint.Spontaneous = false;

            if (!___m_IsInit)
            {
                return(false);
            }
            bool returnValue = (bool)SubstituteText_Invoker(__instance);

            UnityModManager.Logger.Log($"SubstituteText invoker returns {returnValue}");
            if (returnValue)
            {
                return(false);
            }
            if (currentLevel < 0 || currentLevel > spellBookController.MaxCasterLevel)
            {
                return(false);
            }
            if (spellBookController.CurrentSpellbook == null)
            {
                return(false);
            }
            foreach (SpellSlotItem spellSlotItem in ___m_CommonSpellSlots)
            {
                spellSlotItem.DeactivateSlotItem();
                spellSlotItem.SetActive(true);
            }
            foreach (SpellSlotItem spellSlotItem2 in ___m_SpecialSpellSlots)
            {
                spellSlotItem2.DeactivateSlotItem();
                spellSlotItem2.SetActive(false);
            }
            //
            // *********************
            // Patch Start
            // [num] controls how many normal slot of tier [currentLevel] spell has.
            // For arcanists, we have to switch this to her known spell slot number.
            // *********************
            int num;

            num = ArcanistPatch_Helpers.getArcanistMemorizeSlotCnt(currentLevel);
            //num = spellBookController.CurrentSpellbook.CalcSlotsLimit(currentLevel, SpellSlotType.Common);
            // *********************
            // Patch End
            // *********************
            int num2 = spellBookController.CurrentSpellbook.CalcSlotsLimit(currentLevel, SpellSlotType.Favorite);

            foreach (SpellSlotItem spellSlotItem3 in ___m_CommonSpellSlots)
            {
                spellSlotItem3.DeactivateSlotItem();
            }
            int[] array = new int[]
            {
                0,
                0,
                0
            };
            int num3 = (num <= 8) ? 2 : 3;
            int num4 = (int)Mathf.Floor((float)(num / num3));
            int num5 = num % num3;

            if (num > 8)
            {
                array[1] = num4 + num5;
                array[0] = num4;
                array[2] = num4;
            }
            else if (num > 1)
            {
                array[0] = num4 + num5;
                array[1] = num4;
            }
            else if (num > 0)
            {
                array[0] = 1;
            }
            int num6 = 0;

            foreach (int num7 in array)
            {
                for (int k = 0; k < num7; k++)
                {
                    int index = num6 * ___m_CommonSpellSlots.Count / 3 + k;
                    ___m_CommonSpellSlots[index].ActivateSlotItem(SpellSlotType.Common);
                }
                num6++;
            }
            if (___m_SpecialSpellSlots.Length > 0 && num2 > 0)
            {
                ___m_SpecialSlotsContainer.gameObject.SetActive(true);
                if (spellBookController.CurrentSpellbook.Blueprint.CantripsType == CantripsType.Orisions)
                {
                    ___m_LabelSpecialSlots.text       = t.DomainSlots;
                    ___m_SpecialSlotsBackground.color = BlueprintRoot.Instance.UIRoot.SpellBookColors.DomainSlotColor;
                }
                else
                {
                    ___m_LabelSpecialSlots.text       = t.FavoriteSchoolSlots;
                    ___m_SpecialSlotsBackground.color = BlueprintRoot.Instance.UIRoot.SpellBookColors.FavoriteSlotColor;
                }
                foreach (SpellSlotItem spellSlotItem4 in ___m_SpecialSpellSlots)
                {
                    if (num2 <= 0)
                    {
                        break;
                    }
                    SpellSlotType type = (spellBookController.CurrentSpellbook.Blueprint.CantripsType != CantripsType.Orisions) ? SpellSlotType.Favorite : SpellSlotType.Domain;
                    spellSlotItem4.ActivateSlotItem(type);
                    num2--;
                }
            }
            else
            {
                ___m_SpecialSlotsContainer.gameObject.SetActive(false);
            }
            IEnumerable <SpellSlot> memorizedSpellSlots = spellBookController.CurrentSpellbook.GetMemorizedSpellSlots(currentLevel);

            foreach (SpellSlot spellMechanicSlot in memorizedSpellSlots)
            {
                __instance.AddSlot(spellMechanicSlot);
            }

            spellBook.Blueprint.Spontaneous = true;
            return(false);
        }
        static public bool Prefix(ActionBarGroupElement __instance, ref UnitEntityData ___m_Selected, ref ActionBarSubGroupLevels ___m_Levels)
        {
            if (!__instance.PreInit)
            {
                __instance.Dispose();
            }
            int index = 0;
            ActionBarSlotType slotType = __instance.SlotType;

            if (slotType != ActionBarSlotType.Spell)
            {
                /*
                 * if (slotType != ActionBarSlotType.Item) {
                 *  if (slotType == ActionBarSlotType.ActivatableAbility) {
                 *      foreach (Ability ability in ___m_Selected.Abilities) {
                 *          if (!ability.Hidden && !ability.Blueprint.IsCantrip) {
                 *              ActionBarGroupSlot slot = __instance.GetSlot(index++);
                 *              slot.Set(___m_Selected, new MechanicActionBarSlotAbility {
                 *                  Ability = ability.Data,
                 *                  Unit = ___m_Selected
                 *              });
                 *          }
                 *      }
                 *      foreach (ActivatableAbility activatableAbility in ___m_Selected.ActivatableAbilities) {
                 *          ActionBarGroupSlot slot2 = __instance.GetSlot(index++);
                 *          slot2.Set(___m_Selected, new MechanicActionBarSlotActivableAbility {
                 *              ActivatableAbility = activatableAbility,
                 *              Unit = ___m_Selected
                 *          });
                 *      }
                 *  }
                 * }
                 * else {
                 *  foreach (UsableSlot usableSlot in ___m_Selected.Body.QuickSlots) {
                 *      ActionBarGroupSlot slot3 = __instance.GetSlot(index++);
                 *      if (usableSlot.HasItem) {
                 *          slot3.Set(___m_Selected, new MechanicActionBarSlotItem {
                 *              Item = usableSlot.Item,
                 *              Unit = ___m_Selected
                 *          });
                 *      }
                 *      else {
                 *          slot3.Set(___m_Selected, new MechanicActionBarSlotEmpty());
                 *      }
                 *  }
                 * }
                 * __instance.AddEmptySlots(index);
                 * return;
                 */
                return(true);
            }
            if (___m_Levels != null)
            {
                ___m_Levels.Clear();
            }
            List <AbilityData> list = new List <AbilityData>();

            foreach (Ability ability2 in ___m_Selected.Abilities)
            {
                if (!ability2.Hidden && ability2.Blueprint.IsCantrip)
                {
                    AbilityData data = ability2.Data;
                    if (!list.Contains(data))
                    {
                        list.Add(data);
                        if (___m_Levels != null)
                        {
                            ___m_Levels.AddSlot(0, new MechanicActionBarSlotAbility {
                                Ability = data,
                                Unit    = ___m_Selected
                            });
                        }
                    }
                }
            }
            foreach (Spellbook spellbook in ___m_Selected.Descriptor.Spellbooks)
            {
                if (spellbook.Blueprint.Spontaneous)
                {
                    if (spellbook.Blueprint.CharacterClass == Main.arcanist)
                    {
                        for (int i = 1; i <= spellbook.MaxSpellLevel; i++)
                        {
                            IEnumerable <SpellSlot> memorizedSpells = spellbook.GetMemorizedSpells(i);
                            foreach (SpellSlot spellSlot in memorizedSpells)
                            {
                                if (!spellSlot.Available)
                                {
                                    continue;
                                }
                                //the following 2 lines shouldn't be removed.
                                //these are for dealing with the bug appearing at new game:
                                //on new game, the system would automatically memorize (spellperday[1]) spells.
                                //however, arcanist's spell slot cnt on level 1 is fewer than her spell per day.
                                //so the spells memorized in an invalid spellslot would never be forgotten with normal means.
                                int ind = spellSlot.Index;
                                if (ind >= ArcanistPatch_Helpers.getArcanistMemorizeSlotCnt(spellSlot.SpellLevel, spellbook))
                                {
                                    continue;
                                }

                                AbilityData abilityData = spellSlot.Spell;
                                abilityData.ParamSpellSlot = spellSlot;
                                if (!list.Contains(abilityData))
                                {
                                    list.Add(abilityData);
                                    if (___m_Levels != null)
                                    {
                                        ___m_Levels.AddSlot(i, new MechanicActionBarSlotSpontaneusSpell {
                                            Spell = abilityData,
                                            Unit  = ___m_Selected
                                        });
                                    }
                                }
                            }
                        }
                    }

                    else
                    {
                        for (int i = 1; i <= spellbook.MaxSpellLevel; i++)
                        {
                            List <AbilityData> list2      = spellbook.GetSpecialSpells(i).Concat(spellbook.GetKnownSpells(i)).Distinct <AbilityData>().ToList <AbilityData>();
                            List <AbilityData> collection = spellbook.GetCustomSpells(i).ToList <AbilityData>();
                            List <AbilityData> list3      = list2;
                            list3.AddRange(collection);
                            foreach (AbilityData abilityData in list3)
                            {
                                if (!list.Contains(abilityData))
                                {
                                    list.Add(abilityData);
                                    if (___m_Levels != null)
                                    {
                                        ___m_Levels.AddSlot(i, new MechanicActionBarSlotSpontaneusSpell {
                                            Spell = abilityData,
                                            Unit  = ___m_Selected
                                        });
                                    }
                                }
                            }
                        }
                    }
                }
                else
                {
                    //Added codes start. Arcanist use their memorized spells as known spells.
                    if (1 == 0 /*spellbook.Blueprint.CharacterClass == Main.arcanist*/)
                    {
                        UnityModManager.Logger.Log("Rua spellbook is arcanist!");
                        for (int i = 1; i <= spellbook.MaxSpellLevel; i++)
                        {
                            IEnumerable <SpellSlot> memorizedSpells = spellbook.GetMemorizedSpells(i);
                            foreach (SpellSlot spellSlot in memorizedSpells)
                            {
                                if (!spellSlot.Available)
                                {
                                    continue;
                                }
                                AbilityData abilityData = spellSlot.Spell;
                                if (!list.Contains(abilityData))
                                {
                                    list.Add(abilityData);
                                    if (___m_Levels != null)
                                    {
                                        ___m_Levels.AddSlot(i, new MechanicActionBarSlotSpontaneusSpell {
                                            Spell = abilityData,
                                            Unit  = ___m_Selected
                                        });
                                    }
                                }
                            }
                        }
                    }
                    //Added codes end.
                    else
                    {
                        for (int j = 0; j <= spellbook.MaxSpellLevel; j++)
                        {
                            IEnumerable <SpellSlot> memorizedSpells = spellbook.GetMemorizedSpells(j);
                            foreach (SpellSlot spellSlot in memorizedSpells)
                            {
                                if (!list.Contains(spellSlot.Spell))
                                {
                                    list.Add(spellSlot.Spell);
                                    if (___m_Levels != null)
                                    {
                                        ___m_Levels.AddSlot(j, new MechanicActionBarSlotMemorizedSpell {
                                            SpellSlot = spellSlot,
                                            Unit      = ___m_Selected
                                        });
                                    }
                                }
                            }
                        }
                    }
                }
            }
            if (___m_Levels != null)
            {
                ___m_Levels.SetType(__instance.SlotType);
            }
            return(false);
        }