Example #1
0
        private LiveMonster GetNearestEnemy(bool isLeft, Point mouse)
        {
            LiveMonster target = null;
            int         dis    = int.MaxValue;
            int         rate   = 0;

            foreach (var mon in BattleManager.Instance.MonsterQueue.Enumerator)
            {
                if (mon.IsGhost)
                {
                    continue;
                }

                if (isLeft != mon.Owner.IsLeft)
                {
                    var tpDis = MathTool.GetDistance(mon.Position, mouse);
                    if (tpDis / BattleManager.Instance.MemMap.CardSize * 10 > mon.RealRange &&
                        (isLeft && mon.Position.X < mouse.X || !isLeft && mon.Position.X > mouse.X))    //不管身后的敌人
                    {
                        continue;
                    }

                    var targetRate = GetMonsterRate(mon);
                    if (tpDis < dis || tpDis == dis && targetRate > rate)
                    {
                        dis    = tpDis;
                        target = mon;
                        rate   = targetRate;
                    }
                }
            }
            return(target);
        }
Example #2
0
        private void WorldMapViewForm_MouseMove(object sender, MouseEventArgs e)
        {
            int truex = e.X - 15;
            int truey = e.Y - 35;

            string newSel = "";

            foreach (var mapIconConfig in ConfigData.SceneDict.Values)
            {
                if (mapIconConfig.Icon == "")
                {
                    continue;
                }

                var iconSize = iconSizeDict[mapIconConfig.Id];
                if (truex > mapIconConfig.IconX - baseX && truey > mapIconConfig.IconY - baseY && truex < mapIconConfig.IconX - baseX + iconSize.Width && truey < mapIconConfig.IconY - baseY + iconSize.Height)
                {
                    newSel = mapIconConfig.Icon;
                }
            }
            if (newSel != selectName)
            {
                selectName = newSel;
                Invalidate();
            }

            if (mouseHold)
            {
                if (MathTool.GetDistance(e.Location, dragStartPos) > 3)
                {
                    baseX       -= e.Location.X - dragStartPos.X;
                    baseY       -= e.Location.Y - dragStartPos.Y;
                    baseX        = MathTool.Clamp(baseX, 0, worldMap.Width - 750);
                    baseY        = MathTool.Clamp(baseY, 0, worldMap.Height - 500);
                    dragStartPos = e.Location;
                    Invalidate();
                }
                dragStartPos = e.Location;
            }
            else
            {
                dragStartPos = e.Location;
            }
        }
Example #3
0
        protected FlyCheckType FlyProc(Point targetPosition, ref NLPointF position, ref int angle)
        {
            if (MathTool.GetDistance(targetPosition, position.ToPoint()) < 10)//todo 10是一个估算值
            {
                return(FlyCheckType.EndPoint);
            }

            var posDiff = new NLPointF(targetPosition.X - position.X, targetPosition.Y - position.Y);

            posDiff  = posDiff.Normalize() * (float)config.Speed;
            position = position + posDiff;
            var angleD = Math.Atan(-posDiff.Y / posDiff.X) / Math.PI * 180;

            angle = posDiff.X >= 0 ? (int)angleD : (int)angleD + 180;

            if (MathTool.GetDistance(targetPosition, position.ToPoint()) < 10)//todo 10是一个估算值
            {
                return(FlyCheckType.EndPoint);
            }

            return(isLocked?FlyCheckType.Miss:FlyCheckType.ToCheck);
        }
Example #4
0
        private void BattleForm_MouseMove(object sender, MouseEventArgs e)
        {
            if (mouseHold)
            {
                if (MathTool.GetDistance(e.Location, dragStartPos) > 3)
                {
                    baseX       -= e.Location.X - dragStartPos.X;
                    baseY       -= e.Location.Y - dragStartPos.Y;
                    baseX        = MathTool.Clamp(baseX, 0, tileManager.MapPixelWidth - doubleBuffedPanel1.Width);
                    baseY        = MathTool.Clamp(baseY, 0, tileManager.MapPixelHeight - doubleBuffedPanel1.Height);
                    dragStartPos = e.Location;
                    refreshAll.Fire();
                }
            }
            else
            {
                dragStartPos = e.Location;

                var newTarget = battleManager.GetRegionUnitId(baseX + e.Location.X, baseY + e.Location.Y);
                if (newTarget != mouseOnId)
                {
                    mouseOnId = newTarget;
                    refreshAll.Fire();
                }

                var newCellPos = new Point((dragStartPos.X + baseX) / TileManager.CellSize, (dragStartPos.Y + baseY) / TileManager.CellSize);
                if (newCellPos.X != selectCellPos.X || newCellPos.Y != selectCellPos.Y)
                {
                    selectCellPos = newCellPos;
                    refreshAll.Fire();
                }

                if (battleMenu.OnMove(e.X, e.Y))
                {
                    refreshAll.Fire();
                }
            }
        }
Example #5
0
        private bool CanAttack(LiveMonster target)
        {
            var dis = MathTool.GetDistance(target.Position, monster.Position);

            return(dis <= monster.RealRange * BattleManager.Instance.MemMap.CardSize / 10);//射程也是十倍的
        }
        public static bool IsPointInRegionType(RegionTypes type, int mouseX, int mouseY, Point pos, int range, bool forleft)
        {
            if (type == RegionTypes.None)
            {
                return(false);
            }

            int         size       = BattleManager.Instance.MemMap.CardSize;
            int         targetX    = pos.X + size / 2;
            int         targetY    = pos.Y + size / 2;
            MemMapPoint mousePoint = BattleManager.Instance.MemMap.GetMouseCell(mouseX, mouseY);

            if (type == RegionTypes.Circle)
            {
                if (MathTool.GetDistance(mousePoint.X + size / 2, mousePoint.Y + size / 2, targetX, targetY) > range * size / 10)
                {
                    return(false);
                }
            }
            else if (type == RegionTypes.Cross)
            {
                if (!((mousePoint.X == pos.X && Math.Abs(mousePoint.Y - pos.Y) <= range * size / 10) || (mousePoint.Y == pos.Y && Math.Abs(mousePoint.X - pos.X) <= range * size / 10)))
                {
                    return(false);
                }
            }
            else if (type == RegionTypes.Grid)
            {
                if (mousePoint.Y != pos.Y || mousePoint.X != pos.X)
                {
                    return(false);
                }
            }
            else if (type == RegionTypes.Row)
            {
                if (mousePoint.Y != pos.Y || Math.Abs(mousePoint.X - pos.X) > range * size / 10)
                {
                    return(false);
                }
            }
            else if (type == RegionTypes.RowForward)
            {
                if (mousePoint.Y != pos.Y)
                {
                    return(false);
                }
                if (forleft)
                {
                    if (pos.X - mousePoint.X > range * size / 10 || pos.X <= mousePoint.X)
                    {
                        return(false);
                    }
                }
                else
                {
                    if (mousePoint.X - pos.X > range * size / 10 || pos.X >= mousePoint.X)
                    {
                        return(false);
                    }
                }
            }
            else if (type == RegionTypes.Column)
            {
                if (mousePoint.X != pos.X || Math.Abs(mousePoint.Y - pos.Y) > range * size / 10)
                {
                    return(false);
                }
            }
            else if (type == RegionTypes.MultiColumn)
            {
                if (Math.Abs(mousePoint.X - pos.X) > range * size / 10)
                {
                    return(false);
                }
            }
            return(true);
        }