Exemplo n.º 1
0
    /// <summary>
    /// Called for a loaded entity that can cast spells
    /// Checks if the Entity is currently casting a Continous Cast spell
    /// If they are, we update the spell casting, and change mana and XP values
    /// accordingly
    /// </summary>
    /// <param name="data"></param>
    public void Update(SpellCastData data)
    {
        //Check lots 1 and 2
        for (int i = 0; i < 2; i++)
        {
            //get the spell, continue if spell is null
            Spell s = EquiptSpells[i];
            if (s == null)
            {
                continue;
            }
            //If the spell is a hold spell
            if (s is HoldSpell)
            {
                HoldSpell holdSpell = s as HoldSpell;

                if (holdSpell.IsCast)
                {
                    //Check if the key is down
                    if (SpellKeyDown[i] == false)
                    {
                        holdSpell.SpellEnd(data); //If not, then end the spell
                        Debug.Log("Ending");
                    }
                    else
                    {
                        //Set to false to be updated
                        SpellKeyDown[i] = false;
                        //If we have enough mana, update the spell
                        if (CurrentMana > holdSpell.ManaCost * Time.deltaTime)
                        {
                            Debug.Log("Updating");
                            holdSpell.SpellUpdate(data);
                            AddXp(holdSpell);
                            CurrentMana -= holdSpell.ManaCost * Time.deltaTime;
                        }
                        else
                        {
                            Debug.Log("Ending");

                            //If not, stop the spell
                            holdSpell.SpellEnd(data);
                        }
                    }
                }
            }
        }
    }
Exemplo n.º 2
0
    /// <summary>
    /// Casts the specified spell from the local spell inventory
    /// based on the relevent SpellCastData
    /// </summary>
    /// <param name="spell"></param>
    /// <param name="data"></param>
    public void CastSpell(int spell, SpellCastData data)
    {
        //Check if spell number is valid
        if (spell <= 0 && spell < 2)
        {
            SpellKeyDown[spell] = true; //Set the hold figure to tue

            Spell s = EquiptSpells[spell];
            if (s == null)
            {
                return;
            }
            if (s is SingleSpell)
            {
                Debug.Log("single spell");
                //If the spell is a single cast, ensure the cool down and mana costs are valid.
                SingleSpell singSpe = s as SingleSpell;
                if (CurrentMana > s.ManaCost && SpellTimers[spell].ElapsedMilliseconds > singSpe.CoolDown * 1000)
                {
                    singSpe.CastSpell(data);
                    AddXp(s);
                    CurrentMana -= s.ManaCost;
                    SpellTimers[spell].Restart();
                }
                else
                {
                    Debug.Log("Cur man/Cost: " + CurrentMana + "/" + s.ManaCost + " elapsed/cooldown: " + SpellTimers[spell].ElapsedMilliseconds + "/" + singSpe.CoolDown * 1000);
                }
            }
            else
            {
                //If the spell is a hold spell, check if we've started casting it.
                HoldSpell holdSpel = s as HoldSpell;
                if (!holdSpel.IsCast)
                {
                    Debug.Log("Casting");
                    holdSpel.SpellStart(data);
                    AddXp(s);
                    CurrentMana -= s.ManaCost * Time.deltaTime;
                }
                //If we are casting, it is dealth with in the u[
            }
        }
    }