コード例 #1
0
        /// <summary>
        /// Execute action on the selected target
        /// </summary>
        /// <param name="target">Selected target</param>
        public override void Execute(ITargetable target)
        {
            switch (SpawnableDef)
            {
            case BuildingDef buildingDef:
                using (ConstructingBuildingFactory factory = new ConstructingBuildingFactory(factionController))
                {
                    ConstructingBuildingController building = factory.CreateConstructingBuildingControllerOf(buildingDef);
                    SpawnBuilding(building, target);
                }

                break;

            case UnitDef unitDef:
                using (UnitFactory factory = new UnitFactory(factionController, gameController))
                {
                    UnitController unit = factory.CreateNewUnit(unitDef);
                    SpawnUnit(unit, target);
                }

                break;

            default:
                throw new NotImplementedException();
            }
        }
        public static ConstructingBuildingController CreateNewBUCAt(IStructureDef def, Coords topLeft, Faction_Controller factionController)
        {
            ConstructingBuildingController constructingBuildingController = CreateNewBUC((ConstructingBuildingDef)def, factionController);

            constructingBuildingController.ConstructingBuildingModel = new ConstructingBuildingModel()
            {
                StartCoords = topLeft
            };

            return(constructingBuildingController);
        }
コード例 #3
0
        /// <summary>
        /// Spawns IStructure:
        /// <para>- Adds structure to world</para>
        /// <para>- Registers building to faction</para>
        /// <para>- Subscribes Update to Game's onTick</para>
        /// <para>- If ConstructingBuilding, Registers finish-time</para>
        /// </summary>
        /// <param name="spawnCoords">Where to spawn, 'StartCoords'</param>
        /// <param name="structure">What to spawn</param>
        public virtual void SpawnStructure(Coords spawnCoords, IStructure <IStructureDef> structure)
        {
            structure.StartCoords = spawnCoords;

            World.AddStructure(structure);

            structure.Faction.RegisterBuilding(structure);

            Game.onTick += structure.Update;

            if (!(structure is ConstructingBuildingController))
            {
                return;
            }

            ConstructingBuildingController constructingBuilding = (ConstructingBuildingController)structure;

            constructingBuilding.ConstructingBuildingModel.FinishTime = (int)(constructingBuilding.Def.ConstructionTime + Game.LastUpdateGameTime.TotalGameTime.TotalSeconds);
        }
        /// <summary>
        /// Creates new ConstructingBuilding from ConstructingBuildingDef
        /// </summary>
        /// <param name="structureDef">ConstructingBuilding's definition</param>
        /// <returns>ConstructingBuildingController</returns>
        public ConstructingBuildingController CreateBUC(ConstructingBuildingDef structureDef)
        {
            ConstructingBuildingController building = new ConstructingBuildingController(structureDef)
            {
                ConstructingBuildingModel =
                {
                    FactionController = faction
                }
            };


            ConstructingBuildingView view = new ConstructingBuildingView(CONSTRUCTION_IMAGE_SOURCE)
            {
                Model = building.ConstructingBuildingModel
            };

            building.ConstructingBuildingView = view;

            return(building);
        }
        private static ConstructingBuildingController CreateNewBUC(ConstructingBuildingDef def,
                                                                   Faction_Controller factionController)
        {
            ConstructingBuildingController building = new ConstructingBuildingController(def)
            {
                ConstructingBuildingModel =
                {
                    FactionController = factionController
                }
            };


            ConstructingBuildingView view = new ConstructingBuildingView(CONSTRUCTION_IMAGE_SOURCE)
            {
                Model = building.ConstructingBuildingModel
            };

            building.ConstructingBuildingView = view;

            return(building);
        }
コード例 #6
0
        /// <summary>
        /// Spawns a building at a target location
        /// </summary>
        /// <param name="building">building to be spawned</param>
        /// <param name="spawntarget">The target</param>
        private void SpawnBuilding(IStructure <IStructureDef> building, ITargetable spawntarget)
        {
            ConstructingBuildingController constructingBuilding = ConstructingBuildingFactory.CreateNewBUCAt(building.Def, (Coords)spawntarget.FloatCoords, factionController);

            gameController.Spawner.SpawnStructure((Coords)spawntarget.FloatCoords, constructingBuilding);
        }