From 482156d21a5bdb214dcf79e15d86ebb4d4e9a47a Mon Sep 17 00:00:00 2001 From: Piotr Picheta Date: Wed, 29 Jul 2020 11:27:16 +0200 Subject: [PATCH] #36 Prepared more generic approach for handling "not-so-stable" ids. --- .../bot/gateway/impl/ProtoInterfaceImpl.java | 6 ++-- .../ocraft/s2client/protocol/Versions.java | 2 +- .../s2client/protocol/data/Abilities.java | 6 ++-- .../ocraft/s2client/protocol/data/Buffs.java | 11 ++++---- .../ocraft/s2client/protocol/data/Units.java | 28 +++++++++++++++++-- 5 files changed, 40 insertions(+), 13 deletions(-) diff --git a/ocraft-s2client-bot/src/main/java/com/github/ocraft/s2client/bot/gateway/impl/ProtoInterfaceImpl.java b/ocraft-s2client-bot/src/main/java/com/github/ocraft/s2client/bot/gateway/impl/ProtoInterfaceImpl.java index e6611150..cc809135 100644 --- a/ocraft-s2client-bot/src/main/java/com/github/ocraft/s2client/bot/gateway/impl/ProtoInterfaceImpl.java +++ b/ocraft-s2client-bot/src/main/java/com/github/ocraft/s2client/bot/gateway/impl/ProtoInterfaceImpl.java @@ -12,10 +12,10 @@ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell * copies of the Software, and to permit persons to whom the Software is * furnished to do so, subject to the following conditions: - * + * * The above copyright notice and this permission notice shall be included in * all copies or substantial portions of the Software. - * + * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE @@ -31,6 +31,7 @@ import com.github.ocraft.s2client.bot.ClientError; import com.github.ocraft.s2client.bot.gateway.ProtoInterface; import com.github.ocraft.s2client.protocol.BuilderSyntax; +import com.github.ocraft.s2client.protocol.data.Units; import com.github.ocraft.s2client.protocol.game.GameStatus; import com.github.ocraft.s2client.protocol.request.Request; import com.github.ocraft.s2client.protocol.request.Requests; @@ -109,6 +110,7 @@ private boolean connect( .ifPresentOrElse(ping -> { this.dataVersion = ping.getDataVersion(); this.baseBuild = ping.getBaseBuild(); + Units.remapForBuild(this.baseBuild); }, () -> { throw new IllegalStateException("ping failed"); }); diff --git a/ocraft-s2client-protocol/src/main/java/com/github/ocraft/s2client/protocol/Versions.java b/ocraft-s2client-protocol/src/main/java/com/github/ocraft/s2client/protocol/Versions.java index cf9f54c6..1d25fa53 100644 --- a/ocraft-s2client-protocol/src/main/java/com/github/ocraft/s2client/protocol/Versions.java +++ b/ocraft-s2client-protocol/src/main/java/com/github/ocraft/s2client/protocol/Versions.java @@ -37,7 +37,7 @@ public final class Versions { - public static final String API_VERSION = "4.12.0.80188"; + public static final String API_VERSION = "5.0.0.81009"; private static final Map gameVersions = new HashMap<>(); diff --git a/ocraft-s2client-protocol/src/main/java/com/github/ocraft/s2client/protocol/data/Abilities.java b/ocraft-s2client-protocol/src/main/java/com/github/ocraft/s2client/protocol/data/Abilities.java index d58429f5..80a44701 100644 --- a/ocraft-s2client-protocol/src/main/java/com/github/ocraft/s2client/protocol/data/Abilities.java +++ b/ocraft-s2client-protocol/src/main/java/com/github/ocraft/s2client/protocol/data/Abilities.java @@ -559,7 +559,9 @@ public enum Abilities implements Ability { BATTLECRUISER_STOP_CHEER(3785, NONE), BATTLECRUISER_STOP_DANCE(3786, NONE), VIPER_PARASITIC_BOMB_RELAY_PARASITIC_BOMB(3789, NONE), - PARASITIC_BOMB_RELAY_DODGE_PARASITIC_BOMB(3791, NONE); + PARASITIC_BOMB_RELAY_DODGE_PARASITIC_BOMB(3791, NONE), + BATTERY_OVERCHARGE(4107, NONE), + AMORPHOUS_ARMOR_CLOUD(4109, NONE); public static final class Other implements Ability { @@ -610,7 +612,7 @@ public String toString() { EnumSet.allOf(Abilities.class).forEach(ability -> abilityIdMap.put(ability.getAbilityId(), ability)); } - private final int abilityId; + private int abilityId; private final EnumSet targets; Abilities(int abilityId, Target... targets) { diff --git a/ocraft-s2client-protocol/src/main/java/com/github/ocraft/s2client/protocol/data/Buffs.java b/ocraft-s2client-protocol/src/main/java/com/github/ocraft/s2client/protocol/data/Buffs.java index 26201dc8..b34eebb6 100644 --- a/ocraft-s2client-protocol/src/main/java/com/github/ocraft/s2client/protocol/data/Buffs.java +++ b/ocraft-s2client-protocol/src/main/java/com/github/ocraft/s2client/protocol/data/Buffs.java @@ -12,10 +12,10 @@ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell * copies of the Software, and to permit persons to whom the Software is * furnished to do so, subject to the following conditions: - * + * * The above copyright notice and this permission notice shall be included in * all copies or substantial portions of the Software. - * + * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE @@ -323,8 +323,9 @@ public enum Buffs implements Buff { NEXUS_SHIELD_OVERCHARGE(286), PARASITIC_BOMB_DELAY_TIMED_LIFE(287), TRANSFUSION(288), - INHIBITOR_ZONE_TEMPORAL_FIELD(289); - + INHIBITOR_ZONE_TEMPORAL_FIELD(289), + BATTERY_OVERCHARGE(297), + AMORPHOUS_ARMOR_CLOUD(295); public static final class Other implements Buff { @@ -354,7 +355,7 @@ public String toString() { } } - private static Map buffIdMap = new HashMap<>(); + private static final Map buffIdMap = new HashMap<>(); static { EnumSet.allOf(Buffs.class).forEach(buff -> buffIdMap.put(buff.getBuffId(), buff)); diff --git a/ocraft-s2client-protocol/src/main/java/com/github/ocraft/s2client/protocol/data/Units.java b/ocraft-s2client-protocol/src/main/java/com/github/ocraft/s2client/protocol/data/Units.java index c930015d..c54dbbca 100644 --- a/ocraft-s2client-protocol/src/main/java/com/github/ocraft/s2client/protocol/data/Units.java +++ b/ocraft-s2client-protocol/src/main/java/com/github/ocraft/s2client/protocol/data/Units.java @@ -86,7 +86,6 @@ public enum Units implements UnitType { TERRAN_REAPER(49, SMART, MOVE, PATROL, HOLD_POSITION, EFFECT_KD8CHARGE, STOP, ATTACK), TERRAN_REFINERY(20, CANCEL, HALT), TERRAN_REFINERY_RICH(1943, CANCEL, HALT), - TERRAN_REFINERY_RICH_410(1960, CANCEL, HALT), TERRAN_SCV(45, SMART, MOVE, PATROL, HOLD_POSITION, BUILD_COMMAND_CENTER, BUILD_SUPPLY_DEPOT, BUILD_REFINERY, BUILD_BARRACKS, BUILD_ENGINEERING_BAY, BUILD_MISSILE_TURRET, BUILD_BUNKER, BUILD_SENSOR_TOWER, BUILD_GHOST_ACADEMY, BUILD_FACTORY, BUILD_STARPORT, BUILD_ARMORY, BUILD_FUSION_CORE, HALT, STOP, @@ -146,7 +145,6 @@ public enum Units implements UnitType { RESEARCH_ZERG_MISSILE_WEAPONS), ZERG_EXTRACTOR(88, CANCEL), ZERG_EXTRACTOR_RICH(1981, CANCEL), - ZERG_EXTRACTOR_RICH_410(1956, CANCEL), ZERG_GREATER_SPIRE(102, CANCEL_LAST, RESEARCH_ZERG_FLYER_ARMOR, RESEARCH_ZERG_FLYER_ATTACK), ZERG_HATCHERY(86, SMART, MORPH_LAIR, RESEARCH_PNEUMATIZED_CARAPACE, RESEARCH_BURROW, TRAIN_QUEEN, CANCEL, CANCEL_LAST, RALLY_UNITS, RALLY_WORKERS), @@ -214,7 +212,6 @@ public enum Units implements UnitType { PROTOSS_ARCHON(141, SMART, MOVE, PATROL, HOLD_POSITION, STOP, RALLY_UNITS, ATTACK), PROTOSS_ASSIMILATOR(61, CANCEL), PROTOSS_ASSIMILATOR_RICH(1980, CANCEL), - PROTOSS_ASSIMILATOR_RICH_410(1955, CANCEL), PROTOSS_CARRIER(79, SMART, MOVE, PATROL, HOLD_POSITION, BUILD_INTERCEPTORS, STOP, CANCEL_LAST, ATTACK), PROTOSS_COLOSSUS(4, SMART, MOVE, PATROL, HOLD_POSITION, STOP, ATTACK), PROTOSS_CYBERNETICS_CORE(72, RESEARCH_WARP_GATE, CANCEL, CANCEL_LAST, RESEARCH_PROTOSS_AIR_ARMOR, @@ -380,6 +377,31 @@ public static UnitType from(int sc2ApiUnitTypeId) { return Optional.ofNullable(unitTypeIdMap.get(sc2ApiUnitTypeId)).orElse(Other.of(sc2ApiUnitTypeId)); } + public static void remapForBuild(Integer build) { + if (build >= 81009) { + updateId(1981, 1995); + updateId(1980, 1994); + + updateId(1982, 1996); + updateId(1983, 1997); + updateId(1984, 1998); + } else if (build >= 75689) { + updateId(1943, 1960); + updateId(1981, 1956); + updateId(1980, 1955); + + updateId(1982, 1961); + updateId(1983, 1962); + updateId(1984, 1963); + } + } + + private static void updateId(int oldId, int newId) { + UnitType toUpdate = unitTypeIdMap.remove(oldId); + ((Units) toUpdate).unitTypeId = newId; + unitTypeIdMap.put(newId, toUpdate); + } + @Override public Integer toSc2Api() { return getUnitTypeId();