// File: rozpo[P]enemy/data/game/battle/Battle.cpp
// Function: void Battle::calculateDamage<Player, Enemy>(std::shared_ptr<Player>&, std::shared_ptr<Enemy>&, int, std::vector<std::shared_ptr<Skill>, std::allocator<std::shared_ptr<Skill>>> const&)
void Battle::calculateDamage(std::shared_ptr<T1> &user,
                             std::shared_ptr<T2> &target,
                             int x,
                             const std::vector<std::shared_ptr<Skill>> &skills)
{
    int dmg = 0;
    std::cout << '\n';
    for(int i = 0; i<skills.size(); i++)
    {
        if (user->skills[ x ] == skills[ i ]->id) {
            if (skills[ i ]->chance >= ((std::rand () % 100) + 1)) {
                dmg = user->weapon_dmg + ((std::rand () % skills[ i ]->damage) + 1) +
                      (characterDamage (user , skills[ i ]->type));
                if (skills[ i ]->critical >= ((std::rand () % 100) + 1)) {
                    dmg *= 2;
                    if (! skills[ i ]->target)
                        target->hitpoints -= dmg;
                    else {
                        user->hitpoints += dmg;
                        if (user->hitpoints > user->max_hitpoints)
                            user->hitpoints = user->max_hitpoints;
                    }
                    std::cout << user->name << " using " << skills[ i ]->name << " " << dmg << "HP CRITICAL HIT!";
                } else {
                    if (! skills[ i ]->target)
                        target->hitpoints -= dmg;
                    else {
                        user->hitpoints += dmg;
                        if (user->hitpoints > user->max_hitpoints)
                            user->hitpoints = user->max_hitpoints;
                    }
                    std::cout << user->name << " using " << skills[ i ]->name << " " << dmg << "HP";
                }
                std::cout << '\n';
            } else
                std::cout << user->name << " miss! " << skills[ i ]->name << '\n';
        }
    }
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x90, %rsp
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movl %edx, -0x14(%rbp)
movq %rcx, -0x20(%rbp)
movl $0x0, -0x24(%rbp)
movq 0x23fd8(%rip), %rdi     # 0x2efd0
movl $0xa, %esi
callq 0x4240
movl $0x0, -0x28(%rbp)
movslq -0x28(%rbp), %rax
movq %rax, -0x30(%rbp)
movq -0x20(%rbp), %rdi
callq 0xb870
movq %rax, %rcx
movq -0x30(%rbp), %rax
cmpq %rcx, %rax
jae 0xb405
movq -0x8(%rbp), %rdi
callq 0xaf60
movq %rax, %rdi
addq $0x1c, %rdi
movslq -0x14(%rbp), %rsi
callq 0x5000
movl (%rax), %eax
movl %eax, -0x34(%rbp)
movq -0x20(%rbp), %rdi
movslq -0x28(%rbp), %rsi
callq 0xb890
movq %rax, %rdi
callq 0xb8b0
movq %rax, %rcx
movl -0x34(%rbp), %eax
cmpl (%rcx), %eax
jne 0xb3f5
movq -0x20(%rbp), %rdi
movslq -0x28(%rbp), %rsi
callq 0xb890
movq %rax, %rdi
callq 0xb8b0
movl 0x30(%rax), %eax
movl %eax, -0x38(%rbp)
callq 0x4050
movl $0x64, %ecx
cltd
idivl %ecx
movl -0x38(%rbp), %eax
addl $0x1, %edx
cmpl %edx, %eax
jl 0xb38c
movq -0x8(%rbp), %rdi
callq 0xaf60
movl 0x80(%rax), %eax
movl %eax, -0x4c(%rbp)
callq 0x4050
movl %eax, -0x50(%rbp)
movq -0x20(%rbp), %rdi
movslq -0x28(%rbp), %rsi
callq 0xb890
movq %rax, %rdi
callq 0xb8b0
movq %rax, %rcx
movl -0x50(%rbp), %eax
cltd
idivl 0x28(%rcx)
movl -0x4c(%rbp), %eax
addl $0x1, %edx
addl %edx, %eax
movl %eax, -0x40(%rbp)
movq -0x8(%rbp), %rax
movq %rax, -0x48(%rbp)
movq -0x20(%rbp), %rdi
movslq -0x28(%rbp), %rsi
callq 0xb890
movq %rax, %rdi
callq 0xb8b0
movq -0x48(%rbp), %rdi
movl 0x38(%rax), %esi
callq 0xbb20
movl %eax, %ecx
movl -0x40(%rbp), %eax
addl %ecx, %eax
movl %eax, -0x24(%rbp)
movq -0x20(%rbp), %rdi
movslq -0x28(%rbp), %rsi
callq 0xb890
movq %rax, %rdi
callq 0xb8b0
movl 0x34(%rax), %eax
movl %eax, -0x3c(%rbp)
callq 0x4050
movl $0x64, %ecx
cltd
idivl %ecx
movl -0x3c(%rbp), %eax
addl $0x1, %edx
cmpl %edx, %eax
jl 0xb26a
movl -0x24(%rbp), %eax
shll %eax
movl %eax, -0x24(%rbp)
movq -0x20(%rbp), %rdi
movslq -0x28(%rbp), %rsi
callq 0xb890
movq %rax, %rdi
callq 0xb8b0
testb $0x1, 0x2c(%rax)
jne 0xb18d
movl -0x24(%rbp), %eax
movl %eax, -0x54(%rbp)
movq -0x10(%rbp), %rdi
callq 0xaf80
movl -0x54(%rbp), %edx
movl 0x8(%rax), %ecx
subl %edx, %ecx
movl %ecx, 0x8(%rax)
jmp 0xb1e8
movl -0x24(%rbp), %eax
movl %eax, -0x5c(%rbp)
movq -0x8(%rbp), %rdi
callq 0xaf60
movl -0x5c(%rbp), %ecx
addl 0x8(%rax), %ecx
movl %ecx, 0x8(%rax)
movq -0x8(%rbp), %rdi
callq 0xaf60
movl 0x8(%rax), %eax
movl %eax, -0x58(%rbp)
movq -0x8(%rbp), %rdi
callq 0xaf60
movq %rax, %rcx
movl -0x58(%rbp), %eax
cmpl 0xc(%rcx), %eax
jle 0xb1e6
movq -0x8(%rbp), %rdi
callq 0xaf60
movl 0xc(%rax), %eax
movl %eax, -0x60(%rbp)
movq -0x8(%rbp), %rdi
callq 0xaf60
movl -0x60(%rbp), %ecx
movl %ecx, 0x8(%rax)
jmp 0xb1e8
movq -0x8(%rbp), %rdi
callq 0xaf60
movq %rax, %rsi
addq $0x40, %rsi
movq 0x23dd1(%rip), %rdi     # 0x2efd0
callq 0x4190
movq %rax, %rdi
leaq 0x122ed(%rip), %rsi     # 0x1d4fb
callq 0x41b0
movq %rax, -0x68(%rbp)
movq -0x20(%rbp), %rdi
movslq -0x28(%rbp), %rsi
callq 0xb890
movq %rax, %rdi
callq 0xb8b0
movq -0x68(%rbp), %rdi
movq %rax, %rsi
addq $0x8, %rsi
callq 0x4190
movq %rax, %rdi
leaq 0x122d7(%rip), %rsi     # 0x1d51d
callq 0x41b0
movq %rax, %rdi
movl -0x24(%rbp), %esi
callq 0x42d0
movq %rax, %rdi
leaq 0x122a3(%rip), %rsi     # 0x1d503
callq 0x41b0
jmp 0xb379
movq -0x20(%rbp), %rdi
movslq -0x28(%rbp), %rsi
callq 0xb890
movq %rax, %rdi
callq 0xb8b0
testb $0x1, 0x2c(%rax)
jne 0xb2a1
movl -0x24(%rbp), %eax
movl %eax, -0x6c(%rbp)
movq -0x10(%rbp), %rdi
callq 0xaf80
movl -0x6c(%rbp), %edx
movl 0x8(%rax), %ecx
subl %edx, %ecx
movl %ecx, 0x8(%rax)
jmp 0xb2fc
movl -0x24(%rbp), %eax
movl %eax, -0x74(%rbp)
movq -0x8(%rbp), %rdi
callq 0xaf60
movl -0x74(%rbp), %ecx
addl 0x8(%rax), %ecx
movl %ecx, 0x8(%rax)
movq -0x8(%rbp), %rdi
callq 0xaf60
movl 0x8(%rax), %eax
movl %eax, -0x70(%rbp)
movq -0x8(%rbp), %rdi
callq 0xaf60
movq %rax, %rcx
movl -0x70(%rbp), %eax
cmpl 0xc(%rcx), %eax
jle 0xb2fa
movq -0x8(%rbp), %rdi
callq 0xaf60
movl 0xc(%rax), %eax
movl %eax, -0x78(%rbp)
movq -0x8(%rbp), %rdi
callq 0xaf60
movl -0x78(%rbp), %ecx
movl %ecx, 0x8(%rax)
jmp 0xb2fc
movq -0x8(%rbp), %rdi
callq 0xaf60
movq %rax, %rsi
addq $0x40, %rsi
movq 0x23cbd(%rip), %rdi     # 0x2efd0
callq 0x4190
movq %rax, %rdi
leaq 0x121d9(%rip), %rsi     # 0x1d4fb
callq 0x41b0
movq %rax, -0x80(%rbp)
movq -0x20(%rbp), %rdi
movslq -0x28(%rbp), %rsi
callq 0xb890
movq %rax, %rdi
callq 0xb8b0
movq -0x80(%rbp), %rdi
movq %rax, %rsi
addq $0x8, %rsi
callq 0x4190
movq %rax, %rdi
leaq 0x121c3(%rip), %rsi     # 0x1d51d
callq 0x41b0
movq %rax, %rdi
movl -0x24(%rbp), %esi
callq 0x42d0
movq %rax, %rdi
leaq 0x121a0(%rip), %rsi     # 0x1d514
callq 0x41b0
movq 0x23c50(%rip), %rdi     # 0x2efd0
movl $0xa, %esi
callq 0x4240
jmp 0xb3f3
movq -0x8(%rbp), %rdi
callq 0xaf60
movq %rax, %rsi
addq $0x40, %rsi
movq 0x23c2d(%rip), %rdi     # 0x2efd0
callq 0x4190
movq %rax, %rdi
leaq 0x12165(%rip), %rsi     # 0x1d517
callq 0x41b0
movq %rax, -0x88(%rbp)
movq -0x20(%rbp), %rdi
movslq -0x28(%rbp), %rsi
callq 0xb890
movq %rax, %rdi
callq 0xb8b0
movq -0x88(%rbp), %rdi
movq %rax, %rsi
addq $0x8, %rsi
callq 0x4190
movq %rax, %rdi
movl $0xa, %esi
callq 0x4240
jmp 0xb3f5
jmp 0xb3f7
movl -0x28(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x28(%rbp)
jmp 0xb009
addq $0x90, %rsp
popq %rbp
retq
nop