Medication AdjustTreatmentBasedOnDosage(Patient p, Medication m, BedHud hud)
    {
        if (m.currentLevel < 0f)
        {
            //Debug.Log ("Overdose by " + -m.currentLevel);

            m.effectLength = m.effectLength * (1f * (1f - (-m.currentLevel / m.dose)));

            int success = Mathf.RoundToInt((-m.currentLevel / m.dose) * 100f);

            GameController.Instance.UpdateScore(success);
            hud.successText.text = success.ToString() + "% overdose!!";
        }

        if (m.currentLevel > 0f)
        {
            //Debug.Log ("Underdose by " + m.currentLevel);
            m.effectLength = m.effectLength * (1f * (1.5f - (m.currentLevel / m.dose)));

            int success = Mathf.RoundToInt((m.currentLevel / m.dose) * 100f);

            GameController.Instance.UpdateScore(success);
            hud.successText.text = success.ToString() + "% underdose";
        }


        return(m);
    }
    Patient PatientIsDead(Patient p)
    {
        p.inTreatment = false;

        BedController.Instance.WheelBedOutOfBerth(p.bed);
        GameController.Instance.lives [GameController.Instance.patientsDied].SetActive(false);
        GameController.Instance.patientsDied++;

        GameObject bedGo = BedController.Instance.bedToGameObjectMap [p.bed];
        BedHud     hud   = bedGo.GetComponent <BedHud> ();

        hud.nameText.text = hud.nameText.text + " (RIP)";

        if (p.isMale)
        {
            hud.boy.transform.DOLocalMove(new Vector3(hud.boy.transform.position.x, 10f, hud.boy.transform.position.z), 1f);
        }
        else
        {
            hud.girl.transform.DOLocalMove(new Vector3(hud.girl.transform.position.x, 10f, hud.girl.transform.position.z), 1f);
        }


        InAudio.Play(this.gameObject, SoundController.Instance.dead);

        if (GameController.Instance.patientsDied == 3)
        {
            GameController.Instance.GameOver();
        }



        return(p);
    }
    Medication CheckWhetherToStartRecovery(Medication m, Patient p)
    {
        if (m.dose > 0f && m.dosesAdministered < 99)
        {
            //Debug.Log (m.name + " has a dose...");

            if (m.dosesAdministered == m.dosesUntilCured && m.currentLevel > m.dose * 0.5f)
            {
                Debug.Log(m.name + " START RECOVERY!!!");

                if (m.name == "Blood")
                {
                    GameObject bedGo = BedController.Instance.bedToGameObjectMap [p.bed];
                    BedHud     hud   = bedGo.GetComponent <BedHud> ();

                    hud.bloodText.transform.parent.transform.gameObject.SetActive(false);
                }

                m.dosesAdministered = 99;
            }
        }
        else
        {
            //Debug.Log (m.name + " no dose.");
        }

        return(m);
    }
    void DoAccuracyText(BedHud hud, string text)
    {
        hud.successText.text = text;

        hud.successText.transform.DOPunchScale(new Vector2(0.1f, 0.1f), 2f, 5)
        .OnComplete(() => TurnOffText(hud));
    }
    Patient TriggerBloodLoss(Patient p)
    {
        Debug.Log("Blood loss!!");

        GameObject bedGo = BedController.Instance.bedToGameObjectMap[p.bed];
        BedHud     hud   = bedGo.GetComponent <BedHud> ();

        Medication m = p.currentPrescriptions ["Blood"];

        m.dose              = (float)UnityEngine.Random.Range(20, 50);
        m.currentLevel      = UnityEngine.Random.Range(m.dose * 0.4f, m.dose);
        m.dosesUntilCured   = Random.Range(1, 3);
        m.dosesAdministered = 0;
        m.effectLength      = UnityEngine.Random.Range(10f, 20f);

        hud.successText.gameObject.SetActive(true);
        hud.successText.text = "Administer " + m.dose.ToString() + " units!";
        InAudio.Play(this.gameObject, SoundController.Instance.alarm);

        hud.bloodText.transform.parent.transform.gameObject.SetActive(true);
        hud.bloodText.text = m.dose.ToString();


        return(p);
    }
Beispiel #6
0
    Medication DecideWhetherBloodLoss(Patient p)
    {
        float      bloodAmt = (float)UnityEngine.Random.Range(20, 50);
        Medication blood    = new Medication("Blood", bloodAmt, UnityEngine.Random.Range(6f, 18f), 5f, UnityEngine.Random.Range(1, 3));

        blood.currentLevel = UnityEngine.Random.Range(blood.dose * 0.4f, blood.dose);

        if (totalPatients > 2 && UnityEngine.Random.Range(0, 8) == 2)
        {
            GameObject bedGo = BedController.Instance.bedToGameObjectMap [p.bed];
            BedHud     hud   = bedGo.GetComponent <BedHud> ();

            hud.successText.gameObject.SetActive(true);
            hud.successText.text = "Administer " + bloodAmt.ToString() + " units!";

            hud.bloodText.transform.parent.transform.gameObject.SetActive(true);
            hud.bloodText.text = bloodAmt.ToString();


            InAudio.Play(this.gameObject, SoundController.Instance.alarm);
        }
        else
        {
            blood.dose            = 0f;
            blood.currentLevel    = 0f;
            blood.dosesUntilCured = 0;
        }


        return(blood);
    }
    void CalculatePainCaused(Patient p, Medication m, BedHud hud, float injectionQuality)
    {
        hud.successText.gameObject.SetActive(true);

        int painCaused = Mathf.RoundToInt(100f - (injectionQuality * 100f));

        hud.successText.transform.DOPunchScale(new Vector2(0.1f, 0.1f), 2f, 5)
        .OnComplete(() => DoAccuracyText(hud, painCaused.ToString() + "% pain caused"));
    }
Beispiel #8
0
    public void ResetBedToStartPosition(Bed b)
    {
        GameObject go = bedToGameObjectMap [b];

        BedHud hud = go.GetComponent <BedHud> ();

        hud.boy.transform.localPosition  = new Vector3(0f, 0.747f, 0f);
        hud.girl.transform.localPosition = new Vector3(0f, 0.747f, 0f);


        go.transform.position    = new Vector3(-20f, 0.73f, 0f);
        go.transform.eulerAngles = new Vector3(0f, 90f, 0f);
    }
    public void FirePulse(Patient p)
    {
        if (p.inTreatment && p.pulseRate > 0f)
        {
            GameObject bedGo = BedController.Instance.bedToGameObjectMap [p.bed];
            BedHud     hud   = bedGo.GetComponent <BedHud> ();

            float heartRate = 1f / p.pulseRate * 60f;

            hud.heart.transform.DOPunchScale(new Vector3(0.1f, 0.1f, 0.1f), heartRate, 4)
            .OnComplete(() => FirePulse(p));
        }
    }
    public void UpdateBedVisuals(Patient p)
    {
        GameObject bedGo = BedController.Instance.bedToGameObjectMap [p.bed];
        BedHud     hud   = bedGo.GetComponent <BedHud> ();

        hud.pulseRateText.text = Mathf.RoundToInt(p.pulseRate).ToString();

        foreach (Medication m in p.currentPrescriptions.Values)
        {
            if (m.name == "Pain")
            {
                if (m.dose > 0f)
                {
                    p.painLevel           = (m.currentLevel / m.dose);
                    hud.painBar.sizeDelta = new Vector2(200f * p.painLevel, hud.painBar.sizeDelta.y);

                    //Debug.Log ("Pain: " + m.currentLevel + " / " + m.dose);
                }
            }

            if (m.name == "Infection")
            {
                if (m.dose > 0f)
                {
                    p.infection = (m.currentLevel / m.dose);
                    hud.infectionBar.sizeDelta = new Vector2(200f * p.infection, hud.infectionBar.sizeDelta.y);

                    //Debug.Log ("Infection: " + m.currentLevel + " / " + m.dose);
                }
            }

            if (m.name == "Blood")
            {
                if (m.dose > 0f)
                {
                    p.trauma = (m.currentLevel / m.dose);
                    hud.traumaBar.sizeDelta = new Vector2(200f * p.trauma, hud.traumaBar.sizeDelta.y);

                    //Debug.Log ("Infection: " + m.currentLevel + " / " + m.dose);
                }
            }
        }


        if (p.pulseRateTimer <= 0f)
        {
        }
    }
    public void AdministerMedication(Patient p, float amountInjected, float maxAllowed, float injectionQuality, string medName)
    {
        GameObject bedGo = BedController.Instance.bedToGameObjectMap[p.bed];
        BedHud     hud   = bedGo.GetComponent <BedHud> ();

        Medication m = p.currentPrescriptions [medName];

        float startingRate = p.pulseRate;

        p = CheckWhetherCausedBloodLoss(p, m, injectionQuality);
        bool failed = CheckWhetherMedicationFailed(p, m, injectionQuality);

        if (RequiredThisMedication(m))
        {
            if (failed == false)
            {
                m = DoTreatment(m, amountInjected);

                m = AdjustTreatmentBasedOnDosage(p, m, hud);
                p = AdjustPulseBasedOnDosage(p, m);

                CalculatePainCaused(p, m, hud, injectionQuality);

                if (p.pulseRate > 0f && startingRate == 0f)
                {
                    EndCardiacArrest(p);
                }


                p.deathTimer = 0f;
            }
            else
            {
                hud.successText.gameObject.SetActive(true);
                hud.successText.text = "Treatment Failed!!!";
                hud.successText.transform.DOPunchScale(new Vector2(0.1f, 0.1f), 2f, 5)
                .OnComplete(() => TurnOffText(hud));
            }
        }
        else
        {
            p.pulseRate = p.pulseRate + Random.Range(minimumWrongMedEffects [medName], maximumWrongMedEffects [medName]);
            hud.successText.gameObject.SetActive(true);
            hud.successText.transform.DOPunchScale(new Vector2(0.1f, 0.1f), 2f, 5)
            .OnComplete(() => TurnOffText(hud));
            hud.successText.text = "Wrong medication!!!";
        }
    }
    void CardiacArrest(Patient p)
    {
        Debug.Log("Cardiac arrest!!!");

        GameObject bedGo = BedController.Instance.bedToGameObjectMap[p.bed];
        BedHud     hud   = bedGo.GetComponent <BedHud> ();

        p.pulseRate = 0f;

        Medication defib = new Medication("Defib", (float)Random.Range(50, 200), 1f, 1f, 1);

        defib.currentLevel = defib.dose;
        p.prescriptions.Add(defib);

        hud.successText.gameObject.SetActive(true);
        hud.successText.text = "Shock with " + defib.dose.ToString() + " joules!";

        InAudio.Play(this.gameObject, SoundController.Instance.beep);
    }
    void EndCardiacArrest(Patient p)
    {
        Debug.Log("Ended Cardiac arrest!!");

        GameObject bedGo = BedController.Instance.bedToGameObjectMap[p.bed];
        BedHud     hud   = bedGo.GetComponent <BedHud> ();

        Medication m = p.currentPrescriptions ["Defib"];

        m.dose              = 0f;
        m.currentLevel      = m.dose;
        m.dosesUntilCured   = 0;
        m.dosesAdministered = 0;
        m.effectLength      = 0f;
        p.deathTimer        = 0f;

        hud.defibText.transform.parent.transform.gameObject.SetActive(false);

        //InAudio.Play (this.gameObject, SoundController.Instance.beep);
    }
    void TriggerCardiacArrest(Patient p)
    {
        Debug.Log("Cardiac arrest!!");

        GameObject bedGo = BedController.Instance.bedToGameObjectMap[p.bed];
        BedHud     hud   = bedGo.GetComponent <BedHud> ();

        Medication m = p.currentPrescriptions ["Defib"];

        m.dose              = (float)UnityEngine.Random.Range(50, 200);
        m.currentLevel      = m.dose;
        m.dosesUntilCured   = 1;
        m.dosesAdministered = 0;
        m.effectLength      = 50f;
        p.pulseRate         = 0f;

        hud.successText.gameObject.SetActive(true);
        hud.successText.text = "Shock with " + m.dose.ToString() + " joules!";

        hud.defibText.text = m.dose.ToString();
        hud.defibText.transform.parent.transform.gameObject.SetActive(true);

        InAudio.Play(this.gameObject, SoundController.Instance.beep);
    }
 void TurnOffText(BedHud hud)
 {
     hud.successText.gameObject.SetActive(false);
 }
Beispiel #16
0
    List <Medication> GetPrescription(Patient p)
    {
        List <Medication> prescription = new List <Medication> ();

        float painAmt = (float)UnityEngine.Random.Range(20, 101) / 10f;
        float infAmt  = (float)UnityEngine.Random.Range(25, 151) / 10f;

        Medication pain      = new Medication("Pain", painAmt, UnityEngine.Random.Range(10f, 30f), 5f, UnityEngine.Random.Range(1, 5));
        Medication infection = new Medication("Infection", infAmt, UnityEngine.Random.Range(10f, 30f), 5f, UnityEngine.Random.Range(1, 5));

        prescription.Add(pain);
        prescription.Add(infection);


        pain.currentLevel      = UnityEngine.Random.Range(pain.dose * 0.5f, pain.dose);
        infection.currentLevel = UnityEngine.Random.Range(infection.dose * 0.5f, infection.dose);



        if (totalPatients == 1)
        {
            pain.currentLevel         = pain.dose;
            infection.currentLevel    = infection.dose;
            pain.dosesUntilCured      = 1;
            infection.dosesUntilCured = 1;
        }

        ShuffleList(prescription);

        //float bloodAmt2 = (float)UnityEngine.Random.Range (20, 50);
        //Medication blood2 = new Medication ("Blood", bloodAmt2, UnityEngine.Random.Range (10f, 30f), 5f, UnityEngine.Random.Range (1, 2));
        //blood2.currentLevel = UnityEngine.Random.Range (blood2.dose * 0.5f, blood2.dose);
        //	rescription.Add (blood2);


        if (totalPatients < 4)
        {
            prescription [0].dose = 0f;
        }
        else
        {
            if (UnityEngine.Random.Range(0, 2) == 0)
            {
                prescription [UnityEngine.Random.Range(0, 2)].dose = 0f;
            }

            if (UnityEngine.Random.Range(0, 8) == 2)
            {
                GameObject bedGo = BedController.Instance.bedToGameObjectMap[p.bed];
                BedHud     hud   = bedGo.GetComponent <BedHud> ();

                float      bloodAmt = (float)UnityEngine.Random.Range(20, 50);
                Medication blood    = new Medication("Blood", bloodAmt, UnityEngine.Random.Range(10f, 30f), 5f, UnityEngine.Random.Range(1, 2));
                blood.currentLevel = UnityEngine.Random.Range(blood.dose * 0.5f, blood.dose);
                prescription.Add(blood);

                hud.successText.gameObject.SetActive(true);
                hud.successText.text = "Administer " + bloodAmt.ToString() + " units!";

                InAudio.Play(this.gameObject, SoundController.Instance.alarm);
            }
        }

        return(prescription);
    }
    public void SetupPatientVisuals(Patient p)
    {
        GameObject bedGo = BedController.Instance.bedToGameObjectMap[p.bed];
        BedHud     hud   = bedGo.GetComponent <BedHud> ();

        hud.successText.gameObject.SetActive(false);

        if (p.isMale)
        {
            hud.boy.SetActive(true);
            hud.girl.SetActive(false);
        }
        else
        {
            hud.boy.SetActive(false);
            hud.girl.SetActive(true);
        }

        hud.nameText.text       = p.name;
        hud.pulseRateText.text  = p.pulseRate.ToString();
        hud.traumaBar.sizeDelta = new Vector2(0f, hud.traumaBar.sizeDelta.y);


        hud.bloodText.transform.parent.transform.gameObject.SetActive(false);
        hud.defibText.transform.parent.transform.gameObject.SetActive(false);



        foreach (Medication m in p.currentPrescriptions.Values)
        {
            if (m.name == "Pain")
            {
                if (m.dose > 0f)
                {
                    hud.painText.text = m.dose.ToString();
                    hud.painObject.SetActive(true);
                }
                else
                {
                    hud.painBar.sizeDelta = new Vector2(0f, hud.painBar.sizeDelta.y);
                    hud.painObject.SetActive(false);
                }
            }

            if (m.name == "Infection")
            {
                if (m.dose > 0f)
                {
                    hud.infectionText.text = m.dose.ToString();
                    hud.infectionObject.SetActive(true);
                }
                else
                {
                    hud.infectionBar.sizeDelta = new Vector2(0f, hud.infectionBar.sizeDelta.y);
                    hud.infectionObject.SetActive(false);
                }
            }

            if (m.name == "Blood")
            {
                if (m.dose > 0f)
                {
                    hud.successText.gameObject.SetActive(true);
                    hud.successText.text = "Administer " + m.dose.ToString() + " units!";

                    hud.bloodText.transform.parent.transform.gameObject.SetActive(true);
                    hud.bloodText.text = m.dose.ToString();
                }
                else
                {
                    hud.bloodText.transform.parent.transform.gameObject.SetActive(false);
                    hud.successText.gameObject.SetActive(false);
                    //hud.traumaBar.sizeDelta = new Vector2 (0f, hud.traumaBar.sizeDelta.y);
                }
            }
        }

        UpdateBedVisuals(p);
    }