| | |
| | | using System.Threading.Tasks; |
| | | using RichCreator.Utility.Skills; |
| | | using RichCreator.Utility.Maps; |
| | | using RichCreator.Utility.Utilitys; |
| | | |
| | | namespace RichCreator.Utilitys |
| | | { |
| | |
| | | /// <param name="direction"></param> |
| | | /// <param name="needMove"></param> |
| | | /// <returns></returns> |
| | | public static ZTSize GetMoveDistance(ZTRectangle gameRect,ZTPoint rolePosition, ZTPoint[] monsterPositions, SkillInfo skill,out HIDCode direction, out bool needMove) |
| | | public static ZTPoint GetAttackPoint(ZTRectangle gameRect,ZTPoint rolePosition, ZTPoint[] monsterPositions, SkillInfo skill,out HIDCode direction, out bool needMove) |
| | | { |
| | | needMove = false; |
| | | |
| | | ZTSize moveDistance = ZTSize.Empty; |
| | | |
| | | if (monsterPositions.Length <= 1||skill.MovePriority==MovePriority.Nearly) |
| | | { |
| | | moveDistance = GetAttackRectangleByNear(monsterPositions, rolePosition, skill, out direction, out needMove); |
| | | return GetAttackPointByNear(monsterPositions, rolePosition, skill, out direction, out needMove); |
| | | } |
| | | else |
| | | { |
| | | moveDistance = GetAttackRectangleByQuantity(gameRect,monsterPositions, rolePosition, skill, out direction, out needMove); |
| | | return GetAttackPointByQuantity(gameRect,monsterPositions, rolePosition, skill, out direction, out needMove); |
| | | } |
| | | return moveDistance; |
| | | |
| | | } |
| | | |
| | | |
| | |
| | | /// 得到最近的攻击目标距离 |
| | | /// </summary> |
| | | /// <returns></returns> |
| | | private static ZTSize GetAttackRectangleByNear(ZTPoint[] monsterPositions, ZTPoint rolePosition, SkillInfo skill,out HIDCode direction, out bool needMove) |
| | | private static ZTPoint GetAttackPointByNear(ZTPoint[] monsterPositions, ZTPoint rolePosition, SkillInfo skill,out HIDCode direction, out bool needMove) |
| | | { |
| | | needMove = true; |
| | | direction = HIDCode.RightArrow; |
| | | ZTRectangle attackRect = new ZTRectangle(rolePosition.X - skill.Range.Width, rolePosition.Y - skill.Range.Height / 2, rolePosition.X + skill.Range.Width, rolePosition.Y + skill.Range.Height / 2);//攻击范围 |
| | | ZTRectangle attackRange = new ZTRectangle(rolePosition.X - skill.Range.Width, rolePosition.Y - skill.Range.Height / 2, rolePosition.X + skill.Range.Width, rolePosition.Y + skill.Range.Height / 2);//攻击范围 |
| | | //switch (skill.ReleaseAnchor) |
| | | //{ |
| | | // case SkillInfo.SkillAnchor.Side: |
| | |
| | | |
| | | if (index == 0) |
| | | { |
| | | nearDistance = Utils.GetDistance(monsterPositions[index], rolePosition); |
| | | nearDistance = GeoHelper.GetDistance(monsterPositions[index], rolePosition); |
| | | nearMonsterPosition = monsterPositions[index]; |
| | | } |
| | | //天然就在攻击范围内 |
| | | if (Utils.IsInRect(monsterPositions[index], attackRect)) |
| | | if (GeoHelper.IsInRect(monsterPositions[index], attackRange)) |
| | | { |
| | | needMove = false; |
| | | break; |
| | |
| | | } |
| | | |
| | | //计算远近 |
| | | double distance = Utils.GetDistance(monsterPositions[index], rolePosition); |
| | | double distance = GeoHelper.GetDistance(monsterPositions[index], rolePosition); |
| | | if (distance < nearDistance) |
| | | { |
| | | nearDistance = distance; |
| | |
| | | |
| | | } |
| | | |
| | | return moveDistance; |
| | | return new ZTPoint(rolePosition.X+moveDistance.Width,rolePosition.Y+moveDistance.Height); |
| | | } |
| | | |
| | | |
| | |
| | | /// <param name="monsterPositions"></param> |
| | | /// <param name="yRange"></param> |
| | | /// <returns></returns> |
| | | private static ZTSize GetAttackRectangleByQuantity(ZTRectangle gameRect,ZTPoint[] monsterPositions, ZTPoint rolePosition, SkillInfo skill,out HIDCode direction, out bool needMove) |
| | | private static ZTPoint GetAttackPointByQuantity(ZTRectangle gameRect,ZTPoint[] monsterPositions, ZTPoint rolePosition, SkillInfo skill,out HIDCode direction, out bool needMove) |
| | | { |
| | | needMove = true; |
| | | direction = HIDCode.RightArrow; |
| | |
| | | Int32 top = 0, right = 0,bottom = 0,left = 0; |
| | | for (int i = 0; i < monsterPositions.Length; i++) |
| | | { |
| | | if (Utils.IsInRect(monsterPositions[i], monsterRect)) |
| | | if (GeoHelper.IsInRect(monsterPositions[i], monsterRect)) |
| | | { |
| | | ZTPoint monsterPoint = monsterPositions[i]; |
| | | if (i == 0) |
| | |
| | | //两边发技能 |
| | | ZTPoint leftAttackPosition = new ZTPoint(Math.Max(gameRect.Start.X,left+skill.AnchorOffset.Width),Math.Max(top, bottom + skill.AnchorOffset.Height)); |
| | | ZTPoint rightAttackPosition = new ZTPoint(Math.Min(gameRect.End.X,right+skill.AnchorOffset.Width), Math.Max(top,bottom + skill.AnchorOffset.Height)); |
| | | double toLeft = Utils.GetDistance(leftAttackPosition, rolePosition); |
| | | double toRight = Utils.GetDistance(rightAttackPosition, rolePosition); |
| | | double toLeft = GeoHelper.GetDistance(leftAttackPosition, rolePosition); |
| | | double toRight = GeoHelper.GetDistance(rightAttackPosition, rolePosition); |
| | | |
| | | //计算可以发技能的区域 |
| | | if (toLeft <= toRight) |
| | |
| | | } |
| | | } |
| | | |
| | | if (Utils.IsInRect(rolePosition, releaseSkillRect)) |
| | | if (GeoHelper.IsInRect(rolePosition, releaseSkillRect)) |
| | | { |
| | | needMove = false; |
| | | } |
| | | |
| | | |
| | | |
| | | //转换为移动距离 |
| | | return new ZTSize ( releaseSkillPosition.X-rolePosition.X,releaseSkillPosition.Y-rolePosition.Y); |
| | | return releaseSkillPosition; |
| | | ////转换为移动距离 |
| | | //return new ZTSize ( releaseSkillPosition.X-rolePosition.X,releaseSkillPosition.Y-rolePosition.Y); |
| | | } |
| | | |
| | | |
| | |
| | | int count = 0; |
| | | for (int i = 0; i < monsterPositions.Length; i++) |
| | | { |
| | | if (Utils.IsInRect(monsterPositions[i], rect)) |
| | | if (GeoHelper.IsInRect(monsterPositions[i], rect)) |
| | | { |
| | | count++; |
| | | } |