HI! Sorry about the late increadibally late reply. i saw the first post of this topic when it came out but i decided to wait until you finished the the tf speed stuff. however i realised that i wasn't subscribed to this topic. so i never noticed the new replies (you see i thought that you are automatically subscribed to any topic created on your own game. but i was wrong). i only noticed them like 2 days ago.
Why am i replying now instead of 2 days ago? because i realised that i didn't have many comments on your code until i properly implemented it on my own. i already had the TF priority code working but i needed to implement the TF speed functions. i still don't have the Rank system done but i feel i should respond first. i'm going to share with you my written code first as i feel it's the easiest way to comment on your code and then respond to everything else in a new reply. This is also my revenge for making me look through octave code for hours, but in seriousness i hope you can understand it.
The main Thing with the first class is that i wanted to generalise any priority stuff for every enemy. so i don't have to hard code in new values every time i want to add a new enemy. keep in mind that even though english is my only language i am bad at it, so some things will probably be misspelled.
public class Transformation {
public Enimies enemy;
//this value will represent the total transformation across all limbs.
public float overall;
//get;private set; basically means this value is read only outside of this class.
public float priority { get; private set; } = 0;
public List<float[]> decay { get; private set; } = new List<float[]>();
public Limb transforming;
public List<Limb> transformed = new List<Limb>();
//you can think of Static values as "global" values that apply to every transformation
//this is our beginning setup, setting every value to our medium of 3.5f
public static List<float> prevtransformations = new List<float>{3.5f,3.5f,3.5f,3.5f,3.5f,3.5f,3.5f,3.5f,3.5f,3.5f};
public static List<Transformation> alltransformations { get; private set; } = new List<Transformation>();
public static float allprioritys { get; private set; } = 0f;
public Transformation(Enimies newenemy) {
enemy= newenemy;
alltransformations.Add(this);
}
public static void sortpriorities() {
//This sorts every transformation by their prority. in the case of a tie it will break with the dangerlevel
//usefull because we can look at the first value to see which has the highest prority.
alltransformations.Sort((b,a) => {
return (a.priority*100+a.enemy.dangerlevel).CompareTo(b.priority * 100 + b.enemy.dangerlevel);
});
}
public void changepriority(float amounttoadd,float amounttoreduce=0,bool decayval=true,float decayspeed=1) {
//We will force a range of 0 to 700. in your code i noitced that the range is set from 0 to 100. but i also see that you added +200 to the value
//i didn't see a way that you delt with it so im clamping it here.
float val= Mathf.Clamp(priority + amounttoadd, 0, 700);
//if we want prorities to decay based on turn i needed a way to keep track of multiple diffrent sources of decay. so we'll add it to a list
if(decayval)
decay.Add(new float[]{val-priority,decayspeed});
//usefull to keep track of the total prority of every enemy
allprioritys += val - priority;
priority = val;
if (amounttoreduce == 0)
return;
//if we died we want to reduce every enemy prority so this code deals with that
foreach(Transformation transformation in alltransformations) {
if (transformation == this)
continue;
//we'll resursavily call this funciton to change every other enemy prority
transformation.changepriority(amounttoreduce*-1, 0,decayval,decayspeed*(amounttoreduce/amounttoadd));
}
}
public static void decayall() {
//we want to apply all our decay values once per turn.
foreach (Transformation transformation in alltransformations) {
for(int j=0;j<transformation.decay.Count;j++) {
float[] thisdecay = transformation.decay[j];
//our decay may be negitive so we want to deal with each case seperatily
//fun fact: a decay speed that is negitive will never go away.
//So if i ever implement that wolfs bane weapon we can give you a constant wolf priority.
if (thisdecay[0] > 0) {
transformation.changepriority(thisdecay[1] * -1, 0, false);
thisdecay[0] -= thisdecay[1];
if (thisdecay[0] < 0) {
transformation.decay.RemoveAt(j);
j--;
}
}
else {
transformation.changepriority(thisdecay[1] * -1, 0, false);
thisdecay[0] += thisdecay[1];
if (thisdecay[0] > 0) {
transformation.decay.RemoveAt(j);
j--;
}
}
}
}
}
}
Here is the function that determines the TFspeed without the ranking.
private float calculatetransformationspeed(Transformation trans) {
//This is all saved prev transfortation speed values. we are getting the count just incase i want to change how many total values we are saving
int count = Transformation.prevtransformations.Count;
//Unity to my knowladge doesn't have a equivanlet of the sum function, so we need to make it with a for loop
//we define all our varables that will use it here so we only have to loop through the prevtransformation array once
float MoPV = 0;
float D = 0;
float d = 0;
foreach (float number in Transformation.prevtransformations) {
MoPV += number;
D += Mathf.Pow(number - 3.5f, 2);
d += number - 3.5f;
}
MoPV /= count;
float SDoPV = Mathf.Sqrt(D / count) - Mathf.Pow(d / count, 2);
float HpDiff = 2 - (2 * hp / hpmax);
float MpDiff = 2 - (2 * mp / mpmax);
float HungerDiff = 3 - (3.5f * Food_system.instance.hunger / Food_system.instance.maxhunger);
float FHB = (HungerDiff > 0) ? HungerDiff * -1 : 0;
HungerDiff*=(HungerDiff > 0) ? 0:1;
float Pp;
if (trans.priority / 700 > 0.95f)
Pp = 5;
else if (trans.priority / 700 > 0.90f)
Pp = 4;
else if (trans.priority / 700 > 0.80f)
Pp = 3;
else if (trans.priority / 700 > 0.60f)
Pp = 1.5f;
else if (trans.priority / 700 > 0.40f)
Pp = .5f;
else
Pp = 0;
//I don't have reduce curse stuff set up just yet so we'll skip it Same with Ss.
//Random.value just gets a random value between 0 and 1
float rand = Random.value - 0.5f;
//i think this is the most important change. we wont save the effect of the avrage value to our saved values
//if we did the value will drift towerds positive or negitive infinity.
float Tfspeed = ((Mathf.Sqrt(Mathf.Pow(HpDiff,2)+Mathf.Pow(MpDiff,2)+Mathf.Pow(Pp,2)+Mathf.Pow(HungerDiff,2))+rand)/2)-FHB;
//we'll remove the first value and add to the end of the array to save it
Transformation.prevtransformations.RemoveAt(0);
Transformation.prevtransformations.Add(Tfspeed);
Tfspeed += MoPV + (SDoPV * -0.25f);
print(Tfspeed);
return Tfspeed;
}