Пример #1
0
        void SpawnEnemies()
        {
            float             remainingDifficulty   = difficulty;
            List <SpawnEntry> remainingSpawnEntries = new List <SpawnEntry>();

            remainingSpawnEntries.AddRange(spawnEntries);
            do
            {
                int        indexOfSpawnEntry = Random.Range(0, remainingSpawnEntries.Count);
                SpawnEntry spawnEntry        = remainingSpawnEntries[indexOfSpawnEntry];
                if (remainingDifficulty - spawnEntry.difficulty < 0)
                {
                    remainingSpawnEntries.RemoveAt(indexOfSpawnEntry);
                }
                else
                {
                    Enemy enemy = spawnEntry.Spawn();
                    if (enemy != null)
                    {
                        SpeederBot speederBot = enemy as SpeederBot;
                        if (speederBot != null)
                        {
                            speederBot.Init();
                        }
                        enemy.enabled = false;
                        enemies.Add(enemy);
                    }
                    remainingDifficulty -= spawnEntry.difficulty;
                }
            } while (remainingSpawnEntries.Count > 0);
        }
    private SpawnEntry CreateStore(Spawnable prefab)
    {
        SpawnEntry spawnEntry = new SpawnEntry(prefab);

        entries.Add(spawnEntry);
        return(spawnEntry);
    }
Пример #3
0
 public virtual void DoUpdate()
 {
     for (int i = 0; i < spawnEntries.Count; i++)
     {
         SpawnEntry entry = spawnEntries[i];
         if (entry.runTimes > 0)
         {
             entry.spawnTimer += Time.deltaTime;
             if (entry.spawnTimer > entry.spawnRate)
             {
                 for (int i2 = 0; i2 < entry.spawnAmount; i2++)
                 {
                     entry.spawnTimer = 0;
                     float   distanceAroundPerimeter;
                     Vector3 spawnPosition;
                     do
                     {
                         distanceAroundPerimeter = spawnBoundsPerimeter * Random.value;
                         spawnPosition           = spawnBoundsRect.GetPointOnEdges(distanceAroundPerimeter).XYToXZ();
                         spawnPosition.y         = PlayerObject.CurrentActive.trs.position.y;
                     } while (Vector3.Distance(PlayerObject.CurrentActive.trs.position, spawnPosition) < minEnemySpawnDist);
                     spawnPosition.y = entry.enemyPrefab.trs.position.y;
                     Enemy enemy = ObjectPool.Instance.SpawnComponent <Enemy>(entry.enemyPrefab, spawnPosition, Quaternion.identity);
                     enemy.Awaken();
                 }
                 entry.spawnAmount += entry.spawnAmountIncreaseRate;
                 entry.runTimes--;
             }
             spawnEntries[i] = entry;
         }
         else
         {
             spawnEntries.RemoveAt(i);
             i--;
         }
     }
     for (int i = 0; i < eventEntries.Count; i++)
     {
         EventEntry entry = eventEntries[i];
         if (entry.runTimes > 0)
         {
             entry.triggerTimer += Time.deltaTime;
             if (entry.triggerTimer > entry.triggerTime)
             {
                 if (entry.loopTimer)
                 {
                     entry.triggerTimer = 0;
                 }
                 entry.unityEvent.Invoke();
                 entry.runTimes--;
             }
             eventEntries[i] = entry;
         }
         else
         {
             eventEntries.RemoveAt(i);
             i--;
         }
     }
 }
Пример #4
0
 public virtual T SpawnComponent <T> (int prefabIndex, Vector3 position = new Vector3(), Quaternion rotation = new Quaternion(), Transform parent = null)
 {
     lock (lockObject)
     {
         KeyValuePair <GameObject, Transform> cacheEntry;
         SpawnEntry spawnEntry = spawnEntries[prefabIndex];
         if (spawnEntry.cache.Count == 0)
         {
             Preload(prefabIndex);
         }
         do
         {
             cacheEntry = spawnEntry.cache[0];
             spawnEntry.cache.RemoveAt(0);
         } while (cacheEntry.Key == null);
         cacheEntry.Value.position   = position;
         cacheEntry.Value.rotation   = rotation;
         cacheEntry.Value.localScale = spawnEntry.trs.localScale;
         cacheEntry.Value.SetParent(parent, true);
         cacheEntry.Key.SetActive(true);
         spawnEntries[prefabIndex] = spawnEntry;
         return(cacheEntry.Key.GetComponent <T>());
     }
     return(SpawnComponent <T>(prefabIndex, position, rotation, parent));
 }
Пример #5
0
        public virtual T SpawnComponent <T> (int prefabIndex, Vector3 position = new Vector3(), Quaternion rotation = new Quaternion(), Transform parent = null)
        {
            SpawnEntry spawnEntry = spawnEntries[prefabIndex];

            while (spawnEntry.cache.Length <= spawnEntry.preload)
            {
                Preload(prefabIndex);
            }
            KeyValuePair <GameObject, Transform> cacheEntry = spawnEntry.cache[0];
            GameObject clone = cacheEntry.Key;

            if (clone == null)
            {
                return(default(T));
            }
            spawnEntry.cache = spawnEntry.cache.RemoveAt(0);
            SpawnedEntry entry = new SpawnedEntry(clone, cacheEntry.Value);

            entry.prefab         = spawnEntry.prefab;
            entry.prefabIndex    = prefabIndex;
            entry.trs.position   = position;
            entry.trs.rotation   = rotation;
            entry.trs.localScale = spawnEntry.trs.localScale;
            entry.trs.SetParent(parent, true);
            clone.SetActive(true);
            spawnedEntries = spawnedEntries.Add(entry);
            return(entry.go.GetComponent <T>());
        }
Пример #6
0
        public virtual T SpawnComponent <T> (int prefabIndex, Vector3 position = new Vector3(), Quaternion rotation = new Quaternion(), Transform parent = null)
        {
            if (isSpawning)
            {
                isSpawning = false;
                return(Instantiate(spawnEntries[prefabIndex].prefab, position, rotation, parent).GetComponent <T>());
            }
            isSpawning = true;
            SpawnEntry spawnEntry = spawnEntries[prefabIndex];

            if (spawnEntry.cache.Count == 0)
            {
                // while (spawnEntry.cache.Count <= spawnEntry.preload)
                Preload(prefabIndex);
            }
            KeyValuePair <GameObject, Transform> cacheEntry = spawnEntry.cache[0];

            spawnEntry.cache.RemoveAt(0);
            cacheEntry.Value.position   = position;
            cacheEntry.Value.rotation   = rotation;
            cacheEntry.Value.localScale = spawnEntry.trs.localScale;
            cacheEntry.Value.SetParent(parent, true);
            cacheEntry.Key.SetActive(true);
            spawnEntries[prefabIndex] = spawnEntry;
            isSpawning = false;
            return(cacheEntry.Key.GetComponent <T>());
        }
Пример #7
0
		/// <summary>
		/// Converts a spawner to a SpawnEntry used in SpawnData.
		/// </summary>
		/// <param name="spawnerItem">The spawner to convert</param>
		/// <returns>The SpawnEntry representing the spawner</returns>
		public static SpawnEntry SpawnerToData( Item spawnerItem )
		{
			XmlSpawner spawner = spawnerItem as XmlSpawner;

			if ( spawner == null || spawner.Map == Server.Map.Internal )
				return null;

			SpawnEntry entry = new SpawnEntry();

			entry.Map = spawner.Map.MapID;
			entry.X = spawner.X;
			entry.Y = spawner.Y;
			entry.Z = spawner.Z;

			entry.Team = spawner.Team;
			entry.Count = spawner.MaxCount;
			entry.Range = spawner.HomeRange;
			entry.MinDelay = spawner.MinDelay.TotalSeconds;
			entry.MaxDelay = spawner.MaxDelay.TotalSeconds;

			foreach( XmlSpawner.SpawnObject spawn in spawner.SpawnObjects )
			{
				entry.Names.Add( spawn.TypeName );
			}

			return entry;
		}
Пример #8
0
        public void Load(SegmentEntities entities, XElement element, Version version)
        {
            foreach (var spawnElement in element.Elements("spawn"))
            {
                var type    = spawnElement.Attribute("type");
                var spawner = default(Spawner);

                if (type != null)
                {
                    switch ((string)type)
                    {
                    case "LocationSpawner": spawner = new LocationSpawner(spawnElement); break;

                    case "RegionSpawner": spawner = new RegionSpawner(spawnElement); break;
                    }
                }

                if (spawner != null)
                {
                    foreach (var entryElement in spawnElement.Elements("entry"))
                    {
                        var entry = new SpawnEntry(entryElement);

                        var entity     = default(Entity);
                        var entityName = (string)entryElement.Attribute("entity");

                        if (!String.IsNullOrEmpty(entityName))
                        {
                            entity = entities.FirstOrDefault(
                                e => String.Equals(e.Name,
                                                   entityName, StringComparison.Ordinal));
                        }

                        entry.Entity = entity;

                        if (entry.Entity != null)
                        {
                            spawner.Entries.Add(entry);
                        }
                        else
                        {
                            throw new Exception($"Unable to load spawn entry '{entityName}'.");
                        }
                    }

                    if (spawner is LocationSpawner locationSpawner)
                    {
                        Location.Add(locationSpawner);
                    }
                    else if (spawner is RegionSpawner regionSpawner)
                    {
                        Region.Add(regionSpawner);
                    }
                }
            }
        }
        public void Unlink()
        {
            SpawnEntry se = this.Spawner as SpawnEntry;

            if (se != null)
            {
                this.Spawner.Remove(this);
                this.Spawner = null;
            }
        }
Пример #10
0
        public void Reset(SpawnEntry entry)
        {
            var type = entry.SpawnType;

            do
            {
                entry.SpawnType = (VoidType)Utility.RandomMinMax(0, 4);
            }while (entry.SpawnType == type);

            entry.DoSpawn();
        }
Пример #11
0
        public virtual KeyValuePair <GameObject, Transform> Preload(int prefabIndex)
        {
            KeyValuePair <GameObject, Transform> output;
            SpawnEntry spawnEntry = spawnEntries[prefabIndex];
            GameObject clone      = Instantiate(spawnEntry.prefab, trs);

            clone.SetActive(false);
            // spawnEntry.createdCount ++;
            // clone.name = clone.name.Insert(clone.name.Length - 1, "" + spawnEntry.createdCount);
            output = new KeyValuePair <GameObject, Transform>(clone, clone.GetComponent <Transform>());
            spawnEntry.cache.Add(output);
            spawnEntries[prefabIndex] = spawnEntry;
            return(output);
        }
    public bool GetStore(string id, out SpawnEntry outEntry)
    {
        // Iterate all entries
        foreach (SpawnEntry entry in entries)
        {
            if (entry.ID == id) // Check for a matching ID
            {
                outEntry = entry;
                return(true);
            }
        }

        outEntry = null;
        return(false);
    }
Пример #13
0
        public void Reset(SpawnEntry entry)
        {
            if (!Active)
            {
                return;
            }

            VoidType type = entry.SpawnType;

            do
            {
                entry.SpawnType = (VoidType)Utility.RandomMinMax(0, 4);
            }while (entry.SpawnType == type);

            entry.DoSpawn();
        }
Пример #14
0
        public static Harrower Spawn(Point3D platLoc, Map platMap)
        {
            if (m_Instances.Count > 0)
            {
                return(null);
            }

            SpawnEntry entry = m_Entries[Utility.Random(m_Entries.Length)];

            Harrower harrower = new Harrower();

            harrower.MoveToWorld(entry.m_Location, Map.Felucca);

            harrower.m_GateItem = new HarrowerGate(harrower, platLoc, platMap, entry.m_Entrance, Map.Felucca);

            return(harrower);
        }
Пример #15
0
        public static Harrower Spawn(Point3D platLoc, Map platMap)
        {
            if (Instances.Count > 0)
            {
                return(null);
            }

            SpawnEntry entry = m_Entries.GetRandom();

            var harrower = new Harrower();

            harrower.MoveToWorld(entry._Location, Map.Felucca);

            harrower._GateItem = new HarrowerGate(harrower, platLoc, platMap, entry._Entrance, Map.Felucca);

            return(harrower);
        }
Пример #16
0
        public static DarkMaster Spawn(Point3D platLoc, Map platMap)
        {
            if (IdolPedestal.DarkMasterActive())
            {
                return(null);
            }

            SpawnEntry entry = m_Entries[Utility.Random(m_Entries.Length)];

            DarkMaster darkmaster = new DarkMaster();

            darkmaster.MoveToWorld(entry.m_Location, Map.Felucca);

            darkmaster.m_GateItem = new DarkMasterGate(platLoc, platMap, entry.m_Entrance, Map.Felucca);

            return(darkmaster);
        }
Пример #17
0
        public void RemoveFromSpawner(ISpawnable spawnable)
        {
            BaseCreature bc = spawnable as BaseCreature;

            if (bc != null)
            {
                SpawnEntry entry = FindEntryFor(bc);

                if (entry != null)
                {
                    entry.Spawn.Remove(bc);
                    bc.Spawner = null;

                    if (entry.CurrentCount == 0)
                    {
                        Timer.DelayCall <SpawnEntry>(TimeSpan.FromMinutes(Utility.RandomMinMax(2, 5)), en =>
                        {
                            Reset(en);
                        }, entry);
                    }

                    List <DamageStore> list = bc.GetLootingRights();

                    foreach (DamageStore ds in list)
                    {
                        if (ds.m_HasRight)
                        {
                            int points = (bc.Fame / 998) / list.Count;

                            if (points > 0)
                            {
                                AddToOverallTotal(ds.m_Mobile, points);
                            }
                        }
                    }
                }
            }
        }
Пример #18
0
        public override void Deserialize(GenericReader reader)
        {
            base.Deserialize(reader);
            reader.ReadEncodedInt();

            int count = reader.ReadInt();

            for (int i = 0; i < count; i++)
            {
                int id = reader.ReadInt();

                SpawnEntry entry = (SpawnEntry)SpawnEntry.Table[id];

                if (entry != null)
                {
                    entry.Deserialize(reader);
                }
                else
                {
                    SpawnEntry.Remove(reader);
                }
            }
        }
Пример #19
0
        public Entity GetSelectedEntity()
        {
            SpawnEntry entry     = null;
            var        presenter = ServiceLocator.Current.GetInstance <ApplicationPresenter>();

            if (presenter.ActiveDocument is not SpawnsViewModel)
            {
                return(null);
            }
            if (_typeSelector.SelectedIndex == 0)
            {
                entry = _locationEntities.SelectedItem as SpawnEntry;
            }
            else
            {
                entry = _regionEntities.SelectedItem as SpawnEntry;
            }
            if (entry is null)
            {
                return(null as Entity);
            }

            return(entry.Entity);
        }
Пример #20
0
		/// <summary>
		/// Converts a spawner to a SpawnEntry used in SpawnData.
		/// </summary>
		/// <param name="spawnerItem">The spawner to convert</param>
		/// <returns>The SpawnEntry representing the spawner</returns>
		public static SpawnEntry SpawnerToData( Item spawnerItem )
		{
			Spawner spawner = spawnerItem as Spawner;

			if ( spawner == null || spawner.Map == Server.Map.Internal )
				return null;

			SpawnEntry entry = new SpawnEntry();

			entry.Map = spawner.Map.MapID;
			entry.X = spawner.X;
			entry.Y = spawner.Y;
			entry.Z = spawner.Z;

			entry.Team = spawner.Team;
			entry.Count = spawner.Count;
			entry.Range = spawner.HomeRange;
			entry.MinDelay = spawner.MinDelay.TotalSeconds;
			entry.MaxDelay = spawner.MaxDelay.TotalSeconds;

			entry.Names.AddRange( spawner.CreaturesName );

			return entry;
		}
Пример #21
0
        private static void ParseXmlSpawn(Stream reader, string baseFileName)
        {
            List <SpawnDefinition> spawnDefinitions = new List <SpawnDefinition>();

            DataSet ds = new DataSet("Spawns");

            ds.ReadXml(reader);

            if (ds.Tables.Count == 0)
            {
                return;
            }

            foreach (DataRow row in ds.Tables["Points"].Rows)
            {
                SpawnDefinition spawn = new SpawnDefinition {
                    Entries = new List <SpawnEntry>()
                };

                string mapString = (string)row["Map"];

                Map map = Enum.Parse <Map>(mapString);

                spawn.Map = (int)map;

                string objects2;

                if ((objects2 = (string)row["Objects2"]) != null)
                {
                    string[] objectList = SplitString(objects2, ":OBJ=");

                    foreach (string s in objectList)
                    {
                        SpawnEntry spawnEntry = new SpawnEntry();

                        string[] objectDetails = SplitString(s, ":MX=");

                        if (string.IsNullOrEmpty(objectDetails[0]))
                        {
                            continue;
                        }

                        string name = ParseName(objectDetails[0]);

                        // ReSharper disable once ForeachCanBePartlyConvertedToQueryUsingAnotherGetEnumerator
                        foreach (KeyValuePair <string, string> kvp in _replaceRegex)
                        {
                            Match match = Regex.Match(name.ToLower(), kvp.Key);

                            if (match.Length <= 0)
                            {
                                continue;
                            }

                            name = Regex.Replace(name.ToLower(), kvp.Key, kvp.Value);
                            break;
                        }

                        Type typeName = ResolveType(name);

                        if (typeName == null)
                        {
                            Console.WriteLine($"Cannot find type {name}...");
                            continue;
                        }

                        spawnEntry.Name        = typeName.Name;
                        spawnEntry.MaxCount    = int.Parse(GetParm(s, ":MX="));
                        spawnEntry.Probability = 100;

                        spawn.Entries.Add(spawnEntry);
                    }
                }

                if (spawn.Entries.Count == 0)
                {
                    continue;
                }

                spawn.X            = int.Parse((string)row["CentreX"]);
                spawn.Y            = int.Parse((string)row["CentreY"]);
                spawn.Z            = int.Parse((string)row["CentreZ"]);
                spawn.Count        = int.Parse((string)row["MaxCount"]);
                spawn.WalkingRange = int.Parse((string)row["Range"]);
                // Because ModernUO does not support SpawnArea (Rectangle2D), we must calculate a radius for a spawn range
                spawn.HomeRange = CalculateHomeRange(spawn.X, spawn.Y, int.Parse((string)row["X"]),
                                                     int.Parse((string)row["Y"]), int.Parse((string)row["Width"]),
                                                     int.Parse((string)row["Height"]));

                try
                {
                    int minDelay = int.Parse((string)row["MinDelay"]);
                    int maxDelay = int.Parse((string)row["MaxDelay"]);

                    bool isSeconds = bool.Parse((string)row["DelayInSec"]);

                    spawn.MinDelay = isSeconds ? TimeSpan.FromSeconds(minDelay) : TimeSpan.FromMinutes(minDelay);
                    spawn.MaxDelay = isSeconds ? TimeSpan.FromSeconds(maxDelay) : TimeSpan.FromMinutes(maxDelay);
                }
                catch (ArgumentException)
                {
                    spawn.MinDelay = TimeSpan.FromMinutes(5);
                    spawn.MaxDelay = TimeSpan.FromMinutes(10);
                }

                spawnDefinitions.Add(spawn);
            }

            if (spawnDefinitions.Count <= 0)
            {
                return;
            }

            if (!Directory.Exists(OUTPUT_DIRECTORY))
            {
                Directory.CreateDirectory(OUTPUT_DIRECTORY);
            }

            using JsonTextWriter jtw =
                      new JsonTextWriter(
                          new StreamWriter(Path.Combine(OUTPUT_DIRECTORY, $"{baseFileName.ToLower()}.json")));

            JsonSerializer serializer =
                JsonSerializer.Create(new JsonSerializerSettings {
                Formatting = Formatting.Indented
            });

            serializer.Serialize(jtw, spawnDefinitions);
        }
Пример #22
0
        public void Load(SpawnSetting setting)
        {
            if (setting == null)
                return;

            waveIntervalTime = setting.WaveIntervalTime;

            Dictionary<int, SpawnWave> waveDict = new Dictionary<int, SpawnWave>();
            foreach (var locationSetting in setting.Locations)
            {
                foreach (var waveSetting in locationSetting.Waves)
                {
                    SpawnWave wave;
                    if (!waveDict.TryGetValue(waveSetting.WaveIndex, out wave))
                    {
                        wave = new SpawnWave();
                        waveDict.Add(waveSetting.WaveIndex, wave);
                    }

                    SpawnEntry entry = new SpawnEntry();
                    entry.PathIndex = locationSetting.PathIndex;
                    entry.DelayTime = waveSetting.DelayTime;
                    entry.IntervalTime = waveSetting.IntervalTime;
                    entry.SpawnTimes = waveSetting.SpawnTimes;
                    entry.SpawnPerTime = waveSetting.SpawnPerTime;
                    entry.TemplateID = waveSetting.TemplateID;
                    wave.Entries.Add(entry);
                }
            }
            waves = waveDict.Values.ToList();

            WaveCount = waves.Count;
        }
Пример #23
0
        protected override void OnTarget(Mobile from, object target)
        {
            BaseCreature pet = target as BaseCreature;

            if (target == from)
            {
                from.SendMessage("You cannot shrink yourself!");
            }

            else if (target is Item)
            {
                from.SendMessage("You cannot shrink that!");
            }

            else if (target is PlayerMobile)
            {
                from.SendMessage("That person gives you a dirty look!");
            }

            else if (Server.Spells.SpellHelper.CheckCombat(from))
            {
                from.SendMessage("You cannot shrink your pet while you are fighting.");
            }

            else if (null == pet)
            {
                from.SendMessage("That is not a pet!");
            }

            else if ((pet.BodyValue == 400 || pet.BodyValue == 401) && pet.Controlled == false)
            {
                from.SendMessage("That person gives you a dirty look!");
            }

            else if (pet.IsDeadPet)
            {
                from.SendMessage("You cannot shrink the dead!");
            }

            else if (pet.Summoned)
            {
                from.SendMessage("You cannot shrink a summoned creature!");
            }

            else if (!m_StaffCommand && pet.Combatant != null && pet.InRange(pet.Combatant, 12) && pet.Map == pet.Combatant.Map)
            {
                from.SendMessage("Your pet is fighting; you cannot shrink it yet.");
            }

            else if (pet.BodyMod != 0)
            {
                from.SendMessage("You cannot shrink your pet while it is polymorphed.");
            }

            else if (!m_StaffCommand && pet.Controlled == false)
            {
                from.SendMessage("You cannot not shrink wild creatures.");
            }

            else if (!m_StaffCommand && pet.ControlMaster != from)
            {
                from.SendMessage("That is not your pet.");
            }

            else if (!m_StaffCommand && ShrinkItem.IsPackAnimal(pet) && (null != pet.Backpack && pet.Backpack.Items.Count > 0))
            {
                from.SendMessage("You must unload this pet's pack before it can be shrunk.");
            }

            else
            {
                if (pet.ControlMaster != from && !pet.Controlled)
                {
                    SpawnEntry se = pet.Spawner as SpawnEntry;
                    if (se != null && se.UnlinkOnTaming)
                    {
                        pet.Spawner.Remove((ISpawnable)pet);
                        pet.Spawner = null;
                    }

                    pet.CurrentWayPoint = null;
                    pet.ControlMaster   = from;
                    pet.Controlled      = true;
                    pet.ControlTarget   = null;
                    pet.ControlOrder    = OrderType.Come;
                    pet.Guild           = null;
                    pet.Delta(MobileDelta.Noto);
                }

                IEntity p1 = new Entity(Serial.Zero, new Point3D(from.X, from.Y, from.Z), from.Map);
                IEntity p2 = new Entity(Serial.Zero, new Point3D(from.X, from.Y, from.Z + 50), from.Map);

                Effects.SendMovingParticles(p2, p1, ShrinkTable.Lookup(pet), 1, 0, true, false, 0, 3, 1153, 1, 0, EffectLayer.Head, 0x100);
                from.PlaySound(492);
                from.AddToBackpack(new ShrinkItem(pet));

                if (!m_StaffCommand && null != m_ShrinkTool && m_ShrinkTool.ShrinkCharges > 0)
                {
                    m_ShrinkTool.ShrinkCharges--;
                }
            }
        }
Пример #24
0
 public SpawnDrawObject(SpawnEntry spawn)
 {
     Spawn = spawn;
 }