Esempio n. 1
0
 public PlayerStorage()
 {
     regionStorage = new RegionStorage(region: null, flags: new List<string> { }, healinterval: 2, healamount: 20, manainterval: 2, damageinterval: 2, damageamount: 20, tempgroup: null, bannedItems: new List<string>(), bannedNPCs: new List<int>(), bannedTiles: new List<int>(), bannedProjectiles: new List<int>(), command: null, fromgroup: null, togroup: null, groupOnly: new List<string>(), message: null, effectOwner: false, effectAllowed: true);
     regionWarned = 0;
     lastPos = new Vector2();
     gotWarnMessage = false;
     inEventRegion = false;
     hostile = false;
     killed = false;
     groupset = false;
     executedcommand = false;
     promoted = false;
     gotmessage = false;
     muted = false;
 }
Esempio n. 2
0
        private static void SetFlag(CommandArgs args)
        {
            if (args.Parameters.Count < 3)
            {
                args.Player.SendErrorMessage("Syntax: /re setflag <region> <FLAG>");
                return;
            }

            Region region = TShock.Regions.GetRegionByName(args.Parameters[1]);

            if (region == null)
            {
                args.Player.SendErrorMessage("Could not find region {0}!", args.Parameters[1]);
                return;
            }

            if (!RegionEvent.flagTypes.ContainsKey(args.Parameters[2]))
            {
                args.Player.SendErrorMessage("Error: No such flag type exists!");
                args.Player.SendErrorMessage("Type /re list flags, for a list of available flags!");
                return;
            }

            RegionStorage tempStorage = new RegionStorage(region, new List<string>() { args.Parameters[2] }, healinterval: 20, healamount: 2, manainterval: 2, damageinterval: 2, damageamount: 20, tempgroup: Group.DefaultGroup, bannedItems: new List<string>(), bannedNPCs: new List<int>(), bannedTiles: new List<int>(), bannedProjectiles: new List<int>(), command: "", fromgroup: "", togroup: "", groupOnly: new List<string>(), message: "", effectOwner:false, effectAllowed:true);

            if (RegionEvent.regionStorage.ContainsKey(region))
            {
                tempStorage = RegionEvent.regionStorage[region];

                if (RegionEvent.regionStorage[region].flags.Contains(args.Parameters[2]))
                {
                    args.Player.SendErrorMessage("Region \"{0}\" already contains {1} flag!", region.Name, args.Parameters[1]);
                    return;
                }
            }

            switch (args.Parameters[2])
            {
                case "HEAL":
                    {
                        if (args.Parameters.Count != 5)
                        {
                            args.Player.SendErrorMessage("Syntax: /re setflag <region> HEAL <interval> <amount>");
                            return;
                        }
                        int healinterval = -1;
                        int healamount = -1;
                        if (!int.TryParse(args.Parameters[3], out healinterval))
                        {
                            args.Player.SendErrorMessage("{0} is not a valid number!", args.Parameters[3]);
                            return;
                        }
                        if (!int.TryParse(args.Parameters[4], out healamount))
                        {
                            args.Player.SendErrorMessage("{0} is not a valid number!", args.Parameters[4]);
                            return;
                        }

                        tempStorage.healinterval = healinterval;
                        tempStorage.healamount = healamount;
                        break;
                    }
                case "MANA":
                    {
                        // /re setflag MANA <interval>
                        if (args.Parameters.Count != 4)
                        {
                            args.Player.SendErrorMessage("Syntax: /re setflag <region> MANA <interval>");
                            return;
                        }
                        int interval = -1;
                        if (!int.TryParse(args.Parameters[3], out interval))
                        {
                            args.Player.SendErrorMessage("{0} is not a valid number!", args.Parameters[3]);
                            return;
                        }

                        tempStorage.manainterval = interval;
                        break;
                    }
                case "HURT":
                    {
                        if (args.Parameters.Count != 5)
                        {
                            args.Player.SendErrorMessage("Syntax: /re setflag <region> HURT <interval> <amount>");
                            return;
                        }
                        int interval = -1;
                        int amount = -1;
                        if (!int.TryParse(args.Parameters[3], out interval))
                        {
                            args.Player.SendErrorMessage("{0} is not a valid number!", args.Parameters[3]);
                            return;
                        }
                        if (!int.TryParse(args.Parameters[4], out amount))
                        {
                            args.Player.SendErrorMessage("{0} is not a valid number!", args.Parameters[4]);
                            return;
                        }

                        tempStorage.damageinterval = interval;
                        tempStorage.damageamount = amount;
                        break;
                    }
                case "TEMPGROUP":
                    {
                        if (args.Parameters.Count != 4)
                        {
                            args.Player.SendErrorMessage("Syntax: /re setflag <region> TEMPGROUP <group>");
                            return;
                        }

                        Group tempgroup = TShock.Groups.GetGroupByName(args.Parameters[3]);
                        if (tempgroup == null)
                        {
                            args.Player.SendErrorMessage("Could not find group!");
                            return;
                        }
                        tempStorage.tempgroup = tempgroup;

                        break;
                    }
                case "COMMAND":
                    {
                        if (args.Parameters.Count != 4)
                        {
                            args.Player.SendErrorMessage("Syntax: /re setflag <region> COMMAND <command>");
                            return;
                        }
                        //check if they have permission for command
                        if (args.Parameters[3] != null && args.Parameters[3] != "")
                        tempStorage.command = args.Parameters[3];
                        break;
                    }
                case "PROMOTE":
                    {
                        if (args.Parameters.Count != 5)
                        {
                            args.Player.SendErrorMessage("Syntax: /re setflag <region> PROMOTE <fromgroup> <togroup>");
                            return;
                        }
                        Group fromgroup = TShock.Groups.GetGroupByName(args.Parameters[3]);
                        Group togroup = TShock.Groups.GetGroupByName(args.Parameters[4]);

                        if (fromgroup == null && args.Parameters[3] != "*")
                        {
                            args.Player.SendErrorMessage("Could not find fromgroup {0}!", args.Parameters[3]);
                            return;
                        }
                        if (togroup == null)
                        {
                            args.Player.SendErrorMessage("Could not find togroup {0}!", args.Parameters[4]);
                            return;
                        }
                        tempStorage.fromgroup = args.Parameters[3];
                        tempStorage.togroup = togroup.Name;
                        break;
                    }
                case "BANITEM":
                    {
                        if (args.Parameters.Count != 4)
                        {
                            args.Player.SendErrorMessage("Syntax: /re setflag <region> BANITEM <ID/Name>");
                            return;
                        }
                        List<Item> item = TShock.Utils.GetItemByIdOrName(args.Parameters[3]);
                        if (item.Count == 0)
                        {
                            args.Player.SendErrorMessage("Could not find item \"{0}\"!", args.Parameters[3]);
                            return;
                        }
                        else if (item.Count > 1)
                        {
                            TShock.Utils.SendMultipleMatchError(args.Player, item);
                            return;
                        }

                        tempStorage.bannedItems.Add(item[0].name);

                        break;
                    }
                case "BANTILE":
                    {
                        if (args.Parameters.Count != 4)
                        {
                            args.Player.SendErrorMessage("Syntax: /re setflag <region> BANTILE <ID>");
                            return;
                        }
                        int ID = -1;
                        if (!int.TryParse(args.Parameters[3], out ID) || ID < 0 || ID >= Main.maxTileSets)
                        {
                            args.Player.SendErrorMessage("{0} is not a valid number!", args.Parameters[3]);
                            return;
                        }
                        tempStorage.bannedTiles.Add(ID);

                        break;
                    }
                case "BANPROJ":
                    {
                        if (args.Parameters.Count != 4)
                        {
                            args.Player.SendErrorMessage("Syntax: /re setflag <region> BANPROJ <ID>");
                            return;
                        }
                        int ID = -1;
                        if (!int.TryParse(args.Parameters[3], out ID) || ID < 0 || ID >= Main.maxProjectileTypes)
                        {
                            args.Player.SendErrorMessage("{0} is not a valid number!", args.Parameters[3]);
                            return;
                        }
                        tempStorage.bannedProjectiles.Add(ID);

                        break;
                    }
                case "BANMOB":
                    {
                        if (args.Parameters.Count != 4)
                        {
                            args.Player.SendErrorMessage("Syntax: /re setflag <region> BANMOB <ID>");
                            return;
                        }
                        int ID = -1;
                        if (!int.TryParse(args.Parameters[3], out ID) || ID < 0 || ID >= Main.maxNPCTypes)
                        {
                            args.Player.SendErrorMessage("{0} is not a valid number!", args.Parameters[3]);
                            return;
                        }
                        tempStorage.bannedNPCs.Add(ID);

                        break;

                    }
                case "GROUPONLY":
                    {
                        if (args.Parameters.Count != 4)
                        {
                            args.Player.SendErrorMessage("Syntax: /re setflag <region> GROUPONLY <group>");
                            return;
                        }

                        Group grouponly = TShock.Groups.GetGroupByName(args.Parameters[3]);
                        if (grouponly == null)
                        {
                            args.Player.SendErrorMessage("Could not find group!");
                            return;
                        }
                        tempStorage.groupOnly.Add(grouponly.Name);
                        break;
                    }
                case "MESSAGE":
                    {
                        if (args.Parameters.Count != 4)
                        {
                            args.Player.SendErrorMessage("Syntax: /re setflag <region> MESSAGE <message>");
                            return;
                        }
                        if (args.Parameters[3] != null && args.Parameters[3] != "")
                            tempStorage.message = args.Parameters[3];

                        break;
                    }
                default:
                    break;
            }

            if (!RegionEvent.regionStorage.ContainsKey(region))
            {
                RegionEvent.regionStorage.Add(region, tempStorage);

                string flags = JsonConvert.SerializeObject(RegionEvent.regionStorage[region].flags, Formatting.Indented);
                string bannedItems = JsonConvert.SerializeObject(RegionEvent.regionStorage[region].bannedItems, Formatting.Indented);
                string bannedNPCs = JsonConvert.SerializeObject(RegionEvent.regionStorage[region].bannedNPCs, Formatting.Indented);
                string bannedTiles = JsonConvert.SerializeObject(RegionEvent.regionStorage[region].bannedTiles, Formatting.Indented);
                string bannedProjectiles = JsonConvert.SerializeObject(RegionEvent.regionStorage[region].bannedProjectiles, Formatting.Indented);

                int a = -1;
                string query = "INSERT INTO RegionEvent (Name, Flags, HealInterval, HealAmount, ManaInterval, DamageInterval, DamageAmount, TempGroup, BannedItems, BannedNPCs, BannedTiles, BannedProjectiles, Command, FromGroup, ToGroup, Message, EffectOwner, EffectAllowed) VALUES (@0, @1, @2, @3, @4, @5, @6, @7, @8, @9, @10, @11, @12, @13, @14, @15, @16, @17)";
                a = RegionEvent.db.Query(query, region.Name, flags, tempStorage.healinterval, tempStorage.healamount, tempStorage.manainterval, tempStorage.damageinterval, tempStorage.damageamount, tempStorage.tempgroup.Name, bannedItems, bannedNPCs, bannedTiles, bannedProjectiles, tempStorage.command, tempStorage.fromgroup, tempStorage.togroup, tempStorage.message, tempStorage.effectOwner ? 1 : 0, tempStorage.effectAllowed ? 1 : 0);
                if (a < 0)
                {
                    RegionEvent.regionStorage[region].flags.Remove(args.Parameters[2]);
                    args.Player.SendErrorMessage("Failed to save to DB!");
                    return;
                }
                args.Player.SendSuccessMessage("Added flag {0} to region \"{1}\"!", args.Parameters[2], region.Name);
            }
            else
            {
                tempStorage.flags.Add(args.Parameters[2]);

                string flags = JsonConvert.SerializeObject(tempStorage.flags, Formatting.Indented);
                string bannedItems = JsonConvert.SerializeObject(tempStorage.bannedItems, Formatting.Indented);
                string bannedNPCs = JsonConvert.SerializeObject(tempStorage.bannedNPCs, Formatting.Indented);
                string bannedTiles = JsonConvert.SerializeObject(tempStorage.bannedTiles, Formatting.Indented);

                int a = -1;
                string query = "UPDATE RegionEvent SET `Flags`=@0, `HealInterval`=@1, HealAmount=@2, ManaInterval=@3, DamageInterval=@4, DamageAmount=@5, TempGroup=@6, BannedItems=@7, BannedNPCs=@8, BannedTiles=@9, BannedProjectiles=10, Command=@10, FromGroup=@11, ToGroup=@12, Message=@14, EffectOwner=@15, EffectAllowed=@16 WHERE Name=@17";
                a = RegionEvent.db.Query(query, flags, tempStorage.healinterval, tempStorage.healamount, tempStorage.manainterval, tempStorage.damageinterval, tempStorage.damageamount, tempStorage.tempgroup.Name, bannedItems, bannedNPCs, bannedTiles, tempStorage.command, tempStorage.fromgroup, tempStorage.togroup, tempStorage.message, tempStorage.effectOwner ? 1 : 0, tempStorage.effectAllowed ? 1 : 0, region.Name);
                if (a < 0)
                {
                    args.Player.SendErrorMessage("Failed to save to DB!");
                    return;
                }

                RegionEvent.regionStorage[region] = tempStorage;
                args.Player.SendSuccessMessage("Added flag {0} to region \"{1}\"!", args.Parameters[2], region.Name);
            }
        }