// File: MichaelXanth[P]RPG_Game/Living/Monsters/Monster.cpp
// Function: Monster::HitBySpell(Spell*)
void Monster::HitBySpell(Spell* hitSpell)
{
    unsigned int rounds;

    switch(hitSpell->ReduceStat(rounds))//gets the rounds of the effect
    {
        case 1:
            avoidanceAffectedForRounds += rounds;//adds the rounds of the effect

            if(((100 - (double)hitSpell ->GetAvoidanceReduction()) / 100) * avoidance < 0)//if the new avoidance is below 0 then it is set to 0
                avoidance = 0.0;
            else
            {
                oldAvoidance += avoidance;//stores the old avoidance so that it can be restored after the end of the effect
                avoidance = ((100 - (double)hitSpell ->GetAvoidanceReduction()) / 100) * avoidance;//reduces the avoidance
            }
            break;
        case 2:
            damageAffectedForRounds += rounds;//adds the rounds of the effect

            if(minDamage - hitSpell ->GetDamageReduction() < 0)//if the new damage is below 0 then it is set to 0
                minDamage = 0;
            else
            {
                oldMinDamage += minDamage;//stores the old damage so that it can be restored after the end of the effect
                minDamage = minDamage - hitSpell ->GetDamageReduction();//reduces the damage
            }

            if(maxDamage - hitSpell ->GetDamageReduction() < 0)
                maxDamage = 0;
            else
            {
                oldMaxDamage += maxDamage;
                maxDamage = maxDamage - hitSpell ->GetDamageReduction();
            }
            break;
        case 3:
            defenceAffectedForRounds += rounds;//adds the rounds of the effect

            if(defence - hitSpell ->GetDefenceReduction() < 0)//if the new damage is below 0 then it is set to 0
                defence = 0;
            else
            {
                oldDefence += defence;//stores the old damage so that it can be restored after the end of the effect
                defence = defence - hitSpell ->GetDefenceReduction();//reduces the damage
            }
            break;
    }
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x40, %rsp
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movq -0x8(%rbp), %rax
movq %rax, -0x20(%rbp)
movq -0x10(%rbp), %rdi
movq (%rdi), %rax
movq (%rax), %rax
leaq -0x14(%rbp), %rsi
callq *%rax
cwtl
movl %eax, -0x18(%rbp)
subl $0x1, %eax
je 0x2e782
jmp 0x2e763
movl -0x18(%rbp), %eax
subl $0x2, %eax
je 0x2e84b
jmp 0x2e771
movl -0x18(%rbp), %eax
subl $0x3, %eax
je 0x2e906
jmp 0x2e969
movq -0x20(%rbp), %rax
movl -0x14(%rbp), %edx
movl 0x50(%rax), %ecx
addl %edx, %ecx
movl %ecx, 0x50(%rax)
movq -0x10(%rbp), %rdi
movq (%rdi), %rax
movq 0x50(%rax), %rax
callq *%rax
movl %eax, %ecx
movq -0x20(%rbp), %rax
movl %ecx, %ecx
cvtsi2sd %rcx, %xmm0
movsd 0x11925(%rip), %xmm1    # 0x400d8
subsd %xmm0, %xmm1
movsd 0x11919(%rip), %xmm0    # 0x400d8
divsd %xmm0, %xmm1
movss 0x60(%rax), %xmm0
cvtss2sd %xmm0, %xmm0
mulsd %xmm0, %xmm1
xorps %xmm0, %xmm0
ucomisd %xmm1, %xmm0
jbe 0x2e7e7
movq -0x20(%rbp), %rax
xorps %xmm0, %xmm0
movss %xmm0, 0x60(%rax)
jmp 0x2e846
movq -0x20(%rbp), %rax
movss 0x44(%rax), %xmm0
movss 0x60(%rax), %xmm1
addss %xmm1, %xmm0
movss %xmm0, 0x44(%rax)
movq -0x10(%rbp), %rdi
movq (%rdi), %rax
movq 0x50(%rax), %rax
callq *%rax
movl %eax, %ecx
movq -0x20(%rbp), %rax
movl %ecx, %ecx
cvtsi2sd %rcx, %xmm1
movsd 0x118b8(%rip), %xmm0    # 0x400d8
subsd %xmm1, %xmm0
movsd 0x118ac(%rip), %xmm1    # 0x400d8
divsd %xmm1, %xmm0
movss 0x60(%rax), %xmm1
cvtss2sd %xmm1, %xmm1
mulsd %xmm1, %xmm0
cvtsd2ss %xmm0, %xmm0
movss %xmm0, 0x60(%rax)
jmp 0x2e969
movq -0x20(%rbp), %rax
movl -0x14(%rbp), %ecx
addl 0x48(%rax), %ecx
movl %ecx, 0x48(%rax)
movl 0x54(%rax), %eax
movl %eax, -0x24(%rbp)
movq -0x10(%rbp), %rdi
movq (%rdi), %rax
callq *0x40(%rax)
movl %eax, %ecx
movl -0x24(%rbp), %eax
subl %ecx, %eax
cmpl $0x0, %eax
jae 0x2e881
movq -0x20(%rbp), %rax
movl $0x0, 0x54(%rax)
jmp 0x2e8ac
movq -0x20(%rbp), %rax
movl 0x54(%rax), %ecx
addl 0x38(%rax), %ecx
movl %ecx, 0x38(%rax)
movl 0x54(%rax), %eax
movl %eax, -0x28(%rbp)
movq -0x10(%rbp), %rdi
movq (%rdi), %rax
callq *0x40(%rax)
movl -0x28(%rbp), %ecx
movl %eax, %edx
movq -0x20(%rbp), %rax
subl %edx, %ecx
movl %ecx, 0x54(%rax)
movq -0x20(%rbp), %rax
movl 0x58(%rax), %eax
movl %eax, -0x2c(%rbp)
movq -0x10(%rbp), %rdi
movq (%rdi), %rax
callq *0x40(%rax)
movl %eax, %ecx
movl -0x2c(%rbp), %eax
subl %ecx, %eax
cmpl $0x0, %eax
jae 0x2e8d9
movq -0x20(%rbp), %rax
movl $0x0, 0x58(%rax)
jmp 0x2e904
movq -0x20(%rbp), %rax
movl 0x58(%rax), %ecx
addl 0x3c(%rax), %ecx
movl %ecx, 0x3c(%rax)
movl 0x58(%rax), %eax
movl %eax, -0x30(%rbp)
movq -0x10(%rbp), %rdi
movq (%rdi), %rax
callq *0x40(%rax)
movl -0x30(%rbp), %ecx
movl %eax, %edx
movq -0x20(%rbp), %rax
subl %edx, %ecx
movl %ecx, 0x58(%rax)
jmp 0x2e969
movq -0x20(%rbp), %rax
movl -0x14(%rbp), %ecx
addl 0x4c(%rax), %ecx
movl %ecx, 0x4c(%rax)
movl 0x5c(%rax), %eax
movl %eax, -0x34(%rbp)
movq -0x10(%rbp), %rdi
movq (%rdi), %rax
callq *0x48(%rax)
movl %eax, %ecx
movl -0x34(%rbp), %eax
subl %ecx, %eax
cmpl $0x0, %eax
jae 0x2e93c
movq -0x20(%rbp), %rax
movl $0x0, 0x5c(%rax)
jmp 0x2e967
movq -0x20(%rbp), %rax
movl 0x5c(%rax), %ecx
addl 0x40(%rax), %ecx
movl %ecx, 0x40(%rax)
movl 0x5c(%rax), %eax
movl %eax, -0x38(%rbp)
movq -0x10(%rbp), %rdi
movq (%rdi), %rax
callq *0x48(%rax)
movl -0x38(%rbp), %ecx
movl %eax, %edx
movq -0x20(%rbp), %rax
subl %edx, %ecx
movl %ecx, 0x5c(%rax)
jmp 0x2e969
addq $0x40, %rsp
popq %rbp
retq
nop