Example #1
0
        public static void ServerTryClaim(
            IWorldObject worldObject,
            ICharacter character,
            double durationSeconds,
            bool claimForPartyMembers = true)
        {
            if (!SharedIsEnabled)
            {
                return;
            }

            if (worldObject is null ||
                character is null ||
                character.IsNpc ||
                durationSeconds <= 0)
            {
                return;
            }

            var worldObjectPublicState = worldObject.AbstractPublicState as IWorldObjectPublicStateWithClaim;

            if (worldObjectPublicState is null)
            {
                Logger.Warning(
                    $"{worldObject} doesn't implement {nameof(IWorldObjectPublicStateWithClaim)} - cannot claim it");
                return;
            }

            var objectClaim = worldObjectPublicState.WorldObjectClaim;

            if (objectClaim is not null)
            {
                // already claimed
                WorldObjectClaim.ServerTryExtendClaim(objectClaim, character, durationSeconds);
                return;
            }

            objectClaim = Server.World.CreateLogicObject <WorldObjectClaim>();
            WorldObjectClaim.ServerSetupClaim(objectClaim,
                                              character,
                                              worldObject,
                                              durationSeconds,
                                              claimForPartyMembers);
            worldObjectPublicState.WorldObjectClaim = objectClaim;
            //Logger.Dev("World object claim added: " + worldObject);

            if (worldObject.ProtoGameObject is ObjectGroundItemsContainer)
            {
                // set custom timeout for the ground items container to ensure it cannot be removed from the world
                // before the claim expires
                ObjectGroundItemsContainer.ServerSetDestructionTimeout(
                    (IStaticWorldObject)worldObject,
                    durationSeconds);
            }
        }
        public static ICharacter ServerGetCharacterByClaim(ILogicObject objectClaim)
        {
            if (!SharedIsEnabled)
            {
                return(null);
            }

            if (objectClaim is null)
            {
                return(null);
            }

            var playerCharacterId = WorldObjectClaim.GetPublicState(objectClaim).PlayerCharacterId;

            return(Server.World.GetGameObjectById <ICharacter>(GameObjectType.Character, playerCharacterId));
        }
        public static bool SharedIsAllowInteraction(
            ICharacter character,
            IStaticWorldObject worldObject,
            bool showClientNotification)
        {
            if (!SharedIsEnabled)
            {
                return(true);
            }

            if (character is null ||
                !PveSystem.SharedIsPve(clientLogErrorIfDataIsNotYetAvailable: false))
            {
                return(true);
            }

            var worldObjectPublicState = worldObject.AbstractPublicState as IWorldObjectPublicStateWithClaim;

            if (worldObjectPublicState?.WorldObjectClaim is null ||
                WorldObjectClaim.SharedIsClaimedForPlayer(worldObjectPublicState.WorldObjectClaim, character))
            {
                return(true);
            }

            if (IsClient && showClientNotification)
            {
                NotificationSystem.ClientShowNotification(
                    CoreStrings.WorldObjectClaim_Title,
                    CoreStrings.WorldObjectClaim_Description
                    + "[br]"
                    + CoreStrings.WorldObjectClaim_Description2,
                    NotificationColor.Bad,
                    icon: TextureResourceClaimedObject);
            }

            return(false);
        }