// File: t0mm4rx[P]piscine_cpp/day04/ex01/Character.cpp
// Function: Character::attack(Enemy*)
void Character::attack(Enemy *enemy)
{
	if (this->weapon == NULL)
	{
		std::cout << "No weapon, cannot attack" << std::endl;
		return ;
	}
	if (this->ap < this->weapon->getAPCost())
	{
		std::cout << "No AP, cannot attack" << std::endl;
		return ;
	}
	std::cout << this->name << " attack " << enemy->getType() << " with a " << this->weapon->getName() << std::endl;
	this->weapon->attack();
	enemy->takeDamage(this->weapon->getDamage());
	this->ap -= this->weapon->getAPCost();
	this->ap = (this->ap < 0 ? 0 : this->ap);
	if (enemy->getHP() <= 0)
		delete enemy;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0xb0, %rsp
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movq -0x8(%rbp), %rax
movq %rax, -0x68(%rbp)
cmpq $0x0, 0x28(%rax)
jne 0x2879
movq 0x577f(%rip), %rdi      # 0x7fd8
leaq 0x27ca(%rip), %rsi      # 0x502a
callq 0x2100
movq %rax, %rdi
movq 0x5759(%rip), %rsi      # 0x7fc8
callq 0x2130
jmp 0x2a4b
movq -0x68(%rbp), %rax
movl 0x20(%rax), %ecx
movl %ecx, -0x6c(%rbp)
movq 0x28(%rax), %rdi
callq 0x2680
movl %eax, %ecx
movl -0x6c(%rbp), %eax
cmpl %ecx, %eax
jge 0x28bc
movq 0x573c(%rip), %rdi      # 0x7fd8
leaq 0x27a0(%rip), %rsi      # 0x5043
callq 0x2100
movq %rax, %rdi
movq 0x5716(%rip), %rsi      # 0x7fc8
callq 0x2130
jmp 0x2a4b
movq -0x68(%rbp), %rsi
movq 0x5711(%rip), %rdi      # 0x7fd8
callq 0x20f0
movq %rax, %rdi
leaq 0x2782(%rip), %rsi      # 0x5058
callq 0x2100
movq %rax, -0x88(%rbp)
movq -0x10(%rbp), %rsi
leaq -0x30(%rbp), %rdi
movq %rdi, -0x80(%rbp)
callq 0x2d50
movq -0x88(%rbp), %rdi
movq -0x80(%rbp), %rsi
callq 0x20f0
movq %rax, -0x78(%rbp)
jmp 0x2909
movq -0x78(%rbp), %rdi
leaq 0x274d(%rip), %rsi      # 0x5061
callq 0x2100
movq %rax, -0x90(%rbp)
jmp 0x2922
movq -0x68(%rbp), %rax
movq 0x28(%rax), %rsi
leaq -0x60(%rbp), %rdi
callq 0x26a0
jmp 0x2935
movq -0x90(%rbp), %rdi
leaq -0x60(%rbp), %rsi
callq 0x20f0
movq %rax, -0x98(%rbp)
jmp 0x294e
movq -0x98(%rbp), %rdi
movq 0x566c(%rip), %rsi      # 0x7fc8
callq 0x2130
jmp 0x2963
leaq -0x60(%rbp), %rdi
callq 0x2090
leaq -0x30(%rbp), %rdi
callq 0x2090
movq -0x68(%rbp), %rax
movq 0x28(%rax), %rdi
movq (%rdi), %rax
callq *0x10(%rax)
movq -0x68(%rbp), %rax
movq -0x10(%rbp), %rcx
movq %rcx, -0xa0(%rbp)
movq 0x28(%rax), %rdi
callq 0x26d0
movq -0xa0(%rbp), %rdi
movl %eax, %esi
movq (%rdi), %rax
callq *0x10(%rax)
movq -0x68(%rbp), %rax
movq 0x28(%rax), %rdi
callq 0x2680
movl %eax, %edx
movq -0x68(%rbp), %rax
movl 0x20(%rax), %ecx
subl %edx, %ecx
movl %ecx, 0x20(%rax)
cmpl $0x0, 0x20(%rax)
jge 0x29d5
xorl %eax, %eax
movl %eax, -0xa4(%rbp)
jmp 0x29e2
movq -0x68(%rbp), %rax
movl 0x20(%rax), %eax
movl %eax, -0xa4(%rbp)
movq -0x68(%rbp), %rax
movl -0xa4(%rbp), %ecx
movl %ecx, 0x20(%rax)
movq -0x10(%rbp), %rdi
callq 0x2d80
cmpl $0x0, %eax
jg 0x2a4b
movq -0x10(%rbp), %rax
movq %rax, -0xb0(%rbp)
cmpq $0x0, %rax
je 0x2a1b
movq -0xb0(%rbp), %rdi
movq (%rdi), %rax
callq *0x8(%rax)
jmp 0x2a4b
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x38(%rbp)
movl %eax, -0x3c(%rbp)
jmp 0x2a40
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x38(%rbp)
movl %eax, -0x3c(%rbp)
leaq -0x60(%rbp), %rdi
callq 0x2090
leaq -0x30(%rbp), %rdi
callq 0x2090
jmp 0x2a54
addq $0xb0, %rsp
popq %rbp
retq
movq -0x38(%rbp), %rdi
callq 0x21f0
nopl (%rax)