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);
}
//TODO account for tiers
public int talentPointsSpent(){
public int talentPointsSpent(int tier){
int total = 0;
for (LinkedHashMap<Talent, Integer> tier : talents){
for (int i : tier.values()){
total += i;
}
for (int i : talents.get(tier-1).values()){
total += i;
}
return total;
}
//TODO account for tiers
public int talentPointsAvailable(){
//hero currently only gains points up to level 6
return Math.min(lvl, 6) - 1 - talentPointsSpent();
public int talentPointsAvailable(int tier){
if (lvl < Talent.tierLevelThresholds[tier]){
return 0;
} 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() {

View File

@ -71,6 +71,9 @@ public enum Talent {
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 ){
this.icon = icon;
}

View File

@ -469,7 +469,14 @@ public class GameScene extends PixelScene {
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.w( Messages.get(Dungeon.hero, "unspent") );
StatusPane.talentBlink = 10f;

View File

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

View File

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