Using Identifiers

How to choose graphics, items, objects, npcs, tiles, animations

In the cache there is a finite number of every type of game asset. Interestingly you can mix and match these. Across NPCs you can use different animations, add unique graphics, animate objects, move all things on tiles, create custom projectiles and even make unique items from just combining existing assets.

In choosing all these options you need to use identifiers, or as you will see in the code source, "id" or for WorldTiles, "x", "y", "plane". An example of this would be item 995, which is coins. Take a look below in the code to see a simplified class code for item.

public class Item {  
  private short id;  
	protected int amount;  

  public int getId() { return this.id; }

  public Item(int id, int amount) { this(id, amount, false); }
  
  public Item setAmount(int amount) { /*...*/ }

  public void setId(int id) { this.id = (short)id; }

  public int getAmount() { return this.amount; }

  public String getName() { return this.getDefinitions().getName(); }
}

All an item is, is an id and an amount and it is the same for the rest, we are basically getting these from the cache...

public class NPC extends Entity {
	private int id;
	private WorldTile respawnTile;
	private boolean randomWalk;
	private Map<Skill, Integer> combatLevels;
	private boolean spawned;	
	private boolean hidden = false;

	public NPC(int id, WorldTile tile, Direction direction, boolean permaDeath) {
		super(tile);
		this.id = id;
		respawnTile = WorldTile.of(tile);
    //etc...
	}

	public int getId() {
		return id;
	}

	public void setForceWalk(WorldTile tile) {
		resetWalkSteps();
		forceWalk = tile;
	}

}
public class WorldObject {
  protected WorldTile tile;
  protected int id;
  protected ObjectType type;
  protected int rotation;

  public WorldObject(int id, int rotation, int x, int y, int plane) {
    this.tile = WorldTile.of(x, y, plane);
    this.id = id;
    this.type = ObjectDefinitions.getDefs(id).getType(0);
    this.rotation = rotation;
  }   

  public int getId() { return this.id; }
  public int getRotation(int turn) { /*...*/ }
  public WorldTile getTile() { return this.tile; }
}
public final class Animation {  
  private int[] ids;  
  private int speed;
  
  public Animation(int id) {
      this(id, 0);
  } 

  public int[] getIds() {
      return this.ids;
  }

  public int getSpeed() {
      return this.speed;
  }

}