Skip to content
This repository has been archived by the owner on Dec 4, 2020. It is now read-only.

Commit

Permalink
Merge branch 'feature/synth-science' into release
Browse files Browse the repository at this point in the history
  • Loading branch information
zach2good committed Sep 26, 2020
2 parents ead5782 + 2fe384b commit f20edbd
Show file tree
Hide file tree
Showing 4 changed files with 111 additions and 150 deletions.
11 changes: 6 additions & 5 deletions conf/default/map.conf
Original file line number Diff line number Diff line change
Expand Up @@ -116,14 +116,15 @@ craft_chance_multiplier: 1.0
skillup_amount_multiplier: 1
craft_amount_multiplier: 1

#Craft level limit from witch specialization points beging to count. (Retail: 700; Level 75 era:600)
craft_common_cap: 700

#Amount of points allowed in crafts over the level defined above. Points are shared across all crafting skills. (Retail: 400; All skills can go to max: 3200)
craft_specialization_points: 400

#Enable/disable skill-ups from bloodpacts
skillup_bloodpact: 1

#Crafting Factors. DO NOT change defaults without verifiable proof that your change IS how retail does it. Myths need to be optional.
craft_day_matters: 0
craft_moonphase_matters: 0
craft_direction_matters: 0

#Adjust rate of TP gain for mobs and players. Acts as a multiplier, so default is 1.
mob_tp_multiplier: 1.0
player_tp_multiplier: 1.0
Expand Down
21 changes: 8 additions & 13 deletions src/map/map.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -967,13 +967,12 @@ int32 map_config_default()
map_config.speed_mod = 0;
map_config.mount_speed_mod = 0;
map_config.mob_speed_mod = 0;
map_config.skillup_chance_multiplier = 2.5f;
map_config.craft_chance_multiplier = 2.6f;
map_config.skillup_chance_multiplier = 1.0f;
map_config.craft_chance_multiplier = 1.0f;
map_config.skillup_amount_multiplier = 1;
map_config.craft_amount_multiplier = 1;
map_config.craft_day_matters = 1;
map_config.craft_moonphase_matters = 0;
map_config.craft_direction_matters = 0;
map_config.craft_common_cap = 700;
map_config.craft_specialization_points = 400;
map_config.mob_tp_multiplier = 1.0f;
map_config.player_tp_multiplier = 1.0f;
map_config.nm_hp_multiplier = 1.0f;
Expand Down Expand Up @@ -1257,17 +1256,13 @@ int32 map_config_read(const int8* cfgName)
{
map_config.craft_amount_multiplier = (float)atof(w2);
}
else if (strcmp(w1, "craft_day_matters") == 0)
else if (strcmp(w1, "craft_common_cap") == 0)
{
map_config.craft_day_matters = atof(w2);
map_config.craft_common_cap = atoi(w2);
}
else if (strcmp(w1, "craft_moonphase_matters") == 0)
else if (strcmp(w1, "craft_specialization_points") == 0)
{
map_config.craft_moonphase_matters = atof(w2);
}
else if (strcmp(w1, "craft_direction_matters") == 0)
{
map_config.craft_direction_matters = atof(w2);
map_config.craft_specialization_points = atoi(w2);
}
else if (strcmp(w1, "mysql_host") == 0)
{
Expand Down
5 changes: 2 additions & 3 deletions src/map/map.h
Original file line number Diff line number Diff line change
Expand Up @@ -95,9 +95,8 @@ struct map_config_t
float craft_chance_multiplier; // Constant used in the crafting skill-up formula that has a strong effect on skill-up rates
float skillup_amount_multiplier; // Used to increase the amount of skill gained during skill up
float craft_amount_multiplier; // Used to increase the amount of skill gained during skill up
bool craft_day_matters; // Enable/disable Element day factor in synthesis
bool craft_moonphase_matters; // Enable/disable Moon phase factor in synthesis
bool craft_direction_matters; // Enable/disable Compass direction factor in synthesis
uint16 craft_common_cap; // Used in crafting, in synthutils.cpp. Defines skill limit before specialization system
uint16 craft_specialization_points; // Used in crafting, in synthutils.cpp. Defines the maximum points of the specialization system.
float mob_tp_multiplier; // Multiplies the amount of TP mobs gain on any effect that would grant TP
float player_tp_multiplier; // Multiplies the amount of TP players gain on any effect that would grant TP
bool mob_no_despawn; // Toggle whether mobs roam home or despawn
Expand Down
224 changes: 95 additions & 129 deletions src/map/utils/synthutils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ bool isRightRecipe(CCharEntity* PChar)
uint16 skillValue = 0;
uint16 currentSkill = 0;

for (uint8 skillID = 49; skillID < 57; ++skillID) // range for all 8 synth skills
for (uint8 skillID = SKILL_WOODWORKING; skillID <= SKILL_COOKING; ++skillID) // range for all 8 synth skills
{
skillValue = (uint16)Sql_GetUIntData(SqlHandle,(skillID-49+2));
currentSkill = PChar->RealSkills.skill[skillID];
Expand Down Expand Up @@ -165,11 +165,6 @@ bool isRightRecipe(CCharEntity* PChar)

double getSynthDifficulty(CCharEntity* PChar, uint8 skillID)
{
uint8 ElementDirection = 0;
uint8 WeekDay = (uint8)CVanaTime::getInstance()->getWeekday();
uint8 crystalElement = PChar->CraftContainer->getType();
uint8 direction = (PChar->loc.p.rotation - 16)/32;
uint8 strongElement[8] = {2,3,5,4,0,1,7,6};
Mod ModID = Mod::NONE;

switch (skillID)
Expand All @@ -186,55 +181,8 @@ double getSynthDifficulty(CCharEntity* PChar, uint8 skillID)

uint8 charSkill = PChar->RealSkills.skill[skillID]/10; //player skill level is truncated before synth difficulty is calced
double difficult = PChar->CraftContainer->getQuantity(skillID-40) - (double)(charSkill + PChar->getMod(ModID));
double MoonPhase = (double)CVanaTime::getInstance()->getMoonPhase();

if (map_config.craft_day_matters == 1)
{
if (crystalElement == WeekDay)
difficult -= 1;
else if (strongElement[crystalElement] == WeekDay)
difficult += 1;
else if (strongElement[WeekDay] == crystalElement)
difficult -= 1;
else if (WeekDay == LIGHTSDAY)
difficult -= 1;
else if (WeekDay == DARKSDAY)
difficult += 1;
}

if (map_config.craft_moonphase_matters == 1)
{
difficult -= (MoonPhase - 50)/50; // full moon reduces difficulty by 1, new moon increases difficulty by 1, 50% moon has 0 effect
}

if (map_config.craft_direction_matters == 1)
{
switch (direction)
{
case 0: ElementDirection = ELEMENT_WIND; break;
case 1: ElementDirection = ELEMENT_EARTH; break;
case 2: ElementDirection = ELEMENT_LIGHTNING; break;
case 3: ElementDirection = ELEMENT_WATER; break;
case 4: ElementDirection = ELEMENT_FIRE; break;
case 5: ElementDirection = ELEMENT_DARK; break;
case 6: ElementDirection = ELEMENT_LIGHT; break;
case 7: ElementDirection = ELEMENT_ICE; break;
}

if (crystalElement == ElementDirection)
{
difficult -= 0.5;
}
else if (strongElement[crystalElement] == ElementDirection)
{
difficult += 0.5;
}
}

#ifdef _TPZ_SYNTH_DEBUG_MESSAGES_
ShowDebug(CL_CYAN"Direction = %i\n" CL_RESET, ElementDirection);
ShowDebug(CL_CYAN"Day = %i\n" CL_RESET, WeekDay);
ShowDebug(CL_CYAN"Moon = %g\n" CL_RESET, MoonPhase);
ShowDebug(CL_CYAN"Difficulty = %g\n" CL_RESET, difficult);
#endif

Expand Down Expand Up @@ -287,12 +235,7 @@ uint8 calcSynthResult(CCharEntity* PChar)
double chance = 0;
double random = tpzrand::GetRandomNumber(1.);

double MoonPhase = (double)CVanaTime::getInstance()->getMoonPhase();
uint8 WeekDay = (uint8)CVanaTime::getInstance()->getWeekday();
uint8 crystalElement = PChar->CraftContainer->getType();
uint8 strongElement[8] = {2,3,5,4,0,1,7,6};

for(uint8 skillID = 49; skillID < 57; ++skillID)
for (uint8 skillID = SKILL_WOODWORKING; skillID <= SKILL_COOKING; ++skillID)
{
uint8 checkSkill = PChar->CraftContainer->getQuantity(skillID-40);
if(checkSkill != 0)
Expand Down Expand Up @@ -393,23 +336,6 @@ uint8 calcSynthResult(CCharEntity* PChar)

if(chance > 0 && canHQ) // if there is a chance already and it can HQ, we add myth mods
{
if (map_config.craft_moonphase_matters)
chance *= 1.0 - (MoonPhase - 50)/150; //new moon +33% of base rate bonus to hq chance, full moon -33%, corresponding/weakday/lightsday -33%, opposing/darksday +33%

if (map_config.craft_day_matters)
{
if (crystalElement == WeekDay)
chance *= 1.0 - ((double)1 / 3);
else if (strongElement[crystalElement] == WeekDay)
chance *= 1.0 + ((double)1 / 3);
else if (strongElement[WeekDay] == crystalElement)
chance *= 1.0 - ((double)1 / 3);
else if (WeekDay == LIGHTSDAY)
chance *= 1.0 - ((double)1 / 3);
else if (WeekDay == DARKSDAY)
chance *= 1.0 + ((double)1 / 3);
}

//limit max hq chance
if (PChar->CraftContainer->getCraftType() == 1)
chance = std::clamp(chance, 0., 0.800);
Expand Down Expand Up @@ -479,16 +405,12 @@ uint8 calcSynthResult(CCharEntity* PChar)
/********************************************************************
* *
* Do Skill Up *
* To Do: *
* - Lower chance of skill up if recipe s a desynth *
* - Correct calculations so skill up chance in config file *
* matches retail when value is set to 1. *
* *
********************************************************************/

int32 doSynthSkillUp(CCharEntity* PChar)
{
for(uint8 skillID = 49; skillID < 57; ++skillID)
for (uint8 skillID = SKILL_WOODWORKING; skillID <= SKILL_COOKING; ++skillID) // Check for all skills involved in a recipe, to check for skill up
{
if (PChar->CraftContainer->getQuantity(skillID-40) == 0) // Get the required skill level for the recipe
{
Expand All @@ -502,93 +424,137 @@ int32 doSynthSkillUp(CCharEntity* PChar)
int32 baseDiff = PChar->CraftContainer->getQuantity(skillID-40) - charSkill/10; //the 5 lvl difference rule for breaks does NOT consider the effects of image support/gear

if ((baseDiff <= 0) || ((baseDiff > 5) && (PChar->CraftContainer->getQuantity(0) == SYNTHESIS_FAIL))) // synthesis result is stored in the zero cell quantity
{
{ // if you break a recipe higher than 5 levels, no skill ups
continue;
}

if (charSkill < maxSkill)
if (charSkill < maxSkill) // Check if a character can skill up
{
double skillUpChance = ((double)baseDiff*(map_config.craft_chance_multiplier - (log(1.2 + charSkill/100))))/10;
double skillUpChance = (double)baseDiff * map_config.craft_chance_multiplier * (3 - (log(1.2 + charSkill/100))) / 10;

// Apply synthesis skill gain rate modifier before synthesis fail modifier
int16 modSynthSkillGain = PChar->getMod(Mod::SYNTH_SKILL_GAIN);
skillUpChance += (double)modSynthSkillGain * 0.01;

skillUpChance = skillUpChance/(1 + (PChar->CraftContainer->getQuantity(0) == SYNTHESIS_FAIL)); // synthesis result is stored in the zero cell quantity
skillUpChance = skillUpChance / (1 + (PChar->CraftContainer->getQuantity(0) == SYNTHESIS_FAIL)); // Lower skill up chance if synth breaks

if (PChar->CraftContainer->getCraftType() == 1) // If it's a desynth lower skill up rate
skillUpChance = skillUpChance / 2;

double random = tpzrand::GetRandomNumber(1.);
#ifdef _TPZ_SYNTH_DEBUG_MESSAGES_
ShowDebug(CL_CYAN"Skill up chance: %g Random: %g\n" CL_RESET, skillUpChance, random);
#endif

if (random < skillUpChance)
if (random < skillUpChance) // If character skills up
{
int32 satier = 0;
int32 skillAmount = 1;
double chance = 0;

if((baseDiff >= 1) && (baseDiff < 3))
satier = 1;
else if((baseDiff >= 3) && (baseDiff < 5))
satier = 2;
else if((baseDiff >= 5) && (baseDiff < 8))
satier = 3;
else if((baseDiff >= 8) && (baseDiff < 10))
satier = 4;
else if (baseDiff >= 10)
satier = 5;

for(uint8 i = 0; i < 4; i ++)
{
random = tpzrand::GetRandomNumber(1.);
#ifdef _TPZ_SYNTH_DEBUG_MESSAGES_
ShowDebug(CL_CYAN"SkillAmount Tier: %i Random: %g\n" CL_RESET, satier, random);
#endif
int32 skillUpAmount = 1;

switch(satier)
if (charSkill < 600) // no skill ups over 0.1 happen over level 60
{
int32 satier = 0;
double chance = 0;

// Set satier initial rank
if((baseDiff >= 1) && (baseDiff < 3))
satier = 1;
else if((baseDiff >= 3) && (baseDiff < 5))
satier = 2;
else if((baseDiff >= 5) && (baseDiff < 8))
satier = 3;
else if((baseDiff >= 8) && (baseDiff < 10))
satier = 4;
else if (baseDiff >= 10)
satier = 5;

for(uint8 i = 0; i < 4; i ++) // cicle up to 4 times until cap (0.5) or break. The lower the satier, the more likely it will break
{
case 5: chance = 0.900; break;
case 4: chance = 0.700; break;
case 3: chance = 0.500; break;
case 2: chance = 0.300; break;
case 1: chance = 0.200; break;
default: chance = 0.000; break;
#ifdef _TPZ_SYNTH_DEBUG_MESSAGES_
ShowDebug(CL_CYAN"SkillUpAmount Tier: %i Random: %g\n" CL_RESET, satier, random);
#endif

switch(satier)
{
case 5: chance = 0.900; break;
case 4: chance = 0.700; break;
case 3: chance = 0.500; break;
case 2: chance = 0.300; break;
case 1: chance = 0.200; break;
default: chance = 0.000; break;
}

if(chance < random)
break;

skillUpAmount++;
satier--;
}

if(chance < random)
break;

skillAmount++;
satier--;
}

// Do craft amount multiplier
if (map_config.craft_amount_multiplier > 1)
{
skillAmount += (int32)(skillAmount * map_config.craft_amount_multiplier);
if (skillAmount > 9)
skillUpAmount += (int32)(skillUpAmount * map_config.craft_amount_multiplier);
if (skillUpAmount > 9)
{
skillAmount = 9;
skillUpAmount = 9;
}
}

if((skillAmount + charSkill) > maxSkill)
// Cap skill gain if character hits the current cap
if((skillUpAmount + charSkill) > maxSkill)
{
skillAmount = maxSkill - charSkill;
skillUpAmount = maxSkill - charSkill;
}

PChar->RealSkills.skill[skillID] += skillAmount;
PChar->pushPacket(new CMessageBasicPacket(PChar, PChar, skillID, skillAmount, 38));
uint16 skillCumulation = skillUpAmount;
uint8 skillHighest = skillID;
uint16 skillHighestValue = map_config.craft_common_cap;

if((charSkill/10) < (charSkill + skillAmount)/10)
if ((charSkill + skillUpAmount) > map_config.craft_common_cap) // If character is using the specialization system
{
// Cycle through all skills
for (uint8 i = SKILL_WOODWORKING; i <= SKILL_COOKING; i++)
{
if (PChar->RealSkills.skill[i] > map_config.craft_common_cap) // If the skill being checked is above the cap from wich spezialitation points start counting.
{
skillCumulation += (PChar->RealSkills.skill[i] - map_config.craft_common_cap); //Add to the ammount of specialization points in use.
if (skillID != i && PChar->RealSkills.skill[i] > skillHighestValue) //Set the ID of the highest craft UNLESS it's the craft currently in use.
{
skillHighest = i;
skillHighestValue = PChar->RealSkills.skill[i];
}
}
}
}

PChar->RealSkills.skill[skillID] += skillUpAmount;
PChar->pushPacket(new CMessageBasicPacket(PChar, PChar, skillID, skillUpAmount, 38));

if ((charSkill / 10) < (charSkill + skillUpAmount) / 10)
{
PChar->WorkingSkills.skill[skillID] += 0x20;

PChar->pushPacket(new CCharSkillsPacket(PChar));
PChar->pushPacket(new CMessageBasicPacket(PChar, PChar, skillID, (charSkill + skillAmount)/10, 53));
PChar->pushPacket(new CMessageBasicPacket(PChar, PChar, skillID, (charSkill + skillUpAmount) / 10, 53));
}

charutils::SaveCharSkills(PChar, skillID);

if (skillHighest != 0 && skillCumulation > map_config.craft_specialization_points)
{
PChar->RealSkills.skill[skillHighest] -= skillUpAmount;
PChar->pushPacket(new CMessageBasicPacket(PChar, PChar, skillHighest, skillUpAmount, 310));

if ((PChar->RealSkills.skill[skillHighest] + skillUpAmount) / 10 > (PChar->RealSkills.skill[skillHighest]) / 10)
{
PChar->WorkingSkills.skill[skillHighest] -= 0x20;
PChar->pushPacket(new CCharSkillsPacket(PChar));
PChar->pushPacket(new CMessageBasicPacket(PChar, PChar, skillHighest, (PChar->RealSkills.skill[skillHighest] - skillUpAmount) / 10, 53));
}

charutils::SaveCharSkills(PChar, skillHighest);
}
}
}
}
Expand Down

0 comments on commit f20edbd

Please sign in to comment.