Package games.stendhal.server.entity.mapstuff.spawner

Source Code of games.stendhal.server.entity.mapstuff.spawner.SheepFood

/* $Id: SheepFood.java,v 1.10 2011/04/02 15:44:19 kymara Exp $ */
/***************************************************************************
*                      (C) Copyright 2003 - Marauroa                      *
***************************************************************************
***************************************************************************
*                                                                         *
*   This program 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.                                   *
*                                                                         *
***************************************************************************/
package games.stendhal.server.entity.mapstuff.spawner;

import games.stendhal.common.grammar.Grammar;
import games.stendhal.server.core.engine.SingletonRepository;
import games.stendhal.server.entity.item.Item;
import marauroa.common.game.RPClass;
import marauroa.common.game.RPObject;
import marauroa.common.game.Definition.Type;

/**
* A regenerative source of food that can be eaten by sheep.
*/
public class SheepFood extends PassiveEntityRespawnPoint {

  private int amount;

  private static final int MAX_NUMBER_OF_FRUITS = 5;

  /** How long it takes to grow one berry. originally 2000 tt */
  private static final int GROWING_RATE = 1200;

  public static void generateRPClass() {
    final RPClass food = new RPClass("food");
    food.isA("plant_grower");
    food.addAttribute("amount", Type.BYTE);
  }

  public SheepFood(final RPObject object) {
    super(object, "aeryberry", GROWING_RATE);
    setRPClass("food");
    put("type", "food");
    update();
  }

  public SheepFood() {
    super("aeryberry", GROWING_RATE);
    setRPClass("food");
    put("type", "food");
  }

  @Override
  public void update() {
    super.update();
    if (has("amount")) {
      amount = getInt("amount");
    }
  }

  @Override
  public void onFruitPicked(final Item picked) {
    super.onFruitPicked(picked);
    setAmount(amount - 1);
    notifyWorldAboutChanges();
  }

  private void setAmount(final int amount) {
      this.amount = amount;
      put("amount", amount);
  }

  /**
   * Gets the number of ripe fruits that are on.
   *
   * @return number of ripe fruits
   */
  public int getAmount() {
    return amount;
  }

  @Override
  protected void growNewFruit() {
    setAmount(amount + 1);
    notifyWorldAboutChanges();
  }

  @Override
  public String describe() {
    final String text = "You see an aeryberry bush, with "
        + Grammar.quantityplnoun(getAmount(), "berry", "one")
        + " on it. Only sheep can eat aeryberries.";
    return text;
  }

  @Override
  public void setToFullGrowth() {
    setAmount(MAX_NUMBER_OF_FRUITS);
    // don't grow anything new until someone picks a fruit
    SingletonRepository.getTurnNotifier().dontNotify(this);
  }
 
  @Override
  public void setStartState() {
    setToFullGrowth();
  }
}
TOP

Related Classes of games.stendhal.server.entity.mapstuff.spawner.SheepFood

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.