Exemplo n.º 1
0
        public bool HasEnoughMana()
        {
            float curMana = mana.GetAttributeValue();

            if (curMana < manaCost)
            {
                return(false);
            }
            return(true);
        }
Exemplo n.º 2
0
        private bool AttackInQueue()
        {
            isFromQueue = false;
            KeyValuePair <FollowerAttackName, int> attackAndCost;
            // Check player HP threshold over attack queue
            float hp   = playerHealth.GetPercentage();
            float mana = playerMana.GetAttributeValue();

            if (hp <= healThreshold)
            {
                FollowerAttackPool[] healSkills = new FollowerAttackPool[2]
                {
                    FollowerAttackPool.HealBig,
                    FollowerAttackPool.HealSmall
                };

                foreach (var heal in healSkills)
                {
                    attackAndCost = attackManager.GetAttackCost(heal);
                    if (!IsOnCooldown(attackAndCost.Key) && attackAndCost.Value <= mana)
                    {
                        currentAttack    = attackAndCost.Key;
                        resourceTypes    = new IAttribute[1];
                        resourceTypes[0] = playerHealth as IAttribute;
                        return(true);
                    }
                }
            }

            // Check player mana
            if (playerMana.GetPercentage() <= manaThreshold && attackManager.HasAttackInPool(FollowerAttackPool.ManaGain))
            {
                attackAndCost = attackManager.GetAttackCost(FollowerAttackPool.ManaGain);
                if (!IsOnCooldown(attackAndCost.Key))
                {
                    currentAttack    = attackAndCost.Key;
                    resourceTypes    = new IAttribute[2];
                    resourceTypes[0] = playerMana as IAttribute;
                    resourceTypes[1] = selfMana as IAttribute;
                    return(true);
                }
            }

            // Check for lower priority heal over time threshold
            if (hp < regenThreshold)
            {
                attackAndCost = attackManager.GetAttackCost(FollowerAttackPool.HealOverTime);
                if (!IsOnCooldown(attackAndCost.Key) && !IsAttackQueued(attackAndCost.Key))
                {
                    atkQueue.Enqueue(attackAndCost.Key);
                }
            }

            if (atkQueue.Count > 0)
            {
                currentAttack = atkQueue.Peek();
                if (!IsOnCooldown(currentAttack))
                {
                    isFromQueue = true;
                    return(true);
                }
                Debug.Log("Attack in queue is on cooldown? " + currentAttack);
            }

            return(false);
        }
Exemplo n.º 3
0
        private void DecideNextAction()
        {
            if (timeSinceLastAttack >= timeBetweenAttacks)
            {
                // actionModifier should probably affect this...
                float foodValue = fullness.DigestFood(digestSpeed);
                // TODO: figure out base mana recovery when stomach is empty
                float manaAmount = Mathf.Max(1, foodValue * manaConversion);
                selfMana.GainAttribute(manaAmount);
                timeSinceLastAttack = 0;
                string chatMessage = null;

                float fullPercent = fullness.GetPercentage();
                // Check for hunger and whether inventory has consumable
                if (fullPercent <= starveValue && consumableIndex.Count > 0)
                {
                    chatMessage = GetItemToEat();
                }
                else if (AttackInQueue())
                {
                    FollowerAttackStats attackStats = attackManager.GetAttackStats(currentAttack);

                    // Check if have mana to cover attack cost
                    if (attackStats.Cost < selfMana.GetAttributeValue())
                    {
                        attackSpeed    = 100 / fighter.GetStat(Stat.AttackSpeed);
                        timeToAct      = attackStats.CastTime * attackSpeed;
                        actionModifier = attackStats.ActionModifier;
                        selfMana.UseMana(attackStats.Cost);
                        timeSinceActionStart = 0;
                        isAttackActive       = true;
                        isEffectOnHit        = attackStats.ApplyEffect == ApplyEffectOn.OnHit;

                        Sprite sprite = followerAttackIconDB.GetSprite(currentAttack);
                        SpawnHitTimer(sprite);
                        CheckEffectActivation(false);

                        if (isFromQueue)
                        {
                            atkQueue.Dequeue();
                        }
                        if (attackStats.isRecastSkill)
                        {
                            float recastTime = attackStats.RecastTimer + timeToAct;
                            skillRecastRoutines[currentAttack] = StartCoroutine(SkillRecast(currentAttack, recastTime));
                        }
                        chatMessage = "Casting " + attackStats.Name;
                    }
                    else
                    {
                        // Message out of mana, extra check for hunger
                        chatMessage    = "I'm OOMing!";
                        actionModifier = 2f;
                        if (fullPercent <= hungerValue && consumableIndex.Count > 0)
                        {
                            chatMessage = GetItemToEat();
                        }
                    }
                }
                // check if under soft cap for hunger
                else if (fullPercent <= hungerValue && consumableIndex.Count > 0)
                {
                    chatMessage = GetItemToEat();
                }
                else
                {
                    chatMessage    = "Nothing to do?";
                    actionModifier = 2f;
                }

                combatLog.SendMessageToChat(chatMessage);
            }
        }