private int[] GetPassGridIndexs(int targetGridIndex) { FarmRoot instance = FarmRoot.Instance; FarmField field = instance.Field; FarmGrid.GridPosition gridPosition = field.Grid.GetGridPosition(base.transform.localPosition); int gridIndex = field.Grid.GetGridIndex(gridPosition); List <FarmDigimonUtility.PathInfo> path = FarmDigimonUtility.GetPath(gridIndex, targetGridIndex); if (path != null) { FarmDigimonUtility.PathInfo pathInfo = path.SingleOrDefault((FarmDigimonUtility.PathInfo x) => x.gridIndex == targetGridIndex); int startGridIndex = pathInfo.gridIndex; int num = pathInfo.checkPoint - 1; List <int> list = new List <int>(); while (0 <= num && this.ChoosePath(field.Grid, path, startGridIndex, num, list)) { num--; startGridIndex = list.Last <int>(); } if (0 < list.Count) { return(list.ToArray()); } } return(null); }
public IEnumerator AppearanceNormal(GameObject digimon, Action completed) { FarmRoot farmRoot = FarmRoot.Instance; FarmField farmField = farmRoot.Field; int gridIndex = FarmDigimonUtility.GetPassableGridIndex(); if (gridIndex == -1) { digimon.SetActive(false); } else { base.transform.position = farmField.Grid.GetPositionGridCenter(gridIndex, false); base.transform.localScale = Vector3.zero; base.transform.localRotation = Quaternion.identity; Vector3 angles = base.transform.localEulerAngles; angles.y = farmRoot.Camera.transform.localEulerAngles.y + 180f; base.transform.localEulerAngles = angles; float scale = 0.99f; while (1f > scale) { scale += Time.deltaTime; scale = Mathf.Clamp01(scale); float adjScale = scale * 2f; base.transform.localScale = new Vector3(adjScale, adjScale, adjScale); yield return(null); } } if (completed != null) { completed(); } yield break; }
private static void CheckAroundGrids(FarmGrid farmGrid, List <FarmGrid.Grid> fieldGrids, int centerGridIndex, List <int> aroundGridIndexs, bool isIgnorePutedFlag) { FarmGrid.GridPosition gridPosition = farmGrid.IndexToPosition(centerGridIndex); int num = FarmDigimonUtility.CheckGrid(farmGrid, fieldGrids, gridPosition.x, gridPosition.y - 1, isIgnorePutedFlag); if (num != -1) { aroundGridIndexs.Add(num); } num = FarmDigimonUtility.CheckGrid(farmGrid, fieldGrids, gridPosition.x, gridPosition.y + 1, isIgnorePutedFlag); if (num != -1) { aroundGridIndexs.Add(num); } num = FarmDigimonUtility.CheckGrid(farmGrid, fieldGrids, gridPosition.x - 1, gridPosition.y, isIgnorePutedFlag); if (num != -1) { aroundGridIndexs.Add(num); } num = FarmDigimonUtility.CheckGrid(farmGrid, fieldGrids, gridPosition.x + 1, gridPosition.y, isIgnorePutedFlag); if (num != -1) { aroundGridIndexs.Add(num); } }
private bool ChoosePath(FarmGrid farmGrid, List <FarmDigimonUtility.PathInfo> path, int startGridIndex, int targetPathCount, List <int> choosePath) { FarmDigimonUtility.PathInfo[] array = path.Where((FarmDigimonUtility.PathInfo x) => x.checkPoint == targetPathCount).ToArray <FarmDigimonUtility.PathInfo>(); if (array != null) { List <int> list = new List <int>(); if (FarmDigimonUtility.GetAroundGridIndexsForPath(farmGrid, startGridIndex, array, list)) { choosePath.Add(list[0]); return(true); } } return(false); }
private int GetConstructionAroundGridIndex() { FarmRoot instance = FarmRoot.Instance; FarmScenery scenery = instance.Scenery; FarmObject[] array = scenery.farmObjects.Where((FarmObject x) => x.IsConstruction()).ToArray <FarmObject>(); if (array != null && 0 < array.Length) { int num = UnityEngine.Random.Range(0, array.Length); FarmObject farmObject = array[num]; return(FarmDigimonUtility.ChooseAroundGridIndex(farmObject)); } return(-1); }
public static int ChooseAroundGridIndex(FarmObject farmObject) { FarmRoot instance = FarmRoot.Instance; FarmField field = instance.Field; FarmGrid.GridPosition gridPosition = field.Grid.GetGridPosition(farmObject.transform.localPosition); int[] gridIndexs = farmObject.GetGridIndexs(field.GetField(), field.Grid.GetGridIndex(gridPosition)); int[] aroundGridIndexs = FarmDigimonUtility.GetAroundGridIndexs(gridIndexs); int[] passableGridIndexs = field.Grid.GetPassableGridIndexs(aroundGridIndexs); if (0 < passableGridIndexs.Length) { int num = UnityEngine.Random.Range(0, passableGridIndexs.Length); return(passableGridIndexs[num]); } return(-1); }
public void CreateActionParam(FarmDigimonAI.ActionID actionID) { switch (actionID) { case FarmDigimonAI.ActionID.MEAT_FARM: this.actionParam.targetGridIndex = this.GetMeatFarmAroundGridIndex(); break; case FarmDigimonAI.ActionID.STROLL: case FarmDigimonAI.ActionID.STROLL_FAST: this.actionParam.targetGridIndex = FarmDigimonUtility.GetPassableGridIndex(); break; case FarmDigimonAI.ActionID.CONSTRUCTION: this.actionParam.targetGridIndex = this.GetConstructionAroundGridIndex(); break; } this.actionParam.actionID = actionID; if (this.actionParam.targetGridIndex != -1) { this.actionParam.pathGridIndexs = this.GetPassGridIndexs(this.actionParam.targetGridIndex); } }
public static List <FarmDigimonUtility.PathInfo> GetPath(int startGridIndex, int endGridIndex) { FarmRoot instance = FarmRoot.Instance; FarmField field = instance.Field; List <FarmGrid.Grid> grids = instance.Field.GetField().grids; bool[] array = new bool[grids.Count]; List <FarmDigimonUtility.PathInfo> list = new List <FarmDigimonUtility.PathInfo>(); int num = 0; List <int> list2 = new List <int>(); List <int> list3 = new List <int>(); list2.Add(startGridIndex); list.Add(new FarmDigimonUtility.PathInfo { gridIndex = startGridIndex }); if (startGridIndex == endGridIndex) { return(list); } bool flag = false; FarmGrid.GridPosition gridPosition = field.Grid.IndexToPosition(startGridIndex); if (FarmDigimonUtility.CheckGrid(field.Grid, grids, gridPosition.x, gridPosition.y, false) == -1) { flag = true; } while (0 < list2.Count) { num++; for (int i = 0; i < list2.Count; i++) { FarmDigimonUtility.CheckAroundGrids(field.Grid, grids, list2[i], list3, false); } if (flag) { if (0 >= list3.Count) { for (int j = 0; j < list2.Count; j++) { FarmDigimonUtility.CheckAroundGrids(field.Grid, grids, list2[j], list3, true); } } else { flag = false; } } list2.Clear(); for (int k = 0; k < list3.Count; k++) { int num2 = list3[k]; if (!array[num2]) { array[num2] = true; list2.Add(num2); list.Add(new FarmDigimonUtility.PathInfo { gridIndex = num2, checkPoint = num }); if (endGridIndex == num2) { return(list); } } } list3.Clear(); } return(null); }