/// <summary> /// Removes the target from map and explodes it if it's size is not too small. /// </summary> protected override void OnStart() { int size = TraitsUtil.GetSize(agent); if (size <= 1) { agent.RemoveFromMap(); Complete(); return; } AddEventHandlers(); agent.RemoveFromMap(); explodable.Explode(); }
/// <summary> /// Attack the target attack receiever and then call the relevant transition. /// </summary> void AttackTarget() { if (agent.TargetMapElement == null) { CallTargetKilledTransition(); return; } IAttackReceiver attackReceiver = agent.TargetMapElement as IAttackReceiver; if (attackReceiver == null) { CallTargetKilledTransition(); return; } int targetHealth = TraitsUtil.GetHealth(agent.TargetMapElement); if (targetHealth <= 0) { int targetSize = TraitsUtil.GetSize(agent.TargetMapElement); if (targetSize > 1) { CallTargetKilledTransition(); } else { float hunger = 1.0f; bool isEating = Random.value <= hunger; if (isEating) { agent.Description = "Ate " + agent.TargetMapElement.DisplayName; agent.TargetMapElement.Description = "Eaten by " + agent.DisplayName; CallTargetEatenTransition(); } else { CallTargetKilledTransition(); } } } else { attackReceiver.ReceiveAttack(agent); } }