RuneHive-Tarnish
Neural OSRS Enhancement Framework
Loading...
Searching...
No Matches
ProducingSkillAction.java
1package com.osroyale.content.skill.impl;
2
3import com.osroyale.net.packet.out.SendMessage;
4import com.osroyale.game.world.entity.mob.player.Player;
5import com.osroyale.content.skill.SkillAction;
6import com.osroyale.game.world.items.Item;
7import com.osroyale.game.world.items.containers.ItemContainer;
8import com.osroyale.game.world.position.Position;
9import com.osroyale.util.StringUtils;
10
11import java.util.Optional;
12
59
60public abstract class ProducingSkillAction extends SkillAction {
61
68 public ProducingSkillAction(Player player, Optional<Position> position, boolean instant) {
69 super(player, position, instant);
70 }
71
79 public ProducingSkillAction(Player player, Optional<Position> position, int delay, boolean instant) {
80 super(player, position, delay, instant);
81 }
82
83 @Override
84 public final boolean canRun() {
85 Optional<Item[]> removeItem = removeItem();
86
87 if(!removeItem.isPresent())
88 return true;
89
90 ItemContainer container = getMob().getPlayer().inventory.copy();
91 if(container.removeAll(removeItem.get()) && !container.hasCapacityFor(produceItem().get())) {
92 container.fireCapacityExceededEvent();
93 return false;
94 }
95 if(getMob().getPlayer().inventory.containsAll(removeItem.get()))
96 return true;
97
98 if(!message().isPresent()) {
99 for(Item item : removeItem.get()) {
100 if(!getMob().getPlayer().inventory.contains(item)) {
101 String anyOrEnough = item.getAmount() == 1 ? "any" : "enough";
102 getMob().getPlayer().send(new SendMessage("You don't have " + anyOrEnough + " " + StringUtils.appendPluralCheck(item.getName()) + " left."));
103 return false;
104 }
105 }
106 } else {
107 getMob().getPlayer().send(new SendMessage(message().get()));
108 }
109
110 onProduce(false);
111 return false;
112 }
113
114 @Override
115 public final void onExecute() {
116 getMob().skills.addExperience(skill(), experience());
117 removeItem().ifPresent(getMob().getPlayer().inventory::removeAll);
118 produceItem().ifPresent(getMob().getPlayer().inventory::addAll);
119 onProduce(true);
120 }
121
126 public void onProduce(boolean success) {
127
128 }
129
134 public abstract Optional<Item[]> removeItem();
135
140 public abstract Optional<Item[]> produceItem();
141
147 public Optional<String> message() {
148 return Optional.empty();
149 }
150
151}
SkillAction(Mob mob, Optional< Position > position, int delay, boolean instant)
ProducingSkillAction(Player player, Optional< Position > position, boolean instant)
ProducingSkillAction(Player player, Optional< Position > position, int delay, boolean instant)
boolean removeAll(Collection<? extends Item > items)
static String appendPluralCheck(String thing)