// File: /workspace/github_cpp_makefile_star2_O1/arisKoutsou[P]oopproj/./src/livings/Hero.cpp
// Function: Hero::castSpell(Monster*)
void Hero :: castSpell(Monster* target) {
  if (this->spells.empty()) {
    cout << "You have no spells for use" << endl;
    return;
  }
  printEquipedSpells();
  Spell* spellToCast;
  do {
    cout << "Choose a spell to cast"
	 << endl << endl << "> ";
    string name;
    getline(cin, name);
    spellToCast = this->getSpellByName(name);
    if (spellToCast == NULL) {
      cout << endl << "There's no such a spell" << endl;
    }
  } while (spellToCast == NULL);
  Random rng;
  double dodgeProbability = rng.from0to1();
  if (dodgeProbability <= target->getDodge()) {
    cout << endl << "The monster dodged your attack" << endl;
    return;
  }
  int damage = this->dexterity +
    rng.fromMintoMax(spellToCast->getMinDamage(),
		     spellToCast->getMaxDamage());
  int damageReduction = target->getDamageReductionFactor() * damage;
  target->receiveDamage(damage - damageReduction);
  this->magicPower -= spellToCast->getMagicPowerRequired();
  this->magicPower = (this->magicPower < 0) ? 0 : this->magicPower;
  string kind = spellToCast->kindOf();
  if (kind == "FireSpell") {
    FireSpell* auxSpell = static_cast<FireSpell*>(spellToCast);
    int rounds = auxSpell->getReductionRounds();
    double amount = auxSpell->reduceOponentArmorBy();
    target->applyNerf(rounds, amount, Monster :: FIRE);
  } else if (kind == "IceSpell") {
    IceSpell* auxSpell = static_cast<IceSpell*>(spellToCast);
    int rounds = auxSpell->getReductionRounds();
    double amount = auxSpell->reduceOponentDamageRangeBy();
    target->applyNerf(rounds, amount, Monster :: ICE);    
  } else {
    LightningSpell* auxSpell = static_cast<LightningSpell*>(spellToCast);
    int rounds = auxSpell->getReductionRounds();
    double amount = auxSpell->reduceOponentDodgeBy();
    target->applyNerf(rounds, amount, Monster :: LIGHT);
  }
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x38, %rsp
leaq 0x60(%rdi), %rax
cmpq %rax, 0x60(%rdi)
je 0x16385
movq %rdi, %r14
movq %rsi, 0x28(%rsp)
callq 0x164dc
movq 0xeebc(%rip), %r15      # 0x24fc0
leaq 0x4f61(%rip), %r13      # 0x1b06c
movq 0xeebe(%rip), %rbp      # 0x24fd0
leaq 0x8(%rsp), %rbx
movl $0x16, %edx
movq %r15, %rdi
leaq 0x60b3(%rip), %rsi      # 0x1c1d9
callq 0x42f0
movq (%r15), %rax
movq -0x18(%rax), %rdi
addq %r15, %rdi
movl $0xa, %esi
callq 0x4270
movsbl %al, %esi
movq %r15, %rdi
callq 0x4040
movq %rax, %rdi
callq 0x41b0
movq %rax, %r12
movq (%rax), %rax
movq -0x18(%rax), %rdi
addq %r12, %rdi
movl $0xa, %esi
callq 0x4270
movsbl %al, %esi
movq %r12, %rdi
callq 0x4040
movq %rax, %rdi
callq 0x41b0
movl $0x2, %edx
movq %rax, %rdi
movq %r13, %rsi
callq 0x42f0
leaq 0x18(%rsp), %rax
movq %rax, 0x8(%rsp)
movq $0x0, 0x10(%rsp)
movb $0x0, 0x18(%rsp)
movq (%rbp), %rax
movq -0x18(%rax), %rdi
addq %rbp, %rdi
movl $0xa, %esi
callq 0x4270
movsbl %al, %edx
movq %rbp, %rdi
movq %rbx, %rsi
callq 0x4460
movq %r14, %rdi
movq %rbx, %rsi
callq 0x1606c
movq %rax, %r12
testq %rax, %rax
jne 0x16269
movq (%r15), %rax
movq -0x18(%rax), %rdi
addq %r15, %rdi
movl $0xa, %esi
callq 0x4270
movsbl %al, %esi
movq %r15, %rdi
callq 0x4040
movq %rax, %rdi
callq 0x41b0
movq %rax, %r12
movl $0x17, %edx
movq %rax, %rdi
leaq 0x5fd9(%rip), %rsi      # 0x1c1f0
callq 0x42f0
movq (%r12), %rax
movq -0x18(%rax), %rdi
addq %r12, %rdi
movl $0xa, %esi
callq 0x4270
movsbl %al, %esi
movq %r12, %rdi
callq 0x4040
movq %rax, %rdi
callq 0x41b0
movq 0x8(%rsp), %rdi
leaq 0x18(%rsp), %rax
cmpq %rax, %rdi
je 0x16117
movq 0x18(%rsp), %rsi
incq %rsi
callq 0x42a0
jmp 0x16117
movq 0x8(%rsp), %rdi
leaq 0x18(%rsp), %rax
cmpq %rax, %rdi
je 0x16285
movq 0x18(%rsp), %rsi
incq %rsi
callq 0x42a0
leaq 0x7(%rsp), %rdi
xorl %r13d, %r13d
xorl %esi, %esi
callq 0x4d80
callq 0x4da0
movsd %xmm0, 0x30(%rsp)
movq 0x28(%rsp), %rdi
callq 0x1885e
ucomisd 0x30(%rsp), %xmm0
jae 0x163d5
movl 0xa8(%r14), %ebx
movq %r12, %rdi
callq 0x130ac
movl %eax, %ebp
movq %r12, %rdi
callq 0x130a8
movl %ebp, %edi
movq 0x28(%rsp), %r15
movl %eax, %esi
callq 0x4dee
addl %eax, %ebx
movq %r15, %rdi
callq 0x18858
cvtsi2sd %ebx, %xmm1
mulsd %xmm0, %xmm1
cvttsd2si %xmm1, %eax
subl %eax, %ebx
movq (%r15), %rax
movq %r15, %rdi
movl %ebx, %esi
callq *0x10(%rax)
movq %r12, %rdi
callq 0x130a4
movl 0x94(%r14), %ecx
subl %eax, %ecx
testl %ecx, %ecx
cmovgl %ecx, %r13d
movl %r13d, 0x94(%r14)
movq (%r12), %rax
leaq 0x8(%rsp), %rbx
movq %rbx, %rdi
movq %r12, %rsi
callq *0x18(%rax)
leaq 0x5915(%rip), %rsi      # 0x1bc4b
movq %rbx, %rdi
callq 0x40d0
testl %eax, %eax
je 0x1643c
leaq 0x58f5(%rip), %rsi      # 0x1bc42
leaq 0x8(%rsp), %rdi
callq 0x40d0
testl %eax, %eax
je 0x1645c
movq %r12, %rdi
callq 0x125d4
movl %eax, %ebx
movq %r12, %rdi
callq 0x125ce
movq %r15, %rdi
movl %ebx, %esi
movl $0x2, %edx
callq 0x18cfe
jmp 0x1647d
movq 0xec34(%rip), %rbx      # 0x24fc0
leaq 0x5e2b(%rip), %rsi      # 0x1c1be
movl $0x1a, %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
addq $0x38, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0x41b0
movq (%r15), %rax
movq -0x18(%rax), %rdi
addq %r15, %rdi
movl $0xa, %esi
callq 0x4270
movsbl %al, %esi
movq %r15, %rdi
callq 0x4040
movq %rax, %rdi
callq 0x41b0
movq %rax, %rbx
leaq 0x5e02(%rip), %rsi      # 0x1c208
movl $0x1e, %edx
movq %rax, %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
jmp 0x16499
movq %r12, %rdi
callq 0x12b54
movl %eax, %ebx
movq %r12, %rdi
callq 0x12b4e
movq %r15, %rdi
movl %ebx, %esi
xorl %edx, %edx
callq 0x18cfe
jmp 0x1647d
movq %r12, %rdi
callq 0x12054
movl %eax, %ebx
movq %r12, %rdi
callq 0x1204e
movq %r15, %rdi
movl %ebx, %esi
movl $0x1, %edx
callq 0x18cfe
movq 0x8(%rsp), %rdi
leaq 0x18(%rsp), %rax
cmpq %rax, %rdi
je 0x16499
movq 0x18(%rsp), %rsi
incq %rsi
callq 0x42a0
addq $0x38, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
jmp 0x164b4
jmp 0x164b4
jmp 0x164b4
jmp 0x164b4
jmp 0x164b4
jmp 0x164b4
movq %rax, %rbx
movq 0x8(%rsp), %rdi
leaq 0x18(%rsp), %rax
cmpq %rax, %rdi
je 0x164d3
movq 0x18(%rsp), %rsi
incq %rsi
callq 0x42a0
movq %rbx, %rdi
callq 0x4430
nop