Skip to content
Permalink
Browse files

Merge pull request #2400 from Asheraf/stylist_update

moving stylist into it's own interface
  • Loading branch information...
MishimaHaruna committed Mar 11, 2019
2 parents 0d7b360 + 61ee0a6 commit 95bf87b3b3c256f1d84e53a49ee43aab98912932
@@ -465,7 +465,6 @@ HPExport const struct s_HPMDataCheck HPMDataCheck[] = {
{ "hCSData", sizeof(struct hCSData), SERVER_TYPE_MAP },
{ "merge_item", sizeof(struct merge_item), SERVER_TYPE_MAP },
{ "s_packet_db", sizeof(struct s_packet_db), SERVER_TYPE_MAP },
{ "stylist_data_entry", sizeof(struct stylist_data_entry), SERVER_TYPE_MAP },
#else
#define MAP_CLIF_H
#endif // MAP_CLIF_H
@@ -963,6 +962,12 @@ HPExport const struct s_HPMDataCheck HPMDataCheck[] = {
#else
#define MAP_STORAGE_H
#endif // MAP_STORAGE_H
#ifdef MAP_STYLIST_H
{ "stylist_data_entry", sizeof(struct stylist_data_entry), SERVER_TYPE_MAP },
{ "stylist_interface", sizeof(struct stylist_interface), SERVER_TYPE_MAP },
#else
#define MAP_STYLIST_H
#endif // MAP_STYLIST_H
#ifdef MAP_TRADE_H
{ "trade_interface", sizeof(struct trade_interface), SERVER_TYPE_MAP },
#else
@@ -281,6 +281,9 @@ struct stringbuf_interface *StrBuf;
#ifdef COMMON_STRLIB_H /* strlib */
struct strlib_interface *strlib;
#endif // COMMON_STRLIB_H
#ifdef MAP_STYLIST_H /* stylist */
struct stylist_interface *stylist;
#endif // MAP_STYLIST_H
#ifdef COMMON_STRLIB_H /* sv */
struct sv_interface *sv;
#endif // COMMON_STRLIB_H
@@ -646,6 +649,10 @@ HPExport const char *HPM_shared_symbols(int server_type)
if ((server_type&(SERVER_TYPE_ALL)) != 0 && !HPM_SYMBOL("strlib", strlib))
return "strlib";
#endif // COMMON_STRLIB_H
#ifdef MAP_STYLIST_H /* stylist */
if ((server_type&(SERVER_TYPE_MAP)) != 0 && !HPM_SYMBOL("stylist", stylist))
return "stylist";
#endif // MAP_STYLIST_H
#ifdef COMMON_STRLIB_H /* sv */
if ((server_type&(SERVER_TYPE_ALL)) != 0 && !HPM_SYMBOL("sv", sv))
return "sv";
@@ -86,6 +86,7 @@
#include "map/skill.h"
#include "map/status.h"
#include "map/storage.h"
#include "map/stylist.h"
#include "map/trade.h"
#include "map/unit.h"
#include "map/vending.h"
@@ -45,7 +45,7 @@ MAP_C = achievement.c atcommand.c battle.c battleground.c buyingstore.c channel.
instance.c intif.c irc-bot.c itemdb.c log.c mail.c map.c mapreg_sql.c \
mercenary.c mob.c npc.c npc_chat.c party.c path.c pc.c pc_groups.c \
pet.c quest.c rodex.c script.c searchstore.c skill.c status.c storage.c \
trade.c unit.c vending.c
stylist.c trade.c unit.c vending.c
MAP_OBJ = $(addprefix obj_sql/, $(patsubst %c,%o,$(MAP_C)))
MAP_H = achievement.h atcommand.h battle.h battleground.h buyingstore.h channel.h chat.h \
chrif.h clan.h clif.h date.h duel.h elemental.h guild.h homunculus.h HPMmap.h \
@@ -55,7 +55,7 @@ MAP_H = achievement.h atcommand.h battle.h battleground.h buyingstore.h channel.
packets_keys_zero.h packets_shuffle_main.h packets_shuffle_re.h \
packets_shuffle_zero.h packets_struct.h party.h path.h pc.h pc_groups.h \
pet.h quest.h rodex.h script.h searchstore.h skill.h status.h storage.h \
trade.h unit.h vending.h
stylist.h trade.h unit.h vending.h
MAP_PH =

HAVE_MYSQL=@HAVE_MYSQL@
@@ -52,6 +52,7 @@
#include "map/script.h"
#include "map/skill.h"
#include "map/status.h"
#include "map/stylist.h"
#include "map/storage.h"
#include "map/trade.h"
#include "map/unit.h"
#endif
}

static void clif_stylist_vector_init(void)
{
int i;
for (i = 0; i < MAX_STYLIST_TYPE; i++) {
VECTOR_INIT(stylist_data[i]);
}
}

static void clif_stylist_vector_clear(void)
{
int i;
for (i = 0; i < MAX_STYLIST_TYPE; i++) {
VECTOR_CLEAR(stylist_data[i]);
}
}

static bool clif_stylist_read_db_libconfig(void)
{
struct config_t stylist_conf;
struct config_setting_t *stylist = NULL, *it = NULL;
const char *config_filename = "db/stylist_db.conf"; // FIXME hardcoded name
int i = 0;

if (!libconfig->load_file(&stylist_conf, config_filename))
return false;

if ((stylist = libconfig->setting_get_member(stylist_conf.root, "stylist_db")) == NULL) {
ShowError("can't read %s\n", config_filename);
return false;
}

clif->stylist_vector_clear();

while ((it = libconfig->setting_get_elem(stylist, i++))) {
clif->stylist_read_db_libconfig_sub(it, i - 1, config_filename);
}

libconfig->destroy(&stylist_conf);
ShowStatus("Done reading '"CL_WHITE"%d"CL_RESET"' entries in '"CL_WHITE"%s"CL_RESET"'.\n", i, config_filename);
return true;
}

static bool clif_stylist_read_db_libconfig_sub(struct config_setting_t *it, int idx, const char *source)
{
struct stylist_data_entry entry = { 0 };
int i32 = 0, type = 0;
int64 i64 = 0;

nullpo_ret(it);
nullpo_ret(source);

if (!itemdb->lookup_const(it, "Type", &type) || type >= MAX_STYLIST_TYPE || type < 0) {
ShowWarning("clif_stylist_read_db_libconfig_sub: Invalid or missing Type (%d) in \"%s\", entry #%d, skipping.\n", type, source, idx);
return false;
}
if (!itemdb->lookup_const(it, "Id", &i32) || i32 < 0) {
ShowWarning("clif_stylist_read_db_libconfig_sub: Invalid or missing Id (%d) in \"%s\", entry #%d, skipping.\n", i32, source, idx);
return false;
}
entry.id = i32;

if (libconfig->setting_lookup_int64(it, "Zeny", &i64)) {
if (i64 > MAX_ZENY) {
ShowWarning("clif_stylist_read_db_libconfig_sub: zeny is too big in \"%s\", entry #%d, capping to MAX_ZENY.\n", source, idx);
entry.zeny = MAX_ZENY;
} else {
entry.zeny = (int)i64;
}
}

if (itemdb->lookup_const(it, "ItemID", &i32))
entry.itemid = i32;

if (itemdb->lookup_const(it, "BoxItemID", &i32))
entry.boxid = i32;

if (libconfig->setting_lookup_bool(it, "AllowDoram", &i32))
entry.allow_doram = (i32 == 0) ? false : true;

VECTOR_ENSURE(stylist_data[type], 1, 1);
VECTOR_PUSH(stylist_data[type], entry);
return true;
}

static bool clif_style_change_validate_requirements(struct map_session_data *sd, int type, int16 idx)
{
struct item it;
struct stylist_data_entry *entry;

nullpo_retr(false, sd);
Assert_retr(false, type >= 0 && type < MAX_STYLIST_TYPE);
Assert_retr(false, idx >= 0 && idx < VECTOR_LENGTH(stylist_data[type]));

entry = &VECTOR_INDEX(stylist_data[type], idx);

if (sd->status.class == JOB_SUMMONER && (entry->allow_doram == false))
return false;

if (entry->id >= 0) {
if (entry->zeny != 0) {
if (sd->status.zeny < entry->zeny)
return false;

sd->status.zeny -= entry->zeny;
clif->updatestatus(sd, SP_ZENY);
} else if (entry->itemid != 0) {
it.nameid = entry->itemid;
it.amount = 1;
return script->buildin_delitem_search(sd, &it, false);
} else if (entry->boxid != 0) {
it.nameid = entry->boxid;
it.amount = 1;
return script->buildin_delitem_search(sd, &it, false);
}
return true;
}
return false;
}
static void clif_stylist_send_rodexitem(struct map_session_data *sd, int itemid)
{
struct rodex_message msg = { 0 };

nullpo_retv(sd);

msg.receiver_id = sd->status.char_id;
msg.items[0].item.nameid = itemid;
msg.items[0].item.amount = 1;
msg.items[0].item.identify = 1;
msg.type = MAIL_TYPE_NPC | MAIL_TYPE_ITEM;

safestrncpy(msg.sender_name, msg_txt(366), NAME_LENGTH);
safestrncpy(msg.title, msg_txt(367), RODEX_TITLE_LENGTH);
safestrncpy(msg.body, msg_txt(368), MAIL_BODY_LENGTH);
msg.send_date = (int)time(NULL);
msg.expire_date = (int)time(NULL) + RODEX_EXPIRE;

intif->rodex_sendmail(&msg);
}

static void clif_parse_cz_req_style_change(int fd, struct map_session_data *sd) __attribute__((nonnull(2)));
static void clif_parse_cz_req_style_change(int fd, struct map_session_data *sd)
{
const struct PACKET_CZ_REQ_STYLE_CHANGE *p = RP2PTR(fd);

if (p->HeadStyle > 0)
clif->cz_req_style_change_sub(sd, LOOK_HAIR, p->HeadStyle, false);
stylist->request_style_change(sd, LOOK_HAIR, p->HeadStyle, false);
if (p->HeadPalette > 0)
clif->cz_req_style_change_sub(sd, LOOK_HAIR_COLOR, p->HeadPalette, false);
stylist->request_style_change(sd, LOOK_HAIR_COLOR, p->HeadPalette, false);
if (p->BodyPalette > 0)
clif->cz_req_style_change_sub(sd, LOOK_CLOTHES_COLOR, p->BodyPalette, false);
stylist->request_style_change(sd, LOOK_CLOTHES_COLOR, p->BodyPalette, false);
if (p->TopAccessory > 0)
clif->cz_req_style_change_sub(sd, LOOK_HEAD_TOP, p->TopAccessory, true);
stylist->request_style_change(sd, LOOK_HEAD_TOP, p->TopAccessory, true);
if (p->MidAccessory > 0)
clif->cz_req_style_change_sub(sd, LOOK_HEAD_MID, p->MidAccessory, true);
stylist->request_style_change(sd, LOOK_HEAD_MID, p->MidAccessory, true);
if (p->BottomAccessory > 0)
clif->cz_req_style_change_sub(sd, LOOK_HEAD_BOTTOM, p->BottomAccessory, true);
stylist->request_style_change(sd, LOOK_HEAD_BOTTOM, p->BottomAccessory, true);
clif->style_change_response(sd, STYLIST_SHOP_SUCCESS);
return;
}
const struct PACKET_CZ_REQ_STYLE_CHANGE2 *p = RP2PTR(fd);

if (p->HeadStyle > 0)
clif->cz_req_style_change_sub(sd, LOOK_HAIR, p->HeadStyle, false);
stylist->request_style_change(sd, LOOK_HAIR, p->HeadStyle, false);
if (p->HeadPalette > 0)
clif->cz_req_style_change_sub(sd, LOOK_HAIR_COLOR, p->HeadPalette, false);
stylist->request_style_change(sd, LOOK_HAIR_COLOR, p->HeadPalette, false);
if (p->BodyPalette > 0)
clif->cz_req_style_change_sub(sd, LOOK_CLOTHES_COLOR, p->BodyPalette, false);
stylist->request_style_change(sd, LOOK_CLOTHES_COLOR, p->BodyPalette, false);
if (p->TopAccessory > 0)
clif->cz_req_style_change_sub(sd, LOOK_HEAD_TOP, p->TopAccessory, true);
stylist->request_style_change(sd, LOOK_HEAD_TOP, p->TopAccessory, true);
if (p->MidAccessory > 0)
clif->cz_req_style_change_sub(sd, LOOK_HEAD_MID, p->MidAccessory, true);
stylist->request_style_change(sd, LOOK_HEAD_MID, p->MidAccessory, true);
if (p->BottomAccessory > 0)
clif->cz_req_style_change_sub(sd, LOOK_HEAD_BOTTOM, p->BottomAccessory, true);
stylist->request_style_change(sd, LOOK_HEAD_BOTTOM, p->BottomAccessory, true);
if (p->BodyStyle > 0) {
if (pc->has_second_costume(sd)) {
clif->cz_req_style_change_sub(sd, LOOK_BODY2, p->BodyStyle, false);
stylist->request_style_change(sd, LOOK_BODY2, p->BodyStyle, false);
}
}
clif->style_change_response(sd, STYLIST_SHOP_SUCCESS);
return;
}

static void clif_cz_req_style_change_sub(struct map_session_data *sd, int type, int16 idx, bool isitem)
{
struct stylist_data_entry *entry;

nullpo_retv(sd);
Assert_retv(idx > 0);
Assert_retv(type >= 0 && type < MAX_STYLIST_TYPE);

if ((idx - 1) < VECTOR_LENGTH(stylist_data[type])) {
entry = &VECTOR_INDEX(stylist_data[type], idx - 1);
if (clif->style_change_validate_requirements(sd, type, idx - 1)) {
if (isitem == false)
pc->changelook(sd, type, entry->id);
else
clif->stylist_send_rodexitem(sd, entry->id);
}
}
}

static void clif_style_change_response(struct map_session_data *sd, enum stylist_shop flag)
{
#if PACKETVER >= 20151104
clif->pPrivateAirshipRequest = clif_parse_private_airship_request;
clif->PrivateAirshipResponse = clif_private_airship_response;

clif->stylist_vector_init = clif_stylist_vector_init;
clif->stylist_vector_clear = clif_stylist_vector_clear;
clif->stylist_read_db_libconfig = clif_stylist_read_db_libconfig;
clif->stylist_read_db_libconfig_sub = clif_stylist_read_db_libconfig_sub;
clif->style_change_validate_requirements = clif_style_change_validate_requirements;
clif->stylist_send_rodexitem = clif_stylist_send_rodexitem;
clif->pReqStyleChange = clif_parse_cz_req_style_change;
clif->pReqStyleChange2 = clif_parse_cz_req_style_change2;
clif->cz_req_style_change_sub = clif_cz_req_style_change_sub;
clif->style_change_response = clif_style_change_response;

clif->camera_showWindow = clif_camera_showWindow;
@@ -71,10 +71,6 @@ enum rodex_get_items;
#define MAX_ROULETTE_COLUMNS 9 /** client-defined value **/
#define RGB2BGR(c) (((c) & 0x0000FF) << 16 | ((c) & 0x00FF00) | ((c) & 0xFF0000) >> 16)

#ifndef MAX_STYLIST_TYPE
#define MAX_STYLIST_TYPE LOOK_MAX
#endif

#define COLOR_CYAN 0x00ffffU
#define COLOR_RED 0xff0000U
#define COLOR_GREEN 0x00ff00U
@@ -657,16 +653,6 @@ struct attendance_entry {
int qty;
};

/* Stylist data [Asheraf/Hercules]*/
struct stylist_data_entry {
int16 id;
int32 zeny;
int itemid;
int boxid;
bool allow_doram;
};
VECTOR_DECL(struct stylist_data_entry) stylist_data[MAX_STYLIST_TYPE];

struct barter_itemlist_entry {
int addId;
int addAmount;
@@ -1578,15 +1564,8 @@ struct clif_interface {
void (*pPrivateAirshipRequest) (int fd, struct map_session_data *sd);
void (*PrivateAirshipResponse) (struct map_session_data *sd, uint32 flag);

void (*stylist_vector_init) (void);
void (*stylist_vector_clear) (void);
bool (*stylist_read_db_libconfig) (void);
bool (*stylist_read_db_libconfig_sub) (struct config_setting_t *it, int idx, const char *source);
bool (*style_change_validate_requirements) (struct map_session_data *sd, int type, int16 idx);
void (*stylist_send_rodexitem) (struct map_session_data *sd, int itemid);
void (*pReqStyleChange) (int fd, struct map_session_data *sd);
void (*pReqStyleChange2) (int fd, struct map_session_data *sd);
void (*cz_req_style_change_sub) (struct map_session_data *sd, int type, int16 idx, bool isitem);
void (*style_change_response) (struct map_session_data *sd, enum stylist_shop flag);
void (*pPetEvolution) (int fd, struct map_session_data *sd);
void (*petEvolutionResult) (int fd, enum pet_evolution_result result);
@@ -2458,7 +2458,6 @@ static void itemdb_read(bool minimal)
itemdb->read_chains();
itemdb->read_packages();
itemdb->read_options();
clif->stylist_read_db_libconfig();
}

/**
@@ -2707,7 +2706,6 @@ static void do_final_itemdb(void)
itemdb->destroy_item_data(&itemdb->dummy, 0);
db_destroy(itemdb->names);
VECTOR_CLEAR(clif->attendance_data);
clif->stylist_vector_clear();
}

static void do_init_itemdb(bool minimal)
@@ -2717,7 +2715,6 @@ static void do_init_itemdb(bool minimal)
itemdb->options = idb_alloc(DB_OPT_RELEASE_DATA);
itemdb->names = strdb_alloc(DB_OPT_BASE,ITEM_NAME_LENGTH);
itemdb->create_dummy_data(); //Dummy data item.
clif->stylist_vector_init();
itemdb->read(minimal);

if (minimal)
Oops, something went wrong.

0 comments on commit 95bf87b

Please sign in to comment.
You can’t perform that action at this time.