From fe2f840e5d6cb4230ba02c47132790d067b3814d Mon Sep 17 00:00:00 2001 From: Haru Date: Tue, 27 Aug 2013 09:01:53 +0200 Subject: Corrected line endings and BOM issues with several files - Ensured final end-of-line character in every file. - Corrected cases of mixed line endings (mostly CR and CRLF within the same file.) - Removed extra BOM from some scripts, since it causes a parsing error. Signed-off-by: Haru --- src/CMakeLists.txt | 2 +- src/map/chat.c | 894 ++++++++++---------- src/map/chat.h | 112 +-- src/map/duel.c | 408 ++++----- src/map/elemental.c | 1968 ++++++++++++++++++++++---------------------- src/map/elemental.h | 212 ++--- src/map/intif.h | 256 +++--- src/plugins/CMakeLists.txt | 2 +- src/plugins/db2sql.c | 2 +- src/plugins/sample.c | 2 +- 10 files changed, 1929 insertions(+), 1929 deletions(-) (limited to 'src') diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 100958358..0c120f99a 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -17,4 +17,4 @@ add_subdirectory( login ) add_subdirectory( char ) add_subdirectory( map ) add_subdirectory( tool ) -add_subdirectory( plugins ) \ No newline at end of file +add_subdirectory( plugins ) diff --git a/src/map/chat.c b/src/map/chat.c index 75ae3681b..3a76dd157 100644 --- a/src/map/chat.c +++ b/src/map/chat.c @@ -1,447 +1,447 @@ -// Copyright (c) Athena Dev Teams - Licensed under GNU GPL -// For more information, see LICENCE in the main folder - -#include "../common/cbasetypes.h" -#include "../common/malloc.h" -#include "../common/nullpo.h" -#include "../common/showmsg.h" -#include "../common/strlib.h" -#include "../common/mmo.h" -#include "atcommand.h" // msg_txt() -#include "battle.h" // struct battle_config -#include "clif.h" -#include "map.h" -#include "npc.h" // npc_event_do() -#include "pc.h" -#include "skill.h" // ext_skill_unit_onplace() -#include "chat.h" - -#include -#include - - -int chat_triggerevent(struct chat_data *cd); // forward declaration - -/// Initializes a chatroom object (common functionality for both pc and npc chatrooms). -/// Returns a chatroom object on success, or NULL on failure. -static struct chat_data* chat_createchat(struct block_list* bl, const char* title, const char* pass, int limit, bool pub, int trigger, const char* ev, int zeny, int minLvl, int maxLvl) -{ - struct chat_data* cd; - nullpo_retr(NULL, bl); - - cd = (struct chat_data *) aMalloc(sizeof(struct chat_data)); - - safestrncpy(cd->title, title, sizeof(cd->title)); - safestrncpy(cd->pass, pass, sizeof(cd->pass)); - cd->pub = pub; - cd->users = 0; - cd->limit = min(limit, ARRAYLENGTH(cd->usersd)); - cd->trigger = trigger; - cd->zeny = zeny; - cd->minLvl = minLvl; - cd->maxLvl = maxLvl; - memset(cd->usersd, 0, sizeof(cd->usersd)); - cd->owner = bl; - safestrncpy(cd->npc_event, ev, sizeof(cd->npc_event)); - - cd->bl.id = iMap->get_new_object_id(); - cd->bl.m = bl->m; - cd->bl.x = bl->x; - cd->bl.y = bl->y; - cd->bl.type = BL_CHAT; - cd->bl.next = cd->bl.prev = NULL; - - if( cd->bl.id == 0 ) - { - aFree(cd); - cd = NULL; - } - - iMap->addiddb(&cd->bl); - - if( bl->type != BL_NPC ) - cd->kick_list = idb_alloc(DB_OPT_BASE); - - return cd; -} - -/*========================================== - * player chatroom creation - *------------------------------------------*/ -int chat_createpcchat(struct map_session_data* sd, const char* title, const char* pass, int limit, bool pub) -{ - struct chat_data* cd; - nullpo_ret(sd); - - if( sd->chatID ) - return 0; //Prevent people abusing the chat system by creating multiple chats, as pointed out by End of Exam. [Skotlex] - - if( sd->state.vending || sd->state.buyingstore ) - {// not chat, when you already have a store open - return 0; - } - - if( map[sd->bl.m].flag.nochat ) - { - clif->message(sd->fd, msg_txt(281)); - return 0; //Can't create chatrooms on this map. - } - - if( iMap->getcell(sd->bl.m,sd->bl.x,sd->bl.y,CELL_CHKNOCHAT) ) - { - clif->message (sd->fd, msg_txt(665)); - return 0; - } - - pc_stop_walking(sd,1); - - cd = chat_createchat(&sd->bl, title, pass, limit, pub, 0, "", 0, 1, MAX_LEVEL); - if( cd ) { - cd->users = 1; - cd->usersd[0] = sd; - pc_setchatid(sd,cd->bl.id); - pc_stop_attack(sd); - clif->createchat(sd,0); - clif->dispchat(cd,0); - } else - clif->createchat(sd,1); - - return 0; -} - -/*========================================== - * join an existing chatroom - *------------------------------------------*/ -int chat_joinchat(struct map_session_data* sd, int chatid, const char* pass) -{ - struct chat_data* cd; - - nullpo_ret(sd); - cd = (struct chat_data*)iMap->id2bl(chatid); - - if( cd == NULL || cd->bl.type != BL_CHAT || cd->bl.m != sd->bl.m || sd->state.vending || sd->state.buyingstore || sd->chatID || ((cd->owner->type == BL_NPC) ? cd->users+1 : cd->users) >= cd->limit ) - { - clif->joinchatfail(sd,0); - return 0; - } - - if( !cd->pub && strncmp(pass, cd->pass, sizeof(cd->pass)) != 0 && !pc->has_permission(sd, PC_PERM_JOIN_ALL_CHAT) ) - { - clif->joinchatfail(sd,1); - return 0; - } - - if( sd->status.base_level < cd->minLvl || sd->status.base_level > cd->maxLvl ) { - if(sd->status.base_level < cd->minLvl) - clif->joinchatfail(sd,5); - else - clif->joinchatfail(sd,6); - - return 0; - } - - if( sd->status.zeny < cd->zeny ) { - clif->joinchatfail(sd,4); - return 0; - } - - if( cd->owner->type != BL_NPC && idb_exists(cd->kick_list,sd->status.char_id) ) { - clif->joinchatfail(sd,2);//You have been kicked out of the room. - return 0; - } - - pc_stop_walking(sd,1); - cd->usersd[cd->users] = sd; - cd->users++; - - pc_setchatid(sd,cd->bl.id); - - clif->joinchatok(sd, cd); //To the person who newly joined the list of all - clif->addchat(cd, sd); //Reports To the person who already in the chat - clif->dispchat(cd, 0); //Reported number of changes to the people around - - chat_triggerevent(cd); //Event - - return 0; -} - - -/*========================================== - * leave a chatroom - *------------------------------------------*/ -int chat_leavechat(struct map_session_data* sd, bool kicked) -{ - struct chat_data* cd; - int i; - int leavechar; - - nullpo_retr(1, sd); - - cd = (struct chat_data*)iMap->id2bl(sd->chatID); - if( cd == NULL ) - { - pc_setchatid(sd, 0); - return 1; - } - - ARR_FIND( 0, cd->users, i, cd->usersd[i] == sd ); - if ( i == cd->users ) - { // Not found in the chatroom? - pc_setchatid(sd, 0); - return -1; - } - - clif->leavechat(cd, sd, kicked); - pc_setchatid(sd, 0); - cd->users--; - - leavechar = i; - - for( i = leavechar; i < cd->users; i++ ) - cd->usersd[i] = cd->usersd[i+1]; - - - if( cd->users == 0 && cd->owner->type == BL_PC ) { // Delete empty chatroom - struct skill_unit* unit; - struct skill_unit_group* group; - - clif->clearchat(cd, 0); - db_destroy(cd->kick_list); - iMap->deliddb(&cd->bl); - iMap->delblock(&cd->bl); - iMap->freeblock(&cd->bl); - - unit = iMap->find_skill_unit_oncell(&sd->bl, sd->bl.x, sd->bl.y, AL_WARP, NULL, 0); - group = (unit != NULL) ? unit->group : NULL; - if (group != NULL) - skill->unit_onplace(unit, &sd->bl, group->tick); - - return 1; - } - - if( leavechar == 0 && cd->owner->type == BL_PC ) - { // Set and announce new owner - cd->owner = (struct block_list*) cd->usersd[0]; - clif->changechatowner(cd, cd->usersd[0]); - clif->clearchat(cd, 0); - - //Adjust Chat location after owner has been changed. - iMap->delblock( &cd->bl ); - cd->bl.x=cd->usersd[0]->bl.x; - cd->bl.y=cd->usersd[0]->bl.y; - iMap->addblock( &cd->bl ); - - clif->dispchat(cd,0); - } - else - clif->dispchat(cd,0); // refresh chatroom - - return 0; -} - -/*========================================== - * change a chatroom's owner - *------------------------------------------*/ -int chat_changechatowner(struct map_session_data* sd, const char* nextownername) -{ - struct chat_data* cd; - struct map_session_data* tmpsd; - int i; - - nullpo_retr(1, sd); - - cd = (struct chat_data*)iMap->id2bl(sd->chatID); - if( cd == NULL || (struct block_list*) sd != cd->owner ) - return 1; - - ARR_FIND( 1, cd->users, i, strncmp(cd->usersd[i]->status.name, nextownername, NAME_LENGTH) == 0 ); - if( i == cd->users ) - return -1; // name not found - - // erase temporarily - clif->clearchat(cd,0); - - // set new owner - cd->owner = (struct block_list*) cd->usersd[i]; - clif->changechatowner(cd,cd->usersd[i]); - - // swap the old and new owners' positions - tmpsd = cd->usersd[i]; - cd->usersd[i] = cd->usersd[0]; - cd->usersd[0] = tmpsd; - - // set the new chatroom position - iMap->delblock( &cd->bl ); - cd->bl.x = cd->owner->x; - cd->bl.y = cd->owner->y; - iMap->addblock( &cd->bl ); - - // and display again - clif->dispchat(cd,0); - - return 0; -} - -/*========================================== - * change a chatroom's status (title, etc) - *------------------------------------------*/ -int chat_changechatstatus(struct map_session_data* sd, const char* title, const char* pass, int limit, bool pub) -{ - struct chat_data* cd; - - nullpo_retr(1, sd); - - cd = (struct chat_data*)iMap->id2bl(sd->chatID); - if( cd==NULL || (struct block_list *)sd != cd->owner ) - return 1; - - safestrncpy(cd->title, title, CHATROOM_TITLE_SIZE); - safestrncpy(cd->pass, pass, CHATROOM_PASS_SIZE); - cd->limit = min(limit, ARRAYLENGTH(cd->usersd)); - cd->pub = pub; - - clif->changechatstatus(cd); - clif->dispchat(cd,0); - - return 0; -} - -/*========================================== - * kick an user from a chatroom - *------------------------------------------*/ -int chat_kickchat(struct map_session_data* sd, const char* kickusername) -{ - struct chat_data* cd; - int i; - - nullpo_retr(1, sd); - - cd = (struct chat_data *)iMap->id2bl(sd->chatID); - - if( cd==NULL || (struct block_list *)sd != cd->owner ) - return -1; - - ARR_FIND( 0, cd->users, i, strncmp(cd->usersd[i]->status.name, kickusername, NAME_LENGTH) == 0 ); - if( i == cd->users ) - return -1; - - if (pc->has_permission(cd->usersd[i], PC_PERM_NO_CHAT_KICK)) - return 0; //gm kick protection [Valaris] - - idb_put(cd->kick_list,cd->usersd[i]->status.char_id,(void*)1); - - chat->leavechat(cd->usersd[i],1); - return 0; -} - -/// Creates a chat room for the npc. -int chat_createnpcchat(struct npc_data* nd, const char* title, int limit, bool pub, int trigger, const char* ev, int zeny, int minLvl, int maxLvl) -{ - struct chat_data* cd; - nullpo_ret(nd); - - if( nd->chat_id ) { - ShowError("chat_createnpcchat: npc '%s' already has a chatroom, cannot create new one!\n", nd->exname); - return 0; - } - - if( zeny > MAX_ZENY || maxLvl > MAX_LEVEL ) { - ShowError("chat_createnpcchat: npc '%s' has a required lvl or amount of zeny over the max limit!\n", nd->exname); - return 0; - } - - cd = chat_createchat(&nd->bl, title, "", limit, pub, trigger, ev, zeny, minLvl, maxLvl); - - if( cd ) { - nd->chat_id = cd->bl.id; - clif->dispchat(cd,0); - } - - return 0; -} - -/// Removes the chatroom from the npc. -int chat_deletenpcchat(struct npc_data* nd) -{ - struct chat_data *cd; - nullpo_ret(nd); - - cd = (struct chat_data*)iMap->id2bl(nd->chat_id); - if( cd == NULL ) - return 0; - - chat->npckickall(cd); - clif->clearchat(cd, 0); - iMap->deliddb(&cd->bl); - iMap->delblock(&cd->bl); - iMap->freeblock(&cd->bl); - nd->chat_id = 0; - - return 0; -} - -/*========================================== - * Trigger npc event when we enter the chatroom - *------------------------------------------*/ -int chat_triggerevent(struct chat_data *cd) -{ - nullpo_ret(cd); - - if( cd->users >= cd->trigger && cd->npc_event[0] ) - npc_event_do(cd->npc_event); - return 0; -} - -/// Enables the event of the chat room. -/// At most, 127 users are needed to trigger the event. -int chat_enableevent(struct chat_data* cd) -{ - nullpo_ret(cd); - - cd->trigger &= 0x7f; - chat_triggerevent(cd); - return 0; -} - -/// Disables the event of the chat room -int chat_disableevent(struct chat_data* cd) -{ - nullpo_ret(cd); - - cd->trigger |= 0x80; - return 0; -} - -/// Kicks all the users from the chat room. -int chat_npckickall(struct chat_data* cd) -{ - nullpo_ret(cd); - - while( cd->users > 0 ) - chat->leavechat(cd->usersd[cd->users-1],0); - - return 0; -} - -/*===================================== -* Default Functions : chat.h -* Generated by HerculesInterfaceMaker -* created by Susu -*-------------------------------------*/ -void chat_defaults(void) { - chat = &chat_s; - /* funcs */ - - chat->createpcchat = chat_createpcchat; - chat->joinchat = chat_joinchat; - chat->leavechat = chat_leavechat; - chat->changechatowner = chat_changechatowner; - chat->changechatstatus = chat_changechatstatus; - chat->kickchat = chat_kickchat; - - chat->createnpcchat = chat_createnpcchat; - chat->deletenpcchat = chat_deletenpcchat; - chat->enableevent = chat_enableevent; - chat->disableevent = chat_disableevent; - chat->npckickall = chat_npckickall; -} +// Copyright (c) Athena Dev Teams - Licensed under GNU GPL +// For more information, see LICENCE in the main folder + +#include "../common/cbasetypes.h" +#include "../common/malloc.h" +#include "../common/nullpo.h" +#include "../common/showmsg.h" +#include "../common/strlib.h" +#include "../common/mmo.h" +#include "atcommand.h" // msg_txt() +#include "battle.h" // struct battle_config +#include "clif.h" +#include "map.h" +#include "npc.h" // npc_event_do() +#include "pc.h" +#include "skill.h" // ext_skill_unit_onplace() +#include "chat.h" + +#include +#include + + +int chat_triggerevent(struct chat_data *cd); // forward declaration + +/// Initializes a chatroom object (common functionality for both pc and npc chatrooms). +/// Returns a chatroom object on success, or NULL on failure. +static struct chat_data* chat_createchat(struct block_list* bl, const char* title, const char* pass, int limit, bool pub, int trigger, const char* ev, int zeny, int minLvl, int maxLvl) +{ + struct chat_data* cd; + nullpo_retr(NULL, bl); + + cd = (struct chat_data *) aMalloc(sizeof(struct chat_data)); + + safestrncpy(cd->title, title, sizeof(cd->title)); + safestrncpy(cd->pass, pass, sizeof(cd->pass)); + cd->pub = pub; + cd->users = 0; + cd->limit = min(limit, ARRAYLENGTH(cd->usersd)); + cd->trigger = trigger; + cd->zeny = zeny; + cd->minLvl = minLvl; + cd->maxLvl = maxLvl; + memset(cd->usersd, 0, sizeof(cd->usersd)); + cd->owner = bl; + safestrncpy(cd->npc_event, ev, sizeof(cd->npc_event)); + + cd->bl.id = iMap->get_new_object_id(); + cd->bl.m = bl->m; + cd->bl.x = bl->x; + cd->bl.y = bl->y; + cd->bl.type = BL_CHAT; + cd->bl.next = cd->bl.prev = NULL; + + if( cd->bl.id == 0 ) + { + aFree(cd); + cd = NULL; + } + + iMap->addiddb(&cd->bl); + + if( bl->type != BL_NPC ) + cd->kick_list = idb_alloc(DB_OPT_BASE); + + return cd; +} + +/*========================================== + * player chatroom creation + *------------------------------------------*/ +int chat_createpcchat(struct map_session_data* sd, const char* title, const char* pass, int limit, bool pub) +{ + struct chat_data* cd; + nullpo_ret(sd); + + if( sd->chatID ) + return 0; //Prevent people abusing the chat system by creating multiple chats, as pointed out by End of Exam. [Skotlex] + + if( sd->state.vending || sd->state.buyingstore ) + {// not chat, when you already have a store open + return 0; + } + + if( map[sd->bl.m].flag.nochat ) + { + clif->message(sd->fd, msg_txt(281)); + return 0; //Can't create chatrooms on this map. + } + + if( iMap->getcell(sd->bl.m,sd->bl.x,sd->bl.y,CELL_CHKNOCHAT) ) + { + clif->message (sd->fd, msg_txt(665)); + return 0; + } + + pc_stop_walking(sd,1); + + cd = chat_createchat(&sd->bl, title, pass, limit, pub, 0, "", 0, 1, MAX_LEVEL); + if( cd ) { + cd->users = 1; + cd->usersd[0] = sd; + pc_setchatid(sd,cd->bl.id); + pc_stop_attack(sd); + clif->createchat(sd,0); + clif->dispchat(cd,0); + } else + clif->createchat(sd,1); + + return 0; +} + +/*========================================== + * join an existing chatroom + *------------------------------------------*/ +int chat_joinchat(struct map_session_data* sd, int chatid, const char* pass) +{ + struct chat_data* cd; + + nullpo_ret(sd); + cd = (struct chat_data*)iMap->id2bl(chatid); + + if( cd == NULL || cd->bl.type != BL_CHAT || cd->bl.m != sd->bl.m || sd->state.vending || sd->state.buyingstore || sd->chatID || ((cd->owner->type == BL_NPC) ? cd->users+1 : cd->users) >= cd->limit ) + { + clif->joinchatfail(sd,0); + return 0; + } + + if( !cd->pub && strncmp(pass, cd->pass, sizeof(cd->pass)) != 0 && !pc->has_permission(sd, PC_PERM_JOIN_ALL_CHAT) ) + { + clif->joinchatfail(sd,1); + return 0; + } + + if( sd->status.base_level < cd->minLvl || sd->status.base_level > cd->maxLvl ) { + if(sd->status.base_level < cd->minLvl) + clif->joinchatfail(sd,5); + else + clif->joinchatfail(sd,6); + + return 0; + } + + if( sd->status.zeny < cd->zeny ) { + clif->joinchatfail(sd,4); + return 0; + } + + if( cd->owner->type != BL_NPC && idb_exists(cd->kick_list,sd->status.char_id) ) { + clif->joinchatfail(sd,2);//You have been kicked out of the room. + return 0; + } + + pc_stop_walking(sd,1); + cd->usersd[cd->users] = sd; + cd->users++; + + pc_setchatid(sd,cd->bl.id); + + clif->joinchatok(sd, cd); //To the person who newly joined the list of all + clif->addchat(cd, sd); //Reports To the person who already in the chat + clif->dispchat(cd, 0); //Reported number of changes to the people around + + chat_triggerevent(cd); //Event + + return 0; +} + + +/*========================================== + * leave a chatroom + *------------------------------------------*/ +int chat_leavechat(struct map_session_data* sd, bool kicked) +{ + struct chat_data* cd; + int i; + int leavechar; + + nullpo_retr(1, sd); + + cd = (struct chat_data*)iMap->id2bl(sd->chatID); + if( cd == NULL ) + { + pc_setchatid(sd, 0); + return 1; + } + + ARR_FIND( 0, cd->users, i, cd->usersd[i] == sd ); + if ( i == cd->users ) + { // Not found in the chatroom? + pc_setchatid(sd, 0); + return -1; + } + + clif->leavechat(cd, sd, kicked); + pc_setchatid(sd, 0); + cd->users--; + + leavechar = i; + + for( i = leavechar; i < cd->users; i++ ) + cd->usersd[i] = cd->usersd[i+1]; + + + if( cd->users == 0 && cd->owner->type == BL_PC ) { // Delete empty chatroom + struct skill_unit* unit; + struct skill_unit_group* group; + + clif->clearchat(cd, 0); + db_destroy(cd->kick_list); + iMap->deliddb(&cd->bl); + iMap->delblock(&cd->bl); + iMap->freeblock(&cd->bl); + + unit = iMap->find_skill_unit_oncell(&sd->bl, sd->bl.x, sd->bl.y, AL_WARP, NULL, 0); + group = (unit != NULL) ? unit->group : NULL; + if (group != NULL) + skill->unit_onplace(unit, &sd->bl, group->tick); + + return 1; + } + + if( leavechar == 0 && cd->owner->type == BL_PC ) + { // Set and announce new owner + cd->owner = (struct block_list*) cd->usersd[0]; + clif->changechatowner(cd, cd->usersd[0]); + clif->clearchat(cd, 0); + + //Adjust Chat location after owner has been changed. + iMap->delblock( &cd->bl ); + cd->bl.x=cd->usersd[0]->bl.x; + cd->bl.y=cd->usersd[0]->bl.y; + iMap->addblock( &cd->bl ); + + clif->dispchat(cd,0); + } + else + clif->dispchat(cd,0); // refresh chatroom + + return 0; +} + +/*========================================== + * change a chatroom's owner + *------------------------------------------*/ +int chat_changechatowner(struct map_session_data* sd, const char* nextownername) +{ + struct chat_data* cd; + struct map_session_data* tmpsd; + int i; + + nullpo_retr(1, sd); + + cd = (struct chat_data*)iMap->id2bl(sd->chatID); + if( cd == NULL || (struct block_list*) sd != cd->owner ) + return 1; + + ARR_FIND( 1, cd->users, i, strncmp(cd->usersd[i]->status.name, nextownername, NAME_LENGTH) == 0 ); + if( i == cd->users ) + return -1; // name not found + + // erase temporarily + clif->clearchat(cd,0); + + // set new owner + cd->owner = (struct block_list*) cd->usersd[i]; + clif->changechatowner(cd,cd->usersd[i]); + + // swap the old and new owners' positions + tmpsd = cd->usersd[i]; + cd->usersd[i] = cd->usersd[0]; + cd->usersd[0] = tmpsd; + + // set the new chatroom position + iMap->delblock( &cd->bl ); + cd->bl.x = cd->owner->x; + cd->bl.y = cd->owner->y; + iMap->addblock( &cd->bl ); + + // and display again + clif->dispchat(cd,0); + + return 0; +} + +/*========================================== + * change a chatroom's status (title, etc) + *------------------------------------------*/ +int chat_changechatstatus(struct map_session_data* sd, const char* title, const char* pass, int limit, bool pub) +{ + struct chat_data* cd; + + nullpo_retr(1, sd); + + cd = (struct chat_data*)iMap->id2bl(sd->chatID); + if( cd==NULL || (struct block_list *)sd != cd->owner ) + return 1; + + safestrncpy(cd->title, title, CHATROOM_TITLE_SIZE); + safestrncpy(cd->pass, pass, CHATROOM_PASS_SIZE); + cd->limit = min(limit, ARRAYLENGTH(cd->usersd)); + cd->pub = pub; + + clif->changechatstatus(cd); + clif->dispchat(cd,0); + + return 0; +} + +/*========================================== + * kick an user from a chatroom + *------------------------------------------*/ +int chat_kickchat(struct map_session_data* sd, const char* kickusername) +{ + struct chat_data* cd; + int i; + + nullpo_retr(1, sd); + + cd = (struct chat_data *)iMap->id2bl(sd->chatID); + + if( cd==NULL || (struct block_list *)sd != cd->owner ) + return -1; + + ARR_FIND( 0, cd->users, i, strncmp(cd->usersd[i]->status.name, kickusername, NAME_LENGTH) == 0 ); + if( i == cd->users ) + return -1; + + if (pc->has_permission(cd->usersd[i], PC_PERM_NO_CHAT_KICK)) + return 0; //gm kick protection [Valaris] + + idb_put(cd->kick_list,cd->usersd[i]->status.char_id,(void*)1); + + chat->leavechat(cd->usersd[i],1); + return 0; +} + +/// Creates a chat room for the npc. +int chat_createnpcchat(struct npc_data* nd, const char* title, int limit, bool pub, int trigger, const char* ev, int zeny, int minLvl, int maxLvl) +{ + struct chat_data* cd; + nullpo_ret(nd); + + if( nd->chat_id ) { + ShowError("chat_createnpcchat: npc '%s' already has a chatroom, cannot create new one!\n", nd->exname); + return 0; + } + + if( zeny > MAX_ZENY || maxLvl > MAX_LEVEL ) { + ShowError("chat_createnpcchat: npc '%s' has a required lvl or amount of zeny over the max limit!\n", nd->exname); + return 0; + } + + cd = chat_createchat(&nd->bl, title, "", limit, pub, trigger, ev, zeny, minLvl, maxLvl); + + if( cd ) { + nd->chat_id = cd->bl.id; + clif->dispchat(cd,0); + } + + return 0; +} + +/// Removes the chatroom from the npc. +int chat_deletenpcchat(struct npc_data* nd) +{ + struct chat_data *cd; + nullpo_ret(nd); + + cd = (struct chat_data*)iMap->id2bl(nd->chat_id); + if( cd == NULL ) + return 0; + + chat->npckickall(cd); + clif->clearchat(cd, 0); + iMap->deliddb(&cd->bl); + iMap->delblock(&cd->bl); + iMap->freeblock(&cd->bl); + nd->chat_id = 0; + + return 0; +} + +/*========================================== + * Trigger npc event when we enter the chatroom + *------------------------------------------*/ +int chat_triggerevent(struct chat_data *cd) +{ + nullpo_ret(cd); + + if( cd->users >= cd->trigger && cd->npc_event[0] ) + npc_event_do(cd->npc_event); + return 0; +} + +/// Enables the event of the chat room. +/// At most, 127 users are needed to trigger the event. +int chat_enableevent(struct chat_data* cd) +{ + nullpo_ret(cd); + + cd->trigger &= 0x7f; + chat_triggerevent(cd); + return 0; +} + +/// Disables the event of the chat room +int chat_disableevent(struct chat_data* cd) +{ + nullpo_ret(cd); + + cd->trigger |= 0x80; + return 0; +} + +/// Kicks all the users from the chat room. +int chat_npckickall(struct chat_data* cd) +{ + nullpo_ret(cd); + + while( cd->users > 0 ) + chat->leavechat(cd->usersd[cd->users-1],0); + + return 0; +} + +/*===================================== +* Default Functions : chat.h +* Generated by HerculesInterfaceMaker +* created by Susu +*-------------------------------------*/ +void chat_defaults(void) { + chat = &chat_s; + /* funcs */ + + chat->createpcchat = chat_createpcchat; + chat->joinchat = chat_joinchat; + chat->leavechat = chat_leavechat; + chat->changechatowner = chat_changechatowner; + chat->changechatstatus = chat_changechatstatus; + chat->kickchat = chat_kickchat; + + chat->createnpcchat = chat_createnpcchat; + chat->deletenpcchat = chat_deletenpcchat; + chat->enableevent = chat_enableevent; + chat->disableevent = chat_disableevent; + chat->npckickall = chat_npckickall; +} diff --git a/src/map/chat.h b/src/map/chat.h index ff78d8617..a7736e9f3 100644 --- a/src/map/chat.h +++ b/src/map/chat.h @@ -1,56 +1,56 @@ -// Copyright (c) Athena Dev Teams - Licensed under GNU GPL -// For more information, see LICENCE in the main folder -#ifndef _CHAT_H_ -#define _CHAT_H_ -#include "map.h" // struct block_list, CHATROOM_TITLE_SIZE -struct map_session_data; -struct chat_data; - - -struct chat_data { - struct block_list bl; // data for this map object - char title[CHATROOM_TITLE_SIZE]; // room title - char pass[CHATROOM_PASS_SIZE]; // password - bool pub; // private/public flag - uint8 users; // current user count - uint8 limit; // join limit - uint8 trigger; // number of users needed to trigger event - uint32 zeny; // required zeny to join - uint32 minLvl; // minimum base level to join - uint32 maxLvl; // maximum base level allowed to join - struct map_session_data* usersd[20]; - struct block_list* owner; - char npc_event[EVENT_NAME_LENGTH]; - DBMap* kick_list; //DBMap of users who were kicked from this chat -}; - - - - -/*===================================== -* Interface : chat.h -* Generated by HerculesInterfaceMaker -* created by Susu -*-------------------------------------*/ -struct chat_interface { - /* funcs */ - - int (*createpcchat) (struct map_session_data* sd, const char* title, const char* pass, int limit, bool pub); - int (*joinchat) (struct map_session_data* sd, int chatid, const char* pass); - int (*leavechat) (struct map_session_data* sd, bool kicked); - int (*changechatowner) (struct map_session_data* sd, const char* nextownername); - int (*changechatstatus) (struct map_session_data* sd, const char* title, const char* pass, int limit, bool pub); - int (*kickchat) (struct map_session_data* sd, const char* kickusername); - - int (*createnpcchat) (struct npc_data* nd, const char* title, int limit, bool pub, int trigger, const char* ev, int zeny, int minLvl, int maxLvl); - int (*deletenpcchat) (struct npc_data* nd); - int (*enableevent) (struct chat_data* cd); - int (*disableevent) (struct chat_data* cd); - int (*npckickall) (struct chat_data* cd); -} chat_s; - -struct chat_interface *chat; - -void chat_defaults(void); - -#endif /* _CHAT_H_ */ +// Copyright (c) Athena Dev Teams - Licensed under GNU GPL +// For more information, see LICENCE in the main folder +#ifndef _CHAT_H_ +#define _CHAT_H_ +#include "map.h" // struct block_list, CHATROOM_TITLE_SIZE +struct map_session_data; +struct chat_data; + + +struct chat_data { + struct block_list bl; // data for this map object + char title[CHATROOM_TITLE_SIZE]; // room title + char pass[CHATROOM_PASS_SIZE]; // password + bool pub; // private/public flag + uint8 users; // current user count + uint8 limit; // join limit + uint8 trigger; // number of users needed to trigger event + uint32 zeny; // required zeny to join + uint32 minLvl; // minimum base level to join + uint32 maxLvl; // maximum base level allowed to join + struct map_session_data* usersd[20]; + struct block_list* owner; + char npc_event[EVENT_NAME_LENGTH]; + DBMap* kick_list; //DBMap of users who were kicked from this chat +}; + + + + +/*===================================== +* Interface : chat.h +* Generated by HerculesInterfaceMaker +* created by Susu +*-------------------------------------*/ +struct chat_interface { + /* funcs */ + + int (*createpcchat) (struct map_session_data* sd, const char* title, const char* pass, int limit, bool pub); + int (*joinchat) (struct map_session_data* sd, int chatid, const char* pass); + int (*leavechat) (struct map_session_data* sd, bool kicked); + int (*changechatowner) (struct map_session_data* sd, const char* nextownername); + int (*changechatstatus) (struct map_session_data* sd, const char* title, const char* pass, int limit, bool pub); + int (*kickchat) (struct map_session_data* sd, const char* kickusername); + + int (*createnpcchat) (struct npc_data* nd, const char* title, int limit, bool pub, int trigger, const char* ev, int zeny, int minLvl, int maxLvl); + int (*deletenpcchat) (struct npc_data* nd); + int (*enableevent) (struct chat_data* cd); + int (*disableevent) (struct chat_data* cd); + int (*npckickall) (struct chat_data* cd); +} chat_s; + +struct chat_interface *chat; + +void chat_defaults(void); + +#endif /* _CHAT_H_ */ diff --git a/src/map/duel.c b/src/map/duel.c index a04ed855b..c3b241e9e 100644 --- a/src/map/duel.c +++ b/src/map/duel.c @@ -1,204 +1,204 @@ -// Copyright (c) Hercules Dev Team, licensed under GNU GPL. -// See the LICENSE file -// Portions Copyright (c) Athena Dev Teams - -#include "../common/cbasetypes.h" - -#include "atcommand.h" // msg_txt -#include "clif.h" -#include "duel.h" -#include "pc.h" - -#include -#include -#include -#include - -/*========================================== - * Duel organizing functions [LuzZza] - *------------------------------------------*/ -void duel_savetime(struct map_session_data* sd) -{ - time_t timer; - struct tm *t; - - time(&timer); - t = localtime(&timer); - - pc_setglobalreg(sd, "PC_LAST_DUEL_TIME", t->tm_mday*24*60 + t->tm_hour*60 + t->tm_min); -} - -int duel_checktime(struct map_session_data* sd) -{ - int diff; - time_t timer; - struct tm *t; - - time(&timer); - t = localtime(&timer); - - diff = t->tm_mday*24*60 + t->tm_hour*60 + t->tm_min - pc_readglobalreg(sd, "PC_LAST_DUEL_TIME"); - - return !(diff >= 0 && diff < battle_config.duel_time_interval); -} -static int duel_showinfo_sub(struct map_session_data* sd, va_list va) -{ - struct map_session_data *ssd = va_arg(va, struct map_session_data*); - int *p = va_arg(va, int*); - char output[256]; - - if (sd->duel_group != ssd->duel_group) return 0; - - sprintf(output, " %d. %s", ++(*p), sd->status.name); - clif->disp_onlyself(ssd, output, strlen(output)); - return 1; -} - -void duel_showinfo(const unsigned int did, struct map_session_data* sd) -{ - int p=0; - char output[256]; - - if(iDuel->duel_list[did].max_players_limit > 0) - sprintf(output, msg_txt(370), //" -- Duels: %d/%d, Members: %d/%d, Max players: %d --" - did, iDuel->duel_count, - iDuel->duel_list[did].members_count, - iDuel->duel_list[did].members_count + iDuel->duel_list[did].invites_count, - iDuel->duel_list[did].max_players_limit); - else - sprintf(output, msg_txt(371), //" -- Duels: %d/%d, Members: %d/%d --" - did, iDuel->duel_count, - iDuel->duel_list[did].members_count, - iDuel->duel_list[did].members_count + iDuel->duel_list[did].invites_count); - - clif->disp_onlyself(sd, output, strlen(output)); - iMap->map_foreachpc(duel_showinfo_sub, sd, &p); -} - -int duel_create(struct map_session_data* sd, const unsigned int maxpl) -{ - int i=1; - char output[256]; - - while(iDuel->duel_list[i].members_count > 0 && i < MAX_DUEL) i++; - if(i == MAX_DUEL) return 0; - - iDuel->duel_count++; - sd->duel_group = i; - iDuel->duel_list[i].members_count++; - iDuel->duel_list[i].invites_count = 0; - iDuel->duel_list[i].max_players_limit = maxpl; - - strcpy(output, msg_txt(372)); // " -- Duel has been created (@invite/@leave) --" - clif->disp_onlyself(sd, output, strlen(output)); - - clif->map_property(sd, MAPPROPERTY_FREEPVPZONE); - clif->maptypeproperty2(&sd->bl,SELF); - return i; -} - -void duel_invite(const unsigned int did, struct map_session_data* sd, struct map_session_data* target_sd) -{ - char output[256]; - - // " -- Player %s invites %s to duel --" - sprintf(output, msg_txt(373), sd->status.name, target_sd->status.name); - clif->disp_message(&sd->bl, output, strlen(output), DUEL_WOS); - - target_sd->duel_invite = did; - iDuel->duel_list[did].invites_count++; - - // "Blue -- Player %s invites you to PVP duel (@accept/@reject) --" - sprintf(output, msg_txt(374), sd->status.name); - clif->broadcast((struct block_list *)target_sd, output, strlen(output)+1, BC_BLUE, SELF); -} - -static int duel_leave_sub(struct map_session_data* sd, va_list va) -{ - int did = va_arg(va, int); - if (sd->duel_invite == did) - sd->duel_invite = 0; - return 0; -} - -void duel_leave(const unsigned int did, struct map_session_data* sd) -{ - char output[256]; - - // " <- Player %s has left duel --" - sprintf(output, msg_txt(375), sd->status.name); - clif->disp_message(&sd->bl, output, strlen(output), DUEL_WOS); - - iDuel->duel_list[did].members_count--; - - if(iDuel->duel_list[did].members_count == 0) { - iMap->map_foreachpc(duel_leave_sub, did); - iDuel->duel_count--; - } - - sd->duel_group = 0; - duel_savetime(sd); - clif->map_property(sd, MAPPROPERTY_NOTHING); - clif->maptypeproperty2(&sd->bl,SELF); -} - -void duel_accept(const unsigned int did, struct map_session_data* sd) -{ - char output[256]; - - iDuel->duel_list[did].members_count++; - sd->duel_group = sd->duel_invite; - iDuel->duel_list[did].invites_count--; - sd->duel_invite = 0; - - // " -> Player %s has accepted duel --" - sprintf(output, msg_txt(376), sd->status.name); - clif->disp_message(&sd->bl, output, strlen(output), DUEL_WOS); - - clif->map_property(sd, MAPPROPERTY_FREEPVPZONE); - clif->maptypeproperty2(&sd->bl,SELF); -} - -void duel_reject(const unsigned int did, struct map_session_data* sd) -{ - char output[256]; - - // " -- Player %s has rejected duel --" - sprintf(output, msg_txt(377), sd->status.name); - clif->disp_message(&sd->bl, output, strlen(output), DUEL_WOS); - - iDuel->duel_list[did].invites_count--; - sd->duel_invite = 0; -} - -void do_final_duel(void) -{ -} - -void do_init_duel(void) -{ - memset(&iDuel->duel_list[0], 0, sizeof(iDuel->duel_list)); -} - -/*===================================== -* Default Functions : duel.h -* Generated by HerculesInterfaceMaker -* created by Susu -*-------------------------------------*/ -void iDuel_defaults(void) { - iDuel = &iDuel_s; - /* vars */ - iDuel->duel_count = 0; - /* funcs */ - //Duel functions // [LuzZza] - iDuel->create = duel_create; - iDuel->invite = duel_invite; - iDuel->accept = duel_accept; - iDuel->reject = duel_reject; - iDuel->leave = duel_leave; - iDuel->showinfo = duel_showinfo; - iDuel->checktime = duel_checktime; - - iDuel->do_init_duel = do_init_duel; - iDuel->do_final_duel = do_final_duel; -} +// Copyright (c) Hercules Dev Team, licensed under GNU GPL. +// See the LICENSE file +// Portions Copyright (c) Athena Dev Teams + +#include "../common/cbasetypes.h" + +#include "atcommand.h" // msg_txt +#include "clif.h" +#include "duel.h" +#include "pc.h" + +#include +#include +#include +#include + +/*========================================== + * Duel organizing functions [LuzZza] + *------------------------------------------*/ +void duel_savetime(struct map_session_data* sd) +{ + time_t timer; + struct tm *t; + + time(&timer); + t = localtime(&timer); + + pc_setglobalreg(sd, "PC_LAST_DUEL_TIME", t->tm_mday*24*60 + t->tm_hour*60 + t->tm_min); +} + +int duel_checktime(struct map_session_data* sd) +{ + int diff; + time_t timer; + struct tm *t; + + time(&timer); + t = localtime(&timer); + + diff = t->tm_mday*24*60 + t->tm_hour*60 + t->tm_min - pc_readglobalreg(sd, "PC_LAST_DUEL_TIME"); + + return !(diff >= 0 && diff < battle_config.duel_time_interval); +} +static int duel_showinfo_sub(struct map_session_data* sd, va_list va) +{ + struct map_session_data *ssd = va_arg(va, struct map_session_data*); + int *p = va_arg(va, int*); + char output[256]; + + if (sd->duel_group != ssd->duel_group) return 0; + + sprintf(output, " %d. %s", ++(*p), sd->status.name); + clif->disp_onlyself(ssd, output, strlen(output)); + return 1; +} + +void duel_showinfo(const unsigned int did, struct map_session_data* sd) +{ + int p=0; + char output[256]; + + if(iDuel->duel_list[did].max_players_limit > 0) + sprintf(output, msg_txt(370), //" -- Duels: %d/%d, Members: %d/%d, Max players: %d --" + did, iDuel->duel_count, + iDuel->duel_list[did].members_count, + iDuel->duel_list[did].members_count + iDuel->duel_list[did].invites_count, + iDuel->duel_list[did].max_players_limit); + else + sprintf(output, msg_txt(371), //" -- Duels: %d/%d, Members: %d/%d --" + did, iDuel->duel_count, + iDuel->duel_list[did].members_count, + iDuel->duel_list[did].members_count + iDuel->duel_list[did].invites_count); + + clif->disp_onlyself(sd, output, strlen(output)); + iMap->map_foreachpc(duel_showinfo_sub, sd, &p); +} + +int duel_create(struct map_session_data* sd, const unsigned int maxpl) +{ + int i=1; + char output[256]; + + while(iDuel->duel_list[i].members_count > 0 && i < MAX_DUEL) i++; + if(i == MAX_DUEL) return 0; + + iDuel->duel_count++; + sd->duel_group = i; + iDuel->duel_list[i].members_count++; + iDuel->duel_list[i].invites_count = 0; + iDuel->duel_list[i].max_players_limit = maxpl; + + strcpy(output, msg_txt(372)); // " -- Duel has been created (@invite/@leave) --" + clif->disp_onlyself(sd, output, strlen(output)); + + clif->map_property(sd, MAPPROPERTY_FREEPVPZONE); + clif->maptypeproperty2(&sd->bl,SELF); + return i; +} + +void duel_invite(const unsigned int did, struct map_session_data* sd, struct map_session_data* target_sd) +{ + char output[256]; + + // " -- Player %s invites %s to duel --" + sprintf(output, msg_txt(373), sd->status.name, target_sd->status.name); + clif->disp_message(&sd->bl, output, strlen(output), DUEL_WOS); + + target_sd->duel_invite = did; + iDuel->duel_list[did].invites_count++; + + // "Blue -- Player %s invites you to PVP duel (@accept/@reject) --" + sprintf(output, msg_txt(374), sd->status.name); + clif->broadcast((struct block_list *)target_sd, output, strlen(output)+1, BC_BLUE, SELF); +} + +static int duel_leave_sub(struct map_session_data* sd, va_list va) +{ + int did = va_arg(va, int); + if (sd->duel_invite == did) + sd->duel_invite = 0; + return 0; +} + +void duel_leave(const unsigned int did, struct map_session_data* sd) +{ + char output[256]; + + // " <- Player %s has left duel --" + sprintf(output, msg_txt(375), sd->status.name); + clif->disp_message(&sd->bl, output, strlen(output), DUEL_WOS); + + iDuel->duel_list[did].members_count--; + + if(iDuel->duel_list[did].members_count == 0) { + iMap->map_foreachpc(duel_leave_sub, did); + iDuel->duel_count--; + } + + sd->duel_group = 0; + duel_savetime(sd); + clif->map_property(sd, MAPPROPERTY_NOTHING); + clif->maptypeproperty2(&sd->bl,SELF); +} + +void duel_accept(const unsigned int did, struct map_session_data* sd) +{ + char output[256]; + + iDuel->duel_list[did].members_count++; + sd->duel_group = sd->duel_invite; + iDuel->duel_list[did].invites_count--; + sd->duel_invite = 0; + + // " -> Player %s has accepted duel --" + sprintf(output, msg_txt(376), sd->status.name); + clif->disp_message(&sd->bl, output, strlen(output), DUEL_WOS); + + clif->map_property(sd, MAPPROPERTY_FREEPVPZONE); + clif->maptypeproperty2(&sd->bl,SELF); +} + +void duel_reject(const unsigned int did, struct map_session_data* sd) +{ + char output[256]; + + // " -- Player %s has rejected duel --" + sprintf(output, msg_txt(377), sd->status.name); + clif->disp_message(&sd->bl, output, strlen(output), DUEL_WOS); + + iDuel->duel_list[did].invites_count--; + sd->duel_invite = 0; +} + +void do_final_duel(void) +{ +} + +void do_init_duel(void) +{ + memset(&iDuel->duel_list[0], 0, sizeof(iDuel->duel_list)); +} + +/*===================================== +* Default Functions : duel.h +* Generated by HerculesInterfaceMaker +* created by Susu +*-------------------------------------*/ +void iDuel_defaults(void) { + iDuel = &iDuel_s; + /* vars */ + iDuel->duel_count = 0; + /* funcs */ + //Duel functions // [LuzZza] + iDuel->create = duel_create; + iDuel->invite = duel_invite; + iDuel->accept = duel_accept; + iDuel->reject = duel_reject; + iDuel->leave = duel_leave; + iDuel->showinfo = duel_showinfo; + iDuel->checktime = duel_checktime; + + iDuel->do_init_duel = do_init_duel; + iDuel->do_final_duel = do_final_duel; +} diff --git a/src/map/elemental.c b/src/map/elemental.c index 03aa93e49..1952d93e2 100644 --- a/src/map/elemental.c +++ b/src/map/elemental.c @@ -1,984 +1,984 @@ -// 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/showmsg.h" -#include "../common/utils.h" -#include "../common/random.h" -#include "../common/strlib.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 "elemental.h" - -#include -#include -#include -#include - -int elemental_search_index(int class_) { - int i; - ARR_FIND(0, MAX_ELEMENTAL_CLASS, i, elemental->elemental_db[i].class_ == class_); - return (i == MAX_ELEMENTAL_CLASS)?-1:i; -} - -bool elemental_class(int class_) { - return (bool)(elemental_search_index(class_) > -1); -} - -struct view_data * elemental_get_viewdata(int class_) { - int i = elemental_search_index(class_); - if( i < 0 ) - return 0; - - return &elemental->elemental_db[i].vd; -} - -int elemental_create(struct map_session_data *sd, int class_, unsigned int lifetime) { - struct s_elemental ele; - struct s_elemental_db *db; - int i; - - nullpo_retr(1,sd); - - if( (i = elemental_search_index(class_)) < 0 ) - return 0; - - db = &elemental->elemental_db[i]; - memset(&ele,0,sizeof(struct s_elemental)); - - ele.char_id = sd->status.char_id; - ele.class_ = class_; - ele.mode = EL_MODE_PASSIVE; // Initial mode - i = db->status.size+1; // summon level - - //[(Caster�s Max HP/ 3 ) + (Caster�s INT x 10 )+ (Caster�s Job Level x 20 )] x [(Elemental Summon Level + 2) / 3] - ele.hp = ele.max_hp = (sd->battle_status.max_hp/3 + sd->battle_status.int_*10 + sd->status.job_level) * ((i + 2) / 3); - //Caster�s Max SP /4 - ele.sp = ele.max_sp = sd->battle_status.max_sp/4; - //Caster�s [ Max SP / (18 / Elemental Summon Skill Level) 1- 100 ] - ele.atk = (sd->battle_status.max_sp / (18 / i) * 1 - 100); - //Caster�s [ Max SP / (18 / Elemental Summon Skill Level) ] - ele.atk2 = sd->battle_status.max_sp / 18; - //Caster�s HIT + (Caster�s Base Level ) - ele.hit = sd->battle_status.hit + sd->status.base_level; - //[Elemental Summon Skill Level x (Caster�s INT / 2 + Caster�s DEX / 4)] - ele.matk = i * (sd->battle_status.int_ / 2 + sd->battle_status.dex / 4); - //150 + [Caster�s DEX / 10] + [Elemental Summon Skill Level x 3 ] - ele.amotion = 150 + sd->battle_status.dex / 10 + i * 3; - //Caster�s DEF + (Caster�s Base Level / (5 � Elemental Summon Skill Level) - ele.def = sd->battle_status.def + sd->status.base_level / (5-i); - //Caster�s MDEF + (Caster�s INT / (5 - Elemental Summon Skill Level) - ele.mdef = sd->battle_status.mdef + sd->battle_status.int_ / (5-i); - //Caster�s FLEE + (Caster�s Base Level / (5 � Elemental Summon Skill Level) - ele.flee = sd->status.base_level / (5-i); - //Caster�s HIT + (Caster�s Base Level ) - ele.hit = sd->battle_status.hit + sd->status.base_level; - - //per individual bonuses - switch(db->class_){ - case 2114: case 2115: - case 2116: //ATK + (Summon Agni Skill Level x 20) / HIT + (Summon Agni Skill Level x 10) - ele.atk += i * 20; - ele.atk2 += i * 20; - ele.hit += i * 10; - break; - case 2117: case 2118: - case 2119: //MDEF + (Summon Aqua Skill Level x 10) / MATK + (Summon Aqua Skill Level x 20) - ele.mdef += i * 10; - ele.matk += i * 20; - break; - case 2120: case 2121: - case 2122: //FLEE + (Summon Ventus Skill Level x 20) / MATK + (Summon Ventus Skill Level x 10) - ele.flee += i * 20; - ele.matk += i * 10; - break; - case 2123: case 2124: - case 2125: //DEF + (Summon Tera Skill Level x 25) / ATK + (Summon Tera Skill Level x 5) - ele.def += i * 25; - ele.atk += i * 5; - ele.atk2 += i * 5; - break; - } - - if( (i=pc->checkskill(sd,SO_EL_SYMPATHY)) > 0 ){ - ele.hp = ele.max_hp = ele.max_hp * 5 * i / 100; - ele.sp = ele.max_sp = ele.max_sp * 5 * i / 100; - ele.atk += 25 * i; - ele.atk2 += 25 * i; - ele.matk += 25 * i; - } - - ele.life_time = lifetime; - - // Request Char Server to create this elemental - intif->elemental_create(&ele); - - return 1; -} - -int elemental_get_lifetime(struct elemental_data *ed) { - const struct TimerData * td; - if( ed == NULL || ed->summon_timer == INVALID_TIMER ) - return 0; - - td = iTimer->get_timer(ed->summon_timer); - return (td != NULL) ? DIFF_TICK(td->tick, iTimer->gettick()) : 0; -} - -int elemental_save(struct elemental_data *ed) { - ed->elemental.mode = ed->battle_status.mode; - ed->elemental.hp = ed->battle_status.hp; - ed->elemental.sp = ed->battle_status.sp; - ed->elemental.max_hp = ed->battle_status.max_hp; - ed->elemental.max_sp = ed->battle_status.max_sp; - ed->elemental.atk = ed->battle_status.rhw.atk; - ed->elemental.atk2 = ed->battle_status.rhw.atk2; - ed->elemental.matk = ed->battle_status.matk_min; - ed->elemental.def = ed->battle_status.def; - ed->elemental.mdef = ed->battle_status.mdef; - ed->elemental.flee = ed->battle_status.flee; - ed->elemental.hit = ed->battle_status.hit; - ed->elemental.life_time = elemental->get_lifetime(ed); - intif->elemental_save(&ed->elemental); - return 1; -} - -static int elemental_summon_end(int tid, unsigned int tick, int id, intptr_t data) { - struct map_session_data *sd; - struct elemental_data *ed; - - if( (sd = iMap->id2sd(id)) == NULL ) - return 1; - if( (ed = sd->ed) == NULL ) - return 1; - - if( ed->summon_timer != tid ) { - ShowError("elemental_summon_end %d != %d.\n", ed->summon_timer, tid); - return 0; - } - - ed->summon_timer = INVALID_TIMER; - elemental->delete(ed, 0); // Elemental's summon time is over. - - return 0; -} - -void elemental_summon_stop(struct elemental_data *ed) { - nullpo_retv(ed); - if( ed->summon_timer != INVALID_TIMER ) - iTimer->delete_timer(ed->summon_timer, elemental_summon_end); - ed->summon_timer = INVALID_TIMER; -} - -int elemental_delete(struct elemental_data *ed, int reply) { - struct map_session_data *sd; - nullpo_ret(ed); - - sd = ed->master; - ed->elemental.life_time = 0; - - elemental->clean_effect(ed); - elemental->summon_stop(ed); - - if( !sd ) - return unit_free(&ed->bl, 0); - - sd->ed = NULL; - sd->status.ele_id = 0; - - return unit_remove_map(&ed->bl, 0); -} - -void elemental_summon_init(struct elemental_data *ed) { - if( ed->summon_timer == INVALID_TIMER ) - ed->summon_timer = iTimer->add_timer(iTimer->gettick() + ed->elemental.life_time, elemental_summon_end, ed->master->bl.id, 0); - - ed->regen.state.block = 0; -} - -int elemental_data_received(struct s_elemental *ele, bool flag) { - struct map_session_data *sd; - struct elemental_data *ed; - struct s_elemental_db *db; - int i = elemental_search_index(ele->class_); - - if( (sd = iMap->charid2sd(ele->char_id)) == NULL ) - return 0; - - if( !flag || i < 0 ) { // Not created - loaded - DB info - sd->status.ele_id = 0; - return 0; - } - - db = &elemental->elemental_db[i]; - if( !sd->ed ) { // Initialize it after first summon. - sd->ed = ed = (struct elemental_data*)aCalloc(1,sizeof(struct elemental_data)); - ed->bl.type = BL_ELEM; - ed->bl.id = npc_get_new_npc_id(); - ed->master = sd; - ed->db = db; - memcpy(&ed->elemental, ele, sizeof(struct s_elemental)); - iStatus->set_viewdata(&ed->bl, ed->elemental.class_); - ed->vd->head_mid = 10; // Why? - iStatus->change_init(&ed->bl); - unit_dataset(&ed->bl); - ed->ud.dir = sd->ud.dir; - - ed->bl.m = sd->bl.m; - ed->bl.x = sd->bl.x; - ed->bl.y = sd->bl.y; - unit_calc_pos(&ed->bl, sd->bl.x, sd->bl.y, sd->ud.dir); - ed->bl.x = ed->ud.to_x; - ed->bl.y = ed->ud.to_y; - - iMap->addiddb(&ed->bl); - status_calc_elemental(ed,1); - ed->last_spdrain_time = ed->last_thinktime = iTimer->gettick(); - ed->summon_timer = INVALID_TIMER; - elemental_summon_init(ed); - } else { - memcpy(&sd->ed->elemental, ele, sizeof(struct s_elemental)); - ed = sd->ed; - } - - sd->status.ele_id = ele->elemental_id; - - if( ed->bl.prev == NULL && sd->bl.prev != NULL ) { - iMap->addblock(&ed->bl); - clif->spawn(&ed->bl); - clif->elemental_info(sd); - clif->elemental_updatestatus(sd,SP_HP); - clif->hpmeter_single(sd->fd,ed->bl.id,ed->battle_status.hp,ed->battle_status.max_hp); - clif->elemental_updatestatus(sd,SP_SP); - } - - return 1; -} - -int elemental_clean_single_effect(struct elemental_data *ed, uint16 skill_id) { - struct block_list *bl; - sc_type type = iStatus->skill2sc(skill_id); - - nullpo_ret(ed); - - bl = battle->get_master(&ed->bl); - - if( type ) { - switch( type ) { - // Just remove status change. - case SC_PYROTECHNIC_OPTION: - case SC_HEATER_OPTION: - case SC_TROPIC_OPTION: - case SC_FIRE_CLOAK_OPTION: - case SC_AQUAPLAY_OPTION: - case SC_WATER_SCREEN_OPTION: - case SC_COOLER_OPTION: - case SC_CHILLY_AIR_OPTION: - case SC_GUST_OPTION: - case SC_WIND_STEP_OPTION: - case SC_BLAST_OPTION: - case SC_WATER_DROP_OPTION: - case SC_WIND_CURTAIN_OPTION: - case SC_WILD_STORM_OPTION: - case SC_PETROLOGY_OPTION: - case SC_SOLID_SKIN_OPTION: - case SC_CURSED_SOIL_OPTION: - case SC_STONE_SHIELD_OPTION: - case SC_UPHEAVAL_OPTION: - case SC_CIRCLE_OF_FIRE_OPTION: - case SC_TIDAL_WEAPON_OPTION: - if( bl ) status_change_end(bl,type,INVALID_TIMER); // Master - status_change_end(&ed->bl,type-1,INVALID_TIMER); // Elemental Spirit - break; - case SC_ZEPHYR: - if( bl ) status_change_end(bl,type,INVALID_TIMER); - break; - default: - ShowWarning("Invalid SC=%d in elemental_clean_single_effect\n",type); - break; - } - } - - return 1; -} - -int elemental_clean_effect(struct elemental_data *ed) { - struct map_session_data *sd; - - nullpo_ret(ed); - - // Elemental side - status_change_end(&ed->bl, SC_TROPIC, INVALID_TIMER); - status_change_end(&ed->bl, SC_HEATER, INVALID_TIMER); - status_change_end(&ed->bl, SC_AQUAPLAY, INVALID_TIMER); - status_change_end(&ed->bl, SC_COOLER, INVALID_TIMER); - status_change_end(&ed->bl, SC_CHILLY_AIR, INVALID_TIMER); - status_change_end(&ed->bl, SC_PYROTECHNIC, INVALID_TIMER); - status_change_end(&ed->bl, SC_FIRE_CLOAK, INVALID_TIMER); - status_change_end(&ed->bl, SC_WATER_DROP, INVALID_TIMER); - status_change_end(&ed->bl, SC_WATER_SCREEN, INVALID_TIMER); - status_change_end(&ed->bl, SC_GUST, INVALID_TIMER); - status_change_end(&ed->bl, SC_WIND_STEP, INVALID_TIMER); - status_change_end(&ed->bl, SC_BLAST, INVALID_TIMER); - status_change_end(&ed->bl, SC_WIND_CURTAIN, INVALID_TIMER); - status_change_end(&ed->bl, SC_WILD_STORM, INVALID_TIMER); - status_change_end(&ed->bl, SC_PETROLOGY, INVALID_TIMER); - status_change_end(&ed->bl, SC_SOLID_SKIN, INVALID_TIMER); - status_change_end(&ed->bl, SC_CURSED_SOIL, INVALID_TIMER); - status_change_end(&ed->bl, SC_STONE_SHIELD, INVALID_TIMER); - status_change_end(&ed->bl, SC_UPHEAVAL, INVALID_TIMER); - status_change_end(&ed->bl, SC_CIRCLE_OF_FIRE, INVALID_TIMER); - status_change_end(&ed->bl, SC_TIDAL_WEAPON, INVALID_TIMER); - - if( (sd = ed->master) == NULL ) - return 0; - - // Master side - status_change_end(&sd->bl, SC_TROPIC_OPTION, INVALID_TIMER); - status_change_end(&sd->bl, SC_HEATER_OPTION, INVALID_TIMER); - status_change_end(&sd->bl, SC_AQUAPLAY_OPTION, INVALID_TIMER); - status_change_end(&sd->bl, SC_COOLER_OPTION, INVALID_TIMER); - status_change_end(&sd->bl, SC_CHILLY_AIR_OPTION, INVALID_TIMER); - status_change_end(&sd->bl, SC_PYROTECHNIC_OPTION, INVALID_TIMER); - status_change_end(&sd->bl, SC_FIRE_CLOAK_OPTION, INVALID_TIMER); - status_change_end(&sd->bl, SC_WATER_DROP_OPTION, INVALID_TIMER); - status_change_end(&sd->bl, SC_WATER_SCREEN_OPTION, INVALID_TIMER); - status_change_end(&sd->bl, SC_GUST_OPTION, INVALID_TIMER); - status_change_end(&sd->bl, SC_WIND_STEP_OPTION, INVALID_TIMER); - status_change_end(&sd->bl, SC_BLAST_OPTION, INVALID_TIMER); - status_change_end(&sd->bl, SC_WATER_DROP_OPTION, INVALID_TIMER); - status_change_end(&sd->bl, SC_WIND_CURTAIN_OPTION, INVALID_TIMER); - status_change_end(&sd->bl, SC_WILD_STORM_OPTION, INVALID_TIMER); - status_change_end(&sd->bl, SC_ZEPHYR, INVALID_TIMER); - status_change_end(&sd->bl, SC_WIND_STEP_OPTION, INVALID_TIMER); - status_change_end(&sd->bl, SC_PETROLOGY_OPTION, INVALID_TIMER); - status_change_end(&sd->bl, SC_SOLID_SKIN_OPTION, INVALID_TIMER); - status_change_end(&sd->bl, SC_CURSED_SOIL_OPTION, INVALID_TIMER); - status_change_end(&sd->bl, SC_STONE_SHIELD_OPTION, INVALID_TIMER); - status_change_end(&sd->bl, SC_UPHEAVAL_OPTION, INVALID_TIMER); - status_change_end(&sd->bl, SC_CIRCLE_OF_FIRE_OPTION, INVALID_TIMER); - status_change_end(&sd->bl, SC_TIDAL_WEAPON_OPTION, INVALID_TIMER); - - return 1; -} - -int elemental_action(struct elemental_data *ed, struct block_list *bl, unsigned int tick) { - struct skill_condition req; - uint16 skill_id, skill_lv; - int i; - - nullpo_ret(ed); - nullpo_ret(bl); - - if( !ed->master ) - return 0; - - if( ed->target_id ) - elemental->unlocktarget(ed); // Remove previous target. - - ARR_FIND(0, MAX_ELESKILLTREE, i, ed->db->skill[i].id && (ed->db->skill[i].mode&EL_SKILLMODE_AGGRESSIVE)); - if( i == MAX_ELESKILLTREE ) - return 0; - - skill_id = ed->db->skill[i].id; - skill_lv = ed->db->skill[i].lv; - - if( elemental->skillnotok(skill_id, ed) ) - return 0; - - if( ed->ud.skilltimer != INVALID_TIMER ) - return 0; - else if( DIFF_TICK(tick, ed->ud.canact_tick) < 0 ) - return 0; - - ed->target_id = ed->ud.skilltarget = bl->id; // Set new target - ed->last_thinktime = tick; - - // Not in skill range. - if( !battle->check_range(&ed->bl,bl,skill->get_range(skill_id,skill_lv)) ) { - // Try to walk to the target. - if( !unit_walktobl(&ed->bl, bl, skill->get_range(skill_id,skill_lv), 2) ) - elemental->unlocktarget(ed); - else { - // Walking, waiting to be in range. Client don't handle it, then we must handle it here. - int walk_dist = distance_bl(&ed->bl,bl) - skill->get_range(skill_id,skill_lv); - ed->ud.skill_id = skill_id; - ed->ud.skill_lv = skill_lv; - - if( skill->get_inf(skill_id) & INF_GROUND_SKILL ) - ed->ud.skilltimer = iTimer->add_timer( tick+iStatus->get_speed(&ed->bl)*walk_dist, skill->castend_pos, ed->bl.id, 0 ); - else - ed->ud.skilltimer = iTimer->add_timer( tick+iStatus->get_speed(&ed->bl)*walk_dist, skill->castend_id, ed->bl.id, 0 ); - } - return 1; - - } - - req = elemental->skill_get_requirements(skill_id, skill_lv); - - if(req.hp || req.sp){ - struct map_session_data *sd = BL_CAST(BL_PC, battle->get_master(&ed->bl)); - if( sd ){ - if( sd->skill_id_old != SO_EL_ACTION && //regardless of remaining HP/SP it can be cast - (status_get_hp(&ed->bl) < req.hp || status_get_sp(&ed->bl) < req.sp) ) - return 1; - else - status_zap(&ed->bl, req.hp, req.sp); - } - } - - //Otherwise, just cast the skill. - if( skill->get_inf(skill_id) & INF_GROUND_SKILL ) - unit_skilluse_pos(&ed->bl, bl->x, bl->y, skill_id, skill_lv); - else - unit_skilluse_id(&ed->bl, bl->id, skill_id, skill_lv); - - // Reset target. - ed->target_id = 0; - - return 1; -} - -/*=============================================================== - * Action that elemental perform after changing mode. - * Activates one of the skills of the new mode. - *-------------------------------------------------------------*/ -int elemental_change_mode_ack(struct elemental_data *ed, int mode) { - struct block_list *bl = &ed->master->bl; - uint16 skill_id, skill_lv; - int i; - - nullpo_ret(ed); - - if( !bl ) - return 0; - - // Select a skill. - ARR_FIND(0, MAX_ELESKILLTREE, i, ed->db->skill[i].id && (ed->db->skill[i].mode&mode)); - if( i == MAX_ELESKILLTREE ) - return 0; - - skill_id = ed->db->skill[i].id; - skill_lv = ed->db->skill[i].lv; - - if( elemental->skillnotok(skill_id, ed) ) - return 0; - - if( ed->ud.skilltimer != INVALID_TIMER ) - return 0; - else if( DIFF_TICK(iTimer->gettick(), ed->ud.canact_tick) < 0 ) - return 0; - - ed->target_id = bl->id; // Set new target - ed->last_thinktime = iTimer->gettick(); - - if( skill->get_inf(skill_id) & INF_GROUND_SKILL ) - unit_skilluse_pos(&ed->bl, bl->x, bl->y, skill_id, skill_lv); - else - unit_skilluse_id(&ed->bl,bl->id,skill_id,skill_lv); - - ed->target_id = 0; // Reset target after casting the skill to avoid continious attack. - - return 1; -} - -/*=============================================================== - * Change elemental mode. - *-------------------------------------------------------------*/ -int elemental_change_mode(struct elemental_data *ed, int mode) { - nullpo_ret(ed); - - // Remove target - elemental->unlocktarget(ed); - - // Removes the effects of the previous mode. - if(ed->elemental.mode != mode ) elemental->clean_effect(ed); - - ed->battle_status.mode = ed->elemental.mode = mode; - - // Normalize elemental mode to elemental skill mode. - if( mode == EL_MODE_AGGRESSIVE ) mode = EL_SKILLMODE_AGGRESSIVE; // Aggressive spirit mode -> Aggressive spirit skill. - else if( mode == EL_MODE_ASSIST ) mode = EL_SKILLMODE_ASSIST; // Assist spirit mode -> Assist spirit skill. - else mode = EL_SKILLMODE_PASIVE; // Passive spirit mode -> Passive spirit skill. - - // Use a skill inmediately after every change mode. - if( mode != EL_SKILLMODE_AGGRESSIVE ) - elemental->change_mode_ack(ed,mode); - return 1; -} - -void elemental_heal(struct elemental_data *ed, int hp, int sp) { - if( hp ) - clif->elemental_updatestatus(ed->master, SP_HP); - if( sp ) - clif->elemental_updatestatus(ed->master, SP_SP); -} - -int elemental_dead(struct elemental_data *ed) { - elemental->delete(ed, 1); - return 0; -} - -int elemental_unlocktarget(struct elemental_data *ed) { - nullpo_ret(ed); - - ed->target_id = 0; - elemental_stop_attack(ed); - elemental_stop_walking(ed,1); - return 0; -} - -int elemental_skillnotok(uint16 skill_id, struct elemental_data *ed) { - int idx = skill->get_index(skill_id); - nullpo_retr(1,ed); - - if (idx == 0) - return 1; // invalid skill id - - return skill->not_ok(skill_id, ed->master); -} - -struct skill_condition elemental_skill_get_requirements(uint16 skill_id, uint16 skill_lv){ - struct skill_condition req; - int idx = skill->get_index(skill_id); - - memset(&req,0,sizeof(req)); - - if( idx == 0 ) // invalid skill id - return req; - - if( skill_lv < 1 || skill_lv > MAX_SKILL_LEVEL ) - return req; - - req.hp = skill_db[idx].hp[skill_lv-1]; - req.sp = skill_db[idx].sp[skill_lv-1]; - - return req; -} - -int elemental_set_target( struct map_session_data *sd, struct block_list *bl ) { - struct elemental_data *ed = sd->ed; - - nullpo_ret(ed); - nullpo_ret(bl); - - if( ed->bl.m != bl->m || !check_distance_bl(&ed->bl, bl, ed->db->range2) ) - return 0; - - if( !iStatus->check_skilluse(&ed->bl, bl, 0, 0) ) - return 0; - - if( ed->target_id == 0 ) - ed->target_id = bl->id; - - return 1; -} - -static int elemental_ai_sub_timer_activesearch(struct block_list *bl, va_list ap) { - struct elemental_data *ed; - struct block_list **target; - int dist; - - nullpo_ret(bl); - - ed = va_arg(ap,struct elemental_data *); - target = va_arg(ap,struct block_list**); - - //If can't seek yet, not an enemy, or you can't attack it, skip. - if( (*target) == bl || !iStatus->check_skilluse(&ed->bl, bl, 0, 0) ) - return 0; - - if( battle->check_target(&ed->bl,bl,BCT_ENEMY) <= 0 ) - return 0; - - switch( bl->type ) { - case BL_PC: - if( !map_flag_vs(ed->bl.m) ) - return 0; - default: - dist = distance_bl(&ed->bl, bl); - if( ((*target) == NULL || !check_distance_bl(&ed->bl, *target, dist)) && battle->check_range(&ed->bl,bl,ed->db->range2) ) { //Pick closest target? - (*target) = bl; - ed->target_id = bl->id; - ed->min_chase = dist + ed->db->range3; - if( ed->min_chase > AREA_SIZE ) - ed->min_chase = AREA_SIZE; - return 1; - } - break; - } - return 0; -} - -static int elemental_ai_sub_timer(struct elemental_data *ed, struct map_session_data *sd, unsigned int tick) { - struct block_list *target = NULL; - int master_dist, view_range, mode; - - nullpo_ret(ed); - nullpo_ret(sd); - - if( ed->bl.prev == NULL || sd == NULL || sd->bl.prev == NULL ) - return 0; - - // Check if caster can sustain the summoned elemental - if( DIFF_TICK(tick,ed->last_spdrain_time) >= 10000 ){// Drain SP every 10 seconds - int sp = 5; - - switch(ed->vd->class_){ - case 2115: case 2118: - case 2121: case 2124: - sp = 8; - break; - case 2116: case 2119: - case 2122: case 2125: - sp = 11; - break; - } - - if( status_get_sp(&sd->bl) < sp ){ // Can't sustain delete it. - elemental->delete(sd->ed,0); - return 0; - } - - status_zap(&sd->bl,0,sp); - ed->last_spdrain_time = tick; - } - - if( DIFF_TICK(tick,ed->last_thinktime) < MIN_ELETHINKTIME ) - return 0; - - ed->last_thinktime = tick; - - if( ed->ud.skilltimer != INVALID_TIMER ) - return 0; - - if( ed->ud.walktimer != INVALID_TIMER && ed->ud.walkpath.path_pos <= 2 ) - return 0; //No thinking when you just started to walk. - - if(ed->ud.walkpath.path_pos < ed->ud.walkpath.path_len && ed->ud.target == sd->bl.id) - return 0; //No thinking until be near the master. - - if( ed->sc.count && ed->sc.data[SC_BLIND] ) - view_range = 3; - else - view_range = ed->db->range2; - - mode = status_get_mode(&ed->bl); - - master_dist = distance_bl(&sd->bl, &ed->bl); - if( master_dist > AREA_SIZE ) { // Master out of vision range. - elemental->unlocktarget(ed); - unit_warp(&ed->bl,sd->bl.m,sd->bl.x,sd->bl.y,CLR_TELEPORT); - clif->elemental_updatestatus(sd,SP_HP); - clif->elemental_updatestatus(sd,SP_SP); - return 0; - } else if( master_dist > MAX_ELEDISTANCE ) { // Master too far, chase. - short x = sd->bl.x, y = sd->bl.y; - if( ed->target_id ) - elemental->unlocktarget(ed); - if( ed->ud.walktimer != INVALID_TIMER && ed->ud.target == sd->bl.id ) - return 0; //Already walking to him - if( DIFF_TICK(tick, ed->ud.canmove_tick) < 0 ) - return 0; //Can't move yet. - if( iMap->search_freecell(&ed->bl, sd->bl.m, &x, &y, MIN_ELEDISTANCE, MIN_ELEDISTANCE, 1) - && unit_walktoxy(&ed->bl, x, y, 0) ) - return 0; - } - - if( mode == EL_MODE_AGGRESSIVE ) { - target = iMap->id2bl(ed->ud.target); - - if( !target ) - iMap->foreachinrange(elemental_ai_sub_timer_activesearch, &ed->bl, view_range, BL_CHAR, ed, &target, status_get_mode(&ed->bl)); - - if( !target ) { //No targets available. - elemental->unlocktarget(ed); - return 1; - } - - if( battle->check_range(&ed->bl,target,view_range) && rnd()%100 < 2 ) { // 2% chance to cast attack skill. - if( elemental->action(ed,target,tick) ) - return 1; - } - - //Attempt to attack. - //At this point we know the target is attackable, we just gotta check if the range matches. - if( ed->ud.target == target->id && ed->ud.attacktimer != INVALID_TIMER ) //Already locked. - return 1; - - if( battle->check_range(&ed->bl, target, ed->base_status.rhw.range) ) {//Target within range, engage - unit_attack(&ed->bl,target->id,1); - return 1; - } - - //Follow up if possible. - if( !unit_walktobl(&ed->bl, target, ed->base_status.rhw.range, 2) ) - elemental->unlocktarget(ed); - } - - return 0; -} - -static int elemental_ai_sub_foreachclient(struct map_session_data *sd, va_list ap) { - unsigned int tick = va_arg(ap,unsigned int); - if(sd->status.ele_id && sd->ed) - elemental_ai_sub_timer(sd->ed,sd,tick); - - return 0; -} - -static int elemental_ai_timer(int tid, unsigned int tick, int id, intptr_t data) { - iMap->map_foreachpc(elemental_ai_sub_foreachclient,tick); - return 0; -} - -int read_elementaldb(void) { - FILE *fp; - char line[1024], *p; - char *str[26]; - int i, j = 0, k = 0, ele; - struct s_elemental_db *db; - struct status_data *status; - - sprintf(line, "%s/%s", iMap->db_path, "elemental_db.txt"); - memset(elemental->elemental_db,0,sizeof(elemental->elemental_db)); - - fp = fopen(line, "r"); - if( !fp ) { - ShowError("read_elementaldb : can't read elemental_db.txt\n"); - return -1; - } - - while( fgets(line, sizeof(line), fp) && j < MAX_ELEMENTAL_CLASS ) { - k++; - if( line[0] == '/' && line[1] == '/' ) - continue; - - if( line[0] == '\0' || line[0] == '\n' || line[0] == '\r') - continue; - - i = 0; - p = strtok(line, ","); - while( p != NULL && i < 26 ) { - str[i++] = p; - p = strtok(NULL, ","); - } - if( i < 26 ) { - ShowError("read_elementaldb : Incorrect number of columns at elemental_db.txt line %d.\n", k); - continue; - } - - db = &elemental->elemental_db[j]; - 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 = 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("Elemental %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("Elemental %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]); - - j++; - } - - fclose(fp); - ShowStatus("Done reading '"CL_WHITE"%d"CL_RESET"' elementals in '"CL_WHITE"db/elemental_db.txt"CL_RESET"'.\n",j); - - return 0; -} - -int read_elemental_skilldb(void) { - FILE *fp; - char line[1024], *p; - char *str[4]; - struct s_elemental_db *db; - int i, j = 0, k = 0, class_; - uint16 skill_id, skill_lv; - int skillmode; - - sprintf(line, "%s/%s", iMap->db_path, "elemental_skill_db.txt"); - fp = fopen(line, "r"); - if( !fp ) { - ShowError("read_elemental_skilldb : can't read elemental_skill_db.txt\n"); - return -1; - } - - while( fgets(line, sizeof(line), fp) ) { - k++; - if( line[0] == '/' && line[1] == '/' ) - continue; - - if( line[0] == '\0' || line[0] == '\n' || line[0] == '\r') - continue; - - i = 0; - p = strtok(line, ","); - while( p != NULL && i < 4 ) { - str[i++] = p; - p = strtok(NULL, ","); - } - if( i < 4 ) { - ShowError("read_elemental_skilldb : Incorrect number of columns at elemental_skill_db.txt line %d.\n", k); - continue; - } - - class_ = atoi(str[0]); - ARR_FIND(0, MAX_ELEMENTAL_CLASS, i, class_ == elemental->elemental_db[i].class_); - if( i == MAX_ELEMENTAL_CLASS ) { - ShowError("read_elemental_skilldb : Class not found in elemental_db for skill entry, line %d.\n", k); - continue; - } - - skill_id = atoi(str[1]); - if( skill_id < EL_SKILLBASE || skill_id >= EL_SKILLBASE + MAX_ELEMENTALSKILL ) { - ShowError("read_elemental_skilldb : Skill out of range, line %d.\n", k); - continue; - } - - db = &elemental->elemental_db[i]; - skill_lv = atoi(str[2]); - - skillmode = atoi(str[3]); - if( skillmode < EL_SKILLMODE_PASIVE || skillmode > EL_SKILLMODE_AGGRESSIVE ) { - ShowError("read_elemental_skilldb : Skillmode out of range, line %d.\n",k); - continue; - } - ARR_FIND( 0, MAX_ELESKILLTREE, i, db->skill[i].id == 0 || db->skill[i].id == skill_id ); - if( i == MAX_ELESKILLTREE ) { - ShowWarning("Unable to load skill %d into Elemental %d's tree. Maximum number of skills per elemental has been reached.\n", skill_id, class_); - continue; - } - db->skill[i].id = skill_id; - db->skill[i].lv = skill_lv; - db->skill[i].mode = skillmode; - j++; - } - - fclose(fp); - ShowStatus("Done reading '"CL_WHITE"%d"CL_RESET"' entries in '"CL_WHITE"db/elemental_skill_db.txt"CL_RESET"'.\n",j); - return 0; -} - -void reload_elementaldb(void) { - read_elementaldb(); - elemental->reload_skilldb(); -} - -void reload_elemental_skilldb(void) { - elemental->read_skilldb(); -} - -int do_init_elemental(void) { - read_elementaldb(); - elemental->read_skilldb(); - - iTimer->add_timer_func_list(elemental_ai_timer,"elemental_ai_timer"); - iTimer->add_timer_interval(iTimer->gettick()+MIN_ELETHINKTIME,elemental_ai_timer,0,0,MIN_ELETHINKTIME); - - return 0; -} - -void do_final_elemental(void) { - return; -} - -/*===================================== -* Default Functions : elemental.h -* Generated by HerculesInterfaceMaker -* created by Susu -*-------------------------------------*/ -void elemental_defaults(void) { - elemental = &elemental_s; - /* funcs */ - - elemental->class = elemental_class; - elemental->get_viewdata = elemental_get_viewdata; - - elemental->create = elemental_create; - elemental->data_received = elemental_data_received; - elemental->save = elemental_save; - - elemental->change_mode_ack = elemental_change_mode_ack; - elemental->change_mode = elemental_change_mode; - - elemental->heal = elemental_heal; - elemental->dead = elemental_dead; - - elemental->delete = elemental_delete; - elemental->summon_stop = elemental_summon_stop; - - elemental->get_lifetime = elemental_get_lifetime; - - elemental->unlocktarget = elemental_unlocktarget; - elemental->skillnotok = elemental_skillnotok; - elemental->set_target = elemental_set_target; - elemental->clean_single_effect = elemental_clean_single_effect; - elemental->clean_effect = elemental_clean_effect; - elemental->action = elemental_action; - elemental->skill_get_requirements = elemental_skill_get_requirements; - - elemental->read_skilldb = read_elemental_skilldb; - elemental->reload_elementaldb = reload_elementaldb; - elemental->reload_skilldb = reload_elemental_skilldb; - elemental->do_init_elemental = do_init_elemental; - elemental->do_final_elemental = do_final_elemental; -} +// 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/showmsg.h" +#include "../common/utils.h" +#include "../common/random.h" +#include "../common/strlib.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 "elemental.h" + +#include +#include +#include +#include + +int elemental_search_index(int class_) { + int i; + ARR_FIND(0, MAX_ELEMENTAL_CLASS, i, elemental->elemental_db[i].class_ == class_); + return (i == MAX_ELEMENTAL_CLASS)?-1:i; +} + +bool elemental_class(int class_) { + return (bool)(elemental_search_index(class_) > -1); +} + +struct view_data * elemental_get_viewdata(int class_) { + int i = elemental_search_index(class_); + if( i < 0 ) + return 0; + + return &elemental->elemental_db[i].vd; +} + +int elemental_create(struct map_session_data *sd, int class_, unsigned int lifetime) { + struct s_elemental ele; + struct s_elemental_db *db; + int i; + + nullpo_retr(1,sd); + + if( (i = elemental_search_index(class_)) < 0 ) + return 0; + + db = &elemental->elemental_db[i]; + memset(&ele,0,sizeof(struct s_elemental)); + + ele.char_id = sd->status.char_id; + ele.class_ = class_; + ele.mode = EL_MODE_PASSIVE; // Initial mode + i = db->status.size+1; // summon level + + //[(Caster�s Max HP/ 3 ) + (Caster�s INT x 10 )+ (Caster�s Job Level x 20 )] x [(Elemental Summon Level + 2) / 3] + ele.hp = ele.max_hp = (sd->battle_status.max_hp/3 + sd->battle_status.int_*10 + sd->status.job_level) * ((i + 2) / 3); + //Caster�s Max SP /4 + ele.sp = ele.max_sp = sd->battle_status.max_sp/4; + //Caster�s [ Max SP / (18 / Elemental Summon Skill Level) 1- 100 ] + ele.atk = (sd->battle_status.max_sp / (18 / i) * 1 - 100); + //Caster�s [ Max SP / (18 / Elemental Summon Skill Level) ] + ele.atk2 = sd->battle_status.max_sp / 18; + //Caster�s HIT + (Caster�s Base Level ) + ele.hit = sd->battle_status.hit + sd->status.base_level; + //[Elemental Summon Skill Level x (Caster�s INT / 2 + Caster�s DEX / 4)] + ele.matk = i * (sd->battle_status.int_ / 2 + sd->battle_status.dex / 4); + //150 + [Caster�s DEX / 10] + [Elemental Summon Skill Level x 3 ] + ele.amotion = 150 + sd->battle_status.dex / 10 + i * 3; + //Caster�s DEF + (Caster�s Base Level / (5 � Elemental Summon Skill Level) + ele.def = sd->battle_status.def + sd->status.base_level / (5-i); + //Caster�s MDEF + (Caster�s INT / (5 - Elemental Summon Skill Level) + ele.mdef = sd->battle_status.mdef + sd->battle_status.int_ / (5-i); + //Caster�s FLEE + (Caster�s Base Level / (5 � Elemental Summon Skill Level) + ele.flee = sd->status.base_level / (5-i); + //Caster�s HIT + (Caster�s Base Level ) + ele.hit = sd->battle_status.hit + sd->status.base_level; + + //per individual bonuses + switch(db->class_){ + case 2114: case 2115: + case 2116: //ATK + (Summon Agni Skill Level x 20) / HIT + (Summon Agni Skill Level x 10) + ele.atk += i * 20; + ele.atk2 += i * 20; + ele.hit += i * 10; + break; + case 2117: case 2118: + case 2119: //MDEF + (Summon Aqua Skill Level x 10) / MATK + (Summon Aqua Skill Level x 20) + ele.mdef += i * 10; + ele.matk += i * 20; + break; + case 2120: case 2121: + case 2122: //FLEE + (Summon Ventus Skill Level x 20) / MATK + (Summon Ventus Skill Level x 10) + ele.flee += i * 20; + ele.matk += i * 10; + break; + case 2123: case 2124: + case 2125: //DEF + (Summon Tera Skill Level x 25) / ATK + (Summon Tera Skill Level x 5) + ele.def += i * 25; + ele.atk += i * 5; + ele.atk2 += i * 5; + break; + } + + if( (i=pc->checkskill(sd,SO_EL_SYMPATHY)) > 0 ){ + ele.hp = ele.max_hp = ele.max_hp * 5 * i / 100; + ele.sp = ele.max_sp = ele.max_sp * 5 * i / 100; + ele.atk += 25 * i; + ele.atk2 += 25 * i; + ele.matk += 25 * i; + } + + ele.life_time = lifetime; + + // Request Char Server to create this elemental + intif->elemental_create(&ele); + + return 1; +} + +int elemental_get_lifetime(struct elemental_data *ed) { + const struct TimerData * td; + if( ed == NULL || ed->summon_timer == INVALID_TIMER ) + return 0; + + td = iTimer->get_timer(ed->summon_timer); + return (td != NULL) ? DIFF_TICK(td->tick, iTimer->gettick()) : 0; +} + +int elemental_save(struct elemental_data *ed) { + ed->elemental.mode = ed->battle_status.mode; + ed->elemental.hp = ed->battle_status.hp; + ed->elemental.sp = ed->battle_status.sp; + ed->elemental.max_hp = ed->battle_status.max_hp; + ed->elemental.max_sp = ed->battle_status.max_sp; + ed->elemental.atk = ed->battle_status.rhw.atk; + ed->elemental.atk2 = ed->battle_status.rhw.atk2; + ed->elemental.matk = ed->battle_status.matk_min; + ed->elemental.def = ed->battle_status.def; + ed->elemental.mdef = ed->battle_status.mdef; + ed->elemental.flee = ed->battle_status.flee; + ed->elemental.hit = ed->battle_status.hit; + ed->elemental.life_time = elemental->get_lifetime(ed); + intif->elemental_save(&ed->elemental); + return 1; +} + +static int elemental_summon_end(int tid, unsigned int tick, int id, intptr_t data) { + struct map_session_data *sd; + struct elemental_data *ed; + + if( (sd = iMap->id2sd(id)) == NULL ) + return 1; + if( (ed = sd->ed) == NULL ) + return 1; + + if( ed->summon_timer != tid ) { + ShowError("elemental_summon_end %d != %d.\n", ed->summon_timer, tid); + return 0; + } + + ed->summon_timer = INVALID_TIMER; + elemental->delete(ed, 0); // Elemental's summon time is over. + + return 0; +} + +void elemental_summon_stop(struct elemental_data *ed) { + nullpo_retv(ed); + if( ed->summon_timer != INVALID_TIMER ) + iTimer->delete_timer(ed->summon_timer, elemental_summon_end); + ed->summon_timer = INVALID_TIMER; +} + +int elemental_delete(struct elemental_data *ed, int reply) { + struct map_session_data *sd; + nullpo_ret(ed); + + sd = ed->master; + ed->elemental.life_time = 0; + + elemental->clean_effect(ed); + elemental->summon_stop(ed); + + if( !sd ) + return unit_free(&ed->bl, 0); + + sd->ed = NULL; + sd->status.ele_id = 0; + + return unit_remove_map(&ed->bl, 0); +} + +void elemental_summon_init(struct elemental_data *ed) { + if( ed->summon_timer == INVALID_TIMER ) + ed->summon_timer = iTimer->add_timer(iTimer->gettick() + ed->elemental.life_time, elemental_summon_end, ed->master->bl.id, 0); + + ed->regen.state.block = 0; +} + +int elemental_data_received(struct s_elemental *ele, bool flag) { + struct map_session_data *sd; + struct elemental_data *ed; + struct s_elemental_db *db; + int i = elemental_search_index(ele->class_); + + if( (sd = iMap->charid2sd(ele->char_id)) == NULL ) + return 0; + + if( !flag || i < 0 ) { // Not created - loaded - DB info + sd->status.ele_id = 0; + return 0; + } + + db = &elemental->elemental_db[i]; + if( !sd->ed ) { // Initialize it after first summon. + sd->ed = ed = (struct elemental_data*)aCalloc(1,sizeof(struct elemental_data)); + ed->bl.type = BL_ELEM; + ed->bl.id = npc_get_new_npc_id(); + ed->master = sd; + ed->db = db; + memcpy(&ed->elemental, ele, sizeof(struct s_elemental)); + iStatus->set_viewdata(&ed->bl, ed->elemental.class_); + ed->vd->head_mid = 10; // Why? + iStatus->change_init(&ed->bl); + unit_dataset(&ed->bl); + ed->ud.dir = sd->ud.dir; + + ed->bl.m = sd->bl.m; + ed->bl.x = sd->bl.x; + ed->bl.y = sd->bl.y; + unit_calc_pos(&ed->bl, sd->bl.x, sd->bl.y, sd->ud.dir); + ed->bl.x = ed->ud.to_x; + ed->bl.y = ed->ud.to_y; + + iMap->addiddb(&ed->bl); + status_calc_elemental(ed,1); + ed->last_spdrain_time = ed->last_thinktime = iTimer->gettick(); + ed->summon_timer = INVALID_TIMER; + elemental_summon_init(ed); + } else { + memcpy(&sd->ed->elemental, ele, sizeof(struct s_elemental)); + ed = sd->ed; + } + + sd->status.ele_id = ele->elemental_id; + + if( ed->bl.prev == NULL && sd->bl.prev != NULL ) { + iMap->addblock(&ed->bl); + clif->spawn(&ed->bl); + clif->elemental_info(sd); + clif->elemental_updatestatus(sd,SP_HP); + clif->hpmeter_single(sd->fd,ed->bl.id,ed->battle_status.hp,ed->battle_status.max_hp); + clif->elemental_updatestatus(sd,SP_SP); + } + + return 1; +} + +int elemental_clean_single_effect(struct elemental_data *ed, uint16 skill_id) { + struct block_list *bl; + sc_type type = iStatus->skill2sc(skill_id); + + nullpo_ret(ed); + + bl = battle->get_master(&ed->bl); + + if( type ) { + switch( type ) { + // Just remove status change. + case SC_PYROTECHNIC_OPTION: + case SC_HEATER_OPTION: + case SC_TROPIC_OPTION: + case SC_FIRE_CLOAK_OPTION: + case SC_AQUAPLAY_OPTION: + case SC_WATER_SCREEN_OPTION: + case SC_COOLER_OPTION: + case SC_CHILLY_AIR_OPTION: + case SC_GUST_OPTION: + case SC_WIND_STEP_OPTION: + case SC_BLAST_OPTION: + case SC_WATER_DROP_OPTION: + case SC_WIND_CURTAIN_OPTION: + case SC_WILD_STORM_OPTION: + case SC_PETROLOGY_OPTION: + case SC_SOLID_SKIN_OPTION: + case SC_CURSED_SOIL_OPTION: + case SC_STONE_SHIELD_OPTION: + case SC_UPHEAVAL_OPTION: + case SC_CIRCLE_OF_FIRE_OPTION: + case SC_TIDAL_WEAPON_OPTION: + if( bl ) status_change_end(bl,type,INVALID_TIMER); // Master + status_change_end(&ed->bl,type-1,INVALID_TIMER); // Elemental Spirit + break; + case SC_ZEPHYR: + if( bl ) status_change_end(bl,type,INVALID_TIMER); + break; + default: + ShowWarning("Invalid SC=%d in elemental_clean_single_effect\n",type); + break; + } + } + + return 1; +} + +int elemental_clean_effect(struct elemental_data *ed) { + struct map_session_data *sd; + + nullpo_ret(ed); + + // Elemental side + status_change_end(&ed->bl, SC_TROPIC, INVALID_TIMER); + status_change_end(&ed->bl, SC_HEATER, INVALID_TIMER); + status_change_end(&ed->bl, SC_AQUAPLAY, INVALID_TIMER); + status_change_end(&ed->bl, SC_COOLER, INVALID_TIMER); + status_change_end(&ed->bl, SC_CHILLY_AIR, INVALID_TIMER); + status_change_end(&ed->bl, SC_PYROTECHNIC, INVALID_TIMER); + status_change_end(&ed->bl, SC_FIRE_CLOAK, INVALID_TIMER); + status_change_end(&ed->bl, SC_WATER_DROP, INVALID_TIMER); + status_change_end(&ed->bl, SC_WATER_SCREEN, INVALID_TIMER); + status_change_end(&ed->bl, SC_GUST, INVALID_TIMER); + status_change_end(&ed->bl, SC_WIND_STEP, INVALID_TIMER); + status_change_end(&ed->bl, SC_BLAST, INVALID_TIMER); + status_change_end(&ed->bl, SC_WIND_CURTAIN, INVALID_TIMER); + status_change_end(&ed->bl, SC_WILD_STORM, INVALID_TIMER); + status_change_end(&ed->bl, SC_PETROLOGY, INVALID_TIMER); + status_change_end(&ed->bl, SC_SOLID_SKIN, INVALID_TIMER); + status_change_end(&ed->bl, SC_CURSED_SOIL, INVALID_TIMER); + status_change_end(&ed->bl, SC_STONE_SHIELD, INVALID_TIMER); + status_change_end(&ed->bl, SC_UPHEAVAL, INVALID_TIMER); + status_change_end(&ed->bl, SC_CIRCLE_OF_FIRE, INVALID_TIMER); + status_change_end(&ed->bl, SC_TIDAL_WEAPON, INVALID_TIMER); + + if( (sd = ed->master) == NULL ) + return 0; + + // Master side + status_change_end(&sd->bl, SC_TROPIC_OPTION, INVALID_TIMER); + status_change_end(&sd->bl, SC_HEATER_OPTION, INVALID_TIMER); + status_change_end(&sd->bl, SC_AQUAPLAY_OPTION, INVALID_TIMER); + status_change_end(&sd->bl, SC_COOLER_OPTION, INVALID_TIMER); + status_change_end(&sd->bl, SC_CHILLY_AIR_OPTION, INVALID_TIMER); + status_change_end(&sd->bl, SC_PYROTECHNIC_OPTION, INVALID_TIMER); + status_change_end(&sd->bl, SC_FIRE_CLOAK_OPTION, INVALID_TIMER); + status_change_end(&sd->bl, SC_WATER_DROP_OPTION, INVALID_TIMER); + status_change_end(&sd->bl, SC_WATER_SCREEN_OPTION, INVALID_TIMER); + status_change_end(&sd->bl, SC_GUST_OPTION, INVALID_TIMER); + status_change_end(&sd->bl, SC_WIND_STEP_OPTION, INVALID_TIMER); + status_change_end(&sd->bl, SC_BLAST_OPTION, INVALID_TIMER); + status_change_end(&sd->bl, SC_WATER_DROP_OPTION, INVALID_TIMER); + status_change_end(&sd->bl, SC_WIND_CURTAIN_OPTION, INVALID_TIMER); + status_change_end(&sd->bl, SC_WILD_STORM_OPTION, INVALID_TIMER); + status_change_end(&sd->bl, SC_ZEPHYR, INVALID_TIMER); + status_change_end(&sd->bl, SC_WIND_STEP_OPTION, INVALID_TIMER); + status_change_end(&sd->bl, SC_PETROLOGY_OPTION, INVALID_TIMER); + status_change_end(&sd->bl, SC_SOLID_SKIN_OPTION, INVALID_TIMER); + status_change_end(&sd->bl, SC_CURSED_SOIL_OPTION, INVALID_TIMER); + status_change_end(&sd->bl, SC_STONE_SHIELD_OPTION, INVALID_TIMER); + status_change_end(&sd->bl, SC_UPHEAVAL_OPTION, INVALID_TIMER); + status_change_end(&sd->bl, SC_CIRCLE_OF_FIRE_OPTION, INVALID_TIMER); + status_change_end(&sd->bl, SC_TIDAL_WEAPON_OPTION, INVALID_TIMER); + + return 1; +} + +int elemental_action(struct elemental_data *ed, struct block_list *bl, unsigned int tick) { + struct skill_condition req; + uint16 skill_id, skill_lv; + int i; + + nullpo_ret(ed); + nullpo_ret(bl); + + if( !ed->master ) + return 0; + + if( ed->target_id ) + elemental->unlocktarget(ed); // Remove previous target. + + ARR_FIND(0, MAX_ELESKILLTREE, i, ed->db->skill[i].id && (ed->db->skill[i].mode&EL_SKILLMODE_AGGRESSIVE)); + if( i == MAX_ELESKILLTREE ) + return 0; + + skill_id = ed->db->skill[i].id; + skill_lv = ed->db->skill[i].lv; + + if( elemental->skillnotok(skill_id, ed) ) + return 0; + + if( ed->ud.skilltimer != INVALID_TIMER ) + return 0; + else if( DIFF_TICK(tick, ed->ud.canact_tick) < 0 ) + return 0; + + ed->target_id = ed->ud.skilltarget = bl->id; // Set new target + ed->last_thinktime = tick; + + // Not in skill range. + if( !battle->check_range(&ed->bl,bl,skill->get_range(skill_id,skill_lv)) ) { + // Try to walk to the target. + if( !unit_walktobl(&ed->bl, bl, skill->get_range(skill_id,skill_lv), 2) ) + elemental->unlocktarget(ed); + else { + // Walking, waiting to be in range. Client don't handle it, then we must handle it here. + int walk_dist = distance_bl(&ed->bl,bl) - skill->get_range(skill_id,skill_lv); + ed->ud.skill_id = skill_id; + ed->ud.skill_lv = skill_lv; + + if( skill->get_inf(skill_id) & INF_GROUND_SKILL ) + ed->ud.skilltimer = iTimer->add_timer( tick+iStatus->get_speed(&ed->bl)*walk_dist, skill->castend_pos, ed->bl.id, 0 ); + else + ed->ud.skilltimer = iTimer->add_timer( tick+iStatus->get_speed(&ed->bl)*walk_dist, skill->castend_id, ed->bl.id, 0 ); + } + return 1; + + } + + req = elemental->skill_get_requirements(skill_id, skill_lv); + + if(req.hp || req.sp){ + struct map_session_data *sd = BL_CAST(BL_PC, battle->get_master(&ed->bl)); + if( sd ){ + if( sd->skill_id_old != SO_EL_ACTION && //regardless of remaining HP/SP it can be cast + (status_get_hp(&ed->bl) < req.hp || status_get_sp(&ed->bl) < req.sp) ) + return 1; + else + status_zap(&ed->bl, req.hp, req.sp); + } + } + + //Otherwise, just cast the skill. + if( skill->get_inf(skill_id) & INF_GROUND_SKILL ) + unit_skilluse_pos(&ed->bl, bl->x, bl->y, skill_id, skill_lv); + else + unit_skilluse_id(&ed->bl, bl->id, skill_id, skill_lv); + + // Reset target. + ed->target_id = 0; + + return 1; +} + +/*=============================================================== + * Action that elemental perform after changing mode. + * Activates one of the skills of the new mode. + *-------------------------------------------------------------*/ +int elemental_change_mode_ack(struct elemental_data *ed, int mode) { + struct block_list *bl = &ed->master->bl; + uint16 skill_id, skill_lv; + int i; + + nullpo_ret(ed); + + if( !bl ) + return 0; + + // Select a skill. + ARR_FIND(0, MAX_ELESKILLTREE, i, ed->db->skill[i].id && (ed->db->skill[i].mode&mode)); + if( i == MAX_ELESKILLTREE ) + return 0; + + skill_id = ed->db->skill[i].id; + skill_lv = ed->db->skill[i].lv; + + if( elemental->skillnotok(skill_id, ed) ) + return 0; + + if( ed->ud.skilltimer != INVALID_TIMER ) + return 0; + else if( DIFF_TICK(iTimer->gettick(), ed->ud.canact_tick) < 0 ) + return 0; + + ed->target_id = bl->id; // Set new target + ed->last_thinktime = iTimer->gettick(); + + if( skill->get_inf(skill_id) & INF_GROUND_SKILL ) + unit_skilluse_pos(&ed->bl, bl->x, bl->y, skill_id, skill_lv); + else + unit_skilluse_id(&ed->bl,bl->id,skill_id,skill_lv); + + ed->target_id = 0; // Reset target after casting the skill to avoid continious attack. + + return 1; +} + +/*=============================================================== + * Change elemental mode. + *-------------------------------------------------------------*/ +int elemental_change_mode(struct elemental_data *ed, int mode) { + nullpo_ret(ed); + + // Remove target + elemental->unlocktarget(ed); + + // Removes the effects of the previous mode. + if(ed->elemental.mode != mode ) elemental->clean_effect(ed); + + ed->battle_status.mode = ed->elemental.mode = mode; + + // Normalize elemental mode to elemental skill mode. + if( mode == EL_MODE_AGGRESSIVE ) mode = EL_SKILLMODE_AGGRESSIVE; // Aggressive spirit mode -> Aggressive spirit skill. + else if( mode == EL_MODE_ASSIST ) mode = EL_SKILLMODE_ASSIST; // Assist spirit mode -> Assist spirit skill. + else mode = EL_SKILLMODE_PASIVE; // Passive spirit mode -> Passive spirit skill. + + // Use a skill inmediately after every change mode. + if( mode != EL_SKILLMODE_AGGRESSIVE ) + elemental->change_mode_ack(ed,mode); + return 1; +} + +void elemental_heal(struct elemental_data *ed, int hp, int sp) { + if( hp ) + clif->elemental_updatestatus(ed->master, SP_HP); + if( sp ) + clif->elemental_updatestatus(ed->master, SP_SP); +} + +int elemental_dead(struct elemental_data *ed) { + elemental->delete(ed, 1); + return 0; +} + +int elemental_unlocktarget(struct elemental_data *ed) { + nullpo_ret(ed); + + ed->target_id = 0; + elemental_stop_attack(ed); + elemental_stop_walking(ed,1); + return 0; +} + +int elemental_skillnotok(uint16 skill_id, struct elemental_data *ed) { + int idx = skill->get_index(skill_id); + nullpo_retr(1,ed); + + if (idx == 0) + return 1; // invalid skill id + + return skill->not_ok(skill_id, ed->master); +} + +struct skill_condition elemental_skill_get_requirements(uint16 skill_id, uint16 skill_lv){ + struct skill_condition req; + int idx = skill->get_index(skill_id); + + memset(&req,0,sizeof(req)); + + if( idx == 0 ) // invalid skill id + return req; + + if( skill_lv < 1 || skill_lv > MAX_SKILL_LEVEL ) + return req; + + req.hp = skill_db[idx].hp[skill_lv-1]; + req.sp = skill_db[idx].sp[skill_lv-1]; + + return req; +} + +int elemental_set_target( struct map_session_data *sd, struct block_list *bl ) { + struct elemental_data *ed = sd->ed; + + nullpo_ret(ed); + nullpo_ret(bl); + + if( ed->bl.m != bl->m || !check_distance_bl(&ed->bl, bl, ed->db->range2) ) + return 0; + + if( !iStatus->check_skilluse(&ed->bl, bl, 0, 0) ) + return 0; + + if( ed->target_id == 0 ) + ed->target_id = bl->id; + + return 1; +} + +static int elemental_ai_sub_timer_activesearch(struct block_list *bl, va_list ap) { + struct elemental_data *ed; + struct block_list **target; + int dist; + + nullpo_ret(bl); + + ed = va_arg(ap,struct elemental_data *); + target = va_arg(ap,struct block_list**); + + //If can't seek yet, not an enemy, or you can't attack it, skip. + if( (*target) == bl || !iStatus->check_skilluse(&ed->bl, bl, 0, 0) ) + return 0; + + if( battle->check_target(&ed->bl,bl,BCT_ENEMY) <= 0 ) + return 0; + + switch( bl->type ) { + case BL_PC: + if( !map_flag_vs(ed->bl.m) ) + return 0; + default: + dist = distance_bl(&ed->bl, bl); + if( ((*target) == NULL || !check_distance_bl(&ed->bl, *target, dist)) && battle->check_range(&ed->bl,bl,ed->db->range2) ) { //Pick closest target? + (*target) = bl; + ed->target_id = bl->id; + ed->min_chase = dist + ed->db->range3; + if( ed->min_chase > AREA_SIZE ) + ed->min_chase = AREA_SIZE; + return 1; + } + break; + } + return 0; +} + +static int elemental_ai_sub_timer(struct elemental_data *ed, struct map_session_data *sd, unsigned int tick) { + struct block_list *target = NULL; + int master_dist, view_range, mode; + + nullpo_ret(ed); + nullpo_ret(sd); + + if( ed->bl.prev == NULL || sd == NULL || sd->bl.prev == NULL ) + return 0; + + // Check if caster can sustain the summoned elemental + if( DIFF_TICK(tick,ed->last_spdrain_time) >= 10000 ){// Drain SP every 10 seconds + int sp = 5; + + switch(ed->vd->class_){ + case 2115: case 2118: + case 2121: case 2124: + sp = 8; + break; + case 2116: case 2119: + case 2122: case 2125: + sp = 11; + break; + } + + if( status_get_sp(&sd->bl) < sp ){ // Can't sustain delete it. + elemental->delete(sd->ed,0); + return 0; + } + + status_zap(&sd->bl,0,sp); + ed->last_spdrain_time = tick; + } + + if( DIFF_TICK(tick,ed->last_thinktime) < MIN_ELETHINKTIME ) + return 0; + + ed->last_thinktime = tick; + + if( ed->ud.skilltimer != INVALID_TIMER ) + return 0; + + if( ed->ud.walktimer != INVALID_TIMER && ed->ud.walkpath.path_pos <= 2 ) + return 0; //No thinking when you just started to walk. + + if(ed->ud.walkpath.path_pos < ed->ud.walkpath.path_len && ed->ud.target == sd->bl.id) + return 0; //No thinking until be near the master. + + if( ed->sc.count && ed->sc.data[SC_BLIND] ) + view_range = 3; + else + view_range = ed->db->range2; + + mode = status_get_mode(&ed->bl); + + master_dist = distance_bl(&sd->bl, &ed->bl); + if( master_dist > AREA_SIZE ) { // Master out of vision range. + elemental->unlocktarget(ed); + unit_warp(&ed->bl,sd->bl.m,sd->bl.x,sd->bl.y,CLR_TELEPORT); + clif->elemental_updatestatus(sd,SP_HP); + clif->elemental_updatestatus(sd,SP_SP); + return 0; + } else if( master_dist > MAX_ELEDISTANCE ) { // Master too far, chase. + short x = sd->bl.x, y = sd->bl.y; + if( ed->target_id ) + elemental->unlocktarget(ed); + if( ed->ud.walktimer != INVALID_TIMER && ed->ud.target == sd->bl.id ) + return 0; //Already walking to him + if( DIFF_TICK(tick, ed->ud.canmove_tick) < 0 ) + return 0; //Can't move yet. + if( iMap->search_freecell(&ed->bl, sd->bl.m, &x, &y, MIN_ELEDISTANCE, MIN_ELEDISTANCE, 1) + && unit_walktoxy(&ed->bl, x, y, 0) ) + return 0; + } + + if( mode == EL_MODE_AGGRESSIVE ) { + target = iMap->id2bl(ed->ud.target); + + if( !target ) + iMap->foreachinrange(elemental_ai_sub_timer_activesearch, &ed->bl, view_range, BL_CHAR, ed, &target, status_get_mode(&ed->bl)); + + if( !target ) { //No targets available. + elemental->unlocktarget(ed); + return 1; + } + + if( battle->check_range(&ed->bl,target,view_range) && rnd()%100 < 2 ) { // 2% chance to cast attack skill. + if( elemental->action(ed,target,tick) ) + return 1; + } + + //Attempt to attack. + //At this point we know the target is attackable, we just gotta check if the range matches. + if( ed->ud.target == target->id && ed->ud.attacktimer != INVALID_TIMER ) //Already locked. + return 1; + + if( battle->check_range(&ed->bl, target, ed->base_status.rhw.range) ) {//Target within range, engage + unit_attack(&ed->bl,target->id,1); + return 1; + } + + //Follow up if possible. + if( !unit_walktobl(&ed->bl, target, ed->base_status.rhw.range, 2) ) + elemental->unlocktarget(ed); + } + + return 0; +} + +static int elemental_ai_sub_foreachclient(struct map_session_data *sd, va_list ap) { + unsigned int tick = va_arg(ap,unsigned int); + if(sd->status.ele_id && sd->ed) + elemental_ai_sub_timer(sd->ed,sd,tick); + + return 0; +} + +static int elemental_ai_timer(int tid, unsigned int tick, int id, intptr_t data) { + iMap->map_foreachpc(elemental_ai_sub_foreachclient,tick); + return 0; +} + +int read_elementaldb(void) { + FILE *fp; + char line[1024], *p; + char *str[26]; + int i, j = 0, k = 0, ele; + struct s_elemental_db *db; + struct status_data *status; + + sprintf(line, "%s/%s", iMap->db_path, "elemental_db.txt"); + memset(elemental->elemental_db,0,sizeof(elemental->elemental_db)); + + fp = fopen(line, "r"); + if( !fp ) { + ShowError("read_elementaldb : can't read elemental_db.txt\n"); + return -1; + } + + while( fgets(line, sizeof(line), fp) && j < MAX_ELEMENTAL_CLASS ) { + k++; + if( line[0] == '/' && line[1] == '/' ) + continue; + + if( line[0] == '\0' || line[0] == '\n' || line[0] == '\r') + continue; + + i = 0; + p = strtok(line, ","); + while( p != NULL && i < 26 ) { + str[i++] = p; + p = strtok(NULL, ","); + } + if( i < 26 ) { + ShowError("read_elementaldb : Incorrect number of columns at elemental_db.txt line %d.\n", k); + continue; + } + + db = &elemental->elemental_db[j]; + 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 = 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("Elemental %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("Elemental %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]); + + j++; + } + + fclose(fp); + ShowStatus("Done reading '"CL_WHITE"%d"CL_RESET"' elementals in '"CL_WHITE"db/elemental_db.txt"CL_RESET"'.\n",j); + + return 0; +} + +int read_elemental_skilldb(void) { + FILE *fp; + char line[1024], *p; + char *str[4]; + struct s_elemental_db *db; + int i, j = 0, k = 0, class_; + uint16 skill_id, skill_lv; + int skillmode; + + sprintf(line, "%s/%s", iMap->db_path, "elemental_skill_db.txt"); + fp = fopen(line, "r"); + if( !fp ) { + ShowError("read_elemental_skilldb : can't read elemental_skill_db.txt\n"); + return -1; + } + + while( fgets(line, sizeof(line), fp) ) { + k++; + if( line[0] == '/' && line[1] == '/' ) + continue; + + if( line[0] == '\0' || line[0] == '\n' || line[0] == '\r') + continue; + + i = 0; + p = strtok(line, ","); + while( p != NULL && i < 4 ) { + str[i++] = p; + p = strtok(NULL, ","); + } + if( i < 4 ) { + ShowError("read_elemental_skilldb : Incorrect number of columns at elemental_skill_db.txt line %d.\n", k); + continue; + } + + class_ = atoi(str[0]); + ARR_FIND(0, MAX_ELEMENTAL_CLASS, i, class_ == elemental->elemental_db[i].class_); + if( i == MAX_ELEMENTAL_CLASS ) { + ShowError("read_elemental_skilldb : Class not found in elemental_db for skill entry, line %d.\n", k); + continue; + } + + skill_id = atoi(str[1]); + if( skill_id < EL_SKILLBASE || skill_id >= EL_SKILLBASE + MAX_ELEMENTALSKILL ) { + ShowError("read_elemental_skilldb : Skill out of range, line %d.\n", k); + continue; + } + + db = &elemental->elemental_db[i]; + skill_lv = atoi(str[2]); + + skillmode = atoi(str[3]); + if( skillmode < EL_SKILLMODE_PASIVE || skillmode > EL_SKILLMODE_AGGRESSIVE ) { + ShowError("read_elemental_skilldb : Skillmode out of range, line %d.\n",k); + continue; + } + ARR_FIND( 0, MAX_ELESKILLTREE, i, db->skill[i].id == 0 || db->skill[i].id == skill_id ); + if( i == MAX_ELESKILLTREE ) { + ShowWarning("Unable to load skill %d into Elemental %d's tree. Maximum number of skills per elemental has been reached.\n", skill_id, class_); + continue; + } + db->skill[i].id = skill_id; + db->skill[i].lv = skill_lv; + db->skill[i].mode = skillmode; + j++; + } + + fclose(fp); + ShowStatus("Done reading '"CL_WHITE"%d"CL_RESET"' entries in '"CL_WHITE"db/elemental_skill_db.txt"CL_RESET"'.\n",j); + return 0; +} + +void reload_elementaldb(void) { + read_elementaldb(); + elemental->reload_skilldb(); +} + +void reload_elemental_skilldb(void) { + elemental->read_skilldb(); +} + +int do_init_elemental(void) { + read_elementaldb(); + elemental->read_skilldb(); + + iTimer->add_timer_func_list(elemental_ai_timer,"elemental_ai_timer"); + iTimer->add_timer_interval(iTimer->gettick()+MIN_ELETHINKTIME,elemental_ai_timer,0,0,MIN_ELETHINKTIME); + + return 0; +} + +void do_final_elemental(void) { + return; +} + +/*===================================== +* Default Functions : elemental.h +* Generated by HerculesInterfaceMaker +* created by Susu +*-------------------------------------*/ +void elemental_defaults(void) { + elemental = &elemental_s; + /* funcs */ + + elemental->class = elemental_class; + elemental->get_viewdata = elemental_get_viewdata; + + elemental->create = elemental_create; + elemental->data_received = elemental_data_received; + elemental->save = elemental_save; + + elemental->change_mode_ack = elemental_change_mode_ack; + elemental->change_mode = elemental_change_mode; + + elemental->heal = elemental_heal; + elemental->dead = elemental_dead; + + elemental->delete = elemental_delete; + elemental->summon_stop = elemental_summon_stop; + + elemental->get_lifetime = elemental_get_lifetime; + + elemental->unlocktarget = elemental_unlocktarget; + elemental->skillnotok = elemental_skillnotok; + elemental->set_target = elemental_set_target; + elemental->clean_single_effect = elemental_clean_single_effect; + elemental->clean_effect = elemental_clean_effect; + elemental->action = elemental_action; + elemental->skill_get_requirements = elemental_skill_get_requirements; + + elemental->read_skilldb = read_elemental_skilldb; + elemental->reload_elementaldb = reload_elementaldb; + elemental->reload_skilldb = reload_elemental_skilldb; + elemental->do_init_elemental = do_init_elemental; + elemental->do_final_elemental = do_final_elemental; +} diff --git a/src/map/elemental.h b/src/map/elemental.h index 96d2ed89f..250cd3b72 100644 --- a/src/map/elemental.h +++ b/src/map/elemental.h @@ -1,106 +1,106 @@ -// Copyright (c) Athena Dev Teams - Licensed under GNU GPL -// For more information, see LICENCE in the main folder -#ifndef _ELEMENTAL_H_ -#define _ELEMENTAL_H_ -#include "status.h" // struct status_data, struct status_change -#include "unit.h" // struct unit_data -#define MIN_ELETHINKTIME 100 -#define MIN_ELEDISTANCE 2 -#define MAX_ELEDISTANCE 5 -#define EL_MODE_AGGRESSIVE (MD_CANMOVE|MD_AGGRESSIVE|MD_CANATTACK) -#define EL_MODE_ASSIST (MD_CANMOVE|MD_ASSIST) -#define EL_MODE_PASSIVE MD_CANMOVE -#define EL_SKILLMODE_PASIVE 0x1 -#define EL_SKILLMODE_ASSIST 0x2 -#define EL_SKILLMODE_AGGRESSIVE 0x4 -struct elemental_skill { - unsigned short id, lv; - short mode; -}; -struct s_elemental_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 elemental_skill skill[MAX_ELESKILLTREE]; -}; -struct elemental_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_elemental_db *db; - struct s_elemental elemental; - - struct map_session_data *master; - int summon_timer; - int skill_timer; - - unsigned last_thinktime, last_linktime, last_spdrain_time; - short min_chase; - int target_id, attacked_id; -}; - - - - - - - - -#define elemental_stop_walking(ed, type) unit_stop_walking(&(ed)->bl, type) -#define elemental_stop_attack(ed) unit_stop_attack(&(ed)->bl) - - -/*===================================== -* Interface : elemental.h -* Generated by HerculesInterfaceMaker -* created by Susu -*-------------------------------------*/ -struct elemental_interface { - /* vars */ - struct s_elemental_db elemental_db[MAX_ELEMENTAL_CLASS]; // Elemental Database - /* funcs */ - 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_elemental *ele, bool flag); - int (*save) (struct elemental_data *ed); - - int (*change_mode_ack) (struct elemental_data *ed, int mode); - int (*change_mode) (struct elemental_data *ed, int mode); - - void (*heal) (struct elemental_data *ed, int hp, int sp); - int (*dead) (struct elemental_data *ed); - - int (*delete) (struct elemental_data *ed, int reply); - void (*summon_stop) (struct elemental_data *ed); - - int (*get_lifetime) (struct elemental_data *ed); - - int (*unlocktarget) (struct elemental_data *ed); - int (*skillnotok) (uint16 skill_id, struct elemental_data *ed); - int (*set_target) (struct map_session_data *sd, struct block_list *bl); - int (*clean_single_effect) (struct elemental_data *ed, uint16 skill_id); - int (*clean_effect) (struct elemental_data *ed); - int (*action) (struct elemental_data *ed, struct block_list *bl, unsigned int tick); - struct skill_condition (*skill_get_requirements) (uint16 skill_id, uint16 skill_lv); - - int (*read_skilldb) (void); - void (*reload_elementaldb) (void); - void (*reload_skilldb) (void); - int (*do_init_elemental) (void); - void (*do_final_elemental) (void); -} elemental_s; - -struct elemental_interface *elemental; - -void elemental_defaults(void); - -#endif /* _ELEMENTAL_H_ */ +// Copyright (c) Athena Dev Teams - Licensed under GNU GPL +// For more information, see LICENCE in the main folder +#ifndef _ELEMENTAL_H_ +#define _ELEMENTAL_H_ +#include "status.h" // struct status_data, struct status_change +#include "unit.h" // struct unit_data +#define MIN_ELETHINKTIME 100 +#define MIN_ELEDISTANCE 2 +#define MAX_ELEDISTANCE 5 +#define EL_MODE_AGGRESSIVE (MD_CANMOVE|MD_AGGRESSIVE|MD_CANATTACK) +#define EL_MODE_ASSIST (MD_CANMOVE|MD_ASSIST) +#define EL_MODE_PASSIVE MD_CANMOVE +#define EL_SKILLMODE_PASIVE 0x1 +#define EL_SKILLMODE_ASSIST 0x2 +#define EL_SKILLMODE_AGGRESSIVE 0x4 +struct elemental_skill { + unsigned short id, lv; + short mode; +}; +struct s_elemental_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 elemental_skill skill[MAX_ELESKILLTREE]; +}; +struct elemental_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_elemental_db *db; + struct s_elemental elemental; + + struct map_session_data *master; + int summon_timer; + int skill_timer; + + unsigned last_thinktime, last_linktime, last_spdrain_time; + short min_chase; + int target_id, attacked_id; +}; + + + + + + + + +#define elemental_stop_walking(ed, type) unit_stop_walking(&(ed)->bl, type) +#define elemental_stop_attack(ed) unit_stop_attack(&(ed)->bl) + + +/*===================================== +* Interface : elemental.h +* Generated by HerculesInterfaceMaker +* created by Susu +*-------------------------------------*/ +struct elemental_interface { + /* vars */ + struct s_elemental_db elemental_db[MAX_ELEMENTAL_CLASS]; // Elemental Database + /* funcs */ + 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_elemental *ele, bool flag); + int (*save) (struct elemental_data *ed); + + int (*change_mode_ack) (struct elemental_data *ed, int mode); + int (*change_mode) (struct elemental_data *ed, int mode); + + void (*heal) (struct elemental_data *ed, int hp, int sp); + int (*dead) (struct elemental_data *ed); + + int (*delete) (struct elemental_data *ed, int reply); + void (*summon_stop) (struct elemental_data *ed); + + int (*get_lifetime) (struct elemental_data *ed); + + int (*unlocktarget) (struct elemental_data *ed); + int (*skillnotok) (uint16 skill_id, struct elemental_data *ed); + int (*set_target) (struct map_session_data *sd, struct block_list *bl); + int (*clean_single_effect) (struct elemental_data *ed, uint16 skill_id); + int (*clean_effect) (struct elemental_data *ed); + int (*action) (struct elemental_data *ed, struct block_list *bl, unsigned int tick); + struct skill_condition (*skill_get_requirements) (uint16 skill_id, uint16 skill_lv); + + int (*read_skilldb) (void); + void (*reload_elementaldb) (void); + void (*reload_skilldb) (void); + int (*do_init_elemental) (void); + void (*do_final_elemental) (void); +} elemental_s; + +struct elemental_interface *elemental; + +void elemental_defaults(void); + +#endif /* _ELEMENTAL_H_ */ diff --git a/src/map/intif.h b/src/map/intif.h index f0c1067fb..8abcf819d 100644 --- a/src/map/intif.h +++ b/src/map/intif.h @@ -1,128 +1,128 @@ -// Copyright (c) Athena Dev Teams - Licensed under GNU GPL -// For more information, see LICENCE in the main folder -#ifndef _INTIF_H_ -#define _INFIF_H_ -//#include "../common/mmo.h" -struct party_member; -struct guild_member; -struct guild_position; -struct s_pet; -struct s_homunculus; -struct s_mercenary; -struct s_elemental; -struct mail_message; -struct auction_data; - - - - - -#define intif_rename_pc(sd, name) intif->rename(sd, 0, name) -#define intif_rename_pet(sd, name) intif->rename(sd, 1, name) -#define intif_rename_hom(sd, name) intif->rename(sd, 2, name) - - - - - - -/*===================================== -* Interface : intif.h -* Generated by HerculesInterfaceMaker -* created by Susu -*-------------------------------------*/ -struct intif_interface { - /* funcs */ - - - int (*parse) (int fd); - - int (*create_pet)(int account_id, int char_id, short pet_type, short pet_lv, short pet_egg_id, - short pet_equip, short intimate, short hungry, char rename_flag, char incuvate, char *pet_name); - - int (*broadcast) (const char* mes, int len, int type); - int (*broadcast2) (const char* mes, int len, unsigned long fontColor, short fontType, short fontSize, short fontAlign, short fontY); - int (*main_message) (struct map_session_data* sd, const char* message); - - int (*wis_message) (struct map_session_data *sd,char *nick,char *mes,int mes_len); - int (*wis_message_to_gm) (char *Wisp_name, int permission, char *mes); - - int (*saveregistry) (struct map_session_data *sd, int type); - int (*request_registry) (struct map_session_data *sd, int flag); - - int (*request_guild_storage) (int account_id, int guild_id); - int (*send_guild_storage) (int account_id, struct guild_storage *gstor); - - int (*create_party) (struct party_member *member,char *name,int item,int item2); - int (*request_partyinfo) (int party_id, int char_id); - - int (*party_addmember) (int party_id,struct party_member *member); - int (*party_changeoption) (int party_id, int account_id, int exp, int item); - int (*party_leave) (int party_id,int account_id, int char_id); - int (*party_changemap) (struct map_session_data *sd, int online); - int (*break_party) (int party_id); - int (*party_message) (int party_id, int account_id, const char *mes,int len); - int (*party_leaderchange) (int party_id,int account_id,int char_id); - - int (*guild_create) (const char *name, const struct guild_member *master); - int (*guild_request_info) (int guild_id); - int (*guild_addmember) (int guild_id, struct guild_member *m); - int (*guild_leave) (int guild_id, int account_id, int char_id, int flag, const char *mes); - int (*guild_memberinfoshort) (int guild_id, int account_id, int char_id, int online, int lv, int class_); - int (*guild_break) (int guild_id); - int (*guild_message) (int guild_id, int account_id, const char *mes, int len); - int (*guild_change_gm) (int guild_id, const char* name, int len); - int (*guild_change_basicinfo) (int guild_id, int type, const void *data, int len); - int (*guild_change_memberinfo) (int guild_id, int account_id, int char_id, int type, const void *data, int len); - int (*guild_position) (int guild_id, int idx, struct guild_position *p); - int (*guild_skillup) (int guild_id, uint16 skill_id, int account_id, int max); - int (*guild_alliance) (int guild_id1, int guild_id2, int account_id1, int account_id2, int flag); - int (*guild_notice) (int guild_id, const char *mes1, const char *mes2); - int (*guild_emblem) (int guild_id, int len, const char *data); - int (*guild_castle_dataload) (int num, int *castle_ids); - int (*guild_castle_datasave) (int castle_id, int index, int value); - int (*request_petdata) (int account_id, int char_id, int pet_id); - int (*save_petdata) (int account_id, struct s_pet *p); - int (*delete_petdata) (int pet_id); - int (*rename) (struct map_session_data *sd, int type, char *name); - int (*homunculus_create) (int account_id, struct s_homunculus *sh); - bool (*homunculus_requestload) (int account_id, int homun_id); - int (*homunculus_requestsave) (int account_id, struct s_homunculus* sh); - int (*homunculus_requestdelete) (int homun_id); - /******QUEST SYTEM*******/ - int (*request_questlog) (struct map_session_data * sd); - int (*quest_save) (struct map_session_data * sd); - // MERCENARY SYSTEM - int (*mercenary_create) (struct s_mercenary *merc); - int (*mercenary_request) (int merc_id, int char_id); - int (*mercenary_delete) (int merc_id); - int (*mercenary_save) (struct s_mercenary *merc); - // MAIL SYSTEM - int (*Mail_requestinbox) (int char_id, unsigned char flag); - int (*Mail_read) (int mail_id); - int (*Mail_getattach) (int char_id, int mail_id); - int (*Mail_delete) (int char_id, int mail_id); - int (*Mail_return) (int char_id, int mail_id); - int (*Mail_send) (int account_id, struct mail_message *msg); - // AUCTION SYSTEM - int (*Auction_requestlist) (int char_id, short type, int price, const char* searchtext, short page); - int (*Auction_register) (struct auction_data *auction); - int (*Auction_cancel) (int char_id, unsigned int auction_id); - int (*Auction_close) (int char_id, unsigned int auction_id); - int (*Auction_bid) (int char_id, const char* name, unsigned int auction_id, int bid); - // ELEMENTAL SYSTEM - int (*elemental_create) (struct s_elemental *ele); - int (*elemental_request) (int ele_id, int char_id); - int (*elemental_delete) (int ele_id); - int (*elemental_save) (struct s_elemental *ele); - /* @accinfo */ - void (*request_accinfo) (int u_fd, int aid, int group_lv, char* query); - - int (*CheckForCharServer) (void); -} intif_s; - -struct intif_interface *intif; - -void intif_defaults(void); - -#endif /* _INTIF_H_ */ +// Copyright (c) Athena Dev Teams - Licensed under GNU GPL +// For more information, see LICENCE in the main folder +#ifndef _INTIF_H_ +#define _INFIF_H_ +//#include "../common/mmo.h" +struct party_member; +struct guild_member; +struct guild_position; +struct s_pet; +struct s_homunculus; +struct s_mercenary; +struct s_elemental; +struct mail_message; +struct auction_data; + + + + + +#define intif_rename_pc(sd, name) intif->rename(sd, 0, name) +#define intif_rename_pet(sd, name) intif->rename(sd, 1, name) +#define intif_rename_hom(sd, name) intif->rename(sd, 2, name) + + + + + + +/*===================================== +* Interface : intif.h +* Generated by HerculesInterfaceMaker +* created by Susu +*-------------------------------------*/ +struct intif_interface { + /* funcs */ + + + int (*parse) (int fd); + + int (*create_pet)(int account_id, int char_id, short pet_type, short pet_lv, short pet_egg_id, + short pet_equip, short intimate, short hungry, char rename_flag, char incuvate, char *pet_name); + + int (*broadcast) (const char* mes, int len, int type); + int (*broadcast2) (const char* mes, int len, unsigned long fontColor, short fontType, short fontSize, short fontAlign, short fontY); + int (*main_message) (struct map_session_data* sd, const char* message); + + int (*wis_message) (struct map_session_data *sd,char *nick,char *mes,int mes_len); + int (*wis_message_to_gm) (char *Wisp_name, int permission, char *mes); + + int (*saveregistry) (struct map_session_data *sd, int type); + int (*request_registry) (struct map_session_data *sd, int flag); + + int (*request_guild_storage) (int account_id, int guild_id); + int (*send_guild_storage) (int account_id, struct guild_storage *gstor); + + int (*create_party) (struct party_member *member,char *name,int item,int item2); + int (*request_partyinfo) (int party_id, int char_id); + + int (*party_addmember) (int party_id,struct party_member *member); + int (*party_changeoption) (int party_id, int account_id, int exp, int item); + int (*party_leave) (int party_id,int account_id, int char_id); + int (*party_changemap) (struct map_session_data *sd, int online); + int (*break_party) (int party_id); + int (*party_message) (int party_id, int account_id, const char *mes,int len); + int (*party_leaderchange) (int party_id,int account_id,int char_id); + + int (*guild_create) (const char *name, const struct guild_member *master); + int (*guild_request_info) (int guild_id); + int (*guild_addmember) (int guild_id, struct guild_member *m); + int (*guild_leave) (int guild_id, int account_id, int char_id, int flag, const char *mes); + int (*guild_memberinfoshort) (int guild_id, int account_id, int char_id, int online, int lv, int class_); + int (*guild_break) (int guild_id); + int (*guild_message) (int guild_id, int account_id, const char *mes, int len); + int (*guild_change_gm) (int guild_id, const char* name, int len); + int (*guild_change_basicinfo) (int guild_id, int type, const void *data, int len); + int (*guild_change_memberinfo) (int guild_id, int account_id, int char_id, int type, const void *data, int len); + int (*guild_position) (int guild_id, int idx, struct guild_position *p); + int (*guild_skillup) (int guild_id, uint16 skill_id, int account_id, int max); + int (*guild_alliance) (int guild_id1, int guild_id2, int account_id1, int account_id2, int flag); + int (*guild_notice) (int guild_id, const char *mes1, const char *mes2); + int (*guild_emblem) (int guild_id, int len, const char *data); + int (*guild_castle_dataload) (int num, int *castle_ids); + int (*guild_castle_datasave) (int castle_id, int index, int value); + int (*request_petdata) (int account_id, int char_id, int pet_id); + int (*save_petdata) (int account_id, struct s_pet *p); + int (*delete_petdata) (int pet_id); + int (*rename) (struct map_session_data *sd, int type, char *name); + int (*homunculus_create) (int account_id, struct s_homunculus *sh); + bool (*homunculus_requestload) (int account_id, int homun_id); + int (*homunculus_requestsave) (int account_id, struct s_homunculus* sh); + int (*homunculus_requestdelete) (int homun_id); + /******QUEST SYTEM*******/ + int (*request_questlog) (struct map_session_data * sd); + int (*quest_save) (struct map_session_data * sd); + // MERCENARY SYSTEM + int (*mercenary_create) (struct s_mercenary *merc); + int (*mercenary_request) (int merc_id, int char_id); + int (*mercenary_delete) (int merc_id); + int (*mercenary_save) (struct s_mercenary *merc); + // MAIL SYSTEM + int (*Mail_requestinbox) (int char_id, unsigned char flag); + int (*Mail_read) (int mail_id); + int (*Mail_getattach) (int char_id, int mail_id); + int (*Mail_delete) (int char_id, int mail_id); + int (*Mail_return) (int char_id, int mail_id); + int (*Mail_send) (int account_id, struct mail_message *msg); + // AUCTION SYSTEM + int (*Auction_requestlist) (int char_id, short type, int price, const char* searchtext, short page); + int (*Auction_register) (struct auction_data *auction); + int (*Auction_cancel) (int char_id, unsigned int auction_id); + int (*Auction_close) (int char_id, unsigned int auction_id); + int (*Auction_bid) (int char_id, const char* name, unsigned int auction_id, int bid); + // ELEMENTAL SYSTEM + int (*elemental_create) (struct s_elemental *ele); + int (*elemental_request) (int ele_id, int char_id); + int (*elemental_delete) (int ele_id); + int (*elemental_save) (struct s_elemental *ele); + /* @accinfo */ + void (*request_accinfo) (int u_fd, int aid, int group_lv, char* query); + + int (*CheckForCharServer) (void); +} intif_s; + +struct intif_interface *intif; + +void intif_defaults(void); + +#endif /* _INTIF_H_ */ diff --git a/src/plugins/CMakeLists.txt b/src/plugins/CMakeLists.txt index 4e4851bc5..e3043a668 100644 --- a/src/plugins/CMakeLists.txt +++ b/src/plugins/CMakeLists.txt @@ -33,4 +33,4 @@ if( INSTALL_COMPONENT_RUNTIME ) endif( INSTALL_COMPONENT_RUNTIME ) set( TARGET_LIST ${TARGET_LIST} sample CACHE INTERNAL "" ) message( STATUS "Creating target sample - done" ) -endif( BUILD_PLUGIN_sample ) \ No newline at end of file +endif( BUILD_PLUGIN_sample ) diff --git a/src/plugins/db2sql.c b/src/plugins/db2sql.c index 5cb8d52a2..ebd2a9ee5 100644 --- a/src/plugins/db2sql.c +++ b/src/plugins/db2sql.c @@ -135,4 +135,4 @@ HPExport void plugin_init (void) { strlib = GET_SYMBOL("strlib"); HPMi->addCPCommand("server:tools:db2sql",CPCMD_A(db2sql)); -} \ No newline at end of file +} diff --git a/src/plugins/sample.c b/src/plugins/sample.c index 4a8402560..4f9e34f74 100644 --- a/src/plugins/sample.c +++ b/src/plugins/sample.c @@ -141,4 +141,4 @@ HPExport void server_online (void) { /* run when server is shutting down */ HPExport void plugin_final (void) { ShowInfo ("%s says ~Bye world\n",pinfo.name); -} \ No newline at end of file +} -- cgit v1.2.3-70-g09d2