Ejemplo n.º 1
0
        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;
                                }
                                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);
        }
        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);
        }