Skip to content

Commit

Permalink
Track item initial hits, add DM mend ability.
Browse files Browse the repository at this point in the history
Items now track their initial hits as well as max hits. The initial hits
won't change when the item is mended with low spellpower, making it
possible to return an item to its original max condition.

DMs can now return an item to the original condition by casting mend
while immortal.
  • Loading branch information
skittles1 committed Jul 31, 2016
1 parent 6587f9b commit 623880c
Show file tree
Hide file tree
Showing 7 changed files with 74 additions and 27 deletions.
56 changes: 40 additions & 16 deletions kod/object/item.kod
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,12 @@ classvars:
properties:

viObject_flags = OF_GETTABLE

// Item hits set initially. Shouldn't change afterwards.
piHits_init = 0
// Maximum hits for the item. Can change via low spellpower mends etc.
piHits_max = 0
// Current hits for the item. Item breaks when this reaches 0.
piHits = 0

plItem_attributes = $
Expand All @@ -153,6 +158,7 @@ messages:
local iHits_average, oItemAtt;

piHits_init = Random(viHits_init_min,viHits_init_max);
piHits_max = piHits_init;
piHits = piHits_init;
if corpse <> $
{
Expand Down Expand Up @@ -918,15 +924,15 @@ messages:
local iHit_Percent, rItem_condition;

if vbShow_Condition
AND piHits_init > 0
AND piHits_max > 0
{
rItem_condition = vrCondition_exc;
iHit_Percent = (100 * piHits) / piHits_init;
iHit_Percent = (100 * piHits) / piHits_max;
if iHit_Percent > 90
{
// If item is worse than what can be found in the wild, describe it
// as being "patched".
if piHits_init >= viHits_init_min
// If the item max hits is lower than the initial hits, describe it
// as being "patched".
if piHits_max >= piHits_init
{
rItem_condition = vrCondition_exc;
}
Expand All @@ -953,7 +959,7 @@ messages:
}

AddPacket(4,item_cond_master, 4,vrPoss_Article, 4,Send(self,@GetName),
4,rItem_condition,4,piHits,4,piHits_init);
4,rItem_condition,4,piHits,4,piHits_max);
}
else
{
Expand Down Expand Up @@ -1020,16 +1026,16 @@ messages:
// Y = viHits_init_max (max_hits before casting 'mend')
// X = viAverage_value
//
// Translated: An item whose piInit_hits is 80// of viHits_init_max
// Translated: An item whose piHits_max is 80% of viHits_init_max
// and whose piHits is equal to that amount has a value equal
// to 64// of its standard value.
// to 64% of its standard value.

iPercent = (100*piHits_init*piHits)/(viHits_init_max*viHits_init_max);
iPercent = (100 * piHits_max * piHits) / (viHits_init_max * viHits_init_max);
iValue = Send(self,@GetInitValue);
iFinal = (iValue * iPercent)/100;
iFinal = bound(iFinal,10,iValue);

iFinal = (iValue * iPercent) / 100;
iFinal = Bound(iFinal,10,iValue);

foreach i in plItem_Attributes
{
iNum = Send(self,@GetNumFromCompound,#compound=First(i));
Expand All @@ -1041,11 +1047,18 @@ messages:
return iFinal;
}

GetMaxHits()
GetInitHits()
"The item's initial max hits. Keep track of it separately "
"as max hits may change."
{
return piHits_init;
}

GetMaxHits()
{
return piHits_max;
}

GetHits()
{
return piHits;
Expand All @@ -1058,9 +1071,9 @@ messages:
return;
}

piHits_init = number;
piHits_max = number;

return;
return;
}

SetHits(number = $)
Expand All @@ -1075,6 +1088,17 @@ messages:
return;
}

FixMaxHits()
{
if (piHits_init > 0
AND piHits_max = 0)
{
piHits_max = piHits_init;
}

return;
}

NewOwner(what = $)
{
local lData;
Expand Down
3 changes: 3 additions & 0 deletions kod/object/item/passitem/weapon.kod
Original file line number Diff line number Diff line change
Expand Up @@ -165,16 +165,19 @@ messages:
if viWeaponQuality = WEAPON_QUALITY_LOW
{
piHits_init = piHits_init + WEAPON_LOW_QUALITY_HITS;
piHits_max = piHits_max + WEAPON_LOW_QUALITY_HITS;
piHits = piHits + WEAPON_LOW_QUALITY_HITS;
}
else if viWeaponQuality = WEAPON_QUALITY_HIGH
{
piHits_init = piHits_init + WEAPON_HIGH_QUALITY_HITS;
piHits_max = piHits_max + WEAPON_HIGH_QUALITY_HITS;
piHits = piHits + WEAPON_HIGH_QUALITY_HITS;
}
else if viWeaponQuality = WEAPON_NERUDITE
{
piHits_init = piHits_init + WEAPON_NERUDITE_HITS;
piHits_max = piHits_max + WEAPON_NERUDITE_HITS;
piHits = piHits + WEAPON_NERUDITE_HITS;
}

Expand Down
2 changes: 1 addition & 1 deletion kod/object/item/passitem/weapon/ranged.kod
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,7 @@ messages:
}
else
{
hit_roll = hit_roll + ((viHit_roll_modifier * piHits) / piHits_Init);
hit_roll = hit_roll + ((viHit_roll_modifier * piHits) / piHits_max);
}

iWeapHit = hit_roll;
Expand Down
6 changes: 4 additions & 2 deletions kod/object/passive/itematt/iadurabl.kod
Original file line number Diff line number Diff line change
Expand Up @@ -70,8 +70,10 @@ messages:

iHits = Send(oItem,@GetMaxHits);
iHits = (iHits * state1)/100;
iHits = bound(iHits,1,$);
Send(oItem,@setMaxHits,#number=iHits);
iHits = Bound(iHits,1,$);

// Sets max hits, not initial.
Send(oItem,@SetMaxHits,#number=iHits);
Send(oItem,@SetHits,#number=Send(oItem,@GetMaxHits));

return;
Expand Down
2 changes: 1 addition & 1 deletion kod/object/passive/spell.kod
Original file line number Diff line number Diff line change
Expand Up @@ -326,7 +326,7 @@ messages:
rOutlaw = spell_outlaw;
}

rExtra = Send(self,@GetExtraDesc);
rExtra = Send(self,@GetExtraDesc,#who=who);

AddPacket(4,spell_desc_rsc, 4,rSchool, 4,viSpell_Level, 4,vrDesc,
4,rOutlaw, 4,rExtra);
Expand Down
29 changes: 22 additions & 7 deletions kod/object/passive/spell/itemench/mend.kod
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,9 @@ resources:
"Erases the wear of battle from a piece of equipment, restoring it to "
"near new condition. "
"Requires an orc tooth and a sapphire to cast."

mend_extradesc_rsc = \
"\n\nIf you mend an item while immortal, the item will be "
"returned to its original condition."
mend_not_weaponry = "You try to focus on %s%s, but nothing happens!"
mend_beyond_hope = "%s%s is beyond salvage."
mend_full_healed = "%s%s is already in perfect condition."
Expand All @@ -37,6 +39,7 @@ classvars:
vrName = mend_name_rsc
vrIcon = mend_icon_rsc
vrDesc = mend_desc_rsc
vrExtraDesc = mend_extradesc_rsc

viSpell_num = SID_MEND
viSchool = SS_KRAANAN
Expand Down Expand Up @@ -124,23 +127,35 @@ messages:
{
// Immortals heal items back up to full.
iMultiplier = 100;
iAmount = Send(oTarget,@GetInitHits);
}
else
{
// Multiplier is a number from 75// to 95//.
iMultiplier = 75 + iSpellpower/5;
iMultiplier = bound(iMultiplier,75,95);
// Multiplier is a number from 75% to 95%.
iMultiplier = 75 + iSpellpower / 5;
iMultiplier = Bound(iMultiplier,75,95);
}

iAmount = (iAmount*iMultiplier)/100;
iAmount = (iAmount * iMultiplier) / 100;

Send(oTarget,@SetMaxHits,#number=iAmount);
Send(oTarget,@SetHits,#number=iAmount);
Send(who,@MsgSendUser,#message_rsc=mend_working,
#parm1=Send(oTarget,@GetDef),#parm2=Send(oTarget,@GetName));
#parm1=Send(oTarget,@GetDef),#parm2=Send(oTarget,@GetName));

propagate;
}

GetExtraDesc(who=$)
{
if (who <> $
AND IsClass(who,&DM))
{
return vrExtraDesc;
}

propagate;
}

end
////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////
3 changes: 3 additions & 0 deletions kod/object/passive/spell/itemench/mend.lkod
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@ mend_name_rsc = de "Reparieren"
mend_desc_rsc = de \
"Beseitigt die Spuren vieler K�mpfe von einem Teil der Ausr�stung und "
"stellt sie fast v�llig wieder her. Der Zauber ben�tigt einen Orkzahn und einen Saphir."
mend_extradesc_rsc = de \
"\n\nWenn du als Unsterblicher einen Gegenstand reparierst, ist dieser "
"wieder in seinem urspr�nglichen Zustand."
mend_not_weaponry = de \
"Du versuchst dich auf %s%s zu fokussieren, aber es scheint nicht zu funktionieren!"
mend_beyond_hope = de "%s%s ist nicht mehr zu retten."
Expand Down

0 comments on commit 623880c

Please sign in to comment.