示例#1
0
        protected override void OnMapDirectionChanged(MapDirection oldDirection, MapDirection newDirection)
        {
            base.OnMapDirectionChanged(oldDirection, newDirection);
            $"Direction changed: {oldDirection} -> {newDirection}".Dump();

            if (oldDirection != newDirection.Opposite)
                RotateParty(oldDirection, newDirection);
            else
            {
                var midle = oldDirection.NextClockWise;
                RotateParty(oldDirection, midle);
                RotateParty(midle, newDirection);
            }
        }
示例#2
0
        public MapDirection GetRotated(int count)
        {
            bool clockwise = count >= 0;

            if (!clockwise)
            {
                count *= -1;
            }

            MapDirection res = this;

            for (int i = 0; i < count; i++)
            {
                res = clockwise ? res.NextClockWise : res.NextCounterClockWise;
            }

            return(res);
        }
示例#3
0
 public Tile GetTile(MapDirection mapDirection)
 {
     if (mapDirection == MapDirection.East)
     {
         return(East);
     }
     else if (mapDirection == MapDirection.West)
     {
         return(West);
     }
     else if (mapDirection == MapDirection.North)
     {
         return(North);
     }
     else if (mapDirection == MapDirection.South)
     {
         return(South);
     }
     else
     {
         return(null);
     }
 }
示例#4
0
        private void RotateParty(MapDirection oldDirection, MapDirection newDirection)
        {
            var targetLocation = partyGoup.FirstOrDefault()?.Location?.Tile;

            if (targetLocation != null)
            {

                var counterClockWiseGridPoints = new[]
                {
                    Tuple.Create(new Point(0, 0), new Point(0, 1)),
                    Tuple.Create(new Point(0, 1), new Point(1, 1)),
                    Tuple.Create(new Point(1, 1), new Point(1, 0)),
                    Tuple.Create(new Point(1, 0), new Point(0, 0)),
                };

                Func<Point, Point> nextGridPoint = p =>
                {
                    if (oldDirection.NextCounterClockWise == newDirection)
                        return Array.Find(counterClockWiseGridPoints, t => t.Item1 == p).Item2;
                    else if (oldDirection.NextClockWise == newDirection)
                        return Array.Find(counterClockWiseGridPoints, t => t.Item2 == p).Item1;
                    else
                        throw new Exception();
                };

                foreach (var champoin in PartyGroup)
                    targetLocation.LayoutManager.FreeSpace(champoin, champoin.Location.Space);

                foreach (var champoin in PartyGroup)
                {
                    var newSpace = champoin.GroupLayout.AllSpaces.First(s => s.GridPosition == nextGridPoint(champoin.Location.Space.GridPosition));
                    champoin.Location = new FourthSpaceRouteElement(newSpace, targetLocation);
                    Debug.Assert(targetLocation.LayoutManager.TryGetSpace(champoin, champoin.Location.Space));
                }
            }
        }