Beispiel #1
0
 public void AddSpawn(MonsterStaticSpawn spawn)
 {
     lock (m_locker)
     {
         m_spawns.Add(spawn);
         m_spawnsQueue.Enqueue(spawn);
     }
 }
Beispiel #2
0
        public void RemoveSpawn(MonsterStaticSpawn spawn)
        {
            lock (m_locker)
            {
                m_spawns.Remove(spawn);

                var asList = m_spawnsQueue.ToList();
                if (asList.Remove(spawn))
                {
                    m_spawnsQueue = new Queue <MonsterStaticSpawn>(asList);
                }
            }
        }
Beispiel #3
0
        public override void ExecuteAdd(TriggerBase trigger)
        {
            Map map;

            if (!trigger.IsArgumentDefined("map"))
            {
                if (trigger is GameTrigger)
                {
                    map = ((GameTrigger)trigger).Character.Map;
                }
                else
                {
                    trigger.ReplyError("No map defined");
                    return;
                }
            }
            else
            {
                map = trigger.Get <Map>("map");
            }

            var monsterTemplate = trigger.Get <MonsterTemplate>("monster");
            var grade           = MonsterManager.Instance.GetMonsterGrade(monsterTemplate.Id, trigger.Get <int>("grade"));

            if (grade == null)
            {
                trigger.ReplyError("Monster grade {0}({1}) not found", monsterTemplate.Name, trigger.Get <int>("grade"));
                return;
            }

            var pool = map.SpawningPools.OfType <StaticSpawningPool>().FirstOrDefault();

            if (pool == null)
            {
                pool = new StaticSpawningPool(map);
                map.AddSpawningPool(pool);
            }

            var cell      = trigger.IsArgumentDefined("cell") ? trigger.Get <short>("cell") : ((GameTrigger)trigger).Character.Cell.Id;
            var direction = trigger.IsArgumentDefined("direction") ? trigger.Get <DirectionsEnum>("direction") : ((GameTrigger)trigger).Character.Direction;

            WorldServer.Instance.IOTaskPool.AddMessage(() =>
            {
                var group = new MonsterStaticSpawn
                {
                    Map           = map,
                    GroupMonsters = new List <MonsterGrade> {
                        grade
                    },
                    CellId    = cell,
                    Direction = (uint)direction
                };

                WorldServer.Instance.DBAccessor.Database.Insert(group);

                var record = new MonsterStaticSpawnEntity
                {
                    StaticSpawnId  = group.Id,
                    MonsterGradeId = grade.Id,
                };

                WorldServer.Instance.DBAccessor.Database.Insert(record);

                if (group.GroupMonsters.Count == 1)
                {
                    pool.AddSpawn(group);
                }
                map.Area.ExecuteInContext(pool.StartAutoSpawn);
            });
        }