diff --git a/API/src/main/java/cz/neumimto/rpg/api/skills/RepeatingSkill.java b/API/src/main/java/cz/neumimto/rpg/api/skills/RepeatingSkill.java index f94965d38..24a59796b 100644 --- a/API/src/main/java/cz/neumimto/rpg/api/skills/RepeatingSkill.java +++ b/API/src/main/java/cz/neumimto/rpg/api/skills/RepeatingSkill.java @@ -26,7 +26,7 @@ public class RepeatingSkill extends ActiveSkill { @Override public WrappedSkill.WrappedSkillData constructSkillData() { - return new RepeatingSkillData(getId(), super.constructSkillData()); + return new RepeatingSkillData(getId()); } @Override @@ -58,8 +58,8 @@ public static class RepeatingSkillData extends WrappedSkill.WrappedSkillData { public long period; public long maxDuartion; - public RepeatingSkillData(String skill, SkillData wrapped) { - super(skill, wrapped); + public RepeatingSkillData(String skill) { + super(skill); } } diff --git a/API/src/main/java/cz/neumimto/rpg/api/skills/WrappedSkill.java b/API/src/main/java/cz/neumimto/rpg/api/skills/WrappedSkill.java index be97c34bc..3ffbf7cbe 100644 --- a/API/src/main/java/cz/neumimto/rpg/api/skills/WrappedSkill.java +++ b/API/src/main/java/cz/neumimto/rpg/api/skills/WrappedSkill.java @@ -33,7 +33,7 @@ public void setInner(ISkill inner) { @Override public WrappedSkillData constructSkillData() { - return new WrappedSkillData(getId(), inner.constructSkillData()); + return new WrappedSkillData(getId()); } @Override @@ -116,9 +116,8 @@ public static class WrappedSkillData extends SkillData { public SkillData wrapped; - public WrappedSkillData(String skill, SkillData wrapped) { + public WrappedSkillData(String skill) { super(skill); - this.wrapped = wrapped; } public SkillData getWrapped() { diff --git a/Common/src/main/java/cz/neumimto/rpg/common/configuration/SkillTreeLoaderImpl.java b/Common/src/main/java/cz/neumimto/rpg/common/configuration/SkillTreeLoaderImpl.java index 1b52853cb..53f776f07 100644 --- a/Common/src/main/java/cz/neumimto/rpg/common/configuration/SkillTreeLoaderImpl.java +++ b/Common/src/main/java/cz/neumimto/rpg/common/configuration/SkillTreeLoaderImpl.java @@ -29,6 +29,7 @@ import cz.neumimto.rpg.api.localization.LocalizationService; import cz.neumimto.rpg.api.logging.Log; import cz.neumimto.rpg.api.skills.*; +import cz.neumimto.rpg.api.skills.WrappedSkill.WrappedSkillData; import cz.neumimto.rpg.api.skills.mods.ActiveSkillPreProcessorWrapper; import cz.neumimto.rpg.api.skills.scripting.ScriptedSkillNodeDescription; import cz.neumimto.rpg.api.skills.tree.SkillTree; @@ -209,8 +210,8 @@ protected void loadSkill(SkillTree skillTree, Config c) { String skillId = c.getString("SkillId"); try { Config parent = c.getConfig("Parent"); - - SkillData info = createSkillInfo(skillTree, skillId); + String wrappedSkillId = parent.getString("SkillId"); + WrappedSkillData info = (WrappedSkillData) createSkillInfo(skillTree, wrappedSkillId); loadSkill(skillTree, parent, info); } catch (ConfigException ignored) {} @@ -481,6 +482,7 @@ private SkillData getSkillInfo(String id, SkillTree tree) { SkillData info = tree.getSkills().get(lowercased); if (info == null) { info = createSkillInfo(tree, lowercased); + tree.addSkill(info); } return info; } @@ -491,9 +493,18 @@ private SkillData createSkillInfo(SkillTree tree, String lowercased) { if (skill == null) { throw new IllegalStateException("Could not find a skill " + lowercased + " referenced in the skilltree " + tree.getId()); } - SkillData info = skill.constructSkillData(); + SkillData info = constructSkillData(skill); info.setSkill(skill); - tree.addSkill(info); + return info; + } + + private SkillData constructSkillData(ISkill skill) { + SkillData info = skill.constructSkillData(); + if (info instanceof WrappedSkillData) { + WrappedSkillData data = (WrappedSkillData) info; + SkillData wrapped = constructSkillData(data.getSkill()); + data.setWrapped(wrapped); + } return info; } } diff --git a/Common/src/main/java/cz/neumimto/rpg/common/effects/AbstractEffectService.java b/Common/src/main/java/cz/neumimto/rpg/common/effects/AbstractEffectService.java index 10d653dd2..d6acd4cc9 100644 --- a/Common/src/main/java/cz/neumimto/rpg/common/effects/AbstractEffectService.java +++ b/Common/src/main/java/cz/neumimto/rpg/common/effects/AbstractEffectService.java @@ -414,7 +414,7 @@ public void load() { try { StringBuilder finalString = new StringBuilder(); file.createNewFile(); - String s = assetService.getAssetAsString("templates/Effect.md"); + String template = assetService.getAssetAsString("templates/Effect.md"); for (Map.Entry effect : globalEffects.entrySet()) { Class aClass = effect.getValue().asEffectClass(); if (aClass != null && aClass.isAnnotationPresent(Generate.class)) { @@ -424,6 +424,7 @@ public void load() { Class modelType = EffectModelFactory.getModelType(aClass); + String s = new String(template); s = s.replaceAll("\\{\\{effect\\.name}}", name); s = s.replaceAll("\\{\\{effect\\.description}}", description); @@ -448,12 +449,12 @@ public void load() { } } - s = assetService.getAssetAsString("templates/Skill.md"); + template = assetService.getAssetAsString("templates/Skill.md"); StringBuilder skills = new StringBuilder(); for (ISkill iSkill : skillService.getAll()) { String damageType = iSkill.getDamageType(); - + String s = new String(template); s = s.replaceAll("\\{\\{skill\\.damageType}}", damageType == null ? "Deals no damage" : damageType); String id = iSkill.getId(); @@ -468,9 +469,9 @@ public void load() { s = s.replaceAll("\\{\\{skill\\.parameters}}", buffer.toString()); skills.append(s); } - s = assetService.getAssetAsString("templates/SE.md"); + template = assetService.getAssetAsString("templates/SE.md"); - Files.write(file.toPath(), s.replaceAll("\\{\\{effects}}", finalString.toString()) + Files.write(file.toPath(), template.replaceAll("\\{\\{effects}}", finalString.toString()) .replaceAll("\\{\\{skills}}", skills.toString()).getBytes(), StandardOpenOption.APPEND); } catch (IOException e) { e.printStackTrace(); diff --git a/Common/src/main/java/cz/neumimto/rpg/common/inventory/AbstractInventoryService.java b/Common/src/main/java/cz/neumimto/rpg/common/inventory/AbstractInventoryService.java index d01824fc3..34cea5569 100644 --- a/Common/src/main/java/cz/neumimto/rpg/common/inventory/AbstractInventoryService.java +++ b/Common/src/main/java/cz/neumimto/rpg/common/inventory/AbstractInventoryService.java @@ -8,6 +8,7 @@ import cz.neumimto.rpg.api.inventory.InventoryService; import cz.neumimto.rpg.api.inventory.ManagedSlot; import cz.neumimto.rpg.api.inventory.RpgInventory; +import cz.neumimto.rpg.api.items.ItemClass; import cz.neumimto.rpg.api.items.ItemService; import cz.neumimto.rpg.api.items.subtypes.ItemSubtype; import cz.neumimto.rpg.api.items.subtypes.ItemSubtypes; @@ -59,7 +60,10 @@ public void initializeManagedSlots(T activeCharacter) { } else if (armorIds.contains(value.getSlotId())) { slot = new FilteredManagedSlotImpl(value.getSlotId(), item -> activeCharacter.canWear(item.getItemType())); } else if (value.getSlotId() >= 0 && value.getSlotId() < 9) { - slot = new FilteredManagedSlotImpl(value.getSlotId(), item -> activeCharacter.canUse(item.getItemType(), EntityHand.MAIN)); + slot = new FilteredManagedSlotImpl(value.getSlotId(), item + -> activeCharacter.canUse(item.getItemType(), EntityHand.MAIN)); + // || item.getItemType().getItemClass() == ItemClass.ARMOR + // || item.getItemType().getItemClass() == ItemClass.SHIELD); } else { slot = new ManagedSlotImpl(value.getSlotId()); } diff --git a/Common/src/main/resources/localizations/core_localization_en.properties b/Common/src/main/resources/localizations/core_localization_en.properties index 5cd4f583f..ad5a5769b 100644 --- a/Common/src/main/resources/localizations/core_localization_en.properties +++ b/Common/src/main/resources/localizations/core_localization_en.properties @@ -62,6 +62,7 @@ gui.label.skill.setting-per-level=Value Per Level gui.button.label.confirm.skill-selection=Confirm gui.label.weapons.tooltip= gui.label.weapons=Weapons +gui.label.item-class=Item Class gui.label.armor=Armor label.attribute-points=Attribute Points gui.label.armor.tooltip= diff --git a/Common/src/test/resources/testconfig/SkillTree01.conf b/Common/src/test/resources/testconfig/SkillTree01.conf index b0cc66ec4..0f2cc27aa 100644 --- a/Common/src/test/resources/testconfig/SkillTree01.conf +++ b/Common/src/test/resources/testconfig/SkillTree01.conf @@ -3,6 +3,7 @@ Description: 12345 Skills: [ { SkillId: "test" + SkillName: "test1" MaxSkillLevel: 2 Combination: LLRQ MinPlayerLevel: 2 @@ -11,6 +12,7 @@ Skills: [ } { SkillId: "test2" + SkillName: "test2" MaxSkillLevel: 2 Combination: LLRQ MinPlayerLevel: 2 @@ -20,5 +22,4 @@ Skills: [ asdf ] } - ] \ No newline at end of file diff --git a/Implementations/Sponge/7/src/main/java/cz/neumimto/rpg/sponge/gui/GuiHelper.java b/Implementations/Sponge/7/src/main/java/cz/neumimto/rpg/sponge/gui/GuiHelper.java index c7524baad..de9d0906a 100644 --- a/Implementations/Sponge/7/src/main/java/cz/neumimto/rpg/sponge/gui/GuiHelper.java +++ b/Implementations/Sponge/7/src/main/java/cz/neumimto/rpg/sponge/gui/GuiHelper.java @@ -674,7 +674,7 @@ public static Inventory getCharacterAllowedWeapons(ISpongeCharacter character, i content.add(is); } DynamicInventory inv = dView.setActualContent(content.toArray(new ItemStack[content.size() == 0 ? 0 : content.size() - 1])); - String translate = Rpg.get().getLocalizationService().translate(LocalizationKeys.CHARACTER_ARMOR); + String translate = Rpg.get().getLocalizationService().translate(LocalizationKeys.CHARACTER_WEAPONS); inventory = createInventoryTemplate(translate); inv.fill(inventory); CACHED_MENUS.put(name, inventory); diff --git a/Implementations/Sponge/7/src/main/java/cz/neumimto/rpg/sponge/inventory/SpongeInventoryService.java b/Implementations/Sponge/7/src/main/java/cz/neumimto/rpg/sponge/inventory/SpongeInventoryService.java index 9b4b7c4d5..276d4942b 100644 --- a/Implementations/Sponge/7/src/main/java/cz/neumimto/rpg/sponge/inventory/SpongeInventoryService.java +++ b/Implementations/Sponge/7/src/main/java/cz/neumimto/rpg/sponge/inventory/SpongeInventoryService.java @@ -145,7 +145,6 @@ public void dumpItems(GameStartedServerEvent event) { } catch (IllegalAccessException e) { e.printStackTrace(); } - continue; } } } diff --git a/Implementations/Sponge/7/src/main/java/cz/neumimto/rpg/sponge/listeners/InventoryListener.java b/Implementations/Sponge/7/src/main/java/cz/neumimto/rpg/sponge/listeners/InventoryListener.java index 0bc3244e8..9cb4a7998 100644 --- a/Implementations/Sponge/7/src/main/java/cz/neumimto/rpg/sponge/listeners/InventoryListener.java +++ b/Implementations/Sponge/7/src/main/java/cz/neumimto/rpg/sponge/listeners/InventoryListener.java @@ -24,7 +24,11 @@ import cz.neumimto.rpg.api.inventory.InventoryService; import cz.neumimto.rpg.api.inventory.ManagedSlot; import cz.neumimto.rpg.api.inventory.RpgInventory; +import cz.neumimto.rpg.api.items.ItemClass; import cz.neumimto.rpg.api.items.RpgItemStack; +import cz.neumimto.rpg.api.items.RpgItemType; +import cz.neumimto.rpg.api.localization.LocalizationKeys; +import cz.neumimto.rpg.api.localization.LocalizationService; import cz.neumimto.rpg.common.inventory.InventoryHandler; import cz.neumimto.rpg.sponge.entities.players.ISpongeCharacter; import cz.neumimto.rpg.sponge.entities.players.SpongeCharacterService; @@ -53,6 +57,10 @@ import org.spongepowered.api.item.inventory.query.QueryOperationTypes; import org.spongepowered.api.item.inventory.transaction.SlotTransaction; import org.spongepowered.api.item.inventory.type.CarriedInventory; +import org.spongepowered.api.text.Text; +import org.spongepowered.api.text.chat.ChatType; +import org.spongepowered.api.text.chat.ChatTypes; +import org.spongepowered.api.text.format.TextColors; import org.spongepowered.api.util.Tristate; import org.spongepowered.common.event.tracking.phase.packet.drag.DragInventoryAddSlotState; @@ -79,6 +87,8 @@ public class InventoryListener { private InventoryService inventoryService; @Inject private SpongeItemService itemService; + @Inject + private LocalizationService localizationService; @Listener @IsCancelled(Tristate.FALSE) @@ -178,6 +188,8 @@ public void onHotbarInteract(HandInteractEvent event, @First Player player) { ItemStackUtils.dropItem(player, itemStack); player.setItemInHand(HandTypes.MAIN_HAND, ItemStack.empty()); character.setLastHotbarSlotInteraction(-1); + String translate = localizationService.translate(LocalizationKeys.CANNOT_USE_ITEM_CONFIGURATION_REASON); + player.sendMessage(ChatTypes.ACTION_BAR, Text.of(TextColors.RED, translate)); event.setCancelled(true); character.setRequiresDamageRecalculation(true); } @@ -195,71 +207,71 @@ public void onHotbarInteract(HandInteractEvent event, @First Player player) { @Include({ ClickInventoryEvent.Primary.class, ClickInventoryEvent.Secondary.class, - ClickInventoryEvent.Drag.class + ClickInventoryEvent.Drag.class, + ClickInventoryEvent.Shift.class }) public void onInteract(ClickInventoryEvent event, @Root Player player) { final List transactions = event.getTransactions(); - switch (transactions.size()) { - case 1: - SlotTransaction slotTransaction = transactions.get(0); - Slot slot = slotTransaction.getSlot(); - Slot transformed = slot.transform(); - Class aClass = transformed.parent().getClass(); - int slotId = transformed.getInventoryProperty(SlotIndex.class).get().getValue(); - if (!inventoryService.isManagedInventory(aClass, slotId)) { - return; - } - IActiveCharacter character = characterService.getCharacter(player); - Map, RpgInventory> managedInventory = character.getManagedInventory(); - RpgInventory rpgInventory = managedInventory.get(aClass); - ManagedSlot managedSlot = rpgInventory.getManagedSlots().get(slotId); - Optional future = itemService.getRpgItemStack(slotTransaction.getFinal().createStack()); - Optional original = itemService.getRpgItemStack(slotTransaction.getOriginal().createStack()); - - if (future.isPresent()) { - RpgItemStack rpgItemStackF = future.get(); - //change - if (original.isPresent()) { - - RpgItemStack rpgItemStackO = original.get(); - - boolean k = inventoryHandler.handleCharacterEquipActionPre(character, managedSlot, rpgItemStackF) - && inventoryHandler.handleCharacterUnEquipActionPre(character, managedSlot, rpgItemStackO); - if (k) { - inventoryHandler.handleCharacterUnEquipActionPost(character, managedSlot); - inventoryHandler.handleCharacterEquipActionPost(character, managedSlot, rpgItemStackF); - character.setRequiresDamageRecalculation(true); - } else { - event.setCancelled(true); - } + for (SlotTransaction slotTransaction : transactions) { + Slot slot = slotTransaction.getSlot(); + Slot transformed = slot.transform(); + Class aClass = transformed.parent().getClass(); + int slotId = transformed.getInventoryProperty(SlotIndex.class).get().getValue(); + if (!inventoryService.isManagedInventory(aClass, slotId)) { + return; + } + IActiveCharacter character = characterService.getCharacter(player); + Map, RpgInventory> managedInventory = character.getManagedInventory(); + RpgInventory rpgInventory = managedInventory.get(aClass); + ManagedSlot managedSlot = rpgInventory.getManagedSlots().get(slotId); + Optional future = itemService.getRpgItemStack(slotTransaction.getFinal().createStack()); + Optional original = itemService.getRpgItemStack(slotTransaction.getOriginal().createStack()); + + if (future.isPresent()) { + RpgItemStack rpgItemStackF = future.get(); + //change + if (original.isPresent()) { + + RpgItemStack rpgItemStackO = original.get(); + + boolean k = inventoryHandler.handleCharacterEquipActionPre(character, managedSlot, rpgItemStackF) + && inventoryHandler.handleCharacterUnEquipActionPre(character, managedSlot, rpgItemStackO); + if (k) { + inventoryHandler.handleCharacterUnEquipActionPost(character, managedSlot); + inventoryHandler.handleCharacterEquipActionPost(character, managedSlot, rpgItemStackF); + character.setRequiresDamageRecalculation(true); } else { - //equip - if (inventoryHandler.handleCharacterEquipActionPre(character, managedSlot, rpgItemStackF)) { - inventoryHandler.handleCharacterEquipActionPost(character, managedSlot, rpgItemStackF); - character.setRequiresDamageRecalculation(true); - } else { - event.setCancelled(true); - } + event.setCancelled(true); + return; } - } else { - //unequip slot - if (original.isPresent()) { - RpgItemStack rpgItemStack = original.get(); - if (inventoryHandler.handleCharacterUnEquipActionPre(character, managedSlot, rpgItemStack)) { - inventoryHandler.handleCharacterUnEquipActionPost(character, managedSlot); - } + //equip + //todo do we want to apply custom enchantments from armor from hotbar? I think not => make this configurable + ItemClass itemClass = rpgItemStackF.getItemType().getItemClass(); + if (slotId >=0 && slotId <=8 && (itemClass == ItemClass.ARMOR || itemClass == ItemClass.SHIELD)) { + continue; + } + + if (inventoryHandler.handleCharacterEquipActionPre(character, managedSlot, rpgItemStackF)) { + inventoryHandler.handleCharacterEquipActionPost(character, managedSlot, rpgItemStackF); + character.setRequiresDamageRecalculation(true); + } else { + event.setCancelled(true); + return; + } + + } + + } else { + //unequip slot + if (original.isPresent()) { + RpgItemStack rpgItemStack = original.get(); + if (inventoryHandler.handleCharacterUnEquipActionPre(character, managedSlot, rpgItemStack)) { + inventoryHandler.handleCharacterUnEquipActionPost(character, managedSlot); } } - break; - case 2: - //??? - break; - default: - //???//??? - return; + } } - } @Listener diff --git a/Implementations/Sponge/7/src/main/resources/localizations/core_localization_en.properties b/Implementations/Sponge/7/src/main/resources/localizations/core_localization_en.properties index 8e9ae22f3..92d0912e5 100644 --- a/Implementations/Sponge/7/src/main/resources/localizations/core_localization_en.properties +++ b/Implementations/Sponge/7/src/main/resources/localizations/core_localization_en.properties @@ -60,6 +60,7 @@ gui.label.skill.setting-start-at=Base Value gui.label.skill.setting-per-level=Value Per Level gui.button.label.confirm.skill-selection=Confirm gui.label.weapons.tooltip= +gui.label.item-class=Item Class gui.label.weapons=Weapons gui.label.armor=Armor gui.label.armor.tooltip=