Beispiel #1
0
    public void StartTargeting()
    {
        Debug.Log("StartTargeting");
        // register that we want to be told when something gets targeted
        GameClientController gameClient = FindObjectOfType <GameClientController>();

        gameClient.TargetingCallback = SetTarget;
        gameClient.EnterTargetingMode();
    }
    private void TryDeploy(GameClientController gameClient, Ship ship, Shipyard shipyard)
    {
        Debug.Log(string.Format("Trying to deploy {0}({1}) from {2}({3})", ship.CardName, ship.CardId, shipyard.CardName, shipyard.CardId));
        if (gameClient.TryDeployShip(ship, shipyard))
        {
            Debug.Log("Deploy successful");

            // remove this construction panel
            Destroy(transform.parent.gameObject);
        }
    }
Beispiel #3
0
    private void TryDeploy(GameClientController gameClient, Ship ship, Shipyard shipyard)
    {
        Debug.Log(string.Format("Trying to deploy {0}({1}) from {2}({3})", ship.CardName, ship.CardId, shipyard.CardName, shipyard.CardId));
        if (gameClient.TryDeployShip(ship, shipyard))
        {
            Debug.Log("Deploy successful");

            // remove this construction panel
            Destroy(transform.parent.gameObject);
        }
    }
Beispiel #4
0
    public void SetTarget(Card card)
    {
        Debug.Log(string.Format("Trying to target {2} with {3}'s {0} {1}", Weapon.WeaponType, Weapon.Damage, card.CardName, HostShip.CardName));
        Target = card;

        GameClientController gameClient = FindObjectOfType <GameClientController>();

        if (!gameClient.TryTarget(HostShip, WeaponIndex, Target))
        {
            ClearTarget();
        }

        // unregister callback
        gameClient.TargetingCallback = null;
    }
Beispiel #5
0
    public void AdvanceConstruction()
    {
        GameClientController gameClient = FindObjectOfType <GameClientController>();
        Transform            shipGO     = transform.parent.parent; // grandparent should be the card game object - better way to do this? search up 1 level at a time?
        Transform            shipyardGO = shipGO.parent;
        Ship     ship     = (Ship)shipGO.GetComponent <CardLink>().Card;
        Shipyard shipyard = (Shipyard)shipyardGO.GetComponent <CardLink>().Card;

        if (_constructionComplete)
        {
            TryDeploy(gameClient, ship, shipyard);
        }
        else
        {
            TryAdvance(gameClient, ship, shipyard);
        }
    }
Beispiel #6
0
    public void OnDrop(PointerEventData eventData)
    {
        DragHandler d = eventData.pointerDrag.GetComponent <DragHandler>();

        if (d != null)
        {
            CardLink cl = eventData.pointerDrag.GetComponent <CardLink>();
            if (cl != null)
            {
                if (GameClientController == null)
                {
                    GameClientController = FindObjectOfType <GameClientController>();
                }

                Card card = cl.Card;
                Debug.Log(card.CardName + " was dropped on " + gameObject.name);

                if (card.CardType == CardType.SHIP && DropZoneType == DropZoneType.PLAYER_SHIPYARD)
                {
                    // try to host the ship on the shipyard
                    Shipyard shipyard = (Shipyard)GetComponent <CardLink>().Card;

                    if (GameClientController.TryHost((Ship)card, shipyard))
                    {
                        d.returnToParent = false;
                    }
                }

                if (card.CardType == CardType.SHIPYARD && DropZoneType == DropZoneType.PLAYER_CONSTRUCTION_AREA)
                {
                    if (GameClientController.TryPlayShipyard((Shipyard)card))
                    {
                        d.returnToParent = false;
                    }
                }

                if (card.CardType == CardType.OPERATION)
                {
                    if (GameClientController.TryPlayOperation((Operation)card))
                    {
                        d.returnToParent = false;
                    }
                }
            }
        }
    }
    public void OnDrop(PointerEventData eventData)
    {
        DragHandler d = eventData.pointerDrag.GetComponent<DragHandler>();
        if (d != null)
        {
            CardLink cl = eventData.pointerDrag.GetComponent<CardLink>();
            if (cl != null)
            {
                if (GameClientController == null)
                    GameClientController = FindObjectOfType<GameClientController>();

                Card card = cl.Card;
                Debug.Log(card.CardName + " was dropped on " + gameObject.name);

                if (card.CardType == CardType.SHIP && DropZoneType == DropZoneType.PLAYER_SHIPYARD)
                {
                    // try to host the ship on the shipyard
                    Shipyard shipyard = (Shipyard)GetComponent<CardLink>().Card;

                    if (GameClientController.TryHost((Ship)card, shipyard))
                    {
                        d.returnToParent = false;
                    }
                }

                if (card.CardType == CardType.SHIPYARD && DropZoneType == DropZoneType.PLAYER_CONSTRUCTION_AREA)
                {
                    if (GameClientController.TryPlayShipyard((Shipyard)card))
                    {
                        d.returnToParent = false;
                    }

                }

                if (card.CardType == CardType.OPERATION)
                {
                    if (GameClientController.TryPlayOperation((Operation)card))
                    {
                        d.returnToParent = false;
                    }
                }
            }
        }
    }
Beispiel #8
0
    private void TryAdvance(GameClientController gameClient, Ship ship, Shipyard shipyard)
    {
        Debug.Log(string.Format("Trying to advance construction of {0}({1}) on {2}({3})", ship.CardName, ship.CardId, shipyard.CardName, shipyard.CardId));
        if (gameClient.TryAdvanceConstruction(ship, shipyard))
        {
            Debug.Log("Advance successful, trying to update GUI");
            // successfully advanced - decrement the amount
            Text constructionRemaining = (Text)transform.parent.Find("ConstructionRemaining").GetComponent(typeof(Text));
            constructionRemaining.text = ship.ConstructionRemaining.ToString();

            if (ship.ConstructionRemaining == 0)
            {
                _constructionComplete = true;

                // change button text
                Text button = (Text)transform.Find("AdvanceConstructionButtonText").GetComponent(typeof(Text));
                button.text = "Deploy";
            }
        }
    }
    private void TryAdvance(GameClientController gameClient, Ship ship, Shipyard shipyard)
    {
        Debug.Log(string.Format("Trying to advance construction of {0}({1}) on {2}({3})", ship.CardName, ship.CardId, shipyard.CardName, shipyard.CardId));
        if (gameClient.TryAdvanceConstruction(ship, shipyard))
        {
            Debug.Log("Advance successful, trying to update GUI");
            // successfully advanced - decrement the amount
            Text constructionRemaining = (Text)transform.parent.FindChild("ConstructionRemaining").GetComponent(typeof(Text));
            constructionRemaining.text = ship.ConstructionRemaining.ToString();

            if (ship.ConstructionRemaining == 0)
            {
                _constructionComplete = true;

                // change button text
                Text button = (Text)transform.FindChild("AdvanceConstructionButtonText").GetComponent(typeof(Text));
                button.text = "Deploy";
            }
        }
    }
    // Update is called once per frame
    void Update()
    {
        transform.position = Camera.main.ScreenToWorldPoint(new Vector3(Input.mousePosition.x, Input.mousePosition.y, 10));

        if (Input.GetMouseButtonUp(0))
        {
            Debug.Log("Left mouse button clicked");
            GameClientController gameClient = FindObjectOfType <GameClientController>();

            PointerEventData pointerData = new PointerEventData(EventSystem.current)
            {
                pointerId = -1,
            };

            pointerData.position = Input.mousePosition;

            List <RaycastResult> results = new List <RaycastResult>();
            EventSystem.current.RaycastAll(pointerData, results);

            foreach (RaycastResult result in results)
            {
                var cardLink = result.gameObject.GetComponent <CardLink>();
                if (cardLink != null)
                {
                    gameClient.TargetingCallback(cardLink.Card);
                    break;
                }
            }
            Destroy(this.gameObject);
        }
        if (Input.GetMouseButtonUp(1))
        {
            Debug.Log("Right mouse button clicked");
            Destroy(this.gameObject);
        }
    }
 private void ui_ButtonJoinServer_Click(object sender, RoutedEventArgs e)
 {
     GameClientController clientController = new GameClientController();
 }