summaryrefslogtreecommitdiff
path: root/src/char
diff options
context:
space:
mode:
authorHaru <haru@dotalux.com>2018-06-25 00:36:54 +0200
committerHaru <haru@dotalux.com>2018-06-30 01:51:11 +0200
commit4bcd46503481e616214fd40424ea63adf9352db8 (patch)
tree53b6486fcb5edaae7bb363f100a433068604ae6d /src/char
parent409c8a7348f9141a40ec0161d1e5715088516fd8 (diff)
downloadhercules-4bcd46503481e616214fd40424ea63adf9352db8.tar.gz
hercules-4bcd46503481e616214fd40424ea63adf9352db8.tar.bz2
hercules-4bcd46503481e616214fd40424ea63adf9352db8.tar.xz
hercules-4bcd46503481e616214fd40424ea63adf9352db8.zip
Move some non-mapif functionality from the mapif interface to the inter_pet interface
Signed-off-by: Haru <haru@dotalux.com>
Diffstat (limited to 'src/char')
-rw-r--r--src/char/int_pet.c54
-rw-r--r--src/char/int_pet.h4
-rw-r--r--src/char/mapif.c5
-rw-r--r--src/char/mapif.h3
4 files changed, 40 insertions, 26 deletions
diff --git a/src/char/int_pet.c b/src/char/int_pet.c
index f270f205d..6ba4c7bba 100644
--- a/src/char/int_pet.c
+++ b/src/char/int_pet.c
@@ -222,7 +222,7 @@ int mapif_delete_pet_ack(int fd, int flag)
return 0;
}
-int mapif_create_pet(int fd, int account_id, int char_id, short pet_class, short pet_lv, short pet_egg_id,
+struct s_pet *inter_pet_create(int account_id, int char_id, short pet_class, short pet_lv, short pet_egg_id,
short pet_equip, short intimate, short hungry, char rename_flag, char incubate, const char *pet_name)
{
nullpo_ret(pet_name);
@@ -254,33 +254,29 @@ int mapif_create_pet(int fd, int account_id, int char_id, short pet_class, short
inter_pet->pt->pet_id = 0; //Signal NEW pet.
if ((inter_pet->pt->pet_id = inter_pet->tosql(inter_pet->pt)) != 0)
- mapif->pet_created(fd, account_id, inter_pet->pt);
+ return inter_pet->pt;
else //Failed...
- mapif->pet_created(fd, account_id, NULL);
-
- return 0;
+ return NULL;
}
-int mapif_load_pet(int fd, int account_id, int char_id, int pet_id)
+struct s_pet *inter_pet_load(int account_id, int char_id, int pet_id)
{
memset(inter_pet->pt, 0, sizeof(struct s_pet));
inter_pet->fromsql(pet_id, inter_pet->pt);
if(inter_pet->pt!=NULL) {
- if(inter_pet->pt->incubate == 1) {
+ if (inter_pet->pt->incubate == 1) {
inter_pet->pt->account_id = inter_pet->pt->char_id = 0;
- mapif->pet_info(fd, account_id, inter_pet->pt);
+ return inter_pet->pt;
+ } else if (account_id == inter_pet->pt->account_id && char_id == inter_pet->pt->char_id) {
+ return inter_pet->pt;
+ } else {
+ return NULL;
}
- else if(account_id == inter_pet->pt->account_id && char_id == inter_pet->pt->char_id)
- mapif->pet_info(fd, account_id, inter_pet->pt);
- else
- mapif->pet_noinfo(fd, account_id);
}
- else
- mapif->pet_noinfo(fd, account_id);
- return 0;
+ return NULL;
}
int mapif_save_pet(int fd, int account_id, const struct s_pet *data)
@@ -310,16 +306,35 @@ int mapif_delete_pet(int fd, int pet_id)
int mapif_parse_CreatePet(int fd)
{
+ int account_id;
+ struct s_pet *pet;
+
RFIFOHEAD(fd);
- mapif->create_pet(fd, RFIFOL(fd, 2), RFIFOL(fd, 6), RFIFOW(fd, 10), RFIFOW(fd, 12), RFIFOW(fd, 14), RFIFOW(fd, 16), RFIFOW(fd, 18),
- RFIFOW(fd, 20), RFIFOB(fd, 22), RFIFOB(fd, 23), RFIFOP(fd, 24));
+ account_id = RFIFOL(fd, 2);
+ pet = inter_pet->create(account_id, RFIFOL(fd, 6), RFIFOW(fd, 10), RFIFOW(fd, 12), RFIFOW(fd, 14),
+ RFIFOW(fd, 16), RFIFOW(fd, 18), RFIFOW(fd, 20), RFIFOB(fd, 22), RFIFOB(fd, 23), RFIFOP(fd, 24));
+
+ if (pet != NULL)
+ mapif->pet_created(fd, account_id, pet);
+ else
+ mapif->pet_created(fd, account_id, NULL);
+
return 0;
}
int mapif_parse_LoadPet(int fd)
{
+ int account_id;
+ struct s_pet *pet;
+
RFIFOHEAD(fd);
- mapif->load_pet(fd, RFIFOL(fd, 2), RFIFOL(fd, 6), RFIFOL(fd, 10));
+ account_id = RFIFOL(fd, 2);
+ pet = inter_pet->load(account_id, RFIFOL(fd, 6), RFIFOL(fd, 10));
+
+ if (pet != NULL)
+ mapif->pet_info(fd, account_id, pet);
+ else
+ mapif->pet_noinfo(fd, account_id);
return 0;
}
@@ -363,4 +378,7 @@ void inter_pet_defaults(void)
inter_pet->sql_final = inter_pet_sql_final;
inter_pet->delete_ = inter_pet_delete;
inter_pet->parse_frommap = inter_pet_parse_frommap;
+
+ inter_pet->create = inter_pet_create;
+ inter_pet->load = inter_pet_load;
}
diff --git a/src/char/int_pet.h b/src/char/int_pet.h
index ab14a6580..9e3a2ac59 100644
--- a/src/char/int_pet.h
+++ b/src/char/int_pet.h
@@ -36,6 +36,10 @@ struct inter_pet_interface {
void (*sql_final) (void);
int (*delete_) (int pet_id);
int (*parse_frommap) (int fd);
+
+ struct s_pet *(*create) (int account_id, int char_id, short pet_class, short pet_lv, short pet_egg_id,
+ short pet_equip, short intimate, short hungry, char rename_flag, char incubate, const char *pet_name);
+ struct s_pet *(*load) (int account_id, int char_id, int pet_id);
};
#ifdef HERCULES_CORE
diff --git a/src/char/mapif.c b/src/char/mapif.c
index 470d71126..e2956af01 100644
--- a/src/char/mapif.c
+++ b/src/char/mapif.c
@@ -1421,9 +1421,6 @@ int mapif_pet_info(int fd, int account_id, struct s_pet *p);
int mapif_pet_noinfo(int fd, int account_id);
int mapif_save_pet_ack(int fd, int account_id, int flag);
int mapif_delete_pet_ack(int fd, int flag);
-int mapif_create_pet(int fd, int account_id, int char_id, short pet_class, short pet_lv, short pet_egg_id,
- short pet_equip, short intimate, short hungry, char rename_flag, char incubate, const char *pet_name);
-int mapif_load_pet(int fd, int account_id, int char_id, int pet_id);
int mapif_save_pet(int fd, int account_id, const struct s_pet *data);
int mapif_delete_pet(int fd, int pet_id);
int mapif_parse_CreatePet(int fd);
@@ -1624,8 +1621,6 @@ void mapif_defaults(void) {
mapif->pet_noinfo = mapif_pet_noinfo;
mapif->save_pet_ack = mapif_save_pet_ack;
mapif->delete_pet_ack = mapif_delete_pet_ack;
- mapif->create_pet = mapif_create_pet;
- mapif->load_pet = mapif_load_pet;
mapif->save_pet = mapif_save_pet;
mapif->delete_pet = mapif_delete_pet;
mapif->parse_CreatePet = mapif_parse_CreatePet;
diff --git a/src/char/mapif.h b/src/char/mapif.h
index a038dd304..862cb5fc5 100644
--- a/src/char/mapif.h
+++ b/src/char/mapif.h
@@ -144,9 +144,6 @@ struct mapif_interface {
int (*pet_noinfo) (int fd, int account_id);
int (*save_pet_ack) (int fd, int account_id, int flag);
int (*delete_pet_ack) (int fd, int flag);
- int (*create_pet) (int fd, int account_id, int char_id, short pet_class, short pet_lv, short pet_egg_id,
- short pet_equip, short intimate, short hungry, char rename_flag, char incubate, const char *pet_name);
- int (*load_pet) (int fd, int account_id, int char_id, int pet_id);
int (*save_pet) (int fd, int account_id, const struct s_pet *data);
int (*delete_pet) (int fd, int pet_id);
int (*parse_CreatePet) (int fd);