Explorar o código

Allow the application of Skill Ranks.
Allow the learning of spells.

Sam Jaffe %!s(int64=8) %!d(string=hai) anos
pai
achega
5fa27346d2

+ 1 - 1
resources/classes/Cleric.json

@@ -53,7 +53,7 @@
     ],
     "spellList":[
       ["Create Water"],
-      ["Cure Light Wounds"],
+      ["Cure Light Wounds", "Magic Weapon"],
       ["Magic Vestment"]
     ]
   }

+ 1 - 1
resources/classes/Wizard.json

@@ -30,7 +30,7 @@
     ],
     "spellList":[
       ["Create Water"],
-      ["Cure Light Wounds"]
+      ["Magic Weapon"]
     ]
   }
 }

+ 26 - 0
resources/spells/default.json

@@ -123,5 +123,31 @@
     "savingThrow":"Will negates",
     "allowsSpellResistance":true,
     "description":"You imbue a suit of armor or a shield with an enhancement bonus of +1 per four caster levels (maximum +5 at 20th level). An outfit of regular clothing counts as armor that grants no AC bonus for the purpose of this spell."
+  },
+  {
+    "name":"Magic Weapon",
+    "classToLevel":{
+      "Cleric":1,
+      "Paladin":1,
+      "Sorcerer":1,
+      "Wizard":1,
+      "Domain::War":1
+    },
+    "school":"Transmutation",
+    "keywords":["Harmless", "Object"],
+    "components":["V","S","DF"],
+    "castingTime":"Standard",
+    "range":"Touch",
+    "target":"Weapon touched",
+    "duration":{
+      "unit":"minute",
+      "duration":1,
+      "per":1,
+      "step":1
+    },
+    "effect":{"format":"+1 Enhancement Bonus"},
+    "savingThrow":"Will negates",
+    "allowsSpellResistance":true,
+    "description":"Magic weapon gives a weapon a +1 enhancement bonus on attack and damage rolls. (An enhancement bonus does not stack with a masterwork weapon’s +1 bonus on attack rolls.)\nYou can’t cast this spell on a natural weapon, such as an unarmed strike (instead, see magic fang). A monk’s unarmed strike is considered a weapon, and thus it can be enhanced by this spell."
   }
 ]

+ 3 - 0
src/main/lombok/org/leumasjaffe/charsheet/model/magic/DDSpellbook.java

@@ -36,5 +36,8 @@ public abstract class DDSpellbook extends Observable {
 	
 	public abstract void castSpell( int level, final DDSpell spell );
 	
+	public void learnSpells(int level, Collection<DDSpell> known) {
+		throw new UnsupportedOperationException("This class does not have a list of known spells to edit");
+	}
 	public abstract void prepareSpells(int level, Collection<DDSpell> collection);
 }

+ 14 - 1
src/main/lombok/org/leumasjaffe/charsheet/model/magic/impl/Researched.java

@@ -1,5 +1,6 @@
 package org.leumasjaffe.charsheet.model.magic.impl;
 
+import java.util.ArrayList;
 import java.util.Collection;
 import java.util.Collections;
 import java.util.List;
@@ -80,13 +81,25 @@ public class Researched extends Prepared {
 	public List<DDSpell> getSpellsPreparedPreviouslyForLevel(int level) {
 		return Collections.unmodifiableList(get(level).spellsPreparedPreviously);
 	}
+	
+	@Override
+	public void learnSpells(int level, Collection<DDSpell> known) {
+		final Level lInfo = spellInfo.getOrDefault(level, new Level(new ArrayList<>(), 
+				new ArrayList<>(), new ArrayList<>(), 0));
+		lInfo.spellsKnown.clear();
+		lInfo.spellsKnown.addAll(known);
+		spellInfo.putIfAbsent(level, lInfo);
+	}
 
 	@Override
 	public void prepareSpells(int level, Collection<DDSpell> spells) {
+		this.spellInfo.putIfAbsent(level, new Level(new ArrayList<>(), 
+				new ArrayList<>(), new ArrayList<>(), 0));
 		final Level lInfo = get(level);
-		if (!lInfo.spellsKnown.containsAll(spells)) {
+		if (!spellsKnownAtLevel(level).containsAll(spells)) {
 			throw new IllegalArgumentException("Attempted to prepare spells that you don't know");
 		}
+		lInfo.spellsPerDay = spells.size();
 		lInfo.spellsPrepared.clear();
 		lInfo.spellsPreparedPreviously.clear();
 		lInfo.spellsPrepared.addAll(spells);

+ 11 - 2
src/main/lombok/org/leumasjaffe/charsheet/model/magic/impl/Spontaneous.java

@@ -1,5 +1,6 @@
 package org.leumasjaffe.charsheet.model.magic.impl;
 
+import java.util.ArrayList;
 import java.util.Collection;
 import java.util.Collections;
 import java.util.List;
@@ -25,7 +26,7 @@ public class Spontaneous extends DDSpellbook {
 	}
 	
 	@NonNull Map<Integer, Spontaneous.Level> spellInfo;
-	
+		
 	@Override
 	public boolean learnsSpells() {
 		return true;
@@ -67,9 +68,17 @@ public class Spontaneous extends DDSpellbook {
 		return spellInfo.getOrDefault(level, new Level(Collections.emptyList(), 0, 0));
 	}
 
+	@Override
+	public void learnSpells(int level, Collection<DDSpell> known) {
+		final Level lInfo = spellInfo.getOrDefault(level, new Level(new ArrayList<>(), 0, 0));
+		lInfo.spellsKnown.clear();
+		lInfo.spellsKnown.addAll(known);
+		spellInfo.putIfAbsent(level, lInfo);
+	}
+
 	@Override
 	public void prepareSpells(int level, Collection<DDSpell> spells) {
 		final Level lInfo = get(level);
-		lInfo.spellsPerDayRemaining = lInfo.spellsPerDay;
+		lInfo.spellsPerDayRemaining = lInfo.spellsPerDay = spells.size();
 	}
 }

+ 26 - 5
src/main/lombok/org/leumasjaffe/charsheet/view/level/UpdateClassWithLevelPanel.java

@@ -144,10 +144,10 @@ class UpdateClassWithLevelPanel extends JPanel {
 		if (sb.preparesSpells()) {
 			learnAndPrepareListener = new ObservableListener<>(this, (c, v) -> {
 				if (v.get(LEARN_SPELL_INDEX)) {
-					c.createPrepareLearnedSpellPanel(learnSpells.get());
+					if (!prepSpells.isPresent()) c.createPrepareLearnedSpellPanel(learnSpells.get());
 				} else {
-					c.tabbedPane.remove(prepSpells.get());
-					c.prepSpells = null;
+					prepSpells.ifPresent(c.tabbedPane::remove);
+					c.prepSpells = Optional.empty();
 				}
 			});
 			learnAndPrepareListener.setObserved(readyCount);
@@ -185,11 +185,32 @@ class UpdateClassWithLevelPanel extends JPanel {
 	}
 
 	
+	private void commitSpellbook(DDSpellbook book) {
+		learnSpells.ifPresent(pan -> {
+			final List<SelectSpellsPanel> selections = pan.getPanels();
+			for (int i = 0; i < selections.size(); ++i) {
+				if (selections.get(i) == null) continue;
+				List<DDSpell> known = new ArrayList<>(book.spellsKnownAtLevel(i));
+				known.addAll(selections.get(i).getPrepared());
+				book.learnSpells(i, known);
+			}
+		});
+		prepSpells.ifPresent(pan -> {
+			final List<SelectSpellsPanel> selections = pan.getPanels();
+			for (int i = 0; i < selections.size(); ++i) {
+				if (selections.get(i) == null) continue;
+				List<DDSpell> known = new ArrayList<>(book.spellsPreparedAtLevel(i));
+				known.addAll(selections.get(i).getPrepared());
+				book.prepareSpells(i, known);
+			}
+		});
+	}
+	
 	public void commitAllChanges() {
 		final String className = levelUpInfo.ddClass.getName();
 		skills.commitAllChanges();
-		learnSpells.ifPresent(pan -> {});
-		prepSpells.ifPresent(pan -> {});
+		Optional<DDSpellbook> maybeBook = levelUpInfo.ddClass.getSpellBook();
+		maybeBook.ifPresent(this::commitSpellbook);
 		final Set<DDCharacterClass> classes = levelUpInfo.ddCharacter.getClasses();
 		if (classes.stream().map(DDCharacterClass::getName).anyMatch(className::equals)) {
 			// Update class to new data

+ 1 - 1
src/main/lombok/org/leumasjaffe/charsheet/view/skills/SkillLevelUpLine.java

@@ -238,7 +238,7 @@ class SkillLevelUpLine extends JPanel {
 		else { return Optional.of(AbilityHelper.get(chara, skill)); }
 	}
 
-	void applyChange() {
+	public void applyChange() {
 		skill.spendPoints(current.value(), !isClassSkill);
 		ObserverDispatch.notifySubscribers(skill.getRanks(), this);
 	}

+ 3 - 2
src/main/lombok/org/leumasjaffe/charsheet/view/skills/SkillLevelUpPanel.java

@@ -29,6 +29,7 @@ import lombok.experimental.FieldDefaults;
 public abstract class SkillLevelUpPanel extends JPanel {
 	ObservableListener<JTextField, IntValue> purchaseListener;
 	@Getter(AccessLevel.PROTECTED) JPanel panel;
+	List<SkillLevelUpLine> lines;
 
 	public SkillLevelUpPanel(final DDCharacter chara, final DDCharacterClass cclass) {
 		final IntValue pointsAvaliable = new IntValue(Math.max(1, cclass.getSkillPoints() + 
@@ -85,7 +86,7 @@ public abstract class SkillLevelUpPanel extends JPanel {
 		scrollPane.setViewportView(skillPanel);
 		skillPanel.setLayout(new VerticalLayout());
 				
-		final List<SkillLevelUpLine> lines = new ArrayList<>();
+		lines = new ArrayList<>();
 		final DDSkills skills = chara.getSkills();
 		skills.getSkills().stream().forEach( skill -> {
 			SkillLevelUpLine line = new SkillLevelUpLine(chara, cclass, skill, pointsAvaliable);
@@ -103,7 +104,7 @@ public abstract class SkillLevelUpPanel extends JPanel {
 	protected abstract void setIsReady(boolean b);
 	
 	public void commitAllChanges() {
-		
+		lines.forEach(SkillLevelUpLine::applyChange);
 	}
 	
 	@Override