public static bool PatchOnChangeOwnersRequest(List <MyCubeGrid.MySingleOwnershipRequest> requests, long requestingPlayer) { StringBuilder sb = new StringBuilder(); /* No Requests nothing to do */ if (requests == null) { return(true); } string resquesterName = PlayerUtils.GetPlayerNameById(requestingPlayer); string requestFactionTag = PlayerUtils.GetFactionTagStringForPlayer(requestingPlayer); /* Dont want to print the grid information over and over again. */ bool first = true; foreach (MyCubeGrid.MySingleOwnershipRequest request in requests) { MyCubeBlock block = MyEntities.GetEntityById(request.BlockId, false) as MyCubeBlock; /* No block found, or different ownership? */ if (block == null) { continue; } /* No Grid? unlikely but ignore */ MyCubeGrid grid = block.CubeGrid; if (grid == null) { continue; } string gridName = grid.DisplayName; string oldOwnerName = PlayerUtils.GetPlayerNameById(block.OwnerId); string newOwnerName = PlayerUtils.GetPlayerNameById(request.Owner); if (oldOwnerName == newOwnerName) { return(true); } bool isOnline = PlayerUtils.isOnline(block.OwnerId); string onlineString = "[Off]"; if (isOnline) { onlineString = "[On]"; } string oldFactionTag = PlayerUtils.GetFactionTagStringForPlayer(block.OwnerId); string newFactionTag = PlayerUtils.GetFactionTagStringForPlayer(request.Owner); string oldName = oldOwnerName + " " + onlineString + oldFactionTag; string newName = newOwnerName + " " + newFactionTag; string location = GetLocationWhenNeeded(block); /* Opening statement */ if (first) { sb.AppendLine("Player " + resquesterName + " " + requestFactionTag + " requested the following ownership changes on grid: '" + gridName + "'"); first = false; } sb.AppendLine(" block " + block.BlockDefinition.BlockPairName.PadRight(20) + " from " + oldName.PadRight(25) + " to " + newName.PadRight(20) + location); } Log.Info(sb); return(true); }
public static void PatchOnDestroyRequest(MyCubeBlock __instance) { MyCubeBlock block = __instance; if (block as MyTerminalBlock == null) { return; } MyCubeGrid grid = block.CubeGrid; string gridName = grid.DisplayName; string oldOwnerName = PlayerUtils.GetPlayerNameById(block.OwnerId); bool isOnline = PlayerUtils.isOnline(block.OwnerId); string onlineString = "[Off]"; if (isOnline) { onlineString = "[On]"; } string oldFactionTag = PlayerUtils.GetFactionTagStringForPlayer(block.OwnerId); string oldName = oldOwnerName + " " + onlineString + oldFactionTag; string causeName = "[Unknown]"; ChangingEntity cause = OwnershipLoggerPlugin.Instance.DamageCache.Get(block.EntityId); string additionalInfo = null; if (cause != null) { additionalInfo = cause.AdditionalInfo; if (!cause.IsPlanet) { long causeId; if (cause.Controller != 0L) { causeId = cause.Controller; } else { causeId = cause.Owner; } /* Can be offline when weapons are the cause */ bool isCauseOnline = PlayerUtils.isOnline(causeId); string causeOnlineString = "[Off]"; if (isCauseOnline) { causeOnlineString = "[On]"; } string causePlayerName = PlayerUtils.GetPlayerNameById(causeId); string causeFactionTag = PlayerUtils.GetFactionTagStringForPlayer(causeId); causeName = (causePlayerName + " " + causeOnlineString + causeFactionTag).PadRight(25) + " with " + cause.ChangingCause; } else { causeName = "Planet".PadRight(25) + " with " + cause.ChangingCause; } } string blockpairName = block.BlockDefinition.BlockPairName; blockpairName = ChangeName(additionalInfo, blockpairName); string location = GetLocationWhenNeeded(block); Log.Info(causeName.PadRight(45) + " destroyed block " + blockpairName.PadRight(20) + " from " + oldName.PadRight(25) + " " + "".PadRight(20) + " of grid: " + gridName + location); }
public static bool PatchChangeOwnerRequest( MyCubeGrid grid, MyCubeBlock block, long playerId, MyOwnershipShareModeEnum shareMode) { string gridName = grid.DisplayName; string oldOwnerName = PlayerUtils.GetPlayerNameById(block.OwnerId); string newOwnerName = PlayerUtils.GetPlayerNameById(playerId); /* Only shared mode was changed */ if (oldOwnerName == newOwnerName) { return(true); } bool isOnline = PlayerUtils.isOnline(block.OwnerId); string onlineString = "[Off]"; if (isOnline) { onlineString = "[On]"; } string oldFactionTag = PlayerUtils.GetFactionTagStringForPlayer(block.OwnerId); string newFactionTag = PlayerUtils.GetFactionTagStringForPlayer(playerId); string oldName = oldOwnerName + " " + onlineString + oldFactionTag; string newName = newOwnerName + " " + newFactionTag; string causeName = "[Unknown]"; ChangingEntity cause = OwnershipLoggerPlugin.Instance.DamageCache.Get(block.EntityId); string additionalInfo = null; if (playerId == 0L && cause != null) { additionalInfo = cause.AdditionalInfo; if (!cause.IsPlanet) { long causeId; if (cause.Controller != 0L) { causeId = cause.Controller; } else { causeId = cause.Owner; } /* Can be offline when weapons are the cause */ bool isCauseOnline = PlayerUtils.isOnline(causeId); string causeOnlineString = "[Off]"; if (isCauseOnline) { causeOnlineString = "[On]"; } string causePlayerName = PlayerUtils.GetPlayerNameById(causeId); string causeFactionTag = PlayerUtils.GetFactionTagStringForPlayer(causeId); causeName = (causePlayerName + " " + causeOnlineString + causeFactionTag).PadRight(25) + " with " + cause.ChangingCause; } else { causeName = "Planet".PadRight(25) + " with " + cause.ChangingCause; } } else if (playerId != 0L) { /* Can be offline when weapons are the cause */ bool isCauseOnline = PlayerUtils.isOnline(playerId); string causeOnlineString = "[Off]"; if (isCauseOnline) { causeOnlineString = "[On]"; } /* Must be Online then */ causeName = newOwnerName + " " + causeOnlineString + newFactionTag; } string blockpairName = block.BlockDefinition.BlockPairName; blockpairName = ChangeName(additionalInfo, blockpairName); string location = GetLocationWhenNeeded(block); Log.Info(causeName.PadRight(45) + " changed owner on block " + blockpairName.PadRight(20) + " from " + oldName.PadRight(25) + " to " + newName.PadRight(20) + " on grid: " + gridName + location); return(true); }