public bool CanInteract(PlayerController pController)
    {
        bool interactable = false;

        switch (actualState)
        {
        case StateDeliveryMan.Delivering:
            interactable = !onUse && pController.pDatas.objectInHand == null && InGamePhotonManager.Instance.localPlayerID == 0;
            break;

        case StateDeliveryMan.Changing:
            BoxDatasController box = null;
            if (pController.pDatas.objectInHand != null)
            {
                box = pController.pDatas.objectInHand.GetComponent <BoxDatasController>();
            }
            interactable = !onUse && box != null && !box.IsClean();
            break;

        case StateDeliveryMan.Leaving:
            break;

        default:
            break;
        }

        return(interactable);
    }
 private void ChangeBox(PlayerController _pController)
 {
     if (_pController.pDatas.objectInHand != null)
     {
         BoxDatasController boxToCheck = _pController.pDatas.objectInHand.GetComponent <BoxDatasController>();
         if (boxToCheck != null && !boxToCheck.IsClean())
         {
             boxToCheck.expirationTime = 999.9f;
             boxToCheck.state.SetAll(false, false, false);
             boxToCheck.Grabable.dirtinessErrorDetector.Clean(true);
             GameManager.Instance.PopUp.CreateText("Carton échangé en carton neuf", 50, new Vector2(0, 300), 3.0f);
         }
     }
 }
Exemple #3
0
    public void Interact(PlayerController pController)
    {
        player = pController;

        GrabableObject objectInHand = player.pDatas.objectInHand;

#if UNITY_EDITOR
        Debug.Log("objectInHand is NUll :" + (objectInHand == null));
        Debug.Log("boxToUnpack is NUll : " + (grabableReceived == null));
        Debug.Log("boxToGive is NUll: " + (ObjectStack == null));
#endif

        if (objectInHand != null && haveAnObject == false)
        {
            if (grabableReceived == null)
            {
                Aliment actualAliment = objectInHand.GetComponent <Aliment>();

                if (actualAliment != null && actualAliment.alimentState == AlimentState.Box)
                {
                    BoxDatasController boxReceived = actualAliment.GetComponent <BoxDatasController>();

                    // ERROR CHECK
                    if (!boxReceived.IsClean())
                    {
                        string str = "Décartonnage d'un carton de " + actualAliment.alimentName + " n'étant ni au norme, ni en bonne état.";
                        GameManager.Instance.Score.myScore.AddError(Score.HygieneCounter.DecartonnageDirtyCardboard, pController.GetGridCellPos(), str);
                    }

                    // Put Object on post
                    grabableReceived = player.pInteract.ReleaseObject(false, false);
                    grabableReceived.AllowGrab(false);
                    grabableReceived.transform.position = initPos.position;
                    grabableReceived.transform.rotation = initPos.rotation;

                    haveAnObject = true;

                    Aliment newAliment = grabableReceived.GetComponent <Aliment>();

                    // Affect the player
                    player.TeleportTo(playerPosition, true);
                    player.BeginInteractionState();


                    // transform box into crate
                    if (newAliment != null)
                    {
                        currentStartAction = StartCoroutine(StartAction(newAliment, transformationTime, true, true));
                    }

                    photonView.RPC("PutObjectOnUnpackPost", RpcTarget.Others, player.photonView.OwnerActorNr);
                }
                else
                {
                    GameManager.Instance.PopUp.CreateText("Uniquement les boîtes peuvent être déballées", 50, new Vector2(0, 300), 3.0f);
                }
            }
        }
        else if (objectInHand != null && haveAnObject == true)
        {
            GameManager.Instance.PopUp.CreateText("Il y a actuellement un objet sur le poste", 50, new Vector2(0, 300), 3.0f);
        }
    }