private void FixOwnerAndAuthorShip(MyCubeGrid myCubeGrid, string playername) { HashSet <long> authors = new HashSet <long>(); HashSet <MySlimBlock> blocks = new HashSet <MySlimBlock>(myCubeGrid.GetBlocks()); var player = utils.GetPlayerByNameOrId(playername); MyPlayer id = MySession.Static.Players.TryGetPlayerBySteamId(player.SteamUserId); foreach (MySlimBlock block in blocks) { if (block == null || block.CubeGrid == null || block.IsDestroyed) { continue; } MyCubeBlock cubeBlock = block.FatBlock; if (cubeBlock != null && cubeBlock.OwnerId != player.Identity.IdentityId) { myCubeGrid.ChangeOwnerRequest(myCubeGrid, cubeBlock, 0, MyOwnershipShareModeEnum.Faction); if (player.IdentityId != 0) { myCubeGrid.ChangeOwnerRequest(myCubeGrid, cubeBlock, player.IdentityId, MyOwnershipShareModeEnum.Faction); } } if (block.BuiltBy == 0) { /* * Hack: TransferBlocksBuiltByID only transfers authorship if it has an author. * Transfer Authorship Client just sets the author so we need to take care of limits ourselves. */ block.TransferAuthorshipClient(player.IdentityId); block.AddAuthorship(); } authors.Add(block.BuiltBy); IMyCharacter character = player.Character; if (cubeBlock is Sandbox.ModAPI.IMyCockpit cockpit && cockpit.CanControlShip) { cockpit.AttachPilot(character); } } foreach (long author in authors) { MyMultiplayer.RaiseEvent(myCubeGrid, x => new Action <long, long>(x.TransferBlocksBuiltByID), author, player.IdentityId, new EndpointId()); } }
public static bool Repair(MyGroups <MyCubeGrid, MyGridPhysicalGroupData> .Group group, CommandContext Context) { foreach (MyGroups <MyCubeGrid, MyGridPhysicalGroupData> .Node groupNodes in group.Nodes) { MyCubeGrid grid = groupNodes.NodeData; var gridOwner = OwnershipUtils.GetOwner(grid); HashSet <MySlimBlock> blocks = grid.GetBlocks(); foreach (MySlimBlock block in blocks) { long owner = block.OwnerId; if (owner == 0) { owner = gridOwner; } if (block.CurrentDamage > 0 || block.HasDeformation) { block.ClearConstructionStockpile(null); block.IncreaseMountLevel(block.MaxIntegrity, owner, null, 10000, true); MyCubeBlock cubeBlock = block.FatBlock; if (cubeBlock != null) { grid.ChangeOwnerRequest(grid, cubeBlock, 0, MyOwnershipShareModeEnum.Faction); if (owner != 0) { grid.ChangeOwnerRequest(grid, cubeBlock, owner, MyOwnershipShareModeEnum.Faction); } } } } } return(true); }