Ejemplo n.º 1
0
    //--- Methods ---//
    public void GenerateCall()
    {
        // Create a new call group by randomly generating the necessary properties
        // The call capacity can be anywhere between 2 people and the highest room count (inclusive). The +1 is because the Random.Range() function is exclusive at the upper bound
        // The wait time is randomly selected from a list set in the inspector
        // The call duration is randomly selected from a list set in the inspector
        int        newCallCapacity = Random.Range(2, m_roomManager.HighestRoomCapacity + 1);
        float      newCallWaitTime = m_possibleWaitTimes[Random.Range(0, m_possibleWaitTimes.Length)];
        float      newCallLength   = m_possibleCallLengths[Random.Range(0, m_possibleCallLengths.Length)];
        Call_Group newCall         = new Call_Group(newCallCapacity, newCallWaitTime, newCallLength);

        // Place all of the new call individuals into the unassigned room
        m_roomManager.AddUnassignedCallers(newCall.CallParticipants);

        // Hook into the call completion event so we can handle it finishing
        newCall.m_OnCallCompleted.AddListener(this.OnCallCompleted);

        // Add the call group to the list
        m_callList.Add(newCall);

        // Generate a new UI element for the call
        m_callLogUI.AddCallGroupUI(newCall);

        // Reset the timer
        m_timeSinceLastCall = 0.0f;
    }
    public void RemoveCallGroupUI(Call_Group _group)
    {
        // Need to find the associated script
        CallerLog_Script uiScript = null;

        // Find the UI element that is connected to the group
        foreach (var callerUI in m_callerUIObjs)
        {
            // If we found the right UI element, store in and stop searching
            if (callerUI.RefGroup == _group)
            {
                uiScript = callerUI;
                break;
            }
        }

        // If it is still null, back out because it isn't in the list anyways
        if (uiScript == null)
        {
            Debug.LogError("No ui script could be found that matches with the call group in RemoveCallGroupUI()!");
            return;
        }

        // Remove the group from the internal list
        m_callerUIObjs.Remove(uiScript);

        // Destroy the UI's gameobject
        Destroy(uiScript.gameObject);
    }
    public void OnCallGroupDisconnected(Call_Group _group, Call_State _finalState)
    {
        // Grab the call participants
        List <Call_Individual> callers = _group.CallParticipants;

        // Unbind all of the callers within the group
        foreach (var caller in callers)
        {
            UnbindKey(caller.BoundKeyCode);
        }

        // If the call group was the one that was bound, we should unbind it
        if (_group == m_groupToBind)
        {
            m_groupToBind = null;
        }

        // If any of the callers was in the selection, we should remove that as well
        foreach (var caller in callers)
        {
            if (m_selectedCallers.Contains(caller))
            {
                DeselectCaller(caller);
            }
        }

        // Invoke the event since the key bindings have changed
        m_OnBindingsChanged.Invoke();

        // Unhook the listener
        _group.m_OnCallCompleted.RemoveListener(this.OnCallGroupDisconnected);
    }
Ejemplo n.º 4
0
    public IEnumerator DeleteCall(Call_Group _callObj)
    {
        // Wait until the frame is over to ensure all other call operations are completed
        yield return(new WaitForEndOfFrame());

        // Remove the caller from the list
        m_callList.Remove(_callObj);
    }
Ejemplo n.º 5
0
    public void RemoveCallGroupUI(Call_Group _group)
    {
        // TODO: Find the UI element that is connected to the group

        // TODO: Destroy the UI object

        // TODO: Remove the group from the internal list
    }
Ejemplo n.º 6
0
    //--- Methods ---//
    public void AddCallGroupUI(Call_Group _group)
    {
        // TODO: Instantiate the prefab as a child of the list parent

        // TODO: Grab the script off the prefab and add it to the internal list

        // TODO: Pass the group to the script so that it can get set up
    }
Ejemplo n.º 7
0
    public void InitWithData(Call_Group _attachedGroup)
    {
        refGroup = _attachedGroup;

        // Show only the number of key binding slots that are needed for this call
        for (int i = 0; i < _attachedGroup.GetNumParticipants(); i++)
        {
            blockingImages[i].SetActive(false);
        }
    }
    //--- Methods ---//
    public void AddCallGroupUI(Call_Group _group)
    {
        // Instantiate the prefab as a child of the list parent
        GameObject newUIElement = Instantiate(m_uiElementPrefab, m_uiListParent);

        // Grab the script off the prefab
        CallerLog_Script uiScript = newUIElement.GetComponent <CallerLog_Script>();

        // Pass the group to the script so that it can get set up
        uiScript.InitWithData(_group);

        // Store the script in the internal list
        m_callerUIObjs.Add(uiScript);
    }
    //--- Unity Methods ---//
    private void Awake()
    {
        // Init the private variables
        m_selectedCallers = new List <Call_Individual>();
        m_keyBindings     = new Dictionary <KeyCode, Call_Individual>();
        m_roomManager     = GameObject.FindObjectOfType <Room_Manager>();
        m_keyToSwap       = KeyCode.None;
        m_isInSwapMode    = false;
        m_groupToBind     = null;

        // Setup the dictionary to contain blank key bindings for all the letters of the alphabet
        for (var keyCode = KeyCode.A; keyCode <= KeyCode.Z; keyCode++)
        {
            m_keyBindings.Add(keyCode, null);
        }
    }
Ejemplo n.º 10
0
    //Call this function when the group disconnects
    //
    public float CalculateCashForCall(Call_Group disGroup)
    {
        //Variable to store total of new cash to add to total
        float newCash         = 0.0f;
        float patiencePenalty = 0.0f;

        //Calculates money based on how many people are in the call
        float perPersonCash = disGroup.GetNumParticipants() * cashPerPersonInCall;

        //Calculates the penalty for patience
        patienceLeft = disGroup.GetWaitTimeRemaining() / disGroup.GetWaitTimeMax();
        if (patienceLeft >= 0.66)
        {
            patiencePenalty = 1.0f;
        }
        else
        {
            patiencePenalty = patienceLeft;
        }

        //This is only for if they didnt complete the call fully
        //Bonus for completing a call. Depending on the amount of time left in the call. Less time = more money , More time = less money
        timeMax         = disGroup.GetCallTimeMax();
        timeLeftPercent = disGroup.GetCallTimeRemaining() / timeMax;
        float timeLeftBonus = cashCallComplete * (1.0f - timeLeftPercent) * patiencePenalty;  // Little off but not bad
        //Calculates Streak bonus
        float streakBonus = streakConst * streak;


        newCash = perPersonCash + timeLeftBonus + fullCallCompleteBonus + streakBonus;


        totalCash += newCash;

        //Adds the calls earned cash into the daily earning
        daysEarning += newCash;

        //--- Debugs to check cash values ---//
        //Debug.Log("Per Person " + perPersonCash);
        //Debug.Log("Patient Pen " + patiencePenalty);
        //Debug.Log("Tl bonus " + timeLeftBonus);
        //Debug.Log("Streak " + streakBonus);

        //Return the cash earned from the call
        return(newCash);
    }
Ejemplo n.º 11
0
    //--- Event Hooks ---//
    public void OnCallCompleted(Call_Group _callObj, Call_State _callFinalState)
    {
        // Handle the call termination differently, depending on if ended well or not
        if (_callFinalState == Call_State.Waited_Too_Long)
        {
            // Play negative feedback
            audioManager.PlayOneShot(4, 0.2f);

            //TODO: Increment missed calls counter
            persistManager.callsMissed += 1;
        }
        else if (_callFinalState == Call_State.Completed)
        {
            // Play positive feedback
            audioManager.PlayOneShot(3, 0.5f);
            // Add points, reputation, etc
            callsCompletedDaily++;
            GameObject.FindObjectOfType <CashCalculation_Script>().CalculateCashForCall(_callObj);

            //End of game Satisfaction
            //TODO: Increment total calls completed
            persistManager.callsCompleted    += 1;
            persistManager.gamesSatisfaction += _callObj.GetSatisfationFromCall();

            //callCash.GetComponent<TextMeshProUGUI>().text = GameObject.FindObjectOfType<CashCalculation_Script>().CalculateCashForCall(_callObj).ToString();
            totalCash.GetComponent <TextMeshProUGUI>().text = GameObject.FindObjectOfType <CashCalculation_Script>().TotalCashEarned().ToString(); //Returns Total Cash
            //Debug the new money recieved.
            //Debug.Log(this.GetComponent<CashCalculation_Script>().CalculateCashForCall(_callObj));
        }

        // Remove the UI element from the call backlog
        m_callLogUI.RemoveCallGroupUI(_callObj);

        // Unhook the event
        _callObj.m_OnCallCompleted.RemoveListener(this.OnCallCompleted);

        // Remove the callers from their associated rooms
        m_roomManager.DisconnectCallers(_callObj.CallParticipants);

        // We should also remove the call from the list
        // However, we need to wait until the end of the frame to ensure all the other call operations are complete
        StartCoroutine(DeleteCall(_callObj));
    }
Ejemplo n.º 12
0
    //--- Event Hooks ---//
    public void OnCallCompleted(Call_Group _callObj, Call_State _callFinalState)
    {
        // Handle the call termination differently, depending on if ended well or not
        if (_callFinalState == Call_State.Waited_Too_Long)
        {
            // TODO: Play negative feedback
        }
        else if (_callFinalState == Call_State.Completed)
        {
            // TODO: Play positive feedback

            // TODO: Add points, reputation, etc
        }

        // Remove the UI element from the call backlog
        m_callLogUI.RemoveCallGroupUI(_callObj);

        // Either way, unhook the event and remove the call from the list
        _callObj.m_OnCallCompleted.RemoveAllListeners();
        m_callList.Remove(_callObj);
    }
    public void HandleLetterKeyPressed(KeyCode _alphabetKey)
    {
        // If in swap mode, we should prepare to switch the bindings
        if (m_isInSwapMode)
        {
            // If this is the first alphabet key pressed since entering swap mode, we should store it so we can prepare to swap next time
            if (m_keyToSwap == KeyCode.None)
            {
                // Store the key so that next time, we are able to actually perform the swap
                m_keyToSwap = _alphabetKey;
            }
            else
            {
                // Hold the caller temporarily so we can perform a swap
                Call_Individual tempCaller = m_keyBindings[m_keyToSwap];

                // Swap the bindings
                BindCallerToKey(m_keyToSwap, m_keyBindings[_alphabetKey]);
                BindCallerToKey(_alphabetKey, tempCaller);

                // Invoke the event since the key bindings have changed
                m_OnBindingsChanged.Invoke();

                // Clear the held swap key
                m_keyToSwap = KeyCode.None;
            }
        }
        else if (m_groupToBind != null) // Otherwise, if the player selected a call group in the backlog, we should be binding those mappings
        {
            // We should check if the binding is currently open. If it isn't, we should back out
            if (!CheckIfBindingOpen(_alphabetKey))
            {
                return;
            }

            // Grab the individual callers from the bound group
            List <Call_Individual> callers = m_groupToBind.CallParticipants;

            // Loop through and find the next one that needs a binding
            for (int i = 0; i < callers.Count; i++)
            {
                // Grab the caller reference
                var caller = callers[i];

                // If the caller is already bound, we can move on to the next one
                if (caller.BoundKeyCode != KeyCode.None)
                {
                    continue;
                }

                // Otherwise, we can go ahead and perform the binding
                BindCallerToKey(_alphabetKey, caller);

                // Invoke the event since the key bindings have changed
                m_OnBindingsChanged.Invoke();

                // We should also mark the caller as selected to make it easier to move it around after
                SelectCaller(caller);

                // We now also need to move the caller into the waiting room
                m_roomManager.TransferCallers(new List <Call_Individual> {
                    caller
                }, Room_Name.Waiting);

                // If this is the last caller, then the group is fully bound and we can unlink it
                if (i == callers.Count - 1)
                {
                    // The group is no longer in bind mode
                    m_groupToBind.IsInBindMode = false;

                    // Stop tracking the group
                    m_groupToBind = null;
                }

                // Finally, we should break the loop to prevent binding the next caller to the same key
                break;
            }
        }
        else  // Otherwise, the player is selecting / deselecting a caller
        {
            // Grab the call participant reference associated with the keycode
            Call_Individual caller = m_keyBindings[_alphabetKey];

            // Check if there is an actual caller bound to that key
            if (caller != null)
            {
                // If the caller is currently unselected, we should select them and vice versa
                if (m_selectedCallers.Contains(caller))
                {
                    DeselectCaller(caller);
                }
                else
                {
                    SelectCaller(caller);
                }
            }
        }
    }
Ejemplo n.º 14
0
 public void InitWithData(Call_Group _attachedGroup)
 {
     refGroup = _attachedGroup;
 }