Esempio n. 1
0
    private SettlementOperation updateOperationFromStructureList(SettlementOperation operation, GlobalStructureList globalStructureList)
    {
        foreach (var kvp in globalStructureList.globalStructures)
        {
            var structureList       = kvp.Value;
            var applicableStructure = structureList.FirstOrDefault(x => x.id == operation.originalStructureId);

            if (object.Equals(applicableStructure, default(GlobalStructureInfo)))
            {
                continue;
            }
            operation.playfieldName         = kvp.Key;
            operation.originalStructureInfo = applicableStructure;
            operation.originalStructureName = applicableStructure.name;
            if (!operation.originalStructureName.Contains("Infested"))
            {
                operation.stage = SettlementStage.SettlementInvalidated;
                return(operation);
            }
            operation.newStructureName = operation.originalStructureName.Replace("Infested", "Settled");
            operation.stage            = SettlementStage.IdentifiedReplacement;

            return(operation);
        }

        return(operation);
    }
Esempio n. 2
0
 private void Handle_event_statistics(StatisticsParam data)
 {
     if (data.type == StatisticsType.CoreRemoved)
     {
         var structureId = data.int1;
         var sequenceId  = unusedSettlementSequenceNumbers.Dequeue();
         SettlementOperation operation = new SettlementOperation();
         operation.seqNr = sequenceId;
         operation.stage = 0;
         operation.originalStructureId = structureId;
         settlementOperations.Add(sequenceId, operation);
         GameAPI.Game_Request(CmdId.Request_GlobalStructure_List, sequenceId, null);
     }
 }
Esempio n. 3
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;
        }
    }