Exemple #1
0
        /// <summary>
        /// Sends the Worker to Create a Building of a specific type.
        /// </summary>
        /// <param name="buildingType">Type of the Building to be created.</param>
        /// <param name="position">Position where the Building will be placed.
        /// Use Position.IsValidPlacement to check if the position can be used.</param>
        /// <returns>Instance of the building in a progress state.</returns>
        public IBuilding CreateBuilding(BuildingType buildingType, Position position)
        {
            // TODO:
            // 1. send worker to the position near building, queued event when arrival
            // 2. start construction object, queued event when finished
            // 2.5. if interrupted, worker can repeat step 1 and continue on 2 without creating a new object
            // 3. finished event, return to gather
            StopGathering();
            var player = Player.CurrentPlayer;
            var actor  = Create <Building>(
                BuildingHelper.DetermineBuildingType(buildingType),
                BuildingPlacement.PlaceProgressBuilding(
                    BuildingHelper.FindBuildingInFaction(buildingType, UnitController),
                    new List <UnitController> {
                UnitController
            },
                    UnitController.FactionIndex,
                    position,
                    Quaternion.identity,
                    GameManager.Instance.ResourceManagerFaction[UnitController.FactionIndex]
                    ),
                player
                );

            // TODO: make sure the CurrentPlayer stays the same after the movement
            Tutorial.Instance.CreateBuilding();
            // TODO: asynchronous after the movement
            GameManager.Instance.FiredEvent(player, GameEventType.BuildingStartedConstruction, new Arguments
            {
                MyUnit     = this,
                MyBuilding = actor
            });
            return(actor);
        }