Optimize experience gain proc? in Developer Help
|
|
Here's the basic functionality of gaining experiencein my game. You kill someone and if they're more than 6 levels below you (<6), the killer won't gain any experience. But any level higher than the difference of -6, the killer will gain experience in multipels of 7.
mob/proc expGain(mob/M) var/difference = M.Level - Level if(difference>= -6) switch(difference) if(-6) src<<"+7 experience" return 7 if(-5) src<<"+14 experience" return 14 if(-4) src<<"+21 experience" return 21 if(-3) src<<"+28 experience" return 28 if(-2) src<<"+35 experience" return 35 if(-1) src<<"+42 experience" return 42 if(0) src<<"+49 experience" return 49 else src<<"+[7*difference] experience" return 7*difference else src<<"+0 expience"
|
So is there a more efficient way of doing that little tidit?</6>
|
I'm not sure that you intend your proc to work the way it does. Correct me if you do. Here's a table of experience gains by delta:
<pre> delta | exp gain <-6 | 7*0 -6 | 7*1 -5 | 7*2 -4 | 7*3 -3 | 7*4 -2 | 7*5 -1 | 7*6 0 | 7*7 1 | 7*1 <-- wtf 2 | 7*2 ... </pre>
If you do want to drop back down at difference=1, you'd have to modify my snippet above like so: