void OnEvent(MyEvent evt) { Log.AI("FanTan OnHit " + evt.type); var target = evt.attacker; var rd = Random.Range(0, 100); var critical = 1; if (rd < 25) { critical = 2; } SkillDamageCaculate.DoDamage(obj, 100 * critical, evt.attacker); }
/// <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); } }
//找到最近的敌人 不考虑朝向方向 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; foreach (var ene in enemies) { if (IsEnemy(attacker, ene.gameObject)) { var d = (ene.transform.position - transform.position).sqrMagnitude; if (d < minDist) { minDist = d; enemy = ene.gameObject; } } } return(enemy); }
//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; OnTriggerEnter(c); break; } } }
void AOEDamage() { Collider[] col = Physics.OverlapSphere(transform.position, missileData.AOERadius, SkillDamageCaculate.GetDamageLayer()); foreach (Collider c in col) { DoDamage(c); } }
/// <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; } }
/// <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"); } }
//计算技能伤害 public void DoDamage(GameObject g) { SkillDamageCaculate.DoDamage(attacker, skillFullData, g); }