Skip to content

Commit

Permalink
Fixed skilltree views
Browse files Browse the repository at this point in the history
  • Loading branch information
NeumimTo committed May 7, 2018
1 parent 3b71ce5 commit 64ab51f
Show file tree
Hide file tree
Showing 5 changed files with 63 additions and 45 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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();
}
}
30 changes: 27 additions & 3 deletions Plugin/src/main/java/cz/neumimto/rpg/commands/InfoCommand.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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));
Expand Down Expand Up @@ -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));
}
Expand Down
4 changes: 2 additions & 2 deletions Plugin/src/main/java/cz/neumimto/rpg/gui/Gui.java
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down
47 changes: 12 additions & 35 deletions Plugin/src/main/java/cz/neumimto/rpg/gui/VanillaMessaging.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand Down Expand Up @@ -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.
*/
Expand Down Expand Up @@ -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()) {
Expand All @@ -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);

}
Expand All @@ -859,7 +835,7 @@ public void openSkillTreeMenu(IActiveCharacter player, SkillTree skillTree) {
public void moveSkillTreeMenu(IActiveCharacter character) {
Optional<Container> 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());
}
}

Expand All @@ -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
Expand Down

0 comments on commit 64ab51f

Please sign in to comment.