Пример #1
0
        /// <summary>
        /// Raises the tooltip event.
        /// </summary>
        /// <param name="show">If set to <c>true</c> show.</param>
        public override void OnTooltip(bool show)
        {
            // Make sure we have spell info, otherwise game might crash
            if (this.m_SpellInfo == null)
            {
                return;
            }

            // If we are showing the tooltip
            if (show)
            {
                UITooltip.InstantiateIfNecessary(this.gameObject);

                // Prepare the tooltip lines
                UISpellSlot.PrepareTooltip(this.m_SpellInfo);

                // Anchor to this slot
                UITooltip.AnchorToRect(this.transform as RectTransform);

                // Show the tooltip
                UITooltip.Show();
            }
            else
            {
                // Hide the tooltip
                UITooltip.Hide();
            }
        }
Пример #2
0
        /// <summary>
        /// Raises the assign spell event.
        /// </summary>
        /// <param name="spellSlot">The spell slot.</param>
        public void OnAssignSpell(UISpellSlot spellSlot)
        {
            // Return if the slot is not valid
            if (spellSlot == null || spellSlot.GetSpellInfo() == null)
            {
                return;
            }

            // Get the spell info
            UISpellInfo spellInfo = spellSlot.GetSpellInfo();

            // Check if this spell still has cooldown
            if (spellCooldowns.ContainsKey(spellInfo.ID))
            {
                float cooldownTill = spellCooldowns[spellInfo.ID].endTime;

                // Check if the cooldown isnt expired
                if (cooldownTill > Time.time)
                {
                    // Resume the cooldown
                    this.ResumeCooldown(spellInfo.ID);
                }
                else
                {
                    // Cooldown already expired, remove the record
                    spellCooldowns.Remove(spellInfo.ID);
                }
            }
        }
Пример #3
0
 void Awake()
 {
     if (this.slot == null)
     {
         this.slot = this.GetComponent <UISpellSlot>();
     }
 }
Пример #4
0
        public void OnSpellClick(UISpellSlot slot)
        {
            // Make sure we have the cast bar component and the slot is assigned
            if (this.m_CastBar == null || !slot.IsAssigned())
            {
                return;
            }

            // Check if we are already casting
            if (this.m_CastBar.IsCasting)
            {
                return;
            }

            // Get the spell info from the slot
            UISpellInfo spellInfo = slot.GetSpellInfo();

            // Make sure we have spell info
            if (spellInfo == null)
            {
                return;
            }

            // Check if we are on cooldown
            if (spellInfo.Cooldown > 0f && slot.cooldownComponent != null && slot.cooldownComponent.IsOnCooldown)
            {
                return;
            }

            // Check if the spell is not insta cast
            if (!spellInfo.Flags.Has(UISpellInfo_Flags.InstantCast))
            {
                // Start casting
                this.m_CastBar.StartCasting(spellInfo, spellInfo.CastTime, Time.time + spellInfo.CastTime);
            }

            // Handle cooldown just for the demonstration
            if (slot.cooldownComponent != null && spellInfo.Cooldown > 0f)
            {
                // Start the cooldown on all the slots with the specified spell id
                foreach (UISpellSlot s in UISpellSlot.GetSlots())
                {
                    if (s.IsAssigned() && s.GetSpellInfo() != null && s.cooldownComponent != null)
                    {
                        // If the slot IDs match
                        if (s.GetSpellInfo().ID == spellInfo.ID)
                        {
                            // Start the cooldown
                            s.cooldownComponent.StartCooldown(spellInfo.ID, spellInfo.Cooldown);
                        }
                    }
                }
            }
        }
Пример #5
0
        /// <summary>
        /// Assign the slot by the passed source slot.
        /// </summary>
        /// <param name="source">Source.</param>
        public override bool Assign(Object source)
        {
            if (source is UISpellSlot)
            {
                UISpellSlot sourceSlot = source as UISpellSlot;

                if (sourceSlot != null)
                {
                    return(this.Assign(sourceSlot.GetSpellInfo()));
                }
            }

            // Default
            return(false);
        }
Пример #6
0
        protected override void OnEnable()
        {
            base.OnEnable();

            // Check for duplicate id
            List <UISpellSlot> slots     = GetSlotsInGroup(this.m_SlotGroup);
            UISpellSlot        duplicate = slots.Find(x => x.ID == this.m_ID && !x.Equals(this));

            if (duplicate != null)
            {
                int oldId = this.m_ID;
                this.AutoAssignID();
                Debug.LogWarning("Item Slot with duplicate ID: " + oldId + " in Group: " + this.m_SlotGroup + ", generating and assigning new ID: " + this.m_ID + ".");
            }
        }
Пример #7
0
        // <summary>
        /// Performs a slot swap.
        /// </summary>
        /// <returns><c>true</c>, if slot swap was performed, <c>false</c> otherwise.</returns>
        /// <param name="sourceSlot">Source slot.</param>
        public override bool PerformSlotSwap(Object sourceObject)
        {
            // Get the source slot
            UISpellSlot sourceSlot = (sourceObject as UISpellSlot);

            // Get the source spell info
            UISpellInfo sourceSpellInfo = sourceSlot.GetSpellInfo();

            // Assign the source slot by this one
            bool assign1 = sourceSlot.Assign(this.GetSpellInfo());

            // Assign this slot by the source slot
            bool assign2 = this.Assign(sourceSpellInfo);

            // Return the status
            return(assign1 && assign2);
        }
Пример #8
0
        protected void Start()
        {
            // Disable the image and text if they are shown by any chance
            if (this.m_TargetGraphic != null)
            {
                this.m_TargetGraphic.enabled = false;
            }
            if (this.m_TargetText != null)
            {
                this.m_TargetText.enabled = false;
            }

            // Prepare the finish
            if (this.m_FinishGraphic != null)
            {
                this.m_FinishGraphic.enabled = false;
                this.m_FinishGraphic.rectTransform.anchorMin = new Vector2(this.m_FinishGraphic.rectTransform.anchorMin.x, 1f);
                this.m_FinishGraphic.rectTransform.anchorMax = new Vector2(this.m_FinishGraphic.rectTransform.anchorMax.x, 1f);
            }

            // Hook the assign and unassign events
            if (this.m_TargetSlot != null)
            {
                // Check if the slot is a spell slot
                if (this.m_TargetSlot is UISpellSlot)
                {
                    UISpellSlot slot = (this.m_TargetSlot as UISpellSlot);

                    // Hook the events
                    slot.onAssign.AddListener(OnAssignSpell);
                    slot.onUnassign.AddListener(OnUnassignSpell);
                    slot.AssignCooldownComponent(this);
                }
            }
            else
            {
                Debug.LogWarning("The slot cooldown script cannot operate without a target slot, disabling script.");
                this.enabled = false;
                return;
            }
        }
Пример #9
0
 /// <summary>
 /// Raises the unassign event.
 /// </summary>
 public void OnUnassignSpell(UISpellSlot spellSlot)
 {
     this.InterruptCooldown();
 }
Пример #10
0
 public void OnSpellClick(UISpellSlot slot)
 {
     Debug.Log("clicked" + slot.GetSpellInfo().Name);
     CastSpell(GameManager.Instance.GameDB.Spells[slot.GetSpellInfo().ID]);
 }