Пример #1
0
        private void AddTeleporterWaypoint(bool pinned)
        {
            var found      = false;
            var teleporter = Api.World.GetNearestBlockEntity <BlockEntityTeleporter>(Api.World.Player.Entity.Pos.AsBlockPos,
                                                                                     5f, 1f, _ =>
            {
                found = true;
                return(true);
            });

            if (!found)
            {
                Api.ShowChatMessage(LangEx.Error("TeleporterNotFound"));
            }
            else
            {
                var sourcePos  = teleporter.Pos.RelativeToSpawn(Api.World);
                var tpLocation = teleporter.GetField <TeleporterLocation>("tpLocation");

                // Add Source TP Waypoint.
                if (Api.WaypointExistsAtPos(teleporter.Pos, p => p.Icon == "spiral"))
                {
                    return;
                }
                var title = LangEx.Message("TeleporterWaypoint",
                                           tpLocation?.TargetName?.IfNullOrWhitespace("Unknown"));

                Api.AddWaypointAtPos(sourcePos, "spiral", "SpringGreen", title, false);
                Api.Logger.VerboseDebug($"Added Waypoint: {title}");
            }
        }
Пример #2
0
        public void RecentreMapOnWorldSpawn(string option, CmdArgs args)
        {
            var pos        = Api.World.DefaultSpawnPosition.AsBlockPos;
            var displayPos = pos.RelativeToSpawn(Api.World);

            Api.ShowChatMessage(LangEx.Message("RecentreOnPosition", displayPos.X, displayPos.Z));
            RecentreMap(pos.ToVec3d());
        }
Пример #3
0
        public override void OnCustomOption(string option, CmdArgs args)
        {
            var player     = Api.World.Player;
            var displayPos = player.Entity.Pos.AsBlockPos.RelativeToSpawn(Api.World);

            Api.ShowChatMessage(LangEx.Message("RecentreOnPlayer", player.PlayerName, displayPos.X, displayPos.Z));
            RecentreMap(player.Entity.Pos.XYZ);
        }
Пример #4
0
        public override void OnNoOption(string option, CmdArgs args)
        {
            var player = Api.World.Player;
            var pos    = player.Entity.Pos.AsBlockPos.RelativeToSpawn(Api.World);

            Api.SendChatMessage(LangEx.Message("BroadcastGPS", player.PlayerName, pos.X, pos.Y, pos.Z));
            Api.ShowChatMessage(LangEx.Message("LocationCopiedToClipboard"));
            Api.Forms.SetClipboardText($"X = {pos.X}, Y = {pos.Y}, Z = {pos.Z}.");
        }
Пример #5
0
        public void RecentreMapOnPosition(string option, CmdArgs args)
        {
            var playerPos = Api.World.Player.Entity.Pos.AsBlockPos;
            var x         = args.PopInt().GetValueOrDefault(playerPos.X);
            var z         = args.PopInt().GetValueOrDefault(playerPos.Z);
            var pos       = new BlockPos(x, 1, z).Add(Api.World.DefaultSpawnPosition.AsBlockPos);

            Api.ShowChatMessage(LangEx.Message("RecentreOnPosition", x, z));
            RecentreMap(pos.ToVec3d());
        }
        private static bool Patch_BlockEntityTeleporter_OnEntityCollide_Prefix(
            ref BlockEntityTeleporter __instance,
            ref Dictionary <long, TeleportingEntity> ___tpingEntities,
            ref TeleporterLocation ___tpLocation)
        {
            // TODO: Still very hacky. It would be very nice to get a proper way of setting this waypoint.
            //
            // Developer's Notes:   As of Game Version 1.14.10. There is currently no way to gather information
            //                      about the target side of a Teleporter block, other than its name, from the
            //                      Client API. In order for this to work, I would need to trick the server into
            //                      sending the client the updated list of teleporters on the server.
            //
            //                      This should be possible by mimicking the action of refreshing the GUI dialogue
            //                      without the dialogue box needing to be opened. However, parts of the dialogue
            //                      logic is locked behind a GameMode check. I could, internally switch the player
            //                      to creative and back, purely for this check, and it might even be possible to
            //                      do this check at player login, before the user has control of the player character.
            //
            //                      I'd then store the list of teleporters in memory, ready for use, if needed.

            if (JustTeleported > 0)
            {
                return(true);
            }
            if (!Settings.AutoTranslocatorWaypoints)
            {
                return(true);
            }
            if (!___tpingEntities.ContainsKey(Api.World.Player.Entity.EntityId))
            {
                return(true);
            }

            // Add Source TP Waypoint.
            if (Api.WaypointExistsAtPos(__instance.Pos, p => p.Icon == "spiral"))
            {
                return(true);
            }
            var title = LangEx.Message("TeleporterWaypoint",
                                       ___tpLocation?.TargetName?.IfNullOrWhitespace("Unknown"));
            var sourcePos = __instance.Pos.RelativeToSpawn(Api.World);

            Api.AddWaypointAtPos(sourcePos, "spiral", "SpringGreen", title, false);
            Api.Logger.VerboseDebug($"Added Waypoint: {title}");

            JustTeleported = 1;
            Task.Factory.StartNew(() =>
            {
                Thread.Sleep(1000 * 10);
                JustTeleported = 0;
                Api.Logger.VerboseDebug("Teleporter Waypoint Cooldown Reset.");
            });
            return(true);
        }
        private static bool Patch_BlockEntityStaticTranslocator_OnEntityCollide_Prefix(ref BlockEntityStaticTranslocator __instance, Entity entity)
        {
            if (JustTeleported > 0)
            {
                return(true);
            }
            JustTeleported = 1;
            Task.Factory.StartNew(() =>
            {
                Thread.Sleep(1000 * 30);
                JustTeleported = 0;
                Api.Logger.VerboseDebug("Translocator Waypoint Cooldown Reset.");
            });

            if (!Settings.AutoTranslocatorWaypoints)
            {
                return(true);
            }
            if (entity != Api.World.Player.Entity)
            {
                return(true);
            }
            if (!__instance.FullyRepaired || !__instance.Activated || !__instance.GetField <bool>("canTeleport"))
            {
                return(false);
            }

            var sourcePos = __instance.Pos.RelativeToSpawn(Api.World);
            var destPos   = __instance.TargetLocation.RelativeToSpawn(Api.World);

            // Add Source TL Waypoint.
            if (!Api.WaypointExistsAtPos(__instance.Pos))
            {
                Api.AddWaypointAtPos(sourcePos, "spiral", "Fuchsia",
                                     LangEx.Message("TranslocatorWaypoint", destPos.X, destPos.Y, destPos.Z), false);
                Api.Logger.VerboseDebug($"Added Waypoint: Translocator to ({destPos.X}, {destPos.Y}, {destPos.Z})");
            }

            // Add Destination TL Waypoint.
            if (!Api.WaypointExistsAtPos(__instance.TargetLocation))
            {
                Api.AddWaypointAtPos(destPos, "spiral", "Fuchsia",
                                     LangEx.Message("TranslocatorWaypoint", sourcePos.X, sourcePos.Y, sourcePos.Z), false);
                Api.Logger.VerboseDebug($"Added Waypoint: Translocator to ({sourcePos.X}, {sourcePos.Y}, {sourcePos.Z})");
            }

            return(true);
        }
Пример #8
0
        public void RecentreMapOnPlayer(string option, CmdArgs args)
        {
            var player     = Api.World.Player;
            var name       = args.PopWord(player.PlayerName);
            var playerList = Api.World.AllOnlinePlayers.Where(p =>
                                                              p.PlayerName.ToLowerInvariant().StartsWith(name.ToLowerInvariant())).ToList();

            if (playerList.Any())
            {
                player = (IClientPlayer)playerList.First();
            }
            var displayPos = player.Entity.Pos.AsBlockPos.RelativeToSpawn(Api.World);

            Api.ShowChatMessage(LangEx.Message("RecentreOnPlayer", player.PlayerName, displayPos.X, displayPos.Z));
            RecentreMap(player.Entity.Pos.XYZ);
        }
Пример #9
0
        private void AddTranslocatorWaypoint(bool pinned)
        {
            var found        = false;
            var translocator = Api.World.GetNearestBlockEntity <BlockEntityStaticTranslocator>(Api.World.Player.Entity.Pos.AsBlockPos,
                                                                                               5f, 1f, p =>
            {
                if (!p.FullyRepaired || !p.Activated || !p.GetField <bool>("canTeleport"))
                {
                    return(false);
                }
                found = true;
                return(true);
            });

            if (!found)
            {
                Api.ShowChatMessage(LangEx.Error("TranslocatorNotFound"));
            }
            else
            {
                var sourcePos = translocator.Pos.RelativeToSpawn(Api.World);
                var destPos   = translocator.TargetLocation.RelativeToSpawn(Api.World);

                // Add Source TL Waypoint.
                if (!Api.WaypointExistsAtPos(translocator.Pos, p => p.Icon == "spiral"))
                {
                    Api.AddWaypointAtPos(sourcePos, "spiral", "Fuchsia",
                                         LangEx.Message("TranslocatorWaypoint", destPos.X, destPos.Y, destPos.Z), false);
                    Api.Logger.VerboseDebug($"Added Waypoint: Translocator to ({destPos.X}, {destPos.Y}, {destPos.Z})");
                }

                // Add Destination TL Waypoint.
                if (!Api.WaypointExistsAtPos(translocator.TargetLocation, p => p.Icon == "spiral"))
                {
                    Api.AddWaypointAtPos(destPos, "spiral", "Fuchsia",
                                         LangEx.Message("TranslocatorWaypoint", sourcePos.X, sourcePos.Y, sourcePos.Z), false);
                    Api.Logger.VerboseDebug($"Added Waypoint: Translocator to ({sourcePos.X}, {sourcePos.Y}, {sourcePos.Z})");
                }
            }
        }
Пример #10
0
        private void PurgeWaypointsByIcon(string option, CmdArgs args)
        {
            var confirm = LangEx.Phrases("Confirm");

            if (args.Length == 1)
            {
                var icon = args.PopWord();
                Api.ShowChatMessage(icon == confirm
                    ? LangEx.Message("SpecifyIcon")
                    : LangEx.Message("ConfirmationRequest", icon));
            }

            else if (args.Length == 2)
            {
                var icon = args.PopWord();
                if (args.PopWord() != confirm)
                {
                    return;
                }

                try
                {
                    Api.ShowChatMessage(LangEx.Message("PurgingWaypoints", icon, confirm));
                    var i = icon;
                    PurgeWaypoints(p => p.Icon == i);
                }
                catch (Exception ex)
                {
                    Api.Logger.Audit(ex.Message);
                    Api.Logger.Audit(ex.StackTrace);
                }
            }

            else
            {
                Api.ShowChatMessage(LangEx.Message("SpecifyIcon"));
            }
        }
Пример #11
0
 private void AutomaticTraders(string option, CmdArgs args)
 {
     Mod.Settings.AutoTraderWaypoints = !Mod.Settings.AutoTraderWaypoints;
     Api.GetModFile("wpex-settings.data").SaveAsJson(Mod.Settings);
     Api.ShowChatMessage(LangEx.Message("AutoTrader", Mod.Settings.AutoTraderWaypoints));
 }