This behavior cycles through two alt textures, you can use this instead of making multiple states switch textures.
Code:
#region
using wServer.realm;
using wServer.realm.entities;
#endregion
namespace wServer.logic.behaviors
{
public class SetAltTextureCycle : Behavior
{
private readonly int index1;
private readonly int index2;
protected Cooldown coolDown;
public SetAltTextureCycle(int index1, int index2, Cooldown coolDown = new Cooldown())
{
this.index1 = index1;
this.index2 = index2;
this.coolDown = coolDown.Normalize();
}
protected override void OnStateEntry(Entity host, RealmTime time, ref object state)
{
state = 0;
}
protected override void TickCore(Entity host, RealmTime time, ref object state)
{
int cool = (int)state;
if (cool <= 0)
{
if ((host as Enemy).AltTextureIndex != index1)
{
(host as Enemy).AltTextureIndex = index1;
host.UpdateCount++;
}
else
{
(host as Enemy).AltTextureIndex = index2;
host.UpdateCount++;
}
cool = coolDown.Next(Random);
}
else
cool -= time.thisTickTimes;
state = cool;
}
}
}
Example
The stuff commented out was the old method, you can see that the TimedTransition is 1/4 the amount of the new method. This is because having the states switch so quickly, caused the transition to lag behind.