// File: /workspace/github_cpp_makefile_star2_O2/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 0x111a6
movq %rdi, %r14
movq %rsi, 0x8(%rsp)
callq 0x11288
movq 0xffa0(%rip), %r12      # 0x20fc0
leaq 0x4015(%rip), %rbp      # 0x1503c
movq 0xffa2(%rip), %rbx      # 0x20fd0
leaq 0x10(%rsp), %r13
movq %r12, %rdi
leaq 0x519c(%rip), %rsi      # 0x161d9
callq 0x4250
movq %rax, %rdi
callq 0x4120
movq %rax, %rdi
callq 0x4120
movq %rax, %rdi
movq %rbp, %rsi
callq 0x4250
leaq 0x20(%rsp), %rax
movq %rax, 0x10(%rsp)
andq $0x0, 0x18(%rsp)
movb $0x0, 0x20(%rsp)
movq %rbx, %rdi
movq %r13, %rsi
callq 0x4060
movq %r14, %rdi
movq %r13, %rsi
callq 0x10fa2
movq %rax, %r15
testq %rax, %rax
jne 0x110bc
movq %r12, %rdi
callq 0x4120
movq %rax, %rdi
leaq 0x514e(%rip), %rsi      # 0x161f0
callq 0x4250
movq %rax, %rdi
callq 0x4120
movq %r13, %rdi
callq 0x4470
jmp 0x11033
leaq 0x10(%rsp), %rdi
callq 0x4470
leaq 0x7(%rsp), %rdi
xorl %r12d, %r12d
xorl %esi, %esi
callq 0x4acc
callq 0x4aec
movsd %xmm0, 0x30(%rsp)
movq 0x8(%rsp), %r13
movq %r13, %rdi
callq 0x12bfc
ucomisd 0x30(%rsp), %xmm0
jae 0x111cf
movl 0xa8(%r14), %ebx
movq %r15, %rdi
callq 0xed5a
movl %eax, %ebp
movq %r15, %rdi
callq 0xed56
movl %ebp, %edi
movl %eax, %esi
callq 0x4b2c
addl %eax, %ebx
movq %r13, %rdi
callq 0x12bf6
cvtsi2sd %ebx, %xmm1
mulsd %xmm0, %xmm1
cvttsd2si %xmm1, %eax
subl %eax, %ebx
movq (%r13), %rax
movq %r13, %rdi
movl %ebx, %esi
callq *0x10(%rax)
movq %r15, %rdi
callq 0xed52
movl 0x94(%r14), %ecx
subl %eax, %ecx
testl %ecx, %ecx
cmovgl %ecx, %r12d
movl %r12d, 0x94(%r14)
movq (%r15), %rax
leaq 0x10(%rsp), %rbx
movq %rbx, %rdi
movq %r15, %rsi
callq *0x18(%rax)
leaq 0x4ac6(%rip), %rsi      # 0x15c3b
movq %rbx, %rdi
callq 0x5b02
testb %al, %al
je 0x111f4
movq %r15, %rdi
callq 0xe8ee
movl %eax, %ebx
movq %r15, %rdi
callq 0xe8e8
movq 0x8(%rsp), %rdi
movl %ebx, %esi
xorl %edx, %edx
callq 0x12fc6
jmp 0x1124d
movq 0xfe13(%rip), %rdi      # 0x20fc0
leaq 0x500a(%rip), %rsi      # 0x161be
callq 0x4250
movq %rax, %rdi
addq $0x38, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0x4120
movq 0xfdea(%rip), %rdi      # 0x20fc0
callq 0x4120
leaq 0x5026(%rip), %rsi      # 0x16208
movq %rax, %rdi
callq 0x4250
movq %rax, %rdi
callq 0x4120
jmp 0x11257
leaq 0x4a37(%rip), %rsi      # 0x15c32
leaq 0x10(%rsp), %rdi
callq 0x5b02
testb %al, %al
je 0x1122c
movq %r15, %rdi
callq 0xdfe6
movl %eax, %ebx
movq %r15, %rdi
callq 0xdfe0
pushq $0x1
popq %rdx
movq 0x8(%rsp), %rdi
movl %ebx, %esi
callq 0x12fc6
jmp 0x1124d
movq %r15, %rdi
callq 0xe46a
movl %eax, %ebx
movq %r15, %rdi
callq 0xe464
pushq $0x2
popq %rdx
movq 0x8(%rsp), %rdi
movl %ebx, %esi
callq 0x12fc6
leaq 0x10(%rsp), %rdi
callq 0x4470
addq $0x38, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
jmp 0x11272
jmp 0x11272
jmp 0x11272
jmp 0x11272
jmp 0x11272
jmp 0x11272
movq %rax, %rbx
leaq 0x10(%rsp), %rdi
callq 0x4470
movq %rbx, %rdi
callq 0x4410
nop