<commit_before>﻿using System;
using System.Collections;
using System.Collections.Generic;
using Atmospherics;
using UnityEngine;
using Mirror;
using UnityEngine.Events;
using System.Linq;
using UnityEngine.UI;

public class ItemMagBoots : NetworkBehaviour,
	IServerActionGUI, IClientInventoryMove,IServerInventoryMove
{
	[SyncVar(hook = nameof(SyncState))]
	private bool isOn = false;

	public GameObject spriteObject;
	private SpriteHandler spriteHandler;

	[Tooltip("For UI button, 0 = off , 1 = on")]
	public Sprite[] sprites;

	public  SpriteSheetAndData[] spriteSheets;

	private ConnectedPlayer player;
	private ItemAttributesV2 itemAttributesV2;
	private Pickupable pick;

	[Tooltip("The speed debuff to apply to run speed.")]
	[SerializeField]
	private float runSpeedDebuff = 1.5f;


	[SerializeField]
	private ActionData actionData = null;
	public ActionData ActionData => actionData;

	private PlayerMove playerMove;

	private void Awake()
	{
		pick = GetComponent<Pickupable>();
		spriteHandler = spriteObject.GetComponent<SpriteHandler>();
		itemAttributesV2 = GetComponent<ItemAttributesV2>();
		pick.RefreshUISlotImage();
	}

	private void ToggleBoots()
	{
		if(player == null )
		{
			return;
		}
		if (isOn)
		{
			itemAttributesV2.AddTrait(CommonTraits.Instance.NoSlip);
			ApplySpeedDebuff();

		}
		else
		{
			itemAttributesV2.RemoveTrait(CommonTraits.Instance.NoSlip);
			RemoveSpeedDebuff();
		}
		//if the ghost NRE will be thrown
		player.Script.pushPull.ServerSetPushable(!isOn);
	}

	private void SyncState(bool oldVar, bool newVar)
	{
		isOn = newVar;
		spriteHandler.ChangeSprite(isOn ? 1 : 0);
		pick.RefreshUISlotImage();
		ToggleBoots();
	}

	public void ServerChangeState(ConnectedPlayer newPlayer)
	{
		this.player = newPlayer;
		isOn = !isOn;
	}

	private void OnPlayerDeath()
	{
		if (isServer)
		{
			if (isOn)
			{
				ServerChangeState(this.player);
			}
			UIActionManager.Toggle(this, false);
			// player.Script.playerHealth.OnDeathNotifyEvent -= OnPlayerDeath;
			player = null;
		}
		else
		{
			UIActionManager.Toggle(this, false);
		}

	}

	private void ApplySpeedDebuff()
	{
		playerMove.ServerChangeSpeed(run: playerMove.runSpeed - runSpeedDebuff);
	}

	private void RemoveSpeedDebuff()
	{
		playerMove.ServerChangeSpeed(run: playerMove.runSpeed + runSpeedDebuff);
	}

	#region UI related

	public void OnInventoryMoveServer(InventoryMove info)
	{
		if (IsPuttingOn(info) & isOn)
		{
			ApplySpeedDebuff();
		}
		else if (IsTakingOff(info) & isOn)
		{
			ServerChangeState(player);
			RemoveSpeedDebuff();
		}
	}

	private bool IsPuttingOn (InventoryMove info)
	{
		if (info.ToSlot == null | info.ToSlot?.NamedSlot == null)
		{
			return false;
		}
		playerMove = info.ToRootPlayer?.PlayerScript.playerMove;

		return playerMove != null && info.ToSlot.NamedSlot == NamedSlot.feet;
	}

	private bool IsTakingOff (InventoryMove info)
	{
		if (info.FromSlot == null | info.FromSlot?.NamedSlot == null)
		{
			return false;
		}
		playerMove = info.FromRootPlayer?.PlayerScript.playerMove;

		return playerMove != null && info.FromSlot.NamedSlot == NamedSlot.feet;
	}

	// Client only method
	public void OnInventoryMoveClient(ClientInventoryMove info)
	{
		var hand = PlayerManager.LocalPlayerScript.playerNetworkActions;
		//when item is moved and player has it on his feet
		if (hand.GetActiveItemInSlot(NamedSlot.feet) != null && hand.GetActiveItemInSlot(NamedSlot.feet) == gameObject)
		{
			UIActionManager.Toggle(this, true);
			UIActionManager.SetSprite(this, (sprites[0]));
		}
		else
		{
			UIActionManager.Toggle(this, false);
		}
	}

	public void CallActionClient()
	{
		UIActionManager.SetSprite(this, (!isOn ? sprites[1] : sprites[0]));
	}

	public void CallActionServer(ConnectedPlayer SentByPlayer)
	{
		ServerChangeState(SentByPlayer);
	}

	#endregion
}<commit_msg>rewrite Magboots part 2<commit_after>﻿using System;
using System.Collections;
using System.Collections.Generic;
using Atmospherics;
using UnityEngine;
using Mirror;
using UnityEngine.Events;
using System.Linq;
using UnityEngine.UI;

public class ItemMagBoots : NetworkBehaviour,
	IServerActionGUI, IClientInventoryMove,IServerInventoryMove
{
	[SyncVar(hook = nameof(SyncIsOn))]private bool isOn = false;

	public GameObject spriteObject;
	private SpriteHandler spriteHandler;

	[Tooltip("For UI button, 0 = off , 1 = on")]
	public Sprite[] sprites;

	public  SpriteSheetAndData[] spriteSheets;

	private ConnectedPlayer player;
	private ItemAttributesV2 itemAttributesV2;
	private Pickupable pick;

	[Tooltip("The speed debuff to apply to run speed.")]
	[SerializeField]
	private float runSpeedDebuff = 1.5f;


	[SerializeField]
	private ActionData actionData = null;
	public ActionData ActionData => actionData;

	private PlayerMove playerMove;

	private void Awake()
	{
		pick = GetComponent<Pickupable>();
		spriteHandler = spriteObject.GetComponent<SpriteHandler>();
		itemAttributesV2 = gameObject.GetComponent<ItemAttributesV2>();
		pick.RefreshUISlotImage();
	}

	public void OnInventoryMoveServer(InventoryMove info)
	{
		if (IsPuttingOn(info))
		{
			playerMove = info.ToRootPlayer.PlayerScript.playerMove;
		}

		else if (IsTakingOff(info) & isOn)
		{
			playerMove = info.FromRootPlayer.PlayerScript.playerMove;
			isOn = !isOn;
			RemoveEffect();
		}
	}

	private static bool IsPuttingOn (InventoryMove info)
	{
		if (info.ToSlot == null | info.ToSlot?.NamedSlot == null)
		{
			return false;
		}
		return info.ToSlot.NamedSlot == NamedSlot.feet;
	}

	private static bool IsTakingOff (InventoryMove info)
	{
		if (info.FromSlot == null | info.FromSlot?.NamedSlot == null)
		{
			return false;
		}
		return info.FromSlot.NamedSlot == NamedSlot.feet;
	}

	private void ApplyEffect()
	{
		itemAttributesV2.AddTrait(CommonTraits.Instance.NoSlip);
		playerMove.ServerChangeSpeed(run: playerMove.runSpeed - runSpeedDebuff);
		playerMove.PlayerScript.pushPull.ServerSetPushable(false);
	}

	private void RemoveEffect()
	{
		itemAttributesV2.RemoveTrait(CommonTraits.Instance.NoSlip);
		playerMove.ServerChangeSpeed(run: playerMove.runSpeed + runSpeedDebuff);
		playerMove.PlayerScript.pushPull.ServerSetPushable(true);
	}

	[Server]
	public void ServerChangeState(ConnectedPlayer newPlayer)
	{
		isOn = !isOn;
		newPlayer = newPlayer;

		if (isOn)
		{
			ApplyEffect();
		}
		else
		{
			RemoveEffect();
		}
	}

	private void SyncIsOn(bool oldIsOn, bool newIsOn)
	{
		isOn = newIsOn;
		spriteHandler.ChangeSprite(isOn ? 1 : 0);
		pick.RefreshUISlotImage();
	}

	private void OnPlayerDeath()
	{
		if (isServer)
		{
			if (isOn)
			{
				ServerChangeState(player);
			}
			UIActionManager.Toggle(this, false);
			player.Script.playerHealth.OnDeathNotifyEvent -= OnPlayerDeath;
			player = null;
		}
		else
		{
			UIActionManager.Toggle(this, false);
		}
	}

	#region UI
	public void OnInventoryMoveClient(ClientInventoryMove info)
	{
		var pna = PlayerManager.LocalPlayerScript.playerNetworkActions;
		if (info.ClientInventoryMoveType == ClientInventoryMoveType.Added
		    & pna.GetActiveItemInSlot(NamedSlot.feet)?.gameObject == gameObject)
		{
			UIActionManager.Toggle(this, true);
			UIActionManager.SetSprite(this, (sprites[0]));
		}
		else if (info.ClientInventoryMoveType == ClientInventoryMoveType.Removed
		         & pna.GetActiveItemInSlot(NamedSlot.feet)?.gameObject != gameObject)
		{
			UIActionManager.Toggle(this, false);
		}
	}

	public void CallActionClient()
	{
		UIActionManager.SetSprite(this, (!isOn ? sprites[1] : sprites[0]));
	}

	public void CallActionServer(ConnectedPlayer SentByPlayer)
	{
		ServerChangeState(SentByPlayer);
	}

	#endregion
	// private void Awake()
	// {
	//
	// 	spriteHandler = spriteObject.GetComponent<SpriteHandler>();
	// 	itemAttributesV2 = GetComponent<ItemAttributesV2>();
	// 	pick.RefreshUISlotImage();
	// }
	//
	// private void ToggleBoots()
	// {
	// 	if(player == null )
	// 	{
	// 		return;
	// 	}
	// 	if (isOn)
	// 	{
	// 		itemAttributesV2.AddTrait(CommonTraits.Instance.NoSlip);
	// 		ApplySpeedDebuff();
	//
	// 	}
	// 	else
	// 	{
	// 		itemAttributesV2.RemoveTrait(CommonTraits.Instance.NoSlip);
	// 		RemoveSpeedDebuff();
	// 	}
	// 	//if the ghost NRE will be thrown
	// 	player.Script.pushPull.ServerSetPushable(!isOn);
	// }
	//
	// private void SyncState(bool oldVar, bool newVar)
	// {
	// 	isOn = newVar;
	// 	spriteHandler.ChangeSprite(isOn ? 1 : 0);
	// 	pick.RefreshUISlotImage();
	// 	ToggleBoots();
	// }
	//
	// public void ServerChangeState(ConnectedPlayer newPlayer)
	// {
	// 	this.player = newPlayer;
	// 	isOn = !isOn;
	// }
	//
	// private void OnPlayerDeath()
	// {
	// 	if (isServer)
	// 	{
	// 		if (isOn)
	// 		{
	// 			ServerChangeState(this.player);
	// 		}
	// 		UIActionManager.Toggle(this, false);
	// 		// player.Script.playerHealth.OnDeathNotifyEvent -= OnPlayerDeath;
	// 		player = null;
	// 	}
	// 	else
	// 	{
	// 		UIActionManager.Toggle(this, false);
	// 	}
	//
	// }
	//
	// private void ApplySpeedDebuff()
	// {
	// 	playerMove.ServerChangeSpeed(run: playerMove.runSpeed - runSpeedDebuff);
	// }
	//
	// private void RemoveSpeedDebuff()
	// {
	// 	playerMove.ServerChangeSpeed(run: playerMove.runSpeed + runSpeedDebuff);
	// }
	//
	// #region UI related
	//
	// public void OnInventoryMoveServer(InventoryMove info)
	// {
	// 	if (IsTakingOff(info) & isOn)
	// 	{
	// 		ServerChangeState(player);
	// 	}
	// }
	//
	// private bool IsPuttingOn (InventoryMove info)
	// {
	// 	if (info.ToSlot == null | info.ToSlot?.NamedSlot == null)
	// 	{
	// 		return false;
	// 	}
	// 	playerMove = info.ToRootPlayer?.PlayerScript.playerMove;
	//
	// 	return playerMove != null && info.ToSlot.NamedSlot == NamedSlot.feet;
	// }
	//
	// private bool IsTakingOff (InventoryMove info)
	// {
	// 	if (info.FromSlot == null | info.FromSlot?.NamedSlot == null)
	// 	{
	// 		return false;
	// 	}
	// 	playerMove = info.FromRootPlayer?.PlayerScript.playerMove;
	//
	// 	return playerMove != null && info.FromSlot.NamedSlot == NamedSlot.feet;
	// }
	//
	// // Client only method
	// public void OnInventoryMoveClient(ClientInventoryMove info)
	// {
	// 	var hand = PlayerManager.LocalPlayerScript.playerNetworkActions;
	// 	//when item is moved and player has it on his feet
	// 	if (hand.GetActiveItemInSlot(NamedSlot.feet) != null && hand.GetActiveItemInSlot(NamedSlot.feet) == gameObject)
	// 	{
	// 		UIActionManager.Toggle(this, true);
	// 		UIActionManager.SetSprite(this, (sprites[0]));
	// 	}
	// 	else
	// 	{
	// 		UIActionManager.Toggle(this, false);
	// 	}
	// }
	//
	// public void CallActionClient()
	// {
	// 	UIActionManager.SetSprite(this, (!isOn ? sprites[1] : sprites[0]));
	// }
	//
	// public void CallActionServer(ConnectedPlayer SentByPlayer)
	// {
	// 	ServerChangeState(SentByPlayer);
	// }
	//
	// #endregion
}
{'fraction_non_alphanumeric': 0.12832681928159315, 'fraction_numerical': 0.003722315280104225, 'mean_word_length': 3.6971153846153846, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 13, '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': '4133323', 'n_tokens_mistral': 4095, 'n_tokens_neox': 3790, 'n_words': 681}