// File: Agusyc[P]CTRPG/src/battle.cpp
// Function: Battle::useItem()
int Battle::useItem() {
    unsigned int choice;
    bool exitLoop = false;
    while (!exitLoop) {
        for (unsigned int i = 0; i < player.items.size(); i++) {
            cout << i + 1 << ". " << player.items.at(i).name << endl;
        }

        cout << player.items.size() + 1 << ". Go back" << endl;

        cout << "Your choice: ";

        cin >> choice;

        cout << endl;

        if (choice == player.items.size() + 1) {
            return 1;
        }

        if (choice > player.items.size() || choice < 1) {
            printMessage("That's not a valid choice...");
            cout << endl;
            continue;
        }

        exitLoop = true;
    }

    Item item = player.items.at(choice - 1);

    stringstream ss;

    ss << "The item " << YELLOW << item.name << WHITE << ":" << endl;

    if (item.attackBoost != 0) {
        ss << "Boosts your attack by " << GREEN << item.attackBoost << WHITE << endl;
        player.attack += item.attackBoost;
    }

    if (item.defenseBoost != 0) {
        ss << "Boosts your defense by " << GREEN << item.defenseBoost << WHITE << endl;
        player.defense += item.defenseBoost;
    }

    if (item.manaRecover != 0) {
        ss << "Gives you " << GREEN << item.manaRecover << WHITE << " mana." << endl;
        player.mana += item.manaRecover;
    }

    if (item.staminaRecover != 0) {
        ss << "Gives you " << GREEN << item.staminaRecover << WHITE << " stamina." << endl;
        player.stamina += item.staminaRecover;
    }

    if (item.hpRecover != 0) {
        ss << "Gives you " << GREEN << item.hpRecover << WHITE << " HP." << endl;
        player.hp += item.hpRecover;
    }

    cout << ss.str() << endl;

    player.items.erase(player.items.begin() + item.id); // Delete item with index "item.id"

    return 0;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x3c0, %rsp            # imm = 0x3C0
movq %rdi, -0x10(%rbp)
movq -0x10(%rbp), %rax
movq %rax, -0x290(%rbp)
movb $0x0, -0x15(%rbp)
movb -0x15(%rbp), %al
xorb $-0x1, %al
testb $0x1, %al
jne 0x670c
jmp 0x698f
movl $0x0, -0x1c(%rbp)
movq -0x290(%rbp), %rdi
movl -0x1c(%rbp), %eax
movq %rax, -0x298(%rbp)
addq $0x60, %rdi
callq 0x86d0
movq %rax, %rcx
movq -0x298(%rbp), %rax
cmpq %rcx, %rax
jae 0x67a5
movl -0x1c(%rbp), %esi
addl $0x1, %esi
movq 0x11887(%rip), %rdi     # 0x17fd0
callq 0x3380
movq %rax, %rdi
leaq 0xa9df(%rip), %rsi      # 0x11137
callq 0x3290
movq -0x290(%rbp), %rdi
movq %rax, -0x2a0(%rbp)
addq $0x60, %rdi
movl -0x1c(%rbp), %eax
movl %eax, %esi
callq 0x86f0
movq -0x2a0(%rbp), %rdi
movq %rax, %rsi
callq 0x3230
movq %rax, %rdi
movq 0x1182e(%rip), %rsi     # 0x17fc0
callq 0x32b0
movl -0x1c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x1c(%rbp)
jmp 0x6713
movq -0x290(%rbp), %rdi
addq $0x60, %rdi
callq 0x86d0
movq %rax, %rsi
addq $0x1, %rsi
movq 0x1180d(%rip), %rdi     # 0x17fd0
callq 0x30a0
movq %rax, %rdi
leaq 0xa968(%rip), %rsi      # 0x1113a
callq 0x3290
movq %rax, %rdi
movq 0x117df(%rip), %rsi     # 0x17fc0
callq 0x32b0
movq 0x117e3(%rip), %rdi     # 0x17fd0
leaq 0xa92b(%rip), %rsi      # 0x1111f
callq 0x3290
movq 0x117e0(%rip), %rdi     # 0x17fe0
leaq -0x14(%rbp), %rsi
callq 0x3060
movq 0x117c0(%rip), %rdi     # 0x17fd0
movq 0x117a9(%rip), %rsi     # 0x17fc0
callq 0x32b0
movq -0x290(%rbp), %rdi
movl -0x14(%rbp), %eax
movq %rax, -0x2a8(%rbp)
addq $0x60, %rdi
callq 0x86d0
movq %rax, %rcx
movq -0x2a8(%rbp), %rax
addq $0x1, %rcx
cmpq %rcx, %rax
jne 0x6855
movl $0x1, -0x4(%rbp)
jmp 0x6f2a
movq -0x290(%rbp), %rdi
movl -0x14(%rbp), %eax
movq %rax, -0x2b0(%rbp)
addq $0x60, %rdi
callq 0x86d0
movq %rax, %rcx
movq -0x2b0(%rbp), %rax
cmpq %rcx, %rax
ja 0x6888
cmpl $0x1, -0x14(%rbp)
jae 0x6986
leaq -0x41(%rbp), %rdi
movq %rdi, -0x2b8(%rbp)
callq 0x3540
movq -0x2b8(%rbp), %rdx
leaq 0xa89e(%rip), %rsi      # 0x11144
leaq -0x40(%rbp), %rdi
callq 0x33a0
jmp 0x68b1
leaq -0x79(%rbp), %rdi
movq %rdi, -0x2c0(%rbp)
callq 0x3540
movq -0x2c0(%rbp), %rdx
leaq 0xa76d(%rip), %rsi      # 0x1103c
leaq -0x78(%rbp), %rdi
callq 0x33a0
jmp 0x68da
leaq -0x40(%rbp), %rdi
leaq -0x78(%rbp), %rsi
movl $0x23, %edx
movl $0x12c, %ecx            # imm = 0x12C
movl $0x1, %r8d
callq 0x10e00
jmp 0x68f9
leaq -0x78(%rbp), %rdi
callq 0x31b0
leaq -0x79(%rbp), %rdi
callq 0x32d0
leaq -0x40(%rbp), %rdi
callq 0x31b0
leaq -0x41(%rbp), %rdi
callq 0x32d0
movq 0x116ac(%rip), %rdi     # 0x17fd0
movq 0x11695(%rip), %rsi     # 0x17fc0
callq 0x32b0
jmp 0x66fe
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x50(%rbp)
movl %eax, -0x54(%rbp)
jmp 0x6978
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x50(%rbp)
movl %eax, -0x54(%rbp)
jmp 0x6966
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x50(%rbp)
movl %eax, -0x54(%rbp)
leaq -0x78(%rbp), %rdi
callq 0x31b0
leaq -0x79(%rbp), %rdi
callq 0x32d0
leaq -0x40(%rbp), %rdi
callq 0x31b0
leaq -0x41(%rbp), %rdi
callq 0x32d0
jmp 0x6f36
movb $0x1, -0x15(%rbp)
jmp 0x66fe
movq -0x290(%rbp), %rdi
addq $0x60, %rdi
movl -0x14(%rbp), %eax
decl %eax
movl %eax, %esi
callq 0x86f0
movq %rax, %rsi
leaq -0xc0(%rbp), %rdi
callq 0x8730
leaq -0x248(%rbp), %rdi
callq 0x31d0
jmp 0x69c3
leaq -0x238(%rbp), %rdi
leaq 0xa8fa(%rip), %rsi      # 0x112cb
callq 0x3290
movq %rax, -0x2c8(%rbp)
jmp 0x69df
movq -0x2c8(%rbp), %rdi
leaq 0xa643(%rip), %rsi      # 0x11030
callq 0x3290
movq %rax, -0x2d0(%rbp)
jmp 0x69fb
movq -0x2d0(%rbp), %rdi
leaq -0xc0(%rbp), %rsi
callq 0x3230
movq %rax, -0x2d8(%rbp)
jmp 0x6a17
movq -0x2d8(%rbp), %rdi
leaq 0xa617(%rip), %rsi      # 0x1103c
callq 0x3290
movq %rax, -0x2e0(%rbp)
jmp 0x6a33
movq -0x2e0(%rbp), %rdi
leaq 0xaa6b(%rip), %rsi      # 0x114ac
callq 0x3290
movq %rax, -0x2e8(%rbp)
jmp 0x6a4f
movq -0x2e8(%rbp), %rdi
movq 0x11563(%rip), %rsi     # 0x17fc0
callq 0x32b0
jmp 0x6a64
cmpl $0x0, -0xa0(%rbp)
je 0x6b2c
leaq -0x238(%rbp), %rdi
leaq 0xa856(%rip), %rsi      # 0x112d5
callq 0x3290
movq %rax, -0x2f0(%rbp)
jmp 0x6a8d
movq -0x2f0(%rbp), %rdi
leaq 0xa674(%rip), %rsi      # 0x1110f
callq 0x3290
movq %rax, -0x2f8(%rbp)
jmp 0x6aa9
movq -0x2f8(%rbp), %rdi
movl -0xa0(%rbp), %esi
callq 0x3520
movq %rax, -0x300(%rbp)
jmp 0x6ac4
movq -0x300(%rbp), %rdi
leaq 0xa56a(%rip), %rsi      # 0x1103c
callq 0x3290
movq %rax, -0x308(%rbp)
jmp 0x6ae0
movq -0x308(%rbp), %rdi
movq 0x114d2(%rip), %rsi     # 0x17fc0
callq 0x32b0
jmp 0x6af5
movq -0x290(%rbp), %rax
movl -0xa0(%rbp), %ecx
addl 0x20(%rax), %ecx
movl %ecx, 0x20(%rax)
jmp 0x6b2c
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x50(%rbp)
movl %eax, -0x54(%rbp)
jmp 0x6f1c
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x50(%rbp)
movl %eax, -0x54(%rbp)
jmp 0x6f10
cmpl $0x0, -0x9c(%rbp)
je 0x6bd0
leaq -0x238(%rbp), %rdi
leaq 0xa7a5(%rip), %rsi      # 0x112ec
callq 0x3290
movq %rax, -0x310(%rbp)
jmp 0x6b55
movq -0x310(%rbp), %rdi
leaq 0xa5ac(%rip), %rsi      # 0x1110f
callq 0x3290
movq %rax, -0x318(%rbp)
jmp 0x6b71
movq -0x318(%rbp), %rdi
movl -0x9c(%rbp), %esi
callq 0x3520
movq %rax, -0x320(%rbp)
jmp 0x6b8c
movq -0x320(%rbp), %rdi
leaq 0xa4a2(%rip), %rsi      # 0x1103c
callq 0x3290
movq %rax, -0x328(%rbp)
jmp 0x6ba8
movq -0x328(%rbp), %rdi
movq 0x1140a(%rip), %rsi     # 0x17fc0
callq 0x32b0
jmp 0x6bbd
movq -0x290(%rbp), %rax
movl -0x9c(%rbp), %ecx
addl 0x24(%rax), %ecx
movl %ecx, 0x24(%rax)
cmpl $0x0, -0x98(%rbp)
je 0x6c90
leaq -0x238(%rbp), %rdi
leaq 0xa719(%rip), %rsi      # 0x11304
callq 0x3290
movq %rax, -0x330(%rbp)
jmp 0x6bf9
movq -0x330(%rbp), %rdi
leaq 0xa508(%rip), %rsi      # 0x1110f
callq 0x3290
movq %rax, -0x338(%rbp)
jmp 0x6c15
movq -0x338(%rbp), %rdi
movl -0x98(%rbp), %esi
callq 0x3520
movq %rax, -0x340(%rbp)
jmp 0x6c30
movq -0x340(%rbp), %rdi
leaq 0xa3fe(%rip), %rsi      # 0x1103c
callq 0x3290
movq %rax, -0x348(%rbp)
jmp 0x6c4c
movq -0x348(%rbp), %rdi
leaq 0xa6b5(%rip), %rsi      # 0x1130f
callq 0x3290
movq %rax, -0x350(%rbp)
jmp 0x6c68
movq -0x350(%rbp), %rdi
movq 0x1134a(%rip), %rsi     # 0x17fc0
callq 0x32b0
jmp 0x6c7d
movq -0x290(%rbp), %rax
movl -0x98(%rbp), %ecx
addl 0x2c(%rax), %ecx
movl %ecx, 0x2c(%rax)
cmpl $0x0, -0x94(%rbp)
je 0x6d50
leaq -0x238(%rbp), %rdi
leaq 0xa659(%rip), %rsi      # 0x11304
callq 0x3290
movq %rax, -0x358(%rbp)
jmp 0x6cb9
movq -0x358(%rbp), %rdi
leaq 0xa448(%rip), %rsi      # 0x1110f
callq 0x3290
movq %rax, -0x360(%rbp)
jmp 0x6cd5
movq -0x360(%rbp), %rdi
movl -0x94(%rbp), %esi
callq 0x3520
movq %rax, -0x368(%rbp)
jmp 0x6cf0
movq -0x368(%rbp), %rdi
leaq 0xa33e(%rip), %rsi      # 0x1103c
callq 0x3290
movq %rax, -0x370(%rbp)
jmp 0x6d0c
movq -0x370(%rbp), %rdi
leaq 0xa5fc(%rip), %rsi      # 0x11316
callq 0x3290
movq %rax, -0x378(%rbp)
jmp 0x6d28
movq -0x378(%rbp), %rdi
movq 0x1128a(%rip), %rsi     # 0x17fc0
callq 0x32b0
jmp 0x6d3d
movq -0x290(%rbp), %rax
movl -0x94(%rbp), %ecx
addl 0x30(%rax), %ecx
movl %ecx, 0x30(%rax)
cmpl $0x0, -0x90(%rbp)
je 0x6e10
leaq -0x238(%rbp), %rdi
leaq 0xa599(%rip), %rsi      # 0x11304
callq 0x3290
movq %rax, -0x380(%rbp)
jmp 0x6d79
movq -0x380(%rbp), %rdi
leaq 0xa388(%rip), %rsi      # 0x1110f
callq 0x3290
movq %rax, -0x388(%rbp)
jmp 0x6d95
movq -0x388(%rbp), %rdi
movl -0x90(%rbp), %esi
callq 0x3520
movq %rax, -0x390(%rbp)
jmp 0x6db0
movq -0x390(%rbp), %rdi
leaq 0xa27e(%rip), %rsi      # 0x1103c
callq 0x3290
movq %rax, -0x398(%rbp)
jmp 0x6dcc
movq -0x398(%rbp), %rdi
leaq 0xa425(%rip), %rsi      # 0x111ff
callq 0x3290
movq %rax, -0x3a0(%rbp)
jmp 0x6de8
movq -0x3a0(%rbp), %rdi
movq 0x111ca(%rip), %rsi     # 0x17fc0
callq 0x32b0
jmp 0x6dfd
movq -0x290(%rbp), %rax
movl -0x90(%rbp), %ecx
addl 0x34(%rax), %ecx
movl %ecx, 0x34(%rax)
leaq -0x268(%rbp), %rdi
leaq -0x248(%rbp), %rsi
callq 0x3280
jmp 0x6e25
movq 0x111a4(%rip), %rdi     # 0x17fd0
leaq -0x268(%rbp), %rsi
callq 0x3230
movq %rax, -0x3a8(%rbp)
jmp 0x6e41
movq -0x3a8(%rbp), %rdi
movq 0x11171(%rip), %rsi     # 0x17fc0
callq 0x32b0
jmp 0x6e56
leaq -0x268(%rbp), %rdi
callq 0x31b0
movq -0x290(%rbp), %rdi
addq $0x60, %rdi
movq %rdi, -0x3b8(%rbp)
callq 0x87f0
movq %rax, -0x280(%rbp)
movslq -0x84(%rbp), %rsi
leaq -0x280(%rbp), %rdi
callq 0x8820
movq %rax, -0x278(%rbp)
leaq -0x270(%rbp), %rdi
leaq -0x278(%rbp), %rsi
callq 0x8860
movq -0x3b8(%rbp), %rdi
movq -0x270(%rbp), %rsi
callq 0x8780
movq %rax, -0x3b0(%rbp)
jmp 0x6ec9
movq -0x3b0(%rbp), %rax
movq %rax, -0x288(%rbp)
movl $0x0, -0x4(%rbp)
leaq -0x248(%rbp), %rdi
callq 0x31e0
leaq -0xc0(%rbp), %rdi
callq 0x85f0
jmp 0x6f2a
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x50(%rbp)
movl %eax, -0x54(%rbp)
leaq -0x268(%rbp), %rdi
callq 0x31b0
leaq -0x248(%rbp), %rdi
callq 0x31e0
leaq -0xc0(%rbp), %rdi
callq 0x85f0
jmp 0x6f36
movl -0x4(%rbp), %eax
addq $0x3c0, %rsp            # imm = 0x3C0
popq %rbp
retq
movq -0x50(%rbp), %rdi
callq 0x3530
nop