static void Craft(long entityId, CraftModule craft) { if (craft.type == ModuleType.None || craft.type == ModuleType.Count) { return; } var properties = craft.propertyLevels; if (!Helpers.CheckCraftingAccess(components[entityId].propertiesUnlocked[craft.type].BackingArray, properties.BackingArray)) { return; } var requirements = Helpers.GetRequirements(craft.type, properties.BackingArray); var resourceIds = new byte[requirements.Count]; var resourceInfos = new ResourceInfo[requirements.Count]; for (int i = 0; i < requirements.Count; i++) { var resourceId = (byte)craft.resourceIds[i]; var requirement = requirements[i]; if (!ResourcesInventorySystem.TryGetResourceInfo(entityId, resourceId, out var resourceInfo)) { return; } if (resourceInfo.type != requirement.Type) { return; } if (resourceInfo.quantity < requirement.Quantity) { return; } resourceInfo.quantity = requirement.Quantity; resourceIds[i] = resourceId; resourceInfos[i] = resourceInfo; } for (int i = 0; i < resourceInfos.Length; i++) { ResourcesInventorySystem.QueueResourceQuantityDeltaOp(entityId, resourceIds[i], -resourceInfos[i].quantity); } var userDBId = IdentificationsSystem.GetUserDBId(entityId); var moduleFullName = craft.name.HasValue ? craft.name.Value + craft.type.ToString() : "Prototype " + craft.type.ToString(); var craftedModuleDBId = Helpers.GenerateCloudFireStoreRandomDocumentId(random); var craftedModule = new Module(moduleFullName, craft.type, userDBId, properties, false); ModulesInventorySystem.QueueAddModuleOp(entityId, craftedModuleDBId, craftedModule, resourceInfos); }
static int Main(string[] args) { stopwatch.Restart(); if (args.Length != 4) { PrintUsage(); return(1); } Assembly.Load("GeneratedCode"); using (var connection = ConnectWithReceptionist(args[1], Convert.ToUInt16(args[2]), args[3])) { var channel = new Channel(FirestoreClient.DefaultEndpoint.Host, FirestoreClient.DefaultEndpoint.Port, GoogleCredential.FromFile(Path.Combine(Directory.GetCurrentDirectory(), CloudFirestoreInfo.GoogleCredentialFile)).ToChannelCredentials()); var task = FirestoreDb.CreateAsync(CloudFirestoreInfo.FirebaseProjectId, FirestoreClient.Create(channel)); var connected = true; SpatialOSConnectionSystem.connection = connection; var dispatcher = new Dispatcher(); dispatcher.OnDisconnect(op => { Console.Error.WriteLine("[disconnect] " + op.Reason); connected = false; }); CloudFirestoreInfo.Database = task.Result; var factory = new TaskFactory(TaskCreationOptions.LongRunning, TaskContinuationOptions.None); factory.StartNew(ResourcesInventorySystem.UpdateLoop); factory.StartNew(ResourceGeneratorSystem.UpdateLoop); factory.StartNew(ResourceExtractorSystem.UpdateLoop); stopwatch.Stop(); connection.SendLogMessage(LogLevel.Info, "Initialization", string.Format("Init Time {0}ms", stopwatch.Elapsed.TotalMilliseconds.ToString("N0"))); while (connected) { stopwatch.Restart(); using (var opList = connection.GetOpList(100)) { Parallel.Invoke( () => dispatcher.Process(opList), () => PositionsSystem.ProccessOpList(opList), () => IdentificationsSystem.ProccessOpList(opList), () => ResourcesInventorySystem.ProccessOpList(opList), () => ResourceGeneratorSystem.ProccessOpList(opList), () => ResourceExtractorSystem.ProccessOpList(opList) ); } SpatialOSConnectionSystem.Update(); stopwatch.Stop(); } SpatialOSConnectionSystem.connection = null; channel.ShutdownAsync().Wait(); } return(1); }