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

View File

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

View File

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

View File

@ -4,24 +4,20 @@ public enum SStat{
unitsDestroyed, unitsDestroyed,
attacksWon, attacksWon,
pvpsWon, pvpsWon,
gamesWon,
timesLaunched, timesLaunched,
maxWavesSurvived,
zoneMechsUsed, zoneMechsUsed,
enemiesDestroyed,
blocksDestroyed, blocksDestroyed,
playerDestroyed,
routersBuilt,
blocksBuilt,
itemsLaunched, itemsLaunched,
reactorsOverheated, reactorsOverheated,
firesExtinguished,
maxUnitActive, maxUnitActive,
unitsBuilt, unitsBuilt,
bossesDefeated, bossesDefeated,
maxPlayersServer, maxPlayersServer,
mapsMade, mapsMade,
mapsPublished; mapsPublished,
maxWavesSurvived,
blocksBuilt,
;
public int get(){ public int get(){
return SVars.stats.stats.getStatI(name(), 0); 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 class SStats implements SteamUserStatsCallback{
public final SteamUserStats stats = new SteamUserStats(this); public final SteamUserStats stats = new SteamUserStats(this);
//todo store stats periodically
private boolean updated = false; private boolean updated = false;
private ObjectSet<String> mechs = new ObjectSet<>(); private ObjectSet<String> mechs = new ObjectSet<>();
private int statSavePeriod = 4; //in minutes
public SStats(){ public SStats(){
stats.requestCurrentStats(); stats.requestCurrentStats();
@ -32,6 +32,7 @@ public class SStats implements SteamUserStatsCallback{
Core.app.addListener(new ApplicationListener(){ Core.app.addListener(new ApplicationListener(){
Interval i = new Interval(); Interval i = new Interval();
@Override @Override
public void update(){ public void update(){
if(i.get(60f / 4f)){ 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 -> { Events.on(UnitDestroyEvent.class, e -> {
if(ncustom()){ if(ncustom()){
if(e.unit.getTeam() != Vars.player.getTeam()){ if(e.unit.getTeam() != Vars.player.getTeam()){
SStat.enemiesDestroyed.add(); SStat.unitsDestroyed.add();
if(e.unit instanceof BaseUnit && ((BaseUnit)e.unit).isBoss()){ if(e.unit instanceof BaseUnit && ((BaseUnit)e.unit).isBoss()){
SStat.bossesDefeated.add(); SStat.bossesDefeated.add();
@ -94,7 +101,7 @@ public class SStats implements SteamUserStatsCallback{
Events.on(CommandIssueEvent.class, e -> { Events.on(CommandIssueEvent.class, e -> {
if(campaign() && e.command == UnitCommand.attack){ if(campaign() && e.command == UnitCommand.attack){
issueAttackcommand.achieved(); issueAttackCommand.achieved();
} }
}); });
@ -139,8 +146,14 @@ public class SStats implements SteamUserStatsCallback{
Events.on(UnlockEvent.class, e -> { Events.on(UnlockEvent.class, e -> {
if(e.content == Items.thorium) obtainThorium.achieved(); if(e.content == Items.thorium) obtainThorium.achieved();
if(e.content == Items.titanium) obtainTitanium.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.exclusionDeath, dieExclusion::achieved);
Events.on(Trigger.drown, drown::achieved); Events.on(Trigger.drown, drown::achieved);
@ -207,7 +220,6 @@ public class SStats implements SteamUserStatsCallback{
Events.on(ResearchEvent.class, e -> { Events.on(ResearchEvent.class, e -> {
if(e.content == Blocks.router) researchRouter.achieved(); if(e.content == Blocks.router) researchRouter.achieved();
if(e.content == Blocks.launchPad) researchLaunchPad.achieved();
if(!TechTree.all.contains(t -> t.block.locked())){ if(!TechTree.all.contains(t -> t.block.locked())){
researchAll.achieved(); researchAll.achieved();
@ -255,16 +267,22 @@ public class SStats implements SteamUserStatsCallback{
@Override @Override
public void onUserStatsReceived(long gameID, SteamID steamID, SteamResult result){ public void onUserStatsReceived(long gameID, SteamID steamID, SteamResult result){
if(result == SteamResult.OK){ registerEvents();
registerEvents();
}else{ if(result != SteamResult.OK){
Log.err("Failed to recieve steam stats: {0}", result); Log.err("Failed to recieve steam stats: {0}", result);
}else{
Log.err("Recieved steam stats.");
} }
} }
@Override @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 @Override

View File

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