Skip to main content

IBattleSystem

Contract for interacting with the battle system from game code. Provides battle state checking and event subscription.

ibattle system

You start a battle and listen. Everything behind the interface can change -- including moving the whole fight to a server -- without touching your code.

Namespace: OpenMon.MCE.SDK

Definition​

public interface IBattleSystem
{
bool IsInBattle { get; }
event Action OnBattleStarted;
event Action<bool> OnBattleEnded;
}
Engine hooks

engine.Battle is a BattleSystemFacade. It sets IsInBattle and raises OnBattleStarted and OnBattleEnded when the engine calls its hooks, NotifyBattleStarted() and NotifyBattleEnded(bool playerWon). In the current engine nothing calls those hooks yet, so IsInBattle stays false and the two events do not fire. Until they are connected, observe battles through the battle launcher, which is bound in DI and does notify: IBattleLauncher.BattleInProgress, SubscribeToBattleLaunched, SubscribeToBattleToUnload and SubscribeToBattleEnded(Action<BattleResultParameters>).

Properties​

IsInBattle​

Whether a battle is currently in progress.

Type: bool

Returns true from the moment a battle scene loads until the battle results are processed and the overworld resumes.

Events​

OnBattleStarted​

Fired when a battle begins, after the battle scene has loaded and the BattleManager has initialized.

Signature: event Action OnBattleStarted

OnBattleEnded​

Fired when a battle concludes, before the battle scene unloads.

Signature: event Action<bool> OnBattleEnded

ParameterTypeDescription
playerWonbooltrue if the player won, false if the player lost, fled, or was defeated

Usage Example​

using OpenMon.MCE.SDK;
using Zenject;

public class BattleTracker : MonoBehaviour
{
// Only IMonsterCaptureEngine is bound in DI; reach subsystems through it.
[Inject] private IMonsterCaptureEngine engine;

private IBattleSystem battle;

private int totalBattles;
private int wins;

private void Awake()
{
battle = engine.Battle;
}

private void OnEnable()
{
battle.OnBattleStarted += OnBattleStart;
battle.OnBattleEnded += OnBattleEnd;
}

private void OnDisable()
{
battle.OnBattleStarted -= OnBattleStart;
battle.OnBattleEnded -= OnBattleEnd;
}

private void OnBattleStart()
{
totalBattles++;
}

private void OnBattleEnd(bool playerWon)
{
if (playerWon) wins++;
Debug.Log($"Record: {wins}/{totalBattles}");
}

private void Update()
{
// Disable certain UI when in battle
if (battle.IsInBattle)
{
// Hide overworld HUD elements
}
}
}
Memory Management

Always unsubscribe from events in OnDisable() or OnDestroy() to prevent memory leaks. This is especially important for MonoBehaviours that can be destroyed during scene transitions.