Permalink
Browse files

Cleanup skill_damage mapflag for skill (#3583)

* Changed from vector to unordered_map with skill_id as key
  • Loading branch information...
cydh committed Oct 19, 2018
1 parent ab0046c commit d8e760fa784258c95c72c460a6cff204a1cc7557
Showing with 30 additions and 49 deletions.
  1. +16 −20 src/map/atcommand.cpp
  2. +3 −6 src/map/battle.cpp
  3. +10 −21 src/map/map.cpp
  4. +1 −2 src/map/map.hpp
View
@@ -4042,29 +4042,25 @@ ACMD_FUNC(mapinfo) {
}
/* Skill damage adjustment info [Cydh] */
union u_mapflag_args args = {};
args.flag_val = SKILLDMG_MAX; // Check if it's enabled first
if (map_getmapflag_sub(m_id, MF_SKILL_DAMAGE, &args)) {
if (mapdata->flag[MF_SKILL_DAMAGE]) {
clif_displaymessage(fd,msg_txt(sd,1052)); // Skill Damage Adjustments:
sprintf(atcmd_output," > [Map] %d%%, %d%%, %d%%, %d%% | Caster:%d"
,(args.flag_val = SKILLDMG_PC && map_getmapflag_sub(m_id, MF_SKILL_DAMAGE, &args))
,(args.flag_val = SKILLDMG_MOB && map_getmapflag_sub(m_id, MF_SKILL_DAMAGE, &args))
,(args.flag_val = SKILLDMG_BOSS && map_getmapflag_sub(m_id, MF_SKILL_DAMAGE, &args))
,(args.flag_val = SKILLDMG_OTHER && map_getmapflag_sub(m_id, MF_SKILL_DAMAGE, &args))
,(args.flag_val = SKILLDMG_CASTER && map_getmapflag_sub(m_id, MF_SKILL_DAMAGE, &args)));
sprintf(atcmd_output," > [Map] %d%%, %d%%, %d%%, %d%% | Caster:%d",
mapdata->damage_adjust.rate[SKILLDMG_PC],
mapdata->damage_adjust.rate[SKILLDMG_MOB],
mapdata->damage_adjust.rate[SKILLDMG_BOSS],
mapdata->damage_adjust.rate[SKILLDMG_OTHER],
mapdata->damage_adjust.caster);
clif_displaymessage(fd, atcmd_output);
if (mapdata->skill_damage.size()) {
if (!mapdata->skill_damage.empty()) {
clif_displaymessage(fd," > [Map Skill] Name : Player, Monster, Boss Monster, Other | Caster");
for (int j = 0; j < mapdata->skill_damage.size(); j++) {
sprintf(atcmd_output," %d. %s : %d%%, %d%%, %d%%, %d%% | %d"
,j+1
,skill_get_name(mapdata->skill_damage[j].skill_id)
,mapdata->skill_damage[j].rate[SKILLDMG_PC]
,mapdata->skill_damage[j].rate[SKILLDMG_MOB]
,mapdata->skill_damage[j].rate[SKILLDMG_BOSS]
,mapdata->skill_damage[j].rate[SKILLDMG_OTHER]
,mapdata->skill_damage[j].caster);
for (auto skilldmg : mapdata->skill_damage) {
sprintf(atcmd_output," %s : %d%%, %d%%, %d%%, %d%% | %d",
skill_get_name(skilldmg.first),
skilldmg.second.rate[SKILLDMG_PC],
skilldmg.second.rate[SKILLDMG_MOB],
skilldmg.second.rate[SKILLDMG_BOSS],
skilldmg.second.rate[SKILLDMG_OTHER],
skilldmg.second.caster);
clif_displaymessage(fd,atcmd_output);
}
}
View
@@ -2226,10 +2226,8 @@ static int battle_skill_damage_skill(struct block_list *src, struct block_list *
static int battle_skill_damage_map(struct block_list *src, struct block_list *target, uint16 skill_id) {
int rate = 0;
struct map_data *mapdata = map_getmapdata(src->m);
union u_mapflag_args args = {};
args.flag_val = SKILLDMG_MAX; // Check if it's enabled first
if (!mapdata || !map_getmapflag_sub(src->m, MF_SKILL_DAMAGE, &args))
if (!mapdata || !mapdata->flag[MF_SKILL_DAMAGE])
return 0;
// Damage rate for all skills at this map
@@ -2240,9 +2238,8 @@ static int battle_skill_damage_map(struct block_list *src, struct block_list *ta
return rate;
// Damage rate for specified skill at this map
for (int i = 0; i < mapdata->skill_damage.size(); i++) {
if (mapdata->skill_damage[i].skill_id == skill_id && mapdata->skill_damage[i].caster&src->type)
rate += mapdata->skill_damage[i].rate[battle_skill_damage_type(target)];
if (mapdata->skill_damage.find(skill_id) != mapdata->skill_damage.end() && mapdata->skill_damage[skill_id].caster&src->type) {
rate += mapdata->skill_damage[skill_id].rate[battle_skill_damage_type(target)];
}
return rate;
}
View
@@ -3593,7 +3593,7 @@ void map_data_copy(struct map_data *dst_map, struct map_data *src_map) {
memcpy(&dst_map->damage_adjust, &src_map->damage_adjust, sizeof(struct s_skill_damage));
dst_map->flag.insert(src_map->flag.begin(), src_map->flag.end());
dst_map->skill_damage.insert(dst_map->skill_damage.begin(), src_map->skill_damage.begin(), src_map->skill_damage.end());
dst_map->skill_damage.insert(src_map->skill_damage.begin(), src_map->skill_damage.end());
dst_map->zone = src_map->zone;
dst_map->qi_count = 0;
@@ -4443,26 +4443,18 @@ int cleanup_sub(struct block_list *bl, va_list ap)
* @param caster: Caster type
*/
void map_skill_damage_add(struct map_data *m, uint16 skill_id, int rate[SKILLDMG_MAX], uint16 caster) {
if (m->skill_damage.size() > UINT16_MAX)
return;
for (int i = 0; i < m->skill_damage.size(); i++) {
if (m->skill_damage[i].skill_id == skill_id) {
for (int j = 0; j < SKILLDMG_MAX; j++) {
m->skill_damage[i].rate[j] = rate[j];
}
m->skill_damage[i].caster = caster;
return;
}
}
struct s_skill_damage entry = {};
entry.skill_id = skill_id;
for (int i = 0; i < SKILLDMG_MAX; i++)
entry.rate[i] = rate[i];
entry.caster = caster;
m->skill_damage.push_back(entry);
if (m->skill_damage.find(skill_id) != m->skill_damage.end()) {
m->skill_damage[skill_id] = entry;
return;
}
m->skill_damage.insert({ skill_id, entry });
}
/**
@@ -4834,12 +4826,9 @@ bool map_setmapflag_sub(int16 m, enum e_mapflag mapflag, bool status, union u_ma
return false;
}
for (int i = 0; i < SKILLDMG_MAX; i++) {
mapdata->damage_adjust.caster = args->skill_damage.caster;
for (int i = 0; i < SKILLDMG_MAX; i++)
mapdata->damage_adjust.rate[i] = cap_value(args->skill_damage.rate[i], -100, 100000);
if (mapdata->flag.find(mapflag) != mapdata->flag.end() && mapdata->damage_adjust.rate[i])
mapdata->damage_adjust.caster = args->skill_damage.caster;
}
}
}
mapdata->flag[mapflag] = status;
View
@@ -594,7 +594,6 @@ enum e_skill_damage_type : uint8 {
/// Struct for MF_SKILL_DAMAGE
struct s_skill_damage {
unsigned int map; ///< Maps (used for skill_damage_db.txt)
uint16 skill_id; ///< Skill ID (used for mapflag)
uint16 caster; ///< Caster type
int rate[SKILLDMG_MAX]; ///< Used for when all skills are adjusted
};
@@ -729,7 +728,7 @@ struct map_data {
std::vector<s_drop_list> drop_list;
uint32 zone; // zone number (for item/skill restrictions)
struct s_skill_damage damage_adjust; // Used for overall skill damage adjustment
std::vector<s_skill_damage> skill_damage; // Used for single skill damage adjustment
std::unordered_map<uint16, s_skill_damage> skill_damage; // Used for single skill damage adjustment
struct npc_data *npc[MAX_NPC_PER_MAP];
struct spawn_data *moblist[MAX_MOB_LIST_PER_MAP]; // [Wizputer]

0 comments on commit d8e760f

Please sign in to comment.