diff options
author | Ibrahim Zidan <brahem@aotsw.com> | 2019-04-13 21:11:09 +0200 |
---|---|---|
committer | Ibrahim Zidan <brahem@aotsw.com> | 2019-05-05 23:27:59 +0200 |
commit | bd1c1bb39b3d69fba175bda94af4e9d1149fbbb5 (patch) | |
tree | 5e8e804a3f8e3ef8d0f580bc2763b23b84682edb | |
parent | 31f47be4b26e69d2880e12530d021ce6c8c802ea (diff) | |
download | hercules-bd1c1bb39b3d69fba175bda94af4e9d1149fbbb5.tar.gz hercules-bd1c1bb39b3d69fba175bda94af4e9d1149fbbb5.tar.bz2 hercules-bd1c1bb39b3d69fba175bda94af4e9d1149fbbb5.tar.xz hercules-bd1c1bb39b3d69fba175bda94af4e9d1149fbbb5.zip |
Removal of refine database code from status.c and moving it respectfully to its own files
Signed-off-by: Ibrahim Zidan <brahem@aotsw.com>
-rw-r--r-- | src/map/HPMmap.c | 2 | ||||
-rw-r--r-- | src/map/Makefile.in | 6 | ||||
-rw-r--r-- | src/map/atcommand.c | 1 | ||||
-rw-r--r-- | src/map/itemdb.c | 1 | ||||
-rw-r--r-- | src/map/map.c | 3 | ||||
-rw-r--r-- | src/map/refine.c | 233 | ||||
-rw-r--r-- | src/map/refine.h | 107 | ||||
-rw-r--r-- | src/map/refine.p.h | 58 | ||||
-rw-r--r-- | src/map/script.c | 3 | ||||
-rw-r--r-- | src/map/skill.c | 3 | ||||
-rw-r--r-- | src/map/status.c | 197 | ||||
-rw-r--r-- | src/map/status.h | 41 | ||||
-rw-r--r-- | vcproj-12/map-server.vcxproj | 3 | ||||
-rw-r--r-- | vcproj-12/map-server.vcxproj.filters | 9 | ||||
-rw-r--r-- | vcproj-14/map-server.vcxproj | 3 | ||||
-rw-r--r-- | vcproj-14/map-server.vcxproj.filters | 9 | ||||
-rw-r--r-- | vcproj-15/map-server.vcxproj | 3 | ||||
-rw-r--r-- | vcproj-15/map-server.vcxproj.filters | 11 |
18 files changed, 454 insertions, 239 deletions
diff --git a/src/map/HPMmap.c b/src/map/HPMmap.c index cbfa8e8c4..e89f47c12 100644 --- a/src/map/HPMmap.c +++ b/src/map/HPMmap.c @@ -81,6 +81,8 @@ #include "map/pet.h" #include "map/quest.h" #include "map/rodex.h" +#include "map/refine.h" +#include "map/refine.p.h" #include "map/script.h" #include "map/searchstore.h" #include "map/skill.h" diff --git a/src/map/Makefile.in b/src/map/Makefile.in index edb3fdaad..f851de756 100644 --- a/src/map/Makefile.in +++ b/src/map/Makefile.in @@ -44,7 +44,7 @@ MAP_C = achievement.c atcommand.c battle.c battleground.c buyingstore.c channel. chrif.c clan.c clif.c date.c duel.c elemental.c guild.c homunculus.c HPMmap.c \ 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 \ + pet.c quest.c refine.c rodex.c script.c searchstore.c skill.c status.c storage.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 \ @@ -54,9 +54,9 @@ MAP_H = achievement.h atcommand.h battle.h battleground.h buyingstore.h channel. messages_sak.h messages_zero.h mob.h npc.h packets.h packets_keys_main.h \ 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 \ + pet.h quest.h refine.h rodex.h script.h searchstore.h skill.h status.h storage.h \ stylist.h trade.h unit.h vending.h -MAP_PH = +MAP_PH = refine.p.h HAVE_MYSQL=@HAVE_MYSQL@ ifeq ($(HAVE_MYSQL),yes) diff --git a/src/map/atcommand.c b/src/map/atcommand.c index 8bca17fa1..e2ba88e64 100644 --- a/src/map/atcommand.c +++ b/src/map/atcommand.c @@ -48,6 +48,7 @@ #include "map/pc_groups.h" // groupid2name #include "map/pet.h" #include "map/quest.h" +#include "map/refine.h" #include "map/script.h" #include "map/searchstore.h" #include "map/skill.h" diff --git a/src/map/itemdb.c b/src/map/itemdb.c index a61bbd008..11d778f8a 100644 --- a/src/map/itemdb.c +++ b/src/map/itemdb.c @@ -27,6 +27,7 @@ #include "map/map.h" #include "map/mob.h" // MAX_MOB_DB #include "map/pc.h" // W_MUSICAL, W_WHIP +#include "map/refine.h" #include "map/script.h" // item script processing #include "common/HPM.h" #include "common/conf.h" diff --git a/src/map/map.c b/src/map/map.c index 7d2cc87d4..d34d421d7 100644 --- a/src/map/map.c +++ b/src/map/map.c @@ -58,6 +58,7 @@ #include "map/storage.h" #include "map/stylist.h" #include "map/rodex.h" +#include "map/refine.h" #include "map/trade.h" #include "map/unit.h" #include "map/achievement.h" @@ -6190,6 +6191,7 @@ int do_final(void) atcommand->final_msg(); skill->final(); status->final(); + refine->final(); unit->final(); bg->final(); duel->final(); @@ -6711,6 +6713,7 @@ int do_init(int argc, char *argv[]) map->read_zone_db();/* read after item and skill initialization */ mob->init(minimal); pc->init(minimal); + refine->init(minimal); status->init(minimal); party->init(minimal); guild->init(minimal); diff --git a/src/map/refine.c b/src/map/refine.c new file mode 100644 index 000000000..8a172c40b --- /dev/null +++ b/src/map/refine.c @@ -0,0 +1,233 @@ +/** +* This file is part of Hercules. +* http://herc.ws - http://github.com/HerculesWS/Hercules +* +* Copyright (C) 2019 Hercules Dev Team +* +* Hercules is free software: you can redistribute it and/or modify +* it under the terms of the GNU General Public License as published by +* the Free Software Foundation, either version 3 of the License, or +* (at your option) any later version. +* +* This program is distributed in the hope that it will be useful, +* but WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +* GNU General Public License for more details. +* +* You should have received a copy of the GNU General Public License +* along with this program. If not, see <http://www.gnu.org/licenses/>. +*/ + +#define HERCULES_CORE + +#include "refine.p.h" +#include "common/cbasetypes.h" +#include "common/mmo.h" +#include "common/nullpo.h" +#include "common/showmsg.h" +#include "common/strlib.h" +#include "map/map.h" + +#include <stdio.h> +#include <stdlib.h> + +/** @file +* Implementation of the refine interface. +*/ + +static struct refine_interface refine_s; +static struct refine_interface_private refine_p; +static struct refine_interface_dbs refine_dbs; +struct refine_interface *refine; + +/// @copydoc refine_interface::get_refine_chance() +static int refine_get_refine_chance(enum refine_type wlv, int refine_level, enum refine_chance_type type) +{ + Assert_ret((int)wlv >= REFINE_TYPE_ARMOR && wlv < REFINE_TYPE_MAX); + + if (refine_level < 0 || refine_level >= MAX_REFINE) + return 0; + + if (type >= REFINE_CHANCE_TYPE_MAX) + return 0; + + return refine->dbs->refine_info[wlv].chance[type][refine_level]; +} + +/// @copydoc refine_interface_private::readdb_refine_libconfig_sub() +static int refine_readdb_refine_libconfig_sub(struct config_setting_t *r, const char *name, const char *source) +{ + struct config_setting_t *rate = NULL; + int type = REFINE_TYPE_ARMOR, bonus_per_level = 0, rnd_bonus_v = 0, rnd_bonus_lv = 0; + char lv[4]; + nullpo_ret(r); + nullpo_ret(name); + nullpo_ret(source); + + if (strncmp(name, "Armors", 6) == 0) { + type = REFINE_TYPE_ARMOR; + } else if (strncmp(name, "WeaponLevel", 11) != 0 || !strspn(&name[strlen(name)-1], "0123456789") || (type = atoi(strncpy(lv, name+11, 2))) == REFINE_TYPE_ARMOR) { + ShowError("status_readdb_refine_libconfig_sub: Invalid key name for entry '%s' in \"%s\", skipping.\n", name, source); + return 0; + } + if (type < REFINE_TYPE_ARMOR || type >= REFINE_TYPE_MAX) { + ShowError("status_readdb_refine_libconfig_sub: Out of range level for entry '%s' in \"%s\", skipping.\n", name, source); + return 0; + } + if (!libconfig->setting_lookup_int(r, "StatsPerLevel", &bonus_per_level)) { + ShowWarning("status_readdb_refine_libconfig_sub: Missing StatsPerLevel for entry '%s' in \"%s\", skipping.\n", name, source); + return 0; + } + if (!libconfig->setting_lookup_int(r, "RandomBonusStartLevel", &rnd_bonus_lv)) { + ShowWarning("status_readdb_refine_libconfig_sub: Missing RandomBonusStartLevel for entry '%s' in \"%s\", skipping.\n", name, source); + return 0; + } + if (!libconfig->setting_lookup_int(r, "RandomBonusValue", &rnd_bonus_v)) { + ShowWarning("status_readdb_refine_libconfig_sub: Missing RandomBonusValue for entry '%s' in \"%s\", skipping.\n", name, source); + return 0; + } + + if ((rate=libconfig->setting_get_member(r, "Rates")) != NULL && config_setting_is_group(rate)) { + struct config_setting_t *t = NULL; + bool duplicate[MAX_REFINE]; + int bonus[MAX_REFINE], rnd_bonus[MAX_REFINE]; + int chance[REFINE_CHANCE_TYPE_MAX][MAX_REFINE]; + int i, j; + + memset(&duplicate, 0, sizeof(duplicate)); + memset(&bonus, 0, sizeof(bonus)); + memset(&rnd_bonus, 0, sizeof(rnd_bonus)); + + for (i = 0; i < REFINE_CHANCE_TYPE_MAX; i++) + for (j = 0; j < MAX_REFINE; j++) + chance[i][j] = 100; // default value for all rates. + + i = 0; + j = 0; + while ((t = libconfig->setting_get_elem(rate,i++)) != NULL && config_setting_is_group(t)) { + int level = 0, i32; + char *rlvl = config_setting_name(t); + memset(&lv, 0, sizeof(lv)); + + if (!strspn(&rlvl[strlen(rlvl) - 1], "0123456789") || (level = atoi(strncpy(lv, rlvl + 2, 3))) <= 0) { + ShowError("status_readdb_refine_libconfig_sub: Invalid refine level format '%s' for entry %s in \"%s\"... skipping.\n", rlvl, name, source); + continue; + } + + if (level <= 0 || level > MAX_REFINE) { + ShowError("status_readdb_refine_libconfig_sub: Out of range refine level '%s' for entry %s in \"%s\"... skipping.\n", rlvl, name, source); + continue; + } + + level--; + + if (duplicate[level]) { + ShowWarning("status_readdb_refine_libconfig_sub: duplicate rate '%s' for entry %s in \"%s\", overwriting previous entry...\n", rlvl, name, source); + } else { + duplicate[level] = true; + } + + if (libconfig->setting_lookup_int(t, "NormalChance", &i32) != 0) + chance[REFINE_CHANCE_TYPE_NORMAL][level] = i32; + else + chance[REFINE_CHANCE_TYPE_NORMAL][level] = 100; + + if (libconfig->setting_lookup_int(t, "EnrichedChance", &i32) != 0) + chance[REFINE_CHANCE_TYPE_ENRICHED][level] = i32; + else + chance[REFINE_CHANCE_TYPE_ENRICHED][level] = level > 10 ? 0 : 100; // enriched ores up to +10 only. + + if (libconfig->setting_lookup_int(t, "EventNormalChance", &i32) != 0) + chance[REFINE_CHANCE_TYPE_E_NORMAL][level] = i32; + else + chance[REFINE_CHANCE_TYPE_E_NORMAL][level] = 100; + + if (libconfig->setting_lookup_int(t, "EventEnrichedChance", &i32) != 0) + chance[REFINE_CHANCE_TYPE_E_ENRICHED][level] = i32; + else + chance[REFINE_CHANCE_TYPE_E_ENRICHED][level] = level > 10 ? 0 : 100; // enriched ores up to +10 only. + + if (libconfig->setting_lookup_int(t, "Bonus", &i32) != 0) + bonus[level] += i32; + + if (level >= rnd_bonus_lv - 1) + rnd_bonus[level] = rnd_bonus_v * (level - rnd_bonus_lv + 2); + } + for (i = 0; i < MAX_REFINE; i++) { + refine->dbs->refine_info[type].chance[REFINE_CHANCE_TYPE_NORMAL][i] = chance[REFINE_CHANCE_TYPE_NORMAL][i]; + refine->dbs->refine_info[type].chance[REFINE_CHANCE_TYPE_E_NORMAL][i] = chance[REFINE_CHANCE_TYPE_E_NORMAL][i]; + refine->dbs->refine_info[type].chance[REFINE_CHANCE_TYPE_ENRICHED][i] = chance[REFINE_CHANCE_TYPE_ENRICHED][i]; + refine->dbs->refine_info[type].chance[REFINE_CHANCE_TYPE_E_ENRICHED][i] = chance[REFINE_CHANCE_TYPE_E_ENRICHED][i]; + refine->dbs->refine_info[type].randombonus_max[i] = rnd_bonus[i]; + bonus[i] += bonus_per_level + (i > 0 ? bonus[i - 1] : 0); + refine->dbs->refine_info[type].bonus[i] = bonus[i]; + } + } else { + ShowWarning("status_readdb_refine_libconfig_sub: Missing refine rates for entry '%s' in \"%s\", skipping.\n", name, source); + return 0; + } + + return type + 1; +} + +/// @copydoc refine_interface_private::readdb_refine_libconfig() +static int refine_readdb_refine_libconfig(const char *filename) +{ + bool duplicate[REFINE_TYPE_MAX]; + struct config_t refine_db_conf; + struct config_setting_t *r; + char filepath[256]; + int i = 0, count = 0; + + safesnprintf(filepath, sizeof(filepath), "%s/%s", map->db_path, filename); + if (!libconfig->load_file(&refine_db_conf, filepath)) + return 0; + + memset(&duplicate, 0, sizeof(duplicate)); + + while((r = libconfig->setting_get_elem(refine_db_conf.root, i++))) { + char *name = config_setting_name(r); + int type = refine->p->readdb_refine_libconfig_sub(r, name, filename); + if (type != 0) { + if (duplicate[type - 1]) { + ShowWarning("status_readdb_refine_libconfig: duplicate entry for %s in \"%s\", overwriting previous entry...\n", name, filename); + } else { + duplicate[type - 1] = true; + } + count++; + } + } + libconfig->destroy(&refine_db_conf); + ShowStatus("Done reading '"CL_WHITE"%d"CL_RESET"' entries in '"CL_WHITE"%s"CL_RESET"'.\n", count, filename); + + return count; +} + +/// @copydoc refine_interface::init() +static int refine_init(bool minimal) +{ + if (minimal) + return 0; + + refine->p->readdb_refine_libconfig(DBPATH"refine_db.conf"); + return 0; +} + +/// @copydoc refine_interface::final() +static void refine_final(void) +{ +} + +void refine_defaults(void) +{ + refine = &refine_s; + refine->p = &refine_p; + + refine->p->readdb_refine_libconfig = refine_readdb_refine_libconfig; + refine->p->readdb_refine_libconfig_sub = refine_readdb_refine_libconfig_sub; + + refine->dbs = &refine_dbs; + refine->init = refine_init; + refine->final = refine_final; + refine->get_refine_chance = refine_get_refine_chance; +} diff --git a/src/map/refine.h b/src/map/refine.h new file mode 100644 index 000000000..6e7506be7 --- /dev/null +++ b/src/map/refine.h @@ -0,0 +1,107 @@ +/** +* This file is part of Hercules. +* http://herc.ws - http://github.com/HerculesWS/Hercules +* +* Copyright (C) 2019 Hercules Dev Team +* +* Hercules is free software: you can redistribute it and/or modify +* it under the terms of the GNU General Public License as published by +* the Free Software Foundation, either version 3 of the License, or +* (at your option) any later version. +* +* This program is distributed in the hope that it will be useful, +* but WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +* GNU General Public License for more details. +* +* You should have received a copy of the GNU General Public License +* along with this program. If not, see <http://www.gnu.org/licenses/>. +*/ + +#ifndef MAP_REFINE_H +#define MAP_REFINE_H + +/** @file + * Refine Interface. + **/ +#include "common/hercules.h" + +/* Defines */ +/** +* Max Refine available to your server +* Changing this limit requires edits to refine_db.conf +**/ +#ifdef RENEWAL + #define MAX_REFINE 20 +#else + #define MAX_REFINE 10 +#endif + +/* Forward Declarations */ +struct refine_interface_private; + +/* Enums */ +enum refine_type { + REFINE_TYPE_ARMOR = 0, + REFINE_TYPE_WEAPON1 = 1, + REFINE_TYPE_WEAPON2 = 2, + REFINE_TYPE_WEAPON3 = 3, + REFINE_TYPE_WEAPON4 = 4, +#ifndef REFINE_TYPE_MAX + REFINE_TYPE_MAX = 5 +#endif +}; + +enum refine_chance_type { + REFINE_CHANCE_TYPE_NORMAL = 0, // Normal Chance + REFINE_CHANCE_TYPE_ENRICHED = 1, // Enriched Ore Chance + REFINE_CHANCE_TYPE_E_NORMAL = 2, // Event Normal Ore Chance + REFINE_CHANCE_TYPE_E_ENRICHED = 3, // Event Enriched Ore Chance + REFINE_CHANCE_TYPE_MAX +}; + +/* Structures */ +struct s_refine_info { + int chance[REFINE_CHANCE_TYPE_MAX][MAX_REFINE]; // success chance + int bonus[MAX_REFINE]; // cumulative fixed bonus damage + int randombonus_max[MAX_REFINE]; // cumulative maximum random bonus damage +}; + +struct refine_interface_dbs { + struct s_refine_info refine_info[REFINE_TYPE_MAX]; +}; + +/** + * Refine Interface + **/ +struct refine_interface { + struct refine_interface_private *p; + struct refine_interface_dbs *dbs; + + /** + * Initialize refine system + * @param minimal sets refine system to minimal mode in which it won't load or initialize itself + * @return returns 0 in-case of success 1 otherwise + **/ + int (*init)(bool minimal); + + /** + * Finalize refine system + **/ + void (*final)(void); + + /** + * Get the chance to upgrade a piece of equipment. + * @param wlv The weapon type of the item to refine (see see enum refine_type) + * @param refine The target refine level + * @return The chance to refine the item, in percent (0~100) + **/ + int (*get_refine_chance) (enum refine_type wlv, int refine_level, enum refine_chance_type type); +}; + +#ifdef HERCULES_CORE +void refine_defaults(void); +#endif + +HPShared struct refine_interface *refine; +#endif
\ No newline at end of file diff --git a/src/map/refine.p.h b/src/map/refine.p.h new file mode 100644 index 000000000..4d6f403bb --- /dev/null +++ b/src/map/refine.p.h @@ -0,0 +1,58 @@ +/** +* This file is part of Hercules. +* http://herc.ws - http://github.com/HerculesWS/Hercules +* +* Copyright (C) 2019 Hercules Dev Team +* +* Hercules is free software: you can redistribute it and/or modify +* it under the terms of the GNU General Public License as published by +* the Free Software Foundation, either version 3 of the License, or +* (at your option) any later version. +* +* This program is distributed in the hope that it will be useful, +* but WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +* GNU General Public License for more details. +* +* You should have received a copy of the GNU General Public License +* along with this program. If not, see <http://www.gnu.org/licenses/>. +*/ + +#ifndef MAP_REFINE_P_H +#define MAP_REFINE_P_H + +/** @file + * Private header for the refine interface. + **/ + +#include "refine.h" +#include "common/conf.h" + +/** + * Refine Private Interface + **/ +struct refine_interface_private { + /** + * Processes a refine_db.conf entry. + * + * @param r Libconfig setting entry. It is expected to be valid and it + * won't be freed (it is care of the caller to do so if + * necessary) + * @param n Ordinal number of the entry, to be displayed in case of + * validation errors. + * @param source Source of the entry (file name), to be displayed in case of + * validation errors. + * @return # of the validated entry, or 0 in case of failure. + **/ + int (*readdb_refine_libconfig_sub) (struct config_setting_t *r, const char *name, const char *source); + + /** + * Reads from a libconfig-formatted refine_db.conf file. + * + * @param *filename File name, relative to the database path. + * @return The number of found entries. + **/ + int (*readdb_refine_libconfig) (const char *filename); +}; + +#endif diff --git a/src/map/script.c b/src/map/script.c index 4fb24708b..1cc1d3ad2 100644 --- a/src/map/script.c +++ b/src/map/script.c @@ -52,6 +52,7 @@ #include "map/pet.h" #include "map/pet.h" #include "map/quest.h" +#include "map/refine.h" #include "map/skill.h" #include "map/status.h" #include "map/status.h" @@ -9505,7 +9506,7 @@ static BUILDIN(getequippercentrefinery) if (i >= 0 && sd->status.inventory[i].nameid != 0 && sd->status.inventory[i].refine < MAX_REFINE) script_pushint(st, - status->get_refine_chance(itemdb_wlv(sd->status.inventory[i].nameid), (int) sd->status.inventory[i].refine, (enum refine_chance_type) type)); + refine->get_refine_chance(itemdb_wlv(sd->status.inventory[i].nameid), (int) sd->status.inventory[i].refine, (enum refine_chance_type) type)); else script_pushint(st, 0); diff --git a/src/map/skill.c b/src/map/skill.c index 633a73d67..2b2c2b6f1 100644 --- a/src/map/skill.c +++ b/src/map/skill.c @@ -44,6 +44,7 @@ #include "map/path.h" #include "map/pc.h" #include "map/pet.h" +#include "map/refine.h" #include "map/script.h" #include "map/status.h" #include "map/unit.h" @@ -16204,7 +16205,7 @@ static void skill_weaponrefine(struct map_session_data *sd, int idx) return; } - per = status->get_refine_chance(ditem->wlv, (int)item->refine, REFINE_CHANCE_TYPE_NORMAL) * 10; + per = refine->get_refine_chance(ditem->wlv, (int)item->refine, REFINE_CHANCE_TYPE_NORMAL) * 10; // Aegis leaked formula. [malufett] if (sd->status.class == JOB_MECHANIC_T) diff --git a/src/map/status.c b/src/map/status.c index f06bb0330..085e951b6 100644 --- a/src/map/status.c +++ b/src/map/status.c @@ -38,6 +38,7 @@ #include "map/path.h" #include "map/pc.h" #include "map/pet.h" +#include "map/refine.h" #include "map/script.h" #include "map/skill.h" #include "map/skill.h" @@ -2577,18 +2578,18 @@ static int status_calc_pc_(struct map_session_data *sd, enum e_status_calc_opt o r = 0; if (r) - wa->atk2 = status->dbs->refine_info[wlv].bonus[r-1] / 100; + wa->atk2 = refine->dbs->refine_info[wlv].bonus[r-1] / 100; #ifdef RENEWAL wa->matk += sd->inventory_data[index]->matk; wa->wlv = wlv; if( r && sd->weapontype1 != W_BOW ) // renewal magic attack refine bonus - wa->matk += status->dbs->refine_info[wlv].bonus[r-1] / 100; + wa->matk += refine->dbs->refine_info[wlv].bonus[r-1] / 100; #endif //Overrefined bonus. if (r) - wd->overrefine = status->dbs->refine_info[wlv].randombonus_max[r-1] / 100; + wd->overrefine = refine->dbs->refine_info[wlv].randombonus_max[r-1] / 100; wa->range += sd->inventory_data[index]->range; if(sd->inventory_data[index]->script) { @@ -2623,7 +2624,7 @@ static int status_calc_pc_(struct map_session_data *sd, enum e_status_calc_opt o r = 0; if (r) - refinedef += status->dbs->refine_info[REFINE_TYPE_ARMOR].bonus[r-1]; + refinedef += refine->dbs->refine_info[REFINE_TYPE_ARMOR].bonus[r-1]; if(sd->inventory_data[index]->script) { if( i == EQI_HAND_L ) //Shield @@ -13076,25 +13077,6 @@ static int status_natural_heal_timer(int tid, int64 tick, int id, intptr_t data) return 0; } -/** - * Get the chance to upgrade a piece of equipment. - * @param wlv The weapon type of the item to refine (see see enum refine_type) - * @param refine The target refine level - * @return The chance to refine the item, in percent (0~100) - */ -static int status_get_refine_chance(enum refine_type wlv, int refine, enum refine_chance_type type) -{ - Assert_ret((int)wlv >= REFINE_TYPE_ARMOR && wlv < REFINE_TYPE_MAX); - - if (refine < 0 || refine >= MAX_REFINE) - return 0; - - if (type >= REFINE_CHANCE_TYPE_MAX) - return 0; - - return status->dbs->refine_info[wlv].chance[type][refine]; -} - static int status_get_sc_type(sc_type type) { @@ -13405,171 +13387,6 @@ static bool status_readdb_sizefix(char *fields[], int columns, int current) return true; } -/** - * Processes a refine_db.conf entry. - * - * @param r Libconfig setting entry. It is expected to be valid and it - * won't be freed (it is care of the caller to do so if - * necessary) - * @param n Ordinal number of the entry, to be displayed in case of - * validation errors. - * @param source Source of the entry (file name), to be displayed in case of - * validation errors. - * @return # of the validated entry, or 0 in case of failure. - */ -static int status_readdb_refine_libconfig_sub(struct config_setting_t *r, const char *name, const char *source) -{ - struct config_setting_t *rate = NULL; - int type = REFINE_TYPE_ARMOR, bonus_per_level = 0, rnd_bonus_v = 0, rnd_bonus_lv = 0; - char lv[4]; - nullpo_ret(r); - nullpo_ret(name); - nullpo_ret(source); - - if (strncmp(name, "Armors", 6) == 0) { - type = REFINE_TYPE_ARMOR; - } else if (strncmp(name, "WeaponLevel", 11) != 0 || !strspn(&name[strlen(name)-1], "0123456789") || (type = atoi(strncpy(lv, name+11, 2))) == REFINE_TYPE_ARMOR) { - ShowError("status_readdb_refine_libconfig_sub: Invalid key name for entry '%s' in \"%s\", skipping.\n", name, source); - return 0; - } - if (type < REFINE_TYPE_ARMOR || type >= REFINE_TYPE_MAX) { - ShowError("status_readdb_refine_libconfig_sub: Out of range level for entry '%s' in \"%s\", skipping.\n", name, source); - return 0; - } - if (!libconfig->setting_lookup_int(r, "StatsPerLevel", &bonus_per_level)) { - ShowWarning("status_readdb_refine_libconfig_sub: Missing StatsPerLevel for entry '%s' in \"%s\", skipping.\n", name, source); - return 0; - } - if (!libconfig->setting_lookup_int(r, "RandomBonusStartLevel", &rnd_bonus_lv)) { - ShowWarning("status_readdb_refine_libconfig_sub: Missing RandomBonusStartLevel for entry '%s' in \"%s\", skipping.\n", name, source); - return 0; - } - if (!libconfig->setting_lookup_int(r, "RandomBonusValue", &rnd_bonus_v)) { - ShowWarning("status_readdb_refine_libconfig_sub: Missing RandomBonusValue for entry '%s' in \"%s\", skipping.\n", name, source); - return 0; - } - - if ((rate=libconfig->setting_get_member(r, "Rates")) != NULL && config_setting_is_group(rate)) { - struct config_setting_t *t = NULL; - bool duplicate[MAX_REFINE]; - int bonus[MAX_REFINE], rnd_bonus[MAX_REFINE]; - int chance[REFINE_CHANCE_TYPE_MAX][MAX_REFINE]; - int i, j; - - memset(&duplicate, 0, sizeof(duplicate)); - memset(&bonus, 0, sizeof(bonus)); - memset(&rnd_bonus, 0, sizeof(rnd_bonus)); - - for (i = 0; i < REFINE_CHANCE_TYPE_MAX; i++) - for (j = 0; j < MAX_REFINE; j++) - chance[i][j] = 100; // default value for all rates. - - i = 0; - j = 0; - while ((t = libconfig->setting_get_elem(rate,i++)) != NULL && config_setting_is_group(t)) { - int level = 0, i32; - char *rlvl = config_setting_name(t); - memset(&lv, 0, sizeof(lv)); - - if (!strspn(&rlvl[strlen(rlvl) - 1], "0123456789") || (level = atoi(strncpy(lv, rlvl + 2, 3))) <= 0) { - ShowError("status_readdb_refine_libconfig_sub: Invalid refine level format '%s' for entry %s in \"%s\"... skipping.\n", rlvl, name, source); - continue; - } - - if (level <= 0 || level > MAX_REFINE) { - ShowError("status_readdb_refine_libconfig_sub: Out of range refine level '%s' for entry %s in \"%s\"... skipping.\n", rlvl, name, source); - continue; - } - - level--; - - if (duplicate[level]) { - ShowWarning("status_readdb_refine_libconfig_sub: duplicate rate '%s' for entry %s in \"%s\", overwriting previous entry...\n", rlvl, name, source); - } else { - duplicate[level] = true; - } - - if (libconfig->setting_lookup_int(t, "NormalChance", &i32) != 0) - chance[REFINE_CHANCE_TYPE_NORMAL][level] = i32; - else - chance[REFINE_CHANCE_TYPE_NORMAL][level] = 100; - - if (libconfig->setting_lookup_int(t, "EnrichedChance", &i32) != 0) - chance[REFINE_CHANCE_TYPE_ENRICHED][level] = i32; - else - chance[REFINE_CHANCE_TYPE_ENRICHED][level] = level > 10 ? 0 : 100; // enriched ores up to +10 only. - - if (libconfig->setting_lookup_int(t, "EventNormalChance", &i32) != 0) - chance[REFINE_CHANCE_TYPE_E_NORMAL][level] = i32; - else - chance[REFINE_CHANCE_TYPE_E_NORMAL][level] = 100; - - if (libconfig->setting_lookup_int(t, "EventEnrichedChance", &i32) != 0) - chance[REFINE_CHANCE_TYPE_E_ENRICHED][level] = i32; - else - chance[REFINE_CHANCE_TYPE_E_ENRICHED][level] = level > 10 ? 0 : 100; // enriched ores up to +10 only. - - if (libconfig->setting_lookup_int(t, "Bonus", &i32) != 0) - bonus[level] += i32; - - if (level >= rnd_bonus_lv - 1) - rnd_bonus[level] = rnd_bonus_v * (level - rnd_bonus_lv + 2); - } - for (i = 0; i < MAX_REFINE; i++) { - status->dbs->refine_info[type].chance[REFINE_CHANCE_TYPE_NORMAL][i] = chance[REFINE_CHANCE_TYPE_NORMAL][i]; - status->dbs->refine_info[type].chance[REFINE_CHANCE_TYPE_E_NORMAL][i] = chance[REFINE_CHANCE_TYPE_E_NORMAL][i]; - status->dbs->refine_info[type].chance[REFINE_CHANCE_TYPE_ENRICHED][i] = chance[REFINE_CHANCE_TYPE_ENRICHED][i]; - status->dbs->refine_info[type].chance[REFINE_CHANCE_TYPE_E_ENRICHED][i] = chance[REFINE_CHANCE_TYPE_E_ENRICHED][i]; - status->dbs->refine_info[type].randombonus_max[i] = rnd_bonus[i]; - bonus[i] += bonus_per_level + (i > 0 ? bonus[i - 1] : 0); - status->dbs->refine_info[type].bonus[i] = bonus[i]; - } - } else { - ShowWarning("status_readdb_refine_libconfig_sub: Missing refine rates for entry '%s' in \"%s\", skipping.\n", name, source); - return 0; - } - - return type + 1; -} - -/** - * Reads from a libconfig-formatted refine_db.conf file. - * - * @param *filename File name, relative to the database path. - * @return The number of found entries. - */ -static int status_readdb_refine_libconfig(const char *filename) -{ - bool duplicate[REFINE_TYPE_MAX]; - struct config_t refine_db_conf; - struct config_setting_t *r; - char filepath[256]; - int i = 0, count = 0; - - safesnprintf(filepath, sizeof(filepath), "%s/%s", map->db_path, filename); - if (!libconfig->load_file(&refine_db_conf, filepath)) - return 0; - - memset(&duplicate,0,sizeof(duplicate)); - - while((r = libconfig->setting_get_elem(refine_db_conf.root,i++))) { - char *name = config_setting_name(r); - int type = status->readdb_refine_libconfig_sub(r, name, filename); - if (type != 0) { - if (duplicate[type-1]) { - ShowWarning("status_readdb_refine_libconfig: duplicate entry for %s in \"%s\", overwriting previous entry...\n", name, filename); - } else { - duplicate[type-1] = true; - } - count++; - } - } - libconfig->destroy(&refine_db_conf); - ShowStatus("Done reading '"CL_WHITE"%d"CL_RESET"' entries in '"CL_WHITE"%s"CL_RESET"'.\n", count, filename); - - return count; -} - static bool status_readdb_scconfig(char *fields[], int columns, int current) { int val = 0; @@ -13627,7 +13444,6 @@ static int status_readdb(void) // sv->readdb(map->db_path, "job_db2.txt", ',', 1, 1+MAX_LEVEL, -1, status->readdb_job2); sv->readdb(map->db_path, DBPATH"size_fix.txt", ',', MAX_SINGLE_WEAPON_TYPE, MAX_SINGLE_WEAPON_TYPE, ARRAYLENGTH(status->dbs->atkmods), status->readdb_sizefix); - status->readdb_refine_libconfig(DBPATH"refine_db.conf"); sv->readdb(map->db_path, "sc_config.txt", ',', 2, 2, SC_MAX, status->readdb_scconfig); status->read_job_db(); @@ -13685,7 +13501,6 @@ void status_defaults(void) status->natural_heal_prev_tick = 0; status->natural_heal_diff_tick = 0; /* funcs */ - status->get_refine_chance = status_get_refine_chance; // for looking up associated data status->skill2sc = status_skill2sc; status->sc2skill = status_sc2skill; @@ -13819,8 +13634,6 @@ void status_defaults(void) status->natural_heal_timer = status_natural_heal_timer; status->readdb_job2 = status_readdb_job2; status->readdb_sizefix = status_readdb_sizefix; - status->readdb_refine_libconfig = status_readdb_refine_libconfig; - status->readdb_refine_libconfig_sub = status_readdb_refine_libconfig_sub; status->readdb_scconfig = status_readdb_scconfig; status->read_job_db = status_read_job_db; status->read_job_db_sub = status_read_job_db_sub; diff --git a/src/map/status.h b/src/map/status.h index 17af22703..79aaca95f 100644 --- a/src/map/status.h +++ b/src/map/status.h @@ -49,27 +49,6 @@ struct pet_data; ) /** - * Max Refine available to your server - * Changing this limit requires edits to refine_db.txt - **/ -#ifdef RENEWAL - #define MAX_REFINE 20 -#else - #define MAX_REFINE 10 -#endif - -enum refine_type { - REFINE_TYPE_ARMOR = 0, - REFINE_TYPE_WEAPON1 = 1, - REFINE_TYPE_WEAPON2 = 2, - REFINE_TYPE_WEAPON3 = 3, - REFINE_TYPE_WEAPON4 = 4, -#ifndef REFINE_TYPE_MAX - REFINE_TYPE_MAX = 5 -#endif -}; - -/** * SC configuration type * @see db/sc_config.txt for more information **/ @@ -2249,21 +2228,6 @@ struct status_change { #define status_calc_elemental(ed, opt) (status->calc_bl_(&(ed)->bl, SCB_ALL, (opt))) #define status_calc_npc(nd, opt) (status->calc_bl_(&(nd)->bl, SCB_ALL, (opt))) -enum refine_chance_type { - REFINE_CHANCE_TYPE_NORMAL = 0, // Normal Chance - REFINE_CHANCE_TYPE_ENRICHED = 1, // Enriched Ore Chance - REFINE_CHANCE_TYPE_E_NORMAL = 2, // Event Normal Ore Chance - REFINE_CHANCE_TYPE_E_ENRICHED = 3, // Event Enriched Ore Chance - REFINE_CHANCE_TYPE_MAX -}; - -// bonus values and upgrade chances for refining equipment -struct s_refine_info { - int chance[REFINE_CHANCE_TYPE_MAX][MAX_REFINE]; // success chance - int bonus[MAX_REFINE]; // cumulative fixed bonus damage - int randombonus_max[MAX_REFINE]; // cumulative maximum random bonus damage -}; - struct s_status_dbs { BEGIN_ZEROED_BLOCK; /* Everything within this block will be memset to 0 when status_defaults() is executed */ int max_weight_base[CLASS_COUNT]; @@ -2277,8 +2241,6 @@ BEGIN_ZEROED_BLOCK; /* Everything within this block will be memset to 0 when sta int RelevantBLTypes[SI_MAX]; // "icon" -> enum bl_type (for clif->status_change to identify for which bl types to send packets) bool DisplayType[SC_MAX]; /* */ - struct s_refine_info refine_info[REFINE_TYPE_MAX]; - /* */ int atkmods[3][MAX_SINGLE_WEAPON_TYPE];//ATK weapon modification for size (size_fix.txt) char job_bonus[CLASS_COUNT][MAX_LEVEL]; sc_conf_type sc_conf[SC_MAX]; @@ -2307,7 +2269,6 @@ struct status_interface { int (*init) (bool minimal); void (*final) (void); /* funcs */ - int (*get_refine_chance) (enum refine_type wlv, int refine, enum refine_chance_type type); // for looking up associated data sc_type (*skill2sc) (int skill_id); int (*sc2skill) (sc_type sc); @@ -2427,8 +2388,6 @@ struct status_interface { int (*natural_heal_timer) (int tid, int64 tick, int id, intptr_t data); bool (*readdb_job2) (char *fields[], int columns, int current); bool (*readdb_sizefix) (char *fields[], int columns, int current); - int (*readdb_refine_libconfig) (const char *filename); - int (*readdb_refine_libconfig_sub) (struct config_setting_t *r, const char *name, const char *source); bool (*readdb_scconfig) (char *fields[], int columns, int current); void (*read_job_db) (void); void (*read_job_db_sub) (int idx, const char *name, struct config_setting_t *jdb); diff --git a/vcproj-12/map-server.vcxproj b/vcproj-12/map-server.vcxproj index 72bae9d97..34f55be49 100644 --- a/vcproj-12/map-server.vcxproj +++ b/vcproj-12/map-server.vcxproj @@ -213,6 +213,8 @@ <ClInclude Include="..\src\config\renewal.h" /> <ClInclude Include="..\src\config\secure.h" /> <ClInclude Include="..\src\config\classes\general.h" /> + <ClInclude Include="..\src\map\refine.h" /> + <ClInclude Include="..\src\map\refine.p.h" /> <ClInclude Include="..\src\map\rodex.h" /> <ClInclude Include="..\src\map\script.h" /> <ClInclude Include="..\src\map\searchstore.h" /> @@ -288,6 +290,7 @@ <ClCompile Include="..\src\map\pc_groups.c" /> <ClCompile Include="..\src\map\pet.c" /> <ClCompile Include="..\src\map\quest.c" /> + <ClCompile Include="..\src\map\refine.c" /> <ClCompile Include="..\src\map\rodex.c" /> <ClCompile Include="..\src\map\script.c" /> <ClCompile Include="..\src\map\searchstore.c" /> diff --git a/vcproj-12/map-server.vcxproj.filters b/vcproj-12/map-server.vcxproj.filters index 6734c65bf..aae670525 100644 --- a/vcproj-12/map-server.vcxproj.filters +++ b/vcproj-12/map-server.vcxproj.filters @@ -220,6 +220,9 @@ <ClCompile Include="..\src\map\rodex.c"> <Filter>map</Filter> </ClCompile> + <ClCompile Include="..\src\map\refine.c"> + <Filter>map</Filter> + </ClCompile> </ItemGroup> <ItemGroup> <ClInclude Include="..\src\map\achievement.h"> @@ -501,6 +504,12 @@ <ClInclude Include="..\src\map\rodex.h"> <Filter>map</Filter> </ClInclude> + <ClInclude Include="..\src\map\refine.p.h"> + <Filter>map</Filter> + </ClInclude> + <ClInclude Include="..\src\map\refine.h"> + <Filter>map</Filter> + </ClInclude> </ItemGroup> <ItemGroup> <Filter Include="common"> diff --git a/vcproj-14/map-server.vcxproj b/vcproj-14/map-server.vcxproj index b17990588..ed91f231d 100644 --- a/vcproj-14/map-server.vcxproj +++ b/vcproj-14/map-server.vcxproj @@ -211,6 +211,8 @@ <ClInclude Include="..\src\config\renewal.h" /> <ClInclude Include="..\src\config\secure.h" /> <ClInclude Include="..\src\config\classes\general.h" /> + <ClInclude Include="..\src\map\refine.h" /> + <ClInclude Include="..\src\map\refine.p.h" /> <ClInclude Include="..\src\map\rodex.h" /> <ClInclude Include="..\src\map\script.h" /> <ClInclude Include="..\src\map\searchstore.h" /> @@ -286,6 +288,7 @@ <ClCompile Include="..\src\map\pc_groups.c" /> <ClCompile Include="..\src\map\pet.c" /> <ClCompile Include="..\src\map\quest.c" /> + <ClCompile Include="..\src\map\refine.c" /> <ClCompile Include="..\src\map\rodex.c" /> <ClCompile Include="..\src\map\script.c" /> <ClCompile Include="..\src\map\searchstore.c" /> diff --git a/vcproj-14/map-server.vcxproj.filters b/vcproj-14/map-server.vcxproj.filters index c8e64d8fd..3f1b6ca4b 100644 --- a/vcproj-14/map-server.vcxproj.filters +++ b/vcproj-14/map-server.vcxproj.filters @@ -220,6 +220,9 @@ <ClCompile Include="..\src\map\clan.c"> <Filter>map</Filter> </ClCompile> + <ClCompile Include="..\src\map\refine.c"> + <Filter>map</Filter> + </ClCompile> </ItemGroup> <ItemGroup> <ClInclude Include="..\src\map\achievement.h"> @@ -501,6 +504,12 @@ <ClInclude Include="..\src\map\clan.h"> <Filter>map</Filter> </ClInclude> + <ClInclude Include="..\src\map\refine.h"> + <Filter>map</Filter> + </ClInclude> + <ClInclude Include="..\src\map\refine.p.h"> + <Filter>map</Filter> + </ClInclude> </ItemGroup> <ItemGroup> <Filter Include="common"> diff --git a/vcproj-15/map-server.vcxproj b/vcproj-15/map-server.vcxproj index c7a83fa39..8becb90cc 100644 --- a/vcproj-15/map-server.vcxproj +++ b/vcproj-15/map-server.vcxproj @@ -212,6 +212,8 @@ <ClInclude Include="..\src\config\renewal.h" /> <ClInclude Include="..\src\config\secure.h" /> <ClInclude Include="..\src\config\classes\general.h" /> + <ClInclude Include="..\src\map\refine.h" /> + <ClInclude Include="..\src\map\refine.p.h" /> <ClInclude Include="..\src\map\rodex.h" /> <ClInclude Include="..\src\map\script.h" /> <ClInclude Include="..\src\map\searchstore.h" /> @@ -287,6 +289,7 @@ <ClCompile Include="..\src\map\pc_groups.c" /> <ClCompile Include="..\src\map\pet.c" /> <ClCompile Include="..\src\map\quest.c" /> + <ClCompile Include="..\src\map\refine.c" /> <ClCompile Include="..\src\map\rodex.c" /> <ClCompile Include="..\src\map\script.c" /> <ClCompile Include="..\src\map\searchstore.c" /> diff --git a/vcproj-15/map-server.vcxproj.filters b/vcproj-15/map-server.vcxproj.filters index 2a3d1b489..087a700e9 100644 --- a/vcproj-15/map-server.vcxproj.filters +++ b/vcproj-15/map-server.vcxproj.filters @@ -2,7 +2,7 @@ <Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003"> <ItemGroup> <ClCompile Include="..\src\map\achievement.c"> - <Filter>map</Filter> + <Filter>map</Filter> </ClCompile> <ClCompile Include="..\src\map\atcommand.c"> <Filter>map</Filter> @@ -220,6 +220,9 @@ <ClCompile Include="..\src\map\rodex.c"> <Filter>map</Filter> </ClCompile> + <ClCompile Include="..\src\map\refine.c"> + <Filter>map</Filter> + </ClCompile> </ItemGroup> <ItemGroup> <ClInclude Include="..\src\map\achievement.h"> @@ -501,6 +504,12 @@ <ClInclude Include="..\src\map\rodex.h"> <Filter>map</Filter> </ClInclude> + <ClInclude Include="..\src\map\refine.p.h"> + <Filter>map</Filter> + </ClInclude> + <ClInclude Include="..\src\map\refine.h"> + <Filter>map</Filter> + </ClInclude> </ItemGroup> <ItemGroup> <Filter Include="common"> |