示例#1
0
        public static void ServerOnPowerGridBroken(ILogicObject fromPowerGrid, List <ILogicObject> toPowerGrids)
        {
            var fromPowerGridState              = GetPublicState(fromPowerGrid);
            var totalElectricityAmount          = fromPowerGridState.ElectricityAmount;
            var totalElectricityStorageCapacity = fromPowerGridState.ElectricityCapacity - PowerGridSystem.BaseCapacity;

            var totalPowerGridsCount = 1 + toPowerGrids.Count;

            Logger.Info(
                $"Power grid broken. Electricity split: {totalElectricityAmount:F0} to {totalPowerGridsCount} power grids from {fromPowerGrid}");

            fromPowerGridState.ElectricityAmount = CalculateElectricityPart(fromPowerGrid, fromPowerGridState);

            foreach (var toPowerGrid in toPowerGrids)
            {
                var toState = GetPublicState(toPowerGrid);
                // we're using += here as the new power grid might be an already existing grid from another base
                toState.ElectricityAmount += CalculateElectricityPart(toPowerGrid, toState);
            }

            double CalculateElectricityPart(ILogicObject powerGrid, PowerGridPublicState powerGridState)
            {
                // force recalculate grid capacity
                // (it could (and for the "fromPowerGrid", will) apply penalty which we will ignore)
                PowerGridSystem.ServerForceRebuildPowerGrid(powerGrid);

                var powerGridCapacity   = powerGridState.ElectricityCapacity - PowerGridSystem.BaseCapacity;
                var electricityFraction = powerGridCapacity / totalElectricityStorageCapacity;
                var electricityPart     = totalElectricityAmount * electricityFraction;

                Logger.Info($"Electricity share part: {electricityPart:F0} for {powerGrid}");
                return(electricityPart);
            }
        }
示例#2
0
 protected override void ServerUpdate(ServerUpdateData data)
 {
     PowerGridSystem.ServerUpdateGrid(data.GameObject,
                                      data.PublicState,
                                      data.DeltaTime);
 }
示例#3
0
 protected override void ServerInitialize(ServerInitializeData data)
 {
     data.PublicState.ServerInitState();
     PowerGridSystem.ServerRegisterGrid(data.GameObject);
 }
示例#4
0
 public override void ServerOnDestroy(ILogicObject gameObject)
 {
     PowerGridSystem.ServerUnregisterGrid(gameObject);
 }