public static ItemActivationResult Activate(ItemType type, Atom<World> world) { var result = (ItemActivationResult?)null; switch (type) { case ItemType.MiningDroid: world.Set(w => { var playerShip = w.GetWob<Ship>(w.GetPlayerShipID(Globals.PlayerID)); var planet = w.Wobs.Values.OfType<Planet>() .FirstOrDefault(p => IsCloseAhead(playerShip.Pose, p.Pos)); result = planet == null ? ItemActivationResult.Nothing : ItemActivationResult.IsDepleted; if (planet == null) return w; var droidInventoryID = Guid.NewGuid(); return w .SetWob(new Inventory(droidInventoryID)) .SetWob(new Droid(Guid.NewGuid(), playerShip.Pose, droidInventoryID)); }); break; default: throw new NotImplementedException("Activate for " + type); } Debug.Assert(result.HasValue, "Bug: Forgot to set activation result for " + type); return result.Value; }