From caec96615f754500211a7c65eefc1f86717d8d4e Mon Sep 17 00:00:00 2001 From: Anuken Date: Tue, 3 Nov 2020 22:19:50 -0500 Subject: [PATCH] More achievement cleanup --- core/src/mindustry/game/EventType.java | 2 - core/src/mindustry/maps/SectorDamage.java | 4 +- .../mindustry/ui/dialogs/PlanetDialog.java | 2 + .../world/blocks/units/CommandCenter.java | 3 + .../mindustry/desktop/steam/SAchievement.java | 11 ++- .../src/mindustry/desktop/steam/SStat.java | 8 +- .../src/mindustry/desktop/steam/SStats.java | 83 ++++++++++++++----- 7 files changed, 84 insertions(+), 29 deletions(-) diff --git a/core/src/mindustry/game/EventType.java b/core/src/mindustry/game/EventType.java index 5d67d689ff..8f40d0abc9 100644 --- a/core/src/mindustry/game/EventType.java +++ b/core/src/mindustry/game/EventType.java @@ -17,14 +17,12 @@ public class EventType{ phaseDeflectHit, impactPower, thoriumReactorOverheat, - itemLaunch, fireExtinguish, newGame, tutorialComplete, flameAmmo, turretCool, enablePixelation, - drown, exclusionDeath, suicideBomb, openWiki, diff --git a/core/src/mindustry/maps/SectorDamage.java b/core/src/mindustry/maps/SectorDamage.java index 79ae02be5c..2ca49967da 100644 --- a/core/src/mindustry/maps/SectorDamage.java +++ b/core/src/mindustry/maps/SectorDamage.java @@ -233,7 +233,7 @@ public class SectorDamage{ //first, calculate the total health of blocks in the path //radius around the path that gets counted - int radius = 9; + int radius = 8; IntSet counted = new IntSet(); for(Tile t : sparse2){ @@ -337,7 +337,7 @@ public class SectorDamage{ //enemy units like to aim for a lot of non-essential things, so increase resulting health slightly info.sumHealth = sumHealth * 1.2f; //players tend to have longer range units/turrets, so assume DPS is higher - info.sumDps = sumDps * 1.5f; + info.sumDps = sumDps * 1.2f; info.sumRps = sumRps; info.wavesSurvived = getWavesSurvived(info); diff --git a/core/src/mindustry/ui/dialogs/PlanetDialog.java b/core/src/mindustry/ui/dialogs/PlanetDialog.java index 96752008a1..151d777648 100644 --- a/core/src/mindustry/ui/dialogs/PlanetDialog.java +++ b/core/src/mindustry/ui/dialogs/PlanetDialog.java @@ -374,6 +374,8 @@ public class PlanetDialog extends BaseDialog implements PlanetInterfaceRenderer{ stable.add("[accent]Difficulty: " + (int)(sector.baseCoverage * 10)).row(); } + //TODO put most info in submenu + if(sector.isAttacked()){ //TODO localize when finalized //these mechanics are likely to change and as such are not added to the bundle diff --git a/core/src/mindustry/world/blocks/units/CommandCenter.java b/core/src/mindustry/world/blocks/units/CommandCenter.java index 659db5e1d3..a564f4dc07 100644 --- a/core/src/mindustry/world/blocks/units/CommandCenter.java +++ b/core/src/mindustry/world/blocks/units/CommandCenter.java @@ -1,5 +1,6 @@ package mindustry.world.blocks.units; +import arc.*; import arc.graphics.*; import arc.graphics.g2d.*; import arc.scene.style.*; @@ -12,6 +13,7 @@ import mindustry.*; import mindustry.content.*; import mindustry.entities.*; import mindustry.entities.units.*; +import mindustry.game.EventType.*; import mindustry.gen.*; import mindustry.ui.*; import mindustry.world.*; @@ -33,6 +35,7 @@ public class CommandCenter extends Block{ config(UnitCommand.class, (CommandBuild build, UnitCommand command) -> { build.team.data().command = command; effect.at(build); + Events.fire(new CommandIssueEvent(build, command)); }); } diff --git a/desktop/src/mindustry/desktop/steam/SAchievement.java b/desktop/src/mindustry/desktop/steam/SAchievement.java index 8d20447f58..a3ec5d162d 100644 --- a/desktop/src/mindustry/desktop/steam/SAchievement.java +++ b/desktop/src/mindustry/desktop/steam/SAchievement.java @@ -1,10 +1,12 @@ package mindustry.desktop.steam; public enum SAchievement{ - completeTutorial, + //completeTutorial, kill1kEnemies(SStat.unitsDestroyed, 1000), kill100kEnemies(SStat.unitsDestroyed, 1000 * 100), + //TODO achievements for reaching 10k/min production or something launch10kItems(SStat.itemsLaunched, 1000 * 10), + //TODO reduce amounts required here launch1milItems(SStat.itemsLaunched, 1000 * 1000), win10Attack(SStat.attacksWon, 10), win10PvP(SStat.pvpsWon, 10), @@ -43,8 +45,7 @@ public enum SAchievement{ issueAttackCommand, active100Units(SStat.maxUnitActive, 100), build1000Units, - //TODO - buildAllUnits, + buildAllUnits(SStat.unitsBuilt, 30), //TODO activeAllT5, dieExclusion, @@ -55,9 +56,13 @@ public enum SAchievement{ launchItemPad, chainRouters, //TODO + circleConveyor, + //TODO becomeRouter, //TODO save20Schematics, + //TODO + destroyEnemyBase, survive10WavesNoBlocks, useFlameAmmo, coolTurret, diff --git a/desktop/src/mindustry/desktop/steam/SStat.java b/desktop/src/mindustry/desktop/steam/SStat.java index b9438350f0..48e0b25edf 100644 --- a/desktop/src/mindustry/desktop/steam/SStat.java +++ b/desktop/src/mindustry/desktop/steam/SStat.java @@ -29,8 +29,8 @@ public enum SStat{ } } - public void add(int amount){ - SVars.stats.stats.setStatI(name(), get() + amount); + public void set(int amount){ + SVars.stats.stats.setStatI(name(), amount); SVars.stats.onUpdate(); for(SAchievement a : SAchievement.all){ @@ -38,6 +38,10 @@ public enum SStat{ } } + public void add(int amount){ + set(get() + 1); + } + public void add(){ add(1); } diff --git a/desktop/src/mindustry/desktop/steam/SStats.java b/desktop/src/mindustry/desktop/steam/SStats.java index 910c38cad2..3a79708973 100644 --- a/desktop/src/mindustry/desktop/steam/SStats.java +++ b/desktop/src/mindustry/desktop/steam/SStats.java @@ -1,6 +1,7 @@ package mindustry.desktop.steam; import arc.*; +import arc.struct.*; import arc.util.*; import com.codedisaster.steamworks.*; import mindustry.*; @@ -8,6 +9,8 @@ import mindustry.content.*; import mindustry.entities.units.*; import mindustry.game.EventType.*; import mindustry.gen.*; +import mindustry.world.*; +import mindustry.world.blocks.distribution.*; import static mindustry.Vars.*; import static mindustry.desktop.steam.SAchievement.*; @@ -20,6 +23,8 @@ public class SStats implements SteamUserStatsCallback{ //private ObjectSet mechs = new ObjectSet<>(); private int statSavePeriod = 4; //in minutes + private ObjectSet blocksBuilt = new ObjectSet<>(), unitsBuilt = new ObjectSet<>(); + public SStats(){ stats.requestCurrentStats(); @@ -51,7 +56,7 @@ public class SStats implements SteamUserStatsCallback{ void checkUpdate(){ if(campaign()){ - SStat.maxUnitActive.max(Groups.unit.count(t -> t.team() == player.team())); + SStat.maxUnitActive.max(Groups.unit.count(t -> t.team == player.team())); //TODO //if(Groups.unit.count(u -> u.type() == UnitTypes.phantom && u.team() == player.team()) >= 10){ @@ -73,6 +78,11 @@ public class SStats implements SteamUserStatsCallback{ } private void registerEvents(){ + Events.on(ClientLoadEvent.class, e -> { + unitsBuilt = Core.settings.getJson("units-built" , ObjectSet.class, String.class, ObjectSet::new); + blocksBuilt = Core.settings.getJson("blocks-built" , ObjectSet.class, String.class, ObjectSet::new); + }); + Events.on(UnitDestroyEvent.class, e -> { if(ncustom()){ if(e.unit.team != Vars.player.team()){ @@ -105,33 +115,47 @@ public class SStats implements SteamUserStatsCallback{ chainRouters.complete(); } - //TODO implement if(e.tile.block() == Blocks.groundFactory){ buildGroundFactory.complete(); } - //TODO fix, cleaner impl - if(e.tile.block() == Blocks.meltdown || e.tile.block() == Blocks.spectre || e.tile.block() == Blocks.foreshadow){ - if(e.tile.block() == Blocks.meltdown){ - Core.settings.put("meltdownp", true); + if(blocksBuilt.add(e.tile.block().name)){ + if(blocksBuilt.contains("meltdown") && blocksBuilt.contains("spectre") && blocksBuilt.contains("foreshadow")){ + buildMeltdownSpectreForeshadow.complete(); } - if(e.tile.block() == Blocks.spectre){ - Core.settings.put("spectrep", true); - } + save(); + } - if(e.tile.block() == Blocks.foreshadow){ - Core.settings.put("spectrep", true); - } + if(e.tile.block() instanceof Conveyor){ + check: { + Tile current = e.tile; + for(int i = 0; i < 4; i++){ + if(current.build == null) break check; + Tile next = current.nearby(current.build.rotation); + if(next != null && next.block() instanceof Conveyor){ + current = next; + }else{ + break check; + } + } - if(Core.settings.getBool("meltdownp", false) && Core.settings.getBool("spectrep", false)){ - //TODO - //buildMeltdownSpectre.complete(); + if(current == e.tile){ + circleConveyor.complete(); + } } } } }); + Events.on(UnitCreateEvent.class, e -> { + if(campaign()){ + if(unitsBuilt.add(e.unit.type.name)){ + SStat.unitsBuilt.set(content.units().count(u -> unitsBuilt.contains(u.name) && !u.isHidden())); + } + } + }); + Events.on(BlockDestroyEvent.class, e -> { if(campaign() && e.tile.team() != player.team()){ SStat.blocksDestroyed.add(); @@ -151,7 +175,11 @@ public class SStats implements SteamUserStatsCallback{ Events.run(Trigger.exclusionDeath, dieExclusion::complete); - Events.run(Trigger.drown, drown::complete); + Events.on(UnitDrownEvent.class, e -> { + if(campaign() && e.unit.isPlayer()){ + drown.complete(); + } + }); trigger(Trigger.impactPower, powerupImpactReactor); @@ -173,7 +201,11 @@ public class SStats implements SteamUserStatsCallback{ trigger(Trigger.phaseDeflectHit, killEnemyPhaseWall); - trigger(Trigger.itemLaunch, launchItemPad); + Events.on(LaunchItemEvent.class, e -> { + if(campaign()){ + launchItemPad.complete(); + } + }); Events.on(UnitCreateEvent.class, e -> { if(campaign() && e.unit.team() == player.team()){ @@ -214,13 +246,17 @@ public class SStats implements SteamUserStatsCallback{ } }); - Events.on(ResearchEvent.class, e -> { - if(e.content == Blocks.router) researchRouter.complete(); + Runnable checkUnlocks = () -> { + if(Blocks.router.unlocked()) researchRouter.complete(); if(!TechTree.all.contains(t -> t.content.locked())){ researchAll.complete(); } - }); + }; + + //check unlocked stuff on load as well + Events.on(ResearchEvent.class, e -> checkUnlocks.run()); + Events.on(ClientLoadEvent.class, e -> checkUnlocks.run()); Events.on(WinEvent.class, e -> { if(state.hasSector()){ @@ -238,6 +274,8 @@ public class SStats implements SteamUserStatsCallback{ } }); + + //TODO dead achievement /* Events.on(MechChangeEvent.class, e -> { @@ -249,6 +287,11 @@ public class SStats implements SteamUserStatsCallback{ });*/ } + private void save(){ + Core.settings.putJson("units-built" , String.class, unitsBuilt); + Core.settings.putJson("blocks-built" , String.class, blocksBuilt); + } + private void trigger(Trigger trigger, SAchievement ach){ Events.run(trigger, () -> { if(campaign()){