コード例 #1
0
 ///<summary>Returns a string listing the rovers coordinates and heading
 /// </summary>
 public string ReportCoordsAndHeading()
 {
     return(XCoord.ToString() + " " + YCoord.ToString() + " " + Enum.GetName(typeof(Heading), this.Heading));
 }
コード例 #2
0
ファイル: Character.cs プロジェクト: lucent-sea/After_Old
        public async Task Move(string[] ToXYZ)
        {
            dynamic request;
            var     toLocation = Storage.Current.Locations.Find($"{ToXYZ[0]},{ToXYZ[1]},{ToXYZ[2]}");

            if (toLocation == null)
            {
                toLocation = Location.CreateTempLocation(ToXYZ);
                var area = toLocation.ConvertToArea(true);
                request = new
                {
                    Category = "Events",
                    Type     = "AreaCreated",
                    Area     = area
                };
                foreach (var player in toLocation.GetNearbyPlayers())
                {
                    player.SendString(JSON.Encode(request));
                }
            }

            // TODO: Check if blocked.
            var soul            = ConvertToSoul();
            var currentLocation = GetCurrentLocation();

            if (currentLocation == null)
            {
                currentLocation = Location.CreateTempLocation(new string[] { XCoord.ToString(), YCoord.ToString(), ZCoord });
                var area = currentLocation.ConvertToArea(true);
                request = new
                {
                    Category = "Events",
                    Type     = "AreaCreated",
                    Area     = area
                };
                foreach (var player in currentLocation.GetNearbyPlayers())
                {
                    await player.SendString(JSON.Encode(request));
                }
            }
            MovementState = MovementStates.Moving;
            var distance      = currentLocation.GetDistanceFrom(toLocation);
            var travelTime    = distance * 1000;
            var nearbyPlayers = currentLocation.GetNearbyPlayers();

            foreach (var player in toLocation.GetNearbyPlayers())
            {
                if (!nearbyPlayers.Contains(player))
                {
                    nearbyPlayers.Add(player);
                }
            }
            await currentLocation.CharacterLeaves(this);

            FutureXYZ = toLocation.StorageID;
            request   = JSON.Encode(new
            {
                Category   = "Events",
                Type       = "PlayerMove",
                Soul       = soul,
                From       = currentLocation.StorageID,
                To         = toLocation.StorageID,
                TravelTime = travelTime
            });
            foreach (var player in nearbyPlayers)
            {
                await player.SendString(request);
            }
            await Task.Run(async() => {
                Thread.Sleep((int)(Math.Round(travelTime)));
                CurrentXYZ = toLocation.StorageID;
                FutureXYZ  = null;
                await toLocation.CharacterArrives(this);
                MovementState = MovementStates.Ready;
            });
        }