// 状态处理 public void Process(EntityParent theOwner, params Object[] args) { if (theOwner == null || theOwner.Transform == null) { return; } if (theOwner.IsDeath()) { return; } if (args.Length < 2) { LoggerHelper.Error("error skill id"); return; } int hitActionID = (int)(args[0]); uint attackID = (uint)(args[1]); EntityParent attacker = null; if (MogoWorld.Entities.ContainsKey(attackID)) { attacker = MogoWorld.Entities[attackID]; } if (attackID == MogoWorld.thePlayer.ID) { attacker = MogoWorld.thePlayer; } if (theOwner.motor != null) { theOwner.motor.enableStick = false; } //if (attacker == null) //{//没有受击者 // return; //} List <int> hitAction = SkillAction.dataMap[hitActionID].hitAction; if (hitAction == null || hitAction.Count == 0) { return; } int action = Utils.Choice <int>(hitAction); if (action == ActionConstants.HIT) { HitActionRule(theOwner, action, hitActionID); return; } if (!(theOwner is EntityPlayer)) { if (((theOwner is EntityMonster) && theOwner.GetIntAttr("notTurn") == 0) || theOwner is EntityDummy) { if (theOwner.motor == null) { return; } if (attacker != null && attacker.Transform != null) { theOwner.motor.SetTargetToLookAt(attacker.Transform.position); } } } else { if (theOwner.Transform == null) { return; } theOwner.preQuaternion = theOwner.Transform.localRotation; if (attacker != null && attacker.Transform != null) { theOwner.motor.SetTargetToLookAt(attacker.Transform.position); } } HitActionRule(theOwner, action, hitActionID); }
/// <summary> /// 在角色当前朝向的半径radius,扇形角度angle内,在对人物朝向进行最小角度的调整其中一个怪物。 /// 如果区域内无怪,则不调整 /// </summary> /// <param name="t"></param> /// <param name="radius"></param> /// <param name="angle"></param> /// <param name="layerMask"></param> static public void LookAtTargetInRange(this Transform t, float radius, float angle, LayerMask layerMask = LayerMask.Monster | LayerMask.Character | LayerMask.Trap) { Vector3 targetPos = Vector3.zero; float angleMax = Mathf.Infinity; bool isFindSome = false; //遍历entities foreach (KeyValuePair <uint, Mogo.Game.EntityParent> pair in MogoWorld.Entities) { EntityParent entity = pair.Value; if (entity.curHp <= 0) { continue; } if (entity.IsDeath()) { continue; } //if (entity is EntityPlayer) continue; if (entity.m_factionFlag == MogoWorld.thePlayer.m_factionFlag) { continue; } if (entity.Transform == null || t == null) { continue; } if ((1 << entity.Transform.gameObject.layer & (int)layerMask) == 0) { continue; } float entityRadius = ((float)entity.GetIntAttr("scaleRadius")) / 100f; if ((t.position - entity.Transform.position).magnitude > radius + entityRadius) { continue; } //得到切线与(目标物体到人物线)的夹角a float a = Mathf.Atan(entityRadius / (entity.Transform.position - t.position).magnitude); //得到目标点与人物正前方的夹角b float b = Vector3.Angle((entity.Transform.position - t.position), t.forward); //判断b - a 是否在 angle/2内 if ((b - a) > angle / 2) { continue; } //Vector3 tempDir = new Vector3(-t.forward.z, 0, t.forward.x).normalized; //Vector3 lineLeft = Vector3.Slerp(t.forward, tempDir, (angle / (2 * 90f))); //Vector3 lineRight = Vector3.Slerp(t.forward, -tempDir, (angle / (2 * 90f))); //if ((GetDisBetweenLineAndPoint(lineLeft, t.position) > entityRadius || GetDisBetweenLineAndPoint(lineRight, t.position) > entityRadius) // && Vector3.Angle((entity.Transform.position - t.position), t.forward) > (angle / 2f)) continue; //if (Vector3.Angle((entity.Transform.position - t.position), t.forward) > (angle / 2f)) continue; isFindSome = true; if ((b - a) < angleMax) { angleMax = b - a; targetPos = pair.Value.Transform.position; } } if (isFindSome) { t.LookAt(new Vector3(targetPos.x, t.transform.position.y, targetPos.z)); } }