Package ch.sahits.game.openpatrician.controller.personal

Source Code of ch.sahits.game.openpatrician.controller.personal.SocialRankChecker

package ch.sahits.game.openpatrician.controller.personal;

import ch.sahits.game.openpatrician.model.IPlayer;
import ch.sahits.game.openpatrician.model.city.ICity;
import ch.sahits.game.openpatrician.model.personal.ESocialRank;
import ch.sahits.game.openpatrician.model.personal.IReputation;
import ch.sahits.game.openpatrician.model.time.DateObject;
import ch.sahits.game.openpatrician.model.time.EUpdateIntervalRegistration;
import ch.sahits.game.openpatrician.model.time.IPeriodicalUpdate;
import ch.sahits.game.openpatrician.model.time.PeriodicalTimeUpdater;
/**
* This checker checks at the end of month if the next social rank can be reached
* @author Andi Hotz, (c) Sahits GmbH, 2012
* Created on Jul 24, 2012
*
*/
public class SocialRankChecker implements IPeriodicalUpdate {
 
  private final IPlayer player;
 
  public SocialRankChecker(IPlayer player) {
    this.player = player;
  }
  /**
   * Start the update checker
   */
  public void start(){
    new PeriodicalTimeUpdater(EUpdateIntervalRegistration.END_OF_MONTH, this);
  }

  @Override
  public void notify(DateObject date) {
    if (isNextRankAchievable()){
      ESocialRank nextRank = player.getRank().getNextRank();
      player.updateRank(nextRank);
    }

  }
 
  public boolean isNextRankAchievable(){
    ESocialRank rank = player.getRank();
    ICity homeTown = player.getCompany().getHomeTown();
    if (rank==ESocialRank.PATRICIAN || rank==ESocialRank.MAYOR || rank==ESocialRank.ALDERMAN){
      return false;
    }
    long compValue = player.getCompany().getCompanyValue();
    ESocialRank nextRank = rank.getNextRank();
    IReputation rep = homeTown.getReputation(player);
    int popularity = rep.getPopularity();
    if (compValue>=nextRank.getCompanyValue() && popularity>=nextRank.getSocialReputation()){
      if (nextRank==ESocialRank.COUNCILMAN){
        // TODO check for guild membership
        return false;
      }
      return true;
    }
    return false;
  }

}
TOP

Related Classes of ch.sahits.game.openpatrician.controller.personal.SocialRankChecker

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.