Ejemplo n.º 1
0
        /*
         * 1自己   自己的宠物
         * 2其它玩家  其它玩家的宠物
         * 3怪物
         * 4墙体
         * 5: 事件类型碰撞体不参与技能 例如入口和出口的碰撞体? (忽略这种 假设所有都会碰撞)
         *
         *
         * 对于子弹的发射者来讲
         * 按照角色分成三种:
         * 1:友方
         * 2:敌方
         * 3:中立(墙体)
         */

        private void FixedUpdate()
        {
            if (isDie)
            {
                return;
            }
            Collider[] col = Physics.OverlapSphere(transform.position, missileData.Radius,
                                                   SkillDamageCaculate.GetDamageLayer());
            foreach (Collider c in col)
            {
                //和多个不同的敌人目标碰撞
                if (c != lastColobj)
                {
                    lastColobj = c;
                    var hitT = NetworkUtil.GetAttr(c.gameObject);
                    if (hitT != null)
                    {
                        if (hitT.gameObject != this.attacker)
                        {
                            HitSomething(c);
                            break;
                        }
                    }
                    else
                    {
                        HitSomething(c);
                        break;
                    }
                }
            }
        }
Ejemplo n.º 2
0
        //找到最近的敌人 不考虑朝向方向
        public static GameObject FindNearestEnemy(GameObject attacker)
        {
            LayerMask mask    = SkillDamageCaculate.GetDamageLayer();
            var       enemies = Physics.OverlapSphere(attacker.transform.position, attacker.GetComponent <NpcAttribute>().AttackRange, mask);
            float     minDist = 999999;

            GameObject enemy     = null;
            var        transform = attacker.transform;

            Log.Sys("EnemyCount: " + enemies.Length);
            foreach (var ene in enemies)
            {
                var npcAttr = ene.gameObject.GetComponent <NpcAttribute>();
                if (npcAttr == null)
                {
                    npcAttr = ene.gameObject.GetComponentInParent <NpcAttribute>();
                }
                Log.Sys("EnemyIs: " + npcAttr);
                if (npcAttr != null && !npcAttr.IsDead && IsEnemy(attacker, npcAttr.gameObject))
                {
                    var d = (ene.transform.position - transform.position).sqrMagnitude;
                    if (d < minDist)
                    {
                        minDist = d;
                        enemy   = ene.gameObject;
                    }
                }
            }

            return(enemy);
        }
Ejemplo n.º 3
0
        private void Update()
        {
            if (!runner || !runner.stateMachine || !runner.stateMachine.attacker || runner.stateMachine.isStop)
            {
                return;
            }

            var me = runner.stateMachine.attacker;

            Collider[] hitColliders;
            hitColliders = Physics.OverlapSphere(me.transform.position, radius,
                                                 SkillDamageCaculate.GetDamageLayer());

            for (int i = 0; i < hitColliders.Length; i++)
            {
                var enemy = NetworkUtil.GetAttr(hitColliders[i].gameObject);
                if (enemy != null && SkillLogic.IsEnemy(me, enemy.gameObject))
                {
                    if (!hurtEnemy.Contains(enemy.gameObject))
                    {
                        var dir = enemy.transform.position - me.transform.position;
                        dir.y = 0;
                        var cos = Vector3.Dot(dir.normalized, transform.forward);
                        Log.AI("DamageHit " + runner.stateMachine.name + " " + enemy.name + " cos " + cos + " a " + cosAngle);
                        if (cos > cosAngle)
                        {
                            DoDamage(enemy.gameObject);
                            hurtEnemy.Add(enemy.gameObject);
                        }
                    }
                }
            }
            Log.AI("Check Damage Shape " + runner.stateMachine.name);
        }
Ejemplo n.º 4
0
 private void AOEDamage()
 {
     Collider[] col = Physics.OverlapSphere(transform.position, missileData.AOERadius,
                                            SkillDamageCaculate.GetDamageLayer());
     foreach (Collider c in col)
     {
         DoDamage(c);
     }
 }
Ejemplo n.º 5
0
        void OnEvent(MyEvent evt)
        {
            Log.AI("FanTan OnHit " + evt.type);
            var rd       = Random.Range(0, 100);
            var critical = 1;

            if (rd < 25)
            {
                critical = 2;
            }
            SkillDamageCaculate.DoDamage(obj, 100 * critical, evt.attacker, false);
        }
Ejemplo n.º 6
0
 /// <summary>
 /// 显示门开启的效果
 /// </summary>
 /// <returns>The show door open effect.</returns>
 IEnumerator WaitShowDoorOpenEffect()
 {
     while (true)
     {
         var players = Physics.OverlapSphere(transform.position, 4, SkillDamageCaculate.GetDamageLayer());
         foreach (Collider p in players)
         {
             if (p.tag == GameTag.Player)
             {
                 StartCoroutine(ShowOpenEffect());
                 yield break;
             }
         }
         yield return(null);
     }
 }
Ejemplo n.º 7
0
 private bool CheckHit()
 {
     Collider[] col = Physics.OverlapSphere(head.transform.position, missileData.Radius,
                                            SkillDamageCaculate.GetDamageLayer());
     foreach (Collider c in col)
     {
         //和多个不同的敌人目标碰撞
         var hitT = NetworkUtil.GetAttr(c.gameObject);
         if (hitT != null)
         {
             if (hitT.gameObject != this.attacker)
             {
                 HitSomething(hitT);
                 return(true);
             }
         }
     }
     return(false);
 }
Ejemplo n.º 8
0
        /// <summary>
        /// 延迟等待
        /// 判定是否是一次性伤害技能 还是持续性伤害
        ///
        /// 开始判定伤害,技能没有结束
        /// 无伤害只移动对象
        ///
        ///
        /// </summary>
        void Update()
        {
            passTime += Time.deltaTime;
            if (passTime < delayTime)
            {
                return;
            }
            if (Once && damageYet)
            {
                return;
            }
            if (!runner || !runner.stateMachine || !runner.stateMachine.attacker)
            {
                return;
            }

            if (enable && !runner.stateMachine.isStop)
            {
                if (!NoHurt)
                {
                    //物理碰撞检测 玩家附近 或者 碰撞体附近的单位
                    Collider[] hitColliders;
                    if (SyncWithPlayer)
                    {
                        hitColliders = Physics.OverlapSphere(runner.stateMachine.attacker.transform.position, radius, SkillDamageCaculate.GetDamageLayer());
                    }
                    else
                    {
                        hitColliders = Physics.OverlapSphere(transform.position, radius, SkillDamageCaculate.GetDamageLayer());
                    }

                    for (int i = 0; i < hitColliders.Length; i++)
                    {
                        if (SkillLogic.IsEnemy(runner.stateMachine.attacker, hitColliders[i].gameObject))
                        {
                            if (!hurtEnemy.Contains(hitColliders[i].gameObject))
                            {
                                if (shape == Shape.Sphere)
                                {
                                    DoDamage(hitColliders[i].gameObject);
                                    hurtEnemy.Add(hitColliders[i].gameObject);
                                }
                                else if (shape == Shape.Angle)
                                {
                                    Log.AI("DamageHit " + runner.stateMachine.name + " " + hitColliders[i].name);
                                    var dir = hitColliders[i].gameObject.transform.position - transform.position;
                                    var cos = Vector3.Dot(dir.normalized, transform.forward);
                                    if (cos > cosAngle)
                                    {
                                        DoDamage(hitColliders[i].gameObject);
                                        hurtEnemy.Add(hitColliders[i].gameObject);
                                    }
                                }
                            }
                        }
                    }
                    Log.AI("Check Damage Shape " + runner.stateMachine.name);
                    damageYet = true;
                }

                ///DamageShape 开始移动玩家 同时也移动玩家
                if (runner != null && runner.Event.attachOwner)
                {
                    Log.Sys("Move Attack With DamageShape");
                    if (!enableYet)
                    {
                        StartCoroutine(MoveOwner());
                    }
                }
                enableYet = true;
            }
        }
Ejemplo n.º 9
0
 //计算技能伤害
 public void DoDamage(GameObject g)
 {
     SkillDamageCaculate.DoDamage(attacker, skillFullData, g);
 }
Ejemplo n.º 10
0
        //TODO: 子弹可以和四种对象碰撞:

        /*
         * 1自己   自己的宠物
         * 2其它玩家  其它玩家的宠物
         * 3怪物
         * 4墙体
         * 5: 事件类型碰撞体不参与技能 例如入口和出口的碰撞体? (忽略这种 假设所有都会碰撞)
         *
         *
         * 对于子弹的发射者来讲
         * 按照角色分成三种:
         * 1:友方
         * 2:敌方
         * 3:中立(墙体)
         */
        void FixedUpdate()
        {
            if (isDie)
            {
                return;
            }
            Collider[] col = Physics.OverlapSphere(transform.position, missileData.Radius, SkillDamageCaculate.GetDamageLayer());
            foreach (Collider c in col)
            {
                //和多个不同的敌人目标碰撞
                if (c != lastColobj)
                {
                    lastColobj = c;
                    HitSomething(c);
                    break;
                }
            }
        }
Ejemplo n.º 11
0
 //计算技能伤害
 public void DoDamage(GameObject g)
 {
     SkillDamageCaculate.DoDamage(attacker, skillFullData, g, isStaticShoot);
 }
Ejemplo n.º 12
0
        //炸弹所有人都攻击
        void DoDamage(Collider other)
        {
            var tarPos = other.transform.position + new Vector3(0, 1, 0);
            var mePos  = transform.position + new Vector3(0, 0.1f, 0);
            var dir    = tarPos - mePos;

            dir.Normalize();
            RaycastHit hitInfo;
            var        hit = Physics.Raycast(mePos, dir, out hitInfo, bombData.AOERadius, SkillDamageCaculate.GetBlockerLayer());

            Log.Sys("TestBlock: " + mePos + " dir " + dir + " tarpos " + tarPos + " radius " + bombData.AOERadius + " hit " + hit + " hitInfo " + hitInfo);

            //障碍物阻挡无法攻击目标
            if (hit)
            {
                var hitObj = hitInfo.collider.gameObject;
                Log.Sys("Block HitObjIs: " + hitObj + " other " + other.gameObject);
                if (hitObj != other.gameObject)
                {
                    Log.Sys("Bomb Block Hit: " + hitObj + " other " + other.gameObject);
                    return;
                }
            }

            if (!string.IsNullOrEmpty(skillData.HitSound))
            {
                BackgroundSound.Instance.PlayEffect(skillData.HitSound);
            }


            var attr = other.GetComponent <NpcAttribute>();

            if (attr == null)
            {
                attr = other.GetComponentInParent <NpcAttribute>();
            }

            if (runner != null && attr != null)
            {
                runner.DoDamage(attr.gameObject);
            }
        }
Ejemplo n.º 13
0
        /// <summary>
        /// 根据BeamTargetPos 激光瞄准位置
        /// 或者MarkPos 标记位置来选择攻击目标
        /// </summary>
        /// <returns>The explosive.</returns>
        IEnumerator WaitExplosive()
        {
            yield return(new WaitForSeconds(WaitTime));

            var tarPos = Vector3.zero;

            if (AOEHere)
            {
                tarPos = transform.position;
            }
            else if (runner.BeamTargetPos != Vector3.zero)
            {
                tarPos = runner.BeamTargetPos;
            }
            else if (runner.stateMachine.MarkPos != Vector3.zero)
            {
                tarPos = runner.stateMachine.MarkPos;
            }
            if (tarPos != Vector3.zero)
            {
                transform.position = tarPos;
                if (DieParticle != null)
                {
                    GameObject g = Instantiate(DieParticle) as GameObject;
                    NGUITools.AddMissingComponent <RemoveSelf> (g);
                    g.transform.parent   = ObjectManager.objectManager.transform;
                    g.transform.position = runner.BeamTargetPos + ParticlePos;
                }

                Collider[] col = Physics.OverlapSphere(transform.position, AOERadius, SkillDamageCaculate.GetDamageLayer());
                foreach (Collider c in col)
                {
                    DoDamage(c);
                }
            }
            else
            {
                Debug.LogError("BeamTargetPos Is NULL");
            }
        }