summaryrefslogblamecommitdiff
path: root/src/emap/homunculus.c
blob: fdf0b9d30f3717801b9b2919e0bcd03a5be4425d (plain) (tree)
1
2
3
4
5
6



                                                                         
                       
                           






                          
                               









                                                      






                                                                    
                                








                                                            

             
// 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"

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;
}