diff options
author | Dastgir <dastgirpojee@rocketmail.com> | 2015-07-20 18:26:25 +0530 |
---|---|---|
committer | Dastgir <dastgirpojee@rocketmail.com> | 2015-07-20 18:26:25 +0530 |
commit | 4cf80b1e5f29c7973576863e0c4eee809e561702 (patch) | |
tree | 46933e0bcff309b6457547fd8b56298281a9c338 /src/map | |
parent | a7c771a064f5beb5c7f5f3c09a4ad744ac7c7ef5 (diff) | |
parent | 5aaf2707e25b8fa369bf37da1d51d0a0ee203473 (diff) | |
download | hercules-4cf80b1e5f29c7973576863e0c4eee809e561702.tar.gz hercules-4cf80b1e5f29c7973576863e0c4eee809e561702.tar.bz2 hercules-4cf80b1e5f29c7973576863e0c4eee809e561702.tar.xz hercules-4cf80b1e5f29c7973576863e0c4eee809e561702.zip |
Merge branch 'master' of https://github.com/HerculesWS/Hercules
Diffstat (limited to 'src/map')
-rw-r--r-- | src/map/battle.c | 6 | ||||
-rw-r--r-- | src/map/clif.c | 58 | ||||
-rw-r--r-- | src/map/pc.c | 98 | ||||
-rw-r--r-- | src/map/pc.h | 2 | ||||
-rw-r--r-- | src/map/script.c | 19 | ||||
-rw-r--r-- | src/map/skill.c | 2 | ||||
-rw-r--r-- | src/map/status.c | 2 |
7 files changed, 106 insertions, 81 deletions
diff --git a/src/map/battle.c b/src/map/battle.c index 8a834574b..3575dea6f 100644 --- a/src/map/battle.c +++ b/src/map/battle.c @@ -3627,7 +3627,7 @@ struct Damage battle_calc_magic_attack(struct block_list *src,struct block_list } } #ifndef HMAP_ZONE_DAMAGE_CAP_TYPE - if( target && skill_id ) { + if (skill_id) { for(i = 0; i < map->list[target->m].zone->capped_skills_count; i++) { if( skill_id == map->list[target->m].zone->capped_skills[i]->nameid && (map->list[target->m].zone->capped_skills[i]->type & target->type) ) { if( target->type == BL_MOB && map->list[target->m].zone->capped_skills[i]->subtype != MZS_NONE ) { @@ -4101,7 +4101,7 @@ struct Damage battle_calc_misc_attack(struct block_list *src,struct block_list * } } #ifndef HMAP_ZONE_DAMAGE_CAP_TYPE - if( target && skill_id ) { + if (skill_id) { for(i = 0; i < map->list[target->m].zone->capped_skills_count; i++) { if( skill_id == map->list[target->m].zone->capped_skills[i]->nameid && (map->list[target->m].zone->capped_skills[i]->type & target->type) ) { if( target->type == BL_MOB && map->list[target->m].zone->capped_skills[i]->subtype != MZS_NONE ) { @@ -5314,7 +5314,7 @@ struct Damage battle_calc_weapon_attack(struct block_list *src,struct block_list if(skill_id == CR_GRANDCROSS || skill_id == NPC_GRANDDARKNESS) return wd; //Enough, rest is not needed. #ifndef HMAP_ZONE_DAMAGE_CAP_TYPE - if( target && skill_id ) { + if (skill_id) { for(i = 0; i < map->list[target->m].zone->capped_skills_count; i++) { if( skill_id == map->list[target->m].zone->capped_skills[i]->nameid && (map->list[target->m].zone->capped_skills[i]->type & target->type) ) { if( target->type == BL_MOB && map->list[target->m].zone->capped_skills[i]->subtype != MZS_NONE ) { diff --git a/src/map/clif.c b/src/map/clif.c index f01b59fda..cc517c24f 100644 --- a/src/map/clif.c +++ b/src/map/clif.c @@ -5715,54 +5715,30 @@ void clif_solved_charname(int fd, int charid, const char* name) /// 017b <packet len>.W { <name id>.W }* void clif_use_card(struct map_session_data *sd,int idx) { - int i,c,ep; - int fd=sd->fd; + int i, c; + int fd; nullpo_retv(sd); - if (idx < 0 || idx >= MAX_INVENTORY) //Crash-fix from bad packets. + fd = sd->fd; + if (sd->state.trading != 0) + return; + if (!pc->can_insert_card(sd, idx)) return; - if (!sd->inventory_data[idx] || sd->inventory_data[idx]->type != IT_CARD) - return; //Avoid parsing invalid item indexes (no card/no item) - - ep=sd->inventory_data[idx]->equip; - WFIFOHEAD(fd,MAX_INVENTORY * 2 + 4); - WFIFOW(fd,0)=0x17b; - - for(i=c=0;i<MAX_INVENTORY;i++){ - int j; - - if(sd->inventory_data[i] == NULL) - continue; - if(sd->inventory_data[i]->type!=IT_WEAPON && sd->inventory_data[i]->type!=IT_ARMOR) - continue; - if(itemdb_isspecial(sd->status.inventory[i].card[0])) //Can't slot it - continue; - - if (sd->status.inventory[i].identify == 0) //Not identified - continue; - - if ((sd->inventory_data[i]->equip&ep) == 0) //Not equippable on this part. - continue; - - if(sd->inventory_data[i]->type==IT_WEAPON && ep==EQP_SHIELD) //Shield card won't go on left weapon. - continue; - - ARR_FIND( 0, sd->inventory_data[i]->slot, j, sd->status.inventory[i].card[j] == 0 ); - if (j == sd->inventory_data[i]->slot) // No room - continue; + WFIFOHEAD(fd, MAX_INVENTORY * 2 + 4); + WFIFOW(fd, 0) = 0x17b; - if( sd->status.inventory[i].equip > 0 ) // Do not check items that are already equipped + for (i = c = 0; i < MAX_INVENTORY; i++) { + if (!pc->can_insert_card_into(sd, idx, i)) continue; - - WFIFOW(fd,4+c*2)=i+2; + WFIFOW(fd, 4 + c * 2) = i + 2; c++; } - if( !c ) return; // no item is available for card insertion + if (!c) return; // no item is available for card insertion - WFIFOW(fd,2)=4+c*2; - WFIFOSET(fd,WFIFOW(fd,2)); + WFIFOW(fd, 2) = 4 + c * 2; + WFIFOSET(fd, WFIFOW(fd, 2)); } @@ -11394,8 +11370,6 @@ void clif_parse_AutoSpell(int fd,struct map_session_data *sd) /// 017a <card index>.W void clif_parse_UseCard(int fd,struct map_session_data *sd) { - if (sd->state.trading != 0) - return; clif->use_card(sd,RFIFOW(fd,2)-2); } @@ -11404,8 +11378,6 @@ void clif_parse_UseCard(int fd,struct map_session_data *sd) /// 017c <card index>.W <equip index>.W void clif_parse_InsertCard(int fd,struct map_session_data *sd) { - if (sd->state.trading != 0) - return; pc->insert_card(sd,RFIFOW(fd,2)-2,RFIFOW(fd,4)-2); } @@ -12746,7 +12718,7 @@ bool clif_sub_guild_invite(int fd, struct map_session_data *sd, struct map_sessi return false; } - if ( t_sd && t_sd->state.noask ) {// @noask [LuzZza] + if (t_sd->state.noask) {// @noask [LuzZza] clif->noask_sub(sd, t_sd, 2); return false; } diff --git a/src/map/pc.c b/src/map/pc.c index 4dac559e2..b9ef479dc 100644 --- a/src/map/pc.c +++ b/src/map/pc.c @@ -4059,42 +4059,78 @@ int pc_skill(TBL_PC* sd, int id, int level, int flag) } return 1; } + +/** + * Checks if the given card can be inserted into the given equipment piece. + * + * @param sd The current character. + * @param idx_card The card's inventory index (note: it must be a valid index and can be checked by pc_can_insert_card) + * @param idx_equip The target equipment's inventory index. + * @retval true if the card can be inserted. + */ +bool pc_can_insert_card_into(struct map_session_data* sd, int idx_card, int idx_equip) +{ + int i; + + nullpo_ret(sd); + + if (idx_equip < 0 || idx_equip >= MAX_INVENTORY || sd->inventory_data[idx_equip] == NULL) + return false; //Invalid item index. + if (sd->status.inventory[idx_equip].nameid <= 0 || sd->status.inventory[idx_equip].amount < 1) + return false; // target item missing + if (sd->inventory_data[idx_equip]->type != IT_WEAPON && sd->inventory_data[idx_equip]->type != IT_ARMOR) + return false; // only weapons and armor are allowed + if (sd->status.inventory[idx_equip].identify == 0) + return false; // target must be identified + if (itemdb_isspecial(sd->status.inventory[idx_equip].card[0])) + return false; // card slots reserved for other purposes + if (sd->status.inventory[idx_equip].equip != 0) + return false; // item must be unequipped + if ((sd->inventory_data[idx_equip]->equip & sd->inventory_data[idx_card]->equip) == 0) + return false; // card cannot be compounded on this item type + if (sd->inventory_data[idx_equip]->type == IT_WEAPON && sd->inventory_data[idx_card]->equip == EQP_SHIELD) + return false; // attempted to place shield card on left-hand weapon. + + ARR_FIND( 0, sd->inventory_data[idx_equip]->slot, i, sd->status.inventory[idx_equip].card[i] == 0); + if (i == sd->inventory_data[idx_equip]->slot) + return false; // no free slots + return true; +} + +/** + * Checks if the given item is card and it can be inserted into some equipment. + * + * @param sd The current character. + * @param idx_card The card's inventory index. + * @retval true if the card can be inserted. + */ +bool pc_can_insert_card(struct map_session_data* sd, int idx_card) +{ + nullpo_ret(sd); + + if (idx_card < 0 || idx_card >= MAX_INVENTORY || sd->inventory_data[idx_card] == NULL) + return false; //Invalid card index. + if (sd->status.inventory[idx_card].nameid <= 0 || sd->status.inventory[idx_card].amount < 1) + return false; // target card missing + if (sd->inventory_data[idx_card]->type != IT_CARD) + return false; // must be a card + return true; +} + /*========================================== * Append a card to an item ? *------------------------------------------*/ int pc_insert_card(struct map_session_data* sd, int idx_card, int idx_equip) { - int i; int nameid; nullpo_ret(sd); - if( idx_equip < 0 || idx_equip >= MAX_INVENTORY || sd->inventory_data[idx_equip] == NULL ) - return 0; //Invalid item index. - if( idx_card < 0 || idx_card >= MAX_INVENTORY || sd->inventory_data[idx_card] == NULL ) - return 0; //Invalid card index. - if( sd->status.inventory[idx_equip].nameid <= 0 || sd->status.inventory[idx_equip].amount < 1 ) - return 0; // target item missing - if( sd->status.inventory[idx_card].nameid <= 0 || sd->status.inventory[idx_card].amount < 1 ) - return 0; // target card missing - if( sd->inventory_data[idx_equip]->type != IT_WEAPON && sd->inventory_data[idx_equip]->type != IT_ARMOR ) - return 0; // only weapons and armor are allowed - if( sd->inventory_data[idx_card]->type != IT_CARD ) - return 0; // must be a card - if( sd->status.inventory[idx_equip].identify == 0 ) - return 0; // target must be identified - if( itemdb_isspecial(sd->status.inventory[idx_equip].card[0]) ) - return 0; // card slots reserved for other purposes - if( (sd->inventory_data[idx_equip]->equip & sd->inventory_data[idx_card]->equip) == 0 ) - return 0; // card cannot be compounded on this item type - if( sd->inventory_data[idx_equip]->type == IT_WEAPON && sd->inventory_data[idx_card]->equip == EQP_SHIELD ) - return 0; // attempted to place shield card on left-hand weapon. - if( sd->status.inventory[idx_equip].equip != 0 ) - return 0; // item must be unequipped - - ARR_FIND( 0, sd->inventory_data[idx_equip]->slot, i, sd->status.inventory[idx_equip].card[i] == 0 ); - if( i == sd->inventory_data[idx_equip]->slot ) - return 0; // no free slots + if (sd->state.trading != 0) + return 0; + + if (!pc->can_insert_card(sd, idx_card) || !pc->can_insert_card_into(sd, idx_card, idx_equip)) + return 0; // remember the card id to insert nameid = sd->status.inventory[idx_card].nameid; @@ -4105,6 +4141,10 @@ int pc_insert_card(struct map_session_data* sd, int idx_card, int idx_equip) } else {// success + int i; + ARR_FIND( 0, sd->inventory_data[idx_equip]->slot, i, sd->status.inventory[idx_equip].card[i] == 0); + if (i == sd->inventory_data[idx_equip]->slot) + return 0; // no free slots logs->pick_pc(sd, LOG_TYPE_OTHER, -1, &sd->status.inventory[idx_equip],sd->inventory_data[idx_equip]); sd->status.inventory[idx_equip].card[i] = nameid; logs->pick_pc(sd, LOG_TYPE_OTHER, 1, &sd->status.inventory[idx_equip],sd->inventory_data[idx_equip]); @@ -11497,7 +11537,9 @@ void pc_defaults(void) { pc->skill = pc_skill; pc->insert_card = pc_insert_card; - + pc->can_insert_card = pc_can_insert_card; + pc->can_insert_card_into = pc_can_insert_card_into; + pc->steal_item = pc_steal_item; pc->steal_coin = pc_steal_coin; diff --git a/src/map/pc.h b/src/map/pc.h index 4dea27693..c370f9956 100644 --- a/src/map/pc.h +++ b/src/map/pc.h @@ -880,6 +880,8 @@ END_ZEROED_BLOCK; /* End */ int (*skill) (struct map_session_data *sd, int id, int level, int flag); int (*insert_card) (struct map_session_data *sd,int idx_card,int idx_equip); + bool (*can_insert_card) (struct map_session_data* sd, int idx_card); + bool (*can_insert_card_into) (struct map_session_data* sd, int idx_card, int idx_equip); int (*steal_item) (struct map_session_data *sd,struct block_list *bl, uint16 skill_lv); int (*steal_coin) (struct map_session_data *sd,struct block_list *bl); diff --git a/src/map/script.c b/src/map/script.c index f2fce3a8f..30af4d0f7 100644 --- a/src/map/script.c +++ b/src/map/script.c @@ -17177,18 +17177,27 @@ BUILDIN(changequest) { BUILDIN(questactive) { struct map_session_data *sd = script->rid2sd(st); - int quest_progress = 0; + int qid, i; - if (sd == NULL) + if (sd == NULL) { + ShowError("questactive: no player attached!"); return false; + } + + qid = script_getnum(st, 2); + + ARR_FIND(0, sd->avail_quests, i, sd->quest_log[i].quest_id == qid ); - if (quest->check(sd, script_getnum(st, 2), HAVEQUEST) == Q_ACTIVE) + if( i >= sd->avail_quests ) { + script_pushint(st, 0); + return true; + } + + if(sd->quest_log[i].state == Q_ACTIVE) script_pushint(st, 1); else script_pushint(st, 0); - script_pushint(st, quest_progress); - return true; } diff --git a/src/map/skill.c b/src/map/skill.c index 13cdeede3..3a69bf380 100644 --- a/src/map/skill.c +++ b/src/map/skill.c @@ -2714,7 +2714,7 @@ int skill_attack(int attack_type, struct block_list* src, struct block_list *dsr } /* monsters with skill lv higher than MAX_SKILL_LEVEL may get this value beyond the max depending on conditions, we cap to the system's limit */ - if( dsrc && dsrc->type == BL_MOB && skill_lv > MAX_SKILL_LEVEL && dmg.blewcount > 25 ) + if (dsrc->type == BL_MOB && skill_lv > MAX_SKILL_LEVEL && dmg.blewcount > 25) dmg.blewcount = 25; //blown-specific handling diff --git a/src/map/status.c b/src/map/status.c index dc4813055..d88bcf146 100644 --- a/src/map/status.c +++ b/src/map/status.c @@ -5145,7 +5145,7 @@ signed short status_calc_mdef2(struct block_list *bl, struct status_change *sc, if(sc->data[SC_MINDBREAKER]) mdef2 -= mdef2 * sc->data[SC_MINDBREAKER]->val3/100; #ifdef RENEWAL - if(sc && sc->data[SC_ASSUMPTIO]) + if (sc->data[SC_ASSUMPTIO]) mdef2 <<= 1; return (short)cap_value(mdef2,SHRT_MIN,SHRT_MAX); #else |