summaryrefslogtreecommitdiff
path: root/src/map
diff options
context:
space:
mode:
authorultramage <ultramage@54d463be-8e91-2dee-dedb-b68131a5f0ec>2007-12-14 23:38:11 +0000
committerultramage <ultramage@54d463be-8e91-2dee-dedb-b68131a5f0ec>2007-12-14 23:38:11 +0000
commit1382b22cd68bf90f2adc4ae13187416982f9a12f (patch)
tree60602ab8f3578407bffbd1859603c3a586c52256 /src/map
parent78474fe9877675f3fc173f0b7e7235fd6c105067 (diff)
downloadhercules-1382b22cd68bf90f2adc4ae13187416982f9a12f.tar.gz
hercules-1382b22cd68bf90f2adc4ae13187416982f9a12f.tar.bz2
hercules-1382b22cd68bf90f2adc4ae13187416982f9a12f.tar.xz
hercules-1382b22cd68bf90f2adc4ae13187416982f9a12f.zip
Guardian hp handling code removal (see bugreport:342)
- removed guardian hp from the castle data structure, database, savefiles and various script functions (use upgrade_svn11914.sql) - removed guardian hp calculation and manipulation from the castle manager npc, now the hp values are updated by the server itself (glitch: when castle defense changes, all guardians are healed to full) - tweaked script function 'guardianinfo' to provide some data needed by the manager npc (currently available are hp, maxhp and visibility); also, it doesn't need a player attached to execute anymore The whole thing is experimental, use at your own risk (seems to work though...) git-svn-id: https://rathena.svn.sourceforge.net/svnroot/rathena/trunk@11915 54d463be-8e91-2dee-dedb-b68131a5f0ec
Diffstat (limited to 'src/map')
-rw-r--r--src/map/battle.c4
-rw-r--r--src/map/guild.c43
-rw-r--r--src/map/map.c6
-rw-r--r--src/map/map.h7
-rw-r--r--src/map/mob.c13
-rw-r--r--src/map/script.c77
-rw-r--r--src/map/status.c7
7 files changed, 63 insertions, 94 deletions
diff --git a/src/map/battle.c b/src/map/battle.c
index eeb368feb..759b88f83 100644
--- a/src/map/battle.c
+++ b/src/map/battle.c
@@ -548,9 +548,7 @@ int battle_calc_gvg_damage(struct block_list *src,struct block_list *bl,int dama
break;
default:
if (md && md->guardian_data) {
- damage -= damage
- * (md->guardian_data->castle->defense/100)
- * battle_config.castle_defense_rate/100;
+ damage -= damage * (md->guardian_data->castle->defense/100) * battle_config.castle_defense_rate/100;
}
if (flag & BF_SKILL) { //Skills get a different reduction than non-skills. [Skotlex]
if (flag&BF_WEAPON)
diff --git a/src/map/guild.c b/src/map/guild.c
index 8fe10116d..a6ebd5157 100644
--- a/src/map/guild.c
+++ b/src/map/guild.c
@@ -1723,15 +1723,6 @@ int guild_castledataloadack(int castle_id,int index,int value)
case 16:
case 17:
gc->guardian[index-10].visible = value; break;
- case 18:
- case 19:
- case 20:
- case 21:
- case 22:
- case 23:
- case 24:
- case 25:
- gc->guardian[index-18].hp = value; break;
default:
ShowError("guild_castledataloadack ERROR!! (Not found index=%d)\n", index);
return 0;
@@ -1749,14 +1740,28 @@ int guild_castledataloadack(int castle_id,int index,int value)
// ギルド城データ変更要求
int guild_castledatasave(int castle_id,int index,int value)
{
- if (index == 1)
+ if( index == 1 )
{ //The castle's owner has changed? Update Guardian ownership, too. [Skotlex]
struct guild_castle *gc = guild_castle_search(castle_id);
int m = -1;
if (gc) m = map_mapname2mapid(gc->map_name);
if (m != -1)
- map_foreachinmap(mob_guardian_guildchange, m, BL_MOB);
+ map_foreachinmap(mob_guardian_guildchange, m, BL_MOB); //FIXME: why not iterate over gc->guardian[i].id ?
}
+ else
+ if( index == 3 )
+ { // defense invest change -> recalculate guardian hp
+ struct guild_castle* gc = guild_castle_search(castle_id);
+ if( gc )
+ {
+ int i;
+ struct mob_data* gd;
+ for( i = 0; i < MAX_GUARDIANS; i++ )
+ if( gc->guardian[i].visible && (gd = map_id2md(gc->guardian[i].id)) != NULL )
+ status_calc_mob(gd,0);
+ }
+ }
+
return intif_guild_castle_datasave(castle_id,index,value);
}
@@ -1786,15 +1791,6 @@ int guild_castledatasaveack(int castle_id,int index,int value)
case 16:
case 17:
gc->guardian[index-10].visible = value; break;
- case 18:
- case 19:
- case 20:
- case 21:
- case 22:
- case 23:
- case 24:
- case 25:
- gc->guardian[index-18].hp = value; break;
default:
ShowError("guild_castledatasaveack ERROR!! (Not found index=%d)\n", index);
return 0;
@@ -1864,7 +1860,7 @@ static int Gid[MAX_GUILDCASTLE];
int guild_save_sub(int tid,unsigned int tick,int id,int data)
{
struct guild_castle *gc;
- int i,j;
+ int i;
for(i = 0; i < MAX_GUILDCASTLE; i++) { // [Yor]
gc = guild_castle_search(i);
@@ -1874,11 +1870,6 @@ int guild_save_sub(int tid,unsigned int tick,int id,int data)
guild_castledatasave(gc->castle_id, 1, gc->guild_id);
Gid[i] = gc->guild_id;
}
- for (j = 0; j < MAX_GUARDIANS; j++)
- {
- if (gc->guardian[j].visible && Ghp[i][j] != gc->guardian[j].hp)
- guild_castledatasave(gc->castle_id, 18+j, gc->guardian[j].hp);
- }
}
return 0;
diff --git a/src/map/map.c b/src/map/map.c
index 4383d1cd4..43b17daec 100644
--- a/src/map/map.c
+++ b/src/map/map.c
@@ -1763,6 +1763,12 @@ struct map_session_data * map_id2sd(int id)
return (struct map_session_data*)idb_get(pc_db,id);
}
+struct mob_data * map_id2md(int id)
+{// just a id2bl lookup because there's no mob_db
+ if (id <= 0) return NULL;
+ return (struct mob_data*)map_id2bl(id);
+}
+
struct npc_data * map_id2nd(int id)
{// just a id2bl lookup because there's no npc_db
if (id <= 0) return NULL;
diff --git a/src/map/map.h b/src/map/map.h
index 7a3e6ae02..847ca477d 100644
--- a/src/map/map.h
+++ b/src/map/map.h
@@ -1319,9 +1319,10 @@ void map_reqnickdb(struct map_session_data* sd,int charid);
const char* map_charid2nick(int charid);
struct map_session_data* map_charid2sd(int charid);
-struct map_session_data * map_id2sd(int);
-struct npc_data * map_id2nd(int);
-struct block_list * map_id2bl(int);
+struct map_session_data * map_id2sd(int id);
+struct mob_data * map_id2md(int id);
+struct npc_data * map_id2nd(int id);
+struct block_list * map_id2bl(int id);
#define map_id2index(id) map[(id)].index
int map_mapindex2mapid(unsigned short mapindex);
diff --git a/src/map/mob.c b/src/map/mob.c
index 2d0eb04b9..c58ce5e17 100644
--- a/src/map/mob.c
+++ b/src/map/mob.c
@@ -439,7 +439,6 @@ static int mob_spawn_guardian_sub(int tid,unsigned int tick,int id,int data)
{ //Safe removal of guardian.
md->guardian_data->castle->guardian[md->guardian_data->number].visible = 0;
guild_castledatasave(md->guardian_data->castle->castle_id, 10+md->guardian_data->number,0);
- guild_castledatasave(md->guardian_data->castle->castle_id, 18+md->guardian_data->number,0);
}
unit_free(&md->bl,0); //Remove guardian.
}
@@ -1734,9 +1733,6 @@ void mob_damage(struct mob_data *md, struct block_list *src, int damage)
if (src) mob_log_damage(md, src, damage);
}
- if(md->guardian_data && md->guardian_data->number < MAX_GUARDIANS) // guardian hp update [Valaris] (updated by [Skotlex])
- md->guardian_data->castle->guardian[md->guardian_data->number].hp = md->status.hp;
-
if (battle_config.show_mob_info&3)
clif_charnameack (0, &md->bl);
@@ -1779,10 +1775,7 @@ int mob_dead(struct mob_data *md, struct block_list *src, int type)
status = &md->status;
if(md->guardian_data && md->guardian_data->number < MAX_GUARDIANS)
- { // guardian hp update [Valaris] (updated by [Skotlex])
guild_castledatasave(md->guardian_data->castle->castle_id, 10+md->guardian_data->number,0);
- guild_castledatasave(md->guardian_data->castle->castle_id, 18+md->guardian_data->number,0);
- }
md->state.skillstate = MSS_DEAD;
mobskill_use(md,tick,-1); //On Dead skill.
@@ -2291,7 +2284,6 @@ int mob_guardian_guildchange(struct block_list *bl,va_list ap)
{ //Safe removal of guardian.
md->guardian_data->castle->guardian[md->guardian_data->number].visible = 0;
guild_castledatasave(md->guardian_data->castle->castle_id, 10+md->guardian_data->number,0);
- guild_castledatasave(md->guardian_data->castle->castle_id, 18+md->guardian_data->number,0);
}
unit_free(&md->bl,0); //Remove guardian.
}
@@ -2304,7 +2296,6 @@ int mob_guardian_guildchange(struct block_list *bl,va_list ap)
ShowError("mob_guardian_guildchange: New Guild (id %d) does not exists!\n", md->guardian_data->guild_id);
md->guardian_data->castle->guardian[md->guardian_data->number].visible = 0;
guild_castledatasave(md->guardian_data->castle->castle_id, 10+md->guardian_data->number,0);
- guild_castledatasave(md->guardian_data->castle->castle_id, 18+md->guardian_data->number,0);
unit_free(&md->bl,0);
return 0;
}
@@ -2412,10 +2403,6 @@ int mob_class_change (struct mob_data *md, int class_)
*------------------------------------------*/
void mob_heal(struct mob_data *md,unsigned int heal)
{
- if(md->guardian_data && md->guardian_data->number < MAX_GUARDIANS)
- // guardian hp update [Valaris] (updated by [Skotlex])
- md->guardian_data->castle->guardian[md->guardian_data->number].hp = md->status.hp;
-
if (battle_config.show_mob_info&3)
clif_charnameack (0, &md->bl);
}
diff --git a/src/map/script.c b/src/map/script.c
index 2575e42ef..b66197bb5 100644
--- a/src/map/script.c
+++ b/src/map/script.c
@@ -9127,7 +9127,7 @@ BUILDIN_FUNC(getcastledata)
switch(index){
case 0: {
int i;
- for(i=1;i<26;i++) // Initialize[AgitInit]
+ for(i=1;i<18;i++) // Initialize[AgitInit]
guild_castledataload(gc->castle_id,i);
} break;
case 1:
@@ -9157,15 +9157,6 @@ BUILDIN_FUNC(getcastledata)
case 16:
case 17:
script_pushint(st,gc->guardian[index-10].visible); break;
- case 18:
- case 19:
- case 20:
- case 21:
- case 22:
- case 23:
- case 24:
- case 25:
- script_pushint(st,gc->guardian[index-18].hp); break;
default:
script_pushint(st,0); break;
}
@@ -9213,30 +9204,6 @@ BUILDIN_FUNC(setcastledata)
case 16:
case 17:
gc->guardian[index-10].visible = value; break;
- case 18:
- case 19:
- case 20:
- case 21:
- case 22:
- case 23:
- case 24:
- case 25:
- gc->guardian[index-18].hp = value;
- if (gc->guardian[index-18].id)
- { //Update this mob's HP.
- struct block_list *bl = map_id2bl(gc->guardian[index-18].id);
- if (!bl)
- { //Wrong target?
- gc->guardian[index-18].id = 0;
- break;
- }
- if (value < 1) {
- status_kill(bl);
- break;
- }
- status_set_hp(bl, value, 0);
- }
- break;
default:
return 0;
}
@@ -9742,27 +9709,47 @@ BUILDIN_FUNC(guardian)
return 0;
}
-/*================================================
- * Script for Displaying Guardian Info [Valaris]
- *------------------------------------------------*/
+/// Retrieves various information about the specified guardian.
+///
+/// guardianinfo("<map_name>", <index>, <type>) -> <value>
+/// type: 0 - whether it is deployed or not
+/// 1 - maximum hp
+/// 2 - current hp
+///
BUILDIN_FUNC(guardianinfo)
{
- int guardian=script_getnum(st,2);
- TBL_PC *sd=script_rid2sd(st);
- struct guild_castle *gc=guild_mapname2gc(map[sd->bl.m].name);
+ const char* mapname = mapindex_getmapname(script_getstr(st,2),NULL);
+ int id = script_getnum(st,3);
+ int type = script_getnum(st,4);
- if (guardian < 0 || guardian >= MAX_GUARDIANS || gc==NULL)
+ struct guild_castle* gc = guild_mapname2gc(mapname);
+ struct mob_data* gd;
+
+ if( gc == NULL || id < 0 || id >= MAX_GUARDIANS )
{
script_pushint(st,-1);
return 0;
}
- if(gc->guardian[guardian].visible)
- script_pushint(st,gc->guardian[guardian].hp);
- else script_pushint(st,-1);
+ if( type == 0 )
+ script_pushint(st, gc->guardian[id].visible);
+ else
+ if( !gc->guardian[id].visible )
+ script_pushint(st,-1);
+ else
+ if( (gd = map_id2md(gc->guardian[id].id)) == NULL )
+ script_pushint(st,-1);
+ else
+ {
+ if ( type == 1 ) script_pushint(st,gd->status.max_hp);
+ else if( type == 2 ) script_pushint(st,gd->status.hp);
+ else
+ script_pushint(st,-1);
+ }
return 0;
}
+
/*==========================================
* IDからItem名
*------------------------------------------*/
@@ -13158,7 +13145,7 @@ struct script_function buildin_func[] = {
BUILDIN_DEF(soundeffectall,"si*"), // SoundEffectAll [Codemaster]
BUILDIN_DEF(strmobinfo,"ii"), // display mob data [Valaris]
BUILDIN_DEF(guardian,"siisi??"), // summon guardians
- BUILDIN_DEF(guardianinfo,"i"), // display guardian data [Valaris]
+ BUILDIN_DEF(guardianinfo,"sii"), // display guardian data [Valaris]
BUILDIN_DEF(petskillbonus,"iiii"), // [Valaris]
BUILDIN_DEF(petrecovery,"ii"), // [Valaris]
BUILDIN_DEF(petloot,"i"), // [Valaris]
diff --git a/src/map/status.c b/src/map/status.c
index 91ae9eb06..42695e1b4 100644
--- a/src/map/status.c
+++ b/src/map/status.c
@@ -834,11 +834,13 @@ int status_heal(struct block_list *bl,int hp,int sp, int flag)
) //End auto berserk.
status_change_end(bl,SC_PROVOKE,-1);
+ // send hp update to client
switch(bl->type) {
case BL_PC: pc_heal((TBL_PC*)bl,hp,sp,flag&2?1:0); break;
case BL_MOB: mob_heal((TBL_MOB*)bl,hp); break;
case BL_HOM: merc_hom_heal((TBL_HOM*)bl,hp,sp); break;
}
+
return hp+sp;
}
@@ -1446,10 +1448,7 @@ int status_calc_mob(struct mob_data* md, int first)
else {
status->max_hp += 2000 * gc->defense;
status->max_sp += 200 * gc->defense;
- if (md->guardian_data->number < MAX_GUARDIANS) //Spawn with saved HP
- status->hp = gc->guardian[md->guardian_data->number].hp;
- else //Emperium
- status->hp = status->max_hp;
+ status->hp = status->max_hp;
status->sp = status->max_sp;
}
status->batk += status->batk * 10*md->guardian_data->guardup_lv/100;