private static void CreateNewResource(PoolGameObjects.TypePoolPrefabs typePoolResource, AlienJob job, ReaderScene.DataObjectInfoID targetInfo, ModelNPC.GameDataAlien p_dataNPC) { PaletteMapController.SelCheckOptDel deleteOpt = PaletteMapController.SelCheckOptDel.None; PaletteMapController.SelCheckOptDel checkOpt = PaletteMapController.SelCheckOptDel.DelTerra; if (typePoolResource != PoolGameObjects.TypePoolPrefabs.PoolFloor && typePoolResource != PoolGameObjects.TypePoolPrefabs.PoolPerson) { checkOpt = PaletteMapController.SelCheckOptDel.DelPrefab; } ModelNPC.ObjectData spawnObject = Storage.GenWorld.GetCreatePrefab(job.ResourceResult, targetInfo.Field); bool isSpawned = Storage.Data.AddDataObjectInGrid(spawnObject, targetInfo.Field, "CheckJobAlien", p_modeDelete: deleteOpt, p_modeCheck: checkOpt, p_dataNPC: p_dataNPC); spawnObject.PortalId = p_dataNPC.PortalId; if (!isSpawned) { Debug.Log(Storage.EventsUI.ListLogAdd = "### JOB [" + job.Job.ToString() + "]: Not Spawn " + spawnObject.NameObject); } else if (job.Job == TypesJobs.Build) { ManagerPortals.AddConstruction(spawnObject, p_dataNPC); } }
public static bool CheckJobAlien(ModelNPC.GameDataAlien p_dataNPC, GameActionPersonController controller = null, bool isCheckDistance = true) { AlienJob job = p_dataNPC.Job; if (job == null) { return(false); } ReaderScene.DataObjectInfoID targetInfo = ReaderScene.GetInfoID(p_dataNPC.TargetID); if (targetInfo == null) { return(false); } if (!targetInfo.TestIsValud()) { p_dataNPC.TargetID = null; return(false); } if (isCheckDistance) { if (!Helper.DistanceIsFinish(targetInfo.Data.Position, p_dataNPC.Position)) { return(true); } } string fieldTarget = string.Empty; string fieldAlien = string.Empty; bool isExitTargetResource = false; Helper.GetNameFieldByPosit(ref fieldTarget, targetInfo.Data.Position); ModelNPC.PortalData portal = targetInfo.Data as ModelNPC.PortalData; SaveLoadData.TypePrefabs jobResourceTarget = job.TargetResource; Helper.GetNameFieldByPosit(ref fieldAlien, p_dataNPC.Position); if (p_dataNPC.Inventory == null) { p_dataNPC.Inventory = DataObjectInventory.EmptyInventory(); //Debug.Log(Storage.EventsUI.ListLogAdd = "## JOB: dataNPC.Inventory is null"); } else { isExitTargetResource = job.TargetResource.ToString() == p_dataNPC.Inventory.TypeInventoryObject.ToString(); } // --- TO PORTAL if (portal != null) { if (isExitTargetResource) { //***** Back to HOME **** (trget is Portal) //p_dataNPC.InventoryObject is ModelNPC; Storage.PortalsManager.AddResourceFromAlien(portal, p_dataNPC); } // --- TAKE RESOURCE bool checkStorageResource = Storage.PortalsManager.CheckStorageResourceForAlien(portal, p_dataNPC); if (!checkStorageResource && isExitTargetResource) { //End job p_dataNPC.Job = null; p_dataNPC.TargetID = string.Empty; p_dataNPC.TargetPosition = Vector3.zero; } //Continue job if (p_dataNPC.Job != null && p_dataNPC.Job.Job != TypesJobs.Bathering) { return(true); } } // --- TO LOOT && BUILD else { //Test job on target //@JOB@ if (targetInfo.Data.TypePrefab != jobResourceTarget) { return(false); } if (p_dataNPC.CurrentAction != GameActionPersonController.NameActionsPerson.CompletedLoot.ToString() && p_dataNPC.CurrentAction != GameActionPersonController.NameActionsPerson.Work.ToString()) { GameActionPersonController.ExecuteActionNPC(p_dataNPC, GameActionPersonController.NameActionsPerson.Work, controller, true); } if (p_dataNPC.CurrentAction == GameActionPersonController.NameActionsPerson.CompletedLoot.ToString()) { if (job.Job == TypesJobs.Build) { if (p_dataNPC.Inventory == null || p_dataNPC.Inventory.IsEmpty || p_dataNPC.Inventory.TypeInventoryObject.ToString() != job.ResourceResult.ToString()) { Debug.Log(Storage.EventsUI.ListLogAdd = "### JOB BUILD: Inventory is Empty >> " + job.Job.ToString() + " " + job.TargetResource + " R:" + job.ResourceResult); //p_dataNPC.Inventory = DataObjectInventory.EmptyInventory(); return(false); } } GameActionPersonController.ExecuteActionNPC(p_dataNPC, GameActionPersonController.NameActionsPerson.Move, controller, true); // **** FIND RESOURCE **** //---Replace object //1. Remove resource //Vector3 posTarget = targetInfo.Data.Position; bool isTargetTypeTrue = false; PoolGameObjects.TypePoolPrefabs typePoolResource = CheckFieldJobValid(ref isTargetTypeTrue, job, targetInfo.Data); if (job.Job == TypesJobs.Build) { if (typePoolResource == PoolGameObjects.TypePoolPrefabs.PoolFloor) { GenericWorldManager.ClearLayerObject(targetInfo.Data); } //---- TEST //else // Debug.Log(Storage.EventsUI.ListLogAdd = "TypesJobs.Build .. Not Remove resource: " + job.ResourceResult.ToString() + " >> " + targetInfo.Data.NameObject); } else { GenericWorldManager.ClearLayerObject(targetInfo.Data); } //2. Create new resource if (job.ResourceResult != SaveLoadData.TypePrefabs.PrefabField) { CreateNewResource(typePoolResource, job, targetInfo, p_dataNPC); } bool isZonaReal = Helper.IsValidPiontInZona(targetInfo.Data.Position.x, targetInfo.Data.Position.y); if (isZonaReal) { Storage.GenGrid.LoadObjectToReal(targetInfo.Field); } //3. Add resource in Inventory (where not Ground) p_dataNPC.Inventory = targetInfo.Data.LootObjectToInventory(p_dataNPC); //4. Set target to target location //if (job.JobTo == TypesJobTo.ToPortal) //{ //GameActionPersonController.RequestActionNPC(p_dataNPC, GameActionPersonController.NameActionsPerson.Idle, null); //GameActionPersonController.RequestActionNPC(p_dataNPC, GameActionPersonController.NameActionsPerson.Target, null); //} } //continue work... return(true); } return(false); }
private void PersonWork(ReaderScene.DataObjectInfoID infoNPC, int count) { var persData = infoNPC.Data as ModelNPC.GameDataAlien; if (persData == null || persData.IsReality) { return; } //List<GameActionPersonController.NameActionsPerson> actonsNPC = GameActionPersonController.GetActions(persData); //GameActionPersonController.NameActionsPerson actionCurrent = GameActionPersonController.GetCurrentAction(persData); //actionCurrent = GameActionPersonController.GetCurrentAction(persData); //GameActionPersonController.CheckNextAction(persData, actionCurrent, null); //temp_actonsNPC = GameActionPersonController.GetActions(persData); GameActionPersonController.GetCurrentAction_Cache(ref temp_actionCurrent, persData); GameActionPersonController.CheckNextAction(persData, temp_actionCurrent, null); //TEST ----------------------------- if (Storage.SceneDebug.SettingsScene.IsLog) { Storage.EventsUI.ListLogAdd = "WORK: " + persData.NameObject + " >> " + temp_actionCurrent.ToString(); } bool isZonaReal = Helper.IsValidPiontInZona(persData.Position.x, persData.Position.y); if (!persData.IsReality && isZonaReal) { //TEST ------------------------ Storage.EventsUI.ListLogAdd = "GOTO IN REAL WORLD: " + persData.NameObject; string fieldInfo = infoNPC.Field; string fieldPos = Helper.GetNameFieldPosit(persData.Position.x, persData.Position.y); string fieldName = Helper.GetNameFieldByName(persData.NameObject); if (fieldInfo != fieldPos || fieldInfo != fieldName || fieldPos != fieldName) { string strErr = "??? PersonWork name Field I: " + fieldInfo + " P:" + fieldPos + " DN:" + fieldName; Debug.Log(strErr); Storage.EventsUI.ListLogAdd = strErr; } //----------------------------- Storage.GenGrid.LoadObjectToReal(fieldName); //--- Debag //Storage.Instance.SelectGameObjectID = Helper.GetID(persData.NameObject); //Storage.EventsUI.ClearListExpandPersons(); //GameObject gobject = Storage.Instance.GamesObjectsReal[fieldPos].Find(p => p.name == persData.NameObject); //if (gobject != null) //{ // Storage.EventsUI.AddMenuPerson(persData, gobject); // Storage.GamePause = true; //} //else //{ // string strErr = "####### Not n REAL : " + persData.NameObject; // Debug.Log(strErr); // Storage.EventsUI.ListLogAdd = strErr; //} //----------------- } else { } }
//public struct CaseDreamWorker //{ // private string _id; // public string ID { get { return _id; } } // private float _timeStartDreamWork; // public float TimeStartDreamWork { get { return _timeStartDreamWork; } } // public CaseDreamWorker(string p_id, float p_timeCreate) // { // _timeStartDreamWork = p_timeCreate; // _id = p_id; // } // public CaseDreamWorker(string p_id) // { // _timeStartDreamWork = Time.time + Storage.SceneDebug.SettingsScene.TimeWorkAction; // _id = p_id; // } // public void NextTimeWorker() // { // _timeStartDreamWork = Time.time + Storage.SceneDebug.SettingsScene.TimeWorkAction; // } //} IEnumerator NavigatorWorldScene() { bool isTimeOfClear = false; float timeLimitResetNavigator = 10f; float timeLive = Time.time + timeLimitResetNavigator; int nextIndexID = 0; float waitForSeconds_SearchDreamworkersNoNPC = 8f; float waitForSeconds_NotReaderSceneIsValid = 2f; Queue <CaseDreamWorker> colectionLivePerson = new Queue <CaseDreamWorker>(); Queue <CaseDreamWorker> colectionLivePersonVIP = new Queue <CaseDreamWorker>(); List <string> listNPC; while (true) { if (m_isStop) { m_isInit = false; yield break; } timeLimitResetNavigator = Storage.SceneDebug.SettingsScene.TimeLimitResetNavigator; if (Storage.Instance.ReaderSceneIsValid) { //---Init--- if (colectionLivePerson.Count == 0) { m_IsFilledSearchingCollection = false; } if (!m_IsFilledSearchingCollection) { if (Storage.ReaderWorld.CollectionInfoID.Count == 0) { yield return(new WaitForSeconds(5f)); continue; } string message = "Search dreamworkers..."; float timeStartSearch = Time.time; Storage.EventsUI.ListLogAdd = "~~~~~~~~~~" + message; //Storage.EventsUI.SetTittle = message; m_IsRunSearching = true; //<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< SPEED //listNPC = new List<string>(); //int indexWait = 0; //var arrayID = Storage.ReaderWorld.CollectionInfoID.Values.ToArray(); //yield return null; //int count = arrayID.Count(); //nextIndexID = 0; //while(nextIndexID < count) //{ // var item = arrayID[nextIndexID]; // if (item.Data.IsNPC()) // listNPC.Add(item.ID); // if(indexWait > 1000) // { // indexWait = 0; // yield return null; // } // indexWait++; // nextIndexID++; //} //<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< //^^^^^^^^^^^^^^^^^^^^^^^^^^ TEST listNPC = new List <string>(); int indexWait = 0; //var arrayID = Storage.Instance.GridDataG.FieldsD.Select(x => x.Value). // SelectMany(x => x.Objects). // Where(p => p.IsNPC()).ToList(); var arrayID = Storage.Instance.GridDataG.FieldsD.Select(x => x.Value). SelectMany(x => x.Objects).ToList(); yield return(null); int count = arrayID.Count(); nextIndexID = 0; while (nextIndexID < count) { var item = arrayID[nextIndexID]; if (item.IsNPC()) { listNPC.Add(item.Id); } if (indexWait > 1000) { indexWait = 0; yield return(null); } indexWait++; nextIndexID++; } //^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ if (listNPC.Count == 0) { //UnityEngine.Profiling.Profiler.BeginSample("Sample LOCK dreamworkers"); Storage.EventsUI.ListLogAdd = "...Search dreamworkers No NPC... all: " + count; yield return(new WaitForSeconds(waitForSeconds_SearchDreamworkersNoNPC)); //UnityEngine.Profiling.Profiler.EndSample(); //yield return null; continue; } yield return(null); List <Shuffle> listNPC_Rnd = new List <Shuffle>(); foreach (string id in listNPC) { int indRnd = Random.Range(1, listNPC.Count()); listNPC_Rnd.Add(new Shuffle() { ID = id, Index = indRnd }); } yield return(null); //Randomize list listNPC = listNPC_Rnd.OrderBy(p => p.Index).Select(p => p.ID).ToList(); yield return(null); foreach (string id in listNPC) { //colectionLivePerson.Enqueue(new CaseDreamWorker(id)); //var item = new CaseDreamWorker(id); colectionLivePerson.Enqueue(new CaseDreamWorker(id)); } yield return(null); m_IsRunSearching = false; m_IsFilledSearchingCollection = true; //Next time reset timeLive = Time.time + timeLimitResetNavigator; isTimeOfClear = false; //if(Storage.EventsUI.SetTittle == message) //Storage.EventsUI.SetTittle = ""; Storage.EventsUI.ListLogAdd = "...Search dreamworkers end : " + (Time.time - timeStartSearch); Storage.SceneDebug.LivePersonsStartCount = colectionLivePerson.Count; } //---- //---Init VIP--- //---- //End time if (timeLive < Time.time && !isTimeOfClear) //timeLimitResetNavigator; { //Start clear Storage.EventsUI.ListLogAdd = "~~~~~~~~~~ DREAMWORKER: TimeOfClear"; isTimeOfClear = true; } foreach (int nextI in Enumerable.Range(0, 1)) { if (colectionLivePerson.Count == 0) { break; } if (!Storage.Instance.ReaderSceneIsValid) { break; } //CaseDreamWorker dreamworker = colectionLivePerson.Peek(); CaseDreamWorker dreamworker = colectionLivePerson.Dequeue(); //Continue on time work ... if (dreamworker.TimeStartDreamWork >= Time.time) { //Storage.EventsUI.ListLogAdd = "~~~~~~~Continue on time work ..." + dreamworker.ID; //Back to Live collection colectionLivePerson.Enqueue(dreamworker); continue; } //Remove on Live collection //if (isTimeOfClear) // dreamworker = colectionLivePerson.Dequeue(); //Back to Live collection if (isTimeOfClear == false) { colectionLivePerson.Enqueue(dreamworker); } string nextPersonLiveID = dreamworker.ID; if (!Storage.ReaderWorld.CollectionInfoID.ContainsKey(nextPersonLiveID)) { //Debug.Log("############## ReaderWorld.CollectionInfoID.ContainsKey Not found nextPersonLiveID "); continue; } ReaderScene.DataObjectInfoID infoNPC = Storage.ReaderWorld.CollectionInfoID[nextPersonLiveID]; if (infoNPC.Data == null) { Storage.EventsUI.ListLogAdd = "### NavigatorWorldScene InfoNPC.Data is EMPTY"; continue; } PersonWork(infoNPC, colectionLivePerson.Count); dreamworker.NextTimeWorker(); if (colectionLivePerson.Count == 0) { break; } } #if UNITY_EDITOR Storage.SceneDebug.LivePersonsCount = colectionLivePerson.Count; Storage.SceneDebug.InfoCount = Storage.ReaderWorld.CollectionInfoID.Count; #endif float timeNext = Storage.SceneDebug.SettingsScene.TimeRelax; //Storage.Person.TestSpeed yield return(new WaitForSeconds(timeNext)); } else { yield return(new WaitForSeconds(waitForSeconds_NotReaderSceneIsValid)); } } }