<commit_before>﻿using System;
using System.Collections.Generic;
using System.Linq;
using HarryPotterUnity.Cards.Generic;
using HarryPotterUnity.Cards.Interfaces;
using HarryPotterUnity.UI;
using HarryPotterUnity.Utils;
using JetBrains.Annotations;
using UnityEngine;
using UnityEngine.UI;

namespace HarryPotterUnity.Game
{
    [UsedImplicitly]
    public class Player : MonoBehaviour {

        public Player OppositePlayer { get; set; }
        public Hand Hand { get; private set; }
        public Deck Deck { get; private set; }
        public InPlay InPlay { get; private set; }
        public Discard Discard { get; private set; }

        public List<Lesson.LessonTypes> LessonTypesInPlay { get; private set; }

        public int CreaturesInPlay { get; set; }
        public int DamagePerTurn { get; set; }
        public int AmountLessonsInPlay { get; set; }
        private int ActionsAvailable { get; set; }

        public bool IsLocalPlayer { get; set; }
        public MultiplayerGameManager MpGameManager { get; set; }
        public byte NetworkId { get; set; }

        public Text ActionsLeftLabel { private get; set; }
        public Image TurnIndicator { private get; set; }
        public RectTransform EndGamePanel { private get; set; }
        public Text CardsLeftLabel { get; set; }


        private MultiplayerLobbyHudManager _multiplayerLobbyHudManager;

        [UsedImplicitly]
        public void Awake()
        {
            LessonTypesInPlay = new List<Lesson.LessonTypes>();
            ActionsAvailable = 0;
            AmountLessonsInPlay = 0;

            Hand = transform.GetComponentInChildren<Hand>();
            Deck = transform.GetComponentInChildren<Deck>();
            InPlay = transform.GetComponentInChildren<InPlay>();
            Discard = transform.GetComponentInChildren<Discard>();

            _multiplayerLobbyHudManager = GameObject.Find("MultiplayerLobbyHudManager").GetComponent<MultiplayerLobbyHudManager>();

            if (!_multiplayerLobbyHudManager) throw new Exception("MultiplayerGameManager could not find MultiplayerLobbyHudManager!");
        }

        public void InitDeck(List<Lesson.LessonTypes> selectedLessons)
        {
            Deck.InitDeck( DeckGenerator.GenerateDeck(selectedLessons) );
        }

        public void UseActions(int amount = 1)
        {
            ActionsAvailable -= amount;

            ActionsLeftLabel.text = string.Format("Actions Left: {0}", ActionsAvailable);

            if (ActionsAvailable > 0) return;
            ActionsAvailable = 0;
            
            TurnIndicator.gameObject.SetActive(false);

            InPlay.Cards.ForEach(card => ((IPersistentCard) card).OnInPlayAfterTurnAction());
            OppositePlayer.InitTurn();
        }

        private void AddActions(int amount)
        {
            ActionsAvailable += amount;
            ActionsLeftLabel.text = string.Format("Actions Left: {0}", ActionsAvailable);
        }

        public void InitTurn()
        {
            TurnIndicator.gameObject.SetActive(true);
            //BeforeTurnAction happens here
            InPlay.Cards.ForEach(card => ((IPersistentCard) card).OnInPlayBeforeTurnAction());

            Deck.DrawCard();
            AddActions(2);

            //Creatures do damage here
            OppositePlayer.TakeDamage(DamagePerTurn);
        }

        public bool CanUseActions(int amount = 1)
        {
            return ActionsAvailable >= amount;
        }

        public void DrawInitialHand()
        {
            //TODO: Needs cleanup
            for (var i = 0; i < 7; i++)
            {
                var card = Deck.TakeTopCard();
                var cardPosition = Hand.HandCardsOffset;

                var shrinkFactor = Hand.Cards.Count >= 12 ? 0.5f : 1f;

                cardPosition.x += Hand.Cards.Count * Hand.Spacing * shrinkFactor;
                cardPosition.z -= Hand.Cards.Count;

                Hand.Cards.Add(card);
                card.transform.parent = Hand.transform;

                UtilManager.TweenQueue.AddTweenToQueue(card, cardPosition, 0.3f, GenericCard.CardStates.InHand, IsLocalPlayer, TweenQueue.RotationType.NoRotate);
            }       
        }

        public void ShowGameOverLoseMessage()
        {
            var titleLabel = EndGamePanel.FindChild("Title").GetComponent<Text>();
            var messageLabel = EndGamePanel.FindChild("Message").GetComponent<Text>();

            titleLabel.text = "Sorry!";<commit_msg>Clean up DrawInitialHand<commit_after>﻿using System;
using System.Collections.Generic;
using System.Linq;
using HarryPotterUnity.Cards.Generic;
using HarryPotterUnity.Cards.Interfaces;
using HarryPotterUnity.UI;
using HarryPotterUnity.Utils;
using JetBrains.Annotations;
using UnityEngine;
using UnityEngine.UI;

namespace HarryPotterUnity.Game
{
    [UsedImplicitly]
    public class Player : MonoBehaviour {

        public Player OppositePlayer { get; set; }
        public Hand Hand { get; private set; }
        public Deck Deck { get; private set; }
        public InPlay InPlay { get; private set; }
        public Discard Discard { get; private set; }

        public List<Lesson.LessonTypes> LessonTypesInPlay { get; private set; }

        public int CreaturesInPlay { get; set; }
        public int DamagePerTurn { get; set; }
        public int AmountLessonsInPlay { get; set; }
        private int ActionsAvailable { get; set; }

        public bool IsLocalPlayer { get; set; }
        public MultiplayerGameManager MpGameManager { get; set; }
        public byte NetworkId { get; set; }

        public Text ActionsLeftLabel { private get; set; }
        public Image TurnIndicator { private get; set; }
        public RectTransform EndGamePanel { private get; set; }
        public Text CardsLeftLabel { get; set; }


        private MultiplayerLobbyHudManager _multiplayerLobbyHudManager;

        [UsedImplicitly]
        public void Awake()
        {
            LessonTypesInPlay = new List<Lesson.LessonTypes>();
            ActionsAvailable = 0;
            AmountLessonsInPlay = 0;

            Hand = transform.GetComponentInChildren<Hand>();
            Deck = transform.GetComponentInChildren<Deck>();
            InPlay = transform.GetComponentInChildren<InPlay>();
            Discard = transform.GetComponentInChildren<Discard>();

            _multiplayerLobbyHudManager = GameObject.Find("MultiplayerLobbyHudManager").GetComponent<MultiplayerLobbyHudManager>();

            if (!_multiplayerLobbyHudManager) throw new Exception("MultiplayerGameManager could not find MultiplayerLobbyHudManager!");
        }

        public void InitDeck(List<Lesson.LessonTypes> selectedLessons)
        {
            Deck.InitDeck( DeckGenerator.GenerateDeck(selectedLessons) );
        }

        public void UseActions(int amount = 1)
        {
            ActionsAvailable -= amount;

            ActionsLeftLabel.text = string.Format("Actions Left: {0}", ActionsAvailable);

            if (ActionsAvailable > 0) return;
            ActionsAvailable = 0;
            
            TurnIndicator.gameObject.SetActive(false);

            InPlay.Cards.ForEach(card => ((IPersistentCard) card).OnInPlayAfterTurnAction());
            OppositePlayer.InitTurn();
        }

        private void AddActions(int amount)
        {
            ActionsAvailable += amount;
            ActionsLeftLabel.text = string.Format("Actions Left: {0}", ActionsAvailable);
        }

        public void InitTurn()
        {
            TurnIndicator.gameObject.SetActive(true);
            //BeforeTurnAction happens here
            InPlay.Cards.ForEach(card => ((IPersistentCard) card).OnInPlayBeforeTurnAction());

            Deck.DrawCard();
            AddActions(2);

            //Creatures do damage here
            OppositePlayer.TakeDamage(DamagePerTurn);
        }

        public bool CanUseActions(int amount = 1)
        {
            return ActionsAvailable >= amount;
        }

        public void DrawInitialHand()
        {
            for (var i = 0; i < 7; i++)
            {
                var card = Deck.TakeTopCard();
                Hand.Add(card, false);
            }       
        }

        public void ShowGameOverLoseMessage()
        {
            var titleLabel = EndGamePanel.FindChild("Title").GetComponent<Text>();
            var messageLabel = EndGamePanel.FindChild("Message").GetComponent<Text>();

            titleLabel.text = "Sorry!";
{'fraction_non_alphanumeric': 0.08947119924457035, 'fraction_numerical': 0.0034230406043437205, 'mean_word_length': 2.311059007424775, 'pattern_counts': {'":': 0, '<': 25, '<?xml version=': 0, '>': 32, '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': '244783', 'n_tokens_mistral': 2327, 'n_tokens_neox': 2196, 'n_words': 514}