////////////////

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

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

        private static ChestImplanterDefinition GetRandomImplanterFromSet(ChestImplanterSetDefinition setDef)
        {
            if (setDef.Value.Count == 0)
            {
                return(null);
            }

            UnifiedRandom rand           = TmlHelpers.SafelyGetRand();
            float         totalWeight    = setDef.TotalWeight();
            float         randPick       = rand.NextFloat() * totalWeight;
            float         countedWeights = 0;

            for (int i = 0; i < setDef.Value.Count; i++)
            {
                countedWeights += setDef.Value[i].Value.Weight;

                if (countedWeights > randPick)
                {
                    return(setDef.Value[i].Value);
                }
            }

            LogHelpers.Warn("Could not randomly pick from implanter set. Total weight " + countedWeights + " of " + setDef.Value.Count + " implanters.");
            return(null);
        }
        ////////////////

        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;
                    }
                }
            }
        }
        ////

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

            this.ClientPrivateUID = myplayer.Logic.OldPrivateUID;
            this.ClientHasUID     = myplayer.Logic.HasLoadedOldUID;
        }
Esempio n. 7
0
        ////

        private bool RunBloom()
        {
            if (this.Cooldown++ > 20)
            {
                this.Cooldown = 0;
            }
            else
            {
                return(false);
            }

            int           nearby;
            UnifiedRandom rand = TmlHelpers.SafelyGetRand();

            foreach (BrambleBloomTendril tendril in this.Tendrils.ToArray())
            {
                if (tendril.IsSplit())
                {
                    this.Tendrils.Add(tendril.CloneAsSplit());
                }

                (int x, int y)growAt = tendril.Grow();
                nearby = this.CountBramblesNear(growAt.x, growAt.y) + 1;

                if (nearby <= 1 || rand.NextFloat() < (1f - ((float)nearby / 10f)))
                {
                    CursedBrambleTile.CreateBrambleAt(growAt.x, growAt.y);
                }
            }

            return(true);
        }
        ////////////////

        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);
        }
        public static ElementDefinition PickDefinitionForNPC(float chanceForAny)
        {
            UnifiedRandom rand = TmlHelpers.SafelyGetRand();

            if (rand.NextFloat() > chanceForAny)
            {
                return(null);
            }

            var   elements    = ElementsConfig.Instance.Elements;
            float totalWeight = ElementDefinition.GetTotalElementNPCAutoAssignWeight();
            float weight      = rand.NextFloat() * totalWeight;

            float countedWeights = 0f;

            for (int i = 0; i < elements.Count; i++)
            {
                countedWeights += elements[i].AutoAssignNPCWeight;
                if (weight < countedWeights)
                {
                    return(elements[i]);
                }
            }

            return(null);
        }
Esempio n. 10
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);
        }
Esempio n. 11
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();
        }
        ////////////////

        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();
        }
        ////////////////

        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;
            }
        }
Esempio n. 14
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
                                     );
        }
        private static Ambush CreateRandomWorldAmbush(int maxAttempts)
        {
            int           attempts = 0;
            int           randTileX, randTileY;
            UnifiedRandom rand = TmlHelpers.SafelyGetRand();

            do
            {
                randTileX = rand.Next(64, Main.maxTilesX - 64);
                randTileY = rand.Next((int)Main.worldSurface, Main.maxTilesY - 220);

                if (Ambush.CheckForAmbushElegibility(randTileX, randTileY))
                {
                    break;
                }
            } while(attempts++ < maxAttempts);

            if (attempts >= maxAttempts)
            {
                return(null);
            }

            Ambush.AdjustAmbushTileCenter(randTileX, ref randTileY);
            return(Ambush.CreateRandomType(randTileX, randTileY));
        }
        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);
        }
Esempio n. 17
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))
            {
            }
        }
Esempio n. 19
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();
        }
Esempio n. 20
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);
        }
Esempio n. 21
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();
        }
Esempio n. 22
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 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);
            }
        }
Esempio n. 25
0
        ////

        protected override Ambush CloneRandomized(int tileX, int tileY)
        {
            bool isEntrapping = AmbushesMod.Config.AmbushEntrapmentOdds <= 0
                                ? false
                                : TmlHelpers.SafelyGetRand().Next(AmbushesMod.Config.AmbushEntrapmentOdds) == 0;

            isEntrapping = isEntrapping && !WorldHelpers.IsWithinUnderworld(new Vector2(tileX << 4, tileY << 4));

            return(new FlyerSwarmAmbush(tileX, tileY, isEntrapping));
        }
        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);
            }
        }
Esempio n. 27
0
        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);
            }
        }
Esempio n. 28
0
        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);
            }
        }
        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);
            }
        }
Esempio n. 30
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();
        }