Code Search for Developers
 
 
  

Potion.java from Magellan-Client at Krugle


Show Potion.java syntax highlighted

/*
 *  Copyright (C) 2000-2004 Roger Butenuth, Andreas Gampe,
 *                          Stefan Goetz, Sebastian Pappert,
 *                          Klaas Prause, Enno Rehling,
 *                          Sebastian Tusk, Ulrich Kuester,
 *                          Ilja Pavkovic
 *
 * This file is part of the Eressea Java Code Base, see the
 * file LICENSING for the licensing information applying to
 * this file.
 *
 */

package com.eressea;

import java.util.Collection;
import java.util.Iterator;
import java.util.Map;

import com.eressea.util.CollectionFactory;

/**
 * Container class for a potion based on its representation in a cr version >= 42.
 */
public class Potion extends DescribedObject {
	private int level = -1;

	/** The ingredients needed for this potion. The list contains <tt>String</tt> objects. */
	private Map ingredients = null;

	/**
	 * Constructs a new Potion object identified by id.
	 *
	 * @param id TODO: DOCUMENT ME!
	 */
	public Potion(ID id) {
		super(id);
	}

	/**
	 * Sets the level of this Potion.
	 *
	 * @param level TODO: DOCUMENT ME!
	 */
	public void setLevel(int level) {
		this.level = level;
	}

	/**
	 * Returns the level of this Potion.
	 *
	 * @return TODO: DOCUMENT ME!
	 */
	public int getLevel() {
		return this.level;
	}

	/**
	 * Returns the ingredients required for this potion. The elements are instances of class Item.
	 *
	 * @return TODO: DOCUMENT ME!
	 */
	public Collection ingredients() {
		return CollectionFactory.unmodifiableCollection(ingredients);
	}

	/**
	 * Returns a specific ingredient of this potion.
	 *
	 * @param key the item type id of the ingredient to be returned.
	 *
	 * @return TODO: DOCUMENT ME!
	 */
	public Item getIngredient(ID key) {
		if(this.ingredients != null) {
			return (Item) this.ingredients.get(key);
		}

		return null;
	}

	/**
	 * Puts a new element into the list of ingredients required to brew this potion.
	 *
	 * @param i TODO: DOCUMENT ME!
	 *
	 * @return TODO: DOCUMENT ME!
	 */
	public Item addIngredient(Item i) {
		if(this.ingredients == null) {
			this.ingredients = CollectionFactory.createOrderedHashtable();
		}

		this.ingredients.put(i.getItemType().getID(), i);

		return i;
	}

	/**
	 * Removes an item from the list of ingredients required to brew this potion.
	 *
	 * @param key the id of the item's item type to be removed.
	 *
	 * @return TODO: DOCUMENT ME!
	 */
	public Item removeIngredient(ID key) {
		if(this.ingredients != null) {
			return (Item) this.ingredients.remove(key);
		}

		return null;
	}

	/**
	 * Removes all ingredients of this potion.
	 */
	public void clearIngredients() {
		if(this.ingredients != null) {
			this.ingredients.clear();
			this.ingredients = null;
		}
	}

	/**
	 * Merges potion.
	 *
	 * @param curGD TODO: DOCUMENT ME!
	 * @param curPotion TODO: DOCUMENT ME!
	 * @param newGD TODO: DOCUMENT ME!
	 * @param newPotion TODO: DOCUMENT ME!
	 */
	public static void merge(GameData curGD, Potion curPotion, GameData newGD, Potion newPotion) {
		if(curPotion.getName() != null) {
			newPotion.setName(curPotion.getName());
		}

		if(curPotion.getDescription() != null) {
			newPotion.setDescription(curPotion.getDescription());
		}

		if(curPotion.getLevel() != -1) {
			newPotion.setLevel(curPotion.getLevel());
		}

		if(!curPotion.ingredients().isEmpty()) {
			newPotion.clearIngredients();

			for(Iterator iter = curPotion.ingredients().iterator(); iter.hasNext();) {
				Item i = (Item) iter.next();
				com.eressea.rules.ItemType it = newGD.rules.getItemType(i.getItemType().getID(),
																		true);
				newPotion.addIngredient(new Item(it, i.getAmount()));
			}
		}
	}
}




See more files for this project here

Magellan-Client

The Magellan Client is basicly a GUI for the pbem game eressea but can be used for other pbems based on \"atlantis\" too.

Project homepage: http://sourceforge.net/projects/magellan-client
Programming language(s): Java
License: other

  completion/
    AutoCompletion.java
    Completer.java
    CompleterSettingsProvider.java
    Completion.java
    OrderParser.java
  cr/
    Loader.java
  demo/
    actions/
      AbortAction.java
      AddCRAction.java
      AddSelectionAction.java
      ArmyStatsAction.java
      ChangeFactionConfirmationAction.java
      ConfirmAction.java
      ECheckAction.java
      EresseaOptionsAction.java
      ExpandSelectionAction.java
      ExportCRAction.java
      ExternalModuleAction.java
      FactionStatsAction.java
      FileHistoryAction.java
      FileSaveAction.java
      FileSaveAsAction.java
      FillSelectionAction.java
      FindAction.java
      FindPreviousUnconfirmedAction.java
      HelpAction.java
      InfoAction.java
      InvertSelectionAction.java
      IslandAction.java
      MapSaveAction.java
      MenuAction.java
      OpenCRAction.java
      OpenOrdersAction.java
      OpenSelectionAction.java
      OptionAction.java
      QuitAction.java
      RedoAction.java
    desktop/
    Client.java
    ClientPreferences.java
    EMapDetailsPanel.java
    EMapOverviewPanel.java
    FindDialog.java
    MagellanUndoManager.java
    SetOriginDialog.java
  event/
  extern/
  gamebinding/
  io/
  main/
  relation/
  resource/
  rules/
  skillchart/
  swing/
  tasks/
  util/
  Alliance.java
  Battle.java
  Border.java
  Building.java
  CombatSpell.java
  CompleteData.java
  CoordinateID.java
  Described.java
  DescribedObject.java
  EntityID.java
  Faction.java
  GameData.java
  Group.java
  HasRegion.java
  HotSpot.java
  ID.java
  Identifiable.java
  IntegerID.java
  Island.java
  Item.java
  LongID.java
  LuxuryPrice.java
  Message.java
  MissingData.java
  Named.java
  NamedObject.java
  Potion.java
  Region.java
  RegionResource.java
  Related.java
  RelatedObject.java
  Rules.java
  Scheme.java
  Ship.java
  Sign.java
  Skill.java
  Spell.java
  StringID.java
  TempUnit.java
  Unique.java
  Unit.java
  UnitContainer.java
  UnitID.java
  ZeroUnit.java