--- deliantra/server/common/object.C 2007/05/07 03:05:58 1.145 +++ deliantra/server/common/object.C 2007/05/12 16:06:42 1.147 @@ -31,6 +31,7 @@ #include #include #include +#include #include #include @@ -451,15 +452,45 @@ this->owner = owner; } -void -object::set_weapon (object *ob) +bool +object::change_weapon (object *ob) { if (current_weapon == ob) - return; + return true; + + if (chosen_skill) + chosen_skill->flag [FLAG_APPLIED] = false; current_weapon = ob; - new_draw_info_format (NDI_UNIQUE, 0, this, "You switch to your %s.", &ob->name); + chosen_skill = !ob || ob->type == SKILL ? ob : find_skill_by_name (this, ob->skill); + + if (chosen_skill) + chosen_skill->flag [FLAG_APPLIED] = true; + 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) + { + current_weapon = chosen_skill = 0; + update_stats (); + + new_draw_info_format (NDI_UNIQUE, 0, this, + "You try to balance your applied items all at once, but the %s is too much. " + "You need to unapply some items first.", &ob->name); + return false; + } + + new_draw_info_format (NDI_UNIQUE, 0, this, "You switch to your %s.", &ob->name); + } + else + new_draw_info_format (NDI_UNIQUE, 0, this, "You unwield your weapons."); + + return true; } /* Zero the key_values on op, decrementing the shared-string