Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Percentage modifier stat for status effects #10306

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions core/assets/bundles/bundle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -1151,6 +1151,7 @@ unit.minutes = mins
unit.persecond = /sec
unit.perminute = /min
unit.timesspeed = x speed
unit.multiplier = x
unit.percent = %
unit.shieldhealth = shield health
unit.items = items
Expand Down
10 changes: 5 additions & 5 deletions core/src/mindustry/type/StatusEffect.java
Original file line number Diff line number Diff line change
Expand Up @@ -90,11 +90,11 @@ public boolean isHidden(){

@Override
public void setStats(){
if(damageMultiplier != 1) stats.addPercent(Stat.damageMultiplier, damageMultiplier);
if(healthMultiplier != 1) stats.addPercent(Stat.healthMultiplier, healthMultiplier);
if(speedMultiplier != 1) stats.addPercent(Stat.speedMultiplier, speedMultiplier);
if(reloadMultiplier != 1) stats.addPercent(Stat.reloadMultiplier, reloadMultiplier);
if(buildSpeedMultiplier != 1) stats.addPercent(Stat.buildSpeedMultiplier, buildSpeedMultiplier);
if(damageMultiplier != 1) stats.addMultModifier(Stat.damageMultiplier, damageMultiplier);
if(healthMultiplier != 1) stats.addMultModifier(Stat.healthMultiplier, healthMultiplier);
if(speedMultiplier != 1) stats.addMultModifier(Stat.speedMultiplier, speedMultiplier);
if(reloadMultiplier != 1) stats.addMultModifier(Stat.reloadMultiplier, reloadMultiplier);
if(buildSpeedMultiplier != 1) stats.addMultModifier(Stat.buildSpeedMultiplier, buildSpeedMultiplier);
if(damage > 0) stats.add(Stat.damage, damage * 60f, StatUnit.perSecond);
if(damage < 0) stats.add(Stat.healing, -damage * 60f, StatUnit.perSecond);

Expand Down
1 change: 1 addition & 0 deletions core/src/mindustry/world/meta/StatUnit.java
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ public class StatUnit{
perMinute = new StatUnit("perMinute", false),
perShot = new StatUnit("perShot", false),
timesSpeed = new StatUnit("timesSpeed", false),
multiplier = new StatUnit("multiplier", false),
percent = new StatUnit("percent", false),
shieldHealth = new StatUnit("shieldHealth"),
none = new StatUnit("none"),
Expand Down
46 changes: 46 additions & 0 deletions core/src/mindustry/world/meta/StatValues.java
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,48 @@ public static StatValue number(float value, StatUnit unit){
return number(value, unit, false);
}

public static StatValue multiplierModifier(float value, StatUnit unit, boolean merge){
return table -> {
String l1 = (unit.icon == null ? "" : unit.icon + " ") + multStat(value), l2 = (unit.space ? " " : "") + unit.localized();

if(merge){
table.add(l1 + l2).left();
}else{
table.add(l1).left();
table.add(l2).left();
}
};
}

public static StatValue multiplierModifier(float value, StatUnit unit){
return multiplierModifier(value, unit, true);
}

public static StatValue multiplierModifier(float value){
return multiplierModifier(value, StatUnit.multiplier);
}

public static StatValue percentModifier(float value, StatUnit unit, boolean merge){
return table -> {
String l1 = (unit.icon == null ? "" : unit.icon + " ") + ammoStat((value - 1) * 100), l2 = (unit.space ? " " : "") + unit.localized();

if(merge){
table.add(l1 + l2).left();
}else{
table.add(l1).left();
table.add(l2).left();
}
};
}

public static StatValue percentModifier(float value, StatUnit unit){
return percentModifier(value, unit, true);
}

public static StatValue percentModifier(float value){
return percentModifier(value, StatUnit.percent);
}

public static StatValue liquid(Liquid liquid, float amount, boolean perSecond){
return table -> table.add(displayLiquid(liquid, amount, perSecond));
}
Expand Down Expand Up @@ -683,6 +725,10 @@ private static String ammoStat(float val){
return (val > 0 ? "[stat]+" : "[negstat]") + Strings.autoFixed(val, 1);
}

private static String multStat(float val){
return (val >= 1 ? "[stat]" : "[negstat]") + Strings.autoFixed(val, 2);
}

private static TextureRegion icon(UnlockableContent t){
return t.uiIcon;
}
Expand Down
10 changes: 10 additions & 0 deletions core/src/mindustry/world/meta/Stats.java
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,16 @@ public void addPercent(Stat stat, float value){
add(stat, StatValues.number((int)(value * 100), StatUnit.percent));
}

/** Adds a multiplicative modifier stat value. Value is assumed to be in the 0-1 range. */
public void addMultModifier(Stat stat, float value){
add(stat, StatValues.multiplierModifier(value));
}

/** Adds an percent modifier stat value. Value is assumed to be in the 0-1 range. */
public void addPercentModifier(Stat stat, float value){
add(stat, StatValues.percentModifier(value));
}

/** Adds a single y/n boolean value. */
public void add(Stat stat, boolean value){
add(stat, StatValues.bool(value));
Expand Down
Loading