Advertisement
Guest User

Elona + 1.43 skillexp

a guest
May 5th, 2015
217
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 10.29 KB | None | 0 0
  1. #deffunc skillexp int skillID, int entity, int BaseXPGained, int PrimaryStatXPFactor, intPrimaryXPFactor
  2.  
  3.     //  Checks to see if the person gaining the xp actually knows the skill/stat, and terminates if they don't
  4.     if ( sorg(skillID, entity) == 0 ) {
  5.         return 0
  6.     }
  7.    
  8.     //  Terminates if the amount of xp sent to this function is 0.
  9.     if ( BaseXPGained == 0 ) {
  10.         return
  11.     }
  12.    
  13.     /*  This calls skillexp again for the main attribute tied to whatever skill we increase.
  14.         To be clear, the skillexp function is how both attributes and skills gain xp. However, the
  15.         attributes don't have an attribute tied to them, as they ARE the attribute. Or in other words,
  16.         var_82(0,SkillID) is 0 for attributes and 10-18 for skills.
  17.    
  18.         Essentially this just gives a portion of  skill exp to the main stat it's tied to. Presumably, if no
  19.         value is specified, then PrimaryStatXPFactor is defaulted to 0, meaning this gives half xp to
  20.         the main attribute.
  21.     */
  22.     if ( var_82(0, skillID) != 0 ) {
  23.         skillexp var_82(0, skillID), entity, BaseXPGained / (2 + PrimaryStatXPFactor)
  24.     }
  25.    
  26.     /*  This grabs the base value of the affected stat/skill's level, and the
  27.         potential of the stat/skill.
  28.         Divide the stat total by 1000000 to get level
  29.         Do a modulo 1000 on the stat total to get potential
  30.     */
  31.     BaseSkillLevel = sorg(skillID, entity)
  32.     BaseSkillPotential = sgrowth(skillID, entity)
  33.    
  34.     //  Terminate if the stat/skill's potential is 0.
  35.     if ( BaseSkillPotential == 0 ) {
  36.         return
  37.     }
  38.    
  39.     /*  If the amount of experience added is more than 0:
  40.             Determine EffectiveXPGained by BaseXPGain * BaseSkillPotential / (100 + BaseSkillLevel * 10)
  41.             If we're modifying an attribute (strength through luck)
  42.                 If the entity has a stat grwoth modifier buff
  43.                     EffectiveXPGained = Current value of EffectiveXPGained * (100 + magnitute of growth buff)/100
  44.             If EffectiveXPGained is 0
  45.                 If a random number between 0 and BaseSkillLevel/10 is 0,
  46.                     EffectiveXPGained is set to 1.
  47.                 Otherwise, terminate this function.
  48.         Otherwise (i.e, BaseXPGained is negative), then EffectiveXPGained is set to BaseXPGained.
  49.     */
  50.     if ( BaseXPGained > 0 ) {
  51.         EffectiveXPGained = BaseXPGained * BaseSkillPotential / (100 + BaseSkillLevel * 10)
  52.         if ( skillID >= 10 ) {
  53.             if ( skillID <= 19 ) {
  54.                 if ( var_57(270 + skillID - 10, entity) > 0 ) {
  55.                     EffectiveXPGained = EffectiveXPGained * (100 + var_57(270 + skillID - 10, entity)) / 100
  56.                 }
  57.             }
  58.         }
  59.         if ( EffectiveXPGained == 0 ) {
  60.             if ( rnd(BaseSkillLevel / 10 + 1) == 0 ) {
  61.                 EffectiveXPGained = 1
  62.             }
  63.             else {
  64.                 return 0
  65.             }
  66.         }
  67.     }
  68.     else {
  69.         EffectiveXPGained = BaseXPGained
  70.     }
  71.    
  72.     /*  If the player is currently in a showroom, or the entity being modified by this function is
  73.         currently sandbagged (cbit985), then set EffectiveXPGained to 0.
  74.     */
  75.     if ( var_64(20) == 35 ) {
  76.         EffectiveXPGained = 0
  77.     }
  78.     if ( cbit(985, entity) ) {
  79.         EffectiveXPGained = 0
  80.     }
  81.    
  82.     /*  If the skill's ID is > 100 (all skills, no attributes)
  83.             If a random number between 0 and the entity being affected's Learning +49 (inclusive) is greater
  84.             than a random number between 0 and 999
  85.                 If EffectiveXPGained is either more or less than 0
  86.                     EffectiveXPGained is set to EffectiveXPGained * (sqrt(Entity.Learning)+20)/10, where
  87.                     (sqrt(Entity.Learning)+20 has a minimum value of 20 and a maximum of 50. This means that
  88.                     it applies between a 2x and 5x multiplier to EffectiveXPGained when triggered.
  89.     */
  90.     if ( skillID >= 100 ) {
  91.         if ( rnd(var_81(14, entity) + 50) > rnd(1000) ) {
  92.             if ( EffectiveXPGained != 0 ) {
  93.                 EffectiveXPGained = EffectiveXPGained * limit(sqrt(var_81(14, entity)) + 20, 20, 50) / 10
  94.             }
  95.         }
  96.     }
  97.    
  98.     /*  If the skill's ID is > 100 (all skills, no attributes)
  99.         If the entity is NOT the player and IS a pet
  100.             EffectiveXPGained is multiplied by 4.  
  101.     */
  102.     if ( skillID >= 100 ) {
  103.         if ( entity != 0 & entity < 16 ) {
  104.             EffectiveXPGained = EffectiveXPGained * 4
  105.         }
  106.     }
  107.    
  108.     //  If EffectiveXPGained is greater than 20000 at this point, it's reduced to 20000
  109.     if ( EffectiveXPGained > 20000 ) {
  110.         EffectiveXPGained = 20000
  111.     }
  112.    
  113.     //  If GameMode is Overdose, then multiply EffectiveXPGained by 20.
  114.     if ( var_64(250 + 23) == 2 ) {
  115.         EffectiveXPGained = EffectiveXPGained * 20
  116.     }
  117.    
  118.     /*  If player's drowsiness is >= 50 ("Need Sleep", maybe?) AND the entity being modified is a player
  119.         OR a pet, then set EffectiveXPGained to 0.
  120.         Interesting that this means neither you or a pet can gain xp if YOU are sleepy enough.
  121.     */
  122.     if ( var_64(90) >= 50 ) {
  123.         if ( entity == 0 | entity < 16 ) {
  124.             EffectiveXPGained = 0
  125.         }
  126.     }
  127.    
  128.     /*  If EffectiveXPGained is still more than 0 at this point
  129.             If skillID is greater than or equal to 100 (all skills, no attributes)
  130.                 IfPrimaryXPFactor != 1000
  131.                 Note that I can't find a common link with calls to this function wherePrimaryXPFactor is 1000.
  132.                 Most faith gains seem to be that way. Traveling xp gain is that way. There's only a handful.
  133.                     If the entity's totalXPNeededToLevel < 1000
  134.                         PrimaryXPGain = a random number between 0 and totalXPNeededToLevel (-1)*
  135.                         EffectiveXPGained / 1000 / (Level +PrimaryXPFactor) + 1) + either 0 or 1.
  136.                     If, on the other hand, totalXPNeededToLevel is equal to or more than 1000
  137.                         PrimaryXPGain = a random number between 0 and totalXPNeededToLevel(-1) / 1000
  138.                         * EffectiveXPGained / (Level + PrimaryXPFactor)+1) + either 0 or 1.
  139.                     CurrentXPTotal  = CurrentXPTotal + PrimaryXPGain;
  140.                     If the entity being modified by this function is the player,
  141.                         add PrimaryXPGain to XPGainedSinceLastSleep (?)
  142.     */
  143.     if ( EffectiveXPGained > 0 ) {
  144.         if ( skillID >= 100 ) {
  145.             if (PrimaryXPFactor != 1000 ) {
  146.                 if ( var_57(36, entity) < 1000 ) {
  147.                     PrimaryXPGain = rnd(var_57(36, entity) * EffectiveXPGained / 1000 / (var_57(38, entity) +PrimaryXPFactor) + 1) + rnd(2)
  148.                 }
  149.                 if ( var_57(36, entity) >= 1000 ) {
  150.                     PrimaryXPGain = rnd(var_57(36, entity) / 1000 * EffectiveXPGained / (var_57(38, entity) +PrimaryXPFactor) + 1) + rnd(2)
  151.                 }
  152.                 var_57(35, entity) += PrimaryXPGain
  153.                 if ( entity == 0 ) {
  154.                     var_64(92) += PrimaryXPGain
  155.                 }
  156.             }
  157.         }
  158.     }
  159.  
  160.     /*  Returns the current skill exp for the stat/skill and adds it to EffectiveXPGained
  161.         Note that I've renamed "EffectiveXPGained" to "TotalSkillXP" from this point down
  162.         (after the following line) for the sake of clarity.
  163.         Current XP is found by Stat Value \ 1000000 / 1000
  164.         That's modulo 1000000 divided by 1000
  165.     */
  166.     EffectiveXPGained += sexp(skillID, entity)
  167.    
  168.     /*  If TotalSkillXP >= 1000 (at this point, 1000 is a level)
  169.             SkillLevelsGained = TotalSkillXP/1000 (Note than this rounds down. 2500 = 2)
  170.             TotalSkillXP = TotalSkillXP \1000 (This is modulo - takes the remainder. 2500 = 500)
  171.             BaseSkillLevel is increased by SkillLevelsGained
  172.             Loop for the number of skill/stat levels gained
  173.                 Multiply the BaseSkillPotential by 0.9.
  174.                 If BaseSkillPotential would be below 1, set it to 1.
  175.             End loop
  176.             var_81(skillID + 600, entity) is the base exp for the skill/stat.
  177.             (That means 600 values (offset 2400)  past the value of the skillID, fyi)
  178.             This line essentially writes the    stat level, stat experience, and stat potential back to that value.
  179.             Level is multiplied by 1000000, raw skill xp by 1000, and potential is not modified.
  180.            
  181.             synccheck portion returns true if a change happened (level up), and plays a sound if the
  182.             entity being modified is the player or a pet(and displays the stat/skill up message, such as
  183.             "begins to feel good when hit hard" for CON) . It then recalculates all stats (label_1707) and terminates.
  184.     */
  185.     if ( TotalSkillXP >= 1000 ) {
  186.         SkillLevelsGained = TotalSkillXP / 1000
  187.         TotalSkillXP = TotalSkillXP \ 1000
  188.         BaseSkillLevel += SkillLevelsGained
  189.         repeat SkillLevelsGained
  190.             BaseSkillPotential = int(double(BaseSkillPotential) * 0.9)
  191.             if ( BaseSkillPotential < 1 ) {
  192.                 BaseSkillPotential = 1
  193.             }
  194.         loop
  195.         var_81(skillID + 600, entity) = limit(BaseSkillLevel, 0, 2000) * 1000000 + TotalSkillXP * 1000 + BaseSkillPotential
  196.         if ( synccheck(entity, -1) ) {
  197.             if ( entity == 0 | entity < 16 ) {
  198.                 snd 61
  199.                 txtef 2
  200.                 var_139 = 1
  201.             }
  202.             var_241 = 0
  203.             var_245 = 1 + ("" != "") + ("" != "") + ("" != "") + ("" != "") + ("" != "") + ("" != "") + ("" != "") + ("" != "")
  204.             var_245 = rnd(var_245)
  205.             txt_select txtskillchange(skillID, 0, entity), "", "", "", "", "", "", "", ""
  206.             var_208 = 255, 255, 255
  207.         }
  208.         var_625 = entity
  209.         gosub *label_1707
  210.         return 1
  211.     }
  212.    
  213.    
  214.     /*  If the total skill exp is less than 0 (Note that this actually just means that EffectiveXPGained + CurrentSkillXP
  215.         is a negative number)
  216.             Literally the reverse of the above. Only thing to note is that you regain 1.1*BaseSkillPotential +1 for every
  217.             skill/stat level you lose.
  218.             Stat level, stat experience, and stat potential are then re-written to BaseSkillLevel variable.
  219.     */
  220.    
  221.     if ( TotalSkillXP < 0 ) {
  222.         SkillLevelsGained = -TotalSkillXP / 1000 + 1
  223.         TotalSkillXP = 1000 + TotalSkillXP \ 1000
  224.         if ( BaseSkillLevel - SkillLevelsGained < 1 ) {
  225.             SkillLevelsGained = BaseSkillLevel - 1
  226.             if ( BaseSkillLevel == 1 ) {
  227.                 if ( SkillLevelsGained == 0 ) {
  228.                     TotalSkillXP = 0
  229.                 }
  230.             }
  231.         }
  232.         BaseSkillLevel -= SkillLevelsGained
  233.         repeat SkillLevelsGained
  234.             BaseSkillPotential = int(double(BaseSkillPotential) * ((-0.9) + 2)) + 1
  235.             if ( BaseSkillPotential > 400 ) {
  236.                 BaseSkillPotential = 400
  237.             }
  238.         loop
  239.         var_81(skillID + 600, entity) = limit(BaseSkillLevel, 0, 2000) * 1000000 + TotalSkillXP * 1000 + BaseSkillPotential
  240.         if ( synccheck(entity, -1) ) {
  241.             if ( entity == 0 | entity < 16 ) {
  242.                 if ( SkillLevelsGained != 0 ) {
  243.                     var_139 = 1
  244.                     txtef 3
  245.                     var_241 = 0
  246.                     var_245 = 1 + ("" != "") + ("" != "") + ("" != "") + ("" != "") + ("" != "") + ("" != "") + ("" != "") + ("" != "")
  247.                     var_245 = rnd(var_245)
  248.                     txt_select txtskillchange(skillID, 1, entity), "", "", "", "", "", "", "", ""
  249.                     var_208 = 255, 255, 255
  250.                 }
  251.             }
  252.         }
  253.         var_625 = entity
  254.         gosub *label_1707
  255.         return 1
  256.     }
  257.    
  258.     /*  You only get to this point if you don't have enough xp to either gain or lose a stat/skill level, in which case
  259.         the new stat level, stat experience, and stat potential are simply rewritten to the BaseSkillLevel variable.
  260.     */     
  261.     var_81(skillID + 600, entity) = limit(BaseSkillLevel, 0, 2000) * 1000000 + TotalSkillXP * 1000 + BaseSkillPotential
  262.     return 0
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement