// File: /workspace/github_cpp_makefile_star2_O3/kongrigoriou[P]Text-Based-RPG/src/Market.cpp
// Function: Market::buy()
void Market::buy(){

	cout << "Which hero is buying?Type their name" << endl;
	string hero_name;
	Hero* h;
	list<Hero*> :: iterator hr;
	list <Hero*> hrList;
	list<Weapon*> ::iterator it;
	int flag = 0;

	int heroFlag = 0;													//check if the hero name exists
	while(heroFlag == 0){
		cin >> hero_name;
		hrList = team->get_HeroList();
		for(hr = hrList.begin(); hr != hrList.end(); ++hr){
			if((*hr)->get_name() == hero_name){
				h = *hr;
				heroFlag = 1;
				break;
			}
		}
		if(heroFlag == 0){
			cout << "I could not find that name. Try again" << endl;
			cin >> hero_name;
		}
	}

	cout << "What item do you want to buy? Press 1 for Weapon,2 for Armor,3 for Potion,4 for Spell" << endl;
	string answer;
	cin >> answer;
	while(answer != "1" && answer!= "2" && answer!="3" && answer!="4" ){
		cout <<"Wrong input,try again" << endl;
		cin >> answer;
	}
	displayItems();

	if(answer == "1"){

		cout << "Type the name of the weapon you want to buy" << endl;
		string weapon_name;
		cin >> weapon_name;
		
		while(flag == 0){
			for (it = Weapons.begin(); it !=  Weapons.end(); ++it){
				if(weapon_name == (*it)->get_name()){
					flag = 1;
					h->buy_Weapon(*it);
					cout << h->GetWeaponsListSize() << endl;
				}
			}
			if(flag==0){
				cout <<"Weapon doesnt exist.Try again" << endl;
				cin >> weapon_name;
			}	
		}

	}else if(answer == "2"){

		cout << "Type the name of the armor you want to buy" << endl;
		string armor_name;
		cin >> armor_name;
		list<Armor*> :: iterator ar;
		flag = 0;

		while(flag == 0){
			for(ar = Armors.begin(); ar != Armors.end(); ++ar){
				if(armor_name == (*ar)->get_name()){
					flag = 1;
					h->buy_Armor(*ar);
				}
			}
			if(flag==0){
				cout <<"Armor doesnt exist.Try again" << endl;
				cin >> armor_name;
			}
		}

	}else if(answer == "3"){

		cout << "Type the name of the potion you want to buy" << endl;
		string potion_name;
		cin >> potion_name;
		list<Potion*> :: iterator pt;
		flag = 0;

		while(flag == 0){
			for(pt = Potions.begin(); pt != Potions.end(); ++pt){
				if(potion_name == (*pt)->get_name()){
					flag = 1;
					h->buy_Potion(*pt);
				}
			}
			if(flag==0){
				cout <<"Potion doesnt exist.Try again" << endl;
				cin >> potion_name;
			}
		}

	}else if(answer == "4"){

		cout << "Type the name of the ice spell you want to buy" << endl;
		string spell_name;
		cin >> spell_name;
		list<Spell*> :: iterator is;
		flag = 0;

		while( flag == 0){
			for(is = Spells.begin(); is!= Spells.end(); ++is){
				if(spell_name == (*is)->get_name()){
					flag = 1;
					h->buy_Spell(*is);
				}
			}
			if(flag == 0){
				cout <<"Spell doesnt exist.Try again" << endl;
				cin >> spell_name;
			}
		}
	}
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0xb8, %rsp
movq %rdi, %rbx
movq 0xb956(%rip), %r14      # 0x13fd0
leaq 0x6040(%rip), %rsi      # 0xe6c1
movl $0x24, %edx
movq %r14, %rdi
callq 0x31c0
movq (%r14), %rax
movq -0x18(%rax), %rdi
addq %r14, %rdi
movl $0xa, %esi
callq 0x3160
movsbl %al, %esi
movq %r14, %rdi
callq 0x3040
movq %rax, %rdi
callq 0x3100
leaq -0xb0(%rbp), %rcx
movq %rcx, -0x10(%rcx)
xorl %eax, %eax
movq %rax, -0x8(%rcx)
movb $0x0, (%rcx)
leaq -0xd8(%rbp), %rcx
movq %rcx, 0x8(%rcx)
movq %rcx, (%rcx)
movq %rax, 0x10(%rcx)
movq 0xb8fe(%rip), %r15      # 0x13fe0
leaq -0x98(%rbp), %r12
movq %rbx, -0x50(%rbp)
movq %r15, %rdi
leaq -0xc0(%rbp), %rsi
callq 0x31e0
movq 0x78(%rbx), %rsi
movq %r12, %rdi
callq 0xdde2
leaq -0xd8(%rbp), %rdi
movq %r12, %rsi
callq 0x9c4e
movq -0x98(%rbp), %rdi
cmpq %r12, %rdi
je 0x8738
movq (%rdi), %rbx
movl $0x18, %esi
callq 0x3190
movq %rbx, %rdi
cmpq %r12, %rbx
jne 0x8723
leaq -0xd8(%rbp), %r15
movq -0x50(%rbp), %rbx
movq (%r15), %r15
leaq -0xd8(%rbp), %rax
cmpq %rax, %r15
je 0x87c5
movq 0x10(%r15), %rsi
movq %r12, %rdi
callq 0x489e
movq -0x90(%rbp), %rdx
cmpq -0xb8(%rbp), %rdx
jne 0x8791
movq -0x98(%rbp), %r13
testq %rdx, %rdx
je 0x879d
movq -0xc0(%rbp), %rsi
movq %r13, %rdi
callq 0x31a0
testl %eax, %eax
sete %r14b
jmp 0x87a0
movq -0x98(%rbp), %r13
xorl %r14d, %r14d
jmp 0x87a0
movb $0x1, %r14b
leaq -0x88(%rbp), %rax
cmpq %rax, %r13
je 0x87be
movq -0x88(%rbp), %rsi
incq %rsi
movq %r13, %rdi
callq 0x3190
testb %r14b, %r14b
je 0x8743
jmp 0x8822
movl $0x25, %edx
movq 0xb7ff(%rip), %r14      # 0x13fd0
movq %r14, %rdi
leaq 0x5f0b(%rip), %rsi      # 0xe6e6
callq 0x31c0
movq 0xb7f9(%rip), %r15      # 0x13fe0
movq (%r14), %rax
movq -0x18(%rax), %rdi
addq %r14, %rdi
movl $0xa, %esi
callq 0x3160
movsbl %al, %esi
movq %r14, %rdi
callq 0x3040
movq %rax, %rdi
callq 0x3100
movq %r15, %rdi
leaq -0xc0(%rbp), %rsi
callq 0x31e0
jmp 0x86ed
movq 0x10(%r15), %rax
movq %rax, -0x58(%rbp)
movq 0xb79f(%rip), %r14      # 0x13fd0
leaq 0x5ed4(%rip), %rsi      # 0xe70c
movl $0x55, %edx
movq %r14, %rdi
callq 0x31c0
movq (%r14), %rax
addq -0x18(%rax), %r14
movq %r14, %rdi
movl $0xa, %esi
callq 0x3160
movsbl %al, %esi
movq 0xb76d(%rip), %r14      # 0x13fd0
movq %r14, %rdi
callq 0x3040
movq %rax, %rdi
callq 0x3100
leaq -0x98(%rbp), %rsi
leaq -0x88(%rbp), %rax
movq %rax, (%rsi)
movq $0x0, 0x8(%rsi)
movb $0x0, 0x10(%rsi)
movq 0xb749(%rip), %rdi      # 0x13fe0
callq 0x31e0
leaq 0x5e1a(%rip), %r15      # 0xe6bd
leaq -0x98(%rbp), %r12
leaq 0x5e0e(%rip), %r13      # 0xe6bf
movq %r12, %rdi
movq %r15, %rsi
callq 0x30a0
testl %eax, %eax
je 0x8948
movq %r12, %rdi
movq %r13, %rsi
callq 0x30a0
testl %eax, %eax
je 0x8948
movq %r12, %rdi
leaq 0x5e85(%rip), %rsi      # 0xe762
callq 0x30a0
testl %eax, %eax
je 0x8948
movq %r12, %rdi
leaq 0x5e74(%rip), %rsi      # 0xe764
callq 0x30a0
testl %eax, %eax
je 0x8948
movl $0x15, %edx
movq %r14, %rdi
leaq 0x5e5e(%rip), %rsi      # 0xe766
callq 0x31c0
movq (%r14), %rax
movq -0x18(%rax), %rdi
addq %r14, %rdi
movl $0xa, %esi
callq 0x3160
movsbl %al, %esi
movq %r14, %rdi
callq 0x3040
movq %rax, %rdi
callq 0x3100
movq 0xb6a5(%rip), %rdi      # 0x13fe0
movq %r12, %rsi
callq 0x31e0
jmp 0x88b1
movq %rbx, %rdi
callq 0x7f74
leaq 0x5d66(%rip), %rsi      # 0xe6bd
leaq -0x98(%rbp), %rdi
callq 0x30a0
testl %eax, %eax
je 0x8b21
leaq 0x5d4d(%rip), %rsi      # 0xe6bf
leaq -0x98(%rbp), %rdi
callq 0x30a0
testl %eax, %eax
je 0x8cd1
leaq 0x5dd5(%rip), %rsi      # 0xe762
leaq -0x98(%rbp), %rdi
callq 0x30a0
testl %eax, %eax
je 0x8e36
leaq 0x5dbc(%rip), %rsi      # 0xe764
leaq -0x98(%rbp), %rdi
callq 0x30a0
testl %eax, %eax
jne 0x8fad
movq 0xb60d(%rip), %r14      # 0x13fd0
leaq 0x5e8e(%rip), %rsi      # 0xe858
movl $0x2e, %edx
movq %r14, %rdi
callq 0x31c0
movq (%r14), %rax
addq -0x18(%rax), %r14
movq %r14, %rdi
movl $0xa, %esi
callq 0x3160
movsbl %al, %esi
movq 0xb5db(%rip), %rdi      # 0x13fd0
callq 0x3040
movq %rax, %rdi
callq 0x3100
leaq -0x38(%rbp), %rax
movq %rax, -0x10(%rax)
movq $0x0, -0x8(%rax)
movb $0x0, (%rax)
movq 0xb5c4(%rip), %rdi      # 0x13fe0
leaq -0x48(%rbp), %rsi
callq 0x31e0
addq $0x48, %rbx
leaq -0x78(%rbp), %r15
movq (%rbx), %r14
cmpq %rbx, %r14
je 0x8aca
movb $0x1, %al
movl %eax, -0x50(%rbp)
movq 0x10(%r14), %rsi
movq %r15, %rdi
callq 0xc812
movq -0x40(%rbp), %rdx
cmpq -0x70(%rbp), %rdx
jne 0x8a71
movq -0x78(%rbp), %r12
testq %rdx, %rdx
je 0x8a7a
movq -0x48(%rbp), %rdi
movq %r12, %rsi
callq 0x31a0
testl %eax, %eax
sete %r13b
jmp 0x8a7d
movq -0x78(%rbp), %r12
xorl %r13d, %r13d
jmp 0x8a7d
movb $0x1, %r13b
leaq -0x68(%rbp), %rax
cmpq %rax, %r12
je 0x8a95
movq -0x68(%rbp), %rsi
incq %rsi
movq %r12, %rdi
callq 0x3190
testb %r13b, %r13b
jne 0x8aa4
movq (%r14), %r14
cmpq %rbx, %r14
jne 0x8a3e
jmp 0x8ac0
movq 0x10(%r14), %rsi
movq -0x58(%rbp), %rdi
callq 0x4f7a
movq (%r14), %r14
xorl %eax, %eax
cmpq %rbx, %r14
jne 0x8a3b
jmp 0x8f94
testb $0x1, -0x50(%rbp)
je 0x8f94
movl $0x1c, %edx
movq 0xb4fa(%rip), %r14      # 0x13fd0
movq %r14, %rdi
leaq 0x5da7(%rip), %rsi      # 0xe887
callq 0x31c0
movq (%r14), %rax
movq -0x18(%rax), %rdi
addq %r14, %rdi
movl $0xa, %esi
callq 0x3160
movsbl %al, %esi
movq %r14, %rdi
callq 0x3040
movq %rax, %rdi
callq 0x3100
movq 0xb4cd(%rip), %rdi      # 0x13fe0
leaq -0x48(%rbp), %rsi
callq 0x31e0
jmp 0x8a2d
movq 0xb4a8(%rip), %r14      # 0x13fd0
leaq 0x5c4d(%rip), %rsi      # 0xe77c
movl $0x2b, %edx
movq %r14, %rdi
callq 0x31c0
movq (%r14), %rax
addq -0x18(%rax), %r14
movq %r14, %rdi
movl $0xa, %esi
callq 0x3160
movsbl %al, %esi
movq 0xb476(%rip), %rdi      # 0x13fd0
callq 0x3040
movq %rax, %rdi
callq 0x3100
leaq -0x38(%rbp), %rax
movq %rax, -0x10(%rax)
movq $0x0, -0x8(%rax)
movb $0x0, (%rax)
movq 0xb45f(%rip), %rdi      # 0x13fe0
leaq -0x48(%rbp), %rsi
callq 0x31e0
leaq -0x68(%rbp), %r14
leaq -0x78(%rbp), %r12
movq (%rbx), %r15
cmpq %rbx, %r15
je 0x8c7a
movb $0x1, %al
movl %eax, -0x9c(%rbp)
movq 0x10(%r15), %rsi
movq %r12, %rdi
callq 0xc812
movq -0x40(%rbp), %rdx
cmpq -0x70(%rbp), %rdx
jne 0x8bd8
movq -0x78(%rbp), %r13
testq %rdx, %rdx
je 0x8be0
movq -0x48(%rbp), %rdi
movq %r13, %rsi
callq 0x31a0
testl %eax, %eax
sete %bl
jmp 0x8be2
movq -0x78(%rbp), %r13
xorl %ebx, %ebx
jmp 0x8be2
movb $0x1, %bl
cmpq %r14, %r13
je 0x8bf6
movq -0x68(%rbp), %rsi
incq %rsi
movq %r13, %rdi
callq 0x3190
testb %bl, %bl
jne 0x8c08
movq (%r15), %r15
movq -0x50(%rbp), %rbx
cmpq %rbx, %r15
jne 0x8ba6
jmp 0x8c6d
movq 0x10(%r15), %rsi
movq -0x58(%rbp), %rdi
callq 0x4b96
movq -0x50(%rbp), %rbx
movq -0x58(%rbp), %rdi
callq 0x61d4
movq 0xb3a7(%rip), %rdi      # 0x13fd0
movl %eax, %esi
callq 0x3210
movq %rax, %r13
movq (%rax), %rax
movq -0x18(%rax), %rdi
addq %r13, %rdi
movl $0xa, %esi
callq 0x3160
movsbl %al, %esi
movq %r13, %rdi
callq 0x3040
movq %rax, %rdi
callq 0x3100
movq (%r15), %r15
xorl %eax, %eax
cmpq %rbx, %r15
jne 0x8ba0
jmp 0x8f94
testb $0x1, -0x9c(%rbp)
je 0x8f94
movl $0x1d, %edx
movq 0xb34a(%rip), %r15      # 0x13fd0
movq %r15, %rdi
leaq 0x5b18(%rip), %rsi      # 0xe7a8
callq 0x31c0
movq (%r15), %rax
movq -0x18(%rax), %rdi
addq %r15, %rdi
movl $0xa, %esi
callq 0x3160
movsbl %al, %esi
movq %r15, %rdi
callq 0x3040
movq %rax, %rdi
callq 0x3100
movq 0xb31d(%rip), %rdi      # 0x13fe0
leaq -0x48(%rbp), %rsi
callq 0x31e0
jmp 0x8b92
movq 0xb2f8(%rip), %r14      # 0x13fd0
leaq 0x5ae7(%rip), %rsi      # 0xe7c6
movl $0x2a, %edx
movq %r14, %rdi
callq 0x31c0
movq (%r14), %rax
addq -0x18(%rax), %r14
movq %r14, %rdi
movl $0xa, %esi
callq 0x3160
movsbl %al, %esi
movq 0xb2c6(%rip), %rdi      # 0x13fd0
callq 0x3040
movq %rax, %rdi
callq 0x3100
leaq -0x38(%rbp), %rax
movq %rax, -0x10(%rax)
movq $0x0, -0x8(%rax)
movb $0x0, (%rax)
movq 0xb2af(%rip), %rdi      # 0x13fe0
leaq -0x48(%rbp), %rsi
callq 0x31e0
addq $0x18, %rbx
leaq -0x78(%rbp), %r15
movq (%rbx), %r14
cmpq %rbx, %r14
je 0x8ddf
movb $0x1, %al
movl %eax, -0x50(%rbp)
movq 0x10(%r14), %rsi
movq %r15, %rdi
callq 0xc812
movq -0x40(%rbp), %rdx
cmpq -0x70(%rbp), %rdx
jne 0x8d86
movq -0x78(%rbp), %r12
testq %rdx, %rdx
je 0x8d8f
movq -0x48(%rbp), %rdi
movq %r12, %rsi
callq 0x31a0
testl %eax, %eax
sete %r13b
jmp 0x8d92
movq -0x78(%rbp), %r12
xorl %r13d, %r13d
jmp 0x8d92
movb $0x1, %r13b
leaq -0x68(%rbp), %rax
cmpq %rax, %r12
je 0x8daa
movq -0x68(%rbp), %rsi
incq %rsi
movq %r12, %rdi
callq 0x3190
testb %r13b, %r13b
jne 0x8db9
movq (%r14), %r14
cmpq %rbx, %r14
jne 0x8d53
jmp 0x8dd5
movq 0x10(%r14), %rsi
movq -0x58(%rbp), %rdi
callq 0x4cde
movq (%r14), %r14
xorl %eax, %eax
cmpq %rbx, %r14
jne 0x8d50
jmp 0x8f94
testb $0x1, -0x50(%rbp)
je 0x8f94
movl $0x1c, %edx
movq 0xb1e5(%rip), %r14      # 0x13fd0
movq %r14, %rdi
leaq 0x59fc(%rip), %rsi      # 0xe7f1
callq 0x31c0
movq (%r14), %rax
movq -0x18(%rax), %rdi
addq %r14, %rdi
movl $0xa, %esi
callq 0x3160
movsbl %al, %esi
movq %r14, %rdi
callq 0x3040
movq %rax, %rdi
callq 0x3100
movq 0xb1b8(%rip), %rdi      # 0x13fe0
leaq -0x48(%rbp), %rsi
callq 0x31e0
jmp 0x8d42
movq 0xb193(%rip), %r14      # 0x13fd0
leaq 0x59ca(%rip), %rsi      # 0xe80e
movl $0x2b, %edx
movq %r14, %rdi
callq 0x31c0
movq (%r14), %rax
addq -0x18(%rax), %r14
movq %r14, %rdi
movl $0xa, %esi
callq 0x3160
movsbl %al, %esi
movq 0xb161(%rip), %rdi      # 0x13fd0
callq 0x3040
movq %rax, %rdi
callq 0x3100
leaq -0x38(%rbp), %rax
movq %rax, -0x10(%rax)
movq $0x0, -0x8(%rax)
movb $0x0, (%rax)
movq 0xb14a(%rip), %rdi      # 0x13fe0
leaq -0x48(%rbp), %rsi
callq 0x31e0
addq $0x30, %rbx
leaq -0x78(%rbp), %r15
movq (%rbx), %r14
cmpq %rbx, %r14
je 0x8f3d
movb $0x1, %al
movl %eax, -0x50(%rbp)
movq 0x10(%r14), %rsi
movq %r15, %rdi
callq 0xc812
movq -0x40(%rbp), %rdx
cmpq -0x70(%rbp), %rdx
jne 0x8eeb
movq -0x78(%rbp), %r12
testq %rdx, %rdx
je 0x8ef4
movq -0x48(%rbp), %rdi
movq %r12, %rsi
callq 0x31a0
testl %eax, %eax
sete %r13b
jmp 0x8ef7
movq -0x78(%rbp), %r12
xorl %r13d, %r13d
jmp 0x8ef7
movb $0x1, %r13b
leaq -0x68(%rbp), %rax
cmpq %rax, %r12
je 0x8f0f
movq -0x68(%rbp), %rsi
incq %rsi
movq %r12, %rdi
callq 0x3190
testb %r13b, %r13b
jne 0x8f1e
movq (%r14), %r14
cmpq %rbx, %r14
jne 0x8eb8
jmp 0x8f37
movq 0x10(%r14), %rsi
movq -0x58(%rbp), %rdi
callq 0x4e2c
movq (%r14), %r14
xorl %eax, %eax
cmpq %rbx, %r14
jne 0x8eb5
jmp 0x8f94
testb $0x1, -0x50(%rbp)
je 0x8f94
movl $0x1d, %edx
movq 0xb087(%rip), %r14      # 0x13fd0
movq %r14, %rdi
leaq 0x58e7(%rip), %rsi      # 0xe83a
callq 0x31c0
movq (%r14), %rax
movq -0x18(%rax), %rdi
addq %r14, %rdi
movl $0xa, %esi
callq 0x3160
movsbl %al, %esi
movq %r14, %rdi
callq 0x3040
movq %rax, %rdi
callq 0x3100
movq 0xb05a(%rip), %rdi      # 0x13fe0
leaq -0x48(%rbp), %rsi
callq 0x31e0
jmp 0x8ea7
movq -0x48(%rbp), %rdi
leaq -0x38(%rbp), %rax
cmpq %rax, %rdi
je 0x8fad
movq -0x38(%rbp), %rsi
incq %rsi
callq 0x3190
movq -0x98(%rbp), %rdi
leaq -0x88(%rbp), %rax
cmpq %rax, %rdi
je 0x8fcf
movq -0x88(%rbp), %rsi
incq %rsi
callq 0x3190
leaq -0xd8(%rbp), %rbx
movq (%rbx), %rdi
cmpq %rbx, %rdi
je 0x8ff3
movq (%rdi), %r14
movl $0x18, %esi
callq 0x3190
movq %r14, %rdi
cmpq %rbx, %r14
jne 0x8fde
movq -0xc0(%rbp), %rdi
leaq -0xb0(%rbp), %rax
cmpq %rax, %rdi
je 0x9015
movq -0xb0(%rbp), %rsi
incq %rsi
callq 0x3190
addq $0xb8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
jmp 0x9057
jmp 0x9057
jmp 0x9057
jmp 0x9057
jmp 0x9057
jmp 0x9043
jmp 0x9057
jmp 0x9057
jmp 0x9043
jmp 0x904a
jmp 0x9043
jmp 0x9057
jmp 0x9057
jmp 0x9057
movq %rax, %rbx
jmp 0x9095
jmp 0x9057
movq %rax, %rbx
jmp 0x9073
jmp 0x9057
jmp 0x9057
jmp 0x9057
jmp 0x9057
movq %rax, %rbx
movq -0x48(%rbp), %rdi
leaq -0x38(%rbp), %rax
cmpq %rax, %rdi
je 0x9073
movq -0x38(%rbp), %rsi
incq %rsi
callq 0x3190
movq -0x98(%rbp), %rdi
leaq -0x88(%rbp), %rax
cmpq %rax, %rdi
je 0x9095
movq -0x88(%rbp), %rsi
incq %rsi
callq 0x3190
leaq -0xd8(%rbp), %r14
movq (%r14), %rdi
cmpq %r14, %rdi
je 0x90b9
movq (%rdi), %r15
movl $0x18, %esi
callq 0x3190
movq %r15, %rdi
cmpq %r14, %r15
jne 0x90a4
movq -0xc0(%rbp), %rdi
leaq -0xb0(%rbp), %rax
cmpq %rax, %rdi
je 0x90db
movq -0xb0(%rbp), %rsi
incq %rsi
callq 0x3190
movq %rbx, %rdi
callq 0x3220
nop