public bool IsInSkillRange(int skillId, uint targetId) { var spellData = SkillAction.dataMap[SkillData.dataMap[skillId].skillAction[0]]; // 目标类型 0 敌人, 1 自己 2 队友 3 友方 //int targetType = spellData.targetType; // 攻击范围类型。 0 扇形范围 1 圆形范围, 2, 单体。 3 直线范围 4 前方范围 int targetRangeType = spellData.targetRangeType; // 攻击范围参数。 针对不同类型,有不同意义。 浮点数列表 List <float> targetRangeParam = spellData.targetRangeParam; // 最大攻击人数 //int maxTargetCount = spellData.maxTargetCount; // 触发伤害特效帧数 //int damageTriggerFrame = spellData.damageTriggerFrame; List <List <uint> > entities = new List <List <uint> >(); TargetRangeType rangeType = (TargetRangeType)targetRangeType; switch (rangeType) { case TargetRangeType.CircleRange: if (targetRangeParam.Count >= 1) { float radius = targetRangeParam[0] * 0.01f; entities = MogoUtils.GetEntitiesInRange(theOwner.Transform, radius); } break; case TargetRangeType.SectorRange: if (targetRangeParam.Count >= 2) { float radius = targetRangeParam[0] * 0.01f; float angle = targetRangeParam[1]; entities = MogoUtils.GetEntitiesInSector(theOwner.Transform, radius, angle); } break; case TargetRangeType.SingeTarget: if (targetRangeParam.Count >= 1) { float radius = targetRangeParam[0] * 0.01f; float angle = 150; entities = MogoUtils.GetEntitiesInSector(theOwner.Transform, radius, angle); } break; case TargetRangeType.WorldRange: if (targetRangeParam.Count >= 4) { float x1 = targetRangeParam[0] * 0.01f; float y1 = targetRangeParam[1] * 0.01f; float x2 = targetRangeParam[2] * 0.01f; float y2 = targetRangeParam[3] * 0.01f; float minX = Math.Min(x1, x2); float maxX = Math.Max(x1, x2); float minY = Math.Min(y1, y2); float maxY = Math.Max(y1, y2); float radiusX = minX + (maxX - minX) * 0.5f; float radiusY = minY + (maxY - minY) * 0.5f; float radius = Vector2.Distance(new Vector2(x1, y1), new Vector2(x2, y2)) * 0.5f; entities = MogoUtils.GetEntitiesInRange(new Vector3(radiusX, 0, radiusY), radius); } break; case TargetRangeType.LineRange: default: if (targetRangeParam.Count >= 2) { float length = targetRangeParam[0] * 0.01f; float width = targetRangeParam[1] * 0.01f; entities = MogoUtils.GetEntitiesFrontLine(theOwner.Transform, length, theOwner.Transform.forward, width); } break; } if (entities.Count < 3) { return(false); } if (entities[0].Count > 0 && entities[0].Contains(targetId)) { return(true); } if (entities[1].Count > 0 && entities[1].Contains(targetId)) { return(true); } if (entities[2].Count > 0 && entities[2].Contains(targetId)) { return(true); } return(false); }
// 根据技能id, 获取到受攻击者列表。 // 返回值 是一个三元组。 分别是 dummy list, monster list, player list private List <List <uint> > GetHitEntities(int hitActionID, Matrix4x4 ltwm, Quaternion rotation, Vector3 forward, Vector3 position) { var spellData = SkillAction.dataMap[hitActionID]; // 目标类型 0 敌人, 1 自己 2 队友 3 友方 int targetType = spellData.targetType; // 攻击范围类型。 0 扇形范围 1 圆形范围, 2, 单体。 3 直线范围 4 前方范围 int targetRangeType = spellData.targetRangeType; // 攻击范围参数。 针对不同类型,有不同意义。 浮点数列表 List <float> targetRangeParam = spellData.targetRangeParam; float offsetX = spellData.hitXoffset; float offsetY = spellData.hitYoffset; float angleOffset = 180; // 最大攻击人数 //int maxTargetCount = spellData.maxTargetCount; // 触发伤害特效帧数 //int damageTriggerFrame = spellData.damageTriggerFrame; List <List <uint> > entities = new List <List <uint> >(); if (targetType == (int)TargetType.Myself) { List <uint> listDummy = new List <uint>(); List <uint> listMonster = new List <uint>(); List <uint> listPlayer = new List <uint>(); List <uint> listMercenary = new List <uint>(); listPlayer.Add(theOwner.ID); entities.Add(listDummy); entities.Add(listMonster); entities.Add(listPlayer); entities.Add(listMercenary); return(entities); } if (theOwner.Transform == null) { return(entities); } Matrix4x4 entityltwm = theOwner.Transform.localToWorldMatrix; Quaternion entityrotation = theOwner.Transform.rotation; Vector3 entityforward = theOwner.Transform.forward; Vector3 entityposition = theOwner.Transform.position; if (spellData.castPosType == 0) { entityltwm = ltwm; entityrotation = rotation; entityforward = forward; entityposition = position; } TargetRangeType rangeType = (TargetRangeType)targetRangeType; switch (rangeType) { case TargetRangeType.CircleRange: if (targetRangeParam.Count >= 1) { float radius = targetRangeParam[0] * 0.01f; if (spellData.castPosType == 2 && theOwner is EntityDummy) { EntityParent e = theOwner.GetTargetEntity(); if (e != null) { entities = MogoUtils.GetEntitiesInRange(e.Transform.position, radius, offsetX, offsetY, angleOffset); } } else { //entities = MogoUtils.GetEntitiesInRange(theOwner.Transform, radius, offsetX, offsetY, angleOffset); entities = MogoUtils.GetEntitiesInRange(entityltwm, entityrotation, entityforward, entityposition, radius, offsetX, offsetY, angleOffset); } //entities = Utils.GetEntities(theOwner.Transform, radius, 150f); } break; case TargetRangeType.SectorRange: if (targetRangeParam.Count >= 2) { float radius = targetRangeParam[0] * 0.01f; float angle = targetRangeParam[1]; //entities = MogoUtils.GetEntitiesInSector(theOwner.Transform, radius, angle, offsetX, offsetY, angleOffset); entities = MogoUtils.GetEntitiesInSector(entityltwm, entityrotation, entityforward, entityposition, radius, angle, offsetX, offsetY, angleOffset); //entities = Utils.GetEntities(theOwner.Transform, radius, angle); } break; case TargetRangeType.SingeTarget: if (targetRangeParam.Count >= 1) { float radius = targetRangeParam[0] * 0.01f; float angle = 150; //entities = MogoUtils.GetEntitiesInSector(theOwner.Transform, radius, angle, offsetX, offsetY, angleOffset); entities = MogoUtils.GetEntitiesInSector(entityltwm, entityrotation, entityforward, entityposition, radius, angle, offsetX, offsetY, angleOffset); //entities = Utils.GetEntities(theOwner.Transform, radius, angle); MogoUtils.SortByDistance(theOwner.Transform, entities[0]); MogoUtils.SortByDistance(theOwner.Transform, entities[1]); MogoUtils.SortByDistance(theOwner.Transform, entities[2]); if (entities.Count > 1) { for (int i = 1; i < entities.Count; i++) { entities.RemoveAt(i); } } } break; case TargetRangeType.WorldRange: if (targetRangeParam.Count >= 4) { float x1 = targetRangeParam[0] * 0.01f; float y1 = targetRangeParam[1] * 0.01f; float x2 = targetRangeParam[2] * 0.01f; float y2 = targetRangeParam[3] * 0.01f; float minX = Math.Min(x1, x2); float maxX = Math.Max(x1, x2); float minY = Math.Min(y1, y2); float maxY = Math.Max(y1, y2); float radiusX = minX + (maxX - minX) * 0.5f; float radiusY = minY + (maxY - minY) * 0.5f; float radius = Vector2.Distance(new Vector2(x1, y1), new Vector2(x2, y2)) * 0.5f; entities = MogoUtils.GetEntitiesInRange(new Vector3(radiusX, 0, radiusY), radius); } break; case TargetRangeType.LineRange: default: if (targetRangeParam.Count >= 2) { float length = targetRangeParam[0] * 0.01f; float width = targetRangeParam[1] * 0.01f; //entities = MogoUtils.GetEntitiesFrontLineNew(theOwner.Transform, length, theOwner.Transform.forward, width, offsetX, offsetY, angleOffset); entities = MogoUtils.GetEntitiesFrontLineNew(entityltwm, entityrotation, entityforward, entityposition, length, entityforward, width, offsetX, offsetY, angleOffset); //entities = Utils.GetEntities(theOwner.Transform, length, width); } break; } return(entities); }