protected IEnumerator FindValuablesOverTime() { //give ourselves a second before looking for a flower double waitUntil = WorldClock.AdjustedRealTime + 1f; while (WorldClock.AdjustedRealTime < waitUntil && !mDestroyed) { yield return(null); } while (!mDestroyed) { while (WorldClock.AdjustedRealTime < StartleTimeEnd) { yield return(null); } while (GameWorld.Get.PrimaryChunk == null || GameWorld.Get.PrimaryChunk.AboveGroundGroup == null) { yield return(null); } if (CurrentValuable == null) { List <WorldItem> valuables = new List <WorldItem> (); //find something between the player and the critter, closer if it's friendlier //TODO make this work in immediate groups var searchEnum = WIGroups.GetAllChildrenByTypeInLocation(GameWorld.Get.PrimaryChunk.AboveGroundGroup.Path, ValuableScripts, valuables, Position, SearchRadius, false, 1); while (searchEnum.MoveNext()) { yield return(searchEnum.Current); } if (valuables.Count > 0) { valuableIsHeldByPlayer = false; CurrentValuable = valuables [0]; mCurrentValuablePosition = valuables [0].worlditem.FocusPosition; mRandomValuablePosition = valuables [0].worlditem.FocusPosition; } } if (CurrentValuable == null) { //find something between the player and the critter, closer if it's friendlier //TODO make this work in immediate groups List <WorldItem> valuables = WIGroups.Get.Player.GetChildrenOfType(ValuableScripts); if (valuables.Count > 0) { valuableIsHeldByPlayer = true; CurrentValuable = valuables [0]; mCurrentValuablePosition = valuables [0].worlditem.FocusPosition; mRandomValuablePosition = valuables [0].worlditem.FocusPosition; } } waitUntil = WorldClock.AdjustedRealTime + 1.5f; while (WorldClock.AdjustedRealTime < waitUntil && !mDestroyed) { yield return(null); } yield return(null); } }