aboutsummaryrefslogtreecommitdiff
path: root/cpp03/ex01/ScavTrap.cpp
blob: 8379228556272a35bfb0c7461db7bda203bd9644 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
/* ************************************************************************** */
/*                                                                            */
/*                                                        :::      ::::::::   */
/*   ScavTrap.cpp                                       :+:      :+:    :+:   */
/*                                                    +:+ +:+         +:+     */
/*   By: charles <charles.cabergs@gmail.com>        +#+  +:+       +#+        */
/*                                                +#+#+#+#+#+   +#+           */
/*   Created: 2020/04/13 14:15:03 by charles           #+#    #+#             */
/*   Updated: 2020/11/10 15:06:00 by cacharle         ###   ########.fr       */
/*                                                                            */
/* ************************************************************************** */

#include "ScavTrap.hpp"

ScavTrap::ScavTrap():
    m_hitPoints(100),
    m_maxHitPoints(100),
    m_energyPoints(50),
    m_maxEnergyPoints(50),
    m_level(1),
    m_name(""),
    m_meleeAttackDamage(20),
    m_rangedAttackDamage(15),
    m_armorDamageReduction(3)
{
	std::cout << "New " << m_name << ": your gaming references suck" << std::endl;
}

ScavTrap::ScavTrap(std::string const& name):
    m_hitPoints(100),
    m_maxHitPoints(100),
    m_energyPoints(50),
    m_maxEnergyPoints(50),
    m_level(1),
    m_name(name),
    m_meleeAttackDamage(20),
    m_rangedAttackDamage(15),
    m_armorDamageReduction(3)
{
	std::cout << "SC4V-TP New " << m_name << ": your gaming references suck" << std::endl;
}

ScavTrap::ScavTrap(ScavTrap const& other)
{
    *this = other;
}

ScavTrap& ScavTrap::operator=(ScavTrap const& other)
{
    m_hitPoints            = other.m_hitPoints;
    m_maxHitPoints         = other.m_maxHitPoints;
    m_energyPoints         = other.m_energyPoints;
    m_maxEnergyPoints      = other.m_maxEnergyPoints;
    m_level                = other.m_level;
    m_meleeAttackDamage    = other.m_meleeAttackDamage;
    m_rangedAttackDamage   = other.m_rangedAttackDamage;
    m_armorDamageReduction = other.m_armorDamageReduction;
    return *this;
}

ScavTrap::~ScavTrap()
{
	std::cout << "SC4V-TP Delete " << m_name << ": your gaming references still suck" << std::endl;
}

void ScavTrap::rangedAttack(std::string const& target) const
{
	std::cout << "SC4V-TP " << m_name
              << " attacks " << target
			  << " at range, causing " << m_rangedAttackDamage
              << " points of damage!" << std::endl;
}

void ScavTrap::meleeAttack(std::string const& target) const
{
	std::cout << "SC4V-TP " << m_name
              << " attacks " << target
			  << " in melee mode causing " << m_meleeAttackDamage
              << " points of damage!" << std::endl;
}

void ScavTrap::takeDamage(unsigned int amount)
{
    amount -= m_armorDamageReduction;
    if (amount < 0)
        amount = 0;
	if (amount > m_hitPoints)
        amount = m_hitPoints;
	m_hitPoints -= amount;
	std::cout << "SC4V-TP " << m_name
              << " takes " << amount
              << " damage" << std::endl;
}

void ScavTrap::beRepaired(unsigned int amount)
{
    if (amount + m_hitPoints > m_maxHitPoints)
        amount = m_maxHitPoints - m_hitPoints;
    m_hitPoints += amount;
	std::cout << "SC4V-TP " << m_name
              << " gained " << amount
              << " hit points" << std::endl;
}

void ScavTrap::challengeNewcomer(std::string const& target)
{
    std::string challenges[5] = {
        "lick your elbow",
        "do 1 push up",
        "dont talk for 1 hour",
        "draw your name by peeing in the snow",
        "punch me"
    };
	std::cout << "SC4V-TP " << m_name
              << " challenge " << target
              << " to " << challenges[rand() % 5] << std::endl;
}