Achievement work, cleanup

This commit is contained in:
Anuken 2019-09-14 19:01:27 -04:00
parent 6c07c5006a
commit d59f5ddc59
7 changed files with 46 additions and 37 deletions

View File

@ -25,7 +25,8 @@ public class EventType{
enablePixelation,
drown,
exclusionDeath,
suicideBomb
suicideBomb,
openWiki
}
public static class WinEvent{}

View File

@ -6,6 +6,7 @@ import io.anuke.arc.graphics.*;
import io.anuke.arc.scene.ui.*;
import io.anuke.arc.scene.ui.layout.*;
import io.anuke.arc.util.*;
import io.anuke.mindustry.game.EventType.*;
import io.anuke.mindustry.gen.*;
import io.anuke.mindustry.graphics.*;
import io.anuke.mindustry.ui.*;
@ -64,6 +65,8 @@ public class AboutDialog extends FloatingDialog{
}).padLeft(8);
table.addImageButton(Icon.link, () -> {
if(link.name.equals("wiki")) Events.fire(Trigger.openWiki);
if(!Core.net.openURI(link.link)){
ui.showErrorMessage("$linkfail");
Core.app.setClipboardText(link.link);

View File

@ -79,7 +79,7 @@ public class ImpactReactor extends PowerGenerator{
entity.warmup = 1f;
}
if(!prevOut && (getPowerProduction(tile) <= consumes.getPower().requestedPower(entity))){
if(!prevOut && (getPowerProduction(tile) > consumes.getPower().requestedPower(entity))){
Events.fire(Trigger.impactPower);
}

View File

@ -2,29 +2,29 @@ package io.anuke.mindustry.desktop.steam;
public enum SAchievement{
completeTutorial,
kill1kEnemies(SStat.enemiesDestroyed, 1000),
kill100kEnemies(SStat.enemiesDestroyed, 1000 * 100),
kill1kEnemies(SStat.unitsDestroyed, 1000),
kill100kEnemies(SStat.unitsDestroyed, 1000 * 100),
launch10kItems(SStat.itemsLaunched, 1000 * 10),
launch1milItems(SStat.itemsLaunched, 1000 * 1000),
beat10Attack(SStat.attacksWon, 10),
win10PvPMatches(SStat.pvpsWon, 10),
win10Attack(SStat.attacksWon, 10),
win10PvP(SStat.pvpsWon, 10),
defeatAttack5Waves,
launch30Times(SStat.timesLaunched, 30),
survive100Waves(SStat.maxWavesSurvived, 100),
survive500Waves(SStat.maxWavesSurvived, 500),
researchAll,
useAllMechs,
useAllMechs(SStat.zoneMechsUsed, 6),
shockWetEnemy,
killEnemyPhaseWall,
researchLaunchPad,
researchRouter,
place10kBlocks(SStat.blocksBuilt, 10 * 1000),
destroy1kBlocks(SStat.blocksDestroyed, 1000),
overheatReactorCampaign(SStat.reactorsOverheated, 1),
overheatReactor(SStat.reactorsOverheated, 1),
make10maps(SStat.mapsMade, 10),
downloadMapWorkshop,
publishMap(SStat.mapsPublished, 1),
defeatBoss(SStat.bossesDefeated, 1),
unlockAllZones,
configAllZones,
drop10kitems,
powerupImpactReactor,
@ -32,7 +32,7 @@ public enum SAchievement{
obtainTitanium,
suicideBomb,
buildDaggerFactory,
issueAttackcommand,
issueAttackCommand,
active100Units(SStat.maxUnitActive, 100),
active10Phantoms,
active50Crawlers,
@ -42,7 +42,7 @@ public enum SAchievement{
dieExclusion,
drown,
fillCoreAllCampaign,
hostServer10,
hostServer10(SStat.maxPlayersServer, 10),
buildMeltdownSpectre,
launchItemPad,
skipLaunching2Death,
@ -51,6 +51,7 @@ public enum SAchievement{
useFlameAmmo,
coolTurret,
enablePixelation,
openWiki,
;
private final SStat stat;

View File

@ -4,24 +4,20 @@ public enum SStat{
unitsDestroyed,
attacksWon,
pvpsWon,
gamesWon,
timesLaunched,
maxWavesSurvived,
zoneMechsUsed,
enemiesDestroyed,
blocksDestroyed,
playerDestroyed,
routersBuilt,
blocksBuilt,
itemsLaunched,
reactorsOverheated,
firesExtinguished,
maxUnitActive,
unitsBuilt,
bossesDefeated,
maxPlayersServer,
mapsMade,
mapsPublished;
mapsPublished,
maxWavesSurvived,
blocksBuilt,
;
public int get(){
return SVars.stats.stats.getStatI(name(), 0);

View File

@ -20,9 +20,9 @@ import static io.anuke.mindustry.desktop.steam.SAchievement.*;
public class SStats implements SteamUserStatsCallback{
public final SteamUserStats stats = new SteamUserStats(this);
//todo store stats periodically
private boolean updated = false;
private ObjectSet<String> mechs = new ObjectSet<>();
private int statSavePeriod = 4; //in minutes
public SStats(){
stats.requestCurrentStats();
@ -32,6 +32,7 @@ public class SStats implements SteamUserStatsCallback{
Core.app.addListener(new ApplicationListener(){
Interval i = new Interval();
@Override
public void update(){
if(i.get(60f / 4f)){
@ -39,6 +40,12 @@ public class SStats implements SteamUserStatsCallback{
}
}
});
Timer.schedule(() -> {
if(updated){
stats.storeStats();
}
}, statSavePeriod * 60, statSavePeriod * 60);
});
}
@ -71,7 +78,7 @@ public class SStats implements SteamUserStatsCallback{
Events.on(UnitDestroyEvent.class, e -> {
if(ncustom()){
if(e.unit.getTeam() != Vars.player.getTeam()){
SStat.enemiesDestroyed.add();
SStat.unitsDestroyed.add();
if(e.unit instanceof BaseUnit && ((BaseUnit)e.unit).isBoss()){
SStat.bossesDefeated.add();
@ -94,7 +101,7 @@ public class SStats implements SteamUserStatsCallback{
Events.on(CommandIssueEvent.class, e -> {
if(campaign() && e.command == UnitCommand.attack){
issueAttackcommand.achieved();
issueAttackCommand.achieved();
}
});
@ -139,8 +146,14 @@ public class SStats implements SteamUserStatsCallback{
Events.on(UnlockEvent.class, e -> {
if(e.content == Items.thorium) obtainThorium.achieved();
if(e.content == Items.titanium) obtainTitanium.achieved();
if(!content.zones().contains(Zone::locked)){
unlockAllZones.achieved();
}
});
Events.on(Trigger.openWiki, openWiki::achieved);
Events.on(Trigger.exclusionDeath, dieExclusion::achieved);
Events.on(Trigger.drown, drown::achieved);
@ -207,7 +220,6 @@ public class SStats implements SteamUserStatsCallback{
Events.on(ResearchEvent.class, e -> {
if(e.content == Blocks.router) researchRouter.achieved();
if(e.content == Blocks.launchPad) researchLaunchPad.achieved();
if(!TechTree.all.contains(t -> t.block.locked())){
researchAll.achieved();
@ -255,16 +267,22 @@ public class SStats implements SteamUserStatsCallback{
@Override
public void onUserStatsReceived(long gameID, SteamID steamID, SteamResult result){
if(result == SteamResult.OK){
registerEvents();
}else{
registerEvents();
if(result != SteamResult.OK){
Log.err("Failed to recieve steam stats: {0}", result);
}else{
Log.err("Recieved steam stats.");
}
}
@Override
public void onUserStatsStored(long l, SteamResult steamResult){
public void onUserStatsStored(long gameID, SteamResult result){
Log.info("Stored stats: {0}", result);
if(result == SteamResult.OK){
updated = true;
}
}
@Override

View File

@ -44,14 +44,4 @@ public class Upscaler{
Log.info("Done upscaling icons in &lm{0}&lgs.", Time.elapsed()/1000f);
Core.app.exit();
}
static class Res{
final int size;
final String suffix;
public Res(int size, String suffix){
this.size = size;
this.suffix = suffix;
}
}
}