// File: /workspace/github_cpp_makefile_star2_O3/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 0x163e3
movq %rdi, %r14
movq %rsi, 0x28(%rsp)
callq 0x1653a
movq 0xee5e(%rip), %r15      # 0x24fc0
leaq 0x4f03(%rip), %r13      # 0x1b06c
movq 0xee60(%rip), %rbp      # 0x24fd0
leaq 0x8(%rsp), %rbx
movl $0x16, %edx
movq %r15, %rdi
leaq 0x6065(%rip), %rsi      # 0x1c1e9
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 0x160ca
movq %rax, %r12
testq %rax, %rax
jne 0x162c7
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 0x5f8b(%rip), %rsi      # 0x1c200
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 0x16175
movq 0x18(%rsp), %rsi
incq %rsi
callq 0x42a0
jmp 0x16175
movq 0x8(%rsp), %rdi
leaq 0x18(%rsp), %rax
cmpq %rax, %rdi
je 0x162e3
movq 0x18(%rsp), %rsi
incq %rsi
callq 0x42a0
leaq 0x7(%rsp), %rdi
xorl %r13d, %r13d
xorl %esi, %esi
callq 0x4d88
callq 0x4da8
movsd %xmm0, 0x30(%rsp)
movq 0x28(%rsp), %rdi
callq 0x188e2
ucomisd 0x30(%rsp), %xmm0
jae 0x16433
movl 0xa8(%r14), %ebx
movq %r12, %rdi
callq 0x13120
movl %eax, %ebp
movq %r12, %rdi
callq 0x1311c
movl %ebp, %edi
movq 0x28(%rsp), %r15
movl %eax, %esi
callq 0x4df6
addl %eax, %ebx
movq %r15, %rdi
callq 0x188dc
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 0x13118
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 0x58b7(%rip), %rsi      # 0x1bc4b
movq %rbx, %rdi
callq 0x40d0
testl %eax, %eax
je 0x1649a
leaq 0x5897(%rip), %rsi      # 0x1bc42
leaq 0x8(%rsp), %rdi
callq 0x40d0
testl %eax, %eax
je 0x164ba
movq %r12, %rdi
callq 0x12648
movl %eax, %ebx
movq %r12, %rdi
callq 0x12642
movq %r15, %rdi
movl %ebx, %esi
movl $0x2, %edx
callq 0x18d86
jmp 0x164db
movq 0xebd6(%rip), %rbx      # 0x24fc0
leaq 0x5ddd(%rip), %rsi      # 0x1c1ce
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 0x5db4(%rip), %rsi      # 0x1c218
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 0x164f7
movq %r12, %rdi
callq 0x12bc8
movl %eax, %ebx
movq %r12, %rdi
callq 0x12bc2
movq %r15, %rdi
movl %ebx, %esi
xorl %edx, %edx
callq 0x18d86
jmp 0x164db
movq %r12, %rdi
callq 0x120c8
movl %eax, %ebx
movq %r12, %rdi
callq 0x120c2
movq %r15, %rdi
movl %ebx, %esi
movl $0x1, %edx
callq 0x18d86
movq 0x8(%rsp), %rdi
leaq 0x18(%rsp), %rax
cmpq %rax, %rdi
je 0x164f7
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 0x16512
jmp 0x16512
jmp 0x16512
jmp 0x16512
jmp 0x16512
jmp 0x16512
movq %rax, %rbx
movq 0x8(%rsp), %rdi
leaq 0x18(%rsp), %rax
cmpq %rax, %rdi
je 0x16531
movq 0x18(%rsp), %rsi
incq %rsi
callq 0x42a0
movq %rbx, %rdi
callq 0x4430
nop