Пример #1
0
    /// <summary>
    /// Handles left clicking when placing a building
    /// </summary>
    /// <param name="location">The location the action occured from</param>
    private void BuildingMouseLeft(LocationStruct location)
    {
        Building building = currentObject.GetComponent <Building>();

        if (building == null)
        {
            return;
        }
        ResourceCost resCost = currentObject.GetComponent <ResourceCost>();

        if (resCost == null)
        {
            Debug.Log(string.Format("Buildable object {0} does not have a resource cost script", currentObject.name));
        }
        if (!resCost.CheckCost())
        {
            return;
        }
        resCost.DecreaseResources();
        selectedPrefab = null;
        GameObject  tile         = Board.board[location.row, location.column];
        TileControl tc           = tile.GetComponent <TileControl>();
        GameObject  actualObject = (GameObject)PhotonNetwork.Instantiate(Utils.RemoveClone(currentObject.name), currentObject.transform.position, currentObject.transform.rotation, 0);

        Destroy(HUD.currentObject);
        currentObject = null;

        tc.SetOccupyingObject(actualObject);
        actualObject.GetComponent <BoardLocation>().SetLocation(location.row, location.column);

        currState = ActionState.NO_ACTION;
    }
Пример #2
0
    /// <summary>
    /// Displays the resources required for the selected object as well as the current amount of resources
    /// </summary>
    /// <param name="args"></param>
    /// <returns></returns>
    public string GetCurrentResources(params string[] args)
    {
        if (HUD.currentObject == null)
        {
            return("You have to select a building for this to work");
        }
        HUD           hud           = Camera.main.GetComponent <HUD>();
        GameResources resources     = hud.GetResources();
        GameObject    currentObject = HUD.currentObject;
        ResourceCost  resCost       = currentObject.GetComponent <ResourceCost>();
        string        ret           = string.Format("Costs: {0} {1} {2}\r\n", resCost.CostRes1, resCost.CostRes2, resCost.CostRes3);

        ret += string.Format("Current resources: {0} {1} {2}\r\n", resources.GetResource(GameResources.ResourceTypes.RES1), resources.GetResource(GameResources.ResourceTypes.RES2), resources.GetResource(GameResources.ResourceTypes.RES3));
        ret += string.Format("Output of checkcost: {0}\r\n", resCost.CheckCost());
        return(ret);
    }
Пример #3
0
    /// <summary>
    /// Responds to a hud action
    /// </summary>
    /// <param name="go">The gameobject that was clicked</param>
    public override void HUDAction(GameObject go)
    {
        ResourceCost resCost = go.GetComponent <ResourceCost>();

        if (resCost == null)
        {
            Debug.LogError(string.Format("Buildable object {0} does not have a resource cost script", go.name));
        }
        if (!resCost.CheckCost())
        {
            return;
        }
        resCost.DecreaseResources();
        ProductionStruct ps = new ProductionStruct();

        ps.productionObject = go;
        ps.turnsLeft        = go.GetComponent <Unit>().BuildTurns;
        buildQueue.Add(ps);
    }