Example #1
0
 private static TestResult ReadItemsById(DocumentStore documentStore, List<string> generatedIds)
 {
     var ids = generatedIds.TakeRandom().ToList();
     var time = Stopwatch.StartNew();
     foreach (var id in ids)
     {
         var jsonDocument = documentStore.DatabaseCommands.Get(id);
         // we need to convert it to entity to do the same level of work as mongo test
         var p = jsonDocument.DataAsJson.Deserialize<Person>(documentStore.Conventions);
         if (p.Id != null)
             throw new ArgumentException();
     }
     time.Stop();
     var result = new TestResult { Count = ids.Count, TotalMs = time.ElapsedMilliseconds };
     Console.WriteLine("Reading total time: {0} ms, avg item: {1} ms, #records: {2}",
                       result.TotalMs, result.ItemAvgMs, ids.Count);
     return result;
 }
Example #2
0
        private static Task RequestPersonalTask(Dwarf d)
        {
            if (d.SkipPersonalForOneTask || DebugRules.SkipPersonalTasks)
                return null;

            List<Task> tasksToChooseFrom = new List<Task>();

            if (d.NeedFood())
            {
                tasksToChooseFrom.Add(new GetFoodTask());
            }
            if (d.NeedTool())
            {
                tasksToChooseFrom.Add(new GetToolTask());
            }
            if (d.NeedSleep())
            {
                tasksToChooseFrom.Add(new GetSleepTask());
            }
            if (d.NeedCloth())
            {
            }

            if (tasksToChooseFrom.Count == 0)
                return null;
            else
                return tasksToChooseFrom.TakeRandom();
        }
		void KillFleetsAndUpgrades(Faction victoriousFaction, Planet planet)
		{
			// kill orbiting spacefleets
			var fleetsToKill = new List<SpaceFleet>();
			foreach (var fleet in Galaxy.Fleets.Where(x => x.TargetPlanetID == planet.ID)) {
				PointF loc;
				if (fleet.GetCurrentPosition(out loc, Galaxy.Turn)) {
					if (Galaxy.GetPlayer(fleet.OwnerName).FactionName != victoriousFaction.Name) {
						fleetsToKill.Add(fleet);
					}
				}
			}
			if (fleetsToKill.Count > 0) {
				var f = fleetsToKill.TakeRandom(); // pick random one to kill
				Galaxy.Fleets.Remove(f);
				List<UpgradeDef> upgrades;
				if (UpgradeData.TryGetValue(f.OwnerName, out upgrades)) {
					var upgrade = upgrades.SingleOrDefault(u => u.UnitChoice == "fleet_blockade");
					if (upgrade != null) {
						upgrades.Remove(upgrade);
					}
				}
			}

			// occupied planet - delete deployed structures
			if (planet.OwnerName != null && Galaxy.GetPlayer(planet.OwnerName).FactionName != planet.FactionName) {
				RemoveAllUpgradesFromPlanet(planet.ID);
			}
		}