@@ -117,7 +117,7 @@ bool isRightRecipe(CCharEntity* PChar)
117117 uint16 skillValue = 0 ;
118118 uint16 currentSkill = 0 ;
119119
120- for (uint8 skillID = 49 ; skillID < 57 ; ++skillID) // range for all 8 synth skills
120+ for (uint8 skillID = SKILL_WOODWORKING ; skillID <= SKILL_COOKING ; ++skillID) // range for all 8 synth skills
121121 {
122122 skillValue = (uint16)Sql_GetUIntData (SqlHandle,(skillID-49 +2 ));
123123 currentSkill = PChar->RealSkills .skill [skillID];
@@ -165,11 +165,6 @@ bool isRightRecipe(CCharEntity* PChar)
165165
166166double getSynthDifficulty (CCharEntity* PChar, uint8 skillID)
167167{
168- uint8 ElementDirection = 0 ;
169- uint8 WeekDay = (uint8)CVanaTime::getInstance ()->getWeekday ();
170- uint8 crystalElement = PChar->CraftContainer ->getType ();
171- uint8 direction = (PChar->loc .p .rotation - 16 )/32 ;
172- uint8 strongElement[8 ] = {2 ,3 ,5 ,4 ,0 ,1 ,7 ,6 };
173168 Mod ModID = Mod::NONE;
174169
175170 switch (skillID)
@@ -186,55 +181,8 @@ double getSynthDifficulty(CCharEntity* PChar, uint8 skillID)
186181
187182 uint8 charSkill = PChar->RealSkills .skill [skillID]/10 ; // player skill level is truncated before synth difficulty is calced
188183 double difficult = PChar->CraftContainer ->getQuantity (skillID-40 ) - (double )(charSkill + PChar->getMod (ModID));
189- double MoonPhase = (double )CVanaTime::getInstance ()->getMoonPhase ();
190-
191- if (map_config.craft_day_matters == 1 )
192- {
193- if (crystalElement == WeekDay)
194- difficult -= 1 ;
195- else if (strongElement[crystalElement] == WeekDay)
196- difficult += 1 ;
197- else if (strongElement[WeekDay] == crystalElement)
198- difficult -= 1 ;
199- else if (WeekDay == LIGHTSDAY)
200- difficult -= 1 ;
201- else if (WeekDay == DARKSDAY)
202- difficult += 1 ;
203- }
204-
205- if (map_config.craft_moonphase_matters == 1 )
206- {
207- difficult -= (MoonPhase - 50 )/50 ; // full moon reduces difficulty by 1, new moon increases difficulty by 1, 50% moon has 0 effect
208- }
209-
210- if (map_config.craft_direction_matters == 1 )
211- {
212- switch (direction)
213- {
214- case 0 : ElementDirection = ELEMENT_WIND; break ;
215- case 1 : ElementDirection = ELEMENT_EARTH; break ;
216- case 2 : ElementDirection = ELEMENT_LIGHTNING; break ;
217- case 3 : ElementDirection = ELEMENT_WATER; break ;
218- case 4 : ElementDirection = ELEMENT_FIRE; break ;
219- case 5 : ElementDirection = ELEMENT_DARK; break ;
220- case 6 : ElementDirection = ELEMENT_LIGHT; break ;
221- case 7 : ElementDirection = ELEMENT_ICE; break ;
222- }
223-
224- if (crystalElement == ElementDirection)
225- {
226- difficult -= 0.5 ;
227- }
228- else if (strongElement[crystalElement] == ElementDirection)
229- {
230- difficult += 0.5 ;
231- }
232- }
233184
234185 #ifdef _TPZ_SYNTH_DEBUG_MESSAGES_
235- ShowDebug (CL_CYAN" Direction = %i\n " CL_RESET, ElementDirection);
236- ShowDebug (CL_CYAN" Day = %i\n " CL_RESET, WeekDay);
237- ShowDebug (CL_CYAN" Moon = %g\n " CL_RESET, MoonPhase);
238186 ShowDebug (CL_CYAN" Difficulty = %g\n " CL_RESET, difficult);
239187 #endif
240188
@@ -287,12 +235,7 @@ uint8 calcSynthResult(CCharEntity* PChar)
287235 double chance = 0 ;
288236 double random = tpzrand::GetRandomNumber (1 .);
289237
290- double MoonPhase = (double )CVanaTime::getInstance ()->getMoonPhase ();
291- uint8 WeekDay = (uint8)CVanaTime::getInstance ()->getWeekday ();
292- uint8 crystalElement = PChar->CraftContainer ->getType ();
293- uint8 strongElement[8 ] = {2 ,3 ,5 ,4 ,0 ,1 ,7 ,6 };
294-
295- for (uint8 skillID = 49 ; skillID < 57 ; ++skillID)
238+ for (uint8 skillID = SKILL_WOODWORKING; skillID <= SKILL_COOKING; ++skillID)
296239 {
297240 uint8 checkSkill = PChar->CraftContainer ->getQuantity (skillID-40 );
298241 if (checkSkill != 0 )
@@ -393,23 +336,6 @@ uint8 calcSynthResult(CCharEntity* PChar)
393336
394337 if (chance > 0 && canHQ) // if there is a chance already and it can HQ, we add myth mods
395338 {
396- if (map_config.craft_moonphase_matters )
397- 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%
398-
399- if (map_config.craft_day_matters )
400- {
401- if (crystalElement == WeekDay)
402- chance *= 1.0 - ((double )1 / 3 );
403- else if (strongElement[crystalElement] == WeekDay)
404- chance *= 1.0 + ((double )1 / 3 );
405- else if (strongElement[WeekDay] == crystalElement)
406- chance *= 1.0 - ((double )1 / 3 );
407- else if (WeekDay == LIGHTSDAY)
408- chance *= 1.0 - ((double )1 / 3 );
409- else if (WeekDay == DARKSDAY)
410- chance *= 1.0 + ((double )1 / 3 );
411- }
412-
413339 // limit max hq chance
414340 if (PChar->CraftContainer ->getCraftType () == 1 )
415341 chance = std::clamp (chance, 0 ., 0.800 );
@@ -479,16 +405,12 @@ uint8 calcSynthResult(CCharEntity* PChar)
479405/* *******************************************************************
480406* *
481407* Do Skill Up *
482- * To Do: *
483- * - Lower chance of skill up if recipe s a desynth *
484- * - Correct calculations so skill up chance in config file *
485- * matches retail when value is set to 1. *
486408* *
487409********************************************************************/
488410
489411int32 doSynthSkillUp (CCharEntity* PChar)
490412{
491- for (uint8 skillID = 49 ; skillID < 57 ; ++skillID)
413+ for (uint8 skillID = SKILL_WOODWORKING ; skillID <= SKILL_COOKING ; ++skillID) // Check for all skills involved in a recipe, to check for skill up
492414 {
493415 if (PChar->CraftContainer ->getQuantity (skillID-40 ) == 0 ) // Get the required skill level for the recipe
494416 {
@@ -502,93 +424,137 @@ int32 doSynthSkillUp(CCharEntity* PChar)
502424 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
503425
504426 if ((baseDiff <= 0 ) || ((baseDiff > 5 ) && (PChar->CraftContainer ->getQuantity (0 ) == SYNTHESIS_FAIL))) // synthesis result is stored in the zero cell quantity
505- {
427+ { // if you break a recipe higher than 5 levels, no skill ups
506428 continue ;
507429 }
508430
509- if (charSkill < maxSkill)
431+ if (charSkill < maxSkill) // Check if a character can skill up
510432 {
511- double skillUpChance = (( double )baseDiff*( map_config.craft_chance_multiplier - (log (1.2 + charSkill/100 ))))/ 10 ;
433+ double skillUpChance = (double )baseDiff * map_config.craft_chance_multiplier * ( 3 - (log (1.2 + charSkill/100 ))) / 10 ;
512434
513435 // Apply synthesis skill gain rate modifier before synthesis fail modifier
514436 int16 modSynthSkillGain = PChar->getMod (Mod::SYNTH_SKILL_GAIN);
515437 skillUpChance += (double )modSynthSkillGain * 0.01 ;
516438
517- skillUpChance = skillUpChance/(1 + (PChar->CraftContainer ->getQuantity (0 ) == SYNTHESIS_FAIL)); // synthesis result is stored in the zero cell quantity
439+ skillUpChance = skillUpChance / (1 + (PChar->CraftContainer ->getQuantity (0 ) == SYNTHESIS_FAIL)); // Lower skill up chance if synth breaks
440+
441+ if (PChar->CraftContainer ->getCraftType () == 1 ) // If it's a desynth lower skill up rate
442+ skillUpChance = skillUpChance / 2 ;
518443
519444 double random = tpzrand::GetRandomNumber (1 .);
520445 #ifdef _TPZ_SYNTH_DEBUG_MESSAGES_
521446 ShowDebug (CL_CYAN" Skill up chance: %g Random: %g\n " CL_RESET, skillUpChance, random);
522447 #endif
523448
524- if (random < skillUpChance)
449+ if (random < skillUpChance) // If character skills up
525450 {
526- int32 satier = 0 ;
527- int32 skillAmount = 1 ;
528- double chance = 0 ;
529-
530- if ((baseDiff >= 1 ) && (baseDiff < 3 ))
531- satier = 1 ;
532- else if ((baseDiff >= 3 ) && (baseDiff < 5 ))
533- satier = 2 ;
534- else if ((baseDiff >= 5 ) && (baseDiff < 8 ))
535- satier = 3 ;
536- else if ((baseDiff >= 8 ) && (baseDiff < 10 ))
537- satier = 4 ;
538- else if (baseDiff >= 10 )
539- satier = 5 ;
540-
541- for (uint8 i = 0 ; i < 4 ; i ++)
542- {
543- random = tpzrand::GetRandomNumber (1 .);
544- #ifdef _TPZ_SYNTH_DEBUG_MESSAGES_
545- ShowDebug (CL_CYAN" SkillAmount Tier: %i Random: %g\n " CL_RESET, satier, random);
546- #endif
451+ int32 skillUpAmount = 1 ;
547452
548- switch (satier)
453+ if (charSkill < 600 ) // no skill ups over 0.1 happen over level 60
454+ {
455+ int32 satier = 0 ;
456+ double chance = 0 ;
457+
458+ // Set satier initial rank
459+ if ((baseDiff >= 1 ) && (baseDiff < 3 ))
460+ satier = 1 ;
461+ else if ((baseDiff >= 3 ) && (baseDiff < 5 ))
462+ satier = 2 ;
463+ else if ((baseDiff >= 5 ) && (baseDiff < 8 ))
464+ satier = 3 ;
465+ else if ((baseDiff >= 8 ) && (baseDiff < 10 ))
466+ satier = 4 ;
467+ else if (baseDiff >= 10 )
468+ satier = 5 ;
469+
470+ 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
549471 {
550- case 5 : chance = 0.900 ; break ;
551- case 4 : chance = 0.700 ; break ;
552- case 3 : chance = 0.500 ; break ;
553- case 2 : chance = 0.300 ; break ;
554- case 1 : chance = 0.200 ; break ;
555- default : chance = 0.000 ; break ;
472+ #ifdef _TPZ_SYNTH_DEBUG_MESSAGES_
473+ ShowDebug (CL_CYAN" SkillUpAmount Tier: %i Random: %g\n " CL_RESET, satier, random);
474+ #endif
475+
476+ switch (satier)
477+ {
478+ case 5 : chance = 0.900 ; break ;
479+ case 4 : chance = 0.700 ; break ;
480+ case 3 : chance = 0.500 ; break ;
481+ case 2 : chance = 0.300 ; break ;
482+ case 1 : chance = 0.200 ; break ;
483+ default : chance = 0.000 ; break ;
484+ }
485+
486+ if (chance < random)
487+ break ;
488+
489+ skillUpAmount++;
490+ satier--;
556491 }
557-
558- if (chance < random)
559- break ;
560-
561- skillAmount++;
562- satier--;
563492 }
564493
565494 // Do craft amount multiplier
566495 if (map_config.craft_amount_multiplier > 1 )
567496 {
568- skillAmount += (int32)(skillAmount * map_config.craft_amount_multiplier );
569- if (skillAmount > 9 )
497+ skillUpAmount += (int32)(skillUpAmount * map_config.craft_amount_multiplier );
498+ if (skillUpAmount > 9 )
570499 {
571- skillAmount = 9 ;
500+ skillUpAmount = 9 ;
572501 }
573502 }
574503
575- if ((skillAmount + charSkill) > maxSkill)
504+ // Cap skill gain if character hits the current cap
505+ if ((skillUpAmount + charSkill) > maxSkill)
576506 {
577- skillAmount = maxSkill - charSkill;
507+ skillUpAmount = maxSkill - charSkill;
578508 }
579509
580- PChar->RealSkills .skill [skillID] += skillAmount;
581- PChar->pushPacket (new CMessageBasicPacket (PChar, PChar, skillID, skillAmount, 38 ));
510+ uint16 skillCumulation = skillUpAmount;
511+ uint8 skillHighest = skillID;
512+ uint16 skillHighestValue = map_config.craft_common_cap ;
582513
583- if ((charSkill/10 ) < (charSkill + skillAmount)/10 )
514+ if ((charSkill + skillUpAmount) > map_config.craft_common_cap ) // If character is using the specialization system
515+ {
516+ // Cycle through all skills
517+ for (uint8 i = SKILL_WOODWORKING; i <= SKILL_COOKING; i++)
518+ {
519+ 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.
520+ {
521+ skillCumulation += (PChar->RealSkills .skill [i] - map_config.craft_common_cap ); // Add to the ammount of specialization points in use.
522+ if (skillID != i && PChar->RealSkills .skill [i] > skillHighestValue) // Set the ID of the highest craft UNLESS it's the craft currently in use.
523+ {
524+ skillHighest = i;
525+ skillHighestValue = PChar->RealSkills .skill [i];
526+ }
527+ }
528+ }
529+ }
530+
531+ PChar->RealSkills .skill [skillID] += skillUpAmount;
532+ PChar->pushPacket (new CMessageBasicPacket (PChar, PChar, skillID, skillUpAmount, 38 ));
533+
534+ if ((charSkill / 10 ) < (charSkill + skillUpAmount) / 10 )
584535 {
585536 PChar->WorkingSkills .skill [skillID] += 0x20 ;
586537
587538 PChar->pushPacket (new CCharSkillsPacket (PChar));
588- PChar->pushPacket (new CMessageBasicPacket (PChar, PChar, skillID, (charSkill + skillAmount)/ 10 , 53 ));
539+ PChar->pushPacket (new CMessageBasicPacket (PChar, PChar, skillID, (charSkill + skillUpAmount) / 10 , 53 ));
589540 }
590541
591542 charutils::SaveCharSkills (PChar, skillID);
543+
544+ if (skillHighest != 0 && skillCumulation > map_config.craft_specialization_points )
545+ {
546+ PChar->RealSkills .skill [skillHighest] -= skillUpAmount;
547+ PChar->pushPacket (new CMessageBasicPacket (PChar, PChar, skillHighest, skillUpAmount, 310 ));
548+
549+ if ((PChar->RealSkills .skill [skillHighest] + skillUpAmount) / 10 > (PChar->RealSkills .skill [skillHighest]) / 10 )
550+ {
551+ PChar->WorkingSkills .skill [skillHighest] -= 0x20 ;
552+ PChar->pushPacket (new CCharSkillsPacket (PChar));
553+ PChar->pushPacket (new CMessageBasicPacket (PChar, PChar, skillHighest, (PChar->RealSkills .skill [skillHighest] - skillUpAmount) / 10 , 53 ));
554+ }
555+
556+ charutils::SaveCharSkills (PChar, skillHighest);
557+ }
592558 }
593559 }
594560 }
0 commit comments