////

        protected override void SetClientDefaults()
        {
            var myplayer = (ModHelpersPlayer)TmlHelpers.SafelyGetModPlayer(Main.LocalPlayer, ModHelpersMod.Instance, "ModHelpersPlayer");

            this.ClientPrivateUID = myplayer.Logic.OldPrivateUID;
            this.ClientHasUID     = myplayer.Logic.HasLoadedOldUID;
        }
        ////////////////

        public override void PostDrawFullscreenMap(ref string mouseText)
        {
            var myplayer = TmlHelpers.SafelyGetModPlayer <MMMPlayer>(Main.LocalPlayer);

            if (!myplayer.IsMapMirrorPicking)
            {
                return;
            }

            int maxDistSqr = MountedMagicMirrorsMod.MaxTileClickDistance * MountedMagicMirrorsMod.MaxTileClickDistance;

            int mouseX = Main.mouseX - (Main.screenWidth / 2);

            mouseX = (int)((float)mouseX * Main.UIScale);
            mouseX = (Main.screenWidth / 2) + mouseX;
            int mouseY = Main.mouseY - (Main.screenHeight / 2);

            mouseY = (int)((float)mouseY * Main.UIScale);
            mouseY = (Main.screenHeight / 2) + mouseY;

            (int x, int y)mouseTile;
            HUDMapHelpers.GetFullscreenMapTileOfScreenPosition(mouseX, mouseY, out mouseTile);

            int closestTileDistSqr = maxDistSqr;

            (int x, int y)closestTilePos = (0, 0);
            IEnumerable <(int, int)> discoveredMirrors = myplayer.GetDiscoveredMirrors().ToArray();

            foreach ((int tileX, int tileY) in discoveredMirrors)
            {
                int distX   = mouseTile.x - tileX;
                int distY   = mouseTile.y - tileY;
                int distSqr = (distX * distX) + (distY * distY);

                if (distSqr < closestTileDistSqr)
                {
                    closestTileDistSqr = distSqr;
                    closestTilePos     = (tileX, tileY);
                }
            }

            foreach ((int tileX, int tileY) in discoveredMirrors)
            {
                bool isTarget = tileX == closestTilePos.x &&
                                tileY == closestTilePos.y &&
                                closestTileDistSqr < maxDistSqr;

                if (isTarget)
                {
                    myplayer.TargetMirror = (tileX, tileY);
                }

                this.DrawMirrorOnFullscreenMap(tileX, tileY, isTarget);
            }

            if (closestTilePos == (0, 0))
            {
                myplayer.TargetMirror = null;
            }
        }
        ////////////////

        public void DrawSubHealth(InjuryMod mymod, SpriteBatch sb)
        {
            var   myplayer = (InjuryPlayer)TmlHelpers.SafelyGetModPlayer(Main.LocalPlayer, mymod, "InjuryPlayer");
            float percent  = myplayer.Logic.ComputeHarmBufferPercent(Main.LocalPlayer);

            this.DrawSubHealthAtPercent(sb, percent);
        }
Exemple #4
0
        public static void TrialLicenseItemForCurrentPlayer(Item item, bool playSound)
        {
            var itemDef  = new ItemDefinition(item.type);
            var myplayer = (LicensesPlayer)TmlHelpers.SafelyGetModPlayer(Main.LocalPlayer, LicensesMod.Instance, "LicensesPlayer");

            myplayer.TrialLicenseItemByDefinition(itemDef, playSound);
        }
Exemple #5
0
        public override void NetReceive(BinaryReader reader)
        {
            var mymod    = (HonorBoundMod)this.mod;
            var myplayer = (HonorBoundPlayer)TmlHelpers.SafelyGetModPlayer(Main.LocalPlayer, mymod, "HonorBoundPlayer");

            if (!myplayer.HasEnteredWorld)
            {
                return;
            }

            ISet <string> honorifics = new HashSet <string>();

            bool isHonorBound = reader.ReadBoolean();
            bool hasNoHonor   = reader.ReadBoolean();
            int  count        = reader.ReadInt32();

            for (int i = 0; i < count; i++)
            {
                honorifics.Add(reader.ReadString());
            }

            this.Logic = new HonorBoundLogic(isHonorBound, hasNoHonor, honorifics);

            myplayer.OnEnterWorldIfSynced();
        }
Exemple #6
0
        protected override void OnEnter(object data)
        {
            if (this.PlayerWho != Main.myPlayer)
            {
                return;
            }

            var myplayer = TmlHelpers.SafelyGetModPlayer <RewardsPlayer>(this.Player);

            if (Main.netMode == 0)
            {
                myplayer.OnConnectSingle();
            }
            if (Main.netMode == 1)
            {
                myplayer.OnConnectCurrentClient();
            }

            InboxMessages.SetMessage("RewardsModConfigUpdate",
                                     "Rewards config files updated to use ModConfig (tML v0.11+). The old config files " +
                                     "(Rewards Config.json, Rewards Points Config.json, Rewards Shop Config.json) are now obsolete. " +
                                     "If any mod settings have been changed from their defaults in the past, you'll need to import them " +
                                     "manually (preferably via. the menu's Mod Configuration).",
                                     false
                                     );
        }
        ////////////////

        public void UpdatePlayerInfo()
        {
            Player plr      = Main.player[this.PlayerWho];
            var    myplayer = TmlHelpers.SafelyGetModPlayer <PlayerStatisticsPlayer>(plr);

            Color  teamColor;
            string teamColorName = Enum.GetName(typeof(PlayerTeamName), PlayerTeamHelpers.GetTeamName(plr.team, out teamColor));

            this.TeamElement.SetText(teamColorName);
            this.TeamElement.TextColor = teamColor;

            this.PvpKills    = myplayer.GetPvpKills();
            this.PvpDeaths   = myplayer.GetPvpDeaths();
            this.TotalDeaths = myplayer.GetTotalDeaths();
            this.Latency     = myplayer.GetLatency();
            string progress = myplayer.GetProgress(out this.ProgressAmount);

            this.PvPKillsElement.SetText(this.PvpKills + "");
            this.PvPDeathsElement.SetText(this.PvpDeaths + "");
            this.TotalDeathsElement.SetText(this.TotalDeaths + "");
            this.LatencyElement.SetText(this.Latency + "");
            this.ProgressElement.SetText(progress);

            this.Recalculate();
        }
        ////////////////

        private UIElement GetItemIntrinsic(Item item)
        {
            var  myplayer  = TmlHelpers.SafelyGetModPlayer <IntrinsicsPlayer>(Main.LocalPlayer);
            bool isEnabled = myplayer.IntrinsicToggle.GetOrDefault(item.type);

            return(new UIIntrinsicItemButton(item, isEnabled));
        }
        ////////////////

        public void UpdateLists()
        {
            var myplayer = TmlHelpers.SafelyGetModPlayer <IntrinsicsPlayer>(Main.LocalPlayer);

            ////

            var buffs = myplayer.IntrinsicBuffItem.Values
                        .Select(item => this.GetItemIntrinsic(item))
                        .ToList();
            var arms = myplayer.IntrinsicArmItem.Values
                       .Select(item => this.GetItemIntrinsic(item))
                       .ToList();
            var accs = myplayer.IntrinsicAccItem.Values
                       .Select(item => this.GetItemIntrinsic(item))
                       .ToList();

            ////

            this.BuffList.Clear();
            this.ArmList.Clear();
            this.AccList.Clear();

            this.BuffList.Recalculate();
            this.ArmList.Recalculate();
            this.AccList.Recalculate();

            this.BuffList.AddRange(buffs);
            this.ArmList.AddRange(arms);
            this.AccList.AddRange(accs);
        }
        ////////////////

        public UIIntrinsicItemButton(Item item, bool isEnabled)
        {
            this.MyItem    = item;
            this.IsEnabled = isEnabled;

            var label = new UIText(this.MyItem.HoverName);

            label.Top.Set(0f, 0f);
            label.Left.Set(22f, 0f);
            label.TextColor = this.IsEnabled ? Color.White : new Color(96, 96, 96);

            this.Width.Set(-16f, 1f);
            this.Height.Set(40f, 0f);
            this.Append(label);

            this.OnClick += (_, __) => {
                var mymod = IntrinsicsMod.Instance;
                if (!mymod.Config.ToggleableIntrinsics)
                {
                    return;
                }

                var myplayer2 = TmlHelpers.SafelyGetModPlayer <IntrinsicsPlayer>(Main.LocalPlayer);
                this.IsEnabled = myplayer2.ToggleIntrinsic(this.MyItem.type);

                label.TextColor = this.IsEnabled ? Color.White : new Color(96, 96, 96);
            };
        }
        ////////////////

        private void HandlePageTickClicks(Rectangle[] rects)
        {
            Player plr = Main.LocalPlayer;

            if (plr == null || !plr.active)
            {
                return;
            }                                                           //?

            var mymod    = ExtensibleInventoryMod.Instance;
            var myplayer = TmlHelpers.SafelyGetModPlayer <ExtensibleInventoryPlayer>(plr);

            if (Main.mouseLeft && Main.mouseLeftRelease)
            {
                for (int i = 0; i < rects.Length; i++)
                {
                    Rectangle rect = rects[i];

                    if (rect.Contains(Main.mouseX, Main.mouseY))
                    {
                        myplayer.Library.CurrentBook.JumpToPage(Main.LocalPlayer, i);
                        break;
                    }
                }
            }
        }
Exemple #12
0
        ////////////////

        public override void Action(CommandCaller caller, string input, string[] args)
        {
            var mymod = (IntrinsicsMod)this.mod;

            if (!mymod.Config.DebugModeCheat)
            {
                caller.Reply("Cheat mode not active. See configs.", Color.Red);
                return;
            }

            if (Main.netMode == 1)
            {
                LogHelpers.Warn("Not supposed to run on client.");
                return;
            }

            if (Main.netMode == 2 && caller.CommandType != CommandType.Console)
            {
                bool hasPriv = UserHelpers.HasBasicServerPrivilege(caller.Player);

                if (!hasPriv)
                {
                    caller.Reply("Access denied.", Color.Red);
                    return;
                }
            }

            if (args.Length < 1)
            {
                caller.Reply("Insufficient arguments.", Color.Red);
                return;
            }

            string itemName = string.Join(" ", args);
            int    itemId;

            if (!ItemAttributeHelpers.DisplayNamesToIds.ContainsKey(itemName))
            {
                itemId = ItemID.TypeFromUniqueKey(itemName);

                if (itemId == 0)
                {
                    caller.Reply("Invalid item name: " + itemName, Color.Red);
                    return;
                }
            }
            else
            {
                itemId = ItemAttributeHelpers.DisplayNamesToIds[itemName];
            }

            var myplayer = TmlHelpers.SafelyGetModPlayer <IntrinsicsPlayer>(Main.LocalPlayer);

            myplayer.RemoveIntrinsic(ItemID.GetUniqueKey(itemId));                //TODO GetProperUniqueId

            caller.Reply("Intrinsic removed.", Color.Lime);
        }
        public void ScrollPageUp()
        {
            var mymod    = ExtensibleInventoryMod.Instance;
            var myplayer = TmlHelpers.SafelyGetModPlayer <ExtensibleInventoryPlayer>(Main.LocalPlayer);

            if (myplayer.Library.CurrentBook.ScrollPageUp(Main.LocalPlayer))
            {
            }
        }
        public override void ModifyInterfaceLayers(List <GameInterfaceLayer> layers)
        {
            int layerIdx = layers.FindIndex(layer => layer.Name.Equals("Vanilla: Inventory"));

            if (layerIdx == -1)
            {
                return;
            }

            GameInterfaceDrawMethod invOver = delegate {
                if (!Main.playerInventory)
                {
                    return(true);
                }

                var mymod = EncumbranceMod.Instance;
                if (mymod.Config.BurdenedItemSlotOverlayOpacity == 0f)
                {
                    return(true);
                }

                var myplayer = (EncumbrancePlayer)TmlHelpers.SafelyGetModPlayer(Main.LocalPlayer, this, "EncumbrancePlayer");
                int capacity = myplayer.GetCurrentCapacity();

                float invScale = 0.85f;
                //if( (plr.chest != -1 || Main.npcShop > 0) && !Main.recBigList ) {
                //	inv_scale = 0.755f;
                //}

                for (int i = 0; i < 10; i++)
                {
                    for (int j = 0; j < 5; j++)
                    {
                        int idx = i + j * 10;

                        if (idx < capacity)
                        {
                            continue;
                        }

                        Texture2D tex   = this.ShadowBox;
                        int       posX  = (int)(20f + ((float)i * 56f) * invScale);
                        int       posY  = (int)(20f + ((float)j * 56f) * invScale);
                        var       pos   = new Vector2(posX, posY);
                        Color     color = Color.White * mymod.Config.BurdenedItemSlotOverlayOpacity;

                        Main.spriteBatch.Draw(tex, pos, null, color, 0f, default(Vector2), invScale, SpriteEffects.None, 1f);
                    }
                }

                return(true);
            };

            var invOverLayer = new LegacyGameInterfaceLayer("Encumbrance: Inventory Overlay", invOver, InterfaceScaleType.UI);

            layers.Insert(layerIdx + 1, invOverLayer);
        }
Exemple #15
0
        protected override void ReceiveOnServer(int fromWho)
        {
            Player plr      = Main.player[this.Who];           //fromWho
            var    myplayer = TmlHelpers.SafelyGetModPlayer <IntrinsicsPlayer>(plr);
            IDictionary <int, bool> itemStatesMap = this.ItemStates
                                                    .ToDictionary((i) => Math.Abs(i), (i) => i >= 0);

            myplayer.SyncIntrinsicItemsToMe(this.ItemUids, itemStatesMap);
        }
Exemple #16
0
        ////////////////

        internal void LoadFromNetwork(HamstarHelpersConfigData config)
        {
            var mymod    = ModHelpersMod.Instance;
            var myplayer = (ModHelpersPlayer)TmlHelpers.SafelyGetModPlayer(Main.LocalPlayer, ModHelpersMod.Instance, "ModHelpersPlayer");

            mymod.ConfigJson.SetData(config);

            myplayer.Logic.FinishModSettingsSyncOnClient();
        }
Exemple #17
0
        ////////////////

        protected override void InitializeClientSendData()
        {
            var myplayer = TmlHelpers.SafelyGetModPlayer <IntrinsicsPlayer>(Main.LocalPlayer);

            this.ItemUids   = myplayer.IntrinsicItemUids.ToArray();
            this.ItemStates = myplayer.IntrinsicToggle
                              .SafeSelect(kv => kv.Value ? kv.Key : -kv.Key)
                              .ToArray();
        }
Exemple #18
0
        ////////////////

        protected override bool ReceiveRequestWithClient()
        {
            Player player   = Main.LocalPlayer;
            var    myplayer = (ResetModePlayer)TmlHelpers.SafelyGetModPlayer(player, ResetModeMod.Instance, "ResetModePlayer");

            myplayer.Logic.PromptReset(player);

            return(false);
        }
        ////

        public void AddPage()
        {
            var mymod    = ExtensibleInventoryMod.Instance;
            var myplayer = TmlHelpers.SafelyGetModPlayer <ExtensibleInventoryPlayer>(Main.LocalPlayer);

            if (myplayer.Library.CurrentBook.InsertAtCurrentPagePosition(Main.LocalPlayer))
            {
                Main.NewText("Inventory page " + myplayer.Library.CurrentBook.CurrentPageIdx + " added.", Color.LimeGreen);
            }
        }
        public void DelPage()
        {
            var mymod    = ExtensibleInventoryMod.Instance;
            var myplayer = TmlHelpers.SafelyGetModPlayer <ExtensibleInventoryPlayer>(Main.LocalPlayer);

            if (myplayer.Library.CurrentBook.DeleteCurrentPage(Main.LocalPlayer))
            {
                Main.NewText("Inventory page " + myplayer.Library.CurrentBook.CurrentPageIdx + " removed.", Color.LimeGreen);
            }
        }
        ////

        public void TogglePageSharingOn()
        {
            var mymod    = ExtensibleInventoryMod.Instance;
            var myplayer = TmlHelpers.SafelyGetModPlayer <ExtensibleInventoryPlayer>(Main.LocalPlayer);

            if (myplayer.Library.CurrentBook.SetCurrentPageShared(true))
            {
                Main.NewText("Inventory page " + myplayer.Library.CurrentBook.CurrentPageIdx + " auto-shares items.", Color.LimeGreen);
            }
        }
        public void TogglePageSharingOff()
        {
            var mymod    = ExtensibleInventoryMod.Instance;
            var myplayer = TmlHelpers.SafelyGetModPlayer <ExtensibleInventoryPlayer>(Main.LocalPlayer);

            if (myplayer.Library.CurrentBook.SetCurrentPageShared(false))
            {
                Main.NewText("Inventory page " + myplayer.Library.CurrentBook.CurrentPageIdx + " auto-sharing disabled.", Color.Yellow);
            }
        }
        public static void AddBookPage(string bookName = "Default")
        {
            var    myplayer = TmlHelpers.SafelyGetModPlayer <ExtensibleInventoryPlayer>(Main.LocalPlayer);
            string err;

            if (!myplayer.Library.AddBookPage(Main.LocalPlayer, bookName, out err))
            {
                Main.NewText(err, Color.Red);
            }
        }
        public static void RemoveLatestBookPage(Player player, string bookName = "Default")
        {
            var    myplayer = TmlHelpers.SafelyGetModPlayer <ExtensibleInventoryPlayer>(player);
            string err;

            if (!myplayer.Library.RemoveLatestBookPage(player, bookName, out err))
            {
                Main.NewText(err, Color.Red);
            }
        }
Exemple #25
0
        protected override void InitializeServerRequestReplyDataOfClient(int toWho, int fromWho)
        {
            Player plr      = Main.player[fromWho];
            var    myplayer = TmlHelpers.SafelyGetModPlayer <IntrinsicsPlayer>(plr);

            this.Who        = fromWho;
            this.ItemUids   = myplayer.IntrinsicItemUids.ToArray();
            this.ItemStates = myplayer.IntrinsicToggle
                              .SafeSelect(kv => kv.Value ? kv.Key : -kv.Key)
                              .ToArray();
        }
Exemple #26
0
        public override void Update(Player player, ref int buffIndex)
        {
            if (player.mount.Active)
            {
                return;
            }

            var myplayer = TmlHelpers.SafelyGetModPlayer <InjuryPlayer>(player);

            myplayer.IsImpaired = true;
        }
Exemple #27
0
        ////////////////

        public override void ModifyInterfaceLayers(List <GameInterfaceLayer> layers)
        {
            int layerIdx = layers.FindIndex(layer => layer.Name.Equals("Vanilla: Inventory"));

            if (layerIdx == -1)
            {
                return;
            }

            GameInterfaceDrawMethod controlUi = delegate {
                if (!Main.playerInventory || Main.myPlayer < 0 || Main.LocalPlayer == null || !Main.LocalPlayer.active)
                {
                    if (Main.LocalPlayer != null && !Main.LocalPlayer.active)
                    {
                        TmlHelpers.SafelyGetModPlayer <ExtensibleInventoryPlayer>(Main.LocalPlayer);
                        if (!Main.LocalPlayer.active)
                        {
                            return(true);
                        }
                    }
                    //if( Main.playerInventory ) {
                    //	LogHelpers.LogOnce( ""+(Main.myPlayer<0)+","+(Main.LocalPlayer == null)+","+(!Main.LocalPlayer.active) );
                    //}
                    return(true);
                }

                var mymod = ExtensibleInventoryMod.Instance;

                try {
                    mymod.InvUIMngr?.Update(Main._drawInterfaceGameTime);
                    mymod.InvUI?.Draw(Main.spriteBatch);

                    if (!this.Config.HideScrollModeIcon)
                    {
                        var myplayer = TmlHelpers.SafelyGetModPlayer <ExtensibleInventoryPlayer>(Main.LocalPlayer);
                        if (myplayer.ScrollModeOn & this.ScrollIcon != null)
                        {
                            var   pos        = new Vector2(Main.mouseX - 24, Main.mouseY);
                            float colorScale = 0.35f * ((float)myplayer.ScrollModeDuration / (float)ExtensibleInventoryPlayer.ScrollModeMaxDuration);

                            Main.spriteBatch.Draw(this.ScrollIcon, pos, Color.White * colorScale);
                        }
                    }
                } catch (Exception e) {
                    throw new ModHelpersException("", e);
                }

                return(true);
            };

            var invOverLayer = new LegacyGameInterfaceLayer("Extensible Inventory: Page Controls", controlUi, InterfaceScaleType.UI);

            layers.Insert(layerIdx + 1, invOverLayer);
        }
        private void DrawDisabledElementOverlays(SpriteBatch sb)
        {
            var    mymod = ExtensibleInventoryMod.Instance;
            Player plr   = Main.LocalPlayer;

            if (plr == null || !plr.active)
            {
                return;
            }                                                           //?
            var myplayer = TmlHelpers.SafelyGetModPlayer <ExtensibleInventoryPlayer>(plr);

            /*if( !mymod.Config.CanScrollPages ) {
             *      InventoryPageScrollerUI.DrawX( sb, this.ButtonPageLeft );
             *      InventoryPageScrollerUI.DrawX( sb, this.ButtonPageRight );
             * }
             * if( !mymod.Config.CanAddPages ) {
             *      InventoryPageScrollerUI.DrawX( sb, this.ButtonPageAdd );
             * }
             * if( !mymod.Config.CanDeletePages ) {
             *      InventoryPageScrollerUI.DrawX( sb, this.ButtonPageSub );
             * }*/

            if (!myplayer.Library.CurrentBook.IsEnabled)
            {
                if (mymod.Config.CanScrollPages)
                {
                    InventoryUI.DrawX(sb, this.ButtonPageLeft);
                    InventoryUI.DrawX(sb, this.ButtonPageRight);
                }
                if (mymod.Config.CanAddPages)
                {
                    InventoryUI.DrawX(sb, this.ButtonPageAdd);
                }
                if (mymod.Config.CanDeletePages)
                {
                    InventoryUI.DrawX(sb, this.ButtonPageSub);
                }
            }

            if (this.ButtonBooks != null && mymod.Config.CanSwitchBooks)
            {
                foreach (var kv in this.ButtonBooks)
                {
                    string        _;
                    string        bookName   = kv.Key;
                    UIImageButton bookButton = kv.Value;

                    if (!myplayer.Library.CanSwitchBooks(out _) || !myplayer.Library.IsBookEnabled(bookName))
                    {
                        InventoryUI.DrawX(sb, bookButton);
                    }
                }
            }
        }
        ////////////////

        public override void Action(CommandCaller caller, string input, string[] args)
        {
            var mymod = (LicensesMod)this.mod;
            //if( !mymod.Config.DebugModeCheat ) {
            //	throw new UsageException( "Cheat mode not enabled." );
            //}

            var    myplayer = (LicensesPlayer)TmlHelpers.SafelyGetModPlayer(Main.LocalPlayer, mymod, "LicensesPlayer");
            string list     = string.Join(", ", myplayer.LicensedItems);

            Main.NewText(list);
        }
Exemple #30
0
        ////////////////

        public override void MouseOver(int i, int j)
        {
            Main.LocalPlayer.showItemIcon  = true;
            Main.LocalPlayer.showItemIcon2 = ModContent.ItemType <MountableMagicMirrorTileItem>();

            var myplayer = TmlHelpers.SafelyGetModPlayer <MMMPlayer>(Main.LocalPlayer);

            if (myplayer.AddDiscoveredMirror(i, j))
            {
                Main.NewText("Mirror located!", Color.Lime);
            }
        }