Example #1
0
    public ConnectionResult ConnectCall(int receptorId)
    {
        if (gameController.currentGameState != GameState.PLAYING)
        {
            return(ConnectionResult.IS_VOID);
        }

        if (phoneCalls.Count(x => x.state == PhoneCallState.PENDING) > 0)
        {
            if (currentPhoneCall == null)
            {
                if (phoneCalls.Count(x => x.state == PhoneCallState.CONNECTED) > 2)
                {
                    return(ConnectionResult.IS_VOID);
                }

                currentPhoneCall = phoneCalls.Take(phoneCallIndex).FirstOrDefault(x => x.state == PhoneCallState.PENDING && x.caller == receptorId);

                if (currentPhoneCall != null)
                {
                    gameController.NotifyShowCaller(currentPhoneCall.caller);
                    sfxController.PlayPlugIn();
                    return(ConnectionResult.IS_CALLER);
                }
            }
            else if (currentPhoneCall.receiver == receptorId)
            {
                currentPhoneCall.state = PhoneCallState.CONNECTED;
                stressController.EndCall(phoneCalls.IndexOf(currentPhoneCall));
                gameController.CallCompleted(currentPhoneCall.caller, receptorId);
                currentPhoneCall = null;
                sfxController.PlayConnected();
                return(ConnectionResult.IS_RECEIVER);
            }
            else
            {
                stressController.WrongConnection();

                if (receptorId == currentPhoneCall.caller)
                {
                    return(ConnectionResult.IS_SAME);
                }

                if (phoneCalls.Take(phoneCallIndex).Any(x => x.state == PhoneCallState.PENDING && x.caller == receptorId))
                {
                    return(ConnectionResult.IS_SAME);
                }

                gameController.WrongConnection(receptorId);

                sfxController.PlayError();
                return(ConnectionResult.IS_WRONG);
            }
        }

        return(ConnectionResult.IS_VOID);
    }