Jump to content

Adjusting Item Addon


Recommended Posts

Hello everyone.

 

One day I was curious how does normal hit bonus and skill bonus are added to item, so I made a simple simulation as console application from source functions.

 

Spoiler

#include <iostream>
#include <stdlib.h>
#include <time.h>
#include <ctime>
#include <cstdlib>
#include <windows.h>

#define FLT_EPSILON     1.192092896e-07F 
#define RAND_MAX 0x7fff

using namespace std;

int number(int from, int to)
{
	if (from > to)
	{
		int tmp = from;

		from = to;
		to = tmp;
	}

	int returnValue = 0;

	if ((to - from + 1) != 0)
	{
		returnValue = ((rand() % (to - from + 1)) + from);
	}

	return returnValue;
}

int MINMAX(int min, int value, int max)
{
	register int tv;

	tv = (min > value ? min : value);
	return (max < tv) ? max : tv;
}

double uniform_random(double a, double b)
{
	return rand() / (RAND_MAX + 1.f) * (b - a) + a;
}

float gauss_random(float avg, float sigma)
{
	static bool haveNextGaussian = false;
	static float nextGaussian = 0.0f;

	if (haveNextGaussian)
	{
		haveNextGaussian = false;
		return nextGaussian * sigma + avg;
	}
	else
	{
		double v1, v2, s;
		do {
			//v1 = 2 * nextDouble() - 1;   // between -1.0 and 1.0
			//v2 = 2 * nextDouble() - 1;   // between -1.0 and 1.0
			v1 = uniform_random(-1.f, 1.f);
			v2 = uniform_random(-1.f, 1.f);
			s = v1 * v1 + v2 * v2;
		} while (s >= 1.f || fabs(s) < FLT_EPSILON);
		double multiplier = sqrtf(-2 * logf(s) / s);
		nextGaussian = v2 * multiplier;
		haveNextGaussian = true;
		return v1 * multiplier * sigma + avg;
	}
}

int main()
{
	int iSkillBonus, iNormalHitBonus;
	unsigned long long counter = 0;
	srand(time(NULL));
	for (;;)
	{
		iSkillBonus = MINMAX(-30, (int)(gauss_random(0, 5) + 0.5f), 30);
		if (abs(iSkillBonus) <= 20)
			iNormalHitBonus = -2 * iSkillBonus + abs(number(-8, 8) + number(-8, 8)) + number(1, 4);
		else
			iNormalHitBonus = -2 * iSkillBonus + number(1, 5);
	
		counter += 1;
		if (iNormalHitBonus >= 55) ////if normal hit bonus is 55 or higher, the loop will stop
			break;
	
		Sleep(1); //how long you will wait between draws
	

		//you can delete this if you want to make it faster
		cout << "normal hit bonus: " << iNormalHitBonus << endl;
		cout << "skill bonus: " << iSkillBonus << endl;
		//

	}

	cout << "you've used " << counter << " changes" << endl;

	system("pause");
	return 0;
}

 

Code: https://pastebin.com/xBqCQM9w

 

Change whatever you want then compile and test. Maybe this will help someone who wants to adjust this.

 

  • Metin2 Dev 2
  • Love 1
Link to comment
Share on other sites

https://ideone.com/XXJDKE

 

  • Success time: 0.01 memory: 15240 signal:0
    you've used 214433 changes
    
    
  • Success time: 0 memory: 16064 signal:0
    you've used 1809 changes
    
    
  • Success time: 0.03 memory: 15240 signal:0
    you've used 568036 changes
    
    
  • Success time: 0.03 memory: 15240 signal:0
    you've used 493878 changes
    
    
  • Success time: 0 memory: 16064 signal:0
    you've used 71409 changes
    
  • Metin2 Dev 1
Link to comment
Share on other sites

Announcements



×
×
  • Create New...

Important Information

Terms of Use / Privacy Policy / Guidelines / 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.