From 9500c06dab282b6f59541bec1821f54aadfef25c Mon Sep 17 00:00:00 2001 From: Aleos Date: Sat, 23 Mar 2019 16:15:28 -0400 Subject: [PATCH] Corrected unit calculation with setunitdata (#3978) * Fixes #3953. * Resolved an issue with monster's class not being properly recalculated when using script command setunitdata. For now, just allow switching between CLASS_NORMAL and CLASS_BOSS. * Fixed HP and MaxHP adjustment for monster, homunculus, mercenary, elemental, and NPC. * Fixed MaxSP adjustment for homunculus and elemental. * Fixed Size adjustment for monster, homunculus, mercenary, and elemental. * Fixed Race adjustment for monster, homunculus, mercenary, and elemental. * Fixed the Map ID string check to support all unit types. Thanks to @teededung and @SeravySensei! --- src/map/script.cpp | 68 +++++++++++++++++++++++----------------------- src/map/status.cpp | 12 ++++---- 2 files changed, 41 insertions(+), 39 deletions(-) diff --git a/src/map/script.cpp b/src/map/script.cpp index 062cd43ab8..be5bebe74c 100644 --- a/src/map/script.cpp +++ b/src/map/script.cpp @@ -17648,16 +17648,7 @@ BUILDIN_FUNC(getunitdata) /// setunitdata ,,; BUILDIN_FUNC(setunitdata) { - struct block_list* bl = NULL; - const char *mapname = NULL; - TBL_MOB* md = NULL; - TBL_HOM* hd = NULL; - TBL_MER* mc = NULL; - TBL_PET* pd = NULL; - TBL_ELEM* ed = NULL; - TBL_NPC* nd = NULL; - int type, value = 0; - bool calc_status = false; + struct block_list* bl; if(!script_rid2bl(2,bl)) { @@ -17665,6 +17656,13 @@ BUILDIN_FUNC(setunitdata) return SCRIPT_CMD_FAILURE; } + TBL_MOB* md; + TBL_HOM* hd; + TBL_MER* mc; + TBL_PET* pd; + TBL_ELEM* ed; + TBL_NPC* nd; + switch (bl->type) { case BL_MOB: md = map_id2md(bl->id); break; case BL_HOM: hd = map_id2hd(bl->id); break; @@ -17683,9 +17681,11 @@ BUILDIN_FUNC(setunitdata) return SCRIPT_CMD_FAILURE; } - type = script_getnum(st, 3); + int type = script_getnum(st, 3), value = 0; + const char *mapname = NULL; + bool calc_status = false; - if (type == 5 && script_isstring(st, 4)) + if ((type == UMOB_MAPID || type == UHOM_MAPID || type == UPET_MAPID || type == UMER_MAPID || type == UELE_MAPID || type == UNPC_MAPID) && script_isstring(st, 4)) mapname = script_getstr(st, 4); else value = script_getnum(st, 4); @@ -17718,10 +17718,10 @@ BUILDIN_FUNC(setunitdata) } switch (type) { - case UMOB_SIZE: md->base_status->size = (unsigned char)value; calc_status = true; break; + case UMOB_SIZE: md->status.size = md->base_status->size = (unsigned char)value; break; case UMOB_LEVEL: md->level = (unsigned short)value; break; - case UMOB_HP: status_set_hp(bl, (unsigned int)value, 0); clif_name_area(&md->bl); break; - case UMOB_MAXHP: status_set_hp(bl, (unsigned int)value, 0); status_set_maxhp(bl, (unsigned int)value, 0); clif_name_area(&md->bl); break; + case UMOB_HP: md->base_status->hp = (unsigned int)value; status_set_hp(bl, (unsigned int)value, 0); clif_name_area(&md->bl); break; + case UMOB_MAXHP: md->base_status->hp = md->base_status->max_hp = (unsigned int)value; status_set_maxhp(bl, (unsigned int)value, 0); clif_name_area(&md->bl); break; case UMOB_MASTERAID: md->master_id = value; break; case UMOB_MAPID: if (mapname) value = map_mapname2mapid(mapname); unit_warp(bl, (short)value, 0, 0, CLR_TELEPORT); break; case UMOB_X: if (!unit_walktoxy(bl, (short)value, md->bl.y, 2)) unit_movepos(bl, (short)value, md->bl.y, 0, 0); break; @@ -17773,7 +17773,7 @@ BUILDIN_FUNC(setunitdata) case UMOB_FLEE: md->base_status->flee = (short)value; calc_status = true; break; case UMOB_PDODGE: md->base_status->flee2 = (short)value; calc_status = true; break; case UMOB_CRIT: md->base_status->cri = (short)value; calc_status = true; break; - case UMOB_RACE: md->base_status->race = (unsigned char)value; calc_status = true; break; + case UMOB_RACE: md->status.race = md->base_status->race = (unsigned char)value; break; case UMOB_ELETYPE: md->base_status->def_ele = (unsigned char)value; calc_status = true; break; case UMOB_ELELEVEL: md->base_status->ele_lv = (unsigned char)value; calc_status = true; break; case UMOB_AMOTION: md->base_status->amotion = (short)value; calc_status = true; break; @@ -17802,12 +17802,12 @@ BUILDIN_FUNC(setunitdata) return SCRIPT_CMD_FAILURE; } switch (type) { - case UHOM_SIZE: hd->base_status.size = (unsigned char)value; calc_status = true; break; + case UHOM_SIZE: hd->battle_status.size = hd->base_status.size = (unsigned char)value; break; case UHOM_LEVEL: hd->homunculus.level = (unsigned short)value; break; - case UHOM_HP: status_set_hp(bl, (unsigned int)value, 0); break; - case UHOM_MAXHP: status_set_hp(bl, (unsigned int)value, 0); status_set_maxhp(bl, (unsigned int)value, 0); break; + case UHOM_HP: hd->base_status.hp = (unsigned int)value; status_set_hp(bl, (unsigned int)value, 0); break; + case UHOM_MAXHP: hd->base_status.hp = hd->base_status.max_hp = (unsigned int)value; status_set_maxhp(bl, (unsigned int)value, 0); break; case UHOM_SP: hd->base_status.sp = (unsigned int)value; status_set_sp(bl, (unsigned int)value, 0); break; - case UHOM_MAXSP: hd->base_status.max_sp = (unsigned int)value; status_set_maxsp(bl, (unsigned int)value, 0); break; + case UHOM_MAXSP: hd->base_status.sp = hd->base_status.max_sp = (unsigned int)value; status_set_maxsp(bl, (unsigned int)value, 0); break; case UHOM_MASTERCID: hd->homunculus.char_id = (uint32)value; break; case UHOM_MAPID: if (mapname) value = map_mapname2mapid(mapname); unit_warp(bl, (short)value, 0, 0, CLR_TELEPORT); break; case UHOM_X: if (!unit_walktoxy(bl, (short)value, hd->bl.y, 2)) unit_movepos(bl, (short)value, hd->bl.y, 0, 0); break; @@ -17835,7 +17835,7 @@ BUILDIN_FUNC(setunitdata) case UHOM_FLEE: hd->base_status.flee = (short)value; calc_status = true; break; case UHOM_PDODGE: hd->base_status.flee2 = (short)value; calc_status = true; break; case UHOM_CRIT: hd->base_status.cri = (short)value; calc_status = true; break; - case UHOM_RACE: hd->base_status.race = (unsigned char)value; calc_status = true; break; + case UHOM_RACE: hd->battle_status.race = hd->base_status.race = (unsigned char)value; break; case UHOM_ELETYPE: hd->base_status.def_ele = (unsigned char)value; calc_status = true; break; case UHOM_ELELEVEL: hd->base_status.ele_lv = (unsigned char)value; calc_status = true; break; case UHOM_AMOTION: hd->base_status.amotion = (short)value; calc_status = true; break; @@ -17866,8 +17866,8 @@ BUILDIN_FUNC(setunitdata) switch (type) { case UPET_SIZE: pd->status.size = (unsigned char)value; break; case UPET_LEVEL: pd->pet.level = (unsigned short)value; break; - case UPET_HP: status_set_hp(bl, (unsigned int)value, 0); break; - case UPET_MAXHP: status_set_hp(bl, (unsigned int)value, 0); status_set_maxhp(bl, (unsigned int)value, 0); break; + case UPET_HP: pd->status.hp = pd->status.max_hp = (unsigned int)value; status_set_hp(bl, (unsigned int)value, 0); break; + case UPET_MAXHP: pd->status.hp = pd->status.max_hp = (unsigned int)value; status_set_maxhp(bl, (unsigned int)value, 0); break; case UPET_MASTERAID: pd->pet.account_id = (unsigned int)value; break; case UPET_MAPID: if (mapname) value = map_mapname2mapid(mapname); unit_warp(bl, (short)value, 0, 0, CLR_TELEPORT); break; case UPET_X: if (!unit_walktoxy(bl, (short)value, pd->bl.y, 2)) unit_movepos(bl, (short)value, md->bl.y, 0, 0); break; @@ -17913,9 +17913,9 @@ BUILDIN_FUNC(setunitdata) return SCRIPT_CMD_FAILURE; } switch (type) { - case UMER_SIZE: mc->base_status.size = (unsigned char)value; calc_status = true; break; - case UMER_HP: status_set_hp(bl, (unsigned int)value, 0); break; - case UMER_MAXHP: status_set_hp(bl, (unsigned int)value, 0); status_set_maxhp(bl, (unsigned int)value, 0); break; + case UMER_SIZE: mc->battle_status.size = mc->base_status.size = (unsigned char)value; break; + case UMER_HP: mc->base_status.hp = (unsigned int)value; status_set_hp(bl, (unsigned int)value, 0); break; + case UMER_MAXHP: mc->base_status.hp = mc->base_status.max_hp = (unsigned int)value; status_set_maxhp(bl, (unsigned int)value, 0); break; case UMER_MASTERCID: mc->mercenary.char_id = (uint32)value; break; case UMER_MAPID: if (mapname) value = map_mapname2mapid(mapname); unit_warp(bl, (short)value, 0, 0, CLR_TELEPORT); break; case UMER_X: if (!unit_walktoxy(bl, (short)value, mc->bl.y, 2)) unit_movepos(bl, (short)value, mc->bl.y, 0, 0); break; @@ -17943,7 +17943,7 @@ BUILDIN_FUNC(setunitdata) case UMER_FLEE: mc->base_status.flee = (short)value; calc_status = true; break; case UMER_PDODGE: mc->base_status.flee2 = (short)value; calc_status = true; break; case UMER_CRIT: mc->base_status.cri = (short)value; calc_status = true; break; - case UMER_RACE: mc->base_status.race = (unsigned char)value; calc_status = true; break; + case UMER_RACE: mc->battle_status.race = mc->base_status.race = (unsigned char)value; break; case UMER_ELETYPE: mc->base_status.def_ele = (unsigned char)value; calc_status = true; break; case UMER_ELELEVEL: mc->base_status.ele_lv = (unsigned char)value; calc_status = true; break; case UMER_AMOTION: mc->base_status.amotion = (short)value; calc_status = true; break; @@ -17972,11 +17972,11 @@ BUILDIN_FUNC(setunitdata) return SCRIPT_CMD_FAILURE; } switch (type) { - case UELE_SIZE: ed->base_status.size = (unsigned char)value; calc_status = true; break; - case UELE_HP: status_set_hp(bl, (unsigned int)value, 0); break; - case UELE_MAXHP: status_set_hp(bl, (unsigned int)value, 0); status_set_maxhp(bl, (unsigned int)value, 0); break; + case UELE_SIZE: ed->battle_status.size = ed->base_status.size = (unsigned char)value; break; + case UELE_HP: ed->base_status.hp = (unsigned int)value; status_set_hp(bl, (unsigned int)value, 0); break; + case UELE_MAXHP: ed->base_status.hp = ed->base_status.max_hp = (unsigned int)value; status_set_maxhp(bl, (unsigned int)value, 0); break; case UELE_SP: ed->base_status.sp = (unsigned int)value; status_set_sp(bl, (unsigned int)value, 0); break; - case UELE_MAXSP: ed->base_status.max_sp = (unsigned int)value; status_set_maxsp(bl, (unsigned int)value, 0); break; + case UELE_MAXSP: ed->base_status.sp = ed->base_status.max_sp = (unsigned int)value; status_set_maxsp(bl, (unsigned int)value, 0); break; case UELE_MASTERCID: ed->elemental.char_id = (uint32)value; break; case UELE_MAPID: if (mapname) value = map_mapname2mapid(mapname); unit_warp(bl, (short)value, 0, 0, CLR_TELEPORT); break; case UELE_X: if (!unit_walktoxy(bl, (short)value, ed->bl.y, 2)) unit_movepos(bl, (short)value, ed->bl.y, 0, 0); break; @@ -18004,7 +18004,7 @@ BUILDIN_FUNC(setunitdata) case UELE_FLEE: ed->base_status.flee = (short)value; calc_status = true; break; case UELE_PDODGE: ed->base_status.flee2 = (short)value; calc_status = true; break; case UELE_CRIT: ed->base_status.cri = (short)value; calc_status = true; break; - case UELE_RACE: ed->base_status.race = (unsigned char)value; calc_status = true; break; + case UELE_RACE: ed->battle_status.race = ed->base_status.race = (unsigned char)value; break; case UELE_ELETYPE: ed->base_status.def_ele = (unsigned char)value; calc_status = true; break; case UELE_ELELEVEL: ed->base_status.ele_lv = (unsigned char)value; calc_status = true; break; case UELE_AMOTION: ed->base_status.amotion = (short)value; calc_status = true; break; @@ -18036,8 +18036,8 @@ BUILDIN_FUNC(setunitdata) switch (type) { case UNPC_DISPLAY: status_set_viewdata(bl, (unsigned short)value); break; case UNPC_LEVEL: nd->level = (unsigned int)value; break; - case UNPC_HP: status_set_hp(bl, (unsigned int)value, 0); break; - case UNPC_MAXHP: status_set_hp(bl, (unsigned int)value, 0); status_set_maxhp(bl, (unsigned int)value, 0); break; + case UNPC_HP: nd->status.hp = (unsigned int)value; status_set_hp(bl, (unsigned int)value, 0); break; + case UNPC_MAXHP: nd->status.hp = nd->status.max_hp = (unsigned int)value; status_set_maxhp(bl, (unsigned int)value, 0); break; case UNPC_MAPID: if (mapname) value = map_mapname2mapid(mapname); unit_warp(bl, (short)value, 0, 0, CLR_TELEPORT); break; case UNPC_X: if (!unit_walktoxy(bl, (short)value, nd->bl.y, 2)) unit_movepos(bl, (short)value, nd->bl.x, 0, 0); break; case UNPC_Y: if (!unit_walktoxy(bl, nd->bl.x, (short)value, 2)) unit_movepos(bl, nd->bl.x, (short)value, 0, 0); break; diff --git a/src/map/status.cpp b/src/map/status.cpp index 36ddd70dfe..89246bbd28 100644 --- a/src/map/status.cpp +++ b/src/map/status.cpp @@ -4878,11 +4878,6 @@ void status_calc_bl_main(struct block_list *bl, /*enum scb_flag*/int flag) ud->state.change_walk_target = ud->state.speed_changed = 1; } - if((!(bl->type&BL_REGEN)) && (!sc || !sc->count)) { // No difference. - status_cpy(status, b_status); - return; - } - if(flag&SCB_STR) { status->str = status_calc_str(bl, sc, b_status->str); flag|=SCB_BATK; @@ -5105,6 +5100,13 @@ void status_calc_bl_main(struct block_list *bl, /*enum scb_flag*/int flag) if(flag&SCB_MODE) { status->mode = status_calc_mode(bl, sc, b_status->mode); + + // Only switch between Normal and Boss classes as the others are determined by the race value + if (status->class_ == CLASS_NORMAL && status_has_mode(status, MD_STATUS_IMMUNE|MD_KNOCKBACK_IMMUNE|MD_DETECTOR)) + status->class_ = CLASS_BOSS; + else if (status->class_ == CLASS_BOSS && !status_has_mode(status, MD_STATUS_IMMUNE|MD_KNOCKBACK_IMMUNE|MD_DETECTOR)) + status->class_ = CLASS_NORMAL; + // Since mode changed, reset their state. if (!status_has_mode(status,MD_CANATTACK)) unit_stop_attack(bl);