diff options
Diffstat (limited to 'src/map')
-rw-r--r-- | src/map/atcommand.c | 42 | ||||
-rw-r--r-- | src/map/battle.c | 1 | ||||
-rw-r--r-- | src/map/battle.h | 1 | ||||
-rw-r--r-- | src/map/buyingstore.c | 2 | ||||
-rw-r--r-- | src/map/clif.c | 51 | ||||
-rw-r--r-- | src/map/clif.h | 1 | ||||
-rw-r--r-- | src/map/itemdb.c | 627 | ||||
-rw-r--r-- | src/map/itemdb.h | 180 | ||||
-rw-r--r-- | src/map/log.c | 4 | ||||
-rw-r--r-- | src/map/map.c | 10 | ||||
-rw-r--r-- | src/map/map.h | 2 | ||||
-rw-r--r-- | src/map/mob.c | 23 | ||||
-rw-r--r-- | src/map/npc.c | 32 | ||||
-rw-r--r-- | src/map/packets_struct.h | 10 | ||||
-rw-r--r-- | src/map/pc.c | 1345 | ||||
-rw-r--r-- | src/map/pc.h | 3 | ||||
-rw-r--r-- | src/map/pet.c | 2 | ||||
-rw-r--r-- | src/map/script.c | 260 | ||||
-rw-r--r-- | src/map/script.h | 10 | ||||
-rw-r--r-- | src/map/searchstore.c | 4 | ||||
-rw-r--r-- | src/map/skill.c | 17 | ||||
-rw-r--r-- | src/map/status.c | 1181 | ||||
-rw-r--r-- | src/map/storage.c | 40 | ||||
-rw-r--r-- | src/map/storage.h | 4 | ||||
-rw-r--r-- | src/map/trade.c | 4 |
25 files changed, 2205 insertions, 1651 deletions
diff --git a/src/map/atcommand.c b/src/map/atcommand.c index 52192ebdc..a1bc52924 100644 --- a/src/map/atcommand.c +++ b/src/map/atcommand.c @@ -1145,8 +1145,8 @@ ACMD(item) if (number <= 0) number = 1; - if ((item_data = itemdb_searchname(item_name)) == NULL && - (item_data = itemdb_exists(atoi(item_name))) == NULL) + if ((item_data = itemdb->search_name(item_name)) == NULL && + (item_data = itemdb->exists(atoi(item_name))) == NULL) { clif->message(fd, msg_txt(19)); // Invalid item ID or name. return false; @@ -1203,8 +1203,8 @@ ACMD(item2) number = 1; item_id = 0; - if ((item_data = itemdb_searchname(item_name)) != NULL || - (item_data = itemdb_exists(atoi(item_name))) != NULL) + if ((item_data = itemdb->search_name(item_name)) != NULL || + (item_data = itemdb->exists(atoi(item_name))) != NULL) item_id = item_data->nameid; if (item_id > 500) { @@ -2128,8 +2128,8 @@ ACMD(produce) return false; } - if ( (item_data = itemdb_searchname(item_name)) == NULL && - (item_data = itemdb_exists(atoi(item_name))) == NULL ) { + if ( (item_data = itemdb->search_name(item_name)) == NULL && + (item_data = itemdb->exists(atoi(item_name))) == NULL ) { clif->message(fd, msg_txt(170)); //This item is not an equipment. return false; } @@ -2548,7 +2548,7 @@ ACMD(makeegg) return false; } - if ((item_data = itemdb_searchname(message)) != NULL) // for egg name + if ((item_data = itemdb->search_name(message)) != NULL) // for egg name id = item_data->nameid; else if ((id = mobdb_searchname(message)) != 0) // for monster name @@ -3395,7 +3395,7 @@ ACMD(idsearch) sprintf(atcmd_output, msg_txt(77), item_name); // The reference result of '%s' (name: id): clif->message(fd, atcmd_output); - match = itemdb_searchname_array(item_array, MAX_SEARCH, item_name); + match = itemdb->search_name_array(item_array, MAX_SEARCH, item_name); if (match > MAX_SEARCH) { sprintf(atcmd_output, msg_txt(269), MAX_SEARCH, match); clif->message(fd, atcmd_output); @@ -3582,7 +3582,7 @@ ACMD(partyrecall) ACMD(reloaditemdb) { nullpo_retr(-1, sd); - itemdb_reload(); + itemdb->reload(); clif->message(fd, msg_txt(97)); // Item database has been reloaded. return true; @@ -5798,8 +5798,8 @@ ACMD(autolootitem) if (action < 3) // add or remove { - if ((item_data = itemdb_exists(atoi(message))) == NULL) - item_data = itemdb_searchname(message); + if ((item_data = itemdb->exists(atoi(message))) == NULL) + item_data = itemdb->search_name(message); if (!item_data) { // No items founds in the DB with Id or Name clif->message(fd, msg_txt(1189)); // Item not found. @@ -5852,7 +5852,7 @@ ACMD(autolootitem) { if (sd->state.autolootid[i] == 0) continue; - if (!(item_data = itemdb_exists(sd->state.autolootid[i]))) { + if (!(item_data = itemdb->exists(sd->state.autolootid[i]))) { ShowDebug("Non-existant item %d on autolootitem list (account_id: %d, char_id: %d)", sd->state.autolootid[i], sd->status.account_id, sd->status.char_id); continue; } @@ -6695,7 +6695,7 @@ ACMD(mobinfo) j = 0; for (i = 0; i < MAX_MOB_DROP; i++) { int droprate; - if (mob->dropitem[i].nameid <= 0 || mob->dropitem[i].p < 1 || (item_data = itemdb_exists(mob->dropitem[i].nameid)) == NULL) + if (mob->dropitem[i].nameid <= 0 || mob->dropitem[i].p < 1 || (item_data = itemdb->exists(mob->dropitem[i].nameid)) == NULL) continue; droprate = mob->dropitem[i].p; @@ -6720,7 +6720,7 @@ ACMD(mobinfo) strcpy(atcmd_output, msg_txt(1248)); // MVP Items: j = 0; for (i = 0; i < MAX_MVP_DROP; i++) { - if (mob->mvpitem[i].nameid <= 0 || (item_data = itemdb_exists(mob->mvpitem[i].nameid)) == NULL) + if (mob->mvpitem[i].nameid <= 0 || (item_data = itemdb->exists(mob->mvpitem[i].nameid)) == NULL) continue; if (mob->mvpitem[i].p > 0) { j++; @@ -7142,8 +7142,8 @@ ACMD(iteminfo) clif->message(fd, msg_txt(1276)); // Please enter an item name/ID (usage: @ii/@iteminfo <item name/ID>). return false; } - if ((item_array[0] = itemdb_exists(atoi(message))) == NULL) - count = itemdb_searchname_array(item_array, MAX_SEARCH, message); + if ((item_array[0] = itemdb->exists(atoi(message))) == NULL) + count = itemdb->search_name_array(item_array, MAX_SEARCH, message); if (!count) { clif->message(fd, msg_txt(19)); // Invalid item ID or name. @@ -7191,8 +7191,8 @@ ACMD(whodrops) clif->message(fd, msg_txt(1284)); // Please enter item name/ID (usage: @whodrops <item name/ID>). return false; } - if ((item_array[0] = itemdb_exists(atoi(message))) == NULL) - count = itemdb_searchname_array(item_array, MAX_SEARCH, message); + if ((item_array[0] = itemdb->exists(atoi(message))) == NULL) + count = itemdb->search_name_array(item_array, MAX_SEARCH, message); if (!count) { clif->message(fd, msg_txt(19)); // Invalid item ID or name. @@ -8111,7 +8111,7 @@ ACMD(itemlist) const struct item* it = &items[i]; struct item_data* itd; - if( it->nameid == 0 || (itd = itemdb_exists(it->nameid)) == NULL ) + if( it->nameid == 0 || (itd = itemdb->exists(it->nameid)) == NULL ) continue; counter += it->amount; @@ -8194,7 +8194,7 @@ ACMD(itemlist) { struct item_data* card; - if( it->card[j] == 0 || (card = itemdb_exists(it->card[j])) == NULL ) + if( it->card[j] == 0 || (card = itemdb->exists(it->card[j])) == NULL ) continue; counter2++; @@ -8307,7 +8307,7 @@ ACMD(delitem) return false; } - if( ( id = itemdb_searchname(item_name) ) != NULL || ( id = itemdb_exists(atoi(item_name)) ) != NULL ) + if( ( id = itemdb->search_name(item_name) ) != NULL || ( id = itemdb->exists(atoi(item_name)) ) != NULL ) { nameid = id->nameid; } diff --git a/src/map/battle.c b/src/map/battle.c index 800d573a2..9e65146e2 100644 --- a/src/map/battle.c +++ b/src/map/battle.c @@ -6285,7 +6285,6 @@ static const struct _battle_data { { "mobs_level_up_exp_rate", &battle_config.mobs_level_up_exp_rate, 1, 1, INT_MAX, }, { "pk_min_level", &battle_config.pk_min_level, 55, 1, INT_MAX, }, { "skill_steal_max_tries", &battle_config.skill_steal_max_tries, 0, 0, UCHAR_MAX, }, - { "finding_ore_rate", &battle_config.finding_ore_rate, 100, 0, INT_MAX, }, { "exp_calc_type", &battle_config.exp_calc_type, 0, 0, 1, }, { "exp_bonus_attacker", &battle_config.exp_bonus_attacker, 25, 0, INT_MAX, }, { "exp_bonus_max_attacker", &battle_config.exp_bonus_max_attacker, 12, 2, INT_MAX, }, diff --git a/src/map/battle.h b/src/map/battle.h index 7d41a02c5..37968f53a 100644 --- a/src/map/battle.h +++ b/src/map/battle.h @@ -325,7 +325,6 @@ struct Battle_Config { int mobs_level_up_exp_rate; // [Valaris] int pk_min_level; // [celest] int skill_steal_max_tries; //max steal skill tries on a mob. if 0, then w/o limit [Lupus] - int finding_ore_rate; // orn int exp_calc_type; int exp_bonus_attacker; int exp_bonus_max_attacker; diff --git a/src/map/buyingstore.c b/src/map/buyingstore.c index 764b51015..dc07c2409 100644 --- a/src/map/buyingstore.c +++ b/src/map/buyingstore.c @@ -137,7 +137,7 @@ void buyingstore_create(struct map_session_data* sd, int zenylimit, unsigned cha amount = RBUFW(itemlist,i*8+2); price = RBUFL(itemlist,i*8+4); - if( ( id = itemdb_exists(nameid) ) == NULL || amount == 0 ) + if( ( id = itemdb->exists(nameid) ) == NULL || amount == 0 ) {// invalid input break; } diff --git a/src/map/clif.c b/src/map/clif.c index 00e395709..3e01230b2 100644 --- a/src/map/clif.c +++ b/src/map/clif.c @@ -1759,7 +1759,7 @@ void clif_buylist(struct map_session_data *sd, struct npc_data *nd) c = 0; for( i = 0; i < nd->u.shop.count; i++ ) { - struct item_data* id = itemdb_exists(nd->u.shop.shop_item[i].nameid); + struct item_data* id = itemdb->exists(nd->u.shop.shop_item[i].nameid); int val = nd->u.shop.shop_item[i].value; if( id == NULL ) continue; @@ -2497,7 +2497,7 @@ void clif_storagelist(struct map_session_data* sd, struct item* items, int items { if( items[i].nameid <= 0 ) continue; - id = itemdb_search(items[i].nameid); + id = itemdb->search(items[i].nameid); if( !itemdb_isstackable2(id) ) { //Equippable WBUFW(bufe,ne*cmd+4)=i+1; @@ -2577,7 +2577,7 @@ void clif_cartlist(struct map_session_data *sd) { if( sd->status.cart[i].nameid <= 0 ) continue; - id = itemdb_search(sd->status.cart[i].nameid); + id = itemdb->search(sd->status.cart[i].nameid); if( !itemdb_isstackable2(id) ) { //Equippable WBUFW(bufe,ne*cmd+4)=i+2; @@ -6416,7 +6416,7 @@ void clif_vendinglist(struct map_session_data* sd, unsigned int id, struct s_ven for( i = 0; i < count; i++ ) { int index = vending[i].index; - struct item_data* data = itemdb_search(vsd->status.cart[index].nameid); + struct item_data* data = itemdb->search(vsd->status.cart[index].nameid); WFIFOL(fd,offset+ 0+i*22) = vending[i].value; WFIFOW(fd,offset+ 4+i*22) = vending[i].amount; WFIFOW(fd,offset+ 6+i*22) = vending[i].index + 2; @@ -6475,7 +6475,7 @@ void clif_openvending(struct map_session_data* sd, int id, struct s_vending* ven WFIFOL(fd,4) = id; for( i = 0; i < count; i++ ) { int index = vending[i].index; - struct item_data* data = itemdb_search(sd->status.cart[index].nameid); + struct item_data* data = itemdb->search(sd->status.cart[index].nameid); WFIFOL(fd, 8+i*22) = vending[i].value; WFIFOW(fd,12+i*22) = vending[i].index + 2; WFIFOW(fd,14+i*22) = vending[i].amount; @@ -9574,7 +9574,7 @@ void clif_parse_LoadEndAck(int fd,struct map_session_data *sd) if( iMap->night_flag && map[sd->bl.m].flag.nightenabled ) { //Display night. if( !sd->state.night ) { sd->state.night = 1; - clif->sc_end(&sd->bl, sd->bl.id, SELF, SI_SKE); + clif->status_change(&sd->bl, SI_SKE, 1, 0, 0, 0, 0); } } else if( sd->state.night ) { //Clear night display. sd->state.night = 0; @@ -9651,6 +9651,7 @@ void clif_parse_LoadEndAck(int fd,struct map_session_data *sd) // Trigger skill effects if you appear standing on them if(!battle_config.pc_invincible_time) skill->unit_move(&sd->bl,iTimer->gettick(),1); + } @@ -13334,7 +13335,7 @@ void clif_parse_GM_Monster_Item(int fd, struct map_session_data *sd) // FIXME: Stackables have a quantity of 20. // FIXME: Equips are supposed to be unidentified. - if( itemdb_searchname(monster_item_name) ) { + if( itemdb->search_name(monster_item_name) ) { snprintf(command, sizeof(command)-1, "%citem %s", atcommand->at_symbol, monster_item_name); atcommand->parse(fd, sd, command, 1); return; @@ -14509,7 +14510,7 @@ void clif_Mail_read(struct map_session_data *sd, int mail_id) WFIFOL(fd,72) = 0; WFIFOL(fd,76) = msg->zeny; - if( item->nameid && (data = itemdb_exists(item->nameid)) != NULL ) { + if( item->nameid && (data = itemdb->exists(item->nameid)) != NULL ) { WFIFOL(fd,80) = item->amount; WFIFOW(fd,84) = (data->view_id)?data->view_id:item->nameid; WFIFOW(fd,86) = data->type; @@ -14582,7 +14583,7 @@ void clif_parse_Mail_getattach(int fd, struct map_session_data *sd) struct item_data *data; unsigned int weight; - if ((data = itemdb_exists(sd->mail.inbox.msg[i].item.nameid)) == NULL) + if ((data = itemdb->exists(sd->mail.inbox.msg[i].item.nameid)) == NULL) return; switch( pc->checkadditem(sd, data->nameid, sd->mail.inbox.msg[i].item.amount) ) { @@ -14800,7 +14801,7 @@ void clif_Auction_results(struct map_session_data *sd, short count, short pages, WFIFOL(fd,k) = auction.auction_id; safestrncpy((char*)WFIFOP(fd,4+k), auction.seller_name, NAME_LENGTH); - if( (item = itemdb_exists(auction.item.nameid)) != NULL && item->view_id > 0 ) + if( (item = itemdb->exists(auction.item.nameid)) != NULL && item->view_id > 0 ) WFIFOW(fd,28+k) = item->view_id; else WFIFOW(fd,28+k) = auction.item.nameid; @@ -14873,7 +14874,7 @@ void clif_parse_Auction_setitem(int fd, struct map_session_data *sd) return; } - if( (item = itemdb_exists(sd->status.inventory[idx].nameid)) != NULL && !(item->type == IT_ARMOR || item->type == IT_PETARMOR || item->type == IT_WEAPON || item->type == IT_CARD || item->type == IT_ETC) ) + if( (item = itemdb->exists(sd->status.inventory[idx].nameid)) != NULL && !(item->type == IT_ARMOR || item->type == IT_PETARMOR || item->type == IT_WEAPON || item->type == IT_CARD || item->type == IT_ETC) ) { // Consumable or pets are not allowed clif->auction_setitem(sd->fd, idx, true); return; @@ -14980,7 +14981,7 @@ void clif_parse_Auction_register(int fd, struct map_session_data *sd) return; } - if( (item = itemdb_exists(sd->status.inventory[sd->auction.index].nameid)) == NULL ) + if( (item = itemdb->exists(sd->status.inventory[sd->auction.index].nameid)) == NULL ) { // Just in case clif->auction_message(fd, 2); // The auction has been canceled return; @@ -15116,7 +15117,7 @@ void clif_cashshop_show(struct map_session_data *sd, struct npc_data *nd) #endif for( i = 0; i < nd->u.shop.count; i++ ) { - struct item_data* id = itemdb_search(nd->u.shop.shop_item[i].nameid); + struct item_data* id = itemdb->search(nd->u.shop.shop_item[i].nameid); WFIFOL(fd,offset+0+i*11) = nd->u.shop.shop_item[i].value; WFIFOL(fd,offset+4+i*11) = nd->u.shop.shop_item[i].value; // Discount Price WFIFOB(fd,offset+8+i*11) = itemtype(id->type); @@ -16036,7 +16037,7 @@ void clif_party_show_picker(struct map_session_data * sd, struct item * item_dat { #if PACKETVER >= 20071002 unsigned char buf[22]; - struct item_data* id = itemdb_search(item_data->nameid); + struct item_data* id = itemdb->search(item_data->nameid); WBUFW(buf,0) = 0x2b8; WBUFL(buf,2) = sd->status.account_id; @@ -17058,12 +17059,12 @@ void clif_cashshop_db(void) { } if( name[0] == 'I' && name[1] == 'D' && strlen(name) <= 7 ) { - if( !( data = itemdb_exists(atoi(name+2))) ) { + if( !( data = itemdb->exists(atoi(name+2))) ) { ShowWarning("cashshop_db: unknown item id '%s' in category '%s'\n", name+2, entry_name); continue; } } else { - if( !( data = itemdb_searchname(name) ) ) { + if( !( data = itemdb->search_name(name) ) ) { ShowWarning("cashshop_db: unknown item name '%s' in category '%s'\n", name, entry_name); continue; } @@ -17123,7 +17124,6 @@ void clif_monster_hp_bar( struct mob_data* md, struct map_session_data *sd ) { void __attribute__ ((unused)) clif_parse_dull(int fd,struct map_session_data *sd) { return; } - void clif_parse_CashShopOpen(int fd, struct map_session_data *sd) { WFIFOHEAD(fd, 10); WFIFOW(fd, 0) = 0x845; @@ -17177,7 +17177,7 @@ void clif_parse_CashShopBuy(int fd, struct map_session_data *sd) { result = CSBR_SHORTTAGE_CASH; } else if( (sd->cashPoints+kafra_pay) < (clif->cs.data[tab][j]->price * qty) ) { result = CSBR_SHORTTAGE_CASH; - } else if ( !( data = itemdb_exists(clif->cs.data[tab][j]->id) ) ) { + } else if ( !( data = itemdb->exists(clif->cs.data[tab][j]->id) ) ) { result = CSBR_UNKONWN_ITEM; } else { struct item item_tmp; @@ -17445,6 +17445,20 @@ void clif_scriptclear(struct map_session_data *sd, int npcid) { clif->send(&p,sizeof(p), &sd->bl, SELF); } + +void clif_package_item_announce(struct map_session_data *sd, unsigned short nameid, unsigned short containerid) { + struct packet_package_item_announce p; + + p.PacketType = package_item_announceType; + p.PacketLength = 10+NAME_LENGTH; + p.type = 0x0; + p.ItemID = containerid; + p.len = NAME_LENGTH; + safestrncpy(p.Name, sd->status.name, sizeof(p.Name)); + p.BoxItemID = nameid; + clif->send(&p,p.PacketLength, &sd->bl, ALL_CLIENT); +} +/* */ unsigned short clif_decrypt_cmd( int cmd, struct map_session_data *sd ) { if( sd ) { sd->cryptKey = (( sd->cryptKey * clif->cryptKey[1] ) + clif->cryptKey[2]) & 0xFFFFFFFF; @@ -18207,6 +18221,7 @@ void clif_defaults(void) { clif->user_count = clif_user_count; clif->noask_sub = clif_noask_sub; clif->cashshop_load = clif_cashshop_db; + clif->package_announce = clif_package_item_announce; clif->bc_ready = clif_bc_ready; clif->undisguise_timer = clif_undisguise_timer; /*------------------------ diff --git a/src/map/clif.h b/src/map/clif.h index 6e1fa81d3..bea701223 100644 --- a/src/map/clif.h +++ b/src/map/clif.h @@ -501,6 +501,7 @@ struct clif_interface { void (*item_sub) (unsigned char *buf, int n, struct item *i, struct item_data *id, int equip); void (*getareachar_item) (struct map_session_data* sd,struct flooritem_data* fitem); void (*cashshop_load) (void); + void (*package_announce) (struct map_session_data *sd, unsigned short nameid, unsigned short containerid); /* unit-related */ void (*clearunit_single) (int id, clr_type type, int fd); void (*clearunit_area) (struct block_list* bl, clr_type type); diff --git a/src/map/itemdb.c b/src/map/itemdb.c index 859b19aac..0ff991bad 100644 --- a/src/map/itemdb.c +++ b/src/map/itemdb.c @@ -8,6 +8,7 @@ #include "../common/showmsg.h" #include "../common/strlib.h" #include "../common/utils.h" +#include "../common/conf.h" #include "itemdb.h" #include "map.h" #include "battle.h" // struct battle_config @@ -52,14 +53,12 @@ static int itemdb_searchname_sub(DBKey key, DBData *data, va_list ap) /*========================================== * Return item data from item name. (lookup) *------------------------------------------*/ -struct item_data* itemdb_searchname(const char *str) -{ +struct item_data* itemdb_searchname(const char *str) { struct item_data* item; struct item_data* item2=NULL; int i; - for( i = 0; i < ARRAYLENGTH(itemdb_array); ++i ) - { + for( i = 0; i < ARRAYLENGTH(itemdb_array); ++i ) { item = itemdb_array[i]; if( item == NULL ) continue; @@ -77,6 +76,10 @@ struct item_data* itemdb_searchname(const char *str) itemdb_other->foreach(itemdb_other,itemdb_searchname_sub,str,&item,&item2); return item?item:item2; } +/* name to item data */ +struct item_data* itemdb_name2id(const char *str) { + return strdb_get(itemdb->names,str); +} /** * @see DBMatcher @@ -98,8 +101,7 @@ static int itemdb_searchname_array_sub(DBKey key, DBData data, va_list ap) /*========================================== * Founds up to N matches. Returns number of matches [Skotlex] *------------------------------------------*/ -int itemdb_searchname_array(struct item_data** data, int size, const char *str) -{ +int itemdb_searchname_array(struct item_data** data, int size, const char *str) { struct item_data* item; int i; int count=0; @@ -132,38 +134,130 @@ int itemdb_searchname_array(struct item_data** data, int size, const char *str) } return count; } - - -/*========================================== - * Return a random item id from group. (takes into account % chance giving/tot group) - *------------------------------------------*/ -int itemdb_searchrandomid(int group) -{ - if(group<1 || group>=MAX_ITEMGROUP) { - ShowError("itemdb_searchrandomid: Invalid group id %d\n", group); +/* [Ind/Hercules] */ +int itemdb_chain_item(unsigned short chain_id, int *rate) { + struct item_chain_entry *entry; + int i = 0; + + if( chain_id >= itemdb->chain_count ) { + ShowError("itemdb_chain_item: unknown chain id %d\n", chain_id); return UNKNOWN_ITEM_ID; } - if (itemgroup_db[group].qty) - return itemgroup_db[group].nameid[rnd()%itemgroup_db[group].qty]; - ShowError("itemdb_searchrandomid: No item entries for group id %d\n", group); - return UNKNOWN_ITEM_ID; + entry = &itemdb->chains[chain_id].items[ rnd()%itemdb->chains[chain_id].qty ]; + + for( i = 0; i < itemdb->chains[chain_id].qty; i++ ) { + if( rnd()%10000 >= entry->rate ) { + entry = entry->next; + continue; + } else { + if( rate ) + rate[0] = entry->rate; + return entry->id; + } + } + + return 0; } +/* [Ind/Hercules] */ +void itemdb_package_item(struct map_session_data *sd, struct item_package *package) { + int i = 0, get_count, j, flag; + + for( i = 0; i < package->must_qty; i++ ) { + struct item it; + memset(&it, 0, sizeof(it)); + it.nameid = package->must_items[i].id; + it.identify = 1; + + if( package->must_items[i].hours ) { + it.expire_time = (unsigned int)(time(NULL) + ((package->must_items[i].hours*60)*60)); + } + + if( package->must_items[i].named ) { + it.card[0] = CARD0_FORGE; + it.card[1] = 0; + it.card[2] = GetWord(sd->status.char_id, 0); + it.card[3] = GetWord(sd->status.char_id, 1); + } + + if( package->must_items[i].announce ) + clif->package_announce(sd,package->must_items[i].id,package->id); + + get_count = itemdb_isstackable(package->must_items[i].id) ? package->must_items[i].qty : 1; + + it.amount = get_count == 1 ? 1 : get_count; + + for( j = 0; j < package->must_items[i].qty; j += get_count ) { + if ( ( flag = pc->additem(sd, &it, get_count, LOG_TYPE_SCRIPT) ) ) + clif->additem(sd, 0, 0, flag); + } + } + + if( package->random_qty ) { + struct item_package_rand_entry *entry; + + entry = &package->random_list[rnd()%package->random_qty]; + + for( i = 0; i < package->random_qty; i++ ) { + if( rnd()%10000 >= entry->rate ) { + entry = entry->next; + continue; + } else { + struct item it; + memset(&it, 0, sizeof(it)); + + it.nameid = entry->id; + it.identify = 1; + + if( entry->hours ) { + it.expire_time = (unsigned int)(time(NULL) + ((entry->hours*60)*60)); + } + + if( entry->named ) { + it.card[0] = CARD0_FORGE; + it.card[1] = 0; + it.card[2] = GetWord(sd->status.char_id, 0); + it.card[3] = GetWord(sd->status.char_id, 1); + } + + if( entry->announce ) + clif->package_announce(sd,entry->id,package->id); + + get_count = itemdb_isstackable(entry->id) ? entry->qty : 1; + + it.amount = get_count == 1 ? 1 : get_count; + + for( j = 0; j < entry->qty; j += get_count ) { + if ( ( flag = pc->additem(sd, &it, get_count, LOG_TYPE_SCRIPT) ) ) + clif->additem(sd, 0, 0, flag); + } + break; + } + } + } + + return; +} /*========================================== - * Calculates total item-group related bonuses for the given item + * Return a random item id from group. (takes into account % chance giving/tot group) *------------------------------------------*/ -int itemdb_group_bonus(struct map_session_data* sd, int itemid) -{ - int bonus = 0, i, j; - for (i=0; i < MAX_ITEMGROUP; i++) { - if (!sd->itemgrouphealrate[i]) - continue; - ARR_FIND( 0, itemgroup_db[i].qty, j, itemgroup_db[i].nameid[j] == itemid ); - if( j < itemgroup_db[i].qty ) - bonus += sd->itemgrouphealrate[i]; - } - return bonus; +int itemdb_searchrandomid(struct item_group *group) { + + if (group->qty) + return group->nameid[rnd()%group->qty]; + + ShowError("itemdb_searchrandomid: No item entries for group id %d\n", group->id); + return UNKNOWN_ITEM_ID; +} +bool itemdb_in_group(struct item_group *group, int nameid) { + int i; + + for( i = 0; i < group->qty; i++ ) + if( group->nameid[i] == nameid ) + return true; + + return false; } /// Searches for the item_data. @@ -499,7 +593,7 @@ static bool itemdb_read_itemavail(char* str[], int columns, int current) nameid = atoi(str[0]); - if( ( id = itemdb_exists(nameid) ) == NULL ) + if( ( id = itemdb->exists(nameid) ) == NULL ) { ShowWarning("itemdb_read_itemavail: Invalid item id %d.\n", nameid); return false; @@ -520,82 +614,291 @@ static bool itemdb_read_itemavail(char* str[], int columns, int current) return true; } -/*========================================== - * read item group data - *------------------------------------------*/ -static unsigned int itemdb_read_itemgroup_sub(const char* filename) { - FILE *fp; - char line[1024]; - int ln=0; - unsigned int count = 0; - int groupid,j,k,nameid; - char *str[3],*p; - char w1[1024], w2[1024]; - - if( (fp=fopen(filename,"r"))==NULL ){ - ShowError("can't read %s\n", filename); - return 0; +void itemdb_read_groups(void) { + config_t item_group_conf; + config_setting_t *itg = NULL, *it = NULL; +#ifdef RENEWAL + const char *config_filename = "db/re/item_group.conf"; // FIXME hardcoded name +#else + const char *config_filename = "db/pre-re/item_group.conf"; // FIXME hardcoded name +#endif + const char *itname; + int i = 0, count = 0, c; + unsigned int *gsize = NULL; + + if (conf_read_file(&item_group_conf, config_filename)) { + ShowError("can't read %s\n", config_filename); + return; } - - while(fgets(line, sizeof(line), fp)) - { - ln++; - if(line[0]=='/' && line[1]=='/') + + gsize = aMalloc( config_setting_length(item_group_conf.root) * sizeof(unsigned int) ); + + for(i = 0; i < config_setting_length(item_group_conf.root); i++) + gsize[i] = 0; + + i = 0; + while( (itg = config_setting_get_elem(item_group_conf.root,i++)) ) { + const char *name = config_setting_name(itg); + + if( !itemdb->name2id(name) ) { + ShowWarning("itemdb_read_groups: unknown group item '%s', skipping..\n",name); + config_setting_remove(item_group_conf.root, name); + --i; continue; - if(strstr(line,"import")) { - if (sscanf(line, "%[^:]: %[^\r\n]", w1, w2) == 2 && - strcmpi(w1, "import") == 0) { - count += itemdb_read_itemgroup_sub(w2); - continue; - } } - memset(str,0,sizeof(str)); - for(j=0,p=line;j<3 && p;j++){ - str[j]=p; - p=strchr(p,','); - if(p) *p++=0; + + c = 0; + while( (it = config_setting_get_elem(itg,c++)) ) { + if( config_setting_is_list(it) ) + gsize[ i - 1 ] += config_setting_get_int_elem(it,1); + else + gsize[ i - 1 ] += 1; } - if(str[0]==NULL) - continue; - if (j<3) { - if (j>1) //Or else it barks on blank lines... - ShowWarning("itemdb_read_itemgroup: Insufficient fields for entry at %s:%d\n", filename, ln); - continue; + + } + + i = 0; + CREATE(itemdb->groups, struct item_group, config_setting_length(item_group_conf.root)); + itemdb->group_count = (unsigned short)config_setting_length(item_group_conf.root); + + while( (itg = config_setting_get_elem(item_group_conf.root,i++)) ) { + struct item_data *data = itemdb->name2id(config_setting_name(itg)); + int ecount = 0; + + data->group = &itemdb->groups[count]; + + itemdb->groups[count].id = data->nameid; + itemdb->groups[count].qty = config_setting_length(itg); + + CREATE(itemdb->groups[count].nameid, unsigned short, gsize[ count ] + 1); + + c = 0; + while( (it = config_setting_get_elem(itg,c++)) ) { + int repeat = 1; + if( config_setting_is_list(it) ) { + itname = config_setting_get_string_elem(it,0); + repeat = config_setting_get_int_elem(it,1); + } else + itname = config_setting_get_string_elem(itg,c - 1); + + if( !( data = itemdb->name2id(itname) ) ) + ShowWarning("itemdb_read_groups: unknown item '%s' in group '%s'!\n",itname,config_setting_name(itg)); + + itemdb->groups[count].nameid[ecount] = data ? data->nameid : 0; + if( repeat > 1 ) { + //memset would be better? I failed to get the following to work though hu + //memset(&itemdb->groups[count].nameid[ecount+1],itemdb->groups[count].nameid[ecount],sizeof(itemdb->groups[count].nameid[0])*repeat); + int z; + for( z = ecount+1; z < ecount+repeat; z++ ) + itemdb->groups[count].nameid[z] = itemdb->groups[count].nameid[ecount]; + } + ecount += repeat; } - groupid = atoi(str[0]); - if (groupid < 0 || groupid >= MAX_ITEMGROUP) { - ShowWarning("itemdb_read_itemgroup: Invalid group %d in %s:%d\n", groupid, filename, ln); + + count++; + } + + config_destroy(&item_group_conf); + aFree(gsize); + + ShowStatus("Done reading '"CL_WHITE"%lu"CL_RESET"' entries in '"CL_WHITE"%s"CL_RESET"'.\n", count, config_filename); +} + +void itemdb_read_packages(void) { + config_t item_packages_conf; + config_setting_t *itg = NULL, *it = NULL, *t = NULL; +#ifdef RENEWAL + const char *config_filename = "db/re/item_packages.conf"; // FIXME hardcoded name +#else + const char *config_filename = "db/pre-re/item_packages.conf"; // FIXME hardcoded name +#endif + const char *itname; + int i = 0, count = 0, c = 0; + unsigned int *must = NULL, *random = NULL; + + if (conf_read_file(&item_packages_conf, config_filename)) { + ShowError("can't read %s\n", config_filename); + return; + } + + must = aMalloc( config_setting_length(item_packages_conf.root) * sizeof(unsigned int) ); + random = aMalloc( config_setting_length(item_packages_conf.root) * sizeof(unsigned int) ); + + for(i = 0; i < config_setting_length(item_packages_conf.root); i++) { + must[i] = 0; + random[i] = 0; + } + + i = 0; + while( (itg = config_setting_get_elem(item_packages_conf.root,i++)) ) { + const char *name = config_setting_name(itg); + + if( !itemdb->name2id(name) ) { + ShowWarning("itemdb_read_packages: unknown package item '%s', skipping..\n",name); + config_setting_remove(item_packages_conf.root, name); + --i; continue; } - nameid = atoi(str[1]); - if (!itemdb_exists(nameid)) { - ShowWarning("itemdb_read_itemgroup: Non-existant item %d in %s:%d\n", nameid, filename, ln); - continue; + + c = 0; + while( (it = config_setting_get_elem(itg,c++)) ) { + if( ( t = config_setting_get_member(it, "Random")) && !config_setting_get_bool(t) ) + must[ i - 1 ] += 1; + else + random[ i - 1 ] += 1; } - k = atoi(str[2]); - if (itemgroup_db[groupid].qty+k >= MAX_RANDITEM) { - ShowWarning("itemdb_read_itemgroup: Group %d is full (%d entries) in %s:%d\n", groupid, MAX_RANDITEM, filename, ln); - continue; + + } + + CREATE(itemdb->packages, struct item_package, config_setting_length(item_packages_conf.root)); + itemdb->package_count = (unsigned short)config_setting_length(item_packages_conf.root); + + i = 0; + while( (itg = config_setting_get_elem(item_packages_conf.root,i++)) ) { + struct item_data *data = itemdb->name2id(config_setting_name(itg)); + struct item_package_rand_entry *prev = NULL; + int r = 0, m = 0; + + data->package = &itemdb->packages[count]; + + itemdb->packages[count].id = data->nameid; + itemdb->packages[count].random_list = NULL; + itemdb->packages[count].must_items = NULL; + itemdb->packages[count].random_qty = random[ i - 1 ]; + itemdb->packages[count].must_qty = must[ i - 1 ]; + + if( itemdb->packages[count].random_qty ) + CREATE(itemdb->packages[count].random_list, struct item_package_rand_entry, itemdb->packages[count].random_qty); + if( itemdb->packages[count].must_qty ) + CREATE(itemdb->packages[count].must_items, struct item_package_must_entry, itemdb->packages[count].must_qty); + + c = 0; + while( (it = config_setting_get_elem(itg,c++)) ) { + int icount = 1, expire = 0, rate = 10000; + bool announce = false, named = false; + + itname = config_setting_name(it); + + if( !( data = itemdb->name2id(itname) ) ) + ShowWarning("itemdb_read_packages: unknown item '%s' in package '%s'!\n",itname,config_setting_name(itg)); + + if( ( t = config_setting_get_member(it, "Count")) ) + icount = config_setting_get_int(t); + + if( ( t = config_setting_get_member(it, "Expire")) ) + expire = config_setting_get_int(t); + + if( ( t = config_setting_get_member(it, "Rate")) ) { + if( (rate = (unsigned short)config_setting_get_int(t)) > 10000 ) { + ShowWarning("itemdb_read_packages: invalid rate (%d) for item '%s' in package '%s'!\n",itname,config_setting_name(itg)); + rate = 10000; + } + } + + if( ( t = config_setting_get_member(it, "Announce")) && config_setting_get_bool(t) ) + announce = true; + + if( ( t = config_setting_get_member(it, "Named")) && config_setting_get_bool(t) ) + named = true; + + if( ( t = config_setting_get_member(it, "Random")) && !config_setting_get_bool(t) ) { + itemdb->packages[count].must_items[m].id = data ? data->nameid : 0; + itemdb->packages[count].must_items[m].qty = icount; + itemdb->packages[count].must_items[m].hours = expire; + itemdb->packages[count].must_items[m].announce = announce == true ? 1 : 0; + itemdb->packages[count].must_items[m].named = named == true ? 1 : 0; + m++; + } else { + if( prev ) + prev->next = &itemdb->packages[count].random_list[r]; + itemdb->packages[count].random_list[r].id = data ? data->nameid : 0; + itemdb->packages[count].random_list[r].qty = icount; + itemdb->packages[count].random_list[r].hours = expire; + itemdb->packages[count].random_list[r].announce = announce == true ? 1 : 0; + itemdb->packages[count].random_list[r].named = named == true ? 1 : 0; + prev = &itemdb->packages[count].random_list[r]; + r++; + } + } - for(j=0;j<k;j++) - itemgroup_db[groupid].nameid[itemgroup_db[groupid].qty++] = nameid; + + if( prev ) + prev->next = &itemdb->packages[count].random_list[0]; + count++; } - fclose(fp); - return count; + + + config_destroy(&item_packages_conf); + aFree(must); + aFree(random); + + ShowStatus("Done reading '"CL_WHITE"%lu"CL_RESET"' entries in '"CL_WHITE"%s"CL_RESET"'.\n", count, config_filename); } -static void itemdb_read_itemgroup(void) -{ - char path[256]; - unsigned int count; - snprintf(path, 255, "%s/"DBPATH"item_group_db.txt", iMap->db_path); - memset(&itemgroup_db, 0, sizeof(itemgroup_db)); - count = itemdb_read_itemgroup_sub(path); - ShowStatus("Done reading '"CL_WHITE"%lu"CL_RESET"' entries in '"CL_WHITE"%s"CL_RESET"'.\n", count, "item_group_db.txt"); - return; +void itemdb_read_chains(void) { + config_t item_chain_conf; + config_setting_t *itc = NULL, *entry = NULL; +#ifdef RENEWAL + const char *config_filename = "db/re/item_chain.conf"; // FIXME hardcoded name +#else + const char *config_filename = "db/pre-re/item_chain.conf"; // FIXME hardcoded name +#endif + int i = 0, count = 0; + + if (conf_read_file(&item_chain_conf, config_filename)) { + ShowError("can't read %s\n", config_filename); + return; + } + + CREATE(itemdb->chains, struct item_chain, config_setting_length(item_chain_conf.root)); + itemdb->chain_count = (unsigned short)config_setting_length(item_chain_conf.root); + + while( (itc = config_setting_get_elem(item_chain_conf.root,i++)) ) { + struct item_data *data = NULL; + struct item_chain_entry *prev = NULL; + const char *name = config_setting_name(itc); + int c = 0; + + script->set_constant2(name,i-1,0); + itemdb->chains[count].qty = (unsigned short)config_setting_length(itc); + + CREATE(itemdb->chains[count].items, struct item_chain_entry, config_setting_length(itc)); + + while( (entry = config_setting_get_elem(itc,c++)) ) { + const char *itname = config_setting_name(entry); + if( itname[0] == 'I' && itname[1] == 'D' && strlen(itname) < 7 ) { + if( !( data = itemdb->exists(atoi(itname+2)) ) ) + ShowWarning("itemdb_read_chains: unknown item ID '%d' in chain '%s'!\n",atoi(itname+2),name); + } else if( !( data = itemdb->name2id(itname) ) ) + ShowWarning("itemdb_read_chains: unknown item '%s' in chain '%s'!\n",itname,name); + + if( prev ) + prev->next = &itemdb->chains[count].items[c - 1]; + + itemdb->chains[count].items[c - 1].id = data ? data->nameid : 0; + itemdb->chains[count].items[c - 1].rate = data ? config_setting_get_int(entry) : 0; + + prev = &itemdb->chains[count].items[c - 1]; + } + + if( prev ) + prev->next = &itemdb->chains[count].items[0]; + + count++; + } + + config_destroy(&item_chain_conf); + + if( !script->get_constant("ITMCHAIN_ORE",&i) ) + ShowWarning("itemdb_read_chains: failed to find 'ITMCHAIN_ORE' chain to link to cache!\n"); + else + itemdb->chain_cache[ECC_ORE] = i; + + ShowStatus("Done reading '"CL_WHITE"%lu"CL_RESET"' entries in '"CL_WHITE"%s"CL_RESET"'.\n", count, config_filename); } + /*========================================== * Reads item trade restrictions [Skotlex] *------------------------------------------*/ @@ -606,7 +909,7 @@ static bool itemdb_read_itemtrade(char* str[], int columns, int current) nameid = atoi(str[0]); - if( ( id = itemdb_exists(nameid) ) == NULL ) + if( ( id = itemdb->exists(nameid) ) == NULL ) { //ShowWarning("itemdb_read_itemtrade: Invalid item id %d.\n", nameid); //return false; @@ -643,7 +946,7 @@ static bool itemdb_read_itemdelay(char* str[], int columns, int current) nameid = atoi(str[0]); - if( ( id = itemdb_exists(nameid) ) == NULL ) + if( ( id = itemdb->exists(nameid) ) == NULL ) { ShowWarning("itemdb_read_itemdelay: Invalid item id %d.\n", nameid); return false; @@ -673,7 +976,7 @@ static bool itemdb_read_stack(char* fields[], int columns, int current) nameid = (unsigned short)strtoul(fields[0], NULL, 10); - if( ( id = itemdb_exists(nameid) ) == NULL ) + if( ( id = itemdb->exists(nameid) ) == NULL ) { ShowWarning("itemdb_read_stack: Unknown item id '%hu'.\n", nameid); return false; @@ -711,7 +1014,7 @@ static bool itemdb_read_buyingstore(char* fields[], int columns, int current) nameid = atoi(fields[0]); - if( ( id = itemdb_exists(nameid) ) == NULL ) + if( ( id = itemdb->exists(nameid) ) == NULL ) { ShowWarning("itemdb_read_buyingstore: Invalid item id %d.\n", nameid); return false; @@ -738,7 +1041,7 @@ static bool itemdb_read_nouse(char* fields[], int columns, int current) nameid = atoi(fields[0]); - if( ( id = itemdb_exists(nameid) ) == NULL ) { + if( ( id = itemdb->exists(nameid) ) == NULL ) { ShowWarning("itemdb_read_nouse: Invalid item id %d.\n", nameid); return false; } @@ -847,7 +1150,7 @@ void itemdb_read_combos() { /* validate */ for(v = 0; v < retcount; v++) { - if( !itemdb_exists(items[v]) ) { + if( !itemdb->exists(items[v]) ) { ShowError("itemdb_read_combos: line %d of \"%s\" contains unknown item ID %d, skipping.\n", lines, path,items[v]); break; } @@ -856,7 +1159,7 @@ void itemdb_read_combos() { if( v < retcount ) continue; - id = itemdb_exists(items[0]); + id = itemdb->exists(items[0]); idx = id->combos_count; @@ -885,7 +1188,7 @@ void itemdb_read_combos() { struct item_data * it; int index; - it = itemdb_exists(items[v]); + it = itemdb->exists(items[v]); index = it->combos_count; @@ -1095,6 +1398,7 @@ int itemdb_parse_dbrow(char** str, const char* source, int line, int scriptopt) if (*str[21+offset]) id->unequip_script = parse_script(str[21+offset], source, line, scriptopt); + strdb_put(itemdb->names, id->name, id); return id->nameid; } @@ -1328,7 +1632,9 @@ static void itemdb_read(void) { itemdb_readdb(); itemdb_read_combos(); - itemdb_read_itemgroup(); + itemdb->read_groups(); + itemdb->read_chains(); + itemdb->read_packages(); sv->readdb(iMap->db_path, "item_avail.txt", ',', 2, 2, -1, &itemdb_read_itemavail); sv->readdb(iMap->db_path, DBPATH"item_trade.txt", ',', 3, 3, -1, &itemdb_read_itemtrade); sv->readdb(iMap->db_path, "item_delay.txt", ',', 2, 2, -1, &itemdb_read_itemdelay); @@ -1336,6 +1642,9 @@ static void itemdb_read(void) { sv->readdb(iMap->db_path, DBPATH"item_buyingstore.txt", ',', 1, 1, -1, &itemdb_read_buyingstore); sv->readdb(iMap->db_path, "item_nouse.txt", ',', 3, 3, -1, &itemdb_read_nouse); + + itemdb->name_constants(); + itemdb_uid_load(); } @@ -1388,8 +1697,7 @@ static int itemdb_final_sub(DBKey key, DBData *data, va_list ap) return 0; } -void itemdb_reload(void) -{ +void itemdb_reload(void) { struct s_mapiterator* iter; struct map_session_data* sd; @@ -1400,9 +1708,46 @@ void itemdb_reload(void) if( itemdb_array[i] ) destroy_item_data(itemdb_array[i], 1); + for( i = 0; i < itemdb->group_count; i++ ) { + if( itemdb->groups[i].nameid ) + aFree(itemdb->groups[i].nameid); + } + + if( itemdb->groups ) + aFree(itemdb->groups); + + itemdb->groups = NULL; + itemdb->group_count = 0; + + for( i = 0; i < itemdb->chain_count; i++ ) { + if( itemdb->chains[i].items ) + aFree(itemdb->chains[i].items); + } + + if( itemdb->chains ) + aFree(itemdb->chains); + + itemdb->chains = NULL; + itemdb->chain_count = 0; + + for( i = 0; i < itemdb->package_count; i++ ) { + if( itemdb->packages[i].random_list ) + aFree(itemdb->packages[i].random_list); + if( itemdb->packages[i].must_items ) + aFree(itemdb->packages[i].must_items); + } + + if( itemdb->packages ) + aFree(itemdb->packages); + + itemdb->packages = NULL; + itemdb->package_count = 0; + itemdb_other->clear(itemdb_other, itemdb_final_sub); - + memset(itemdb_array, 0, sizeof(itemdb_array)); + + db_clear(itemdb->names); // read new data itemdb_read(); @@ -1454,34 +1799,94 @@ void itemdb_reload(void) } mapit->free(iter); } +void itemdb_name_constants(void) { + DBIterator *iter = db_iterator(itemdb->names); + struct item_data *data; + + for( data = dbi_first(iter); dbi_exists(iter); data = dbi_next(iter) ) + script->set_constant2(data->name,data->nameid,0); -void do_final_itemdb(void) -{ + dbi_destroy(iter); +} +void do_final_itemdb(void) { int i; for( i = 0; i < ARRAYLENGTH(itemdb_array); ++i ) if( itemdb_array[i] ) destroy_item_data(itemdb_array[i], 1); + for( i = 0; i < itemdb->group_count; i++ ) { + if( itemdb->groups[i].nameid ) + aFree(itemdb->groups[i].nameid); + } + + if( itemdb->groups ) + aFree(itemdb->groups); + + for( i = 0; i < itemdb->chain_count; i++ ) { + if( itemdb->chains[i].items ) + aFree(itemdb->chains[i].items); + } + + if( itemdb->chains ) + aFree(itemdb->chains); + + for( i = 0; i < itemdb->package_count; i++ ) { + if( itemdb->packages[i].random_list ) + aFree(itemdb->packages[i].random_list); + if( itemdb->packages[i].must_items ) + aFree(itemdb->packages[i].must_items); + } + + if( itemdb->packages ) + aFree(itemdb->packages); + itemdb_other->destroy(itemdb_other, itemdb_final_sub); destroy_item_data(&dummy_item, 0); + db_destroy(itemdb->names); } -int do_init_itemdb(void) { +void do_init_itemdb(void) { memset(itemdb_array, 0, sizeof(itemdb_array)); itemdb_other = idb_alloc(DB_OPT_BASE); + itemdb->names = strdb_alloc(DB_OPT_BASE,ITEM_NAME_LENGTH); create_dummy_data(); //Dummy data item. itemdb_read(); clif->cashshop_load(); - - return 0; } /* incomplete */ void itemdb_defaults(void) { itemdb = &itemdb_s; - itemdb->reload = itemdb_reload;//incomplet=e + itemdb->init = do_init_itemdb; + itemdb->final = do_final_itemdb; + itemdb->reload = itemdb_reload;//incomplete + itemdb->name_constants = itemdb_name_constants; + /* */ + itemdb->groups = NULL; + itemdb->group_count = 0; + /* */ + itemdb->chains = NULL; + itemdb->chain_count = 0; + /* */ + itemdb->packages = NULL; + itemdb->package_count = 0; + /* */ + itemdb->names = NULL; + /* */ + itemdb->read_groups = itemdb_read_groups; + itemdb->read_chains = itemdb_read_chains; + itemdb->read_packages = itemdb_read_packages; /* */ + itemdb->search_name = itemdb_searchname; + itemdb->search_name_array = itemdb_searchname_array; + itemdb->load = itemdb_load; + itemdb->search = itemdb_search; itemdb->parse_dbrow = itemdb_parse_dbrow; itemdb->exists = itemdb_exists;//incomplete + itemdb->name2id = itemdb_name2id; + itemdb->in_group = itemdb_in_group; + itemdb->group_item = itemdb_searchrandomid; + itemdb->chain_item = itemdb_chain_item; + itemdb->package_item = itemdb_package_item; } diff --git a/src/map/itemdb.h b/src/map/itemdb.h index 44b455d80..5e870a5f2 100644 --- a/src/map/itemdb.h +++ b/src/map/itemdb.h @@ -9,18 +9,29 @@ #include "../common/mmo.h" // ITEM_NAME_LENGTH #include "map.h" -// 32k array entries in array (the rest goes to the db) -#define MAX_ITEMDB 0x8000 +/** + * Declarations + **/ +struct item_group; +struct item_package; -#define MAX_RANDITEM 11000 +/** + * Defines + **/ +#define MAX_ITEMDB 0x8000 // 32k array entries in array (the rest goes to the db) +#define MAX_ITEMDELAYS 10 // The maximum number of item delays +#define MAX_SEARCH 5 //Designed for search functions, species max number of matches to display. +#define MAX_ITEMS_PER_COMBO 6 /* maximum amount of items a combo may require */ -// The maximum number of item delays -#define MAX_ITEMDELAYS 10 +#define CARD0_FORGE 0x00FF +#define CARD0_CREATE 0x00FE +#define CARD0_PET ((short)0xFF00) -#define MAX_SEARCH 5 //Designed for search functions, species max number of matches to display. +//Marks if the card0 given is "special" (non-item id used to mark pets/created items. [Skotlex] +#define itemdb_isspecial(i) (i == CARD0_FORGE || i == CARD0_CREATE || i == CARD0_PET) -/* maximum amount of items a combo may require */ -#define MAX_ITEMS_PER_COMBO 6 +//Use apple for unknown items. +#define UNKNOWN_ITEM_ID 512 enum item_itemid { ITEMID_HOLY_WATER = 523, @@ -76,21 +87,12 @@ enum { NOUSE_SITTING = 0x01, } item_nouse_list; -//The only item group required by the code to be known. See const.txt for the full list. -#define IG_FINDINGORE 6 -#define IG_POTION 37 -//The max. item group count (increase this when needed). -#define MAX_ITEMGROUP 63 - -#define CARD0_FORGE 0x00FF -#define CARD0_CREATE 0x00FE -#define CARD0_PET ((short)0xFF00) - -//Marks if the card0 given is "special" (non-item id used to mark pets/created items. [Skotlex] -#define itemdb_isspecial(i) (i == CARD0_FORGE || i == CARD0_CREATE || i == CARD0_PET) - -//Use apple for unknown items. -#define UNKNOWN_ITEM_ID 512 +// +enum e_chain_cache { + ECC_ORE, + /* */ + ECC_MAX, +}; struct item_data { uint16 nameid; @@ -152,11 +154,9 @@ struct item_data { /* bugreport:309 */ struct item_combo **combos; unsigned char combos_count; -}; - -struct item_group { - int nameid[MAX_RANDITEM]; - int qty; //Counts amount of items in the group. + /* TODO add a pointer to some sort of (struct extra) and gather all the not-common vals into it to save memory */ + struct item_group *group; + struct item_package *package; }; struct item_combo { @@ -167,29 +167,65 @@ struct item_combo { bool isRef;/* whether this struct is a reference or the master */ }; -struct item_group itemgroup_db[MAX_ITEMGROUP]; - -struct item_data* itemdb_searchname(const char *name); -int itemdb_searchname_array(struct item_data** data, int size, const char *str); -struct item_data* itemdb_load(int nameid); -struct item_data* itemdb_search(int nameid); -struct item_data* itemdb_exists(int nameid); -#define itemdb_name(n) itemdb_search(n)->name -#define itemdb_jname(n) itemdb_search(n)->jname -#define itemdb_type(n) itemdb_search(n)->type -#define itemdb_atk(n) itemdb_search(n)->atk -#define itemdb_def(n) itemdb_search(n)->def -#define itemdb_look(n) itemdb_search(n)->look -#define itemdb_weight(n) itemdb_search(n)->weight -#define itemdb_equip(n) itemdb_search(n)->equip -#define itemdb_usescript(n) itemdb_search(n)->script -#define itemdb_equipscript(n) itemdb_search(n)->script -#define itemdb_wlv(n) itemdb_search(n)->wlv -#define itemdb_range(n) itemdb_search(n)->range -#define itemdb_slot(n) itemdb_search(n)->slot -#define itemdb_available(n) (itemdb_search(n)->flag.available) -#define itemdb_viewid(n) (itemdb_search(n)->view_id) -#define itemdb_autoequip(n) (itemdb_search(n)->flag.autoequip) +struct item_group { + unsigned short id; + unsigned short *nameid; + unsigned short qty; +}; + +struct item_chain_entry { + unsigned short id; + unsigned short rate; + struct item_chain_entry *next; +}; + +struct item_chain { + struct item_chain_entry *items; + unsigned short qty; +}; + +struct item_package_rand_entry { + unsigned short id; + unsigned short qty; + unsigned short rate; + unsigned short hours; + unsigned int announce : 1; + unsigned int named : 1; + struct item_package_rand_entry *next; +}; + +struct item_package_must_entry { + unsigned short id; + unsigned short qty; + unsigned short hours; + unsigned int announce : 1; + unsigned int named : 1; +}; + +struct item_package { + unsigned short id; + struct item_package_rand_entry *random_list; + struct item_package_must_entry *must_items; + unsigned short random_qty; + unsigned short must_qty; +}; + +#define itemdb_name(n) itemdb->search(n)->name +#define itemdb_jname(n) itemdb->search(n)->jname +#define itemdb_type(n) itemdb->search(n)->type +#define itemdb_atk(n) itemdb->search(n)->atk +#define itemdb_def(n) itemdb->search(n)->def +#define itemdb_look(n) itemdb->search(n)->look +#define itemdb_weight(n) itemdb->search(n)->weight +#define itemdb_equip(n) itemdb->search(n)->equip +#define itemdb_usescript(n) itemdb->search(n)->script +#define itemdb_equipscript(n) itemdb->search(n)->script +#define itemdb_wlv(n) itemdb->search(n)->wlv +#define itemdb_range(n) itemdb->search(n)->range +#define itemdb_slot(n) itemdb->search(n)->slot +#define itemdb_available(n) (itemdb->search(n)->flag.available) +#define itemdb_viewid(n) (itemdb->search(n)->view_id) +#define itemdb_autoequip(n) (itemdb->search(n)->flag.autoequip) #define itemdb_is_rune(n) (n >= ITEMID_NAUTHIZ && n <= ITEMID_HAGALAZ) #define itemdb_is_element(n) (n >= 990 && n <= 993) #define itemdb_is_spellbook(n) (n >= 6188 && n <= 6205) @@ -200,12 +236,9 @@ struct item_data* itemdb_exists(int nameid); #define itemdb_is_GNthrowable(n) (n >= 13268 && n <= 13290) const char* itemdb_typename(int type); -int itemdb_group_bonus(struct map_session_data* sd, int itemid); -int itemdb_searchrandomid(int flags); - -#define itemdb_value_buy(n) itemdb_search(n)->value_buy -#define itemdb_value_sell(n) itemdb_search(n)->value_sell -#define itemdb_canrefine(n) (!itemdb_search(n)->flag.no_refine) +#define itemdb_value_buy(n) itemdb->search(n)->value_buy +#define itemdb_value_sell(n) itemdb->search(n)->value_sell +#define itemdb_canrefine(n) (!itemdb->search(n)->flag.no_refine) //Item trade restrictions [Skotlex] int itemdb_isdropable_sub(struct item_data *, int, int); int itemdb_cantrade_sub(struct item_data*, int, int); @@ -235,17 +268,40 @@ int itemdb_isstackable(int); int itemdb_isstackable2(struct item_data *); uint64 itemdb_unique_id(int8 flag, int64 value); // Unique Item ID -void itemdb_reload(void); - -void do_final_itemdb(void); -int do_init_itemdb(void); - /* incomplete */ struct itemdb_interface { + void (*init) (void); + void (*final) (void); void (*reload) (void); + void (*name_constants) (void); + /* */ + struct item_group *groups; + unsigned short group_count; + /* */ + struct item_chain *chains; + unsigned short chain_count; + unsigned short chain_cache[ECC_MAX]; + /* */ + struct item_package *packages; + unsigned short package_count; + /* */ + DBMap *names; + /* */ + void (*read_groups) (void); + void (*read_chains) (void); + void (*read_packages) (void); /* */ + struct item_data* (*name2id) (const char *str); + struct item_data* (*search_name) (const char *name); + int (*search_name_array) (struct item_data** data, int size, const char *str); + struct item_data* (*load)(int nameid); + struct item_data* (*search)(int nameid); int (*parse_dbrow) (char** str, const char* source, int line, int scriptopt); struct item_data* (*exists) (int nameid); + bool (*in_group) (struct item_group *group, int nameid); + int (*group_item) (struct item_group *group); + int (*chain_item) (unsigned short chain_id, int *rate); + void (*package_item) (struct map_session_data *sd, struct item_package *package); } itemdb_s; struct itemdb_interface *itemdb; diff --git a/src/map/log.c b/src/map/log.c index dfb4c4a61..ae516b84e 100644 --- a/src/map/log.c +++ b/src/map/log.c @@ -187,14 +187,14 @@ void log_pick(int id, int16 m, e_log_pick_type type, int amount, struct item* it /// logs item transactions (players) void log_pick_pc(struct map_session_data* sd, e_log_pick_type type, int amount, struct item* itm, struct item_data *data) { nullpo_retv(sd); - log_pick(sd->status.char_id, sd->bl.m, type, amount, itm, data ? data : itemdb_exists(itm->nameid)); + log_pick(sd->status.char_id, sd->bl.m, type, amount, itm, data ? data : itemdb->exists(itm->nameid)); } /// logs item transactions (monsters) void log_pick_mob(struct mob_data* md, e_log_pick_type type, int amount, struct item* itm, struct item_data *data) { nullpo_retv(md); - log_pick(md->class_, md->bl.m, type, amount, itm, data ? data : itemdb_exists(itm->nameid)); + log_pick(md->class_, md->bl.m, type, amount, itm, data ? data : itemdb->exists(itm->nameid)); } void log_zeny_sub_sql(struct map_session_data* sd, e_log_pick_type type, struct map_session_data* src_sd, int amount) { if( SQL_ERROR == SQL->Query(logmysql_handle, LOG_QUERY " INTO `%s` (`time`, `char_id`, `src_id`, `type`, `amount`, `map`) VALUES (NOW(), '%d', '%d', '%c', '%d', '%s')", diff --git a/src/map/map.c b/src/map/map.c index fbdb7a9f9..956ae5969 100644 --- a/src/map/map.c +++ b/src/map/map.c @@ -3842,7 +3842,7 @@ bool map_zone_mf_cache(int m, char *flag, char *params) { int drop_id = 0, drop_type = 0; if (!strcmpi(drop_arg1, "random")) drop_id = -1; - else if (itemdb_exists((drop_id = atoi(drop_arg1))) == NULL) + else if (itemdb->exists((drop_id = atoi(drop_arg1))) == NULL) drop_id = 0; if (!strcmpi(drop_arg2, "inventory")) drop_type = 1; @@ -4441,11 +4441,11 @@ unsigned short map_zone_str2itemid(const char *name) { if( !name ) return 0; if( name[0] == 'I' && name[1] == 'D' && strlen(name) <= 7 ) { - if( !( data = itemdb_exists(atoi(name+2))) ) { + if( !( data = itemdb->exists(atoi(name+2))) ) { return 0; } } else { - if( !( data = itemdb_searchname(name) ) ) { + if( !( data = itemdb->search_name(name) ) ) { return 0; } } @@ -5030,7 +5030,7 @@ void do_final(void) clif->final(); do_final_npc(); script->final(); - do_final_itemdb(); + itemdb->final(); storage->final(); guild->final(); party->do_final_party(); @@ -5466,7 +5466,7 @@ int do_init(int argc, char *argv[]) clif->init(); ircbot->init(); script->init(); - do_init_itemdb(); + itemdb->init(); skill->init(); read_map_zone_db();/* read after item and skill initalization */ do_init_mob(); diff --git a/src/map/map.h b/src/map/map.h index 3e7c45bc3..1b15b477d 100644 --- a/src/map/map.h +++ b/src/map/map.h @@ -386,7 +386,7 @@ enum _sp { SP_SUBSIZE, SP_HP_DRAIN_VALUE_RACE, SP_ADD_ITEM_HEAL_RATE, SP_SP_DRAIN_VALUE_RACE, SP_EXP_ADDRACE, // 2026-2030 SP_SP_GAIN_RACE, SP_SUBRACE2, SP_UNBREAKABLE_SHOES, // 2031-2033 SP_UNSTRIPABLE_WEAPON,SP_UNSTRIPABLE_ARMOR,SP_UNSTRIPABLE_HELM,SP_UNSTRIPABLE_SHIELD, // 2034-2037 - SP_INTRAVISION, SP_ADD_MONSTER_DROP_ITEMGROUP, SP_SP_LOSS_RATE, // 2038-2040 + SP_INTRAVISION, SP_ADD_MONSTER_DROP_CHAINITEM, SP_SP_LOSS_RATE, // 2038-2040 SP_ADD_SKILL_BLOW, SP_SP_VANISH_RATE, SP_MAGIC_SP_GAIN_VALUE, SP_MAGIC_HP_GAIN_VALUE, SP_ADD_CLASS_DROP_ITEM, //2041-2045 SP_EMATK, SP_SP_GAIN_RACE_ATTACK, SP_HP_GAIN_RACE_ATTACK, SP_SKILL_USE_SP_RATE, //2046-2049 SP_SKILL_COOLDOWN,SP_SKILL_FIXEDCAST, SP_SKILL_VARIABLECAST, SP_FIXCASTRATE, SP_VARCASTRATE, //2050-2054 diff --git a/src/map/mob.c b/src/map/mob.c index 6bb40478f..3f282bf7e 100644 --- a/src/map/mob.c +++ b/src/map/mob.c @@ -2330,7 +2330,7 @@ int mob_dead(struct mob_data *md, struct block_list *src, int type) { if (md->db->dropitem[i].nameid <= 0) continue; - if ( !(it = itemdb_exists(md->db->dropitem[i].nameid)) ) + if ( !(it = itemdb->exists(md->db->dropitem[i].nameid)) ) continue; drop_rate = md->db->dropitem[i].p; if (drop_rate <= 0) { @@ -2394,9 +2394,11 @@ int mob_dead(struct mob_data *md, struct block_list *src, int type) } // Ore Discovery [Celest] - if (sd == mvp_sd && pc->checkskill(sd,BS_FINDINGORE)>0 && battle_config.finding_ore_rate/10 >= rnd()%10000) { - ditem = mob_setdropitem(itemdb_searchrandomid(IG_FINDINGORE), 1, NULL); - mob_item_drop(md, dlist, ditem, 0, battle_config.finding_ore_rate/10, homkillonly); + if (sd == mvp_sd && pc->checkskill(sd,BS_FINDINGORE) > 0) { + if( (temp = itemdb->chain_item(itemdb->chain_cache[ECC_ORE],&i)) ) { + ditem = mob_setdropitem(temp, 1, NULL); + mob_item_drop(md, dlist, ditem, 0, i, homkillonly); + } } if(sd) { @@ -2424,8 +2426,9 @@ int mob_dead(struct mob_data *md, struct block_list *src, int type) if (rnd()%10000 >= drop_rate) continue; - itemid = (sd->add_drop[i].id > 0) ? sd->add_drop[i].id : itemdb_searchrandomid(sd->add_drop[i].group); - mob_item_drop(md, dlist, mob_setdropitem(itemid,1,NULL), 0, drop_rate, homkillonly); + itemid = (sd->add_drop[i].id > 0) ? sd->add_drop[i].id : itemdb->chain_item(sd->add_drop[i].group,&drop_rate); + if( itemid ) + mob_item_drop(md, dlist, mob_setdropitem(itemid,1,NULL), 0, drop_rate, homkillonly); } } @@ -2504,7 +2507,7 @@ int mob_dead(struct mob_data *md, struct block_list *src, int type) struct item_data *data; if(mdrop_id[i] <= 0) continue; - if(! (data = itemdb_exists(mdrop_id[i])) ) + if(! (data = itemdb->exists(mdrop_id[i])) ) continue; temp = mdrop_p[i]; @@ -3785,7 +3788,7 @@ static bool mob_parse_dbrow(char** str) //calculate and store Max available drop chance of the MVP item if (db->mvpitem[i].p) { struct item_data *id; - id = itemdb_search(db->mvpitem[i].nameid); + id = itemdb->search(db->mvpitem[i].nameid); if (id->maxchance == -1 || (id->maxchance < db->mvpitem[i].p/10 + 1) ) { //item has bigger drop chance or sold in shops id->maxchance = db->mvpitem[i].p/10 + 1; //reduce MVP drop info to not spoil common drop rate @@ -3803,7 +3806,7 @@ static bool mob_parse_dbrow(char** str) db->dropitem[i].p = 0; //No drop. continue; } - id = itemdb_search(db->dropitem[i].nameid); + id = itemdb->search(db->dropitem[i].nameid); type = id->type; rate = atoi(str[k+1]); if( (class_ >= 1324 && class_ <= 1363) || (class_ >= 1938 && class_ <= 1946) ) @@ -4560,7 +4563,7 @@ static bool mob_readdb_itemratio(char* str[], int columns, int current) int nameid, ratio, i; nameid = atoi(str[0]); - if( itemdb_exists(nameid) == NULL ) + if( itemdb->exists(nameid) == NULL ) { ShowWarning("itemdb_read_itemratio: Invalid item id %d.\n", nameid); return false; diff --git a/src/map/npc.c b/src/map/npc.c index 46e6d0fd2..d90f87f5d 100644 --- a/src/map/npc.c +++ b/src/map/npc.c @@ -610,18 +610,14 @@ int npc_timerevent_start(struct npc_data* nd, int rid) ShowError("npc_timerevent_start: Attached player not found!\n"); return 1; } - // Check if timer is already started. - if( sd ) - { + if( sd ) { if( sd->npc_timer_id != INVALID_TIMER ) return 0; - } - else if( nd->u.scr.timerid != INVALID_TIMER || nd->u.scr.timertick ) + } else if( nd->u.scr.timerid != INVALID_TIMER || nd->u.scr.timertick ) return 0; - if (j < nd->u.scr.timeramount) - { + if (j < nd->u.scr.timeramount) { int next; struct timer_event_data *ted; // Arrange for the next event @@ -640,10 +636,10 @@ int npc_timerevent_start(struct npc_data* nd, int rid) nd->u.scr.timertick = tick; // Set when timer is started nd->u.scr.timerid = iTimer->add_timer(tick+next,npc_timerevent,nd->bl.id,(intptr_t)ted); } - } - else if (!sd) - { + + } else if (!sd) { nd->u.scr.timertick = tick; + } return 0; @@ -664,7 +660,6 @@ int npc_timerevent_stop(struct npc_data* nd) ShowError("npc_timerevent_stop: Attached player not found!\n"); return 1; } - tid = sd?&sd->npc_timer_id:&nd->u.scr.timerid; if( *tid == INVALID_TIMER && (sd || !nd->u.scr.timertick) ) // Nothing to stop return 0; @@ -785,7 +780,7 @@ int npc_settimerevent_tick(struct npc_data* nd, int newtimer) nd->u.scr.rid = 0; // Check if timer is started - flag = (nd->u.scr.timerid != INVALID_TIMER); + flag = (nd->u.scr.timerid != INVALID_TIMER || nd->u.scr.timertick); if( flag ) npc_timerevent_stop(nd); nd->u.scr.timer = newtimer; @@ -1322,7 +1317,7 @@ int npc_cashshop_buylist(struct map_session_data *sd, int points, int count, uns nameid = item_list[i*2+1]; amount = item_list[i*2+0]; - if( !itemdb_exists(nameid) || amount <= 0 ) + if( !itemdb->exists(nameid) || amount <= 0 ) return 5; ARR_FIND(0,nd->u.shop.count,j,nd->u.shop.shop_item[j].nameid == nameid); @@ -1427,7 +1422,7 @@ int npc_cashshop_buy(struct map_session_data *sd, int nameid, int amount, int po if( sd->state.trading ) return 4; - if( (item = itemdb_exists(nameid)) == NULL ) + if( (item = itemdb->exists(nameid)) == NULL ) return 5; // Invalid Item ARR_FIND(0, nd->u.shop.count, i, nd->u.shop.shop_item[i].nameid == nameid); @@ -1526,7 +1521,7 @@ int npc_buylist(struct map_session_data* sd, int n, unsigned short* item_list) nameid = item_list[i*2+1] = nd->u.shop.shop_item[j].nameid; //item_avail replacement value = nd->u.shop.shop_item[j].value; - if( !itemdb_exists(nameid) ) + if( !itemdb->exists(nameid) ) return 3; // item no longer in itemdb if( !itemdb_isstackable(nameid) && amount > 1 ) { @@ -2211,7 +2206,7 @@ static const char* npc_parse_shop(char* w1, char* w2, char* w3, char* w4, const break; } - if( (id = itemdb_exists(nameid)) == NULL ) + if( (id = itemdb->exists(nameid)) == NULL ) { ShowWarning("npc_parse_shop: Invalid sell item in file '%s', line '%d' (id '%d').\n", filepath, strline(buffer,start-buffer), nameid); p = strchr(p+1,','); @@ -3230,7 +3225,7 @@ const char* npc_parse_mapflag(char* w1, char* w2, char* w3, char* w4, const char int drop_id = 0, drop_type = 0; if (!strcmpi(drop_arg1, "random")) drop_id = -1; - else if (itemdb_exists((drop_id = atoi(drop_arg1))) == NULL) + else if (itemdb->exists((drop_id = atoi(drop_arg1))) == NULL) drop_id = 0; if (!strcmpi(drop_arg2, "inventory")) drop_type = 1; @@ -3850,6 +3845,9 @@ int npc_reload(void) { npc->motd = npc_name2id("HerculesMOTD"); /* [Ind/Hercules] */ + /* re-insert */ + itemdb->name_constants(); + //Re-read the NPC Script Events cache. npc_read_event_script(); diff --git a/src/map/packets_struct.h b/src/map/packets_struct.h index 083c00e31..1a52040a8 100644 --- a/src/map/packets_struct.h +++ b/src/map/packets_struct.h @@ -73,6 +73,7 @@ enum packet_headers { authokType = 0x2eb, #endif script_clearType = 0x8d6, + package_item_announceType = 0x7fd, #if PACKETVER < 4 unit_walkingType = 0x7b, #elif PACKETVER < 7 @@ -459,6 +460,15 @@ struct packet_script_clear { unsigned int NpcID; } __attribute__((packed)); +struct packet_package_item_announce { + short PacketType; + short PacketLength; + unsigned char type; + unsigned short ItemID; + char len; + char Name[NAME_LENGTH]; + unsigned short BoxItemID; +} __attribute__((packed)); #pragma pack(pop) diff --git a/src/map/pc.c b/src/map/pc.c index d8e2a0537..ec1036749 100644 --- a/src/map/pc.c +++ b/src/map/pc.c @@ -619,7 +619,7 @@ int pc_setinventorydata(struct map_session_data *sd) for(i=0;i<MAX_INVENTORY;i++) { id = sd->status.inventory[i].nameid; - sd->inventory_data[i] = id?itemdb_search(id):NULL; + sd->inventory_data[i] = id?itemdb->search(id):NULL; } return 0; } @@ -720,7 +720,7 @@ int pc_setequipindex(struct map_session_data *sd) // if( item->card[MAX_SLOTS - 1] && s < MAX_SLOTS - 1 ) // s = MAX_SLOTS - 1; // -// ARR_FIND( 0, s, i, item->card[i] && (data = itemdb_exists(item->card[i])) != NULL && data->flag.no_equip&flag ); +// ARR_FIND( 0, s, i, item->card[i] && (data = itemdb->exists(item->card[i])) != NULL && data->flag.no_equip&flag ); // return( i < s ) ? 0 : 1; //} @@ -1809,9 +1809,9 @@ static int pc_bonus_addeff_onskill(struct s_addeffectonskill* effect, int max, e return 1; } -static int pc_bonus_item_drop(struct s_add_drop *drop, const short max, short id, short group, int race, int rate) -{ +static int pc_bonus_item_drop(struct s_add_drop *drop, const short max, short id, short group, int race, int rate) { int i; + ShowDebug("Adding %s (%d) with rate %d\n",id?itemdb_name(id):"NONE",id,rate); //Apply config rate adjustment settings. if (rate >= 0) { //Absolute drop. if (battle_config.item_rate_adddrop != 100) @@ -1851,6 +1851,8 @@ static int pc_bonus_item_drop(struct s_add_drop *drop, const short max, short id ShowWarning("pc_bonus: Reached max (%d) number of added drops per character!\n", max); return 0; } + if( id ) + ShowDebug("Adding %s (%d) with rate %d\n",itemdb_name(id),id,rate); drop[i].id = id; drop[i].group = group; drop[i].race |= race; @@ -2638,6 +2640,10 @@ int pc_bonus(struct map_session_data *sd,int type,int val) break; #endif + case SP_ADD_MONSTER_DROP_CHAINITEM: + if (sd->state.lr_flag != 2) + pc_bonus_item_drop(sd->add_drop, ARRAYLENGTH(sd->add_drop), 0, val, (1<<RC_BOSS)|(1<<RC_NONBOSS), 10000); + break; default: ShowWarning("pc_bonus: unknown type %d %d !\n",type,val); break; @@ -2655,593 +2661,589 @@ int pc_bonus2(struct map_session_data *sd,int type,int type2,int val) nullpo_ret(sd); switch(type){ - case SP_ADDELE: - if(type2 >= ELE_MAX) { - ShowError("pc_bonus2: SP_ADDELE: Invalid element %d\n", type2); + case SP_ADDELE: + if(type2 >= ELE_MAX) { + ShowError("pc_bonus2: SP_ADDELE: Invalid element %d\n", type2); + break; + } + if(!sd->state.lr_flag) + sd->right_weapon.addele[type2]+=val; + else if(sd->state.lr_flag == 1) + sd->left_weapon.addele[type2]+=val; + else if(sd->state.lr_flag == 2) + sd->arrow_addele[type2]+=val; break; - } - if(!sd->state.lr_flag) - sd->right_weapon.addele[type2]+=val; - else if(sd->state.lr_flag == 1) - sd->left_weapon.addele[type2]+=val; - else if(sd->state.lr_flag == 2) - sd->arrow_addele[type2]+=val; - break; - case SP_ADDRACE: - if(!sd->state.lr_flag) - sd->right_weapon.addrace[type2]+=val; - else if(sd->state.lr_flag == 1) - sd->left_weapon.addrace[type2]+=val; - else if(sd->state.lr_flag == 2) - sd->arrow_addrace[type2]+=val; - break; - case SP_ADDSIZE: - if(!sd->state.lr_flag) - sd->right_weapon.addsize[type2]+=val; - else if(sd->state.lr_flag == 1) - sd->left_weapon.addsize[type2]+=val; - else if(sd->state.lr_flag == 2) - sd->arrow_addsize[type2]+=val; - break; - case SP_SUBELE: - if(type2 >= ELE_MAX) { - ShowError("pc_bonus2: SP_SUBELE: Invalid element %d\n", type2); + case SP_ADDRACE: + if(!sd->state.lr_flag) + sd->right_weapon.addrace[type2]+=val; + else if(sd->state.lr_flag == 1) + sd->left_weapon.addrace[type2]+=val; + else if(sd->state.lr_flag == 2) + sd->arrow_addrace[type2]+=val; break; - } - if(sd->state.lr_flag != 2) - sd->subele[type2]+=val; - break; - case SP_SUBRACE: - if(sd->state.lr_flag != 2) - sd->subrace[type2]+=val; - break; - case SP_ADDEFF: - if (type2 > SC_MAX) { - ShowWarning("pc_bonus2 (Add Effect): %d is not supported.\n", type2); + case SP_ADDSIZE: + if(!sd->state.lr_flag) + sd->right_weapon.addsize[type2]+=val; + else if(sd->state.lr_flag == 1) + sd->left_weapon.addsize[type2]+=val; + else if(sd->state.lr_flag == 2) + sd->arrow_addsize[type2]+=val; break; - } - pc_bonus_addeff(sd->addeff, ARRAYLENGTH(sd->addeff), (sc_type)type2, - sd->state.lr_flag!=2?val:0, sd->state.lr_flag==2?val:0, 0); - break; - case SP_ADDEFF2: - if (type2 > SC_MAX) { - ShowWarning("pc_bonus2 (Add Effect2): %d is not supported.\n", type2); + case SP_SUBELE: + if(type2 >= ELE_MAX) { + ShowError("pc_bonus2: SP_SUBELE: Invalid element %d\n", type2); + break; + } + if(sd->state.lr_flag != 2) + sd->subele[type2]+=val; break; - } - pc_bonus_addeff(sd->addeff, ARRAYLENGTH(sd->addeff), (sc_type)type2, - sd->state.lr_flag!=2?val:0, sd->state.lr_flag==2?val:0, ATF_SELF); - break; - case SP_RESEFF: - if (type2 < SC_COMMON_MIN || type2 > SC_COMMON_MAX) { - ShowWarning("pc_bonus2 (Resist Effect): %d is not supported.\n", type2); + case SP_SUBRACE: + if(sd->state.lr_flag != 2) + sd->subrace[type2]+=val; break; - } - if(sd->state.lr_flag == 2) + case SP_ADDEFF: + if (type2 > SC_MAX) { + ShowWarning("pc_bonus2 (Add Effect): %d is not supported.\n", type2); + break; + } + pc_bonus_addeff(sd->addeff, ARRAYLENGTH(sd->addeff), (sc_type)type2, + sd->state.lr_flag!=2?val:0, sd->state.lr_flag==2?val:0, 0); break; - i = sd->reseff[type2-SC_COMMON_MIN]+val; - sd->reseff[type2-SC_COMMON_MIN]= cap_value(i, 0, 10000); - break; - case SP_MAGIC_ADDELE: - if(type2 >= ELE_MAX) { - ShowError("pc_bonus2: SP_MAGIC_ADDELE: Invalid element %d\n", type2); + case SP_ADDEFF2: + if (type2 > SC_MAX) { + ShowWarning("pc_bonus2 (Add Effect2): %d is not supported.\n", type2); + break; + } + pc_bonus_addeff(sd->addeff, ARRAYLENGTH(sd->addeff), (sc_type)type2, + sd->state.lr_flag!=2?val:0, sd->state.lr_flag==2?val:0, ATF_SELF); break; - } - if(sd->state.lr_flag != 2) - sd->magic_addele[type2]+=val; - break; - case SP_MAGIC_ADDRACE: - if(sd->state.lr_flag != 2) - sd->magic_addrace[type2]+=val; - break; - case SP_MAGIC_ADDSIZE: - if(sd->state.lr_flag != 2) - sd->magic_addsize[type2]+=val; - break; - case SP_MAGIC_ATK_ELE: - if(sd->state.lr_flag != 2) - sd->magic_atk_ele[type2]+=val; - break; - case SP_ADD_DAMAGE_CLASS: - switch (sd->state.lr_flag) { - case 0: //Right hand - ARR_FIND(0, ARRAYLENGTH(sd->right_weapon.add_dmg), i, sd->right_weapon.add_dmg[i].rate == 0 || sd->right_weapon.add_dmg[i].class_ == type2); - if (i == ARRAYLENGTH(sd->right_weapon.add_dmg)) - { - ShowWarning("pc_bonus2: Reached max (%d) number of add Class dmg bonuses per character!\n", ARRAYLENGTH(sd->right_weapon.add_dmg)); + case SP_RESEFF: + if (type2 < SC_COMMON_MIN || type2 > SC_COMMON_MAX) { + ShowWarning("pc_bonus2 (Resist Effect): %d is not supported.\n", type2); + break; + } + if(sd->state.lr_flag == 2) + break; + i = sd->reseff[type2-SC_COMMON_MIN]+val; + sd->reseff[type2-SC_COMMON_MIN]= cap_value(i, 0, 10000); + break; + case SP_MAGIC_ADDELE: + if(type2 >= ELE_MAX) { + ShowError("pc_bonus2: SP_MAGIC_ADDELE: Invalid element %d\n", type2); + break; + } + if(sd->state.lr_flag != 2) + sd->magic_addele[type2]+=val; + break; + case SP_MAGIC_ADDRACE: + if(sd->state.lr_flag != 2) + sd->magic_addrace[type2]+=val; + break; + case SP_MAGIC_ADDSIZE: + if(sd->state.lr_flag != 2) + sd->magic_addsize[type2]+=val; + break; + case SP_MAGIC_ATK_ELE: + if(sd->state.lr_flag != 2) + sd->magic_atk_ele[type2]+=val; + break; + case SP_ADD_DAMAGE_CLASS: + switch (sd->state.lr_flag) { + case 0: //Right hand + ARR_FIND(0, ARRAYLENGTH(sd->right_weapon.add_dmg), i, sd->right_weapon.add_dmg[i].rate == 0 || sd->right_weapon.add_dmg[i].class_ == type2); + if (i == ARRAYLENGTH(sd->right_weapon.add_dmg)) + { + ShowWarning("pc_bonus2: Reached max (%d) number of add Class dmg bonuses per character!\n", ARRAYLENGTH(sd->right_weapon.add_dmg)); + break; + } + sd->right_weapon.add_dmg[i].class_ = type2; + sd->right_weapon.add_dmg[i].rate += val; + if (!sd->right_weapon.add_dmg[i].rate) //Shift the rest of elements up. + memmove(&sd->right_weapon.add_dmg[i], &sd->right_weapon.add_dmg[i+1], sizeof(sd->right_weapon.add_dmg) - (i+1)*sizeof(sd->right_weapon.add_dmg[0])); + break; + case 1: //Left hand + ARR_FIND(0, ARRAYLENGTH(sd->left_weapon.add_dmg), i, sd->left_weapon.add_dmg[i].rate == 0 || sd->left_weapon.add_dmg[i].class_ == type2); + if (i == ARRAYLENGTH(sd->left_weapon.add_dmg)) + { + ShowWarning("pc_bonus2: Reached max (%d) number of add Class dmg bonuses per character!\n", ARRAYLENGTH(sd->left_weapon.add_dmg)); + break; + } + sd->left_weapon.add_dmg[i].class_ = type2; + sd->left_weapon.add_dmg[i].rate += val; + if (!sd->left_weapon.add_dmg[i].rate) //Shift the rest of elements up. + memmove(&sd->left_weapon.add_dmg[i], &sd->left_weapon.add_dmg[i+1], sizeof(sd->left_weapon.add_dmg) - (i+1)*sizeof(sd->left_weapon.add_dmg[0])); break; } - sd->right_weapon.add_dmg[i].class_ = type2; - sd->right_weapon.add_dmg[i].rate += val; - if (!sd->right_weapon.add_dmg[i].rate) //Shift the rest of elements up. - memmove(&sd->right_weapon.add_dmg[i], &sd->right_weapon.add_dmg[i+1], sizeof(sd->right_weapon.add_dmg) - (i+1)*sizeof(sd->right_weapon.add_dmg[0])); break; - case 1: //Left hand - ARR_FIND(0, ARRAYLENGTH(sd->left_weapon.add_dmg), i, sd->left_weapon.add_dmg[i].rate == 0 || sd->left_weapon.add_dmg[i].class_ == type2); - if (i == ARRAYLENGTH(sd->left_weapon.add_dmg)) + case SP_ADD_MAGIC_DAMAGE_CLASS: + if(sd->state.lr_flag == 2) + break; + ARR_FIND(0, ARRAYLENGTH(sd->add_mdmg), i, sd->add_mdmg[i].rate == 0 || sd->add_mdmg[i].class_ == type2); + if (i == ARRAYLENGTH(sd->add_mdmg)) { - ShowWarning("pc_bonus2: Reached max (%d) number of add Class dmg bonuses per character!\n", ARRAYLENGTH(sd->left_weapon.add_dmg)); + ShowWarning("pc_bonus2: Reached max (%d) number of add Class magic dmg bonuses per character!\n", ARRAYLENGTH(sd->add_mdmg)); break; } - sd->left_weapon.add_dmg[i].class_ = type2; - sd->left_weapon.add_dmg[i].rate += val; - if (!sd->left_weapon.add_dmg[i].rate) //Shift the rest of elements up. - memmove(&sd->left_weapon.add_dmg[i], &sd->left_weapon.add_dmg[i+1], sizeof(sd->left_weapon.add_dmg) - (i+1)*sizeof(sd->left_weapon.add_dmg[0])); + sd->add_mdmg[i].class_ = type2; + sd->add_mdmg[i].rate += val; + if (!sd->add_mdmg[i].rate) //Shift the rest of elements up. + memmove(&sd->add_mdmg[i], &sd->add_mdmg[i+1], sizeof(sd->add_mdmg) - (i+1)*sizeof(sd->add_mdmg[0])); break; - } - break; - case SP_ADD_MAGIC_DAMAGE_CLASS: - if(sd->state.lr_flag == 2) + case SP_ADD_DEF_CLASS: + if(sd->state.lr_flag == 2) + break; + ARR_FIND(0, ARRAYLENGTH(sd->add_def), i, sd->add_def[i].rate == 0 || sd->add_def[i].class_ == type2); + if (i == ARRAYLENGTH(sd->add_def)) + { + ShowWarning("pc_bonus2: Reached max (%d) number of add Class def bonuses per character!\n", ARRAYLENGTH(sd->add_def)); + break; + } + sd->add_def[i].class_ = type2; + sd->add_def[i].rate += val; + if (!sd->add_def[i].rate) //Shift the rest of elements up. + memmove(&sd->add_def[i], &sd->add_def[i+1], sizeof(sd->add_def) - (i+1)*sizeof(sd->add_def[0])); break; - ARR_FIND(0, ARRAYLENGTH(sd->add_mdmg), i, sd->add_mdmg[i].rate == 0 || sd->add_mdmg[i].class_ == type2); - if (i == ARRAYLENGTH(sd->add_mdmg)) - { - ShowWarning("pc_bonus2: Reached max (%d) number of add Class magic dmg bonuses per character!\n", ARRAYLENGTH(sd->add_mdmg)); + case SP_ADD_MDEF_CLASS: + if(sd->state.lr_flag == 2) + break; + ARR_FIND(0, ARRAYLENGTH(sd->add_mdef), i, sd->add_mdef[i].rate == 0 || sd->add_mdef[i].class_ == type2); + if (i == ARRAYLENGTH(sd->add_mdef)) + { + ShowWarning("pc_bonus2: Reached max (%d) number of add Class mdef bonuses per character!\n", ARRAYLENGTH(sd->add_mdef)); + break; + } + sd->add_mdef[i].class_ = type2; + sd->add_mdef[i].rate += val; + if (!sd->add_mdef[i].rate) //Shift the rest of elements up. + memmove(&sd->add_mdef[i], &sd->add_mdef[i+1], sizeof(sd->add_mdef) - (i+1)*sizeof(sd->add_mdef[0])); break; - } - sd->add_mdmg[i].class_ = type2; - sd->add_mdmg[i].rate += val; - if (!sd->add_mdmg[i].rate) //Shift the rest of elements up. - memmove(&sd->add_mdmg[i], &sd->add_mdmg[i+1], sizeof(sd->add_mdmg) - (i+1)*sizeof(sd->add_mdmg[0])); - break; - case SP_ADD_DEF_CLASS: - if(sd->state.lr_flag == 2) + case SP_HP_DRAIN_RATE: + if(!sd->state.lr_flag) { + sd->right_weapon.hp_drain[RC_NONBOSS].rate += type2; + sd->right_weapon.hp_drain[RC_NONBOSS].per += val; + sd->right_weapon.hp_drain[RC_BOSS].rate += type2; + sd->right_weapon.hp_drain[RC_BOSS].per += val; + } + else if(sd->state.lr_flag == 1) { + sd->left_weapon.hp_drain[RC_NONBOSS].rate += type2; + sd->left_weapon.hp_drain[RC_NONBOSS].per += val; + sd->left_weapon.hp_drain[RC_BOSS].rate += type2; + sd->left_weapon.hp_drain[RC_BOSS].per += val; + } break; - ARR_FIND(0, ARRAYLENGTH(sd->add_def), i, sd->add_def[i].rate == 0 || sd->add_def[i].class_ == type2); - if (i == ARRAYLENGTH(sd->add_def)) - { - ShowWarning("pc_bonus2: Reached max (%d) number of add Class def bonuses per character!\n", ARRAYLENGTH(sd->add_def)); + case SP_HP_DRAIN_VALUE: + if(!sd->state.lr_flag) { + sd->right_weapon.hp_drain[RC_NONBOSS].value += type2; + sd->right_weapon.hp_drain[RC_NONBOSS].type = val; + sd->right_weapon.hp_drain[RC_BOSS].value += type2; + sd->right_weapon.hp_drain[RC_BOSS].type = val; + } + else if(sd->state.lr_flag == 1) { + sd->left_weapon.hp_drain[RC_NONBOSS].value += type2; + sd->left_weapon.hp_drain[RC_NONBOSS].type = val; + sd->left_weapon.hp_drain[RC_BOSS].value += type2; + sd->left_weapon.hp_drain[RC_BOSS].type = val; + } break; - } - sd->add_def[i].class_ = type2; - sd->add_def[i].rate += val; - if (!sd->add_def[i].rate) //Shift the rest of elements up. - memmove(&sd->add_def[i], &sd->add_def[i+1], sizeof(sd->add_def) - (i+1)*sizeof(sd->add_def[0])); - break; - case SP_ADD_MDEF_CLASS: - if(sd->state.lr_flag == 2) + case SP_SP_DRAIN_RATE: + if(!sd->state.lr_flag) { + sd->right_weapon.sp_drain[RC_NONBOSS].rate += type2; + sd->right_weapon.sp_drain[RC_NONBOSS].per += val; + sd->right_weapon.sp_drain[RC_BOSS].rate += type2; + sd->right_weapon.sp_drain[RC_BOSS].per += val; + } + else if(sd->state.lr_flag == 1) { + sd->left_weapon.sp_drain[RC_NONBOSS].rate += type2; + sd->left_weapon.sp_drain[RC_NONBOSS].per += val; + sd->left_weapon.sp_drain[RC_BOSS].rate += type2; + sd->left_weapon.sp_drain[RC_BOSS].per += val; + } break; - ARR_FIND(0, ARRAYLENGTH(sd->add_mdef), i, sd->add_mdef[i].rate == 0 || sd->add_mdef[i].class_ == type2); - if (i == ARRAYLENGTH(sd->add_mdef)) - { - ShowWarning("pc_bonus2: Reached max (%d) number of add Class mdef bonuses per character!\n", ARRAYLENGTH(sd->add_mdef)); + case SP_SP_DRAIN_VALUE: + if(!sd->state.lr_flag) { + sd->right_weapon.sp_drain[RC_NONBOSS].value += type2; + sd->right_weapon.sp_drain[RC_NONBOSS].type = val; + sd->right_weapon.sp_drain[RC_BOSS].value += type2; + sd->right_weapon.sp_drain[RC_BOSS].type = val; + } + else if(sd->state.lr_flag == 1) { + sd->left_weapon.sp_drain[RC_NONBOSS].value += type2; + sd->left_weapon.sp_drain[RC_NONBOSS].type = val; + sd->left_weapon.sp_drain[RC_BOSS].value += type2; + sd->left_weapon.sp_drain[RC_BOSS].type = val; + } break; - } - sd->add_mdef[i].class_ = type2; - sd->add_mdef[i].rate += val; - if (!sd->add_mdef[i].rate) //Shift the rest of elements up. - memmove(&sd->add_mdef[i], &sd->add_mdef[i+1], sizeof(sd->add_mdef) - (i+1)*sizeof(sd->add_mdef[0])); - break; - case SP_HP_DRAIN_RATE: - if(!sd->state.lr_flag) { - sd->right_weapon.hp_drain[RC_NONBOSS].rate += type2; - sd->right_weapon.hp_drain[RC_NONBOSS].per += val; - sd->right_weapon.hp_drain[RC_BOSS].rate += type2; - sd->right_weapon.hp_drain[RC_BOSS].per += val; - } - else if(sd->state.lr_flag == 1) { - sd->left_weapon.hp_drain[RC_NONBOSS].rate += type2; - sd->left_weapon.hp_drain[RC_NONBOSS].per += val; - sd->left_weapon.hp_drain[RC_BOSS].rate += type2; - sd->left_weapon.hp_drain[RC_BOSS].per += val; - } - break; - case SP_HP_DRAIN_VALUE: - if(!sd->state.lr_flag) { - sd->right_weapon.hp_drain[RC_NONBOSS].value += type2; - sd->right_weapon.hp_drain[RC_NONBOSS].type = val; - sd->right_weapon.hp_drain[RC_BOSS].value += type2; - sd->right_weapon.hp_drain[RC_BOSS].type = val; - } - else if(sd->state.lr_flag == 1) { - sd->left_weapon.hp_drain[RC_NONBOSS].value += type2; - sd->left_weapon.hp_drain[RC_NONBOSS].type = val; - sd->left_weapon.hp_drain[RC_BOSS].value += type2; - sd->left_weapon.hp_drain[RC_BOSS].type = val; - } - break; - case SP_SP_DRAIN_RATE: - if(!sd->state.lr_flag) { - sd->right_weapon.sp_drain[RC_NONBOSS].rate += type2; - sd->right_weapon.sp_drain[RC_NONBOSS].per += val; - sd->right_weapon.sp_drain[RC_BOSS].rate += type2; - sd->right_weapon.sp_drain[RC_BOSS].per += val; - } - else if(sd->state.lr_flag == 1) { - sd->left_weapon.sp_drain[RC_NONBOSS].rate += type2; - sd->left_weapon.sp_drain[RC_NONBOSS].per += val; - sd->left_weapon.sp_drain[RC_BOSS].rate += type2; - sd->left_weapon.sp_drain[RC_BOSS].per += val; - } - break; - case SP_SP_DRAIN_VALUE: - if(!sd->state.lr_flag) { - sd->right_weapon.sp_drain[RC_NONBOSS].value += type2; - sd->right_weapon.sp_drain[RC_NONBOSS].type = val; - sd->right_weapon.sp_drain[RC_BOSS].value += type2; - sd->right_weapon.sp_drain[RC_BOSS].type = val; - } - else if(sd->state.lr_flag == 1) { - sd->left_weapon.sp_drain[RC_NONBOSS].value += type2; - sd->left_weapon.sp_drain[RC_NONBOSS].type = val; - sd->left_weapon.sp_drain[RC_BOSS].value += type2; - sd->left_weapon.sp_drain[RC_BOSS].type = val; - } - break; - case SP_SP_VANISH_RATE: - if(sd->state.lr_flag != 2) { - sd->bonus.sp_vanish_rate += type2; - sd->bonus.sp_vanish_per += val; - } - break; - case SP_GET_ZENY_NUM: - if(sd->state.lr_flag != 2 && sd->bonus.get_zeny_rate < val) { - sd->bonus.get_zeny_rate = val; - sd->bonus.get_zeny_num = type2; - } - break; - case SP_ADD_GET_ZENY_NUM: - if(sd->state.lr_flag != 2) { - sd->bonus.get_zeny_rate += val; - sd->bonus.get_zeny_num += type2; - } - break; - case SP_WEAPON_COMA_ELE: - if(type2 >= ELE_MAX) { - ShowError("pc_bonus2: SP_WEAPON_COMA_ELE: Invalid element %d\n", type2); + case SP_SP_VANISH_RATE: + if(sd->state.lr_flag != 2) { + sd->bonus.sp_vanish_rate += type2; + sd->bonus.sp_vanish_per += val; + } break; - } - if(sd->state.lr_flag == 2) + case SP_GET_ZENY_NUM: + if(sd->state.lr_flag != 2 && sd->bonus.get_zeny_rate < val) { + sd->bonus.get_zeny_rate = val; + sd->bonus.get_zeny_num = type2; + } break; - sd->weapon_coma_ele[type2] += val; - sd->special_state.bonus_coma = 1; - break; - case SP_WEAPON_COMA_RACE: - if(sd->state.lr_flag == 2) + case SP_ADD_GET_ZENY_NUM: + if(sd->state.lr_flag != 2) { + sd->bonus.get_zeny_rate += val; + sd->bonus.get_zeny_num += type2; + } break; - sd->weapon_coma_race[type2] += val; - sd->special_state.bonus_coma = 1; - break; - case SP_WEAPON_ATK: - if(sd->state.lr_flag != 2) - sd->weapon_atk[type2]+=val; - break; - case SP_WEAPON_ATK_RATE: - if(sd->state.lr_flag != 2) - sd->weapon_atk_rate[type2]+=val; - break; - case SP_CRITICAL_ADDRACE: - if(sd->state.lr_flag != 2) - sd->critaddrace[type2] += val*10; - break; - case SP_ADDEFF_WHENHIT: - if (type2 > SC_MAX) { - ShowWarning("pc_bonus2 (Add Effect when hit): %d is not supported.\n", type2); + case SP_WEAPON_COMA_ELE: + if(type2 >= ELE_MAX) { + ShowError("pc_bonus2: SP_WEAPON_COMA_ELE: Invalid element %d\n", type2); + break; + } + if(sd->state.lr_flag == 2) + break; + sd->weapon_coma_ele[type2] += val; + sd->special_state.bonus_coma = 1; break; - } - if(sd->state.lr_flag != 2) - pc_bonus_addeff(sd->addeff2, ARRAYLENGTH(sd->addeff2), (sc_type)type2, val, 0, 0); - break; - case SP_SKILL_ATK: - if(sd->state.lr_flag == 2) + case SP_WEAPON_COMA_RACE: + if(sd->state.lr_flag == 2) + break; + sd->weapon_coma_race[type2] += val; + sd->special_state.bonus_coma = 1; break; - ARR_FIND(0, ARRAYLENGTH(sd->skillatk), i, sd->skillatk[i].id == 0 || sd->skillatk[i].id == type2); - if (i == ARRAYLENGTH(sd->skillatk)) - { //Better mention this so the array length can be updated. [Skotlex] - ShowDebug("run_script: bonus2 bSkillAtk reached it's limit (%d skills per character), bonus skill %d (+%d%%) lost.\n", ARRAYLENGTH(sd->skillatk), type2, val); + case SP_WEAPON_ATK: + if(sd->state.lr_flag != 2) + sd->weapon_atk[type2]+=val; break; - } - if (sd->skillatk[i].id == type2) - sd->skillatk[i].val += val; - else { - sd->skillatk[i].id = type2; - sd->skillatk[i].val = val; - } - break; - case SP_SKILL_HEAL: - if(sd->state.lr_flag == 2) + case SP_WEAPON_ATK_RATE: + if(sd->state.lr_flag != 2) + sd->weapon_atk_rate[type2]+=val; break; - ARR_FIND(0, ARRAYLENGTH(sd->skillheal), i, sd->skillheal[i].id == 0 || sd->skillheal[i].id == type2); - if (i == ARRAYLENGTH(sd->skillheal)) - { // Better mention this so the array length can be updated. [Skotlex] - ShowDebug("run_script: bonus2 bSkillHeal reached it's limit (%d skills per character), bonus skill %d (+%d%%) lost.\n", ARRAYLENGTH(sd->skillheal), type2, val); + case SP_CRITICAL_ADDRACE: + if(sd->state.lr_flag != 2) + sd->critaddrace[type2] += val*10; break; - } - if (sd->skillheal[i].id == type2) - sd->skillheal[i].val += val; - else { - sd->skillheal[i].id = type2; - sd->skillheal[i].val = val; - } - break; - case SP_SKILL_HEAL2: - if(sd->state.lr_flag == 2) + case SP_ADDEFF_WHENHIT: + if (type2 > SC_MAX) { + ShowWarning("pc_bonus2 (Add Effect when hit): %d is not supported.\n", type2); + break; + } + if(sd->state.lr_flag != 2) + pc_bonus_addeff(sd->addeff2, ARRAYLENGTH(sd->addeff2), (sc_type)type2, val, 0, 0); break; - ARR_FIND(0, ARRAYLENGTH(sd->skillheal2), i, sd->skillheal2[i].id == 0 || sd->skillheal2[i].id == type2); - if (i == ARRAYLENGTH(sd->skillheal2)) - { // Better mention this so the array length can be updated. [Skotlex] - ShowDebug("run_script: bonus2 bSkillHeal2 reached it's limit (%d skills per character), bonus skill %d (+%d%%) lost.\n", ARRAYLENGTH(sd->skillheal2), type2, val); + case SP_SKILL_ATK: + if(sd->state.lr_flag == 2) + break; + ARR_FIND(0, ARRAYLENGTH(sd->skillatk), i, sd->skillatk[i].id == 0 || sd->skillatk[i].id == type2); + if (i == ARRAYLENGTH(sd->skillatk)) + { //Better mention this so the array length can be updated. [Skotlex] + ShowDebug("run_script: bonus2 bSkillAtk reached it's limit (%d skills per character), bonus skill %d (+%d%%) lost.\n", ARRAYLENGTH(sd->skillatk), type2, val); + break; + } + if (sd->skillatk[i].id == type2) + sd->skillatk[i].val += val; + else { + sd->skillatk[i].id = type2; + sd->skillatk[i].val = val; + } break; - } - if (sd->skillheal2[i].id == type2) - sd->skillheal2[i].val += val; - else { - sd->skillheal2[i].id = type2; - sd->skillheal2[i].val = val; - } - break; - case SP_ADD_SKILL_BLOW: - if(sd->state.lr_flag == 2) + case SP_SKILL_HEAL: + if(sd->state.lr_flag == 2) + break; + ARR_FIND(0, ARRAYLENGTH(sd->skillheal), i, sd->skillheal[i].id == 0 || sd->skillheal[i].id == type2); + if (i == ARRAYLENGTH(sd->skillheal)) + { // Better mention this so the array length can be updated. [Skotlex] + ShowDebug("run_script: bonus2 bSkillHeal reached it's limit (%d skills per character), bonus skill %d (+%d%%) lost.\n", ARRAYLENGTH(sd->skillheal), type2, val); + break; + } + if (sd->skillheal[i].id == type2) + sd->skillheal[i].val += val; + else { + sd->skillheal[i].id = type2; + sd->skillheal[i].val = val; + } break; - ARR_FIND(0, ARRAYLENGTH(sd->skillblown), i, sd->skillblown[i].id == 0 || sd->skillblown[i].id == type2); - if (i == ARRAYLENGTH(sd->skillblown)) - { //Better mention this so the array length can be updated. [Skotlex] - ShowDebug("run_script: bonus2 bSkillBlown reached it's limit (%d skills per character), bonus skill %d (+%d%%) lost.\n", ARRAYLENGTH(sd->skillblown), type2, val); + case SP_SKILL_HEAL2: + if(sd->state.lr_flag == 2) + break; + ARR_FIND(0, ARRAYLENGTH(sd->skillheal2), i, sd->skillheal2[i].id == 0 || sd->skillheal2[i].id == type2); + if (i == ARRAYLENGTH(sd->skillheal2)) + { // Better mention this so the array length can be updated. [Skotlex] + ShowDebug("run_script: bonus2 bSkillHeal2 reached it's limit (%d skills per character), bonus skill %d (+%d%%) lost.\n", ARRAYLENGTH(sd->skillheal2), type2, val); + break; + } + if (sd->skillheal2[i].id == type2) + sd->skillheal2[i].val += val; + else { + sd->skillheal2[i].id = type2; + sd->skillheal2[i].val = val; + } break; - } - if(sd->skillblown[i].id == type2) - sd->skillblown[i].val += val; - else { - sd->skillblown[i].id = type2; - sd->skillblown[i].val = val; - } - break; -#ifndef RENEWAL_CAST - case SP_VARCASTRATE: -#endif - case SP_CASTRATE: - if(sd->state.lr_flag == 2) + case SP_ADD_SKILL_BLOW: + if(sd->state.lr_flag == 2) + break; + ARR_FIND(0, ARRAYLENGTH(sd->skillblown), i, sd->skillblown[i].id == 0 || sd->skillblown[i].id == type2); + if (i == ARRAYLENGTH(sd->skillblown)) + { //Better mention this so the array length can be updated. [Skotlex] + ShowDebug("run_script: bonus2 bSkillBlown reached it's limit (%d skills per character), bonus skill %d (+%d%%) lost.\n", ARRAYLENGTH(sd->skillblown), type2, val); + break; + } + if(sd->skillblown[i].id == type2) + sd->skillblown[i].val += val; + else { + sd->skillblown[i].id = type2; + sd->skillblown[i].val = val; + } break; - ARR_FIND(0, ARRAYLENGTH(sd->skillcast), i, sd->skillcast[i].id == 0 || sd->skillcast[i].id == type2); - if (i == ARRAYLENGTH(sd->skillcast)) - { //Better mention this so the array length can be updated. [Skotlex] - ShowDebug("run_script: bonus2 %s reached it's limit (%d skills per character), bonus skill %d (+%d%%) lost.\n", + #ifndef RENEWAL_CAST + case SP_VARCASTRATE: + #endif + case SP_CASTRATE: + if(sd->state.lr_flag == 2) + break; + ARR_FIND(0, ARRAYLENGTH(sd->skillcast), i, sd->skillcast[i].id == 0 || sd->skillcast[i].id == type2); + if (i == ARRAYLENGTH(sd->skillcast)) + { //Better mention this so the array length can be updated. [Skotlex] + ShowDebug("run_script: bonus2 %s reached it's limit (%d skills per character), bonus skill %d (+%d%%) lost.\n", -#ifndef RENEWAL_CAST - "bCastRate", -#else - "bVariableCastrate", -#endif + #ifndef RENEWAL_CAST + "bCastRate", + #else + "bVariableCastrate", + #endif - ARRAYLENGTH(sd->skillcast), type2, val); + ARRAYLENGTH(sd->skillcast), type2, val); + break; + } + if(sd->skillcast[i].id == type2) + sd->skillcast[i].val += val; + else { + sd->skillcast[i].id = type2; + sd->skillcast[i].val = val; + } break; - } - if(sd->skillcast[i].id == type2) - sd->skillcast[i].val += val; - else { - sd->skillcast[i].id = type2; - sd->skillcast[i].val = val; - } - break; - case SP_FIXCASTRATE: - if(sd->state.lr_flag == 2) - break; + case SP_FIXCASTRATE: + if(sd->state.lr_flag == 2) + break; - ARR_FIND(0, ARRAYLENGTH(sd->skillfixcastrate), i, sd->skillfixcastrate[i].id == 0 || sd->skillfixcastrate[i].id == type2); + ARR_FIND(0, ARRAYLENGTH(sd->skillfixcastrate), i, sd->skillfixcastrate[i].id == 0 || sd->skillfixcastrate[i].id == type2); - if (i == ARRAYLENGTH(sd->skillfixcastrate)) + if (i == ARRAYLENGTH(sd->skillfixcastrate)) - { + { - ShowDebug("run_script: bonus2 bFixedCastrate reached it's limit (%d skills per character), bonus skill %d (+%d%%) lost.\n", ARRAYLENGTH(sd->skillfixcastrate), type2, val); - break; - } + ShowDebug("run_script: bonus2 bFixedCastrate reached it's limit (%d skills per character), bonus skill %d (+%d%%) lost.\n", ARRAYLENGTH(sd->skillfixcastrate), type2, val); + break; + } - if(sd->skillfixcastrate[i].id == type2) - sd->skillfixcastrate[i].val += val; + if(sd->skillfixcastrate[i].id == type2) + sd->skillfixcastrate[i].val += val; - else { - sd->skillfixcastrate[i].id = type2; - sd->skillfixcastrate[i].val = val; - } + else { + sd->skillfixcastrate[i].id = type2; + sd->skillfixcastrate[i].val = val; + } - break; + break; - case SP_HP_LOSS_RATE: - if(sd->state.lr_flag != 2) { - sd->hp_loss.value = type2; - sd->hp_loss.rate = val; - } - break; - case SP_HP_REGEN_RATE: - if(sd->state.lr_flag != 2) { - sd->hp_regen.value = type2; - sd->hp_regen.rate = val; - } - break; - case SP_ADDRACE2: - if (!(type2 > RC2_NONE && type2 < RC2_MAX)) + case SP_HP_LOSS_RATE: + if(sd->state.lr_flag != 2) { + sd->hp_loss.value = type2; + sd->hp_loss.rate = val; + } break; - if(sd->state.lr_flag != 2) - sd->right_weapon.addrace2[type2] += val; - else - sd->left_weapon.addrace2[type2] += val; - break; - case SP_SUBSIZE: - if(sd->state.lr_flag != 2) - sd->subsize[type2]+=val; - break; - case SP_SUBRACE2: - if (!(type2 > RC2_NONE && type2 < RC2_MAX)) + case SP_HP_REGEN_RATE: + if(sd->state.lr_flag != 2) { + sd->hp_regen.value = type2; + sd->hp_regen.rate = val; + } break; - if(sd->state.lr_flag != 2) - sd->subrace2[type2]+=val; - break; - case SP_ADD_ITEM_HEAL_RATE: - if(sd->state.lr_flag == 2) + case SP_ADDRACE2: + if (!(type2 > RC2_NONE && type2 < RC2_MAX)) + break; + if(sd->state.lr_flag != 2) + sd->right_weapon.addrace2[type2] += val; + else + sd->left_weapon.addrace2[type2] += val; break; - if (type2 < MAX_ITEMGROUP) { //Group bonus - sd->itemgrouphealrate[type2] += val; + case SP_SUBSIZE: + if(sd->state.lr_flag != 2) + sd->subsize[type2]+=val; break; - } - //Standard item bonus. - for(i=0; i < ARRAYLENGTH(sd->itemhealrate) && sd->itemhealrate[i].nameid && sd->itemhealrate[i].nameid != type2; i++); - if(i == ARRAYLENGTH(sd->itemhealrate)) { - ShowWarning("pc_bonus2: Reached max (%d) number of item heal bonuses per character!\n", ARRAYLENGTH(sd->itemhealrate)); + case SP_SUBRACE2: + if (!(type2 > RC2_NONE && type2 < RC2_MAX)) + break; + if(sd->state.lr_flag != 2) + sd->subrace2[type2]+=val; break; - } - sd->itemhealrate[i].nameid = type2; - sd->itemhealrate[i].rate += val; - break; - case SP_EXP_ADDRACE: - if(sd->state.lr_flag != 2) - sd->expaddrace[type2]+=val; - break; - case SP_SP_GAIN_RACE: - if(sd->state.lr_flag != 2) - sd->sp_gain_race[type2]+=val; - break; - case SP_ADD_MONSTER_DROP_ITEM: - if (sd->state.lr_flag != 2) - pc_bonus_item_drop(sd->add_drop, ARRAYLENGTH(sd->add_drop), type2, 0, (1<<RC_BOSS)|(1<<RC_NONBOSS), val); - break; - case SP_ADD_MONSTER_DROP_ITEMGROUP: - if (sd->state.lr_flag != 2) - pc_bonus_item_drop(sd->add_drop, ARRAYLENGTH(sd->add_drop), 0, type2, (1<<RC_BOSS)|(1<<RC_NONBOSS), val); - break; - case SP_SP_LOSS_RATE: - if(sd->state.lr_flag != 2) { - sd->sp_loss.value = type2; - sd->sp_loss.rate = val; - } - break; - case SP_SP_REGEN_RATE: - if(sd->state.lr_flag != 2) { - sd->sp_regen.value = type2; - sd->sp_regen.rate = val; - } - break; - case SP_HP_DRAIN_VALUE_RACE: - if(!sd->state.lr_flag) { - sd->right_weapon.hp_drain[type2].value += val; - } - else if(sd->state.lr_flag == 1) { - sd->left_weapon.hp_drain[type2].value += val; - } - break; - case SP_SP_DRAIN_VALUE_RACE: - if(!sd->state.lr_flag) { - sd->right_weapon.sp_drain[type2].value += val; - } - else if(sd->state.lr_flag == 1) { - sd->left_weapon.sp_drain[type2].value += val; - } - break; - case SP_IGNORE_MDEF_RATE: - if(sd->state.lr_flag != 2) - sd->ignore_mdef[type2] += val; - break; - case SP_IGNORE_DEF_RATE: - if(sd->state.lr_flag != 2) - sd->ignore_def[type2] += val; - break; - case SP_SP_GAIN_RACE_ATTACK: - if(sd->state.lr_flag != 2) - sd->sp_gain_race_attack[type2] = cap_value(sd->sp_gain_race_attack[type2] + val, 0, INT16_MAX); - break; - case SP_HP_GAIN_RACE_ATTACK: - if(sd->state.lr_flag != 2) - sd->hp_gain_race_attack[type2] = cap_value(sd->hp_gain_race_attack[type2] + val, 0, INT16_MAX); - break; - case SP_SKILL_USE_SP_RATE: //bonus2 bSkillUseSPrate,n,x; - if(sd->state.lr_flag == 2) + case SP_ADD_ITEM_HEAL_RATE: + if(sd->state.lr_flag == 2) + break; + //Standard item bonus. + for(i=0; i < ARRAYLENGTH(sd->itemhealrate) && sd->itemhealrate[i].nameid && sd->itemhealrate[i].nameid != type2; i++); + if(i == ARRAYLENGTH(sd->itemhealrate)) { + ShowWarning("pc_bonus2: Reached max (%d) number of item heal bonuses per character!\n", ARRAYLENGTH(sd->itemhealrate)); + break; + } + sd->itemhealrate[i].nameid = type2; + sd->itemhealrate[i].rate += val; break; - ARR_FIND(0, ARRAYLENGTH(sd->skillusesprate), i, sd->skillusesprate[i].id == 0 || sd->skillusesprate[i].id == type2); - if (i == ARRAYLENGTH(sd->skillusesprate)) { - ShowDebug("run_script: bonus2 bSkillUseSPrate reached it's limit (%d skills per character), bonus skill %d (+%d%%) lost.\n", ARRAYLENGTH(sd->skillusesprate), type2, val); + case SP_EXP_ADDRACE: + if(sd->state.lr_flag != 2) + sd->expaddrace[type2]+=val; break; - } - if (sd->skillusesprate[i].id == type2) - sd->skillusesprate[i].val += val; - else { - sd->skillusesprate[i].id = type2; - sd->skillusesprate[i].val = val; - } - break; - case SP_SKILL_COOLDOWN: - if(sd->state.lr_flag == 2) + case SP_SP_GAIN_RACE: + if(sd->state.lr_flag != 2) + sd->sp_gain_race[type2]+=val; break; - ARR_FIND(0, ARRAYLENGTH(sd->skillcooldown), i, sd->skillcooldown[i].id == 0 || sd->skillcooldown[i].id == type2); - if (i == ARRAYLENGTH(sd->skillcooldown)) - { - ShowDebug("run_script: bonus2 bSkillCoolDown reached it's limit (%d skills per character), bonus skill %d (+%d%%) lost.\n", ARRAYLENGTH(sd->skillcooldown), type2, val); + case SP_ADD_MONSTER_DROP_ITEM: + if (sd->state.lr_flag != 2) + pc_bonus_item_drop(sd->add_drop, ARRAYLENGTH(sd->add_drop), type2, 0, (1<<RC_BOSS)|(1<<RC_NONBOSS), val); break; - } - if (sd->skillcooldown[i].id == type2) - sd->skillcooldown[i].val += val; - else { - sd->skillcooldown[i].id = type2; - sd->skillcooldown[i].val = val; - } - break; - case SP_SKILL_FIXEDCAST: - if(sd->state.lr_flag == 2) + case SP_SP_LOSS_RATE: + if(sd->state.lr_flag != 2) { + sd->sp_loss.value = type2; + sd->sp_loss.rate = val; + } break; - ARR_FIND(0, ARRAYLENGTH(sd->skillfixcast), i, sd->skillfixcast[i].id == 0 || sd->skillfixcast[i].id == type2); - if (i == ARRAYLENGTH(sd->skillfixcast)) - { - ShowDebug("run_script: bonus2 bSkillFixedCast reached it's limit (%d skills per character), bonus skill %d (+%d%%) lost.\n", ARRAYLENGTH(sd->skillfixcast), type2, val); + case SP_SP_REGEN_RATE: + if(sd->state.lr_flag != 2) { + sd->sp_regen.value = type2; + sd->sp_regen.rate = val; + } break; - } - if (sd->skillfixcast[i].id == type2) - sd->skillfixcast[i].val += val; - else { - sd->skillfixcast[i].id = type2; - sd->skillfixcast[i].val = val; - } - break; - case SP_SKILL_VARIABLECAST: - if(sd->state.lr_flag == 2) + case SP_HP_DRAIN_VALUE_RACE: + if(!sd->state.lr_flag) { + sd->right_weapon.hp_drain[type2].value += val; + } + else if(sd->state.lr_flag == 1) { + sd->left_weapon.hp_drain[type2].value += val; + } break; - ARR_FIND(0, ARRAYLENGTH(sd->skillvarcast), i, sd->skillvarcast[i].id == 0 || sd->skillvarcast[i].id == type2); - if (i == ARRAYLENGTH(sd->skillvarcast)) - { - ShowDebug("run_script: bonus2 bSkillVariableCast reached it's limit (%d skills per character), bonus skill %d (+%d%%) lost.\n", ARRAYLENGTH(sd->skillvarcast), type2, val); + case SP_SP_DRAIN_VALUE_RACE: + if(!sd->state.lr_flag) { + sd->right_weapon.sp_drain[type2].value += val; + } + else if(sd->state.lr_flag == 1) { + sd->left_weapon.sp_drain[type2].value += val; + } break; - } - if (sd->skillvarcast[i].id == type2) - sd->skillvarcast[i].val += val; - else { - sd->skillvarcast[i].id = type2; - sd->skillvarcast[i].val = val; - } - break; -#ifdef RENEWAL_CAST - case SP_VARCASTRATE: - if(sd->state.lr_flag == 2) + case SP_IGNORE_MDEF_RATE: + if(sd->state.lr_flag != 2) + sd->ignore_mdef[type2] += val; break; - ARR_FIND(0, ARRAYLENGTH(sd->skillcast), i, sd->skillcast[i].id == 0 || sd->skillcast[i].id == type2); - if (i == ARRAYLENGTH(sd->skillcast)) - { - ShowDebug("run_script: bonus2 bVariableCastrate reached it's limit (%d skills per character), bonus skill %d (+%d%%) lost.\n",ARRAYLENGTH(sd->skillcast), type2, val); + case SP_IGNORE_DEF_RATE: + if(sd->state.lr_flag != 2) + sd->ignore_def[type2] += val; break; - } - if(sd->skillcast[i].id == type2) - sd->skillcast[i].val -= val; - else { - sd->skillcast[i].id = type2; - sd->skillcast[i].val -= val; - } - break; -#endif - case SP_SKILL_USE_SP: //bonus2 bSkillUseSP,n,x; - if(sd->state.lr_flag == 2) + case SP_SP_GAIN_RACE_ATTACK: + if(sd->state.lr_flag != 2) + sd->sp_gain_race_attack[type2] = cap_value(sd->sp_gain_race_attack[type2] + val, 0, INT16_MAX); break; - ARR_FIND(0, ARRAYLENGTH(sd->skillusesp), i, sd->skillusesp[i].id == 0 || sd->skillusesp[i].id == type2); - if (i == ARRAYLENGTH(sd->skillusesp)) { - ShowDebug("run_script: bonus2 bSkillUseSP reached it's limit (%d skills per character), bonus skill %d (+%d%%) lost.\n", ARRAYLENGTH(sd->skillusesp), type2, val); + case SP_HP_GAIN_RACE_ATTACK: + if(sd->state.lr_flag != 2) + sd->hp_gain_race_attack[type2] = cap_value(sd->hp_gain_race_attack[type2] + val, 0, INT16_MAX); + break; + case SP_SKILL_USE_SP_RATE: //bonus2 bSkillUseSPrate,n,x; + if(sd->state.lr_flag == 2) + break; + ARR_FIND(0, ARRAYLENGTH(sd->skillusesprate), i, sd->skillusesprate[i].id == 0 || sd->skillusesprate[i].id == type2); + if (i == ARRAYLENGTH(sd->skillusesprate)) { + ShowDebug("run_script: bonus2 bSkillUseSPrate reached it's limit (%d skills per character), bonus skill %d (+%d%%) lost.\n", ARRAYLENGTH(sd->skillusesprate), type2, val); + break; + } + if (sd->skillusesprate[i].id == type2) + sd->skillusesprate[i].val += val; + else { + sd->skillusesprate[i].id = type2; + sd->skillusesprate[i].val = val; + } + break; + case SP_SKILL_COOLDOWN: + if(sd->state.lr_flag == 2) + break; + ARR_FIND(0, ARRAYLENGTH(sd->skillcooldown), i, sd->skillcooldown[i].id == 0 || sd->skillcooldown[i].id == type2); + if (i == ARRAYLENGTH(sd->skillcooldown)) + { + ShowDebug("run_script: bonus2 bSkillCoolDown reached it's limit (%d skills per character), bonus skill %d (+%d%%) lost.\n", ARRAYLENGTH(sd->skillcooldown), type2, val); + break; + } + if (sd->skillcooldown[i].id == type2) + sd->skillcooldown[i].val += val; + else { + sd->skillcooldown[i].id = type2; + sd->skillcooldown[i].val = val; + } + break; + case SP_SKILL_FIXEDCAST: + if(sd->state.lr_flag == 2) + break; + ARR_FIND(0, ARRAYLENGTH(sd->skillfixcast), i, sd->skillfixcast[i].id == 0 || sd->skillfixcast[i].id == type2); + if (i == ARRAYLENGTH(sd->skillfixcast)) + { + ShowDebug("run_script: bonus2 bSkillFixedCast reached it's limit (%d skills per character), bonus skill %d (+%d%%) lost.\n", ARRAYLENGTH(sd->skillfixcast), type2, val); + break; + } + if (sd->skillfixcast[i].id == type2) + sd->skillfixcast[i].val += val; + else { + sd->skillfixcast[i].id = type2; + sd->skillfixcast[i].val = val; + } + break; + case SP_SKILL_VARIABLECAST: + if(sd->state.lr_flag == 2) + break; + ARR_FIND(0, ARRAYLENGTH(sd->skillvarcast), i, sd->skillvarcast[i].id == 0 || sd->skillvarcast[i].id == type2); + if (i == ARRAYLENGTH(sd->skillvarcast)) + { + ShowDebug("run_script: bonus2 bSkillVariableCast reached it's limit (%d skills per character), bonus skill %d (+%d%%) lost.\n", ARRAYLENGTH(sd->skillvarcast), type2, val); + break; + } + if (sd->skillvarcast[i].id == type2) + sd->skillvarcast[i].val += val; + else { + sd->skillvarcast[i].id = type2; + sd->skillvarcast[i].val = val; + } + break; + #ifdef RENEWAL_CAST + case SP_VARCASTRATE: + if(sd->state.lr_flag == 2) + break; + ARR_FIND(0, ARRAYLENGTH(sd->skillcast), i, sd->skillcast[i].id == 0 || sd->skillcast[i].id == type2); + if (i == ARRAYLENGTH(sd->skillcast)) + { + ShowDebug("run_script: bonus2 bVariableCastrate reached it's limit (%d skills per character), bonus skill %d (+%d%%) lost.\n",ARRAYLENGTH(sd->skillcast), type2, val); + break; + } + if(sd->skillcast[i].id == type2) + sd->skillcast[i].val -= val; + else { + sd->skillcast[i].id = type2; + sd->skillcast[i].val -= val; + } + break; + #endif + case SP_SKILL_USE_SP: //bonus2 bSkillUseSP,n,x; + if(sd->state.lr_flag == 2) + break; + ARR_FIND(0, ARRAYLENGTH(sd->skillusesp), i, sd->skillusesp[i].id == 0 || sd->skillusesp[i].id == type2); + if (i == ARRAYLENGTH(sd->skillusesp)) { + ShowDebug("run_script: bonus2 bSkillUseSP reached it's limit (%d skills per character), bonus skill %d (+%d%%) lost.\n", ARRAYLENGTH(sd->skillusesp), type2, val); + break; + } + if (sd->skillusesp[i].id == type2) + sd->skillusesp[i].val += val; + else { + sd->skillusesp[i].id = type2; + sd->skillusesp[i].val = val; + } + break; + case SP_ADD_MONSTER_DROP_CHAINITEM: + if (sd->state.lr_flag != 2) + pc_bonus_item_drop(sd->add_drop, ARRAYLENGTH(sd->add_drop), 0, val, 1<<type2, 10000); + break; + default: + ShowWarning("pc_bonus2: unknown type %d %d %d!\n",type,type2,val); break; - } - if (sd->skillusesp[i].id == type2) - sd->skillusesp[i].val += val; - else { - sd->skillusesp[i].id = type2; - sd->skillusesp[i].val = val; - } - break; - default: - ShowWarning("pc_bonus2: unknown type %d %d %d!\n",type,type2,val); - break; } return 0; } @@ -3251,124 +3253,119 @@ int pc_bonus3(struct map_session_data *sd,int type,int type2,int type3,int val) nullpo_ret(sd); switch(type){ - case SP_ADD_MONSTER_DROP_ITEM: - if(sd->state.lr_flag != 2) - pc_bonus_item_drop(sd->add_drop, ARRAYLENGTH(sd->add_drop), type2, 0, 1<<type3, val); - break; - case SP_ADD_CLASS_DROP_ITEM: - if(sd->state.lr_flag != 2) - pc_bonus_item_drop(sd->add_drop, ARRAYLENGTH(sd->add_drop), type2, 0, -type3, val); - break; - case SP_AUTOSPELL: - if(sd->state.lr_flag != 2) - { - int target = skill->get_inf(type2); //Support or Self (non-auto-target) skills should pick self. - target = target&INF_SUPPORT_SKILL || (target&INF_SELF_SKILL && !(skill->get_inf2(type2)&INF2_NO_TARGET_SELF)); - pc_bonus_autospell(sd->autospell, ARRAYLENGTH(sd->autospell), - target?-type2:type2, type3, val, 0, current_equip_card_id); - } - break; - case SP_AUTOSPELL_WHENHIT: - if(sd->state.lr_flag != 2) - { - int target = skill->get_inf(type2); //Support or Self (non-auto-target) skills should pick self. - target = target&INF_SUPPORT_SKILL || (target&INF_SELF_SKILL && !(skill->get_inf2(type2)&INF2_NO_TARGET_SELF)); - pc_bonus_autospell(sd->autospell2, ARRAYLENGTH(sd->autospell2), - target?-type2:type2, type3, val, BF_NORMAL|BF_SKILL, current_equip_card_id); - } - break; - case SP_SP_DRAIN_RATE: - if(!sd->state.lr_flag) { - sd->right_weapon.sp_drain[RC_NONBOSS].rate += type2; - sd->right_weapon.sp_drain[RC_NONBOSS].per += type3; - sd->right_weapon.sp_drain[RC_NONBOSS].type = val; - sd->right_weapon.sp_drain[RC_BOSS].rate += type2; - sd->right_weapon.sp_drain[RC_BOSS].per += type3; - sd->right_weapon.sp_drain[RC_BOSS].type = val; - - } - else if(sd->state.lr_flag == 1) { - sd->left_weapon.sp_drain[RC_NONBOSS].rate += type2; - sd->left_weapon.sp_drain[RC_NONBOSS].per += type3; - sd->left_weapon.sp_drain[RC_NONBOSS].type = val; - sd->left_weapon.sp_drain[RC_BOSS].rate += type2; - sd->left_weapon.sp_drain[RC_BOSS].per += type3; - sd->left_weapon.sp_drain[RC_BOSS].type = val; - } - break; - case SP_HP_DRAIN_RATE_RACE: - if(!sd->state.lr_flag) { - sd->right_weapon.hp_drain[type2].rate += type3; - sd->right_weapon.hp_drain[type2].per += val; - } - else if(sd->state.lr_flag == 1) { - sd->left_weapon.hp_drain[type2].rate += type3; - sd->left_weapon.hp_drain[type2].per += val; - } - break; - case SP_SP_DRAIN_RATE_RACE: - if(!sd->state.lr_flag) { - sd->right_weapon.sp_drain[type2].rate += type3; - sd->right_weapon.sp_drain[type2].per += val; - } - else if(sd->state.lr_flag == 1) { - sd->left_weapon.sp_drain[type2].rate += type3; - sd->left_weapon.sp_drain[type2].per += val; - } - break; - case SP_ADD_MONSTER_DROP_ITEMGROUP: - if (sd->state.lr_flag != 2) - pc_bonus_item_drop(sd->add_drop, ARRAYLENGTH(sd->add_drop), 0, type2, 1<<type3, val); - break; + case SP_ADD_MONSTER_DROP_ITEM: + if(sd->state.lr_flag != 2) + pc_bonus_item_drop(sd->add_drop, ARRAYLENGTH(sd->add_drop), type2, 0, 1<<type3, val); + break; + case SP_ADD_CLASS_DROP_ITEM: + if(sd->state.lr_flag != 2) + pc_bonus_item_drop(sd->add_drop, ARRAYLENGTH(sd->add_drop), type2, 0, -type3, val); + break; + case SP_AUTOSPELL: + if(sd->state.lr_flag != 2) + { + int target = skill->get_inf(type2); //Support or Self (non-auto-target) skills should pick self. + target = target&INF_SUPPORT_SKILL || (target&INF_SELF_SKILL && !(skill->get_inf2(type2)&INF2_NO_TARGET_SELF)); + pc_bonus_autospell(sd->autospell, ARRAYLENGTH(sd->autospell), + target?-type2:type2, type3, val, 0, current_equip_card_id); + } + break; + case SP_AUTOSPELL_WHENHIT: + if(sd->state.lr_flag != 2) + { + int target = skill->get_inf(type2); //Support or Self (non-auto-target) skills should pick self. + target = target&INF_SUPPORT_SKILL || (target&INF_SELF_SKILL && !(skill->get_inf2(type2)&INF2_NO_TARGET_SELF)); + pc_bonus_autospell(sd->autospell2, ARRAYLENGTH(sd->autospell2), + target?-type2:type2, type3, val, BF_NORMAL|BF_SKILL, current_equip_card_id); + } + break; + case SP_SP_DRAIN_RATE: + if(!sd->state.lr_flag) { + sd->right_weapon.sp_drain[RC_NONBOSS].rate += type2; + sd->right_weapon.sp_drain[RC_NONBOSS].per += type3; + sd->right_weapon.sp_drain[RC_NONBOSS].type = val; + sd->right_weapon.sp_drain[RC_BOSS].rate += type2; + sd->right_weapon.sp_drain[RC_BOSS].per += type3; + sd->right_weapon.sp_drain[RC_BOSS].type = val; - case SP_ADDEFF: - if (type2 > SC_MAX) { - ShowWarning("pc_bonus3 (Add Effect): %d is not supported.\n", type2); + } + else if(sd->state.lr_flag == 1) { + sd->left_weapon.sp_drain[RC_NONBOSS].rate += type2; + sd->left_weapon.sp_drain[RC_NONBOSS].per += type3; + sd->left_weapon.sp_drain[RC_NONBOSS].type = val; + sd->left_weapon.sp_drain[RC_BOSS].rate += type2; + sd->left_weapon.sp_drain[RC_BOSS].per += type3; + sd->left_weapon.sp_drain[RC_BOSS].type = val; + } + break; + case SP_HP_DRAIN_RATE_RACE: + if(!sd->state.lr_flag) { + sd->right_weapon.hp_drain[type2].rate += type3; + sd->right_weapon.hp_drain[type2].per += val; + } + else if(sd->state.lr_flag == 1) { + sd->left_weapon.hp_drain[type2].rate += type3; + sd->left_weapon.hp_drain[type2].per += val; + } + break; + case SP_SP_DRAIN_RATE_RACE: + if(!sd->state.lr_flag) { + sd->right_weapon.sp_drain[type2].rate += type3; + sd->right_weapon.sp_drain[type2].per += val; + } + else if(sd->state.lr_flag == 1) { + sd->left_weapon.sp_drain[type2].rate += type3; + sd->left_weapon.sp_drain[type2].per += val; + } + break; + case SP_ADDEFF: + if (type2 > SC_MAX) { + ShowWarning("pc_bonus3 (Add Effect): %d is not supported.\n", type2); + break; + } + pc_bonus_addeff(sd->addeff, ARRAYLENGTH(sd->addeff), (sc_type)type2, + sd->state.lr_flag!=2?type3:0, sd->state.lr_flag==2?type3:0, val); break; - } - pc_bonus_addeff(sd->addeff, ARRAYLENGTH(sd->addeff), (sc_type)type2, - sd->state.lr_flag!=2?type3:0, sd->state.lr_flag==2?type3:0, val); - break; - case SP_ADDEFF_WHENHIT: - if (type2 > SC_MAX) { - ShowWarning("pc_bonus3 (Add Effect when hit): %d is not supported.\n", type2); + case SP_ADDEFF_WHENHIT: + if (type2 > SC_MAX) { + ShowWarning("pc_bonus3 (Add Effect when hit): %d is not supported.\n", type2); + break; + } + if(sd->state.lr_flag != 2) + pc_bonus_addeff(sd->addeff2, ARRAYLENGTH(sd->addeff2), (sc_type)type2, type3, 0, val); break; - } - if(sd->state.lr_flag != 2) - pc_bonus_addeff(sd->addeff2, ARRAYLENGTH(sd->addeff2), (sc_type)type2, type3, 0, val); - break; - case SP_ADDEFF_ONSKILL: - if( type3 > SC_MAX ) { - ShowWarning("pc_bonus3 (Add Effect on skill): %d is not supported.\n", type3); + case SP_ADDEFF_ONSKILL: + if( type3 > SC_MAX ) { + ShowWarning("pc_bonus3 (Add Effect on skill): %d is not supported.\n", type3); + break; + } + if( sd->state.lr_flag != 2 ) + pc_bonus_addeff_onskill(sd->addeff3, ARRAYLENGTH(sd->addeff3), (sc_type)type3, val, type2, ATF_TARGET); break; - } - if( sd->state.lr_flag != 2 ) - pc_bonus_addeff_onskill(sd->addeff3, ARRAYLENGTH(sd->addeff3), (sc_type)type3, val, type2, ATF_TARGET); - break; - case SP_ADDELE: - if (type2 > ELE_MAX) { - ShowWarning("pc_bonus3 (SP_ADDELE): element %d is out of range.\n", type2); + case SP_ADDELE: + if (type2 > ELE_MAX) { + ShowWarning("pc_bonus3 (SP_ADDELE): element %d is out of range.\n", type2); + break; + } + if (sd->state.lr_flag != 2) + pc_bonus_addele(sd, (unsigned char)type2, type3, val); break; - } - if (sd->state.lr_flag != 2) - pc_bonus_addele(sd, (unsigned char)type2, type3, val); - break; - case SP_SUBELE: - if (type2 > ELE_MAX) { - ShowWarning("pc_bonus3 (SP_SUBELE): element %d is out of range.\n", type2); + case SP_SUBELE: + if (type2 > ELE_MAX) { + ShowWarning("pc_bonus3 (SP_SUBELE): element %d is out of range.\n", type2); + break; + } + if (sd->state.lr_flag != 2) + pc_bonus_subele(sd, (unsigned char)type2, type3, val); break; - } - if (sd->state.lr_flag != 2) - pc_bonus_subele(sd, (unsigned char)type2, type3, val); - break; - default: - ShowWarning("pc_bonus3: unknown type %d %d %d %d!\n",type,type2,type3,val); - break; + default: + ShowWarning("pc_bonus3: unknown type %d %d %d %d!\n",type,type2,type3,val); + break; } return 0; @@ -3421,24 +3418,24 @@ int pc_bonus5(struct map_session_data *sd,int type,int type2,int type3,int type4 nullpo_ret(sd); switch(type){ - case SP_AUTOSPELL: - if(sd->state.lr_flag != 2) - pc_bonus_autospell(sd->autospell, ARRAYLENGTH(sd->autospell), (val&1?type2:-type2), (val&2?-type3:type3), type4, type5, current_equip_card_id); - break; + case SP_AUTOSPELL: + if(sd->state.lr_flag != 2) + pc_bonus_autospell(sd->autospell, ARRAYLENGTH(sd->autospell), (val&1?type2:-type2), (val&2?-type3:type3), type4, type5, current_equip_card_id); + break; - case SP_AUTOSPELL_WHENHIT: - if(sd->state.lr_flag != 2) - pc_bonus_autospell(sd->autospell2, ARRAYLENGTH(sd->autospell2), (val&1?type2:-type2), (val&2?-type3:type3), type4, type5, current_equip_card_id); - break; + case SP_AUTOSPELL_WHENHIT: + if(sd->state.lr_flag != 2) + pc_bonus_autospell(sd->autospell2, ARRAYLENGTH(sd->autospell2), (val&1?type2:-type2), (val&2?-type3:type3), type4, type5, current_equip_card_id); + break; - case SP_AUTOSPELL_ONSKILL: - if(sd->state.lr_flag != 2) - pc_bonus_autospell_onskill(sd->autospell3, ARRAYLENGTH(sd->autospell3), type2, (val&1?-type3:type3), (val&2?-type4:type4), type5, current_equip_card_id); - break; + case SP_AUTOSPELL_ONSKILL: + if(sd->state.lr_flag != 2) + pc_bonus_autospell_onskill(sd->autospell3, ARRAYLENGTH(sd->autospell3), type2, (val&1?-type3:type3), (val&2?-type4:type4), type5, current_equip_card_id); + break; - default: - ShowWarning("pc_bonus5: unknown type %d %d %d %d %d %d!\n",type,type2,type3,type4,type5,val); - break; + default: + ShowWarning("pc_bonus5: unknown type %d %d %d %d %d %d!\n",type,type2,type3,type4,type5,val); + break; } return 0; @@ -3628,7 +3625,7 @@ int pc_checkadditem(struct map_session_data *sd,int nameid,int amount) if(amount > MAX_AMOUNT) return ADDITEM_OVERAMOUNT; - data = itemdb_search(nameid); + data = itemdb->search(nameid); if(!itemdb_isstackable2(data)) return ADDITEM_NEW; @@ -3863,7 +3860,7 @@ int pc_additem(struct map_session_data *sd,struct item *item_data,int amount,e_l if( amount > MAX_AMOUNT ) return 5; - data = itemdb_search(item_data->nameid); + data = itemdb->search(item_data->nameid); if( data->stack.inventory && amount > data->stack.amount ) {// item stack limitation @@ -4250,11 +4247,10 @@ int pc_isUseitem(struct map_session_data *sd,int n) * 0 = fail * 1 = success *------------------------------------------*/ -int pc_useitem(struct map_session_data *sd,int n) -{ +int pc_useitem(struct map_session_data *sd,int n) { unsigned int tick = iTimer->gettick(); int amount, nameid, i; - struct script_code *script; + struct script_code *item_script; nullpo_ret(sd); @@ -4357,7 +4353,7 @@ int pc_useitem(struct map_session_data *sd,int n) sd->catch_target_class = -1; amount = sd->status.inventory[n].amount; - script = sd->inventory_data[n]->script; + item_script = sd->inventory_data[n]->script; //Check if the item is to be consumed immediately [Skotlex] if( sd->inventory_data[n]->flag.delay_consume ) clif->useitemack(sd,n,amount,true); @@ -4380,9 +4376,14 @@ int pc_useitem(struct map_session_data *sd,int n) sd->canuseitem_tick = tick + battle_config.item_use_interval; if( itemdb_iscashfood(nameid) ) sd->canusecashfood_tick = tick + battle_config.cashfood_use_interval; - - run_script(script,0,sd->bl.id,fake_nd->bl.id); + + script->current_item_id = nameid; + + run_script(item_script,0,sd->bl.id,fake_nd->bl.id); + + script->current_item_id = 0; potion_flag = 0; + return 1; } @@ -4402,7 +4403,7 @@ int pc_cart_additem(struct map_session_data *sd,struct item *item_data,int amoun if(item_data->nameid <= 0 || amount <= 0) return 1; - data = itemdb_search(item_data->nameid); + data = itemdb->search(item_data->nameid); if( data->stack.cart && amount > data->stack.amount ) {// item stack limitation @@ -4465,7 +4466,7 @@ int pc_cart_delitem(struct map_session_data *sd,int n,int amount,int type,e_log_ struct item_data * data; nullpo_retr(1, sd); - if( sd->status.cart[n].nameid == 0 || sd->status.cart[n].amount < amount || !(data = itemdb_exists(sd->status.cart[n].nameid)) ) + if( sd->status.cart[n].nameid == 0 || sd->status.cart[n].amount < amount || !(data = itemdb->exists(sd->status.cart[n].nameid)) ) return 1; logs->pick_pc(sd, log_type, -amount, &sd->status.cart[n],data); @@ -4570,7 +4571,7 @@ int pc_show_steal(struct block_list *bl,va_list ap) sd=va_arg(ap,struct map_session_data *); itemid=va_arg(ap,int); - if((item=itemdb_exists(itemid))==NULL) + if((item=itemdb->exists(itemid))==NULL) sprintf(output,"%s stole an Unknown Item (id: %i).",sd->status.name, itemid); else sprintf(output,"%s stole %s.",sd->status.name,item->jname); @@ -4623,7 +4624,7 @@ int pc_steal_item(struct map_session_data *sd,struct block_list *bl, uint16 skil // Try dropping one item, in the order from first to last possible slot. // Droprate is affected by the skill success rate. for( i = 0; i < MAX_STEAL_DROP; i++ ) - if( md->db->dropitem[i].nameid > 0 && (data = itemdb_exists(md->db->dropitem[i].nameid)) && rnd() % 10000 < md->db->dropitem[i].p * rate/100. ) + if( md->db->dropitem[i].nameid > 0 && (data = itemdb->exists(md->db->dropitem[i].nameid)) && rnd() % 10000 < md->db->dropitem[i].p * rate/100. ) break; if( i == MAX_STEAL_DROP ) return 0; @@ -7304,12 +7305,10 @@ int pc_itemheal(struct map_session_data *sd,int itemid, int hp,int sp) bonus += bonus*(potion_flag-1)*50/100; //All item bonuses. bonus += sd->bonus.itemhealrate2; - //Item Group bonuses - bonus += bonus*itemdb_group_bonus(sd, itemid)/100; //Individual item bonuses. - for(i = 0; i < ARRAYLENGTH(sd->itemhealrate) && sd->itemhealrate[i].nameid; i++) - { - if (sd->itemhealrate[i].nameid == itemid) { + for(i = 0; i < ARRAYLENGTH(sd->itemhealrate) && sd->itemhealrate[i].nameid; i++) { + struct item_data *it = itemdb->exists(sd->itemhealrate[i].nameid); + if (sd->itemhealrate[i].nameid == itemid || (it && it->group && itemdb->in_group(it->group,itemid))) { bonus += bonus*sd->itemhealrate[i].rate/100; break; } @@ -8477,7 +8476,7 @@ int pc_load_combo(struct map_session_data *sd) { for( j = 0; j < id->slot; j++ ) { if (!sd->status.inventory[idx].card[j]) continue; - if ( ( data = itemdb_exists(sd->status.inventory[idx].card[j]) ) != NULL ) { + if ( ( data = itemdb->exists(sd->status.inventory[idx].card[j]) ) != NULL ) { if( data->combos_count ) ret += pc_checkcombo(sd,data); } @@ -8661,7 +8660,7 @@ int pc_equipitem(struct map_session_data *sd,int n,int req_pos) struct item_data *data; if (!sd->status.inventory[n].card[i]) continue; - if ( ( data = itemdb_exists(sd->status.inventory[n].card[i]) ) != NULL ) { + if ( ( data = itemdb->exists(sd->status.inventory[n].card[i]) ) != NULL ) { if( data->combos_count ) pc_checkcombo(sd,data); } @@ -8684,7 +8683,7 @@ int pc_equipitem(struct map_session_data *sd,int n,int req_pos) struct item_data *data; if (!sd->status.inventory[n].card[i]) continue; - if ( ( data = itemdb_exists(sd->status.inventory[n].card[i]) ) != NULL ) { + if ( ( data = itemdb->exists(sd->status.inventory[n].card[i]) ) != NULL ) { if( data->equip_script ) run_script(data->equip_script,0,sd->bl.id,fake_nd->bl.id); } @@ -8822,7 +8821,7 @@ int pc_unequipitem(struct map_session_data *sd,int n,int flag) { struct item_data *data; if (!sd->status.inventory[n].card[i]) continue; - if ( ( data = itemdb_exists(sd->status.inventory[n].card[i]) ) != NULL ) { + if ( ( data = itemdb->exists(sd->status.inventory[n].card[i]) ) != NULL ) { if( data->combos_count ) { if( pc_removecombo(sd,data) ) status_cacl = true; @@ -8852,7 +8851,7 @@ int pc_unequipitem(struct map_session_data *sd,int n,int flag) { if (!sd->status.inventory[n].card[i]) continue; - if ( ( data = itemdb_exists(sd->status.inventory[n].card[i]) ) != NULL ) { + if ( ( data = itemdb->exists(sd->status.inventory[n].card[i]) ) != NULL ) { if( data->unequip_script ) run_script(data->unequip_script,0,sd->bl.id,fake_nd->bl.id); } diff --git a/src/map/pc.h b/src/map/pc.h index 43d5d40c7..298808d0d 100644 --- a/src/map/pc.h +++ b/src/map/pc.h @@ -10,7 +10,7 @@ #include "battle.h" // battle_config #include "battleground.h" #include "buyingstore.h" // struct s_buyingstore -#include "itemdb.h" // MAX_ITEMGROUP +#include "itemdb.h" #include "map.h" // RC_MAX #include "script.h" // struct script_reg, struct script_regstr #include "searchstore.h" // struct s_search_store_info @@ -256,7 +256,6 @@ struct map_session_data { int expaddrace[RC_MAX]; int ignore_mdef[RC_MAX]; int ignore_def[RC_MAX]; - int itemgrouphealrate[MAX_ITEMGROUP]; short sp_gain_race[RC_MAX]; short sp_gain_race_attack[RC_MAX]; short hp_gain_race_attack[RC_MAX]; diff --git a/src/map/pet.c b/src/map/pet.c index 00402f9d4..8ed88c46c 100644 --- a/src/map/pet.c +++ b/src/map/pet.c @@ -592,7 +592,7 @@ int pet_menu(struct map_session_data *sd,int menunum) if(!sd->status.pet_id || sd->pd->pet.intimate <= 0 || sd->pd->pet.incuvate) return 1; - egg_id = itemdb_exists(sd->pd->petDB->EggID); + egg_id = itemdb->exists(sd->pd->petDB->EggID); if (egg_id) { if ((egg_id->flag.trade_restriction&0x01) && !pc->inventoryblank(sd)) { clif->message(sd->fd, msg_txt(451)); // You can't return your pet because your inventory is full. diff --git a/src/map/script.c b/src/map/script.c index f65c0c21c..481cb5870 100644 --- a/src/map/script.c +++ b/src/map/script.c @@ -1397,7 +1397,7 @@ const char* parse_syntax(const char* p) v = p2-p; // length of word at p2 memcpy(label,p,v); label[v]='\0'; - if( !script_get_constant(label, &v) ) + if( !script->get_constant(label, &v) ) disp_error_message("parse_syntax: 'case' label is not an integer",p); p = skip_word(p); } else { //Numeric value @@ -1951,25 +1951,32 @@ bool script_get_constant(const char* name, int* value) } /// Creates new constant or parameter with given value. -void script_set_constant(const char* name, int value, bool isparameter) -{ +void script_set_constant(const char* name, int value, bool isparameter) { int n = add_str(name); - if( script->str_data[n].type == C_NOP ) - {// new + if( script->str_data[n].type == C_NOP ) {// new script->str_data[n].type = isparameter ? C_PARAM : C_INT; script->str_data[n].val = value; - } - else if( script->str_data[n].type == C_PARAM || script->str_data[n].type == C_INT ) - {// existing parameter or constant + } else if( script->str_data[n].type == C_PARAM || script->str_data[n].type == C_INT ) {// existing parameter or constant ShowError("script_set_constant: Attempted to overwrite existing %s '%s' (old value=%d, new value=%d).\n", ( script->str_data[n].type == C_PARAM ) ? "parameter" : "constant", name, script->str_data[n].val, value); - } - else - {// existing name + } else {// existing name ShowError("script_set_constant: Invalid name for %s '%s' (already defined as %s).\n", isparameter ? "parameter" : "constant", name, script_op2name(script->str_data[n].type)); } } +/* will override if necessary */ +void script_set_constant2(const char *name, int value, bool isparameter) { + int n = add_str(name); + + if( script->str_data[n].type != C_NOP ) { + script->str_data[n].next = 0; + script->str_data[n].func = NULL; + script->str_data[n].backpatch = -1; + script->str_data[n].label = -1; + } + script->str_data[n].type = isparameter ? C_PARAM : C_INT; + script->str_data[n].val = value; +} /*========================================== * Reading constant databases * const.txt @@ -5564,11 +5571,11 @@ BUILDIN(countitem) if( data_isstring(data) ) {// item name - id = itemdb_searchname(script->conv_str(st, data)); + id = itemdb->search_name(script->conv_str(st, data)); } else {// item id - id = itemdb_exists(script->conv_num(st, data)); + id = itemdb->exists(script->conv_num(st, data)); } if( id == NULL ) @@ -5611,11 +5618,11 @@ BUILDIN(countitem2) if( data_isstring(data) ) {// item name - id = itemdb_searchname(script->conv_str(st, data)); + id = itemdb->search_name(script->conv_str(st, data)); } else {// item id - id = itemdb_exists(script->conv_num(st, data)); + id = itemdb->exists(script->conv_num(st, data)); } if( id == NULL ) @@ -5678,9 +5685,9 @@ BUILDIN(checkweight) data = script_getdata(st,i); script->get_val(st, data); // convert into value in case of a variable if( data_isstring(data) ){// item name - id = itemdb_searchname(script->conv_str(st, data)); + id = itemdb->search_name(script->conv_str(st, data)); } else {// item id - id = itemdb_exists(script->conv_num(st, data)); + id = itemdb->exists(script->conv_num(st, data)); } if( id == NULL ) { ShowError("buildin_checkweight: Invalid item '%s'.\n", script_getstr(st,i)); // returns string, regardless of what it was @@ -5794,7 +5801,7 @@ BUILDIN(checkweight2) script_removetop(st, -1, 0); if(fail) continue; //cpntonie to depop rest - if(itemdb_exists(nameid) == NULL ){ + if(itemdb->exists(nameid) == NULL ){ ShowError("buildin_checkweight2: Invalid item '%d'.\n", nameid); fail=1; continue; @@ -5852,7 +5859,7 @@ BUILDIN(getitem) if( data_isstring(data) ) {// "<item name>" const char *name=script->conv_str(st,data); - if( (item_data = itemdb_searchname(name)) == NULL ){ + if( (item_data = itemdb->search_name(name)) == NULL ){ ShowError("buildin_getitem: Nonexistant item %s requested.\n", name); return false; //No item created. } @@ -5864,7 +5871,7 @@ BUILDIN(getitem) nameid = -nameid; flag = 1; } - if( nameid <= 0 || !(item_data = itemdb_exists(nameid)) ){ + if( nameid <= 0 || !(item_data = itemdb->exists(nameid)) ){ ShowError("buildin_getitem: Nonexistant item %d requested.\n", nameid); return false; //No item created. } @@ -5939,7 +5946,7 @@ BUILDIN(getitem2) script->get_val(st,data); if( data_isstring(data) ){ const char *name=script->conv_str(st,data); - struct item_data *item_data = itemdb_searchname(name); + struct item_data *item_data = itemdb->search_name(name); if( item_data ) nameid=item_data->nameid; else @@ -5963,7 +5970,7 @@ BUILDIN(getitem2) if(nameid > 0) { memset(&item_tmp,0,sizeof(item_tmp)); - item_data=itemdb_exists(nameid); + item_data=itemdb->exists(nameid); if (item_data == NULL) return -1; if(item_data->type==IT_WEAPON || item_data->type==IT_ARMOR){ @@ -6035,7 +6042,7 @@ BUILDIN(rentitem) if( data_isstring(data) ) { const char *name = script->conv_str(st,data); - struct item_data *itd = itemdb_searchname(name); + struct item_data *itd = itemdb->search_name(name); if( itd == NULL ) { ShowError("buildin_rentitem: Nonexistant item %s requested.\n", name); @@ -6046,7 +6053,7 @@ BUILDIN(rentitem) else if( data_isint(data) ) { nameid = script->conv_num(st,data); - if( nameid <= 0 || !itemdb_exists(nameid) ) + if( nameid <= 0 || !itemdb->exists(nameid) ) { ShowError("buildin_rentitem: Nonexistant item %d requested.\n", nameid); return false; @@ -6097,7 +6104,7 @@ BUILDIN(getnameditem) script->get_val(st,data); if( data_isstring(data) ){ const char *name=script->conv_str(st,data); - struct item_data *item_data = itemdb_searchname(name); + struct item_data *item_data = itemdb->search_name(name); if( item_data == NULL) { //Failed script_pushint(st,0); @@ -6107,7 +6114,7 @@ BUILDIN(getnameditem) }else nameid = script->conv_num(st,data); - if(!itemdb_exists(nameid)/* || itemdb_isstackable(nameid)*/) + if(!itemdb->exists(nameid)/* || itemdb_isstackable(nameid)*/) { //Even though named stackable items "could" be risky, they are required for certain quests. script_pushint(st,0); return true; @@ -6146,12 +6153,30 @@ BUILDIN(getnameditem) * gets a random item ID from an item group [Skotlex] * groupranditem group_num *------------------------------------------*/ -BUILDIN(grouprandomitem) -{ - int group; +BUILDIN(grouprandomitem) { + struct item_data *data; + int nameid; + + if( script_hasdata(st, 2) ) + nameid = script_getnum(st, 2); + else if ( script->current_item_id ) + nameid = script->current_item_id; + else { + ShowWarning("buildin_grouprandomitem: no item id provided and no item attached\n"); + script_pushint(st, 0); + return true; + } - group = script_getnum(st,2); - script_pushint(st,itemdb_searchrandomid(group)); + if( !(data = itemdb->exists(nameid)) ) { + ShowWarning("buildin_grouprandomitem: unknown item id %d\n",nameid); + script_pushint(st, 0); + } else if ( !data->group ) { + ShowWarning("buildin_grouprandomitem: item '%s' (%d) isn't a group!\n",data->name,nameid); + script_pushint(st, 0); + } else { + script_pushint(st, itemdb->group_item(data->group)); + } + return true; } @@ -6171,13 +6196,13 @@ BUILDIN(makeitem) script->get_val(st,data); if( data_isstring(data) ){ const char *name=script->conv_str(st,data); - if( (item_data = itemdb_searchname(name)) ) + if( (item_data = itemdb->search_name(name)) ) nameid=item_data->nameid; else nameid=UNKNOWN_ITEM_ID; } else { nameid=script->conv_num(st,data); - if( nameid <= 0 || !(item_data = itemdb_exists(nameid)) ){ + if( nameid <= 0 || !(item_data = itemdb->exists(nameid)) ){ ShowError("makeitem: Nonexistant item %d requested.\n", nameid); return false; //No item created. } @@ -6384,7 +6409,7 @@ BUILDIN(delitem) if( data_isstring(data) ) { const char* item_name = script->conv_str(st,data); - struct item_data* id = itemdb_searchname(item_name); + struct item_data* id = itemdb->search_name(item_name); if( id == NULL ) { ShowError("script:delitem: unknown item \"%s\".\n", item_name); @@ -6396,7 +6421,7 @@ BUILDIN(delitem) else { it.nameid = script->conv_num(st,data);// <item id> - if( !itemdb_exists( it.nameid ) ) + if( !itemdb->exists( it.nameid ) ) { ShowError("script:delitem: unknown item \"%d\".\n", it.nameid); st->state = END; @@ -6453,7 +6478,7 @@ BUILDIN(delitem2) if( data_isstring(data) ) { const char* item_name = script->conv_str(st,data); - struct item_data* id = itemdb_searchname(item_name); + struct item_data* id = itemdb->search_name(item_name); if( id == NULL ) { ShowError("script:delitem2: unknown item \"%s\".\n", item_name); @@ -6465,7 +6490,7 @@ BUILDIN(delitem2) else { it.nameid = script->conv_num(st,data);// <item id> - if( !itemdb_exists( it.nameid ) ) + if( !itemdb->exists( it.nameid ) ) { ShowError("script:delitem: unknown item \"%d\".\n", it.nameid); st->state = END; @@ -8422,7 +8447,12 @@ BUILDIN(monster) if (sd && strcmp(mapn, "this") == 0) m = sd->bl.m; else { - m = iMap->mapname2mapid(mapn); + + if ( ( m = iMap->mapname2mapid(mapn) ) == -1 ) { + ShowWarning("buildin_monster: Attempted to spawn monster class %d on non-existing map '%s'\n",class_, mapn); + return false; + } + if (map[m].flag.src4instance && st->instance_id >= 0) { // Try to redirect to the instance map, not the src map if ((m = instance->mapid2imapid(m, st->instance_id)) < 0) { ShowError("buildin_monster: Trying to spawn monster (%d) on instance map (%s) without instance attached.\n", class_, mapn); @@ -8456,7 +8486,7 @@ BUILDIN(getmobdrops) { if( mob->dropitem[i].nameid < 1 ) continue; - if( itemdb_exists(mob->dropitem[i].nameid) == NULL ) + if( itemdb->exists(mob->dropitem[i].nameid) == NULL ) continue; mapreg_setreg(reference_uid(add_str("$@MobDrop_item"), j), mob->dropitem[i].nameid); @@ -9129,14 +9159,14 @@ BUILDIN(itemeffect) { if( data_isstring( data ) ){ const char *name = script->conv_str( st, data ); - if( ( item_data = itemdb_searchname( name ) ) == NULL ){ + if( ( item_data = itemdb->search_name( name ) ) == NULL ){ ShowError( "buildin_itemeffect: Nonexistant item %s requested.\n", name ); return false; } } else if( data_isint( data ) ){ int nameid = script->conv_num( st, data ); - if( ( item_data = itemdb_exists( nameid ) ) == NULL ){ + if( ( item_data = itemdb->exists( nameid ) ) == NULL ){ ShowError("buildin_itemeffect: Nonexistant item %d requested.\n", nameid ); return false; } @@ -9363,7 +9393,7 @@ BUILDIN(getareadropitem) script->get_val(st,data); if( data_isstring(data) ){ const char *name=script->conv_str(st,data); - struct item_data *item_data = itemdb_searchname(name); + struct item_data *item_data = itemdb->search_name(name); item=UNKNOWN_ITEM_ID; if( item_data ) item=item_data->nameid; @@ -11446,13 +11476,13 @@ BUILDIN(getitemname) if( data_isstring(data) ){ const char *name=script->conv_str(st,data); - struct item_data *item_data = itemdb_searchname(name); + struct item_data *item_data = itemdb->search_name(name); if( item_data ) item_id=item_data->nameid; }else item_id=script->conv_num(st,data); - i_data = itemdb_exists(item_id); + i_data = itemdb->exists(item_id); if (i_data == NULL) { script_pushconststr(st,"null"); @@ -11474,7 +11504,7 @@ BUILDIN(getitemslots) item_id=script_getnum(st,2); - i_data = itemdb_exists(item_id); + i_data = itemdb->exists(item_id); if (i_data) script_pushint(st,i_data->slot); @@ -11515,7 +11545,7 @@ BUILDIN(getiteminfo) item_id = script_getnum(st,2); n = script_getnum(st,3); - i_data = itemdb_exists(item_id); + i_data = itemdb->exists(item_id); if (i_data && n>=0 && n<=14) { item_arr = (int*)&i_data->value_buy; @@ -11557,7 +11587,7 @@ BUILDIN(setiteminfo) item_id = script_getnum(st,2); n = script_getnum(st,3); value = script_getnum(st,4); - i_data = itemdb_exists(item_id); + i_data = itemdb->exists(item_id); if (i_data && n>=0 && n<=14) { item_arr = (int*)&i_data->value_buy; @@ -13106,7 +13136,7 @@ BUILDIN(equip) sd = script_rid2sd(st); nameid=script_getnum(st,2); - if((item_data = itemdb_exists(nameid)) == NULL) + if((item_data = itemdb->exists(nameid)) == NULL) { ShowError("wrong item ID : equipitem(%i)\n",nameid); return false; @@ -13125,7 +13155,7 @@ BUILDIN(autoequip) nameid=script_getnum(st,2); flag=script_getnum(st,3); - if( ( item_data = itemdb_exists(nameid) ) == NULL ) + if( ( item_data = itemdb->exists(nameid) ) == NULL ) { ShowError("buildin_autoequip: Invalid item '%d'.\n", nameid); return false; @@ -14464,7 +14494,7 @@ BUILDIN(setitemscript) new_bonus_script = script_getstr(st,3); if( script_hasdata(st,4) ) n=script_getnum(st,4); - i_data = itemdb_exists(item_id); + i_data = itemdb->exists(item_id); if (!i_data || new_bonus_script==NULL || ( new_bonus_script[0] && new_bonus_script[0]!='{' )) { script_pushint(st,0); @@ -14630,10 +14660,10 @@ BUILDIN(searchitem) int32 i; TBL_PC* sd = NULL; - if ((items[0] = itemdb_exists(atoi(itemname)))) + if ((items[0] = itemdb->exists(atoi(itemname)))) count = 1; else { - count = itemdb_searchname_array(items, ARRAYLENGTH(items), itemname); + count = itemdb->search_name_array(items, ARRAYLENGTH(items), itemname); if (count > MAX_SEARCH) count = MAX_SEARCH; } @@ -16831,50 +16861,53 @@ BUILDIN(checkre) return true; } -/* getrandgroupitem <group_id>,<quantity> */ +/* getrandgroupitem <container_item_id>,<quantity> */ BUILDIN(getrandgroupitem) { - TBL_PC* sd; - int i, get_count = 0, flag, nameid, group = script_getnum(st, 2), qty = script_getnum(st,3); - struct item item_tmp; - - if( !( sd = script_rid2sd(st) ) ) - return true; - - if( qty <= 0 ) { - ShowError("getrandgroupitem: qty is <= 0!\n"); - return false; - } - - if(group < 1 || group >= MAX_ITEMGROUP) { - ShowError("getrandgroupitem: Invalid group id %d\n", group); - return false; - } - if (!itemgroup_db[group].qty) { - ShowError("getrandgroupitem: group id %d is empty!\n", group); - return false; - } - - nameid = itemdb_searchrandomid(group); - memset(&item_tmp,0,sizeof(item_tmp)); - - item_tmp.nameid = nameid; - item_tmp.identify = itemdb_isidentified(nameid); - - //Check if it's stackable. - if (!itemdb_isstackable(nameid)) - get_count = 1; - else - get_count = qty; + struct item_data *data = NULL; + struct map_session_data *sd = NULL; + int nameid = script_getnum(st, 2); + int count = script_getnum(st, 3); - for (i = 0; i < qty; i += get_count) { - // if not pet egg - if (!pet_create_egg(sd, nameid)) { - if ((flag = pc->additem(sd, &item_tmp, get_count, LOG_TYPE_SCRIPT))) { - clif->additem(sd, 0, 0, flag); - if( pc->candrop(sd,&item_tmp) ) - iMap->addflooritem(&item_tmp,get_count,sd->bl.m,sd->bl.x,sd->bl.y,0,0,0,0); + if( !(data = itemdb->exists(nameid)) ) { + ShowWarning("buildin_getrandgroupitem: unknown item id %d\n",nameid); + script_pushint(st, 1); + } else if ( count <= 0 ) { + ShowError("buildin_getrandgroupitem: qty is <= 0!\n"); + script_pushint(st, 1); + } else if ( !data->group ) { + ShowWarning("buildin_getrandgroupitem: item '%s' (%d) isn't a group!\n",data->name,nameid); + script_pushint(st, 1); + } else if( !( sd = script->rid2sd(st) ) ) { + ShowWarning("buildin_getrandgroupitem: no player attached!! (item %s (%d))\n",data->name,nameid); + script_pushint(st, 1); + } else { + int i, get_count, flag; + struct item it; + + memset(&it,0,sizeof(it)); + + nameid = itemdb->group_item(data->group); + + it.nameid = nameid; + it.identify = itemdb_isidentified(nameid); + + if (!itemdb_isstackable(nameid)) + get_count = 1; + else + get_count = count; + + for (i = 0; i < count; i += get_count) { + // if not pet egg + if (!pet_create_egg(sd, nameid)) { + if ((flag = pc->additem(sd, &it, get_count, LOG_TYPE_SCRIPT))) { + clif->additem(sd, 0, 0, flag); + if( pc->candrop(sd,&it) ) + iMap->addflooritem(&it,get_count,sd->bl.m,sd->bl.x,sd->bl.y,0,0,0,0); + } } } + + script_pushint(st, 0); } return true; @@ -17268,6 +17301,41 @@ BUILDIN(qiclear) { return true; } +/** + * packageitem({<optional container_item_id>}) + * when no item id is provided it tries to assume it comes from the current item id being processed (if any) + **/ +BUILDIN(packageitem) { + struct item_data *data = NULL; + struct map_session_data *sd = NULL; + int nameid; + + if( script_hasdata(st, 2) ) + nameid = script_getnum(st, 2); + else if ( script->current_item_id ) + nameid = script->current_item_id; + else { + ShowWarning("buildin_packageitem: no item id provided and no item attached\n"); + script_pushint(st, 1); + return true; + } + + if( !(data = itemdb->exists(nameid)) ) { + ShowWarning("buildin_packageitem: unknown item id %d\n",nameid); + script_pushint(st, 1); + } else if ( !data->package ) { + ShowWarning("buildin_packageitem: item '%s' (%d) isn't a package!\n",data->name,nameid); + script_pushint(st, 1); + } else if( !( sd = script->rid2sd(st) ) ) { + ShowWarning("buildin_packageitem: no player attached!! (item %s (%d))\n",data->name,nameid); + script_pushint(st, 1); + } else { + itemdb->package_item(sd,data->package); + script_pushint(st, 0); + } + + return true; +} // declarations that were supposed to be exported from npc_chat.c #ifdef PCRE_SUPPORT @@ -17782,6 +17850,9 @@ void script_parse_builtin(void) { BUILDIN_DEF(qicheck,"i"), BUILDIN_DEF(qiget,"i"), BUILDIN_DEF(qiclear,"i"), + + BUILDIN_DEF(packageitem,"?"), + }; int i,n, len = ARRAYLENGTH(BUILDIN), start = script->buildin_count; char* p; @@ -17859,6 +17930,8 @@ void script_defaults(void) { script->word_buf = NULL; script->word_size = 0; + script->current_item_id = 0; + script->init = do_init_script; script->final = do_final_script; @@ -17874,6 +17947,9 @@ void script_defaults(void) { script->push_str = push_str; script->push_copy = push_copy; script->pop_stack = pop_stack; + script->set_constant = script_set_constant; + script->set_constant2 = script_set_constant2; + script->get_constant = script_get_constant; script->queue = script_hqueue_get; script->queue_add = script_hqueue_add; diff --git a/src/map/script.h b/src/map/script.h index 3cfcd9de4..a047779a8 100644 --- a/src/map/script.h +++ b/src/map/script.h @@ -202,9 +202,6 @@ struct DBMap* script_get_label_db(void); struct DBMap* script_get_userfunc_db(void); void script_run_autobonus(const char *autobonus,int id, int pos); -bool script_get_constant(const char* name, int* value); -void script_set_constant(const char* name, int value, bool isparameter); - void script_cleararray_pc(struct map_session_data* sd, const char* varname, void* value); void script_setarray_pc(struct map_session_data* sd, const char* varname, uint8 idx, void* value, int* refcache); @@ -357,10 +354,12 @@ struct script_interface { char *str_buf; int str_size; // size of the buffer int str_pos; // next position to be assigned - // + /* */ char *word_buf; int word_size; /* */ + unsigned short current_item_id; + /* */ void (*init) (void); void (*final) (void); /* */ @@ -376,6 +375,9 @@ struct script_interface { struct script_data* (*push_str) (struct script_stack* stack, enum c_op type, char* str); struct script_data* (*push_copy) (struct script_stack* stack, int pos); void (*pop_stack) (struct script_state* st, int start, int end); + void (*set_constant) (const char* name, int value, bool isparameter); + void (*set_constant2) (const char *name, int value, bool isparameter); + bool (*get_constant) (const char* name, int* value); /* */ struct hQueue *(*queue) (int idx); bool (*queue_add) (int idx, int var); diff --git a/src/map/searchstore.c b/src/map/searchstore.c index 3cda77e4a..d346a0de6 100644 --- a/src/map/searchstore.c +++ b/src/map/searchstore.c @@ -135,14 +135,14 @@ void searchstore_query(struct map_session_data* sd, unsigned char type, unsigned // validate lists for( i = 0; i < item_count; i++ ) { - if( !itemdb_exists(itemlist[i]) ) { + if( !itemdb->exists(itemlist[i]) ) { ShowWarning("searchstore_query: Client resolved item %hu is not known.\n", itemlist[i]); clif->search_store_info_failed(sd, SSI_FAILED_NOTHING_SEARCH_ITEM); return; } } for( i = 0; i < card_count; i++ ) { - if( !itemdb_exists(cardlist[i]) ) { + if( !itemdb->exists(cardlist[i]) ) { ShowWarning("searchstore_query: Client resolved card %hu is not known.\n", cardlist[i]); clif->search_store_info_failed(sd, SSI_FAILED_NOTHING_SEARCH_ITEM); return; diff --git a/src/map/skill.c b/src/map/skill.c index aec1ebbfc..509de6f4a 100644 --- a/src/map/skill.c +++ b/src/map/skill.c @@ -6474,7 +6474,7 @@ int skill_castend_nodamage_id (struct block_list *src, struct block_list *bl, ui return 1; } if( sd ) { - int x,bonus=100; + int x,bonus=100, potion = min(500+skill_lv,505); x = skill_lv%11 - 1; i = pc->search_inventory(sd,skill_db[skill_id].itemid[x]); if( i < 0 || skill_db[skill_id].itemid[x] <= 0 ) { @@ -6523,11 +6523,14 @@ int skill_castend_nodamage_id (struct block_list *src, struct block_list *bl, ui } } - if (sd->itemgrouphealrate[IG_POTION]>0) { - hp += hp * sd->itemgrouphealrate[IG_POTION] / 100; - sp += sp * sd->itemgrouphealrate[IG_POTION] / 100; + for(i = 0; i < ARRAYLENGTH(sd->itemhealrate) && sd->itemhealrate[i].nameid; i++) { + if (sd->itemhealrate[i].nameid == potion) { + hp += hp * sd->itemhealrate[i].rate / 100; + sp += sp * sd->itemhealrate[i].rate / 100; + break; + } } - + if( (i = pc->skillheal_bonus(sd, skill_id)) ) { hp += hp * i / 100; sp += sp * i / 100; @@ -9936,7 +9939,7 @@ int skill_castend_pos2(struct block_list* src, int x, int y, uint16 skill_id, ui int i = skill_lv%11 - 1; struct item_data *item; i = skill_db[skill_id].itemid[i]; - item = itemdb_search(i); + item = itemdb->search(i); potion_flag = 1; potion_hp = 0; potion_sp = 0; @@ -15925,7 +15928,7 @@ int skill_produce_mix (struct map_session_data *sd, uint16 skill_id, int nameid, if( skill_id == RK_RUNEMASTERY ) { int temp_qty, skill_lv = pc->checkskill(sd,skill_id); - data = itemdb_search(nameid); + data = itemdb->search(nameid); if( skill_lv == 10 ) temp_qty = 1 + rnd()%3; else if( skill_lv > 5 ) temp_qty = 1 + rnd()%2; diff --git a/src/map/status.c b/src/map/status.c index 55b79fff7..48ad1e239 100644 --- a/src/map/status.c +++ b/src/map/status.c @@ -2371,7 +2371,6 @@ int status_calc_pc_(struct map_session_data* sd, bool first) + sizeof(sd->expaddrace) + sizeof(sd->ignore_mdef) + sizeof(sd->ignore_def) - + sizeof(sd->itemgrouphealrate) + sizeof(sd->sp_gain_race) + sizeof(sd->sp_gain_race_attack) + sizeof(sd->hp_gain_race_attack) @@ -2600,16 +2599,9 @@ int status_calc_pc_(struct map_session_data* sd, bool first) current_equip_card_id= c= sd->status.inventory[index].card[j]; if(!c) continue; - data = itemdb_exists(c); + data = itemdb->exists(c); if(!data) continue; - if(first && data->equip_script) {//Execute equip-script on login - run_script(data->equip_script,0,sd->bl.id,0); - if (!calculating) - return 1; - } - if(!data->script) - continue; for(k = 0; k < map[sd->bl.m].zone->disabled_items_count; k++) { if( map[sd->bl.m].zone->disabled_items[k] == data->nameid ) { @@ -2620,6 +2612,15 @@ int status_calc_pc_(struct map_session_data* sd, bool first) if( k < map[sd->bl.m].zone->disabled_items_count ) continue; + if(first && data->equip_script) {//Execute equip-script on login + run_script(data->equip_script,0,sd->bl.id,0); + if (!calculating) + return 1; + } + + if(!data->script) + continue; + if(i == EQI_HAND_L && sd->status.inventory[index].equip == EQP_HAND_L) { //Left hand status. sd->state.lr_flag = 1; run_script(data->script,0,sd->bl.id,0); @@ -2632,15 +2633,13 @@ int status_calc_pc_(struct map_session_data* sd, bool first) } } - if( sc->count && sc->data[SC_ITEMSCRIPT] ) - { - struct item_data *data = itemdb_exists(sc->data[SC_ITEMSCRIPT]->val1); + if( sc->count && sc->data[SC_ITEMSCRIPT] ) { + struct item_data *data = itemdb->exists(sc->data[SC_ITEMSCRIPT]->val1); if( data && data->script ) run_script(data->script,0,sd->bl.id,0); } - if( sd->pd ) - { // Pet Bonus + if( sd->pd ) { // Pet Bonus struct pet_data *pd = sd->pd; if( pd && pd->petDB && pd->petDB->equip_script && pd->pet.intimate >= battle_config.pet_equip_min_friendly ) run_script(pd->petDB->equip_script,0,sd->bl.id,0); @@ -3871,8 +3870,7 @@ void status_calc_bl_main(struct block_list *bl, /*enum scb_flag*/int flag) if(flag&SCB_DSPD) { int dmotion; - if( bl->type&BL_PC ) - { + if( bl->type&BL_PC ) { if (b_status->agi == status->agi) status->dmotion = status_calc_dmotion(bl, sc, b_status->dmotion); else { @@ -3883,16 +3881,11 @@ void status_calc_bl_main(struct block_list *bl, /*enum scb_flag*/int flag) //It's safe to ignore b_status->dmotion since no bonus affects it. status->dmotion = status_calc_dmotion(bl, sc, status->dmotion); } - } - else - if( bl->type&BL_HOM ) - { + } else if( bl->type&BL_HOM ) { dmotion = 800-status->agi*4; status->dmotion = cap_value(dmotion, 400, 800); status->dmotion = status_calc_dmotion(bl, sc, b_status->dmotion); - } - else // mercenary and mobs - { + } else { // mercenary and mobs status->dmotion = status_calc_dmotion(bl, sc, b_status->dmotion); } } @@ -3918,13 +3911,13 @@ void status_calc_bl_(struct block_list* bl, enum scb_flag flag, bool first) if( flag&SCB_BASE ) {// calculate the object's base status too switch( bl->type ) { - case BL_PC: status_calc_pc_(BL_CAST(BL_PC,bl), first); break; - case BL_MOB: status_calc_mob_(BL_CAST(BL_MOB,bl), first); break; - case BL_PET: status_calc_pet_(BL_CAST(BL_PET,bl), first); break; - case BL_HOM: status_calc_homunculus_(BL_CAST(BL_HOM,bl), first); break; - case BL_MER: status_calc_mercenary_(BL_CAST(BL_MER,bl), first); break; - case BL_ELEM: status_calc_elemental_(BL_CAST(BL_ELEM,bl), first); break; - case BL_NPC: status_calc_npc_(BL_CAST(BL_NPC,bl), first); break; + case BL_PC: status_calc_pc_(BL_CAST(BL_PC,bl), first); break; + case BL_MOB: status_calc_mob_(BL_CAST(BL_MOB,bl), first); break; + case BL_PET: status_calc_pet_(BL_CAST(BL_PET,bl), first); break; + case BL_HOM: status_calc_homunculus_(BL_CAST(BL_HOM,bl), first); break; + case BL_MER: status_calc_mercenary_(BL_CAST(BL_MER,bl), first); break; + case BL_ELEM: status_calc_elemental_(BL_CAST(BL_ELEM,bl), first); break; + case BL_NPC: status_calc_npc_(BL_CAST(BL_NPC,bl), first); break; } } @@ -6300,43 +6293,43 @@ int status_get_sc_def(struct block_list *bl, enum sc_type type, int rate, int ti else tick -= (status->vit + status->luk) / 20 * 1000; break; - case SC_BURNING: - tick -= 75 * status->luk + 125 * status->agi; - tick = max(tick,5000); // Minimum Duration 5s. - break; - case SC_FROSTMISTY: - tick -= 1000 * ((status->vit + status->dex) / 20); - tick = max(tick,6000); // Minimum Duration 10s. - break; - case SC_OBLIVIONCURSE: // 100% - (100 - 0.8 x INT) - sc_def = 100 - ( 100 - status->int_* 8 / 10 ); - sc_def = max(sc_def, 5); // minimum of 5% - break; - case SC_WUGBITE: // {(Base Success chance) - (Target's AGI / 4)} - rate -= status->agi*100/4; - rate = max(rate,5000); // minimum of 50% - break; - case SC_ELECTRICSHOCKER: - if( bl->type == BL_MOB ) - tick -= 1000 * (status->agi/10); - break; - case SC_CRYSTALIZE: - tick -= (1000*(status->vit/10))+(status_get_lv(bl)/50); - break; - case SC_MANDRAGORA: - sc_def = (status->vit+status->luk)/5; - break; - case SC_KYOUGAKU: - tick -= 1000 * status_get_int(bl) / 20; - break; - case SC_NEEDLE_OF_PARALYZE: - tick -= 50 * (status->vit + status->luk); //(1000/20); - break; - default: - //Effect that cannot be reduced? Likely a buff. - if (!(rnd()%10000 < rate)) - return 0; - return tick?tick:1; + case SC_BURNING: + tick -= 75 * status->luk + 125 * status->agi; + tick = max(tick,5000); // Minimum Duration 5s. + break; + case SC_FROSTMISTY: + tick -= 1000 * ((status->vit + status->dex) / 20); + tick = max(tick,6000); // Minimum Duration 10s. + break; + case SC_OBLIVIONCURSE: // 100% - (100 - 0.8 x INT) + sc_def = 100 - ( 100 - status->int_* 8 / 10 ); + sc_def = max(sc_def, 5); // minimum of 5% + break; + case SC_WUGBITE: // {(Base Success chance) - (Target's AGI / 4)} + rate -= status->agi*100/4; + rate = max(rate,5000); // minimum of 50% + break; + case SC_ELECTRICSHOCKER: + if( bl->type == BL_MOB ) + tick -= 1000 * (status->agi/10); + break; + case SC_CRYSTALIZE: + tick -= (1000*(status->vit/10))+(status_get_lv(bl)/50); + break; + case SC_MANDRAGORA: + sc_def = (status->vit+status->luk)/5; + break; + case SC_KYOUGAKU: + tick -= 1000 * status_get_int(bl) / 20; + break; + case SC_NEEDLE_OF_PARALYZE: + tick -= 50 * (status->vit + status->luk); //(1000/20); + break; + default: + //Effect that cannot be reduced? Likely a buff. + if (!(rnd()%10000 < rate)) + return 0; + return tick?tick:1; } if (sd) { @@ -6528,27 +6521,26 @@ int status_change_start(struct block_list* bl,enum sc_type type,int rate,int val if( type >= SC_COMMON_MIN && type <= SC_COMMON_MAX) // Confirmed. return 0; // Immune to status ailements switch( type ) { - case SC_QUAGMIRE://Tester said it protects against this and decrease agi. - case SC_DEC_AGI: - case SC_BURNING: - case SC_FROSTMISTY: - //case SC_WHITEIMPRISON://Need confirm. Protected against this in the past. [Rytech] - case SC_MARSHOFABYSS: - case SC_TOXIN: - case SC_PARALYSE: - case SC_VENOMBLEED: - case SC_MAGICMUSHROOM: - case SC_DEATHHURT: - case SC_PYREXIA: - case SC_OBLIVIONCURSE: - case SC_LEECHESEND: - case SC_CRYSTALIZE: ////08/31/2011 - Class Balance Changes - case SC_DEEP_SLEEP: - case SC_MANDRAGORA: + case SC_QUAGMIRE://Tester said it protects against this and decrease agi. + case SC_DEC_AGI: + case SC_BURNING: + case SC_FROSTMISTY: + //case SC_WHITEIMPRISON://Need confirm. Protected against this in the past. [Rytech] + case SC_MARSHOFABYSS: + case SC_TOXIN: + case SC_PARALYSE: + case SC_VENOMBLEED: + case SC_MAGICMUSHROOM: + case SC_DEATHHURT: + case SC_PYREXIA: + case SC_OBLIVIONCURSE: + case SC_LEECHESEND: + case SC_CRYSTALIZE: ////08/31/2011 - Class Balance Changes + case SC_DEEP_SLEEP: + case SC_MANDRAGORA: return 0; } - } - else if( sc->data[SC_INSPIRATION] ) { + } else if( sc->data[SC_INSPIRATION] ) { if( type >= SC_COMMON_MIN && type <= SC_COMMON_MAX ) return 0; // Immune to status ailements switch( type ) { @@ -6590,286 +6582,286 @@ int status_change_start(struct block_list* bl,enum sc_type type,int rate,int val || (type==SC_ANGRIFFS_MODUS && sc->data[SC_GOLDENE_FERSE]) ) return 0; - case SC_STONE: - if(sc->data[SC_POWER_OF_GAIA]) - return 0; - case SC_FREEZE: - //Undead are immune to Freeze/Stone - if (undead_flag && !(flag&1)) - return 0; - case SC_DEEP_SLEEP: - case SC_SLEEP: - case SC_STUN: - case SC_FROSTMISTY: - case SC_CRYSTALIZE: - if (sc->opt1) - return 0; //Cannot override other opt1 status changes. [Skotlex] - if((type == SC_FREEZE || type == SC_FROSTMISTY || type == SC_CRYSTALIZE) && sc->data[SC_WARMER]) - return 0; //Immune to Frozen and Freezing status if under Warmer status. [Jobbie] - break; - - //There all like berserk, do not everlap each other - case SC__BLOODYLUST: - if(!sd) return 0; //should only affect player - case SC_BERSERK: - if (((type == SC_BERSERK) && (sc->data[SC_SATURDAY_NIGHT_FEVER] || sc->data[SC__BLOODYLUST])) - || ((type == SC__BLOODYLUST) && (sc->data[SC_SATURDAY_NIGHT_FEVER] || sc->data[SC_BERSERK])) - ) - return 0; + case SC_STONE: + if(sc->data[SC_POWER_OF_GAIA]) + return 0; + case SC_FREEZE: + //Undead are immune to Freeze/Stone + if (undead_flag && !(flag&1)) + return 0; + case SC_DEEP_SLEEP: + case SC_SLEEP: + case SC_STUN: + case SC_FROSTMISTY: + case SC_CRYSTALIZE: + if (sc->opt1) + return 0; //Cannot override other opt1 status changes. [Skotlex] + if((type == SC_FREEZE || type == SC_FROSTMISTY || type == SC_CRYSTALIZE) && sc->data[SC_WARMER]) + return 0; //Immune to Frozen and Freezing status if under Warmer status. [Jobbie] break; - case SC_BURNING: - if(sc->opt1 || sc->data[SC_FROSTMISTY]) - return 0; - break; + //There all like berserk, do not everlap each other + case SC__BLOODYLUST: + if(!sd) return 0; //should only affect player + case SC_BERSERK: + if (((type == SC_BERSERK) && (sc->data[SC_SATURDAY_NIGHT_FEVER] || sc->data[SC__BLOODYLUST])) + || ((type == SC__BLOODYLUST) && (sc->data[SC_SATURDAY_NIGHT_FEVER] || sc->data[SC_BERSERK])) + ) + return 0; + break; - case SC_CRUCIS: - //Only affects demons and undead element (but not players) - if((!undead_flag && status->race!=RC_DEMON) || bl->type == BL_PC) - return 0; - break; - case SC_LEXAETERNA: - if( (sc->data[SC_STONE] && sc->opt1 == OPT1_STONE) || sc->data[SC_FREEZE] ) - return 0; - break; - case SC_KYRIE: - if (bl->type == BL_MOB) - return 0; - break; - case SC_OVERTHRUST: - if (sc->data[SC_OVERTHRUSTMAX]) - return 0; //Overthrust can't take effect if under Max Overthrust. [Skotlex] - case SC_OVERTHRUSTMAX: - if( sc->option&OPTION_MADOGEAR ) - return 0;//Overthrust and Overthrust Max cannot be used on Mado Gear [Ind] - break; - case SC_ADRENALINE: - if(sd && !pc_check_weapontype(sd,skill->get_weapontype(BS_ADRENALINE))) - return 0; - if (sc->data[SC_QUAGMIRE] || - sc->data[SC_DEC_AGI] || - sc->option&OPTION_MADOGEAR //Adrenaline doesn't affect Mado Gear [Ind] - ) - return 0; - break; - case SC_ADRENALINE2: - if(sd && !pc_check_weapontype(sd,skill->get_weapontype(BS_ADRENALINE2))) - return 0; - if (sc->data[SC_QUAGMIRE] || - sc->data[SC_DEC_AGI] - ) - return 0; - break; - case SC_MAGNIFICAT: - if( sc->data[SC_OFFERTORIUM] || sc->option&OPTION_MADOGEAR ) //Mado is immune to magnificat - return 0; + case SC_BURNING: + if(sc->opt1 || sc->data[SC_FROSTMISTY]) + return 0; break; - case SC_ONEHANDQUICKEN: - case SC_MER_QUICKEN: - case SC_TWOHANDQUICKEN: - if(sc->data[SC_DEC_AGI]) - return 0; - case SC_INC_AGI: - if(sd && pc_issit(sd)){ - pc->setstand(sd); - clif->standing(&sd->bl); - } + case SC_CRUCIS: + //Only affects demons and undead element (but not players) + if((!undead_flag && status->race!=RC_DEMON) || bl->type == BL_PC) + return 0; + break; + case SC_LEXAETERNA: + if( (sc->data[SC_STONE] && sc->opt1 == OPT1_STONE) || sc->data[SC_FREEZE] ) + return 0; + break; + case SC_KYRIE: + if (bl->type == BL_MOB) + return 0; + break; + case SC_OVERTHRUST: + if (sc->data[SC_OVERTHRUSTMAX]) + return 0; //Overthrust can't take effect if under Max Overthrust. [Skotlex] + case SC_OVERTHRUSTMAX: + if( sc->option&OPTION_MADOGEAR ) + return 0;//Overthrust and Overthrust Max cannot be used on Mado Gear [Ind] + break; + case SC_ADRENALINE: + if(sd && !pc_check_weapontype(sd,skill->get_weapontype(BS_ADRENALINE))) + return 0; + if (sc->data[SC_QUAGMIRE] || + sc->data[SC_DEC_AGI] || + sc->option&OPTION_MADOGEAR //Adrenaline doesn't affect Mado Gear [Ind] + ) + return 0; + break; + case SC_ADRENALINE2: + if(sd && !pc_check_weapontype(sd,skill->get_weapontype(BS_ADRENALINE2))) + return 0; + if (sc->data[SC_QUAGMIRE] || + sc->data[SC_DEC_AGI] + ) + return 0; + break; + case SC_MAGNIFICAT: + if( sc->data[SC_OFFERTORIUM] || sc->option&OPTION_MADOGEAR ) //Mado is immune to magnificat + return 0; + break; + case SC_ONEHANDQUICKEN: + case SC_MER_QUICKEN: + case SC_TWOHANDQUICKEN: + if(sc->data[SC_DEC_AGI]) + return 0; - case SC_CONCENTRATION: - case SC_SPEARQUICKEN: - case SC_TRUESIGHT: - case SC_WINDWALK: - case SC_CARTBOOST: - case SC_ASSNCROS: - if (sc->data[SC_QUAGMIRE]) - return 0; - if(sc->option&OPTION_MADOGEAR) - return 0;//Mado is immune to increase agi, wind walk, cart boost, etc (others above) [Ind] - break; - case SC_CLOAKING: - //Avoid cloaking with no wall and low skill level. [Skotlex] - //Due to the cloaking card, we have to check the wall versus to known - //skill level rather than the used one. [Skotlex] - //if (sd && val1 < 3 && skill_check_cloaking(bl,NULL)) - if( sd && pc->checkskill(sd, AS_CLOAKING) < 3 && !skill->check_cloaking(bl,NULL) ) - return 0; - break; - case SC_MODECHANGE: - { - int mode; - struct status_data *bstatus = status_get_base_status(bl); - if (!bstatus) return 0; - if (sc->data[type]) - { //Pile up with previous values. - if(!val2) val2 = sc->data[type]->val2; - val3 |= sc->data[type]->val3; - val4 |= sc->data[type]->val4; - } - mode = val2?val2:bstatus->mode; //Base mode - if (val4) mode&=~val4; //Del mode - if (val3) mode|= val3; //Add mode - if (mode == bstatus->mode) { //No change. - if (sc->data[type]) //Abort previous status - return status_change_end(bl, type, INVALID_TIMER); - return 0; - } - } - break; - //Strip skills, need to divest something or it fails. - case SC_NOEQUIPWEAPON: - if (sd && !(flag&4)) { //apply sc anyway if loading saved sc_data - int i; - opt_flag = 0; //Reuse to check success condition. - if(sd->bonus.unstripable_equip&EQP_WEAPON) + case SC_INC_AGI: + if(sd && pc_issit(sd)){ + pc->setstand(sd); + clif->standing(&sd->bl); + } + + case SC_CONCENTRATION: + case SC_SPEARQUICKEN: + case SC_TRUESIGHT: + case SC_WINDWALK: + case SC_CARTBOOST: + case SC_ASSNCROS: + if (sc->data[SC_QUAGMIRE]) + return 0; + if(sc->option&OPTION_MADOGEAR) + return 0;//Mado is immune to increase agi, wind walk, cart boost, etc (others above) [Ind] + break; + case SC_CLOAKING: + //Avoid cloaking with no wall and low skill level. [Skotlex] + //Due to the cloaking card, we have to check the wall versus to known + //skill level rather than the used one. [Skotlex] + //if (sd && val1 < 3 && skill_check_cloaking(bl,NULL)) + if( sd && pc->checkskill(sd, AS_CLOAKING) < 3 && !skill->check_cloaking(bl,NULL) ) + return 0; + break; + case SC_MODECHANGE: + { + int mode; + struct status_data *bstatus = status_get_base_status(bl); + if (!bstatus) return 0; + if (sc->data[type]) + { //Pile up with previous values. + if(!val2) val2 = sc->data[type]->val2; + val3 |= sc->data[type]->val3; + val4 |= sc->data[type]->val4; + } + mode = val2?val2:bstatus->mode; //Base mode + if (val4) mode&=~val4; //Del mode + if (val3) mode|= val3; //Add mode + if (mode == bstatus->mode) { //No change. + if (sc->data[type]) //Abort previous status + return status_change_end(bl, type, INVALID_TIMER); return 0; + } + } + break; + //Strip skills, need to divest something or it fails. + case SC_NOEQUIPWEAPON: + if (sd && !(flag&4)) { //apply sc anyway if loading saved sc_data + int i; + opt_flag = 0; //Reuse to check success condition. + if(sd->bonus.unstripable_equip&EQP_WEAPON) + return 0; - i = sd->equip_index[EQI_HAND_R]; - if (i>=0 && sd->inventory_data[i] && sd->inventory_data[i]->type == IT_WEAPON) { - opt_flag|=2; + i = sd->equip_index[EQI_HAND_R]; + if (i>=0 && sd->inventory_data[i] && sd->inventory_data[i]->type == IT_WEAPON) { + opt_flag|=2; + pc->unequipitem(sd,i,3); + } + if (!opt_flag) return 0; + } + if (tick == 1) return 1; //Minimal duration: Only strip without causing the SC + break; + case SC_NOEQUIPSHIELD: + if( val2 == 1 ) val2 = 0; //GX effect. Do not take shield off.. + else + if (sd && !(flag&4)) { + int i; + if(sd->bonus.unstripable_equip&EQP_SHIELD) + return 0; + i = sd->equip_index[EQI_HAND_L]; + if ( i < 0 || !sd->inventory_data[i] || sd->inventory_data[i]->type != IT_ARMOR ) + return 0; pc->unequipitem(sd,i,3); } - if (!opt_flag) return 0; - } - if (tick == 1) return 1; //Minimal duration: Only strip without causing the SC - break; - case SC_NOEQUIPSHIELD: - if( val2 == 1 ) val2 = 0; //GX effect. Do not take shield off.. - else - if (sd && !(flag&4)) { - int i; - if(sd->bonus.unstripable_equip&EQP_SHIELD) + if (tick == 1) return 1; //Minimal duration: Only strip without causing the SC + break; + case SC_NOEQUIPARMOR: + if (sd && !(flag&4)) { + int i; + if(sd->bonus.unstripable_equip&EQP_ARMOR) + return 0; + i = sd->equip_index[EQI_ARMOR]; + if ( i < 0 || !sd->inventory_data[i] ) + return 0; + pc->unequipitem(sd,i,3); + } + if (tick == 1) return 1; //Minimal duration: Only strip without causing the SC + break; + case SC_NOEQUIPHELM: + if (sd && !(flag&4)) { + int i; + if(sd->bonus.unstripable_equip&EQP_HELM) + return 0; + i = sd->equip_index[EQI_HEAD_TOP]; + if ( i < 0 || !sd->inventory_data[i] ) + return 0; + pc->unequipitem(sd,i,3); + } + if (tick == 1) return 1; //Minimal duration: Only strip without causing the SC + break; + case SC_MER_FLEE: + case SC_MER_ATK: + case SC_MER_HP: + case SC_MER_SP: + case SC_MER_HIT: + if( bl->type != BL_MER ) + return 0; // Stats only for Mercenaries + break; + case SC_FOOD_STR: + if (sc->data[SC_FOOD_STR_CASH] && sc->data[SC_FOOD_STR_CASH]->val1 > val1) return 0; - i = sd->equip_index[EQI_HAND_L]; - if ( i < 0 || !sd->inventory_data[i] || sd->inventory_data[i]->type != IT_ARMOR ) + break; + case SC_FOOD_AGI: + if (sc->data[SC_FOOD_AGI_CASH] && sc->data[SC_FOOD_AGI_CASH]->val1 > val1) return 0; - pc->unequipitem(sd,i,3); - } - if (tick == 1) return 1; //Minimal duration: Only strip without causing the SC - break; - case SC_NOEQUIPARMOR: - if (sd && !(flag&4)) { - int i; - if(sd->bonus.unstripable_equip&EQP_ARMOR) + break; + case SC_FOOD_VIT: + if (sc->data[SC_FOOD_VIT_CASH] && sc->data[SC_FOOD_VIT_CASH]->val1 > val1) return 0; - i = sd->equip_index[EQI_ARMOR]; - if ( i < 0 || !sd->inventory_data[i] ) + break; + case SC_FOOD_INT: + if (sc->data[SC_FOOD_INT_CASH] && sc->data[SC_FOOD_INT_CASH]->val1 > val1) return 0; - pc->unequipitem(sd,i,3); - } - if (tick == 1) return 1; //Minimal duration: Only strip without causing the SC - break; - case SC_NOEQUIPHELM: - if (sd && !(flag&4)) { - int i; - if(sd->bonus.unstripable_equip&EQP_HELM) + break; + case SC_FOOD_DEX: + if (sc->data[SC_FOOD_DEX_CASH] && sc->data[SC_FOOD_DEX_CASH]->val1 > val1) return 0; - i = sd->equip_index[EQI_HEAD_TOP]; - if ( i < 0 || !sd->inventory_data[i] ) + break; + case SC_FOOD_LUK: + if (sc->data[SC_FOOD_LUK_CASH] && sc->data[SC_FOOD_LUK_CASH]->val1 > val1) return 0; - pc->unequipitem(sd,i,3); - } - if (tick == 1) return 1; //Minimal duration: Only strip without causing the SC - break; - case SC_MER_FLEE: - case SC_MER_ATK: - case SC_MER_HP: - case SC_MER_SP: - case SC_MER_HIT: - if( bl->type != BL_MER ) - return 0; // Stats only for Mercenaries - break; - case SC_FOOD_STR: - if (sc->data[SC_FOOD_STR_CASH] && sc->data[SC_FOOD_STR_CASH]->val1 > val1) - return 0; - break; - case SC_FOOD_AGI: - if (sc->data[SC_FOOD_AGI_CASH] && sc->data[SC_FOOD_AGI_CASH]->val1 > val1) - return 0; - break; - case SC_FOOD_VIT: - if (sc->data[SC_FOOD_VIT_CASH] && sc->data[SC_FOOD_VIT_CASH]->val1 > val1) - return 0; - break; - case SC_FOOD_INT: - if (sc->data[SC_FOOD_INT_CASH] && sc->data[SC_FOOD_INT_CASH]->val1 > val1) - return 0; - break; - case SC_FOOD_DEX: - if (sc->data[SC_FOOD_DEX_CASH] && sc->data[SC_FOOD_DEX_CASH]->val1 > val1) - return 0; - break; - case SC_FOOD_LUK: - if (sc->data[SC_FOOD_LUK_CASH] && sc->data[SC_FOOD_LUK_CASH]->val1 > val1) - return 0; - break; - case SC_FOOD_STR_CASH: - if (sc->data[SC_FOOD_STR] && sc->data[SC_FOOD_STR]->val1 > val1) - return 0; - break; - case SC_FOOD_AGI_CASH: - if (sc->data[SC_FOOD_AGI] && sc->data[SC_FOOD_AGI]->val1 > val1) - return 0; - break; - case SC_FOOD_VIT_CASH: - if (sc->data[SC_FOOD_VIT] && sc->data[SC_FOOD_VIT]->val1 > val1) - return 0; - break; - case SC_FOOD_INT_CASH: - if (sc->data[SC_FOOD_INT] && sc->data[SC_FOOD_INT]->val1 > val1) - return 0; - break; - case SC_FOOD_DEX_CASH: - if (sc->data[SC_FOOD_DEX] && sc->data[SC_FOOD_DEX]->val1 > val1) - return 0; - break; - case SC_FOOD_LUK_CASH: - if (sc->data[SC_FOOD_LUK] && sc->data[SC_FOOD_LUK]->val1 > val1) - return 0; - break; - case SC_CAMOUFLAGE: - if( sd && pc->checkskill(sd, RA_CAMOUFLAGE) < 3 && !skill->check_camouflage(bl,NULL) ) - return 0; - break; - case SC__STRIPACCESSARY: - if( sd ) { - int i = -1; - if( !(sd->bonus.unstripable_equip&EQI_ACC_L) ) { - i = sd->equip_index[EQI_ACC_L]; - if( i >= 0 && sd->inventory_data[i] && sd->inventory_data[i]->type == IT_ARMOR ) - pc->unequipitem(sd,i,3); //L-Accessory - } if( !(sd->bonus.unstripable_equip&EQI_ACC_R) ) { - i = sd->equip_index[EQI_ACC_R]; - if( i >= 0 && sd->inventory_data[i] && sd->inventory_data[i]->type == IT_ARMOR ) - pc->unequipitem(sd,i,3); //R-Accessory - } - if( i < 0 ) + break; + case SC_FOOD_STR_CASH: + if (sc->data[SC_FOOD_STR] && sc->data[SC_FOOD_STR]->val1 > val1) return 0; - } - if (tick == 1) return 1; //Minimal duration: Only strip without causing the SC - break; - case SC_TOXIN: - case SC_PARALYSE: - case SC_VENOMBLEED: - case SC_MAGICMUSHROOM: - case SC_DEATHHURT: - case SC_PYREXIA: - case SC_OBLIVIONCURSE: - case SC_LEECHESEND: - { // it doesn't stack or even renewed - int i = SC_TOXIN; - for(; i<= SC_LEECHESEND; i++) - if(sc->data[i]) return 0; - } - break; - case SC_SATURDAY_NIGHT_FEVER: - if (sc->data[SC_BERSERK] || sc->data[SC_INSPIRATION] || sc->data[SC__BLOODYLUST]) - return 0; break; - case SC_OFFERTORIUM: - if (sc->data[SC_MAGNIFICAT]) - return 0; + case SC_FOOD_AGI_CASH: + if (sc->data[SC_FOOD_AGI] && sc->data[SC_FOOD_AGI]->val1 > val1) + return 0; break; + case SC_FOOD_VIT_CASH: + if (sc->data[SC_FOOD_VIT] && sc->data[SC_FOOD_VIT]->val1 > val1) + return 0; + break; + case SC_FOOD_INT_CASH: + if (sc->data[SC_FOOD_INT] && sc->data[SC_FOOD_INT]->val1 > val1) + return 0; + break; + case SC_FOOD_DEX_CASH: + if (sc->data[SC_FOOD_DEX] && sc->data[SC_FOOD_DEX]->val1 > val1) + return 0; + break; + case SC_FOOD_LUK_CASH: + if (sc->data[SC_FOOD_LUK] && sc->data[SC_FOOD_LUK]->val1 > val1) + return 0; + break; + case SC_CAMOUFLAGE: + if( sd && pc->checkskill(sd, RA_CAMOUFLAGE) < 3 && !skill->check_camouflage(bl,NULL) ) + return 0; + break; + case SC__STRIPACCESSARY: + if( sd ) { + int i = -1; + if( !(sd->bonus.unstripable_equip&EQI_ACC_L) ) { + i = sd->equip_index[EQI_ACC_L]; + if( i >= 0 && sd->inventory_data[i] && sd->inventory_data[i]->type == IT_ARMOR ) + pc->unequipitem(sd,i,3); //L-Accessory + } if( !(sd->bonus.unstripable_equip&EQI_ACC_R) ) { + i = sd->equip_index[EQI_ACC_R]; + if( i >= 0 && sd->inventory_data[i] && sd->inventory_data[i]->type == IT_ARMOR ) + pc->unequipitem(sd,i,3); //R-Accessory + } + if( i < 0 ) + return 0; + } + if (tick == 1) return 1; //Minimal duration: Only strip without causing the SC + break; + case SC_TOXIN: + case SC_PARALYSE: + case SC_VENOMBLEED: + case SC_MAGICMUSHROOM: + case SC_DEATHHURT: + case SC_PYREXIA: + case SC_OBLIVIONCURSE: + case SC_LEECHESEND: + { // it doesn't stack or even renewed + int i = SC_TOXIN; + for(; i<= SC_LEECHESEND; i++) + if(sc->data[i]) return 0; + } + break; + case SC_SATURDAY_NIGHT_FEVER: + if (sc->data[SC_BERSERK] || sc->data[SC_INSPIRATION] || sc->data[SC__BLOODYLUST]) + return 0; + break; + case SC_OFFERTORIUM: + if (sc->data[SC_MAGNIFICAT]) + return 0; + break; } //Check for BOSS resistances @@ -6915,236 +6907,236 @@ int status_change_start(struct block_list* bl,enum sc_type type,int rate,int val //Before overlapping fail, one must check for status cured. switch (type) { - case SC_BLESSING: - //TO-DO Blessing and Agi up should do 1 damage against players on Undead Status, even on PvM - //but cannot be plagiarized (this requires aegis investigation on packets and official behavior) [Brainstorm] - if ((!undead_flag && status->race!=RC_DEMON) || bl->type == BL_PC) { - status_change_end(bl, SC_CURSE, INVALID_TIMER); - if (sc->data[SC_STONE] && sc->opt1 == OPT1_STONE) - status_change_end(bl, SC_STONE, INVALID_TIMER); - } - break; - case SC_INC_AGI: - status_change_end(bl, SC_DEC_AGI, INVALID_TIMER); - break; - case SC_QUAGMIRE: - status_change_end(bl, SC_CONCENTRATION, INVALID_TIMER); - status_change_end(bl, SC_TRUESIGHT, INVALID_TIMER); - status_change_end(bl, SC_WINDWALK, INVALID_TIMER); - //Also blocks the ones below... - case SC_DEC_AGI: - status_change_end(bl, SC_CARTBOOST, INVALID_TIMER); - //Also blocks the ones below... - case SC_DONTFORGETME: - status_change_end(bl, SC_INC_AGI, INVALID_TIMER); - status_change_end(bl, SC_ADRENALINE, INVALID_TIMER); - status_change_end(bl, SC_ADRENALINE2, INVALID_TIMER); - status_change_end(bl, SC_SPEARQUICKEN, INVALID_TIMER); - status_change_end(bl, SC_TWOHANDQUICKEN, INVALID_TIMER); - status_change_end(bl, SC_ONEHANDQUICKEN, INVALID_TIMER); - status_change_end(bl, SC_MER_QUICKEN, INVALID_TIMER); - status_change_end(bl, SC_ACCELERATION, INVALID_TIMER); - break; - case SC_ONEHANDQUICKEN: - //Removes the Aspd potion effect, as reported by Vicious. [Skotlex] - status_change_end(bl, SC_ATTHASTE_POTION1, INVALID_TIMER); - status_change_end(bl, SC_ATTHASTE_POTION2, INVALID_TIMER); - status_change_end(bl, SC_ATTHASTE_POTION3, INVALID_TIMER); - status_change_end(bl, SC_ATTHASTE_INFINITY, INVALID_TIMER); - break; - case SC_OVERTHRUSTMAX: - //Cancels Normal Overthrust. [Skotlex] - status_change_end(bl, SC_OVERTHRUST, INVALID_TIMER); - break; - case SC_KYRIE: - //Cancels Assumptio - status_change_end(bl, SC_ASSUMPTIO, INVALID_TIMER); - break; - case SC_DELUGE: - if (sc->data[SC_FOGWALL] && sc->data[SC_BLIND]) - status_change_end(bl, SC_BLIND, INVALID_TIMER); - break; - case SC_SILENCE: - if (sc->data[SC_GOSPEL] && sc->data[SC_GOSPEL]->val4 == BCT_SELF) - status_change_end(bl, SC_GOSPEL, INVALID_TIMER); - break; - case SC_HIDING: - status_change_end(bl, SC_RG_CCONFINE_M, INVALID_TIMER); - status_change_end(bl, SC_RG_CCONFINE_S, INVALID_TIMER); - break; - case SC__BLOODYLUST: - case SC_BERSERK: - if(battle_config.berserk_cancels_buffs) { - status_change_end(bl, SC_ONEHANDQUICKEN, INVALID_TIMER); + case SC_BLESSING: + //TO-DO Blessing and Agi up should do 1 damage against players on Undead Status, even on PvM + //but cannot be plagiarized (this requires aegis investigation on packets and official behavior) [Brainstorm] + if ((!undead_flag && status->race!=RC_DEMON) || bl->type == BL_PC) { + status_change_end(bl, SC_CURSE, INVALID_TIMER); + if (sc->data[SC_STONE] && sc->opt1 == OPT1_STONE) + status_change_end(bl, SC_STONE, INVALID_TIMER); + } + break; + case SC_INC_AGI: + status_change_end(bl, SC_DEC_AGI, INVALID_TIMER); + break; + case SC_QUAGMIRE: + status_change_end(bl, SC_CONCENTRATION, INVALID_TIMER); + status_change_end(bl, SC_TRUESIGHT, INVALID_TIMER); + status_change_end(bl, SC_WINDWALK, INVALID_TIMER); + //Also blocks the ones below... + case SC_DEC_AGI: + status_change_end(bl, SC_CARTBOOST, INVALID_TIMER); + //Also blocks the ones below... + case SC_DONTFORGETME: + status_change_end(bl, SC_INC_AGI, INVALID_TIMER); + status_change_end(bl, SC_ADRENALINE, INVALID_TIMER); + status_change_end(bl, SC_ADRENALINE2, INVALID_TIMER); + status_change_end(bl, SC_SPEARQUICKEN, INVALID_TIMER); status_change_end(bl, SC_TWOHANDQUICKEN, INVALID_TIMER); - status_change_end(bl, SC_LKCONCENTRATION, INVALID_TIMER); - status_change_end(bl, SC_PARRYING, INVALID_TIMER); - status_change_end(bl, SC_AURABLADE, INVALID_TIMER); + status_change_end(bl, SC_ONEHANDQUICKEN, INVALID_TIMER); status_change_end(bl, SC_MER_QUICKEN, INVALID_TIMER); - } -#ifdef RENEWAL - else { - status_change_end(bl, SC_TWOHANDQUICKEN, INVALID_TIMER); - } -#endif - break; - case SC_ASSUMPTIO: - status_change_end(bl, SC_KYRIE, INVALID_TIMER); - status_change_end(bl, SC_KAITE, INVALID_TIMER); - break; - case SC_KAITE: - status_change_end(bl, SC_ASSUMPTIO, INVALID_TIMER); - break; - case SC_CARTBOOST: - if(sc->data[SC_DEC_AGI]) - { //Cancel Decrease Agi, but take no further effect [Skotlex] - status_change_end(bl, SC_DEC_AGI, INVALID_TIMER); - return 0; - } - break; - case SC_FUSION: - status_change_end(bl, SC_SOULLINK, INVALID_TIMER); - break; - case SC_GS_ADJUSTMENT: - status_change_end(bl, SC_GS_MADNESSCANCEL, INVALID_TIMER); - break; - case SC_GS_MADNESSCANCEL: - status_change_end(bl, SC_GS_ADJUSTMENT, INVALID_TIMER); - break; - //NPC_CHANGEUNDEAD will debuff Blessing and Agi Up - case SC_PROPERTYUNDEAD: - status_change_end(bl, SC_BLESSING, INVALID_TIMER); - status_change_end(bl, SC_INC_AGI, INVALID_TIMER); - break; - case SC_FOOD_STR: - status_change_end(bl, SC_FOOD_STR_CASH, INVALID_TIMER); - break; - case SC_FOOD_AGI: - status_change_end(bl, SC_FOOD_AGI_CASH, INVALID_TIMER); - break; - case SC_FOOD_VIT: - status_change_end(bl, SC_FOOD_VIT_CASH, INVALID_TIMER); - break; - case SC_FOOD_INT: - status_change_end(bl, SC_FOOD_INT_CASH, INVALID_TIMER); - break; - case SC_FOOD_DEX: - status_change_end(bl, SC_FOOD_DEX_CASH, INVALID_TIMER); - break; - case SC_FOOD_LUK: - status_change_end(bl, SC_FOOD_LUK_CASH, INVALID_TIMER); - break; - case SC_FOOD_STR_CASH: - status_change_end(bl, SC_FOOD_STR, INVALID_TIMER); - break; - case SC_FOOD_AGI_CASH: - status_change_end(bl, SC_FOOD_AGI, INVALID_TIMER); - break; - case SC_FOOD_VIT_CASH: - status_change_end(bl, SC_FOOD_VIT, INVALID_TIMER); - break; - case SC_FOOD_INT_CASH: - status_change_end(bl, SC_FOOD_INT, INVALID_TIMER); - break; - case SC_FOOD_DEX_CASH: - status_change_end(bl, SC_FOOD_DEX, INVALID_TIMER); - break; - case SC_FOOD_LUK_CASH: - status_change_end(bl, SC_FOOD_LUK, INVALID_TIMER); - break; - case SC_ENDURE: - if( val4 ) - status_change_end(bl, SC_LKCONCENTRATION, INVALID_TIMER); - break; - case SC_FIGHTINGSPIRIT: - status_change_end(bl, type, INVALID_TIMER); // Remove previous one. - break; - case SC_MARSHOFABYSS: - status_change_end(bl, SC_INCAGI, INVALID_TIMER); - status_change_end(bl, SC_WINDWALK, INVALID_TIMER); - status_change_end(bl, SC_ATTHASTE_POTION1, INVALID_TIMER); - status_change_end(bl, SC_ATTHASTE_POTION2, INVALID_TIMER); - status_change_end(bl, SC_ATTHASTE_POTION3, INVALID_TIMER); - status_change_end(bl, SC_ATTHASTE_INFINITY, INVALID_TIMER); - break; - case SC_SWING: - case SC_SYMPHONY_LOVE: - case SC_MOONLIT_SERENADE: - case SC_RUSH_WINDMILL: - case SC_ECHOSONG: - case SC_HARMONIZE: //group A doesn't overlap - if (type != SC_SWING) status_change_end(bl, SC_SWING, INVALID_TIMER); - if (type != SC_SYMPHONY_LOVE) status_change_end(bl, SC_SYMPHONY_LOVE, INVALID_TIMER); - if (type != SC_MOONLIT_SERENADE) status_change_end(bl, SC_MOONLIT_SERENADE, INVALID_TIMER); - if (type != SC_RUSH_WINDMILL) status_change_end(bl, SC_RUSH_WINDMILL, INVALID_TIMER); - if (type != SC_ECHOSONG) status_change_end(bl, SC_ECHOSONG, INVALID_TIMER); - if (type != SC_HARMONIZE) status_change_end(bl, SC_HARMONIZE, INVALID_TIMER); - break; - case SC_SIREN: - case SC_DEEP_SLEEP: - case SC_GLOOMYDAY: - case SC_SONG_OF_MANA: - case SC_DANCE_WITH_WUG: - case SC_SATURDAY_NIGHT_FEVER: - case SC_LERADS_DEW: - case SC_MELODYOFSINK: - case SC_BEYOND_OF_WARCRY: - case SC_UNLIMITED_HUMMING_VOICE: //group B - if (type != SC_SIREN) status_change_end(bl, SC_SIREN, INVALID_TIMER); - if (type != SC_DEEP_SLEEP) status_change_end(bl, SC_DEEP_SLEEP, INVALID_TIMER); - if (type != SC_LERADS_DEW) status_change_end(bl, SC_LERADS_DEW, INVALID_TIMER); - if (type != SC_MELODYOFSINK) status_change_end(bl, SC_MELODYOFSINK, INVALID_TIMER); - if (type != SC_BEYOND_OF_WARCRY) status_change_end(bl, SC_BEYOND_OF_WARCRY, INVALID_TIMER); - if (type != SC_UNLIMITED_HUMMING_VOICE) status_change_end(bl, SC_UNLIMITED_HUMMING_VOICE, INVALID_TIMER); - if (type != SC_GLOOMYDAY) { - status_change_end(bl, SC_GLOOMYDAY, INVALID_TIMER); - status_change_end(bl, SC_GLOOMYDAY_SK, INVALID_TIMER); - } - if (type != SC_SONG_OF_MANA) status_change_end(bl, SC_SONG_OF_MANA, INVALID_TIMER); - if (type != SC_DANCE_WITH_WUG) status_change_end(bl, SC_DANCE_WITH_WUG, INVALID_TIMER); - if (type != SC_SATURDAY_NIGHT_FEVER) { - if (sc->data[SC_SATURDAY_NIGHT_FEVER]) { - sc->data[SC_SATURDAY_NIGHT_FEVER]->val2 = 0; //mark to not lose hp - status_change_end(bl, SC_SATURDAY_NIGHT_FEVER, INVALID_TIMER); - } - } - break; - case SC_REFLECTSHIELD: - status_change_end(bl, SC_LG_REFLECTDAMAGE, INVALID_TIMER); - break; - case SC_LG_REFLECTDAMAGE: - status_change_end(bl, SC_REFLECTSHIELD, INVALID_TIMER); - break; - case SC_SHIELDSPELL_DEF: - case SC_SHIELDSPELL_MDEF: - case SC_SHIELDSPELL_REF: - status_change_end(bl, SC_MAGNIFICAT, INVALID_TIMER); - if( type != SC_SHIELDSPELL_DEF ) - status_change_end(bl, SC_SHIELDSPELL_DEF, INVALID_TIMER); - if( type != SC_SHIELDSPELL_MDEF ) - status_change_end(bl, SC_SHIELDSPELL_MDEF, INVALID_TIMER); - if( type != SC_SHIELDSPELL_REF ) - status_change_end(bl, SC_SHIELDSPELL_REF, INVALID_TIMER); - break; - case SC_GENTLETOUCH_ENERGYGAIN: - case SC_GENTLETOUCH_CHANGE: - case SC_GENTLETOUCH_REVITALIZE: - if( type != SC_GENTLETOUCH_REVITALIZE ) - status_change_end(bl, SC_GENTLETOUCH_REVITALIZE, INVALID_TIMER); - if( type != SC_GENTLETOUCH_ENERGYGAIN ) - status_change_end(bl, SC_GENTLETOUCH_ENERGYGAIN, INVALID_TIMER); - if( type != SC_GENTLETOUCH_CHANGE ) - status_change_end(bl, SC_GENTLETOUCH_CHANGE, INVALID_TIMER); - break; - case SC_INVINCIBLE: - status_change_end(bl, SC_INVINCIBLEOFF, INVALID_TIMER); - break; - case SC_INVINCIBLEOFF: - status_change_end(bl, SC_INVINCIBLE, INVALID_TIMER); - break; - case SC_MAGICPOWER: - status_change_end(bl, type, INVALID_TIMER); - break; + status_change_end(bl, SC_ACCELERATION, INVALID_TIMER); + break; + case SC_ONEHANDQUICKEN: + //Removes the Aspd potion effect, as reported by Vicious. [Skotlex] + status_change_end(bl, SC_ATTHASTE_POTION1, INVALID_TIMER); + status_change_end(bl, SC_ATTHASTE_POTION2, INVALID_TIMER); + status_change_end(bl, SC_ATTHASTE_POTION3, INVALID_TIMER); + status_change_end(bl, SC_ATTHASTE_INFINITY, INVALID_TIMER); + break; + case SC_OVERTHRUSTMAX: + //Cancels Normal Overthrust. [Skotlex] + status_change_end(bl, SC_OVERTHRUST, INVALID_TIMER); + break; + case SC_KYRIE: + //Cancels Assumptio + status_change_end(bl, SC_ASSUMPTIO, INVALID_TIMER); + break; + case SC_DELUGE: + if (sc->data[SC_FOGWALL] && sc->data[SC_BLIND]) + status_change_end(bl, SC_BLIND, INVALID_TIMER); + break; + case SC_SILENCE: + if (sc->data[SC_GOSPEL] && sc->data[SC_GOSPEL]->val4 == BCT_SELF) + status_change_end(bl, SC_GOSPEL, INVALID_TIMER); + break; + case SC_HIDING: + status_change_end(bl, SC_RG_CCONFINE_M, INVALID_TIMER); + status_change_end(bl, SC_RG_CCONFINE_S, INVALID_TIMER); + break; + case SC__BLOODYLUST: + case SC_BERSERK: + if(battle_config.berserk_cancels_buffs) { + status_change_end(bl, SC_ONEHANDQUICKEN, INVALID_TIMER); + status_change_end(bl, SC_TWOHANDQUICKEN, INVALID_TIMER); + status_change_end(bl, SC_LKCONCENTRATION, INVALID_TIMER); + status_change_end(bl, SC_PARRYING, INVALID_TIMER); + status_change_end(bl, SC_AURABLADE, INVALID_TIMER); + status_change_end(bl, SC_MER_QUICKEN, INVALID_TIMER); + } + #ifdef RENEWAL + else { + status_change_end(bl, SC_TWOHANDQUICKEN, INVALID_TIMER); + } + #endif + break; + case SC_ASSUMPTIO: + status_change_end(bl, SC_KYRIE, INVALID_TIMER); + status_change_end(bl, SC_KAITE, INVALID_TIMER); + break; + case SC_KAITE: + status_change_end(bl, SC_ASSUMPTIO, INVALID_TIMER); + break; + case SC_CARTBOOST: + if(sc->data[SC_DEC_AGI]) + { //Cancel Decrease Agi, but take no further effect [Skotlex] + status_change_end(bl, SC_DEC_AGI, INVALID_TIMER); + return 0; + } + break; + case SC_FUSION: + status_change_end(bl, SC_SOULLINK, INVALID_TIMER); + break; + case SC_GS_ADJUSTMENT: + status_change_end(bl, SC_GS_MADNESSCANCEL, INVALID_TIMER); + break; + case SC_GS_MADNESSCANCEL: + status_change_end(bl, SC_GS_ADJUSTMENT, INVALID_TIMER); + break; + //NPC_CHANGEUNDEAD will debuff Blessing and Agi Up + case SC_PROPERTYUNDEAD: + status_change_end(bl, SC_BLESSING, INVALID_TIMER); + status_change_end(bl, SC_INC_AGI, INVALID_TIMER); + break; + case SC_FOOD_STR: + status_change_end(bl, SC_FOOD_STR_CASH, INVALID_TIMER); + break; + case SC_FOOD_AGI: + status_change_end(bl, SC_FOOD_AGI_CASH, INVALID_TIMER); + break; + case SC_FOOD_VIT: + status_change_end(bl, SC_FOOD_VIT_CASH, INVALID_TIMER); + break; + case SC_FOOD_INT: + status_change_end(bl, SC_FOOD_INT_CASH, INVALID_TIMER); + break; + case SC_FOOD_DEX: + status_change_end(bl, SC_FOOD_DEX_CASH, INVALID_TIMER); + break; + case SC_FOOD_LUK: + status_change_end(bl, SC_FOOD_LUK_CASH, INVALID_TIMER); + break; + case SC_FOOD_STR_CASH: + status_change_end(bl, SC_FOOD_STR, INVALID_TIMER); + break; + case SC_FOOD_AGI_CASH: + status_change_end(bl, SC_FOOD_AGI, INVALID_TIMER); + break; + case SC_FOOD_VIT_CASH: + status_change_end(bl, SC_FOOD_VIT, INVALID_TIMER); + break; + case SC_FOOD_INT_CASH: + status_change_end(bl, SC_FOOD_INT, INVALID_TIMER); + break; + case SC_FOOD_DEX_CASH: + status_change_end(bl, SC_FOOD_DEX, INVALID_TIMER); + break; + case SC_FOOD_LUK_CASH: + status_change_end(bl, SC_FOOD_LUK, INVALID_TIMER); + break; + case SC_ENDURE: + if( val4 ) + status_change_end(bl, SC_LKCONCENTRATION, INVALID_TIMER); + break; + case SC_FIGHTINGSPIRIT: + status_change_end(bl, type, INVALID_TIMER); // Remove previous one. + break; + case SC_MARSHOFABYSS: + status_change_end(bl, SC_INCAGI, INVALID_TIMER); + status_change_end(bl, SC_WINDWALK, INVALID_TIMER); + status_change_end(bl, SC_ATTHASTE_POTION1, INVALID_TIMER); + status_change_end(bl, SC_ATTHASTE_POTION2, INVALID_TIMER); + status_change_end(bl, SC_ATTHASTE_POTION3, INVALID_TIMER); + status_change_end(bl, SC_ATTHASTE_INFINITY, INVALID_TIMER); + break; + case SC_SWING: + case SC_SYMPHONY_LOVE: + case SC_MOONLIT_SERENADE: + case SC_RUSH_WINDMILL: + case SC_ECHOSONG: + case SC_HARMONIZE: //group A doesn't overlap + if (type != SC_SWING) status_change_end(bl, SC_SWING, INVALID_TIMER); + if (type != SC_SYMPHONY_LOVE) status_change_end(bl, SC_SYMPHONY_LOVE, INVALID_TIMER); + if (type != SC_MOONLIT_SERENADE) status_change_end(bl, SC_MOONLIT_SERENADE, INVALID_TIMER); + if (type != SC_RUSH_WINDMILL) status_change_end(bl, SC_RUSH_WINDMILL, INVALID_TIMER); + if (type != SC_ECHOSONG) status_change_end(bl, SC_ECHOSONG, INVALID_TIMER); + if (type != SC_HARMONIZE) status_change_end(bl, SC_HARMONIZE, INVALID_TIMER); + break; + case SC_SIREN: + case SC_DEEP_SLEEP: + case SC_GLOOMYDAY: + case SC_SONG_OF_MANA: + case SC_DANCE_WITH_WUG: + case SC_SATURDAY_NIGHT_FEVER: + case SC_LERADS_DEW: + case SC_MELODYOFSINK: + case SC_BEYOND_OF_WARCRY: + case SC_UNLIMITED_HUMMING_VOICE: //group B + if (type != SC_SIREN) status_change_end(bl, SC_SIREN, INVALID_TIMER); + if (type != SC_DEEP_SLEEP) status_change_end(bl, SC_DEEP_SLEEP, INVALID_TIMER); + if (type != SC_LERADS_DEW) status_change_end(bl, SC_LERADS_DEW, INVALID_TIMER); + if (type != SC_MELODYOFSINK) status_change_end(bl, SC_MELODYOFSINK, INVALID_TIMER); + if (type != SC_BEYOND_OF_WARCRY) status_change_end(bl, SC_BEYOND_OF_WARCRY, INVALID_TIMER); + if (type != SC_UNLIMITED_HUMMING_VOICE) status_change_end(bl, SC_UNLIMITED_HUMMING_VOICE, INVALID_TIMER); + if (type != SC_GLOOMYDAY) { + status_change_end(bl, SC_GLOOMYDAY, INVALID_TIMER); + status_change_end(bl, SC_GLOOMYDAY_SK, INVALID_TIMER); + } + if (type != SC_SONG_OF_MANA) status_change_end(bl, SC_SONG_OF_MANA, INVALID_TIMER); + if (type != SC_DANCE_WITH_WUG) status_change_end(bl, SC_DANCE_WITH_WUG, INVALID_TIMER); + if (type != SC_SATURDAY_NIGHT_FEVER) { + if (sc->data[SC_SATURDAY_NIGHT_FEVER]) { + sc->data[SC_SATURDAY_NIGHT_FEVER]->val2 = 0; //mark to not lose hp + status_change_end(bl, SC_SATURDAY_NIGHT_FEVER, INVALID_TIMER); + } + } + break; + case SC_REFLECTSHIELD: + status_change_end(bl, SC_LG_REFLECTDAMAGE, INVALID_TIMER); + break; + case SC_LG_REFLECTDAMAGE: + status_change_end(bl, SC_REFLECTSHIELD, INVALID_TIMER); + break; + case SC_SHIELDSPELL_DEF: + case SC_SHIELDSPELL_MDEF: + case SC_SHIELDSPELL_REF: + status_change_end(bl, SC_MAGNIFICAT, INVALID_TIMER); + if( type != SC_SHIELDSPELL_DEF ) + status_change_end(bl, SC_SHIELDSPELL_DEF, INVALID_TIMER); + if( type != SC_SHIELDSPELL_MDEF ) + status_change_end(bl, SC_SHIELDSPELL_MDEF, INVALID_TIMER); + if( type != SC_SHIELDSPELL_REF ) + status_change_end(bl, SC_SHIELDSPELL_REF, INVALID_TIMER); + break; + case SC_GENTLETOUCH_ENERGYGAIN: + case SC_GENTLETOUCH_CHANGE: + case SC_GENTLETOUCH_REVITALIZE: + if( type != SC_GENTLETOUCH_REVITALIZE ) + status_change_end(bl, SC_GENTLETOUCH_REVITALIZE, INVALID_TIMER); + if( type != SC_GENTLETOUCH_ENERGYGAIN ) + status_change_end(bl, SC_GENTLETOUCH_ENERGYGAIN, INVALID_TIMER); + if( type != SC_GENTLETOUCH_CHANGE ) + status_change_end(bl, SC_GENTLETOUCH_CHANGE, INVALID_TIMER); + break; + case SC_INVINCIBLE: + status_change_end(bl, SC_INVINCIBLEOFF, INVALID_TIMER); + break; + case SC_INVINCIBLEOFF: + status_change_end(bl, SC_INVINCIBLE, INVALID_TIMER); + break; + case SC_MAGICPOWER: + status_change_end(bl, type, INVALID_TIMER); + break; } //Check for overlapping fails @@ -9223,24 +9215,24 @@ int status_change_end_(struct block_list* bl, enum sc_type type, int tid, const if (sce->timer != INVALID_TIMER) //Could be a SC with infinite duration iTimer->delete_timer(sce->timer,status_change_timer); if (sc->opt1) - switch (type) { - //"Ugly workaround" [Skotlex] - //delays status change ending so that a skill that sets opt1 fails to - //trigger when it also removed one - case SC_STONE: - sce->val3 = 0; //Petrify time counter. - case SC_FREEZE: - case SC_STUN: - case SC_SLEEP: - if (sce->val1) { - //Removing the 'level' shouldn't affect anything in the code - //since these SC are not affected by it, and it lets us know - //if we have already delayed this attack or not. - sce->val1 = 0; - sce->timer = iTimer->add_timer(iTimer->gettick()+10, status_change_timer, bl->id, type); - return 1; + switch (type) { + //"Ugly workaround" [Skotlex] + //delays status change ending so that a skill that sets opt1 fails to + //trigger when it also removed one + case SC_STONE: + sce->val3 = 0; //Petrify time counter. + case SC_FREEZE: + case SC_STUN: + case SC_SLEEP: + if (sce->val1) { + //Removing the 'level' shouldn't affect anything in the code + //since these SC are not affected by it, and it lets us know + //if we have already delayed this attack or not. + sce->val1 = 0; + sce->timer = iTimer->add_timer(iTimer->gettick()+10, status_change_timer, bl->id, type); + return 1; + } } - } } (sc->count)--; @@ -11417,12 +11409,11 @@ static bool status_readdb_refine(char* fields[], int columns, int current) return true; } -static bool status_readdb_scconfig(char* fields[], int columns, int current) -{ +static bool status_readdb_scconfig(char* fields[], int columns, int current) { int val = 0; char* type = fields[0]; - if( !script_get_constant(type, &val) ){ + if( !script->get_constant(type, &val) ){ ShowWarning("status_readdb_sc_conf: Invalid status type %s specified.\n", type); return false; } diff --git a/src/map/storage.c b/src/map/storage.c index 49cb18cbe..e3fa073af 100644 --- a/src/map/storage.c +++ b/src/map/storage.c @@ -24,9 +24,6 @@ #include <stdlib.h> #include <string.h> - -static DBMap* guild_storage_db; // int guild_id -> struct guild_storage* - /*========================================== * Sort items in the warehouse *------------------------------------------*/ @@ -58,14 +55,13 @@ static void storage_sortitem(struct item* items, unsigned int size) /*========================================== * Init/Terminate *------------------------------------------*/ -int do_init_storage(void) // Called from map.c::do_init() -{ - guild_storage_db=idb_alloc(DB_OPT_RELEASE_DATA); +/* ##TODO not really init_storage but init_gstorage, should rename/move */ +int do_init_storage(void) { // Called from map.c::do_init() + gstorage->db = idb_alloc(DB_OPT_RELEASE_DATA); return 1; } -void do_final_storage(void) // by [MC Cameri] -{ - guild_storage_db->destroy(guild_storage_db,NULL); +void do_final_storage(void) { // by [MC Cameri] + gstorage->db->destroy(gstorage->db,NULL); } /** @@ -83,7 +79,7 @@ static int storage_reconnect_sub(DBKey key, DBData *data, va_list ap) //Function to be invoked upon server reconnection to char. To save all 'dirty' storages [Skotlex] void do_reconnect_storage(void) { - guild_storage_db->foreach(guild_storage_db, storage_reconnect_sub); + gstorage->db->foreach(gstorage->db, storage_reconnect_sub); } /*========================================== @@ -132,8 +128,7 @@ int compare_item(struct item *a, struct item *b) /*========================================== * Internal add-item function. *------------------------------------------*/ -static int storage_additem(struct map_session_data* sd, struct item* item_data, int amount) -{ +int storage_additem(struct map_session_data* sd, struct item* item_data, int amount) { struct storage_data* stor = &sd->status.storage; struct item_data *data; int i; @@ -141,7 +136,7 @@ static int storage_additem(struct map_session_data* sd, struct item* item_data, if( item_data->nameid <= 0 || amount <= 0 ) return 1; - data = itemdb_search(item_data->nameid); + data = itemdb->search(item_data->nameid); if( data->stack.storage && amount > data->stack.amount ) {// item stack limitation @@ -226,7 +221,7 @@ int storage_storageadd(struct map_session_data* sd, int index, int amount) if( amount < 1 || amount > sd->status.inventory[index].amount ) return 0; - if( storage_additem(sd,&sd->status.inventory[index],amount) == 0 ) + if( storage->additem(sd,&sd->status.inventory[index],amount) == 0 ) pc->delitem(sd,index,amount,0,4,LOG_TYPE_STORAGE); return 1; @@ -283,7 +278,7 @@ int storage_storageaddfromcart(struct map_session_data* sd, int index, int amoun if( amount < 1 || amount > sd->status.cart[index].amount ) return 0; - if( storage_additem(sd,&sd->status.cart[index],amount) == 0 ) + if( storage->additem(sd,&sd->status.cart[index],amount) == 0 ) pc->cart_delitem(sd,index,amount,0,LOG_TYPE_STORAGE); return 1; @@ -359,19 +354,17 @@ struct guild_storage *guild2storage(int guild_id) { struct guild_storage *gs = NULL; if(guild->search(guild_id) != NULL) - gs = idb_ensure(guild_storage_db,guild_id,create_guildstorage); + gs = idb_ensure(gstorage->db,guild_id,create_guildstorage); return gs; } //For just locating a storage without creating one. [Skotlex] -struct guild_storage *guild2storage2(int guild_id) -{ - return (struct guild_storage*)idb_get(guild_storage_db,guild_id); +struct guild_storage *guild2storage2(int guild_id) { + return (struct guild_storage*)idb_get(gstorage->db,guild_id); } -int guild_storage_delete(int guild_id) -{ - idb_remove(guild_storage_db,guild_id); +int guild_storage_delete(int guild_id) { + idb_remove(gstorage->db,guild_id); return 0; } @@ -435,7 +428,7 @@ int guild_storage_additem(struct map_session_data* sd, struct guild_storage* sto if(item_data->nameid <= 0 || amount <= 0) return 1; - data = itemdb_search(item_data->nameid); + data = itemdb->search(item_data->nameid); if( data->stack.guildstorage && amount > data->stack.amount ) {// item stack limitation @@ -745,6 +738,7 @@ void storage_defaults(void) { storage->delitem = storage_delitem; storage->open = storage_storageopen; storage->add = storage_storageadd; + storage->additem = storage_additem; storage->get = storage_storageget; storage->addfromcart = storage_storageaddfromcart; storage->gettocart = storage_storagegettocart; diff --git a/src/map/storage.h b/src/map/storage.h index 058b980b1..fc05ef06c 100644 --- a/src/map/storage.h +++ b/src/map/storage.h @@ -9,6 +9,7 @@ struct storage_data; struct guild_storage; struct item; struct map_session_data; +struct DBMap; struct storage_interface { int (*init) (void); @@ -20,6 +21,7 @@ struct storage_interface { int (*open) (struct map_session_data *sd); int (*add) (struct map_session_data *sd,int index,int amount); int (*get) (struct map_session_data *sd,int index,int amount); + int (*additem) (struct map_session_data* sd, struct item* item_data, int amount); int (*addfromcart) (struct map_session_data *sd,int index,int amount); int (*gettocart) (struct map_session_data *sd,int index,int amount); void (*close) (struct map_session_data *sd); @@ -28,6 +30,8 @@ struct storage_interface { struct storage_interface *storage; struct guild_storage_interface { + struct DBMap* db; // int guild_id -> struct guild_storage* + /* */ struct guild_storage *(*id2storage) (int guild_id); struct guild_storage *(*id2storage2) (int guild_id); int (*delete) (int guild_id); diff --git a/src/map/trade.c b/src/map/trade.c index f469f4b28..a2a29651b 100644 --- a/src/map/trade.c +++ b/src/map/trade.c @@ -257,7 +257,7 @@ int trade_check(struct map_session_data *sd, struct map_session_data *tsd) if (amount > inventory[n].amount) return 0; //qty Exploit? - data = itemdb_search(inventory[n].nameid); + data = itemdb->search(inventory[n].nameid); i = MAX_INVENTORY; if (itemdb_isstackable2(data)) { //Stackable item. for(i = 0; i < MAX_INVENTORY; i++) @@ -288,7 +288,7 @@ int trade_check(struct map_session_data *sd, struct map_session_data *tsd) if (amount > inventory2[n].amount) return 0; // search if it's possible to add item (for full inventory) - data = itemdb_search(inventory2[n].nameid); + data = itemdb->search(inventory2[n].nameid); i = MAX_INVENTORY; if (itemdb_isstackable2(data)) { for(i = 0; i < MAX_INVENTORY; i++) |