So, today I started tackling the quest system; and boy did I learn a lot. So much that I went back and redesigned the Gathering Professions. Now the two work roughly the same, only with the quest system running a method for each character. How they work is like this:
There is an array that stores the integer values of every character's "PlayerPrefs.GetInt("characterQuesting") values. I then created a method that checks for specific values to be present in the array. Each character's value is unique (character 1 is 1, character 2 is 2, so on and so forth). I then made a single script that checks every 15 seconds to see if the character is questing by running a method designed to count the amount of a single value inside the array. This works hand in hand with the actual questing method to check the value of each character's local questing variable and if it returns 1, it adds an experience point to the character each time the method is run.
void Start()
{
InvokeRepeating("CountQuesting", 14, 15);
InvokeRepeating("PerformQuesting", 15, 15);
}
void CountQuesting()
{
CountOccurrences(1);
CountOccurrences(2);
CountOccurrences(3);
CountOccurrences(4);
//etc...
}
int CountOccurrences(int valueToCheck)
{
int counter = 0;
foreach(int currentValue in gathering)
{
if(currentValue == valueToCheck)
{
counter++; //increase counter
if(valueToCheck == 1)
{
character1Questing = counter;
}
if(valueToCheck == 2)
{
character2Questing = counter;
}
if(valueToCheck == 3)
{
character3Questing = counter;
}
if(valueToCheck == 4)
{
character4Questing = counter;
}
//etc...
}
}
return counter;
}
void PerformQuesting()
{
if(character1Questing == 1)
{
character1Experience ++;
}
if(character2Questing == 1)
{
character2Experience ++;
}
if(character3Questing == 1)
{
character3Experience ++;
}
if(character4Questing == 1)
{
character4Experience ++;
}
//etc...
}
No comments:
Post a Comment