public void CreatePortal() { string[] portalsId = Storage.GenWorld.GenericPortal(1, SaveLoadData.TypePrefabs.PortalBlue); foreach (string idPortal in portalsId) { if (ReaderScene.ExistID(idPortal)) { var info = ReaderScene.GetInfoID(idPortal); ModelNPC.PortalData portalNext = info.Data as ModelNPC.PortalData; if (portalNext != null) { Portals.Add(portalNext); //... Check on Real string fieldName = string.Empty; Helper.GetNameFieldByPosit(ref fieldName, portalNext.Position); bool isZonaReal = Helper.IsValidPiontInZona(portalNext.Position.x, portalNext.Position.y); if (!isZonaReal) { portalNext.IsReality = false; } if (!portalNext.IsReality && isZonaReal) { Storage.GenGrid.LoadObjectToReal(fieldName); } //else // portalNext.IsReality = false; } } } }
public void UpdateDataObect(string nameField, int index, ModelNPC.ObjectData setObject, string callFunc, Vector3 newPos = new Vector3()) { if (Storage.Log.IsSaveHistory) { ModelNPC.ObjectData oldObj = ReaderScene.GetObjectDataFromGrid(nameField, index); Storage.Log.SaveHistory(setObject.NameObject, "UpdateDataObect", callFunc, nameField, "", oldObj, setObject); Storage.Log.SaveHistory(oldObj.NameObject, "UpdateDataObect", callFunc, nameField, "RESAVE", oldObj, setObject); } var testPos = new Vector3(); if (testPos != newPos) { //if (setObject.IsMoveValid()) //FIX~~TRANSFER //{ // setObject.IsTransfer = true; setObject.SetPosition(newPos); // setObject.IsTransfer = false; //} } SetObjecDataFromGrid(nameField, index, setObject); // -- 3* if (Storage.Map.IsGridMap) { Storage.Map.CheckSector(nameField); } }
public static ModelNPC.ObjectData GetObjectDataFromGrid(string nameGameObject, string nameField) { if (!ReaderScene.IsGridDataFieldExist(nameField)) { Debug.Log("################# Error FindObjectData FIELD NOT FOUND :" + nameField + " find object: " + nameGameObject); //if (!Storage.Instance.IsLoadingWorldThread) //{ //Storage.Data.AddNewFieldInGrid(nameField, "GetObjecsDataFromGrid", true); //} //else //{ // Debug.Log("################# Error FindObjectData FIELD NOT FOUND :" + nameField + " find object: " + nameGameObject); return(null); // //return new ModelNPC.ObjectData(); //} } List <ModelNPC.ObjectData> objects = ReaderScene.GetObjectsDataFromGrid(nameField); int index = objects.FindIndex(p => p.NameObject == nameGameObject); if (index == -1) { Debug.Log("################# Error FindObjectData DATA OBJECT NOT FOUND : " + nameGameObject + " in Field: " + nameField); return(null); } return(objects[index]); }
private static void CeckJobPass(ref ModelNPC.ObjectData result, ModelNPC.GameDataAlien dataAlien) { dataAlien.JobPass++; if (dataAlien.JobPass > 2) { Debug.Log(Storage.EventsUI.ListLogAdd = "[[[ JobPass Go To Home ]]] " + dataAlien.NameObject); if (dataAlien.PortalId == null) { Storage.PortalsManager.SetHome(dataAlien); } var info = ReaderScene.GetInfoID(dataAlien.PortalId); if (info != null) { if (dataAlien.JobPass >= 5) { result = info.Data; } else { var portal = info.Data as ModelNPC.PortalData; if (portal != null && portal.Resources == null && portal.Resources.Count > 0) { result = info.Data; } } } dataAlien.JobPass = 0; } }
/* * public void RemoveDataObjectInGrid(string nameField, int index, string callFunc, bool isDebug = false, ModelNPC.ObjectData dataObjDel = null) * { * ModelNPC.ObjectData histData = null; * if (Storage.Log.IsSaveHistory) * histData = ReaderScene.GetObjectsDataFromGrid(nameField)[index]; * if (isDebug) * Debug.Log("****** RemoveDataObjectInGrid : start " + histData); * * if(dataObjDel!=null && dataObjDel.NameObject != histData.NameObject) * { * index = ReaderScene.GetObjectsDataFromGrid(nameField).FindIndex(p => p.NameObject == dataObjDel.NameObject); * if (index == -1) * { * Debug.Log("###################### RemoveDataObjectInGrid Data Del: " + dataObjDel.NameObject + " Data Find: " + histData.NameObject + " ... NOT find in Field: " + nameField); * Storage.Log.SaveHistory(histData.NameObject, "ERROR RemoveDataObjectInGrid", callFunc, nameField, "Conflict Name", dataObjDel, histData); * return; * } * histData = ReaderScene.GetObjectsDataFromGrid(nameField)[index]; * if(dataObjDel.NameObject != histData.NameObject) * { * Debug.Log("###################### RemoveDataObjectInGrid Data Del: " + dataObjDel.NameObject + " Data Find: " + histData.NameObject + " ... NOT find in Field: " + nameField); * Storage.Log.SaveHistory(histData.NameObject, "ERROR RemoveDataObjectInGrid", callFunc, nameField, "Conflict Name", dataObjDel, histData); * return; * } * } * * //ReaderScene.GetObjecsDataFromGrid(nameField).RemoveAt(index); * RemoveObjecDataGridByIndex(nameField, index); * * if (Storage.Log.IsSaveHistory) * { * if (histData == null) * { * Debug.Log("##################### Error RemoveDataObjectInGrid save SaveHistory histData == null "); * return; * } * Storage.Log.SaveHistory(histData.NameObject, "RemoveDataObjectInGrid", callFunc, nameField, "", histData, dataObjDel); * } * * if (Storage.Map.IsGridMap) * Storage.Map.CheckSector(nameField); * } */ public void RemoveDataObjectInGrid(ModelNPC.ObjectData dataObjDel = null) { string nameField = string.Empty; int index = -1; if (dataObjDel != null) { Helper.GetNameFieldByPosit(ref nameField, dataObjDel.Position); //---------- test ------ //var objs = ReaderScene.GetObjectsDataFromGrid(nameField); //index = objs.FindIndex(p => p.NameObject == dataObjDel.NameObject); //--------------------- index = ReaderScene.GetObjectsDataFromGrid(nameField).FindIndex(p => p.NameObject == dataObjDel.NameObject); //--------------------- if (index == -1) { Debug.Log("###################### RemoveDataObjectInGrid Data Del: " + dataObjDel.NameObject + " Data Find: " + dataObjDel.NameObject + " ... NOT find in Field: " + nameField); Storage.Log.SaveHistory(dataObjDel.NameObject, "ERROR RemoveDataObjectInGrid", "", nameField, "Conflict Name", dataObjDel, dataObjDel); return; } } RemoveObjecDataGridByIndex(nameField, index); if (Storage.Log.IsSaveHistory) { Storage.Log.SaveHistory(dataObjDel.NameObject, "RemoveDataObjectInGrid", "RemoveDataObjectInGrid", nameField, "", dataObjDel, dataObjDel); } if (Storage.Map.IsGridMap) { Storage.Map.CheckSector(nameField); } }
public void DrawLocationHero(bool isOpenChange = false) { if (!isOpenChange) { return; } if (IsOpen || isOpenChange) { Texture2D textureMap = prefabFrameMap.GetComponent <SpriteRenderer>().sprite.texture; Texture2D textureMapResult = textureMap; //Texture2D textureResult = new Texture2D(textureMap.width, textureMap.height); //Graphics.CopyTexture(textureMap, 0, 0, 0, 0, textureMap.width, textureMap.height, textureResult, 0, 0, 0, 0); //-- Restore --- if (Storage.Instance.SelectFieldPosHero != saveHeroPosField) { if (!string.IsNullOrEmpty(saveHeroPosField)) { SaveLoadData.TypePrefabs prefabType = SaveLoadData.TypePrefabs.PrefabField; string nameField = saveHeroPosField; if (ReaderScene.IsGridDataFieldExist(nameField)) { foreach (ModelNPC.ObjectData datObjItem in ReaderScene.GetObjectsDataFromGrid(nameField)) { if (datObjItem.TypePrefabName != SaveLoadData.TypePrefabs.PrefabUfo.ToString() && datObjItem.TypePrefabName != SaveLoadData.TypePrefabs.PrefabBoss.ToString()) { prefabType = (SaveLoadData.TypePrefabs)Enum.Parse(typeof(SaveLoadData.TypePrefabs), datObjItem.TypePrefabName); break; //@@@+ } } } Vector2 posF = Helper.GetPositByField(nameField); int x = (int)posF.x; int y = (int)posF.y; DrawTextureTo(SizeCellMap, "Restore", SizeCellMap - 1, textureMapResult, y, x, prefabType); } saveHeroPosField = Storage.Instance.SelectFieldPosHero; } //------ //@@@+ textureMapResult = AddTextureHeroOnMap(textureMapResult); //@@@- //Vector2 posHero = Helper.GetPositByField(Storage.Instance.SelectFieldPosHero); //int heroX = (int)posHero.x; //int heroY = (int)posHero.y; //DrawTextureTo(SizeCellMap, "Hero", SizeCellMap - 1, textureResult, heroY, heroX, Storage.Map.textureHero); textureMapResult.Apply(); Sprite spriteMe = Sprite.Create(textureMapResult, new Rect(0.0f, 0.0f, textureMapResult.width, textureMapResult.height), new Vector2(0.5f, 0.5f), 100.0f); prefabFrameMap.GetComponent <SpriteRenderer>().sprite = spriteMe; } }
private bool IsValidLargeLock(bool isFullTest = true) { //if (m_dataNPC.TargetID != null && temp_TargetID != m_dataNPC.TargetID && Storage.ReaderWorld.CollectionInfoID.ContainsKey(m_dataNPC.TargetID)) //if (m_dataNPC.TargetID != null && temp_TargetID != m_dataNPC.TargetID) //if (m_dataNPC.TargetID != null && temp_TargetID != m_dataNPC.TargetID) //if (m_dataNPC.TargetID != null && temp_TargetID != m_dataNPC.TargetID && Storage.ReaderWorld.CollectionInfoID.ContainsKey(m_dataNPC.TargetID)) bool isCheckLarge = false; bool isCheckTarget = true; if (!string.IsNullOrEmpty(m_dataNPC.TargetID) && Storage.Instance.ReaderSceneIsValid) { isCheckLarge = isCheckTarget = Storage.ReaderWorld.CollectionInfoID.ContainsKey(m_dataNPC.TargetID); } if (m_dataNPC.TargetID != null && temp_TargetID != m_dataNPC.TargetID && isCheckTarget) { if (isCheckLarge) { temp_isLargeBlock = !Storage.ReaderWorld.CollectionInfoID[m_dataNPC.TargetID].Data.IsFloor(); } else { temp_isLargeBlock = false; } temp_TargetID = m_dataNPC.TargetID; if (!temp_isLargeBlock) { string nameFiledTarget = Helper.GetNameField(m_dataNPC.TargetPosition); List <ModelNPC.ObjectData> objs = new List <ModelNPC.ObjectData>(); ReaderScene.GetObjectsDataFromGridTo(ref objs, nameFiledTarget); if (objs != null) { foreach (var item in objs) { if (!item.IsFloor()) { temp_isLargeBlock = true; break; } } } } //temp_isLargeBlock = false == Storage.ReaderWorld.CollectionInfoID[m_dataNPC.TargetID].Data.IsFloor(); } if (!isFullTest) { return(temp_isLargeBlock); } float distField = Vector2.Distance(new Vector2(m_dataNPC.TargetPosition.x, m_dataNPC.TargetPosition.y) , new Vector2(m_dataNPC.Position.x, m_dataNPC.Position.y)); return(temp_isLargeBlock || distField > 1); }
public void RemoveObjecDataGridByIndex(string nameField, int index) { temp_objsDeletes = ReaderScene.GetObjectsDataFromGrid(nameField); if (Storage.Instance.ReaderSceneIsValid) { temp_string = temp_objsDeletes[index].Id; Storage.ReaderWorld.RemoveObjectInfo(temp_string); } temp_objsDeletes.RemoveAt(index); temp_objsDeletes = null; }
public void ClearObjecsDataFromGrid(string nameField) { if (Storage.Instance.ReaderSceneIsValid) { foreach (var item in ReaderScene.GetObjectsDataFromGrid(nameField)) { Storage.ReaderWorld.RemoveObjectInfo(item.Id); } } ReaderScene.GetObjectsDataFromGrid(nameField).Clear(); }
public void SetObjecDataFromGrid(string nameField, int index, ModelNPC.ObjectData newData) { if (!ReaderScene.IsGridDataFieldExist(nameField)) { Storage.Data.AddNewFieldInGrid(nameField, "SetObjecDataFromGrid"); } ReaderScene.GetObjectsDataFromGrid(nameField)[index] = newData; if (Storage.Instance.ReaderSceneIsValid) { Storage.ReaderWorld.UpdateLinkData(newData, nameField, index); } }
public void SetTargetField_ObservableAlien(string p_field) { if (!ReaderSceneIsValid) { return; } var info = ReaderScene.GetObjectDataFromGridContinue(p_field, 0); if (info != null) { SetTargetID_ObservableAlien(info.Id); } }
public Texture2D DrawLocationHero(Texture2D textureResult) { //Texture2D textureResult = new Texture2D(textureMap.width, textureMap.height); //Graphics.CopyTexture(textureMap, 0, 0, 0, 0, textureMap.width, textureMap.height, textureResult, 0, 0, 0, 0); //-- Restore --- //if (Storage.Instance.SelectFieldPosHero != saveHeroPosField) //{ //Clear old position Hero if (!string.IsNullOrEmpty(saveHeroPosField)) { SaveLoadData.TypePrefabs prefabType = SaveLoadData.TypePrefabs.PrefabField; string nameField = saveHeroPosField; if (ReaderScene.IsGridDataFieldExist(nameField)) { foreach (ModelNPC.ObjectData datObjItem in ReaderScene.GetObjectsDataFromGrid(nameField)) { if (datObjItem.TypePrefabName != SaveLoadData.TypePrefabs.PrefabUfo.ToString() && datObjItem.TypePrefabName != SaveLoadData.TypePrefabs.PrefabBoss.ToString()) { prefabType = (SaveLoadData.TypePrefabs)Enum.Parse(typeof(SaveLoadData.TypePrefabs), datObjItem.TypePrefabName); } } } Vector2 posF = Helper.GetPositByField(nameField); int x = (int)posF.x; int y = (int)posF.y; DrawTextureTo(SizeCellMap, "Restore", SizeCellMap - 1, textureResult, y, x, prefabType); } saveHeroPosField = Storage.Instance.SelectFieldPosHero; //} //------ //@@@+ textureResult = AddTextureHeroOnMap(textureResult); //@@@- //Vector2 posHero = Helper.GetPositByField(Storage.Instance.SelectFieldPosHero); //int heroX = (int)posHero.x; //int heroY = (int)posHero.y; //DrawTextureTo(SizeCellMap, "Hero", SizeCellMap - 1, textureResult, heroY, heroX, Storage.Map.textureHero); return(textureResult); }
public static bool IsFreeFieldConstruct(int x = 0, int y = 0) { string nameField = Helper.GetNameField(x, y); List <ModelNPC.ObjectData> dataObjs = ReaderScene.GetObjectsDataFromGridContinue(nameField); if (dataObjs == null) { return(true); } foreach (ModelNPC.ObjectData itemData in dataObjs) { if (itemData.TypePoolPrefab != PoolGameObjects.TypePoolPrefabs.PoolFloor) { return(false); } } return(true); }
//public static bool IsFieldFree( // List<PoolGameObjects.TypePoolPrefabs> filretsIgnorType = null, // int x = 0, int y = 0) //{ // string nameField = Helper.GetNameField(x, y); // List<ModelNPC.ObjectData> dataObjs = ReaderScene.GetObjectsDataFromGridContinue(nameField); // foreach (ModelNPC.ObjectData itemData in dataObjs) // { // if (filretsIgnorType.Contains(itemData.TypePoolPrefab)) // { // return false; // } // } // return true; //} public static bool IsFreeFieldConstructBiom(int x, int y, TypesBiomNPC biomType) { string nameField = Helper.GetNameField(x, y); List <ModelNPC.ObjectData> dataObjs = ReaderScene.GetObjectsDataFromGridContinue(nameField); if (dataObjs == null) { return(true); } foreach (ModelNPC.ObjectData itemData in dataObjs) { if (Storage.GridData.GetPrefabsBioms[biomType].Contains(itemData.TypePrefab)) { return(false); } } return(true); }
public static bool IsFieldMe(int x, int y, SaveLoadData.TypePrefabs prefabMe) { string nameField = Helper.GetNameField(x, y); List <ModelNPC.ObjectData> dataObjs = ReaderScene.GetObjectsDataFromGridContinue(nameField); if (dataObjs == null) { return(false); } foreach (ModelNPC.ObjectData itemData in dataObjs) { if (itemData.TypePrefab == prefabMe) { return(true); } } return(false); }
public static void AddConstruction(ModelNPC.ObjectData spawnedBuild, ModelNPC.GameDataAlien alien) { if (string.IsNullOrEmpty(spawnedBuild.PortalId)) { Debug.Log(Storage.EventsUI.ListLogAdd = "### Portal AddConstruction = spawnedBuild.PortalId - is null"); return; } ModelNPC.PortalData portal = Storage.PortalsManager.Portals.Find(p => p.Id == spawnedBuild.PortalId); // info.Data as ModelNPC.PortalData; if (portal == null) { Debug.Log(Storage.EventsUI.ListLogAdd = "### Portal AddConstruction = Storage.PortalsManager.Portals - not found = " + spawnedBuild.PortalId); Storage.PortalsManager.SetHome(alien); spawnedBuild.PortalId = alien.PortalId; var info = ReaderScene.GetInfoID(spawnedBuild.PortalId); if (info == null) { Debug.Log(Storage.EventsUI.ListLogAdd = "### Portal AddConstruction = spawnedBuild.Id - not found = " + spawnedBuild.Id); } else { portal = info.Data as ModelNPC.PortalData; } } //%CLUSTER FILL if (spawnedBuild.IsFloor()) { Vector2Int posField = Helper.GetFieldPositByWorldPosit(spawnedBuild.Position); int clusterFill = AlienJobsManager.GetClusterSize(posField.x, posField.y, spawnedBuild.TypePrefab); (spawnedBuild as ModelNPC.TerraData).ClusterFillSize = clusterFill; (spawnedBuild as ModelNPC.TerraData).DataCreate = DateTime.Now; } if (portal != null) { portal.AddConstruction(spawnedBuild.TypePrefab, spawnedBuild.Id); } else { Debug.Log(Storage.EventsUI.ListLogAdd = "### Portal AddConstruction = portal is null"); } }
public Vector3 SearchParking(ref string nameField) { List <ObjectData> dataObjs; int x = 0; int y = 0; Helper.GetFieldPositByWorldPosit(ref x, ref y, Position); List <Vector2Int> findedFileds = new List <Vector2Int>(); Helper.GetSpiralFields(ref findedFileds, x, y, 20); foreach (Vector2Int fieldNext in findedFileds) { Helper.GetNameField_Cache(ref nameField, fieldNext.x, fieldNext.y); if (ReaderScene.IsFieldFree(nameField)) { return(Helper.NormalizFieldToWorld(fieldNext)); } } return(Vector3.zero); }
private bool IsFreeLocationPortalConstruction( ref Dictionary <Vector2Int, bool> excludedFreeFileds, int x, int y, int lenSize, SaveLoadData.TypePrefabs buildType, ModelNPC.PortalData portal) { ReaderScene.DataObjectInfoID infoNext; Vector2 requestPosition = new Vector2(x, y); Vector2 biuldPosition; int portaBuildingyardSize = 2; List <string> bouldingId; portal.ConstructionsId.TryGetValue(buildType, out bouldingId); if (bouldingId == null) { return(true); } biuldPosition = Helper.GetFieldPositByWorldPosit(portal.Position); if (Vector3.Distance(requestPosition, biuldPosition) < portaBuildingyardSize) { return(false); } foreach (var nextID in bouldingId) { infoNext = ReaderScene.GetInfoID(nextID); if (infoNext == null || infoNext.Data == null) { continue; } biuldPosition = Helper.GetFieldPositByWorldPosit(infoNext.Data.Position); if (Vector3.Distance(requestPosition, biuldPosition) < lenSize) { return(false); } } return(true); }
public bool ChildrenPreparationIncubation() { string id; int fieldX_NPC = 0; int fieldY_NPC = 0; int fieldX_Portal = 0; int fieldY_Portal = 0; bool isParkingLock = false; Helper.GetFieldPositByWorldPosit(ref fieldX_Portal, ref fieldY_Portal, Position); if (!Storage.Instance.ReaderSceneIsValid) { return(false); } for (int i = ChildrensId.Count - 1; i >= 0; i--) { id = ChildrensId[i]; var dataNPC = ReaderScene.GetInfoID(id); if (dataNPC == null) { ChildrensId.RemoveAt(i); } else { Helper.GetFieldPositByWorldPosit(ref fieldX_NPC, ref fieldY_NPC, dataNPC.Data.Position); isParkingLock = fieldX_NPC == fieldX_Portal && fieldY_NPC == fieldY_Portal; if (isParkingLock) { return(false); } } } if (ChildrensId.Count == 0) { return(true); } return(true); }
//public static void IsMeCluster(ref bool result, int x, int y, SaveLoadData.TypePrefabs resourceResult, int ClusterSize = 0) //{ // int countClusterObjects = 0; // for (int stepX = -1; stepX < 2; stepX ++) // { // for (int stepY = -1; stepY < 2; stepY++) // { // result = IsFieldMe(x + stepX, y + stepY, resourceResult); // if (result) // { // if(countClusterObjects >= ClusterSize) // return; // countClusterObjects++; // } // } // } //} //public static bool IsFilledLocationConstruction(int x, int y) //{ // return false; //} //List<PoolGameObjects.TypePoolPrefabs> filretsIgnorType = null) /* * public static bool IsFreeLocationConstruction( * ref Dictionary<Vector2Int, bool> excludedFreeFileds, * int x, int y, * int lenSnake, * TypesBiomNPC biomType * ) * * { * temp_spatal.indexSingle = 0; * temp_spatal._single = 1; * temp_spatal.limitInvertSingle = 1; * temp_spatal.indexFileds = 0; * temp_spatal.isValid = true; // !isTestZonaWorls; * temp_spatal.index = 0; * temp_spatal.nextF = 0; * temp_spatal.Order = 0; * temp_spatal.StartX = x; * temp_spatal.StartY = y; * if (lenSnake == 0) * lenSnake = 40; * * for (temp_spatal.index = 0; temp_spatal.index < 20; temp_spatal.index++) * { * //X * for (temp_spatal.nextF = 0; temp_spatal.nextF < temp_spatal.index; temp_spatal.nextF++) * { * x += temp_spatal._single; * temp_spatal.isValid = true; * if (temp_spatal.isValid) * { * temp_spatal.testPosit = new Vector2Int(x, y); * //already tested on free * if (IsNotInListFree(temp_spatal.testPosit, excludedFreeFileds)) * { * //test on free * if (IsFreeFieldConstructBiom(x, y, biomType) == false) * return false; * AddExcludeFreeFiled(temp_spatal.testPosit, excludedFreeFileds); * } * temp_spatal.indexFileds++; * } * temp_spatal.indexSingle++; * if (temp_spatal.indexFileds > lenSnake) * return true; * if (temp_spatal.indexSingle >= temp_spatal.limitInvertSingle) * { * temp_spatal.limitInvertSingle += 2; * temp_spatal.indexSingle = 0; * temp_spatal._single *= -1; * } * } * //Y * for (temp_spatal.nextF = 0; temp_spatal.nextF < temp_spatal.index; temp_spatal.nextF++) * { * y += temp_spatal._single; * temp_spatal.isValid = true; * * if (temp_spatal.isValid) * { * temp_spatal.testPosit = new Vector2Int(x, y); * * //already tested on free * if (IsNotInListFree(temp_spatal.testPosit, excludedFreeFileds)) * { * //test on free * if (IsFreeFieldConstructBiom(x, y, biomType) == false) * return false; * AddExcludeFreeFiled(temp_spatal.testPosit, excludedFreeFileds); * } * temp_spatal.indexFileds++; * } * temp_spatal.indexSingle++; * if (temp_spatal.indexFileds > lenSnake) * return true; * if (temp_spatal.indexSingle >= temp_spatal.limitInvertSingle) * { * temp_spatal.limitInvertSingle += 2; * temp_spatal.indexSingle = 0; * temp_spatal._single *= -1; * } * } * } * * return true; * } */ public static bool FilterData( ref ModelNPC.ObjectData findedData, List <PoolGameObjects.TypePoolPrefabs> filretsIgnorType = null, SaveLoadData.TypePrefabs findType = SaveLoadData.TypePrefabs.PrefabField, int x = 0, int y = 0) { string nameField = Helper.GetNameField(x, y); List <ModelNPC.ObjectData> dataObjs = ReaderScene.GetObjectsDataFromGridContinue(nameField); foreach (ModelNPC.ObjectData itemData in dataObjs) { if (filretsIgnorType.Contains(itemData.TypePoolPrefab)) { findedData = null; break; } else if (itemData.TypePrefab == findType) { findedData = itemData; } } return(true); }
public bool RemoveAllFindDataObject(string nameObj) { //Debug.Log("+++++ RemoveAllFindDataObject +++ start :" + nameObj); bool isRemoved = false; string idObj = Helper.GetID(nameObj); //Debug.Log("+++++ RemoveAllFindDataObject +++ start :" + idObj); //-----------------------FIXED Correct foreach (var item in _GridDataG.FieldsD) { string nameField = item.Key; List <ModelNPC.ObjectData> resListData = ReaderScene.GetObjectsDataFromGrid(nameField).Where(p => { return(p.NameObject.IndexOf(idObj) != -1); }).ToList(); if (resListData != null) { var resListDataTest = ReaderScene.GetObjectsDataFromGrid(nameField).Where(p => { return(p.NameObject.IndexOf(idObj) != -1); }); if (resListDataTest.Count() != resListData.Count()) { Debug.Log("+++++ RemoveAllFindDataObject: resListDataTest.Count(" + resListDataTest.Count() + ") != resListData.Count(" + resListData.Count() + ")"); } //foreach (var obj in resListData) for (int i = 0; i < resListData.Count(); i++) { var obj = resListData[i]; if (obj == null) { Debug.Log("+++++ CORRECT ++++ DELETE (" + idObj + ") >>>> in DATA Object Fields: " + nameField + " obj is null"); continue; } Debug.Log("+++++ CORRECT ++++ DELETE (" + idObj + ") >>>> in DATA Object Fields: " + nameField + " obj=" + obj); RemoveDataObjectInGrid(nameField, i, "NextPosition"); isRemoved = true; } } } return(isRemoved); }
//@DESTROY@ public bool DestroyFullObject(GameObject gObj, bool isCorrect = false, bool isStopReal = false) //???? isStopReal { if (gObj == null) { Debug.Log("+++ DestroyFullObject ++++ object is null"); return(false); } //if (isCorrect) // Debug.Log("++++++++++++ DestroyFullObject ++++ : " + gObj); string setName = gObj.name; string nameField = Helper.GetNameFieldByName(setName); if (nameField == null) { return(false); } bool isExistReal = true; if (!_GamesObjectsReal.ContainsKey(nameField)) { isExistReal = false; if (isStopReal) { Debug.Log("####### DestroyFullObject not field : " + nameField); return(false); } } if (isExistReal) { List <GameObject> listObjInField = _GamesObjectsReal[nameField]; for (int i = listObjInField.Count - 1; i >= 0; i--) { if (listObjInField[i] == null) { _UpdateData.RemoveRealObject(i, nameField, "DestroyRealObject"); } } if (listObjInField.Count > 0) { int indRealData = listObjInField.FindIndex(p => p.name == setName); if (indRealData == -1) { Debug.Log("+++ ------ DestroyFullObject: ------ Hero destroy >>> Not find GamesObjectsReal : " + gObj.name); } else { _UpdateData.RemoveRealObject(indRealData, nameField, "DestroyRealObject"); } } } bool isDestroyOnBild = false; if (gObj != null) { if (PoolGameObjects.IsUsePoolObjects) { var evObj = gObj.GetComponent <EventsObject>(); if (evObj != null && evObj.PoolCase.IsDesrtoy) //Replace Data on Construct when Paint Prafab { isDestroyOnBild = true; } } //@@@- //Destroy(gObj); //@@@+ gObj.GetEvent().PoolCase.Deactivate();// .IsDesrtoy = true; } else { Debug.Log("+++ DestroyFullObject ++++ Destroy ---- object is null"); } KillObjectHistory.Add(setName); //++ history //----------------------------------------------- bool isRemovedCorrect = false; bool isRemReal = false; bool isRemData = false; if (isCorrect) { isRemReal = _UpdateData.RemoveAllFindRealObject(setName); } //Destroy to Data if (false == ReaderScene.IsGridDataFieldExist(nameField)) { Debug.Log("+++++ ------- DestroyRealObject ----- !GridData.FieldsD not field=" + nameField); return(false); } List <ModelNPC.ObjectData> dataObjects = ReaderScene.GetObjectsDataFromGrid(nameField); int indObj = dataObjects.FindIndex(p => p.NameObject == gObj.name); if (!isCorrect) { if (indObj != -1) { //Destroy to Data _UpdateData.RemoveDataObjectInGrid(nameField, indObj, "DestroyRealObject"); } else { if (!isDestroyOnBild) { Debug.Log("!!!! ObjectData GridData not object=" + gObj.name); //RemoveAllFindRealObject(gObj.name); _UpdateData.RemoveAllFindDataObject(gObj.name); } } } else { if (indObj != -1) { //@DD@ dataObjects.RemoveAt(indObj); _UpdateData.RemoveDataObjectInGrid(nameField, indObj, "DestroyRealObject"); } isRemData = _UpdateData.RemoveAllFindDataObject(setName); } if (isRemData || isRemReal) { isRemovedCorrect = true; } return(isRemovedCorrect); }
public void InitCollectionID() { m_ReaderWorld = new ReaderScene(); }
public static void FindFromLocation_Cache(ref ModelNPC.ObjectData result, ModelNPC.ObjectData data, int distantion) { dataAlien_FindFromLocation_Cache = data as ModelNPC.GameDataAlien; GetFieldPositByWorldPosit(ref posFieldInt_FindFromLocation_X, ref posFieldInt_FindFromLocation_Y, data.Position.x, data.Position.y); result = ReaderScene.GetDataInfoLocation(posFieldInt_FindFromLocation_X, posFieldInt_FindFromLocation_Y, distantion, data.Id, data.TypePrefab, dataAlien_FindFromLocation_Cache.PrevousTargetID, false).ResultData; }
IEnumerator StartLoadDataBigXML() { string stepErr = "start"; Debug.Log("Loaded Xml GridData start..."); Dictionary <string, ModelNPC.FieldData> fieldsD_Test = new Dictionary <string, ModelNPC.FieldData>(); yield return(null); LoadingWordlTimer = Time.time; string nameField = ""; stepErr = "c.1"; string datapathPart = Application.dataPath + "/Levels/LevelDataPart1x2.xml"; if (File.Exists(datapathPart)) { int indProgress = 0; int limitUpdate = 20; //using (XmlReader xml = XmlReader.Create(stReader)) using (XmlReader xml = XmlReader.Create(datapathPart)) //using (XmlReader xml = XmlReader.Create(new StreamReader(datapathPart, System.Text.Encoding.UTF8))) { while (xml.Read()) { switch (xml.NodeType) { case XmlNodeType.Element: if (xml.Name == "Key") { XElement el = XElement.ReadFrom(xml) as XElement; nameField = el.Value; //nameField = xml.Value.Clone().ToString(); break; } //if (xml.Name == "Objects") if (xml.Name == "ObjectData") //WWW { indProgress++; if (indProgress > limitUpdate) { indProgress = 0; yield return(null); } XElement el = XElement.ReadFrom(xml) as XElement; string inputString = el.ToString(); //--------------- //XmlSerializer serializer = new XmlSerializer(typeof(List<ModelNPC.ObjectData>), Serializator.extraTypes); //WWW XmlSerializer serializer = new XmlSerializer(typeof(ModelNPC.ObjectData), Serializator.extraTypes); //-------------- StringReader stringReader = new StringReader(inputString); //stringReader.Read(); // skip BOM //-------------- //List<KeyValuePair<string, ModelNPC.FieldData>> dataResult = (List<KeyValuePair<string, ModelNPC.FieldData>>)serializer.Deserialize(rdr); //Debug.Log("! " + inputString); //List<ModelNPC.ObjectData> dataResult; ModelNPC.ObjectData dataResult; try { dataResult = (ModelNPC.ObjectData)serializer.Deserialize(stringReader); } catch (Exception x) { Debug.Log("############# " + x.Message); yield break; } //------------------------- if (ReaderScene.IsGridDataFieldExist(nameField)) { fieldsD_Test[nameField].Objects.Add(dataResult); } else { //_GridDataG.FieldsD.Add(nameField, new ModelNPC.FieldData() //{ // NameField = nameField, // Objects = new List<ModelNPC.ObjectData>() { dataResult } //}); fieldsD_Test.Add(nameField, new ModelNPC.FieldData() { NameField = nameField, Objects = new List <ModelNPC.ObjectData>() { dataResult } }); } } break; } } } //xml.Close(); //stReader.Close(); } //------------ Storage.Data.SetGridDatatBig = fieldsD_Test; yield return(null); Storage.Data.CompletedLoadWorld();//fieldsD_Temp //-------------- float loadingTime = Time.time - LoadingWordlTimer; Storage.EventsUI.SetMessageBox = "Ты ждал: " + loadingTime; yield return(new WaitForSeconds(4f)); Storage.EventsUI.HideMessage(); }
public static void FindFromLocationType_Cache(ref ModelNPC.ObjectData result, SaveLoadData.TypePrefabs typeRequested, Vector3 posRequested, int distantion, bool isFoor) { GetFieldPositByWorldPosit(ref posFieldInt_FindFromLocation_X, ref posFieldInt_FindFromLocation_Y, posRequested.x, posRequested.y); result = ReaderScene.GetDataInfoLocation(posFieldInt_FindFromLocation_X, posFieldInt_FindFromLocation_Y, distantion, string.Empty, typeRequested, string.Empty, isFoor).ResultData; }
public static ModelNPC.ObjectData FindFromLocationType(SaveLoadData.TypePrefabs typeRequested, Vector3 posRequested, int distantion, bool isFoor) { GetFieldPositByWorldPosit(ref posFieldInt_FindFromLocation_X, ref posFieldInt_FindFromLocation_Y, posRequested.x, posRequested.y); ReaderScene.DataInfoFinder finder = ReaderScene.GetDataInfoLocation(posFieldInt_FindFromLocation_X, posFieldInt_FindFromLocation_Y, distantion, string.Empty, typeRequested, string.Empty, isFoor); return(finder.ResultData); }
public void InitDialogView(SceneDebuger.CaseSceneDialogPerson p_caseDialogPerson, ModeInfo p_mode = ModeInfo.Person) { if (DialogIcon == null) { return; } var data = p_caseDialogPerson.Person.Data; if (p_mode == ModeInfo.Person) { CaseDialogPerson = p_caseDialogPerson; string modelView = data.ModelView; if (modelView == null) { modelView = data.TypePrefab.ToString(); } if (!Storage.Palette.SpritesPrefabs.ContainsKey(modelView)) { Debug.Log(Storage.EventsUI.ListLogAdd = "#### InitDialogView Not found modelView = " + modelView); DialogIcon.GetComponent <SpriteRenderer>().sprite = null; } else { Sprite spriteGobject = Storage.Palette.SpritesPrefabs[modelView]; DialogIcon.GetComponent <SpriteRenderer>().sprite = spriteGobject; } string spriteNameAction = "ActionIcon" + data.CurrentAction.ToString(); //"ActionIconMove" if (!Storage.Palette.SpritesUI.ContainsKey(spriteNameAction)) { Debug.Log(Storage.EventsUI.ListLogAdd = "#### InitDialogView Not found spriteNameAction = " + spriteNameAction); DialogIconAction.GetComponent <SpriteRenderer>().sprite = null; } else { Sprite spriteAction = Storage.Palette.SpritesUI[spriteNameAction]; DialogIconAction.GetComponent <SpriteRenderer>().sprite = spriteAction; } string fieldTarget = Helper.GetNameFieldPosit(data.TargetPosition.x, data.TargetPosition.y); if (fieldTarget == null) { Debug.Log(Storage.EventsUI.ListLogAdd = "#### fieldTarget is null "); return; } var objectsGrid = ReaderScene.GetObjectsDataFromGridContinue(fieldTarget); if (objectsGrid != null) { //Debug.Log(Storage.EventsUI.ListLogAdd = "#### objectsGrid is null from " + fieldTarget); //return; foreach (var objData in objectsGrid) { if (objData == null) { Storage.EventsUI.ListLogAdd = "### TARGET ReaderScene NOT FIELD: " + fieldTarget; continue; } string modelViewTarget = objData.ModelView; if (modelViewTarget == null) { modelViewTarget = objData.TypePrefabName; } if (modelViewTarget == null) { Debug.Log(Storage.EventsUI.ListLogAdd = "#### InitDialogView Not found modelViewTarget is null >> " + objData.NameObject); continue; } if (!Storage.Palette.SpritesPrefabs.ContainsKey(modelViewTarget)) { Debug.Log(Storage.EventsUI.ListLogAdd = "#### InitDialogView Not found modelViewTarget = " + modelViewTarget); DialogIconTarget.GetComponent <SpriteRenderer>().sprite = null; } else { Sprite spriteTarget = Storage.Palette.SpritesPrefabs[modelViewTarget]; DialogIconTarget.GetComponent <SpriteRenderer>().sprite = spriteTarget; if (p_caseDialogPerson.Person.Data != null) { if (CaseDialogTarget != null && CaseDialogTarget.IsLock && CaseDialogTarget.Person != null && CaseDialogTarget.Person.ID == p_caseDialogPerson.Person.ID) { Storage.SceneDebug.UpdateTargetDialog(CaseDialogTarget, p_caseDialogPerson.Person, modelViewTarget); } else { CaseDialogTarget = Storage.SceneDebug.CreateTargetDialog(p_caseDialogPerson.Person, modelViewTarget); } DrawRayTarget(); //!!!!!!!!!!!!!!!!!!!!!! } else { Debug.Log(Storage.EventsUI.ListLogAdd = "#### InitDialogView Not found p_caseDialogPerson.Person.Data is null >> " + p_caseDialogPerson.Person.ID); } break; } } } } else { CaseDialogPerson = p_caseDialogPerson; DialogIcon.GetComponent <SpriteRenderer>().sprite = Storage.Palette.SpritesPrefabs[DialogModelViewTarget]; } m_info = data.NameObject; SetMode(p_mode); }
/* * public static bool CheckJobAlien(ModelNPC.GameDataAlien p_dataNPC, GameActionPersonController controller = null) * { * AlienJob job = p_dataNPC.Job; * if (job != null) * { * string fieldAlien = string.Empty; * string fieldTarget = string.Empty; * Helper.GetNameFieldByPosit(ref fieldAlien, p_dataNPC.Position); * SaveLoadData.TypePrefabs jobResourceTarget = job.TargetResource; * //Target object * ReaderScene.DataObjectInfoID targetInfo = ReaderScene.GetInfoID(p_dataNPC.TargetID); * if (targetInfo != null) * { * if (!targetInfo.TestIsValud()) * { * p_dataNPC.TargetID = null; * } * else * { * int distField = 0; * Helper.GetDistatntionFields(ref distField, targetInfo.Data.Position, p_dataNPC.Position); * Helper.GetNameFieldByPosit(ref fieldTarget, targetInfo.Data.Position); * * ModelNPC.PortalData portal = targetInfo.Data as ModelNPC.PortalData; * if (distField < 2) * { * bool isExitTargetResource = false; * 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) * { * //if (!job.IsJobCompleted && !job.IsJobRun) * //if (p_dataNPC.CurrentAction == GameActionPersonController.NameActionsPerson.Target.ToString()) * //p_dataNPC.CurrentAction != GameActionPersonController.NameActionsPerson.Work.ToString()) * if (p_dataNPC.CurrentAction != GameActionPersonController.NameActionsPerson.CompletedLoot.ToString() && * p_dataNPC.CurrentAction != GameActionPersonController.NameActionsPerson.Work.ToString()) * { * //job.IsJobRun = true; * //p_dataNPC.CurrentAction = GameActionPersonController.NameActionsPerson.Target.ToString(); * //GameActionPersonController.RequestActionNPC(p_dataNPC, GameActionPersonController.NameActionsPerson.Work, null); * GameActionPersonController.ExecuteActionNPC(p_dataNPC, GameActionPersonController.NameActionsPerson.Work, controller, true); * } * //if(job.IsJobCompleted) * 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; * } * } * //p_dataNPC.CurrentAction = GameActionPersonController.NameActionsPerson.Target.ToString(); * 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) * { * bool isTestMe = false; * 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; * isTestMe = true; * } * * //Storage.GenWorld.GenericPrefabOnWorld(job.ResourceResult, posTarget); * 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); * } * bool isZonaReal = Helper.IsValidPiontInZona(targetInfo.Data.Position.x, targetInfo.Data.Position.y); * //if (!targetInfo.Data.IsReality && isZonaReal) * 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; * } */ public static void GetAlienNextTargetObject(ref ModelNPC.ObjectData result, ref AlienJob job, ModelNPC.GameDataAlien dataAlien) { int versionSearching = 2;// 1; //@JOB@ if (Storage.Person.PersonPriority == null) { Storage.EventsUI.ListLogAdd = "### GetAlienNextTargetObject >> PersonPriority is null"; Storage.Person.LoadPriorityPerson(); result = null; return; } if (dataAlien == null) { Storage.EventsUI.ListLogAdd = "### GetAlienNextTargetObject >> dataAlien is null"; result = null; return; } //m_prioritysGet = PersonPriority[dataAlien.TypePrefab]; //int distantionFind = UnityEngine.Random.Range(2, 15); //v.1 if (versionSearching == 1) { //result = FindFromLocation(dataAlien.Position, distantionFind, prioritys, dataAlien.Id, dataAlien.TypePrefab); //result = Helper.FindFromLocation(dataAlien, distantionFind); temp_distantionFind = UnityEngine.Random.Range(2, 15); Helper.FindFromLocation_Cache(ref result, dataAlien, temp_distantionFind); } else //v.3 { if (job != null) { //fix job bool isCompletedMission = job != null && dataAlien.Inventory != null && dataAlien.Inventory.NameInventopyObject == job.TargetResource.ToString(); switch (job.JobTo) { case TypesJobTo.ToPortal: if (isCompletedMission) { if (dataAlien.PortalId == null) { Storage.PortalsManager.SetHome(dataAlien); } var info = ReaderScene.GetInfoID(dataAlien.PortalId); if (info != null) { result = info.Data; } } break; default: job = null; break; } } if (result == null) { temp_distantionFind = UnityEngine.Random.Range(2, 150); if (dataAlien.Inventory != null && !dataAlien.Inventory.IsEmpty && dataAlien.Inventory.TypeInventoryObject.IsPrefab())//FIX%CLUSTER { Storage.PortalsManager.FindJobBuildLocation(ref result, ref job, dataAlien, temp_distantionFind); } if (result == null) { CeckJobPass(ref result, dataAlien); if (result == null) { Storage.Person.FindJobResouceLocation(ref result, ref job, dataAlien, temp_distantionFind); } } if (result == null) { temp_distantionFind = UnityEngine.Random.Range(2, 25);//15 Helper.FindFromLocation_Cache(ref result, dataAlien, temp_distantionFind); } } } //v.2 //if (versionSearching == 2) //{ // string fieldName = Helper.GetNameFieldPosit(dataAlien.Position.x, dataAlien.Position.y); // Vector2 posField = Helper.GetPositByField(fieldName); // Vector2Int posFieldInt = new Vector2Int((int)posField.x, (int)posField.y); // ReaderScene.DataInfoFinder finder = ReaderScene.GetDataInfoLocationFromID((int)posFieldInt.x, (int)posFieldInt.y, distantionFind, dataAlien.TypePrefab, dataAlien.Id); }
public void FindJobBuildLocation(ref ModelNPC.ObjectData result, ref AlienJob job, ModelNPC.GameDataAlien dataAien, int distantionWay) { if (!Storage.Person.CollectionAlienJob.ContainsKey(dataAien.TypePrefab)) { return; } ReaderScene.DataObjectInfoID info; ModelNPC.PortalData portal = null; List <string> listId; TypesBiomNPC biomType = Helper.GetBiomByTypeModel(dataAien.TypePrefab); SaveLoadData.TypePrefabs floorType = PortalBiomFloorsBase[biomType]; result = null; if (string.IsNullOrEmpty(dataAien.PortalId)) { return; } info = ReaderScene.GetInfoID(dataAien.PortalId); if (info == null) { return; } portal = info.Data as ModelNPC.PortalData; portal.ConstructionsId.TryGetValue(floorType, out listId); if (listId == null) { return; } List <AlienJob> jobs = null; Vector2Int test_fieldPos = Vector2Int.zero; Vector2Int keyField; int x = 0; int y = 0; string nameField = string.Empty; string key = string.Empty; bool isFieldJobValid = true; bool isValidFieldBuildFar = true; bool isValidFar = true; bool isInventoryContainTargetResource = false; temp_excludedFreeFileds.Clear(); //Get jobs Storage.Person.CollectionAlienJob.TryGetValue(dataAien.TypePrefab, out jobs); Helper.GetFieldPositByWorldPosit(ref x, ref y, dataAien.Position); temp_findedFloorsIdForBuild.Clear(); //Fill floors portal for building System.Random rnd = new System.Random(); temp_findedFloorsIdForBuild = listId.OrderBy(p => rnd.Next()).ToList(); List <ModelNPC.TerraData> floorsData = new List <ModelNPC.TerraData>(); foreach (string nextRndID in temp_findedFloorsIdForBuild) { info = ReaderScene.GetInfoID(nextRndID); if (info == null) { continue; } if (!(info.Data is ModelNPC.TerraData)) { continue; } floorsData.Add(info.Data as ModelNPC.TerraData); } //Floors portal foreach (ModelNPC.TerraData floorData in floorsData.OrderBy(p => p.ClusterFillSize)) { isValidFieldBuildFar = true; isFieldJobValid = true; keyField = Helper.GetFieldPositByWorldPosit(floorData.Position); //Select job by target resource foreach (AlienJob jobItem in jobs.Where(p => p.TargetResource == floorData.TypePrefab)) //fix all jobs for type Resource { job = jobItem; if (job != null) { if (job.Job != TypesJobs.Build) { continue; } // Test field on free PoolGameObjects.TypePoolPrefabs typePoolResult = AlienJobsManager.CheckFieldJobValid(ref isFieldJobValid, job, floorData); //Filter: Build switch (job.Job) { case TypesJobs.Build: isValidFar = false; //Test inventory filled isInventoryContainTargetResource = dataAien.Inventory != null && dataAien.Inventory.EqualsInv(job.ResourceResult); if (!isInventoryContainTargetResource) { isValidFar = false; } else if (typePoolResult == PoolGameObjects.TypePoolPrefabs.PoolFloor) { //test near objects type of me (Cluster) //AlienJobsManager.IsMeCluster(ref isValidFar, keyField.x, keyField.y, job.ResourceResult, job.ClusterSize); job = null; continue; } else { //Build Prefab if (isValidFieldBuildFar) //Test Free location { //isValidFieldBuildFar = IsFreeLocationPortalConstruction(ref temp_excludedFreeFileds, // keyField.x, keyField.y, job.BuildingyardSize, dataAien.Inventory.TypePrefabObject, portal); //TypesBiomNPC isValidFieldBuildFar = IsFreeLocationPortalConstruction(ref temp_excludedFreeFileds, keyField.x, keyField.y, job.BuildingyardSize, job.ResourceResult, portal); //TypesBiomNPC } isValidFar = isValidFieldBuildFar; } if (!isValidFar || !isFieldJobValid) { job = null; continue; } break; } result = floorData; return; } } } temp_findedFloorsIdForBuild.Clear(); dataAien.JobPass = 0; job = null; }