ID:272778
 
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>
if(difference < -6)
exp = 0
else
exp = (difference + 7) * 7
src << "+[exp] experience"
return exp


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:

if(difference < -6)
exp = 0
else if(difference > 0)
exp = difference * 7
else
exp = (difference + 7) * 7
src << "+[exp] experience"
return exp
In response to PirateHead (#1)
No, I didn't want it to drop back xD My bad. I didn't even think of it like that. So add a +7 into the else in the switch statement like so.

                else
src<<"+[7*(difference+7)] experience"
return 7*(difference+7)


Any way to optimize that?
In response to Mizukouken Ketsu (#2)
Mizukouken Ketsu wrote:
No, I didn't want it to drop back xD My bad. I didn't even think of it like that. So add a +7 into the else in the switch statement like so.

>                 else
> src<<"+[7*(difference+7)] experience"
> return 7*(difference+7)
>


Any way to optimize that?

Yes lol:
<dm>
if(difference < -6)
src << "0 experience"
return 0
else
src << "+[7*(difference+7)] experience"
return 7*(difference+7)
In response to Mizukouken Ketsu (#2)
                else
var/X = 7*(difference+7)
src<<"+[X] experience"
return X


You save typing and it helps CPU.
In response to Jeff8500 (#4)
7 * (-6) + 7 = -35

They'd be losing experience. Bad.
In response to Mizukouken Ketsu (#5)
I took the formula straight out of your post. Besides, it would be 7 * (-6+7), anyway, so you would get 7.
In response to Jeff8500 (#6)
Oh wow I gots order of operation issues x.x My bad. Thanks Jeff :)