// File: 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
movq %rsp, %rbp
subq $0x140, %rsp            # imm = 0x140
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movq -0x8(%rbp), %rdi
movq %rdi, -0xc8(%rbp)
addq $0x60, %rdi
callq 0x17ad0
testb $0x1, %al
jne 0x25ead
jmp 0x25ed4
movq 0x1a10c(%rip), %rdi     # 0x3ffc0
leaq 0x92db(%rip), %rsi      # 0x2f196
callq 0x52f0
movq %rax, %rdi
movq 0x1a0d6(%rip), %rsi     # 0x3ffa0
callq 0x5330
jmp 0x262ff
movq -0xc8(%rbp), %rdi
callq 0x26320
movq 0x1a0d9(%rip), %rdi     # 0x3ffc0
leaq 0x92c3(%rip), %rsi      # 0x2f1b1
callq 0x52f0
movq %rax, %rdi
movq 0x1a0a3(%rip), %rsi     # 0x3ffa0
movq %rsi, -0xd8(%rbp)
callq 0x5330
movq -0xd8(%rbp), %rsi
movq %rax, %rdi
callq 0x5330
movq %rax, %rdi
leaq 0x811a(%rip), %rsi      # 0x2e03c
callq 0x52f0
leaq -0x38(%rbp), %rdi
movq %rdi, -0xd0(%rbp)
callq 0x5460
movq -0xd0(%rbp), %rsi
movq 0x1a093(%rip), %rdi     # 0x3ffd8
callq 0x5070
jmp 0x25f4c
movq -0xc8(%rbp), %rdi
leaq -0x38(%rbp), %rsi
callq 0x25dc0
movq %rax, -0xe0(%rbp)
jmp 0x25f65
movq -0xe0(%rbp), %rax
movq %rax, -0x18(%rbp)
cmpq $0x0, -0x18(%rbp)
jne 0x25fe0
movq 0x1a042(%rip), %rdi     # 0x3ffc0
movq 0x1a01b(%rip), %rsi     # 0x3ffa0
callq 0x5330
movq %rax, -0xe8(%rbp)
jmp 0x25f93
movq -0xe8(%rbp), %rdi
leaq 0x9227(%rip), %rsi      # 0x2f1c8
callq 0x52f0
movq %rax, -0xf0(%rbp)
jmp 0x25faf
movq -0xf0(%rbp), %rdi
movq 0x19fe3(%rip), %rsi     # 0x3ffa0
callq 0x5330
jmp 0x25fc4
jmp 0x25fe0
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x40(%rbp)
movl %eax, -0x44(%rbp)
leaq -0x38(%rbp), %rdi
callq 0x55d0
jmp 0x26308
leaq -0x38(%rbp), %rdi
callq 0x55d0
cmpq $0x0, -0x18(%rbp)
je 0x25ee0
leaq -0x45(%rbp), %rdi
xorl %esi, %esi
callq 0x5f80
callq 0x5fc0
movsd %xmm0, -0x50(%rbp)
movsd -0x50(%rbp), %xmm0
movsd %xmm0, -0xf8(%rbp)
movq -0x10(%rbp), %rdi
callq 0x29d10
movsd -0xf8(%rbp), %xmm1
ucomisd %xmm1, %xmm0
jb 0x26063
movq 0x19f8c(%rip), %rdi     # 0x3ffc0
movq 0x19f65(%rip), %rsi     # 0x3ffa0
callq 0x5330
movq %rax, %rdi
leaq 0x9196(%rip), %rsi      # 0x2f1e0
callq 0x52f0
movq %rax, %rdi
movq 0x19f47(%rip), %rsi     # 0x3ffa0
callq 0x5330
jmp 0x262ff
movq -0xc8(%rbp), %rax
movl 0xa8(%rax), %eax
movl %eax, -0xfc(%rbp)
movq -0x18(%rbp), %rdi
callq 0x219f0
movl %eax, -0x100(%rbp)
movq -0x18(%rbp), %rdi
callq 0x219d0
movl -0x100(%rbp), %edi
movl %eax, %esi
callq 0x6040
movl %eax, %ecx
movl -0xfc(%rbp), %eax
addl %ecx, %eax
movl %eax, -0x54(%rbp)
movq -0x10(%rbp), %rdi
callq 0x29cf0
cvtsi2sdl -0x54(%rbp), %xmm1
mulsd %xmm1, %xmm0
cvttsd2si %xmm0, %eax
movl %eax, -0x58(%rbp)
movq -0x10(%rbp), %rdi
movl -0x54(%rbp), %esi
subl -0x58(%rbp), %esi
movq (%rdi), %rax
callq *0x10(%rax)
movq -0x18(%rbp), %rdi
callq 0x219b0
movl %eax, %edx
movq -0xc8(%rbp), %rax
movl 0x94(%rax), %ecx
subl %edx, %ecx
movl %ecx, 0x94(%rax)
cmpl $0x0, 0x94(%rax)
jge 0x26104
xorl %eax, %eax
movl %eax, -0x104(%rbp)
jmp 0x26117
movq -0xc8(%rbp), %rax
movl 0x94(%rax), %eax
movl %eax, -0x104(%rbp)
movq -0xc8(%rbp), %rax
movl -0x104(%rbp), %ecx
movl %ecx, 0x94(%rax)
movq -0x18(%rbp), %rsi
movq (%rsi), %rax
movq 0x18(%rax), %rax
leaq -0x78(%rbp), %rdi
movq %rdi, -0x110(%rbp)
callq *%rax
movq -0x110(%rbp), %rdi
leaq 0x8adb(%rip), %rsi      # 0x2ec2b
callq 0x8e10
movb %al, -0x105(%rbp)
jmp 0x2615d
movb -0x105(%rbp), %al
testb $0x1, %al
jne 0x2616c
jmp 0x261ee
movq -0x18(%rbp), %rax
movq %rax, -0x80(%rbp)
movq -0x80(%rbp), %rdi
callq 0x21210
movl %eax, -0x114(%rbp)
jmp 0x26185
movl -0x114(%rbp), %eax
movl %eax, -0x84(%rbp)
movq -0x80(%rbp), %rdi
callq 0x211f0
movsd %xmm0, -0x120(%rbp)
jmp 0x261a4
movsd -0x120(%rbp), %xmm0
movsd %xmm0, -0x90(%rbp)
movq -0x10(%rbp), %rdi
movl -0x84(%rbp), %esi
movsd -0x90(%rbp), %xmm0
xorl %edx, %edx
callq 0x2a3a0
jmp 0x261cf
jmp 0x262f6
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x40(%rbp)
movl %eax, -0x44(%rbp)
leaq -0x78(%rbp), %rdi
callq 0x55d0
jmp 0x26308
leaq 0x8a2d(%rip), %rsi      # 0x2ec22
leaq -0x78(%rbp), %rdi
callq 0x8e10
movb %al, -0x121(%rbp)
jmp 0x26206
movb -0x121(%rbp), %al
testb $0x1, %al
jne 0x26212
jmp 0x26283
movq -0x18(%rbp), %rax
movq %rax, -0x98(%rbp)
movq -0x98(%rbp), %rdi
callq 0x20270
movl %eax, -0x128(%rbp)
jmp 0x26231
movl -0x128(%rbp), %eax
movl %eax, -0x9c(%rbp)
movq -0x98(%rbp), %rdi
callq 0x20250
movsd %xmm0, -0x130(%rbp)
jmp 0x26253
movsd -0x130(%rbp), %xmm0
movsd %xmm0, -0xa8(%rbp)
movq -0x10(%rbp), %rdi
movl -0x9c(%rbp), %esi
movsd -0xa8(%rbp), %xmm0
movl $0x1, %edx
callq 0x2a3a0
jmp 0x26281
jmp 0x262f4
movq -0x18(%rbp), %rax
movq %rax, -0xb0(%rbp)
movq -0xb0(%rbp), %rdi
callq 0x20a50
movl %eax, -0x134(%rbp)
jmp 0x262a2
movl -0x134(%rbp), %eax
movl %eax, -0xb4(%rbp)
movq -0xb0(%rbp), %rdi
callq 0x20a30
movsd %xmm0, -0x140(%rbp)
jmp 0x262c4
movsd -0x140(%rbp), %xmm0
movsd %xmm0, -0xc0(%rbp)
movq -0x10(%rbp), %rdi
movl -0xb4(%rbp), %esi
movsd -0xc0(%rbp), %xmm0
movl $0x2, %edx
callq 0x2a3a0
jmp 0x262f2
jmp 0x262f4
jmp 0x262f6
leaq -0x78(%rbp), %rdi
callq 0x55d0
addq $0x140, %rsp            # imm = 0x140
popq %rbp
retq
movq -0x40(%rbp), %rdi
callq 0x5550
nopw %cs:(%rax,%rax)