Package com.aldaviva.autorpg.game

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

package com.aldaviva.autorpg.game;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Configurable;

import com.aldaviva.autorpg.Utils;
import com.aldaviva.autorpg.data.entities.Character;
import com.aldaviva.autorpg.data.entities.Configuration;
import com.aldaviva.autorpg.data.enums.ConfigurationKey;
import com.aldaviva.autorpg.data.types.MapPoint;

@Configurable
class WanderHandler implements CharacterProgressHandler {
 
  private static final Logger LOGGER = LoggerFactory.getLogger(WanderHandler.class);

  @Autowired
  private RealmMap worldMap;

  public void handleProgress(Character character) {
    MapPoint origin = character.getLocation();
    if (origin == null) {
      origin = new MapPoint();
      origin.x = Utils.getRandomInt(0, Integer.valueOf(Configuration.getValue(ConfigurationKey.MAP_WIDTH)));
      origin.y = Utils.getRandomInt(0, Integer.valueOf(Configuration.getValue(ConfigurationKey.MAP_HEIGHT)));
    }
    MapPoint destination = worldMap.getDestination(origin, RealmMap.MovementDirection.getRandomDirection());
    character.setLocation(destination);
    LOGGER.debug(character.getName() + " has walked to " + destination.x + ", " + destination.y);
  }
}
TOP

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

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.