Exemplo n.º 1
0
        private static void ServerTrySpawnMobs(IStaticWorldObject worldObject)
        {
            if (LandClaimSystem.SharedIsLandClaimedByAnyone(worldObject.Bounds))
            {
                // don't spawn mobs as the land is claimed
                return;
            }

            // calculate how many creatures are still alive
            var mobsList = GetPrivateState(worldObject).MobsList;

            var mobsAlive = 0;

            for (var index = 0; index < mobsList.Count; index++)
            {
                var character = mobsList[index];
                if (character.IsDestroyed)
                {
                    mobsList.RemoveAt(index--);
                    continue;
                }

                if (character.TilePosition.TileSqrDistanceTo(worldObject.TilePosition)
                    > MobDespawnDistance * MobDespawnDistance)
                {
                    // the guardian mob is too far - probably lured away by a player
                    using var tempListObservers = Api.Shared.GetTempList <ICharacter>();
                    Server.World.GetScopedByPlayers(character, tempListObservers);
                    if (tempListObservers.Count == 0)
                    {
                        // despawn this mob as it's not observed by any player
                        Server.World.DestroyObject(character);
                        mobsList.RemoveAt(index--);
                    }

                    continue;
                }

                mobsAlive++;
            }

            var countToSpawn = MobsCountLimit - mobsAlive;

            if (countToSpawn <= 0)
            {
                return;
            }

            // spawn mobs(s) nearby
            countToSpawn = Math.Min(countToSpawn, ServerSpawnMobsMaxCountPerIteration);
            ServerMobSpawnHelper.ServerTrySpawnMobsCustom(protoMob: LazyProtoMob.Value,
                                                          spawnedCollection: mobsList,
                                                          countToSpawn,
                                                          excludeBounds: worldObject.Bounds.Inflate(1),
                                                          maxSpawnDistanceFromExcludeBounds: MobSpawnDistance,
                                                          noObstaclesCheckRadius: 0.5,
                                                          maxAttempts: 200);
        }
Exemplo n.º 2
0
        protected override void ServerOnObjectSpawned(IGameObjectWithProto spawnedObject)
        {
            // spawn some guardian mobs so it will be harder to claim this deposit
            var objectGeothermalSpring = (IStaticWorldObject)spawnedObject;

            ServerMobSpawnHelper.ServerTrySpawnMobsCustom(
                protoMob: Api.GetProtoEntity <MobCloakedLizard>(),
                countToSpawn: 3,
                excludeBounds: objectGeothermalSpring.Bounds.Inflate(1),
                maxSpawnDistanceFromExcludeBounds: 2,
                noObstaclesCheckRadius: 0.5,
                maxAttempts: 200);
        }