Skip to content

Commit 91eb357

Browse files
Lemongrass3110CrazyBS
authored andcommitted
Added support for homunculus autofeeding (rathena#3007)
* Added support for homunculus autofeeding This feature is available in 2017-09-20bRagexeRE or later Credits to @Asheraf in HerculesWS/Hercules#1898
1 parent 6968488 commit 91eb357

File tree

13 files changed

+92
-32
lines changed

13 files changed

+92
-32
lines changed

conf/battle/feature.conf

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,3 +67,11 @@ feature.roulette: off
6767
// Achievement (Note 1)
6868
// Requires: 2015-05-13aRagexe or later
6969
feature.achievement: on
70+
71+
// Homunculues Autofeeding (Note 1)
72+
// Requires: 2017-09-20bRagexeRE or later
73+
feature.homunculus_autofeed: off
74+
75+
// At which rate should homunculus autofeeding trigger?
76+
// Default: 30
77+
feature.homunculus_autofeed_rate: 30

sql-files/main.sql

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -608,6 +608,7 @@ CREATE TABLE IF NOT EXISTS `homunculus` (
608608
`alive` tinyint(2) NOT NULL default '1',
609609
`rename_flag` tinyint(2) NOT NULL default '0',
610610
`vaporize` tinyint(2) NOT NULL default '0',
611+
`autofeed` tinyint(2) NOT NULL default '0',
611612
PRIMARY KEY (`homun_id`)
612613
) ENGINE=MyISAM;
613614

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
ALTER TABLE `homunculus`
2+
ADD COLUMN `autofeed` tinyint(2) NOT NULL default '0' AFTER `vaporize`;

src/char/char.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2453,7 +2453,7 @@ bool char_checkdb(void){
24532453
}
24542454
//checking homunculus_db
24552455
if( SQL_ERROR == Sql_Query(sql_handle, "SELECT `homun_id`,`char_id`,`class`,`prev_class`,`name`,`level`,`exp`,`intimacy`,`hunger`,"
2456-
"`str`,`agi`,`vit`,`int`,`dex`,`luk`,`hp`,`max_hp`,`sp`,`max_sp`,`skill_point`,`alive`,`rename_flag`,`vaporize` "
2456+
"`str`,`agi`,`vit`,`int`,`dex`,`luk`,`hp`,`max_hp`,`sp`,`max_sp`,`skill_point`,`alive`,`rename_flag`,`vaporize`,`autofeed` "
24572457
" FROM `%s` LIMIT 1;", schema_config.homunculus_db) ){
24582458
Sql_ShowDebug(sql_handle);
24592459
return false;

src/char/int_homun.cpp

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -93,10 +93,10 @@ bool mapif_homunculus_save(struct s_homunculus* hd)
9393
if( hd->hom_id == 0 )
9494
{// new homunculus
9595
if( SQL_ERROR == Sql_Query(sql_handle, "INSERT INTO `%s` "
96-
"(`char_id`, `class`,`prev_class`,`name`,`level`,`exp`,`intimacy`,`hunger`, `str`, `agi`, `vit`, `int`, `dex`, `luk`, `hp`,`max_hp`,`sp`,`max_sp`,`skill_point`, `rename_flag`, `vaporize`) "
97-
"VALUES ('%d', '%d', '%d', '%s', '%d', '%u', '%u', '%d', '%d', %d, '%d', '%d', '%d', '%d', '%u', '%u', '%u', '%u', '%d', '%d', '%d')",
96+
"(`char_id`, `class`,`prev_class`,`name`,`level`,`exp`,`intimacy`,`hunger`, `str`, `agi`, `vit`, `int`, `dex`, `luk`, `hp`,`max_hp`,`sp`,`max_sp`,`skill_point`, `rename_flag`, `vaporize`, `autofeed`) "
97+
"VALUES ('%d', '%d', '%d', '%s', '%d', '%u', '%u', '%d', '%d', %d, '%d', '%d', '%d', '%d', '%u', '%u', '%u', '%u', '%d', '%d', '%d', '%d')",
9898
schema_config.homunculus_db, hd->char_id, hd->class_, hd->prev_class, esc_name, hd->level, hd->exp, hd->intimacy, hd->hunger, hd->str, hd->agi, hd->vit, hd->int_, hd->dex, hd->luk,
99-
hd->hp, hd->max_hp, hd->sp, hd->max_sp, hd->skillpts, hd->rename_flag, hd->vaporize) )
99+
hd->hp, hd->max_hp, hd->sp, hd->max_sp, hd->skillpts, hd->rename_flag, hd->vaporize, hd->autofeed) )
100100
{
101101
Sql_ShowDebug(sql_handle);
102102
flag = false;
@@ -108,9 +108,9 @@ bool mapif_homunculus_save(struct s_homunculus* hd)
108108
}
109109
else
110110
{
111-
if( SQL_ERROR == Sql_Query(sql_handle, "UPDATE `%s` SET `char_id`='%d', `class`='%d',`prev_class`='%d',`name`='%s',`level`='%d',`exp`='%u',`intimacy`='%u',`hunger`='%d', `str`='%d', `agi`='%d', `vit`='%d', `int`='%d', `dex`='%d', `luk`='%d', `hp`='%u',`max_hp`='%u',`sp`='%u',`max_sp`='%u',`skill_point`='%d', `rename_flag`='%d', `vaporize`='%d' WHERE `homun_id`='%d'",
111+
if( SQL_ERROR == Sql_Query(sql_handle, "UPDATE `%s` SET `char_id`='%d', `class`='%d',`prev_class`='%d',`name`='%s',`level`='%d',`exp`='%u',`intimacy`='%u',`hunger`='%d', `str`='%d', `agi`='%d', `vit`='%d', `int`='%d', `dex`='%d', `luk`='%d', `hp`='%u',`max_hp`='%u',`sp`='%u',`max_sp`='%u',`skill_point`='%d', `rename_flag`='%d', `vaporize`='%d', `autofeed`='%d' WHERE `homun_id`='%d'",
112112
schema_config.homunculus_db, hd->char_id, hd->class_, hd->prev_class, esc_name, hd->level, hd->exp, hd->intimacy, hd->hunger, hd->str, hd->agi, hd->vit, hd->int_, hd->dex, hd->luk,
113-
hd->hp, hd->max_hp, hd->sp, hd->max_sp, hd->skillpts, hd->rename_flag, hd->vaporize, hd->hom_id) )
113+
hd->hp, hd->max_hp, hd->sp, hd->max_sp, hd->skillpts, hd->rename_flag, hd->vaporize, hd->autofeed, hd->hom_id) )
114114
{
115115
Sql_ShowDebug(sql_handle);
116116
flag = false;
@@ -155,7 +155,7 @@ bool mapif_homunculus_load(int homun_id, struct s_homunculus* hd)
155155

156156
memset(hd, 0, sizeof(*hd));
157157

158-
if( SQL_ERROR == Sql_Query(sql_handle, "SELECT `homun_id`,`char_id`,`class`,`prev_class`,`name`,`level`,`exp`,`intimacy`,`hunger`, `str`, `agi`, `vit`, `int`, `dex`, `luk`, `hp`,`max_hp`,`sp`,`max_sp`,`skill_point`,`rename_flag`, `vaporize` FROM `%s` WHERE `homun_id`='%u'",
158+
if( SQL_ERROR == Sql_Query(sql_handle, "SELECT `homun_id`,`char_id`,`class`,`prev_class`,`name`,`level`,`exp`,`intimacy`,`hunger`, `str`, `agi`, `vit`, `int`, `dex`, `luk`, `hp`,`max_hp`,`sp`,`max_sp`,`skill_point`,`rename_flag`, `vaporize`, `autofeed` FROM `%s` WHERE `homun_id`='%u'",
159159
schema_config.homunculus_db, homun_id) )
160160
{
161161
Sql_ShowDebug(sql_handle);
@@ -196,6 +196,7 @@ bool mapif_homunculus_load(int homun_id, struct s_homunculus* hd)
196196
Sql_GetData(sql_handle, 19, &data, NULL); hd->skillpts = atoi(data);
197197
Sql_GetData(sql_handle, 20, &data, NULL); hd->rename_flag = atoi(data);
198198
Sql_GetData(sql_handle, 21, &data, NULL); hd->vaporize = atoi(data);
199+
Sql_GetData(sql_handle, 22, &data, NULL); hd->autofeed = atoi(data);
199200
Sql_FreeResult(sql_handle);
200201

201202
hd->intimacy = umin(hd->intimacy,100000);

src/common/mmo.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -434,6 +434,7 @@ struct s_homunculus { //[orn]
434434
int luk_value;
435435

436436
char spiritball; //for homun S [lighta]
437+
bool autofeed;
437438
};
438439

439440
struct s_mercenary {

src/map/battle.cpp

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8503,6 +8503,8 @@ static const struct _battle_data {
85038503
{ "autoloot_adjust", &battle_config.autoloot_adjust, 0, 0, 1, },
85048504
{ "broadcast_hide_name", &battle_config.broadcast_hide_name, 2, 0, NAME_LENGTH, },
85058505
{ "skill_drop_items_full", &battle_config.skill_drop_items_full, 0, 0, 1, },
8506+
{ "feature.homunculus_autofeed", &battle_config.feature_homunculus_autofeed, 1, 0, 1, },
8507+
{ "feature.homunculus_autofeed_rate", &battle_config.feature_homunculus_autofeed_rate,30, 0, 100, },
85068508

85078509
#include "../custom/battle_config_init.inc"
85088510
};
@@ -8633,6 +8635,13 @@ void battle_adjust_conf()
86338635
}
86348636
#endif
86358637

8638+
#if PACKETVER < 20170920
8639+
if( battle_config.feature_homunculus_autofeed ){
8640+
ShowWarning("conf/battle/feature.conf homunculus autofeeding is enabled but it requires PACKETVER 2017-09-20 or newer, disabling...\n");
8641+
battle_config.feature_homunculus_autofeed = 0;
8642+
}
8643+
#endif
8644+
86368645
#ifndef CELL_NOSTACK
86378646
if (battle_config.custom_cell_stack_limit != 1)
86388647
ShowWarning("Battle setting 'custom_cell_stack_limit' takes no effect as this server was compiled without Cell Stack Limit support.\n");

src/map/battle.hpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -639,6 +639,8 @@ struct Battle_Config
639639
int autoloot_adjust;
640640
int broadcast_hide_name;
641641
int skill_drop_items_full;
642+
int feature_homunculus_autofeed;
643+
int feature_homunculus_autofeed_rate;
642644

643645
#include "../custom/battle_config_struct.inc"
644646
};

src/map/clif.cpp

Lines changed: 47 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -9765,23 +9765,21 @@ void clif_feel_hate_reset(struct map_session_data *sd)
97659765
}
97669766

97679767

9768-
/// Equip window (un)tick ack (ZC_CONFIG).
9769-
/// 02d9 <type>.L <value>.L
9770-
/// type:
9771-
/// 0 = open equip window
9772-
/// value:
9773-
/// 0 = disabled
9774-
/// 1 = enabled
9775-
void clif_equiptickack(struct map_session_data* sd, int flag)
9776-
{
9768+
/// Send out reply to configuration change
9769+
/// 02d9 <type>.L <value>.L (ZC_CONFIG)
9770+
/// type: see enum e_config_type
9771+
/// value:
9772+
/// false = disabled
9773+
/// true = enabled
9774+
void clif_configuration( struct map_session_data* sd, enum e_config_type type, bool enabled ){
97779775
int fd;
97789776
nullpo_retv(sd);
97799777
fd = sd->fd;
97809778

97819779
WFIFOHEAD(fd, packet_len(0x2d9));
97829780
WFIFOW(fd, 0) = 0x2d9;
9783-
WFIFOL(fd, 2) = 0;
9784-
WFIFOL(fd, 6) = flag;
9781+
WFIFOL(fd, 2) = type;
9782+
WFIFOL(fd, 6) = enabled;
97859783
WFIFOSET(fd, packet_len(0x2d9));
97869784
}
97879785

@@ -10449,6 +10447,13 @@ void clif_parse_LoadEndAck(int fd,struct map_session_data *sd)
1044910447
clif_partyinvitationstate(sd);
1045010448
clif_equipcheckbox(sd);
1045110449
#endif
10450+
#if PACKETVER >= 20170920
10451+
if( sd->hd ){
10452+
clif_configuration( sd, CONFIG_HOMUNCULUS_AUTOFEED, sd->hd->homunculus.autofeed );
10453+
}else{
10454+
clif_configuration( sd, CONFIG_HOMUNCULUS_AUTOFEED, false );
10455+
}
10456+
#endif
1045210457

1045310458
if (sd->guild && battle_config.guild_notice_changemap == 1)
1045410459
clif_guild_notice(sd); // Displays after VIP
@@ -16543,19 +16548,38 @@ void clif_parse_ViewPlayerEquip(int fd, struct map_session_data* sd)
1654316548
}
1654416549

1654516550

16546-
/// Request to change equip window tick (CZ_CONFIG).
16547-
/// 02d8 <type>.L <flag>.L
16548-
/// type:
16549-
/// 0 = open equip window
16551+
/// Request to a configuration.
16552+
/// 02d8 <type>.L <flag>.L (CZ_CONFIG)
16553+
/// type: see enum e_config_type
1655016554
/// flag:
16551-
/// 0 = disabled
16552-
/// 1 = enabled
16553-
void clif_parse_EquipTick(int fd, struct map_session_data* sd)
16554-
{
16555-
//int type = RFIFOL(fd,packet_db[cmd].pos[0]);
16556-
bool flag = RFIFOL(fd,packet_db[RFIFOW(fd,0)].pos[1]) != 0;
16557-
sd->status.show_equip = flag;
16558-
clif_equiptickack(sd, flag);
16555+
/// false = disabled
16556+
/// true = enabled
16557+
void clif_parse_configuration( int fd, struct map_session_data* sd ){
16558+
int cmd = RFIFOW(fd,0);
16559+
int type = RFIFOL(fd,packet_db[cmd].pos[0]);
16560+
bool flag = RFIFOL(fd,packet_db[cmd].pos[1]) != 0;
16561+
16562+
switch( type ){
16563+
case CONFIG_OPEN_EQUIPMENT_WINDOW:
16564+
sd->status.show_equip = flag;
16565+
break;
16566+
case CONFIG_PET_AUTOFEED:
16567+
// TODO: Implement with pet evolution system
16568+
break;
16569+
case CONFIG_HOMUNCULUS_AUTOFEED:
16570+
// Player can not click this if he does not have a homunculus or it is vaporized
16571+
if( sd->hd == nullptr || sd->hd->homunculus.vaporize ){
16572+
return;
16573+
}
16574+
16575+
sd->hd->homunculus.autofeed = flag;
16576+
break;
16577+
default:
16578+
ShowWarning( "clif_parse_configuration: received unknown configuration type '%d'...\n", type );
16579+
return;
16580+
}
16581+
16582+
clif_configuration( sd, static_cast<e_config_type>(type), flag );
1655916583
}
1656016584

1656116585
/// Request to change party invitation tick.

src/map/clif.hpp

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -536,6 +536,13 @@ enum e_damage_type : uint8_t {
536536
DMG_TOUCH, /// (touch skill?)
537537
};
538538

539+
enum e_config_type : uint32 {
540+
CONFIG_OPEN_EQUIPMENT_WINDOW = 0,
541+
// Unknown
542+
CONFIG_PET_AUTOFEED = 2,
543+
CONFIG_HOMUNCULUS_AUTOFEED
544+
};
545+
539546
int clif_setip(const char* ip);
540547
void clif_setbindip(const char* ip);
541548
void clif_setport(uint16 port);
@@ -862,7 +869,7 @@ void clif_homskillup(struct map_session_data *sd, uint16 skill_id); //[orn]
862869
int clif_hom_food(struct map_session_data *sd,int foodid,int fail); //[orn]
863870
void clif_send_homdata(struct map_session_data *sd, int state, int param); //[orn]
864871

865-
void clif_equiptickack(struct map_session_data* sd, int flag);
872+
void clif_configuration( struct map_session_data* sd, enum e_config_type type, bool enabled );
866873
void clif_partytickack(struct map_session_data* sd, bool flag);
867874
void clif_viewequip_ack(struct map_session_data* sd, struct map_session_data* tsd);
868875
void clif_equipcheckbox(struct map_session_data* sd);

0 commit comments

Comments
 (0)