Ejemplo n.º 1
0
    public static object Deserialize(uLink.BitStream r, params object[] codecOptions)
    {
        try
        {
            CSTreatment cst = new CSTreatment();
            cst.abnormalId     = r.ReadInt32();
            cst.npcId          = r.ReadInt32();
            cst.needTreatTimes = r.ReadInt32();

            AbnormalTypeTreatData attd = AbnormalTypeTreatData.GetTreatment(cst.abnormalId);
            if (EntityMgr.Instance.Get(cst.npcId) == null)
            {
                cst.npcName = "?";
            }
            else
            {
                cst.npcName = EntityMgr.Instance.Get(cst.npcId).ExtGetName();
            }
            cst.diseaseName = AbnormalData.GetData((PEAbnormalType)cst.abnormalId).name;
            cst.treatName   = PELocalization.GetString(attd.treatDescription);
            cst.medicineList.Add(new ItemIdCount(attd.treatItemId[0], attd.treatItemNum));
            cst.treatTime   = attd.treatTime;
            cst.restoreTime = attd.restoreTime;
            return(cst);
        }
        catch (System.Exception e)
        {
            throw e;
        }
    }
Ejemplo n.º 2
0
    void RPC_S2C_TRT_SetTreat(uLink.BitStream stream, uLink.NetworkMessageInfo info)
    {
        CSTreatment tInUse = stream.Read <CSTreatment>();

        if (m_Entity == null)
        {
            Debug.LogError("entity not ready");
            return;
        }
        treatEntity.SetTreat(tInUse);
    }
Ejemplo n.º 3
0
 void Test()
 {
     MedicalHistoryList.Clear();
     for (int i = 0; i < 7; i++)
     {
         CSTreatment item = new CSTreatment();
         item.npcName     = "LongLongName" + i.ToString();
         item.diseaseName = "dis" + i.ToString();
         item.treatName   = "fangan" + i.ToString();
         MedicalHistoryList.Add(item);
     }
 }
Ejemplo n.º 4
0
    public void OnCheckFinish()
    {
        Data.m_CurTime = -1;
        Data.m_Time    = -1;
        CSMain.Instance.RemoveCounter(m_Counter);
//		StopCounter();
        if (GameConfig.IsMultiMode)
        {
            isNpcReady = false;
            return;
        }
        PeEntity           checkNpc = allPatients[0];
        List <CSTreatment> csts     = new List <CSTreatment>();

        System.Random rand = new System.Random();
        if (rand.NextDouble() > DEFAULT_CHECK_CHANGCE + m_Workers[0].GetDiagnoseChanceSkill)
        {
            csts.Add(CSTreatment.GetRandomTreatment(checkNpc));
        }
        else
        {
            csts = CSTreatment.CreateTreatment(checkNpc);
        }
        //--to do:
        //生成病历
        //更改npc状态  eg.diagnosing,treating, rest

        m_MgCreator.RemoveNpcTreatment(checkNpc.Id);
        if (csts != null && csts.Count > 0)
        {
            m_MgCreator.AddTreatment(csts);
            checkNpc.GetCmpt <NpcCmpt>().MedicalState = ENpcMedicalState.SearchTreat;
        }
        else
        {
            checkNpc.GetCmpt <NpcCmpt>().MedicalState = ENpcMedicalState.Cure;
        }

        allPatients.RemoveAt(0);
        Data.npcIds.RemoveAt(0);
        isNpcReady = false;
        if (allPatients.Count >= 1)
        {
            SetPatientIcon(m_Creator.GetNpc(allPatients[0].Id));
            allPatients[0].GetCmpt <NpcCmpt>().MedicalState = ENpcMedicalState.SearchDiagnos;
        }
        else
        {
            SetPatientIcon(null);
        }

        RefreshTreatment();
    }
Ejemplo n.º 5
0
    public float GetRestoreTime(PeEntity npc)
    {
        CSTreatment csTreatment = m_MgCreator.FindTreatment(npc.Id, true);

        if (csTreatment != null)
        {
            return(csTreatment.restoreTime);
        }
        else
        {
            return(0);
        }
    }
Ejemplo n.º 6
0
    public override void CreateData()
    {
        CSDefaultData ddata = null;
        bool          isNew;

        if (GameConfig.IsMultiMode)
        {
            isNew = MultiColonyManager.Instance.AssignData(ID, CSConst.dtTreat, ref ddata, _ColonyObj);
        }
        else
        {
            isNew = m_Creator.m_DataInst.AssignData(ID, CSConst.dtTreat, ref ddata);
        }
        m_Data = ddata as CSTreatData;

        if (isNew)
        {
            Data.m_Name       = CSUtils.GetEntityName(m_Type);
            Data.m_Durability = Info.m_Durability;
        }
        else
        {
            StartRepairCounter(Data.m_CurRepairTime, Data.m_RepairTime, Data.m_RepairValue);
            StartDeleteCounter(Data.m_CurDeleteTime, Data.m_DeleteTime);

            if (Data.npcIds.Count > 0)
            {
                foreach (int id in Data.npcIds)
                {
                    PeEntity npc = EntityMgr.Instance.Get(id);
                    if (npc != null)
                    {
                        allPatients.Add(npc);
                    }
                }
            }
            if (allPatients.Count > 0)
            {
                treatmentInUse = m_MgCreator.FindTreatment(allPatients[0].Id, true);
            }
            if (Data.m_ObjID >= 0)
            {
                medicineItem = ItemAsset.ItemMgr.Instance.Get(Data.m_ObjID);
            }

            StartCounter(Data.m_CurTime, Data.m_Time);

            //--to do update UI
        }
    }
Ejemplo n.º 7
0
    public static CSTreatment _readTreatmentData(BinaryReader r, int version)
    {
        CSTreatment cst = new CSTreatment();

        if (version >= CSDataMgr.VERSION001)
        {
            cst.abnormalId     = r.ReadInt32();
            cst.npcId          = r.ReadInt32();
            cst.npcName        = r.ReadString();
            cst.needTreatTimes = r.ReadInt32();
        }
        cst.InitFromRecord();
        return(cst);
    }
Ejemplo n.º 8
0
 public static void Serialize(uLink.BitStream stream, object value, params object[] codecOptions)
 {
     try
     {
         CSTreatment to = value as CSTreatment;
         stream.WriteInt32(to.abnormalId);
         stream.WriteInt32(to.npcId);
         stream.WriteInt32(to.needTreatTimes);
     }
     catch (System.Exception e)
     {
         throw e;
     }
 }
Ejemplo n.º 9
0
    public void SetTreat(CSTreatment tInUse)
    {
        allPatients[0].GetCmpt <NpcCmpt>().MedicalState = ENpcMedicalState.SearchTreat;

        treatmentInUse = m_MgCreator.GetTreatment(tInUse.abnormalId, tInUse.npcId, tInUse.needTreatTimes);
        if (treatmentInUse == null)
        {
            Debug.LogError("treatmentInUse == null!");
        }
        else
        {
            SetPatientIcon(m_Creator.GetNpc(allPatients[0].Id));
            ShowMedicineNeed(treatmentInUse.medicineList[0]);
        }
    }
Ejemplo n.º 10
0
 public float GetTreatTime(PeEntity npc)
 {
     if (treatmentInUse.npcId != npc.Id)
     {
         treatmentInUse = m_MgCreator.FindTreatment(npc.Id, true);
     }
     if (treatmentInUse != null)
     {
         return(treatmentInUse.treatTime);
     }
     else
     {
         return(0);
     }
 }
Ejemplo n.º 11
0
    public static CSTreatment GenTreatmentFromDatabase(PeEntity npc, int abnormalId)
    {
        CSTreatment           cst  = new CSTreatment();
        AbnormalTypeTreatData attd = AbnormalTypeTreatData.GetTreatment(abnormalId);

        cst.abnormalId  = abnormalId;
        cst.npcName     = npc.ExtGetName();
        cst.diseaseName = AbnormalData.GetData((PEAbnormalType)abnormalId).name;
        cst.treatName   = PELocalization.GetString(attd.treatDescription);
        cst.medicineList.Add(new ItemIdCount(attd.treatItemId[0], attd.treatItemNum));
        cst.npcId          = npc.Id;
        cst.needTreatTimes = attd.treatNum;
        cst.treatTime      = attd.treatTime;
        cst.restoreTime    = attd.restoreTime;
        return(cst);
    }
Ejemplo n.º 12
0
 public void AddPatientToUI(PeEntity npc)
 {
     if (npc == null)
     {
         RemovePatientFromUI();
     }
     else
     {
         treatmentInUse = m_MgCreator.FindTreatment(npc.Id, true);
         if (treatmentInUse == null || treatmentInUse.medicineList == null)
         {
             return;
         }
         SetPatientIcon(m_Creator.GetNpc(npc.Id));
         ShowMedicineNeed(treatmentInUse.medicineList[0]);
     }
 }
Ejemplo n.º 13
0
    public int treatState = 0;//0-treat,1-restore
    public static List <CSTreatment> CreateTreatment(PeEntity npc)
    {
        List <int> npcAbnormalTypeId = new List <int>();

        foreach (PEAbnormalType abTypeId in npc.GetCmpt <NpcCmpt>().illAbnormals)
        {
            npcAbnormalTypeId.Add((int)abTypeId);
        }
        List <CSTreatment> treatmentList = new List <CSTreatment>();

        foreach (int id in npcAbnormalTypeId)
        {
            CSTreatment cst = GenTreatmentFromDatabase(npc, id);
            treatmentList.Add(cst);
        }
        //--to do
        return(treatmentList);
    }
Ejemplo n.º 14
0
    public void TreatFinish(int npcId, bool treatSuccess)
    {
        //CSMain.Instance.RemoveCounter(m_Counter);
        StopCounter();
//        PeEntity npc = EntityMgr.Instance.Get(npcId);


        //--to do
        if (treatSuccess)
        {
            if (treatmentInUse != null)
            {
                treatmentInUse.needTreatTimes -= 1;

                if (treatmentInUse.needTreatTimes > 0)
                {
                    allPatients[0].GetCmpt <NpcCmpt>().MedicalState = ENpcMedicalState.SearchHospital;
                }
                else
                {
                    allPatients[0].GetCmpt <NpcCmpt>().CureSick((PEAbnormalType)treatmentInUse.abnormalId);
                    m_MgCreator.UpdateTreatment();
                    if (m_MgCreator.FindTreatment(allPatients[0].Id) == null)
                    {
                        allPatients[0].GetCmpt <NpcCmpt>().MedicalState = ENpcMedicalState.Cure;
                    }
                    else
                    {
                        allPatients[0].GetCmpt <NpcCmpt>().MedicalState = ENpcMedicalState.SearchTreat;
                    }
                }
            }
            else
            {
                allPatients[0].GetCmpt <NpcCmpt>().MedicalState = ENpcMedicalState.SearchHospital;
            }
        }
        else
        {
            m_MgCreator.RemoveNpcTreatment(allPatients[0].Id);
            allPatients[0].GetCmpt <NpcCmpt>().AddSick(PEAbnormalType.MedicalAccident);
            allPatients[0].GetCmpt <NpcCmpt>().MedicalState = ENpcMedicalState.SearchDiagnos;
            //--to do
        }

        treatmentInUse = null;
        allPatients.RemoveAt(0);
        Data.npcIds.RemoveAt(0);
        isNpcReady = false;
        if (allPatients.Count >= 1)
        {
            AddPatientToUI(allPatients[0]);
            allPatients[0].GetCmpt <NpcCmpt>().MedicalState = ENpcMedicalState.SearchTreat;
        }
        else
        {
            RemovePatientFromUI();
        }


        RefreshTreatment();
    }
Ejemplo n.º 15
0
    public void OnTreatFinish()
    {
        CSMain.Instance.RemoveCounter(m_Counter);
        if (GameConfig.IsMultiMode)
        {
            isNpcReady = false;
            return;
        }
        bool treatSuccess = false;

        System.Random rand = new System.Random();
        if (rand.NextDouble() > DEFAULT_TREAT_CHANCE + m_Workers[0].GetTreatChanceSkill)
        {
            //fail
            treatSuccess = false;
        }
        else
        {
            if (treatmentInUse != null)
            {
                if (!allPatients[0].GetCmpt <NpcCmpt>().illAbnormals.Contains((PEAbnormalType)treatmentInUse.abnormalId))
                {
                    treatSuccess = false;
                }
                else
                {
                    treatSuccess = true;
                }
            }
        }
        //--to do:
        //更新病历
        //更新npc状态

        if (treatSuccess)
        {
            if (treatmentInUse != null)
            {
                treatmentInUse.needTreatTimes -= 1;

                if (treatmentInUse.needTreatTimes > 0)
                {
                    allPatients[0].GetCmpt <NpcCmpt>().MedicalState = ENpcMedicalState.SearchHospital;
                }
                else
                {
                    allPatients[0].GetCmpt <NpcCmpt>().CureSick((PEAbnormalType)treatmentInUse.abnormalId);
                    m_MgCreator.UpdateTreatment();
                    if (m_MgCreator.FindTreatment(allPatients[0].Id) == null)
                    {
                        allPatients[0].GetCmpt <NpcCmpt>().MedicalState = ENpcMedicalState.Cure;
                    }
                    else
                    {
                        allPatients[0].GetCmpt <NpcCmpt>().MedicalState = ENpcMedicalState.SearchTreat;
                    }
                }
            }
            else
            {
                allPatients[0].GetCmpt <NpcCmpt>().MedicalState = ENpcMedicalState.SearchHospital;
            }
        }
        else
        {
            //--to do
            //medical negligence
            m_MgCreator.RemoveNpcTreatment(allPatients[0].Id);
            allPatients[0].GetCmpt <NpcCmpt>().AddSick(PEAbnormalType.MedicalAccident);
            allPatients[0].GetCmpt <NpcCmpt>().MedicalState = ENpcMedicalState.SearchDiagnos;
        }

        treatmentInUse = null;
        allPatients.RemoveAt(0);
        Data.npcIds.RemoveAt(0);
        isNpcReady = false;
        if (allPatients.Count >= 1)
        {
            AddPatientToUI(allPatients[0]);
            allPatients[0].GetCmpt <NpcCmpt>().MedicalState = ENpcMedicalState.SearchTreat;
        }
        else
        {
            RemovePatientFromUI();
        }

        RefreshTreatment();
    }
Ejemplo n.º 16
0
    public override bool Equals(object obj)
    {
        CSTreatment cp = obj as CSTreatment;

        return(abnormalId == cp.abnormalId && npcId == cp.npcId && needTreatTimes == cp.needTreatTimes);
    }