Пример #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
        private void AddTraderWaypoint(bool pinned)
        {
            var found = false;

            var trader = Api.World.GetNearestEntity(Api.World.Player.Entity.Pos.XYZ, 10f, 10f, p =>
            {
                if (!p.Code.Path.StartsWith("humanoid-trader-") || !p.Alive)
                {
                    return(false);
                }
                found = true;
                return(true);
            });

            if (!found)
            {
                Api.ShowChatMessage(LangEx.Error("TraderNotFound"));
            }
            else
            {
                var pos         = trader.Pos.AsBlockPos.RelativeToSpawn(Api.World);
                var displayName = trader.GetBehavior <EntityBehaviorNameTag>().DisplayName;

                if (Api.WaypointExistsWithinRadius(trader.Pos.AsBlockPos, 10, 10,
                                                   p => p.Icon == "trader" && p.Title.Contains(displayName)))
                {
                    Api.ShowChatMessage(LangEx.Error("WaypointAlreadyExists"));
                    return;
                }

                var colour  = TraderIconColour(trader.Code.Path);
                var wpTitle = Lang.Get("tradingwindow-" + trader.Code.Path, displayName);
                Api.AddWaypointAtPos(pos, "trader", colour, wpTitle, pinned);
            }
        }
Пример #3
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());
        }
Пример #4
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);
        }
Пример #5
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}.");
        }
Пример #6
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);
        }
Пример #8
0
        internal void ComposeWindow()
        {
            ClearComposers();

            var         rows  = new[] { 0f, 1f, 1.5f, 2.5f, 3.0f };
            const float width = 500f;

            var guiComposer = Api.AsClientMain().GetField <GuiComposerManager>("GuiComposers")
                              .Create("wpex-settings", ElementStdBounds.AutosizedMainDialog)
                              .AddShadedDialogBG(ElementStdBounds.DialogBackground()
                                                 .WithFixedPadding(GuiStyle.ElementToDialogPadding, GuiStyle.ElementToDialogPadding), false)
                              .BeginChildElements();

            // Title.
            guiComposer.AddStaticText(LangEx.UI("SettingsWindow.Headers.Wpex"),
                                      CairoFont.WhiteSmallishText().WithFontSize(25f),
                                      EnumTextOrientation.Center,
                                      ElementStdBounds.MenuButton(rows[0])
                                      .WithFixedWidth(width));

            // Auto Translocator.
            guiComposer.AddStaticText(LangEx.UI("SettingsWindow.Labels.AutoTranslocator"), CairoFont.WhiteSmallishText(),
                                      ElementStdBounds.MenuButton(rows[1], EnumDialogArea.LeftTop).WithFixedWidth(330))
            .AddHoverText(LangEx.UI("SettingsWindow.Tooltips.AutoTranslocator"), CairoFont.WhiteSmallText(), 250,
                          ElementStdBounds.MenuButton(rows[1], EnumDialogArea.LeftTop).WithFixedWidth(250))
            .AddSwitch(AutoTranslocatorChanged,
                       ElementStdBounds.MenuButton(rows[1], EnumDialogArea.LeftTop).WithFixedOffset(350.0, 0), "AutoTranslocatorWaypoints");

            // Auto Trader
            guiComposer.AddStaticText(LangEx.UI("SettingsWindow.Labels.AutoTrader"), CairoFont.WhiteSmallishText(),
                                      ElementStdBounds.MenuButton(rows[2], EnumDialogArea.LeftTop).WithFixedWidth(330))
            .AddHoverText(LangEx.UI("SettingsWindow.Tooltips.AutoTrader"), CairoFont.WhiteSmallText(), 250,
                          ElementStdBounds.MenuButton(rows[2], EnumDialogArea.LeftTop).WithFixedWidth(250))
            .AddSwitch(AutoTraderChanged,
                       ElementStdBounds.MenuButton(rows[2], EnumDialogArea.LeftTop).WithFixedOffset(350.0, 0), "AutoTraderWaypoints");

            // Donate Button.
            guiComposer.AddButton(LangEx.UI("SettingsWindow.Labels.Donate"), OnDonateButton,
                                  ElementStdBounds.MenuButton(rows[3]).WithFixedWidth(width));

            // Back Button.
            guiComposer.AddButton(Lang.Get("pause-back2game"), OnBackToGame,
                                  ElementStdBounds.MenuButton(rows[4]).WithFixedWidth(width));

            guiComposer.GetSwitch("AutoTranslocatorWaypoints").On = Mod.Settings.AutoTranslocatorWaypoints;
            guiComposer.GetSwitch("AutoTraderWaypoints").On       = Mod.Settings.AutoTraderWaypoints;

            SingleComposer = guiComposer.EndChildElements().Compose();
        }
        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);
        }
Пример #10
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);
        }
Пример #11
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})");
                }
            }
        }
Пример #12
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"));
            }
        }
Пример #13
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));
 }
Пример #14
0
 /// <summary>
 ///     The default help text to display when using the .help command.
 /// </summary>
 /// <returns>By default, returns the description of the command, as set within the language files. This can be overridden.</returns>
 public virtual string HelpText()
 {
     return(LangEx.FluentChat(this, "Description"));
 }