Exemplo n.º 1
0
        private void ItemDropped(GetDataHandlers.ItemDropEventArgs args)
        {
            //Debug.Print("Dropped Item!");

            var itemIdName = EnglishLanguage.GetItemNameById(args.Type);

            if (_itemName?.Equals(itemIdName, StringComparison.OrdinalIgnoreCase) ?? true)
            {
                var index = Main.maxItems;
                for (var i = 0; i < Main.maxItems; ++i)
                {
                    if (!Main.item[i].active && Main.itemLockoutTime[i] == 0)
                    {
                        index = i;
                        break;
                    }
                }
                if (index == Main.maxItems)
                {
                    var minTimeDiff = 0;
                    for (var i = 0; i < Main.maxItems; ++i)
                    {
                        var timeDiff = Main.item[i].spawnTime - Main.itemLockoutTime[i];
                        if (timeDiff > minTimeDiff)
                        {
                            minTimeDiff = timeDiff;
                            index       = i;
                        }
                    }
                }
                _blacklistedIndexes.Add(index);
            }
        }
Exemplo n.º 2
0
        private void OnItemDrop(object sender, GetDataHandlers.ItemDropEventArgs args)
        {
            var player = args.Player;

            if (args.Handled)
            {
                return;
            }

            if (args.ID == Main.maxItems)
            {
                var itemIdName = EnglishLanguage.GetItemNameById(args.Type);
                if (_itemName?.Equals(itemIdName, StringComparison.OrdinalIgnoreCase) ?? true)
                {
                    var index = Main.maxItems;
                    for (var i = 0; i < Main.maxItems; ++i)
                    {
                        if (!Main.item[i].active && Main.itemLockoutTime[i] == 0)
                        {
                            index = i;
                            break;
                        }
                    }
                    if (index == Main.maxItems)
                    {
                        var minTimeDiff = 0;
                        for (var i = 0; i < Main.maxItems; ++i)
                        {
                            var timeDiff = Main.item[i].spawnTime - Main.itemLockoutTime[i];
                            if (timeDiff > minTimeDiff)
                            {
                                minTimeDiff = timeDiff;
                                index       = i;
                            }
                        }
                    }
                    _blacklistedIndexes.Add(index);
                }
            }
            else if (partyMembers.Any(p => p.IsValidMember && p.Player.Index == player.Index))
            {
                var index = args.ID;
                var item  = Main.item[index];
                if (_itemName?.Equals(item.Name, StringComparison.OrdinalIgnoreCase) ?? true)
                {
                    if (_blacklistedIndexes.Contains(index))
                    {
                        _blacklistedIndexes.Remove(index);
                    }
                    else
                    {
                        var difference = item.stack - args.Stacks;
                        _amount = Math.Max(0, _amount - difference);
                    }
                }
            }
        }
Exemplo n.º 3
0
 public static bool IsBannedItem(int ID, out bool Locally)
 {
     lock (Locker)
     {
         if (Locally = ItemBans.TryGetValue(ID, out bool banned))
         {
             return(banned);
         }
         string name = EnglishLanguage.GetItemNameById(ID);
         return(TShock.ItemBans.DataModel.ItemBans.Any(b => (b.Name == name)));
     }
 }
 private static int?GetItemIdFromName(string name)
 {
     for (var i = 0; i < Main.maxItemTypes; ++i)
     {
         var itemName = EnglishLanguage.GetItemNameById(i);
         if (itemName?.Equals(name, StringComparison.OrdinalIgnoreCase) ?? false)
         {
             return(i);
         }
     }
     return(null);
 }
Exemplo n.º 5
0
        /// <summary>
        /// Gets items by name
        /// </summary>
        /// <param name="name">name</param>
        /// <returns>List of Items</returns>
        public List <Item> GetItemByName(string name)
        {
            var    found        = new List <Item>();
            Item   item         = new Item();
            string nameLower    = name.ToLowerInvariant();
            var    checkEnglish = Language.ActiveCulture != GameCulture.FromCultureName(GameCulture.CultureName.English);

            for (int i = 1; i < Main.maxItemTypes; i++)
            {
                item.netDefaults(i);
                if (!String.IsNullOrWhiteSpace(item.Name))
                {
                    if (item.Name.ToLowerInvariant() == nameLower)
                    {
                        return new List <Item> {
                                   item
                        }
                    }
                    ;
                    if (item.Name.ToLowerInvariant().StartsWith(nameLower))
                    {
                        found.Add(item.Clone());
                    }
                }

                if (!checkEnglish)
                {
                    continue;
                }

                string englishName = EnglishLanguage.GetItemNameById(i).ToLowerInvariant();
                if (!String.IsNullOrEmpty(englishName))
                {
                    if (englishName == nameLower)
                    {
                        return new List <Item> {
                                   item
                        }
                    }
                    ;
                    if (englishName.StartsWith(nameLower))
                    {
                        found.Add(item.Clone());
                    }
                }
            }
            return(found);
        }
Exemplo n.º 6
0
 public void Give(Item item, TSPlayer player, int amount = 0, [ItemPrefix] int prefix = 0)
 {
     if (amount == 0 || amount > item.maxStack)
     {
         amount = item.maxStack;
     }
     if (player.GiveItemCheck(item.type, EnglishLanguage.GetItemNameById(item.type), amount, prefix))
     {
         Sender.SendSuccessMessage(string.Format("Gave {0} {1} {2}(s).", player.Name, amount, item.Name));
         player.SendSuccessMessage(string.Format("{0} gave you {1} {2}(s).", Sender.Name, amount, item.Name));
     }
     else
     {
         Fail("You cannot spawn banned items.");
     }
 }
Exemplo n.º 7
0
        internal void OnChestItemChange(object sender, ChestItemEventArgs args)
        {
            Item item = new Item();

            item.netDefaults(args.Type);


            if (DataModel.ItemIsBanned(EnglishLanguage.GetItemNameById(item.type), args.Player))
            {
                SendCorrectiveMessage(args.Player, item.Name);
                args.Handled = true;
                return;
            }

            args.Handled = false;
            return;
        }
Exemplo n.º 8
0
 public static bool RemoveItemBanOverride(int ID, out bool Banned, out bool Whitelist)
 {
     lock (Locker)
     {
         string name = EnglishLanguage.GetItemNameById(ID);
         Banned = TShock.ItemBans.DataModel.ItemBans.Any(b =>
                                                         (!(b is ItemBanOverride) && (b.Name == name)));
         if (ItemBans.TryRemove(ID, out Whitelist))
         {
             Database.RemoveItemBan(ID);
             TShock.ItemBans.DataModel.ItemBans.RemoveAll(b =>
                                                          ((b is ItemBanOverride @override) && (@override.Name == name)));
             return(true);
         }
         return(false);
     }
 }
Exemplo n.º 9
0
        internal void OnTileEdit(object sender, TileEditEventArgs args)
        {
            if (args.Action == EditAction.PlaceTile || args.Action == EditAction.PlaceWall)
            {
                if (args.Player.TPlayer.autoActuator && DataModel.ItemIsBanned("Actuator", args.Player))
                {
                    args.Player.SendTileSquare(args.X, args.Y, 1);
                    args.Player.SendErrorMessage("You do not have permission to place actuators.");
                    args.Handled = true;
                    return;
                }

                if (DataModel.ItemIsBanned(EnglishLanguage.GetItemNameById(args.Player.SelectedItem.netID), args.Player))
                {
                    args.Player.SendTileSquare(args.X, args.Y, 4);
                    args.Handled = true;
                    return;
                }
            }
        }
Exemplo n.º 10
0
        private void OnItemDrop(object sender, GetDataHandlers.ItemDropEventArgs args)
        {
            var player = args.Player;

            if (args.Handled || args.ID != Main.maxItems || partyMembers.All(p => p.Player.Index != player.Index))
            {
                return;
            }

            var itemIdName = EnglishLanguage.GetItemNameById(args.Type);

            if (_itemName?.Equals(itemIdName, StringComparison.OrdinalIgnoreCase) ?? true)
            {
                _amount -= args.Stacks;
                if (_amount < 0)
                {
                    player.GiveItem(args.Type, "", 20, 42, -_amount, args.Prefix);
                    _amount = 0;
                }
                args.Handled = true;
            }
        }
Exemplo n.º 11
0
        internal void OnPlayerUpdate(object sender, PlayerUpdateEventArgs args)
        {
            DisableFlags disableFlags = TShock.Config.Settings.DisableSecondUpdateLogs ? DisableFlags.WriteToConsole : DisableFlags.WriteToLogAndConsole;
            bool         useItem      = args.Control.IsUsingItem;
            TSPlayer     player       = args.Player;
            string       itemName     = player.TPlayer.inventory[args.SelectedItem].Name;

            if (DataModel.ItemIsBanned(EnglishLanguage.GetItemNameById(player.TPlayer.inventory[args.SelectedItem].netID), args.Player))
            {
                player.TPlayer.controlUseItem = false;
                player.Disable($"holding banned item: {itemName}", disableFlags);

                SendCorrectiveMessage(player, itemName);

                player.TPlayer.Update(player.TPlayer.whoAmI);
                NetMessage.SendData((int)PacketTypes.PlayerUpdate, -1, player.Index, NetworkText.Empty, player.Index);

                args.Handled = true;
                return;
            }

            args.Handled = false;
            return;
        }
Exemplo n.º 12
0
        /// <summary>Called by OnGameUpdate once per second to execute tasks regularly but not too often.</summary>
        /// <param name="args">The standard event arguments.</param>
        internal void OnSecondlyUpdate(EventArgs args)
        {
            DisableFlags disableFlags = TShock.Config.Settings.DisableSecondUpdateLogs ? DisableFlags.WriteToConsole : DisableFlags.WriteToLogAndConsole;

            foreach (TSPlayer player in TShock.Players)
            {
                if (player == null || !player.Active)
                {
                    continue;
                }

                // Untaint now, re-taint if they fail the check.
                UnTaint(player);

                // No matter the player type, we do a check when a player is holding an item that's banned.
                if (DataModel.ItemIsBanned(EnglishLanguage.GetItemNameById(player.TPlayer.inventory[player.TPlayer.selectedItem].netID), player))
                {
                    string itemName = player.TPlayer.inventory[player.TPlayer.selectedItem].Name;
                    player.Disable($"holding banned item: {itemName}", disableFlags);
                    SendCorrectiveMessage(player, itemName);
                }

                // If SSC isn't enabled OR if SSC is enabled and the player is logged in
                // In a case like this, we do the full check too.
                if (!Main.ServerSideCharacter || (Main.ServerSideCharacter && player.IsLoggedIn))
                {
                    // The Terraria inventory is composed of a multicultural set of arrays
                    // with various different contents and beliefs

                    // Armor ban checks
                    foreach (Item item in player.TPlayer.armor)
                    {
                        if (DataModel.ItemIsBanned(EnglishLanguage.GetItemNameById(item.type), player))
                        {
                            Taint(player);
                            SendCorrectiveMessage(player, item.Name);
                        }
                    }

                    // Dye ban checks
                    foreach (Item item in player.TPlayer.dye)
                    {
                        if (DataModel.ItemIsBanned(EnglishLanguage.GetItemNameById(item.type), player))
                        {
                            Taint(player);
                            SendCorrectiveMessage(player, item.Name);
                        }
                    }

                    // Misc equip ban checks
                    foreach (Item item in player.TPlayer.miscEquips)
                    {
                        if (DataModel.ItemIsBanned(EnglishLanguage.GetItemNameById(item.type), player))
                        {
                            Taint(player);
                            SendCorrectiveMessage(player, item.Name);
                        }
                    }

                    // Misc dye ban checks
                    foreach (Item item in player.TPlayer.miscDyes)
                    {
                        if (DataModel.ItemIsBanned(EnglishLanguage.GetItemNameById(item.type), player))
                        {
                            Taint(player);
                            SendCorrectiveMessage(player, item.Name);
                        }
                    }
                }
            }

            // Set the update time to now, so that we know when to execute next.
            // We do this at the end so that the task can't re-execute faster than we expected.
            // (If we did this at the start of the method, the method execution would count towards the timer.)
            LastTimelyRun = DateTime.UtcNow;
        }
Exemplo n.º 13
0
 public static string GetItemNameFromId(int type)
 {
     return(EnglishLanguage.GetItemNameById(type));
 }