--- deliantra/server/common/object.C 2010/03/28 02:53:46 1.316 +++ deliantra/server/common/object.C 2010/04/02 03:41:24 1.317 @@ -599,48 +599,27 @@ if (current_weapon == ob) return true; - if (chosen_skill) - chosen_skill->flag [FLAG_APPLIED] = false; - - current_weapon = ob; - chosen_skill = !ob || ob->type == SKILL ? ob : find_skill_by_name (this, ob->skill); - - if (chosen_skill) - chosen_skill->flag [FLAG_APPLIED] = true; + if (current_weapon && current_weapon->flag [FLAG_APPLIED]) + { + manual_apply (this, current_weapon, AP_UNAPPLY); - update_stats (); - - if (ob) - { - // now check wether any body locations became invalid, in which case - // we cannot apply the weapon at the moment. - for (int i = 0; i < NUM_BODY_LOCATIONS; ++i) - if (slot[i].used < 0) - { - if (chosen_skill) - chosen_skill->flag [FLAG_APPLIED] = false; - - current_weapon = chosen_skill = 0; - update_stats (); - - new_draw_info_format (NDI_UNIQUE, 0, this, - "You try to balance all your items at once, " - "but the %s is just too much for your body. " - "[You need to unapply some items first - use the 'body' command to see " - "how many items you can wear on a specific body part.]", &ob->name); - return false; - } + if (current_weapon && !current_weapon->flag [FLAG_APPLIED])//D + LOG (llevError, "FATAL: did not clear current_weapon (%s)\n", current_weapon->debug_desc ()); - //new_draw_info_format (NDI_UNIQUE, 0, this, "You switch to your %s.", &ob->name); + if (current_weapon && current_weapon->flag [FLAG_APPLIED]) + return false; } - else - ;//new_draw_info_format (NDI_UNIQUE, 0, this, "You unwield your weapons."); - if (ob && !ob->flag [FLAG_APPLIED] && ob->type != SPELL) + current_weapon = 0; + + if (ob && !ob->flag [FLAG_APPLIED]) { - LOG (llevError | logBacktrace, "%s changed to unapplied weapon %s", - &name, ob->debug_desc ()); - return false; + manual_apply (this, ob, AP_APPLY); + + if (ob->flag [FLAG_APPLIED]) + current_weapon = ob; + else + return false; } return true; @@ -1154,9 +1133,23 @@ if (pl && pl->is_player ()) { + if (expect_false (pl->contr->combat_ob == this)) + { + pl->apply (pl->contr->combat_ob, AP_UNAPPLY); + pl->contr->combat_ob = 0; + if (pl->contr->ranged_ob) pl->apply (pl->contr->ranged_ob); + } + + if (expect_false (pl->contr->ranged_ob == this)) + { + pl->apply (pl->contr->ranged_ob, AP_UNAPPLY); + pl->contr->ranged_ob = 0; + if (pl->contr->combat_ob) pl->apply (pl->contr->combat_ob); + } + pl->contr->queue_stats_update (); - if (glow_radius && pl->is_on_map ()) + if (expect_false (glow_radius) && pl->is_on_map ()) update_all_los (pl->map, pl->x, pl->y); } }