Implemented healing consumables

This commit is contained in:
kuroppoi 2022-07-22 12:25:08 +02:00
parent a6f9e649ff
commit c4e6bbc9fb
3 changed files with 39 additions and 14 deletions

View file

@ -30,6 +30,7 @@ import brainwine.gameserver.entity.Entity;
import brainwine.gameserver.entity.EntityStatus; import brainwine.gameserver.entity.EntityStatus;
import brainwine.gameserver.entity.FacingDirection; import brainwine.gameserver.entity.FacingDirection;
import brainwine.gameserver.entity.npc.Npc; import brainwine.gameserver.entity.npc.Npc;
import brainwine.gameserver.item.Action;
import brainwine.gameserver.item.Item; import brainwine.gameserver.item.Item;
import brainwine.gameserver.item.ItemRegistry; import brainwine.gameserver.item.ItemRegistry;
import brainwine.gameserver.item.ItemUseType; import brainwine.gameserver.item.ItemUseType;
@ -666,6 +667,21 @@ public class Player extends Entity implements CommandExecutor {
return MathUtils.clamp(skills.getOrDefault(skill, 1), 1, MAX_NATURAL_SKILL_LEVEL); return MathUtils.clamp(skills.getOrDefault(skill, 1), 1, MAX_NATURAL_SKILL_LEVEL);
} }
public void consume(Item item) {
Action action = item.getAction();
// TODO some kind of abstraction for things like this would be pretty cool
switch(action) {
case HEAL: heal(item.getPower()); break;
default: break;
}
// (Temporary?) measure to prevent consuming unimplemented consumables
if(action != Action.NONE) {
inventory.removeItem(item);
}
}
public void awardLoot(Loot loot) { public void awardLoot(Loot loot) {
awardLoot(loot, DialogType.LOOT); awardLoot(loot, DialogType.LOOT);
} }

View file

@ -5,6 +5,8 @@ import com.fasterxml.jackson.annotation.JsonEnumDefaultValue;
public enum Action { public enum Action {
DIG, DIG,
HEAL,
REFILL,
@JsonEnumDefaultValue @JsonEnumDefaultValue
NONE; NONE;

View file

@ -36,22 +36,29 @@ public class InventoryUseRequest extends PlayerRequest {
player.setHeldItem(item); player.setHeldItem(item);
} }
// Lovely type ambiguity. Always nice. // Use item
if(details instanceof Collection) { if(status == 1) {
Collection<?> entityIds = (Collection<?>)details; if(item.isConsumable()) {
int maxEntityAttackCount = 1; // TODO agility skill player.consume(item);
}
for(Object id : entityIds) { // Lovely type ambiguity. Always nice.
if(id instanceof Integer) { if(item.isWeapon() && details instanceof Collection) {
Npc npc = player.getZone().getNpc((int)id); Collection<?> entityIds = (Collection<?>)details;
int maxEntityAttackCount = 1; // TODO agility skill
if(npc != null && player.canSee(npc)) {
npc.attack(player, item);
}
}
if(--maxEntityAttackCount <= 0) { for(Object id : entityIds) {
break; if(id instanceof Integer) {
Npc npc = player.getZone().getNpc((int)id);
if(npc != null && player.canSee(npc)) {
npc.attack(player, item);
}
}
if(--maxEntityAttackCount <= 0) {
break;
}
} }
} }
} }