// File: /workspace/github_cpp_makefile_star2_O3/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 0xcb8f
movq %rcx, %rbx
movq %rsi, %r14
leaq 0x17947(%rip), %rax     # 0x24308
movslq (%rax,%rdx,4), %rcx
addq %rax, %rcx
jmpq *%rcx
leaq 0x6(%rsp), %rdx
movq %rbx, %rsi
callq 0xed28
testb %al, %al
je 0xcb8f
movswq 0x6(%rsp), %r15
movq (%rbx), %rax
movq -0x8(%rax,%r15,8), %rsi
movq %r14, %rdi
callq 0xb202
movq (%rbx), %rax
movq -0x8(%rax,%r15,8), %rdi
callq 0x10808
movb $0x1, %bpl
testb %al, %al
je 0xcb91
movq (%rbx), %rax
movq -0x8(%rax,%r15,8), %rdi
testq %rdi, %rdi
je 0xca23
movq (%rdi), %rax
callq *0x18(%rax)
movq (%rbx), %rax
leaq (%rax,%r15,8), %rsi
movq 0x8(%rbx), %rdx
cmpq %rdx, %rsi
je 0xca40
leaq -0x8(%rsi), %rdi
subq %rsi, %rdx
callq 0x32b0
movq 0x8(%rbx), %rdx
addq $-0x8, %rdx
movq %rdx, 0x8(%rbx)
jmp 0xcb91
movq %r14, %rdi
movl $0x1, %esi
addq $0x8, %rsp
popq %rbx
popq %r14
popq %r15
popq %rbp
jmp 0xb562
movq %r14, %rdi
movl $0x1, %esi
addq $0x8, %rsp
popq %rbx
popq %r14
popq %r15
popq %rbp
jmp 0xb568
movq %r14, %rdi
movl $0x1, %esi
addq $0x8, %rsp
popq %rbx
popq %r14
popq %r15
popq %rbp
jmp 0xb56e
movq %r14, %rdi
callq 0x10a26
movl %eax, %ebp
movq %r14, %rdi
callq 0x10a36
cmpl %eax, %ebp
jne 0xcb60
movq 0x22515(%rip), %rbx     # 0x2efc8
leaq 0x17dc4(%rip), %rsi     # 0x2487e
movl $0x3, %edx
movq %rbx, %rdi
callq 0x31e0
movq (%rbx), %rax
movq -0x18(%rax), %rdi
addq %rbx, %rdi
movl $0xa, %esi
callq 0x3190
movsbl %al, %esi
movq %rbx, %rdi
callq 0x3040
movq %rax, %rdi
callq 0x3100
movq %rax, %r14
leaq 0x17d8a(%rip), %rsi     # 0x24882
movl $0x25, %edx
movq %rax, %rdi
callq 0x31e0
movq (%r14), %rax
movq -0x18(%rax), %rdi
addq %r14, %rdi
movl $0xa, %esi
callq 0x3190
movsbl %al, %esi
movq %r14, %rdi
callq 0x3040
movq %rax, %rdi
callq 0x3100
movl $0x16e360, %edi         # imm = 0x16E360
callq 0x3260
leaq 0x17d6b(%rip), %rsi     # 0x248a8
movl $0x3, %edx
movq %rbx, %rdi
callq 0x31e0
leaq 0x19c52(%rip), %rsi     # 0x267a3
movl $0x3, %edx
movq %rbx, %rdi
callq 0x31e0
jmp 0xcb8f
leaq 0x6(%rsp), %rdx
movq %rbx, %rsi
callq 0xed28
testb %al, %al
je 0xcb8f
movswq 0x6(%rsp), %r15
movq (%rbx), %rax
movq -0x8(%rax,%r15,8), %rsi
movq %r14, %rdi
callq 0xb366
testb %al, %al
jne 0xc9f5
xorl %ebp, %ebp
movl %ebp, %eax
addq $0x8, %rsp
popq %rbx
popq %r14
popq %r15
popq %rbp
retq