Пример #1
0
        public static bool ServerHasAccess(
            IStaticWorldObject worldObject,
            ICharacter character,
            WorldObjectAccessMode currentAccessMode,
            bool writeToLog)
        {
            if (CreativeModeSystem.SharedIsInCreativeMode(character))
            {
                return(true);
            }

            switch (currentAccessMode)
            {
            case WorldObjectAccessMode.Closed:
            default:
                if (writeToLog)
                {
                    Logger.Warning(
                        $"Character cannot interact with {worldObject} - no access.",
                        character);

                    Instance.CallClient(
                        character,
                        _ => _.ClientRemote_OnCannotInteractNoAccess(worldObject));
                }

                return(false);

            case WorldObjectAccessMode.OpensToEveryone:
                return(true);

            case WorldObjectAccessMode.OpensToObjectOwners:
            case WorldObjectAccessMode.OpensToObjectOwnersOrAreaOwners:
            {
                if (WorldObjectOwnersSystem.SharedIsOwner(character, worldObject))
                {
                    // an object owner
                    return(true);
                }

                // not an object owner
                if (currentAccessMode == WorldObjectAccessMode.OpensToObjectOwnersOrAreaOwners)
                {
                    if (LandClaimSystem.SharedIsOwnedLand(worldObject.TilePosition, character, out _))
                    {
                        // an area owner
                        return(true);
                    }
                }

                // not an object owner and not an area owner
                if (writeToLog)
                {
                    WorldObjectOwnersSystem.ServerNotifyNotOwner(character, worldObject);
                }

                return(false);
            }
            }
        }
Пример #2
0
        private void ServerRemote_SetMode(IStaticWorldObject worldObject, WorldObjectAccessMode mode)
        {
            var character = ServerRemoteContext.Character;

            if (!InteractionCheckerSystem.SharedHasInteraction(character,
                                                               worldObject,
                                                               requirePrivateScope: true))
            {
                throw new Exception("The player character is not interacting with " + worldObject);
            }

            if (!WorldObjectOwnersSystem.SharedIsOwner(character, worldObject) &&
                !CreativeModeSystem.SharedIsInCreativeMode(character))
            {
                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);
        }
Пример #3
0
 public static void ClientSetMode(IStaticWorldObject worldObject, WorldObjectAccessMode mode)
 {
     Instance.CallServer(_ => _.ServerRemote_SetMode(worldObject, mode));
 }