summaryrefslogtreecommitdiff
path: root/src/map/unit.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/map/unit.c')
-rw-r--r--src/map/unit.c271
1 files changed, 123 insertions, 148 deletions
diff --git a/src/map/unit.c b/src/map/unit.c
index 39fff0eab..78a85ba3e 100644
--- a/src/map/unit.c
+++ b/src/map/unit.c
@@ -2,45 +2,48 @@
// See the LICENSE file
// Portions Copyright (c) Athena Dev Teams
-#include "../common/showmsg.h"
-#include "../common/timer.h"
-#include "../common/nullpo.h"
-#include "../common/db.h"
-#include "../common/malloc.h"
-#include "../common/random.h"
-#include "../common/HPM.h"
+#define HERCULES_CORE
+#include "../config/core.h" // RENEWAL_CAST
+#include "unit.h"
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+
+#include "battle.h"
+#include "battleground.h"
+#include "chat.h"
+#include "chrif.h"
+#include "clif.h"
+#include "duel.h"
+#include "elemental.h"
+#include "guild.h"
+#include "homunculus.h"
+#include "instance.h"
+#include "intif.h"
#include "map.h"
+#include "mercenary.h"
+#include "mob.h"
+#include "npc.h"
+#include "party.h"
#include "path.h"
#include "pc.h"
-#include "mob.h"
#include "pet.h"
-#include "homunculus.h"
-#include "instance.h"
-#include "mercenary.h"
-#include "elemental.h"
+#include "script.h"
#include "skill.h"
-#include "clif.h"
-#include "duel.h"
-#include "npc.h"
-#include "guild.h"
#include "status.h"
-#include "unit.h"
-#include "battle.h"
-#include "battleground.h"
-#include "chat.h"
+#include "storage.h"
#include "trade.h"
#include "vending.h"
-#include "party.h"
-#include "intif.h"
-#include "chrif.h"
-#include "script.h"
-#include "storage.h"
-
-#include <stdio.h>
-#include <stdlib.h>
-#include <string.h>
-
+#include "../common/HPM.h"
+#include "../common/db.h"
+#include "../common/malloc.h"
+#include "../common/nullpo.h"
+#include "../common/random.h"
+#include "../common/showmsg.h"
+#include "../common/socket.h"
+#include "../common/timer.h"
const short dirx[8]={0,-1,-1,-1,0,1,1,1};
const short diry[8]={1,1,0,-1,-1,-1,0,1};
@@ -241,7 +244,7 @@ int unit_walktoxy_timer(int tid, int64 tick, int id, intptr_t data) {
{
if (!(ud->skill_id == NPC_SELFDESTRUCTION && ud->skilltimer != INVALID_TIMER))
{ //Skill used, abort walking
- clif->fixpos(bl); //Fix position as walk has been cancelled.
+ clif->fixpos(bl); //Fix position as walk has been canceled.
return 0;
}
//Resend walk packet for proper Self Destruction display.
@@ -289,7 +292,7 @@ int unit_walktoxy_timer(int tid, int64 tick, int id, intptr_t data) {
clif->move(ud);
} else if(ud->state.running) {
//Keep trying to run.
- if ( !(unit->run(bl) || unit->wugdash(bl,sd)) )
+ if ( !(unit->run(bl, NULL, SC_RUN) || unit->run(bl, sd, SC_WUGDASH)) )
ud->state.running = 0;
} else if (ud->target_to) {
//Update target trajectory.
@@ -377,8 +380,12 @@ int unit_walktoxy( struct block_list *bl, short x, short y, int flag)
unit->set_target(ud, 0);
sc = status->get_sc(bl);
- if (sc && (sc->data[SC_CONFUSION] || sc->data[SC__CHAOS])) //Randomize the target position
- map->random_dir(bl, &ud->to_x, &ud->to_y);
+ if( sc ) {
+ if( sc->data[SC_CONFUSION] || sc->data[SC__CHAOS] ) //Randomize the target position
+ map->random_dir(bl, &ud->to_x, &ud->to_y);
+ if( sc->data[SC_COMBOATTACK] )
+ status_change_end(bl, SC_COMBOATTACK, INVALID_TIMER);
+ }
if(ud->walktimer != INVALID_TIMER) {
// When you come to the center of the grid because the change of destination while you're walking right now
@@ -479,137 +486,95 @@ int unit_walktobl(struct block_list *bl, struct block_list *tbl, int range, int
return 0;
}
-int unit_run(struct block_list *bl) {
- struct status_change *sc = status->get_sc(bl);
- short to_x,to_y,dir_x,dir_y;
- int lv;
- int i;
-
- if (!(sc && sc->data[SC_RUN]))
- return 0;
-
- if (!unit->can_move(bl)) {
- status_change_end(bl, SC_RUN, INVALID_TIMER);
- return 0;
- }
-
- lv = sc->data[SC_RUN]->val1;
- dir_x = dirx[sc->data[SC_RUN]->val2];
- dir_y = diry[sc->data[SC_RUN]->val2];
- // determine destination cell
- to_x = bl->x;
- to_y = bl->y;
- for(i=0;i<AREA_SIZE;i++) {
- if(!map->getcell(bl->m,to_x+dir_x,to_y+dir_y,CELL_CHKPASS))
- break;
-
- //if sprinting and there's a PC/Mob/NPC, block the path [Kevin]
- if(sc->data[SC_RUN] && map->count_oncell(bl->m, to_x+dir_x, to_y+dir_y, BL_PC|BL_MOB|BL_NPC))
- break;
-
- to_x += dir_x;
- to_y += dir_y;
- }
+/**
+ * Called by unit_run when an object was hit
+ * @param sd Required only when using SC_WUGDASH
+ **/
+void unit_run_hit( struct block_list *bl, struct status_change *sc, struct map_session_data *sd, enum sc_type type ) {
+ int lv = sc->data[type]->val1;
- if( (to_x == bl->x && to_y == bl->y ) || (to_x == (bl->x+1) || to_y == (bl->y+1)) || (to_x == (bl->x-1) || to_y == (bl->y-1))) {
- //If you can't run forward, you must be next to a wall, so bounce back. [Skotlex]
+ //If you can't run forward, you must be next to a wall, so bounce back. [Skotlex]
+ if( type == SC_RUN )
clif->sc_load(bl,bl->id,AREA,SI_TING,0,0,0);
- //Set running to 0 beforehand so status_change_end knows not to enable spurt [Kevin]
- unit->bl2ud(bl)->state.running = 0;
- status_change_end(bl, SC_RUN, INVALID_TIMER);
+ //Set running to 0 beforehand so status_change_end knows not to enable spurt [Kevin]
+ unit->bl2ud(bl)->state.running = 0;
+ status_change_end(bl, type, INVALID_TIMER);
+ if( type == SC_RUN ) {
skill->blown(bl,bl,skill->get_blewcount(TK_RUN,lv),unit->getdir(bl),0);
clif->fixpos(bl); //Why is a clif->slide (skill->blown) AND a fixpos needed? Ask Aegis.
clif->sc_end(bl,bl->id,AREA,SI_TING);
- return 0;
- }
- if (unit->walktoxy(bl, to_x, to_y, 1))
- return 1;
- //There must be an obstacle nearby. Attempt walking one cell at a time.
- do {
- to_x -= dir_x;
- to_y -= dir_y;
- } while (--i > 0 && !unit->walktoxy(bl, to_x, to_y, 1));
- if ( i == 0 ) {
- // copy-paste from above
- clif->sc_load(bl,bl->id,AREA,SI_TING,0,0,0);
-
- //Set running to 0 beforehand so status_change_end knows not to enable spurt [Kevin]
- unit->bl2ud(bl)->state.running = 0;
- status_change_end(bl, SC_RUN, INVALID_TIMER);
-
- skill->blown(bl,bl,skill->get_blewcount(TK_RUN,lv),unit->getdir(bl),0);
+ } else if( sd ) {
clif->fixpos(bl);
- clif->sc_end(bl,bl->id,AREA,SI_TING);
- return 0;
+ skill->castend_damage_id(bl, &sd->bl, RA_WUGDASH, lv, timer->gettick(), SD_LEVEL);
}
- return 1;
+ return;
}
-//Exclusive function to Wug Dash state. [Jobbie/3CeAM]
-int unit_wugdash(struct block_list *bl, struct map_session_data *sd) {
- struct status_change *sc = status->get_sc(bl);
+/**
+ * Makes character run, used for SC_RUN and SC_WUGDASH
+ * @param sd Required only when using SC_WUGDASH
+ * @retval true Finished running
+ * @retval false Hit an object/Couldn't run
+ **/
+bool unit_run( struct block_list *bl, struct map_session_data *sd, enum sc_type type ) {
+ struct status_change *sc;
short to_x,to_y,dir_x,dir_y;
- int lv;
int i;
- if (!(sc && sc->data[SC_WUGDASH]))
- return 0;
- nullpo_ret(sd);
- nullpo_ret(bl);
+ nullpo_retr(false, bl);
+ sc = status->get_sc(bl);
- if (!unit->can_move(bl)) {
- status_change_end(bl,SC_WUGDASH,INVALID_TIMER);
- return 0;
+ if( !(sc && sc->data[type]) )
+ return false;
+
+ if( !unit->can_move(bl) ) {
+ status_change_end(bl, type, INVALID_TIMER);
+ return false;
}
- lv = sc->data[SC_WUGDASH]->val1;
- dir_x = dirx[sc->data[SC_WUGDASH]->val2];
- dir_y = diry[sc->data[SC_WUGDASH]->val2];
+ dir_x = dirx[sc->data[type]->val2];
+ dir_y = diry[sc->data[type]->val2];
+ // determine destination cell
to_x = bl->x;
to_y = bl->y;
- for(i=0;i<AREA_SIZE;i++) {
+
+ // Search for available path
+ for(i = 0; i < AREA_SIZE; i++) {
if(!map->getcell(bl->m,to_x+dir_x,to_y+dir_y,CELL_CHKPASS))
break;
- if(sc->data[SC_WUGDASH] && map->count_oncell(bl->m, to_x+dir_x, to_y+dir_y, BL_PC|BL_MOB|BL_NPC))
+ //if sprinting and there's a PC/Mob/NPC, block the path [Kevin]
+ if( map->count_oncell(bl->m, to_x+dir_x, to_y+dir_y, BL_PC|BL_MOB|BL_NPC) )
break;
to_x += dir_x;
to_y += dir_y;
}
- if(to_x == bl->x && to_y == bl->y) {
+ // Can't run forward
+ if( (to_x == bl->x && to_y == bl->y ) || (to_x == (bl->x+1) || to_y == (bl->y+1)) || (to_x == (bl->x-1) || to_y == (bl->y-1))) {
+ unit->run_hit(bl, sc, sd, type);
+ return false;
+ }
- unit->bl2ud(bl)->state.running = 0;
- status_change_end(bl,SC_WUGDASH,INVALID_TIMER);
+ if( unit->walktoxy(bl, to_x, to_y, 1) )
+ return true;
- if( sd ){
- clif->fixpos(bl);
- skill->castend_damage_id(bl, &sd->bl, RA_WUGDASH, lv, timer->gettick(), SD_LEVEL);
- }
- return 0;
- }
- if (unit->walktoxy(bl, to_x, to_y, 1))
- return 1;
+ //There must be an obstacle nearby. Attempt walking one cell at a time.
do {
to_x -= dir_x;
to_y -= dir_y;
} while (--i > 0 && !unit->walktoxy(bl, to_x, to_y, 1));
- if (i==0) {
-
- unit->bl2ud(bl)->state.running = 0;
- status_change_end(bl,SC_WUGDASH,INVALID_TIMER);
- if( sd ){
- clif->fixpos(bl);
- skill->castend_damage_id(bl, &sd->bl, RA_WUGDASH, lv, timer->gettick(), SD_LEVEL);
- }
- return 0;
+ if ( i == 0 ) {
+ unit->run_hit(bl, sc, sd, type);
+ return false;
}
+
return 1;
}
@@ -866,7 +831,7 @@ int unit_stop_walking(struct block_list *bl,int type)
return 0;
//NOTE: We are using timer data after deleting it because we know the
//timer->delete function does not messes with it. If the function's
- //behaviour changes in the future, this code could break!
+ //behavior changes in the future, this code could break!
td = timer->get(ud->walktimer);
timer->delete(ud->walktimer, unit->walktoxy_timer);
ud->walktimer = INVALID_TIMER;
@@ -889,7 +854,7 @@ int unit_stop_walking(struct block_list *bl,int type)
if(bl->type == BL_PET && type&~0xff)
ud->canmove_tick = timer->gettick() + (type>>8);
- //Readded, the check in unit_set_walkdelay means dmg during running won't fall through to this place in code [Kevin]
+ //Read, the check in unit_set_walkdelay means dmg during running won't fall through to this place in code [Kevin]
if (ud->state.running) {
status_change_end(bl, SC_RUN, INVALID_TIMER);
status_change_end(bl, SC_WUGDASH, INVALID_TIMER);
@@ -944,6 +909,7 @@ int unit_can_move(struct block_list *bl) {
))
return 0; //Can't move
+ // Status changes that block movement
if (sc) {
if( sc->count
&& (
@@ -955,6 +921,7 @@ int unit_can_move(struct block_list *bl) {
|| (sc->data[SC_GOSPEL] && sc->data[SC_GOSPEL]->val4 == BCT_SELF) // cannot move while gospel is in effect
|| (sc->data[SC_BASILICA] && sc->data[SC_BASILICA]->val4 == bl->id) // Basilica caster cannot move
|| sc->data[SC_STOP]
+ || sc->data[SC_FALLENEMPIRE]
|| sc->data[SC_RG_CCONFINE_M]
|| sc->data[SC_RG_CCONFINE_S]
|| sc->data[SC_GS_MADNESSCANCEL]
@@ -1100,7 +1067,7 @@ int unit_skilluse_id2(struct block_list *src, int target_id, uint16 skill_id, ui
) {
if (sc->data[SC_COMBOATTACK]->val2)
target_id = sc->data[SC_COMBOATTACK]->val2;
- else
+ else if( skill->get_inf(skill_id) != 1 ) // Only non-targetable skills should use auto target
target_id = ud->target;
if( skill->get_inf(skill_id)&INF_SELF_SKILL && skill->get_nk(skill_id)&NK_NO_DAMAGE )// exploit fix
@@ -1177,8 +1144,8 @@ int unit_skilluse_id2(struct block_list *src, int target_id, uint16 skill_id, ui
if( (skill->get_inf2(skill_id)&INF2_ENSEMBLE_SKILL) && skill->check_pc_partner(sd, skill_id, &skill_lv, 1, 0) < 1 ) {
clif->skill_fail(sd,skill_id,USESKILL_FAIL_LEVEL,0);
- return 0;
- }
+ return 0;
+ }
switch(skill_id){
case SA_CASTCANCEL:
@@ -1247,7 +1214,7 @@ int unit_skilluse_id2(struct block_list *src, int target_id, uint16 skill_id, ui
if (!temp) //Stop attack on non-combo skills [Skotlex]
unit->stop_attack(src);
- else if(ud->attacktimer != INVALID_TIMER) //Elsewise, delay current attack sequence
+ else if(ud->attacktimer != INVALID_TIMER) //Else-wise, delay current attack sequence
ud->attackabletime = tick + status_get_adelay(src);
ud->state.skillcastcancel = castcancel;
@@ -1363,16 +1330,16 @@ int unit_skilluse_id2(struct block_list *src, int target_id, uint16 skill_id, ui
}
if(!ud->state.running) //need TK_RUN or WUGDASH handler to be done before that, see bugreport:6026
- unit->stop_walking(src,1);// eventhough this is not how official works but this will do the trick. bugreport:6829
+ unit->stop_walking(src,1);// even though this is not how official works but this will do the trick. bugreport:6829
// in official this is triggered even if no cast time.
clif->skillcasting(src, src->id, target_id, 0,0, skill_id, skill->get_ele(skill_id, skill_lv), casttime);
if( casttime > 0 || temp )
- {
+ {
if (sd && target->type == BL_MOB)
{
TBL_MOB *md = (TBL_MOB*)target;
- mob->skill_event(md, src, tick, -1); //Cast targetted skill event.
+ mob->skill_event(md, src, tick, -1); //Cast targeted skill event.
if (tstatus->mode&(MD_CASTSENSOR_IDLE|MD_CASTSENSOR_CHASE) &&
battle->check_target(target, src, BCT_ENEMY) > 0)
{
@@ -1467,7 +1434,7 @@ int unit_skilluse_pos2( struct block_list *src, short skill_x, short skill_y, ui
if( skill->not_ok(skill_id, sd) || !skill->check_condition_castbegin(sd, skill_id, skill_lv) )
return 0;
/**
- * "WHY IS IT HEREE": pneuma cannot be cancelled past this point, the client displays the animation even,
+ * "WHY IS IT HEREE": pneuma cannot be canceled past this point, the client displays the animation even,
* if we cancel it from nodamage_id, so it has to be here for it to not display the animation.
**/
if( skill_id == AL_PNEUMA && map->getcell(src->m, skill_x, skill_y, CELL_CHKLANDPROTECTOR) ) {
@@ -1552,7 +1519,7 @@ int unit_skilluse_pos2( struct block_list *src, short skill_x, short skill_y, ui
if( casttime > 0 ) {
ud->skilltimer = timer->add( tick+casttime, skill->castend_pos, src->id, 0 );
if( (sd && pc->checkskill(sd,SA_FREECAST) > 0) || skill_id == LG_EXEEDBREAK)
- status_calc_bl(&sd->bl, SCB_SPEED);
+ status_calc_bl(&sd->bl, SCB_SPEED);
} else {
ud->skilltimer = INVALID_TIMER;
skill->castend_pos(ud->skilltimer,tick,src->id,0);
@@ -1637,6 +1604,10 @@ int unit_attack(struct block_list *src,int target_id,int continuous) {
unit->stop_attack(src);
return 0;
}
+ if( !pc->can_attack(sd, target_id) ) {
+ unit->stop_attack(src);
+ return 0;
+ }
}
if( battle->check_target(src,target,BCT_ENEMY) <= 0 || !status->check_skilluse(src, target, 0, 0) ) {
unit->unattackable(src);
@@ -1645,7 +1616,7 @@ int unit_attack(struct block_list *src,int target_id,int continuous) {
ud->state.attack_continue = continuous;
unit->set_target(ud, target_id);
- if (continuous) //If you're to attack continously, set to auto-case character
+ if (continuous) //If you're to attack continuously, set to auto-case character
ud->chaserange = status_get_range(src);
//Just change target/type. [Skotlex]
@@ -1826,6 +1797,7 @@ int unit_attack_timer_sub(struct block_list* src, int tid, int64 tick) {
#ifdef OFFICIAL_WALKPATH
|| !path->search_long(NULL, src->m, src->x, src->y, target->x, target->y, CELL_CHKWALL)
#endif
+ || (sd && !pc->can_attack(sd, ud->target) )
)
return 0; // can't attack under these conditions
@@ -1935,7 +1907,7 @@ int unit_attack_timer(int tid, int64 tick, int id, intptr_t data) {
/*==========================================
* Cancels an ongoing skill cast.
* flag&1: Cast-Cancel invoked.
- * flag&2: Cancel only if skill is cancellable.
+ * flag&2: Cancel only if skill is can be cancel.
*------------------------------------------*/
int unit_skillcastcancel(struct block_list *bl,int type)
{
@@ -1951,7 +1923,7 @@ int unit_skillcastcancel(struct block_list *bl,int type)
sd = BL_CAST(BL_PC, bl);
if (type&2) {
- //See if it can be cancelled.
+ //See if it can be canceled.
if (!ud->state.skillcastcancel)
return 0;
@@ -2054,7 +2026,7 @@ int unit_changeviewsize(struct block_list *bl,short size)
/*==========================================
* Removes a bl/ud from the map.
* Returns 1 on success. 0 if it couldn't be removed or the bl was free'd
- * if clrtype is 1 (death), appropiate cleanup is performed.
+ * if clrtype is 1 (death), appropriate cleanup is performed.
* Otherwise it is assumed bl is being warped.
* On-Kill specific stuff is not performed here, look at status->damage for that.
*------------------------------------------*/
@@ -2138,11 +2110,14 @@ int unit_remove_map(struct block_list *bl, clr_type clrtype, const char* file, i
trade->cancel(sd);
buyingstore->close(sd);
searchstore->close(sd);
- if(sd->state.storage_flag == 1)
- storage->pc_quit(sd,0);
- else if (sd->state.storage_flag == 2)
- gstorage->pc_quit(sd,0);
- sd->state.storage_flag = 0; //Force close it when being warped.
+ if( sd->menuskill_id != AL_TELEPORT ) { // issue: 8027
+ if(sd->state.storage_flag == 1)
+ storage->pc_quit(sd,0);
+ else if (sd->state.storage_flag == 2)
+ gstorage->pc_quit(sd,0);
+
+ sd->state.storage_flag = 0; //Force close it when being warped.
+ }
if(sd->party_invite>0)
party->reply_invite(sd,sd->party_invite,0);
if(sd->guild_invite>0)
@@ -2610,7 +2585,7 @@ void unit_defaults(void) {
unit->walktobl_sub = unit_walktobl_sub;
unit->walktobl = unit_walktobl;
unit->run = unit_run;
- unit->wugdash = unit_wugdash;
+ unit->run_hit = unit_run_hit;
unit->escape = unit_escape;
unit->movepos = unit_movepos;
unit->setdir = unit_setdir;