summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorzephyrus <zephyrus@54d463be-8e91-2dee-dedb-b68131a5f0ec>2008-08-31 22:56:05 +0000
committerzephyrus <zephyrus@54d463be-8e91-2dee-dedb-b68131a5f0ec>2008-08-31 22:56:05 +0000
commit08c870656aeb76d839a8ad2fd071818b8618f899 (patch)
tree3ac8cc1544cd0a60f00312cdb6c8c21f62f287a8
parent409cb0381295716d654fd2ee5021e1011a45ab80 (diff)
downloadhercules-08c870656aeb76d839a8ad2fd071818b8618f899.tar.gz
hercules-08c870656aeb76d839a8ad2fd071818b8618f899.tar.bz2
hercules-08c870656aeb76d839a8ad2fd071818b8618f899.tar.xz
hercules-08c870656aeb76d839a8ad2fd071818b8618f899.zip
- A proper mercenary lifetime calculation.
git-svn-id: https://rathena.svn.sourceforge.net/svnroot/rathena/trunk@13165 54d463be-8e91-2dee-dedb-b68131a5f0ec
-rw-r--r--src/char_sql/int_homun.c6
-rw-r--r--src/common/mmo.h2
-rw-r--r--src/map/chrif.c2
-rw-r--r--src/map/clif.c2
-rw-r--r--src/map/mercenary.c26
-rw-r--r--src/map/mercenary.h1
-rw-r--r--src/map/unit.c5
7 files changed, 23 insertions, 21 deletions
diff --git a/src/char_sql/int_homun.c b/src/char_sql/int_homun.c
index 17633ef4a..77753f04a 100644
--- a/src/char_sql/int_homun.c
+++ b/src/char_sql/int_homun.c
@@ -303,7 +303,7 @@ bool mapif_mercenary_save(struct s_mercenary* merc)
{ // Create new DB entry
if( SQL_ERROR == Sql_Query(sql_handle,
"INSERT INTO `mercenary` (`char_id`,`class`,`hp`,`sp`,`kill_counter`,`life_time`) VALUES ('%d','%d','%d','%d','%u','%u')",
- merc->char_id, merc->class_, merc->hp, merc->sp, merc->kill_count, merc->remain_life_time) )
+ merc->char_id, merc->class_, merc->hp, merc->sp, merc->kill_count, merc->life_time) )
{
Sql_ShowDebug(sql_handle);
flag = false;
@@ -313,7 +313,7 @@ bool mapif_mercenary_save(struct s_mercenary* merc)
}
else if( SQL_ERROR == Sql_Query(sql_handle,
"UPDATE `mercenary` SET `char_id` = '%d', `class` = '%d', `hp` = '%d', `sp` = '%d', `kill_counter` = '%u', `life_time` = '%u' WHERE `mer_id` = '%d'",
- merc->char_id, merc->class_, merc->hp, merc->sp, merc->kill_count, merc->remain_life_time, merc->mercenary_id) )
+ merc->char_id, merc->class_, merc->hp, merc->sp, merc->kill_count, merc->life_time, merc->mercenary_id) )
{ // Update DB entry
Sql_ShowDebug(sql_handle);
flag = false;
@@ -346,7 +346,7 @@ bool mapif_mercenary_load(int merc_id, int char_id, struct s_mercenary *merc)
Sql_GetData(sql_handle, 1, &data, NULL); merc->hp = atoi(data);
Sql_GetData(sql_handle, 2, &data, NULL); merc->sp = atoi(data);
Sql_GetData(sql_handle, 3, &data, NULL); merc->kill_count = atoi(data);
- Sql_GetData(sql_handle, 4, &data, NULL); merc->remain_life_time = atoi(data);
+ Sql_GetData(sql_handle, 4, &data, NULL); merc->life_time = atoi(data);
Sql_FreeResult(sql_handle);
if( save_log )
ShowInfo("Mercenary loaded (%d - %d).\n", merc->mercenary_id, merc->char_id);
diff --git a/src/common/mmo.h b/src/common/mmo.h
index 6be0fab19..d94796723 100644
--- a/src/common/mmo.h
+++ b/src/common/mmo.h
@@ -240,7 +240,7 @@ struct s_mercenary {
short class_;
int hp, sp;
unsigned int kill_count;
- unsigned int remain_life_time;
+ unsigned int life_time;
};
struct s_friend {
diff --git a/src/map/chrif.c b/src/map/chrif.c
index 2fc1b9dbe..7ff0c12e6 100644
--- a/src/map/chrif.c
+++ b/src/map/chrif.c
@@ -286,7 +286,7 @@ int chrif_save(struct map_session_data *sd, int flag)
intif_save_petdata(sd->status.account_id,&sd->pd->pet);
if( sd->hd && merc_is_hom_active(sd->hd) )
merc_save(sd->hd);
- if( sd->md && sd->md->mercenary.remain_life_time > 0 )
+ if( sd->md && mercenary_get_lifetime(sd->md) > 0 )
mercenary_save(sd->md);
return 0;
diff --git a/src/map/clif.c b/src/map/clif.c
index c56fc3f26..67ab85b39 100644
--- a/src/map/clif.c
+++ b/src/map/clif.c
@@ -12434,7 +12434,7 @@ void clif_mercenary_info(struct map_session_data *sd)
WFIFOL(fd,52) = status->max_hp;
WFIFOL(fd,56) = status->sp;
WFIFOL(fd,60) = status->max_sp;
- WFIFOL(fd,64) = (int)time(NULL) + (md->mercenary.remain_life_time / 1000);
+ WFIFOL(fd,64) = (int)time(NULL) + (mercenary_get_lifetime(md) / 1000);
WFIFOW(fd,68) = 0; // Loyalty
WFIFOL(fd,70) = 0; // Summon Count
WFIFOL(fd,74) = md->mercenary.kill_count;
diff --git a/src/map/mercenary.c b/src/map/mercenary.c
index 08a640275..bcbba3dd1 100644
--- a/src/map/mercenary.c
+++ b/src/map/mercenary.c
@@ -76,7 +76,7 @@ int merc_create(struct map_session_data *sd, int class_, unsigned int lifetime)
merc.class_ = class_;
merc.hp = db->status.max_hp;
merc.sp = db->status.max_sp;
- merc.remain_life_time = lifetime;
+ merc.life_time = lifetime;
// Request Char Server to create this mercenary
intif_mercenary_create(&merc);
@@ -84,19 +84,21 @@ int merc_create(struct map_session_data *sd, int class_, unsigned int lifetime)
return 1;
}
-int mercenary_save(struct mercenary_data *md)
+int mercenary_get_lifetime(struct mercenary_data *md)
{
- const struct TimerData * td = get_timer(md->contract_timer);
+ const struct TimerData * td;
+ if( md == NULL )
+ return 0;
+ td = get_timer(md->contract_timer);
+ return (td != NULL) ? DIFF_TICK(td->tick, gettick()) : 0;
+}
+
+int mercenary_save(struct mercenary_data *md)
+{
md->mercenary.hp = md->battle_status.hp;
md->mercenary.sp = md->battle_status.sp;
- if( td != NULL )
- md->mercenary.remain_life_time = DIFF_TICK(td->tick, gettick());
- else
- {
- md->mercenary.remain_life_time = 0;
- ShowWarning("mercenary_save : mercenary without timer (tid %d)\n", md->contract_timer);
- }
+ md->mercenary.life_time = mercenary_get_lifetime(md);
intif_mercenary_save(&md->mercenary);
return 1;
@@ -127,7 +129,7 @@ static int merc_contract_end(int tid, unsigned int tick, int id, intptr data)
int merc_delete(struct mercenary_data *md, int reply)
{
struct map_session_data *sd = md->master;
- md->mercenary.remain_life_time = 0;
+ md->mercenary.life_time = 0;
merc_contract_stop(md);
@@ -149,7 +151,7 @@ void merc_contract_stop(struct mercenary_data *md)
void merc_contract_init(struct mercenary_data *md)
{
if( md->contract_timer == INVALID_TIMER )
- md->contract_timer = add_timer(gettick() + md->mercenary.remain_life_time, merc_contract_end, md->master->bl.id, 0);
+ md->contract_timer = add_timer(gettick() + md->mercenary.life_time, merc_contract_end, md->master->bl.id, 0);
md->regen.state.block = 0;
}
diff --git a/src/map/mercenary.h b/src/map/mercenary.h
index 0579cc2bf..9c65b19e7 100644
--- a/src/map/mercenary.h
+++ b/src/map/mercenary.h
@@ -47,5 +47,6 @@ int mercenary_dead(struct mercenary_data *md, struct block_list *src);
int do_init_mercenary(void);
int merc_delete(struct mercenary_data *md, int reply);
void merc_contract_stop(struct mercenary_data *md);
+int mercenary_get_lifetime(struct mercenary_data *md);
#endif /* _MERCENARY_H_ */
diff --git a/src/map/unit.c b/src/map/unit.c
index c1fb60031..59924a108 100644
--- a/src/map/unit.c
+++ b/src/map/unit.c
@@ -1850,14 +1850,13 @@ int unit_remove_map_(struct block_list *bl, int clrtype, const char* file, int l
map_freeblock_unlock();
return 0;
}
-
break;
}
case BL_MER:
{
struct mercenary_data *md = (struct mercenary_data *)bl;
ud->canact_tick = ud->canmove_tick;
- if( !md->mercenary.remain_life_time && !(md->master && !md->master->state.active) )
+ if( mercenary_get_lifetime(md) <= 0 && !(md->master && !md->master->state.active) )
{
clif_clearunit_area(bl,clrtype);
map_delblock(bl);
@@ -2097,7 +2096,7 @@ int unit_free(struct block_list *bl, int clrtype)
struct map_session_data *sd = md->master;
if( clrtype >= 0 )
{
- if( md->mercenary.remain_life_time > 0 )
+ if( mercenary_get_lifetime(md) > 0 )
mercenary_save(md);
else
{