Package com.aldaviva.autorpg.game

Source Code of com.aldaviva.autorpg.game.RandomEventManager

package com.aldaviva.autorpg.game;

import java.util.ArrayList;
import java.util.List;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Component;

import com.aldaviva.autorpg.game.events.FindItemEvent;
import com.aldaviva.autorpg.game.events.HandofGodEvent;
import com.aldaviva.autorpg.game.events.QuestStartEvent;
import com.aldaviva.autorpg.game.events.RandomEvent;

@Component
public class RandomEventManager implements PeriodicUpdater {

  private static final Logger LOGGER = LoggerFactory.getLogger(RandomEventManager.class);

  private List<RandomEvent> randomEvents = new ArrayList<RandomEvent>();

  public void init() {
    LOGGER.debug("Initializing Random Event Manager.");

    randomEvents.add(new HandofGodEvent());
    randomEvents.add(new FindItemEvent());
    randomEvents.add(new QuestStartEvent());
  }
 
  public void force(int i){
    try {
      randomEvents.get(i).forceOccur();
    } catch(IndexOutOfBoundsException e){
      LOGGER.error("Random event #"+i+" not found. Choose a number between 0 and "+(randomEvents.size()-1)+" (inclusive).");
    }
  }

  public void update() {
    for (RandomEvent event : randomEvents) {
      event.rollToOccur();
    }
  }

}
TOP

Related Classes of com.aldaviva.autorpg.game.RandomEventManager

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.