Пример #1
0
        public bool CheckFinishedModifications(short id)
        {
            if (CheckItem(id) || _player == null)
            {
                SSCUtils.FillInventory(_player, Constants.JunkItem, Constants.EmptyItem);
                LockModifications     = false;
                OnPvPInventoryChecked = true;
                Clear();
                return(true);
            }

            return(false);
        }
Пример #2
0
    public static List <Arrow> ProcessGameRow(string data)
    {
        List <Arrow> list   = new List <Arrow>();
        var          arrays = data.Replace("\n", "").Replace("\r", "").ToCharArray();

        foreach (var character in arrays)
        {
            list.Add(new Arrow()
            {
                Type = SSCUtils.CharToNote(character)
            });
        }
        return(list);
    }
Пример #3
0
        /// <summary>
        /// Handles player updates.
        /// </summary>
        private void OnPlayerUpdate(object sender, PlayerUpdateArgs e)
        {
            if (!PvPModifier.Config.EnablePlugin)
            {
                return;
            }
            if (e.Player.TPlayer.dead)
            {
                return;
            }

            //If the player has their pvp turned on without sending a TogglePvP packet (ex. through a /pvp command),
            //The plugin will detect it here and send the modified items.
            if (e.Player.TPlayer.hostile && !e.Player.InvTracker.StartForcePvPInventoryCheck)
            {
                e.Player.InvTracker.StartForcePvPInventoryCheck = true;
                PvPUtils.SendCustomItems(e.Player);
            }

            if (!e.Player.TPlayer.hostile && e.Player.InvTracker.StartForcePvPInventoryCheck)
            {
                PvPUtils.RefreshInventory(e.Player);
                e.Player.InvTracker.Clear();
                e.Player.InvTracker.StartForcePvPInventoryCheck = false;
            }

            //If the player tries to use a modified item in their hand, it will be dumped back into their inventory
            if ((e.PlayerAction & 32) == 32)
            {
                if (e.Player.TPlayer.hostile)
                {
                    Item item = e.Player.TPlayer.inventory[58];

                    if (item.netID != 0 && PvPUtils.IsModifiedItem(item.netID) && e.Player.CanModInventory())
                    {
                        SSCUtils.SetItem(e.Player, 58, 0);
                        CustomWeaponDropper.DropItem(e.Player, new CustomWeapon {
                            ItemNetId     = (short)item.netID, Prefix = item.prefix, Stack = (short)item.stack,
                            DropAreaWidth = short.MaxValue, DropAreaHeight = short.MaxValue
                        });
                        e.Player.SendErrorMessage("You cannot use this weapon in your hand!");
                    }
                }
            }
        }
Пример #4
0
        /// <summary>
        /// Replaces items placed into the inventory into the pvp versions.
        /// </summary>
        private void CheckIncomingItems(object sender, PlayerSlotArgs e)
        {
            if (!PvPModifier.Config.EnablePlugin)
            {
                return;
            }

            if (!e.Player.TPlayer.hostile)
            {
                return;
            }
            if (e.SlotId >= 58)
            {
                return;
            }

            //Only runs after initial pvp check
            if (e.Player.InvTracker.OnPvPInventoryChecked)
            {
                if (e.Player.InvTracker.LockModifications)
                {
                    return;
                }

                //If the item is being consumed, don't modify the item
                if (Math.Abs(e.Player.TPlayer.inventory[e.SlotId].stack - e.Stack) <= 1 &&
                    e.Player.TPlayer.inventory[e.SlotId].netID == e.NetID)
                {
                    return;
                }

                //If the item is modified, fill empty spaces and add it to queue
                if (PvPUtils.IsModifiedItem(e.NetID))
                {
                    SSCUtils.FillInventoryToIndex(e.Player, Constants.EmptyItem, Constants.JunkItem, e.SlotId);
                    SSCUtils.SetItem(e.Player, e.SlotId, Constants.EmptyItem);
                    e.Player.InvTracker.AddItem(PvPUtils.GetCustomWeapon(e.Player, e.NetID, e.Prefix, e.Stack));
                    e.Player.InvTracker.StartDroppingItems();
                }
            }
        }
Пример #5
0
        private static void ModPvP(CommandArgs args)
        {
            var      player   = args.Player;
            var      input    = args.Parameters;
            int      id       = -1;
            DbObject dbObject = null;

            if (input.Count < 1 || !StringConsts.TryGetSectionFromString(input[0], out var section))
            {
                player.SendErrorMessage(HelpModPvP);
                return;
            }

            if (section == StringConsts.Help)
            {
                if (input.Count > 1)
                {
                    StringConsts.TryGetSectionFromString(input[1], out var helpsection);

                    switch (helpsection)
                    {
                    case StringConsts.Database:
                        player.SendMessage(DatabaseAttributes, Color.Yellow);
                        return;

                    case StringConsts.Config:
                        player.SendMessage(ConfigAttributes, Color.Yellow);
                        return;

                    default:
                        player.SendErrorMessage(InvalidSyntax + AttributesHelp);
                        return;
                    }
                }

                player.SendErrorMessage(AttributesHelp);
                return;
            }

            if (section != StringConsts.Config)
            {
                if (input.Count < 3)
                {
                    player.SendErrorMessage(HelpModPvP);
                    return;
                }

                if (!int.TryParse(input[1], out id))
                {
                    var foundItems = TShock.Utils.GetIdFromInput(section, input[1]);
                    if (foundItems.Count == 1)
                    {
                        id = foundItems[0];
                    }
                    else if (foundItems.Count > 1)
                    {
                        player.SendErrorMessage("Found Multiple items");
                        foreach (int item in foundItems)
                        {
                            player.SendMessage($"({item}) {MiscUtils.GetNameFromInput(section, item)}", Color.Yellow);
                        }
                        return;
                    }
                    else
                    {
                        player.SendErrorMessage(NothingFoundError);
                        return;
                    }
                }

                dbObject = Cache.GetSection(section, id);
                if (dbObject == null)
                {
                    player.SendErrorMessage(NothingFoundError);
                    return;
                }

                if (input.Count < 4)
                {
                    player.SendErrorMessage(InvalidSyntax + "Please enter value(s) for the attribute(s).");
                    return;
                }
            }
            else
            {
                if (input.Count < 3)
                {
                    player.SendErrorMessage(HelpModPvP);
                    return;
                }
            }

            var pairedInputs = MiscUtils.SplitIntoPairs(input.Skip((section != StringConsts.Config).ToInt() + 1).ToArray());

            foreach (var pair in pairedInputs)
            {
                var attribute = "";
                if (section != StringConsts.Config)
                {
                    StringConsts.TryGetDatabaseAttributeFromString(pair[0], out attribute);
                }
                else
                {
                    StringConsts.TryGetConfigValueFromString(pair[0], out attribute);
                }

                pair[0] = attribute;
            }

            switch (section)
            {
            case DbTables.ItemTable:
            case DbTables.ProjectileTable:
            case DbTables.BuffTable:
                string name = MiscUtils.GetNameFromInput(section, id);
                player.SendMessage($"Modifying {name} ({id})", Color.Green);

                foreach (var pair in pairedInputs)
                {
                    if (dbObject.TrySetValue(pair[0], pair[1]))
                    {
                        player.SendMessage($"Set {pair[0]} to {pair[1]}", Color.YellowGreen);
                        if (args.Silent)
                        {
                            PvPModifier.Webhook.Send(player.Account.Name, section, name, pair[0], pair[1]);
                        }
                    }
                    else
                    {
                        player.SendErrorMessage(InvalidValue(pair[0], section));
                    }
                }

                if (dbObject is DbItem)
                {
                    foreach (var pvper in PvPModifier.ActivePlayers)
                    {
                        if (!pvper.TPlayer.hostile)
                        {
                            continue;
                        }

                        int itemindex = pvper.TPlayer.FindItem(id);
                        if (itemindex != -1)
                        {
                            SSCUtils.FillInventoryToIndex(pvper, 0, Constants.JunkItem, itemindex);
                            var item = pvper.TPlayer.inventory[itemindex];
                            SSCUtils.SetItem(pvper, (byte)itemindex, 0);
                            pvper.InvTracker.AddItem(PvPUtils.GetCustomWeapon(pvper, id, item.prefix, (short)item.stack));
                        }
                        pvper.InvTracker.StartDroppingItems();
                    }
                }

                break;

            case StringConsts.Config:
                foreach (var pair in pairedInputs)
                {
                    if (MiscUtils.SetValueWithString(PvPModifier.Config, pair[0], pair[1]))
                    {
                        player.SendSuccessMessage($"Set {pair[0]} to {pair[1]}");
                    }
                    else
                    {
                        player.SendErrorMessage(ConfigValueFail(pair[0], pair[1]));
                    }
                }

                PvPModifier.Config.Write(Config.ConfigPath);
                break;

            default:
                player.SendErrorMessage(HelpModPvP);
                return;
            }
        }