예제 #1
0
        private static void OnRazeBlockInCompoundBlockRequest(MySyncGrid sync, ref RazeBlockInCompoundBlockMsg msg, MyNetworkClient sender)
        {
            m_tmpLocationsAndIdsReceive.Clear();
            Debug.Assert(m_tmpLocationsAndIdsReceive != msg.LocationsAndIds, "The raze block in compound block message was received via loopback using the same list. This causes erasing of the message.");
            var handler = sync.RazedBlockInCompoundBlock;

            if (handler != null)
            {
                handler(msg.LocationsAndIds, m_tmpLocationsAndIdsReceive);
            }

            if (Sync.IsServer && m_tmpLocationsAndIdsReceive.Count > 0)
            {
                // Broadcast to clients, use result collection
                msg.LocationsAndIds = m_tmpLocationsAndIdsReceive;
                Sync.Layer.SendAsRpcToAll(ref msg);
            }
        }
예제 #2
0
        private static void OnBonesReceived(MySyncGrid sync, ref BonesMsg msg, MyNetworkClient sender)
        {
            sync.Entity.Skeleton.DeserializePart(msg.MinBone, msg.MaxBone, sync.Entity.GridSize, msg.Bones);

            Vector3I minCube = Vector3I.Zero;
            Vector3I maxCube = Vector3I.Zero;

            // To hit incident cubes
            Vector3I min = msg.MinBone;// -Vector3I.One;
            Vector3I max = msg.MaxBone;// +Vector3I.One;

            sync.Entity.Skeleton.Wrap(ref minCube, ref min);
            sync.Entity.Skeleton.Wrap(ref maxCube, ref max);

            minCube -= Vector3I.One;
            maxCube += Vector3I.One;

            Vector3I pos;
            for (pos.X = minCube.X; pos.X <= maxCube.X; pos.X++)
            {
                for (pos.Y = minCube.Y; pos.Y <= maxCube.Y; pos.Y++)
                {
                    for (pos.Z = minCube.Z; pos.Z <= maxCube.Z; pos.Z++)
                    {
                        sync.Entity.SetCubeDirty(pos);
                    }
                }
            }
        }
예제 #3
0
        private static void OnColorBlocksRequest(MySyncGrid sync, ref ColorBlocksMsg msg, MyNetworkClient sender)
        {
            var handler = sync.BlocksColored;
            if (handler != null) handler(msg.Min, msg.Max, ColorExtensions.UnpackHSVFromUint(msg.HSV), msg.PlaySound);

            if (Sync.IsServer)
            {
                // Broadcast to clients, use result collection
                Sync.Layer.SendMessageToAll(ref msg);
            }
        }
예제 #4
0
        private static void OnRazeBlocksAreaSuccess(MySyncGrid sync, ref RazeBlocksAreaSuccessMsg successMsg, MyNetworkClient sender)
        {
            Debug.Assert(sync.BlocksRazeAreaSuccess != null, "Handler should not be null, Raze messages will be ignored!");

            var handler = sync.BlocksRazeAreaSuccess;
            if (handler != null) handler(ref successMsg.Pos, ref successMsg.Size, successMsg.FailList);
        }
예제 #5
0
        private static void OnBuildBlocksAreaSuccess(MySyncGrid sync, ref BuildBlocksAreaSuccessMsg successMsg, MyNetworkClient sender)
        {
            Debug.Assert(sync.BlocksBuiltAreaSuccess != null, "Handler should not be null, build messages will be ignored!");

            var handler = sync.BlocksBuiltAreaSuccess;
            if (handler != null) handler(ref successMsg.Area, successMsg.EntityIdSeed, successMsg.FailList, successMsg.OwnerId);
        }
예제 #6
0
        private static void OnBuildBlockRequest(MySyncGrid sync, ref BuildBlockMsg msg, MyNetworkClient sender)
        {
            MyCubeGrid.MyBlockLocation? builtBlock = null;

            MyEntity builder = null;
            MyEntities.TryGetEntityById(msg.BuilderEntityId, out builder);

            var buildHandler = sync.BlockBuilt;
            if (buildHandler != null) buildHandler(ColorExtensions.UnpackHSVFromUint(msg.ColorMaskHsv), msg.Location, msg.BlockObjectBuilder, ref builtBlock, builder);
            
            if (Sync.IsServer)
            {
                Sync.Layer.SendMessageToAll(ref msg);
            }
            
            var afterHandler = sync.AfterBlockBuilt;
            if (afterHandler != null && builtBlock != null) afterHandler(builtBlock.Value);
        }
예제 #7
0
        private static void OnRemoveSplit(MySyncGrid grid, ref RemoveSplitMsg msg, MyNetworkClient sender)
        {
            MyCubeGrid m_grid;
            if (MyEntities.TryGetEntityById(msg.GridEntityId, out m_grid))
            {
                m_tmpBlockListReceive.Clear();
                foreach (var position in msg.RemovedBlocks)
                {
                    var block = m_grid.GetCubeBlock(position);
                    Debug.Assert(block != null, "Block was null when trying to remove a grid split. Desync?");
                    if (block == null)
                    {
                        MySandboxGame.Log.WriteLine("Block was null when trying to remove a grid split. Desync?");
                        continue;
                    }

                    m_tmpBlockListReceive.Add(block);
                }

                MyCubeGrid.RemoveSplit(m_grid, m_tmpBlockListReceive, 0, m_tmpBlockListReceive.Count, sync: false);
                m_tmpBlockListReceive.Clear();
            }
        }
예제 #8
0
 private static void OnChangeDisplayName(MySyncGrid grid, ref ChangeDisplayNameMsg msg, MyNetworkClient sender)
 {
     MyCubeGrid m_grid;
     if (MyEntities.TryGetEntityById(msg.GridEntityId, out m_grid))
         m_grid.DisplayName = msg.DisplayName;
 }
예제 #9
0
        private static void OnSetToConstructionRequest(MySyncGrid sync, ref SetToConstructionRequestMsg msg, MyNetworkClient sender)
        {
            var block = sync.Entity.GetCubeBlock(msg.BlockPosition);
            Debug.Assert(block != null, "Could not find block to set to construction site");
            if (block == null) return;

            block.SetToConstructionSite();

            MyEntity ownerEntity = null;
            if (!MyEntities.TryGetEntityById(msg.OwnerEntityId, out ownerEntity))
            {
                Debug.Assert(false, "Set to construction site inventory owner entity was null");
                return;
            }

            var owner = (ownerEntity as IMyInventoryOwner);
            Debug.Assert(owner != null, "Set to construction site inventory owner was not an inventory owner");

            var inventory = owner.GetInventory(msg.InventoryIndex);
            Debug.Assert(inventory != null, "Set to construction site inventory owner did not have the given inventory");

            block.MoveItemsToConstructionStockpile(inventory);
            block.IncreaseMountLevel(MyWelder.WELDER_AMOUNT_PER_SECOND * MyEngineConstants.UPDATE_STEP_SIZE_IN_SECONDS, msg.RequestingPlayer);
        }
예제 #10
0
        private static void OnStockpileFillRequest(MySyncGrid sync, ref StockpileFillRequestMsg msg, MyNetworkClient sender)
        {
            var block = sync.Entity.GetCubeBlock(msg.BlockPosition);
            Debug.Assert(block != null, "Could not find block whose stockpile fill was requested");
            if (block == null) return;

            MyEntity ownerEntity = null;
            if (!MyEntities.TryGetEntityById(msg.OwnerEntityId, out ownerEntity))
            {
                Debug.Assert(false, "Stockpile fill inventory owner entity was null");
                return;
            }

            var owner = (ownerEntity as IMyInventoryOwner);
            Debug.Assert(owner != null, "Stockpile fill inventory owner was not an inventory owner");

            var inventory = owner.GetInventory(msg.InventoryIndex);
            Debug.Assert(inventory != null, "Stockpile fill inventory owner did not have the given inventory");

            block.MoveItemsToConstructionStockpile(inventory);
        }
예제 #11
0
 private static void OnStockpileChanged(MySyncGrid sync, ref StockpileChangedMsg msg, MyNetworkClient sender)
 {
     if (sync.BlockStockpileChanged != null)
         sync.BlockStockpileChanged(msg.BlockPosition, msg.SubBlockId, msg.Changes);
 }
예제 #12
0
 private static void OnIntegrityChanged(MySyncGrid sync, ref IntegrityChangedMsg msg, MyNetworkClient sender)
 {
     if (sync.BlockIntegrityChanged != null)
         sync.BlockIntegrityChanged(msg.BlockPosition, msg.SubBlockId, msg.BuildIntegrity, msg.Integrity, msg.IntegrityChangeType, msg.ToolOwner);
 }
예제 #13
0
 private static void OnThrustReceived(MySyncGrid sync, ref ThrustMsg msg, MyNetworkClient sender)
 {
     sync.Entity.GridSystems.ThrustSystem.ControlThrust = msg.Thrust;
 }
예제 #14
0
        private static void OnThrustTorqueReceived(MySyncGrid sync, ref ThrustAndTorqueMsg msg, MyNetworkClient sender)
        {
            sender.ClientFrameId = msg.ClientFrameId;

            //if (false)
            {
                sync.Entity.GridSystems.ThrustSystem.ControlThrust = msg.Thrust;
                sync.Entity.GridSystems.GyroSystem.ControlTorque = msg.Torque;
            }
        }
예제 #15
0
        private static void OnPowerProducerStateRequest(MySyncGrid sync, ref PowerProducerStateMsg msg, MyNetworkClient sender)
        {
            var handler = sync.PowerProducerStateChanged;
            if (handler != null) handler(msg.Enabled, msg.PlayerId);

            if (Sync.IsServer)
                Sync.Layer.SendMessageToAll(ref msg);
        }
예제 #16
0
        private static void OnChangeDisplayNameRequest(MySyncGrid sync, ref ChangeDisplayNameMsg msg, MyNetworkClient sender)
        {
            if (Sync.IsServer)
                ChangeDisplayName(ref msg);
            else
                System.Diagnostics.Debug.Fail("Invalid display name change request!");

        }
예제 #17
0
 private static void OnModifyGroupSuccess(MySyncGrid sync, ref ModifyBlockGroupMsg msg, MyNetworkClient sender)
 {
     if (msg.Blocks == null || msg.Blocks.Count() == 0)
         foreach (var group in sync.Entity.BlockGroups)
         {
             if (group.Name.ToString().Equals(msg.Name))
             {
                 sync.Entity.RemoveGroup(group);
                 break;
             }
         }
     else
     {
         MyBlockGroup group = new MyBlockGroup(sync.Entity);
         group.Name.Clear().Append(msg.Name);
         foreach (var blockId in msg.Blocks)
         {
             MyTerminalBlock block = null;
             if (MyEntities.TryGetEntityById(blockId, out block))
                 group.Blocks.Add(block);
         }
         sync.Entity.AddGroup(group);
     }
 }
예제 #18
0
        private static void OnCreateSplits(MySyncGrid syncGrid, ref CreateSplitsMsg msg, MyNetworkClient sender)
        {
            m_tmpBlockListReceive.Clear();

            var grid = syncGrid.Entity;
            foreach (var b in msg.SplitBlocks)
            {
                var block = grid.GetCubeBlock(b);
                m_tmpBlockListReceive.Add(block); // Add even null, we cannot break the order
            }
            MyCubeGrid.CreateSplits(grid, m_tmpBlockListReceive, msg.Groups, false);

            m_tmpBlockListReceive.Clear();
        }
예제 #19
0
        private static void OnConvertedToShipRequest(MySyncGrid sync, ref ConvertToShipMsg msg, MyNetworkClient sender)
        {
            if (!sync.Entity.IsStatic)
            {
                Debug.Assert(false, "Grid was not static!");
                return;
            }

            if (Sync.IsServer)
                Sync.Layer.SendMessageToAllAndSelf(ref msg, MyTransportMessageEnum.Success);
        }
예제 #20
0
 private static void OnChangeDestructibleBlocks(MySyncGrid syncObject, ref ChangeDestructibleBlocksMsg msg, MyNetworkClient sender)
 {
     syncObject.Entity.DestructibleBlocks = msg.DestructionEnabled;
 }
예제 #21
0
        private static void OnConvertedToShipSuccess(MySyncGrid sync, ref ConvertToShipMsg msg, MyNetworkClient sender)
        {
            if (!sync.Entity.IsStatic)
            {
                Debug.Assert(false, "Grid was not static!");
                return;
            }

            sync.Entity.ConvertToDynamic();
        }
예제 #22
0
        private static void OnBuildBlocksAreaRequest(MySyncGrid sync, ref BuildBlocksAreaRequestMsg msg, MyNetworkClient sender)
        {
            Debug.Assert(sync.BlocksBuiltAreaRequest != null, "Handler should not be null, build messages will be ignored!");

            var handler = sync.BlocksBuiltAreaRequest;
            if (handler != null) handler(ref msg.Area, msg.OwnerId);
        }
예제 #23
0
 private static void OnMergeGridSuccess(MySyncGrid sync, ref MergeMsg msg, MyNetworkClient sender)
 {
     MyCubeGrid grid = null;
     if (MyEntities.TryGetEntityById<MyCubeGrid>(msg.OtherEntityId, out grid))
     {
         Vector3I gridOffset = msg.GridOffset;
         MatrixI transform = new MatrixI(msg.GridOffset, msg.GridForward, msg.GridUp);
         sync.Entity.MergeGridInternal(grid, ref transform);
     }
 }
예제 #24
0
        private static void OnRazeBlocksAreaRequest(MySyncGrid sync, ref RazeBlocksAreaRequestMsg msg, MyNetworkClient sender)
        {
            Debug.Assert(sync.BlocksRazeAreaRequest != null, "Handler should not be null, Raze messages will be ignored!");

            var handler = sync.BlocksRazeAreaRequest;
            if (handler != null) handler(ref msg.Pos, ref msg.Size);
        }
예제 #25
0
 private static void OnChangeOwnerRequest(MySyncGrid sync, ref ChangeOwnershipMsg msg, MyNetworkClient sender)
 {
     MyCubeBlock block = null;
     if (MyEntities.TryGetEntityById<MyCubeBlock>(msg.BlockId, out block))
     {
         if (Sync.IsServer && ((MyFakes.ENABLE_BATTLE_SYSTEM && MySession.Static.Battle && block.IDModule == null) || (block.IDModule.Owner == 0) || block.IDModule.Owner == msg.RequestingPlayer || (msg.Owner == 0)))
         {
             OnChangeOwner(sync, ref msg, sender);
             Sync.Layer.SendMessageToAll(ref msg, MyTransportMessageEnum.Success);
         }
         else
         {
             System.Diagnostics.Debug.Fail("Invalid ownership change request!");
         }
     }
 }
예제 #26
0
        private static void OnBuildBlocksRequest(MySyncGrid sync, ref BuildBlocksMsg msg, MyNetworkClient sender)
        {
            if (msg.Locations == null)
            {
                Debug.Fail("Invalid message");
                return;
            }

            m_tmpBuildList.Clear();
            Debug.Assert(m_tmpBuildList != msg.Locations, "The build block message was received via loopback using the temporary build list. This causes erasing ot the message.");

            MyEntity builder = null;
            MyEntities.TryGetEntityById(msg.BuilderEntityId, out builder);

            MyCubeBuilder.BuildComponent.GetBlocksPlacementMaterials(msg.Locations, sync.Entity);
            if (!MyCubeBuilder.BuildComponent.HasBuildingMaterials(builder))
                return;

            {
                var handler = sync.BlocksBuilt;
                if (handler != null) handler(ColorExtensions.UnpackHSVFromUint(msg.ColorMaskHsv), msg.Locations, m_tmpBuildList, builder);
            }

            if (Sync.IsServer && m_tmpBuildList.Count > 0)
            {
                // Broadcast to clients, use result collection
                msg.Locations = m_tmpBuildList;
                Sync.Layer.SendMessageToAll(ref msg);
            }

            {
                var handler = sync.AfterBlocksBuilt;
                if (handler != null) handler(m_tmpBuildList);
            }
        }
예제 #27
0
 private static void OnChangeOwner(MySyncGrid grid, ref ChangeOwnershipMsg msg, MyNetworkClient sender)
 {
     MyCubeBlock block = null;
     if (MyEntities.TryGetEntityById<MyCubeBlock>(msg.BlockId, out block))
     {
         block.ChangeOwner(msg.Owner, msg.ShareMode);
     }
 }
예제 #28
0
        private static void OnRazeBlockInCompoundBlockRequest(MySyncGrid sync, ref RazeBlockInCompoundBlockMsg msg, MyNetworkClient sender)
        {
            m_tmpLocationsAndIdsReceive.Clear();
            Debug.Assert(m_tmpLocationsAndIdsReceive != msg.LocationsAndIds, "The raze block in compound block message was received via loopback using the same list. This causes erasing of the message.");
            var handler = sync.RazedBlockInCompoundBlock;
            if (handler != null) handler(msg.LocationsAndIds, m_tmpLocationsAndIdsReceive);

            if (Sync.IsServer && m_tmpLocationsAndIdsReceive.Count > 0)
            {
                // Broadcast to clients, use result collection
                msg.LocationsAndIds = m_tmpLocationsAndIdsReceive;
                Sync.Layer.SendMessageToAll(ref msg);
            }
        }
예제 #29
0
 private static void OnChangeGridOwner(MySyncGrid syncObject, ref ChangeGridOwnershipMsg message, MyNetworkClient sender)
 {
     foreach (var block in syncObject.Entity.GetBlocks())
     {
         if (block.FatBlock != null && block.BlockDefinition.RatioEnoughForOwnership(block.BuildLevelRatio))
         {
             block.FatBlock.ChangeOwner(message.Owner, message.ShareMode);
         }
     }
 }
예제 #30
0
        private static void OnBonesMultiplied(MySyncGrid sync, ref BonesMultiplyMsg msg, MyNetworkClient sender)
        {
            var block = sync.Entity.GetCubeBlock(msg.Location);

            Debug.Assert(block != null, "Block was null in OnBonesMultiplied handler!");
            if (block == null) return;

            sync.Entity.MultiplyBlockSkeleton(block, msg.Multiplier);
        }
예제 #31
0
 private static void OnSetHandbrake(MySyncGrid syncObject, ref SetHandbrakeMsg msg, MyNetworkClient sender)
 {
     syncObject.Entity.GridSystems.WheelSystem.HandBrake = msg.Handbrake;
 }