diff --git a/Plugin/src/main/java/cz/neumimto/rpg/commands/CommandSkilltree.java b/Plugin/src/main/java/cz/neumimto/rpg/commands/CommandSkilltree.java index 04e668a18..63a1abcc0 100644 --- a/Plugin/src/main/java/cz/neumimto/rpg/commands/CommandSkilltree.java +++ b/Plugin/src/main/java/cz/neumimto/rpg/commands/CommandSkilltree.java @@ -21,12 +21,14 @@ import cz.neumimto.core.ioc.Inject; import cz.neumimto.rpg.GroupService; import cz.neumimto.rpg.ResourceLoader; +import cz.neumimto.rpg.TextHelper; import cz.neumimto.rpg.configuration.Localization; import cz.neumimto.rpg.gui.Gui; import cz.neumimto.rpg.players.CharacterService; import cz.neumimto.rpg.players.IActiveCharacter; +import cz.neumimto.rpg.players.SkillTreeViewModel; import cz.neumimto.rpg.players.groups.ConfigClass; -import org.spongepowered.api.command.CommandException; +import cz.neumimto.rpg.skills.SkillTree; import org.spongepowered.api.command.CommandResult; import org.spongepowered.api.command.CommandSource; import org.spongepowered.api.entity.living.player.Player; @@ -48,20 +50,35 @@ public CommandSkilltree() { } @Override - public CommandResult process(CommandSource commandSource, String s) throws CommandException { + public CommandResult process(CommandSource commandSource, String s) { Player p =(Player) commandSource; IActiveCharacter character = characterService.getCharacter(p); + if (character.isStub()) { + character.getPlayer().sendMessage(TextHelper.parse(Localization.CHARACTER_IS_REQUIRED)); + return CommandResult.empty(); + } ConfigClass configClass; if ("".equals(s.trim()) ) { configClass = character.getPrimaryClass().getConfigClass(); } else { configClass = groupService.getNClass(s); } - if (configClass == null) { + if (configClass == null || configClass == ConfigClass.Default) { Gui.sendMessage(character, Localization.NON_EXISTING_GROUP); return CommandResult.builder().build(); } - Gui.openSkillTreeMenu(character, configClass.getSkillTree()); + SkillTree skillTree = configClass.getSkillTree(); + for (SkillTreeViewModel treeViewModel : character.getSkillTreeViewLocation().values()) { + treeViewModel.setCurrent(false); + } + if (character.getSkillTreeViewLocation().get(skillTree.getId()) == null){ + SkillTreeViewModel skillTreeViewModel = new SkillTreeViewModel(); + character.getSkillTreeViewLocation().put(skillTree.getId(), skillTreeViewModel); + skillTreeViewModel.setSkillTree(skillTree); + } else { + character.getSkillTreeViewLocation().get(skillTree.getId()).setCurrent(true); + } + Gui.openSkillTreeMenu(character); return CommandResult.success(); } } diff --git a/Plugin/src/main/java/cz/neumimto/rpg/commands/InfoCommand.java b/Plugin/src/main/java/cz/neumimto/rpg/commands/InfoCommand.java index f1cc24bac..1148c065a 100644 --- a/Plugin/src/main/java/cz/neumimto/rpg/commands/InfoCommand.java +++ b/Plugin/src/main/java/cz/neumimto/rpg/commands/InfoCommand.java @@ -32,11 +32,13 @@ import cz.neumimto.rpg.players.CharacterBase; import cz.neumimto.rpg.players.CharacterService; import cz.neumimto.rpg.players.IActiveCharacter; +import cz.neumimto.rpg.players.SkillTreeViewModel; +import cz.neumimto.rpg.players.groups.ConfigClass; import cz.neumimto.rpg.players.groups.PlayerGroup; import cz.neumimto.rpg.skills.SkillService; +import cz.neumimto.rpg.skills.SkillTree; import org.slf4j.Logger; import org.spongepowered.api.Game; -import org.spongepowered.api.command.CommandException; import org.spongepowered.api.command.CommandResult; import org.spongepowered.api.command.CommandSource; import org.spongepowered.api.entity.living.player.Player; @@ -83,7 +85,7 @@ public InfoCommand() { } @Override - public CommandResult process(CommandSource commandSource, String s) throws CommandException { + public CommandResult process(CommandSource commandSource, String s) { final String[] args = s.split(" "); if (args.length == 0) { commandSource.sendMessage(getUsage(commandSource)); @@ -168,7 +170,29 @@ public CommandResult process(CommandSource commandSource, String s) throws Comma } } else if (args[0].equalsIgnoreCase("skilltree")) { IActiveCharacter character = characterService.getCharacter(((Player) commandSource).getUniqueId()); - Gui.openSkillTreeMenu(character, character.getPrimaryClass().getConfigClass().getSkillTree()); + SkillTree skillTree = character.getPrimaryClass().getConfigClass().getSkillTree(); + if (args.length == 2) { + for (ConfigClass configClass : groupService.getClasses()) { + if (configClass.getName().equalsIgnoreCase(args[1])) { + skillTree = configClass.getSkillTree(); + } + } + } + if (skillTree == SkillTree.Default) { + commandSource.sendMessage(Text.of(TextColors.RED, "Unknown class, or the class has no skilltree defined")); + return CommandResult.empty(); + } + for (SkillTreeViewModel treeViewModel : character.getSkillTreeViewLocation().values()) { + treeViewModel.setCurrent(false); + } + if (character.getSkillTreeViewLocation().get(skillTree.getId()) == null){ + SkillTreeViewModel skillTreeViewModel = new SkillTreeViewModel(); + character.getSkillTreeViewLocation().put(skillTree.getId(), skillTreeViewModel); + skillTreeViewModel.setSkillTree(skillTree); + } else { + character.getSkillTreeViewLocation().get(skillTree.getId()).setCurrent(true); + } + Gui.openSkillTreeMenu(character); } else { commandSource.sendMessage(getUsage(commandSource)); } diff --git a/Plugin/src/main/java/cz/neumimto/rpg/gui/Gui.java b/Plugin/src/main/java/cz/neumimto/rpg/gui/Gui.java index d15b9149b..f16111de3 100644 --- a/Plugin/src/main/java/cz/neumimto/rpg/gui/Gui.java +++ b/Plugin/src/main/java/cz/neumimto/rpg/gui/Gui.java @@ -76,8 +76,8 @@ public static void sendCooldownMessage(IActiveCharacter player, String skillname getMessageTypeOf(player).sendCooldownMessage(player, skillname, cooldown); } - public static void openSkillTreeMenu(IActiveCharacter player, SkillTree skillTree) { - getMessageTypeOf(player).openSkillTreeMenu(player, skillTree); + public static void openSkillTreeMenu(IActiveCharacter player) { + getMessageTypeOf(player).openSkillTreeMenu(player); } public static void sendEffectStatus(IActiveCharacter player, EffectStatusType type, IEffect effect) { diff --git a/Plugin/src/main/java/cz/neumimto/rpg/gui/IPlayerMessage.java b/Plugin/src/main/java/cz/neumimto/rpg/gui/IPlayerMessage.java index f2dfe629f..ca0077d3b 100644 --- a/Plugin/src/main/java/cz/neumimto/rpg/gui/IPlayerMessage.java +++ b/Plugin/src/main/java/cz/neumimto/rpg/gui/IPlayerMessage.java @@ -97,7 +97,7 @@ public interface IPlayerMessage { void sendCannotUseItemNotification(IActiveCharacter character, ItemStack is, CannotUseItemReson reason); - void openSkillTreeMenu(IActiveCharacter player, SkillTree skillTree); + void openSkillTreeMenu(IActiveCharacter player); void moveSkillTreeMenu(IActiveCharacter character); diff --git a/Plugin/src/main/java/cz/neumimto/rpg/gui/VanillaMessaging.java b/Plugin/src/main/java/cz/neumimto/rpg/gui/VanillaMessaging.java index e29bfa29a..74ab1f11c 100644 --- a/Plugin/src/main/java/cz/neumimto/rpg/gui/VanillaMessaging.java +++ b/Plugin/src/main/java/cz/neumimto/rpg/gui/VanillaMessaging.java @@ -18,31 +18,17 @@ package cz.neumimto.rpg.gui; -import static cz.neumimto.rpg.gui.GuiHelper.back; -import static cz.neumimto.rpg.gui.GuiHelper.createPlayerGroupView; -import static cz.neumimto.rpg.gui.GuiHelper.getItemLore; - import cz.neumimto.core.ioc.Inject; import cz.neumimto.core.ioc.IoC; import cz.neumimto.core.ioc.PostProcess; import cz.neumimto.core.ioc.Singleton; -import cz.neumimto.rpg.Arg; -import cz.neumimto.rpg.GroupService; -import cz.neumimto.rpg.NtRpgPlugin; -import cz.neumimto.rpg.Pair; -import cz.neumimto.rpg.ResourceLoader; -import cz.neumimto.rpg.TextHelper; +import cz.neumimto.rpg.*; import cz.neumimto.rpg.commands.InfoCommand; import cz.neumimto.rpg.configuration.CommandPermissions; import cz.neumimto.rpg.configuration.Localization; import cz.neumimto.rpg.configuration.PluginConfig; import cz.neumimto.rpg.damage.DamageService; -import cz.neumimto.rpg.effects.EffectService; -import cz.neumimto.rpg.effects.EffectSourceType; -import cz.neumimto.rpg.effects.EffectStatusType; -import cz.neumimto.rpg.effects.IEffect; -import cz.neumimto.rpg.effects.IEffectContainer; -import cz.neumimto.rpg.effects.InternalEffectSourceProvider; +import cz.neumimto.rpg.effects.*; import cz.neumimto.rpg.effects.common.def.BossBarExpNotifier; import cz.neumimto.rpg.effects.common.def.ManaBarNotifier; import cz.neumimto.rpg.inventory.CannotUseItemReson; @@ -59,11 +45,7 @@ import cz.neumimto.rpg.inventory.runewords.RuneWord; import cz.neumimto.rpg.persistance.DirectAccessDao; import cz.neumimto.rpg.persistance.model.CharacterClass; -import cz.neumimto.rpg.players.CharacterBase; -import cz.neumimto.rpg.players.CharacterService; -import cz.neumimto.rpg.players.ExtendedNClass; -import cz.neumimto.rpg.players.IActiveCharacter; -import cz.neumimto.rpg.players.SkillTreeViewModel; +import cz.neumimto.rpg.players.*; import cz.neumimto.rpg.players.groups.ConfigClass; import cz.neumimto.rpg.players.groups.PlayerGroup; import cz.neumimto.rpg.players.groups.Race; @@ -108,18 +90,11 @@ import org.spongepowered.api.text.format.TextStyles; import org.spongepowered.api.util.Color; -import java.util.ArrayList; -import java.util.Collection; -import java.util.Collections; -import java.util.HashMap; -import java.util.Iterator; -import java.util.List; -import java.util.Map; -import java.util.Optional; -import java.util.Set; -import java.util.TreeSet; +import java.util.*; import java.util.concurrent.TimeUnit; +import static cz.neumimto.rpg.gui.GuiHelper.*; + /** * Created by NeumimTo on 6.8.2015. */ @@ -840,7 +815,8 @@ public void sendCannotUseItemNotification(IActiveCharacter character, ItemStack } @Override - public void openSkillTreeMenu(IActiveCharacter player, SkillTree skillTree) { + public void openSkillTreeMenu(IActiveCharacter player) { + SkillTree skillTree = player.getLastTimeInvokedSkillTreeView().getSkillTree(); if (player.getSkillTreeViewLocation().get(skillTree.getId()) == null){ SkillTreeViewModel skillTreeViewModel = new SkillTreeViewModel(); for (SkillTreeViewModel treeViewModel : player.getSkillTreeViewLocation().values()) { @@ -850,7 +826,7 @@ public void openSkillTreeMenu(IActiveCharacter player, SkillTree skillTree) { skillTreeViewModel.setSkillTree(skillTree); } Inventory skillTreeInventoryViewTemplate = GuiHelper.createSkillTreeInventoryViewTemplate(player, skillTree); - createSkillTreeView(player, skillTreeInventoryViewTemplate, skillTree); + createSkillTreeView(player, skillTreeInventoryViewTemplate); player.getPlayer().openInventory(skillTreeInventoryViewTemplate); } @@ -859,7 +835,7 @@ public void openSkillTreeMenu(IActiveCharacter player, SkillTree skillTree) { public void moveSkillTreeMenu(IActiveCharacter character) { Optional openInventory = character.getPlayer().getOpenInventory(); if (openInventory.isPresent()) { - createSkillTreeView(character, openInventory.get().query(GridInventory.class).first(), character.getPrimaryClass().getConfigClass().getSkillTree()); + createSkillTreeView(character, openInventory.get().query(GridInventory.class).first()); } } @@ -876,9 +852,10 @@ public void displayInitialProperties(PlayerGroup g, Player p) { } - private void createSkillTreeView(IActiveCharacter character, Inventory skillTreeInventoryViewTemplate, SkillTree skillTree) { + private void createSkillTreeView(IActiveCharacter character, Inventory skillTreeInventoryViewTemplate) { SkillTreeViewModel skillTreeViewModel = character.getLastTimeInvokedSkillTreeView(); + SkillTree skillTree = skillTreeViewModel.getSkillTree(); short[][] skillTreeMap = skillTreeViewModel.getSkillTree().getSkillTreeMap(); int y = skillTree.getCenter().value + skillTreeViewModel.getLocation().value; //y int x = skillTree.getCenter().key + skillTreeViewModel.getLocation().key; //x