Example #1
0
        //Spawns a nightmare
        public static void SpawnNightmare(NightmareType nt, EntityAlive target = null)
        {
            NightmareInstance ni = new NightmareInstance();

            ni.InstanceType = nt;

            try
            {
                API.Log("Spawning instance " + ni.InstanceType.ClassName);


                using (Dictionary <int, EntityClass> .KeyCollection.Enumerator enumerator3 = EntityClass.list.Keys.GetEnumerator())
                {
                    while (enumerator3.MoveNext())
                    {
                        //Find entity class
                        int current3 = enumerator3.Current;
                        //API.Log("Iterating enum, on " + current3+ " ("+EntityClass.list[current3].entityClassName+")");
                        if (!EntityClass.list[current3].entityClassName.Equals(ni.InstanceType.ClassName))
                        {
                            continue;
                        }
                        //API.Log("Found entity " + current3 + " to be classname " + ni.InstanceType.ClassName);
                        //Find a place to spawn it
                        int x = 0, y = 0, z = 0;


                        if (target == null)
                        {
                            API.Log("Finding target");
                            ni.PickRandomTarget();
                        }
                        else
                        {
                            ni.TargetEntity = target;
                        }

                        if (ni.TargetEntity == null)
                        {
                            API.Log("Failed to find a target entity");
                            return;
                        }
                        API.Log("Finding location to spawn");


                        bool isSpawnLocFound = false;
                        for (int i = 0; i < 10; i++)
                        {
                            if (GameManager.Instance.World.FindRandomSpawnPointNearPlayer(ni.TargetEntity, 30, out x, out y, out z, 200))
                            {
                                isSpawnLocFound = true;
                                break;
                            }
                        }

                        if (!isSpawnLocFound)
                        {
                            API.Log("Failed to find spawn location near player" + ni.TargetEntity);
                            return;
                        }

                        UnityEngine.Vector3 pos = new UnityEngine.Vector3(x, y, z);

                        API.Log("Creating entity.." + current3);
                        //This is found in AIDirectoryBloodMoonParty
                        ni.Instance         = (EntityEnemy)EntityFactory.CreateEntity(current3, pos);
                        ni.Instance.isFeral = true;

                        //ni.Instance.lootContainer.AddItem(new ItemStack(new ItemValue(114), 1));
                        //string loot = "Loot: ";
                        //foreach (var item in ni.Instance.equipment.GetItems())
                        //{
                        //   loot += string.Format("{0} [{1}] x{2}", item.ItemClass, item.Quality);
                        //}
                        //API.Log(string.Format("Loot: {0}", loot));

                        GameManager.Instance.World.SpawnEntityInWorld(ni.Instance);


                        //ni.Instance.SetEntityName("A nightmare");
                        //ni.Instance.SetSpawnerSource(EnumSpawnerSource.Dynamic);
                        NightmareInstances.Add(ni);
                        ni.Instance.SetAttackTarget(ni.TargetEntity, 1200);
                        API.Log("Added instance " + ni.InstanceType.ClassName + " at " + x + ", " + y + ", " + z);

                        WhisperMessage(ConnectionManager.Instance.GetClientInfoForPlayerId(ni.TargetEntity.belongsPlayerId.ToString()), ni.InstanceType.Message);
                        return;
                    }
                }
                API.Log("Failed to find class type of nightmare: " + ni.InstanceType.ClassName);
            }
            catch (Exception e)
            {
                API.Log("Failed to spawn nightmare: " + e.Message);
                return;
            }
        }
Example #2
0
 public void AddType(NightmareType nt)
 {
     NightmareTypes.Add(nt);
 }
Example #3
0
 public NightmareSeed(NightmareType nt, ulong seedTime)
 {
     NightmareTypes.Add(nt);
     SeedTime = seedTime;
 }
Example #4
0
        public static void SeedNightmares()
        {
            try
            {
                NightmareSeeds.Clear();
                ulong currentTime = GameManager.Instance.World.GetWorldTime();

                API.Log("Seeding nightmares with current time: " + currentTime);

                Random rnd         = new Random();
                int    playerCount = GameManager.Instance.World.Players.Count;
                if (playerCount < 2)
                {
                    playerCount = 2;
                }

                int maxNumberofNightmares = playerCount + GameUtils.WorldTimeToDays(GameManager.Instance.World.GetWorldTime());
                if (maxNumberofNightmares < 2)
                {
                    maxNumberofNightmares = 2;
                }

                int numberOfNightmares = rnd.Next(1, maxNumberofNightmares);

                int batchNumberofNightmares = playerCount + (GameUtils.WorldTimeToDays(GameManager.Instance.World.GetWorldTime()) / 2);
                if (batchNumberofNightmares < 2)
                {
                    batchNumberofNightmares = 2;
                }

                API.Log("Preparing " + numberOfNightmares + " total nightmares for the next 24 hours");

                ulong lastTime = currentTime;
                int   timeGap  = 6000 / numberOfNightmares;
                API.Log("Timegap: " + timeGap + " (" + (timeGap / 5.8f) + "s)");
                if (timeGap < 2)
                {
                    timeGap = 200;
                }

                for (int i = 0; i < numberOfNightmares; i++)
                {
                    string        nightmareGroup = "";
                    NightmareType nt             = GetRandomNightmareType();
                    //1440 minutes in a day.
                    NightmareSeed ns = new NightmareSeed(nt, lastTime + (ulong)rnd.Next(1, timeGap));
                    nightmareGroup += nt.ClassName;

                    //add additional nightmares based on batch
                    int batchCount = rnd.Next(1, batchNumberofNightmares);
                    for (int j = 1; j < batchCount; j++)
                    {
                        nt = GetRandomNightmareType();
                        ns.AddType(nt);
                        nightmareGroup += ", " + nt.ClassName;
                    }

                    lastTime = ns.SeedTime;
                    API.Log(NightmareSeeds.Count + " contains: " + nightmareGroup + " and will spawn at " + ns.SeedTime);
                    if (i == 0)
                    {
                        NextNightmare = ns.SeedTime;
                    }
                    NightmareSeeds.Add(ns);
                }

                NextNightmareReseed = currentTime + 6000;
            } catch (Exception e)
            {
                API.Log("Exception while seeding nightmares: " + e.Message);
            }
        }
Example #5
0
        private static void Start()
        {
            NightmareType n;

            n = new NightmareType("A nightmare manifests itself", "zombieSpider", 0, 10);
            NightmareTypes.Add(n);
            n = new NightmareType("A nightmare manifests itself", "animalZombieDog", 0, 100);
            NightmareTypes.Add(n);
            n = new NightmareType("A nightmare manifests itself", "animalWolf", 0, 80);
            NightmareTypes.Add(n);
            n = new NightmareType("A nightmare manifests itself", "animalBear", 0, 20);
            NightmareTypes.Add(n);
            n = new NightmareType("A nightmare manifests itself", "zombieFatCop", 0, 10);
            NightmareTypes.Add(n);
            n = new NightmareType("A nightmare manifests itself", "zombieArlene", 0, 20);
            NightmareTypes.Add(n);

            n = new NightmareType("A nightmare manifests itself", "animalBear", 1, 50);
            NightmareTypes.Add(n);
            n = new NightmareType("A nightmare manifests itself", "zombieSoldier", 1, 20);
            NightmareTypes.Add(n);
            n = new NightmareType("A nightmare manifests itself", "zombieSoldier", 1, 20);
            NightmareTypes.Add(n);
            n = new NightmareType("A nightmare manifests itself", "zombieSkateboarderFeral", 1, 20);
            NightmareTypes.Add(n);
            n = new NightmareType("A nightmare manifests itself", "zombieCheerleaderFeral", 1, 20);
            NightmareTypes.Add(n);


            n = new NightmareType("A nightmare manifests itself", "zombieOldTimer", 2, 20);
            NightmareTypes.Add(n);
            n = new NightmareType("A nightmare manifests itself", "zombieArleneFeral", 2, 20);
            NightmareTypes.Add(n);
            //n = new NightmareType("A nightmare manifests itself", "animalZombieVulture", 2, 20);
            //NightmareTypes.Add(n);

            n = new NightmareType("A nightmare manifests itself", "zombieSoldierFeral", 3, 20);
            NightmareTypes.Add(n);
            n = new NightmareType("A nightmare manifests itself", "zombieFatHawaiianFeral", 3, 20);
            NightmareTypes.Add(n);
            n = new NightmareType("A nightmare manifests itself", "zombieSnowFeral", 3, 20);
            NightmareTypes.Add(n);

            n = new NightmareType("A nightmare manifests itself", "zombieScreamer", 4, 100);
            NightmareTypes.Add(n);
            n = new NightmareType("A nightmare manifests itself", "zombieSpiderFeral", 4, 100);
            NightmareTypes.Add(n);

            n = new NightmareType("A nightmare manifests itself", "animalZombieBear", 5, 20);
            NightmareTypes.Add(n);
            n = new NightmareType("A nightmare manifests itself", "zombieStripperFeral", 5, 20);
            NightmareTypes.Add(n);

            n = new NightmareType("A nightmare manifests itself", "zombieScreamerFeral", 6, 150);
            NightmareTypes.Add(n);
            n = new NightmareType("A nightmare manifests itself", "zombieFatCopFeral", 6, 150);
            NightmareTypes.Add(n);
            n = new NightmareType("A nightmare manifests itself", "zombieFatCopFeralRadiated", 6, 100);
            NightmareTypes.Add(n);


            n = new NightmareType("A nightmare manifests itself", "zombieFatCopFeralRadiated", 7, 350);
            NightmareTypes.Add(n);


            API.Log("*** Initialized Nightmare Mod, Added " + NightmareTypes.Count + " nightmare types ***");

            th = new Thread(new ThreadStart(MainLoop));
            th.IsBackground = true;
            th.Start();
        }