All Downloads are FREE. Search and download functionalities are using the official Maven repository.

dev.robocode.tankroyale.botapi.internal.BotEventHandlers Maven / Gradle / Ivy

There is a newer version: 0.26.1
Show newest version
package dev.robocode.tankroyale.botapi.internal;

import dev.robocode.tankroyale.botapi.IBaseBot;
import dev.robocode.tankroyale.botapi.events.*;

final class BotEventHandlers {

    final EventHandler onConnected = new EventHandler<>();
    final EventHandler onDisconnected = new EventHandler<>();
    final EventHandler onConnectionError = new EventHandler<>();

    final EventHandler onGameStarted = new EventHandler<>();
    final EventHandler onGameEnded = new EventHandler<>();
    final EventHandler onGameAborted = new EventHandler<>();
    final EventHandler onRoundStarted = new EventHandler<>();
    final EventHandler onRoundEnded = new EventHandler<>();
    final EventHandler onTick = new EventHandler<>();
    final EventHandler onSkippedTurn = new EventHandler<>();
    final EventHandler onDeath = new EventHandler<>();
    final EventHandler onBotDeath = new EventHandler<>();
    final EventHandler onHitBot = new EventHandler<>();
    final EventHandler onHitWall = new EventHandler<>();
    final EventHandler onBulletFired = new EventHandler<>();
    final EventHandler onHitByBullet = new EventHandler<>();
    final EventHandler onBulletHit = new EventHandler<>();
    final EventHandler onBulletHitBullet = new EventHandler<>();
    final EventHandler onBulletHitWall = new EventHandler<>();
    final EventHandler onScannedBot = new EventHandler<>();
    final EventHandler onWonRound = new EventHandler<>();
    final EventHandler onCustomEvent = new EventHandler<>();
    final EventHandler onTeamMessage = new EventHandler<>();

    final EventHandler onNextTurn = new EventHandler<>();

    BotEventHandlers(IBaseBot baseBot) {
        onConnected.subscribe(baseBot::onConnected);
        onDisconnected.subscribe(baseBot::onDisconnected);
        onConnectionError.subscribe(baseBot::onConnectionError);
        onGameStarted.subscribe(baseBot::onGameStarted);
        onGameEnded.subscribe(baseBot::onGameEnded);
        onRoundStarted.subscribe(baseBot::onRoundStarted);
        onRoundEnded.subscribe(baseBot::onRoundEnded);
        onTick.subscribe(baseBot::onTick);
        onSkippedTurn.subscribe(baseBot::onSkippedTurn);
        onDeath.subscribe(baseBot::onDeath);
        onBotDeath.subscribe(baseBot::onBotDeath);
        onHitBot.subscribe(baseBot::onHitBot);
        onHitWall.subscribe(baseBot::onHitWall);
        onBulletFired.subscribe(baseBot::onBulletFired);
        onHitByBullet.subscribe(baseBot::onHitByBullet);
        onBulletHit.subscribe(baseBot::onBulletHit);
        onBulletHitBullet.subscribe(baseBot::onBulletHitBullet);
        onBulletHitWall.subscribe(baseBot::onBulletHitWall);
        onScannedBot.subscribe(baseBot::onScannedBot);
        onWonRound.subscribe(baseBot::onWonRound);
        onCustomEvent.subscribe(baseBot::onCustomEvent);
        onTeamMessage.subscribe(baseBot::onTeamMessage);
    }

    void fire(BotEvent event) {
        if (event instanceof TickEvent) {
            onTick.publish((TickEvent) event);
        } else if (event instanceof ScannedBotEvent) {
            onScannedBot.publish((ScannedBotEvent) event);
        } else if (event instanceof SkippedTurnEvent) {
            onSkippedTurn.publish((SkippedTurnEvent) event);
        } else if (event instanceof HitBotEvent) {
            onHitBot.publish((HitBotEvent) event);
        } else if (event instanceof HitWallEvent) {
            onHitWall.publish((HitWallEvent) event);
        } else if (event instanceof BulletFiredEvent) {
            onBulletFired.publish((BulletFiredEvent) event);
        } else if (event instanceof BulletHitWallEvent) {
            onBulletHitWall.publish((BulletHitWallEvent) event);
        } else if (event instanceof HitByBulletEvent) {
            onHitByBullet.publish((HitByBulletEvent) event);
        } else if (event instanceof BulletHitBotEvent) {
            onBulletHit.publish((BulletHitBotEvent) event);
        } else if (event instanceof BotDeathEvent) {
            onBotDeath.publish((BotDeathEvent) event);
        } else if (event instanceof DeathEvent) {
            onDeath.publish((DeathEvent) event);
        } else if (event instanceof BulletHitBulletEvent) {
            onBulletHitBullet.publish((BulletHitBulletEvent) event);
        } else if (event instanceof WonRoundEvent) {
            onWonRound.publish((WonRoundEvent) event);
        } else if (event instanceof CustomEvent) {
            onCustomEvent.publish((CustomEvent) event);
        } else if (event instanceof TeamMessageEvent) {
            onTeamMessage.publish((TeamMessageEvent) event);
        } else {
            throw new IllegalStateException("Unhandled event type: " + event);
        }
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy