Ejemplo n.º 1
0
    protected void SelectRoadLocation()
    {
        if (Input.GetMouseButtonUp(0))
        {
            Ray ray = Camera.main.ScreenPointToRay(Input.mousePosition);

            if (Physics.Raycast(ray, out RaycastHit hit))
            {
                //Debug.Log(hit.collider.name);
                if (hit.collider.tag == "Path") // click on another player, enemy, building
                {
                    WorldPath p = hit.collider.transform.GetComponent <WorldPath>();

                    if (p.IsAvailable() && selectablePaths.Contains(p))
                    {
                        TogglePathBlink();

                        if (currentTurn == 1)
                        {
                            currentPhase = Phase.SECOND_SETTLEMENT_PLACEMENT;

                            p.ConstructRoad(PhotonNetwork.LocalPlayer.ActorNumber);



                            myRoads.Add(p);

                            inventory.TakeFromPlayer(Inventory.UnitCode.ROAD, 1);

                            EndLocalTurn();
                        }
                        else if (currentTurn == 2)
                        {
                            p.ConstructRoad(PhotonNetwork.LocalPlayer.ActorNumber);



                            myRoads.Add(p);

                            inventory.TakeFromPlayer(Inventory.UnitCode.ROAD, 1);

                            EndLocalTurn();
                        }
                        else
                        {
                            if (currentPhase == Phase.PLAYED_EXPANSION_CARD)
                            {
                                // Free road placement.

                                p.ConstructRoad(PhotonNetwork.LocalPlayer.ActorNumber);

                                myRoads.Add(p);

                                inventory.TakeFromPlayer(Inventory.UnitCode.ROAD, 1);

                                freeRoadsPlaced++;
                                // If second one is placed, put up event text.

                                if (freeRoadsPlaced == 2)
                                {
                                    eventTextController.SendEvent(EventTextController.EventCode.PLAYER_IDLE, PhotonNetwork.LocalPlayer);
                                    currentPhase = Phase.TRADE_BUILD_IDLE;
                                }
                            }
                            else
                            {
                                // Pay resources
                                inventory.PayRoadConstruction();


                                p.ConstructRoad(PhotonNetwork.LocalPlayer.ActorNumber);

                                myRoads.Add(p);

                                inventory.TakeFromPlayer(Inventory.UnitCode.ROAD, 1);

                                // Inform event text.

                                eventTextController.SendEvent(EventTextController.EventCode.ROAD_CONSTRUCTED, PhotonNetwork.LocalPlayer);

                                eventTextController.SendEvent(EventTextController.EventCode.PLAYER_IDLE, PhotonNetwork.LocalPlayer);
                                currentPhase = Phase.TRADE_BUILD_IDLE;
                            }
                        }
                    }
                }
            }
        }
    }