示例#1
0
        private void DoPlayerSpell(PlayerWitch p, PlayerSpell spell)
        {
            int repeats = p.Action.GetRepeats();

            if (repeats < 1)
            {
                throw new GameException("Repeat can't be zero (on " + spell.Id + ")");
            }
            if (repeats > 1 && !spell.IsRepeatable())
            {
                throw new GameException("Spell " + spell.Id + " is not repeatable");
            }
            if (!spell.IsActive())
            {
                throw new GameException("Spell " + spell.Id + " is exhausted");
            }
            if (!p.CanAfford(spell.Recipe, repeats))
            {
                throw new GameException("Not enough ingredients for spell " + spell.Id);
            }
            if (!p.EnoughSpace(spell.Recipe, repeats))
            {
                throw new GameException("Not enough space in inventory for spell " + spell.Id);
            }

            //do spell
            for (int k = 0; k < repeats; ++k)
            {
                for (int i = 0; i < INGREDIENT_TYPE_COUNT; ++i)
                {
                    p.Inventory.Add(i, spell.GetDelta()[i]);
                }
            }
            spell.Deactivate();

            EventData e = new EventData();

            e.Type      = EventData.PLAYER_SPELL;
            e.PlayerIdx = p.Index;
            e.SpellId   = spell.Id;
            e.Repeats   = repeats;
            _viewerEvents.Add(e);
        }
示例#2
0
    protected override IEnumerator Attacking()
    {
        isAttacking = true;
        Vector3    startPos = transform.position;
        Quaternion startRot = transform.rotation;

        animator.SetBool("blocking", false);

        hurtbox.enabled = false;

        yield return(new WaitUntil(() => attackChosen));

        yield return(new WaitUntil(() => TargetChosen()));

        battleManager.CurrentMove = currentMove;

        try
        {
            for (int i = 0; i < currentMove.particleEffects.Length; i++)
            {
                StartCoroutine(PlayParticles(currentMove.particleDelay[i],
                                             currentMove.particleEffects[i], spellSpawnTransforms[currentMove.particleSpawnPositionID[i]],
                                             currentMove.particleDuration[i], currentMove.releaseOnInit[i]));
            }
        }
        catch (NullReferenceException) {
            Debug.Log("particles are null");
        }

        PlayerMelee     melee      = currentMove as PlayerMelee;
        PlayerSpell     spell      = currentMove as PlayerSpell;
        PlayerSelfBuff  selfBuff   = currentMove as PlayerSelfBuff;
        SpellProjectile projectile = null;

        if (melee != null)
        {
            walkingForward = true;
            agent.SetDestination(currentTarget.GetAttackPosition().position);
            agent.stoppingDistance = attackPositionOffset;
            yield return(new WaitUntil(() => !agent.pathPending));

            yield return(new WaitUntil(() => agent.pathStatus == NavMeshPathStatus.PathComplete && agent.remainingDistance <= attackPositionOffset));

            hitboxes[melee.hitboxID].enabled = true;
        }

        animator.SetTrigger(name: currentMove.animationName);

        yield return(new WaitUntil(() => animator.GetCurrentAnimatorClipInfo(0)[0].clip.name.Contains(currentMove.animationName)));

        PayForAttack();

        if (selfBuff != null)
        {
            Debug.Log($"{selfBuff.EnhanceDuration(this, selfBuff.buff.duration)}");
            AddPerk(selfBuff.buff, selfBuff.EnhanceDuration(this, selfBuff.buff.duration));
        }

        if (spell != null)
        {
            if (spell.type == SpellType.Areal)
            {
                yield return(new WaitForSeconds(spell.delay[0]));

                foreach (Enemy enemy in battleManager.GetEnemies())
                {
                    for (int i = 0; i < spell.projectile.Length; i++)
                    {
                        //yield return new WaitForSeconds(spell.delay[i]);
                        projectile = Instantiate(spell.projectile[i], spellSpawnTransforms[0].position,
                                                 transform.rotation, transform.parent);
                        projectile.LockOnTarget(enemy.GetProjectileTarget());
                    }
                }
            }
            else
            {
                bool isMultiple = spell.type == SpellType.Multiple;
                if (!isMultiple)
                {
                    transform.rotation = Quaternion.Lerp(transform.rotation,
                                                         Quaternion.LookRotation(currentTarget.transform.position - transform.position),
                                                         Time.deltaTime);
                }
                Enemy[] aliveEnemies = battleManager.GetEnemies().FindAll(enemy => !enemy.IsDead()).ToArray();
                for (int i = 0; i < spell.projectile.Length; i++)
                {
                    yield return(new WaitForSeconds(spell.delay[i]));

                    projectile = Instantiate(spell.projectile[i], spellSpawnTransforms[spell.spawnTransformID].position,
                                             transform.rotation, transform);
                    projectile.LockOnTarget(isMultiple ? aliveEnemies[Mathf.Min(aliveEnemies.Length - 1, i)].GetProjectileTarget() :
                                            currentTarget.GetProjectileTarget());
                }
            }
        }
        yield return(new WaitUntil(() => !animator.GetCurrentAnimatorClipInfo(0)[0].clip.name.Contains(currentMove.animationName)));

        if (melee != null)
        {
            walkingForward       = false;
            agent.updateRotation = false;
            agent.SetDestination(startPos);
            agent.stoppingDistance           = 0f;
            hitboxes[melee.hitboxID].enabled = false;
            yield return(new WaitUntil(() => !agent.pathPending));

            yield return(new WaitUntil(() => agent.pathStatus == NavMeshPathStatus.PathComplete && agent.remainingDistance == 0));

            agent.updateRotation = true;
            transform.rotation   = startRot;
        }

        yield return(new WaitUntil(() => projectile == null));

        attackChosen = false;
        bool doBlock = attributes.probabilityOfBlock +
                       (currentMove as PlayerMove).probOfBlock > UnityEngine.Random.Range(0, 1f);

        animator.SetBool("blocking", doBlock);

        hurtbox.enabled = true;
        yield return(base.Attacking());
    }
示例#3
0
 public void SetParameters(PlayerSpell spell, SpellTitles title, int attackNumber)
 {
     this.spell        = spell;
     this.title        = title;
     this.attackNumber = attackNumber;
 }
示例#4
0
        public void CastSpell(Monster opponent, string inputName)
        {
            int index = Spellbook.FindIndex(f => f.Name == inputName);

            if (index != -1 &&
                ManaPoints >= Spellbook[index].ManaCost &&
                PlayerClass == PlayerClassType.Mage)
            {
                switch (Spellbook[index].SpellCategory)
                {
                case SpellType.Fireball:
                    PlayerSpell.CastFireOffense(opponent, this, index);
                    return;

                case SpellType.Frostbolt:
                    PlayerSpell.CastFrostOffense(opponent, this, index);
                    return;

                case SpellType.Lightning:
                    PlayerSpell.CastArcaneOffense(opponent, this, index);
                    return;

                case SpellType.Heal:
                    PlayerSpell.CastHealing(this, index);
                    return;

                case SpellType.Rejuvenate:
                    PlayerSpell.CastHealing(this, index);
                    return;

                case SpellType.Diamondskin:
                    PlayerSpell.CastAugmentArmor(this, index);
                    return;

                case SpellType.Reflect:
                    PlayerSpell.CastReflectDamage(this, index);
                    return;

                case SpellType.TownPortal:
                    OutputHelper.Display.StoreUserOutput(
                        Settings.FormatAttackSuccessText(),
                        Settings.FormatDefaultBackground(),
                        "You cannot cast a portal during combat!");
                    return;

                case SpellType.ArcaneIntellect:
                    PlayerSpell.CastArcaneIntellect(this, index);
                    return;

                case SpellType.FrostNova:
                    PlayerSpell.CastFrostOffense(opponent, this, index);
                    return;

                default:
                    throw new ArgumentOutOfRangeException();
                }
            }
            if (index != -1)
            {
                throw new InvalidOperationException();
            }
            throw new IndexOutOfRangeException();
        }
示例#5
0
    void UseSpells()
    {
        //this section has a lot of repeated code
        //i can't think of a better way to do it right now, but ideally it would be fixed at some point

        if (Input.anyKeyDown)
        {
            string      inString = Input.inputString.Substring(0, 1); //make sure we grab the first input only
            PlayerSpell toUse    = null;
            bool        useSpell = false;

            if (inString.Length > 0)
            {
                switch (inString)
                {
                case "j":
                    if (JBound)
                    {
                        toUse    = JBound;
                        useSpell = true;
                        if (JBound.limitedUse)
                        {
                            JBound.usesLeft--;
                            if (JBound.usesLeft <= 0)
                            {
                                JBound = null;
                            }
                        }
                    }
                    break;

                case "i":
                    if (IBound)
                    {
                        toUse    = IBound;
                        useSpell = true;
                        if (IBound.limitedUse)
                        {
                            IBound.usesLeft--;
                            if (IBound.usesLeft <= 0)
                            {
                                IBound = null;
                            }
                        }
                    }
                    break;

                case "k":
                    if (KBound)
                    {
                        toUse    = KBound;
                        useSpell = true;
                        if (KBound.limitedUse)
                        {
                            KBound.usesLeft--;
                            if (KBound.usesLeft <= 0)
                            {
                                KBound = null;
                            }
                        }
                    }
                    break;

                case "l":
                    if (LBound)
                    {
                        toUse    = LBound;
                        useSpell = true;
                        if (LBound.limitedUse)
                        {
                            LBound.usesLeft--;
                            if (LBound.usesLeft <= 0)
                            {
                                LBound = null;
                            }
                        }
                    }
                    break;

                default:
                    break;
                }

                if (useSpell)
                {
                    PlayerSpell spell = Instantiate(toUse, transform.position + new Vector3(0, 1f, 0), Quaternion.identity);
                }
            }
        }
    }
示例#6
0
 public void AddSpell(Character pChar, PlayerSpell newspell)
 {
     pChar.SpellList.Add(newspell);
 }
示例#7
0
        public static void SpellInfo(Player player, string[] input)
        {
            StringBuilder inputName = new StringBuilder();

            for (int i = 1; i < input.Length; i++)
            {
                inputName.Append(input[i]);
                if (i != input.Length - 1)
                {
                    inputName.Append(" ");
                }
            }
            int index = player.Spellbook.FindIndex(f =>
                                                   f.Name == inputName.ToString() || f.Name == input[1] || f.Name.Contains(inputName.ToString()));
            TextInfo textInfo = new CultureInfo("en-US", false).TextInfo;

            if (index != -1 && player.PlayerClass == PlayerClassType.Mage)
            {
                OutputHelper.Display.StoreUserOutput(
                    Settings.FormatInfoText(),
                    Settings.FormatDefaultBackground(),
                    textInfo.ToTitleCase(player.Spellbook[index].Name));
                string rankString = $"Rank: {player.Spellbook[index].Rank}";
                OutputHelper.Display.StoreUserOutput(
                    Settings.FormatInfoText(),
                    Settings.FormatDefaultBackground(),
                    rankString);
                string manaCostString = $"Mana Cost: {player.Spellbook[index].ManaCost}";
                OutputHelper.Display.StoreUserOutput(
                    Settings.FormatInfoText(),
                    Settings.FormatDefaultBackground(),
                    manaCostString);
                switch (player.Spellbook[index].SpellCategory)
                {
                case SpellType.Fireball:
                    PlayerSpell.FireOffenseSpellInfo(player, index);
                    break;

                case SpellType.Frostbolt:
                    PlayerSpell.FrostOffenseSpellInfo(player, index);
                    break;

                case SpellType.Lightning:
                    PlayerSpell.ArcaneOffenseSpellInfo(player, index);
                    break;

                case SpellType.Heal:
                    PlayerSpell.HealingSpellInfo(player, index);
                    break;

                case SpellType.Rejuvenate:
                    PlayerSpell.HealingSpellInfo(player, index);
                    break;

                case SpellType.Diamondskin:
                    PlayerSpell.AugmentArmorSpellInfo(player, index);
                    break;

                case SpellType.TownPortal:
                    PlayerSpell.PortalSpellInfo();
                    break;

                case SpellType.Reflect:
                    PlayerSpell.ReflectDamageSpellInfo(player, index);
                    break;

                case SpellType.ArcaneIntellect:
                    PlayerSpell.ArcaneIntellectSpellInfo(player, index);
                    break;

                case SpellType.FrostNova:
                    PlayerSpell.FrostOffenseSpellInfo(player, index);
                    break;

                default:
                    throw new ArgumentOutOfRangeException();
                }
            }
            else if (index != -1 && player.PlayerClass != PlayerClassType.Mage)
            {
                OutputHelper.Display.StoreUserOutput(
                    Settings.FormatFailureOutputText(),
                    Settings.FormatDefaultBackground(),
                    "You're not a mage!");
            }
            else
            {
                OutputHelper.Display.StoreUserOutput(
                    Settings.FormatFailureOutputText(),
                    Settings.FormatDefaultBackground(),
                    "You don't have that spell.");
            }
        }
示例#8
0
 public void SetSpellToSpellUI(SpellTitles title, PlayerSpell spell)
 {
     editableSpell.ChangeSpell(title, spell);
     GameManager.UIOverlapsMouse = false;
     gameObject.SetActive(false);
 }