Exemple #1
0
    IEnumerator TranslateBoxToPosition(BoxDatasController _box, int previousPos)
    {
        int     finalPos = boxInPos[_box];
        Vector3 startPos = _box.transform.position;
        float   timePass = 0f;

        float timeNeeded = 1f * (previousPos - finalPos);

        bool posReleased = false;

        while (timePass < timeNeeded && previousPos != finalPos)
        {
            timePass += Time.deltaTime;

            if (!posReleased)
            {
                PosFree.Add(previousPos);
                posReleased = true;
            }

            _box.transform.position = Vector3.Lerp(startPos, PosInstantiation[finalPos].position, timePass / timeNeeded);

            yield return(0);
        }

        if (finalPos == 0)
        {
            _box.SetActive(true);
        }

        yield return(0);
    }
    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);
    }
Exemple #3
0
    public void CheckBoxOnline(int _actorNumber)
    {
        PlayerController   photonPlayer = InGamePhotonManager.Instance.PlayersConnected[_actorNumber];
        BoxDatasController box          = photonPlayer.pDatas.boxInMind;

        boxChecked.Add(box.boxID);
        user = photonPlayer;
        photonPlayer.TeleportTo(posUser, true);
    }
Exemple #4
0
    private void CheckBox(PlayerController _pController)
    {
        BoxDatasController box = _pController.pDatas.boxInMind;

        boxChecked.Add(box.boxID);
        // Affect the player
        user = _pController;
        _pController.TeleportTo(posUser, true);
        _pController.BeginInteractionState();

        photonView.RPC("CheckBoxOnline", RpcTarget.Others, _pController.photonView.OwnerActorNr);
        StartCoroutine(StartAction(_pController, true));
    }
 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 #6
0
    IEnumerator InstantiateBox()
    {
        while (boxToInstantiate.Count > 0 && PosFree.Count > 0)
        {
            yield return(new WaitForSeconds(1.2f));

            if (PosFree.Contains(PosInstantiation.Count() - 2))
            {
                int posIndex = PosInstantiation.Count() - 1;
                int finalPosIndex;

                Poolable           foodToInstantiate = PoolManager.Instance.Get(boxToInstantiate[0], true);
                BoxDatasController box  = foodToInstantiate.GetComponent <BoxDatasController>();
                PhotonView         view = foodToInstantiate.GetComponent <PhotonView>();

                foodToInstantiate.transform.position = PosInstantiation[posIndex].position;
                foodToInstantiate.transform.rotation = PosInstantiation[posIndex].rotation;

                box.Init();
                box.SetActive(false);
                box.Grabable.onGrab += OnGrabBox;

                boxInPos.Add(box, posIndex);

                PosFree.Remove(posIndex);

                finalPosIndex = GetFinalBoxPosition(posIndex);

                boxInPos[box] = finalPosIndex;
                PosFree.Remove(finalPosIndex);

                StartCoroutine(TranslateBoxToPosition(box, posIndex));

                photonView.RPC("InstantiateBox", RpcTarget.Others, boxToInstantiate[0].Key, boxToInstantiate[0].Value, posIndex, finalPosIndex, view.ViewID);

                boxToInstantiate.RemoveAt(0);
            }

            yield return(0);
        }

        yield return(0);
    }
Exemple #7
0
    private void OnGrabBox(GrabableObject _grabableObject)
    {
        BoxDatasController box = _grabableObject.GetComponent <BoxDatasController>();

        PosFree.Add(boxInPos[box]);
        boxInPos.Remove(box);

        UpdateBoxPosition();

        StartCoroutine(InstantiateBox());

        _grabableObject.onGrab -= OnGrabBox;

        if (boxInPos.Count == 0)
        {
            deliveryMan.Leave();
        }

        // sound
        GameManager.Instance.Audio.PlaySound("FastConveyorBelt", AudioManager.Canal.SoundEffect);
    }
Exemple #8
0
    private void UpdateBoxPosition()
    {
        int finalPos = -1;

        for (int i = 0; i < PosInstantiation.Count(); i++)
        {
            if (PosFree.Contains(i))
            {
                finalPos = i;
                for (int j = i; j < PosInstantiation.Count(); j++)
                {
                    if (!PosFree.Contains(j))
                    {
                        BoxDatasController ga = null;

                        foreach (BoxDatasController _g in boxInPos.Keys)
                        {
                            if (boxInPos[_g] == j)
                            {
                                ga = _g;
                                break;
                            }
                        }

                        if (ga != null)
                        {
                            boxInPos[ga] = finalPos;
                            PosFree.Remove(finalPos);

                            StartCoroutine(TranslateBoxToPosition(ga, j));

                            break;
                        }
                    }
                }
            }
        }
    }
Exemple #9
0
    void InstantiateBox(string _alimentName, AlimentState _alimentState, int posFree, int finalPos, int viewID)
    {
        //Debug.Log("Receive RPC InstantiateBox :" + _alimentName + " AlimentState:" + _alimentState + " viewID:" + viewID);
        KeyValuePair <string, AlimentState> key = new KeyValuePair <string, AlimentState>(_alimentName, _alimentState);

        Poolable           foodToInstantiate = PoolManager.Instance.Get(key, viewID);
        BoxDatasController box = foodToInstantiate.GetComponent <BoxDatasController>();

        foodToInstantiate.transform.position = PosInstantiation[posFree].position;
        foodToInstantiate.transform.rotation = PosInstantiation[posFree].rotation;

        box.Init();
        box.SetActive(false);
        box.Grabable.onGrab += OnGrabBox;

        boxInPos.Add(box, posFree);

        PosFree.Remove(posFree);

        boxInPos[box] = finalPos;
        PosFree.Remove(finalPos);

        StartCoroutine(TranslateBoxToPosition(box, posFree));
    }
Exemple #10
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);
        }
    }