Ejemplo n.º 1
0
    public void ClientCardPeel(int grabbed_id, int player_id)
    {
        // Return if player is already holding something
        foreach (GameObject grabbable in grabbable_objects)
        {
            if (grabbable.GetComponent <GrabbableScript>().held_by_player_ == player_id)
            {
                return;
            }
        }
        // Find the deck, return if can't find it
        GameObject deck = null;

        foreach (GameObject grabbable in grabbable_objects)
        {
            if (grabbable.GetComponent <GrabbableScript>().id_ == grabbed_id &&
                grabbable.GetComponent <DeckScript>())
            {
                deck = grabbable;
            }
        }
        if (!deck)
        {
            return;
        }
        // Grab whatever card is on top of the deck, depending on which way
        // the deck is facing
        GameObject card = null;

        if ((deck.rigidbody.rotation * new Vector3(0, 1, 0)).y >= 0.0f)
        {
            card = deck.GetComponent <DeckScript>().TakeCard(true);
        }
        else
        {
            card = deck.GetComponent <DeckScript>().TakeCard(false);
        }
        card.GetComponent <GrabbableScript>().held_by_player_ = player_id;
        CursorScript cursor_script = null;

        foreach (GameObject cursor in cursor_objects)
        {
            if (cursor.GetComponent <CursorScript>().id() == player_id)
            {
                cursor_script = cursor.GetComponent <CursorScript>();
            }
        }
        cursor_script.SetCardFaceUp((card.transform.up.y < 0.0f));
        cursor_script.SetCardRotated(GetRotateFromGrabbable(card));
        card.GetComponent <CardScript>().PickUpSound();
    }
Ejemplo n.º 2
0
    public void ClientGrab(int grabbed_id, int player_id)
    {
        // Check if client is already holding dice or tokens
        bool holding_anything          = false;
        bool holding_anything_but_dice = false;

        foreach (GameObject grabbable in grabbable_objects)
        {
            GrabbableScript grabbable_script = grabbable.GetComponent <GrabbableScript>();
            if (grabbable_script.held_by_player_ == player_id)
            {
                holding_anything = true;
                if (!grabbable.GetComponent <DiceScript>())
                {
                    holding_anything_but_dice = true;
                }
            }
        }
        CursorScript cursor_script = null;

        foreach (GameObject cursor in cursor_objects)
        {
            if (cursor.GetComponent <CursorScript>().id() == player_id)
            {
                cursor_script = cursor.GetComponent <CursorScript>();
            }
        }
        // See if client can grab object given already-grabbed objects
        foreach (GameObject grabbable in grabbable_objects)
        {
            GrabbableScript grabbable_script = grabbable.GetComponent <GrabbableScript>();
            if (grabbable_script.id_ == grabbed_id)
            {
                if (grabbable_script.held_by_player_ == player_id)
                {
                    return;
                }
                if ((grabbable.GetComponent <DiceScript>() && !holding_anything_but_dice) ||
                    (grabbable.GetComponent <TokenScript>() && !holding_anything) ||
                    (grabbable.GetComponent <ParentTokenScript>() && !holding_anything) ||
                    (grabbable.GetComponent <DeckScript>() && !holding_anything) ||
                    (grabbable.GetComponent <CardScript>() && !holding_anything) ||
                    (grabbable.GetComponent <CoinScript>() && !holding_anything))
                {
                    grabbable_script.held_by_player_ = player_id;
                    if (grabbable.GetComponent <DiceScript>())
                    {
                        grabbable.GetComponent <DiceScript>().PickUpSound();
                    }
                    if (grabbable.GetComponent <CoinScript>())
                    {
                        grabbable.GetComponent <CoinScript>().PickUpSound();
                    }
                    if (grabbable.GetComponent <DeckScript>())
                    {
                        cursor_script.SetCardFaceUp((grabbable.transform.up.y > 0.0f));
                        cursor_script.SetCardRotated(GetRotateFromGrabbable(grabbable));
                        grabbable.GetComponent <DeckScript>().PickUpSound();
                    }
                    if (grabbable.GetComponent <CardScript>())
                    {
                        cursor_script.SetCardFaceUp((grabbable.transform.up.y < 0.0f));
                        cursor_script.SetCardRotated(GetRotateFromGrabbable(grabbable));
                        grabbable.GetComponent <CardScript>().PickUpSound();
                    }
                    if (grabbable.GetComponent <TokenScript>())
                    {
                        grabbable.GetComponent <TokenScript>().PickUpSound();
                    }
                    if (grabbable.GetComponent <ParentTokenScript>())
                    {
                        grabbable.GetComponent <ParentTokenScript>().PickUpSound();
                        cursor_script.SetCardRotated(GetRotateFromGrabbable(grabbable));
                    }
                    grabbable.rigidbody.mass = 0.2f;
                }
            }
        }
    }