mirror of
https://github.com/array-in-a-matrix/brainwine.git
synced 2025-04-02 11:11:58 -04:00
Implemented healing consumables
This commit is contained in:
parent
a6f9e649ff
commit
c4e6bbc9fb
3 changed files with 39 additions and 14 deletions
|
@ -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);
|
||||
}
|
||||
|
|
|
@ -5,6 +5,8 @@ import com.fasterxml.jackson.annotation.JsonEnumDefaultValue;
|
|||
public enum Action {
|
||||
|
||||
DIG,
|
||||
HEAL,
|
||||
REFILL,
|
||||
|
||||
@JsonEnumDefaultValue
|
||||
NONE;
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue