Tradeskills.cpp
Code:
//returns true on success
<!bool Client::TradeskillExecute(DBTradeskillRecipe_Struct *spec, SkillType tradeskill) {
>!bool Client::TradeskillExecute(DBTradeskillRecipe_Struct *spec) {
<! if(spec == NULL || tradeskill == 0)
!> if(spec == NULL)
return(false);
<! int16 user_skill = GetSkill(tradeskill);
!> int16 user_skill = GetSkill(spec->tradeskill);
float chance = 0;
float skillup_modifier;
sint16 thirdstat = 0;
sint16 stat_modifier = 15;
uint16 success_modifier;
// Rework based on the info on eqtraders.com
// http://mboards.eqtraders.com/eq/showthread.php?t=22246
// 09/10/2006 v0.1 (eq4me)
// 09/11/2006 v0.2 (eq4me)
// Todo:
// Implementing AAs
// Success modifiers based on recipes
// Skillup modifiers based on the rarity of the ingredients
// Some tradeskills are more eqal then others. ;-)
// If you want to customize the stage1 success rate do it here.
// Remember: skillup_modifier is (float). Lower is better
<! switch(tradeskill) {
!> switch(spec->tradeskill) {
case FLETCHING:
case ALCHEMY:
case JEWELRY_MAKING:
case POTTERY:
skillup_modifier = 4;
break;
case BAKING:
case BREWING:
skillup_modifier = 3;
break;
case RESEARCH:
skillup_modifier = 1;
break;
default:
skillup_modifier = 2;
break;
}
// Some tradeskills take the higher of one additional stat beside INT and WIS
// to determine the skillup rate. Additionally these tradeskills do not have an
// -15 modifier on their statbonus.
<! if (tradeskill == FLETCHING || tradeskill == MAKE_POISON) {
!> switch(spec->tradeskill) {
!> case FLETCHING:
!> case MAKE_POISON:
thirdstat = GetDEX();
stat_modifier = 0;
break;
<! } else if (tradeskill == BLACKSMITHING) {
!> case BLACKSMITHING:
thirdstat = GetSTR();
stat_modifier = 0;
!> break;
!> default:
!> break;
}
sint16 higher_from_int_wis = (GetINT() > GetWIS()) ? GetINT() : GetWIS();
sint16 bonusstat = (higher_from_int_wis > thirdstat) ? higher_from_int_wis : thirdstat;
vector< pair<uint32,uint8> >::iterator itr;
//calculate the base success chance
// For trivials over 68 the chance is (skill - 0.75*trivial) +51.5
// For trivial up to 68 the chance is (skill - trivial) + 66
if (spec->trivial >= 68) {
chance = (user_skill - (0.75*spec->trivial)) + 51.5;
} else {
chance = (user_skill - spec->trivial) + 66;
}
sint16 over_trivial = (sint16)user_skill - (sint16)spec->trivial;
//handle caps
if(spec->nofail) {
chance = 100; //cannot fail.
_log(TRADESKILLS__TRACE, "...This combine cannot fail.");
} else if(over_trivial > 0) {
// At reaching trivial the chance goes to 95% going up an additional
// percent for every 40 skillpoints above the trivial.
// The success rate is not modified through stats.
// Mastery AAs are unaccounted for so far.
// chance_AA = chance + ((100 - chance) * mastery_modifier)
// But the 95% limit with an additional 1% for every 40 skill points
// above critical still stands.
// Mastery modifier is: 10%/25%/50% for rank one/two/three
chance = 95.0f + (float(user_skill - spec->trivial) / 40.0f);
Message_StringID(4, TRADESKILL_TRIVIAL);
} else if(chance < 5) {
// Minimum chance is always 5
chance = 5;
} else if(chance > 95) {
//cap is 95, shouldent reach this before trivial, but just in case.
chance = 95;
}
_log(TRADESKILLS__TRACE, "...Current skill: %d , Trivial: %d , Success chance: %f percent", user_skill , spec->trivial , chance);
_log(TRADESKILLS__TRACE, "...Bonusstat: %d , INT: %d , WIS: %d , DEX: %d , STR: %d", bonusstat , GetINT() , GetWIS() , GetDEX() , GetSTR());
float res = MakeRandomFloat(0, 99);
<! if ((tradeskill==75) || GetGM() || (chance > res)){
>! if ((spec->tradeskill==75) || GetGM() || (chance > res)){
success_modifier = 1;
if(over_trivial < 0)
<! CheckIncreaseTradeskill(bonusstat, stat_modifier, skillup_modifier, success_modifier, tradeskill);
!> CheckIncreaseTradeskill(bonusstat, stat_modifier, skillup_modifier, success_modifier, spec->tradeskill);
Message_StringID(4,TRADESKILL_SUCCEED);
_log(TRADESKILLS__TRACE, "Tradeskill success");
itr = spec->onsuccess.begin();
while(itr != spec->onsuccess.end()) {
//should we check this crap?
SummonItem(itr->first, itr->second);
itr++;
}
return(true);
} else {
success_modifier = 2; // Halves the chance
if(over_trivial < 0)
<! CheckIncreaseTradeskill(bonusstat, stat_modifier, skillup_modifier, success_modifier, tradeskill);
!> CheckIncreaseTradeskill(bonusstat, stat_modifier, skillup_modifier, success_modifier, spec->tradeskill);
Message_StringID(4,TRADESKILL_FAILED);
_log(TRADESKILLS__TRACE, "Tradeskill failed");
itr = spec->onfail.begin();
while(itr != spec->onfail.end()) {
//should we check these arguments?
SummonItem(itr->first, itr->second);
itr++;
}
}
return(false);
}
changed signature to remove tradeskill as it is now part of spec
changed references to tradeskill to spec->tradeskill
changed compound if statement to switch to facilitate changes in evaluation (not needed for code to work)