// File: /workspace/github_cpp_makefile_star2_O2/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, -0x38(%rbp)
movq 0xbdd7(%rip), %rdi      # 0x12fd0
leaq 0x54c3(%rip), %rsi      # 0xc6c3
callq 0x31a0
movq %rax, %rdi
callq 0x30f0
leaq -0xc8(%rbp), %rax
movq %rax, -0x10(%rax)
andq $0x0, -0x8(%rax)
movb $0x0, (%rax)
leaq -0xb8(%rbp), %r12
movq %r12, 0x8(%r12)
movq %r12, (%r12)
andq $0x0, 0x10(%r12)
movb $0x1, %al
leaq -0xd8(%rbp), %r14
leaq -0x80(%rbp), %r15
testb $0x1, %al
je 0x72ef
movq 0xbd8e(%rip), %rdi      # 0x12fe0
movq %r14, %rsi
callq 0x31f0
movq -0x38(%rbp), %rax
movq 0x78(%rax), %rsi
movq %r15, %rdi
callq 0xad92
movq %r12, %rdi
movq %r15, %rsi
callq 0x8058
movq %r15, %rdi
callq 0x7fb8
movq %r12, %rbx
movq (%rbx), %rbx
cmpq %r12, %rbx
je 0x72b1
movq 0x10(%rbx), %rsi
movq %r15, %rdi
callq 0x42e0
movq %r15, %rdi
movq %r14, %rsi
callq 0x5ce4
movl %eax, %r13d
movq %r15, %rdi
callq 0x30e0
testb %r13b, %r13b
je 0x7280
jmp 0x72e0
movq 0xbd18(%rip), %rdi      # 0x12fd0
leaq 0x5429(%rip), %rsi      # 0xc6e8
callq 0x31a0
movq %rax, %rdi
callq 0x30f0
movq 0xbd0d(%rip), %rdi      # 0x12fe0
movq %r14, %rsi
callq 0x31f0
jmp 0x724b
movq 0x10(%rbx), %rax
movq %rax, -0x40(%rbp)
xorl %eax, %eax
jmp 0x7243
movq 0xbcda(%rip), %rdi      # 0x12fd0
leaq 0x5411(%rip), %rsi      # 0xc70e
callq 0x31a0
movq %rax, %rdi
callq 0x30f0
leaq -0x70(%rbp), %rax
movq %rax, -0x10(%rax)
andq $0x0, -0x8(%rax)
movb $0x0, (%rax)
movq 0xbcbf(%rip), %rdi      # 0x12fe0
leaq -0x80(%rbp), %rsi
callq 0x31f0
leaq 0x538e(%rip), %r14      # 0xc6bf
leaq -0x80(%rbp), %r15
leaq 0x5385(%rip), %r12      # 0xc6c1
leaq 0x5421(%rip), %r13      # 0xc764
leaq 0x541c(%rip), %rbx      # 0xc766
movq %r15, %rdi
movq %r14, %rsi
callq 0x7f76
testb %al, %al
je 0x73b2
movq %r15, %rdi
movq %r12, %rsi
callq 0x7f76
testb %al, %al
je 0x73b2
movq %r15, %rdi
movq %r13, %rsi
callq 0x7f76
testb %al, %al
je 0x73b2
movq %r15, %rdi
movq %rbx, %rsi
callq 0x7f76
testb %al, %al
je 0x73b2
movq 0xbc43(%rip), %rdi      # 0x12fd0
leaq 0x53d4(%rip), %rsi      # 0xc768
callq 0x31a0
movq %rax, %rdi
callq 0x30f0
movq 0xbc38(%rip), %rdi      # 0x12fe0
movq %r15, %rsi
callq 0x31f0
jmp 0x734a
movq -0x38(%rbp), %rdi
callq 0x6d40
leaq 0x52fd(%rip), %rsi      # 0xc6bf
leaq -0x80(%rbp), %rdi
callq 0x5d10
testb %al, %al
je 0x74d3
movq 0xbbf6(%rip), %rdi      # 0x12fd0
leaq 0x539d(%rip), %rsi      # 0xc77e
callq 0x31a0
movq %rax, %rdi
callq 0x30f0
leaq -0x50(%rbp), %rax
movq %rax, -0x10(%rax)
andq $0x0, -0x8(%rax)
movb $0x0, (%rax)
movq 0xbbdb(%rip), %rdi      # 0x12fe0
leaq -0x60(%rbp), %rsi
callq 0x31f0
xorl %r15d, %r15d
leaq -0x60(%rbp), %r12
leaq -0xa0(%rbp), %r13
testl %r15d, %r15d
jne 0x77be
xorl %r15d, %r15d
movb $0x1, %al
movl %eax, -0x2c(%rbp)
movq -0x38(%rbp), %rbx
movq (%rbx), %rbx
cmpq -0x38(%rbp), %rbx
je 0x749a
movq 0x10(%rbx), %rsi
movq %r13, %rdi
callq 0x9f40
movq %r12, %rdi
movq %r13, %rsi
callq 0x5ce4
movl %eax, %r14d
movq %r13, %rdi
callq 0x30e0
testb %r14b, %r14b
je 0x7431
movq 0x10(%rbx), %rsi
movq -0x40(%rbp), %rdi
callq 0x4516
movq -0x40(%rbp), %rdi
callq 0x5294
movq 0xbb52(%rip), %rdi      # 0x12fd0
movl %eax, %esi
callq 0x3230
movl $0x0, -0x2c(%rbp)
movq %rax, %rdi
callq 0x30f0
pushq $0x1
popq %r15
jmp 0x7431
testb $0x1, -0x2c(%rbp)
je 0x741c
movq 0xbb25(%rip), %rdi      # 0x12fd0
leaq 0x52f8(%rip), %rsi      # 0xc7aa
callq 0x31a0
movq %rax, %rdi
callq 0x30f0
movq 0xbb1a(%rip), %rdi      # 0x12fe0
movq %r12, %rsi
callq 0x31f0
jmp 0x741c
leaq 0x51e7(%rip), %rsi      # 0xc6c1
leaq -0x80(%rbp), %rdi
callq 0x5d10
testb %al, %al
je 0x75cc
movq 0xbade(%rip), %rdi      # 0x12fd0
leaq 0x52cf(%rip), %rsi      # 0xc7c8
callq 0x31a0
movq %rax, %rdi
callq 0x30f0
leaq -0x50(%rbp), %rax
movq %rax, -0x10(%rax)
andq $0x0, -0x8(%rax)
movb $0x0, (%rax)
movq 0xbac3(%rip), %rdi      # 0x12fe0
leaq -0x60(%rbp), %rsi
callq 0x31f0
addq $0x18, -0x38(%rbp)
xorl %ebx, %ebx
leaq -0x60(%rbp), %r13
leaq -0xa0(%rbp), %r14
testl %ebx, %ebx
jne 0x77be
xorl %ebx, %ebx
movb $0x1, %al
movl %eax, -0x2c(%rbp)
movq -0x38(%rbp), %r12
movq (%r12), %r12
cmpq -0x38(%rbp), %r12
je 0x7597
movq 0x10(%r12), %rsi
movq %r14, %rdi
callq 0x9f40
movq %r13, %rdi
movq %r14, %rsi
callq 0x5ce4
movl %eax, %r15d
movq %r14, %rdi
callq 0x30e0
testb %r15b, %r15b
je 0x754b
movq 0x10(%r12), %rsi
movl $0x0, -0x2c(%rbp)
movq -0x40(%rbp), %rdi
callq 0x45e2
pushq $0x1
popq %rbx
jmp 0x754b
testb $0x1, -0x2c(%rbp)
je 0x7538
movq 0xba2c(%rip), %rdi      # 0x12fd0
leaq 0x5248(%rip), %rsi      # 0xc7f3
callq 0x31a0
movq %rax, %rdi
callq 0x30f0
movq 0xba21(%rip), %rdi      # 0x12fe0
movq %r13, %rsi
callq 0x31f0
jmp 0x7538
leaq 0x5191(%rip), %rsi      # 0xc764
leaq -0x80(%rbp), %rdi
callq 0x5d10
testb %al, %al
je 0x76c5
movq 0xb9e5(%rip), %rdi      # 0x12fd0
leaq 0x521e(%rip), %rsi      # 0xc810
callq 0x31a0
movq %rax, %rdi
callq 0x30f0
leaq -0x50(%rbp), %rax
movq %rax, -0x10(%rax)
andq $0x0, -0x8(%rax)
movb $0x0, (%rax)
movq 0xb9ca(%rip), %rdi      # 0x12fe0
leaq -0x60(%rbp), %rsi
callq 0x31f0
addq $0x30, -0x38(%rbp)
xorl %ebx, %ebx
leaq -0x60(%rbp), %r13
leaq -0xa0(%rbp), %r14
testl %ebx, %ebx
jne 0x77be
xorl %ebx, %ebx
movb $0x1, %al
movl %eax, -0x2c(%rbp)
movq -0x38(%rbp), %r12
movq (%r12), %r12
cmpq -0x38(%rbp), %r12
je 0x7690
movq 0x10(%r12), %rsi
movq %r14, %rdi
callq 0x9f40
movq %r13, %rdi
movq %r14, %rsi
callq 0x5ce4
movl %eax, %r15d
movq %r14, %rdi
callq 0x30e0
testb %r15b, %r15b
je 0x7644
movq 0x10(%r12), %rsi
movl $0x0, -0x2c(%rbp)
movq -0x40(%rbp), %rdi
callq 0x46b0
pushq $0x1
popq %rbx
jmp 0x7644
testb $0x1, -0x2c(%rbp)
je 0x7631
movq 0xb933(%rip), %rdi      # 0x12fd0
leaq 0x5198(%rip), %rsi      # 0xc83c
callq 0x31a0
movq %rax, %rdi
callq 0x30f0
movq 0xb928(%rip), %rdi      # 0x12fe0
movq %r13, %rsi
callq 0x31f0
jmp 0x7631
leaq 0x509a(%rip), %rsi      # 0xc766
leaq -0x80(%rbp), %rdi
callq 0x5d10
testb %al, %al
je 0x77c7
movq 0xb8ec(%rip), %rdi      # 0x12fd0
leaq 0x516f(%rip), %rsi      # 0xc85a
callq 0x31a0
movq %rax, %rdi
callq 0x30f0
leaq -0x50(%rbp), %rax
movq %rax, -0x10(%rax)
andq $0x0, -0x8(%rax)
movb $0x0, (%rax)
movq 0xb8d1(%rip), %rdi      # 0x12fe0
leaq -0x60(%rbp), %rsi
callq 0x31f0
addq $0x48, -0x38(%rbp)
xorl %ebx, %ebx
leaq -0x60(%rbp), %r13
leaq -0xa0(%rbp), %r14
testl %ebx, %ebx
jne 0x77be
xorl %ebx, %ebx
movb $0x1, %al
movl %eax, -0x2c(%rbp)
movq -0x38(%rbp), %r12
movq (%r12), %r12
cmpq -0x38(%rbp), %r12
je 0x7789
movq 0x10(%r12), %rsi
movq %r14, %rdi
callq 0x9f40
movq %r13, %rdi
movq %r14, %rsi
callq 0x5ce4
movl %eax, %r15d
movq %r14, %rdi
callq 0x30e0
testb %r15b, %r15b
je 0x773d
movq 0x10(%r12), %rsi
movl $0x0, -0x2c(%rbp)
movq -0x40(%rbp), %rdi
callq 0x477e
pushq $0x1
popq %rbx
jmp 0x773d
testb $0x1, -0x2c(%rbp)
je 0x772a
movq 0xb83a(%rip), %rdi      # 0x12fd0
leaq 0x50ec(%rip), %rsi      # 0xc889
callq 0x31a0
movq %rax, %rdi
callq 0x30f0
movq 0xb82f(%rip), %rdi      # 0x12fe0
movq %r13, %rsi
callq 0x31f0
jmp 0x772a
leaq -0x60(%rbp), %rdi
callq 0x30e0
leaq -0x80(%rbp), %rdi
callq 0x30e0
leaq -0xb8(%rbp), %rdi
callq 0x7fb8
leaq -0xd8(%rbp), %rdi
callq 0x30e0
addq $0xb8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
jmp 0x7825
jmp 0x7825
jmp 0x7825
jmp 0x7825
jmp 0x7825
jmp 0x783c
jmp 0x7825
jmp 0x7825
jmp 0x7812
jmp 0x7825
jmp 0x7825
jmp 0x7825
movq %rax, %rbx
jmp 0x7831
jmp 0x7825
jmp 0x7825
jmp 0x7825
jmp 0x783c
jmp 0x7825
jmp 0x783c
jmp 0x7825
movq %rax, %rbx
leaq -0x60(%rbp), %rdi
callq 0x30e0
leaq -0x80(%rbp), %rdi
callq 0x30e0
jmp 0x783f
movq %rax, %rbx
leaq -0xb8(%rbp), %rdi
callq 0x7fb8
leaq -0xd8(%rbp), %rdi
callq 0x30e0
movq %rbx, %rdi
callq 0x3240
nop