Esempio n. 1
0
 public void CSStoreSortSuccess(int tabIndex, int[] ids, CSStorage storage)
 {
     if (storage == m_storage)
     {
         if (tabIndex == (int)m_Type)
         {
             int pageCount = m_GridsRow * m_GridsCol;
             for (int i = 0; i < ids.Length; i++)
             {
                 if (ids[i] == -1)
                 {
                     //m_CurPack[i] = null;
                     if ((i / pageCount) == m_PageIndex)
                     {
                         m_Grids[i % pageCount].SetItem(null);
                     }
                 }
                 else
                 {
                     ItemObject itemObj = ItemMgr.Instance.Get(ids[i]);
                     //m_CurPack[i] = itemObj;
                     if ((i / pageCount) == m_PageIndex)
                     {
                         m_Grids[i % pageCount].SetItem(itemObj);
                     }
                 }
             }
         }
     }
 }
Esempio n. 2
0
 public void CSStorageResultSyncItemList(CSStorage storage)
 {
     if (storage == m_storage)
     {
         RestItems();
     }
 }
Esempio n. 3
0
    public void SetPackage(ItemPackage package, int type = 0, CSStorage storage = null)
    {
        m_Package   = package;
        m_PageIndex = 0;
        m_OpType    = 0;

        SetType(type);
        if (GameConfig.IsMultiMode)
        {
            m_storage = storage;
        }
    }
Esempio n. 4
0
 // Add Storage to m_Storages
 public void AddStorage(CSStorage storage)
 {
     if (!m_Storages.Exists(item0 => item0 == storage))
     {
         m_Storages.Add(storage);
         UpdateStorageMenu();
     }
     else
     {
         Debug.LogWarning("The storage that you want to add into UI is areadly exsts!");
     }
 }
Esempio n. 5
0
 // Remove Storage to m_Storages
 public void RemoveStorage(CSStorage storage)
 {
     if (m_Storages.Remove(storage))
     {
         UpdateStorageMenu();
         GameObject go = m_StorageMenuObjs.Find(item0 => item0.activeSelf == true);
         if (go != null)
         {
             go.GetComponent <UICheckbox>().isChecked = true;
             OnStorageMenuSelect(go);
         }
     }
 }
Esempio n. 6
0
 static ItemAsset.ItemObject GetCanEatItemFromCSStorage(PeEntity entity, CSStorage storage, int[] eatIds)
 {
     ItemAsset.ItemObject item = null;
     for (int i = 0; i < eatIds.Length; i++)
     {
         item = storage.m_Package.FindItemByProtoId(eatIds[i]);
         if (item != null)
         {
             break;
         }
     }
     return(item);
 }
Esempio n. 7
0
    private void SetActiveStorage()
    {
        if (m_SetActiveStorage != null)
        {
            int index = m_Storages.FindIndex(item0 => item0 == m_SetActiveStorage);
            if (index != -1)
            {
                m_StorageMenuObjs[index].GetComponent <UICheckbox>().isChecked = true;
                OnStorageMenuSelect(m_StorageMenuObjs[index]);
            }

            m_SetActiveStorage = null;
        }
    }
Esempio n. 8
0
    void OnStorageMenuSelect(GameObject go)
    {
        if (Input.GetMouseButtonUp(1))
        {
            return;
        }

        int index = m_StorageMenuObjs.FindIndex(item0 => item0 == go);

        ActiveStorage = m_Storages[index];
        CSUI_MainWndCtrl.Instance.mSelectedEnntity = ActiveStorage;
        m_StorageMain.m_ItemCB.isChecked           = true;
        OnStorageTypeSelect(m_StorageMain.m_ItemCB.gameObject);
    }
Esempio n. 9
0
    public void CSStoreResultSplit(bool suc, int objId, int destIndex, CSStorage storage)
    {
        ItemObject itemObj = ItemMgr.Instance.Get(objId);
        int        type    = itemObj.protoData.tabIndex;

        if (suc)
        {
            if (storage == m_storage)
            {
                if (type == (int)m_Type)
                {
                    SetItemWithIndex(itemObj, destIndex);
                }
            }
        }
    }
Esempio n. 10
0
 public void CSStoreResultFetch(bool success, int objId, CSStorage storage)
 {
     if (success)
     {
         if (storage == m_storage)
         {
             ItemObject itemObj = ItemMgr.Instance.Get(objId);
             if (OpStatusEvent != null)
             {
                 OpStatusEvent(EEventType.TakeAwayItem, itemObj.protoData.GetName(), CSUtils.GetEntityName(CSConst.etStorage));
             }
             if ((int)m_Type == itemObj.protoData.tabIndex)
             {
                 RestItems();
             }
         }
     }
 }
Esempio n. 11
0
        public static bool CanEatSthFromStorages(PeEntity entity, List <CSCommon> storages, out ItemAsset.ItemObject item)
        {
            item = null;
            if (storages == null)
            {
                return(false);
            }

            for (int i = 0; i < storages.Count; i++)
            {
                CSStorage storage = storages[i] as CSStorage;
                if (storage != null && IsContinueEatFromStorage(entity, storage, out item))
                {
                    return(true);
                }
            }
            return(false);
        }
Esempio n. 12
0
 public void CSStoreResultStore(bool success, int index, int objId, CSStorage storage)
 {
     if (success)
     {
         if (storage == m_storage)
         {
             ItemObject itemObj = ItemMgr.Instance.Get(objId);
             if (OpStatusEvent != null)
             {
                 OpStatusEvent(EEventType.PutItemInto, itemObj.protoData.GetName(), CSUtils.GetEntityName(CSConst.etStorage));
             }
             if ((int)m_Type == itemObj.protoData.tabIndex)
             {
                 SetItemWithIndex(itemObj, index);
             }
         }
     }
 }
Esempio n. 13
0
        public static bool CanEatFromStorage(PeEntity entity, CSStorage storage, out ItemAsset.ItemObject item)
        {
            item = null;
            List <AttrPer> attrpers;

            if (IsWantEat(entity, out attrpers))
            {
                for (int i = 0; i < attrpers.Count; i++)
                {
                    int[] eatids = GetEatIDs(attrpers[i].mTypeId, attrpers[i].mCurPercent);
                    item = GetCanEatItemFromCSStorage(entity, storage, eatids);
                    if (item != null)
                    {
                        return(true);
                    }
                }
            }
            return(false);
        }
Esempio n. 14
0
    // Update is called once per frame
    void Update()
    {
        if (ActiveStorage == null && m_Storages.Count > 0)
        {
            ActiveStorage = m_Storages[0];
        }

        if (ActiveStorage != null)
        {
            m_StorageMain.m_Main.SetWork(ActiveStorage.IsRunning);
        }
        else
        {
            m_StorageMain.m_Main.SetWork(false);
        }

        Transform trans = m_HistoryRootUI.transform;

        trans.localPosition = new Vector3(trans.localPosition.x, -m_HistoryRootUI.mVariableHeight, trans.localPosition.z);

        SetActiveStorage();
    }
Esempio n. 15
0
    public void CSStoreResultDelete(bool suc, int index, int objId, CSStorage storage)
    {
        ItemObject itemObj = ItemMgr.Instance.Get(objId);
        int        type    = itemObj.protoData.tabIndex;

        if (suc)
        {
            if (storage == m_storage)
            {
                if (OpStatusEvent != null)
                {
                    OpStatusEvent(EEventType.DeleteItem, itemObj.protoData.GetName(), CSUtils.GetEntityName(CSConst.etStorage));
                }

                if (type == (int)m_Type)
                {
                    if (index != -1)
                    {
                        SetItemWithIndex(null, index);
                    }
                }
            }
        }
    }
Esempio n. 16
0
    void Update()
    {
        if (!PeGameMgr.IsSingle)
        {
            return;
        }
        if (core == null)
        {
            Init();
        }
        if (core == null)
        {
            return;
        }
        counter++;
        if (counter % 450 == 0)
        {
            counter = 0;
            //--to do
            //1.collect requirements
            if (core.Storages == null)
            {
                return;
            }

            CSFactory factory = core.Factory;

            List <CSCommon> storages = core.Storages;
            ClearRequirements();
            List <CSCommon> allCommon = core.GetBelongCommons();
            foreach (CSCommon cse in allCommon)
            {
                if ((cse as CSPPCoal != null) || (cse as CSFarm != null) /*|| (cse as CSMedicalTreat !=null)*/)
                {
                    List <ItemIdCount> requirementsList = cse.GetRequirements();
                    if (requirementsList != null && requirementsList.Count > 0)
                    {
                        if (cse as CSPPCoal != null)
                        {
                            ppcoalRequirements.Add(cse, requirementsList);
                        }
                        //					if(cse as CSMedicalTreat!=null)
                        //						treatRequirements.Add(cse,requirementsList);
                        if (cse as CSFarm != null)
                        {
                            farmRequirements.Add(cse, requirementsList);
                        }
                    }
                }
            }
            bool transferedFactoryItem = false;
            //--to do
            if (storages != null)
            {
                //0.transfer factoryEndItem
                if (factory != null)
                {
                    List <ItemIdCount> replicateEndItem = factory.GetCompoudingEndItem();
                    if (replicateEndItem.Count > 0)
                    {
                        List <int> protoList = CSStorage.GetAutoProtoIdList();
                        foreach (ItemIdCount rIic in replicateEndItem)
                        {
                            if (protoList.Contains(rIic.protoId))
                            {
                                if (CSUtils.AddToStorage(rIic.protoId, rIic.count, core))
                                {
                                    factory.CountDownItem(rIic.protoId, rIic.count);
                                    transferedFactoryItem = true;
                                }
                            }
                        }
                    }
                }

                List <ItemIdCount> requirementsList = storages[0].GetRequirements();
                if (requirementsList != null && requirementsList.Count > 0)
                {
                    storageRequirements.Add(storages[0], requirementsList);
                }
            }

            //2.check doing requirements** one by one? && do requirements
            //1)check storage&factory Get supply
            List <ItemIdCount> itemsNeedToGet = new List <ItemIdCount> ();
            GetItemFromStorageAndFactory(ppcoalRequirements, storages, factory, ref itemsNeedToGet);
            GetItemFromStorageAndFactory(farmRequirements, storages, factory, ref itemsNeedToGet);
            GetItemFromStorageAndFactory(storageRequirements, storages, factory, ref itemsNeedToGet);

            if (itemsNeedToGet.Count > 0)
            {
                //3.analysis to processing or replicate
                //1).check is replicating
                if (factory != null)
                {
                    List <ItemIdCount> itemsInReplicating = new List <ItemIdCount>();
                    List <ItemIdCount> compoundingList    = factory.GetCompoudingItem();
                    foreach (ItemIdCount needItem in itemsNeedToGet)
                    {
                        ItemIdCount cItem = compoundingList.Find(it => it.protoId == needItem.protoId);
                        if (cItem != null)
                        {
                            if (cItem.count >= needItem.count)
                            {
                                itemsInReplicating.Add(new ItemIdCount(cItem.protoId, needItem.count));
                            }
                            else
                            {
                                itemsInReplicating.Add(new ItemIdCount(cItem.protoId, cItem.count));
                            }
                        }
                    }
                    if (itemsInReplicating.Count > 0)
                    {
                        foreach (ItemIdCount ic in itemsInReplicating)
                        {
                            ItemIdCount decreaseItem = itemsNeedToGet.Find(it => it.protoId == ic.protoId);
                            if (decreaseItem.count > ic.count)
                            {
                                decreaseItem.count -= ic.count;
                            }
                            else
                            {
                                itemsNeedToGet.Remove(decreaseItem);
                            }
                        }
                    }

                    //2).put material into storage
                    GetItemMaterialFromFactory(factory, itemsNeedToGet, ref transferedFactoryItem);
                    if (transferedFactoryItem)
                    {
                        ShowTips(ETipType.factory_to_storage);
                    }

                    //3).count what need Processing/ replicate some
                    //1-check can be replicated,if ok, replicate
                    factory.CreateNewTaskWithItems(itemsNeedToGet);
                }
                //2-check the left things to resolve to resource
                //3-in 2,check resource already have, remove it
                List <ItemIdCount> resourceItems = ResolveItemsToProcess(itemsNeedToGet, core, factory);
//				foreach(ItemIdCount iic in resourceItems){
//					int gotCount =0;
//					foreach(CSCommon sc in storages){
//						CSStorage cst = sc as CSStorage;
//						int itemCount = cst.GetItemCount(iic.protoId);
//						if(itemCount>0)
//						{
//							if(itemCount>=iic.count-gotCount)
//							{
//								gotCount = iic.count;
//								break;
//							}else{
//								gotCount += itemCount;
//							}
//						}
//					}
//					iic.count-=gotCount;
//				}

                resourceItems.RemoveAll(it => it.count <= 0);
                if (resourceItems.Count > 0)
                {
                    //3).check is Processing
                    CSProcessing process = core.ProcessingFacility;
                    if (process != null)
                    {
                        List <ItemIdCount> processingList = process.GetItemsInProcessing();
                        foreach (ItemIdCount iic in processingList)
                        {
                            CSUtils.RemoveItemIdCount(resourceItems, iic.protoId, iic.count);
                        }
                    }
                    if (resourceItems.Count > 0)
                    {
                        //4).assign processing task
                        if (process != null)
                        {
                            process.CreateNewTaskWithItems(resourceItems);
                        }
                    }
                }
            }



            //meet desire
            ClearDesires();
            if (storages != null)
            {
                List <ItemIdCount> desireList = storages[0].GetDesires();
                if (desireList != null && desireList.Count > 0)
                {
                    storageDesires.Add(storages[0], desireList);
                    List <ItemIdCount> itemsDesireToGet = new List <ItemIdCount> ();
                    GetItemFromStorageAndFactory(storageDesires, storages, factory, ref itemsDesireToGet);
                    if (itemsDesireToGet.Count > 0 && factory != null)
                    {
                        if (factory != null)
                        {
                            List <ItemIdCount> itemsInReplicating = new List <ItemIdCount>();
                            List <ItemIdCount> compoundingList    = factory.GetCompoudingItem();
                            foreach (ItemIdCount needItem in itemsDesireToGet)
                            {
                                ItemIdCount cItem = compoundingList.Find(it => it.protoId == needItem.protoId);
                                if (cItem != null)
                                {
                                    if (cItem.count >= needItem.count)
                                    {
                                        itemsInReplicating.Add(new ItemIdCount(cItem.protoId, needItem.count));
                                    }
                                    else
                                    {
                                        itemsInReplicating.Add(new ItemIdCount(cItem.protoId, cItem.count));
                                    }
                                }
                            }
                            if (itemsInReplicating.Count > 0)
                            {
                                foreach (ItemIdCount ic in itemsInReplicating)
                                {
                                    ItemIdCount decreaseItem = itemsDesireToGet.Find(it => it.protoId == ic.protoId);
                                    if (decreaseItem.count > ic.count)
                                    {
                                        decreaseItem.count -= ic.count;
                                    }
                                    else
                                    {
                                        itemsDesireToGet.Remove(decreaseItem);
                                    }
                                }
                            }
                        }
                        factory.CreateNewTaskWithItems(itemsDesireToGet);
                    }
                }
            }


            //medical system
            if (core.MedicalCheck != null && core.MedicalTreat != null && core.MedicalTent != null &&
                core.MedicalCheck.IsRunning && core.MedicalTreat.IsRunning && core.MedicalTent.IsRunning &&
                (core.MedicalCheck.WorkerCount + core.MedicalTreat.WorkerCount + core.MedicalTent.WorkerCount > 0))
            {
                if (lastTime < 0)
                {
                    lastTime = GameTime.PlayTime.Second;
                }
                else
                {
                    core.MedicineResearchState += GameTime.PlayTime.Second - lastTime;
                    lastTime = GameTime.PlayTime.Second;
                    if (storages != null && core.MedicineResearchState >= medicineSupplyTime)
                    {
                        Debug.Log("supplyMedicineTime");
                        core.MedicineResearchTimes++;
                        List <ItemIdCount> supportMedicine = new List <ItemIdCount> ();
                        //try supply
                        foreach (MedicineSupply ms in CSMedicineSupport.AllMedicine)
                        {
                            if (core.MedicineResearchTimes - ms.rounds * Mathf.FloorToInt(core.MedicineResearchTimes / ms.rounds)
                                < 1)
                            {
                                if (CSUtils.GetItemCountFromAllStorage(ms.protoId, core) < ItemAsset.ItemProto.GetItemData(ms.protoId).maxStackNum)
                                {
                                    supportMedicine.Add(new ItemIdCount(ms.protoId, ms.count));
                                }
                            }
                        }
                        if (supportMedicine.Count > 0)
                        {
                            if (CSUtils.AddItemListToStorage(supportMedicine, core))
                            {
                                ShowTips(ETipType.medicine_supply);
                            }
                            else
                            {
                                ShowTips(ETipType.storage_full);
                            }
                        }

                        core.MedicineResearchState = 0;
                        if (core.MedicineResearchTimes == Int32.MaxValue)
                        {
                            core.MedicineResearchTimes = 0;
                        }
                    }
                }
            }
            else
            {
                lastTime = GameTime.PlayTime.Second;
            }
        }
    }
Esempio n. 17
0
    public void GetItemFromStorageAndFactory(Dictionary <CSCommon, List <ItemIdCount> > requirementsMachine, List <CSCommon> storages, CSFactory factory, ref List <ItemIdCount> itemsNeedToGet)
    {
        foreach (KeyValuePair <CSCommon, List <ItemIdCount> > kvp in requirementsMachine)
        {
            foreach (ItemIdCount iic in kvp.Value)
            {
                //1.storage,storageRequire
                int gotCount            = 0;
                int getCountFromStorage = 0;
                if (kvp.Key as CSStorage == null)
                {
                    foreach (CSCommon sc in storages)
                    {
                        CSStorage cst       = sc as CSStorage;
                        int       itemCount = cst.GetItemCount(iic.protoId);
                        if (itemCount > 0)
                        {
                            if (itemCount >= iic.count - gotCount)
                            {
                                gotCount            = iic.count;
                                getCountFromStorage = iic.count;
                                break;
                            }
                            else
                            {
                                gotCount            += itemCount;
                                getCountFromStorage += itemCount;
                            }
                        }
                    }
                    if (gotCount == iic.count)
                    {
                        if (kvp.Key.MeetDemand(iic.protoId, gotCount))
                        {
                            CSUtils.CountDownItemFromAllStorage(iic.protoId, gotCount, core);
                        }
                        continue;
                    }
                }
                //2.factory
                int leftCount       = iic.count - gotCount;
                int getCountFromFac = 0;
                if (factory != null)
                {
                    int factoryItemCount = factory.GetCompoundEndItemCount(iic.protoId);
                    if (factoryItemCount > 0)
                    {
                        int countDownCount = 0;
                        if (factoryItemCount >= leftCount)
                        {
                            countDownCount = leftCount;
                        }
                        else
                        {
                            countDownCount = factoryItemCount;
                        }
                        gotCount        += countDownCount;
                        getCountFromFac += countDownCount;
                    }
                }

                if (gotCount == iic.count)
                {
                    if (kvp.Key.MeetDemand(iic.protoId, gotCount))
                    {
                        if (getCountFromStorage > 0)
                        {
                            CSUtils.CountDownItemFromAllStorage(iic.protoId, getCountFromStorage, core);
                        }
                        if (getCountFromFac > 0)
                        {
                            factory.CountDownItem(iic.protoId, getCountFromFac);
                        }
                    }
                    continue;
                }
                else
                {
                    if (gotCount > 0)
                    {
                        if (kvp.Key.MeetDemand(iic.protoId, gotCount))
                        {
                            if (getCountFromStorage > 0)
                            {
                                CSUtils.CountDownItemFromAllStorage(iic.protoId, getCountFromStorage, core);
                            }
                            if (getCountFromFac > 0)
                            {
                                factory.CountDownItem(iic.protoId, getCountFromFac);
                            }
                        }
                    }
                }

                leftCount = iic.count - gotCount;

                //3.add to needToGet
                ItemIdCount addNeed = itemsNeedToGet.Find(it => it.protoId == iic.protoId);
                if (addNeed != null)
                {
                    addNeed.count += leftCount;
                }
                else
                {
                    itemsNeedToGet.Add(new ItemIdCount(iic.protoId, leftCount));
                }
            }
        }
    }
Esempio n. 18
0
    // <CETC> Create Non-Managed Entity
    public override int CreateEntity(CSEntityAttr attr, out CSEntity outEnti)
    {
        outEnti = null;

        if (attr.m_Type == CSConst.etAssembly)
        {
            Debug.LogWarning("Non-Managed Creator cant create the Assembly Entity.");
            return(CSConst.rrtUnkown);
        }

        if (m_CommonEntities.ContainsKey(attr.m_InstanceId))
        {
            outEnti                  = m_CommonEntities[attr.m_InstanceId];
            outEnti.gameObject       = attr.m_Obj;
            outEnti.Position         = attr.m_Pos;
            outEnti.ItemID           = attr.m_protoId;
            outEnti.BaseData.m_Alive = true;
            return(CSConst.rrtSucceed);
        }

        CSCommon csc = null;

        switch (attr.m_Type)
        {
        case CSConst.etStorage:
            csc = new CSStorage();
            CSStorage css = csc as CSStorage;
            css.m_Info    = CSInfoMgr.m_StorageInfo;
            css.m_Creator = this;
            css.m_Power   = attr.m_Power;
            css.m_Package.ExtendPackage(CSInfoMgr.m_StorageInfo.m_MaxItem, CSInfoMgr.m_StorageInfo.m_MaxEquip, CSInfoMgr.m_StorageInfo.m_MaxRecource, CSInfoMgr.m_StorageInfo.m_MaxArmor);
            break;

        case CSConst.etEnhance:
            csc = new CSEnhance();
            CSEnhance csen = csc as CSEnhance;
            csen.m_Creator = this;
            csen.m_Power   = attr.m_Power;
            csen.m_Info    = CSInfoMgr.m_EnhanceInfo;
            break;

        case CSConst.etRepair:
            csc = new CSRepair();
            CSRepair csr = csc as CSRepair;
            csr.m_Creator = this;
            csr.m_Power   = attr.m_Power;
            csr.m_Info    = CSInfoMgr.m_RepairInfo;
            break;

        case CSConst.etRecyle:
            csc = new CSRecycle();
            CSRecycle csrc = csc as CSRecycle;
            csrc.m_Creator = this;
            csrc.m_Power   = attr.m_Power;
            csrc.m_Info    = CSInfoMgr.m_RecycleInfo;
            break;

        case CSConst.etDwelling:
            csc = new CSDwellings();
            CSDwellings csd = csc as CSDwellings;
            csd.m_Creator = this;
            csd.m_Power   = attr.m_Power;;
            csd.m_Info    = CSInfoMgr.m_DwellingsInfo;
            break;

        case CSConst.etppCoal:
            csc = new CSPPCoal();
            CSPPCoal cscppc = csc as CSPPCoal;
            cscppc.m_Creator   = this;
            cscppc.m_Power     = 10000;
            cscppc.m_RestPower = 10000;
            cscppc.m_Info      = CSInfoMgr.m_ppCoal;
            break;

        case CSConst.etppSolar:
            csc = new CSPPSolar();
            CSPPSolar cspps = csc as CSPPSolar;
            cspps.m_Creator   = this;
            cspps.m_Power     = 10000;
            cspps.m_RestPower = 10000;
            cspps.m_Info      = CSInfoMgr.m_ppCoal;
            break;

        case CSConst.etFactory:
            csc           = new CSFactory();
            csc.m_Creator = this;
            csc.m_Info    = CSInfoMgr.m_FactoryInfo;
            break;

        default:
            break;
        }

        csc.ID = attr.m_InstanceId;
        csc.CreateData();
        csc.gameObject = attr.m_Obj;
        csc.Position   = attr.m_Pos;
        csc.ItemID     = attr.m_protoId;

        outEnti = csc;
        m_CommonEntities.Add(attr.m_InstanceId, csc);
        return(CSConst.rrtSucceed);
    }
Esempio n. 19
0
    CSCommon _CreateCommon(int type)
    {
        CSCommon csc = null;

        switch (type)
        {
        case CSConst.etStorage:
            csc = new CSStorage();
            CSStorage css = csc as CSStorage;
            css.m_Info    = CSInfoMgr.m_StorageInfo;
            css.m_Creator = this;
            css.m_Package.ExtendPackage(CSInfoMgr.m_StorageInfo.m_MaxItem, CSInfoMgr.m_StorageInfo.m_MaxEquip, CSInfoMgr.m_StorageInfo.m_MaxRecource, CSInfoMgr.m_StorageInfo.m_MaxArmor);
            break;

        case CSConst.etEnhance:
            csc = new CSEnhance();
            CSEnhance csen = csc as CSEnhance;
            csen.m_Creator = this;
            csen.m_Info    = CSInfoMgr.m_EnhanceInfo;
            break;

        case CSConst.etRepair:
            csc = new CSRepair();
            CSRepair csr = csc as CSRepair;
            csr.m_Creator = this;
            csr.m_Info    = CSInfoMgr.m_RepairInfo;
            break;

        case CSConst.etRecyle:
            csc = new CSRecycle();
            CSRecycle csrc = csc as CSRecycle;
            csrc.m_Creator = this;
            csrc.m_Info    = CSInfoMgr.m_RecycleInfo;
            break;

        case CSConst.etDwelling:
            csc = new CSDwellings();
            CSDwellings csd = csc as CSDwellings;
            csd.m_Creator = this;
            csd.m_Info    = CSInfoMgr.m_DwellingsInfo;

            // Find the npc to live
            if (!PeGameMgr.IsMulti)
            {
                int index = 0;
                foreach (KeyValuePair <int, CSCommon> kvp in m_CommonEntities)
                {
                    if (index >= csd.m_NPCS.Length)
                    {
                        break;
                    }

                    if (kvp.Value.m_Type == CSConst.etDwelling)
                    {
                        CSDwellings dwellings = kvp.Value as CSDwellings;
                        if (dwellings.IsRunning)
                        {
                            continue;
                        }
                        for (int i = 0; i < dwellings.m_NPCS.Length; i++)
                        {
                            if (dwellings.m_NPCS[i] != null)
                            {
                                csd.AddNpcs(dwellings.m_NPCS[i]);
                                dwellings.RemoveNpc(dwellings.m_NPCS[i]);
                                index++;
                            }
                        }
                    }
                }
            }
            break;

        case CSConst.etppCoal:
            csc = new CSPPCoal();
            CSPPCoal cscppc = csc as CSPPCoal;
            cscppc.m_Creator   = this;
            cscppc.m_Power     = 10000;
            cscppc.m_RestPower = 10000;
            cscppc.m_Info      = CSInfoMgr.m_ppCoal;
            break;

        case CSConst.etppSolar:
            csc = new CSPPSolar();
            CSPPSolar cspps = csc as CSPPSolar;
            cspps.m_Creator   = this;
            cspps.m_Power     = 10000;
            cspps.m_RestPower = 10000;
            cspps.m_Info      = CSInfoMgr.m_ppCoal;
            break;

        case CSConst.etFarm:
            csc           = new CSFarm();
            csc.m_Creator = this;
            csc.m_Info    = CSInfoMgr.m_FarmInfo;
            break;

        case CSConst.etFactory:
            csc           = new CSFactory();
            csc.m_Creator = this;
            csc.m_Info    = CSInfoMgr.m_FactoryInfo;
            break;

        case CSConst.etProcessing:
            csc = new CSProcessing(this);
            CSProcessing csp = csc as CSProcessing;
            csp.m_Info = CSInfoMgr.m_ProcessingInfo;
            break;

        case CSConst.etTrade:
            csc = new CSTrade(this);
            CSTrade cst = csc as CSTrade;
            cst.m_Info = CSInfoMgr.m_Trade;
            break;

        case CSConst.etTrain:
            csc = new CSTraining(this);
            CSTraining cstrain = csc as CSTraining;
            cstrain.m_Info = CSInfoMgr.m_Train;
            break;

        case CSConst.dtCheck:
            csc = new CSMedicalCheck(this);
            CSMedicalCheck csCheck = csc as CSMedicalCheck;
            csCheck.m_Info = CSInfoMgr.m_Check;
            break;

        case CSConst.dtTreat:
            csc = new CSMedicalTreat(this);
            CSMedicalTreat csTreat = csc as CSMedicalTreat;
            csTreat.m_Info = CSInfoMgr.m_Treat;
            break;

        case CSConst.dtTent:
            csc = new CSMedicalTent(this);
            CSMedicalTent csTent = csc as CSMedicalTent;
            csTent.m_Info = CSInfoMgr.m_Tent;
            break;

        case CSConst.dtppFusion:
            csc = new CSPPFusion();
            CSPPFusion csFusion = csc as CSPPFusion;
            csFusion.m_Creator   = this;
            csFusion.m_Power     = 10000;
            csFusion.m_RestPower = 100000;
            csFusion.m_Info      = CSInfoMgr.m_ppFusion;
            break;

        default:
            break;
        }

        return(csc);
    }
Esempio n. 20
0
 public void CSStoreResultExchange(bool success, int objId, int destIndex, int destId, int originIndex, CSStorage storage)
 {
     if (success)
     {
         if (storage == m_storage)
         {
             ItemObject originObj = ItemMgr.Instance.Get(objId);
             int        type      = originObj.protoData.tabIndex;
             ItemObject destObj;
             if (destId == -1)
             {
                 destObj = null;
             }
             else
             {
                 destObj = ItemMgr.Instance.Get(destId);
             }
             if ((int)m_Type == type)
             {
                 SetItemWithIndex(originObj, destIndex);
                 SetItemWithIndex(destObj, originIndex);
             }
         }
     }
 }
    private void _farmWorkStyle()
    {
        CSFarm farm = WorkRoom as CSFarm;

        if (farm == null)
        {
            return;
        }

        FarmPlantLogic plant = null;

        CSMgCreator mgCreator = m_Creator as CSMgCreator;

        // Only watering and weeding
        if (m_WorkMode == CSConst.pwtFarmForMag)
        {
            if (m_FarmWorkMap.Count != 0)
            {
                return;
            }

            ItemObject waterItem   = farm.GetPlantTool(0);
            ItemObject weedingItem = farm.GetPlantTool(1);

            // Watering
            plant = waterItem == null ? null : farm.AssignOutWateringPlant();
            if (plant != null)
            {
                FarmWorkInfo fwi = new FarmWorkInfo(plant);
                m_FarmWorkMap.Add(EFarmWorkType.Watering, fwi);

                //_sendToWorkOnFarm(fwi.m_Pos);
            }
            else
            {
                // Weeding
                plant = weedingItem == null ? null : farm.AssignOutCleaningPlant();

                if (plant != null)
                {
                    FarmWorkInfo fwi = new FarmWorkInfo(plant);
                    m_FarmWorkMap.Add(EFarmWorkType.Cleaning, fwi);

                    //_sendToWorkOnFarm(fwi.m_Pos);
                }
                //else
                //    Idle(0.0f, false);
            }
        }
        else if (m_WorkMode == CSConst.pwtFarmForHarvest)
        {
            if (m_FarmWorkMap.Count != 0)
            {
                return;
            }

            CSStorage storage = null;

            foreach (CSStorage css in farm.Assembly.m_BelongObjectsMap[CSConst.ObjectType.Storage])
            {
                SlotList slotList = css.m_Package.GetSlotList();
                if (slotList.GetVacancyCount() >= 2)
                //if (css.m_Package.GetEmptyGridCount() >= 2)
                {
                    storage = css;
                    break;
                }
            }

            if (storage != null)
            {
                plant = farm.AssignOutRipePlant();

                if (plant != null)
                {
                    FarmWorkInfo fwi = new FarmWorkInfo(plant);
                    m_FarmWorkMap.Add(EFarmWorkType.Harvesting, fwi);
                    //_sendToWorkOnFarm(fwi.m_Pos);
                }
                //else
                //    Idle(0.0f, false);
            }
            //else
            //    Idle(0.0f, false);
        }
        else if (m_WorkMode == CSConst.pwtFarmForPlant)
        {
            // Planting
            if (m_FarmWorkMap.Count == 0)
            {
#if NEW_CLOD_MGR
                ClodChunk cc = mgCreator.m_Clod.FindCleanChunk(farm.Assembly.Position, farm.Assembly.Radius);
#else
                ClodChunk cc = CSClodMgr.FindCleanChunk(farm.Assembly.Position, farm.Assembly.Radius);
#endif

                if (farm.HasPlantSeed() && cc != null)
                {
                    Vector3 pos;
                    bool    flag = cc.FindCleanClod(out pos);
                    if (flag)
                    {
#if NEW_CLOD_MGR
                        mgCreator.m_Clod.DirtyTheChunk(cc.m_ChunkIndex, true);
#else
                        CSClodMgr.DirtyTheChunk(cc.m_ChunkIndex, true);
#endif
                        FarmWorkInfo fwi = new FarmWorkInfo(cc, pos);
                        m_FarmWorkMap.Add(EFarmWorkType.Planting, fwi);

                        _sendToWorkOnFarm(fwi.m_Pos);
                    }
                }
                //else
                //    Idle(0.0f, false);
            }
            else if (m_FarmWorkMap.ContainsKey(EFarmWorkType.Planting) &&
                     m_FarmWorkMap[EFarmWorkType.Planting].m_Pos == Vector3.zero)
            {
                if (farm.HasPlantSeed())
                {
                    FarmWorkInfo fwi  = m_FarmWorkMap[EFarmWorkType.Planting];
                    bool         flag = fwi.m_ClodChunk.FindCleanClod(out fwi.m_Pos);

                    if (flag)
                    {
                        //_sendToWorkOnFarm(fwi.m_Pos);
                    }
                    else
                    {
                        m_FarmWorkMap.Remove(EFarmWorkType.Planting);
                    }
                }
                else
                {
                    FarmWorkInfo fwi = m_FarmWorkMap[EFarmWorkType.Planting];
#if NEW_CLOD_MGR
                    mgCreator.m_Clod.DirtyTheChunk(fwi.m_ClodChunk.m_ChunkIndex, false);
#else
                    CSClodMgr.DirtyTheChunk(fwi.m_ClodChunk.m_ChunkIndex, false);
#endif
                    m_FarmWorkMap.Remove(EFarmWorkType.Planting);
                }
            }

            if (!m_FarmWorkMap.ContainsKey(EFarmWorkType.Planting))
            {
                //Idle(0.0f, false);
            }
        }
    }
Esempio n. 22
0
    public RandomItemObj GetTaskResult(float percent, List <ItemIdCount> itemList)
    {
        System.Random rand = new System.Random();
        //--to do: wait
        //count item 10%random
        //create item
        //add to npcpackage
        List <ItemIdCount> resourceGot = new List <ItemIdCount> ();

        foreach (ItemIdCount item in itemList)
        {
            int getCount = Mathf.FloorToInt(item.count * percent);
            resourceGot.Add(new ItemIdCount(item.protoId, getCount));
        }
        List <ItemIdCount> itemIdNum = resourceGot.FindAll(it => it.count > 0);

        if (itemIdNum.Count <= 0)
        {
            return(null);
        }

        //put into storage
        bool addInStorage = false;

        if (Assembly != null && Assembly.Storages != null)
        {
            List <MaterialItem> materialList = CSUtils.ItemIdCountToMaterialItem(itemIdNum);
            foreach (CSCommon css in Assembly.Storages)
            {
                CSStorage storage = css as CSStorage;
                if (storage.m_Package.CanAdd(materialList))
                {
                    storage.m_Package.Add(materialList);
                    addInStorage = true;
                    //--to do: inform player
                    CSUtils.ShowTips(ProcessingConst.INFORM_FINISH_TO_STORAGE);
                    break;
                }
                else
                {
                    if (CSAutocycleMgr.Instance != null)
                    {
                        CSAutocycleMgr.Instance.ShowTips(ETipType.storage_full);
                    }
                }
            }
        }
        if (addInStorage)
        {
            return(null);
        }

        int[] items = CSUtils.ItemIdCountListToIntArray(itemIdNum);

        Vector3 resultPos = Position + new Vector3(0f, 0.72f, 0f);

        if (BuildingLogic != null)
        {
            if (BuildingLogic.m_ResultTrans.Length > 0)
            {
                Transform trans = BuildingLogic.m_ResultTrans[rand.Next(BuildingLogic.m_ResultTrans.Count())];
                if (trans != null)
                {
                    resultPos = trans.position;
                }
            }
        }
        while (RandomItemMgr.Instance.ContainsPos(resultPos))
        {
            resultPos += new Vector3(0, 0.01f, 0);
        }
        //return new RandomItemObj(resultPos + new Vector3((float)rand.NextDouble()*0.15f, 0, (float)rand.NextDouble()*0.15f), items);
        CSUtils.ShowTips(ProcessingConst.INFORM_FINISH_TO_RANDOMITEM);
        return(RandomItemMgr.Instance.GenProcessingItem(resultPos + new Vector3((float)rand.NextDouble() * 0.15f, 0, (float)rand.NextDouble() * 0.15f), items));
    }
Esempio n. 23
0
    private void OnRecycled()
    {
        Dictionary <int, int> recycleItems = GetRecycleItems();

        if (null == recycleItems)
        {
            return;
        }

        List <ItemIdCount> resourceGot = new List <ItemIdCount>();

        foreach (KeyValuePair <int, int> kvp in recycleItems)
        {
            resourceGot.Add(new ItemIdCount(kvp.Key, kvp.Value));
        }

        if (resourceGot.Count <= 0)
        {
            return;
        }
        List <MaterialItem> materialList = CSUtils.ItemIdCountToMaterialItem(resourceGot);
        ItemPackage         accessor     = PeCreature.Instance.mainPlayer.GetCmpt <PlayerPackageCmpt>().package._playerPak;

        if (null == accessor)
        {
            return;
        }

        bool addToPackage = false;

        //lz-2016.12.27 尝试添加到玩家背包
        if (accessor.CanAdd(materialList))
        {
            accessor.Add(materialList);
            GameUI.Instance.mItemPackageCtrl.ResetItem();
            addToPackage = true;
            CSUtils.ShowTips(RecycleConst.INFORM_FINISH_TO_PACKAGE);
        }

        //lz-2016.12.27 尝试添加到基地存储箱
        if (!addToPackage && Assembly != null && Assembly.Storages != null)
        {
            foreach (CSCommon css in Assembly.Storages)
            {
                CSStorage storage = css as CSStorage;
                if (storage.m_Package.CanAdd(materialList))
                {
                    storage.m_Package.Add(materialList);
                    addToPackage = true;
                    CSUtils.ShowTips(RecycleConst.INFORM_FINISH_TO_STORAGE);
                    break;
                }
            }
        }

        //lz-2016.12.27 尝试生成一个小球放物品
        if (!addToPackage)
        {
            System.Random rand = new System.Random();

            List <ItemIdCount> itemIdNum = resourceGot.FindAll(it => it.count > 0);
            if (itemIdNum.Count <= 0)
            {
                return;
            }

            int[] items = CSUtils.ItemIdCountListToIntArray(itemIdNum);

            Vector3 resultPos = Position + new Vector3(0f, 0.72f, 0f);

            if (BuildingLogic != null)
            {
                if (BuildingLogic.m_ResultTrans.Length > 0)
                {
                    Transform trans = BuildingLogic.m_ResultTrans[rand.Next(BuildingLogic.m_ResultTrans.Length)];
                    if (trans != null)
                    {
                        resultPos = trans.position;
                    }
                }
            }
            while (RandomItemMgr.Instance.ContainsPos(resultPos))
            {
                resultPos += new Vector3(0, 0.01f, 0);
            }
            RandomItemMgr.Instance.GenProcessingItem(resultPos + new Vector3((float)rand.NextDouble() * 0.15f, 0, (float)rand.NextDouble() * 0.15f), items);
            addToPackage = true;
            CSUtils.ShowTips(RecycleConst.INFORM_FINISH_TO_RANDOMITEM);
        }

        if (addToPackage)
        {
            // Delete Item;
            ItemMgr.Instance.DestroyItem(m_Item.itemObj.instanceId);
            m_Item = null;

            // Call back
            if (onRecylced != null)
            {
                onRecylced();
            }
        }
    }