RuneHive-Game
Loading...
Searching...
No Matches
com.runehive.content.bags.ItemBag Class Referenceabstract
Inheritance diagram for com.runehive.content.bags.ItemBag:
Collaboration diagram for com.runehive.content.bags.ItemBag:

Public Member Functions

void check (Player player)
void empty (Player player)
void fill (Player player)
abstract String getIndication ()
abstract String getItem ()
abstract String getName ()
abstract Predicate< ItemisAllowed ()
 ItemBag (ItemContainer container)

Public Attributes

final ItemContainer container

Detailed Description

Definition at line 11 of file ItemBag.java.

Constructor & Destructor Documentation

◆ ItemBag()

com.runehive.content.bags.ItemBag.ItemBag ( ItemContainer container)

Definition at line 15 of file ItemBag.java.

15 {
16 this.container = container;
17 }

References container.

Member Function Documentation

◆ check()

void com.runehive.content.bags.ItemBag.check ( Player player)

Reimplemented in com.runehive.content.bags.impl.CoalBag.

Definition at line 72 of file ItemBag.java.

72 {
73 player.message("You look in your "+getName()+" and see:");
74
75 if (container.getFreeSlots() == container.capacity()) {
76 player.message("The "+getName()+" is empty.");
77 return;
78 }
79 for (Item item : container.getItems()) {
80 if(item == null) continue;
81 player.message(item.getAmount() + "x " + ItemDefinition.get(item.getId()).getName());
82 }
83 }

References container, com.runehive.game.world.items.ItemDefinition.get(), getName(), com.runehive.game.world.items.ItemDefinition.getName(), and com.runehive.game.world.entity.mob.player.Player.message().

Here is the call graph for this function:

◆ empty()

void com.runehive.content.bags.ItemBag.empty ( Player player)

Definition at line 44 of file ItemBag.java.

44 {
45 if (container.getFreeSlots() == container.capacity()) {
46 player.message("The "+getName()+" is already empty.");
47 return;
48 }
49 if (player.inventory.getFreeSlots() <= 0) {
50 player.message("You don't have enough inventory space to empty the contents of this "+getName()+".");
51 return;
52 }
53 for(Item item : container.getItems()) {
54 int freeSlots = player.inventory.getFreeSlots();
55 if (freeSlots <= 0) {
56 player.inventory.refresh();
57 return;
58 }
59 if(item == null) continue;
60
61 int amount = item.getAmount();
62
63 if(amount > freeSlots)
64 amount = freeSlots;
65
66 container.remove(new Item(item.getId(), amount));
67 player.inventory.add(new Item(item.getId(), item.getAmount()));
68 }
69 player.inventory.refresh();
70 }

References com.runehive.game.world.items.containers.ItemContainer.add(), container, com.runehive.game.world.items.containers.ItemContainer.getFreeSlots(), getName(), com.runehive.game.world.entity.mob.player.Player.inventory, com.runehive.game.world.entity.mob.player.Player.message(), and com.runehive.game.world.items.containers.inventory.Inventory.refresh().

Here is the call graph for this function:

◆ fill()

void com.runehive.content.bags.ItemBag.fill ( Player player)

Definition at line 27 of file ItemBag.java.

27 {
28 player.message("You search your inventory for "+getItem()+" to put into the "+getName()+"...");
29
30 if (Arrays.stream(player.inventory.getItems()).noneMatch(isAllowed())) {
31 player.message("There "+getIndication()+" no "+getItem()+" in your inventory that can be added to the "+getName()+".");
32 return;
33 }
34
35 Arrays.stream(player.inventory.getItems()).filter(isAllowed()).forEach(item -> {
36 player.inventory.remove(item);
37 container.add(item);
38 });
39
40 player.message("You add the "+getItem()+" to your "+getName()+".");
41 player.inventory.refresh();
42 }

References container, getIndication(), getItem(), com.runehive.game.world.items.containers.ItemContainer.getItems(), getName(), com.runehive.game.world.entity.mob.player.Player.inventory, isAllowed(), com.runehive.game.world.entity.mob.player.Player.message(), com.runehive.game.world.items.containers.inventory.Inventory.refresh(), and com.runehive.game.world.items.containers.ItemContainer.remove().

Here is the call graph for this function:

◆ getIndication()

abstract String com.runehive.content.bags.ItemBag.getIndication ( )
abstract

Reimplemented in com.runehive.content.bags.impl.CoalBag, and com.runehive.content.bags.impl.GemBag.

Referenced by fill().

Here is the caller graph for this function:

◆ getItem()

abstract String com.runehive.content.bags.ItemBag.getItem ( )
abstract

Reimplemented in com.runehive.content.bags.impl.CoalBag, and com.runehive.content.bags.impl.GemBag.

Referenced by fill().

Here is the caller graph for this function:

◆ getName()

abstract String com.runehive.content.bags.ItemBag.getName ( )
abstract

Reimplemented in com.runehive.content.bags.impl.CoalBag, and com.runehive.content.bags.impl.GemBag.

Referenced by check(), empty(), and fill().

Here is the caller graph for this function:

◆ isAllowed()

abstract Predicate< Item > com.runehive.content.bags.ItemBag.isAllowed ( )
abstract

Reimplemented in com.runehive.content.bags.impl.CoalBag, and com.runehive.content.bags.impl.GemBag.

Referenced by fill().

Here is the caller graph for this function:

Member Data Documentation

◆ container

final ItemContainer com.runehive.content.bags.ItemBag.container

The documentation for this class was generated from the following file: