コード例 #1
0
    void actionsQueueMoniter()
    {
        if (buildingActionQueue.Count > 0)
        {
            //if (buildingActionQueue[0].enabled == false)
            //{
            //    buildingActionQueue[0].enabled = true;
            //}

            //if (buildingActionQueue[0].started== false)
            //{
            //    buildingActionQueue[0].startAction();
            //    buildingActionQueue[0].doAction();
            //}
            //else
            //{
            //    if (buildingActionQueue[0].callEachFrame==true)
            //    {
            //        buildingActionQueue[0].doAction();
            //    }
            //}
            // if (buildingActionQueue[0].areWeDone() == true)
            //{
            buildingActionQueue[0].onComplete();
            BuildingAction ba = buildingActionQueue[0];
            buildingActionQueue.RemoveAt(0);
            Destroy(ba.gameObject);
            //}
        }
    }
コード例 #2
0
    private void InteractWithBoard(BuildingAction action)
    {
        Ray        ray = Camera.main.ScreenPointToRay(Input.mousePosition);
        RaycastHit hit = new RaycastHit();

        if (Physics.Raycast(ray, out hit, 1000.0f))
        {
            Vector3 gridPosition = _board.CalculateGridPosition(hit.point);

            // UnityEngine.EventSystems.EventSystem.current.IsPointerOverGameObject() => UI 오브젝트를 눌렀는지 판단
            if (!UnityEngine.EventSystems.EventSystem.current.IsPointerOverGameObject())
            {
                if (action == BuildingAction.Build && _board.CheckForBuildingAtPosition(gridPosition) == null)
                {
                    if (_city.Cash >= _selectedBuilding.cost)
                    {
                        _city.DepositCash(-_selectedBuilding.cost);
                        _uiController.UpdateCityData();
                        _city.buildingCounts[_selectedBuilding.id]++;
                        _board.AddBuilding(_selectedBuilding, gridPosition);
                    }
                }
                else if (action == BuildingAction.Remove && _board.CheckForBuildingAtPosition(gridPosition) != null)
                {
                    _city.DepositCash(_board.CheckForBuildingAtPosition(gridPosition).cost / 2);
                    _uiController.UpdateCityData();
                    _board.RemoveBuilding(gridPosition);
                }
            }
        }
    }
コード例 #3
0
    void drawBuildingActionButtons()
    {
        List <GameObject> building = SelectionManager.me.getSelected();

        if (building.Count > 0)
        {
            Building b = building[0].GetComponent <Building>();
            List <BuildingAction> buildActions = b.actionsWeCanPerform;

            if (buildActions.Count > 0)
            {
                string queueInfo = "";
                if (b.buildingActionQueue.Count == 0)
                {
                    queueInfo = "No actions queued";
                }
                else
                {
                    queueInfo = "\n" + b.buildingActionQueue[0].getProgress() + "\n" + "There are" +
                                (b.buildingActionQueue.Count - 1).ToString() + " actions remaining" + "\n" + b.name;
                }


                string BuildingInfo = b.name;

                Rect infoPos = new Rect(20, (originalHeight - (originalHeight / 5)) + 10, originalWidth / 4, (originalHeight / 5) - 20);//have slight offsetsso there is a gap at the edge
                GUI.Box(infoPos, BuildingInfo + queueInfo);

                int xoff = 0;
                int yoff = 0;
                foreach (BuildingAction ba in buildActions)
                {
                    Rect buttonPos = new Rect(550 + (200 * xoff), originalHeight - (originalHeight / 5) + (20 + (100 * yoff)), 200, 100);

                    if (GUI.Button(buttonPos, ba.getButtonText()))
                    {
                        BuildingAction baNew = (BuildingAction)Instantiate(ba, building[0].transform);
                        building[0].gameObject.GetComponent <Building>().buildingActionQueue.Add(baNew);
                    }

                    xoff++;
                    if (xoff > 4)
                    {
                        xoff = 0;
                        yoff++;
                    }
                }
            }
        }
    }
コード例 #4
0
    private void SlimeComponentEnable()
    {
        //Debug.Log("Network is enabled");
        if (!slimeClass.isBuilding)
        {
            SlimeNetwork network = GetComponent <SlimeNetwork>();
            if (network != null)
            {
                network.enabled = true;
            }

            if (move != null && photonView.isMine)
            {
                move.StartUpdatePathLoop();                             //slime start finding the target
            }

            SlimeSummon summon = GetComponent <SlimeSummon>();
            if (summon != null && photonView.isMine)
            {
                summon.StartSummonLoop();
            }

            Guardian guardian = GetComponent <Guardian>();
            if (guardian != null && photonView.isMine)
            {
                guardian.SpellingGuardianBuff(slimeClass);
            }
        }
        else
        {
            BuildingNetwork b = GetComponent <BuildingNetwork>();
            if (b != null)
            {
                b.enabled = true;
            }

            BuildingSpawnCost money = GetComponent <BuildingSpawnCost>();
            if (money != null && photonView.isMine)
            {
                money.StartSpawnCostLoop();
            }

            BuildingAction t = GetComponent <BuildingAction>();
            if (t != null && photonView.isMine)
            {
                t.SetUpBuilding(slimeClass);
            }
        }
    }
コード例 #5
0
    // Update is called once per frame
    void Update()
    {
        selectionMode = SelectionManager.me.selectionMode;

        List <GameObject> building = SelectionManager.me.getSelected();

        if (building.Count > 0)
        {
            Building b = building[0].GetComponent <Building>();
            // if (b.actionsWeCanPerform != null)
            // {
            List <BuildingAction> buildActions = b.actionsWeCanPerform;

            if (buildActions.Count > 0)
            {
                //string queueInfo = "";
                //if (b.buildingActionQueue.Count == 0)
                //{
                //    queueInfo = "No actions queued";
                //}
                //else
                //{
                //    queueInfo = "\n" + b.buildingActionQueue[0].getProgress() + "\n" + "There are" +
                //                (b.buildingActionQueue.Count - 1).ToString() + " actions remaining" + "\n" + b.name;
                //}
                string BuildingInfo = b.name;
                foreach (BuildingAction ba in buildActions)
                {
                    if (isClicked)
                    {
                        BuildingAction baNew = (BuildingAction)Instantiate(ba, building[0].transform);
                        building[0].gameObject.GetComponent <Building>().buildingActionQueue.Add(baNew);
                        isClicked = false;
                    }
                }
            }
            // }
            if (building[0].GetComponent <Building>() == true)
            {
                buildingName.text    = building[0].GetComponent <Building>().name;
                buildingImage.sprite = building[0].GetComponent <Building>().buildingSprite;
            }
            else
            {
                Debug.Log("ffe");
            }
        }
    }
コード例 #6
0
    public bool CanAffordBuildingAction(Vector3Int position, BuildingAction action)
    {
        GameObject buildingLogic = _positionToBuildingLogic[position];
        float      playerMind    = playerStats.GetMind();

        switch (action)
        {
        case BuildingAction.REPAIR:
            return(playerMind >= GetRepairCost(buildingLogic.GetComponent <BuildingHealth>()));

        case BuildingAction.UPGRADE_HEALTH:
            return(playerMind >= GetHealthUpgradeCost(buildingLogic.GetComponent <BuildingHealth>()));

        case BuildingAction.UPGRADE_PRODUCTION:
            return(playerMind >= GetProductionUpgradeCost(buildingLogic.GetComponent <BuildingLogicBase>()));

        default:
            Debug.LogError("Unexpected branch in CanAffordBuildingAction");
            Debug.LogError($"Action {action}");
            return(false);
        }
    }
コード例 #7
0
    public void ExecuteActionOnBuilding(Vector3Int position, BuildingAction action)
    {
        GameObject        buildingLogic = _positionToBuildingLogic[position];
        BuildingHealth    health        = buildingLogic.GetComponent <BuildingHealth>();
        BuildingLogicBase logic         = buildingLogic.GetComponent <BuildingLogicBase>();

        switch (action)
        {
        case BuildingAction.UPGRADE_HEALTH:
            int healthUpgradeCost = GetHealthUpgradeCost(health);
            if (healthUpgradeCost > playerStats.GetMind())
            {
                Debug.Log("Upgrade health failed");
                return;
            }
            health.DoUpgradeHealth();
            playerStats.UpdateMind(-healthUpgradeCost);

            ConstructionSpace space = _positionToConstructionSpace[position];
            if (health.WallSprite != null && !_constructionSpaceToWallSprite.ContainsKey(space))
            {
                GameObject wallSprite = Instantiate(WallPrefab);
                wallSprite.GetComponent <SpriteRenderer>().sprite = health.WallSprite;
                wallSprite.transform.position         = GetConstructionSpaceWorldCenter(space) + Vector3.back;
                _constructionSpaceToWallSprite[space] = wallSprite;
            }

            switch (logic.GetBuildingType())
            {
            case "library":
                audioManager.PlayUpLibrary();
                break;

            case "market":
                audioManager.PlayUpMarket();
                break;

            case "gym":
                audioManager.PlayUpGym();
                break;

            case "amp":
                audioManager.PlayUpAmp();
                break;

            case "vice":
                audioManager.PlayUpVice();
                break;
            }
            return;

        case BuildingAction.UPGRADE_PRODUCTION:
            int productionUpgradeCost = GetProductionUpgradeCost(logic);
            if (productionUpgradeCost > playerStats.GetMind())
            {
                Debug.Log("Upgrade production failed");
                return;
            }
            logic.DoUpgradeProduction();
            playerStats.UpdateMind(-productionUpgradeCost);
            switch (logic.GetBuildingType())
            {
            case "library":
                audioManager.PlayUpLibrary();
                break;

            case "market":
                audioManager.PlayUpMarket();
                break;

            case "gym":
                audioManager.PlayUpGym();
                break;

            case "amp":
                audioManager.PlayUpAmp();
                break;

            case "vice":
                audioManager.PlayUpVice();
                break;
            }
            return;

        case BuildingAction.REPAIR:
            audioManager.PlayBuildingBuilt();
            int repairCost = GetRepairCost(health);
            if (repairCost > playerStats.GetMind())
            {
                Debug.Log("Repair failed");
                return;
            }
            health.DoRepair();
            playerStats.UpdateMind(-repairCost);
            return;
        }
    }