// File: /workspace/github_cpp_makefile_star2_O2/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
pushq %r15
pushq %r14
pushq %rbx
pushq %rax
decl %edx
cmpl $0x4, %edx
ja 0xa6b3
movq %rcx, %rbx
movq %rsi, %r14
leaq 0x10daf(%rip), %rax     # 0x1b308
movslq (%rax,%rdx,4), %rcx
addq %rax, %rcx
jmpq *%rcx
leaq 0x6(%rsp), %rdx
movq %rbx, %rsi
callq 0xbb2c
testb %al, %al
je 0xa6b3
movswq 0x6(%rsp), %r15
movq (%rbx), %rax
movq -0x8(%rax,%r15,8), %rsi
movq %r14, %rdi
callq 0x93dc
movq (%rbx), %rax
movq -0x8(%rax,%r15,8), %rdi
callq 0xcecc
movb $0x1, %bpl
testb %al, %al
je 0xa6b5
movq (%rbx), %rax
movq -0x8(%rax,%r15,8), %rdi
testq %rdi, %rdi
je 0xa5bb
movq (%rdi), %rax
callq *0x18(%rax)
movq (%rbx), %rax
leaq (%rax,%r15,8), %rsi
addq $-0x8, %rsi
movq %rbx, %rdi
callq 0xbc32
jmp 0xa6b5
pushq $0x1
popq %rsi
movq %r14, %rdi
addq $0x8, %rsp
popq %rbx
popq %r14
popq %r15
popq %rbp
jmp 0x9668
pushq $0x1
popq %rsi
movq %r14, %rdi
addq $0x8, %rsp
popq %rbx
popq %r14
popq %r15
popq %rbp
jmp 0x966e
pushq $0x1
popq %rsi
movq %r14, %rdi
addq $0x8, %rsp
popq %rbx
popq %r14
popq %r15
popq %rbp
jmp 0x9674
movq %r14, %rdi
callq 0xd080
movl %eax, %ebp
movq %r14, %rdi
callq 0xd090
cmpl %eax, %ebp
jne 0xa684
movq 0x1c99c(%rip), %rbx     # 0x26fc8
leaq 0x1124b(%rip), %rsi     # 0x1b87e
movq %rbx, %rdi
callq 0x31d0
movq %rbx, %rdi
callq 0x30d0
leaq 0x11238(%rip), %rsi     # 0x1b882
movq %rax, %rdi
callq 0x31d0
movq %rax, %rdi
callq 0x30d0
movl $0x16e360, %edi         # imm = 0x16E360
callq 0x32a0
leaq 0x1123d(%rip), %rsi     # 0x1b8a8
movq %rbx, %rdi
callq 0x31d0
leaq 0x13129(%rip), %rsi     # 0x1d7a3
movq %rbx, %rdi
callq 0x31d0
jmp 0xa6b3
leaq 0x6(%rsp), %rdx
movq %rbx, %rsi
callq 0xbb2c
testb %al, %al
je 0xa6b3
movswq 0x6(%rsp), %r15
movq (%rbx), %rax
movq -0x8(%rax,%r15,8), %rsi
movq %r14, %rdi
callq 0x94ea
testb %al, %al
jne 0xa58d
xorl %ebp, %ebp
movl %ebp, %eax
addq $0x8, %rsp
popq %rbx
popq %r14
popq %r15
popq %rbp
retq