private void ServerRemote_SetMode(IStaticWorldObject worldObject, WorldObjectAccessMode mode) { var character = ServerRemoteContext.Character; if (!InteractionCheckerSystem.HasInteraction(character, worldObject, requirePrivateScope: true)) { throw new Exception("The player character is not interacting with " + worldObject); } if (!WorldObjectOwnersSystem.SharedIsOwner(character, worldObject)) { throw new Exception("The player character is not the owner of " + worldObject); } if (!(worldObject.ProtoStaticWorldObject is IProtoObjectWithAccessMode protoObjectWithAccessMode)) { throw new Exception("This world object doesn't have an access mode"); } if (mode == WorldObjectAccessMode.Closed && !protoObjectWithAccessMode.IsClosedAccessModeAvailable) { throw new Exception("Closed access mode is not supported for " + protoObjectWithAccessMode); } var privateState = worldObject.GetPrivateState <IObjectWithAccessModePrivateState>(); privateState.AccessMode = mode; Logger.Important($"Access mode changed: {mode}; {worldObject}", character); }
private void ServerRemote_SetServerMode(IStaticWorldObject lightObject, ObjectLightMode mode) { var character = ServerRemoteContext.Character; if (!InteractionCheckerSystem.HasInteraction(character, lightObject, requirePrivateScope: true)) { throw new Exception("The player character is not interacting with the light object"); } var privateState = GetPrivateState(lightObject); var publicState = GetPublicState(lightObject); privateState.Mode = mode; Logger.Important($"Light mode changed: {mode}, light: {lightObject}", character); this.ServerUpdateLight(lightObject, privateState, publicState, deltaTime: 0); }
public static string ServerSetOwners( IStaticWorldObject worldObject, List <string> newOwners, NetworkSyncList <string> currentOwners, ICharacter byOwner) { if (!InteractionCheckerSystem.HasInteraction(ServerRemoteContext.Character, worldObject, requirePrivateScope: true)) { throw new Exception("The player character is not interacting with " + worldObject); } if (!currentOwners.Contains(byOwner.Name)) { return(DialogCannotSetOwners_MessageNotOwner); } if (!((IProtoObjectWithOwnersList)worldObject.ProtoStaticWorldObject) .SharedCanEditOwners(worldObject, byOwner)) { return(DialogCannotSetOwners_MessageCannotEdit); } currentOwners.GetDiff(newOwners, out var ownersToAdd, out var ownersToRemove); if (currentOwners.Count - ownersToRemove.Count <= 0) { return(DialogCannotSetOwners_MessageCannotRemoveLastOwner); } if (ownersToRemove.Contains(byOwner.Name)) { return(DialogCannotSetOwners_MessageCannotRemoveSelf); } if (ownersToAdd.Count == 0 && ownersToRemove.Count == 0) { Logger.Warning( "No need to change the owners - the new owners list is the same as the current owners list: " + worldObject, characterRelated: byOwner); return(null); } foreach (var n in ownersToAdd) { var name = n; var playerToAdd = Api.Server.Characters.GetPlayerCharacter(name); if (playerToAdd == null) { return(string.Format(DialogCannotSetOwners_MessageFormatPlayerNotFound, name)); } // get proper player name name = playerToAdd.Name; if (currentOwners.AddIfNotContains(name)) { Api.Logger.Important($"Added owner: {name}; {worldObject}", characterRelated: byOwner); } } foreach (var name in ownersToRemove) { if (!currentOwners.Remove(name)) { continue; } Api.Logger.Important($"Removed owner: {name}; {worldObject}", characterRelated: byOwner); var removedPlayer = Api.Server.Characters.GetPlayerCharacter(name); if (removedPlayer == null) { continue; } InteractableStaticWorldObjectHelper.ServerTryAbortInteraction(removedPlayer, worldObject); } ServerInvokeOwnersChangedEvent(worldObject); return(null); }
public ObjectLandClaimCanUpgradeCheckResult SharedCanUpgrade( IStaticWorldObject worldObjectLandClaim, IProtoObjectLandClaim protoUpgradedLandClaim, ICharacter character, out IConstructionUpgradeEntryReadOnly upgradeEntry, bool writeErrors = true) { upgradeEntry = null; foreach (var entry in this.ConfigUpgrade.Entries) { if (entry.ProtoStructure == protoUpgradedLandClaim) { upgradeEntry = entry; break; } } var currentLandClaimArea = GetPublicState(worldObjectLandClaim).LandClaimAreaObject; var founderName = LandClaimArea.GetPrivateState(currentLandClaimArea).LandClaimFounder; var result = ObjectLandClaimCanUpgradeCheckResult.Success; if (upgradeEntry == null) { result = ObjectLandClaimCanUpgradeCheckResult.ErrorUnknown; } if (result == ObjectLandClaimCanUpgradeCheckResult.Success) { if (character.Name != founderName) { result = ObjectLandClaimCanUpgradeCheckResult.ErrorNotFounder; } } if (result == ObjectLandClaimCanUpgradeCheckResult.Success) { // validate player know the tech, have enough items, etc if (!upgradeEntry.CheckRequirementsSatisfied(character)) { upgradeEntry = null; result = ObjectLandClaimCanUpgradeCheckResult.ErrorRequirementsNotSatisfied; } } if (result == ObjectLandClaimCanUpgradeCheckResult.Success) { // check there will be no intersection with other areas if (!LandClaimSystem.SharedCheckCanPlaceOrUpgradeLandClaimThere(protoUpgradedLandClaim, worldObjectLandClaim.TilePosition, character)) { result = ObjectLandClaimCanUpgradeCheckResult.ErrorAreaIntersection; } } if (result == ObjectLandClaimCanUpgradeCheckResult.Success) { if (!InteractionCheckerSystem.HasInteraction(character, worldObjectLandClaim, requirePrivateScope: true)) { result = ObjectLandClaimCanUpgradeCheckResult.ErrorNoActiveInteraction; } } if (writeErrors && result != ObjectLandClaimCanUpgradeCheckResult.Success) { Logger.Warning( $"Can\'t upgrade: {worldObjectLandClaim} to {protoUpgradedLandClaim}: error code - {result}", character); } return(result); }