Package civquest.units.models

Source Code of civquest.units.models.Musketeer

/*  This file is part of CivQuest.
*
*  CivQuest is free software; you can redistribute it and/or modify
*  it under the terms of the GNU General Public License as published by
*  the Free Software Foundation; either version 2 of the License, or
*  (at your option) any later version.
*
*  CivQuest is distributed in the hope that it will be useful,
*  but WITHOUT ANY WARRANTY; without even the implied warranty of
*  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
*  GNU General Public License for more details.
*
*  You should have received a copy of the GNU General Public License
*  along with CivQuest; if not, write to the Free Software
*  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
*
*  $Id: Musketeer.java 703 2006-01-22 10:34:40Z wpausch $
*/
package civquest.units.models;

import civquest.core.Game;
import civquest.damage.Damage;
import civquest.gameChange.GameChange;
import civquest.io.DataToSave;
import civquest.io.LoadedData;
import civquest.io.Persistent.LoadingStep;
import civquest.map.Field;
import civquest.map.combat.ShotResults;
import civquest.map.combat.damage.BulletDamage;
import civquest.map.gameChange.SetMapObjectHealth;
import civquest.map.mapobj.Attacking;
import civquest.units.Unit;
import civquest.util.Coordinate;
import java.util.ArrayList;
import java.util.List;
import java.util.Random;

/**
*/
public class Musketeer extends Unit implements Attacking {

  private int timeOfNextShot;

  public Musketeer(Field field) {
    super(field);
  }

  public Musketeer(LoadedData loadedData, LoadingStep step) throws Exception {
    super(loadedData, step);
  }

  public int getSpeed(Coordinate to) {
    Field toField = Game.getMapData().getField(to);
    return (toField.isSea() ? 0 : 500);   
  }

  public List<GameChange> receive(Damage damage) {
     List<GameChange> retList = new ArrayList<GameChange>();
    Random random = new Random();
    double healthDecrease = Math.abs(random.nextGaussian() * 0.25);
    SetMapObjectHealth change = new SetMapObjectHealth(this.getID(),
                               this.getHealth() - healthDecrease);
    retList.add(change);
     return retList;
  }

  public void beforeCombatAsAttacker() {
    timeOfNextShot = 200;
  }

  public void beforeCombatAsDefender() {
    timeOfNextShot = 250;
  }

  public int getTimeOfNextShot() {
    return timeOfNextShot;
  }

  public boolean canStillShootAsDefender() {
    return true;
  }

  public ShotResults calculateAttack() {
     timeOfNextShot += 200;

    return new ShotResults(new BulletDamage(getSize(), 250));
  }

  public String getModelName() {
    return "units_musketeer";
  }

  private static final String TIME_OF_NEXT_SHOT_KEY = "timeOfNextShot";

  public DataToSave getPersistentData() {
    DataToSave data = super.getPersistentData();
    data.put(TIME_OF_NEXT_SHOT_KEY, timeOfNextShot);
    return data;
  }

  public void setPersistentData(LoadingStep step)
    throws Exception {

    super.setPersistentData(step);
    if (step == LoadingStep.CONSTRUCT) {
      timeOfNextShot = loadedData.getInt(TIME_OF_NEXT_SHOT_KEY);
    }
  }
}
TOP

Related Classes of civquest.units.models.Musketeer

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.