// File: /workspace/github_cpp_makefile_star2_O1/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 0xcc1f
movq %rcx, %rbx
movq %rsi, %r14
leaq 0x178b3(%rip), %rax     # 0x24308
movslq (%rax,%rdx,4), %rcx
addq %rax, %rcx
jmpq *%rcx
leaq 0x6(%rsp), %rdx
movq %rbx, %rsi
callq 0xedbe
testb %al, %al
je 0xcc1f
movswq 0x6(%rsp), %r15
movq (%rbx), %rax
movq -0x8(%rax,%r15,8), %rsi
movq %r14, %rdi
callq 0xb21a
movq (%rbx), %rax
movq -0x8(%rax,%r15,8), %rdi
callq 0x108b8
movb $0x1, %bpl
testb %al, %al
je 0xcc21
movq (%rbx), %rax
movq -0x8(%rax,%r15,8), %rdi
testq %rdi, %rdi
je 0xcab4
movq (%rdi), %rax
callq *0x18(%rax)
shlq $0x3, %r15
addq (%rbx), %r15
movq 0x8(%rbx), %rdx
cmpq %rdx, %r15
je 0xcad3
leaq -0x8(%r15), %rdi
subq %r15, %rdx
movq %r15, %rsi
callq 0x32b0
addq $-0x8, 0x8(%rbx)
jmp 0xcc21
movq %r14, %rdi
movl $0x1, %esi
addq $0x8, %rsp
popq %rbx
popq %r14
popq %r15
popq %rbp
jmp 0xb57a
movq %r14, %rdi
movl $0x1, %esi
addq $0x8, %rsp
popq %rbx
popq %r14
popq %r15
popq %rbp
jmp 0xb580
movq %r14, %rdi
movl $0x1, %esi
addq $0x8, %rsp
popq %rbx
popq %r14
popq %r15
popq %rbp
jmp 0xb586
movq %r14, %rdi
callq 0x10ad6
movl %eax, %ebp
movq %r14, %rdi
callq 0x10ae6
cmpl %eax, %ebp
jne 0xcbf0
movq 0x22485(%rip), %rbx     # 0x2efc8
leaq 0x17d34(%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 0x17cfa(%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 0x17cdb(%rip), %rsi     # 0x248a8
movl $0x3, %edx
movq %rbx, %rdi
callq 0x31e0
leaq 0x19bc2(%rip), %rsi     # 0x267a3
movl $0x3, %edx
movq %rbx, %rdi
callq 0x31e0
jmp 0xcc1f
leaq 0x6(%rsp), %rdx
movq %rbx, %rsi
callq 0xedbe
testb %al, %al
je 0xcc1f
movswq 0x6(%rsp), %r15
movq (%rbx), %rax
movq -0x8(%rax,%r15,8), %rsi
movq %r14, %rdi
callq 0xb37e
testb %al, %al
jne 0xca89
xorl %ebp, %ebp
movl %ebp, %eax
addq $0x8, %rsp
popq %rbx
popq %r14
popq %r15
popq %rbp
retq