Exemplo n.º 1
0
        void SpawnCrate(Actor self, CrateSpawnerInfo info)
        {
            var threshold = 100;
            var inWater   = self.World.SharedRandom.NextDouble() < info.WaterChance;

            for (var n = 0; n < threshold; n++)
            {
                var p = self.World.ChooseRandomCell(self.World.SharedRandom);

                // Is this valid terrain?
                var terrainType = self.World.GetTerrainType(p);
                if (!(inWater ? info.ValidWater : info.ValidGround).Contains(terrainType))
                {
                    continue;
                }

                // Don't spawn on any actors
                if (self.World.WorldActor.Trait <BuildingInfluence>().GetBuildingAt(p) != null)
                {
                    continue;
                }
                if (self.World.ActorMap.GetUnitsAt(p).Any())
                {
                    continue;
                }

                self.World.AddFrameEndTask(
                    w => crates.Add(w.CreateActor("crate", new TypeDictionary
                {
                    new LocationInit(p),
                    new OwnerInit(self.World.WorldActor.Owner),
                })));
                return;
            }
        }
Exemplo n.º 2
0
 public CrateSpawner(CrateSpawnerInfo info, Actor self)
 {
     this.info = info;
     this.self = self;
 }