// File: /workspace/github_cpp_makefile_star2_O1/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 $0xa8, %rsp
movq %rdi, %rbx
movq 0xb95e(%rip), %r14      # 0x13fd0
leaq 0x6048(%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 -0xa8(%rbp), %rcx
movq %rcx, -0x10(%rcx)
xorl %eax, %eax
movq %rax, -0x8(%rcx)
movb $0x0, (%rcx)
leaq -0xd0(%rbp), %r12
movq %r12, 0x8(%r12)
movq %r12, (%r12)
movq %rax, 0x10(%r12)
leaq -0x90(%rbp), %r13
movq %rbx, -0x98(%rbp)
movq 0xb8f5(%rip), %rdi      # 0x13fe0
leaq -0xb8(%rbp), %rsi
callq 0x31e0
movq 0x78(%rbx), %rsi
movq %r13, %rdi
callq 0xdd6a
movq %r12, %rdi
movq %r13, %rsi
callq 0x9b9a
movq -0x90(%rbp), %rdi
cmpq %r13, %rdi
je 0x872f
movq (%rdi), %rbx
movl $0x18, %esi
callq 0x3190
movq %rbx, %rdi
cmpq %r13, %rbx
jne 0x871a
movq %r12, %r14
movq (%r14), %r14
cmpq %r12, %r14
je 0x87a7
movq 0x10(%r14), %rsi
movq %r13, %rdi
callq 0x489a
movq -0x88(%rbp), %rdx
cmpq -0xb0(%rbp), %rdx
jne 0x8776
testq %rdx, %rdx
je 0x877b
movq -0xb8(%rbp), %rsi
movq -0x90(%rbp), %rdi
callq 0x31a0
testl %eax, %eax
sete %r15b
jmp 0x877e
xorl %r15d, %r15d
jmp 0x877e
movb $0x1, %r15b
movq -0x90(%rbp), %rdi
leaq -0x80(%rbp), %rax
cmpq %rax, %rdi
je 0x879a
movq -0x80(%rbp), %rsi
incq %rsi
callq 0x3190
testb %r15b, %r15b
je 0x8732
movq 0x10(%r14), %rax
movq %rax, -0x50(%rbp)
movq -0x98(%rbp), %rbx
cmpq %r12, %r14
jne 0x8819
movl $0x25, %edx
movq 0xb811(%rip), %rdi      # 0x13fd0
leaq 0x5f20(%rip), %rsi      # 0xe6e6
callq 0x31c0
movq 0xb7fe(%rip), %rcx      # 0x13fd0
movq (%rcx), %rax
movq -0x18(%rax), %rdi
addq %rcx, %rdi
movl $0xa, %esi
callq 0x3160
movsbl %al, %esi
movq 0xb7e0(%rip), %rdi      # 0x13fd0
callq 0x3040
movq %rax, %rdi
callq 0x3100
movq 0xb7dc(%rip), %rdi      # 0x13fe0
leaq -0xb8(%rbp), %rsi
callq 0x31e0
cmpq %r12, %r14
je 0x86e4
movq 0xb7b0(%rip), %r15      # 0x13fd0
leaq 0x5ee5(%rip), %rsi      # 0xe70c
movl $0x55, %edx
movq %r15, %rdi
callq 0x31c0
movq (%r15), %rax
addq -0x18(%rax), %r15
movq %r15, %rdi
movl $0xa, %esi
callq 0x3160
movsbl %al, %esi
movq 0xb77e(%rip), %r15      # 0x13fd0
movq %r15, %rdi
callq 0x3040
movq %rax, %rdi
callq 0x3100
leaq -0x90(%rbp), %rsi
leaq -0x80(%rbp), %rax
movq %rax, (%rsi)
movq $0x0, 0x8(%rsi)
movb $0x0, 0x10(%rsi)
movq 0xb75d(%rip), %rdi      # 0x13fe0
callq 0x31e0
leaq 0x5e2e(%rip), %r12      # 0xe6bd
leaq -0x90(%rbp), %r13
leaq 0x5e22(%rip), %r14      # 0xe6bf
movq %r13, %rdi
movq %r12, %rsi
callq 0x30a0
testl %eax, %eax
je 0x8934
movq %r13, %rdi
movq %r14, %rsi
callq 0x30a0
testl %eax, %eax
je 0x8934
movq %r13, %rdi
leaq 0x5e99(%rip), %rsi      # 0xe762
callq 0x30a0
testl %eax, %eax
je 0x8934
movq %r13, %rdi
leaq 0x5e88(%rip), %rsi      # 0xe764
callq 0x30a0
testl %eax, %eax
je 0x8934
movl $0x15, %edx
movq %r15, %rdi
leaq 0x5e72(%rip), %rsi      # 0xe766
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 0xb6b9(%rip), %rdi      # 0x13fe0
movq %r13, %rsi
callq 0x31e0
jmp 0x889d
movq %rbx, %rdi
callq 0x7f6c
leaq 0x5d7a(%rip), %rsi      # 0xe6bd
leaq -0x90(%rbp), %rdi
callq 0x30a0
testl %eax, %eax
je 0x8aff
leaq 0x5d61(%rip), %rsi      # 0xe6bf
leaq -0x90(%rbp), %rdi
callq 0x30a0
testl %eax, %eax
je 0x8c9c
leaq 0x5de9(%rip), %rsi      # 0xe762
leaq -0x90(%rbp), %rdi
callq 0x30a0
testl %eax, %eax
je 0x8df3
leaq 0x5dd0(%rip), %rsi      # 0xe764
leaq -0x90(%rbp), %rdi
callq 0x30a0
testl %eax, %eax
jne 0x8f5f
movq 0xb621(%rip), %r15      # 0x13fd0
leaq 0x5ea2(%rip), %rsi      # 0xe858
movl $0x2e, %edx
movq %r15, %rdi
callq 0x31c0
movq (%r15), %rax
addq -0x18(%rax), %r15
movq %r15, %rdi
movl $0xa, %esi
callq 0x3160
movsbl %al, %esi
movq 0xb5ef(%rip), %r14      # 0x13fd0
movq %r14, %rdi
callq 0x3040
movq %rax, %rdi
callq 0x3100
leaq -0x38(%rbp), %rax
movq %rax, -0x10(%rax)
movq $0x0, -0x8(%rax)
movb $0x0, (%rax)
movq 0xb5d5(%rip), %rdi      # 0x13fe0
leaq -0x48(%rbp), %rsi
callq 0x31e0
addq $0x48, %rbx
leaq -0x70(%rbp), %r13
movq (%rbx), %r12
cmpq %rbx, %r12
je 0x8aaf
xorl %r15d, %r15d
movq 0x10(%r12), %rsi
movq %r13, %rdi
callq 0xc78e
movq -0x40(%rbp), %rdx
cmpq -0x68(%rbp), %rdx
jne 0x8a5c
testq %rdx, %rdx
je 0x8a61
movq -0x70(%rbp), %rsi
movq -0x48(%rbp), %rdi
callq 0x31a0
testl %eax, %eax
sete %r14b
jmp 0x8a64
xorl %r14d, %r14d
jmp 0x8a64
movb $0x1, %r14b
movq -0x70(%rbp), %rdi
leaq -0x60(%rbp), %rax
cmpq %rax, %rdi
je 0x8a7d
movq -0x60(%rbp), %rsi
incq %rsi
callq 0x3190
testb %r14b, %r14b
je 0x8a96
movq 0x10(%r12), %rsi
movl $0x1, %r15d
movq -0x50(%rbp), %rdi
callq 0x4f76
movq (%r12), %r12
cmpq %rbx, %r12
jne 0x8a2b
testl %r15d, %r15d
movq 0xb527(%rip), %r14      # 0x13fd0
jne 0x8f46
movl $0x1c, %edx
movq %r14, %rdi
leaq 0x5dc9(%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 0xb4ef(%rip), %rdi      # 0x13fe0
leaq -0x48(%rbp), %rsi
callq 0x31e0
jmp 0x8a1c
movq 0xb4ca(%rip), %r15      # 0x13fd0
leaq 0x5c6f(%rip), %rsi      # 0xe77c
movl $0x2b, %edx
movq %r15, %rdi
callq 0x31c0
movq (%r15), %rax
addq -0x18(%rax), %r15
movq %r15, %rdi
movl $0xa, %esi
callq 0x3160
movsbl %al, %esi
movq 0xb498(%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 0xb481(%rip), %rdi      # 0x13fe0
leaq -0x48(%rbp), %rsi
callq 0x31e0
leaq -0x60(%rbp), %r14
leaq -0x70(%rbp), %r13
movq (%rbx), %r15
cmpq %rbx, %r15
je 0x8c3d
xorl %r12d, %r12d
movq 0x10(%r15), %rsi
movq %r13, %rdi
callq 0xc78e
movq -0x40(%rbp), %rdx
cmpq -0x68(%rbp), %rdx
jne 0x8bae
testq %rdx, %rdx
je 0x8bb2
movq -0x70(%rbp), %rsi
movq -0x48(%rbp), %rdi
callq 0x31a0
testl %eax, %eax
sete %bl
jmp 0x8bb4
xorl %ebx, %ebx
jmp 0x8bb4
movb $0x1, %bl
movq -0x70(%rbp), %rdi
cmpq %r14, %rdi
je 0x8bc9
movq -0x60(%rbp), %rsi
incq %rsi
callq 0x3190
testb %bl, %bl
je 0x8c21
movq 0x10(%r15), %rsi
movq -0x50(%rbp), %rdi
callq 0x4b92
movq -0x50(%rbp), %rdi
callq 0x61ce
movq 0xb3e6(%rip), %rdi      # 0x13fd0
movl %eax, %esi
callq 0x3210
movq %rax, %r12
movq (%rax), %rax
movq -0x18(%rax), %rdi
addq %r12, %rdi
movl $0xa, %esi
callq 0x3160
movsbl %al, %esi
movq %r12, %rdi
callq 0x3040
movl $0x1, %r12d
movq %rax, %rdi
callq 0x3100
movq (%r15), %r15
movq -0x98(%rbp), %rbx
cmpq %rbx, %r15
jne 0x8b7f
testl %r12d, %r12d
jne 0x8f46
movl $0x1d, %edx
movq 0xb387(%rip), %rdi      # 0x13fd0
leaq 0x5b58(%rip), %rsi      # 0xe7a8
callq 0x31c0
movq 0xb374(%rip), %rcx      # 0x13fd0
movq (%rcx), %rax
movq -0x18(%rax), %rdi
addq %rcx, %rdi
movl $0xa, %esi
callq 0x3160
movsbl %al, %esi
movq 0xb356(%rip), %rdi      # 0x13fd0
callq 0x3040
movq %rax, %rdi
callq 0x3100
movq 0xb352(%rip), %rdi      # 0x13fe0
leaq -0x48(%rbp), %rsi
callq 0x31e0
jmp 0x8b70
movq 0xb32d(%rip), %r15      # 0x13fd0
leaq 0x5b1c(%rip), %rsi      # 0xe7c6
movl $0x2a, %edx
movq %r15, %rdi
callq 0x31c0
movq (%r15), %rax
addq -0x18(%rax), %r15
movq %r15, %rdi
movl $0xa, %esi
callq 0x3160
movsbl %al, %esi
movq 0xb2fb(%rip), %r14      # 0x13fd0
movq %r14, %rdi
callq 0x3040
movq %rax, %rdi
callq 0x3100
leaq -0x38(%rbp), %rax
movq %rax, -0x10(%rax)
movq $0x0, -0x8(%rax)
movb $0x0, (%rax)
movq 0xb2e1(%rip), %rdi      # 0x13fe0
leaq -0x48(%rbp), %rsi
callq 0x31e0
addq $0x18, %rbx
leaq -0x70(%rbp), %r13
movq (%rbx), %r12
cmpq %rbx, %r12
je 0x8da3
xorl %r15d, %r15d
movq 0x10(%r12), %rsi
movq %r13, %rdi
callq 0xc78e
movq -0x40(%rbp), %rdx
cmpq -0x68(%rbp), %rdx
jne 0x8d50
testq %rdx, %rdx
je 0x8d55
movq -0x70(%rbp), %rsi
movq -0x48(%rbp), %rdi
callq 0x31a0
testl %eax, %eax
sete %r14b
jmp 0x8d58
xorl %r14d, %r14d
jmp 0x8d58
movb $0x1, %r14b
movq -0x70(%rbp), %rdi
leaq -0x60(%rbp), %rax
cmpq %rax, %rdi
je 0x8d71
movq -0x60(%rbp), %rsi
incq %rsi
callq 0x3190
testb %r14b, %r14b
je 0x8d8a
movq 0x10(%r12), %rsi
movl $0x1, %r15d
movq -0x50(%rbp), %rdi
callq 0x4cda
movq (%r12), %r12
cmpq %rbx, %r12
jne 0x8d1f
testl %r15d, %r15d
movq 0xb233(%rip), %r14      # 0x13fd0
jne 0x8f46
movl $0x1c, %edx
movq %r14, %rdi
leaq 0x5a3f(%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 0xb1fb(%rip), %rdi      # 0x13fe0
leaq -0x48(%rbp), %rsi
callq 0x31e0
jmp 0x8d10
movq 0xb1d6(%rip), %r15      # 0x13fd0
leaq 0x5a0d(%rip), %rsi      # 0xe80e
movl $0x2b, %edx
movq %r15, %rdi
callq 0x31c0
movq (%r15), %rax
addq -0x18(%rax), %r15
movq %r15, %rdi
movl $0xa, %esi
callq 0x3160
movsbl %al, %esi
movq 0xb1a4(%rip), %r14      # 0x13fd0
movq %r14, %rdi
callq 0x3040
movq %rax, %rdi
callq 0x3100
leaq -0x38(%rbp), %rax
movq %rax, -0x10(%rax)
movq $0x0, -0x8(%rax)
movb $0x0, (%rax)
movq 0xb18a(%rip), %rdi      # 0x13fe0
leaq -0x48(%rbp), %rsi
callq 0x31e0
addq $0x30, %rbx
leaq -0x70(%rbp), %r13
movq (%rbx), %r12
cmpq %rbx, %r12
je 0x8ef6
xorl %r15d, %r15d
movq 0x10(%r12), %rsi
movq %r13, %rdi
callq 0xc78e
movq -0x40(%rbp), %rdx
cmpq -0x68(%rbp), %rdx
jne 0x8ea7
testq %rdx, %rdx
je 0x8eac
movq -0x70(%rbp), %rsi
movq -0x48(%rbp), %rdi
callq 0x31a0
testl %eax, %eax
sete %r14b
jmp 0x8eaf
xorl %r14d, %r14d
jmp 0x8eaf
movb $0x1, %r14b
movq -0x70(%rbp), %rdi
leaq -0x60(%rbp), %rax
cmpq %rax, %rdi
je 0x8ec8
movq -0x60(%rbp), %rsi
incq %rsi
callq 0x3190
testb %r14b, %r14b
je 0x8ee1
movq 0x10(%r12), %rsi
movl $0x1, %r15d
movq -0x50(%rbp), %rdi
callq 0x4e28
movq (%r12), %r12
cmpq %rbx, %r12
jne 0x8e76
testl %r15d, %r15d
movq 0xb0dc(%rip), %r14      # 0x13fd0
jne 0x8f46
movl $0x1d, %edx
movq %r14, %rdi
leaq 0x5935(%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 0xb0a8(%rip), %rdi      # 0x13fe0
leaq -0x48(%rbp), %rsi
callq 0x31e0
jmp 0x8e67
movq -0x48(%rbp), %rdi
leaq -0x38(%rbp), %rax
cmpq %rax, %rdi
je 0x8f5f
movq -0x38(%rbp), %rsi
incq %rsi
callq 0x3190
movq -0x90(%rbp), %rdi
leaq -0x80(%rbp), %rax
cmpq %rax, %rdi
je 0x8f7b
movq -0x80(%rbp), %rsi
incq %rsi
callq 0x3190
leaq -0xd0(%rbp), %rbx
movq (%rbx), %rdi
cmpq %rbx, %rdi
je 0x8f9f
movq (%rdi), %r14
movl $0x18, %esi
callq 0x3190
movq %r14, %rdi
cmpq %rbx, %r14
jne 0x8f8a
movq -0xb8(%rbp), %rdi
leaq -0xa8(%rbp), %rax
cmpq %rax, %rdi
je 0x8fc1
movq -0xa8(%rbp), %rsi
incq %rsi
callq 0x3190
addq $0xa8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
jmp 0x8ff0
jmp 0x900e
jmp 0x900e
jmp 0x900e
jmp 0x9007
jmp 0x8fe5
jmp 0x9007
jmp 0x8ff0
jmp 0x900e
movq %rax, %rbx
jmp 0x902a
jmp 0x8ff0
jmp 0x900e
jmp 0x900e
movq %rax, %rbx
leaq -0x38(%rbp), %rax
movq -0x48(%rbp), %rdi
jmp 0x9019
jmp 0x900e
jmp 0x9007
jmp 0x900e
jmp 0x900e
jmp 0x900e
movq %rax, %rbx
jmp 0x9046
jmp 0x900e
movq %rax, %rbx
movq -0x48(%rbp), %rdi
leaq -0x38(%rbp), %rax
cmpq %rax, %rdi
je 0x902a
movq -0x38(%rbp), %rsi
incq %rsi
callq 0x3190
movq -0x90(%rbp), %rdi
leaq -0x80(%rbp), %rax
cmpq %rax, %rdi
je 0x9046
movq -0x80(%rbp), %rsi
incq %rsi
callq 0x3190
leaq -0xd0(%rbp), %r14
movq (%r14), %rdi
cmpq %r14, %rdi
je 0x906a
movq (%rdi), %r15
movl $0x18, %esi
callq 0x3190
movq %r15, %rdi
cmpq %r14, %r15
jne 0x9055
movq -0xb8(%rbp), %rdi
leaq -0xa8(%rbp), %rax
cmpq %rax, %rdi
je 0x908c
movq -0xa8(%rbp), %rsi
incq %rsi
callq 0x3190
movq %rbx, %rdi
callq 0x3220