Пример #1
0
        /// <summary>
        /// Server spawn callback for static object.
        /// </summary>
        /// <param name="trigger">Trigger leading to this spawn.</param>
        /// <param name="zone">Server zone instance.</param>
        /// <param name="protoStaticWorldObject">Prototype of static object to spawn.</param>
        /// <param name="tilePosition">Position to try spawn at.</param>
        protected IGameObjectWithProto ServerSpawnStaticObject(
            IProtoTrigger trigger,
            IServerZone zone,
            IProtoStaticWorldObject protoStaticWorldObject,
            Vector2Ushort tilePosition)
        {
            foreach (var tileOffset in protoStaticWorldObject.Layout.TileOffsets)
            {
                // ensure that each tile in object layout is inside the zone
                if (tileOffset != Vector2Int.Zero &&
                    !zone.IsContainsPosition(tilePosition.AddAndClamp(tileOffset)))
                {
                    // some tile is outside the zone
                    return(null);
                }
            }

            if (!protoStaticWorldObject.CheckTileRequirements(
                    tilePosition,
                    character: null,
                    logErrors: false))
            {
                // cannot spawn static object there
                return(null);
            }

            var spawnedObject = ServerWorldService.CreateStaticWorldObject(protoStaticWorldObject, tilePosition);

            if (spawnedObject == null)
            {
                // cannot spawn static object there
                return(null);
            }

            // if spawned a vegetation - set random growth progress
            if (protoStaticWorldObject is IProtoObjectVegetation protoVegetation)
            {
                double growProgress;
                if (trigger == null ||
                    trigger is TriggerWorldInit)
                {
                    // world initialization spawn
                    growProgress = RandomHelper.RollWithProbability(0.6)
                                       ? 1                          // 60% are spawned in full grown state
                                       : Random.Next(0, 11) / 10.0; // other are spawned with random growth progress
                }
                else
                {
                    // spawn saplings
                    growProgress = 0;
                }

                protoVegetation.ServerSetGrowthProgress(spawnedObject, growProgress);
            }

            ServerDecalsDestroyHelper.DestroyAllDecals(tilePosition, protoStaticWorldObject.Layout);
            return(spawnedObject);
        }
Пример #2
0
        private void ServerRemote_PlaceAt(Vector2Ushort tilePosition, bool isSlope)
        {
            var worldService = Server.World;
            var tile         = worldService.GetTile(tilePosition);

            worldService.SetTileData(
                tilePosition,
                tile.ProtoTile,
                tileHeight: tile.Height,
                isSlope: isSlope,
                isCliff: false);

            worldService.SetTileData(
                tilePosition.AddAndClamp(new Vector2Ushort(1, 0)),
                tile.ProtoTile,
                tileHeight: tile.Height,
                isSlope: isSlope,
                isCliff: false);

            worldService.FixMapTilesRecentlyModified();
        }
Пример #3
0
 public static Vector2Ushort SharedCalculateLandClaimObjectCenterTilePosition(
     Vector2Ushort tilePosition,
     IProtoObjectLandClaim protoObjectLandClaim)
 {
     return(tilePosition.AddAndClamp(protoObjectLandClaim.Layout.Center.ToVector2Int()));
 }