Beispiel #1
0
        public async Task CreateStructureAsync(string aEBPFile, PlayfieldGlobalStructureInfo aStructure)
        {
            var NewID = await Request_NewEntityId();

            aStructure.Type = GetStructureInfo(aEBPFile);

            var SpawnInfo = new EntitySpawnInfo()
            {
                forceEntityId  = NewID.id,
                playfield      = aStructure.Playfield,
                pos            = aStructure.Pos,
                rot            = aStructure.Rot,
                name           = $"EBP:{Path.GetFileNameWithoutExtension(aStructure.Name)}",
                type           = (byte)Array.IndexOf(new[] { "Undef", "", "BA", "CV", "SV", "HV", "", "AstVoxel" }, aStructure.Type), // Entity.GetFromEntityType 'Kommentare der Devs: Set this Undef = 0, BA = 2, CV = 3, SV = 4, HV = 5, AstVoxel = 7
                entityTypeName = "",                                                                                                  // 'Kommentare der Devs:  ...or set this to f.e. 'ZiraxMale', 'AlienCivilian1Fat', etc
                prefabName     = Path.GetFileNameWithoutExtension(aEBPFile),
                prefabDir      = Path.GetDirectoryName(aEBPFile),
                factionGroup   = 0,
                factionId      = 0, // erstmal auf "public" aStructure.Faction,
            };

            try { await Request_Load_Playfield(new PlayfieldLoad(20, aStructure.Playfield, 0)); }
            catch { }  // Playfield already loaded

            try
            {
                await Request_Entity_Spawn(SpawnInfo);
                await Request_Structure_Touch(NewID); // Sonst wird die Struktur sofort wieder gelöscht !!!
            }
            finally
            {
                try { File.Delete(aEBPFile); } catch { }
            }
        }
Beispiel #2
0
        public async Task CreateStructure(string aSelectBackupDir, PlayfieldGlobalStructureInfo aStructure)
        {
            var NewID = await Request_NewEntityId();

            var SourceDir = Path.Combine(BackupDir,
                                         aSelectBackupDir == CurrentSaveGame ? EmpyrionConfiguration.ProgramPath : aSelectBackupDir,
                                         @"Saves\Games",
                                         Path.GetFileName(EmpyrionConfiguration.SaveGamePath), "Shared", aStructure.structureName);
            var sourceExportDat = Path.Combine(SourceDir, "Export.dat");
            var TargetDir       = Path.Combine(EmpyrionConfiguration.SaveGamePath, "Shared", $"{NewID.id}");

            var SpawnInfo = new EntitySpawnInfo()
            {
                forceEntityId     = NewID.id,
                playfield         = aStructure.Playfield,
                pos               = aStructure.Pos,
                rot               = aStructure.Rot,
                name              = aStructure.Name,
                type              = (byte)Array.IndexOf(new[] { "Undef", "", "BA", "CV", "SV", "HV", "", "AstVoxel" }, aStructure.Type), // Entity.GetFromEntityType 'Kommentare der Devs: Set this Undef = 0, BA = 2, CV = 3, SV = 4, HV = 5, AstVoxel = 7
                entityTypeName    = "",                                                                                                  // 'Kommentare der Devs:  ...or set this to f.e. 'ZiraxMale', 'AlienCivilian1Fat', etc
                prefabName        = $"{aStructure.Type}_Player",
                factionGroup      = 0,
                factionId         = 0, // erstmal auf "public" aStructure.Faction,
                exportedEntityDat = File.Exists(sourceExportDat) ? sourceExportDat : null
            };

            Directory.CreateDirectory(Path.GetDirectoryName(TargetDir));
            CopyAll(new DirectoryInfo(SourceDir), new DirectoryInfo(TargetDir));

            try { await Request_Load_Playfield(new PlayfieldLoad(20, aStructure.Playfield, 0)); }
            catch { }  // Playfield already loaded

            await Request_Entity_Spawn(SpawnInfo);

            for (int i = 0; i < 10; i++)
            {
                try
                {
                    await Request_Structure_Touch(NewID); // Sonst wird die Struktur sofort wieder gelöscht !!!

                    break;
                }
                catch
                {
                    await Task.Delay(5000);
                }
            }
        }
Beispiel #3
0
    private static void debugEntitySpawning(PString prefabName)
    {
        EntitySpawnInfo info = new EntitySpawnInfo
        {
            playfield    = "Akua",
            pos          = new PVector3(11.5354891F, 58.5829468F, -11.8831434F),
            rot          = new PVector3(0F, 139.371F, 0F),
            name         = "BA_Alien",
            type         = 2,
            factionGroup = 2,
            factionId    = 0,
            prefabName   = "Infested-Test"
        };
        var cmd = new APICmd(CmdId.Request_Entity_Spawn, info);

        broker.HandleCall(cmd);
    }
Beispiel #4
0
        public static void Request_Entity_Spawn(EntitySpawnInfo arg, Action callback = null, Action <ErrorInfo> onError = null)
        {
            Action <CmdId, object> wiredCallback = null;

            if (callback != null)
            {
                wiredCallback = (_, val) => callback();
            }

            var apiCmd = new GenericAPICommand(
                CmdId.Request_Entity_Spawn,
                arg,
                wiredCallback,
                onError ?? noOpErrorHandler
                );

            Broker.Execute(apiCmd);
        }
 public Task RequestEntitySpawn(EntitySpawnInfo entitySpawnInfo)
 {
     return(SendRequest(Eleon.Modding.CmdId.Request_Entity_Spawn, entitySpawnInfo));
 }
Beispiel #6
0
 public async Task <bool> Request_Entity_Spawn(EntitySpawnInfo arg, CancellationToken ct)
 {
     return(await Broker.SendRequestAsync(CmdId.Request_Entity_Spawn, arg, ct));
 }
Beispiel #7
0
 public async Task <bool> Request_Entity_Spawn(EntitySpawnInfo arg)
 {
     return(await Broker.SendRequestAsync(CmdId.Request_Entity_Spawn, arg));
 }
Beispiel #8
0
    private void HandleSettlementWokflowEvent(ModGameAPI GameAPI, SettlementOperation operation, CmdId eventType, object data)
    {
        var operationPayload = Serializer.Serialize(operation);

        var message = $"*** processing operation {operation.seqNr}\n *** cmdid:{eventType} \n *** " +
                      $"last operation: {operation.stage} \n***  payload: {operationPayload}";

        GameAPI.Console_Write(message);


        switch (eventType)
        {
        case CmdId.Event_GlobalStructure_List:
            var structureList = (GlobalStructureList)data;
            operation = updateOperationFromStructureList(operation, structureList);
            if (operation.stage != SettlementStage.IdentifiedReplacement)
            {
                deprovisionOperation(operation.seqNr);
                return;
            }
            settlementOperations[operation.seqNr] = operation;
            GameAPI.Game_Request(CmdId.Request_NewEntityId, operation.seqNr, null);
            break;

        case CmdId.Event_NewEntityId:
            var newId = (Id)data;

            GameAPI.Console_Write($"*** new id: {Serializer.Serialize(newId)} ***");

            operation.newStructureId = newId;
            EntitySpawnInfo newInfo = new EntitySpawnInfo()
            {
                forceEntityId = newId.id,
                playfield     = operation.playfieldName,
                pos           = operation.originalStructureInfo.pos,
                rot           = operation.originalStructureInfo.rot,
                name          = operation.newStructureName,
                prefabName    = "Test-Bed (Settled)",
                type          = operation.originalStructureInfo.type,
            };

            GameAPI.Console_Write($"*** requesting spawn: {Serializer.Serialize(newInfo)} ***");
            operation.newStructureInfo            = newInfo;
            operation.stage                       = SettlementStage.ProvisionedReplacement;
            operation.stage                       = SettlementStage.RequestedDemolition;
            settlementOperations[operation.seqNr] = operation;
            Id outId = new Id(operation.originalStructureInfo.id);
            GameAPI.Game_Request(CmdId.Request_Entity_Destroy, operation.seqNr, outId);

            break;

        case CmdId.Event_Ok:
            if (operation.stage == SettlementStage.RequestedDemolition)
            {
                operation.stage = SettlementStage.EmplacedNewSettlement;
                settlementOperations[operation.seqNr] = operation;
                GameAPI.Console_Write($"*** new settlement info:{Serializer.Serialize(operation.newStructureInfo)}");
                GameAPI.Game_Request(CmdId.Request_Entity_Spawn, operation.seqNr, operation.newStructureInfo);
            }
            else if (operation.stage == SettlementStage.EmplacedNewSettlement)
            {
                operation.stage = SettlementStage.SettlementComplete;
                settlementOperations[operation.seqNr] = operation;
                deprovisionOperation(operation.seqNr);
                GameAPI.Console_Write("*** settlement complete!!! ***");
            }
            break;

        case CmdId.Event_Error:
            var error = (ErrorInfo)data;
            GameAPI.Console_Write($"*** error: {Serializer.Serialize(error)} ***");

            deprovisionOperation(operation.seqNr);
            break;
        }
    }
Beispiel #9
0
 public void Request_Entity_Spawn(EntitySpawnInfo arg, Action callback = null, Action <ErrorInfo> onError = null)
 {
     Broker.Request_Entity_Spawn(arg, callback, onError);
 }
Beispiel #10
0
 public static Task <object> Request_Entity_Spawn(EntitySpawnInfo param)
 {
     return(Broker.CreateCommandWithArgAndReturn <EntitySpawnInfo, object>(CmdId.Request_Entity_Spawn, param));
 }
Beispiel #11
0
 public static Task <object> Request_Entity_Spawn(EntitySpawnInfo param, Action callback, Action <ErrorInfo> onError = null)
 {
     return(Broker.CreateCommandWithArgAndReturn <EntitySpawnInfo, object>(CmdId.Request_Entity_Spawn, param, callback, onError));
 }