//
//  World.hpp
//  Game
//
//  Created by Darvydas on 24/01/2019.
//

#ifndef PLAYER_H
#define PLAYER_H

#include "cocos2d.h"

#include "dragonBones/cocos2dx/CCDragonBonesHeaders.h"

#include "Game/GameScene/World/Utils.h"
#include "Game/GameScene/World/Map/House.hpp"
#include "Game/GameScene/World/Objects/Base.hpp"
#include "Config/Config.hpp"
#include "Utils/json/Manager.hpp"

#include <unordered_map>

namespace Game
{
    enum EkeyState
    {
        Pressed,
        Unpressed,
        None,
    };

	enum LevelStatus
	{
		LEVEL_WON,
		LEVEL_LOST,
		LEVEL_PLAYING
	};

	class CHUD;

	class CPlayer : public Objects::CBase {
	public:
		struct SCharacter
		{
			std::string characterName;
			int vitality;
			int intelligence;
			int sanity;
			int endurance;
			int charisma;
		};

		enum StatType
		{
			VITALITY,
			INTELLIGENCE,
			SANITY,
			ENDURANCE,
			CHARISMA
		};

        static CPlayer *create(Map::CHouse* pcHouse, cocos2d::Size sSize, CHUD* hud);

        bool canMoveToDirection(Utils::EDirection eDirection);
        
        void keyPressed(cocos2d::EventKeyboard::KeyCode keyCode);
        void keyReleased(cocos2d::EventKeyboard::KeyCode keyCode);

		LevelStatus AddVitality(int value);
		LevelStatus AddIntelligence(int value);
		LevelStatus AddSanity(int value);
		LevelStatus AddEndurance(int value);
		LevelStatus AddCharisma(int value);
		LevelStatus CheckStatsForLevelEnd();

		void OnNextLevel();
		void OnLevelFail();

		void LoadCharacterNeutral();
		void LoadCharacterDetective();
		void LoadCharacterHulk();
		void LoadCharacterRockstar();
		void LoadCharacterStickMan();
		void LoadCharacterMadScientist();
        
	private:
        
        void update(const float dt);
        
        void setUp();
		void createVisualElements(CHUD* hud);
        
        cocos2d::Point getTilePositionPositionInWorld(cocos2d::Point pPoint);
        
    public: 
		CHUD* m_CHUD;
        float m_bIsMoving;
        
        float m_fSpeed;
        float m_fSpeedDecline;
        
        cocos2d::Point m_pCurrentSpeed;
        
        Map::CHouse* m_pcHouse;
		int m_CharacterCurrID;
		int m_MaxCharacters;
		SCharacter m_CharacterData;

	private:
		
		//std::unordered_map<StatType, int> m_StatsMoreThen;
		//std::unordered_map<StatType, int> m_StatsLessThen;
        

		struct ObjectiveStat
		{
			StatType m_StatType;
			int m_Target;
		};

		std::vector<ObjectiveStat> m_ObjectiveStats;

        EkeyState m_eKeyW, m_eKeyA, m_eKeyS, m_eKeyD;
        
#pragma mark Dragon bones -
        
    private:
        
        bool m_bStateChanged = false;
		std::vector<SCharacter*> m_CharacterSkins;
        
    private:
        
        dragonBones::CCArmatureDisplay* armatureDisplay;
        dragonBones::CCFactory factory;
        
        dragonBones::CCArmatureDisplay* armatureDisplaySide;
        dragonBones::CCFactory factorySide;
                
        void createDragonBones();
	};
}

#endif /* PLAYER_H */
