コード例 #1
0
        void Start()
        {
            dialogueCamera.SetActive(false);

            dialogueOwnerAI = dialogueOwner.GetComponent <AI_Core_V3>();
        }
コード例 #2
0
        void HitTarget()
        {
            AI_Core_V3 targetAi = hitbox.target.GetComponent <AI_Core_V3>();

            // If I am player, I don't want to hit npcs or player friends
            if (weaponOwner.tag == "Player" && targetAi.alliance != ALLIANCE.ENEMY)
            {
                return;
            }

            // If target is not Player
            if (targetAi != null)
            {
                targetAi.SetTarget(weaponOwner);

                // Decide here if we take the damage
                float chance = UnityEngine.Random.Range(0, 1f);

                if (chance >= targetAi.minimumChanceToDefend)
                {
                    // Get parry sfx from our health owner
                    AudioClip parryClip = targetAi.GetComponent <WeaponManager>().weaponSlots[0].currentWeapon.parryHitSFX;

                    if (parryClip)
                    {
                        audioSource.PlayOneShot(parryClip);
                    }

                    targetAi.SetState(AGENT_STATE.DEFEND);
                    return;
                }

                if (chance >= targetAi.minimumChanceToDodge)
                {
                    // Get parry sfx from our health owner
                    AudioClip dodgeClip = targetAi.GetComponent <Battler>().dodgeClip;

                    if (dodgeClip)
                    {
                        audioSource.PlayOneShot(dodgeClip);
                    }

                    targetAi.SetState(AGENT_STATE.DODGE);
                    return;
                }
            }


            // Calculate damage (mix of weapon and characterStats)
            float damage = currentWeapon.weaponDamage;

            damage += weaponOwner.GetComponent <BaseStats>().GetAttack();

            Debug.Log("Character current attack power: " + weaponOwner.GetComponent <BaseStats>().GetAttack());
            Debug.Log("Damage applied: " + damage);

            // Apply damage to hitbox current target
            hitbox.target.GetComponent <Health>().TakeDamage(damage, weaponOwner);

            // Play SFX
            if (hitbox.target.GetComponent <Battler>().IsDefending())
            {
                // Get target equipped weapon to know what the impact sound should sound like
                audioSource.PlayOneShot(hitbox.target.GetComponent <WeaponManager>().weaponSlots[0].currentWeapon.parryHitSFX);
                audioSource.PlayOneShot(currentWeapon.hitSFX);

                return;
            }

            audioSource.PlayOneShot(currentWeapon.hitSFX);
            // Get center position of target based on their capsule collider
            Vector3 targetCenter = hitbox.target.GetComponent <CapsuleCollider>().bounds.center;

            // Add FX
            Instantiate(currentWeapon.particlePrefab, targetCenter, Quaternion.identity);
        }
コード例 #3
0
        public void TakeDamage(float damageAmount, GameObject damageOwner)
        {
            this.damageOwner = damageOwner;

            if (IsDead())
            {
                return;
            }

            // Get base stats for defense
            defenseBuff = (int)GetComponent <BaseStats>().GetDefense();

            CharacterEquipmentSlot charEquipmentSlots = GetComponent <CharacterEquipmentSlot>();

            int armorRate = 0;

            if (charEquipmentSlots != null)
            {
                armorRate = (int)charEquipmentSlots.GetArmorBonus();
            }
            defenseBuff += (int)armorRate; // Influenced by char stats as well

            // If we are defending, consult the equipped weapon or shield to check how much damage it should absorb using its defenseRate property
            if (GetComponent <Battler>().IsDefending())
            {
                // Assume we don't have a shield equipped, use weapon
                defenseBuff += (int)GetComponent <WeaponManager>().weaponSlots[0].currentWeapon.defenseRate;
            }

            // Finally, update the damage we will receive
            float damage = Mathf.Clamp(damageAmount - defenseBuff, 0, maxHealthPoints);

            currentHealthPoints = Mathf.Max(currentHealthPoints - damage, 0);

            UpdateHealthSlider();

            // Now evaluate result
            if (currentHealthPoints > 0f)
            {
                AI_Core_V3 ai = GetComponent <AI_Core_V3>();

                // Non-player case
                if (ai != null)
                {
                    ai.SetState(AGENT_STATE.TAKING_DAMAGE);
                }
                else
                {
                    GetComponent <Battler>().TakeDamage();
                }
            }
            else
            {
                // Award experience to Playero nly
                if (damageOwner.gameObject.tag == "Player")
                {
                    // Reward target with experience points
                    damageOwner.GetComponent <BaseStats>().IncreaseExperience(
                        GetComponent <Battler>().GetRewardExperience()
                        );
                }

                Die();

                OnDieEvent.Invoke();

                // Remove strafe from player
                PlayerController playerController = damageOwner.GetComponent <PlayerController>();
                if (playerController != null)
                {
                    playerController.Strafe(false);
                }
            }
        }