v0.9.0b: lots of logic implementation for multiple talent tiers

This commit is contained in:
Evan Debenham 2020-10-14 01:40:31 -04:00
parent f59073b4b0
commit 833b182d75
5 changed files with 45 additions and 25 deletions

View File

@ -310,21 +310,22 @@ public class Hero extends Char {
Talent.onTalentUpgraded(this, talent); Talent.onTalentUpgraded(this, talent);
} }
//TODO account for tiers public int talentPointsSpent(int tier){
public int talentPointsSpent(){
int total = 0; int total = 0;
for (LinkedHashMap<Talent, Integer> tier : talents){ for (int i : talents.get(tier-1).values()){
for (int i : tier.values()){ total += i;
total += i;
}
} }
return total; return total;
} }
//TODO account for tiers public int talentPointsAvailable(int tier){
public int talentPointsAvailable(){ if (lvl < Talent.tierLevelThresholds[tier]){
//hero currently only gains points up to level 6 return 0;
return Math.min(lvl, 6) - 1 - talentPointsSpent(); } else if (lvl >= Talent.tierLevelThresholds[tier+1]){
return Talent.tierLevelThresholds[tier+1] - Talent.tierLevelThresholds[tier] - talentPointsSpent(tier);
} else {
return 1 + lvl - Talent.tierLevelThresholds[tier] - talentPointsSpent(tier);
}
} }
public String className() { public String className() {

View File

@ -71,6 +71,9 @@ public enum Talent {
int icon; int icon;
// tiers 1/2/3/4 start at levels 2/7/13/21
public static int[] tierLevelThresholds = new int[]{0, 2, 7, 13, 21, 31};
Talent(int icon ){ Talent(int icon ){
this.icon = icon; this.icon = icon;
} }

View File

@ -469,7 +469,14 @@ public class GameScene extends PixelScene {
GLog.h(Messages.get(this, "return"), Dungeon.depth); GLog.h(Messages.get(this, "return"), Dungeon.depth);
} }
if (Dungeon.hero.talentPointsAvailable() > 0){ boolean unspentTalents = false;
for (int i = 1; i <= Dungeon.hero.talents.size(); i++){
if (Dungeon.hero.talentPointsAvailable(i) > 0){
unspentTalents = true;
break;
}
}
if (unspentTalents){
GLog.newLine(); GLog.newLine();
GLog.w( Messages.get(Dungeon.hero, "unspent") ); GLog.w( Messages.get(Dungeon.hero, "unspent") );
StatusPane.talentBlink = 10f; StatusPane.talentBlink = 10f;

View File

@ -46,6 +46,7 @@ public class TalentButton extends Button {
private SmartTexture icons; private SmartTexture icons;
private TextureFilm film; private TextureFilm film;
int tier;
Talent talent; Talent talent;
int pointsInTalent; int pointsInTalent;
boolean upgradeEnabled; boolean upgradeEnabled;
@ -55,8 +56,9 @@ public class TalentButton extends Button {
ColorBlock fill; ColorBlock fill;
public TalentButton(Talent talent, int points, boolean upgradeEnabled){ public TalentButton(int tier, Talent talent, int points, boolean upgradeEnabled){
super(); super();
this.tier = tier;
this.talent = talent; this.talent = talent;
this.pointsInTalent = points; this.pointsInTalent = points;
this.upgradeEnabled = upgradeEnabled; this.upgradeEnabled = upgradeEnabled;
@ -107,7 +109,7 @@ public class TalentButton extends Button {
if (upgradeEnabled if (upgradeEnabled
&& Dungeon.hero != null && Dungeon.hero != null
&& Dungeon.hero.talentPointsAvailable() > 0 && Dungeon.hero.talentPointsAvailable(tier) > 0
&& Dungeon.hero.pointsInTalent(talent) < talent.maxPoints()){ && Dungeon.hero.pointsInTalent(talent) < talent.maxPoints()){
ShatteredPixelDungeon.scene().addToFront(new WndInfoTalent(talent, pointsInTalent, new Callback() { ShatteredPixelDungeon.scene().addToFront(new WndInfoTalent(talent, pointsInTalent, new Callback() {
@Override @Override
@ -140,7 +142,7 @@ public class TalentButton extends Button {
} }
public void upgradeTalent(){ public void upgradeTalent(){
if (Dungeon.hero.talentPointsAvailable() > 0 && parent != null) { if (Dungeon.hero.talentPointsAvailable(tier) > 0 && parent != null) {
Dungeon.hero.upgradeTalent(talent); Dungeon.hero.upgradeTalent(talent);
float oldWidth = fill.width(); float oldWidth = fill.width();
pointsInTalent++; pointsInTalent++;

View File

@ -49,14 +49,16 @@ public class TalentsPane extends ScrollPane {
public TalentsPane( boolean canUpgrade, ArrayList<LinkedHashMap<Talent, Integer>> talents ) { public TalentsPane( boolean canUpgrade, ArrayList<LinkedHashMap<Talent, Integer>> talents ) {
super(new Component()); super(new Component());
//TODO more code here for future tiers as they are added int tiersAvailable = 1;
int tiersAvailable;
if (!canUpgrade){ if (!canUpgrade){
tiersAvailable = 4; tiersAvailable = 4;
} else if (Dungeon.hero.lvl >= 7){
tiersAvailable = 2;
} else { } else {
tiersAvailable = 1; while (Dungeon.hero.lvl+1 >= Talent.tierLevelThresholds[tiersAvailable+1]){
tiersAvailable++;
}
//TODO lighten limit as future tiers are added
tiersAvailable = Math.min(tiersAvailable, 2);
} }
for (int i = 0; i < Math.min(tiersAvailable, talents.size()); i++){ for (int i = 0; i < Math.min(tiersAvailable, talents.size()); i++){
@ -83,8 +85,9 @@ public class TalentsPane extends ScrollPane {
protected void layout() { protected void layout() {
super.layout(); super.layout();
float top = 2; float top = 0;
for (int i = 0; i < panes.size(); i++){ for (int i = 0; i < panes.size(); i++){
top += 2;
panes.get(i).setRect(x, top, width, 0); panes.get(i).setRect(x, top, width, 0);
top = panes.get(i).bottom(); top = panes.get(i).bottom();
@ -100,11 +103,13 @@ public class TalentsPane extends ScrollPane {
blocker.y = top; blocker.y = top;
blocker.size(width, height - top); blocker.size(width, height - top);
blockText.setPos((width - blockText.width())/2f, blocker.y + 10); blockText.setPos((width - blockText.width())/2f, blocker.y + (height - blocker.y)/2 - 3);
} }
public static class TalentTierPane extends Component { public static class TalentTierPane extends Component {
private int tier;
RenderedTextBlock title; RenderedTextBlock title;
ArrayList<TalentButton> buttons; ArrayList<TalentButton> buttons;
@ -113,6 +118,8 @@ public class TalentsPane extends ScrollPane {
public TalentTierPane(LinkedHashMap<Talent, Integer> talents, int tier, boolean canUpgrade){ public TalentTierPane(LinkedHashMap<Talent, Integer> talents, int tier, boolean canUpgrade){
super(); super();
this.tier = tier;
title = PixelScene.renderTextBlock(Messages.titleCase(Messages.get(TalentsPane.class, "tier", tier)), 9); title = PixelScene.renderTextBlock(Messages.titleCase(Messages.get(TalentsPane.class, "tier", tier)), 9);
title.hardlight(Window.TITLE_COLOR); title.hardlight(Window.TITLE_COLOR);
add(title); add(title);
@ -121,7 +128,7 @@ public class TalentsPane extends ScrollPane {
buttons = new ArrayList<>(); buttons = new ArrayList<>();
for (Talent talent : talents.keySet()){ for (Talent talent : talents.keySet()){
TalentButton btn = new TalentButton(talent, talents.get(talent), canUpgrade){ TalentButton btn = new TalentButton(tier, talent, talents.get(talent), canUpgrade){
@Override @Override
public void upgradeTalent() { public void upgradeTalent() {
super.upgradeTalent(); super.upgradeTalent();
@ -145,9 +152,9 @@ public class TalentsPane extends ScrollPane {
stars.clear(); stars.clear();
} }
int totStars = 5; int totStars = Talent.tierLevelThresholds[tier+1] - Talent.tierLevelThresholds[tier];
int openStars = Dungeon.hero.talentPointsAvailable(); int openStars = Dungeon.hero.talentPointsAvailable(tier);
int usedStars = Dungeon.hero.talentPointsSpent(); int usedStars = Dungeon.hero.talentPointsSpent(tier);
for (int i = 0; i < totStars; i++){ for (int i = 0; i < totStars; i++){
Image im = new Speck().image(Speck.STAR); Image im = new Speck().image(Speck.STAR);
stars.add(im); stars.add(im);