Esempio n. 1
0
        /// <summary>
        ///     被攻击
        /// </summary>
        /// <param name="attacker"></param>
        public override void BeAttacked(IMilitaryUnit attacker)
        {
            var momentum = attacker.GetUnit().unitRigidbody.velocity.magnitude *
                           attacker.GetUnit().unitRigidbody.mass;
            var damage = momentum - defence > 0 ? momentum - defence : 1;

            // Debug.Log("Damage:" + damage);
            _attacker = attacker;

            HP -= (int)damage;
            BeAttackedEventHandler?.Invoke(attacker);
        }
Esempio n. 2
0
        /// <summary>
        ///     被攻击
        /// </summary>
        /// <param name="attacker"></param>
        /// <exception cref="Exception"></exception>
        public virtual void BeAttacked(IMilitaryUnit attacker)
        {
            if (Death)
            {
                throw new Exception("WAS DEAD");
            }
            var damage = attacker.AttackValue - defence > 0 ? attacker.AttackValue - defence : 1;

            HP       -= damage;
            _attacker = attacker;
            BeAttackedEventHandler?.Invoke(attacker);
        }
        public override void Start()
        {
            BeAttackedEventHandler.AddListener(AttackedReact);
            if (!isUnmovable)
            {
                // TODO StartEventHandler += () => navMeshAgent.stoppingDistance = attackRange * 0.8f;

                unitRigidbody.velocity = OriginalVelocity;
            }
            InitTarget     = GetEnemySide();
            _maxShootSpeed = Mathf.Sqrt(attackRange * Bullet.Gravity / Mathf.Sin(45f * 2 * Mathf.Deg2Rad));
            _attackTrigger = transform.Find("FindEnemyRange").GetComponent <FindEnemyTrigger>();
            pathFinder.endReachedDistance = this.attackRange * .8f;

            FindEnemy();

            base.Start();
        }
Esempio n. 4
0
        protected override void Awake()
        {
            _maxHp        = this.HP;
            unitRigidbody = GetComponent <Rigidbody>();
            UnitDeathEventHandler.AddListener((p, m) => { p.ChangeResource(GameResourceType.Gold, deathReward); });
            BeAttackedEventHandler.AddListener(mUnit =>
            {
                var momentum = mUnit.GetUnit().unitRigidbody.velocity.magnitude *
                               mUnit.GetUnit().unitRigidbody.mass;
                var damage = momentum - defence > 0 ? momentum - defence : 1;

                var mainModule          = attackedEffect.GetComponent <ParticleSystem>().main;
                mainModule.maxParticles = (int)Mathf.Lerp(0f, 1000f, damage / this._maxHp);
                var effect = Instantiate(attackedEffect, transform.position,
                                         Quaternion.Euler(0, 0, 0), transform.parent);
                Destroy(effect, 5f);
            });
            UnitDeathEventHandler.AddListener((player, mUnit) =>
            {
                Instantiate(deathEffect, transform.position,
                            Quaternion.Euler(0, 0, 0), transform.parent);
            });
        }