Ejemplo n.º 1
0
        public void OnWaitingForPlayers(WaitingForPlayersEvent ev)
        {
            if (!plugin.enable)
            {
                if (plugin.verbose)
                {
                    plugin.Info("ItemSpawner is disabled: the list was not read");
                }
                return;
            }
            string[] items;

            if (plugin.useGlobalItems)
            {
                if (!FileManager.FileExists("./items.txt"))
                {
                    plugin.Info("Created items.txt file with a MTF_LIEUTENANT_KEYCARD (or a coin) in the Intercom room and one MICROHID at the Silo warhead as an example in the global directory.");
                    File.WriteAllText("./items.txt", "NUKE:MICROHID:100:-0.05,402.46,3.52:1,0,0\nINTERCOM:MICROHID,COIN:100:-9.212725,-6.839905,-3.935197:0.5,0,0");
                }
                items = FileManager.ReadAllLines("./items.txt");
            }
            else
            {
                if (!FileManager.FileExists(FileManager.GetAppFolder() + ("items.txt")))
                {
                    plugin.Info("Created items.txt file with a MTF_LIEUTENANT_KEYCARD (or a coin) in the Intercom room and one MICROHID at the Silo warhead as an example in the server directory or in the Appdata folder.");
                    File.WriteAllText(FileManager.GetAppFolder() + ("items.txt"), "NUKE:MICROHID:100:-0.05,402.46,3.52:1,0,0\nINTERCOM:MTF_LIEUTENANT_KEYCARD,COIN:100:-9.212725,-6.839905,-3.935197:0.5,0,0");
                }
                items = FileManager.ReadAllLines(FileManager.GetAppFolder() + ("items.txt"));
            }
            if (items.Length < 0)
            {
                plugin.Error("Your 'items.txt' file is completely blank.");
                return;
            }
            else
            {
                int currentLine = -1;
                spawnlist.Clear();                 // Reload the spawnlist
                foreach (string item in items)
                {
                    currentLine++;

                    if (string.IsNullOrWhiteSpace(item))
                    {
                        continue;
                    }

                    if (item[0] == '#')
                    {
                        continue;
                    }

                    try
                    {
                        // RoomType:ItemType, ItemType2...:Probability:Vector3:Rotation
                        string[] data = item.Split(':');
                        if (data.Length == 0)
                        {
                            continue;
                        }
                        if (data.Length != 5)
                        {
                            plugin.Error("Error reading line " + (currentLine + 1));
                            continue;
                        }
                        if (!Enum.TryParse(data[0].Trim(), out RoomType room))
                        {
                            plugin.Error("Error using RoomType " + data[0] + " in line " + (currentLine + 1));
                            continue;
                        }
                        string[]        itemData    = data[1].Split(',');
                        List <ItemType> itemTypes   = new List <ItemType>();
                        List <int>      CustomItems = new List <int>();
                        if (itemData.Length == 0)
                        {
                            plugin.Error("Error fetching ItemTypes " + data[1] + " in line " + currentLine);
                            continue;
                        }
                        foreach (string itemDataUntrimmed in itemData)
                        {
                            string itemDataValue = itemDataUntrimmed.Trim();
                            #region ItemManager Region
                            if (itemDataValue.StartsWith("IM_"))
                            {
                                if (int.TryParse(itemDataValue.Substring(3), out int customItem))
                                {
                                    if (ItemManager.Items.Handlers.ContainsKey(customItem))
                                    {
                                        CustomItems.Add(customItem);
                                    }
                                    else
                                    {
                                        plugin.Error("Custom item with ID " + customItem + " not installed/not found!");
                                    }
                                }
                                else
                                {
                                    plugin.Error("\"ID\" " + itemDataValue.Substring(3) + " isn't a valid ID for ItemManager!");
                                }
                            }
                            else
                            #endregion
                            if (!Enum.TryParse(itemDataValue.Trim(), out ItemType itemType))
                            {
                                if (int.TryParse(itemDataValue.Trim(), out int id))
                                {
                                    itemType = (ItemType)id;
                                    itemTypes.Add((ItemType)id);
                                }
                                else
                                {
                                    plugin.Error("Error using ItemType " + itemDataValue.Trim() + " in line " + currentLine);
                                }
                            }
                            else
                            {
                                itemTypes.Add(itemType);
                            }
                        }
                        if (!float.TryParse(data[2].Trim(), out float probability))
                        {
                            plugin.Error("Error using probability " + data[2].Trim() + " in line " + currentLine);
                            continue;
                        }
                        Vector3 position = Vector3Parser(data[3].Trim(), currentLine);
                        if (position == null)
                        {
                            continue;
                        }
                        Vector3 rotation = Vector3Parser(data[4].Trim(), currentLine);
                        if (rotation == null)
                        {
                            continue;
                        }

                        // If it worked until here means everything went to plan uwu
                        spawnlist.Add(new SpawnInfo(room, currentLine, itemTypes.ToArray(), CustomItems.ToArray(), probability, position, rotation));
                    }
                    catch (Exception e)
                    {
                        plugin.Info("Somewhere it f****d up: " + e.ToString());
                    }
                }
            }
            if (spawnlist.Count != 0)
            {
                foreach (Room room in Spawner.rooms)
                {
                    foreach (SpawnInfo spawn in spawnlist.Where(x => x.RoomType == room.RoomType))
                    {
                        if (rand.Next(0, 10000) <= spawn.probability * 100)
                        {
                            if (spawn.CustomItems != null)
                            {
                                int itemInt = rand.Next(0, spawn.items.Length + spawn.CustomItems.Length);
                                if (itemInt < spawn.items.Length)
                                {
                                    Spawner.SpawnItem(room, spawn.items[itemInt], spawn.position, spawn.rotation);
                                }
                                else
                                {
                                    CIQueue.Enqueue(new CusItemInfo(room, spawn.CustomItems[itemInt - spawn.items.Length], spawn.position, spawn.rotation));
                                }
                            }
                            else
                            {
                                Spawner.SpawnItem(room, spawn.items[rand.Next(0, spawn.items.Length)], spawn.position, spawn.rotation);
                            }
                        }
                    }
                }
            }
        }
Ejemplo n.º 2
0
        public void OnWaitingForPlayers(WaitingForPlayersEvent ev)
        {
            if (!plugin.enable)
            {
                if (plugin.verbose)
                {
                    plugin.Info("ItemSpawner is disabled: the list was not read");
                }
                return;
            }
            string[] items;
            if (plugin.useGlobalItems)
            {
                if (!FileManager.FileExists("./items.txt"))
                {
                    plugin.Info("Created items.txt file with a microhid (or a coin) in the Intercom room and one at the Silo warhead as an example.");
                    File.WriteAllText("./items.txt", "NUKE:MICROHID:100:-0.05,402.46,3.52:1,0,0\nINTERCOM:MICROHID,COIN:100:-9.212725,-6.839905,-3.935197:0.5,0,0");
                }
                items = FileManager.ReadAllLines("./items.txt");
            }
            else
            {
                items = FileManager.ReadAllLines(FileManager.GetAppFolder() + ("items.txt"));
            }
            if (items.Length < 0)
            {
                plugin.Error("Your 'items.txt' file is completely blank.");
                return;
            }
            else
            {
                int currentLine = -1;
                spawnlist.Clear();                 //Reload the spawnlist
                foreach (string item in items)
                {
                    currentLine++;

                    if (string.IsNullOrWhiteSpace(item))
                    {
                        continue;
                    }

                    if (item[0] == '#')
                    {
                        continue;
                    }

                    try
                    {
                        // RoomType:ItemType, ItemType2...:Probability:Vector:Rotation
                        string[] data = item.Split(':');
                        if (data.Length == 0)
                        {
                            continue;
                        }
                        if (data.Length != 5)
                        {
                            plugin.Error("Error reading line " + currentLine);
                            continue;
                        }
                        if (!Enum.TryParse(data[0].Trim(), out RoomType room))
                        {
                            plugin.Error("Error using RoomType " + data[0] + " in line " + currentLine);
                            continue;
                        }
                        string[]        itemData  = data[1].Split(',');
                        List <ItemType> itemTypes = new List <ItemType>();
                        if (itemData.Length == 0)
                        {
                            plugin.Error("Error fetching ItemTypes " + data[1] + " in line " + currentLine);
                            continue;
                        }
                        foreach (string itemDataValue in itemData)
                        {
                            if (!Enum.TryParse(itemDataValue.Trim(), out ItemType itemType))
                            {
                                plugin.Error("Error using ItemType " + itemDataValue.Trim() + " in line " + currentLine);
                                continue;
                            }
                            itemTypes.Add(itemType);
                        }
                        if (!float.TryParse(data[2].Trim(), out float probability))
                        {
                            plugin.Error("Error using probability " + data[2].Trim() + " in line " + currentLine);
                            continue;
                        }
                        Vector position = VectorParser(data[3].Trim(), currentLine);
                        if (position == null)
                        {
                            continue;
                        }
                        Vector rotation = VectorParser(data[4].Trim(), currentLine);
                        if (rotation == null)
                        {
                            continue;
                        }

                        // If it worked until here means everything went to plan uwu
                        spawnlist.Add(new SpawnInfo(room, currentLine, itemTypes.ToArray(), probability, position, rotation));
                    }
                    catch (Exception e)
                    {
                        plugin.Info("Somewhere it f****d up: " + e.ToString());
                    }
                }
            }
            if (spawnlist.Count != 0)
            {
                foreach (Room room in Spawner.rooms)
                {
                    foreach (SpawnInfo spawn in spawnlist.Where(x => x.RoomType == room.RoomType))
                    {
                        if (rand.Next(0, 10000) <= spawn.probability * 100)
                        {
                            Spawner.SpawnItem(room, spawn.items[rand.Next(0, spawn.items.Length)], spawn.position, spawn.rotation);
                        }
                    }
                }
            }
        }