Exemple #1
0
    private void DropItem()
    {
        if (!heldItem)
        {
            return;
        }

        HoldableItem holdableItem = heldItem.GetComponent <HoldableItem>();

        if (!holdableItem)
        {
            return;
        }

        heldItem = null;
        hasItem  = false;

        //  Remove parent hand
        holdableItem.transform.SetParent(null);

        if (playerController.facingDirection == PlayerController.FacingDirection.Left)
        {
            holdableItem.transform.position = new Vector3(holdableItem.transform.position.x - 1, holdableItem.transform.position.y, transform.position.z);
        }
        else
        {
            holdableItem.transform.position = new Vector3(holdableItem.transform.position.x + 1, holdableItem.transform.position.y, transform.position.z);
        }

        holdableItem.boxColl[0].enabled    = true;
        holdableItem.boxColl[1].enabled    = true;
        holdableItem.rigidBody.isKinematic = false;

        //Debug.Log("Dropped item");
    }
    void Update()
    {
        if (Input.GetMouseButtonDown(0))
        {
            if (myHeldItem == null)
            {
                Vector2    mousePosition = Input.mousePosition;
                Ray        ray           = camera.ScreenPointToRay(mousePosition);
                RaycastHit raycastHit;
                Physics.Raycast(ray, out raycastHit);
                if (raycastHit.collider != null)
                {
                    Debug.Log(raycastHit.collider.gameObject.name);
                    HoldableItem item = (raycastHit.collider.gameObject.GetComponent <HoldableItem>());
                    if (item == null)
                    {
                        item = (raycastHit.collider.gameObject.GetComponentInParent <HoldableItem>());
                    }
                    if (item != null)
                    {
                        GrabItem(item);
                    }
                }
            }
        }

        if (Input.GetMouseButtonUp(0))
        {
            ReleaseItem();
        }
    }
 /// <summary>
 /// Gets the holdable item component of this food item
 /// </summary>
 /// <returns></returns>
 public HoldableItem GetHoldableItemComponent()
 {
     if (_holdableItemComponent == null)
     {
         _holdableItemComponent = GetComponent <HoldableItem>();
     }
     return(_holdableItemComponent);
 }
Exemple #4
0
 private void  OnChoppableItemOnBoardPickedUp(HoldableItem itemOnBoard)
 {
     if (itemOnBoard.HoldingState == HoldableItem.HeldState.Held)
     {
         itemOnBoard.OnHoldStateChange.RemoveListener(OnChoppableItemOnBoardPickedUp);
         OnChoppableItemUnboarded.Invoke(choppableItemOnBoard);
         choppableItemOnBoard = null;
     }
 }
Exemple #5
0
    public override void PlayerDroppedItem(HoldableItem droppedItem, PlayerController playerThatDroppedTheItem)
    {
        Disposable disposableItem = droppedItem.GetComponent <Disposable>();

        if (disposableItem != null)
        {
            GameManager.GameManagerSingleton.ModifyPlayerScore(playerThatDroppedTheItem.Player, -disposableItem.PointsDeductedForDisposing());
            disposableItem.Dispose(playerThatDroppedTheItem);
        }
    }
    void Awake()
    {
        usable   = GetComponent <UsableItem>();
        holdable = GetComponent <HoldableItem>();
        rb       = GetComponent <Rigidbody>();
        collider = GetComponent <Collider>();

        usable.OnUsed      += HandleUse;
        holdable.OnGrabbed += HandleGrab;
    }
    private void Yeet()
    {
        Rigidbody itemRB = item.transform.GetComponent <Rigidbody>();

        itemRB.isKinematic            = false;
        itemRB.useGravity             = true;
        itemRB.collisionDetectionMode = CollisionDetectionMode.ContinuousSpeculative;
        itemRB.AddForce(this.direction * throwPower + Vector3.up * 2f, ForceMode.Impulse);

        this.item = null;
    }
Exemple #8
0
 public override void PlayerDroppedItem(HoldableItem droppedItem, PlayerController playerThatDroppedTheItem)
 {
     if (servingAreaParent.transform.childCount >= 1)
     {
         return;
     }
     droppedItem.ToggleRigidBodyKinematic(true);
     droppedItem.transform.SetParent(servingAreaParent);
     droppedItem.transform.position = servingAreaParent.transform.position;
     OnAreaServed.Invoke(droppedItem, playerThatDroppedTheItem);
 }
Exemple #9
0
    private IEnumerator InitialiseSportsItem(HoldableItem item)
    {
        Instantiate(projectorSound);
        yield return(new WaitForSeconds(projectorSoundDelay));

        SportsItemSpotLight spotLight = Instantiate(sportsItemSpotLightPreFab);

        spotLight.target = item.transform;
        spotLight.GoHome();
        item.rigidbody.isKinematic = false;
    }
    public IEnumerator PickUpItemeEnum(HoldableItem item)
    {
        _inProgress = true;
        Debug.Log("Picking up item");
        _currentlyHeldItem = item;
        Services.UIManager.HideItemPickupPrompt();
        PlayerAnimation.Pickup();
        yield return(new WaitForSeconds(.33f));

        AttachToTransform(item);
        _inProgress = false;
    }
Exemple #11
0
    /// <summary>
    /// Method called to drop the item held in hand
    /// </summary>
    public HoldableItem DropItem()
    {
        // Get the next item dropped from the hand
        HoldableItem droppedItem = DropAndGetHeldItem();

        // If the dropped item isn't null,
        // Then set its parent to null and
        // turn off the IsKinematic on the rigidbody
        if (droppedItem != null)
        {
            droppedItem.transform.parent = null;
            droppedItem.ToggleRigidBodyKinematic(false);
        }
        return(droppedItem);
    }
Exemple #12
0
    void ChopLog()
    {
        GameObject   log    = Instantiate(spawnedLogPrefab, transform.position + new Vector3(0.5f, 1f, 0.5f), Quaternion.identity);
        HoldableItem script = log.GetComponent <HoldableItem>();

        script.player = player;

        health -= 1;

        transform.localScale = initialScale * ((float)health / maxHealth);

        if (health == 0)
        {
            SetRespawnTimer();
        }
    }
    private HoldableItem GetClosestItem()
    {
        HoldableItem closest      = null;
        float        shortestDist = 1000f;

        foreach (HoldableItem item in _itemsInCollider)
        {
            float dist = DistanceTo(item);
            if (dist < shortestDist)
            {
                shortestDist = dist;
                closest      = item;
            }
        }
        return(closest);
    }
Exemple #14
0
    public override void PlayerDroppedItem(HoldableItem droppedItem, PlayerController player)
    {
        HoldableItem itemOnBoard = transform.GetComponentInChildren <HoldableItem>();

        if (itemOnBoard == null)
        {
            droppedItem.transform.parent   = transform;
            droppedItem.transform.position = transform.position;
            droppedItem.ToggleRigidBodyKinematic(true);
            choppableItemOnBoard = droppedItem.GetComponent <Choppable>();
            if (choppableItemOnBoard != null)
            {
                droppedItem.OnHoldStateChange.AddListener(OnChoppableItemOnBoardPickedUp);
                OnChoppableItemBoarded.Invoke(choppableItemOnBoard);
            }
        }
    }
Exemple #15
0
 /// <summary>
 /// Method called to drop the next item held by the player
 /// </summary>
 /// <returns></returns>
 public HoldableItem DropAndGetHeldItem()
 {
     // If the items in hand count is more than 0, then
     // return the first item in the list
     // Remove the item from the list of items held in hand
     // Notify the item that it's been dropped
     if (itemsInHand.Count > 0)
     {
         HoldableItem itemDropped = itemsInHand[0];
         itemsInHand.RemoveAt(0);
         itemDropped.ItemDropped();
         OnHeldItemsChanged.Invoke(this);
         return(itemDropped);
     }
     // Otherwise, return null
     else
     {
         return(null);
     }
 }
Exemple #16
0
    private IEnumerator StartScene()
    {
        HoldableItem[] sportsItems       = FindObjectsOfType <HoldableItem>();
        HoldableItem[] sortedSportsItems = new HoldableItem[sportsItems.Length];

        for (int i = 0; i < sportsItems.Length; i++)
        {
            HoldableItem item = sportsItems[i];
            item.rigidbody.isKinematic       = true;
            sortedSportsItems[item.priority] = item;
        }

        yield return(new WaitForSeconds(0.2f));

        for (int i = 0; i < sortedSportsItems.Length; i++)
        {
            StartCoroutine(InitialiseSportsItem(sortedSportsItems[i]));
            yield return(new WaitForSeconds(projectorTimeInterval));
        }
    }
Exemple #17
0
    private IEnumerator GrabItemCoroutine(HoldableItem item)
    {
        item.rigidbody.isKinematic = true;
        float addition = 2.2f;

        while (true)
        {
            Vector3 mousePosition   = GetMouseWorldPosition();
            Vector3 newItemPosition =
                Vector3.MoveTowards(item.rigidbody.position, GetMouseWorldPosition(), addition * Time.deltaTime);
            item.rigidbody.position = newItemPosition;
            if (Vector3.Distance(mousePosition, newItemPosition) < 0.01f)
            {
                break;
            }
            yield return(null);
        }

        myHeldItem = item;
    }
    private void OnTriggerExit(Collider other)
    {
        HoldableItem holdableItem = other.GetComponent <HoldableItem>();

        if (holdableItem == null)
        {
            return;
        }

        if (_itemsInCollider.Contains(holdableItem))
        {
            _itemsInCollider.Remove(holdableItem);
        }

        if (_itemsInCollider.Count <= 0)
        {
            Services.UIManager.HideItemPickupPrompt();
            canPickUpItem = false;
        }
    }
    public override void PlayerDroppedItem(HoldableItem droppedItem, PlayerController playerThatDroppedTheItem)
    {
        // If the max ingredients are held in this bowl, then do nothing
        if (MaxIngredientsHeld())
        {
            return;
        }

        // Try and get the dropped item's food game object component
        FoodGameObject droppedFood = droppedItem.GetComponent <FoodGameObject>();

        if (droppedFood != null)
        {
            // If the dropped food is bowlable, then add the salad ingredient
            if (droppedFood.FoodIngredient.IsBowlable)
            {
                AddSaladIngredientToList(droppedFood);
            }
        }
    }
Exemple #20
0
    /// <summary>
    /// Method called to hold an item
    /// </summary>
    /// <param name="item"></param>
    public void HoldItem(HoldableItem item)
    {
        // If hands are full, then do nothing
        if (HandsFull())
        {
            Debug.LogWarning("Hads are full. Could not hold item " + item.name);
            return;
        }
        // Otherwise, place the item in the hands position
        item.transform.position = playerHand.transform.position;
        item.transform.parent   = playerHand.transform;
        item.transform.rotation = transform.rotation;
        // Set the holdable item to kinematic
        item.ToggleRigidBodyKinematic(true);
        // Add the holdable item into the list of items held in hand
        itemsInHand.Add(item);
        // Notify the item that it's being held
        item.ItemHeld();

        OnHeldItemsChanged.Invoke(this);
    }
 private void PickUpItem(PlayerInput input)
 {
     if (input.pickUpPressed)
     {
         HoldableCoordinator itemProcced = playerControllerStateMachine.InteractionDetector.GetHoldableItemDetected();
         if (itemProcced != null && playerControllerStateMachine.PlayerHand.HandsFull() == false)
         {
             playerControllerStateMachine.PlayerHand.HoldItem(itemProcced.GetHoldableItem());
         }
     }
     else if (input.dropPressed)
     {
         if (playerControllerStateMachine.PlayerHand.HasAnyItemInHand())
         {
             Interactable interactable = playerControllerStateMachine.InteractionDetector.GetInteractableObjectDetected();
             HoldableItem droppedItem  = playerControllerStateMachine.PlayerHand.DropItem();
             if (interactable != null)
             {
                 interactable.PlayerDroppedItem(droppedItem, playerControllerStateMachine);
             }
         }
     }
 }
    private void OnTriggerEnter(Collider other)
    {
        HoldableItem holdableItem = other.GetComponent <HoldableItem>();

        if (_holdingItem)
        {
            return;
        }
        if (holdableItem == null)
        {
            return;
        }
        if (_itemsInCollider.Contains(holdableItem))
        {
            return;
        }

        _itemsInCollider.Add(holdableItem);

        canPickUpItem = true;

        Services.UIManager.DisplayItemPickupPrompt();
    }
 void Update()
 {
     if (photonView.IsMine)                   // Determines if you're the correct player
     {
         if (Input.GetKeyDown(KeyCode.Space)) // Throw the item
         {
             if (itemSlot.childCount != 0)
             {
                 HoldableItem heldItem = itemSlot.GetChild(0).GetComponent <HoldableItem>();
                 heldItem.transform.parent = null; // Detatch object
                                                   // Yeet(otherPlayerGORef.transform.position, 10f, heldItem);
                 YeetWrapper(heldItem);
             }
         }
         if (Input.GetKeyDown(KeyCode.Q)) // Drop item
         {
             if (itemSlot.childCount != 0)
             {
                 itemSlot.GetChild(0).parent = null;
             }
         }
     }
 }
    /// <summary>
    /// Method called when the customer is served
    /// </summary>
    /// <param name="itemServed"></param>
    /// <param name="servingPlayer"></param>
    private void CustomerAreaServed(HoldableItem itemServed, PlayerController servingPlayer)
    {
        // Try to get the salad locator on the item served
        SaladLocator saladLocator = itemServed.GetComponent <SaladLocator>();

        // If the salad item is not null, then see if the salad ingredients match the order ingredients
        if (saladLocator != null)
        {
            // Check if the ingredient lists are the same
            if (AreIngredientListsTheSame(CustomerOrder, saladLocator.SaladBowlAttached.SaladIngredients))
            {
                // If yes, then the customer has been served
                customerServed = true;
                // Remove the listener from the on area served event
                servingArea.OnAreaServed.RemoveListener(CustomerAreaServed);
                // Consume the ingredients in the bowl
                saladLocator.SaladBowlAttached.ConsumeBowl();
                // Reward the corresponding player using the respective player logic handler
                if (customerLogicHandler != null)
                {
                    customerLogicHandler.RewardPlayer(servingPlayer.Player, this);
                }
                OnCustomerCorrectlyServed.Invoke(this);
            }
            // Otherwise, the player served the wrong order, call the player served wrong order
            else
            {
                PlayerServedWrongOder(servingPlayer);
            }
        }
        // If the item served is not a salad, make the customer angry lol
        else
        {
            PlayerServedWrongOder(servingPlayer);
        }
    }
    public void InputPressed()
    {
        if (_inProgress)
        {
            return;
        }
        // If the player has an item in their possession, drop it.
        if (_holdingItem)
        {
            DropItem();
            return;
        }

        // otherwise, check if there are any items that can be picked up.

        if (_itemsInCollider.Count == 0)
        {
            return;
        }

        HoldableItem closest = GetClosestItem();

        StartCoroutine(PickUpItemeEnum(closest));
    }
Exemple #26
0
 /// <summary>
 /// Method called when the food game object hold state changes
 /// </summary>
 /// <param name="itemCoordinated"></param>
 private void OnHoldableItemHeldStateChanged(HoldableItem itemCoordinated)
 {
     this.onHoldableStateChange.Invoke(this as HoldableCoordinator);
 }
 public void AttachToTransform(HoldableItem item)
 {
     _holdingItem = true;
     _currentlyHeldItem.AttachToTransform(_itemAttachmentPoint);
 }
 void OnDrop(GameObject dropper)
 {
     heldItem   = null;
     usableItem = null;
 }
    // Update is called once per frame
    void Update()
    {
        Vector2 input      = GetMovementInput();
        Vector2 mouseInput = GetMouseInput();
        float   rollInput  = GetRotationInput();
        float   vInput     = GetVerticalInput();

        Quaternion lookX    = Quaternion.AngleAxis(mouseInput.x, Vector3.up);
        Quaternion lookY    = Quaternion.AngleAxis(mouseInput.y, -Vector3.right);
        Quaternion lookRoll = Quaternion.AngleAxis(rollInput, -Vector3.forward);

        transform.localRotation = transform.localRotation * lookX * lookY * lookRoll;

        Vector3 move = (transform.forward * input.y) + (transform.right * input.x) + (transform.up * vInput);

        rb.velocity = move * Speed;

        GameObject objectInCrosshairs = GetObjectInCrosshairs();

        if (objectInCrosshairs != target)
        {
            if (target != null)
            {
                target.GetComponent <Outline>().enabled = false;
                target = null;
            }

            if (objectInCrosshairs != null)
            {
                objectInCrosshairs.GetComponent <Outline>().enabled = true;
                target = objectInCrosshairs;
            }
        }


        if (Input.GetMouseButtonDown(0))
        {
            if (heldItem == null)
            {
                if (objectInCrosshairs != null)
                {
                    HoldableItem holdable = objectInCrosshairs.GetComponent <HoldableItem>();
                    if (holdable)
                    {
                        holdable.PickUp(Hand);
                        heldItem           = holdable;
                        heldItem.OnThrown += OnDrop;
                        usableItem         = heldItem.GetComponent <UsableItem>();
                    }
                    else
                    {
                        UsableItem usable = objectInCrosshairs.GetComponent <UsableItem>();
                        if (usable)
                        {
                            usable.Use(gameObject, objectInCrosshairs);
                        }
                    }
                }
            }
            else
            {
                if (usableItem)
                {
                    usableItem.Use(gameObject, objectInCrosshairs);
                }
            }
        }

        if (heldItem != null && Input.GetMouseButtonDown(1))
        {
            heldItem.Drop(Hand);
            heldItem = null;
        }
    }
 private float DistanceTo(HoldableItem item) => Vector3.Distance(item.transform.position, _itemAttachmentPoint.position);