Example #1
0
        public override void OnDisable()
        {
            if (!enable)
            {
                return;
            }

            Instance = null;
            Events.TeamRespawnEvent        -= LocalEvents.TeamRespawnEvent;
            Events.ConsoleCommandEvent     -= LocalEvents.OnCallCommand;
            Events.WaitingForPlayersEvent  -= LocalEvents.OnWaitingForPlayers;
            Events.RemoteAdminCommandEvent -= CommandEvents.OnRACommand;
        }
Example #2
0
        public override void OnEnable()
        {
            enable = Config.GetBool("mtfp_enable", true);
            if (!enable)
            {
                return;
            }
            RNG           = new Random();
            Configs       = MTFPConfigs.ReloadConfigs();
            LocalEvents   = new MTFPEvents(this);
            CommandEvents = new MTFPlusCommands(this);

            if (this.Configs.debug)
            {
                DebugMessage("MTFPlus loaded in Debug Mode. The console will get spammed as hell.");
            }
            Instance = this;
            Events.TeamRespawnEvent        += LocalEvents.TeamRespawnEvent;
            Events.ConsoleCommandEvent     += LocalEvents.OnCallCommand;
            Events.WaitingForPlayersEvent  += LocalEvents.OnWaitingForPlayers;
            Events.RemoteAdminCommandEvent += CommandEvents.OnRACommand;
        }
Example #3
0
 public MTFPlusCommands(MTFplus plugin)
 {
     this.plugin = plugin;
 }
Example #4
0
 public MTFPEvents(MTFplus plugin)
 {
     this.plugin = plugin;
 }
Example #5
0
        public static int LoadClasses(MTFplus plugin = null)
        {
            bool   verbose         = plugin != null;
            int    SuccessfulCount = 0;
            string directory       = FileManager.GetAppFolder() + @"MTFplus";

            MTFplus.computedSubclasses = string.Empty;
            MTFplus.subclasses.Clear();
            if (!Directory.Exists(directory))
            {
                Directory.CreateDirectory(directory);
                File.WriteAllText(directory + @"/medic.txt",
                                  "Inventory: KeycardSeniorGuard, GunProject90, Radio, Disarmer, Medkit, Medkit, Medkit, Medkit\n" +
                                  "Max: 2\n" +
                                  "Role: NtfCadet\n" +
                                  "Probability: 80\n" +
                                  "Ammo5: 200\n" +
                                  "Ammo7: 70\n" +
                                  "Ammo9: 50");
                if (verbose)
                {
                    plugin.DebugMessage("Created " + directory + ". Fill it with your own MTF classes!\nAdditionally, a template class (Medic) was created with it");
                }
            }
            string[] filenames = Directory.GetFiles(directory, "*.txt");
            foreach (string filename in filenames)
            {
                string name = filename.Remove(0, directory.Length + 1);
                if (verbose)
                {
                    plugin.DebugMessage("Fetching " + name + "...");
                }
                string[] lines = FileManager.ReadAllLines(filename).Where(x => !string.IsNullOrWhiteSpace(x)).Where(x => x[0] != '#').ToArray();

                // Default values
                RoleType role        = RoleType.NtfCadet;
                int      maxCount    = 1;
                float    probability = 100f;

                List <ItemType> inventory   = new List <ItemType>();
                int[]           IMinventory = new int[16];
                for (int i = 0; i < 16; i++)
                {
                    IMinventory[i] = -1;
                }
                int HP = 0;

                int[] ammo = new int[3] {
                    0, 0, 0
                };
                string broadcast = string.Empty;
                foreach (string data in lines)
                {
                    if (data.StartsWith("Inventory"))
                    {
                        string[] invData = data.Remove(0, 10).Split(',');
                        for (int i = 0, j = 0; i < invData.Length; i++, j++)
                        {
                            string item = invData[i].Trim();
#if ItemManager
                            if (item.StartsWith("IM:"))
                            {
                                if (int.TryParse(item.Substring(3), out int aux))
                                {
                                    try
                                    {
                                        if (ItemManagerExists(aux))
                                        {
                                            IMinventory[j] = aux;
                                            inventory.Add(ItemType.COIN);
                                        }
                                        else
                                        {
                                            if (verbose)
                                            {
                                                plugin.Error("Custom item (ItemManager) with ID: " + aux + " doesn't exist/isn't installed!");
                                            }
                                            j--;
                                        }
                                    }
                                    catch (Exception e)
                                    {
                                        if (verbose)
                                        {
                                            plugin.Error("ItemManager not found or threw an error!\n" + e);
                                        }
                                    }
                                }
                                else
                                {
                                    if (verbose)
                                    {
                                        plugin.Error("Invalid CustomItem \"" + item + " (" + item.Substring(3) + ")" + "\" in " + filename + "!");
                                    }
                                }
                                continue;
                            }
#endif
                            if (Enum.TryParse(item, out ItemType parsedItem))
                            {
                                inventory.Add(parsedItem);
                            }
                            else if (Enum.TryParse(item, out SMod2ItemType smod2Item))
                            {
                                inventory.Add((ItemType)smod2Item);
                            }
                            else
                            {
                                if (verbose)
                                {
                                    plugin.DebugMessage("[ERROR] Invalid item \"" + item + "\" in " + filename + '!');
                                }
                            }
                        }
                        if (inventory.Count == 0 && IMinventory.Length == 0)
                        {
                            if (verbose)
                            {
                                plugin.DebugMessage("[WARNING] \"" + filename + "\" doesn't have any valid items. Are you sure this is intended?");
                            }
                        }
                    }
                    else if (data.StartsWith("Role"))
                    {
                        string roleData = data.Remove(0, 5).Trim();
                        if (Enum.TryParse(roleData, out RoleType roleParsed))
                        {
                            role = roleParsed;
                        }
                        else if (Enum.TryParse(roleData, out SMod2RoleType smod2Role))
                        {
                            role = (RoleType)smod2Role;
                        }
                        else
                        {
                            if (verbose)
                            {
                                plugin.DebugMessage("[ERROR] Invalid role \"" + roleData + "\" in " + filename + '!');
                            }
                        }
                    }
                    else if (data.StartsWith("Max"))
                    {
                        string maxData = data.Remove(0, 4).Trim();
                        if (!int.TryParse(maxData, out int probablyMaxCount))
                        {
                            if (verbose)
                            {
                                plugin.DebugMessage("[ERROR] Invalid maximum count \"" + maxData + "\" in " + filename + '!');
                            }
                        }
                        else
                        {
                            maxCount = probablyMaxCount;
                        }
                    }
                    else if (data.StartsWith("Probability"))
                    {
                        string prob = data.Remove(0, 12).Trim();
                        if (!float.TryParse(prob, out float probabilitey))
                        {
                            if (verbose)
                            {
                                plugin.DebugMessage("[ERROR] Invalid probability \"" + prob + "\" in " + filename + '!');
                            }
                        }
                        else
                        {
                            probability = probabilitey;
                        }
                    }
                    else if (data.StartsWith("Ammo"))
                    {
                        if (!int.TryParse(data[4].ToString(), out int ammoTyperino))
                        {
                            if (verbose)
                            {
                                plugin.DebugMessage("[ERROR] \"Ammo\" \"" + data + "\" unrecognized in " + filename + '!');
                            }
                        }
                        int ammoType = (ammoTyperino - 5) / 2;
                        if (ammoType < 0 || ammoType > 2)
                        {
                            if (verbose)
                            {
                                plugin.DebugMessage("[ERROR] " + data[4].ToString() + " is not a type of ammo! (in line: " + data + " in " + filename);
                            }
                        }
                        string ammoStr = data.Remove(0, 6).Trim();
                        if (!int.TryParse(ammoStr, out int parsedAmmo))
                        {
                            if (verbose)
                            {
                                plugin.DebugMessage("[ERROR] Invalid Ammo \"" + ammoStr + "\" in " + filename + '!');
                            }
                        }
                        else
                        {
                            ammo[ammoType] = parsedAmmo;
                        }
                    }
                    else if (data.StartsWith("Broadcast"))
                    {
                        broadcast = data.Remove(0, 10).Trim();
                    }
                    else if (data.StartsWith("HP"))
                    {
                        string HPstr = data.Substring(3).Trim();
                        if (!int.TryParse(HPstr, out int HPaux))
                        {
                            if (verbose)
                            {
                                plugin.DebugMessage("[ERROR] Invalid HP \"" + HPstr + "\" in " + filename + '!');
                            }
                        }
                        else
                        {
                            HP = HPaux;
                        }
                    }
                    else
                    {
                        if (verbose)
                        {
                            plugin.DebugMessage("[ERROR] Unknown line: " + data + " in file " + filename);
                        }
                    }
                }
                name = name.Substring(0, name.Length - 4);
                Subclass subclass = new Subclass(name, role, inventory, IMinventory, probability, ammo, broadcast, HP);
                for (int i = 0; i < maxCount; i++)
                {
                    MTFplus.subclasses.Add(subclass);
                }
                MTFplus.disctinctSubclasses.Add(subclass);

                if (verbose)
                {
                    plugin.DebugMessage("[INFO] Success! Loaded " + name + " as a new class" + (plugin.Configs.debug ? ":\n" + subclass.ToString() : string.Empty));
                    if (plugin.Configs.debug)
                    {
                        plugin.DebugMessage(subclass.ToString());
                    }
                }
                SuccessfulCount++;
            }

            return(SuccessfulCount);
        }