コード例 #1
0
ファイル: Permabuffs.cs プロジェクト: newyrose/PermabuffsV2
        private void PBuffs(CommandArgs args)
        {
            if (config.buffgroups.Length == 0)
            {
                args.Player.SendErrorMessage("Your server administrator has not defined any buff groups. Please contact an admin to fix this issue.");
                return;
            }

            List <BuffGroup> availableBuffGroups = config.buffgroups.Where(e => args.Player.HasPermission($"pb.{e.groupPerm}") || args.Player.HasPermission("pb.useall")).ToList();

            int bufftype = -1;

            if (args.Parameters.Count == 0)
            {
                args.Player.SendErrorMessage("Invalid syntax: {0}permabuff <buff name or ID>", (args.Silent ? TShock.Config.CommandSilentSpecifier : TShock.Config.CommandSpecifier));
                return;
            }

            string buff = string.Join(" ", args.Parameters);

            // Get buff type by name
            if (!int.TryParse(args.Parameters[0], out bufftype))
            {
                List <int> bufftypelist = TShock.Utils.GetBuffByName(buff);

                if (bufftypelist.Count < 1)
                {
                    args.Player.SendErrorMessage("No buffs by that name were found.");
                    return;
                }
                else if (bufftypelist.Count > 1)
                {
                    TShock.Utils.SendMultipleMatchError(args.Player, bufftypelist.Select(p => TShock.Utils.GetBuffName(p)));
                    return;
                }
                else
                {
                    bufftype = bufftypelist[0];
                }
            }
            else if (bufftype > Main.maxBuffTypes || bufftype < 1)             // Buff ID is not valid (less than 1 or higher than 206 (1.3.5.3)).
            {
                args.Player.SendErrorMessage("Invalid buff ID!");
            }


            int playerid = args.Player.User.ID;

            availableBuffGroups.RemoveAll(e => !e.buffIDs.Contains(bufftype));

            if (availableBuffGroups.Count == 0)
            {
                args.Player.SendErrorMessage("You do not have access to this permabuff!");
                return;
            }

            if (DB.PlayerBuffs[playerid].bufflist.Contains(bufftype))
            {
                DB.PlayerBuffs[playerid].bufflist.Remove(bufftype);
                DB.UpdatePlayerBuffs(playerid, DB.PlayerBuffs[playerid].bufflist);
                args.Player.SendInfoMessage("You have removed the " + TShock.Utils.GetBuffName(bufftype) + " permabuff.");
                return;
            }

            if (bufftype.IsPermanent())
            {
                DB.PlayerBuffs[playerid].bufflist.Add(bufftype);
                DB.UpdatePlayerBuffs(playerid, DB.PlayerBuffs[playerid].bufflist);
                args.Player.SendSuccessMessage($"You have permabuffed yourself with the {TShock.Utils.GetBuffName(bufftype)} buff! Re-type this command to disable the buff.");
            }
            else
            {
                args.Player.SetBuff(bufftype);
                args.Player.SendSuccessMessage($"You have given yourself the {TShock.Utils.GetBuffName(bufftype)} buff.");
            }
        }
コード例 #2
0
ファイル: Permabuffs.cs プロジェクト: newyrose/PermabuffsV2
        private void PBGive(CommandArgs args)
        {
            if (config.buffgroups.Length == 0)
            {
                args.Player.SendErrorMessage("Your server administrator has not defined any buff groups. Please contact an admin to fix this issue.");
                return;
            }

            List <BuffGroup> availableBuffGroups = config.buffgroups.Where(e => args.Player.HasPermission($"pb.{e.groupPerm}") || args.Player.HasPermission("pb.useall")).ToList();

            if (args.Parameters.Count == 2)
            {
                // /gpermabuffs -g list
                if (args.Parameters[0].Equals("-g", StringComparison.CurrentCultureIgnoreCase) && args.Parameters[1].Equals("list", StringComparison.CurrentCultureIgnoreCase))
                {
                    args.Player.SendInfoMessage($"Available buff groups: {string.Join(", ", availableBuffGroups.Select(e => e.groupName))}");
                    return;
                }

                // Get player id from args.Parameters[1]
                string          playername = args.Parameters[1];
                List <TSPlayer> players    = TShock.Utils.FindPlayer(playername);
                if (players.Count < 1)
                {
                    args.Player.SendErrorMessage("No players found.");
                    return;
                }
                else if (players.Count > 1)
                {
                    TShock.Utils.SendMultipleMatchError(args.Player, players.Select(p => p.Name));
                    return;
                }
                else if (!players[0].IsLoggedIn)
                {
                    args.Player.SendErrorMessage("This player cannot receive permabuffs!");
                    return;
                }
                int playerid = players[0].User.ID;

                //Get buff name/id from args.Parameters[0]
                string buff = args.Parameters[0];
                if (!int.TryParse(args.Parameters[0], out int bufftype))
                {
                    List <int> bufftypelist = new List <int>();
                    bufftypelist = TShock.Utils.GetBuffByName(buff);

                    if (bufftypelist.Count < 1)
                    {
                        args.Player.SendErrorMessage("No buffs by that name were found.");
                        return;
                    }
                    else if (bufftypelist.Count > 1)
                    {
                        TShock.Utils.SendMultipleMatchError(args.Player, bufftypelist.Select(p => TShock.Utils.GetBuffName(p)));
                        return;
                    }
                    else
                    {
                        bufftype = bufftypelist[0];
                    }
                }
                else if (bufftype > Main.maxBuffTypes || bufftype < 1)                 // Buff ID is not valid (less than 1 or higher than 192 (1.3.1)).
                {
                    args.Player.SendErrorMessage("Invalid buff ID!");
                }

                //Removes all groups where the buff isn't included, leaving only a list of groups where player has access AND contains the buff
                availableBuffGroups.RemoveAll(e => !e.buffIDs.Contains(bufftype));

                if (availableBuffGroups.Count == 0)
                {
                    args.Player.SendErrorMessage("You do not have access to this permabuff!");
                    return;
                }

                if (DB.PlayerBuffs[playerid].bufflist.Contains(bufftype))
                {
                    DB.PlayerBuffs[playerid].bufflist.Remove(bufftype);
                    DB.UpdatePlayerBuffs(playerid, DB.PlayerBuffs[playerid].bufflist);
                    args.Player.SendInfoMessage($"You have removed the {TShock.Utils.GetBuffName(bufftype)} permabuff for {players[0].Name}.");
                    if (!args.Silent)
                    {
                        players[0].SendInfoMessage($"{args.Player.Name} has removed your {TShock.Utils.GetBuffName(bufftype)} permabuff.");
                    }
                }
                else if (bufftype.IsPermanent())
                {
                    DB.PlayerBuffs[playerid].bufflist.Add(bufftype);
                    DB.UpdatePlayerBuffs(playerid, DB.PlayerBuffs[playerid].bufflist);
                    args.Player.SendSuccessMessage($"You have permabuffed {players[0].Name} with the {TShock.Utils.GetBuffName(bufftype)} buff!");
                    if (!args.Silent)
                    {
                        players[0].SendInfoMessage($"{args.Player.Name} has permabuffed you with the {TShock.Utils.GetBuffName(bufftype)} buff!");
                    }
                }
                else
                {
                    args.Player.SetBuff(bufftype);
                    args.Player.SendSuccessMessage($"You have given {players[0].Name} the {TShock.Utils.GetBuffName(bufftype)} buff!");
                    if (!args.Silent)
                    {
                        players[0].SendInfoMessage($"{args.Player.Name} has given you the {TShock.Utils.GetBuffName(bufftype)} buff!");
                    }
                }
            }
            //gpermabuff -g <group> <player>
            else if (args.Parameters.Count == 3)
            {
                if (args.Parameters[0] != "-g")
                {
                    args.Player.SendErrorMessage("Invalid syntax:");
                    args.Player.SendErrorMessage("{0}gpermabuff <buff name or ID> <player>", TShock.Config.CommandSpecifier);
                    args.Player.SendErrorMessage("{0}gpermabuff -g <buff group> <player>", TShock.Config.CommandSpecifier);
                }

                var matchedPlayers = TShock.Utils.FindPlayer(args.Parameters[2]);

                if (matchedPlayers.Count == 0)
                {
                    args.Player.SendErrorMessage($"No players found by the name: {args.Parameters[2]}");
                    return;
                }
                else if (matchedPlayers.Count > 1)
                {
                    TShock.Utils.SendMultipleMatchError(args.Player, matchedPlayers.Select(p => p.Name));
                    return;
                }
                else if (!matchedPlayers[0].IsLoggedIn)
                {
                    args.Player.SendErrorMessage("This player cannot receive permabuffs!");
                    return;
                }
                else if (!availableBuffGroups.Any(e => e.groupName.Equals(args.Parameters[1], StringComparison.CurrentCultureIgnoreCase)))
                {
                    args.Player.SendErrorMessage("No buffgroups matched your query!");
                }

                TSPlayer player = matchedPlayers[0];
                int      id     = matchedPlayers[0].User.ID;

                foreach (var buff in availableBuffGroups.First(e => e.groupName.Equals(args.Parameters[1], StringComparison.CurrentCultureIgnoreCase)).buffIDs)
                {
                    if (!DB.PlayerBuffs[id].bufflist.Contains(buff) && buff.IsPermanent())
                    {
                        DB.PlayerBuffs[id].bufflist.Add(buff);
                    }
                }
                DB.UpdatePlayerBuffs(id, DB.PlayerBuffs[id].bufflist);

                args.Player.SendSuccessMessage($"Successfully permabuffed {player.Name} with all of the buffs in the group {args.Parameters[1]}!");

                if (!args.Silent)
                {
                    args.Player.SendInfoMessage($"{args.Player.Name} has permabuffed you with all of the buffs in the group {args.Parameters[1]}!");
                }
            }
            else
            {
                args.Player.SendErrorMessage("Invalid syntax:");
                args.Player.SendErrorMessage("{0}gpermabuff <buff name or ID> <player>", TShock.Config.CommandSpecifier);
                args.Player.SendErrorMessage("{0}gpermabuff -g <buff group> <player>", TShock.Config.CommandSpecifier);
                return;
            }
        }
コード例 #3
0
ファイル: Permabuffs.cs プロジェクト: newyrose/PermabuffsV2
 public void OnAccDelete(AccountDeleteEventArgs args)
 {
     DB.ClearPlayerBuffs(args.User.ID);
 }