Skip to content

Commit

Permalink
Merge pull request #3237 from guilherme-gm/autospell-refactor
Browse files Browse the repository at this point in the history
Refactor Auto Spell and move its config to libconfig
  • Loading branch information
MishimaHaruna authored Oct 19, 2023
2 parents 5266c62 + 17d3acd commit 811d1fd
Show file tree
Hide file tree
Showing 11 changed files with 909 additions and 125 deletions.
135 changes: 135 additions & 0 deletions db/pre-re/autospell_db.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,135 @@
//================= Hercules Database =====================================
//= _ _ _
//= | | | | | |
//= | |_| | ___ _ __ ___ _ _| | ___ ___
//= | _ |/ _ \ '__/ __| | | | |/ _ \/ __|
//= | | | | __/ | | (__| |_| | | __/\__ \
//= \_| |_/\___|_| \___|\__,_|_|\___||___/
//================= License ===============================================
//= This file is part of Hercules.
//= http://herc.ws - http://github.com/HerculesWS/Hercules
//=
//= Copyright (C) 2023 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/>.
//=========================================================================
//= AutoSpell skills configuration
//=
//= This file lists the skills available for Sage AutoSpell (Hindsight) skill.
//=
//= Notes:
//= - The maximum number of entries is controlled by MAX_AUTOSPELL_DB (src/map/skill.h)
//= - Additionally, some official clients have a hard limit on the number of skills
//= (this is limited by packet size and can't be changed)
//= - SkillLevel and SpiritBoost configures the basic behavior of the skills, the requirement
//= for the player to have learned the skill at this level is applied on source
//=========================================================================

autospell_db: (
/**************************************************************************
************* Entry structure ********************************************
**************************************************************************
{
SkillId: Skill ID/Name (constant string or int)
SkillLevel: Highest usable level (int, defaults to 0) (can be grouped by AutoSpell Levels)
(Level 0 would mean not usable in this AutoSpell level)
SpiritBoost: Use max level when under Sage Spirit? (boolean, defaults to false)
},
**************************************************************************/

{
SkillId: "MG_NAPALMBEAT"
SkillLevel: 3
SpiritBoost: false
},
{
SkillId: "MG_COLDBOLT"
SkillLevel: {
// Lv1: 0
Lv2: 1
Lv3: 2
Lv4: 3
Lv5: 3
Lv6: 3
Lv7: 3
Lv8: 3
Lv9: 3
Lv10: 3
}
SpiritBoost: true
},
{
SkillId: "MG_FIREBOLT"
SkillLevel: {
// Lv1: 0
Lv2: 1
Lv3: 2
Lv4: 3
Lv5: 3
Lv6: 3
Lv7: 3
Lv8: 3
Lv9: 3
Lv10: 3
}
SpiritBoost: true
},
{
SkillId: "MG_LIGHTNINGBOLT"
SkillLevel: {
// Lv1: 0
Lv2: 1
Lv3: 2
Lv4: 3
Lv5: 3
Lv6: 3
Lv7: 3
Lv8: 3
Lv9: 3
Lv10: 3
}
SpiritBoost: true
},
{
SkillId: "MG_SOULSTRIKE"
SkillLevel: {
// Lv1 .. Lv4: 0
Lv5: 1
Lv6: 2
Lv7: 3
Lv8: 3
Lv9: 3
Lv10: 3
}
SpiritBoost: false
},
{
SkillId: "MG_FIREBALL"
SkillLevel: {
// Lv1 .. Lv7: 0
Lv8: 1
Lv9: 2
Lv10: 2
}
SpiritBoost: false
},
{
SkillId: "MG_FROSTDIVER"
SkillLevel: {
// Lv1 .. Lv9: 0
Lv10: 1
}
SpiritBoost: false
},
)
135 changes: 135 additions & 0 deletions db/re/autospell_db.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,135 @@
//================= Hercules Database =====================================
//= _ _ _
//= | | | | | |
//= | |_| | ___ _ __ ___ _ _| | ___ ___
//= | _ |/ _ \ '__/ __| | | | |/ _ \/ __|
//= | | | | __/ | | (__| |_| | | __/\__ \
//= \_| |_/\___|_| \___|\__,_|_|\___||___/
//================= License ===============================================
//= This file is part of Hercules.
//= http://herc.ws - http://github.com/HerculesWS/Hercules
//=
//= Copyright (C) 2023 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/>.
//=========================================================================
//= AutoSpell skills configuration
//=
//= This file lists the skills available for Sage AutoSpell (Hindsight) skill.
//=
//= Notes:
//= - The maximum number of entries is controlled by MAX_AUTOSPELL_DB (src/map/skill.h)
//= - Additionally, some official clients have a hard limit on the number of skills
//= (this is limited by packet size and can't be changed)
//= - SkillLevel and SpiritBoost configures the basic behavior of the skills, the requirement
//= for the player to have learned the skill at this level is applied on source
//=========================================================================

autospell_db: (
/**************************************************************************
************* Entry structure ********************************************
**************************************************************************
{
SkillId: Skill ID/Name (constant string or int)
SkillLevel: Highest usable level (int, defaults to 0) (can be grouped by AutoSpell Levels)
(Level 0 would mean not usable in this AutoSpell level)
SpiritBoost: Use max level when under Sage Spirit? (boolean, defaults to false)
},
**************************************************************************/

{
SkillId: "MG_NAPALMBEAT"
SkillLevel: 3
SpiritBoost: false
},
{
SkillId: "MG_COLDBOLT"
SkillLevel: {
// Lv1: 0
Lv2: 1
Lv3: 2
Lv4: 3
Lv5: 3
Lv6: 3
Lv7: 3
Lv8: 3
Lv9: 3
Lv10: 3
}
SpiritBoost: true
},
{
SkillId: "MG_FIREBOLT"
SkillLevel: {
// Lv1: 0
Lv2: 1
Lv3: 2
Lv4: 3
Lv5: 3
Lv6: 3
Lv7: 3
Lv8: 3
Lv9: 3
Lv10: 3
}
SpiritBoost: true
},
{
SkillId: "MG_LIGHTNINGBOLT"
SkillLevel: {
// Lv1: 0
Lv2: 1
Lv3: 2
Lv4: 3
Lv5: 3
Lv6: 3
Lv7: 3
Lv8: 3
Lv9: 3
Lv10: 3
}
SpiritBoost: true
},
{
SkillId: "MG_SOULSTRIKE"
SkillLevel: {
// Lv1 .. Lv4: 0
Lv5: 1
Lv6: 2
Lv7: 3
Lv8: 3
Lv9: 3
Lv10: 3
}
SpiritBoost: false
},
{
SkillId: "MG_FIREBALL"
SkillLevel: {
// Lv1 .. Lv7: 0
Lv8: 1
Lv9: 2
Lv10: 2
}
SpiritBoost: false
},
{
SkillId: "MG_FROSTDIVER"
SkillLevel: {
// Lv1 .. Lv9: 0
Lv10: 1
}
SpiritBoost: false
},
)
1 change: 1 addition & 0 deletions src/common/HPMDataCheck.h
Original file line number Diff line number Diff line change
Expand Up @@ -1185,6 +1185,7 @@ HPExport const struct s_HPMDataCheck HPMDataCheck[] = {
#define MAP_SEARCHSTORE_H
#endif // MAP_SEARCHSTORE_H
#ifdef MAP_SKILL_H
{ "s_autospell_db", sizeof(struct s_autospell_db), SERVER_TYPE_MAP },
{ "s_skill_abra_db", sizeof(struct s_skill_abra_db), SERVER_TYPE_MAP },
{ "s_skill_arrow_db", sizeof(struct s_skill_arrow_db), SERVER_TYPE_MAP },
{ "s_skill_changematerial_db", sizeof(struct s_skill_changematerial_db), SERVER_TYPE_MAP },
Expand Down
53 changes: 25 additions & 28 deletions src/map/clif.c
Original file line number Diff line number Diff line change
Expand Up @@ -8007,46 +8007,43 @@ static void clif_pet_food(struct map_session_data *sd, int foodid, int fail)
WFIFOSET(fd, sizeof(struct PACKET_ZC_FEED_PET));
}

/// Presents a list of skills that can be auto-spelled (ZC_AUTOSPELLLIST).
/// 01cd { <skill id>.L }*7
static void clif_autospell(struct map_session_data *sd, uint16 skill_lv)
/**
* Presents a list of skills that can be auto-spelled (ZC_AUTOSPELLLIST).
*
* 01cd { <skill id>.L }*7
* 0afb <packet len>.W { <skills>.L }*
*
* @param sd player who will receive the list
* @param skill_lv autospell skill level
* @param skill_ids_list list of available skills to choose from
* @param list_len length of skill_ids_list
*/
static void clif_autospell(struct map_session_data *sd, uint16 skill_lv, int *skill_ids_list, int list_len)
{
#if PACKETVER_MAIN_NUM >= 20090406 || defined(PACKETVER_RE) || defined(PACKETVER_ZERO) || PACKETVER_SAK_NUM >= 20080618
nullpo_retv(sd);

int fd = sd->fd;
#if PACKETVER_MAIN_NUM >= 20181128 || PACKETVER_RE_NUM >= 20181031
// reserve space for 7 skills
WFIFOHEAD(fd, sizeof(struct PACKET_ZC_AUTOSPELLLIST) + 4 * 7);
const int len = sizeof(struct PACKET_ZC_AUTOSPELLLIST) + sizeof(int) * list_len;
#else
WFIFOHEAD(fd, sizeof(struct PACKET_ZC_AUTOSPELLLIST));
const int len = sizeof(struct PACKET_ZC_AUTOSPELLLIST);
if (list_len > 7) {
ShowError("%s: AutoSpell list too big for current client. Limit: %d, received: %d. Truncating list...\n", __func__, 7, list_len);
list_len = 7;
}
#endif

int fd = sd->fd;
WFIFOHEAD(fd, len);

struct PACKET_ZC_AUTOSPELLLIST *p = WFIFOP(fd, 0);
memset(p, 0, sizeof(struct PACKET_ZC_AUTOSPELLLIST));
p->packetType = HEADER_ZC_AUTOSPELLLIST;
int index = 0;

if (skill_lv > 0 && pc->checkskill(sd, MG_NAPALMBEAT) > 0)
p->skills[index++] = MG_NAPALMBEAT;
if (skill_lv > 1 && pc->checkskill(sd, MG_COLDBOLT) > 0)
p->skills[index++] = MG_COLDBOLT;
if (skill_lv > 1 && pc->checkskill(sd, MG_FIREBOLT) > 0)
p->skills[index++] = MG_FIREBOLT;
if (skill_lv > 1 && pc->checkskill(sd, MG_LIGHTNINGBOLT) > 0)
p->skills[index++] = MG_LIGHTNINGBOLT;
if (skill_lv > 4 && pc->checkskill(sd, MG_SOULSTRIKE) > 0)
p->skills[index++] = MG_SOULSTRIKE;
if (skill_lv > 7 && pc->checkskill(sd, MG_FIREBALL) > 0)
p->skills[index++] = MG_FIREBALL;
if (skill_lv > 9 && pc->checkskill(sd, MG_FROSTDIVER) > 0)
p->skills[index++] = MG_FROSTDIVER;

p->packetType = HEADER_ZC_AUTOSPELLLIST;
#if PACKETVER_MAIN_NUM >= 20181128 || PACKETVER_RE_NUM >= 20181031
const int len = sizeof(struct PACKET_ZC_AUTOSPELLLIST) + index * 4;
p->packetLength = len;
#else
const int len = sizeof(struct PACKET_ZC_AUTOSPELLLIST);
#endif
memcpy(p->skills, skill_ids_list, sizeof(int) * list_len);
WFIFOSET(fd, len);

sd->menuskill_id = SA_AUTOSPELL;
Expand Down Expand Up @@ -14199,7 +14196,7 @@ static void clif_parse_AutoSpell(int fd, struct map_session_data *sd)
if( !skill_id )
return;

skill->autospell(sd, skill_id);
skill->autospell_spell_selected(sd, skill_id);
clif_menuskill_clear(sd);
}

Expand Down
2 changes: 1 addition & 1 deletion src/map/clif.h
Original file line number Diff line number Diff line change
Expand Up @@ -1091,7 +1091,7 @@ struct clif_interface {
void (*skill_mapinfomessage) (struct map_session_data *sd, int type);
void (*skill_produce_mix_list) (struct map_session_data *sd, int skill_id, int trigger);
void (*cooking_list) (struct map_session_data *sd, int trigger, uint16 skill_id, int qty, int list_type);
void (*autospell) (struct map_session_data *sd,uint16 skill_lv);
void (*autospell) (struct map_session_data *sd, uint16 skill_lv, int *skill_ids_list, int list_len);
void (*combo_delay) (struct block_list *bl,int wait);
void (*status_change) (struct block_list *bl, int relevant_bl, int type, int flag, int total_tick, int val1, int val2, int val3);
void (*status_change_sub) (struct block_list *bl, int type, int relevant_bl, int flag, int tick, int total_tick, int val1, int val2, int val3);
Expand Down
Loading

0 comments on commit 811d1fd

Please sign in to comment.