summaryrefslogtreecommitdiff
path: root/src/emap/homunculus.c
blob: cce18cfe55c4b6cdf6b138cb7e30ae8f764aa489 (plain) (blame)
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
// Copyright (c) Copyright (c) Hercules Dev Team, licensed under GNU GPL.
// Copyright (c) 2014 - 2015 Evol developers

#include "common/hercules.h"
#include "map/status.h"
#include "map/homunculus.h"

#include <stdio.h>
#include <stdlib.h>
#include <string.h>

#include "common/HPMi.h"
#include "common/nullpo.h"
#include "plugins/HPMHooking.h"

#include "emap/send.h"

enum homun_type ehomunculus_class2type_pre(int *class_ __attribute__ ((unused)))
{
    hookStop();
    return HT_REG;
}

int ehomunculus_gainexp_pre(struct homun_data **hdPtr,
                            unsigned int *expPtr)
{
    struct homun_data *hd = *hdPtr;
    nullpo_ret(hd);
    const int exp = *expPtr;

    // Handle some cases when EXP is not due
    if (hd->homunculus.vaporize != HOM_ST_ACTIVE) {
        // Homunculus is not active, so do nothing
        hookStop();
        return 1;
    } else if (!status->isdead(&hd->bl)) {
        // Homunculus is active and alive, inform M+ of the EXP gain
        send_homun_exp(hd, exp);
    } else if (exp > 1) {
        // Homunculus is dead, so give only half the EXP
        send_homun_exp(hd, exp/2);
        *expPtr = exp / 2;
    } else {
        // Homunculus is dead and the exp to receive is zero
        hookStop();
        return 1;
    }
    return 0;
}