Jump to content

upgrade system to +20


Monkuar

Recommended Posts

Need a little help here for my game.

 

Let's say you can upgrade items... I want users to upgrade to level 20.

 

Let's say, +1 is 80% chance and to get it to +20 would be 2% chance.

 

How would I go about this? I would also need variables to use, let's say crystals they need to use to increase the % of upgrading by XX %.

 

Ty

Link to comment
https://forums.phpfreaks.com/topic/281830-upgrade-system-to-20/
Share on other sites

Okay so for your percents per level, basically you will want to have a map/table for each of your levels. One way to do this is to just hardcode an array with the percents you want. For example:

 

$percents = array(1=>80,20=2);
I just showed your first and last level as an example; you'd add levels 2-19 with your own values. The benefit if doing it this way is that you have more control over balancing your game.

 

Alternatively, if you just want to do something simple like make it an even(ish) spread, you could automate this with a formula:

 

$percents = array();
$minLevel=1;
$maxLevel=20;
$minPercent=2;
$maxPercent=80;
for ($p=$minLevel;$p<=$maxLevel;$p++) {
  $percentInc = ($maxPercent-$minPercent)/($maxLevel-1);
  $percent = $maxPercent-(($p-1)*$percentInc);
  $percents[$p] = $percent;
}
This will give you an array of percents like this:

 

Array
(
    [1] => 80
    [2] => 75.8947368421
    [3] => 71.7894736842
    [4] => 67.6842105263
    [5] => 63.5789473684
    [6] => 59.4736842105
    [7] => 55.3684210526
    [8] => 51.2631578947
    [9] => 47.1578947368
    [10] => 43.0526315789
    [11] => 38.9473684211
    [12] => 34.8421052632
    [13] => 30.7368421053
    [14] => 26.6315789474
    [15] => 22.5263157895
    [16] => 18.4210526316
    [17] => 14.3157894737
    [18] => 10.2105263158
    [19] => 6.10526315789
    [20] => 2
)
IMO you should prolly throw some rounding into the mix but that's a judgement call you'll have to make.

Wow, exactly what I was looking for.  That code is very easy to read as well. (I always get lost in foreaches, but this is very simple for me, thank you)

 

I'll be making the lvl 19 lower than 6% chance though just because I want +20 to be end-game material.

 

Marked as solved, didn't know you guys were still active here thank you a lot.

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.