private VillageDoorInfo GetVillageDoorAt(int par1, int par2, int par3) { for (IEnumerator <VillageDoorInfo> iterator = NewDoors.GetEnumerator(); iterator.MoveNext();) { VillageDoorInfo villagedoorinfo = iterator.Current; if (villagedoorinfo.PosX == par1 && villagedoorinfo.PosZ == par3 && Math.Abs(villagedoorinfo.PosY - par2) <= 1) { return(villagedoorinfo); } } for (IEnumerator <Village> iterator1 = VillageList.GetEnumerator(); iterator1.MoveNext();) { Village village = iterator1.Current; VillageDoorInfo villagedoorinfo1 = village.GetVillageDoorAt(par1, par2, par3); if (villagedoorinfo1 != null) { return(villagedoorinfo1); } } return(null); }
private VillageDoorInfo Func_48284_a(Village par1Village) { VillageDoorInfo villagedoorinfo = null; int i = 0x7fffffff; List <VillageDoorInfo> list = par1Village.GetVillageDoorInfoList(); IEnumerator <VillageDoorInfo> iterator = list.GetEnumerator(); do { if (!iterator.MoveNext()) { break; } VillageDoorInfo villagedoorinfo1 = iterator.Current; int j = villagedoorinfo1.GetDistanceSquared(MathHelper2.Floor_double(TheEntity.PosX), MathHelper2.Floor_double(TheEntity.PosY), MathHelper2.Floor_double(TheEntity.PosZ)); if (j < i && !Func_48285_a(villagedoorinfo1)) { villagedoorinfo = villagedoorinfo1; i = j; } }while (true); return(villagedoorinfo); }
private void AddUnassignedWoodenDoorsAroundToNewDoorsList(ChunkCoordinates par1ChunkCoordinates) { sbyte byte0 = 16; sbyte byte1 = 4; sbyte byte2 = 16; for (int i = par1ChunkCoordinates.PosX - byte0; i < par1ChunkCoordinates.PosX + byte0; i++) { for (int j = par1ChunkCoordinates.PosY - byte1; j < par1ChunkCoordinates.PosY + byte1; j++) { for (int k = par1ChunkCoordinates.PosZ - byte2; k < par1ChunkCoordinates.PosZ + byte2; k++) { if (!IsWoodenDoorAt(i, j, k)) { continue; } VillageDoorInfo villagedoorinfo = GetVillageDoorAt(i, j, k); if (villagedoorinfo == null) { AddDoorToNewListIfAppropriate(i, j, k); } else { villagedoorinfo.LastActivityTimestamp = TickCounter; } } } } }
/// <summary> /// Find a door suitable for shelter. If there are more doors in a distance of 16 blocks, then the least restricted /// one (i.e. the one protecting the lowest number of villagers) of them is chosen, else the nearest one regardless /// of restriction. /// </summary> public virtual VillageDoorInfo FindNearestDoorUnrestricted(int par1, int par2, int par3) { VillageDoorInfo villagedoorinfo = null; int i = 0x7fffffff; IEnumerator <VillageDoorInfo> iterator = VillageDoorInfoList.GetEnumerator(); do { if (!iterator.MoveNext()) { break; } VillageDoorInfo villagedoorinfo1 = iterator.Current; int j = villagedoorinfo1.GetDistanceSquared(par1, par2, par3); if (j > 256) { j *= 1000; } else { j = villagedoorinfo1.GetDoorOpeningRestrictionCounter(); } if (j < i) { villagedoorinfo = villagedoorinfo1; i = j; } }while (true); return(villagedoorinfo); }
public virtual void AddVillageDoorInfo(VillageDoorInfo par1VillageDoorInfo) { VillageDoorInfoList.Add(par1VillageDoorInfo); CenterHelper.PosX += par1VillageDoorInfo.PosX; CenterHelper.PosY += par1VillageDoorInfo.PosY; CenterHelper.PosZ += par1VillageDoorInfo.PosZ; UpdateVillageRadiusAndCenter(); LastAddDoorTimestamp = par1VillageDoorInfo.LastActivityTimestamp; }
private bool Func_48285_a(VillageDoorInfo par1VillageDoorInfo) { for (IEnumerator <VillageDoorInfo> iterator = DoorList.GetEnumerator(); iterator.MoveNext();) { VillageDoorInfo villagedoorinfo = iterator.Current; if (par1VillageDoorInfo.PosX == villagedoorinfo.PosX && par1VillageDoorInfo.PosY == villagedoorinfo.PosY && par1VillageDoorInfo.PosZ == villagedoorinfo.PosZ) { return(true); } } return(false); }
/// <summary> /// Returns whether the EntityAIBase should begin execution. /// </summary> public override bool ShouldExecute() { Func_48286_h(); if (Field_48289_e && TheEntity.WorldObj.IsDaytime()) { return(false); } Village village = TheEntity.WorldObj.VillageCollectionObj.FindNearestVillage(MathHelper2.Floor_double(TheEntity.PosX), MathHelper2.Floor_double(TheEntity.PosY), MathHelper2.Floor_double(TheEntity.PosZ), 0); if (village == null) { return(false); } DoorInfo = Func_48284_a(village); if (DoorInfo == null) { return(false); } bool flag = TheEntity.GetNavigator().Func_48665_b(); TheEntity.GetNavigator().SetBreakDoors(false); Field_48291_c = TheEntity.GetNavigator().GetPathToXYZ(DoorInfo.PosX, DoorInfo.PosY, DoorInfo.PosZ); TheEntity.GetNavigator().SetBreakDoors(flag); if (Field_48291_c != null) { return(true); } Vec3D vec3d = RandomPositionGenerator.Func_48620_a(TheEntity, 10, 7, Vec3D.CreateVector(DoorInfo.PosX, DoorInfo.PosY, DoorInfo.PosZ)); if (vec3d == null) { return(false); } else { TheEntity.GetNavigator().SetBreakDoors(false); Field_48291_c = TheEntity.GetNavigator().GetPathToXYZ(vec3d.XCoord, vec3d.YCoord, vec3d.ZCoord); TheEntity.GetNavigator().SetBreakDoors(flag); return(Field_48291_c != null); } }
public virtual VillageDoorInfo GetVillageDoorAt(int par1, int par2, int par3) { if (Center.GetDistanceSquared(par1, par2, par3) > (float)(VillageRadius * VillageRadius)) { return(null); } for (IEnumerator <VillageDoorInfo> iterator = VillageDoorInfoList.GetEnumerator(); iterator.MoveNext();) { VillageDoorInfo villagedoorinfo = iterator.Current; if (villagedoorinfo.PosX == par1 && villagedoorinfo.PosZ == par3 && Math.Abs(villagedoorinfo.PosY - par2) <= 1) { return(villagedoorinfo); } } return(null); }
private void UpdateVillageRadiusAndCenter() { int i = VillageDoorInfoList.Count; if (i == 0) { Center.Set(0, 0, 0); VillageRadius = 0; return; } Center.Set(CenterHelper.PosX / i, CenterHelper.PosY / i, CenterHelper.PosZ / i); int j = 0; for (IEnumerator <VillageDoorInfo> iterator = VillageDoorInfoList.GetEnumerator(); iterator.MoveNext();) { VillageDoorInfo villagedoorinfo = iterator.Current; j = Math.Max(villagedoorinfo.GetDistanceSquared(Center.PosX, Center.PosY, Center.PosZ), j); } VillageRadius = Math.Max(32, (int)Math.Sqrt(j) + 1); }
private void AddNewDoorsToVillageOrCreateVillage() { for (int i = 0; i < NewDoors.Count; i++) { VillageDoorInfo villagedoorinfo = (VillageDoorInfo)NewDoors[i]; bool flag = false; IEnumerator <Village> iterator = VillageList.GetEnumerator(); do { if (!iterator.MoveNext()) { break; } Village village1 = iterator.Current; int j = (int)village1.GetCenter().GetEuclideanDistanceTo(villagedoorinfo.PosX, villagedoorinfo.PosY, villagedoorinfo.PosZ); if (j > 32 + village1.GetVillageRadius()) { continue; } village1.AddVillageDoorInfo(villagedoorinfo); flag = true; break; }while (true); if (!flag) { Village village = new Village(WorldObj); village.AddVillageDoorInfo(villagedoorinfo); VillageList.Add(village); } } NewDoors.Clear(); }