diff options
author | shennetsind <ind@henn.et> | 2013-07-29 15:09:31 -0300 |
---|---|---|
committer | shennetsind <ind@henn.et> | 2013-07-29 15:09:31 -0300 |
commit | 640c66779d8da4baa8af6bd0fee2583ec2b6143c (patch) | |
tree | e9df09e06fd350b36b57e4fc8751db9432d0fdc9 /src | |
parent | 30cce75c040c211fccb0cf53f2ff572509b5a0aa (diff) | |
download | hercules-640c66779d8da4baa8af6bd0fee2583ec2b6143c.tar.gz hercules-640c66779d8da4baa8af6bd0fee2583ec2b6143c.tar.bz2 hercules-640c66779d8da4baa8af6bd0fee2583ec2b6143c.tar.xz hercules-640c66779d8da4baa8af6bd0fee2583ec2b6143c.zip |
Fixed Bug #7597 / Follow up b7171479a47490ff80bf04849f763158d6d96fac
http://hercules.ws/board/tracker/issue-7597-server-crash/
Signed-off-by: shennetsind <ind@henn.et>
Diffstat (limited to 'src')
-rw-r--r-- | src/map/atcommand.c | 2 | ||||
-rw-r--r-- | src/map/clif.c | 2 | ||||
-rw-r--r-- | src/map/intif.c | 2 | ||||
-rw-r--r-- | src/map/map.c | 2 | ||||
-rw-r--r-- | src/map/mercenary.c | 1102 | ||||
-rw-r--r-- | src/map/mercenary.h | 190 | ||||
-rw-r--r-- | src/map/pc.c | 2 | ||||
-rw-r--r-- | src/map/script.c | 4 | ||||
-rw-r--r-- | src/map/status.c | 7 | ||||
-rw-r--r-- | src/map/unit.c | 2 |
10 files changed, 655 insertions, 660 deletions
diff --git a/src/map/atcommand.c b/src/map/atcommand.c index d8ca2389f..74dc04889 100644 --- a/src/map/atcommand.c +++ b/src/map/atcommand.c @@ -3598,7 +3598,7 @@ ACMD(reloadmobdb) { mob_reload(); read_petdb(); homun->reload(); - mercenary->read_mercenarydb(); + mercenary->read_db(); mercenary->read_skilldb(); elemental->reload_elementaldb(); clif->message(fd, msg_txt(98)); // Monster database has been reloaded. diff --git a/src/map/clif.c b/src/map/clif.c index 446adda28..117a315e9 100644 --- a/src/map/clif.c +++ b/src/map/clif.c @@ -15773,7 +15773,7 @@ void clif_parse_mercenary_action(int fd, struct map_session_data* sd) if( sd->md == NULL ) return; - if( option == 2 ) mercenary->merc_delete(sd->md, 2); + if( option == 2 ) mercenary->delete(sd->md, 2); } diff --git a/src/map/intif.c b/src/map/intif.c index 4d75dcbb7..b252d2607 100644 --- a/src/map/intif.c +++ b/src/map/intif.c @@ -1967,7 +1967,7 @@ int intif_parse_mercenary_received(int fd) return 0; } - mercenary->merc_data_received((struct s_mercenary*)RFIFOP(fd,5), RFIFOB(fd,4)); + mercenary->data_received((struct s_mercenary*)RFIFOP(fd,5), RFIFOB(fd,4)); return 0; } diff --git a/src/map/map.c b/src/map/map.c index 88e254d03..dbada2e96 100644 --- a/src/map/map.c +++ b/src/map/map.c @@ -5398,7 +5398,7 @@ int do_init(int argc, char *argv[]) storage->init(); do_init_pet(); homun->init(); - mercenary->do_init_mercenary(); + mercenary->init(); elemental->do_init_elemental(); do_init_quest(); do_init_npc(); diff --git a/src/map/mercenary.c b/src/map/mercenary.c index d6d5ce081..bb30bb0d1 100644 --- a/src/map/mercenary.c +++ b/src/map/mercenary.c @@ -1,551 +1,551 @@ -// Copyright (c) Hercules Dev Team, licensed under GNU GPL.
-// See the LICENSE file
-// Portions Copyright (c) Athena Dev Teams
-
-#include "../common/cbasetypes.h"
-#include "../common/malloc.h"
-#include "../common/socket.h"
-#include "../common/timer.h"
-#include "../common/nullpo.h"
-#include "../common/mmo.h"
-#include "../common/random.h"
-#include "../common/showmsg.h"
-#include "../common/strlib.h"
-#include "../common/utils.h"
-
-#include "log.h"
-#include "clif.h"
-#include "chrif.h"
-#include "intif.h"
-#include "itemdb.h"
-#include "map.h"
-#include "pc.h"
-#include "status.h"
-#include "skill.h"
-#include "mob.h"
-#include "pet.h"
-#include "battle.h"
-#include "party.h"
-#include "guild.h"
-#include "atcommand.h"
-#include "script.h"
-#include "npc.h"
-#include "trade.h"
-#include "unit.h"
-#include "mercenary.h"
-
-#include <stdio.h>
-#include <stdlib.h>
-#include <string.h>
-#include <math.h>
-
-struct s_mercenary_db mercenary_db[MAX_MERCENARY_CLASS]; // Mercenary Database
-
-int merc_search_index(int class_)
-{
- int i;
- ARR_FIND(0, MAX_MERCENARY_CLASS, i, mercenary_db[i].class_ == class_);
- return (i == MAX_MERCENARY_CLASS)?-1:i;
-}
-
-bool merc_class(int class_)
-{
- return (bool)(merc_search_index(class_) > -1);
-}
-
-struct view_data * merc_get_viewdata(int class_)
-{
- int i = merc_search_index(class_);
- if( i < 0 )
- return 0;
-
- return &mercenary_db[i].vd;
-}
-
-int merc_create(struct map_session_data *sd, int class_, unsigned int lifetime)
-{
- struct s_mercenary merc;
- struct s_mercenary_db *db;
- int i;
- nullpo_retr(0,sd);
-
- if( (i = merc_search_index(class_)) < 0 )
- return 0;
-
- db = &mercenary_db[i];
- memset(&merc,0,sizeof(struct s_mercenary));
-
- merc.char_id = sd->status.char_id;
- merc.class_ = class_;
- merc.hp = db->status.max_hp;
- merc.sp = db->status.max_sp;
- merc.life_time = lifetime;
-
- // Request Char Server to create this mercenary
- intif->mercenary_create(&merc);
-
- return 1;
-}
-
-int mercenary_get_lifetime(struct mercenary_data *md)
-{
- const struct TimerData * td;
- if( md == NULL || md->contract_timer == INVALID_TIMER )
- return 0;
-
- td = iTimer->get_timer(md->contract_timer);
- return (td != NULL) ? DIFF_TICK(td->tick, iTimer->gettick()) : 0;
-}
-
-int mercenary_get_guild(struct mercenary_data *md)
-{
- int class_;
-
- if( md == NULL || md->db == NULL )
- return -1;
-
- class_ = md->db->class_;
-
- if( class_ >= 6017 && class_ <= 6026 )
- return ARCH_MERC_GUILD;
- if( class_ >= 6027 && class_ <= 6036 )
- return SPEAR_MERC_GUILD;
- if( class_ >= 6037 && class_ <= 6046 )
- return SWORD_MERC_GUILD;
-
- return -1;
-}
-
-int mercenary_get_faith(struct mercenary_data *md)
-{
- struct map_session_data *sd;
- int class_;
-
- if( md == NULL || md->db == NULL || (sd = md->master) == NULL )
- return 0;
-
- class_ = md->db->class_;
-
- if( class_ >= 6017 && class_ <= 6026 )
- return sd->status.arch_faith;
- if( class_ >= 6027 && class_ <= 6036 )
- return sd->status.spear_faith;
- if( class_ >= 6037 && class_ <= 6046 )
- return sd->status.sword_faith;
-
- return 0;
-}
-
-int mercenary_set_faith(struct mercenary_data *md, int value)
-{
- struct map_session_data *sd;
- int class_, *faith;
-
- if( md == NULL || md->db == NULL || (sd = md->master) == NULL )
- return 0;
-
- class_ = md->db->class_;
-
- if( class_ >= 6017 && class_ <= 6026 )
- faith = &sd->status.arch_faith;
- else if( class_ >= 6027 && class_ <= 6036 )
- faith = &sd->status.spear_faith;
- else if( class_ >= 6037 && class_ <= 6046 )
- faith = &sd->status.sword_faith;
- else
- return 0;
-
- *faith += value;
- *faith = cap_value(*faith, 0, SHRT_MAX);
- clif->mercenary_updatestatus(sd, SP_MERCFAITH);
-
- return 0;
-}
-
-int mercenary_get_calls(struct mercenary_data *md)
-{
- struct map_session_data *sd;
- int class_;
-
- if( md == NULL || md->db == NULL || (sd = md->master) == NULL )
- return 0;
-
- class_ = md->db->class_;
-
- if( class_ >= 6017 && class_ <= 6026 )
- return sd->status.arch_calls;
- if( class_ >= 6027 && class_ <= 6036 )
- return sd->status.spear_calls;
- if( class_ >= 6037 && class_ <= 6046 )
- return sd->status.sword_calls;
-
- return 0;
-}
-
-int mercenary_set_calls(struct mercenary_data *md, int value)
-{
- struct map_session_data *sd;
- int class_, *calls;
-
- if( md == NULL || md->db == NULL || (sd = md->master) == NULL )
- return 0;
-
- class_ = md->db->class_;
-
- if( class_ >= 6017 && class_ <= 6026 )
- calls = &sd->status.arch_calls;
- else if( class_ >= 6027 && class_ <= 6036 )
- calls = &sd->status.spear_calls;
- else if( class_ >= 6037 && class_ <= 6046 )
- calls = &sd->status.sword_calls;
- else
- return 0;
-
- *calls += value;
- *calls = cap_value(*calls, 0, INT_MAX);
-
- return 0;
-}
-
-int mercenary_save(struct mercenary_data *md)
-{
- md->mercenary.hp = md->battle_status.hp;
- md->mercenary.sp = md->battle_status.sp;
- md->mercenary.life_time = mercenary->get_lifetime(md);
-
- intif->mercenary_save(&md->mercenary);
- return 1;
-}
-
-static int merc_contract_end(int tid, unsigned int tick, int id, intptr_t data)
-{
- struct map_session_data *sd;
- struct mercenary_data *md;
-
- if( (sd = iMap->id2sd(id)) == NULL )
- return 1;
- if( (md = sd->md) == NULL )
- return 1;
-
- if( md->contract_timer != tid )
- {
- ShowError("merc_contract_end %d != %d.\n", md->contract_timer, tid);
- return 0;
- }
-
- md->contract_timer = INVALID_TIMER;
- mercenary->merc_delete(md, 0); // Mercenary soldier's duty hour is over.
-
- return 0;
-}
-
-int merc_delete(struct mercenary_data *md, int reply)
-{
- struct map_session_data *sd = md->master;
- md->mercenary.life_time = 0;
-
- mercenary->merc_contract_stop(md);
-
- if( !sd )
- return unit_free(&md->bl, CLR_OUTSIGHT);
-
- if( md->devotion_flag )
- {
- md->devotion_flag = 0;
- status_change_end(&sd->bl, SC_DEVOTION, INVALID_TIMER);
- }
-
- switch( reply )
- {
- case 0: mercenary->set_faith(md, 1); break; // +1 Loyalty on Contract ends.
- case 1: mercenary->set_faith(md, -1); break; // -1 Loyalty on Mercenary killed
- }
-
- clif->mercenary_message(sd, reply);
- return unit_remove_map(&md->bl, CLR_OUTSIGHT);
-}
-
-void merc_contract_stop(struct mercenary_data *md)
-{
- nullpo_retv(md);
- if( md->contract_timer != INVALID_TIMER )
- iTimer->delete_timer(md->contract_timer, merc_contract_end);
- md->contract_timer = INVALID_TIMER;
-}
-
-void merc_contract_init(struct mercenary_data *md)
-{
- if( md->contract_timer == INVALID_TIMER )
- md->contract_timer = iTimer->add_timer(iTimer->gettick() + md->mercenary.life_time, merc_contract_end, md->master->bl.id, 0);
-
- md->regen.state.block = 0;
-}
-
-int merc_data_received(struct s_mercenary *merc, bool flag)
-{
- struct map_session_data *sd;
- struct mercenary_data *md;
- struct s_mercenary_db *db;
- int i = merc_search_index(merc->class_);
-
- if( (sd = iMap->charid2sd(merc->char_id)) == NULL )
- return 0;
- if( !flag || i < 0 )
- { // Not created - loaded - DB info
- sd->status.mer_id = 0;
- return 0;
- }
-
- db = &mercenary_db[i];
- if( !sd->md )
- {
- sd->md = md = (struct mercenary_data*)aCalloc(1,sizeof(struct mercenary_data));
- md->bl.type = BL_MER;
- md->bl.id = npc_get_new_npc_id();
- md->devotion_flag = 0;
-
- md->master = sd;
- md->db = db;
- memcpy(&md->mercenary, merc, sizeof(struct s_mercenary));
- iStatus->set_viewdata(&md->bl, md->mercenary.class_);
- iStatus->change_init(&md->bl);
- unit_dataset(&md->bl);
- md->ud.dir = sd->ud.dir;
-
- md->bl.m = sd->bl.m;
- md->bl.x = sd->bl.x;
- md->bl.y = sd->bl.y;
- unit_calc_pos(&md->bl, sd->bl.x, sd->bl.y, sd->ud.dir);
- md->bl.x = md->ud.to_x;
- md->bl.y = md->ud.to_y;
-
- iMap->addiddb(&md->bl);
- status_calc_mercenary(md,1);
- md->contract_timer = INVALID_TIMER;
- merc_contract_init(md);
- }
- else
- {
- memcpy(&sd->md->mercenary, merc, sizeof(struct s_mercenary));
- md = sd->md;
- }
-
- if( sd->status.mer_id == 0 )
- mercenary->set_calls(md, 1);
- sd->status.mer_id = merc->mercenary_id;
-
- if( md && md->bl.prev == NULL && sd->bl.prev != NULL )
- {
- iMap->addblock(&md->bl);
- clif->spawn(&md->bl);
- clif->mercenary_info(sd);
- clif->mercenary_skillblock(sd);
- }
-
- return 1;
-}
-
-void mercenary_heal(struct mercenary_data *md, int hp, int sp)
-{
- if( hp )
- clif->mercenary_updatestatus(md->master, SP_HP);
- if( sp )
- clif->mercenary_updatestatus(md->master, SP_SP);
-}
-
-int mercenary_dead(struct mercenary_data *md)
-{
- mercenary->merc_delete(md, 1);
- return 0;
-}
-
-int mercenary_killbonus(struct mercenary_data *md)
-{
- const enum sc_type scs[] = { SC_MER_FLEE, SC_MER_ATK, SC_MER_HP, SC_MER_SP, SC_MER_HIT };
- int index = rnd() % ARRAYLENGTH(scs);
-
- sc_start(&md->bl, scs[index], 100, rnd() % 5, 600000);
- return 0;
-}
-
-int mercenary_kills(struct mercenary_data *md)
-{
- md->mercenary.kill_count++;
- md->mercenary.kill_count = cap_value(md->mercenary.kill_count, 0, INT_MAX);
-
- if( (md->mercenary.kill_count % 50) == 0 )
- {
- mercenary->set_faith(md, 1);
- mercenary_killbonus(md);
- }
-
- if( md->master )
- clif->mercenary_updatestatus(md->master, SP_MERCKILLS);
-
- return 0;
-}
-
-int mercenary_checkskill(struct mercenary_data *md, uint16 skill_id)
-{
- int i = skill_id - MC_SKILLBASE;
-
- if( !md || !md->db )
- return 0;
- if( md->db->skill[i].id == skill_id )
- return md->db->skill[i].lv;
-
- return 0;
-}
-
-static bool read_mercenarydb_sub(char* str[], int columns, int current)
-{
- int ele;
- struct s_mercenary_db *db;
- struct status_data *status;
-
- db = &mercenary_db[current];
- db->class_ = atoi(str[0]);
- safestrncpy(db->sprite, str[1], NAME_LENGTH);
- safestrncpy(db->name, str[2], NAME_LENGTH);
- db->lv = atoi(str[3]);
-
- status = &db->status;
- db->vd.class_ = db->class_;
-
- status->max_hp = atoi(str[4]);
- status->max_sp = atoi(str[5]);
- status->rhw.range = atoi(str[6]);
- status->rhw.atk = atoi(str[7]);
- status->rhw.atk2 = status->rhw.atk + atoi(str[8]);
- status->def = atoi(str[9]);
- status->mdef = atoi(str[10]);
- status->str = atoi(str[11]);
- status->agi = atoi(str[12]);
- status->vit = atoi(str[13]);
- status->int_ = atoi(str[14]);
- status->dex = atoi(str[15]);
- status->luk = atoi(str[16]);
- db->range2 = atoi(str[17]);
- db->range3 = atoi(str[18]);
- status->size = atoi(str[19]);
- status->race = atoi(str[20]);
-
- ele = atoi(str[21]);
- status->def_ele = ele%10;
- status->ele_lv = ele/20;
- if( status->def_ele >= ELE_MAX )
- {
- ShowWarning("Mercenary %d has invalid element type %d (max element is %d)\n", db->class_, status->def_ele, ELE_MAX - 1);
- status->def_ele = ELE_NEUTRAL;
- }
- if( status->ele_lv < 1 || status->ele_lv > 4 )
- {
- ShowWarning("Mercenary %d has invalid element level %d (max is 4)\n", db->class_, status->ele_lv);
- status->ele_lv = 1;
- }
-
- status->aspd_rate = 1000;
- status->speed = atoi(str[22]);
- status->adelay = atoi(str[23]);
- status->amotion = atoi(str[24]);
- status->dmotion = atoi(str[25]);
-
- return true;
-}
-
-int read_mercenarydb(void)
-{
- memset(mercenary_db,0,sizeof(mercenary_db));
- sv->readdb(iMap->db_path, "mercenary_db.txt", ',', 26, 26, MAX_MERCENARY_CLASS, &read_mercenarydb_sub);
-
- return 0;
-}
-
-static bool read_mercenary_skilldb_sub(char* str[], int columns, int current)
-{// <merc id>,<skill id>,<skill level>
- struct s_mercenary_db *db;
- int i, class_;
- uint16 skill_id, skill_lv;
-
- class_ = atoi(str[0]);
- ARR_FIND(0, MAX_MERCENARY_CLASS, i, class_ == mercenary_db[i].class_);
- if( i == MAX_MERCENARY_CLASS )
- {
- ShowError("read_mercenary_skilldb : Class %d not found in mercenary_db for skill entry.\n", class_);
- return false;
- }
-
- skill_id = atoi(str[1]);
- if( skill_id < MC_SKILLBASE || skill_id >= MC_SKILLBASE + MAX_MERCSKILL )
- {
- ShowError("read_mercenary_skilldb : Skill %d out of range.\n", skill_id);
- return false;
- }
-
- db = &mercenary_db[i];
- skill_lv = atoi(str[2]);
-
- i = skill_id - MC_SKILLBASE;
- db->skill[i].id = skill_id;
- db->skill[i].lv = skill_lv;
-
- return true;
-}
-
-int read_mercenary_skilldb(void)
-{
- sv->readdb(iMap->db_path, "mercenary_skill_db.txt", ',', 3, 3, -1, &read_mercenary_skilldb_sub);
-
- return 0;
-}
-
-int do_init_mercenary(void)
-{
- mercenary->read_mercenarydb();
- mercenary->read_skilldb();
-
- //add_timer_func_list(mercenary_contract, "mercenary_contract");
- return 0;
-}
-
-int do_final_mercenary(void);
-
-/*=====================================
-* Default Functions : mercenary.h
-* Generated by HerculesInterfaceMaker
-* created by Susu
-*-------------------------------------*/
-void mercenary_defaults(void) {
- mercenary = &mercenary_s;
-
/* vars */
-
- mercenary->mercenary_db[MAX_MERCENARY_CLASS] = mercenary_db[MAX_MERCENARY_CLASS];
-
/* funcs */
-
- mercenary->merc_class = merc_class;
- mercenary->merc_get_viewdata = merc_get_viewdata;
-
- mercenary->merc_create = merc_create;
- mercenary->merc_data_received = merc_data_received;
- mercenary->save = mercenary_save;
-
- mercenary->heal = mercenary_heal;
- mercenary->dead = mercenary_dead;
-
- mercenary->merc_delete = merc_delete;
- mercenary->merc_contract_stop = merc_contract_stop;
-
- mercenary->get_lifetime = mercenary_get_lifetime;
- mercenary->get_guild = mercenary_get_guild;
- mercenary->get_faith = mercenary_get_faith;
- mercenary->set_faith = mercenary_set_faith;
- mercenary->get_calls = mercenary_get_calls;
- mercenary->set_calls = mercenary_set_calls;
- mercenary->kills = mercenary_kills;
-
- mercenary->checkskill = mercenary_checkskill;
- mercenary->read_mercenarydb = read_mercenarydb;
- mercenary->read_skilldb = read_mercenary_skilldb;
-
- mercenary->do_init_mercenary = do_init_mercenary;
-}
+// Copyright (c) Hercules Dev Team, licensed under GNU GPL. +// See the LICENSE file +// Portions Copyright (c) Athena Dev Teams + +#include "../common/cbasetypes.h" +#include "../common/malloc.h" +#include "../common/socket.h" +#include "../common/timer.h" +#include "../common/nullpo.h" +#include "../common/mmo.h" +#include "../common/random.h" +#include "../common/showmsg.h" +#include "../common/strlib.h" +#include "../common/utils.h" + +#include "log.h" +#include "clif.h" +#include "chrif.h" +#include "intif.h" +#include "itemdb.h" +#include "map.h" +#include "pc.h" +#include "status.h" +#include "skill.h" +#include "mob.h" +#include "pet.h" +#include "battle.h" +#include "party.h" +#include "guild.h" +#include "atcommand.h" +#include "script.h" +#include "npc.h" +#include "trade.h" +#include "unit.h" +#include "mercenary.h" + +#include <stdio.h> +#include <stdlib.h> +#include <string.h> +#include <math.h> + +struct mercenary_interface mercenary_s; + +int merc_search_index(int class_) +{ + int i; + ARR_FIND(0, MAX_MERCENARY_CLASS, i, mercenary->db[i].class_ == class_); + return (i == MAX_MERCENARY_CLASS)?-1:i; +} + +bool merc_class(int class_) +{ + return (bool)(merc_search_index(class_) > -1); +} + +struct view_data * merc_get_viewdata(int class_) +{ + int i = merc_search_index(class_); + if( i < 0 ) + return 0; + + return &mercenary->db[i].vd; +} + +int merc_create(struct map_session_data *sd, int class_, unsigned int lifetime) +{ + struct s_mercenary merc; + struct s_mercenary_db *db; + int i; + nullpo_retr(0,sd); + + if( (i = merc_search_index(class_)) < 0 ) + return 0; + + db = &mercenary->db[i]; + memset(&merc,0,sizeof(struct s_mercenary)); + + merc.char_id = sd->status.char_id; + merc.class_ = class_; + merc.hp = db->status.max_hp; + merc.sp = db->status.max_sp; + merc.life_time = lifetime; + + // Request Char Server to create this mercenary + intif->mercenary_create(&merc); + + return 1; +} + +int mercenary_get_lifetime(struct mercenary_data *md) +{ + const struct TimerData * td; + if( md == NULL || md->contract_timer == INVALID_TIMER ) + return 0; + + td = iTimer->get_timer(md->contract_timer); + return (td != NULL) ? DIFF_TICK(td->tick, iTimer->gettick()) : 0; +} + +int mercenary_get_guild(struct mercenary_data *md) +{ + int class_; + + if( md == NULL || md->db == NULL ) + return -1; + + class_ = md->db->class_; + + if( class_ >= 6017 && class_ <= 6026 ) + return ARCH_MERC_GUILD; + if( class_ >= 6027 && class_ <= 6036 ) + return SPEAR_MERC_GUILD; + if( class_ >= 6037 && class_ <= 6046 ) + return SWORD_MERC_GUILD; + + return -1; +} + +int mercenary_get_faith(struct mercenary_data *md) +{ + struct map_session_data *sd; + int class_; + + if( md == NULL || md->db == NULL || (sd = md->master) == NULL ) + return 0; + + class_ = md->db->class_; + + if( class_ >= 6017 && class_ <= 6026 ) + return sd->status.arch_faith; + if( class_ >= 6027 && class_ <= 6036 ) + return sd->status.spear_faith; + if( class_ >= 6037 && class_ <= 6046 ) + return sd->status.sword_faith; + + return 0; +} + +int mercenary_set_faith(struct mercenary_data *md, int value) +{ + struct map_session_data *sd; + int class_, *faith; + + if( md == NULL || md->db == NULL || (sd = md->master) == NULL ) + return 0; + + class_ = md->db->class_; + + if( class_ >= 6017 && class_ <= 6026 ) + faith = &sd->status.arch_faith; + else if( class_ >= 6027 && class_ <= 6036 ) + faith = &sd->status.spear_faith; + else if( class_ >= 6037 && class_ <= 6046 ) + faith = &sd->status.sword_faith; + else + return 0; + + *faith += value; + *faith = cap_value(*faith, 0, SHRT_MAX); + clif->mercenary_updatestatus(sd, SP_MERCFAITH); + + return 0; +} + +int mercenary_get_calls(struct mercenary_data *md) +{ + struct map_session_data *sd; + int class_; + + if( md == NULL || md->db == NULL || (sd = md->master) == NULL ) + return 0; + + class_ = md->db->class_; + + if( class_ >= 6017 && class_ <= 6026 ) + return sd->status.arch_calls; + if( class_ >= 6027 && class_ <= 6036 ) + return sd->status.spear_calls; + if( class_ >= 6037 && class_ <= 6046 ) + return sd->status.sword_calls; + + return 0; +} + +int mercenary_set_calls(struct mercenary_data *md, int value) +{ + struct map_session_data *sd; + int class_, *calls; + + if( md == NULL || md->db == NULL || (sd = md->master) == NULL ) + return 0; + + class_ = md->db->class_; + + if( class_ >= 6017 && class_ <= 6026 ) + calls = &sd->status.arch_calls; + else if( class_ >= 6027 && class_ <= 6036 ) + calls = &sd->status.spear_calls; + else if( class_ >= 6037 && class_ <= 6046 ) + calls = &sd->status.sword_calls; + else + return 0; + + *calls += value; + *calls = cap_value(*calls, 0, INT_MAX); + + return 0; +} + +int mercenary_save(struct mercenary_data *md) +{ + md->mercenary.hp = md->battle_status.hp; + md->mercenary.sp = md->battle_status.sp; + md->mercenary.life_time = mercenary->get_lifetime(md); + + intif->mercenary_save(&md->mercenary); + return 1; +} + +static int merc_contract_end(int tid, unsigned int tick, int id, intptr_t data) +{ + struct map_session_data *sd; + struct mercenary_data *md; + + if( (sd = iMap->id2sd(id)) == NULL ) + return 1; + if( (md = sd->md) == NULL ) + return 1; + + if( md->contract_timer != tid ) + { + ShowError("merc_contract_end %d != %d.\n", md->contract_timer, tid); + return 0; + } + + md->contract_timer = INVALID_TIMER; + mercenary->delete(md, 0); // Mercenary soldier's duty hour is over. + + return 0; +} + +int merc_delete(struct mercenary_data *md, int reply) +{ + struct map_session_data *sd = md->master; + md->mercenary.life_time = 0; + + mercenary->contract_stop(md); + + if( !sd ) + return unit_free(&md->bl, CLR_OUTSIGHT); + + if( md->devotion_flag ) + { + md->devotion_flag = 0; + status_change_end(&sd->bl, SC_DEVOTION, INVALID_TIMER); + } + + switch( reply ) + { + case 0: mercenary->set_faith(md, 1); break; // +1 Loyalty on Contract ends. + case 1: mercenary->set_faith(md, -1); break; // -1 Loyalty on Mercenary killed + } + + clif->mercenary_message(sd, reply); + return unit_remove_map(&md->bl, CLR_OUTSIGHT); +} + +void merc_contract_stop(struct mercenary_data *md) +{ + nullpo_retv(md); + if( md->contract_timer != INVALID_TIMER ) + iTimer->delete_timer(md->contract_timer, merc_contract_end); + md->contract_timer = INVALID_TIMER; +} + +void merc_contract_init(struct mercenary_data *md) +{ + if( md->contract_timer == INVALID_TIMER ) + md->contract_timer = iTimer->add_timer(iTimer->gettick() + md->mercenary.life_time, merc_contract_end, md->master->bl.id, 0); + + md->regen.state.block = 0; +} + +int merc_data_received(struct s_mercenary *merc, bool flag) +{ + struct map_session_data *sd; + struct mercenary_data *md; + struct s_mercenary_db *db; + int i = merc_search_index(merc->class_); + + if( (sd = iMap->charid2sd(merc->char_id)) == NULL ) + return 0; + if( !flag || i < 0 ) + { // Not created - loaded - DB info + sd->status.mer_id = 0; + return 0; + } + + db = &mercenary->db[i]; + if( !sd->md ) + { + sd->md = md = (struct mercenary_data*)aCalloc(1,sizeof(struct mercenary_data)); + md->bl.type = BL_MER; + md->bl.id = npc_get_new_npc_id(); + md->devotion_flag = 0; + + md->master = sd; + md->db = db; + memcpy(&md->mercenary, merc, sizeof(struct s_mercenary)); + iStatus->set_viewdata(&md->bl, md->mercenary.class_); + iStatus->change_init(&md->bl); + unit_dataset(&md->bl); + md->ud.dir = sd->ud.dir; + + md->bl.m = sd->bl.m; + md->bl.x = sd->bl.x; + md->bl.y = sd->bl.y; + unit_calc_pos(&md->bl, sd->bl.x, sd->bl.y, sd->ud.dir); + md->bl.x = md->ud.to_x; + md->bl.y = md->ud.to_y; + + iMap->addiddb(&md->bl); + status_calc_mercenary(md,1); + md->contract_timer = INVALID_TIMER; + merc_contract_init(md); + } + else + { + memcpy(&sd->md->mercenary, merc, sizeof(struct s_mercenary)); + md = sd->md; + } + + if( sd->status.mer_id == 0 ) + mercenary->set_calls(md, 1); + sd->status.mer_id = merc->mercenary_id; + + if( md && md->bl.prev == NULL && sd->bl.prev != NULL ) + { + iMap->addblock(&md->bl); + clif->spawn(&md->bl); + clif->mercenary_info(sd); + clif->mercenary_skillblock(sd); + } + + return 1; +} + +void mercenary_heal(struct mercenary_data *md, int hp, int sp) +{ + if( hp ) + clif->mercenary_updatestatus(md->master, SP_HP); + if( sp ) + clif->mercenary_updatestatus(md->master, SP_SP); +} + +int mercenary_dead(struct mercenary_data *md) +{ + mercenary->delete(md, 1); + return 0; +} + +int mercenary_killbonus(struct mercenary_data *md) +{ + const enum sc_type scs[] = { SC_MER_FLEE, SC_MER_ATK, SC_MER_HP, SC_MER_SP, SC_MER_HIT }; + int index = rnd() % ARRAYLENGTH(scs); + + sc_start(&md->bl, scs[index], 100, rnd() % 5, 600000); + return 0; +} + +int mercenary_kills(struct mercenary_data *md) +{ + md->mercenary.kill_count++; + md->mercenary.kill_count = cap_value(md->mercenary.kill_count, 0, INT_MAX); + + if( (md->mercenary.kill_count % 50) == 0 ) + { + mercenary->set_faith(md, 1); + mercenary_killbonus(md); + } + + if( md->master ) + clif->mercenary_updatestatus(md->master, SP_MERCKILLS); + + return 0; +} + +int mercenary_checkskill(struct mercenary_data *md, uint16 skill_id) +{ + int i = skill_id - MC_SKILLBASE; + + if( !md || !md->db ) + return 0; + if( md->db->skill[i].id == skill_id ) + return md->db->skill[i].lv; + + return 0; +} + +static bool read_mercenarydb_sub(char* str[], int columns, int current) +{ + int ele; + struct s_mercenary_db *db; + struct status_data *status; + + db = &mercenary->db[current]; + db->class_ = atoi(str[0]); + safestrncpy(db->sprite, str[1], NAME_LENGTH); + safestrncpy(db->name, str[2], NAME_LENGTH); + db->lv = atoi(str[3]); + + status = &db->status; + db->vd.class_ = db->class_; + + status->max_hp = atoi(str[4]); + status->max_sp = atoi(str[5]); + status->rhw.range = atoi(str[6]); + status->rhw.atk = atoi(str[7]); + status->rhw.atk2 = status->rhw.atk + atoi(str[8]); + status->def = atoi(str[9]); + status->mdef = atoi(str[10]); + status->str = atoi(str[11]); + status->agi = atoi(str[12]); + status->vit = atoi(str[13]); + status->int_ = atoi(str[14]); + status->dex = atoi(str[15]); + status->luk = atoi(str[16]); + db->range2 = atoi(str[17]); + db->range3 = atoi(str[18]); + status->size = atoi(str[19]); + status->race = atoi(str[20]); + + ele = atoi(str[21]); + status->def_ele = ele%10; + status->ele_lv = ele/20; + if( status->def_ele >= ELE_MAX ) + { + ShowWarning("Mercenary %d has invalid element type %d (max element is %d)\n", db->class_, status->def_ele, ELE_MAX - 1); + status->def_ele = ELE_NEUTRAL; + } + if( status->ele_lv < 1 || status->ele_lv > 4 ) + { + ShowWarning("Mercenary %d has invalid element level %d (max is 4)\n", db->class_, status->ele_lv); + status->ele_lv = 1; + } + + status->aspd_rate = 1000; + status->speed = atoi(str[22]); + status->adelay = atoi(str[23]); + status->amotion = atoi(str[24]); + status->dmotion = atoi(str[25]); + + return true; +} + +int read_mercenarydb(void) { + memset(mercenary->db,0,sizeof(mercenary->db)); + sv->readdb(iMap->db_path, "mercenary_db.txt", ',', 26, 26, MAX_MERCENARY_CLASS, &read_mercenarydb_sub); + + return 0; +} + +static bool read_mercenary_skilldb_sub(char* str[], int columns, int current) +{// <merc id>,<skill id>,<skill level> + struct s_mercenary_db *db; + int i, class_; + uint16 skill_id, skill_lv; + + class_ = atoi(str[0]); + ARR_FIND(0, MAX_MERCENARY_CLASS, i, class_ == mercenary->db[i].class_); + if( i == MAX_MERCENARY_CLASS ) + { + ShowError("read_mercenary_skilldb : Class %d not found in mercenary_db for skill entry.\n", class_); + return false; + } + + skill_id = atoi(str[1]); + if( skill_id < MC_SKILLBASE || skill_id >= MC_SKILLBASE + MAX_MERCSKILL ) + { + ShowError("read_mercenary_skilldb : Skill %d out of range.\n", skill_id); + return false; + } + + db = &mercenary->db[i]; + skill_lv = atoi(str[2]); + + i = skill_id - MC_SKILLBASE; + db->skill[i].id = skill_id; + db->skill[i].lv = skill_lv; + + return true; +} + +int read_mercenary_skilldb(void) +{ + sv->readdb(iMap->db_path, "mercenary_skill_db.txt", ',', 3, 3, -1, &read_mercenary_skilldb_sub); + + return 0; +} + +int do_init_mercenary(void) +{ + mercenary->read_db(); + mercenary->read_skilldb(); + + //add_timer_func_list(mercenary_contract, "mercenary_contract"); + return 0; +} + +int do_final_mercenary(void); + +/*===================================== +* Default Functions : mercenary.h +* Generated by HerculesInterfaceMaker +* created by Susu +*-------------------------------------*/ +void mercenary_defaults(void) { + mercenary = &mercenary_s; + + /* vars */ + memset(mercenary->db,0,sizeof(mercenary->db)); + + /* funcs */ + + mercenary->init = do_init_mercenary; + + mercenary->class = merc_class; + mercenary->get_viewdata = merc_get_viewdata; + + mercenary->create = merc_create; + mercenary->data_received = merc_data_received; + mercenary->save = mercenary_save; + + mercenary->heal = mercenary_heal; + mercenary->dead = mercenary_dead; + + mercenary->delete = merc_delete; + mercenary->contract_stop = merc_contract_stop; + + mercenary->get_lifetime = mercenary_get_lifetime; + mercenary->get_guild = mercenary_get_guild; + mercenary->get_faith = mercenary_get_faith; + mercenary->set_faith = mercenary_set_faith; + mercenary->get_calls = mercenary_get_calls; + mercenary->set_calls = mercenary_set_calls; + mercenary->kills = mercenary_kills; + + mercenary->checkskill = mercenary_checkskill; + mercenary->read_db = read_mercenarydb; + mercenary->read_skilldb = read_mercenary_skilldb; +} diff --git a/src/map/mercenary.h b/src/map/mercenary.h index 5c69f9b60..b59a1c808 100644 --- a/src/map/mercenary.h +++ b/src/map/mercenary.h @@ -1,97 +1,93 @@ -// Copyright (c) Athena Dev Teams - Licensed under GNU GPL
-// For more information, see LICENCE in the main folder
-#ifndef _MERCENARY_H_
-#define _MERCENARY_H_
-#include "status.h" // struct status_data, struct status_change
-#include "unit.h" // struct unit_data
-// number of cells that a mercenary can walk to from it's master before being warped
-#define MAX_MER_DISTANCE 15
-enum {
- ARCH_MERC_GUILD,
- SPEAR_MERC_GUILD,
- SWORD_MERC_GUILD,
-};
-struct s_mercenary_db {
- int class_;
- char sprite[NAME_LENGTH], name[NAME_LENGTH];
- unsigned short lv;
- short range2, range3;
- struct status_data status;
- struct view_data vd;
- struct {
- unsigned short id, lv;
- } skill[MAX_MERCSKILL];
-};
-struct mercenary_data {
- struct block_list bl;
- struct unit_data ud;
- struct view_data *vd;
- struct status_data base_status, battle_status;
- struct status_change sc;
- struct regen_data regen;
- struct s_mercenary_db *db;
- struct s_mercenary mercenary;
- char blockskill[MAX_SKILL];
-
- struct map_session_data *master;
- int contract_timer;
-
- unsigned devotion_flag : 1;
- unsigned int masterteleport_timer;
-};
-
-
-
-
-
-
-
-/**
- * atcommand.c required
- **/
-
-
-/*=====================================
-* Interface : mercenary.h
-* Generated by HerculesInterfaceMaker
-* created by Susu
-*-------------------------------------*/
-struct mercenary_interface {
-
/* vars */
-
- struct s_mercenary_db mercenary_db[MAX_MERCENARY_CLASS];
-
/* funcs */
-
- bool (*merc_class) (int class_);
- struct view_data * (*merc_get_viewdata) (int class_);
-
- int (*merc_create) (struct map_session_data *sd, int class_, unsigned int lifetime);
- int (*merc_data_received) (struct s_mercenary *merc, bool flag);
- int (*save) (struct mercenary_data *md);
-
- void (*heal) (struct mercenary_data *md, int hp, int sp);
- int (*dead) (struct mercenary_data *md);
-
- int (*merc_delete) (struct mercenary_data *md, int reply);
- void (*merc_contract_stop) (struct mercenary_data *md);
-
- int (*get_lifetime) (struct mercenary_data *md);
- int (*get_guild) (struct mercenary_data *md);
- int (*get_faith) (struct mercenary_data *md);
- int (*set_faith) (struct mercenary_data *md, int value);
- int (*get_calls) (struct mercenary_data *md);
- int (*set_calls) (struct mercenary_data *md, int value);
- int (*kills) (struct mercenary_data *md);
-
- int (*checkskill) (struct mercenary_data *md, uint16 skill_id);
- int (*read_mercenarydb) (void);
- int (*read_skilldb) (void);
-
- int (*do_init_mercenary) (void);
-} mercenary_s;
-
-struct mercenary_interface *mercenary;
-
-void mercenary_defaults(void);
-
-#endif /* _MERCENARY_H_ */
+// Copyright (c) Athena Dev Teams - Licensed under GNU GPL +// For more information, see LICENCE in the main folder +#ifndef _MERCENARY_H_ +#define _MERCENARY_H_ + +#include "status.h" // struct status_data, struct status_change +#include "unit.h" // struct unit_data + +// number of cells that a mercenary can walk to from it's master before being warped +#define MAX_MER_DISTANCE 15 + +enum { + ARCH_MERC_GUILD, + SPEAR_MERC_GUILD, + SWORD_MERC_GUILD, +}; + +struct s_mercenary_db { + int class_; + char sprite[NAME_LENGTH], name[NAME_LENGTH]; + unsigned short lv; + short range2, range3; + struct status_data status; + struct view_data vd; + struct { + unsigned short id, lv; + } skill[MAX_MERCSKILL]; +}; + +struct mercenary_data { + struct block_list bl; + struct unit_data ud; + struct view_data *vd; + struct status_data base_status, battle_status; + struct status_change sc; + struct regen_data regen; + struct s_mercenary_db *db; + struct s_mercenary mercenary; + char blockskill[MAX_SKILL]; + + struct map_session_data *master; + int contract_timer; + + unsigned devotion_flag : 1; + unsigned int masterteleport_timer; +}; + +/*===================================== +* Interface : mercenary.h +* Generated by HerculesInterfaceMaker +* created by Susu +*-------------------------------------*/ +struct mercenary_interface { + + /* vars */ + + struct s_mercenary_db db[MAX_MERCENARY_CLASS]; + + /* funcs */ + + int (*init) (void); + + bool (*class) (int class_); + struct view_data * (*get_viewdata) (int class_); + + int (*create) (struct map_session_data *sd, int class_, unsigned int lifetime); + int (*data_received) (struct s_mercenary *merc, bool flag); + int (*save) (struct mercenary_data *md); + + void (*heal) (struct mercenary_data *md, int hp, int sp); + int (*dead) (struct mercenary_data *md); + + int (*delete) (struct mercenary_data *md, int reply); + void (*contract_stop) (struct mercenary_data *md); + + int (*get_lifetime) (struct mercenary_data *md); + int (*get_guild) (struct mercenary_data *md); + int (*get_faith) (struct mercenary_data *md); + int (*set_faith) (struct mercenary_data *md, int value); + int (*get_calls) (struct mercenary_data *md); + int (*set_calls) (struct mercenary_data *md, int value); + int (*kills) (struct mercenary_data *md); + + int (*checkskill) (struct mercenary_data *md, uint16 skill_id); + int (*read_db) (void); + int (*read_skilldb) (void); +}; + +struct mercenary_interface *mercenary; + +void mercenary_defaults(void); + +#endif /* _MERCENARY_H_ */ diff --git a/src/map/pc.c b/src/map/pc.c index 0a815cb24..35a283752 100644 --- a/src/map/pc.c +++ b/src/map/pc.c @@ -6739,7 +6739,7 @@ int pc_dead(struct map_session_data *sd,struct block_list *src) { } if( sd->md ) - mercenary->merc_delete(sd->md, 3); // Your mercenary soldier has ran away. + mercenary->delete(sd->md, 3); // Your mercenary soldier has ran away. if( sd->ed ) elemental->delete(sd->ed, 0); diff --git a/src/map/script.c b/src/map/script.c index e9a93918b..2a917236a 100644 --- a/src/map/script.c +++ b/src/map/script.c @@ -15396,11 +15396,11 @@ BUILDIN(mercenary_create) class_ = script_getnum(st,2); - if( !mercenary->merc_class(class_) ) + if( !mercenary->class(class_) ) return true; contract_time = script_getnum(st,3); - mercenary->merc_create(sd, class_, contract_time); + mercenary->create(sd, class_, contract_time); return true; } diff --git a/src/map/status.c b/src/map/status.c index 1ea86e163..c253bb74f 100644 --- a/src/map/status.c +++ b/src/map/status.c @@ -6055,8 +6055,8 @@ void status_set_viewdata(struct block_list *bl, int class_) vd = npc_get_viewdata(class_); else if (homdb_checkid(class_)) vd = homun->get_viewdata(class_); - else if (mercenary->merc_class(class_)) - vd = mercenary->merc_get_viewdata(class_); + else if (mercenary->class(class_)) + vd = mercenary->get_viewdata(class_); else if (elemental->class(class_)) vd = elemental->get_viewdata(class_); else @@ -8331,7 +8331,7 @@ int status_change_start(struct block_list* bl,enum sc_type type,int rate,int val if( pc_isfalcon(sd) ) pc->setoption(sd, sd->sc.option&~OPTION_FALCON); if( sd->status.pet_id > 0 ) pet_menu(sd, 3); if( homun_alive(sd->hd) ) homun->vaporize(sd,1); - if( sd->md ) mercenary->merc_delete(sd->md,3); + if( sd->md ) mercenary->delete(sd->md,3); } break; case SC__LAZINESS: @@ -8350,7 +8350,6 @@ int status_change_start(struct block_list* bl,enum sc_type type,int rate,int val sc_start(bl,SC_NOEQUIPWEAPON,100,val1,tick); sc_start(bl,SC_NOEQUIPSHIELD,100,val1,tick); break; - break; case SC_GN_CARTBOOST: if( val1 < 3 ) val2 = 50; diff --git a/src/map/unit.c b/src/map/unit.c index 1860be342..9becb128e 100644 --- a/src/map/unit.c +++ b/src/map/unit.c @@ -2542,7 +2542,7 @@ int unit_free(struct block_list *bl, clr_type clrtype) if( sd ) sd->md = NULL; - mercenary->merc_contract_stop(md); + mercenary->contract_stop(md); break; } case BL_ELEM: { |