Exemplo n.º 1
0
        /// <summary>
        /// Assign the slot by spell info.
        /// </summary>
        /// <param name="spellInfo">Spell info.</param>
        public bool Assign(UISpellInfo spellInfo)
        {
            if (spellInfo == null)
            {
                return(false);
            }

            // Make sure we unassign first, so the event is called before new assignment
            this.Unassign();

            // Use the base class assign to set the icon
            this.Assign(spellInfo.Icon);

            // Set the spell info
            this.m_SpellInfo = spellInfo;

            // Invoke the on assign event
            if (this.onAssign != null)
            {
                this.onAssign.Invoke(this);
            }

            // Notify the cooldown component
            if (this.m_Cooldown != null)
            {
                this.m_Cooldown.OnAssignSpell();
            }

            // Success
            return(true);
        }
        void Start()
        {
            if (UISpellDatabase.Instance == null || !this.m_IsDemo)
            {
                return;
            }

            UISpellInfo[] spells = UISpellDatabase.Instance.spells;
            UISpellInfo   spell  = spells[Random.Range(0, spells.Length)];

            if (this.m_Slot != null)
            {
                this.m_Slot.Assign(spell);
            }
            if (this.m_NameText != null)
            {
                this.m_NameText.text = spell.Name;
            }
            if (this.m_RankText != null)
            {
                this.m_RankText.text = Random.Range(1, 6).ToString();
            }
            if (this.m_DescriptionText != null)
            {
                this.m_DescriptionText.text = spell.Description;
            }
        }
Exemplo n.º 3
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);
                }
            }
        }
        private void Player_StartCastEvent(object sender, EventArgs e)
        {
            if (player.castingSpell.Name != "" && !this.castBar.IsCasting)
            {
                UISpellInfo spellInfo = new UISpellInfo(player.castingSpell);

                UnityThread.executeInUpdate(() => castBar.StartCasting(spellInfo, spellInfo.CastTime, Time.time + spellInfo.CastTime));
            }
        }
Exemplo n.º 5
0
        void Start()
        {
            if (this.m_CastBar != null && UISpellDatabase.Instance != null)
            {
                this.spell1 = UISpellDatabase.Instance.Get(0);
                this.spell2 = UISpellDatabase.Instance.Get(2);

                this.StartCoroutine("StartTestRoutine");
            }
        }
Exemplo n.º 6
0
        /// <summary>
        /// Unassign this slot.
        /// </summary>
        public override void Unassign()
        {
            // Remove the icon
            base.Unassign();

            // Clear the talent info
            this.m_TalentInfo = null;

            // Clear the spell info
            this.m_SpellInfo = null;
        }
Exemplo n.º 7
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);
                        }
                    }
                }
            }
        }
Exemplo n.º 8
0
        /// <summary>
        /// Unassign this slot.
        /// </summary>
        public override void Unassign()
        {
            // Remove the icon
            base.Unassign();

            // Clear the spell info
            this.m_SpellInfo = null;

            // Invoke the on unassign event
            if (this.onUnassign != null)
            {
                this.onUnassign.Invoke(this);
            }
        }
Exemplo n.º 9
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
            IUISpellSlot sourceSlot = (sourceObject as IUISpellSlot);

            // 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);
        }
Exemplo n.º 10
0
        /// <summary>
        /// Unassign this slot.
        /// </summary>
        public override void Unassign()
        {
            // Remove the icon
            base.Unassign();

            // Clear the spell info
            this.m_SpellInfo = null;

            // Invoke the on unassign event
            if (this.onUnassign != null)
            {
                this.onUnassign.Invoke(this);
            }

            // Notify the cooldown component
            if (this.m_Cooldown != null)
            {
                this.m_Cooldown.OnUnassignSpell();
            }
        }
Exemplo n.º 11
0
		/// <summary>
		/// Assign the specified slot by talentInfo and spellInfo.
		/// </summary>
		/// <param name="talentInfo">Talent info.</param>
		/// <param name="spellInfo">Spell info.</param>
		public bool Assign(UITalentInfo talentInfo, UISpellInfo spellInfo)
		{
			if (talentInfo == null || spellInfo == null)
				return false;
			
			// Use the base class to assign the icon
			this.Assign(spellInfo.Icon);
			
			// Set the talent info
			this.m_TalentInfo = talentInfo;
			
			// Set the spell info
			this.m_SpellInfo = spellInfo;
			
			// Update the points label
			this.UpdatePointsLabel();
			
			// Return success
			return true;
		}
Exemplo n.º 12
0
        /// <summary>
        /// Checks if the target slot has an active cooldown and resumes it.
        /// </summary>
        public void CheckForActiveCooldown()
        {
            // Return if the slot is not valid
            if (this.m_CooldownSlot == null)
            {
                return;
            }

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

            if (spellInfo == null)
            {
                return;
            }

            // 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)
                {
                    this.m_IsOnCooldown = true;

                    // Resume the cooldown
                    this.ResumeCooldown(spellInfo.ID);
                }
                else
                {
                    // Cooldown already expired, remove the record
                    spellCooldowns.Remove(spellInfo.ID);
                }
            }
        }
Exemplo n.º 13
0
        /// <summary>
        /// Starts the casting of the specified spell.
        /// </summary>
        /// <param name="spellInfo">Spell info.</param>
        /// <param name="duration">Duration.</param>
        /// <param name="endTime">End time.</param>
        public virtual void StartCasting(UISpellInfo spellInfo, float duration, float endTime)
        {
            // Make sure we can start casting it
            if (this.m_IsCasting)
            {
                return;
            }

            // Stop the coroutine might be still running on the hide delay
            this.StopCoroutine("AnimateCast");
            this.StopCoroutine("DelayHide");

            // Apply the normal colors
            this.ApplyColorStage(this.m_NormalColors);

            // Change the fill pct
            this.SetFillAmount(0f);

            // Set the spell name
            if (this.m_TitleLabel != null)
            {
                this.m_TitleLabel.text = spellInfo.Name;
            }

            // Set the full time cast text
            if (this.m_FullTimeLabel != null)
            {
                this.m_FullTimeLabel.text = spellInfo.CastTime.ToString(this.m_FullTimeFormat);
            }

            // Set the icon if we have enabled icons
            if (this.m_UseSpellIcon)
            {
                // Check if we have a sprite
                if (spellInfo.Icon != null)
                {
                    // Check if the icon image is set
                    if (this.m_IconImage != null)
                    {
                        this.m_IconImage.sprite = spellInfo.Icon;
                    }

                    // Enable the frame
                    if (this.m_IconFrame != null)
                    {
                        this.m_IconFrame.SetActive(true);
                    }
                }
            }

            // Set some info about the cast
            this.currentCastDuration = duration;
            this.currentCastEndTime  = endTime;

            // Define that we start casting animation
            this.m_IsCasting = true;

            // Show the cast bar
            this.Show();

            // Start the cast animation
            this.StartCoroutine("AnimateCast");
        }
Exemplo n.º 14
0
        public static void PrepareTooltip(UISpellInfo spellInfo)
        {
            // Make sure we have spell info, otherwise game might crash
            if (spellInfo == null)
            {
                return;
            }

            // Set the tooltip width
            if (UITooltipManager.Instance != null)
            {
                UITooltip.SetWidth(UITooltipManager.Instance.spellTooltipWidth);
            }

            // Set the spell name as title
            UITooltip.AddLine(spellInfo.Name, "SpellTitle");

            // Spacer
            UITooltip.AddSpacer();

            // Prepare some attributes
            if (spellInfo.Flags.Has(UISpellInfo_Flags.Passive))
            {
                UITooltip.AddLine("Passive", "SpellAttribute");
            }
            else
            {
                // Power consumption
                if (spellInfo.PowerCost > 0f)
                {
                    if (spellInfo.Flags.Has(UISpellInfo_Flags.PowerCostInPct))
                    {
                        UITooltip.AddLineColumn(spellInfo.PowerCost.ToString("0") + "% Energy", "SpellAttribute");
                    }
                    else
                    {
                        UITooltip.AddLineColumn(spellInfo.PowerCost.ToString("0") + " Energy", "SpellAttribute");
                    }
                }

                // Range
                if (spellInfo.Range > 0f)
                {
                    if (spellInfo.Range == 1f)
                    {
                        UITooltip.AddLineColumn("Melee range", "SpellAttribute");
                    }
                    else
                    {
                        UITooltip.AddLineColumn(spellInfo.Range.ToString("0") + " yd range", "SpellAttribute");
                    }
                }

                // Cast time
                if (spellInfo.CastTime == 0f)
                {
                    UITooltip.AddLineColumn("Instant", "SpellAttribute");
                }
                else
                {
                    UITooltip.AddLineColumn(spellInfo.CastTime.ToString("0.0") + " sec cast", "SpellAttribute");
                }

                // Cooldown
                if (spellInfo.Cooldown > 0f)
                {
                    UITooltip.AddLineColumn(spellInfo.Cooldown.ToString("0.0") + " sec cooldown", "SpellAttribute");
                }
            }

            // Set the spell description if not empty
            if (!string.IsNullOrEmpty(spellInfo.Description))
            {
                UITooltip.AddSpacer();
                UITooltip.AddLine(spellInfo.Description, "SpellDescription");
            }
        }