From c4e6bbc9fb62b9d6c17a03b86cea603711ee3811 Mon Sep 17 00:00:00 2001 From: kuroppoi <68156848+kuroppoi@users.noreply.github.com> Date: Fri, 22 Jul 2022 12:25:08 +0200 Subject: [PATCH] Implemented healing consumables --- .../gameserver/entity/player/Player.java | 16 +++++++++ .../brainwine/gameserver/item/Action.java | 2 ++ .../server/requests/InventoryUseRequest.java | 35 +++++++++++-------- 3 files changed, 39 insertions(+), 14 deletions(-) diff --git a/gameserver/src/main/java/brainwine/gameserver/entity/player/Player.java b/gameserver/src/main/java/brainwine/gameserver/entity/player/Player.java index 7025eb2..e1907b7 100644 --- a/gameserver/src/main/java/brainwine/gameserver/entity/player/Player.java +++ b/gameserver/src/main/java/brainwine/gameserver/entity/player/Player.java @@ -30,6 +30,7 @@ import brainwine.gameserver.entity.Entity; import brainwine.gameserver.entity.EntityStatus; import brainwine.gameserver.entity.FacingDirection; import brainwine.gameserver.entity.npc.Npc; +import brainwine.gameserver.item.Action; import brainwine.gameserver.item.Item; import brainwine.gameserver.item.ItemRegistry; 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); } + 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) { awardLoot(loot, DialogType.LOOT); } diff --git a/gameserver/src/main/java/brainwine/gameserver/item/Action.java b/gameserver/src/main/java/brainwine/gameserver/item/Action.java index b6a52c4..960392c 100644 --- a/gameserver/src/main/java/brainwine/gameserver/item/Action.java +++ b/gameserver/src/main/java/brainwine/gameserver/item/Action.java @@ -5,6 +5,8 @@ import com.fasterxml.jackson.annotation.JsonEnumDefaultValue; public enum Action { DIG, + HEAL, + REFILL, @JsonEnumDefaultValue NONE; diff --git a/gameserver/src/main/java/brainwine/gameserver/server/requests/InventoryUseRequest.java b/gameserver/src/main/java/brainwine/gameserver/server/requests/InventoryUseRequest.java index ffca668..f0c9d92 100644 --- a/gameserver/src/main/java/brainwine/gameserver/server/requests/InventoryUseRequest.java +++ b/gameserver/src/main/java/brainwine/gameserver/server/requests/InventoryUseRequest.java @@ -36,22 +36,29 @@ public class InventoryUseRequest extends PlayerRequest { player.setHeldItem(item); } - // Lovely type ambiguity. Always nice. - if(details instanceof Collection) { - Collection entityIds = (Collection)details; - int maxEntityAttackCount = 1; // TODO agility skill + // Use item + if(status == 1) { + if(item.isConsumable()) { + player.consume(item); + } - for(Object id : entityIds) { - if(id instanceof Integer) { - Npc npc = player.getZone().getNpc((int)id); - - if(npc != null && player.canSee(npc)) { - npc.attack(player, item); - } - } + // Lovely type ambiguity. Always nice. + if(item.isWeapon() && details instanceof Collection) { + Collection entityIds = (Collection)details; + int maxEntityAttackCount = 1; // TODO agility skill - if(--maxEntityAttackCount <= 0) { - break; + for(Object id : entityIds) { + 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; + } } } }