// File: MichaelXanth[P]RPG_Game/Living/Heroes/Hero.cpp
// Function: Hero::DisplayWeapons(bool)
bool Hero::DisplayWeapons(bool isInBattle)
{
    int arrow = 0;
    int lines;

    Weapon* prevWeaponBoth = equippedWeaponBoth;
    Weapon* prevWeaponLeft = equippedWeaponLeft;
    Weapon* prevWeaponRight = equippedWeaponRight;

    lines = 4 * weaponsArray.size();

    if(!weaponsArray.size())
    {
        cout << "\033[s";
        cout << endl << "Sorry, there are no available weapons." << endl;

        usleep(1500000);

        cout << "\033[u";
        cout << "\033[J";

        return false;
    }

    if(isInBattle)
        cout << endl << "Press 'b' to cancel, 'c' to confirm, 'enter' to equip or unequip a weapon and 'u' to unequip all equipped weapons" << endl << endl;
    else
        cout << endl << "Press 'b' to go back and confirm, 'c' to cancel, 'enter' to equip or unequip a weapon and 'u' to unequip all equipped weapons" << endl << endl;

    while(true)
    {
        char selection;

        for(unsigned int i = 0; i < weaponsArray.size(); i++)
        {
            if(arrow == i)
                cout << " \033[1;33m~> ";
            else
                cout << "    ";

            cout << weaponsArray[i]->GetName() << "\033[0m";

            if(equippedWeaponLeft == weaponsArray[i])
                cout << " \033[38;5;10m(equiped on the left hand) \033[0m";
            else if(equippedWeaponRight == weaponsArray[i])
                cout << " \033[38;5;10m(equiped on the right hand)\033[0m";
            else if(equippedWeaponBoth == weaponsArray[i])
                cout << " \033[38;5;10m(equiped on both hands)    \033[0m";
            else
                cout << "                            ";

            cout << endl;

            cout << "    \u2022 Damage: " << weaponsArray[i]->GetDamage() << endl;
            if(weaponsArray[i]->TwoHanded())
                cout << "    \u2022 Hands:  Both hands required" << endl << endl;
            else
                cout << "    \u2022 Hands:  1 hand required" << endl << endl;
        }

        selection = getch();

        if((isInBattle && selection == 'b') || (!isInBattle && selection == 'c'))
        {
            if (equippedWeaponBoth != NULL)
            {
                weaponDamage -= equippedWeaponBoth->GetDamage();
                equippedWeaponBoth = NULL;
            }

            if (equippedWeaponRight != NULL)
            {
                weaponDamage -= equippedWeaponRight->GetDamage();
                equippedWeaponRight = NULL;
            }

            if (equippedWeaponLeft != NULL)
            {
                weaponDamage -= equippedWeaponLeft->GetDamage();
                equippedWeaponLeft = NULL;
            }

            equippedWeaponBoth = prevWeaponBoth;
            equippedWeaponLeft = prevWeaponLeft;
            equippedWeaponRight = prevWeaponRight;

            weaponDamage = 0;

            if(equippedWeaponBoth != NULL)
                weaponDamage += equippedWeaponBoth->GetDamage();

            if(equippedWeaponRight != NULL)
                weaponDamage += equippedWeaponRight->GetDamage();

            if(equippedWeaponLeft != NULL)
                weaponDamage += equippedWeaponLeft->GetDamage();
        }

        if(selection == 'b')
        {
            cout << "\033[" << lines + 3 << "A";
            cout << "\033[J";
            /*for(int i = 0; i < lines + 6; i++)
                cout << "\033[1A\033[K";
            cout << "\033[5B";*/
            return false;
        }
        else if(selection == 'c')
        {
            /*if(isInBattle)
            {
                cout << "\033[" << lines + 11 << "A";
                cout << "\033[J";
                cout << "\t\t\t\tCHECKPOINT\n";
                usleep(1500000);
                cout << "\033[1A\033[K";
            }
            else
            {*/
                cout << "\033[" << lines + 3 << "A";
                cout << "\033[J";
            //}

            /*for(int i = 0; i < lines + 11; i++)
                cout << "\033[1A\033[K";*/

            return true;
        }
        else if(selection == 'u')
        {
            equippedWeaponBoth = NULL;
            equippedWeaponRight = NULL;
            equippedWeaponLeft = NULL;

            weaponDamage = 0;
        }
        else if(selection == '\n')
        {
            if(weaponsArray[arrow] == equippedWeaponBoth)
            {
                weaponDamage -= equippedWeaponBoth->GetDamage();
                equippedWeaponBoth = NULL;
            }
            else if(weaponsArray[arrow] == equippedWeaponRight)
            {
                weaponDamage -= equippedWeaponRight->GetDamage();
                equippedWeaponRight = NULL;
            }
            else if(weaponsArray[arrow] == equippedWeaponLeft)
            {
                weaponDamage -= equippedWeaponLeft->GetDamage();
                equippedWeaponLeft = NULL;
            }
            else
            {
                int selectedHand;
                char newSelection = ' ';

                if(weaponsArray[arrow]->TwoHanded() == true)
                {
                    selectedHand = 3;
                }
                else
                {
                    cout << "Press 'c' to cancel!" << endl;
                    cout << "Press 1 for right hand or 2 for left hand: ";

                    do{
                        newSelection = getch();

                        if(newSelection == 'c')
                            break;
                    }while(newSelection < '1' || newSelection > '2');

                    selectedHand = newSelection - '0';

                    cout << endl << "\033[2A\033[J";
                }

                if(newSelection != 'c')
                    EquipWeapon(weaponsArray[arrow],selectedHand);
            }
        }
        else if(selection == 'w' && arrow)
            arrow--;
        else if(selection == 's' && arrow < weaponsArray.size() - 1)
            arrow++;

        cout << "\033[" << lines << "A";
    }
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0xd0, %rsp
movb %sil, %al
movq %rdi, -0x10(%rbp)
andb $0x1, %al
movb %al, -0x11(%rbp)
movq -0x10(%rbp), %rdi
movq %rdi, -0x80(%rbp)
movl $0x0, -0x18(%rbp)
movq 0xd8(%rdi), %rax
movq %rax, -0x28(%rbp)
movq 0xd0(%rdi), %rax
movq %rax, -0x30(%rbp)
movq 0xc8(%rdi), %rax
movq %rax, -0x38(%rbp)
addq $0x80, %rdi
callq 0x26e80
movq -0x80(%rbp), %rdi
shlq $0x2, %rax
movl %eax, -0x1c(%rbp)
addq $0x80, %rdi
callq 0x26e80
cmpq $0x0, %rax
jne 0x256cd
movq 0x28971(%rip), %rdi     # 0x4dfc8
leaq 0x18220(%rip), %rsi     # 0x3d87e
callq 0x4260
movq 0x2895e(%rip), %rdi     # 0x4dfc8
movq 0x28947(%rip), %rsi     # 0x4dfb8
callq 0x4290
movq %rax, %rdi
leaq 0x1a661(%rip), %rsi     # 0x3fce1
callq 0x4260
movq %rax, %rdi
movq 0x28929(%rip), %rsi     # 0x4dfb8
callq 0x4290
movl $0x16e360, %edi         # imm = 0x16E360
callq 0x4390
movq 0x28923(%rip), %rdi     # 0x4dfc8
leaq 0x181fc(%rip), %rsi     # 0x3d8a8
callq 0x4260
movq 0x28910(%rip), %rdi     # 0x4dfc8
leaq 0x1a174(%rip), %rsi     # 0x3f833
callq 0x4260
movb $0x0, -0x1(%rbp)
jmp 0x25f66
testb $0x1, -0x11(%rbp)
je 0x25715
movq 0x288ee(%rip), %rdi     # 0x4dfc8
movq 0x288d7(%rip), %rsi     # 0x4dfb8
callq 0x4290
movq %rax, %rdi
leaq 0x1a618(%rip), %rsi     # 0x3fd08
callq 0x4260
movq %rax, %rdi
movq 0x288b9(%rip), %rsi     # 0x4dfb8
callq 0x4290
movq %rax, %rdi
movq 0x288aa(%rip), %rsi     # 0x4dfb8
callq 0x4290
jmp 0x25755
movq 0x288ac(%rip), %rdi     # 0x4dfc8
movq 0x28895(%rip), %rsi     # 0x4dfb8
callq 0x4290
movq %rax, %rdi
leaq 0x1a648(%rip), %rsi     # 0x3fd7a
callq 0x4260
movq %rax, %rdi
movq 0x28877(%rip), %rsi     # 0x4dfb8
callq 0x4290
movq %rax, %rdi
movq 0x28868(%rip), %rsi     # 0x4dfb8
callq 0x4290
jmp 0x25757
movl $0x0, -0x40(%rbp)
movq -0x80(%rbp), %rdi
movl -0x40(%rbp), %eax
movq %rax, -0x88(%rbp)
addq $0x80, %rdi
callq 0x26e80
movq %rax, %rcx
movq -0x88(%rbp), %rax
cmpq %rcx, %rax
jae 0x25a24
movl -0x18(%rbp), %eax
cmpl -0x40(%rbp), %eax
jne 0x257a8
movq 0x2882e(%rip), %rdi     # 0x4dfc8
leaq 0x1a421(%rip), %rsi     # 0x3fbc2
callq 0x4260
jmp 0x257bb
movq 0x28819(%rip), %rdi     # 0x4dfc8
leaq 0x18050(%rip), %rsi     # 0x3d806
callq 0x4260
movq -0x80(%rbp), %rdi
subq $-0x80, %rdi
movl -0x40(%rbp), %eax
movl %eax, %esi
callq 0x27540
movq (%rax), %rsi
movq (%rsi), %rax
movq (%rax), %rax
leaq -0x60(%rbp), %rdi
movq %rdi, -0x98(%rbp)
callq *%rax
movq -0x98(%rbp), %rsi
movq 0x287d7(%rip), %rdi     # 0x4dfc8
callq 0x4210
movq %rax, -0x90(%rbp)
jmp 0x257ff
movq -0x90(%rbp), %rdi
leaq 0x1a667(%rip), %rsi     # 0x3fe74
callq 0x4260
jmp 0x25814
leaq -0x60(%rbp), %rdi
callq 0x4160
movq -0x80(%rbp), %rdi
movq 0xd0(%rdi), %rax
movq %rax, -0xa0(%rbp)
addq $0x80, %rdi
movl -0x40(%rbp), %eax
movl %eax, %esi
callq 0x27540
movq %rax, %rcx
movq -0xa0(%rbp), %rax
cmpq (%rcx), %rax
jne 0x25881
movq 0x28772(%rip), %rdi     # 0x4dfc8
leaq 0x1a59b(%rip), %rsi     # 0x3fdf8
callq 0x4260
jmp 0x25926
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x68(%rbp)
movl %eax, -0x6c(%rbp)
leaq -0x60(%rbp), %rdi
callq 0x4160
jmp 0x25f74
movq -0x80(%rbp), %rdi
movq 0xc8(%rdi), %rax
movq %rax, -0xa8(%rbp)
addq $0x80, %rdi
movl -0x40(%rbp), %eax
movl %eax, %esi
callq 0x27540
movq %rax, %rcx
movq -0xa8(%rbp), %rax
cmpq (%rcx), %rax
jne 0x258c8
movq 0x2870e(%rip), %rdi     # 0x4dfc8
leaq 0x1a562(%rip), %rsi     # 0x3fe23
callq 0x4260
jmp 0x25924
movq -0x80(%rbp), %rdi
movq 0xd8(%rdi), %rax
movq %rax, -0xb0(%rbp)
addq $0x80, %rdi
movl -0x40(%rbp), %eax
movl %eax, %esi
callq 0x27540
movq %rax, %rcx
movq -0xb0(%rbp), %rax
cmpq (%rcx), %rax
jne 0x2590f
movq 0x286c7(%rip), %rdi     # 0x4dfc8
leaq 0x1a546(%rip), %rsi     # 0x3fe4e
callq 0x4260
jmp 0x25922
movq 0x286b2(%rip), %rdi     # 0x4dfc8
leaq 0x17ed1(%rip), %rsi     # 0x3d7ee
callq 0x4260
jmp 0x25924
jmp 0x25926
movq 0x2869b(%rip), %rdi     # 0x4dfc8
movq 0x28684(%rip), %rsi     # 0x4dfb8
callq 0x4290
movq 0x28688(%rip), %rdi     # 0x4dfc8
leaq 0x1a532(%rip), %rsi     # 0x3fe79
callq 0x4260
movq -0x80(%rbp), %rdi
movq %rax, -0xb8(%rbp)
addq $0x80, %rdi
movl -0x40(%rbp), %eax
movl %eax, %esi
callq 0x27540
movq (%rax), %rdi
callq 0x1e5e0
movq -0xb8(%rbp), %rdi
movl %eax, %esi
callq 0x4370
movq %rax, %rdi
movq 0x28630(%rip), %rsi     # 0x4dfb8
callq 0x4290
movq -0x80(%rbp), %rdi
addq $0x80, %rdi
movl -0x40(%rbp), %eax
movl %eax, %esi
callq 0x27540
movq (%rax), %rdi
callq 0x1e600
testb $0x1, %al
jne 0x259b0
jmp 0x259e3
movq 0x28611(%rip), %rdi     # 0x4dfc8
leaq 0x1a4cc(%rip), %rsi     # 0x3fe8a
callq 0x4260
movq %rax, %rdi
movq 0x285eb(%rip), %rsi     # 0x4dfb8
callq 0x4290
movq %rax, %rdi
movq 0x285dc(%rip), %rsi     # 0x4dfb8
callq 0x4290
jmp 0x25a14
movq 0x285de(%rip), %rdi     # 0x4dfc8
leaq 0x1a4bd(%rip), %rsi     # 0x3feae
callq 0x4260
movq %rax, %rdi
movq 0x285b8(%rip), %rsi     # 0x4dfb8
callq 0x4290
movq %rax, %rdi
movq 0x285a9(%rip), %rsi     # 0x4dfb8
callq 0x4290
jmp 0x25a16
movl -0x40(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x40(%rbp)
jmp 0x2575e
callq 0x1e820
movb %al, -0x39(%rbp)
testb $0x1, -0x11(%rbp)
je 0x25a3b
movsbl -0x39(%rbp), %eax
cmpl $0x62, %eax
je 0x25a52
testb $0x1, -0x11(%rbp)
jne 0x25bc6
movsbl -0x39(%rbp), %eax
cmpl $0x63, %eax
jne 0x25bc6
movq -0x80(%rbp), %rax
cmpq $0x0, 0xd8(%rax)
je 0x25a8f
movq -0x80(%rbp), %rax
movq 0xd8(%rax), %rdi
callq 0x1e5e0
movl %eax, %edx
movq -0x80(%rbp), %rax
movl 0xfc(%rax), %ecx
subl %edx, %ecx
movl %ecx, 0xfc(%rax)
movq $0x0, 0xd8(%rax)
movq -0x80(%rbp), %rax
cmpq $0x0, 0xc8(%rax)
je 0x25acc
movq -0x80(%rbp), %rax
movq 0xc8(%rax), %rdi
callq 0x1e5e0
movl %eax, %edx
movq -0x80(%rbp), %rax
movl 0xfc(%rax), %ecx
subl %edx, %ecx
movl %ecx, 0xfc(%rax)
movq $0x0, 0xc8(%rax)
movq -0x80(%rbp), %rax
cmpq $0x0, 0xd0(%rax)
je 0x25b09
movq -0x80(%rbp), %rax
movq 0xd0(%rax), %rdi
callq 0x1e5e0
movl %eax, %edx
movq -0x80(%rbp), %rax
movl 0xfc(%rax), %ecx
subl %edx, %ecx
movl %ecx, 0xfc(%rax)
movq $0x0, 0xd0(%rax)
movq -0x80(%rbp), %rax
movq -0x28(%rbp), %rcx
movq %rcx, 0xd8(%rax)
movq -0x30(%rbp), %rcx
movq %rcx, 0xd0(%rax)
movq -0x38(%rbp), %rcx
movq %rcx, 0xc8(%rax)
movl $0x0, 0xfc(%rax)
cmpq $0x0, 0xd8(%rax)
je 0x25b64
movq -0x80(%rbp), %rax
movq 0xd8(%rax), %rdi
callq 0x1e5e0
movl %eax, %ecx
movq -0x80(%rbp), %rax
addl 0xfc(%rax), %ecx
movl %ecx, 0xfc(%rax)
movq -0x80(%rbp), %rax
cmpq $0x0, 0xc8(%rax)
je 0x25b94
movq -0x80(%rbp), %rax
movq 0xc8(%rax), %rdi
callq 0x1e5e0
movl %eax, %ecx
movq -0x80(%rbp), %rax
addl 0xfc(%rax), %ecx
movl %ecx, 0xfc(%rax)
movq -0x80(%rbp), %rax
cmpq $0x0, 0xd0(%rax)
je 0x25bc4
movq -0x80(%rbp), %rax
movq 0xd0(%rax), %rdi
callq 0x1e5e0
movl %eax, %ecx
movq -0x80(%rbp), %rax
addl 0xfc(%rax), %ecx
movl %ecx, 0xfc(%rax)
jmp 0x25bc6
movsbl -0x39(%rbp), %eax
cmpl $0x62, %eax
jne 0x25c1b
movq 0x283f2(%rip), %rdi     # 0x4dfc8
leaq 0x177fe(%rip), %rsi     # 0x3d3db
callq 0x4260
movq %rax, %rdi
movl -0x1c(%rbp), %esi
addl $0x3, %esi
callq 0x4430
movq %rax, %rdi
leaq 0x180d8(%rip), %rsi     # 0x3dcd2
callq 0x4260
movq 0x283c2(%rip), %rdi     # 0x4dfc8
leaq 0x19c26(%rip), %rsi     # 0x3f833
callq 0x4260
movb $0x0, -0x1(%rbp)
jmp 0x25f66
movsbl -0x39(%rbp), %eax
cmpl $0x63, %eax
jne 0x25c70
movq 0x2839d(%rip), %rdi     # 0x4dfc8
leaq 0x177a9(%rip), %rsi     # 0x3d3db
callq 0x4260
movq %rax, %rdi
movl -0x1c(%rbp), %esi
addl $0x3, %esi
callq 0x4430
movq %rax, %rdi
leaq 0x18083(%rip), %rsi     # 0x3dcd2
callq 0x4260
movq 0x2836d(%rip), %rdi     # 0x4dfc8
leaq 0x19bd1(%rip), %rsi     # 0x3f833
callq 0x4260
movb $0x1, -0x1(%rbp)
jmp 0x25f66
movsbl -0x39(%rbp), %eax
cmpl $0x75, %eax
jne 0x25cad
movq -0x80(%rbp), %rax
movq $0x0, 0xd8(%rax)
movq $0x0, 0xc8(%rax)
movq $0x0, 0xd0(%rax)
movl $0x0, 0xfc(%rax)
jmp 0x25f30
movsbl -0x39(%rbp), %eax
cmpl $0xa, %eax
jne 0x25ed0
movq -0x80(%rbp), %rdi
addq $0x80, %rdi
movslq -0x18(%rbp), %rsi
callq 0x27540
movq -0x80(%rbp), %rcx
movq (%rax), %rax
cmpq 0xd8(%rcx), %rax
jne 0x25d12
movq -0x80(%rbp), %rax
movq 0xd8(%rax), %rdi
callq 0x1e5e0
movl %eax, %edx
movq -0x80(%rbp), %rax
movl 0xfc(%rax), %ecx
subl %edx, %ecx
movl %ecx, 0xfc(%rax)
movq $0x0, 0xd8(%rax)
jmp 0x25ece
movq -0x80(%rbp), %rdi
addq $0x80, %rdi
movslq -0x18(%rbp), %rsi
callq 0x27540
movq -0x80(%rbp), %rcx
movq (%rax), %rax
cmpq 0xc8(%rcx), %rax
jne 0x25d6a
movq -0x80(%rbp), %rax
movq 0xc8(%rax), %rdi
callq 0x1e5e0
movl %eax, %edx
movq -0x80(%rbp), %rax
movl 0xfc(%rax), %ecx
subl %edx, %ecx
movl %ecx, 0xfc(%rax)
movq $0x0, 0xc8(%rax)
jmp 0x25ecc
movq -0x80(%rbp), %rdi
addq $0x80, %rdi
movslq -0x18(%rbp), %rsi
callq 0x27540
movq -0x80(%rbp), %rcx
movq (%rax), %rax
cmpq 0xd0(%rcx), %rax
jne 0x25dc2
movq -0x80(%rbp), %rax
movq 0xd0(%rax), %rdi
callq 0x1e5e0
movl %eax, %edx
movq -0x80(%rbp), %rax
movl 0xfc(%rax), %ecx
subl %edx, %ecx
movl %ecx, 0xfc(%rax)
movq $0x0, 0xd0(%rax)
jmp 0x25eca
movq -0x80(%rbp), %rdi
movb $0x20, -0x71(%rbp)
addq $0x80, %rdi
movslq -0x18(%rbp), %rsi
callq 0x27540
movq (%rax), %rdi
callq 0x1e600
andb $0x1, %al
movzbl %al, %eax
cmpl $0x1, %eax
jne 0x25df8
movl $0x3, -0x70(%rbp)
jmp 0x25e99
movq 0x281c9(%rip), %rdi     # 0x4dfc8
leaq 0x1a0c8(%rip), %rsi     # 0x3fece
callq 0x4260
movq %rax, %rdi
movq 0x281a3(%rip), %rsi     # 0x4dfb8
callq 0x4290
movq 0x281a7(%rip), %rdi     # 0x4dfc8
leaq 0x1a0bb(%rip), %rsi     # 0x3fee3
callq 0x4260
callq 0x1e820
movb %al, -0x71(%rbp)
movsbl -0x71(%rbp), %eax
cmpl $0x63, %eax
jne 0x25e40
jmp 0x25e6d
jmp 0x25e42
movsbl -0x71(%rbp), %ecx
movb $0x1, %al
cmpl $0x31, %ecx
movb %al, -0xb9(%rbp)
jl 0x25e63
movsbl -0x71(%rbp), %eax
cmpl $0x32, %eax
setg %al
movb %al, -0xb9(%rbp)
movb -0xb9(%rbp), %al
testb $0x1, %al
jne 0x25e2d
movsbl -0x71(%rbp), %eax
subl $0x30, %eax
movl %eax, -0x70(%rbp)
movq 0x2814a(%rip), %rdi     # 0x4dfc8
movq 0x28133(%rip), %rsi     # 0x4dfb8
callq 0x4290
movq %rax, %rdi
leaq 0x1999b(%rip), %rsi     # 0x3f82f
callq 0x4260
movsbl -0x71(%rbp), %eax
cmpl $0x63, %eax
je 0x25ec8
movq -0x80(%rbp), %rdi
addq $0x80, %rdi
movslq -0x18(%rbp), %rsi
callq 0x27540
movq -0x80(%rbp), %rdi
movq (%rax), %rsi
movl -0x70(%rbp), %eax
movswl %ax, %edx
callq 0x20800
jmp 0x25eca
jmp 0x25ecc
jmp 0x25ece
jmp 0x25f2e
movsbl -0x39(%rbp), %eax
cmpl $0x77, %eax
jne 0x25eea
cmpl $0x0, -0x18(%rbp)
je 0x25eea
movl -0x18(%rbp), %eax
addl $-0x1, %eax
movl %eax, -0x18(%rbp)
jmp 0x25f2c
movsbl -0x39(%rbp), %eax
cmpl $0x73, %eax
jne 0x25f2a
movq -0x80(%rbp), %rdi
movslq -0x18(%rbp), %rax
movq %rax, -0xc8(%rbp)
addq $0x80, %rdi
callq 0x26e80
movq %rax, %rcx
movq -0xc8(%rbp), %rax
subq $0x1, %rcx
cmpq %rcx, %rax
jae 0x25f2a
movl -0x18(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x18(%rbp)
jmp 0x25f2c
jmp 0x25f2e
jmp 0x25f30
jmp 0x25f32
jmp 0x25f34
movq 0x2808d(%rip), %rdi     # 0x4dfc8
leaq 0x17499(%rip), %rsi     # 0x3d3db
callq 0x4260
movq %rax, %rdi
movl -0x1c(%rbp), %esi
callq 0x4430
movq %rax, %rdi
leaq 0x17d76(%rip), %rsi     # 0x3dcd2
callq 0x4260
jmp 0x25757
movb -0x1(%rbp), %al
andb $0x1, %al
addq $0xd0, %rsp
popq %rbp
retq
movq -0x68(%rbp), %rdi
callq 0x4440
nopl (%rax)