<commit_before>using ACE.Database.Models.Shard;
using ACE.Database.Models.World;
using ACE.DatLoader;
using ACE.DatLoader.FileTypes;
using ACE.Entity;
using ACE.Entity.Enum;
using ACE.Entity.Enum.Properties;
using ACE.Server.Entity;
using ACE.Server.Entity.Actions;
using ACE.Server.Network.GameMessages.Messages;
using ACE.Server.Network.Motion;

namespace ACE.Server.WorldObjects
{
    public class PKModifier : WorldObject
    {
        /// <summary>
        /// A new biota be created taking all of its values from weenie.
        /// </summary>
        public PKModifier(Weenie weenie, ObjectGuid guid) : base(weenie, guid)
        {
            SetEphemeralValues();
        }

        /// <summary>
        /// Restore a WorldObject from the database.
        /// </summary>
        public PKModifier(Biota biota) : base(biota)
        {
            SetEphemeralValues();
        }

        private void SetEphemeralValues()
        {
            if (PkLevelModifier == -1)
                BaseDescriptionFlags |= ObjectDescriptionFlag.NpkSwitch;

            if (PkLevelModifier == 1)
                BaseDescriptionFlags |= ObjectDescriptionFlag.PkSwitch;
        }

        private static readonly UniversalMotion twitch = new UniversalMotion(MotionStance.Standing, new MotionItem(MotionCommand.Twitch1));

        public uint? AllowedActivator
        {
            get => GetProperty(PropertyInstanceId.AllowedActivator);
            set { if (!value.HasValue) RemoveProperty(PropertyInstanceId.AllowedActivator); else SetProperty(PropertyInstanceId.AllowedActivator, value.Value); }
        }

        public uint? UseTargetSuccessAnimation
        {
            get => GetProperty(PropertyDataId.UseTargetSuccessAnimation);
            set { if (!value.HasValue) RemoveProperty(PropertyDataId.UseTargetSuccessAnimation); else SetProperty(PropertyDataId.UseTargetSuccessAnimation, value.Value); }
        }

        public override void ActOnUse(ObjectGuid playerId)
        {
            var player = CurrentLandblock.GetObject(playerId) as Player;
            if (player == null)
            {
                return;
            }

            if (!player.IsWithinUseRadiusOf(this))
                player.DoMoveTo(this);
            else
            {
                //if (ServerIsPKServer) // Need some form of config switch in configmanager...
                //{
                //    player.Session.Network.EnqueueSend(new GameMessageSystemChat(GetProperty(PropertyString.UsePkServerError), ChatMessageType.Broadcast));
                //    player.SendUseDoneEvent();
                //    return;
                //}

                if (AllowedActivator == null)
                {
                    //if (player.PkLevelModifier == 0) // wrong check but if PkTimestamp + MINIMUM_TIME_SINCE_PK_FLOAT < Time.GetUnixTimestamp proceed else fail
                    //{
                    if ((player.PkLevelModifier ?? -1) != PkLevelModifier)
                    {
                        AllowedActivator = ObjectGuid.Invalid.Full;

                        var switchTimer = new ActionChain();
                        var turnToMotion = new UniversalMotion(MotionStance.Standing, Location, Guid);
                        turnToMotion.MovementTypes = MovementTypes.TurnToObject;
                        switchTimer.AddAction(this, () => player.CurrentLandblock.EnqueueBroadcastMotion(player, turnToMotion));
                        switchTimer.AddDelaySeconds(1);
                        switchTimer.AddAction(player, () =>
                        {
                            if (UseTargetSuccessAnimation.HasValue)
                                CurrentLandblock.EnqueueBroadcastMotion(this, new UniversalMotion(MotionStance.Standing, new MotionItem((MotionCommand)UseTargetSuccessAnimation)));
                            else
                                CurrentLandblock.EnqueueBroadcastMotion(this, twitch);
                        });
                        if (UseTargetSuccessAnimation.HasValue)
                            switchTimer.AddDelaySeconds(DatManager.PortalDat.ReadFromDat<MotionTable>(MotionTableId).GetAnimationLength((MotionCommand)UseTargetSuccessAnimation));
                        else
                            switchTimer.AddDelaySeconds(DatManager.PortalDat.ReadFromDat<MotionTable>(MotionTableId).GetAnimationLength(MotionCommand.Twitch1));
                        switchTimer.AddAction(player, () =>
                        {
                            player.Session.Network.EnqueueSend(new GameMessageSystemChat(GetProperty(PropertyString.UseMessage), ChatMessageType.Broadcast));
                            player.PkLevelModifier = PkLevelModifier;<commit_msg>Advocates cannot change their PK status<commit_after>using ACE.Database.Models.Shard;
using ACE.Database.Models.World;
using ACE.DatLoader;
using ACE.DatLoader.FileTypes;
using ACE.Entity;
using ACE.Entity.Enum;
using ACE.Entity.Enum.Properties;
using ACE.Server.Entity;
using ACE.Server.Entity.Actions;
using ACE.Server.Network.GameMessages.Messages;
using ACE.Server.Network.Motion;

namespace ACE.Server.WorldObjects
{
    public class PKModifier : WorldObject
    {
        /// <summary>
        /// A new biota be created taking all of its values from weenie.
        /// </summary>
        public PKModifier(Weenie weenie, ObjectGuid guid) : base(weenie, guid)
        {
            SetEphemeralValues();
        }

        /// <summary>
        /// Restore a WorldObject from the database.
        /// </summary>
        public PKModifier(Biota biota) : base(biota)
        {
            SetEphemeralValues();
        }

        private void SetEphemeralValues()
        {
            if (PkLevelModifier == -1)
                BaseDescriptionFlags |= ObjectDescriptionFlag.NpkSwitch;

            if (PkLevelModifier == 1)
                BaseDescriptionFlags |= ObjectDescriptionFlag.PkSwitch;
        }

        private static readonly UniversalMotion twitch = new UniversalMotion(MotionStance.Standing, new MotionItem(MotionCommand.Twitch1));

        public uint? AllowedActivator
        {
            get => GetProperty(PropertyInstanceId.AllowedActivator);
            set { if (!value.HasValue) RemoveProperty(PropertyInstanceId.AllowedActivator); else SetProperty(PropertyInstanceId.AllowedActivator, value.Value); }
        }

        public uint? UseTargetSuccessAnimation
        {
            get => GetProperty(PropertyDataId.UseTargetSuccessAnimation);
            set { if (!value.HasValue) RemoveProperty(PropertyDataId.UseTargetSuccessAnimation); else SetProperty(PropertyDataId.UseTargetSuccessAnimation, value.Value); }
        }

        public override void ActOnUse(ObjectGuid playerId)
        {
            var player = CurrentLandblock.GetObject(playerId) as Player;
            if (player == null)
            {
                return;
            }

            if (!player.IsWithinUseRadiusOf(this))
                player.DoMoveTo(this);
            else
            {
                //if (ServerIsPKServer) // Need some form of config switch in configmanager...
                //{
                //    player.Session.Network.EnqueueSend(new GameMessageSystemChat(GetProperty(PropertyString.UsePkServerError), ChatMessageType.Broadcast));
                //    player.SendUseDoneEvent();
                //    return;
                //}

                if (AllowedActivator == null)
                {
                    if (player.IsAdvocate || (player.AdvocateLevel > 0) || (player.AdvocateQuest ?? false) || (player.AdvocateState ?? false))
                    {
                        // Advocates cannot change their PK status
                        if (PkLevelModifier == 1)
                            return; // maybe send error msg to tell PK to ask another advocate to @remove them (or maybe make the @remove command support self removal)

                       // letting it fall through for the NpkSwitch because it will not change status and error properly.
                    }

                    //if (player.PkLevelModifier == 0) // wrong check but if PkTimestamp(? maybe different timestamp) + MINIMUM_TIME_SINCE_PK_FLOAT < Time.GetUnixTimestamp proceed else fail
                    //{
                    if ((player.PkLevelModifier ?? -1) != PkLevelModifier)
                    {
                        AllowedActivator = ObjectGuid.Invalid.Full;

                        var switchTimer = new ActionChain();
                        var turnToMotion = new UniversalMotion(MotionStance.Standing, Location, Guid);
                        turnToMotion.MovementTypes = MovementTypes.TurnToObject;
                        switchTimer.AddAction(this, () => player.CurrentLandblock.EnqueueBroadcastMotion(player, turnToMotion));
                        switchTimer.AddDelaySeconds(1);
                        switchTimer.AddAction(player, () =>
                        {
                            if (UseTargetSuccessAnimation.HasValue)
                                CurrentLandblock.EnqueueBroadcastMotion(this, new UniversalMotion(MotionStance.Standing, new MotionItem((MotionCommand)UseTargetSuccessAnimation)));
                            else
                                CurrentLandblock.EnqueueBroadcastMotion(this, twitch);
                        });
                        if (UseTargetSuccessAnimation.HasValue)
                            switchTimer.AddDelaySeconds(DatManager.PortalDat.ReadFromDat<MotionTable>(MotionTableId).GetAnimationLength((MotionCommand)UseTargetSuccessAnimation));
                        else
                            switchTimer.AddDelaySeconds(DatManager.PortalDat.ReadFromDat<MotionTable>(MotionTableId).GetAnimationLength(MotionCommand.Twitch1));
                        switchTimer.AddAction(player, () =>
                        {
                            player.Session.Network.EnqueueSend(new GameMessageSystemChat(GetProperty(PropertyString.UseMessage), ChatMessageType.Broadcast));
                            player.PkLevelModifier = PkLevelModifier;
{'fraction_non_alphanumeric': 0.08329211593629439, 'fraction_numerical': 0.0015827480462953804, 'mean_word_length': 1.9001721170395869, 'pattern_counts': {'":': 0, '<': 17, '<?xml version=': 0, '>': 26, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5206807', 'n_tokens_mistral': 2532, 'n_tokens_neox': 2380, 'n_words': 470}