| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
|
| 18 |
|
| 19 |
|
| 20 |
|
| 21 |
|
| 22 |
|
| 23 |
|
| 24 |
|
| 25 |
|
| 26 |
|
| 27 |
#include <global.h> |
| 28 |
#include <ob_methods.h> |
| 29 |
#include <ob_types.h> |
| 30 |
#include <sounds.h> |
| 31 |
#include <sproto.h> |
| 32 |
|
| 33 |
static method_ret armour_improver_type_apply(ob_methods *context, object *lighter, object *applier, int aflags); |
| 34 |
|
| 35 |
|
| 36 |
|
| 37 |
|
| 38 |
void init_type_armour_improver(void) { |
| 39 |
register_apply(ARMOUR_IMPROVER, armour_improver_type_apply); |
| 40 |
} |
| 41 |
|
| 42 |
|
| 43 |
|
| 44 |
|
| 45 |
|
| 46 |
|
| 47 |
|
| 48 |
|
| 49 |
|
| 50 |
|
| 51 |
|
| 52 |
|
| 53 |
|
| 54 |
|
| 55 |
|
| 56 |
|
| 57 |
|
| 58 |
static void improve_armour(object *op, object *improver, object *armour) { |
| 59 |
object *tmp; |
| 60 |
int oldmagic = armour->magic; |
| 61 |
|
| 62 |
if (armour->magic >= settings.armor_max_enchant) { |
| 63 |
draw_ext_info(NDI_UNIQUE, 0, op, MSG_TYPE_APPLY, MSG_TYPE_APPLY_ERROR, |
| 64 |
"This armour can not be enchanted any further."); |
| 65 |
return; |
| 66 |
} |
| 67 |
|
| 68 |
|
| 69 |
|
| 70 |
|
| 71 |
|
| 72 |
|
| 73 |
if (armour->title) { |
| 74 |
draw_ext_info(NDI_UNIQUE, 0, op, MSG_TYPE_APPLY, MSG_TYPE_APPLY_ERROR, |
| 75 |
"This armour will not accept further enchantment."); |
| 76 |
return; |
| 77 |
} |
| 78 |
|
| 79 |
|
| 80 |
|
| 81 |
if (QUERY_FLAG(armour, FLAG_APPLIED) |
| 82 |
&& op->type == PLAYER |
| 83 |
&& (op->contr->item_power+1) > (settings.item_power_factor*op->level)) { |
| 84 |
apply_special(op, armour, AP_UNAPPLY); |
| 85 |
if (QUERY_FLAG(armour, FLAG_APPLIED)) { |
| 86 |
|
| 87 |
draw_ext_info(NDI_UNIQUE, 0, op, |
| 88 |
MSG_TYPE_APPLY, MSG_TYPE_APPLY_ERROR, |
| 89 |
"You can't enchant this armour without unapplying it because it would consume your soul!"); |
| 90 |
return; |
| 91 |
} |
| 92 |
} |
| 93 |
|
| 94 |
|
| 95 |
|
| 96 |
if (armour->nrof > 1) |
| 97 |
tmp = object_split(armour, armour->nrof-1, NULL, 0); |
| 98 |
else |
| 99 |
tmp = NULL; |
| 100 |
|
| 101 |
armour->magic++; |
| 102 |
|
| 103 |
if (!settings.armor_speed_linear) { |
| 104 |
int base = 100; |
| 105 |
int pow = 0; |
| 106 |
|
| 107 |
while (pow < armour->magic) { |
| 108 |
base = base-(base*settings.armor_speed_improvement)/100; |
| 109 |
pow++; |
| 110 |
} |
| 111 |
|
| 112 |
ARMOUR_SPEED(armour) = (ARMOUR_SPEED(&armour->arch->clone)*base)/100; |
| 113 |
} else |
| 114 |
ARMOUR_SPEED(armour) = (ARMOUR_SPEED(&armour->arch->clone)*(100+armour->magic*settings.armor_speed_improvement))/100; |
| 115 |
|
| 116 |
if (!settings.armor_weight_linear) { |
| 117 |
int base = 100; |
| 118 |
int pow = 0; |
| 119 |
|
| 120 |
while (pow < armour->magic) { |
| 121 |
base = base-(base*settings.armor_weight_reduction)/100; |
| 122 |
pow++; |
| 123 |
} |
| 124 |
armour->weight = (armour->arch->clone.weight*base)/100; |
| 125 |
} else |
| 126 |
armour->weight = (armour->arch->clone.weight*(100-armour->magic*settings.armor_weight_reduction))/100; |
| 127 |
|
| 128 |
if (armour->weight <= 0) { |
| 129 |
LOG(llevInfo, "Warning: enchanted armours can have negative weight\n."); |
| 130 |
armour->weight = 1; |
| 131 |
} |
| 132 |
|
| 133 |
armour->item_power += (armour->magic-oldmagic)*3; |
| 134 |
if (armour->item_power < 0) |
| 135 |
armour->item_power = 0; |
| 136 |
|
| 137 |
if (op->type == PLAYER) { |
| 138 |
esrv_update_item(UPD_WEIGHT|UPD_NAME|UPD_NROF, op, armour); |
| 139 |
if (QUERY_FLAG(armour, FLAG_APPLIED)) |
| 140 |
fix_object(op); |
| 141 |
} |
| 142 |
object_decrease_nrof_by_one(improver); |
| 143 |
if (tmp) { |
| 144 |
object_insert_in_ob(tmp, op); |
| 145 |
} |
| 146 |
return; |
| 147 |
} |
| 148 |
|
| 149 |
|
| 150 |
|
| 151 |
|
| 152 |
|
| 153 |
|
| 154 |
|
| 155 |
|
| 156 |
|
| 157 |
|
| 158 |
|
| 159 |
|
| 160 |
|
| 161 |
|
| 162 |
|
| 163 |
static method_ret armour_improver_type_apply(ob_methods *context, object *scroll, object *applier, int aflags) { |
| 164 |
object *armor; |
| 165 |
|
| 166 |
if (applier->type != PLAYER) |
| 167 |
return METHOD_UNHANDLED; |
| 168 |
|
| 169 |
if (!QUERY_FLAG(applier, FLAG_WIZCAST) |
| 170 |
&& (get_map_flags(applier->map, NULL, applier->x, applier->y, NULL, NULL)&P_NO_MAGIC)) { |
| 171 |
draw_ext_info(NDI_UNIQUE, 0, applier, MSG_TYPE_APPLY, MSG_TYPE_APPLY_ERROR, |
| 172 |
"Something blocks the magic of the scroll."); |
| 173 |
return METHOD_OK; |
| 174 |
} |
| 175 |
armor = find_marked_object(applier); |
| 176 |
if (!armor) { |
| 177 |
draw_ext_info(NDI_UNIQUE, 0, applier, MSG_TYPE_APPLY, MSG_TYPE_APPLY_ERROR, |
| 178 |
"You need to mark an armor object."); |
| 179 |
return METHOD_OK; |
| 180 |
} |
| 181 |
if (armor->type != ARMOUR |
| 182 |
&& armor->type != CLOAK |
| 183 |
&& armor->type != BOOTS |
| 184 |
&& armor->type != GLOVES |
| 185 |
&& armor->type != BRACERS |
| 186 |
&& armor->type != SHIELD |
| 187 |
&& armor->type != HELMET) { |
| 188 |
draw_ext_info(NDI_UNIQUE, 0, applier, MSG_TYPE_APPLY, MSG_TYPE_APPLY_ERROR, |
| 189 |
"Your marked item is not armour!"); |
| 190 |
return METHOD_OK; |
| 191 |
} |
| 192 |
|
| 193 |
draw_ext_info(NDI_UNIQUE, 0, applier, MSG_TYPE_APPLY, MSG_TYPE_APPLY_SUCCESS, |
| 194 |
"Applying armour enchantment."); |
| 195 |
improve_armour(applier, scroll, armor); |
| 196 |
return METHOD_OK; |
| 197 |
} |