<commit_before>﻿using System.Collections.Generic;
using UnityEngine;
using UnityEngine.Networking;
using UI;

namespace PlayGroup {

    public class PlayerMove: NetworkBehaviour {

        private PlayerSprites playerSprites;

        private static KeyCode[] keyCodes = { KeyCode.W, KeyCode.A, KeyCode.S, KeyCode.D, KeyCode.UpArrow, KeyCode.LeftArrow, KeyCode.DownArrow, KeyCode.RightArrow };

        public bool diagonalMovement;
        public float speed = 10;
		public bool isInSpace = false;
		[SyncVar]
		public bool allowInput = true;

        private List<KeyCode> pressedKeys = new List<KeyCode>();

        void Start() {
            playerSprites = gameObject.GetComponent<PlayerSprites>();
        }

        public PlayerAction SendAction() {
            var actionKeys = new List<int>();
            foreach(var keyCode in keyCodes) {
				if(Input.GetKey(keyCode) && allowInput) {
                    actionKeys.Add((int) keyCode);
                }
            }

            return new PlayerAction() { keyCodes = actionKeys.ToArray() };
        }

        public Vector3 GetNextPosition(Vector3 currentPosition, PlayerAction action) {
			if (isServer) {
				bool isSpace = Matrix.Matrix.At(currentPosition).IsSpace();
				if (isSpace && !isInSpace) {
					isInSpace = true;
				} else if (!isSpace && isInSpace) {
					isInSpace = false;
				}
			}

            var direction = GetDirection(action);
            var adjustedDirection = AdjustDirection(currentPosition, direction);

            if(adjustedDirection == Vector3.zero) {
                Interact(currentPosition, direction);
            }

            playerSprites.FaceDirection(direction);
            return currentPosition + adjustedDirection;
        }

        private Vector3 GetDirection(PlayerAction action) {
            ProcessAction(action);

            if(diagonalMovement) {
                return GetMoveDirection(pressedKeys);
            }
            if(pressedKeys.Count > 0) {
                return GetMoveDirection(pressedKeys[pressedKeys.Count - 1]);
            }
            return Vector3.zero;
        }

        private void ProcessAction(PlayerAction action) {
            var actionKeys = new List<int>(action.keyCodes);
            foreach(var keyCode in keyCodes) {
                if(actionKeys.Contains((int) keyCode) && !pressedKeys.Contains(keyCode)) {
                    pressedKeys.Add(keyCode);
                } else if(!actionKeys.Contains((int) keyCode) && pressedKeys.Contains(keyCode)) {
                    pressedKeys.Remove(keyCode);
                }
            }
        }

        private Vector3 GetMoveDirection(List<KeyCode> actions) {
            var direction = Vector3.zero;
            foreach(var keycode in pressedKeys) {
                direction += GetMoveDirection(keycode);
            }
            direction.x = Mathf.Clamp(direction.x, -1, 1);
            direction.y = Mathf.Clamp(direction.y, -1, 1);

            return direction;
        }

        private Vector3 GetMoveDirection(KeyCode action) {
			if (UIManager.Chat.isChatFocus)
				return Vector3.zero;
			
            switch(action) {
                case KeyCode.W:
                case KeyCode.UpArrow:
                    return Vector3.up;
                case KeyCode.A:
                case KeyCode.LeftArrow:
                    return Vector3.left;
                case KeyCode.S:
                case KeyCode.DownArrow:
                    return Vector3.down;
                case KeyCode.D:
                case KeyCode.RightArrow:
                    return Vector3.right;
            }

            return Vector3.zero;
        }

        private Vector3 AdjustDirection(Vector3 currentPosition, Vector3 direction) {
            var horizontal = Vector3.Scale(direction, Vector3.right);
            var vertical = Vector3.Scale(direction, Vector3.up);

            if(Matrix.Matrix.At(currentPosition + direction).IsPassable()) {
                if((Matrix.Matrix.At(currentPosition + horizontal).IsPassable() ||
                               Matrix.Matrix.At(currentPosition + vertical).IsPassable())) {
                    return direction;
                }
            }
            return Vector3.zero;
        }
        private void Interact(Vector3 currentPosition, Vector3 direction) {
            DoorController doorController = Matrix.Matrix.At(currentPosition + direction).GetDoor();
            if(doorController != null) {
                doorController.CmdTryOpen();
            }
        }
    }
}<commit_msg>Stop player from moving while chat is open<commit_after>﻿using System.Collections.Generic;
using UnityEngine;
using UnityEngine.Networking;
using UI;

namespace PlayGroup {

    public class PlayerMove: NetworkBehaviour {

        private PlayerSprites playerSprites;

        private static KeyCode[] keyCodes = { KeyCode.W, KeyCode.A, KeyCode.S, KeyCode.D, KeyCode.UpArrow, KeyCode.LeftArrow, KeyCode.DownArrow, KeyCode.RightArrow };

        public bool diagonalMovement;
        public float speed = 10;
		public bool isInSpace = false;
		[SyncVar]
		public bool allowInput = true;

        private List<KeyCode> pressedKeys = new List<KeyCode>();

        void Start() {
            playerSprites = gameObject.GetComponent<PlayerSprites>();
        }

        public PlayerAction SendAction() {
            var actionKeys = new List<int>();

            foreach(var keyCode in keyCodes) {
				if (PlayerManager.LocalPlayer == gameObject && UIManager.Chat.isChatFocus)
					return new PlayerAction() { keyCodes = actionKeys.ToArray() };
				
				if(Input.GetKey(keyCode) && allowInput) {
                    actionKeys.Add((int) keyCode);
                }
            }

            return new PlayerAction() { keyCodes = actionKeys.ToArray() };
        }

        public Vector3 GetNextPosition(Vector3 currentPosition, PlayerAction action) {
			if (isServer) {
				bool isSpace = Matrix.Matrix.At(currentPosition).IsSpace();
				if (isSpace && !isInSpace) {
					isInSpace = true;
				} else if (!isSpace && isInSpace) {
					isInSpace = false;
				}
			}

            var direction = GetDirection(action);
            var adjustedDirection = AdjustDirection(currentPosition, direction);

            if(adjustedDirection == Vector3.zero) {
                Interact(currentPosition, direction);
            }

            playerSprites.FaceDirection(direction);
            return currentPosition + adjustedDirection;
        }

        private Vector3 GetDirection(PlayerAction action) {
            ProcessAction(action);

            if(diagonalMovement) {
                return GetMoveDirection(pressedKeys);
            }
            if(pressedKeys.Count > 0) {
                return GetMoveDirection(pressedKeys[pressedKeys.Count - 1]);
            }
            return Vector3.zero;
        }

        private void ProcessAction(PlayerAction action) {
            var actionKeys = new List<int>(action.keyCodes);
            foreach(var keyCode in keyCodes) {
                if(actionKeys.Contains((int) keyCode) && !pressedKeys.Contains(keyCode)) {
                    pressedKeys.Add(keyCode);
                } else if(!actionKeys.Contains((int) keyCode) && pressedKeys.Contains(keyCode)) {
                    pressedKeys.Remove(keyCode);
                }
            }
        }

        private Vector3 GetMoveDirection(List<KeyCode> actions) {
            var direction = Vector3.zero;
            foreach(var keycode in pressedKeys) {
                direction += GetMoveDirection(keycode);
            }
            direction.x = Mathf.Clamp(direction.x, -1, 1);
            direction.y = Mathf.Clamp(direction.y, -1, 1);

            return direction;
        }

        private Vector3 GetMoveDirection(KeyCode action) {
			if (PlayerManager.LocalPlayer == gameObject && UIManager.Chat.isChatFocus)
				return Vector3.zero;
			
            switch(action) {
                case KeyCode.W:
                case KeyCode.UpArrow:
                    return Vector3.up;
                case KeyCode.A:
                case KeyCode.LeftArrow:
                    return Vector3.left;
                case KeyCode.S:
                case KeyCode.DownArrow:
                    return Vector3.down;
                case KeyCode.D:
                case KeyCode.RightArrow:
                    return Vector3.right;
            }

            return Vector3.zero;
        }

        private Vector3 AdjustDirection(Vector3 currentPosition, Vector3 direction) {
            var horizontal = Vector3.Scale(direction, Vector3.right);
            var vertical = Vector3.Scale(direction, Vector3.up);

            if(Matrix.Matrix.At(currentPosition + direction).IsPassable()) {
                if((Matrix.Matrix.At(currentPosition + horizontal).IsPassable() ||
                               Matrix.Matrix.At(currentPosition + vertical).IsPassable())) {
                    return direction;
                }
            }
            return Vector3.zero;
        }
        private void Interact(Vector3 currentPosition, Vector3 direction) {
            DoorController doorController = Matrix.Matrix.At(currentPosition + direction).GetDoor();
            if(doorController != null) {
                doorController.CmdTryOpen();
            }
        }
    }
}
{'fraction_non_alphanumeric': 0.09036338299924965, 'fraction_numerical': 0.006860328009432951, 'mean_word_length': 1.847985347985348, 'pattern_counts': {'":': 0, '<': 15, '<?xml version=': 0, '>': 17, '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': '5280849', 'n_tokens_mistral': 2510, 'n_tokens_neox': 2331, 'n_words': 502}