Ejemplo n.º 1
0
        // -----------------------------------------------------------------------------------
        // ActivateRangedAttack
        // -----------------------------------------------------------------------------------
        protected virtual void ActivateRangedAttack()
        {
            var attack = (MonsterAttackRangedTemplate)attacks[currentAttack].template;

            //animator.SetTrigger("IsAttack");

            GameObject go = Instantiate(attack.projectile, bulletInstancePosition.transform.position, transform.rotation);

            go.GetComponent <Projectile>().owner = this;

            FSMType = FSMTypes.Idle;
        }
Ejemplo n.º 2
0
        // -----------------------------------------------------------------------------------
        // ActivateMeleeAttack
        // -----------------------------------------------------------------------------------
        public void ActivateMeleeAttack()
        {
            MonsterAttackMeleeTemplate attack = (MonsterAttackMeleeTemplate)attacks[currentAttack].template;
            RaycastHit hit;

            //animator.SetTrigger("IsAttack");

            if (Physics.Raycast(transform.position, transform.TransformDirection(Vector3.forward), out hit, attack.attackDistance + 0.5f))
            {
                IHitable hitable = hit.collider.gameObject.GetComponent(typeof(IHitable)) as IHitable;
                if (hitable != null)
                {
                    SoundController.Play(attack.attackSound, transform.position);
                    hitable.Hit(new HitInfo(attack.damage, hit.point, false, this));
                }
            }

            FSMType = FSMTypes.Idle;
        }
Ejemplo n.º 3
0
 // -----------------------------------------------------------------------------------
 // ActivateMovement
 // -----------------------------------------------------------------------------------
 protected void ActivateMovement()
 {
     moveController.Move((transform.forward - transform.up) * statistics.Speed * Time.deltaTime);
     FSMType = FSMTypes.Idle;
 }
Ejemplo n.º 4
0
        // -----------------------------------------------------------------------------------
        // UpdateBehaviour
        // -----------------------------------------------------------------------------------
        protected void UpdateBehaviour()
        {
            int iterations = 0;

            // ------------ Select Attack
            if (FSMType == FSMTypes.Idle && attacks.Count > 0 && Obj.GetPlayer.statistics.Health > 0)
            {
                while (FSMType == FSMTypes.Idle)
                {
                    currentAttack = Random.Range(0, attacks.Count);

                    if (seePlayer &&
                        UnityEngine.Random.value <= attacks[currentAttack].template.attackProbability &&
                        attacks[currentAttack].template.manaCost <= statistics.Mana &&
                        distanceToPlayer <= attacks[currentAttack].template.attackDistance &&
                        Time.time - attacks[currentAttack].currentCooldown > attacks[currentAttack].template.attackCooldown
                        )
                    {
                        FSMType = FSMTypes.Attack;
                    }

                    iterations++;
                    if (FSMType != FSMTypes.Attack && iterations > attacks.Count * 2)
                    {
                        FSMType       = FSMTypes.Move;
                        currentAttack = -1;
                    }
                }
            }

            // ---------- Activate Attack
            if (FSMType == FSMTypes.Attack)
            {
                // ------------ Pay Attack Costs
                attacks[currentAttack].currentCooldown = Time.time;
                statistics.Mana -= attacks[currentAttack].template.manaCost;

                // ------------ Activate Attack
                if (attacks[currentAttack].template is MonsterAttackMeleeTemplate)
                {
                    Invoke("ActivateMeleeAttack", attacks[currentAttack].template.attackDelayTime);
                }
                else if (attacks[currentAttack].template is MonsterAttackRangedTemplate)
                {
                    Invoke("ActivateRangedAttack", attacks[currentAttack].template.attackDelayTime);
                }

                /* Fhiz: Todo:
                 *      add special and area attacks here later
                 */

                // ---------- Activate Movement
            }
            else if (FSMType == FSMTypes.Move)
            {
                if (seePlayer &&
                    UnityEngine.Random.value <= moveProbability)
                {
                    Invoke("ActivateMovement", moveCooldown);
                }
                else
                {
                    FSMType = FSMTypes.Idle;
                }
            }
        }