- A proper mercenary lifetime calculation.

git-svn-id: https://svn.code.sf.net/p/rathena/svn/trunk@13165 54d463be-8e91-2dee-dedb-b68131a5f0ec
This commit is contained in:
zephyrus 2008-08-31 22:56:05 +00:00
parent 639c161d4b
commit 6a1de57730
7 changed files with 23 additions and 21 deletions

View File

@ -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);

View File

@ -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 {

View File

@ -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;

View File

@ -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;

View File

@ -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_get_lifetime(struct mercenary_data *md)
{
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)
{
const struct TimerData * td = get_timer(md->contract_timer);
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;
}

View File

@ -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_ */

View File

@ -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
{