コード例 #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);
        }
コード例 #2
0
        public void TryPlaceBuild()
        {
            if (Input.GetButtonDown("RMB"))
            {
                Destroy(obj);
                place = false;
            }
            RaycastHit hit;
            Ray        ray = Camera.main.ScreenPointToRay(Input.mousePosition);

            Physics.Raycast(ray, out hit, 10000);
            for (int x = 0; x < build.cost.Length; x++)
            {
                if (build.cost[x] == 0 || ResourceManagerPlayerOnly.resourceTypes[x].amount >= build.cost[x])
                {
                    continue;
                }
                Destroy(obj);
                place = false;
            }
            if (!hit.collider)
            {
                return;
            }
            int i = uGrid.DetermineLocation(hit.point, gridI);

            if (!uGrid.IsValidLocation(i))
            {
                return;
            }
            if (uGrid.grids[gridI].points[i].state != 2)
            {
                loc = i;
                obj.transform.position = uGrid.grids[gridI].points[i].loc;
            }
            if (!Input.GetButtonDown("LMB"))
            {
                return;
            }
            try
            {
                Actor.Create <Game.Actors.Buildings.Building>(
                    BuildingHelper.DetermineBuildingType(BuildingHelper.PrefabToType(build.obj)),
                    PlaceProgressBuilding(
                        build,
                        unitSelect.curSelectedS,
                        GameManager.Instance.GuiPlayer.FactionIndex,
                        new Position(loc),
                        obj.transform.rotation,
                        ResourceManagerPlayerOnly),
                    GameManager.Instance.GuiPlayer);
            }
            catch (InvalidOperationException)
            {
                return;
            }
            if (!Input.GetButton("ContinuePlace"))
            {
                Destroy(obj);
                place  = false;
                placed = true;
            }
        }