// File: MichaelXanth[P]RPG_Game/Game/Game.cpp
// Function: Game::ChooseAction(Hero&, short, std::vector<Monster*, std::allocator<Monster*>>&)
bool Game::ChooseAction(Hero& hero, short action, vector<Monster *>& monsters)
{
    short monsterNum;

    switch(action)
    {
        case 1:
            if (ChooseMonsterToAttack(monsters , monsterNum) == false)
                return false;

            // Hero attacks with their weapon or bare hands(savage!)
            Battle::AttackWithWeapon(hero,*monsters[monsterNum - 1]);

            // If the monster faints then it is deleted
            if (monsters[monsterNum - 1]->Fainted()) {
                delete monsters[monsterNum - 1];
                monsters.erase(monsters.begin() + monsterNum - 1);
            }

            return true;

        case 2:
            if (hero.GetAvailableSpellSlots() == hero.GetMaxSpellsSlots()) {
                cout << "\033[s";
                cout << endl << "Sorry, there are no available spells." << endl;

                usleep(1500000);

                cout << "\033[u";
                cout << "\033[J";

                return false;
            }

            if (ChooseMonsterToAttack(monsters , monsterNum) == false)
                return false;

            // Casts the chosen spell
            if (Battle::CastSpell(hero,*monsters[monsterNum - 1]) == false)
                return false;
            
            else {
                // If the monster faints then it is deleted
                if (monsters[monsterNum - 1]->Fainted()) {
                    delete monsters[monsterNum - 1];
                    monsters.erase(monsters.begin() + monsterNum - 1);
                }
            }

            return true;

        case 3:
            if (Battle::ChangeArmor(hero,true) == false)
                return false;
            return true;

        case 4:
            if (Battle::ChangeWeapon(hero,true) == false)
                return false;
            return true;

        case 5:
            if (Battle::UsePotion(hero,true) == false)
                return false;
            return true;
        
        default:
        return false;
    }
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0xd0, %rsp
movw %dx, %ax
movq %rdi, -0x10(%rbp)
movq %rsi, -0x18(%rbp)
movw %ax, -0x1a(%rbp)
movq %rcx, -0x28(%rbp)
movq -0x10(%rbp), %rax
movq %rax, -0x90(%rbp)
movswl -0x1a(%rbp), %eax
decl %eax
movl %eax, %ecx
movq %rcx, -0x88(%rbp)
subl $0x4, %eax
ja 0x199a3
movq -0x88(%rbp), %rax
leaq 0x23ca9(%rip), %rcx     # 0x3d308
movslq (%rcx,%rax,4), %rax
addq %rcx, %rax
jmpq *%rax
movq -0x90(%rbp), %rdi
movq -0x28(%rbp), %rsi
leaq -0x2a(%rbp), %rdx
callq 0x1b5f0
andb $0x1, %al
movzbl %al, %eax
cmpl $0x0, %eax
jne 0x1968f
movb $0x0, -0x1(%rbp)
jmp 0x199a7
movq -0x18(%rbp), %rax
movq %rax, -0x98(%rbp)
movq -0x28(%rbp), %rdi
movswl -0x2a(%rbp), %eax
subl $0x1, %eax
movslq %eax, %rsi
callq 0x1b800
movq -0x98(%rbp), %rdi
movq (%rax), %rsi
callq 0x175f0
movq -0x28(%rbp), %rdi
movswl -0x2a(%rbp), %eax
subl $0x1, %eax
movslq %eax, %rsi
callq 0x1b800
movq (%rax), %rdi
callq 0x1ea40
testb $0x1, %al
jne 0x196e0
jmp 0x1976d
movq -0x28(%rbp), %rdi
movswl -0x2a(%rbp), %eax
subl $0x1, %eax
movslq %eax, %rsi
callq 0x1b800
movq (%rax), %rax
movq %rax, -0xa0(%rbp)
cmpq $0x0, %rax
je 0x19710
movq -0xa0(%rbp), %rdi
movq (%rdi), %rax
callq *0x18(%rax)
movq -0x28(%rbp), %rax
movq %rax, -0xa8(%rbp)
movq -0x28(%rbp), %rdi
callq 0x1b890
movq %rax, -0x50(%rbp)
movswq -0x2a(%rbp), %rsi
leaq -0x50(%rbp), %rdi
callq 0x1b8c0
movq %rax, -0x48(%rbp)
leaq -0x48(%rbp), %rdi
movl $0x1, %esi
callq 0x1b900
movq %rax, -0x40(%rbp)
leaq -0x38(%rbp), %rdi
leaq -0x40(%rbp), %rsi
callq 0x1b940
movq -0xa8(%rbp), %rdi
movq -0x38(%rbp), %rsi
callq 0x1b820
movq %rax, -0x58(%rbp)
movb $0x1, -0x1(%rbp)
jmp 0x199a7
movq -0x18(%rbp), %rdi
callq 0x1ee10
movl %eax, -0xac(%rbp)
movq -0x18(%rbp), %rdi
callq 0x1ee50
movl %eax, %ecx
movl -0xac(%rbp), %eax
cmpl %ecx, %eax
jne 0x19817
movq 0x34827(%rip), %rdi     # 0x4dfc8
leaq 0x240d6(%rip), %rsi     # 0x3d87e
callq 0x4260
movq 0x34814(%rip), %rdi     # 0x4dfc8
movq 0x347fd(%rip), %rsi     # 0x4dfb8
callq 0x4290
movq %rax, %rdi
leaq 0x240b8(%rip), %rsi     # 0x3d882
callq 0x4260
movq %rax, %rdi
movq 0x347df(%rip), %rsi     # 0x4dfb8
callq 0x4290
movl $0x16e360, %edi         # imm = 0x16E360
callq 0x4390
movq 0x347d9(%rip), %rdi     # 0x4dfc8
leaq 0x240b2(%rip), %rsi     # 0x3d8a8
callq 0x4260
movq 0x347c6(%rip), %rdi     # 0x4dfc8
leaq 0x2602a(%rip), %rsi     # 0x3f833
callq 0x4260
movb $0x0, -0x1(%rbp)
jmp 0x199a7
movq -0x90(%rbp), %rdi
movq -0x28(%rbp), %rsi
leaq -0x2a(%rbp), %rdx
callq 0x1b5f0
andb $0x1, %al
movzbl %al, %eax
cmpl $0x0, %eax
jne 0x1983e
movb $0x0, -0x1(%rbp)
jmp 0x199a7
movq -0x18(%rbp), %rax
movq %rax, -0xb8(%rbp)
movq -0x28(%rbp), %rdi
movswl -0x2a(%rbp), %eax
subl $0x1, %eax
movslq %eax, %rsi
callq 0x1b800
movq -0xb8(%rbp), %rdi
movq (%rax), %rsi
callq 0x17750
andb $0x1, %al
movzbl %al, %eax
cmpl $0x0, %eax
jne 0x1987e
movb $0x0, -0x1(%rbp)
jmp 0x199a7
movq -0x28(%rbp), %rdi
movswl -0x2a(%rbp), %eax
subl $0x1, %eax
movslq %eax, %rsi
callq 0x1b800
movq (%rax), %rdi
callq 0x1ea40
testb $0x1, %al
jne 0x198a2
jmp 0x1992f
movq -0x28(%rbp), %rdi
movswl -0x2a(%rbp), %eax
subl $0x1, %eax
movslq %eax, %rsi
callq 0x1b800
movq (%rax), %rax
movq %rax, -0xc0(%rbp)
cmpq $0x0, %rax
je 0x198d2
movq -0xc0(%rbp), %rdi
movq (%rdi), %rax
callq *0x18(%rax)
movq -0x28(%rbp), %rax
movq %rax, -0xc8(%rbp)
movq -0x28(%rbp), %rdi
callq 0x1b890
movq %rax, -0x78(%rbp)
movswq -0x2a(%rbp), %rsi
leaq -0x78(%rbp), %rdi
callq 0x1b8c0
movq %rax, -0x70(%rbp)
leaq -0x70(%rbp), %rdi
movl $0x1, %esi
callq 0x1b900
movq %rax, -0x68(%rbp)
leaq -0x60(%rbp), %rdi
leaq -0x68(%rbp), %rsi
callq 0x1b940
movq -0xc8(%rbp), %rdi
movq -0x60(%rbp), %rsi
callq 0x1b820
movq %rax, -0x80(%rbp)
jmp 0x19931
movb $0x1, -0x1(%rbp)
jmp 0x199a7
movq -0x18(%rbp), %rdi
movl $0x1, %esi
callq 0x179d0
andb $0x1, %al
movzbl %al, %eax
cmpl $0x0, %eax
jne 0x19955
movb $0x0, -0x1(%rbp)
jmp 0x199a7
movb $0x1, -0x1(%rbp)
jmp 0x199a7
movq -0x18(%rbp), %rdi
movl $0x1, %esi
callq 0x17a20
andb $0x1, %al
movzbl %al, %eax
cmpl $0x0, %eax
jne 0x19979
movb $0x0, -0x1(%rbp)
jmp 0x199a7
movb $0x1, -0x1(%rbp)
jmp 0x199a7
movq -0x18(%rbp), %rdi
movl $0x1, %esi
callq 0x17980
andb $0x1, %al
movzbl %al, %eax
cmpl $0x0, %eax
jne 0x1999d
movb $0x0, -0x1(%rbp)
jmp 0x199a7
movb $0x1, -0x1(%rbp)
jmp 0x199a7
movb $0x0, -0x1(%rbp)
movb -0x1(%rbp), %al
andb $0x1, %al
addq $0xd0, %rsp
popq %rbp
retq
nopw %cs:(%rax,%rax)