<commit_before>﻿using System;
using System.Collections.Generic;
using Rocket.API;
using Rocket.Core.Logging;
using Rocket.Unturned.Player;
using Safezone.Util;

namespace Safezone.Model.Flag.Impl
{
    public class GodmodeFlag : BoolFlag
    {
        private readonly Dictionary<uint, bool> _godModeStates = new Dictionary<uint, bool>();
        public override string Description => "Gives players in safezone godmode";

        public override object DefaultValue => true;
        public override void UpdateState(List<UnturnedPlayer> players)
        {
            //do nothing
        }

        public override void OnSafeZoneEnter(UnturnedPlayer player)
        {
            if (!GetValue<bool>(SafeZone.GetGroup(player))) return;
            EnableGodMode(player);
        }

        public override void OnSafeZoneLeave(UnturnedPlayer player)
        {
            if (!GetValue<bool>(SafeZone.GetGroup(player))) return;
            DisableGodMode(player);
        }

        private void EnableGodMode(IRocketPlayer player)
        {
            if (!(player is UnturnedPlayer))
            {
                throw new NotSupportedException();
            }
            var id = PlayerUtil.GetId(player);<commit_msg>Godmode Flag: restore health when leaving safezone<commit_after>﻿using System;
using System.Collections.Generic;
using Rocket.API;
using Rocket.Core.Logging;
using Rocket.Unturned.Player;
using Safezone.Util;
using SDG.Unturned;
using Steamworks;
using UnityEngine;

namespace Safezone.Model.Flag.Impl
{
    public class GodmodeFlag : BoolFlag
    {
        private readonly Dictionary<uint, bool> _godModeStates = new Dictionary<uint, bool>();
        public override string Description => "Gives players in safezone godmode";
        public override object DefaultValue => true;
        private readonly Dictionary<ulong, byte> lastHealth = new Dictionary<ulong, byte>();
         
        public override void UpdateState(List<UnturnedPlayer> players)
        {
            //do nothing
        }

        public override void OnSafeZoneEnter(UnturnedPlayer player)
        {
            var steamId = PlayerUtil.GetCSteamId(player);
            if (steamId == CSteamID.Nil) return;
            lastHealth.Add(steamId.m_SteamID, player.Health);
            if (!GetValue<bool>(SafeZone.GetGroup(player))) return;
            EnableGodMode(player);
        }

        public override void OnSafeZoneLeave(UnturnedPlayer player)
        {
            if (!GetValue<bool>(SafeZone.GetGroup(player))) return;
            DisableGodMode(player);
            var steamId = PlayerUtil.GetCSteamId(player);
            if (steamId == CSteamID.Nil) return;

            var health = lastHealth[steamId.m_SteamID];
            var currentHealth = player.Health;
            if (currentHealth < health)
            {
                player.Heal((byte) (health - currentHealth));
            }
            else
            {
                player.Damage((byte) (currentHealth-health), Vector3.zero, EDeathCause.KILL, ELimb.SPINE, CSteamID.Nil)
            }
        }

        private void EnableGodMode(IRocketPlayer player)
        {
            if (!(player is UnturnedPlayer))
            {
                throw new NotSupportedException();
            }
            var id = PlayerUtil.GetId(player);
{'fraction_non_alphanumeric': 0.08781954887218045, 'fraction_numerical': 0.0003007518796992481, 'mean_word_length': 2.2898120672601383, 'pattern_counts': {'":': 0, '<': 16, '<?xml version=': 0, '>': 19, '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': '4528465', 'n_tokens_mistral': 895, 'n_tokens_neox': 855, 'n_words': 212}