summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDastgir <dastgirp@gmail.com>2018-06-05 12:10:05 +0530
committerAsheraf <acheraf1998@gmail.com>2018-06-25 21:21:27 +0100
commit9a95d3c61f8195c326ed430323074ef8ec23273c (patch)
tree5a8c81a39bfb437d4d6d18bca44881617d73cda1
parent7c9860b275ee1c1d39bad2ca2551da82bd525267 (diff)
downloadhercules-9a95d3c61f8195c326ed430323074ef8ec23273c.tar.gz
hercules-9a95d3c61f8195c326ed430323074ef8ec23273c.tar.bz2
hercules-9a95d3c61f8195c326ed430323074ef8ec23273c.tar.xz
hercules-9a95d3c61f8195c326ed430323074ef8ec23273c.zip
Implemented Pet Autofeeding
-rw-r--r--conf/map/battle/feature.conf5
-rw-r--r--db/pre-re/pet_db.conf1
-rw-r--r--db/re/pet_db.conf1
-rw-r--r--sql-files/main.sql2
-rw-r--r--sql-files/upgrades/2018-06-05--12-02.sql24
-rw-r--r--sql-files/upgrades/index.txt1
-rw-r--r--src/char/int_pet.c15
-rw-r--r--src/common/mmo.h1
-rw-r--r--src/map/battle.c1
-rw-r--r--src/map/battle.h1
-rw-r--r--src/map/clif.c30
-rw-r--r--src/map/clif.h2
-rw-r--r--src/map/pet.c10
-rw-r--r--src/map/pet.h1
14 files changed, 79 insertions, 16 deletions
diff --git a/conf/map/battle/feature.conf b/conf/map/battle/feature.conf
index 8d19539b4..285633209 100644
--- a/conf/map/battle/feature.conf
+++ b/conf/map/battle/feature.conf
@@ -71,6 +71,11 @@ features: {
// false: disable
enable_homun_autofeed: true
+ // Allow Pet autofeeding
+ // true: enable (Default)
+ // false: disable
+ enable_pet_autofeed: true
+
// Enable Attendance System for clients >= 2018-03-07bRagexeRE or 2018-04-04bRagexe or 2018-04-11aRagexe_zero
// true: enable (Default)
// false: disable
diff --git a/db/pre-re/pet_db.conf b/db/pre-re/pet_db.conf
index 3ce78e546..4e66584b0 100644
--- a/db/pre-re/pet_db.conf
+++ b/db/pre-re/pet_db.conf
@@ -56,6 +56,7 @@ pet_db:(
AttackRate: attack rate (int, defaults to 0)
DefendRate: Defence attack (int, defaults to 0)
ChangeTargetRate: change target (int, defaults to 0)
+ AutoFeed: true/false (boolean, defaults to false)
PetScript: <" Pet Script (can also be multi-line) ">
EquipScript: <" Equip Script (can also be multi-line) ">
},
diff --git a/db/re/pet_db.conf b/db/re/pet_db.conf
index 6d6083e59..348fcfcd3 100644
--- a/db/re/pet_db.conf
+++ b/db/re/pet_db.conf
@@ -56,6 +56,7 @@ pet_db:(
AttackRate: attack rate (int, defaults to 0)
DefendRate: Defence attack (int, defaults to 0)
ChangeTargetRate: change target (int, defaults to 0)
+ AutoFeed: true/false (boolean, defaults to false)
PetScript: <" Pet Script (can also be multi-line) ">
EquipScript: <" Equip Script (can also be multi-line) ">
},
diff --git a/sql-files/main.sql b/sql-files/main.sql
index 2e51d6a12..8f7e5355b 100644
--- a/sql-files/main.sql
+++ b/sql-files/main.sql
@@ -782,6 +782,7 @@ CREATE TABLE IF NOT EXISTS `pet` (
`hungry` SMALLINT(9) UNSIGNED NOT NULL DEFAULT '0',
`rename_flag` TINYINT(4) UNSIGNED NOT NULL DEFAULT '0',
`incubate` INT(11) UNSIGNED NOT NULL DEFAULT '0',
+ `autofeed` TINYINT(2) UNSIGNED NOT NULL DEFAULT '0',
PRIMARY KEY (`pet_id`)
) ENGINE=MyISAM;
@@ -893,6 +894,7 @@ INSERT IGNORE INTO `sql_updates` (`timestamp`) VALUES (1496588700); -- 2017-06-0
INSERT IGNORE INTO `sql_updates` (`timestamp`) VALUES (1509835214); -- 2017-11-04--10-39.sql
INSERT IGNORE INTO `sql_updates` (`timestamp`) VALUES (1519671456); -- 2018-02-26--15-57.sql
INSERT IGNORE INTO `sql_updates` (`timestamp`) VALUES (1520654809); -- 2018-03-10--04-06.sql
+INSERT IGNORE INTO `sql_updates` (`timestamp`) VALUES (1528180320); -- 2018-06-05--12-02.sql
--
-- Table structure for table `storage`
--
diff --git a/sql-files/upgrades/2018-06-05--12-02.sql b/sql-files/upgrades/2018-06-05--12-02.sql
new file mode 100644
index 000000000..26c22243f
--- /dev/null
+++ b/sql-files/upgrades/2018-06-05--12-02.sql
@@ -0,0 +1,24 @@
+#1528180320
+
+-- This file is part of Hercules.
+-- http://herc.ws - http://github.com/HerculesWS/Hercules
+--
+-- Copyright (C) 2018 Hercules Dev Team
+-- Copyright (C) 2018 Dastgir
+--
+-- 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/>.
+
+ALTER TABLE `pet` ADD COLUMN `autofeed` TINYINT(2) UNSIGNED NOT NULL DEFAULT '0';
+
+INSERT INTO `sql_updates` (`timestamp`, `ignored`) VALUES (1528180320 , 'No');
diff --git a/sql-files/upgrades/index.txt b/sql-files/upgrades/index.txt
index dac60b6aa..5a737f93a 100644
--- a/sql-files/upgrades/index.txt
+++ b/sql-files/upgrades/index.txt
@@ -45,3 +45,4 @@
2017-11-04--10-39.sql
2018-02-26--15-57.sql
2018-03-10--04-06.sql
+2018-06-05--12-02.sql
diff --git a/src/char/int_pet.c b/src/char/int_pet.c
index 0ece11b51..f270f205d 100644
--- a/src/char/int_pet.c
+++ b/src/char/int_pet.c
@@ -66,19 +66,19 @@ int inter_pet_tosql(const struct s_pet *p)
if (p->pet_id == 0) {
// New pet.
if (SQL_ERROR == SQL->Query(inter->sql_handle, "INSERT INTO `%s` "
- "(`class`,`name`,`account_id`,`char_id`,`level`,`egg_id`,`equip`,`intimate`,`hungry`,`rename_flag`,`incubate`) "
- "VALUES ('%d', '%s', '%d', '%d', '%d', '%d', '%d', '%d', '%d', '%d', '%d')",
+ "(`class`,`name`,`account_id`,`char_id`,`level`,`egg_id`,`equip`,`intimate`,`hungry`,`rename_flag`,`incubate`, `autofeed`) "
+ "VALUES ('%d', '%s', '%d', '%d', '%d', '%d', '%d', '%d', '%d', '%d', '%d', '%d')",
pet_db, p->class_, esc_name, p->account_id, p->char_id, p->level, p->egg_id,
- p->equip, intimate, hungry, p->rename_flag, p->incubate)) {
+ p->equip, intimate, hungry, p->rename_flag, p->incubate, p->autofeed)) {
Sql_ShowDebug(inter->sql_handle);
return 0;
}
pet_id = (int)SQL->LastInsertId(inter->sql_handle);
} else {
// Update pet.
- if (SQL_ERROR == SQL->Query(inter->sql_handle, "UPDATE `%s` SET `class`='%d',`name`='%s',`account_id`='%d',`char_id`='%d',`level`='%d',`egg_id`='%d',`equip`='%d',`intimate`='%d',`hungry`='%d',`rename_flag`='%d',`incubate`='%d' WHERE `pet_id`='%d'",
+ if (SQL_ERROR == SQL->Query(inter->sql_handle, "UPDATE `%s` SET `class`='%d',`name`='%s',`account_id`='%d',`char_id`='%d',`level`='%d',`egg_id`='%d',`equip`='%d',`intimate`='%d',`hungry`='%d',`rename_flag`='%d',`incubate`='%d', `autofeed`='%d' WHERE `pet_id`='%d'",
pet_db, p->class_, esc_name, p->account_id, p->char_id, p->level, p->egg_id,
- p->equip, intimate, hungry, p->rename_flag, p->incubate, p->pet_id)) {
+ p->equip, intimate, hungry, p->rename_flag, p->incubate, p->autofeed, p->pet_id)) {
Sql_ShowDebug(inter->sql_handle);
return 0;
}
@@ -102,9 +102,9 @@ int inter_pet_fromsql(int pet_id, struct s_pet* p)
nullpo_ret(p);
memset(p, 0, sizeof(struct s_pet));
- //`pet` (`pet_id`, `class`,`name`,`account_id`,`char_id`,`level`,`egg_id`,`equip`,`intimate`,`hungry`,`rename_flag`,`incubate`)
+ //`pet` (`pet_id`, `class`,`name`,`account_id`,`char_id`,`level`,`egg_id`,`equip`,`intimate`,`hungry`,`rename_flag`,`incubate`, `autofeed`)
- if( SQL_ERROR == SQL->Query(inter->sql_handle, "SELECT `pet_id`, `class`,`name`,`account_id`,`char_id`,`level`,`egg_id`,`equip`,`intimate`,`hungry`,`rename_flag`,`incubate` FROM `%s` WHERE `pet_id`='%d'", pet_db, pet_id) )
+ if( SQL_ERROR == SQL->Query(inter->sql_handle, "SELECT `pet_id`, `class`,`name`,`account_id`,`char_id`,`level`,`egg_id`,`equip`,`intimate`,`hungry`,`rename_flag`,`incubate`,`autofeed` FROM `%s` WHERE `pet_id`='%d'", pet_db, pet_id) )
{
Sql_ShowDebug(inter->sql_handle);
return 0;
@@ -124,6 +124,7 @@ int inter_pet_fromsql(int pet_id, struct s_pet* p)
SQL->GetData(inter->sql_handle, 9, &data, NULL); p->hungry = atoi(data);
SQL->GetData(inter->sql_handle, 10, &data, NULL); p->rename_flag = atoi(data);
SQL->GetData(inter->sql_handle, 11, &data, NULL); p->incubate = atoi(data);
+ SQL->GetData(inter->sql_handle, 12, &data, NULL); p->autofeed = atoi(data);
SQL->FreeResult(inter->sql_handle);
diff --git a/src/common/mmo.h b/src/common/mmo.h
index 74d48dd47..0b4ba4a45 100644
--- a/src/common/mmo.h
+++ b/src/common/mmo.h
@@ -544,6 +544,7 @@ struct s_pet {
char name[NAME_LENGTH];
char rename_flag;
char incubate;
+ int autofeed;
};
struct s_homunculus { //[orn]
diff --git a/src/map/battle.c b/src/map/battle.c
index 6a961afeb..4d320704a 100644
--- a/src/map/battle.c
+++ b/src/map/battle.c
@@ -7319,6 +7319,7 @@ static const struct battle_data {
{ "features/rodex", &battle_config.feature_rodex, 1, 0, 1, },
{ "features/rodex_use_accountmail", &battle_config.feature_rodex_use_accountmail, 0, 0, 1, },
{ "features/enable_homun_autofeed", &battle_config.feature_enable_homun_autofeed, 1, 0, 1, },
+ { "features/enable_pet_autofeed", &battle_config.feature_enable_pet_autofeed, 1, 0, 1, },
{ "storage_use_item", &battle_config.storage_use_item, 0, 0, 1, },
{ "features/enable_attendance_system", &battle_config.feature_enable_attendance_system,1, 0, 1, },
{ "features/feature_attendance_endtime",&battle_config.feature_attendance_endtime, 1, 0, 99999999, },
diff --git a/src/map/battle.h b/src/map/battle.h
index c325daf0d..f4176f142 100644
--- a/src/map/battle.h
+++ b/src/map/battle.h
@@ -563,6 +563,7 @@ struct Battle_Config {
int feature_rodex_use_accountmail;
int feature_enable_homun_autofeed;
+ int feature_enable_pet_autofeed;
int storage_use_item;
diff --git a/src/map/clif.c b/src/map/clif.c
index aeaf03e43..86b159288 100644
--- a/src/map/clif.c
+++ b/src/map/clif.c
@@ -9093,7 +9093,7 @@ void clif_feel_hate_reset(struct map_session_data *sd)
/// value:
/// 0 = disabled
/// 1 = enabled
-void clif_zc_config(struct map_session_data* sd, int type, int flag)
+void clif_zc_config(struct map_session_data* sd, enum CZ_CONFIG type, int flag)
{
int fd;
nullpo_retv(sd);
@@ -16154,24 +16154,38 @@ void clif_parse_cz_config(int fd, struct map_session_data *sd) __attribute__((no
/// 02d8 <type>.L <value>.L
/// type:
/// 0 = open equip window
+/// 2 = pet autofeeding
/// 3 = homunculus autofeeding
/// value:
/// 0 = disabled
/// 1 = enabled
void clif_parse_cz_config(int fd, struct map_session_data *sd)
{
- int type = RFIFOL(fd, 2);
+ enum CZ_CONFIG type = RFIFOL(fd, 2);
int flag = RFIFOL(fd, 6);
- if (type == CZ_CONFIG_OPEN_EQUIPMENT_WINDOW) {
+ switch (type) {
+ case CZ_CONFIG_OPEN_EQUIPMENT_WINDOW:
sd->status.show_equip = flag;
- } else if (type == CZ_CONFIG_HOMUNCULUS_AUTOFEEDING) {
- struct homun_data *hd;
- hd = sd->hd;
+ break;
+ case CZ_CONFIG_PET_AUTOFEEDING: {
+ struct pet_data *pd = sd->pd;
+ nullpo_retv(pd);
+ if (pd->petDB->autofeed == 0) {
+ clif->message(fd, "Autofeed is disabled for this pet.");
+ return;
+ }
+ pd->pet.autofeed = flag;
+ break;
+ }
+ case CZ_CONFIG_HOMUNCULUS_AUTOFEEDING: {
+ struct homun_data *hd = sd->hd;
nullpo_retv(hd);
hd->homunculus.autofeed = flag;
- } else {
- ShowWarning("clif_parse_cz_config: Unsupported type has been received (%d).", type);
+ break;
+ }
+ default:
+ ShowWarning("clif_parse_cz_config: Unsupported type has been received (%u).\n", type);
return;
}
clif->zc_config(sd, type, flag);
diff --git a/src/map/clif.h b/src/map/clif.h
index 4b625023f..a8a9ddf70 100644
--- a/src/map/clif.h
+++ b/src/map/clif.h
@@ -834,7 +834,7 @@ struct clif_interface {
void (*mission_info) (struct map_session_data *sd, int mob_id, unsigned char progress);
void (*feel_hate_reset) (struct map_session_data *sd);
void (*partytickack) (struct map_session_data* sd, bool flag);
- void (*zc_config) (struct map_session_data *sd, int type, int flag);
+ void (*zc_config) (struct map_session_data *sd, enum CZ_CONFIG type, int flag);
void (*viewequip_ack) (struct map_session_data* sd, struct map_session_data* tsd);
void (*equpcheckbox) (struct map_session_data* sd);
void (*displayexp) (struct map_session_data *sd, uint64 exp, char type, bool is_quest);
diff --git a/src/map/pet.c b/src/map/pet.c
index 4bac79dc8..4e3503b05 100644
--- a/src/map/pet.c
+++ b/src/map/pet.c
@@ -233,6 +233,13 @@ int pet_hungry(int tid, int64 tick, int id, intptr_t data) {
return 1; //You lost the pet already, the rest is irrelevant.
pd->pet.hungry--;
+ /* Pet Autofeed */
+ if (battle_config.feature_enable_homun_autofeed != 0) {
+ if (pd->petDB->autofeed == 1 && pd->pet.autofeed == 1 && pd->pet.hungry <= 25) {
+ pet->food(sd, pd);
+ }
+ }
+
if( pd->pet.hungry < 0 )
{
pet_stop_attack(pd);
@@ -1359,6 +1366,9 @@ int pet_read_db_sub(struct config_setting_t *it, int n, const char *source)
if (libconfig->setting_lookup_int(it, "ChangeTargetRate", &i32))
pet->db[n].change_target_rate = i32;
+ if ((t = libconfig->setting_get_member(it, "AutoFeed")) && (i32 = libconfig->setting_get_bool(t)))
+ pet->db[n].autofeed = i32;
+
if (libconfig->setting_lookup_string(it, "PetScript", &str))
pet->db[n].pet_script = *str ? script->parse(str, source, -pet->db[n].class_, SCRIPT_IGNORE_EXTERNAL_BRACKETS, NULL) : NULL;
diff --git a/src/map/pet.h b/src/map/pet.h
index d341be97c..434b07015 100644
--- a/src/map/pet.h
+++ b/src/map/pet.h
@@ -50,6 +50,7 @@ struct s_pet_db {
int attack_rate;
int defence_attack_rate;
int change_target_rate;
+ int autofeed;
struct script_code *equip_script;
struct script_code *pet_script;
};