예제 #1
0
파일: Bullet.cs 프로젝트: itcodes/unityRpg
 /// <summary>
 ///子弹伤害计算也交给skillLayoutRunner执行
 /// </summary>
 /// <param name="other">Other.</param>
 void DoDamage(Collider other)
 {
     if (SkillLogic.IsEnemy(attacker, other.gameObject) && !missileData.DontHurtObject)
     {
         if (!string.IsNullOrEmpty(skillData.HitSound))
         {
             BackgroundSound.Instance.PlayEffect(skillData.HitSound);
         }
         if (runner != null)
         {
             runner.DoDamage(other.gameObject);
         }
     }
 }
예제 #2
0
 /// <summary>
 ///子弹伤害计算也交给skillLayoutRunner执行
 /// </summary>
 /// <param name="other">Other.</param>
 void DoDamage(Collider other)
 {
     if (SkillLogic.IsEnemy(runner.stateMachine.attacker, other.gameObject))
     {
         var skillData = runner.stateMachine.skillFullData.skillData;
         if (!string.IsNullOrEmpty(skillData.HitSound))
         {
             BackgroundSound.Instance.PlayEffect(skillData.HitSound);
         }
         if (runner != null)
         {
             runner.DoDamage(other.gameObject);
         }
     }
 }
예제 #3
0
파일: Bullet.cs 프로젝트: itcodes/unityRpg
        /*
         *客户端表现粒子和服务器计算伤害的数值分离开来
         */
        void OnTriggerEnter(Collider other)
        {
            Log.AI("Bullet collider enemy " + other.name + " " + other.tag);
            if (SkillLogic.IsEnemy(attacker, other.gameObject))
            {
                //攻击多个目标只释放一次 DieParticle
                CreateHitParticle();

                //计算随机的弹射 反射方向
                if (LeftRicochets > 0)
                {
                    Log.AI("Generate new bullet " + LeftRicochets);
                    LeftRicochets--;
                    initPos = transform.position;
                    //子弹应该冲入怪物群中
                    transform.localRotation = Quaternion.Euler(new Vector3(0, transform.localRotation.eulerAngles.y + Random.Range(-missileData.RandomAngle, missileData.RandomAngle), 0));
                    //sleepTime = IgnoreTime;
                }
                else
                {
                    //地震是穿透的因此只会等待粒子自然死亡
                    //非穿透性子弹
                    if (!missileData.piercing)
                    {
                        GameObject.Destroy(gameObject);
                    }
                }

                //伤害多个目标
                if (missileData.IsAOE)
                {
                    AOEDamage();
                }
                else                   //只伤害一个目标
                                       //TODO:通过SkillDamageCaculate计算伤害 Level Information
                {
                    DoDamage(other);
                }

                //非穿透性子弹
                if (!missileData.piercing)
                {
                    var evt = new MyEvent(MyEvent.EventType.EventMissileDie);
                    evt.missile = transform;
                    MyEventSystem.myEventSystem.PushLocalEvent(attacker.GetComponent <KBEngine.KBNetworkView> ().GetLocalId(), evt);
                }
                //TODO::撞击其它玩家如何处理
            }
            else if (other.tag == attacker.tag)
            {
            }
            else                //装到墙体 或者建筑物 等对象身上 则 反射  Not used
            {
                Log.AI("Bullet colldier with Wall " + gameObject.name);
                if (missileData.HitParticle != null)
                {
                    GameObject g = Instantiate(missileData.HitParticle) as GameObject;
                    NGUITools.AddMissingComponent <RemoveSelf> (g);
                    g.transform.position = transform.position;
                    g.transform.parent   = ObjectManager.objectManager.transform;
                }

                if (LeftRicochets > 0)
                {
                    Log.AI("Generate new bullet " + LeftRicochets);
                    LeftRicochets--;
                    initPos = transform.position;
                    transform.localRotation = Quaternion.Euler(new Vector3(0, transform.localRotation.eulerAngles.y + 180 + Random.Range(-missileData.RandomAngle, missileData.RandomAngle), 0));
                    //sleepTime = IgnoreTime;
                }
                else
                {
                    if (!missileData.piercing)
                    {
                        GameObject.Destroy(gameObject);
                    }
                }
                if (!missileData.piercing)
                {
                    var evt = new MyEvent(MyEvent.EventType.EventMissileDie);
                    evt.missile = transform;
                    MyEventSystem.myEventSystem.PushLocalEvent(attacker.GetComponent <KBEngine.KBNetworkView> ().GetLocalId(), evt);
                }
            }
        }
예제 #4
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;
            }
        }