ServUO Version
Publish 57
Ultima Expansion
Endless Journey
Getting the following:
C#:
Operator '||' cannot be applied to operands of type 'ArcaneFocus' and 'EverlastingArcaneFocus'
related to:
C#:
        public static int GetFocusLevel(Mobile from)
        {
            // Iomega0318 - EverlastingArcaneFocus
            ArcaneFocus focus = (FindArcaneFocus(from) || FindEverlastingArcaneFocus(from));

            if (focus == null || focus.Deleted)
            {
                if (Core.TOL && from is BaseCreature && from.Skills[SkillName.Spellweaving].Value > 0)
                {
                    return (int)Math.Max(1, Math.Min(6, from.Skills[SkillName.Spellweaving].Value / 20));
                }

                return Math.Max(GetMasteryFocusLevel(from), 0);
            }

            return Math.Max(GetMasteryFocusLevel(from), focus.StrengthBonus);
        }

        public static int GetMasteryFocusLevel(Mobile from)
        {
            if (!Core.TOL)
            {
                return 0;
            }

            if (from.Skills.CurrentMastery == SkillName.Spellweaving)
            {
                return Math.Max(1, MasteryInfo.GetMasteryLevel(from, SkillName.Spellweaving));
            }

            return 0;
        }

        public static ArcaneFocus FindArcaneFocus(Mobile from)
        {
            if (from == null || from.Backpack == null)
            {
                return null;
            }
            
            if (from.Holding is ArcaneFocus)
            {
                return (ArcaneFocus)from.Holding;
            }

            return from.Backpack.FindItemByType<ArcaneFocus>();
        }
        
        // Iomega0318 - EverlastingArcaneFocus
        public static EverlastingArcaneFocus FindEverlastingArcaneFocus(Mobile from)
        {
            if (from == null || from.Backpack == null)
            {
                return null;
            }
            
            if (from.Holding is EverlastingArcaneFocus)
            {
                return (EverlastingArcaneFocus)from.Holding;
            }

            return from.Backpack.FindItemByType<EverlastingArcaneFocus>();
        }

Not quite sure what that means, if you need to see the full scripts let me know, essentially what I am trying to do is add in an item that can be used indefinitely and doesn't expire to be used in place of the arcane focus, but not replace it.
 
Try using ?? (the null fallback operator)
Code:
(FindArcaneFocus(from) ?? FindEverlastingArcaneFocus(from))

As long as FindEverlastingArcaneFocus returns the type ArcaneFocus, it should work.
 
Try using ?? (the null fallback operator)
Code:
(FindArcaneFocus(from) ?? FindEverlastingArcaneFocus(from))

As long as FindEverlastingArcaneFocus returns the type ArcaneFoxus, it should work.
Hmm, I just copied the FindArcaneFocus and changed the name..

**EDIT**
Ahh must be the everlasting focus, I tried using just that and got the following:
C#:
ArcaneFocus focus = FindEverlastingArcaneFocus(from);
C#:
Cannot implicitly convert type 'Server.Items.EverlastingArcaneFocus' to 'Server.Items.ArcaneFocus'

**EDIT TWO**
Okay so this works.. but if I uncomment the Arcane Focus I can't seem to get both of them to work..
C#:
        public static int GetFocusLevel(Mobile from)
        {
            // Iomega0318 - EverlastingArcaneFocus
            //ArcaneFocus focus = (FindArcaneFocus(from) || FindEverlastingArcaneFocus(from));
            //ArcaneFocus focus = FindArcaneFocus(from);
            EverlastingArcaneFocus efocus = FindEverlastingArcaneFocus(from);

            /*if (focus == null || focus.Deleted)
            {
                if (Core.TOL && from is BaseCreature && from.Skills[SkillName.Spellweaving].Value > 0)
                {
                    return (int)Math.Max(1, Math.Min(6, from.Skills[SkillName.Spellweaving].Value / 20));
                }

                return Math.Max(GetMasteryFocusLevel(from), 0);
            }*/

            //return Math.Max(GetMasteryFocusLevel(from), focus.StrengthBonus);
            
            if (efocus == null || efocus.Deleted)
            {
                if (Core.TOL && from is BaseCreature && from.Skills[SkillName.Spellweaving].Value > 0)
                {
                    return (int)Math.Max(1, Math.Min(6, from.Skills[SkillName.Spellweaving].Value / 20));
                }

                return Math.Max(GetMasteryFocusLevel(from), 0);
            }

            return Math.Max(GetMasteryFocusLevel(from), efocus.StrengthBonus);
        }
 
Last edited:
Try using ?? (the null fallback operator)
Code:
(FindArcaneFocus(from) ?? FindEverlastingArcaneFocus(from))

As long as FindEverlastingArcaneFocus returns the type ArcaneFocus, it should work.
It's a different item altogether though so wouldn't it never return that type lol?
 
You could make EverlastingArcaneFocus directly inherit ArcaneFocus and override the mechanic that consumes the charges.

Otherwise your only other option is to check it separately, as early as possible;
C#:
        public static int GetFocusLevel(Mobile from)
        {
            // Iomega0318 - EverlastingArcaneFocus

            EverlastingArcaneFocus efocus = FindEverlastingArcaneFocus(from);

            if (efocus != null && !efocus.Deleted)
            {
                return efocus.StrengthBonus;
            }

            ArcaneFocus focus = FindArcaneFocus(from);

            if (focus == null || focus.Deleted)
            {
                if (Core.TOL && from is BaseCreature && from.Skills[SkillName.Spellweaving].Value > 0)
                {
                    return (int)Math.Max(1, Math.Min(6, from.Skills[SkillName.Spellweaving].Value / 20));
                }

                return Math.Max(GetMasteryFocusLevel(from), 0);
            }
...
 
Well the goal with this was to remove the timer from the focus so it never expires it doesn't use charges, I've been playing with it more and can mostly get everything to work but can't get it to do both at the same time, this line is where I'm stuck on currently:
C#:
return Math.Max(GetMasteryFocusLevel(from), focus.StrengthBonus || efocus.StrengthBonus);
C#:
Operator '||' cannot be applied to operands of type 'int' and 'int'
C#:
        public static int GetFocusLevel(Mobile from)
        {
            // Iomega0318 - EverlastingArcaneFocus
            //ArcaneFocus focus = (FindArcaneFocus(from) || FindEverlastingArcaneFocus(from));
            ArcaneFocus focus = FindArcaneFocus(from);
            EverlastingArcaneFocus efocus = FindEverlastingArcaneFocus(from);

            if (focus == null || focus.Deleted || efocus == null || efocus.Deleted)
            {
                if (Core.TOL && from is BaseCreature && from.Skills[SkillName.Spellweaving].Value > 0)
                {
                    return (int)Math.Max(1, Math.Min(6, from.Skills[SkillName.Spellweaving].Value / 20));
                }

                return Math.Max(GetMasteryFocusLevel(from), 0);
            }

            return Math.Max(GetMasteryFocusLevel(from), focus.StrengthBonus || efocus.StrengthBonus);
        }

I'm not sure how I would override the timer if I use the Arcane Focus as a base class..
 
You can't use a logic OR || operator in this way, you need to use Math.Max twice;
C#:
var value = GetMasteryFocusLevel(from);

value = Math.Max(value, focus.StrengthBonus);
value = Math.Max(value, efocus.StrengthBonus);

return value;
 
You could make EverlastingArcaneFocus directly inherit ArcaneFocus and override the mechanic that consumes the charges.

Otherwise your only other option is to check it separately, as early as possible;
C#:
        public static int GetFocusLevel(Mobile from)
        {
            // Iomega0318 - EverlastingArcaneFocus

            EverlastingArcaneFocus efocus = FindEverlastingArcaneFocus(from);

            if (efocus != null && !efocus.Deleted)
            {
                return efocus.StrengthBonus;
            }

            ArcaneFocus focus = FindArcaneFocus(from);

            if (focus == null || focus.Deleted)
            {
                if (Core.TOL && from is BaseCreature && from.Skills[SkillName.Spellweaving].Value > 0)
                {
                    return (int)Math.Max(1, Math.Min(6, from.Skills[SkillName.Spellweaving].Value / 20));
                }

                return Math.Max(GetMasteryFocusLevel(from), 0);
            }
...

You can't use a logic OR || operator in this way, you need to use Math.Max twice;
C#:
var value = GetMasteryFocusLevel(from);

value = Math.Max(value, focus.StrengthBonus);
value = Math.Max(value, efocus.StrengthBonus);

return value;
Ok so I took both of what you suggested and put them together, the good news is now the Everlasting Focus is working and the system reads it and applies the buff, the bad news is now when using the normal focus the server crashes haha..
C#:
        public static int GetFocusLevel(Mobile from)
        {
            // Iomega0318 - EverlastingArcaneFocus
            EverlastingArcaneFocus efocus = FindEverlastingArcaneFocus(from);

            if (efocus != null && !efocus.Deleted)
            {
                return efocus.StrengthBonus;
            }
            
            ArcaneFocus focus = FindArcaneFocus(from);

            if (focus == null || focus.Deleted)
            {
                if (Core.TOL && from is BaseCreature && from.Skills[SkillName.Spellweaving].Value > 0)
                {
                    return (int)Math.Max(1, Math.Min(6, from.Skills[SkillName.Spellweaving].Value / 20));
                }

                return Math.Max(GetMasteryFocusLevel(from), 0);
            }
            
            var value = GetMasteryFocusLevel(from);

            value = Math.Max(value, focus.StrengthBonus);
            value = Math.Max(value, efocus.StrengthBonus);

            return value;
        }
C#:
Exception:
System.NullReferenceException: Object reference not set to an instance of an object.
   at Server.Spells.Spellweaving.ArcanistSpell.GetFocusLevel(Mobile from)
   at Server.Spells.Spellweaving.ArcanistSpell.OnBeginCast()
   at Server.Spells.Spell.Cast()
   at Server.ACC.CSS.CSpellbookGump.OnResponse(NetState state, RelayInfo info)
   at Server.Network.PacketHandlers.DisplayGumpResponse(NetState state, PacketReader pvSrc) in C:\ServUO\Server\Network\PacketHandlers.cs:line 1457
   at Knives.TownHouses.GumpResponse.DisplayGumpResponse(NetState state, PacketReader pvSrc)
   at Server.Network.MessagePump.HandleReceive(NetState ns) in C:\ServUO\Server\Network\MessagePump.cs:line 347
   at Server.Network.MessagePump.Slice() in C:\ServUO\Server\Network\MessagePump.cs:line 136
   at Server.Core.Main(String[] args) in C:\ServUO\Server\Main.cs:line 676
 
You almost had it :p
C#:
        public static int GetFocusLevel(Mobile from)
        {
            // Iomega0318 - EverlastingArcaneFocus
            EverlastingArcaneFocus efocus = FindEverlastingArcaneFocus(from);

            if (efocus != null && !efocus.Deleted)
            {
                return Math.Max(GetMasteryFocusLevel(from), efocus.StrengthBonus);
            }
            
            ArcaneFocus focus = FindArcaneFocus(from);

            if (focus == null || focus.Deleted)
            {
                if (Core.TOL && from is BaseCreature && from.Skills[SkillName.Spellweaving].Value > 0)
                {
                    return (int)Math.Max(1, Math.Min(6, from.Skills[SkillName.Spellweaving].Value / 20));
                }

                return Math.Max(GetMasteryFocusLevel(from), 0);
            }

            return Math.Max(GetMasteryFocusLevel(from), focus.StrengthBonus);
        }

This might be easier to understand though, inverted the last if-statement to match the first;
C#:
        public static int GetFocusLevel(Mobile from)
        {
            // Iomega0318 - EverlastingArcaneFocus
            EverlastingArcaneFocus efocus = FindEverlastingArcaneFocus(from);

            if (efocus != null && !efocus.Deleted)
            {
                return Math.Max(GetMasteryFocusLevel(from), efocus.StrengthBonus);
            }
            
            ArcaneFocus focus = FindArcaneFocus(from);

            if (focus != null && !focus.Deleted)
            {
                return Math.Max(GetMasteryFocusLevel(from), focus.StrengthBonus);
            }

            if (Core.TOL && from is BaseCreature && from.Skills[SkillName.Spellweaving].Value > 0)
            {
                return (int)Math.Max(1, Math.Min(6, from.Skills[SkillName.Spellweaving].Value / 20));
            }

            return Math.Max(GetMasteryFocusLevel(from), 0);
        }
 
Back