/// <summary> /// Event handler to process when our fired shell hit something. /// Note that in TankShooting.cs our agents is setup to listen whenever a new shell is fired, /// so we don't have to worry about that, this method will automagically be called. /// (just need to implement your rewards here, however you want) /// </summary> /// <param name="explosion">The ShellExplosion component sending the event</param> /// <param name="damages">Dictionary with { tank id : damage } damages dealt by explosion</param> public override void OnTankShellHit(Complete.ShellExplosion explosion, Dictionary <int, float> damages) { const float rewardPerDamage = 0.005f; // max damage is 100, so max reward would be 0.5 const float selfDamageFactor = -1.5f; // anytime we damage ourself, assess large penalty foreach (var entry in damages) { if (entry.Key == this.playerNumber) { // argh... we hit ourself!! AddReward(entry.Value * rewardPerDamage * selfDamageFactor); // Debug.unityLogger.Log(LOGTAG, gameObject.name + " HIT OURSELF! Reward = " + (entry.Value * rewardPerDamage * selfDamageFactor).ToString()); } else { // yay... we hit someone else!! AddReward(entry.Value * rewardPerDamage); // Debug.unityLogger.Log(LOGTAG, gameObject.name + " HIT TARGET! Reward = " + (entry.Value * rewardPerDamage).ToString()); } } // housekeeping, remove listener since explosion will be destroyed if (explosion) { explosion.OnExplosion -= OnTankShellHit; } }
/// <summary> /// Event handler to process when our fired shell hit something. /// Note that in TankShooting.cs our agents is setup to listen whenever a new shell is fired, /// so we don't have to worry about that, this method will automagically be called. /// (just need to implement your rewards here, however you want) /// </summary> /// <param name="explosion">The ShellExplosion component sending the event</param> /// <param name="damages">Dictionary with { tank id : damage } damages dealt by explosion</param> public void OnTankShellHit(Complete.ShellExplosion explosion, Dictionary <int, float> damages) { foreach (var entry in damages) { if (entry.Key != this.playerNumber) { AddReward(entry.Value * rewardPerDamage); // Debug.unityLogger.Log(LOGTAG, gameObject.name + " HIT TARGET! Reward = " + (entry.Value * rewardPerDamage).ToString()); } } // housekeeping, remove listener since explosion will be destroyed if (explosion) { explosion.OnExplosion -= OnTankShellHit; } }
// more interface methods below, these are abstract so your subclass needs to implement them public abstract void OnTankShellHit(Complete.ShellExplosion explosion, Dictionary <int, float> damages);