The Cathedral of Attnam

Iter Vehemens ad Necem (IVAN)
Login
Username
Password


 Valid CSS  Valid HTML 4.01 Strict

Piece of code

The Cathedral of Attnam  >  Programming
Print

View profile
Send message
Find posts Find topics
 
Mar 27, 2008 at 12:22 am #1  !
Planplan's Avatar
Planplan
zombie


Joined: Feb 28, 2008
Occupation: Web developper
Location: Paris
Posts: 38
Groups:
Piece of code
Here a small piece of code I made to allow Helmet, Cloak, Body Armor and Belt to add Arm Strength, Dexterity, Leg Strength and Agility. It's maybe a bit dirty, but it work.
The enchant bonus is divised by 2, because the bonus value is added to each arm or leg. A +1 Dexterity bonus will add +0.5 Dexterity to each arm so (could be invisible for a +1 item so, unless you're Dexterity is already a bit trained).
Code

---------- bodypart.h ----------

ITEM(bodypart, item)
{
public:
...
item* GetExternalHelmet() const;
item* GetExternalBelt() const;
...
};

ITEM(arm, bodypart)
{
public:
...
void ApplyStrengthBonus(item*);
void ApplyDexterityBonus(item*);
...
};

ITEM(leg, bodypart)
{
public:
...
void ApplyStrengthBonus(item*);
void ApplyAgilityBonus(item*);
...
};


---------- bodypart.cpp ----------

item* bodypart::GetExternalHelmet() const { return GetHumanoidMaster()->GetHelmet(); }
item* bodypart::GetExternalBelt() const { return GetHumanoidMaster()->GetBelt(); }


void arm::CalculateAttributeBonuses()
{
...
if(Master)
{
...
ApplyStrengthBonus(GetExternalHelmet());
ApplyStrengthBonus(GetExternalCloak());
ApplyStrengthBonus(GetExternalBodyArmor());
ApplyStrengthBonus(GetExternalBelt());
ApplyDexterityBonus(GetExternalHelmet());
ApplyDexterityBonus(GetExternalCloak());
ApplyDexterityBonus(GetExternalBodyArmor());
ApplyDexterityBonus(GetExternalBelt());
}
}

void leg::CalculateAttributeBonuses()
{
...
if(Master)
{
...
ApplyStrengthBonus(GetExternalHelmet());
ApplyStrengthBonus(GetExternalCloak());
ApplyStrengthBonus(GetExternalBodyArmor());
ApplyStrengthBonus(GetExternalBelt());
ApplyAgilityBonus(GetExternalHelmet());
ApplyAgilityBonus(GetExternalCloak());
ApplyAgilityBonus(GetExternalBodyArmor());
ApplyAgilityBonus(GetExternalBelt());
}
}


void arm::ApplyStrengthBonus(item* Item)
{
if(Item && Item->AffectsArmStrength())
StrengthBonus += Item->GetEnchantment() / 2;
}

void arm::ApplyDexterityBonus(item* Item)
{
if(Item && Item->AffectsDexterity())
DexterityBonus += Item->GetEnchantment() / 2;
}

void leg::ApplyStrengthBonus(item* Item)
{
if(Item && Item->AffectsLegStrength())
StrengthBonus += Item->GetEnchantment() / 2;
}

void leg::ApplyAgilityBonus(item* Item)
{
if(Item && Item->AffectsAgility())
AgilityBonus += Item->GetEnchantment() / 2;
}


Tell me if you encounter bugs, I'll edit this code, and feel free to post your own.
 
Last edited by Planplan : Mar 27, 2008 at 4:36 pm. Edited 2 times total
 
View profile
Send message
Find posts Find topics
 
Mar 27, 2008 at 12:31 am #2  !
Dumb Shit's Avatar
Dumb Shit
Banned


Joined: Mar 14, 2008
Posts: 62
Have you ever heard of a program called "Diff"
 
 
View profile
Send message
Find posts Find topics
 
Mar 27, 2008 at 3:22 pm #3  !
nukes
hedgehog


Joined: Mar 25, 2008
Posts: 9
If it's not needed other changes from the CVS version could you make me a patch?
 
 
View profile
Send message
Find posts Find topics
 
Mar 27, 2008 at 4:39 pm #4  !
Planplan's Avatar
Planplan
zombie


Joined: Feb 28, 2008
Occupation: Web developper
Location: Paris
Posts: 38
Groups:
Here for you nukes, added it to my first message. Nice people always get what they want
 
 
 Print


The Cathedral of Attnam  >  Programming  >  Piece of code

Jump to