Thanks for the anti-clumping ideas, I'll think about that next too
I'm just trying to visualise how to implement the tokens. I was thinking a ds_grid where you'd list the tokens then list whatever object is currently in posession of it (so index 0 would be: token, attacker_ID) and then attackers would reserve or free up their slot depending on states/actions but it seems faster to just ask you how you did it! (Also searching for token AI programming implementation is noisy because token is already an accepted term in programming)
In my own implementation enemies can't steal tokens from one another, or care in any other way who has which token, so that information isn't stored anywhere. I simply have a publicly accessible list of currently unused tokens (tokens themselves are instances of an AttackToken class). Each enemy has a reference to the token they're currently holding (if any).
When an enemy wants to attack, it checks the list, and if there's any token on it, they take one (literally Remove () it from the list and store it within themselves). Then when they're done, they return it (Add ()) to the list and set their own reference to the token to null.
Relevant snippers of code, modified for simplicity. This is on EnemyManager, which is a singleton in the scene:
Code:
List <AttackToken> _attackTokens = new List <AttackToken> ();
Code:
for (int i = 0; i < numTokens; i++) {
_attackTokens.Add (new AttackToken ());
}
Then the functions to get and return tokens:
Code:
public AttackToken GetAttackToken () {
AttackToken ret = null;
if (_attackTokens.Count > 0) {
ret = _attackTokens.Remove (_attackTokens.Count -1);
}
return ret;
}
public void ReturnAttackToken (ref AttackToken token) {
if (token != null) {
_attackTokens.Add (token);
token = null;
}
}
The AttackToken class itself could perfectly be an entirely empty class with this implementation (mine has a few more things like cooldowns, etc.)
Code:
class AttackToken {
}
Then on each enemy, when you want to attack, you call EnemyManager.GetAttackToken. If it returns null you can't attack; if it returns a token, you store it, and attack. When the attack ends, you call EnemyManager.ReturnToken.
Last edited: