// File: /workspace/github_cpp_makefile_star2_O3/arisKoutsou[P]oopproj/./src/livings/Hero.cpp
// Function: Hero::buy(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>> const&)
void Hero::buy(const string& itemName) {
  Market* currentMarket = this->getTile().getMarket();

  if (currentMarket == NULL) {
    cout << "You can't buy on a tile that has no market!" << endl << endl;
    return;
  }

  Item* itemToBuy = currentMarket->getItemByName(itemName);

  if (itemToBuy != NULL) {    
    string kind = itemToBuy->kindOf();
    Item* itemToAdd;
    bool equiped = false;

    cout << endl << "Bought " << itemName
	 << " (" << kind << ")";
    if (kind == "Weapon") {
      itemToAdd = new Weapon(*static_cast<Weapon*>(itemToBuy));
      Weapon* aux = static_cast<Weapon*>(itemToAdd);
      if (aux->needsBothHands()) {
        if (this->usesLeftHand() == false && this->usesRightHand() == false) {
	  this->equipWeapon(aux);
	  equiped = true;
	}
      } else {
	if (this->usesLeftHand() == false || this->usesRightHand() == false) {
	  this->equipWeapon(aux);
	  equiped = true;
	}
      }
    } else if (kind == "Armor") {
      itemToAdd = new Armor(*static_cast<Armor*>(itemToBuy));
      if (this->shield == NULL) {
	this->shield = static_cast<Armor*>(itemToAdd);
	equiped = true;
      }
    } else {
      itemToAdd = new Potion(*static_cast<Potion*>(itemToBuy));
    }

    if(!equiped) inventory.addItem(itemToAdd);
    setMoney(getMoney() - itemToBuy->buyFor());
    return;
  }

  Spell* spellToBuy = currentMarket->getSpellByName(itemName);
  
  if (spellToBuy != NULL) {
    string kind = spellToBuy->kindOf();
    Spell* spellToAdd;
    bool equiped = false;

    cout << endl << "Bought " << itemName
	 << " (" << kind << ")";
    if (kind == "IceSpell") {
      spellToAdd = new IceSpell(*static_cast<IceSpell*>(spellToBuy));
    } else if (kind == "FireSpell") {
      spellToAdd = new FireSpell(*static_cast<FireSpell*>(spellToBuy));
    } else {
      spellToAdd = new LightningSpell(*static_cast<LightningSpell*>(spellToBuy));
    }
    if (this->spells.size() == 0) {
      this->spells.push_back(spellToAdd);
      equiped = true;
    }

    if (!equiped) inventory.addSpell(spellToAdd);
    setMoney(getMoney() - spellToBuy->getValue());
    return;
  }

  cout << endl << "There's no item/spell with this name" << endl;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r12
pushq %rbx
subq $0x20, %rsp
movq %rsi, %r15
movq %rdi, %rbx
callq 0x1353e
movq %rax, %rdi
callq 0x66b2
testq %rax, %rax
je 0x15610
movq %rax, %r12
movq %rax, %rdi
movq %r15, %rsi
callq 0x11eea
testq %rax, %rax
je 0x15688
movq %rax, %r14
movq (%rax), %rax
movq %rsp, %rdi
movq %r14, %rsi
callq *0x18(%rax)
movq 0xfadb(%rip), %rdi      # 0x24fc0
movq (%rdi), %rax
addq -0x18(%rax), %rdi
movl $0xa, %esi
callq 0x4270
movsbl %al, %esi
movq 0xfac0(%rip), %rdi      # 0x24fc0
callq 0x4040
movq %rax, %rdi
callq 0x41b0
movq %rax, %r12
leaq 0x6b7c(%rip), %rsi      # 0x1c093
movl $0x7, %edx
movq %rax, %rdi
callq 0x42f0
movq (%r15), %rsi
movq 0x8(%r15), %rdx
movq %r12, %rdi
callq 0x42f0
movq %rax, %r15
leaq 0x6b5e(%rip), %rsi      # 0x1c09b
movl $0x2, %edx
movq %rax, %rdi
callq 0x42f0
movq (%rsp), %rsi
movq 0x8(%rsp), %rdx
movq %r15, %rdi
callq 0x42f0
leaq 0x6069(%rip), %rsi      # 0x1b5cb
movl $0x1, %edx
movq %rax, %rdi
callq 0x42f0
leaq 0x663c(%rip), %rsi      # 0x1bbb2
movq %rsp, %rdi
callq 0x40d0
testl %eax, %eax
je 0x157ce
leaq 0x662c(%rip), %rsi      # 0x1bbb9
movq %rsp, %rdi
callq 0x40d0
testl %eax, %eax
je 0x1585e
movl $0x60, %edi
callq 0x4290
movq %rax, %r15
leaq 0xf787(%rip), %rax      # 0x24d38
addq $0x10, %rax
movq %rax, (%r15)
leaq 0x8(%r15), %rdi
movq %r15, %rax
addq $0x18, %rax
movq %rax, 0x8(%r15)
movq 0x8(%r14), %rsi
movq 0x10(%r14), %rdx
addq %rsi, %rdx
callq 0x4cf0
movq 0x38(%r14), %rax
movq %rax, 0x38(%r15)
movups 0x28(%r14), %xmm0
movups %xmm0, 0x28(%r15)
leaq 0xf6f8(%rip), %rax      # 0x24ce8
addq $0x10, %rax
movq %rax, (%r15)
movups 0x40(%r14), %xmm0
movups 0x4c(%r14), %xmm1
movups %xmm0, 0x40(%r15)
movups %xmm1, 0x4c(%r15)
jmp 0x1592e
movq 0xf9a9(%rip), %rbx      # 0x24fc0
leaq 0x6a49(%rip), %rsi      # 0x1c067
movl $0x2b, %edx
movq %rbx, %rdi
callq 0x42f0
movq (%rbx), %rax
movq -0x18(%rax), %rdi
addq %rbx, %rdi
movl $0xa, %esi
callq 0x4270
movsbl %al, %esi
movq %rbx, %rdi
callq 0x4040
movq %rax, %rdi
callq 0x41b0
movq %rax, %rbx
movq (%rax), %rax
movq -0x18(%rax), %rdi
addq %rbx, %rdi
movl $0xa, %esi
callq 0x4270
movsbl %al, %esi
movq %rbx, %rdi
callq 0x4040
movq %rax, %rdi
addq $0x20, %rsp
popq %rbx
popq %r12
popq %r14
popq %r15
popq %rbp
jmp 0x41b0
movq %r12, %rdi
movq %r15, %rsi
callq 0x11f88
testq %rax, %rax
je 0x158d1
movq %rax, %r14
movq (%rax), %rax
movq %rsp, %rdi
movq %r14, %rsi
callq *0x18(%rax)
movq 0xf90e(%rip), %rdi      # 0x24fc0
movq (%rdi), %rax
addq -0x18(%rax), %rdi
movl $0xa, %esi
callq 0x4270
movsbl %al, %esi
movq 0xf8f3(%rip), %rdi      # 0x24fc0
callq 0x4040
movq %rax, %rdi
callq 0x41b0
movq %rax, %r12
leaq 0x69af(%rip), %rsi      # 0x1c093
movl $0x7, %edx
movq %rax, %rdi
callq 0x42f0
movq (%r15), %rsi
movq 0x8(%r15), %rdx
movq %r12, %rdi
callq 0x42f0
movq %rax, %r15
leaq 0x6991(%rip), %rsi      # 0x1c09b
movl $0x2, %edx
movq %rax, %rdi
callq 0x42f0
movq (%rsp), %rsi
movq 0x8(%rsp), %rdx
movq %r15, %rdi
callq 0x42f0
leaq 0x5e9c(%rip), %rsi      # 0x1b5cb
movl $0x1, %edx
movq %rax, %rdi
callq 0x42f0
leaq 0x64ff(%rip), %rsi      # 0x1bc42
movq %rsp, %rdi
callq 0x40d0
testl %eax, %eax
je 0x1595d
leaq 0x64f1(%rip), %rsi      # 0x1bc4b
movq %rsp, %rdi
callq 0x40d0
testl %eax, %eax
je 0x159be
movl $0x58, %edi
callq 0x4290
movq %rax, %r15
leaq 0xf10a(%rip), %rax      # 0x24888
addq $0x10, %rax
movq %rax, (%r15)
movsd 0x8(%r14), %xmm0
movsd %xmm0, 0x8(%r15)
leaq 0x10(%r15), %rdi
movq %r15, %rax
addq $0x20, %rax
movq %rax, 0x10(%r15)
movq 0x10(%r14), %rsi
movq 0x18(%r14), %rdx
addq %rsi, %rdx
callq 0x4cf0
movl 0x40(%r14), %eax
movl %eax, 0x40(%r15)
movups 0x30(%r14), %xmm0
movups %xmm0, 0x30(%r15)
leaq 0xf01f(%rip), %rax      # 0x247e8
jmp 0x15a1d
movl $0x48, %edi
callq 0x4290
movq %rax, %r15
leaq 0xf556(%rip), %rax      # 0x24d38
addq $0x10, %rax
movq %rax, (%r15)
leaq 0x8(%r15), %rdi
movq %r15, %rax
addq $0x18, %rax
movq %rax, 0x8(%r15)
movq 0x8(%r14), %rsi
movq 0x10(%r14), %rdx
addq %rsi, %rdx
callq 0x4cf0
movq 0x38(%r14), %rax
movq %rax, 0x38(%r15)
movups 0x28(%r14), %xmm0
movups %xmm0, 0x28(%r15)
leaq 0xf427(%rip), %rax      # 0x24c48
addq $0x10, %rax
movq %rax, (%r15)
movl 0x40(%r14), %eax
movl %eax, 0x40(%r15)
movb 0x44(%r14), %al
movb %al, 0x44(%r15)
movq %r15, %rdi
callq 0x19db6
movq 0x48(%rbx), %rcx
movq 0x50(%rbx), %rdx
testb %al, %al
je 0x1591e
orq %rdx, %rcx
jne 0x1592e
jmp 0x1593f
movl $0x48, %edi
callq 0x4290
movq %rax, %r15
leaq 0xf4c6(%rip), %rax      # 0x24d38
addq $0x10, %rax
movq %rax, (%r15)
leaq 0x8(%r15), %rdi
movq %r15, %rax
addq $0x18, %rax
movq %rax, 0x8(%r15)
movq 0x8(%r14), %rsi
movq 0x10(%r14), %rdx
addq %rsi, %rdx
callq 0x4cf0
movq 0x38(%r14), %rax
movq %rax, 0x38(%r15)
movups 0x28(%r14), %xmm0
movups %xmm0, 0x28(%r15)
leaq 0xf3e7(%rip), %rax      # 0x24c98
addq $0x10, %rax
movq %rax, (%r15)
movsd 0x40(%r14), %xmm0
movsd %xmm0, 0x40(%r15)
cmpq $0x0, 0x58(%rbx)
jne 0x1592e
movq %r15, 0x58(%rbx)
jmp 0x1594a
movq 0xf6e8(%rip), %rbx      # 0x24fc0
movq (%rbx), %rax
movq -0x18(%rax), %rdi
addq %rbx, %rdi
movl $0xa, %esi
callq 0x4270
movsbl %al, %esi
movq %rbx, %rdi
callq 0x4040
movq %rax, %rdi
callq 0x41b0
movq %rax, %rbx
leaq 0x6795(%rip), %rsi      # 0x1c09e
movl $0x24, %edx
movq %rax, %rdi
callq 0x42f0
movq (%rbx), %rax
jmp 0x15658
testq %rdx, %rdx
setne %al
testq %rcx, %rcx
setne %cl
testb %al, %cl
je 0x1593f
leaq 0xc0(%rbx), %rdi
movq %r15, %rsi
callq 0xea7c
jmp 0x1594a
movq %rbx, %rdi
movq %r15, %rsi
callq 0x14aa0
movl 0xac(%rbx), %ebp
movq %r14, %rdi
callq 0x1a800
jmp 0x15a78
movl $0x58, %edi
callq 0x4290
movq %rax, %r15
leaq 0xef17(%rip), %rax      # 0x24888
addq $0x10, %rax
movq %rax, (%r15)
movsd 0x8(%r14), %xmm0
movsd %xmm0, 0x8(%r15)
leaq 0x10(%r15), %rdi
movq %r15, %rax
addq $0x20, %rax
movq %rax, 0x10(%r15)
movq 0x10(%r14), %rsi
movq 0x18(%r14), %rdx
addq %rsi, %rdx
callq 0x4cf0
movl 0x40(%r14), %eax
movl %eax, 0x40(%r15)
movups 0x30(%r14), %xmm0
movups %xmm0, 0x30(%r15)
leaq 0xeddc(%rip), %rax      # 0x24798
jmp 0x15a1d
movl $0x58, %edi
callq 0x4290
movq %rax, %r15
leaq 0xeeb6(%rip), %rax      # 0x24888
addq $0x10, %rax
movq %rax, (%r15)
movsd 0x8(%r14), %xmm0
movsd %xmm0, 0x8(%r15)
leaq 0x10(%r15), %rdi
movq %r15, %rax
addq $0x20, %rax
movq %rax, 0x10(%r15)
movq 0x10(%r14), %rsi
movq 0x18(%r14), %rdx
addq %rsi, %rdx
callq 0x4cf0
movl 0x40(%r14), %eax
movl %eax, 0x40(%r15)
movups 0x30(%r14), %xmm0
movups %xmm0, 0x30(%r15)
leaq 0xee1b(%rip), %rax      # 0x24838
addq $0x10, %rax
movq %rax, (%r15)
movl 0x50(%r14), %eax
movl %eax, 0x50(%r15)
movq 0x48(%r14), %rax
movq %rax, 0x48(%r15)
cmpq $0x0, 0x70(%rbx)
je 0x15a4c
leaq 0xc0(%rbx), %rdi
movq %r15, %rsi
callq 0xeb00
jmp 0x15a6a
movl $0x18, %edi
callq 0x4290
leaq 0x60(%rbx), %rsi
movq %r15, 0x10(%rax)
movq %rax, %rdi
callq 0x4050
incq 0x70(%rbx)
movl 0xac(%rbx), %ebp
movq %r14, %rdi
callq 0x1312e
subl %eax, %ebp
movl %ebp, 0xac(%rbx)
leaq 0x10(%rsp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0x15a9b
movq 0x10(%rsp), %rsi
incq %rsi
callq 0x42a0
addq $0x20, %rsp
popq %rbx
popq %r12
popq %r14
popq %r15
popq %rbp
retq
jmp 0x15aac
jmp 0x15aac
movq %rax, %rbx
movl $0x58, %esi
jmp 0x15aca
jmp 0x15ab8
movq %rax, %rbx
movl $0x48, %esi
jmp 0x15aca
movq %rax, %rbx
movl $0x60, %esi
movq %r15, %rdi
callq 0x42a0
jmp 0x15adb
jmp 0x15ad8
jmp 0x15ad8
movq %rax, %rbx
leaq 0x10(%rsp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0x15af6
movq 0x10(%rsp), %rsi
incq %rsi
callq 0x42a0
movq %rbx, %rdi
callq 0x4430