package org.project;
import java.util.*;

import org.project.entity.Entity;
import org.project.entity.enemies.Enemy;
import org.project.entity.enemies.Goblin;
import org.project.entity.enemies.Skeleton;
import org.project.entity.enemies.Vampire;
import org.project.entity.players.Assassin;
import org.project.entity.players.Knight;
import org.project.entity.players.Player;
import org.project.entity.players.Wizard;
import org.project.item.armors.*;
import org.project.item.weapons.Sword;
import org.project.item.weapons.SwordPro;
import org.project.item.weapons.SwordProMax;
import org.project.item.weapons.Weapon;
import org.project.location.Location;


public class Main {
    public static void main(String[] args) {
        // TODO: ADD LOCATIONS TO YOUR GAME
        int a ;
        int b ;
        int c ;
        String name  ;

        Scanner input = new Scanner(System.in) ;
        Random random = new Random() ;

        List<Location> locations = new ArrayList<>();
        ArrayList<Enemy> enemies = new ArrayList<>() ;

       Weapon sword = new Sword(3 , 4 ) ;
       Weapon swordProMax = new SwordProMax(5 , 2 ) ;
       Weapon swordPro = new SwordPro(4 , 3) ;

        Enemy vampire = new Vampire(12 ,5 , swordProMax) ;
        Enemy skeleton = new Skeleton(10 , 2 , sword) ;
        Enemy goblin = new Goblin(8 , 12 , swordPro) ;
        enemies.add(skeleton) ;
        enemies.add(vampire) ;
        enemies.add(goblin) ;
        Weapon swo ;
        Armor arm = null;
        Player player ;
        Enemy enemy  = skeleton ;
        String enemy_name = "Skeleton" ;
        boolean enemyIsLive = false ;












        System.out.println("---- Enter your name : ----") ;
        name = input.nextLine() ;

        System.out.println("----select your character ----") ;
        System.out.println(" Assassin  : 1 , Wizard : 2 , Knight : 3  ");
        a = input.nextInt() ;
        System.out.println("-----select your Weapon ----");
        System.out.println(" Sword   : 1 , Sword Pro  : 2 , Sword Pro Max : 3  ");
        b = input.nextInt() ;
        System.out.println("-----select your Armor ----");
        System.out.println(" Normal Armor  : 1 , Armor Pro   : 2 , Armor Pro Max : 3  , Knight Armor : 4 ");
        c = input.nextInt() ;
        if (b == 1) {
             swo = new Sword(sword);
        }
        else if (b == 2 )
        {
            swo = new SwordPro(swordPro) ;

        }
        else {
            swo = new SwordProMax(swordProMax) ;
        }
        if (c == 1 )
        {
             arm = new ArmorNormal(1 ,2) ;
        }
        else if (c == 2 )
        {
             arm = new ArmorPro(2 ,2) ;
        }
        else if (c == 3)
        {
             arm = new ArmorProMax(5 ,1) ;
        }
        else if (c == 4)
        {
            Armor knightarmor  = new KnightArmor(3 , 2 ) ;
        }
        if (a == 1 )
        {
             player = new Assassin(name , swo , arm ) ;
        }
        else if ( a == 2 )
        {
             player = new Wizard(name , swo , arm ) ;
        }
        else {
             player = new Knight(name , swo , arm ) ;
        }
        System.out.println(player.IsLive());
        System.out.println(player.getHp());
        while(!player.ISLive())
        {
            int sel = 0 ;
            System.out.println(enemyIsLive);
            while (sel != 1 &&  enemyIsLive == false) {
                System.out.println("your Enemy is  : " + enemy_name);
                System.out.println("# 1) Fight the enemy");
                System.out.println("# 2) Move to another location:");
                sel = input.nextInt();
                if (sel == 2) {
                    enemy = enemies.get(random.nextInt(enemies.size()));
                    enemy_name = enemy.getName();


                }
                else if (sel == 1)
                {
                    enemyIsLive = true ;
                    break ;

                }
            }

                playerMove(player , enemy );
                showDetails(player , enemy);
                pause(5);
                System.out.println(enemy.IsLive());
                if (enemy.IsLive())
                {
                    System.out.println("salam");
                   int  ran = random.nextInt(2) ;
                   System.out.println(ran);
                   if (Objects.equals(enemy.getName(), "Goblin"))
                   {
                       int ran2 = random.nextInt(3) ;
                       if (ran == 0)
                       {
                           enemy.LightAttack(player , 3 );
                           showDetails(player , enemy);
                           pause(5);
                       }
                       else
                       {
                           enemy.attack(player);
                           showDetails(player , enemy);
                           pause(5);
                       }
                   }
                   else {
                       enemyMove(player, enemy, ran);
                       showDetails(player, enemy);
                       pause(5);
                   }

                }
                else {
                    System.out.println("the " + enemy_name + " died !");
                    enemyIsLive = false;
                    sel = 0 ;
                    player.UpGradeMaxHP();
                    player.UpGradeMaxMP();
                    player.freshFactors();
                    enemy.freshFactors();
                }



            }










        // TODO: IMPLEMENT GAMEPLAY
    }
    public static  void playerMove (Player player , Enemy enemy )
    {


        System.out.println("# What You Want To Do :");
        System.out.println("# 1) Light Attack ");
        System.out.println("# 2) Heavy Attack ");
        System.out.println("# 3) Defend ") ;
        System.out.println("# 4) Heal") ;
        System.out.println("# 5) Special Ability");
        Scanner sc = new Scanner(System.in) ;
        int x = sc.nextInt() ;

        switch (x) {
            case 1 :
                player.LightAttack(enemy , 3);
                break;


            case 2 :
                player.attack(enemy);
                break;

            case 3 :
                player.defend(player , 5);
                break;

            case 4 :
                player.heal(6);
                break;

            case 5 :
                player.specialAttack(enemy);
                break;

        }
    }
    public static void enemyMove ( Player player  , Enemy enemy  , int x )
    {
        switch (x) {
            case 0 :
                enemy.LightAttack(player , 3);
                break;

            case 1 :
                enemy.attack(player);
                break;
        }
    }
    public  static void showDetails (Player player , Enemy enemy )
    {
        System.out.println("player's Max Hp : " + player.getMaxHP() + " Mp : " + player.getMaxMP()) ;
        System.out.println("player's Hp : " + player.getHp() + " Mp : " + player.getMp());
        System.out.println("Enemy's  Max Hp : " + enemy.getMaxHP()+ " Mp : " + enemy.getMaxMP()) ;
        System.out.println("Enemy's Hp : " + enemy.getHp() + " Mp : " + enemy.getMp());
    }
    public static void pause(double seconds) {
        try {
            Thread.sleep((long)(seconds * 1000));
        } catch (InterruptedException e) {

        }
    }
}