From deef35c5028dff11d41b2892762d8752c8b5e7fd Mon Sep 17 00:00:00 2001 From: hundun Date: Sat, 22 Jul 2023 13:34:25 +0800 Subject: [PATCH] WIP idleShard apply idleForest's update --- .../gdxgame/idledemo/DemoChildGameConfig.java | 46 ++--- .../hundun/gdxgame/idledemo/DemoIdleGame.java | 8 +- .../idledemo/logic/ConstructionId.java | 13 -- .../logic/ConstructionPrototypeId.java | 11 + .../logic/DemoBuiltinConstructionsLoader.java | 108 +--------- .../idledemo/logic/DemoGameDictionary.java | 75 ++++--- .../idledemo/logic/DemoSaveHandler.java | 13 +- .../idledemo/logic/DemoTextureManager.java | 9 +- .../logic/IdleForestAchievementLoader.java | 15 ++ .../BaseIdleForestConstruction.java | 63 ++++++ .../IdleForestClickOutputComponent.java | 10 + .../IdleForestOutputComponent.java | 21 ++ .../IdleForestProficiencyComponent.java | 32 +++ .../CookieAutoProviderPrototype.java | 76 +++++++ .../idledemo/ui/entity/GameEntityFactory.java | 18 +- .../idledemo/ui/screen/DemoPlayScreen.java | 19 -- build.gradle | 4 +- .../core/framework/BaseIdleGame.java | 2 +- .../model/manager/AbstractTextureManager.java | 2 +- .../model/manager/AudioPlayManager.java | 2 +- .../model/manager/GameEntityManager.java | 28 +-- .../ui/component/AchievementMaskBoard.java | 6 +- .../starter/ui/component/GameImageDrawer.java | 4 +- .../starter/ui/component/PopupInfoBoard.java | 17 +- .../ui/component/StorageInfoBoard.java | 7 +- .../AbstractConstructionControlBoard.java | 34 +++- .../impl/ConstructionControlNode.java | 63 ++++-- .../ui/screen/menu/BaseIdleMenuScreen.java | 14 +- .../ui/screen/play/BaseIdlePlayScreen.java | 87 ++++++-- .../gamelib/export/IdleGameplayExport.java | 128 ++---------- .../framework/IdleGameplayContext.java | 17 +- .../callback/IAchievementUnlockCallback.java | 7 +- .../IConstructionCollectionListener.java | 5 + .../INotificationBoardCallerAndCallback.java | 6 + .../framework/data/ChildGameConfig.java | 10 +- .../framework/data/ConstructionSaveData.java | 4 + .../framework/data/GameplaySaveData.java | 4 +- .../IOneFrameResourceChangeListener.java | 3 +- .../framework/model/AbstractAchievement.java | 31 +++ .../framework/model/AchievementPrototype.java | 51 ----- .../model/IBuiltinAchievementsLoader.java | 9 + .../AbstractConstructionPrototype.java | 44 ++++ .../construction/BaseAutoConstruction.java | 94 --------- .../construction/BaseBuffConstruction.java | 59 ------ .../BaseClickGatherConstruction.java | 55 ----- .../construction/BaseConstructionFactory.java | 43 ++-- .../construction/base/BaseConstruction.java | 96 +++++---- .../construction/base/DescriptionPackage.java | 23 ++- .../base/DescriptionPackageFactory.java | 94 ++------- .../construction/base/ExistenceComponent.java | 65 ++++++ .../base/IBuiltinConstructionsLoader.java | 4 +- .../construction/base/LevelComponent.java | 18 +- .../construction/base/OutputComponent.java | 40 +++- .../base/ProficiencyComponent.java | 80 ++++++++ .../construction/base/PromotionComponent.java | 2 +- .../construction/base/UpgradeComponent.java | 109 +++++++--- .../starter/BaseAutoOutputComponent.java | 35 ++++ .../starter/BaseAutoProficiencyComponent.java | 41 ++++ .../starter/ConstProficiencyComponent.java | 21 ++ .../starter/EmptyOutputComponent.java | 26 +++ .../framework/model/grid/GridPosition.java | 20 ++ .../framework/model/grid/ITileNode.java | 22 ++ .../framework/model/grid/ITileNodeMap.java | 6 + .../framework/model/grid/TileNodeUtils.java | 155 +++++++++++++++ .../model/manager/AchievementManager.java | 74 +++++-- .../model/manager/ConstructionManager.java | 188 +++++++++++++----- .../framework/model/manager/EventManager.java | 65 +++++- .../model/manager/StorageManager.java | 21 +- .../model/resource/ResourcePack.java | 8 + .../framework/util/text/IGameDictionary.java | 7 +- 70 files changed, 1644 insertions(+), 953 deletions(-) delete mode 100644 IdleDemo-game/core/src/main/java/hundun/gdxgame/idledemo/logic/ConstructionId.java create mode 100644 IdleDemo-game/core/src/main/java/hundun/gdxgame/idledemo/logic/ConstructionPrototypeId.java create mode 100644 IdleDemo-game/core/src/main/java/hundun/gdxgame/idledemo/logic/IdleForestAchievementLoader.java create mode 100644 IdleDemo-game/core/src/main/java/hundun/gdxgame/idledemo/logic/construction/BaseIdleForestConstruction.java create mode 100644 IdleDemo-game/core/src/main/java/hundun/gdxgame/idledemo/logic/construction/IdleForestClickOutputComponent.java create mode 100644 IdleDemo-game/core/src/main/java/hundun/gdxgame/idledemo/logic/construction/IdleForestOutputComponent.java create mode 100644 IdleDemo-game/core/src/main/java/hundun/gdxgame/idledemo/logic/construction/IdleForestProficiencyComponent.java create mode 100644 IdleDemo-game/core/src/main/java/hundun/gdxgame/idledemo/logic/prototype/CookieAutoProviderPrototype.java create mode 100644 idleshare/gamelib/src/hundun/gdxgame/idleshare/gamelib/framework/callback/IConstructionCollectionListener.java create mode 100644 idleshare/gamelib/src/hundun/gdxgame/idleshare/gamelib/framework/callback/INotificationBoardCallerAndCallback.java create mode 100644 idleshare/gamelib/src/hundun/gdxgame/idleshare/gamelib/framework/model/AbstractAchievement.java delete mode 100644 idleshare/gamelib/src/hundun/gdxgame/idleshare/gamelib/framework/model/AchievementPrototype.java create mode 100644 idleshare/gamelib/src/hundun/gdxgame/idleshare/gamelib/framework/model/IBuiltinAchievementsLoader.java create mode 100644 idleshare/gamelib/src/hundun/gdxgame/idleshare/gamelib/framework/model/construction/AbstractConstructionPrototype.java delete mode 100644 idleshare/gamelib/src/hundun/gdxgame/idleshare/gamelib/framework/model/construction/BaseAutoConstruction.java delete mode 100644 idleshare/gamelib/src/hundun/gdxgame/idleshare/gamelib/framework/model/construction/BaseBuffConstruction.java delete mode 100644 idleshare/gamelib/src/hundun/gdxgame/idleshare/gamelib/framework/model/construction/BaseClickGatherConstruction.java create mode 100644 idleshare/gamelib/src/hundun/gdxgame/idleshare/gamelib/framework/model/construction/base/ExistenceComponent.java create mode 100644 idleshare/gamelib/src/hundun/gdxgame/idleshare/gamelib/framework/model/construction/base/ProficiencyComponent.java create mode 100644 idleshare/gamelib/src/hundun/gdxgame/idleshare/gamelib/framework/model/construction/starter/BaseAutoOutputComponent.java create mode 100644 idleshare/gamelib/src/hundun/gdxgame/idleshare/gamelib/framework/model/construction/starter/BaseAutoProficiencyComponent.java create mode 100644 idleshare/gamelib/src/hundun/gdxgame/idleshare/gamelib/framework/model/construction/starter/ConstProficiencyComponent.java create mode 100644 idleshare/gamelib/src/hundun/gdxgame/idleshare/gamelib/framework/model/construction/starter/EmptyOutputComponent.java create mode 100644 idleshare/gamelib/src/hundun/gdxgame/idleshare/gamelib/framework/model/grid/GridPosition.java create mode 100644 idleshare/gamelib/src/hundun/gdxgame/idleshare/gamelib/framework/model/grid/ITileNode.java create mode 100644 idleshare/gamelib/src/hundun/gdxgame/idleshare/gamelib/framework/model/grid/ITileNodeMap.java create mode 100644 idleshare/gamelib/src/hundun/gdxgame/idleshare/gamelib/framework/model/grid/TileNodeUtils.java diff --git a/IdleDemo-game/core/src/main/java/hundun/gdxgame/idledemo/DemoChildGameConfig.java b/IdleDemo-game/core/src/main/java/hundun/gdxgame/idledemo/DemoChildGameConfig.java index 2e91158..f04302f 100644 --- a/IdleDemo-game/core/src/main/java/hundun/gdxgame/idledemo/DemoChildGameConfig.java +++ b/IdleDemo-game/core/src/main/java/hundun/gdxgame/idledemo/DemoChildGameConfig.java @@ -1,24 +1,19 @@ package hundun.gdxgame.idledemo; -import java.io.File; -import java.util.Arrays; +import java.util.ArrayList; import java.util.HashMap; import java.util.List; import java.util.Map; -import com.badlogic.gdx.Gdx; - import hundun.gdxgame.gamelib.base.util.JavaFeatureForGwt; import hundun.gdxgame.idledemo.logic.BuffId; -import hundun.gdxgame.idledemo.logic.DemoBuiltinConstructionsLoader; -import hundun.gdxgame.idledemo.logic.ConstructionId; +import hundun.gdxgame.idledemo.logic.ConstructionPrototypeId; import hundun.gdxgame.idledemo.logic.GameArea; import hundun.gdxgame.idledemo.logic.ResourceType; import hundun.gdxgame.idledemo.ui.screen.DemoMenuScreen; import hundun.gdxgame.idledemo.ui.screen.DemoPlayScreen; import hundun.gdxgame.idleshare.gamelib.framework.data.ChildGameConfig; -import hundun.gdxgame.idleshare.gamelib.framework.data.GameplaySaveData; -import hundun.gdxgame.idleshare.gamelib.framework.model.AchievementPrototype; +import hundun.gdxgame.idleshare.gamelib.framework.model.AbstractAchievement; /** * @author hundun @@ -31,20 +26,19 @@ public DemoChildGameConfig() { // BuiltinConstructionsLoader builtinConstructionsLoader = new BuiltinConstructionsLoader(game); // this.setConstructions(builtinConstructionsLoader.load()); - Map> areaShownConstructionIds = new HashMap<>(); - areaShownConstructionIds.put(GameArea.AREA_COOKIE, JavaFeatureForGwt.arraysAsList( - ConstructionId.COOKIE_CLICK_PROVIDER - )); - areaShownConstructionIds.put(GameArea.AREA_BUILDING, JavaFeatureForGwt.arraysAsList( - ConstructionId.COOKIE_AUTO_PROVIDER, - ConstructionId.COOKIE_SELLER + Map> areaControlableConstructionVMPrototypeIds = new HashMap<>(); + areaControlableConstructionVMPrototypeIds.put(GameArea.AREA_COOKIE, JavaFeatureForGwt.arraysAsList( + ConstructionPrototypeId.COOKIE_AUTO_PROVIDER )); - areaShownConstructionIds.put(GameArea.AREA_WIN, JavaFeatureForGwt.arraysAsList( - ConstructionId.WIN_PROVIDER + this.setAreaControlableConstructionVMPrototypeIds(areaControlableConstructionVMPrototypeIds); + + Map> areaControlableConstructionPrototypeVMPrototypeIds = new HashMap<>(); + areaControlableConstructionPrototypeVMPrototypeIds.put(GameArea.AREA_COOKIE, JavaFeatureForGwt.arraysAsList( + ConstructionPrototypeId.COOKIE_AUTO_PROVIDER )); + this.setAreaControlableConstructionPrototypeVMPrototypeIds(areaControlableConstructionPrototypeVMPrototypeIds); + - this.setAreaControlableConstructionIds(areaShownConstructionIds); - this.setAreaShowEntityByOwnAmountConstructionIds(areaShownConstructionIds); Map> areaShownResourceIds = new HashMap<>(); areaShownResourceIds.put(GameArea.AREA_COOKIE, JavaFeatureForGwt.arraysAsList( @@ -57,20 +51,16 @@ public DemoChildGameConfig() { ResourceType.COOKIE )); this.setAreaShowEntityByChangeAmountResourceIds(areaShowEntityByChangeAmountResourceIds); - + + this.setAreaShowEntityByOwnAmountConstructionPrototypeIds(new HashMap<>()); + Map screenIdToFilePathMap = JavaFeatureForGwt.mapOf( DemoMenuScreen.class.getSimpleName(), "audio/Loop-Menu.wav", DemoPlayScreen.class.getSimpleName(), "audio/forest.mp3" ); this.setScreenIdToFilePathMap(screenIdToFilePathMap); - - List achievementPrototypes = JavaFeatureForGwt.arraysAsList( - new AchievementPrototype("Game win", "You win the game!", - JavaFeatureForGwt.mapOf(BuffId.WIN, 1), - null - ) - ); - this.setAchievementPrototypes(achievementPrototypes); + + this.setAchievementPrototypeIds(new ArrayList<>()); } diff --git a/IdleDemo-game/core/src/main/java/hundun/gdxgame/idledemo/DemoIdleGame.java b/IdleDemo-game/core/src/main/java/hundun/gdxgame/idledemo/DemoIdleGame.java index 7479b46..27618b6 100644 --- a/IdleDemo-game/core/src/main/java/hundun/gdxgame/idledemo/DemoIdleGame.java +++ b/IdleDemo-game/core/src/main/java/hundun/gdxgame/idledemo/DemoIdleGame.java @@ -8,13 +8,8 @@ import com.badlogic.gdx.utils.viewport.ScreenViewport; import com.ray3k.stripe.FreeTypeSkin; -import hundun.gdxgame.idledemo.logic.DemoGameDictionary; -import hundun.gdxgame.idledemo.logic.DemoTextureManager; +import hundun.gdxgame.idledemo.logic.*; import hundun.gdxgame.gamelib.base.save.ISaveTool; -import hundun.gdxgame.idledemo.logic.DemoBuiltinConstructionsLoader; -import hundun.gdxgame.idledemo.logic.DemoSaveHandler; -import hundun.gdxgame.idledemo.logic.GameArea; -import hundun.gdxgame.idledemo.logic.RootSaveData; import hundun.gdxgame.idledemo.ui.screen.DemoMenuScreen; import hundun.gdxgame.idledemo.ui.screen.DemoScreenContext; import hundun.gdxgame.idleshare.core.framework.BaseIdleGame; @@ -65,6 +60,7 @@ protected void createStage1() { frontend, new DemoGameDictionary(), new DemoBuiltinConstructionsLoader(), + new IdleForestAchievementLoader(), BaseIdlePlayScreen.LOGIC_FRAME_PER_SECOND, childGameConfig ); diff --git a/IdleDemo-game/core/src/main/java/hundun/gdxgame/idledemo/logic/ConstructionId.java b/IdleDemo-game/core/src/main/java/hundun/gdxgame/idledemo/logic/ConstructionId.java deleted file mode 100644 index 83b2d78..0000000 --- a/IdleDemo-game/core/src/main/java/hundun/gdxgame/idledemo/logic/ConstructionId.java +++ /dev/null @@ -1,13 +0,0 @@ -package hundun.gdxgame.idledemo.logic; - - - - -public class ConstructionId { - - public static final String COOKIE_CLICK_PROVIDER = "ENUM_CSTR@COOKIE_CLICK_PROVIDER"; - public static final String COOKIE_AUTO_PROVIDER = "ENUM_CSTR@COOKIE_AUTO_PROVIDER"; - public static final String WIN_PROVIDER = "ENUM_CSTR@WIN_PROVIDER"; - - public static final String COOKIE_SELLER = "ENUM_CSTR@COOKIE_SELLER"; -} diff --git a/IdleDemo-game/core/src/main/java/hundun/gdxgame/idledemo/logic/ConstructionPrototypeId.java b/IdleDemo-game/core/src/main/java/hundun/gdxgame/idledemo/logic/ConstructionPrototypeId.java new file mode 100644 index 0000000..83b910b --- /dev/null +++ b/IdleDemo-game/core/src/main/java/hundun/gdxgame/idledemo/logic/ConstructionPrototypeId.java @@ -0,0 +1,11 @@ +package hundun.gdxgame.idledemo.logic; + + + + +public class ConstructionPrototypeId { + + + public static final String COOKIE_AUTO_PROVIDER = "ENUM_CSTR@COOKIE_AUTO_PROVIDER"; + +} diff --git a/IdleDemo-game/core/src/main/java/hundun/gdxgame/idledemo/logic/DemoBuiltinConstructionsLoader.java b/IdleDemo-game/core/src/main/java/hundun/gdxgame/idledemo/logic/DemoBuiltinConstructionsLoader.java index 93f2a56..74bae19 100644 --- a/IdleDemo-game/core/src/main/java/hundun/gdxgame/idledemo/logic/DemoBuiltinConstructionsLoader.java +++ b/IdleDemo-game/core/src/main/java/hundun/gdxgame/idledemo/logic/DemoBuiltinConstructionsLoader.java @@ -1,17 +1,13 @@ package hundun.gdxgame.idledemo.logic; import java.util.ArrayList; +import java.util.HashMap; import java.util.List; import java.util.Map; import hundun.gdxgame.gamelib.base.util.JavaFeatureForGwt; -import hundun.gdxgame.idledemo.DemoIdleGame; -import hundun.gdxgame.idleshare.core.framework.BaseIdleGame; -import hundun.gdxgame.idleshare.gamelib.framework.IdleGameplayContext; -import hundun.gdxgame.idleshare.gamelib.framework.model.construction.BaseAutoConstruction; -import hundun.gdxgame.idleshare.gamelib.framework.model.construction.BaseBuffConstruction; -import hundun.gdxgame.idleshare.gamelib.framework.model.construction.BaseClickGatherConstruction; -import hundun.gdxgame.idleshare.gamelib.framework.model.construction.BaseConstructionFactory; +import hundun.gdxgame.idledemo.logic.prototype.CookieAutoProviderPrototype; +import hundun.gdxgame.idleshare.gamelib.framework.model.construction.*; import hundun.gdxgame.idleshare.gamelib.framework.model.construction.base.BaseConstruction; import hundun.gdxgame.idleshare.gamelib.framework.model.construction.base.DescriptionPackageFactory; import hundun.gdxgame.idleshare.gamelib.framework.model.construction.base.IBuiltinConstructionsLoader; @@ -20,107 +16,19 @@ import hundun.gdxgame.idleshare.gamelib.framework.model.construction.base.UpgradeComponent; import hundun.gdxgame.idleshare.gamelib.framework.model.resource.ResourcePack; import hundun.gdxgame.idleshare.gamelib.framework.model.resource.ResourcePair; -import hundun.gdxgame.idleshare.gamelib.framework.util.text.IGameDictionary; import hundun.gdxgame.idleshare.gamelib.framework.util.text.Language; public class DemoBuiltinConstructionsLoader implements IBuiltinConstructionsLoader { @Override - public List provide(Language language) { - List constructions = new ArrayList<>(); - // clicker-provider - { - BaseConstruction construction = new BaseClickGatherConstruction(ConstructionId.COOKIE_CLICK_PROVIDER); - construction.descriptionPackage = DescriptionPackageFactory.getGatherDescriptionPackage(language); - - OutputComponent outputComponent = new OutputComponent(construction); - outputComponent.setOutputGainPack(toPack(JavaFeatureForGwt.mapOf( - ResourceType.COOKIE, 1 - ))); - construction.setOutputComponent(outputComponent); - - UpgradeComponent upgradeComponent = new UpgradeComponent(construction); - construction.setUpgradeComponent(upgradeComponent); - - LevelComponent levelComponent = new LevelComponent(construction, false); - construction.setLevelComponent(levelComponent); - - constructions.add(construction); - } - // auto-provider - { - BaseConstruction construction = new BaseAutoConstruction(ConstructionId.COOKIE_AUTO_PROVIDER); - construction.descriptionPackage = DescriptionPackageFactory.getMaxLevelAutoDescriptionPackage(language); - - OutputComponent outputComponent = new OutputComponent(construction); - outputComponent.setOutputGainPack(toPack(JavaFeatureForGwt.mapOf( - ResourceType.COOKIE, 1 - ))); - construction.setOutputComponent(outputComponent); - - UpgradeComponent upgradeComponent = new UpgradeComponent(construction); - upgradeComponent.setUpgradeCostPack(toPack(JavaFeatureForGwt.mapOf( - ResourceType.COIN, 25 - ))); - construction.setUpgradeComponent(upgradeComponent); - - LevelComponent levelComponent = new LevelComponent(construction, false); - construction.setLevelComponent(levelComponent); - - construction.setMaxDrawNum(9); - constructions.add(construction); - } - // seller - { - BaseConstruction construction = new BaseAutoConstruction(ConstructionId.COOKIE_SELLER); - construction.descriptionPackage = DescriptionPackageFactory.getWorkingLevelAutoDescriptionPackage(language); - - OutputComponent outputComponent = new OutputComponent(construction); - outputComponent.setOutputCostPack(toPack(JavaFeatureForGwt.mapOf( - ResourceType.COOKIE, 1 - ))); - outputComponent.setOutputGainPack(toPack(JavaFeatureForGwt.mapOf( - ResourceType.COIN, 5 - ))); - construction.setOutputComponent(outputComponent); - - UpgradeComponent upgradeComponent = new UpgradeComponent(construction); - upgradeComponent.setUpgradeCostPack(toPack(JavaFeatureForGwt.mapOf( - ResourceType.COIN, 500 - ))); - construction.setUpgradeComponent(upgradeComponent); - - LevelComponent levelComponent = new LevelComponent(construction, true); - construction.setLevelComponent(levelComponent); - - construction.setMaxDrawNum(9); - constructions.add(construction); - } - // win - { - BaseConstruction construction = new BaseBuffConstruction(ConstructionId.WIN_PROVIDER, BuffId.WIN); - construction.descriptionPackage = DescriptionPackageFactory.getWinDescriptionPackage(language); - - OutputComponent outputComponent = new OutputComponent(construction); - construction.setOutputComponent(outputComponent); - - UpgradeComponent upgradeComponent = new UpgradeComponent(construction); - upgradeComponent.setUpgradeCostPack(toPack(JavaFeatureForGwt.mapOf( - ResourceType.COIN, 500 - ))); - construction.setUpgradeComponent(upgradeComponent); - - LevelComponent levelComponent = new LevelComponent(construction, false); - construction.setLevelComponent(levelComponent); - - construction.setMaxLevel(1); - constructions.add(construction); - } - return constructions; + public Map getProviderMap(Language language) { + Map result = new HashMap<>(); + result.put(ConstructionPrototypeId.COOKIE_AUTO_PROVIDER, new CookieAutoProviderPrototype(language)); + return result; } - private static ResourcePack toPack(Map map) { + public static ResourcePack toPack(Map map) { ResourcePack pack = new ResourcePack(); List pairs = new ArrayList<>(map.size()); map.entrySet().forEach(entry -> pairs.add(new ResourcePair(entry.getKey(), (long)entry.getValue()))); diff --git a/IdleDemo-game/core/src/main/java/hundun/gdxgame/idledemo/logic/DemoGameDictionary.java b/IdleDemo-game/core/src/main/java/hundun/gdxgame/idledemo/logic/DemoGameDictionary.java index 70a7563..bfd0138 100644 --- a/IdleDemo-game/core/src/main/java/hundun/gdxgame/idledemo/logic/DemoGameDictionary.java +++ b/IdleDemo-game/core/src/main/java/hundun/gdxgame/idledemo/logic/DemoGameDictionary.java @@ -14,31 +14,20 @@ public class DemoGameDictionary implements IGameDictionary { - public String constructionIdToShowName(Language language, String constructionId) { + public String constructionPrototypeIdToShowName(Language language, String constructionId) { switch (language) { case CN: switch (constructionId) { - case ConstructionId.COOKIE_CLICK_PROVIDER: - return "大饼干"; - case ConstructionId.COOKIE_AUTO_PROVIDER: + + case ConstructionPrototypeId.COOKIE_AUTO_PROVIDER: return "自动点击器"; - case ConstructionId.COOKIE_SELLER: - return "自动销售器"; - case ConstructionId.WIN_PROVIDER: - return "奖杯购买处"; default: return "口口"; } default: switch (constructionId) { - case ConstructionId.COOKIE_CLICK_PROVIDER: - return "main cookie"; - case ConstructionId.COOKIE_AUTO_PROVIDER: + case ConstructionPrototypeId.COOKIE_AUTO_PROVIDER: return "cliker"; - case ConstructionId.COOKIE_SELLER: - return "seller"; - case ConstructionId.WIN_PROVIDER: - return "win"; default: return "[dic lost]"; } @@ -48,31 +37,19 @@ public String constructionIdToShowName(Language language, String constructionId) } @Override - public String constructionIdToDetailDescroptionConstPart(Language language, String constructionId) { + public String constructionPrototypeIdToDetailDescroptionConstPart(Language language, String constructionId) { switch (language) { case CN: - switch (constructionId) { - case ConstructionId.COOKIE_CLICK_PROVIDER: - return "戳一戳,获得饼干"; - case ConstructionId.COOKIE_AUTO_PROVIDER: - return "自动获得饼干"; - case ConstructionId.COOKIE_SELLER: + switch (constructionId) { + case ConstructionPrototypeId.COOKIE_AUTO_PROVIDER: return "自动获得饼干"; - case ConstructionId.WIN_PROVIDER: - return "购买一个奖杯以赢得胜利"; default: return "[dic lost]"; } default: switch (constructionId) { - case ConstructionId.COOKIE_CLICK_PROVIDER: - return "Click gain some cookie"; - case ConstructionId.COOKIE_AUTO_PROVIDER: + case ConstructionPrototypeId.COOKIE_AUTO_PROVIDER: return "Auto gain some cookie"; - case ConstructionId.COOKIE_SELLER: - return "Auto sell cookies"; - case ConstructionId.WIN_PROVIDER: - return "Get a trophy and win the game"; default: return "[dic lost]"; } @@ -98,4 +75,40 @@ public Map getLanguageShowNameMap() { Language.EN, "English" ); } + + @Override + public List getAchievementTexts(Language language) + { + switch (language) + { + case CN: + return JavaFeatureForGwt.arraysAsList("当前任务:", "已完成:", "回到游戏"); + default: + return JavaFeatureForGwt.arraysAsList("Quest: ", "Completed: ", "back"); + } + } + + @Override + public List getPlayScreenTexts(Language language) + { + switch (language) + { + case CN: + return JavaFeatureForGwt.arraysAsList("购买", "购买费用"); + default: + return JavaFeatureForGwt.arraysAsList("Build", "Build cost"); + } + } + + @Override + public List getStageSelectMaskBoardTexts(Language language) + { + switch (language) + { + case CN: + return JavaFeatureForGwt.arraysAsList("返回", "关卡1", "关卡2", "关卡3"); + default: + return JavaFeatureForGwt.arraysAsList("Back", "Stage1", "Stage2", "Stage3"); + } + } } diff --git a/IdleDemo-game/core/src/main/java/hundun/gdxgame/idledemo/logic/DemoSaveHandler.java b/IdleDemo-game/core/src/main/java/hundun/gdxgame/idledemo/logic/DemoSaveHandler.java index f9fe0c7..2297d23 100644 --- a/IdleDemo-game/core/src/main/java/hundun/gdxgame/idledemo/logic/DemoSaveHandler.java +++ b/IdleDemo-game/core/src/main/java/hundun/gdxgame/idledemo/logic/DemoSaveHandler.java @@ -10,6 +10,7 @@ import hundun.gdxgame.idleshare.gamelib.framework.data.ConstructionSaveData; import hundun.gdxgame.idleshare.gamelib.framework.data.GameplaySaveData; import hundun.gdxgame.idleshare.gamelib.framework.data.SystemSettingSaveData; +import hundun.gdxgame.idleshare.gamelib.framework.model.grid.GridPosition; import hundun.gdxgame.idleshare.gamelib.framework.util.text.Language; /** @@ -25,18 +26,24 @@ public DemoSaveHandler(IFrontend frontEnd, ISaveTool saveTool) { @Override protected RootSaveData genereateStarterRootSaveData() { + + GridPosition USELESS_POSITON = new GridPosition(0, 0); + return RootSaveData.builder() .gameplaySave(GameplaySaveData.builder() .constructionSaveDataMap( JavaFeatureForGwt.mapOf( - ConstructionId.COOKIE_SELLER, + ConstructionPrototypeId.COOKIE_AUTO_PROVIDER, ConstructionSaveData.builder() + .prototypeId(ConstructionPrototypeId.COOKIE_AUTO_PROVIDER) .level(1) .workingLevel(0) - .build())) + .position(USELESS_POSITON) + .build()) + ) .ownResoueces(new HashMap<>()) .unlockedResourceTypes(new HashSet<>()) - .unlockedAchievementNames(new HashSet<>()) + .unlockedAchievementIds(new HashSet<>()) .build()) .systemSettingSaveData(SystemSettingSaveData.builder() .language(Language.EN) diff --git a/IdleDemo-game/core/src/main/java/hundun/gdxgame/idledemo/logic/DemoTextureManager.java b/IdleDemo-game/core/src/main/java/hundun/gdxgame/idledemo/logic/DemoTextureManager.java index d6f0674..f594920 100644 --- a/IdleDemo-game/core/src/main/java/hundun/gdxgame/idledemo/logic/DemoTextureManager.java +++ b/IdleDemo-game/core/src/main/java/hundun/gdxgame/idledemo/logic/DemoTextureManager.java @@ -1,8 +1,5 @@ package hundun.gdxgame.idledemo.logic; -import java.util.HashMap; -import java.util.Map; - import com.badlogic.gdx.Gdx; import com.badlogic.gdx.graphics.Texture; import com.badlogic.gdx.graphics.g2d.TextureRegion; @@ -15,7 +12,7 @@ public class DemoTextureManager extends AbstractTextureManager { @Override public void lazyInitOnGameCreateStage2() { - winTexture = new Texture(Gdx.files.internal("win.png")); + achievementMaskBoardTexture = new Texture(Gdx.files.internal("win.png")); menuTexture = new Texture(Gdx.files.internal("menu.png")); defaultBoardNinePatchTexture = new Texture(Gdx.files.internal("defaultBoardNinePatch.png")); defaultBoardNinePatchEdgeSize = 4; @@ -42,8 +39,8 @@ public void lazyInitOnGameCreateStage2() { Texture texture = new Texture(Gdx.files.internal("constructionEntities.png")); TextureRegion[][] regions = TextureRegion.split(texture, 32, 32); //constructionEntityMap.put(ConstructionId.COOKIE_CLICK_PROVIDER, regions[0][0]); - constructionEntityMap.put(ConstructionId.COOKIE_AUTO_PROVIDER, regions[0][1]); - constructionEntityMap.put(ConstructionId.COOKIE_SELLER, regions[0][2]); + constructionEntityMap.put(ConstructionPrototypeId.COOKIE_AUTO_PROVIDER, regions[0][1]); + //constructionEntityMap.put(ConstructionPrototypeId.COOKIE_SELLER, regions[0][2]); //constructionEntityMap.put(ConstructionId.WIN_PROVIDER, regions[0][3]); } { diff --git a/IdleDemo-game/core/src/main/java/hundun/gdxgame/idledemo/logic/IdleForestAchievementLoader.java b/IdleDemo-game/core/src/main/java/hundun/gdxgame/idledemo/logic/IdleForestAchievementLoader.java new file mode 100644 index 0000000..6bb7b27 --- /dev/null +++ b/IdleDemo-game/core/src/main/java/hundun/gdxgame/idledemo/logic/IdleForestAchievementLoader.java @@ -0,0 +1,15 @@ +package hundun.gdxgame.idledemo.logic; + +import hundun.gdxgame.idleshare.gamelib.framework.model.AbstractAchievement; +import hundun.gdxgame.idleshare.gamelib.framework.model.IBuiltinAchievementsLoader; +import hundun.gdxgame.idleshare.gamelib.framework.util.text.Language; + +import java.util.HashMap; +import java.util.Map; + +public class IdleForestAchievementLoader implements IBuiltinAchievementsLoader { + @Override + public Map getProviderMap(Language language) { + return new HashMap<>(); + } +} diff --git a/IdleDemo-game/core/src/main/java/hundun/gdxgame/idledemo/logic/construction/BaseIdleForestConstruction.java b/IdleDemo-game/core/src/main/java/hundun/gdxgame/idledemo/logic/construction/BaseIdleForestConstruction.java new file mode 100644 index 0000000..702cefa --- /dev/null +++ b/IdleDemo-game/core/src/main/java/hundun/gdxgame/idledemo/logic/construction/BaseIdleForestConstruction.java @@ -0,0 +1,63 @@ +package hundun.gdxgame.idledemo.logic.construction; + +import hundun.gdxgame.idleshare.gamelib.framework.model.construction.base.*; +import hundun.gdxgame.idleshare.gamelib.framework.model.construction.starter.ConstProficiencyComponent; +import hundun.gdxgame.idleshare.gamelib.framework.model.grid.GridPosition; + +public class BaseIdleForestConstruction extends BaseConstruction { + + public BaseIdleForestConstruction( + String prototypeId, + String id, + GridPosition position, + DescriptionPackage descriptionPackage + ) { + super(prototypeId, id); + + this.descriptionPackage = descriptionPackage; + + UpgradeComponent upgradeComponent = new UpgradeComponent(this); + this.upgradeComponent = upgradeComponent; + + LevelComponent levelComponent = new LevelComponent(this, false); + this.levelComponent = levelComponent; + + ExistenceComponent existenceComponent = new ExistenceComponent(this); + this.existenceComponent = existenceComponent; + + this.saveData.setPosition(position); + this.saveData.setLevel(1); + this.saveData.setWorkingLevel(1); + this.saveData.setProficiency(0); + } + + public static BaseIdleForestConstruction typeAutoConstProficienc(String prototypeId, + String id, + GridPosition position, + DescriptionPackage descriptionPackage) + { + BaseIdleForestConstruction thiz = new BaseIdleForestConstruction(prototypeId, id, position, descriptionPackage); + + ConstProficiencyComponent proficiencyComponent = new ConstProficiencyComponent(thiz); + thiz.proficiencyComponent = proficiencyComponent; + + IdleForestOutputComponent outputComponent = new IdleForestOutputComponent(thiz); + thiz.outputComponent = outputComponent; + + return thiz; + } + + public static BaseIdleForestConstruction typeClick(String prototypeId, + String id, + GridPosition position, + DescriptionPackage descriptionPackage) + { + BaseIdleForestConstruction thiz = new BaseIdleForestConstruction(prototypeId, id, position, descriptionPackage); + + IdleForestClickOutputComponent outputComponent = new IdleForestClickOutputComponent(thiz); + thiz.outputComponent = outputComponent; + + return thiz; + } + +} diff --git a/IdleDemo-game/core/src/main/java/hundun/gdxgame/idledemo/logic/construction/IdleForestClickOutputComponent.java b/IdleDemo-game/core/src/main/java/hundun/gdxgame/idledemo/logic/construction/IdleForestClickOutputComponent.java new file mode 100644 index 0000000..7712258 --- /dev/null +++ b/IdleDemo-game/core/src/main/java/hundun/gdxgame/idledemo/logic/construction/IdleForestClickOutputComponent.java @@ -0,0 +1,10 @@ +package hundun.gdxgame.idledemo.logic.construction; + +import hundun.gdxgame.idleshare.gamelib.framework.model.construction.base.BaseConstruction; +import hundun.gdxgame.idleshare.gamelib.framework.model.construction.starter.EmptyOutputComponent; + +public class IdleForestClickOutputComponent extends EmptyOutputComponent { + public IdleForestClickOutputComponent(BaseConstruction construction) { + super(construction); + } +} diff --git a/IdleDemo-game/core/src/main/java/hundun/gdxgame/idledemo/logic/construction/IdleForestOutputComponent.java b/IdleDemo-game/core/src/main/java/hundun/gdxgame/idledemo/logic/construction/IdleForestOutputComponent.java new file mode 100644 index 0000000..26a9d78 --- /dev/null +++ b/IdleDemo-game/core/src/main/java/hundun/gdxgame/idledemo/logic/construction/IdleForestOutputComponent.java @@ -0,0 +1,21 @@ +package hundun.gdxgame.idledemo.logic.construction; + +import hundun.gdxgame.idleshare.gamelib.framework.model.construction.base.BaseConstruction; +import hundun.gdxgame.idleshare.gamelib.framework.model.construction.starter.BaseAutoOutputComponent; + +public class IdleForestOutputComponent extends BaseAutoOutputComponent { + + public IdleForestOutputComponent(BaseConstruction construction) { + super(construction); + } + + @Override + public long calculateModifiedOutputGain(long baseValue, int level, int proficiency) { + return (long)((baseValue * level) * (0.5 + proficiency / construction.getProficiencyComponent().maxProficiency * 0.5)); + } + + @Override + public long calculateModifiedOutputCost(long baseValue, int level, int proficiency) { + return (long)((baseValue * level) * (0.5 + proficiency / construction.getProficiencyComponent().maxProficiency * 0.5)); + } +} diff --git a/IdleDemo-game/core/src/main/java/hundun/gdxgame/idledemo/logic/construction/IdleForestProficiencyComponent.java b/IdleDemo-game/core/src/main/java/hundun/gdxgame/idledemo/logic/construction/IdleForestProficiencyComponent.java new file mode 100644 index 0000000..44efa92 --- /dev/null +++ b/IdleDemo-game/core/src/main/java/hundun/gdxgame/idledemo/logic/construction/IdleForestProficiencyComponent.java @@ -0,0 +1,32 @@ +package hundun.gdxgame.idledemo.logic.construction; + +import hundun.gdxgame.idleshare.gamelib.framework.model.construction.base.BaseConstruction; +import hundun.gdxgame.idleshare.gamelib.framework.model.construction.starter.BaseAutoProficiencyComponent; + +public class IdleForestProficiencyComponent extends BaseAutoProficiencyComponent { + + public static interface ProficiencySpeedCalculator { + int invoke(BaseIdleForestConstruction thiz); + } + public ProficiencySpeedCalculator proficiencySpeedCalculator; + + + public IdleForestProficiencyComponent(BaseConstruction construction, Integer second) { + super(construction, second, 50); + } + + @Override + public void onSubLogicFrame() + { + super.onSubLogicFrame(); + checkAutoPromoteDemote(); + } + + @Override + protected void tryProficiencyOnce() { + if (this.proficiencySpeedCalculator != null) + { + this.changeProficiency(proficiencySpeedCalculator.invoke((BaseIdleForestConstruction)construction)); + } + } +} diff --git a/IdleDemo-game/core/src/main/java/hundun/gdxgame/idledemo/logic/prototype/CookieAutoProviderPrototype.java b/IdleDemo-game/core/src/main/java/hundun/gdxgame/idledemo/logic/prototype/CookieAutoProviderPrototype.java new file mode 100644 index 0000000..c3416b2 --- /dev/null +++ b/IdleDemo-game/core/src/main/java/hundun/gdxgame/idledemo/logic/prototype/CookieAutoProviderPrototype.java @@ -0,0 +1,76 @@ +package hundun.gdxgame.idledemo.logic.prototype; + +import hundun.gdxgame.gamelib.base.util.JavaFeatureForGwt; +import hundun.gdxgame.idledemo.logic.ConstructionPrototypeId; +import hundun.gdxgame.idledemo.logic.DemoBuiltinConstructionsLoader; +import hundun.gdxgame.idledemo.logic.ResourceType; +import hundun.gdxgame.idledemo.logic.construction.BaseIdleForestConstruction; +import hundun.gdxgame.idleshare.gamelib.framework.model.construction.AbstractConstructionPrototype; +import hundun.gdxgame.idleshare.gamelib.framework.model.construction.base.BaseConstruction; +import hundun.gdxgame.idleshare.gamelib.framework.model.construction.base.DescriptionPackage; +import hundun.gdxgame.idleshare.gamelib.framework.model.construction.base.DescriptionPackageFactory; +import hundun.gdxgame.idleshare.gamelib.framework.model.grid.GridPosition; +import hundun.gdxgame.idleshare.gamelib.framework.util.text.Language; + +import java.util.HashMap; +import java.util.UUID; + +public class CookieAutoProviderPrototype extends AbstractConstructionPrototype { + public static DescriptionPackage descriptionPackageEN = DescriptionPackage.builder() + .buttonDescroption("Upgrade") + .outputCostDescriptionStart("Consume") + .outputGainDescriptionStart("Produce") + .upgradeCostDescriptionStart("Upgrade cost") + .upgradeMaxLevelDescription("(max)") + .levelDescroptionProvider(DescriptionPackageFactory.ONLY_LEVEL_IMP) + .proficiencyDescroptionProvider(DescriptionPackageFactory.EN_PROFICIENCY_IMP) + .build(); + + + public static DescriptionPackage descriptionPackageCN = DescriptionPackage.builder() + .buttonDescroption("升级") + .outputCostDescriptionStart("自动消耗") + .outputGainDescriptionStart("自动产出") + .upgradeCostDescriptionStart("升级费用") + .upgradeMaxLevelDescription("(已达到最大等级)") + .levelDescroptionProvider(DescriptionPackageFactory.ONLY_LEVEL_IMP) + .proficiencyDescroptionProvider(DescriptionPackageFactory.CN_PROFICIENCY_IMP) + .build(); + + public CookieAutoProviderPrototype(Language language) { + super( + ConstructionPrototypeId.COOKIE_AUTO_PROVIDER, + language, + DemoBuiltinConstructionsLoader.toPack(JavaFeatureForGwt.mapOf( + ResourceType.COIN, 40 + )) + ); + switch (language) + { + case CN: + this.descriptionPackage = descriptionPackageCN; + break; + default: + this.descriptionPackage = descriptionPackageEN; + break; + } + + } + + @Override + public BaseConstruction getInstance(GridPosition position) { + String id = prototypeId + "_" + UUID.randomUUID().toString(); + BaseIdleForestConstruction construction = BaseIdleForestConstruction.typeAutoConstProficienc(prototypeId, id, position, descriptionPackage); + + construction.getOutputComponent().setOutputCostPack(DemoBuiltinConstructionsLoader.toPack(new HashMap<>())); + construction.getOutputComponent().setOutputGainPack(DemoBuiltinConstructionsLoader.toPack(JavaFeatureForGwt.mapOf( + ResourceType.COOKIE, 5 + ))); + + construction.getUpgradeComponent().setUpgradeCostPack(DemoBuiltinConstructionsLoader.toPack(JavaFeatureForGwt.mapOf( + ResourceType.COIN, 50 + ))); + + return construction; + } +} diff --git a/IdleDemo-game/core/src/main/java/hundun/gdxgame/idledemo/ui/entity/GameEntityFactory.java b/IdleDemo-game/core/src/main/java/hundun/gdxgame/idledemo/ui/entity/GameEntityFactory.java index 671d860..07d9616 100644 --- a/IdleDemo-game/core/src/main/java/hundun/gdxgame/idledemo/ui/entity/GameEntityFactory.java +++ b/IdleDemo-game/core/src/main/java/hundun/gdxgame/idledemo/ui/entity/GameEntityFactory.java @@ -1,20 +1,10 @@ package hundun.gdxgame.idledemo.ui.entity; -import com.badlogic.gdx.Gdx; -import com.badlogic.gdx.graphics.g2d.Sprite; -import com.badlogic.gdx.graphics.g2d.TextureRegion; - -import hundun.gdxgame.idledemo.DemoIdleGame; -import hundun.gdxgame.idledemo.logic.ConstructionId; +import hundun.gdxgame.idledemo.logic.ConstructionPrototypeId; import hundun.gdxgame.idledemo.logic.ResourceType; import hundun.gdxgame.idledemo.ui.screen.DemoPlayScreen; -import hundun.gdxgame.idleshare.core.framework.BaseIdleGame; import hundun.gdxgame.idleshare.core.framework.model.entity.BaseGameEntityFactory; import hundun.gdxgame.idleshare.core.framework.model.entity.GameEntity; -import hundun.gdxgame.idleshare.core.framework.model.entity.RandomMoveEntity; -import hundun.gdxgame.idleshare.core.starter.ui.component.GameAreaControlBoard; -import hundun.gdxgame.idleshare.core.starter.ui.component.StorageInfoBoard; -import hundun.gdxgame.idleshare.core.starter.ui.screen.play.BaseIdlePlayScreen; import hundun.gdxgame.idleshare.core.starter.ui.screen.play.PlayScreenLayoutConst; /** @@ -35,12 +25,8 @@ public GameEntityFactory(PlayScreenLayoutConst layoutConst, DemoPlayScreen paren public GameEntity newConstructionEntity(String id, int index) { switch (id) { - case ConstructionId.COOKIE_CLICK_PROVIDER: - return null; - case ConstructionId.COOKIE_AUTO_PROVIDER: + case ConstructionPrototypeId.COOKIE_AUTO_PROVIDER: return this.rowStableConstructionEntity(id, index, 1); - case ConstructionId.COOKIE_SELLER: - return this.rowStableConstructionEntity(id, index, 0); default: // no need GameEntity return null; diff --git a/IdleDemo-game/core/src/main/java/hundun/gdxgame/idledemo/ui/screen/DemoPlayScreen.java b/IdleDemo-game/core/src/main/java/hundun/gdxgame/idledemo/ui/screen/DemoPlayScreen.java index c791218..46e5be9 100644 --- a/IdleDemo-game/core/src/main/java/hundun/gdxgame/idledemo/ui/screen/DemoPlayScreen.java +++ b/IdleDemo-game/core/src/main/java/hundun/gdxgame/idledemo/ui/screen/DemoPlayScreen.java @@ -1,35 +1,16 @@ package hundun.gdxgame.idledemo.ui.screen; -import com.badlogic.gdx.Gdx; -import com.badlogic.gdx.graphics.GL20; -import com.badlogic.gdx.graphics.Pixmap; -import com.badlogic.gdx.graphics.Texture; import com.badlogic.gdx.graphics.g2d.NinePatch; -import com.badlogic.gdx.graphics.g2d.TextureRegion; -import com.badlogic.gdx.scenes.scene2d.Stage; -import com.badlogic.gdx.scenes.scene2d.ui.Image; -import com.badlogic.gdx.scenes.scene2d.ui.Table; import com.badlogic.gdx.scenes.scene2d.utils.NinePatchDrawable; import com.badlogic.gdx.scenes.scene2d.utils.TextureRegionDrawable; -import com.badlogic.gdx.utils.viewport.FitViewport; import hundun.gdxgame.idledemo.DemoIdleGame; import hundun.gdxgame.idledemo.logic.GameArea; import hundun.gdxgame.idledemo.logic.ResourceType; import hundun.gdxgame.idledemo.logic.RootSaveData; import hundun.gdxgame.idledemo.ui.entity.GameEntityFactory; -import hundun.gdxgame.idleshare.core.starter.ui.component.AchievementMaskBoard; -import hundun.gdxgame.idleshare.core.starter.ui.component.BackgroundImageBox; -import hundun.gdxgame.idleshare.core.starter.ui.component.GameAreaControlBoard; -import hundun.gdxgame.idleshare.core.starter.ui.component.GameImageDrawer; -import hundun.gdxgame.idleshare.core.starter.ui.component.PopupInfoBoard; -import hundun.gdxgame.idleshare.core.starter.ui.component.StorageInfoBoard; -import hundun.gdxgame.idleshare.core.starter.ui.component.board.construction.impl.fixed.FixedConstructionControlBoard; -import hundun.gdxgame.idleshare.core.starter.ui.component.board.construction.impl.scroll.ScrollConstructionControlBoard; import hundun.gdxgame.idleshare.core.starter.ui.screen.play.BaseIdlePlayScreen; import hundun.gdxgame.idleshare.core.starter.ui.screen.play.PlayScreenLayoutConst; -import hundun.gdxgame.idleshare.gamelib.framework.model.AchievementPrototype; -import hundun.gdxgame.idleshare.gamelib.framework.model.construction.base.BaseConstruction; /** * @author hundun diff --git a/build.gradle b/build.gradle index be66331..449b586 100644 --- a/build.gradle +++ b/build.gradle @@ -79,8 +79,8 @@ project(":idleshare:desktop") { api "com.badlogicgames.gdx:gdx-backend-lwjgl:$gdxVersion" api "com.badlogicgames.gdx:gdx-platform:$gdxVersion:natives-desktop" api "com.badlogicgames.gdx:gdx-freetype-platform:$gdxVersion:natives-desktop" - - implementation group: 'com.fasterxml.jackson.core', name: 'jackson-databind', version: '2.10.5' + + api group: 'com.fasterxml.jackson.core', name: 'jackson-databind', version: '2.10.5' } } diff --git a/idleshare/core/src/hundun/gdxgame/idleshare/core/framework/BaseIdleGame.java b/idleshare/core/src/hundun/gdxgame/idleshare/core/framework/BaseIdleGame.java index fed4851..0148015 100644 --- a/idleshare/core/src/hundun/gdxgame/idleshare/core/framework/BaseIdleGame.java +++ b/idleshare/core/src/hundun/gdxgame/idleshare/core/framework/BaseIdleGame.java @@ -56,7 +56,7 @@ protected void createStage2() { protected void createStage3() { - audioPlayManager.lazyInit(childGameConfig.getScreenIdToFilePathMap()); + audioPlayManager.lazyInitOnGameCreate(childGameConfig.getScreenIdToFilePathMap()); } diff --git a/idleshare/core/src/hundun/gdxgame/idleshare/core/framework/model/manager/AbstractTextureManager.java b/idleshare/core/src/hundun/gdxgame/idleshare/core/framework/model/manager/AbstractTextureManager.java index 9db9015..5a5d243 100644 --- a/idleshare/core/src/hundun/gdxgame/idleshare/core/framework/model/manager/AbstractTextureManager.java +++ b/idleshare/core/src/hundun/gdxgame/idleshare/core/framework/model/manager/AbstractTextureManager.java @@ -11,7 +11,7 @@ public abstract class AbstractTextureManager { @Getter - protected Texture winTexture; + protected Texture achievementMaskBoardTexture; @Getter protected Texture menuTexture; diff --git a/idleshare/core/src/hundun/gdxgame/idleshare/core/framework/model/manager/AudioPlayManager.java b/idleshare/core/src/hundun/gdxgame/idleshare/core/framework/model/manager/AudioPlayManager.java index 1ba6ed8..0c25601 100644 --- a/idleshare/core/src/hundun/gdxgame/idleshare/core/framework/model/manager/AudioPlayManager.java +++ b/idleshare/core/src/hundun/gdxgame/idleshare/core/framework/model/manager/AudioPlayManager.java @@ -26,7 +26,7 @@ public AudioPlayManager(BaseIdleGame game) { this.game = game; } - public void lazyInit(Map screenIdToFilePathMap) { + public void lazyInitOnGameCreate(Map screenIdToFilePathMap) { if (screenIdToFilePathMap != null) { screenIdToFilePathMap.forEach((k, v) -> { try { diff --git a/idleshare/core/src/hundun/gdxgame/idleshare/core/framework/model/manager/GameEntityManager.java b/idleshare/core/src/hundun/gdxgame/idleshare/core/framework/model/manager/GameEntityManager.java index 182f18e..8cda4d8 100644 --- a/idleshare/core/src/hundun/gdxgame/idleshare/core/framework/model/manager/GameEntityManager.java +++ b/idleshare/core/src/hundun/gdxgame/idleshare/core/framework/model/manager/GameEntityManager.java @@ -24,7 +24,7 @@ public class GameEntityManager { private BaseIdleGame game; @Getter - private Map> gameEntitiesOfConstructionIds = new HashMap<>(); + private Map> gameEntitiesOfConstructionPrototypeIds = new HashMap>(); @Getter private Map> gameEntitiesOfResourceIds = new HashMap<>(); @Getter @@ -41,7 +41,7 @@ public GameEntityManager(BaseIdleGame game) { } public void allEntityMoveForFrame() { - for (Entry> entry : gameEntitiesOfConstructionIds.entrySet()) { + for (Entry> entry : gameEntitiesOfConstructionPrototypeIds.entrySet()) { List queue = entry.getValue(); queue.forEach(entity -> { entity.frameLogic(); @@ -102,7 +102,7 @@ private void positionChange(GameEntity entity) { } private void checkResourceEntityByOwnAmount(String resourceId, BaseGameEntityFactory gameEntityFactory) { - long resourceNum = game.getIdleGameplayExport().getResourceNumOrZero(resourceId); + long resourceNum = game.getIdleGameplayExport().getGameplayContext().getStorageManager().getResourceNumOrZero(resourceId); int drawNum = gameEntityFactory.calculateResourceDrawNum(resourceId, resourceNum); gameEntitiesOfResourceIds.computeIfAbsent(resourceId, k -> new LinkedList<>()); @@ -139,22 +139,22 @@ private void addResourceEntityByChangeAmount(String resourceId, BaseGameEntityFa } } - private void checkConstructionEntityByOwnAmount(String id, BaseGameEntityFactory gameEntityFactory) { - BaseConstruction construction = game.getIdleGameplayExport().getConstruction(id); - int resourceNum = construction.getSaveData().getWorkingLevel(); - int MAX_DRAW_NUM = construction.getMaxDrawNum(); - int drawNum = gameEntityFactory.calculateConstructionDrawNum(id, resourceNum, MAX_DRAW_NUM); - gameEntitiesOfConstructionIds.computeIfAbsent(id, k -> new LinkedList<>()); - List gameEntities = gameEntitiesOfConstructionIds.get(id); + private void checkConstructionEntityByOwnAmount(String prototypeId, BaseGameEntityFactory gameEntityFactory) { + List constructions = game.getIdleGameplayExport().getGameplayContext().getConstructionManager().getConstructionsOfPrototype(prototypeId); + int resourceNum = constructions.stream().mapToInt(it -> it.getSaveData().getWorkingLevel()).sum(); + int MAX_DRAW_NUM = 5; + int drawNum = gameEntityFactory.calculateConstructionDrawNum(prototypeId, resourceNum, MAX_DRAW_NUM); + gameEntitiesOfConstructionPrototypeIds.computeIfAbsent(prototypeId, k -> new LinkedList<>()); + List gameEntities = gameEntitiesOfConstructionPrototypeIds.get(prototypeId); while (gameEntities.size() > drawNum) { - Gdx.app.log(this.getClass().getSimpleName(), "checkConstructionEntityByOwnAmount " + id + " remove, current = " + gameEntities.size() + " , target = " + drawNum); + Gdx.app.log(this.getClass().getSimpleName(), "checkConstructionEntityByOwnAmount " + prototypeId + " remove, current = " + gameEntities.size() + " , target = " + drawNum); gameEntities.remove(gameEntities.size() - 1); } while (gameEntities.size() < drawNum) { int newIndex = gameEntities.size(); - GameEntity gameEntity = gameEntityFactory.newConstructionEntity(id, newIndex); + GameEntity gameEntity = gameEntityFactory.newConstructionEntity(prototypeId, newIndex); if (gameEntity != null) { - Gdx.app.log(this.getClass().getSimpleName(), "checkConstructionEntityByOwnAmount " + id + " new, current = " + gameEntities.size() + " , target = " + drawNum); + Gdx.app.log(this.getClass().getSimpleName(), "checkConstructionEntityByOwnAmount " + prototypeId + " new, current = " + gameEntities.size() + " , target = " + drawNum); gameEntities.add(gameEntity); } else { //Gdx.app.log(this.getClass().getSimpleName(), "checkConstructionEntityByOwnAmount " + id + " , cannot create new entity."); @@ -175,7 +175,7 @@ public void lazyInit(Map> areaShowEntityByOwnAmountConstruc * 某些引擎(如Unity)不光要在此处queue.clear(),还要queue.ForEach(entity => UnityEngine.Object.Destroy(entity.gameObject)); */ public void destoryNoNeedDrawConstructionIds(List needDrawConstructionIds) { - for (Entry> entry : gameEntitiesOfConstructionIds.entrySet()) { + for (Entry> entry : gameEntitiesOfConstructionPrototypeIds.entrySet()) { List queue = entry.getValue(); if (!needDrawConstructionIds.contains(entry.getKey())) { queue.clear(); diff --git a/idleshare/core/src/hundun/gdxgame/idleshare/core/starter/ui/component/AchievementMaskBoard.java b/idleshare/core/src/hundun/gdxgame/idleshare/core/starter/ui/component/AchievementMaskBoard.java index 85902ca..7d220b2 100644 --- a/idleshare/core/src/hundun/gdxgame/idleshare/core/starter/ui/component/AchievementMaskBoard.java +++ b/idleshare/core/src/hundun/gdxgame/idleshare/core/starter/ui/component/AchievementMaskBoard.java @@ -12,7 +12,7 @@ import hundun.gdxgame.idleshare.core.framework.BaseIdleGame; import hundun.gdxgame.idleshare.core.starter.ui.screen.play.BaseIdlePlayScreen; -import hundun.gdxgame.idleshare.gamelib.framework.model.AchievementPrototype; +import hundun.gdxgame.idleshare.gamelib.framework.model.AbstractAchievement; /** * @author hundun @@ -25,7 +25,7 @@ public class AchievementMaskBoard, T_SAVE> e public AchievementMaskBoard(BaseIdlePlayScreen parent) { this.parent = parent; - this.setBackground(new SpriteDrawable(new Sprite(parent.getGame().getTextureManager().getWinTexture()))); + this.setBackground(new SpriteDrawable(new Sprite(parent.getGame().getTextureManager().getAchievementMaskBoardTexture()))); this.setBounds(0, 0, Gdx.graphics.getWidth(), Gdx.graphics.getHeight()); label = new Label("", parent.getGame().getMainSkin()); @@ -43,7 +43,7 @@ public void clicked(InputEvent event, float x, float y) { this.setVisible(false); } - public void setAchievementPrototype(AchievementPrototype prototype) { + public void setAchievementPrototype(AbstractAchievement prototype) { label.setText(prototype.getDescription()); } } diff --git a/idleshare/core/src/hundun/gdxgame/idleshare/core/starter/ui/component/GameImageDrawer.java b/idleshare/core/src/hundun/gdxgame/idleshare/core/starter/ui/component/GameImageDrawer.java index d1d23f7..79f06a1 100644 --- a/idleshare/core/src/hundun/gdxgame/idleshare/core/starter/ui/component/GameImageDrawer.java +++ b/idleshare/core/src/hundun/gdxgame/idleshare/core/starter/ui/component/GameImageDrawer.java @@ -42,7 +42,7 @@ public void allEntitiesMoveForFrameAndDraw() { if (needDrawConstructionIds != null) { for (String id : needDrawConstructionIds) { - List queue = manager.getGameEntitiesOfConstructionIds().get(id); + List queue = manager.getGameEntitiesOfConstructionPrototypeIds().get(id); if (queue == null) { continue; } @@ -83,7 +83,7 @@ public void allEntitiesMoveForFrameAndDraw() { @Override - public void onResourceChange(Map changeMap) { + public void onResourceChange(Map changeMap, Map> deltaHistoryMap) { GameEntityManager manager = parent.getGameEntityManager(); String gameArea = parent.getArea(); diff --git a/idleshare/core/src/hundun/gdxgame/idleshare/core/starter/ui/component/PopupInfoBoard.java b/idleshare/core/src/hundun/gdxgame/idleshare/core/starter/ui/component/PopupInfoBoard.java index e51a647..a9814e1 100644 --- a/idleshare/core/src/hundun/gdxgame/idleshare/core/starter/ui/component/PopupInfoBoard.java +++ b/idleshare/core/src/hundun/gdxgame/idleshare/core/starter/ui/component/PopupInfoBoard.java @@ -8,7 +8,6 @@ import hundun.gdxgame.idleshare.core.framework.BaseIdleGame; import hundun.gdxgame.idleshare.core.starter.ui.screen.play.BaseIdlePlayScreen; -import hundun.gdxgame.idleshare.gamelib.export.IdleGameplayExport.ConstructionExportProxy; import hundun.gdxgame.idleshare.gamelib.framework.model.construction.base.BaseConstruction; import hundun.gdxgame.idleshare.gamelib.framework.model.construction.base.UpgradeComponent.UpgradeState; import hundun.gdxgame.idleshare.gamelib.framework.model.resource.ResourcePack; @@ -42,7 +41,7 @@ private Container wapperContainer(T content) { return container; } - private void rebuildCells(ConstructionExportProxy model) { + private void rebuildCells(BaseConstruction model) { this.clearChildren(); add(wapperContainer(new Label(model.getDetailDescroptionConstPart(), parent.getGame().getMainSkin()))) @@ -50,14 +49,14 @@ private void rebuildCells(ConstructionExportProxy model) { .left() .row(); - buildOnePack(model.getOutputCostPack()); + buildOnePack(model.getOutputComponent().getOutputCostPack()); - buildOnePack(model.getOutputGainPack()); + buildOnePack(model.getOutputComponent().getOutputGainPack()); - if (model.getUpgradeState() == UpgradeState.HAS_NEXT_UPGRADE) { - buildOnePack(model.getUpgradeCostPack()); - } else if (model.getUpgradeState() == UpgradeState.REACHED_MAX_UPGRADE) { - this.add(wapperContainer(new Label(model.getUpgradeCostPack().getDescriptionStart(), parent.getGame().getMainSkin()))); + if (model.getUpgradeComponent().getUpgradeState() == UpgradeState.HAS_NEXT_UPGRADE) { + buildOnePack(model.getUpgradeComponent().getUpgradeCostPack()); + } else if (model.getUpgradeComponent().getUpgradeState() == UpgradeState.REACHED_MAX_UPGRADE_HAS_TRANSFER) { + this.add(wapperContainer(new Label(model.getUpgradeComponent().getUpgradeCostPack().getDescriptionStart(), parent.getGame().getMainSkin()))); this.add(wapperContainer(new Label(model.getDescriptionPackage().getUpgradeMaxLevelDescription(), parent.getGame().getMainSkin()))); this.row(); } @@ -82,7 +81,7 @@ private void buildOnePack(ResourcePack pack) { } - public void update(ConstructionExportProxy model) { + public void update(BaseConstruction model) { rebuildCells(model); } diff --git a/idleshare/core/src/hundun/gdxgame/idleshare/core/starter/ui/component/StorageInfoBoard.java b/idleshare/core/src/hundun/gdxgame/idleshare/core/starter/ui/component/StorageInfoBoard.java index 0fc6953..a5add1c 100644 --- a/idleshare/core/src/hundun/gdxgame/idleshare/core/starter/ui/component/StorageInfoBoard.java +++ b/idleshare/core/src/hundun/gdxgame/idleshare/core/starter/ui/component/StorageInfoBoard.java @@ -86,14 +86,15 @@ public void updateViewData() { // .collect(Collectors.joining(" ")); // text += "\nBuffs = " + parent.game.getModelContext().getBuffManager().getBuffAmounts(); // mainLabel.setText(text); - boolean needRebuildCells = !shownTypes.equals(parent.getGame().getIdleGameplayExport().getUnlockedResourceTypes()); + Set unlockedResourceTypes = parent.getGame().getIdleGameplayExport().getGameplayContext().getStorageManager().getUnlockedResourceTypes(); + boolean needRebuildCells = !shownTypes.equals(unlockedResourceTypes); if (needRebuildCells) { shownTypes.clear(); - shownTypes.addAll(parent.getGame().getIdleGameplayExport().getUnlockedResourceTypes()); + shownTypes.addAll(unlockedResourceTypes); rebuildCells(); } - nodes.stream().forEach(node -> node.update(parent.getGame().getIdleGameplayExport().getResourceNumOrZero(node.getResourceType()))); + nodes.stream().forEach(node -> node.update(parent.getGame().getIdleGameplayExport().getGameplayContext().getStorageManager().getResourceNumOrZero(node.getResourceType()))); } @Override diff --git a/idleshare/core/src/hundun/gdxgame/idleshare/core/starter/ui/component/board/construction/AbstractConstructionControlBoard.java b/idleshare/core/src/hundun/gdxgame/idleshare/core/starter/ui/component/board/construction/AbstractConstructionControlBoard.java index 113d732..b2461de 100644 --- a/idleshare/core/src/hundun/gdxgame/idleshare/core/starter/ui/component/board/construction/AbstractConstructionControlBoard.java +++ b/idleshare/core/src/hundun/gdxgame/idleshare/core/starter/ui/component/board/construction/AbstractConstructionControlBoard.java @@ -17,10 +17,11 @@ import hundun.gdxgame.idleshare.core.framework.BaseIdleGame; import hundun.gdxgame.idleshare.core.starter.ui.component.board.construction.impl.ConstructionControlNode; import hundun.gdxgame.idleshare.core.starter.ui.screen.play.BaseIdlePlayScreen; -import hundun.gdxgame.idleshare.gamelib.export.IdleGameplayExport.ConstructionExportProxy; +import hundun.gdxgame.idleshare.gamelib.framework.callback.IConstructionCollectionListener; import hundun.gdxgame.idleshare.gamelib.framework.model.construction.base.BaseConstruction; -public abstract class AbstractConstructionControlBoard, T_SAVE> extends Table implements ILogicFrameListener, IGameAreaChangeListener { +public abstract class AbstractConstructionControlBoard, T_SAVE> extends Table + implements ILogicFrameListener, IGameAreaChangeListener, IConstructionCollectionListener { protected BaseIdlePlayScreen parent; /** * 显示在当前screen的Construction集合。以ConstructionView形式存在。 @@ -41,20 +42,28 @@ public void onLogicFrame() { @Override public void onGameAreaChange(String last, String current) { + onConstructionCollectionChange(); + } - - List newConstructions = parent.getGame().getIdleGameplayExport().getAreaShownConstructionsOrEmpty(current); + @Override + public void onConstructionCollectionChange() { + List newConstructions = parent.getGame().getIdleGameplayExport().getGameplayContext() + .getConstructionManager().getAreaControlableConstructionsOrEmpty(parent.getArea()); + newConstructions = filterConstructions(newConstructions); int childrenSize = initChild(newConstructions.size()); - for (int i = 0; i < childrenSize && i < newConstructions.size(); i++) { + for (int i = 0; i < childrenSize && i < newConstructions.size(); i++) + { constructionControlNodes.get(i).setModel(newConstructions.get(i)); } - for (int i = newConstructions.size(); i < childrenSize; i++) { + for (int i = newConstructions.size(); i < childrenSize; i++) + { constructionControlNodes.get(i).setModel(null); } - Gdx.app.log("ConstructionInfoBorad", "Constructions change to: " + newConstructions.stream().map(construction -> construction.getName()).collect(Collectors.joining(","))); - + parent.getGame().getFrontend().log("ConstructionInfoBorad", + "Constructions change to: " + newConstructions.stream().map(BaseConstruction::getName).collect(Collectors.joining(",")) + ); } /** @@ -62,4 +71,13 @@ public void onGameAreaChange(String last, String current) { * @return childrenSize */ protected abstract int initChild(int areaShownConstructionsSize); + + /** + * 子类可添加筛选 + */ + protected List filterConstructions(List constructions) + { + return constructions; + } + } diff --git a/idleshare/core/src/hundun/gdxgame/idleshare/core/starter/ui/component/board/construction/impl/ConstructionControlNode.java b/idleshare/core/src/hundun/gdxgame/idleshare/core/starter/ui/component/board/construction/impl/ConstructionControlNode.java index dff76ed..60f1cb2 100644 --- a/idleshare/core/src/hundun/gdxgame/idleshare/core/starter/ui/component/board/construction/impl/ConstructionControlNode.java +++ b/idleshare/core/src/hundun/gdxgame/idleshare/core/starter/ui/component/board/construction/impl/ConstructionControlNode.java @@ -14,7 +14,6 @@ import hundun.gdxgame.idleshare.core.framework.BaseIdleGame; import hundun.gdxgame.idleshare.core.starter.ui.screen.play.BaseIdlePlayScreen; import hundun.gdxgame.idleshare.core.starter.ui.screen.play.PlayScreenLayoutConst; -import hundun.gdxgame.idleshare.gamelib.export.IdleGameplayExport.ConstructionExportProxy; import hundun.gdxgame.idleshare.gamelib.framework.model.construction.base.BaseConstruction; @@ -24,13 +23,16 @@ */ public class ConstructionControlNode, T_SAVE> extends Table { BaseIdlePlayScreen parent; - ConstructionExportProxy model; + BaseConstruction model; Label constructionNameLabel; TextButton upWorkingLevelButton; TextButton downWorkingLevelButton; Label workingLevelLabel; - + Label proficiencyLabel; + Label positionLabel; TextButton clickEffectButton; + TextButton destoryButton; + TextButton transformButton; Table changeWorkingLevelGroup; @@ -53,7 +55,7 @@ public ConstructionControlNode(BaseIdlePlayScreen parent, int in @Override public void clicked(InputEvent event, float x, float y) { Gdx.app.log("ConstructionView", "clicked"); - parent.getGame().getIdleGameplayExport().constructionOnClick(model.getId()); + model.getOutputComponent().doOutput(); } }); @@ -93,7 +95,7 @@ public void exit(InputEvent event, float x, float y, int pointer, Actor toActor) @Override public void clicked(InputEvent event, float x, float y) { Gdx.app.log("ConstructionView", "down clicked"); - parent.getGame().getIdleGameplayExport().constructionChangeWorkingLevel(model.getId(), -1); + model.getLevelComponent().changeWorkingLevel(-1); } }); changeWorkingLevelGroup.add(downWorkingLevelButton).size(CHILD_WIDTH / 4, CHILD_HEIGHT); @@ -107,16 +109,20 @@ public void clicked(InputEvent event, float x, float y) { @Override public void clicked(InputEvent event, float x, float y) { Gdx.app.log(ConstructionControlNode.class.getSimpleName(), "up clicked"); - parent.getGame().getIdleGameplayExport().constructionChangeWorkingLevel(model.getId(), 1); + model.getLevelComponent().changeWorkingLevel(1); } }); changeWorkingLevelGroup.add(upWorkingLevelButton).size(CHILD_WIDTH / 4, CHILD_HEIGHT); - + this.proficiencyLabel = new Label("", parent.getGame().getMainSkin()); + this.positionLabel = new Label("", parent.getGame().getMainSkin()); + this.destoryButton = new TextButton("-", parent.getGame().getMainSkin()); + this.transformButton = new TextButton("-", parent.getGame().getMainSkin()); // ------ this ------ this.add(constructionNameLabel).size(CHILD_WIDTH, NAME_CHILD_HEIGHT).row(); this.add(clickEffectButton).size(CHILD_WIDTH, CHILD_HEIGHT).row(); - this.add(changeWorkingLevelGroup).size(CHILD_WIDTH, CHILD_HEIGHT); + this.add(changeWorkingLevelGroup).size(CHILD_WIDTH, CHILD_HEIGHT).row(); + this.add(proficiencyLabel).size(CHILD_WIDTH, CHILD_HEIGHT).row(); this.setBackground(DrawableFactory.createBorderBoard(30, 10, 0.8f, 1)); } @@ -143,10 +149,10 @@ private void initAsChangeWorkingLevelStyle() { } - public void setModel(ConstructionExportProxy constructionExportProxy) { + public void setModel(BaseConstruction constructionExportProxy) { this.model = constructionExportProxy; if (constructionExportProxy != null) { - if (constructionExportProxy.isWorkingLevelChangable()) { + if (constructionExportProxy.getLevelComponent().isWorkingLevelChangable()) { initAsChangeWorkingLevelStyle(); } else { initAsNormalStyle(); @@ -169,23 +175,42 @@ public void update() { } // ------ update text ------ constructionNameLabel.setText(model.getName()); - clickEffectButton.setText(model.getButtonDescroption()); - workingLevelLabel.setText(model.getWorkingLevelDescroption()); + clickEffectButton.setText(model.getDescriptionPackage().getButtonDescroption()); + workingLevelLabel.setText(model.getLevelComponent().getWorkingLevelDescroption()); + proficiencyLabel.setText(model.getProficiencyComponent().getProficiencyDescroption()); + positionLabel.setText(model.getSaveData().getPosition().toShowText()); + destoryButton.setText(model.descriptionPackage.getDestroyButtonDescroption()); // ------ update clickable-state ------ - boolean canClickEffect = parent.getGame().getIdleGameplayExport().constructionCanClickEffect(model.getId()); - //clickEffectButton.setTouchable(clickable ? Touchable.enabled : Touchable.disabled); - - - if (canClickEffect) { + if (model.getOutputComponent().canOutput()) { clickEffectButton.setDisabled(false); clickEffectButton.getLabel().setColor(Color.WHITE); } else { clickEffectButton.setDisabled(true); clickEffectButton.getLabel().setColor(Color.RED); } + if (model.getExistenceComponent().canDestory()) + { + destoryButton.setDisabled(false); + destoryButton.getLabel().setColor(Color.WHITE); + } + else + { + destoryButton.setDisabled(true); + destoryButton.getLabel().setColor(Color.RED); + } + if (model.getUpgradeComponent().canTransfer()) + { + transformButton.setDisabled(false); + transformButton.getLabel().setColor(Color.WHITE); + } + else + { + transformButton.setDisabled(true); + transformButton.getLabel().setColor(Color.RED); + } - boolean canUpWorkingLevel = parent.getGame().getIdleGameplayExport().constructionCanChangeWorkingLevel(model.getId(), 1); + boolean canUpWorkingLevel = model.getLevelComponent().canChangeWorkingLevel(1); if (canUpWorkingLevel) { upWorkingLevelButton.setDisabled(false); upWorkingLevelButton.getLabel().setColor(Color.WHITE); @@ -194,7 +219,7 @@ public void update() { upWorkingLevelButton.getLabel().setColor(Color.RED); } - boolean canDownWorkingLevel = parent.getGame().getIdleGameplayExport().constructionCanChangeWorkingLevel(model.getId(), -1); + boolean canDownWorkingLevel = model.getLevelComponent().canChangeWorkingLevel(-1); if (canDownWorkingLevel) { downWorkingLevelButton.setDisabled(false); downWorkingLevelButton.getLabel().setColor(Color.WHITE); diff --git a/idleshare/core/src/hundun/gdxgame/idleshare/core/starter/ui/screen/menu/BaseIdleMenuScreen.java b/idleshare/core/src/hundun/gdxgame/idleshare/core/starter/ui/screen/menu/BaseIdleMenuScreen.java index 8bb209f..ffe596c 100644 --- a/idleshare/core/src/hundun/gdxgame/idleshare/core/starter/ui/screen/menu/BaseIdleMenuScreen.java +++ b/idleshare/core/src/hundun/gdxgame/idleshare/core/starter/ui/screen/menu/BaseIdleMenuScreen.java @@ -42,9 +42,8 @@ public abstract class BaseIdleMenuScreen, T_ TextButton buttonContinueGame; TextButton buttonNewGame; TextButton buttonIntoSettingScreen; + LanguageSwitchBoard languageSwitchBoardVM; - - public BaseIdleMenuScreen(T_GAME game, InputListener buttonContinueGameInputListener, InputListener buttonNewGameInputListener) { @@ -92,14 +91,15 @@ private void initScene2d() { .fillY() .padTop(10) .row(); - - uiRootTable.add(new LanguageSwitchBoard<>(this, - Language.values(), + + this.languageSwitchBoardVM = new LanguageSwitchBoard<>(this, + Language.values(), game.getIdleGameplayExport().getLanguage(), memuScreenTexts.get(3), memuScreenTexts.get(4), - it -> game.getIdleGameplayExport().setLanguage(it)) - ) + it -> game.getIdleGameplayExport().setLanguage(it) + ); + uiRootTable.add(languageSwitchBoardVM) .padTop(10); if (game.debugMode) { diff --git a/idleshare/core/src/hundun/gdxgame/idleshare/core/starter/ui/screen/play/BaseIdlePlayScreen.java b/idleshare/core/src/hundun/gdxgame/idleshare/core/starter/ui/screen/play/BaseIdlePlayScreen.java index fef8b63..b5c3a3b 100644 --- a/idleshare/core/src/hundun/gdxgame/idleshare/core/starter/ui/screen/play/BaseIdlePlayScreen.java +++ b/idleshare/core/src/hundun/gdxgame/idleshare/core/starter/ui/screen/play/BaseIdlePlayScreen.java @@ -3,7 +3,10 @@ import com.badlogic.gdx.Gdx; import com.badlogic.gdx.scenes.scene2d.ui.Image; -import hundun.gdxgame.corelib.starter.StarterPlayScreen; +import hundun.gdxgame.corelib.base.BaseHundunScreen; +import hundun.gdxgame.gamelib.base.LogicFrameHelper; +import hundun.gdxgame.gamelib.starter.listerner.IGameAreaChangeListener; +import hundun.gdxgame.gamelib.starter.listerner.ILogicFrameListener; import hundun.gdxgame.idleshare.core.framework.BaseIdleGame; import hundun.gdxgame.idleshare.core.framework.model.manager.GameEntityManager; import hundun.gdxgame.idleshare.core.starter.ui.component.AchievementMaskBoard; @@ -14,13 +17,16 @@ import hundun.gdxgame.idleshare.core.starter.ui.component.StorageInfoBoard; import hundun.gdxgame.idleshare.core.starter.ui.component.board.construction.AbstractConstructionControlBoard; import hundun.gdxgame.idleshare.core.starter.ui.component.board.construction.impl.fixed.FixedConstructionControlBoard; -import hundun.gdxgame.idleshare.gamelib.export.IdleGameplayExport.ConstructionExportProxy; import hundun.gdxgame.idleshare.gamelib.framework.callback.IAchievementUnlockCallback; import hundun.gdxgame.idleshare.gamelib.framework.callback.ISecondaryInfoBoardCallback; -import hundun.gdxgame.idleshare.gamelib.framework.model.AchievementPrototype; +import hundun.gdxgame.idleshare.gamelib.framework.model.AbstractAchievement; import hundun.gdxgame.idleshare.gamelib.framework.model.construction.base.BaseConstruction; import lombok.Getter; +import java.util.ArrayList; +import java.util.List; +import java.util.Map; + /** * @author hundun @@ -28,8 +34,8 @@ * @param */ public abstract class BaseIdlePlayScreen, T_SAVE> - extends StarterPlayScreen - implements IAchievementUnlockCallback, ISecondaryInfoBoardCallback { + extends BaseHundunScreen + implements IAchievementUnlockCallback, ISecondaryInfoBoardCallback { public static final int LOGIC_FRAME_PER_SECOND = 30; @@ -45,12 +51,22 @@ public abstract class BaseIdlePlayScreen, T_ protected AbstractConstructionControlBoard constructionControlBoard; protected BackgroundImageBox backgroundImageBox; protected GameAreaControlBoard gameAreaControlBoard; + // ----- not ui ------ @Getter protected GameEntityManager gameEntityManager; - + @Getter + protected String area; + private final String startArea; + protected List logicFrameListeners; + protected List gameAreaChangeListeners; + public BaseIdlePlayScreen(T_GAME game, String startArea, PlayScreenLayoutConst layoutConst) { - super(game, startArea, game.getSharedViewport(), LOGIC_FRAME_PER_SECOND); + super(game, game.getSharedViewport()); this.layoutConst = layoutConst; + this.startArea = startArea; + this.logicFrameHelper = new LogicFrameHelper(LOGIC_FRAME_PER_SECOND); + this.logicFrameListeners = new ArrayList<>(); + this.gameAreaChangeListeners = new ArrayList<>(); } @Override @@ -70,7 +86,7 @@ public void hideAchievementMaskBoard() { } @Override - public void onAchievementUnlock(AchievementPrototype prototype) { + public void showAchievementMaskBoard(AbstractAchievement prototype) { game.getFrontend().log(this.getClass().getSimpleName(), "onAchievementUnlock called"); achievementMaskBoard.setAchievementPrototype(prototype); achievementMaskBoard.setVisible(true); @@ -79,7 +95,7 @@ public void onAchievementUnlock(AchievementPrototype prototype) { } @Override - public void showAndUpdateGuideInfo(ConstructionExportProxy model) { + public void showAndUpdateGuideInfo(BaseConstruction model) { secondaryInfoBoard.setVisible(true); secondaryInfoBoard.update(model); } @@ -93,7 +109,11 @@ public void hideAndCleanGuideInfo() { protected void lazyInitLogicContext() { this.gameImageDrawer = new GameImageDrawer<>(this); this.gameEntityManager = new GameEntityManager(game); - gameEntityManager.lazyInit(game.getChildGameConfig().getAreaShowEntityByOwnAmountConstructionIds(), game.getChildGameConfig().getAreaShowEntityByOwnAmountResourceIds(), game.getChildGameConfig().getAreaShowEntityByChangeAmountResourceIds()); + gameEntityManager.lazyInit( + game.getChildGameConfig().getAreaShowEntityByOwnAmountConstructionPrototypeIds(), + game.getChildGameConfig().getAreaShowEntityByOwnAmountResourceIds(), + game.getChildGameConfig().getAreaShowEntityByChangeAmountResourceIds() + ); logicFrameListeners.add(constructionControlBoard); logicFrameListeners.add(game.getIdleGameplayExport()); @@ -102,8 +122,8 @@ protected void lazyInitLogicContext() { gameAreaChangeListeners.add(constructionControlBoard); gameAreaChangeListeners.add(gameAreaControlBoard); - this.getGame().getIdleGameplayExport().eventManagerRegisterListener(this); - this.getGame().getIdleGameplayExport().eventManagerRegisterListener(gameImageDrawer); + this.getGame().getIdleGameplayExport().getGameplayContext().getEventManager().registerListener(this); + this.getGame().getIdleGameplayExport().getGameplayContext().getEventManager().registerListener(gameImageDrawer); } @@ -149,7 +169,44 @@ protected void lazyInitBackUiAndPopupUiContent() { protected void gameObjectDraw(float delta) { gameImageDrawer.allEntitiesMoveForFrameAndDraw(); } - - - + + @Override + protected void onLogicFrame() { + super.onLogicFrame(); + + for (ILogicFrameListener logicFrameListener : logicFrameListeners) { + logicFrameListener.onLogicFrame(); + } + } + + @Override + public void show() { + super.show(); + + Gdx.input.setInputProcessor(uiStage); + game.getBatch().setProjectionMatrix(uiStage.getViewport().getCamera().combined); + + backUiStage.clear(); + popupRootTable.clear(); + lazyInitBackUiAndPopupUiContent(); + + uiRootTable.clear(); + lazyInitUiRootContext(); + + lazyInitLogicContext(); + + // start area + setAreaAndNotifyChildren(startArea); + Gdx.app.log(this.getClass().getSimpleName(), "show done"); + } + + public void setAreaAndNotifyChildren(String current) { + String last = this.area; + this.area = current; + + for (IGameAreaChangeListener gameAreaChangeListener : gameAreaChangeListeners) { + gameAreaChangeListener.onGameAreaChange(last, current); + } + + } } diff --git a/idleshare/gamelib/src/hundun/gdxgame/idleshare/gamelib/export/IdleGameplayExport.java b/idleshare/gamelib/src/hundun/gdxgame/idleshare/gamelib/export/IdleGameplayExport.java index 3a896c2..7746729 100644 --- a/idleshare/gamelib/src/hundun/gdxgame/idleshare/gamelib/export/IdleGameplayExport.java +++ b/idleshare/gamelib/src/hundun/gdxgame/idleshare/gamelib/export/IdleGameplayExport.java @@ -13,6 +13,7 @@ import hundun.gdxgame.idleshare.gamelib.framework.data.ChildGameConfig; import hundun.gdxgame.idleshare.gamelib.framework.data.GameplaySaveData; import hundun.gdxgame.idleshare.gamelib.framework.data.SystemSettingSaveData; +import hundun.gdxgame.idleshare.gamelib.framework.model.IBuiltinAchievementsLoader; import hundun.gdxgame.idleshare.gamelib.framework.model.construction.BaseConstructionFactory; import hundun.gdxgame.idleshare.gamelib.framework.model.construction.base.BaseConstruction; import hundun.gdxgame.idleshare.gamelib.framework.model.construction.base.DescriptionPackage; @@ -34,144 +35,55 @@ public class IdleGameplayExport implements ILogicFrameListener, ISubGameplaySaveHandler, ISubSystemSettingSaveHandler { + @Getter private IdleGameplayContext gameplayContext; private IBuiltinConstructionsLoader builtinConstructionsLoader; + private IBuiltinAchievementsLoader builtinAchievementsLoader; private ChildGameConfig childGameConfig; @Getter private IGameDictionary gameDictionary; @Setter @Getter private Language language; - + public String stageId; + public IdleGameplayExport( IFrontend frontEnd, IGameDictionary gameDictionary, IBuiltinConstructionsLoader builtinConstructionsLoader, + IBuiltinAchievementsLoader builtinAchievementsLoader, int LOGIC_FRAME_PER_SECOND, ChildGameConfig childGameConfig) { this.gameDictionary = gameDictionary; this.builtinConstructionsLoader = builtinConstructionsLoader; + this.builtinAchievementsLoader = builtinAchievementsLoader; this.childGameConfig = childGameConfig; this.gameplayContext = new IdleGameplayContext(frontEnd, gameDictionary, LOGIC_FRAME_PER_SECOND); } - public long getResourceNumOrZero(String resourceId) { - return gameplayContext.getStorageManager().getResourceNumOrZero(resourceId); - } - - public BaseConstruction getConstruction(String id) { - return gameplayContext.getConstructionFactory().getConstruction(id); - } - @Override public void onLogicFrame() { gameplayContext.getConstructionManager().onSubLogicFrame(); gameplayContext.getStorageManager().onSubLogicFrame(); } + @Override + public void applyGameplaySaveData(GameplaySaveData gameplaySaveData) { + this.stageId = gameplaySaveData.getStageId(); - public static class ConstructionExportProxy { - - private BaseConstruction model; - @Getter - String id; - @Getter - String name; - @Getter - DescriptionPackage descriptionPackage; - @Getter - ResourcePack outputGainPack; - @Getter - ResourcePack outputCostPack; - @Getter - UpgradeState upgradeState; - @Getter - ResourcePack upgradeCostPack; - - private static ConstructionExportProxy fromModel(BaseConstruction model) { - ConstructionExportProxy result = new ConstructionExportProxy(); - result.model = model; - result.id = model.getId(); - result.name = model.getName(); - result.outputCostPack = (model.getOutputComponent().getOutputCostPack()); - result.outputGainPack = (model.getOutputComponent().getOutputGainPack()); - result.upgradeState = (model.getUpgradeComponent().getUpgradeState()); - result.upgradeCostPack = (model.getUpgradeComponent().getUpgradeCostPack()); - result.descriptionPackage = (model.getDescriptionPackage()); - - return result; - } - - // ------- need runtime calculate ------ - - public boolean isWorkingLevelChangable() { - return model.getLevelComponent().isWorkingLevelChangable(); - } - - public String getButtonDescroption() { - return model.getButtonDescroption(); - } - - public String getDetailDescroptionConstPart() { - return model.getDetailDescroptionConstPart(); - } - - public String getWorkingLevelDescroption() { - return model.getLevelComponent().getWorkingLevelDescroption(); - } - } - - public List getAreaShownConstructionsOrEmpty(String current) { - return gameplayContext.getConstructionManager().getAreaShownConstructionsOrEmpty(current).stream() - .map(it -> ConstructionExportProxy.fromModel(it)) - .collect(Collectors.toList()) - ; - } - - public void eventManagerRegisterListener(Object object) { - gameplayContext.getEventManager().registerListener(object); - } - - public Set getUnlockedResourceTypes() { - return gameplayContext.getStorageManager().getUnlockedResourceTypes(); - } - public void constructionChangeWorkingLevel(String id, int delta) { - BaseConstruction model = gameplayContext.getConstructionFactory().getConstruction(id); - model.getLevelComponent().changeWorkingLevel(delta); - } + gameplaySaveData.getConstructionSaveDataMap().values().forEach(it -> { + gameplayContext.getConstructionManager().loadInstance(it); + }); - public void constructionOnClick(String id) { - BaseConstruction model = gameplayContext.getConstructionFactory().getConstruction(id); - model.onClick(); - } - - public boolean constructionCanClickEffect(String id) { - BaseConstruction model = gameplayContext.getConstructionFactory().getConstruction(id); - return model.canClickEffect(); - } - - public boolean constructionCanChangeWorkingLevel(String id, int delta) { - BaseConstruction model = gameplayContext.getConstructionFactory().getConstruction(id); - return model.getLevelComponent().canChangeWorkingLevel(delta); - } - - @Override - public void applyGameplaySaveData(GameplaySaveData gameplaySaveData) { - Collection constructions = gameplayContext.getConstructionFactory().getConstructions(); - for (BaseConstruction construction : constructions) { - if (gameplaySaveData.getConstructionSaveDataMap().containsKey(construction.getId())) { - construction.setSaveData(gameplaySaveData.getConstructionSaveDataMap().get(construction.getId())); - construction.updateModifiedValues(); - } - } gameplayContext.getStorageManager().setUnlockedResourceTypes(gameplaySaveData.getUnlockedResourceTypes()); gameplayContext.getStorageManager().setOwnResoueces(gameplaySaveData.getOwnResoueces()); - gameplayContext.getAchievementManager().setUnlockedAchievementNames(gameplaySaveData.getUnlockedAchievementNames()); + gameplayContext.getAchievementManager().setUnlockedAchievementIds(gameplaySaveData.getUnlockedAchievementIds()); } @Override public void currentSituationToGameplaySaveData(GameplaySaveData gameplaySaveData) { - Collection constructions = gameplayContext.getConstructionFactory().getConstructions(); + gameplaySaveData.setStageId(this.stageId); + List constructions = gameplayContext.getConstructionManager().getConstructions(); gameplaySaveData.setConstructionSaveDataMap(constructions.stream() .collect(Collectors.toMap( it -> it.getId(), @@ -180,7 +92,7 @@ public void currentSituationToGameplaySaveData(GameplaySaveData gameplaySaveData ); gameplaySaveData.setUnlockedResourceTypes(gameplayContext.getStorageManager().getUnlockedResourceTypes()); gameplaySaveData.setOwnResoueces(gameplayContext.getStorageManager().getOwnResoueces()); - gameplaySaveData.setUnlockedAchievementNames(gameplayContext.getAchievementManager().getUnlockedAchievementNames()); + gameplaySaveData.setUnlockedAchievementIds(gameplayContext.getAchievementManager().getUnlockedAchievementIds()); } @Override @@ -188,8 +100,9 @@ public void applySystemSetting(SystemSettingSaveData systemSettingSave) { this.language = systemSettingSave.getLanguage(); gameplayContext.allLazyInit( systemSettingSave.getLanguage(), - childGameConfig, - builtinConstructionsLoader.provide(systemSettingSave.getLanguage()) + childGameConfig, + builtinConstructionsLoader.getProviderMap(language), + builtinAchievementsLoader.getProviderMap(language) ); gameplayContext.getFrontEnd().log(this.getClass().getSimpleName(), "applySystemSetting done"); } @@ -199,5 +112,4 @@ public void currentSituationToSystemSetting(SystemSettingSaveData systemSettingS systemSettingSave.setLanguage(this.getLanguage()); } - } diff --git a/idleshare/gamelib/src/hundun/gdxgame/idleshare/gamelib/framework/IdleGameplayContext.java b/idleshare/gamelib/src/hundun/gdxgame/idleshare/gamelib/framework/IdleGameplayContext.java index 3f26129..a695a08 100644 --- a/idleshare/gamelib/src/hundun/gdxgame/idleshare/gamelib/framework/IdleGameplayContext.java +++ b/idleshare/gamelib/src/hundun/gdxgame/idleshare/gamelib/framework/IdleGameplayContext.java @@ -2,11 +2,14 @@ import java.util.Collection; import java.util.List; +import java.util.Map; import java.util.stream.Collectors; import hundun.gdxgame.gamelib.base.IFrontend; import hundun.gdxgame.idleshare.gamelib.framework.data.ChildGameConfig; import hundun.gdxgame.idleshare.gamelib.framework.data.GameplaySaveData; +import hundun.gdxgame.idleshare.gamelib.framework.model.AbstractAchievement; +import hundun.gdxgame.idleshare.gamelib.framework.model.construction.AbstractConstructionPrototype; import hundun.gdxgame.idleshare.gamelib.framework.model.construction.BaseConstructionFactory; import hundun.gdxgame.idleshare.gamelib.framework.model.construction.base.BaseConstruction; import hundun.gdxgame.idleshare.gamelib.framework.model.construction.base.DescriptionPackageFactory; @@ -60,10 +63,16 @@ public IdleGameplayContext( } - public void allLazyInit(Language language, ChildGameConfig childGameConfig, List constructions) { - this.getConstructionFactory().lazyInit(this, language, constructions); - this.getConstructionManager().lazyInit(childGameConfig.getAreaControlableConstructionIds()); - this.getAchievementManager().lazyInit(childGameConfig.getAchievementPrototypes()); + public void allLazyInit( + Language language, + ChildGameConfig childGameConfig, + Map providerMap, + Map achievementProviderMap + ) { + this.getConstructionFactory().lazyInit(this, language, providerMap); + this.getConstructionManager().lazyInit(childGameConfig.getAreaControlableConstructionVMPrototypeIds(), + childGameConfig.getAreaControlableConstructionPrototypeVMPrototypeIds()); + this.getAchievementManager().lazyInit(achievementProviderMap, childGameConfig.getAchievementPrototypeIds()); } } diff --git a/idleshare/gamelib/src/hundun/gdxgame/idleshare/gamelib/framework/callback/IAchievementUnlockCallback.java b/idleshare/gamelib/src/hundun/gdxgame/idleshare/gamelib/framework/callback/IAchievementUnlockCallback.java index d9a80eb..b16c6d7 100644 --- a/idleshare/gamelib/src/hundun/gdxgame/idleshare/gamelib/framework/callback/IAchievementUnlockCallback.java +++ b/idleshare/gamelib/src/hundun/gdxgame/idleshare/gamelib/framework/callback/IAchievementUnlockCallback.java @@ -1,6 +1,9 @@ package hundun.gdxgame.idleshare.gamelib.framework.callback; -import hundun.gdxgame.idleshare.gamelib.framework.model.AchievementPrototype; +import hundun.gdxgame.idleshare.gamelib.framework.model.AbstractAchievement; + +import java.util.List; +import java.util.Map; /** * @author hundun @@ -8,5 +11,5 @@ */ public interface IAchievementUnlockCallback { void hideAchievementMaskBoard(); - void onAchievementUnlock(AchievementPrototype prototype); + void showAchievementMaskBoard(AbstractAchievement prototype); } diff --git a/idleshare/gamelib/src/hundun/gdxgame/idleshare/gamelib/framework/callback/IConstructionCollectionListener.java b/idleshare/gamelib/src/hundun/gdxgame/idleshare/gamelib/framework/callback/IConstructionCollectionListener.java new file mode 100644 index 0000000..d234f50 --- /dev/null +++ b/idleshare/gamelib/src/hundun/gdxgame/idleshare/gamelib/framework/callback/IConstructionCollectionListener.java @@ -0,0 +1,5 @@ +package hundun.gdxgame.idleshare.gamelib.framework.callback; + +public interface IConstructionCollectionListener { + void onConstructionCollectionChange(); +} diff --git a/idleshare/gamelib/src/hundun/gdxgame/idleshare/gamelib/framework/callback/INotificationBoardCallerAndCallback.java b/idleshare/gamelib/src/hundun/gdxgame/idleshare/gamelib/framework/callback/INotificationBoardCallerAndCallback.java new file mode 100644 index 0000000..00a2d07 --- /dev/null +++ b/idleshare/gamelib/src/hundun/gdxgame/idleshare/gamelib/framework/callback/INotificationBoardCallerAndCallback.java @@ -0,0 +1,6 @@ +package hundun.gdxgame.idleshare.gamelib.framework.callback; + +public interface INotificationBoardCallerAndCallback { + void hideNotificationMaskBoard(); + void showNotificationMaskBoard(String data); +} diff --git a/idleshare/gamelib/src/hundun/gdxgame/idleshare/gamelib/framework/data/ChildGameConfig.java b/idleshare/gamelib/src/hundun/gdxgame/idleshare/gamelib/framework/data/ChildGameConfig.java index 7fcee5b..54dcb35 100644 --- a/idleshare/gamelib/src/hundun/gdxgame/idleshare/gamelib/framework/data/ChildGameConfig.java +++ b/idleshare/gamelib/src/hundun/gdxgame/idleshare/gamelib/framework/data/ChildGameConfig.java @@ -3,8 +3,7 @@ import java.util.List; import java.util.Map; -import hundun.gdxgame.idleshare.gamelib.framework.model.AchievementPrototype; -import hundun.gdxgame.idleshare.gamelib.framework.model.construction.base.BaseConstruction; +import hundun.gdxgame.idleshare.gamelib.framework.model.AbstractAchievement; import lombok.Getter; import lombok.Setter; @@ -15,10 +14,11 @@ @Getter @Setter public abstract class ChildGameConfig { - Map> areaControlableConstructionIds; - Map> areaShowEntityByOwnAmountConstructionIds; + Map> areaControlableConstructionVMPrototypeIds; + Map> areaControlableConstructionPrototypeVMPrototypeIds; + Map> areaShowEntityByOwnAmountConstructionPrototypeIds; Map> areaShowEntityByOwnAmountResourceIds; Map> areaShowEntityByChangeAmountResourceIds; Map screenIdToFilePathMap; - List achievementPrototypes; + List achievementPrototypeIds; } diff --git a/idleshare/gamelib/src/hundun/gdxgame/idleshare/gamelib/framework/data/ConstructionSaveData.java b/idleshare/gamelib/src/hundun/gdxgame/idleshare/gamelib/framework/data/ConstructionSaveData.java index 00d12ee..ddadcb2 100644 --- a/idleshare/gamelib/src/hundun/gdxgame/idleshare/gamelib/framework/data/ConstructionSaveData.java +++ b/idleshare/gamelib/src/hundun/gdxgame/idleshare/gamelib/framework/data/ConstructionSaveData.java @@ -1,5 +1,6 @@ package hundun.gdxgame.idleshare.gamelib.framework.data; +import hundun.gdxgame.idleshare.gamelib.framework.model.grid.GridPosition; import lombok.AllArgsConstructor; import lombok.Builder; import lombok.NoArgsConstructor; @@ -14,6 +15,9 @@ @AllArgsConstructor @NoArgsConstructor public class ConstructionSaveData { + public String prototypeId; private int level; private int workingLevel; + private int proficiency; + private GridPosition position; } diff --git a/idleshare/gamelib/src/hundun/gdxgame/idleshare/gamelib/framework/data/GameplaySaveData.java b/idleshare/gamelib/src/hundun/gdxgame/idleshare/gamelib/framework/data/GameplaySaveData.java index ffa7d92..2e680b9 100644 --- a/idleshare/gamelib/src/hundun/gdxgame/idleshare/gamelib/framework/data/GameplaySaveData.java +++ b/idleshare/gamelib/src/hundun/gdxgame/idleshare/gamelib/framework/data/GameplaySaveData.java @@ -18,9 +18,9 @@ @AllArgsConstructor @NoArgsConstructor public class GameplaySaveData { + String stageId; Map ownResoueces; Set unlockedResourceTypes; Map constructionSaveDataMap; - Set unlockedAchievementNames; - + Set unlockedAchievementIds; } diff --git a/idleshare/gamelib/src/hundun/gdxgame/idleshare/gamelib/framework/listener/IOneFrameResourceChangeListener.java b/idleshare/gamelib/src/hundun/gdxgame/idleshare/gamelib/framework/listener/IOneFrameResourceChangeListener.java index 6b98d80..f964198 100644 --- a/idleshare/gamelib/src/hundun/gdxgame/idleshare/gamelib/framework/listener/IOneFrameResourceChangeListener.java +++ b/idleshare/gamelib/src/hundun/gdxgame/idleshare/gamelib/framework/listener/IOneFrameResourceChangeListener.java @@ -1,5 +1,6 @@ package hundun.gdxgame.idleshare.gamelib.framework.listener; +import java.util.List; import java.util.Map; /** @@ -7,5 +8,5 @@ * Created on 2022/02/08 */ public interface IOneFrameResourceChangeListener { - void onResourceChange(Map changeMap); + void onResourceChange(Map changeMap, Map> deltaHistoryMap); } diff --git a/idleshare/gamelib/src/hundun/gdxgame/idleshare/gamelib/framework/model/AbstractAchievement.java b/idleshare/gamelib/src/hundun/gdxgame/idleshare/gamelib/framework/model/AbstractAchievement.java new file mode 100644 index 0000000..49de6da --- /dev/null +++ b/idleshare/gamelib/src/hundun/gdxgame/idleshare/gamelib/framework/model/AbstractAchievement.java @@ -0,0 +1,31 @@ +package hundun.gdxgame.idleshare.gamelib.framework.model; + +import hundun.gdxgame.idleshare.gamelib.framework.IdleGameplayContext; +import lombok.AllArgsConstructor; +import lombok.Data; +import lombok.NoArgsConstructor; + +import java.util.Map; + +/** + * @author hundun + * Created on 2021/11/12 + */ +@Data +@AllArgsConstructor +@NoArgsConstructor +public abstract class AbstractAchievement { + protected IdleGameplayContext gameplayContext; + protected String id; + protected String name; + protected String description; + protected String congratulationText; + protected Map awardResourceMap; + + public abstract boolean checkUnlock(); + + public void lazyInitDescription(IdleGameplayContext gameplayContext) + { + this.gameplayContext = gameplayContext; + } +} diff --git a/idleshare/gamelib/src/hundun/gdxgame/idleshare/gamelib/framework/model/AchievementPrototype.java b/idleshare/gamelib/src/hundun/gdxgame/idleshare/gamelib/framework/model/AchievementPrototype.java deleted file mode 100644 index 6a308f9..0000000 --- a/idleshare/gamelib/src/hundun/gdxgame/idleshare/gamelib/framework/model/AchievementPrototype.java +++ /dev/null @@ -1,51 +0,0 @@ -package hundun.gdxgame.idleshare.gamelib.framework.model; - -import java.util.Map; - -/** - * @author hundun - * Created on 2021/11/12 - */ -public class AchievementPrototype { - String name; - String description; - Map requiredBuffs; - Map requiredResources; - - // ------ replace-lombok ------ - public AchievementPrototype() { - } - public AchievementPrototype(String name, String description, Map requiredBuffs, - Map requiredResources) { - super(); - this.name = name; - this.description = description; - this.requiredBuffs = requiredBuffs; - this.requiredResources = requiredResources; - } - public String getName() { - return name; - } - public void setName(String name) { - this.name = name; - } - public String getDescription() { - return description; - } - public void setDescription(String description) { - this.description = description; - } - public Map getRequiredBuffs() { - return requiredBuffs; - } - public void setRequiredBuffs(Map requiredBuffs) { - this.requiredBuffs = requiredBuffs; - } - public Map getRequiredResources() { - return requiredResources; - } - public void setRequiredResources(Map requiredResources) { - this.requiredResources = requiredResources; - } - -} diff --git a/idleshare/gamelib/src/hundun/gdxgame/idleshare/gamelib/framework/model/IBuiltinAchievementsLoader.java b/idleshare/gamelib/src/hundun/gdxgame/idleshare/gamelib/framework/model/IBuiltinAchievementsLoader.java new file mode 100644 index 0000000..7b9b37f --- /dev/null +++ b/idleshare/gamelib/src/hundun/gdxgame/idleshare/gamelib/framework/model/IBuiltinAchievementsLoader.java @@ -0,0 +1,9 @@ +package hundun.gdxgame.idleshare.gamelib.framework.model; + +import hundun.gdxgame.idleshare.gamelib.framework.util.text.Language; + +import java.util.Map; + +public interface IBuiltinAchievementsLoader { + Map getProviderMap(Language language); +} diff --git a/idleshare/gamelib/src/hundun/gdxgame/idleshare/gamelib/framework/model/construction/AbstractConstructionPrototype.java b/idleshare/gamelib/src/hundun/gdxgame/idleshare/gamelib/framework/model/construction/AbstractConstructionPrototype.java new file mode 100644 index 0000000..ff0b8fc --- /dev/null +++ b/idleshare/gamelib/src/hundun/gdxgame/idleshare/gamelib/framework/model/construction/AbstractConstructionPrototype.java @@ -0,0 +1,44 @@ +package hundun.gdxgame.idleshare.gamelib.framework.model.construction; + +import hundun.gdxgame.idleshare.gamelib.framework.IdleGameplayContext; +import hundun.gdxgame.idleshare.gamelib.framework.model.construction.base.BaseConstruction; +import hundun.gdxgame.idleshare.gamelib.framework.model.construction.base.DescriptionPackage; +import hundun.gdxgame.idleshare.gamelib.framework.model.grid.GridPosition; +import hundun.gdxgame.idleshare.gamelib.framework.model.resource.ResourcePack; +import hundun.gdxgame.idleshare.gamelib.framework.util.text.Language; +import lombok.Getter; + +@Getter +public abstract class AbstractConstructionPrototype { + + protected String prototypeId; + protected Language language; + protected ResourcePack buyInstanceCostPack; + + protected DescriptionPackage descriptionPackage; + + public AbstractConstructionPrototype(String prototypeId, + Language language, + ResourcePack buyInstanceCostPack + ) + { + this.prototypeId = prototypeId; + this.language = language; + this.buyInstanceCostPack = buyInstanceCostPack; + + if (buyInstanceCostPack != null) + { + buyInstanceCostPack.setModifiedValues(buyInstanceCostPack.getBaseValues()); + buyInstanceCostPack.setModifiedValuesDescription(ResourcePack.toDescription(buyInstanceCostPack.getModifiedValues())); + } + } + + public void lazyInitDescription(IdleGameplayContext gameContext, Language language) { + if (buyInstanceCostPack != null) + { + buyInstanceCostPack.setDescriptionStart(gameContext.getGameDictionary().getPlayScreenTexts(language).get(1)); + } + } + + public abstract BaseConstruction getInstance(GridPosition position); +} diff --git a/idleshare/gamelib/src/hundun/gdxgame/idleshare/gamelib/framework/model/construction/BaseAutoConstruction.java b/idleshare/gamelib/src/hundun/gdxgame/idleshare/gamelib/framework/model/construction/BaseAutoConstruction.java deleted file mode 100644 index 9b0099f..0000000 --- a/idleshare/gamelib/src/hundun/gdxgame/idleshare/gamelib/framework/model/construction/BaseAutoConstruction.java +++ /dev/null @@ -1,94 +0,0 @@ -package hundun.gdxgame.idleshare.gamelib.framework.model.construction; - -import java.util.List; - -import hundun.gdxgame.idleshare.gamelib.framework.IdleGameplayContext; -import hundun.gdxgame.idleshare.gamelib.framework.model.construction.base.BaseConstruction; -import hundun.gdxgame.idleshare.gamelib.framework.model.resource.ResourcePair; -/** - * @author hundun - * Created on 2021/11/10 - */ -public class BaseAutoConstruction extends BaseConstruction { - - protected int autoOutputProgress = 0; - - - public BaseAutoConstruction(String id - ) { - super(id); - } - - @Override - protected void printDebugInfoAfterConstructed() { - super.printDebugInfoAfterConstructed(); - StringBuilder builder = new StringBuilder(); - for (int i = 0; i < maxLevel; i++) { - builder.append(i).append("->").append(upgradeComponent.getCalculateCostFunction().apply(1L, i)).append(","); - } - gameContext.getFrontEnd().log(this.id, "getUpgradeCost=[" + builder.toString() + "]"); - } - - - @Override - public void onClick() { - if (!canClickEffect()) { - return; - } - doUpgrade(); - } - - private void doUpgrade() { - List upgradeCostRule = upgradeComponent.getUpgradeCostPack().getModifiedValues(); - gameContext.getStorageManager().modifyAllResourceNum(upgradeCostRule, false); - saveData.setLevel(saveData.getLevel() + 1); - if (!levelComponent.isWorkingLevelChangable()) { - saveData.setWorkingLevel(saveData.getLevel()); - } - updateModifiedValues(); - } - - @Override - public boolean canClickEffect() { - return canUpgrade(); - } - - - @Override - public void onLogicFrame() { - autoOutputProgress++; - int logicFrameCountMax = outputComponent.getAutoOutputSecondCountMax() * gameContext.LOGIC_FRAME_PER_SECOND; - if (autoOutputProgress >= logicFrameCountMax) { - autoOutputProgress = 0; - tryAutoOutputOnce(); - } - } - - private void tryAutoOutputOnce() { - if (!canOutput()) { - gameContext.getFrontEnd().log(this.id, "canOutput"); - return; - } - gameContext.getFrontEnd().log(this.id, "AutoOutput"); - if (outputComponent.hasCost()) { - gameContext.getStorageManager().modifyAllResourceNum(outputComponent.getOutputCostPack().getModifiedValues(), false); - } - if (outputComponent.getOutputGainPack() != null) { - gameContext.getStorageManager().modifyAllResourceNum(outputComponent.getOutputGainPack().getModifiedValues(), true); - } - } - - @Override - protected long calculateModifiedOutput(long baseValue, int level) { - return baseValue * level; - } - - @Override - protected long calculateModifiedOutputCost(long baseValue, int level) { - return baseValue * level; - } - - - - -} diff --git a/idleshare/gamelib/src/hundun/gdxgame/idleshare/gamelib/framework/model/construction/BaseBuffConstruction.java b/idleshare/gamelib/src/hundun/gdxgame/idleshare/gamelib/framework/model/construction/BaseBuffConstruction.java deleted file mode 100644 index 5332389..0000000 --- a/idleshare/gamelib/src/hundun/gdxgame/idleshare/gamelib/framework/model/construction/BaseBuffConstruction.java +++ /dev/null @@ -1,59 +0,0 @@ -package hundun.gdxgame.idleshare.gamelib.framework.model.construction; - -import java.util.List; - -import hundun.gdxgame.idleshare.gamelib.framework.IdleGameplayContext; -import hundun.gdxgame.idleshare.gamelib.framework.model.construction.base.BaseConstruction; -import hundun.gdxgame.idleshare.gamelib.framework.model.resource.ResourcePair; - -/** - * @author hundun - * Created on 2021/11/10 - */ -public class BaseBuffConstruction extends BaseConstruction { - - private final String buffId; - - public BaseBuffConstruction(String id, String buffId) { - super(id); - this.buffId = buffId; - } - - @Override - public void onLogicFrame() { - // do nothing - } - - @Override - public void onClick() { - if (!canUpgrade()) { - return; - } - doEnhanceBuff(); - } - - private void doEnhanceBuff() { - List upgradeCostRule = upgradeComponent.getUpgradeCostPack().getModifiedValues(); - gameContext.getStorageManager().modifyAllResourceNum(upgradeCostRule, false); - saveData.setLevel(saveData.getLevel() + 1); - gameContext.getBuffManager().addBuffAmout(buffId, 1); - updateModifiedValues(); - } - - @Override - public boolean canClickEffect() { - return canUpgrade(); - } - - @Override - protected long calculateModifiedOutput(long baseValue, int level) { - throw new UnsupportedOperationException(); - } - - @Override - protected long calculateModifiedOutputCost(long baseValue, int level) { - throw new UnsupportedOperationException(); - } - - -} diff --git a/idleshare/gamelib/src/hundun/gdxgame/idleshare/gamelib/framework/model/construction/BaseClickGatherConstruction.java b/idleshare/gamelib/src/hundun/gdxgame/idleshare/gamelib/framework/model/construction/BaseClickGatherConstruction.java deleted file mode 100644 index d31c611..0000000 --- a/idleshare/gamelib/src/hundun/gdxgame/idleshare/gamelib/framework/model/construction/BaseClickGatherConstruction.java +++ /dev/null @@ -1,55 +0,0 @@ -package hundun.gdxgame.idleshare.gamelib.framework.model.construction; - -import hundun.gdxgame.idleshare.gamelib.framework.IdleGameplayContext; -import hundun.gdxgame.idleshare.gamelib.framework.model.construction.base.BaseConstruction; - - -/** - * @author hundun - * Created on 2021/11/10 - */ -public class BaseClickGatherConstruction extends BaseConstruction { - - public BaseClickGatherConstruction(String id - ) { - super(id); - } - - @Override - public void onClick() { - if (!canClickEffect()) { - return; - } - doGather(); - } - - private void doGather() { - if (outputComponent.hasCost()) { - gameContext.getStorageManager().modifyAllResourceNum(outputComponent.getOutputCostPack().getModifiedValues(), false); - } - gameContext.getStorageManager().modifyAllResourceNum(outputComponent.getOutputGainPack().getModifiedValues(), true); - } - - @Override - public boolean canClickEffect() { - return canOutput(); - } - - - @Override - public void onLogicFrame() { - // do nothing - } - - @Override - protected long calculateModifiedOutput(long baseValue, int level) { - return baseValue; - } - - @Override - protected long calculateModifiedOutputCost(long baseValue, int level) { - return baseValue; - } - - -} diff --git a/idleshare/gamelib/src/hundun/gdxgame/idleshare/gamelib/framework/model/construction/BaseConstructionFactory.java b/idleshare/gamelib/src/hundun/gdxgame/idleshare/gamelib/framework/model/construction/BaseConstructionFactory.java index a9815d1..1d8da79 100644 --- a/idleshare/gamelib/src/hundun/gdxgame/idleshare/gamelib/framework/model/construction/BaseConstructionFactory.java +++ b/idleshare/gamelib/src/hundun/gdxgame/idleshare/gamelib/framework/model/construction/BaseConstructionFactory.java @@ -1,12 +1,12 @@ package hundun.gdxgame.idleshare.gamelib.framework.model.construction; -import java.util.Collection; import java.util.HashMap; import java.util.List; import java.util.Map; import hundun.gdxgame.idleshare.gamelib.framework.IdleGameplayContext; import hundun.gdxgame.idleshare.gamelib.framework.model.construction.base.BaseConstruction; +import hundun.gdxgame.idleshare.gamelib.framework.model.grid.GridPosition; import hundun.gdxgame.idleshare.gamelib.framework.util.text.Language; /** @@ -15,25 +15,36 @@ */ public class BaseConstructionFactory { - Map constructions = new HashMap<>(); + IdleGameplayContext gameContext; + Language language; + Map providerMap; - public BaseConstruction getConstruction(String id) { - BaseConstruction result = constructions.get(id); - if (result == null) { - throw new RuntimeException("getConstruction " + id + " not found"); - } - return result; + public void lazyInit( + IdleGameplayContext gameContext, + Language language, + Map providerMap + ) { + this.language = language; + this.providerMap = providerMap; + this.gameContext = gameContext; } - public Collection getConstructions() { - return constructions.values(); + public AbstractConstructionPrototype getPrototype(String prototypeId) + { + AbstractConstructionPrototype prototype = providerMap.get(prototypeId); + prototype.lazyInitDescription(gameContext, language); + return prototype; } - public void lazyInit(IdleGameplayContext gameContext, Language language, List constructions) { - constructions.forEach(item -> this.constructions.put(item.getId(), item)); - this.constructions.values().forEach(it -> { - it.lazyInitDescription(gameContext, language); - gameContext.getEventManager().registerListener(it); - }); + + public BaseConstruction getInstanceOfPrototype(String prototypeId, GridPosition position) + { + AbstractConstructionPrototype prototype = providerMap.get(prototypeId); + BaseConstruction construction = prototype.getInstance(position); + construction.lazyInitDescription(gameContext, language); + gameContext.getEventManager().registerListener(construction); + return construction; } + + } diff --git a/idleshare/gamelib/src/hundun/gdxgame/idleshare/gamelib/framework/model/construction/base/BaseConstruction.java b/idleshare/gamelib/src/hundun/gdxgame/idleshare/gamelib/framework/model/construction/base/BaseConstruction.java index c7ca631..20f5f39 100644 --- a/idleshare/gamelib/src/hundun/gdxgame/idleshare/gamelib/framework/model/construction/base/BaseConstruction.java +++ b/idleshare/gamelib/src/hundun/gdxgame/idleshare/gamelib/framework/model/construction/base/BaseConstruction.java @@ -4,19 +4,21 @@ * Created on 2021/11/05 */ +import java.util.Map; import java.util.Random; import hundun.gdxgame.gamelib.starter.listerner.ILogicFrameListener; import hundun.gdxgame.idleshare.gamelib.framework.IdleGameplayContext; import hundun.gdxgame.idleshare.gamelib.framework.data.ConstructionSaveData; import hundun.gdxgame.idleshare.gamelib.framework.listener.IBuffChangeListener; -import hundun.gdxgame.idleshare.gamelib.framework.model.construction.base.DescriptionPackage.ILevelDescroptionProvider; -import hundun.gdxgame.idleshare.gamelib.framework.util.text.IGameDictionary; +import hundun.gdxgame.idleshare.gamelib.framework.model.grid.GridPosition; +import hundun.gdxgame.idleshare.gamelib.framework.model.grid.ITileNode; import hundun.gdxgame.idleshare.gamelib.framework.util.text.Language; import lombok.Getter; import lombok.Setter; -public abstract class BaseConstruction implements ILogicFrameListener, IBuffChangeListener { +public abstract class BaseConstruction implements IBuffChangeListener, ITileNode { + protected static final int DEFAULT_MAX_LEVEL = 99; @Getter @@ -33,7 +35,7 @@ public abstract class BaseConstruction implements ILogicFrameListener, IBuffChan protected Random random = new Random(); @Getter - protected IdleGameplayContext gameContext; + protected IdleGameplayContext gameplayContext; /** * NotNull @@ -47,7 +49,8 @@ public abstract class BaseConstruction implements ILogicFrameListener, IBuffChan @Getter protected String id; - + @Getter + protected String prototypeId; @Getter protected String detailDescroptionConstPart; @@ -76,13 +79,51 @@ public abstract class BaseConstruction implements ILogicFrameListener, IBuffChan @Getter @Setter protected LevelComponent levelComponent; + /** + * NotNull + */ + @Getter + @Setter + protected ProficiencyComponent proficiencyComponent; + + /** + * NotNull + */ + @Getter + @Setter + protected ExistenceComponent existenceComponent; + + @Getter + @Setter + protected boolean allowPositionOverwrite = false; + Map> neighbors; + + @Override + public GridPosition getPosition() { + return saveData.getPosition(); + } + + @Override + public void setPosition(GridPosition position) { + saveData.setPosition(position); + } + + @Override + public Map> getNeighbors() { + return neighbors; + } + + @Override + public void setNeighbors(Map> neighbors) { + this.neighbors = neighbors; + } public void lazyInitDescription(IdleGameplayContext gameContext, Language language) { - this.gameContext = gameContext; + this.gameplayContext = gameContext; - this.name = gameContext.getGameDictionary().constructionIdToShowName(language, id); - this.detailDescroptionConstPart = gameContext.getGameDictionary().constructionIdToDetailDescroptionConstPart(language, id); + this.name = gameContext.getGameDictionary().constructionPrototypeIdToShowName(language, id); + this.detailDescroptionConstPart = gameContext.getGameDictionary().constructionPrototypeIdToDetailDescroptionConstPart(language, id); outputComponent.lazyInitDescription(); upgradeComponent.lazyInitDescription(); @@ -90,34 +131,20 @@ public void lazyInitDescription(IdleGameplayContext gameContext, Language langua updateModifiedValues(); } - public BaseConstruction(String id) { - - this.saveData = new ConstructionSaveData(); + public BaseConstruction(String prototypeId, String id) { + this.prototypeId = prototypeId; this.id = id; - } - - public abstract void onClick(); - - public abstract boolean canClickEffect(); + this.saveData = new ConstructionSaveData(); - public String getButtonDescroption() { - return descriptionPackage.getButtonDescroption(); } - //protected abstract long calculateModifiedUpgradeCost(long baseValue, int level); - protected abstract long calculateModifiedOutput(long baseValue, int level); - protected abstract long calculateModifiedOutputCost(long baseValue, int level); - - - /** * 重新计算各个数值的加成后的结果 */ public void updateModifiedValues() { - gameContext.getFrontEnd().log(this.name, "updateCurrentCache called"); + gameplayContext.getFrontEnd().log(this.name, "updateCurrentCache called"); // -------------- - boolean reachMaxLevel = this.getSaveData().getLevel() == this.getMaxLevel(); - upgradeComponent.updateModifiedValues(reachMaxLevel); + upgradeComponent.updateModifiedValues(); outputComponent.updateModifiedValues(); } @@ -132,17 +159,10 @@ protected void printDebugInfoAfterConstructed() { // default do nothing } - protected boolean canOutput() { - return outputComponent.canOutput(); - } - - - protected boolean canUpgrade() { - return upgradeComponent.canUpgrade(); - } - - public String getSaveDataKey() { - return id; + public void onSubLogicFrame() + { + outputComponent.onSubLogicFrame(); + proficiencyComponent.onSubLogicFrame(); } diff --git a/idleshare/gamelib/src/hundun/gdxgame/idleshare/gamelib/framework/model/construction/base/DescriptionPackage.java b/idleshare/gamelib/src/hundun/gdxgame/idleshare/gamelib/framework/model/construction/base/DescriptionPackage.java index 7bdc8e9..e6d377e 100644 --- a/idleshare/gamelib/src/hundun/gdxgame/idleshare/gamelib/framework/model/construction/base/DescriptionPackage.java +++ b/idleshare/gamelib/src/hundun/gdxgame/idleshare/gamelib/framework/model/construction/base/DescriptionPackage.java @@ -13,19 +13,32 @@ @Data @AllArgsConstructor @NoArgsConstructor +@Builder public class DescriptionPackage { + String buttonDescroption; + String outputCostDescriptionStart; String outputGainDescriptionStart; + String upgradeCostDescriptionStart; String upgradeMaxLevelDescription; - String buttonDescroption; - ILevelDescroptionProvider levelDescroptionProvider; - public static interface ILevelDescroptionProvider { + private String transformButtonDescroption; + private String transformCostDescriptionStart; + private String upgradeMaxLevelHasTransferDescription; - + private String destroyButtonDescroption; + private String destroyGainDescriptionStart; + private String destroyCostDescriptionStart; + ILevelDescroptionProvider levelDescroptionProvider; + + private IProficiencyDescroptionProvider proficiencyDescroptionProvider; + + public static interface ILevelDescroptionProvider { String provide(int level, int workingLevel, boolean reachMaxLevel); } - + public static interface IProficiencyDescroptionProvider { + String provide(int proficiency, Boolean reachMaxProficiency); + } } diff --git a/idleshare/gamelib/src/hundun/gdxgame/idleshare/gamelib/framework/model/construction/base/DescriptionPackageFactory.java b/idleshare/gamelib/src/hundun/gdxgame/idleshare/gamelib/framework/model/construction/base/DescriptionPackageFactory.java index 15f8dd3..0b759ee 100644 --- a/idleshare/gamelib/src/hundun/gdxgame/idleshare/gamelib/framework/model/construction/base/DescriptionPackageFactory.java +++ b/idleshare/gamelib/src/hundun/gdxgame/idleshare/gamelib/framework/model/construction/base/DescriptionPackageFactory.java @@ -1,6 +1,7 @@ package hundun.gdxgame.idleshare.gamelib.framework.model.construction.base; import hundun.gdxgame.idleshare.gamelib.framework.model.construction.base.DescriptionPackage.ILevelDescroptionProvider; +import hundun.gdxgame.idleshare.gamelib.framework.model.construction.base.DescriptionPackage.IProficiencyDescroptionProvider; import hundun.gdxgame.idleshare.gamelib.framework.util.text.Language; /** @@ -8,93 +9,34 @@ * Created on 2023/03/01 */ public class DescriptionPackageFactory { - - private static ILevelDescroptionProvider EMPTY_IMP = (level, workingLevel, reachMaxLevel) -> ""; - private static ILevelDescroptionProvider ONLY_LEVEL_IMP = (level, workingLevel, reachMaxLevel) -> { + + public static ILevelDescroptionProvider NO_LEVEL_IMP = (level, workingLevel, reachMaxLevel) -> ""; + public static ILevelDescroptionProvider ONLY_LEVEL_IMP = (level, workingLevel, reachMaxLevel) -> { return "lv." + level; }; - private static ILevelDescroptionProvider WORKING_LEVEL_IMP = (level, workingLevel, reachMaxLevel) -> { + public static ILevelDescroptionProvider WORKING_LEVEL_IMP = (level, workingLevel, reachMaxLevel) -> { return "lv." + workingLevel + "/" + level + (reachMaxLevel ? "(max)" : ""); }; - private static ILevelDescroptionProvider LOCK_IMP = (level, workingLevel, reachMaxLevel) -> { + public static ILevelDescroptionProvider LOCK_IMP = (level, workingLevel, reachMaxLevel) -> { return (reachMaxLevel ? "Unlocked" : ""); }; - - private static ILevelDescroptionProvider CN_EMPTY_IMP = (level, workingLevel, reachMaxLevel) -> ""; - private static ILevelDescroptionProvider CN_ONLY_LEVEL_IMP = (level, workingLevel, reachMaxLevel) -> { + public static IProficiencyDescroptionProvider EN_PROFICIENCY_IMP = (proficiency, reachMaxProficiency) -> { + return "efficiency: " + proficiency; + }; + + public static ILevelDescroptionProvider CN_NO_LEVEL_IMP = (level, workingLevel, reachMaxLevel) -> ""; + public static ILevelDescroptionProvider CN_ONLY_LEVEL_IMP = (level, workingLevel, reachMaxLevel) -> { return "等级" + level; }; - private static ILevelDescroptionProvider CN_WORKING_LEVEL_IMP = (level, workingLevel, reachMaxLevel) -> { + public static ILevelDescroptionProvider CN_WORKING_LEVEL_IMP = (level, workingLevel, reachMaxLevel) -> { return "等级" +workingLevel + "/" + level + (reachMaxLevel ? "(最大)" : ""); }; - private static ILevelDescroptionProvider CN_LOCK_IMP = (level, workingLevel, reachMaxLevel) -> { + public static ILevelDescroptionProvider CN_LOCK_IMP = (level, workingLevel, reachMaxLevel) -> { return (reachMaxLevel ? "已解锁" : ""); }; - - public static DescriptionPackage getWorkingLevelAutoDescriptionPackage(Language language) { - switch (language) { - case CN: - return new DescriptionPackage( - "自动消耗", "自动产出", "升级费用", "(已达到最大等级)", "升级", - CN_WORKING_LEVEL_IMP); - default: - return new DescriptionPackage( - "AutoCost", "AutoGain", "UpgradeCost", "(max level)", "Upgrade", - WORKING_LEVEL_IMP); - } - } - - public static DescriptionPackage getMaxLevelAutoDescriptionPackage(Language language) { - switch (language) { - case CN: - return new DescriptionPackage( - "自动消耗", "自动产出", "升级费用", "(已达到最大等级)", "升级", - CN_ONLY_LEVEL_IMP); - default: - return new DescriptionPackage( - "AutoCost", "AutoGain", "UpgradeCost", "(max level)", "Upgrade", - ONLY_LEVEL_IMP); - } - } - - public static DescriptionPackage getSellingDescriptionPackage(Language language) { - switch (language) { - case CN: - return new DescriptionPackage( - "自动出售", "自动获得", "升级费用", "(已达到最大等级)", "升级", - CN_WORKING_LEVEL_IMP); - default: - return new DescriptionPackage( - "Sell", "Gain", "UpgradeCost", "(max level)", "Upgrade", - WORKING_LEVEL_IMP); - } - } - - public static DescriptionPackage getGatherDescriptionPackage(Language language) { - switch (language) { - case CN: - return new DescriptionPackage( - "消耗", "获得", null, null, "采集", - CN_EMPTY_IMP); - default: - return new DescriptionPackage( - "Pay", "Gain", null, null, "Gather", - EMPTY_IMP); - } - } - - - public static DescriptionPackage getWinDescriptionPackage(Language language) { - switch (language) { - case CN: - return new DescriptionPackage( - null, null, "支付", null, "解锁", - CN_LOCK_IMP); - default: - return new DescriptionPackage( - null, null, "Pay", null, "Unlock", - LOCK_IMP); - } - } + public static IProficiencyDescroptionProvider CN_PROFICIENCY_IMP = (proficiency, reachMaxProficiency) -> { + return "效率" + proficiency; + }; + } diff --git a/idleshare/gamelib/src/hundun/gdxgame/idleshare/gamelib/framework/model/construction/base/ExistenceComponent.java b/idleshare/gamelib/src/hundun/gdxgame/idleshare/gamelib/framework/model/construction/base/ExistenceComponent.java new file mode 100644 index 0000000..186e9ab --- /dev/null +++ b/idleshare/gamelib/src/hundun/gdxgame/idleshare/gamelib/framework/model/construction/base/ExistenceComponent.java @@ -0,0 +1,65 @@ +package hundun.gdxgame.idleshare.gamelib.framework.model.construction.base; + +import hundun.gdxgame.idleshare.gamelib.framework.model.resource.ResourcePack; + +public class ExistenceComponent { + private final BaseConstruction construction; + + /** + * Nullable + */ + public ResourcePack destoryCostPack; + /** + * Nullable + */ + public ResourcePack destoryGainPack; + + public boolean allowAnyProficiencyDestory; + + public ExistenceComponent(BaseConstruction construction) + { + this.construction = construction; + + } + + public void lazyInitDescription() + { + if (destoryGainPack != null && destoryCostPack != null) + { + this.destoryGainPack.setDescriptionStart(construction.descriptionPackage.getDestroyGainDescriptionStart()); + this.destoryCostPack.setDescriptionStart(construction.descriptionPackage.getDestroyCostDescriptionStart()); + } + } + + public void updateModifiedValues() + { + if (destoryGainPack != null && destoryCostPack != null) + { + destoryCostPack.setModifiedValues(destoryCostPack.getBaseValues()); + destoryCostPack.setModifiedValuesDescription(ResourcePack.toDescription(destoryCostPack.getModifiedValues())); + destoryGainPack.setModifiedValues(destoryGainPack.getBaseValues()); + destoryGainPack.setModifiedValuesDescription(ResourcePack.toDescription(destoryGainPack.getModifiedValues())); + } + } + + public Boolean canDestory() + { + if (!allowAnyProficiencyDestory && !construction.proficiencyComponent.isMaxProficiency()) + { + return false; + } + return destoryGainPack != null && destoryCostPack != null && construction.gameplayContext.getStorageManager().isEnough(destoryCostPack.getModifiedValues()); + } + + public void doDestory(String constructionPrototypeIdOfEmpty) + { + construction.gameplayContext.getConstructionManager().addToRemoveQueue(construction); + construction.gameplayContext.getStorageManager().modifyAllResourceNum(construction.existenceComponent.destoryCostPack.getModifiedValues(), false); + construction.gameplayContext.getStorageManager().modifyAllResourceNum(construction.existenceComponent.destoryGainPack.getModifiedValues(), true); + + if (constructionPrototypeIdOfEmpty != null) + { + construction.gameplayContext.getConstructionManager().addToCreateQueue(constructionPrototypeIdOfEmpty, construction.getPosition()); + } + } +} diff --git a/idleshare/gamelib/src/hundun/gdxgame/idleshare/gamelib/framework/model/construction/base/IBuiltinConstructionsLoader.java b/idleshare/gamelib/src/hundun/gdxgame/idleshare/gamelib/framework/model/construction/base/IBuiltinConstructionsLoader.java index 87bb285..49c7cf5 100644 --- a/idleshare/gamelib/src/hundun/gdxgame/idleshare/gamelib/framework/model/construction/base/IBuiltinConstructionsLoader.java +++ b/idleshare/gamelib/src/hundun/gdxgame/idleshare/gamelib/framework/model/construction/base/IBuiltinConstructionsLoader.java @@ -1,7 +1,9 @@ package hundun.gdxgame.idleshare.gamelib.framework.model.construction.base; import java.util.List; +import java.util.Map; +import hundun.gdxgame.idleshare.gamelib.framework.model.construction.AbstractConstructionPrototype; import hundun.gdxgame.idleshare.gamelib.framework.util.text.IGameDictionary; import hundun.gdxgame.idleshare.gamelib.framework.util.text.Language; @@ -10,5 +12,5 @@ * Created on 2023/03/01 */ public interface IBuiltinConstructionsLoader { - List provide(Language language); + Map getProviderMap(Language language); } diff --git a/idleshare/gamelib/src/hundun/gdxgame/idleshare/gamelib/framework/model/construction/base/LevelComponent.java b/idleshare/gamelib/src/hundun/gdxgame/idleshare/gamelib/framework/model/construction/base/LevelComponent.java index 2dcb056..04c5572 100644 --- a/idleshare/gamelib/src/hundun/gdxgame/idleshare/gamelib/framework/model/construction/base/LevelComponent.java +++ b/idleshare/gamelib/src/hundun/gdxgame/idleshare/gamelib/framework/model/construction/base/LevelComponent.java @@ -13,7 +13,10 @@ public class LevelComponent { @Getter private final boolean workingLevelChangable; - + public static final int DEFAULT_MIN_WORKING_LEVEL = 0; + public int minWorkingLevel = DEFAULT_MIN_WORKING_LEVEL; + public static final int DEFAULT_MAX_LEVEL = 5; + public int maxLevel = DEFAULT_MAX_LEVEL; public LevelComponent(BaseConstruction construction, boolean workingLevelChangable) { super(); this.construction = construction; @@ -21,7 +24,7 @@ public LevelComponent(BaseConstruction construction, boolean workingLevelChangab } public String getWorkingLevelDescroption() { - boolean reachMaxLevel = construction.getSaveData().getLevel() == construction.getMaxLevel(); + boolean reachMaxLevel = construction.getSaveData().getLevel() == this.maxLevel; return construction.descriptionPackage.getLevelDescroptionProvider().provide(construction.saveData.getLevel(), construction.saveData.getWorkingLevel(), reachMaxLevel); } @@ -30,7 +33,7 @@ public boolean canChangeWorkingLevel(int delta) { return false; } int next = construction.saveData.getWorkingLevel() + delta; - if (next > construction.saveData.getLevel() || next < 0) { + if (next > construction.saveData.getLevel() || next < minWorkingLevel) { return false; } return true; @@ -40,10 +43,15 @@ public void changeWorkingLevel(int delta) { if (canChangeWorkingLevel(delta)) { construction.saveData.setWorkingLevel(construction.saveData.getWorkingLevel() + delta); construction.updateModifiedValues(); - construction.getGameContext().getFrontEnd().log(construction.name, "changeWorkingLevel delta = " + delta + ", success to " + construction.saveData.getWorkingLevel()); + construction.getGameplayContext().getFrontEnd().log(construction.name, "changeWorkingLevel delta = " + delta + ", success to " + construction.saveData.getWorkingLevel()); } else { - construction.getGameContext().getFrontEnd().log(construction.name, "changeWorkingLevel delta = " + delta + ", but cannot!"); + construction.getGameplayContext().getFrontEnd().log(construction.name, "changeWorkingLevel delta = " + delta + ", but cannot!"); } } + public boolean isReachMaxLevel() + { + return construction.saveData.getLevel() >= this.maxLevel; + } + } diff --git a/idleshare/gamelib/src/hundun/gdxgame/idleshare/gamelib/framework/model/construction/base/OutputComponent.java b/idleshare/gamelib/src/hundun/gdxgame/idleshare/gamelib/framework/model/construction/base/OutputComponent.java index 69c8697..8a9581a 100644 --- a/idleshare/gamelib/src/hundun/gdxgame/idleshare/gamelib/framework/model/construction/base/OutputComponent.java +++ b/idleshare/gamelib/src/hundun/gdxgame/idleshare/gamelib/framework/model/construction/base/OutputComponent.java @@ -13,8 +13,8 @@ * @author hundun * Created on 2021/12/17 */ -public class OutputComponent { - private final BaseConstruction construction; +public abstract class OutputComponent { + protected final BaseConstruction construction; /** * 对于Click型,即为基础点击收益;对于Auto型,即为基础自动收益; @@ -32,10 +32,10 @@ public class OutputComponent { protected ResourcePack outputCostPack; - private static final int DEFAULT_AUTO_OUPUT_SECOND_MAX = 1; + protected static final int DEFAULT_AUTO_OUPUT_SECOND_MAX = 1; @Getter @Setter - private int autoOutputSecondCountMax = DEFAULT_AUTO_OUPUT_SECOND_MAX; + protected int autoOutputSecondCountMax = DEFAULT_AUTO_OUPUT_SECOND_MAX; public OutputComponent(BaseConstruction construction) { this.construction = construction; @@ -56,7 +56,11 @@ public void updateModifiedValues() { outputGainPack.setModifiedValues( outputGainPack.getBaseValues().stream() .map(pair -> { - long newAmout = construction.calculateModifiedOutput(pair.getAmount(), construction.saveData.getWorkingLevel()); + long newAmout = this.calculateModifiedOutputGain( + pair.getAmount(), + construction.saveData.getWorkingLevel(), + construction.saveData.getProficiency() + ); return new ResourcePair(pair.getType(), newAmout); }) .collect(Collectors.toList()) @@ -73,7 +77,11 @@ public void updateModifiedValues() { outputCostPack.setModifiedValues( outputCostPack.getBaseValues().stream() .map(pair -> { - long newAmout = construction.calculateModifiedOutputCost(pair.getAmount(), construction.saveData.getWorkingLevel()); + long newAmout = this.calculateModifiedOutputCost( + pair.getAmount(), + construction.saveData.getWorkingLevel(), + construction.saveData.getProficiency() + ); return new ResourcePair(pair.getType(), newAmout); }) .collect(Collectors.toList()) @@ -91,12 +99,28 @@ public boolean hasCost() { return outputCostPack != null; } - protected boolean canOutput() { + public boolean canOutput() { if (!hasCost()) { return true; } List compareTarget = outputCostPack.getModifiedValues(); - return construction.getGameContext().getStorageManager().isEnough(compareTarget); + return construction.getGameplayContext().getStorageManager().isEnough(compareTarget); } + + public void doOutput() + { + if (this.hasCost()) + { + construction.getGameplayContext().getStorageManager().modifyAllResourceNum(this.outputCostPack.getModifiedValues(), false); + } + if (this.outputGainPack != null) + { + construction.getGameplayContext().getStorageManager().modifyAllResourceNum(this.outputGainPack.getModifiedValues(), true); + } + } + + public abstract void onSubLogicFrame(); + public abstract long calculateModifiedOutputGain(long baseValue, int level, int proficiency); + public abstract long calculateModifiedOutputCost(long baseValue, int level, int proficiency); } diff --git a/idleshare/gamelib/src/hundun/gdxgame/idleshare/gamelib/framework/model/construction/base/ProficiencyComponent.java b/idleshare/gamelib/src/hundun/gdxgame/idleshare/gamelib/framework/model/construction/base/ProficiencyComponent.java new file mode 100644 index 0000000..680ac7c --- /dev/null +++ b/idleshare/gamelib/src/hundun/gdxgame/idleshare/gamelib/framework/model/construction/base/ProficiencyComponent.java @@ -0,0 +1,80 @@ +package hundun.gdxgame.idleshare.gamelib.framework.model.construction.base; + +public abstract class ProficiencyComponent { + + public int maxProficiency = 100; + protected final BaseConstruction construction; + public String promoteConstructionPrototypeId; + public String demoteConstructionPrototypeId; + + public ProficiencyComponent(BaseConstruction construction) + { + this.construction = construction; + } + + public String getProficiencyDescroption() + { + Boolean reachMaxLevel = construction.saveData.getProficiency() >= this.maxProficiency; + return construction.descriptionPackage.getProficiencyDescroptionProvider().provide(construction.saveData.getProficiency(), reachMaxLevel); + } + + public Boolean canPromote() + { + return isMaxProficiency() && promoteConstructionPrototypeId != null; + } + + public Boolean canDemote() + { + return (construction.saveData.getProficiency() < 0) && demoteConstructionPrototypeId != null; + } + + public void doPromote() + { + construction.gameplayContext.getConstructionManager().addToRemoveQueue(construction); + construction.gameplayContext.getConstructionManager().addToCreateQueue(construction.proficiencyComponent.promoteConstructionPrototypeId, construction.getPosition()); + } + + public void doDemote() + { + construction.gameplayContext.getConstructionManager().addToRemoveQueue(construction); + construction.gameplayContext.getConstructionManager().addToCreateQueue(construction.proficiencyComponent.demoteConstructionPrototypeId, construction.getPosition()); + } + + public void changeProficiency(int delta) + { + construction.saveData.setProficiency(Math.max(0, Math.min(construction.saveData.getProficiency() + delta, this.maxProficiency))); + construction.updateModifiedValues(); + //construction.gameContext.frontend.log(construction.name, "changeProficiency delta = " + delta + ", success to " + construction.saveData.proficiency); + } + + public void cleanProficiency() + { + + construction.saveData.setProficiency(0); + construction.updateModifiedValues(); + construction.gameplayContext.getFrontEnd().log(construction.name, "cleanProficiency"); + + } + + public abstract void onSubLogicFrame(); + + protected void checkAutoPromoteDemote() + { + if (this.canPromote()) + { + this.doPromote(); + } + else if (this.canDemote()) + { + this.doDemote(); + } + } + + + public abstract void afterUpgrade(); + + public boolean isMaxProficiency() + { + return construction.saveData.getProficiency() >= maxProficiency; + } +} diff --git a/idleshare/gamelib/src/hundun/gdxgame/idleshare/gamelib/framework/model/construction/base/PromotionComponent.java b/idleshare/gamelib/src/hundun/gdxgame/idleshare/gamelib/framework/model/construction/base/PromotionComponent.java index 84d0997..18a4b4b 100644 --- a/idleshare/gamelib/src/hundun/gdxgame/idleshare/gamelib/framework/model/construction/base/PromotionComponent.java +++ b/idleshare/gamelib/src/hundun/gdxgame/idleshare/gamelib/framework/model/construction/base/PromotionComponent.java @@ -58,7 +58,7 @@ public boolean isMeetLevel() { } public boolean isMeetResource() { - return construction.getGameContext().getStorageManager().isEnough(promotionCostPack.getModifiedValues()); + return construction.getGameplayContext().getStorageManager().isEnough(promotionCostPack.getModifiedValues()); } } diff --git a/idleshare/gamelib/src/hundun/gdxgame/idleshare/gamelib/framework/model/construction/base/UpgradeComponent.java b/idleshare/gamelib/src/hundun/gdxgame/idleshare/gamelib/framework/model/construction/base/UpgradeComponent.java index 2bee58f..ed6b3ab 100644 --- a/idleshare/gamelib/src/hundun/gdxgame/idleshare/gamelib/framework/model/construction/base/UpgradeComponent.java +++ b/idleshare/gamelib/src/hundun/gdxgame/idleshare/gamelib/framework/model/construction/base/UpgradeComponent.java @@ -14,42 +14,52 @@ * Created on 2021/12/17 */ public class UpgradeComponent { - private final BaseConstruction construction; - @Getter - @Setter - private ResourcePack upgradeCostPack; - public static enum UpgradeState { NO_UPGRADE, HAS_NEXT_UPGRADE, - REACHED_MAX_UPGRADE, - ; + REACHED_MAX_UPGRADE_NO_TRANSFER, + REACHED_MAX_UPGRADE_HAS_TRANSFER; } + + private final BaseConstruction construction; + + @Getter + @Setter + private ResourcePack upgradeCostPack; + @Getter + @Setter + private ResourcePack transformCostPack; + @Getter + @Setter + private String transformConstructionPrototypeId; + @Getter private UpgradeState upgradeState; - + /** * 影响升级后下一级费用,详见具体公式 */ private static final double upgradeCostLevelUpArg = 1.05; private static final BiFunction DEFAULT_CALCULATE_COST_FUNCTION = (baseValue, level) -> { - return (long)( + return (long) ( baseValue - * (1 + 1 * level) - * Math.pow(upgradeCostLevelUpArg, level) - ); + * (1 + 1 * level) + * Math.pow(upgradeCostLevelUpArg, level) + ); }; private BiFunction calculateCostFunction = DEFAULT_CALCULATE_COST_FUNCTION; + // ------ replace-lombok ------ public BiFunction getCalculateCostFunction() { return calculateCostFunction; } + public void setCalculateCostFunction(BiFunction calculateCostFunction) { this.calculateCostFunction = calculateCostFunction; } - + public UpgradeComponent(BaseConstruction construction) { super(); this.construction = construction; @@ -62,40 +72,87 @@ public void lazyInitDescription() { upgradeState = UpgradeState.HAS_NEXT_UPGRADE; upgradeCostPack.setDescriptionStart(construction.descriptionPackage.getUpgradeCostDescriptionStart()); } + if (transformCostPack != null) { + transformCostPack.setDescriptionStart(construction.descriptionPackage.getTransformCostDescriptionStart()); + } } - public void updateModifiedValues(boolean reachMaxLevel) { + public void updateModifiedValues() { + Boolean reachMaxLevel = construction.levelComponent.isReachMaxLevel(); if (upgradeCostPack != null) { if (reachMaxLevel) { - upgradeState = UpgradeState.REACHED_MAX_UPGRADE; this.upgradeCostPack.setModifiedValues(null); this.upgradeCostPack.setModifiedValuesDescription(null); + if (transformCostPack != null) { + upgradeState = UpgradeState.REACHED_MAX_UPGRADE_HAS_TRANSFER; + + this.transformCostPack.setModifiedValues(transformCostPack.getBaseValues()); + this.transformCostPack.setModifiedValuesDescription(ResourcePack.toDescription(this.transformCostPack.getModifiedValues())); + } else { + upgradeState = UpgradeState.REACHED_MAX_UPGRADE_NO_TRANSFER; + } } else { this.upgradeCostPack.setModifiedValues( upgradeCostPack.getBaseValues().stream() - .map(pair -> { + .map(pair -> { long newAmout = calculateCostFunction.apply(pair.getAmount(), construction.saveData.getLevel()); return new ResourcePair(pair.getType(), newAmout); }) - .collect(Collectors.toList()) - ); - this.upgradeCostPack.setModifiedValuesDescription( - upgradeCostPack.getModifiedValues().stream() - .map(pair -> pair.getType() + "x" + pair.getAmount()) - .collect(Collectors.joining(", ")) - + "; " + .collect(Collectors.toList()) ); + this.upgradeCostPack.setModifiedValuesDescription(ResourcePack.toDescription(this.upgradeCostPack.getModifiedValues())); } } } protected boolean canUpgrade() { - if (construction.saveData.getLevel() >= construction.maxLevel || upgradeCostPack == null) { + if (construction.levelComponent.isReachMaxLevel() || upgradeCostPack == null) { + return false; + } + if (!construction.proficiencyComponent.isMaxProficiency()) { return false; } List compareTarget = upgradeCostPack.getModifiedValues(); - return construction.getGameContext().getStorageManager().isEnough(compareTarget); + return construction.getGameplayContext().getStorageManager().isEnough(compareTarget); + } + + public void doUpgrade() + { + List upgradeCostRule = this.upgradeCostPack.getModifiedValues(); + construction.gameplayContext.getStorageManager().modifyAllResourceNum(upgradeCostRule, false); + construction.saveData.setLevel((construction.saveData.getLevel() + 1)); + if (!construction.levelComponent.isWorkingLevelChangable()) + { + construction.saveData.setWorkingLevel((construction.saveData.getLevel())); + } + construction.proficiencyComponent.afterUpgrade(); + construction.updateModifiedValues(); + construction.gameplayContext.getEventManager().notifyConstructionCollectionChange(); } -} + public Boolean canTransfer() + { + if (!construction.levelComponent.isReachMaxLevel() || transformCostPack == null) + { + return false; + } + if (!construction.proficiencyComponent.isMaxProficiency()) + { + return false; + } + + List compareTarget = transformCostPack.getModifiedValues(); + return construction.gameplayContext.getStorageManager().isEnough(compareTarget); + } + + public void doTransfer() + { + if (construction.upgradeComponent.transformCostPack != null) + { + construction.gameplayContext.getStorageManager().modifyAllResourceNum(construction.upgradeComponent.transformCostPack.getModifiedValues(), false); + } + construction.gameplayContext.getConstructionManager().addToRemoveQueue(construction); + construction.gameplayContext.getConstructionManager().addToCreateQueue(construction.upgradeComponent.transformConstructionPrototypeId, construction.getPosition()); + } +} \ No newline at end of file diff --git a/idleshare/gamelib/src/hundun/gdxgame/idleshare/gamelib/framework/model/construction/starter/BaseAutoOutputComponent.java b/idleshare/gamelib/src/hundun/gdxgame/idleshare/gamelib/framework/model/construction/starter/BaseAutoOutputComponent.java new file mode 100644 index 0000000..f48a91e --- /dev/null +++ b/idleshare/gamelib/src/hundun/gdxgame/idleshare/gamelib/framework/model/construction/starter/BaseAutoOutputComponent.java @@ -0,0 +1,35 @@ +package hundun.gdxgame.idleshare.gamelib.framework.model.construction.starter; + +import hundun.gdxgame.idleshare.gamelib.framework.model.construction.base.BaseConstruction; +import hundun.gdxgame.idleshare.gamelib.framework.model.construction.base.OutputComponent; + +public abstract class BaseAutoOutputComponent extends OutputComponent { + + protected int autoOutputProgress = 0; + + public BaseAutoOutputComponent(BaseConstruction construction) { + super(construction); + } + + @Override + public void onSubLogicFrame() { + autoOutputProgress++; + int outputFrameCountMax = this.autoOutputSecondCountMax * construction.getGameplayContext().LOGIC_FRAME_PER_SECOND; + if (autoOutputProgress >= outputFrameCountMax) + { + autoOutputProgress = 0; + tryAutoOutputOnce(); + } + } + + private void tryAutoOutputOnce() + { + if (!this.canOutput()) + { + //gameContext.frontend.log(this.id, "canOutput"); + return; + } + //gameContext.frontend.log(this.id, "AutoOutput"); + this.doOutput(); + } +} diff --git a/idleshare/gamelib/src/hundun/gdxgame/idleshare/gamelib/framework/model/construction/starter/BaseAutoProficiencyComponent.java b/idleshare/gamelib/src/hundun/gdxgame/idleshare/gamelib/framework/model/construction/starter/BaseAutoProficiencyComponent.java new file mode 100644 index 0000000..50f45ad --- /dev/null +++ b/idleshare/gamelib/src/hundun/gdxgame/idleshare/gamelib/framework/model/construction/starter/BaseAutoProficiencyComponent.java @@ -0,0 +1,41 @@ +package hundun.gdxgame.idleshare.gamelib.framework.model.construction.starter; + +import hundun.gdxgame.idleshare.gamelib.framework.model.construction.base.BaseConstruction; +import hundun.gdxgame.idleshare.gamelib.framework.model.construction.base.ProficiencyComponent; + +public abstract class BaseAutoProficiencyComponent extends ProficiencyComponent { + + protected final Integer upgradeLostProficiency; + protected int autoProficiencyProgress = 0; + protected final Integer AUTO_PROFICIENCY_SECOND_MAX; // n秒生长一次 + + public BaseAutoProficiencyComponent(BaseConstruction construction, Integer second, Integer upgradeLostProficiency) { + super(construction); + this.AUTO_PROFICIENCY_SECOND_MAX = second; + this.upgradeLostProficiency = upgradeLostProficiency; + } + + @Override + public void onSubLogicFrame() { + if (AUTO_PROFICIENCY_SECOND_MAX != null) + { + autoProficiencyProgress++; + int proficiencyFrameCountMax = AUTO_PROFICIENCY_SECOND_MAX * construction.getGameplayContext().LOGIC_FRAME_PER_SECOND; + if (autoProficiencyProgress >= proficiencyFrameCountMax) + { + autoProficiencyProgress = 0; + tryProficiencyOnce(); + } + } + } + + @Override + public void afterUpgrade() { + if (upgradeLostProficiency != null) + { + construction.getSaveData().setProficiency(construction.getSaveData().getProficiency() - this.upgradeLostProficiency); + } + } + + protected abstract void tryProficiencyOnce(); +} diff --git a/idleshare/gamelib/src/hundun/gdxgame/idleshare/gamelib/framework/model/construction/starter/ConstProficiencyComponent.java b/idleshare/gamelib/src/hundun/gdxgame/idleshare/gamelib/framework/model/construction/starter/ConstProficiencyComponent.java new file mode 100644 index 0000000..d043fff --- /dev/null +++ b/idleshare/gamelib/src/hundun/gdxgame/idleshare/gamelib/framework/model/construction/starter/ConstProficiencyComponent.java @@ -0,0 +1,21 @@ +package hundun.gdxgame.idleshare.gamelib.framework.model.construction.starter; + +import hundun.gdxgame.idleshare.gamelib.framework.model.construction.base.BaseConstruction; +import hundun.gdxgame.idleshare.gamelib.framework.model.construction.base.ProficiencyComponent; + +public class ConstProficiencyComponent extends ProficiencyComponent { + + public ConstProficiencyComponent(BaseConstruction construction) { + super(construction); + } + + @Override + public void onSubLogicFrame() { + // do nothing + } + + @Override + public void afterUpgrade() { + // do nothing + } +} diff --git a/idleshare/gamelib/src/hundun/gdxgame/idleshare/gamelib/framework/model/construction/starter/EmptyOutputComponent.java b/idleshare/gamelib/src/hundun/gdxgame/idleshare/gamelib/framework/model/construction/starter/EmptyOutputComponent.java new file mode 100644 index 0000000..d6475f5 --- /dev/null +++ b/idleshare/gamelib/src/hundun/gdxgame/idleshare/gamelib/framework/model/construction/starter/EmptyOutputComponent.java @@ -0,0 +1,26 @@ +package hundun.gdxgame.idleshare.gamelib.framework.model.construction.starter; + +import hundun.gdxgame.idleshare.gamelib.framework.model.construction.base.BaseConstruction; +import hundun.gdxgame.idleshare.gamelib.framework.model.construction.base.OutputComponent; + +public class EmptyOutputComponent extends OutputComponent { + + public EmptyOutputComponent(BaseConstruction construction) { + super(construction); + } + + @Override + public void onSubLogicFrame() { + + } + + @Override + public long calculateModifiedOutputGain(long baseValue, int level, int proficiency) { + return baseValue; + } + + @Override + public long calculateModifiedOutputCost(long baseValue, int level, int proficiency) { + return baseValue; + } +} diff --git a/idleshare/gamelib/src/hundun/gdxgame/idleshare/gamelib/framework/model/grid/GridPosition.java b/idleshare/gamelib/src/hundun/gdxgame/idleshare/gamelib/framework/model/grid/GridPosition.java new file mode 100644 index 0000000..1e75e5e --- /dev/null +++ b/idleshare/gamelib/src/hundun/gdxgame/idleshare/gamelib/framework/model/grid/GridPosition.java @@ -0,0 +1,20 @@ +package hundun.gdxgame.idleshare.gamelib.framework.model.grid; + +import hundun.gdxgame.gamelib.base.util.JavaFeatureForGwt; +import lombok.AllArgsConstructor; +import lombok.Data; +import lombok.Getter; + +@Getter +@AllArgsConstructor +public class GridPosition { + + int x; + int y; + + public String toShowText() + { + return JavaFeatureForGwt.stringFormat("({0},{1})", x, y); + } + +} diff --git a/idleshare/gamelib/src/hundun/gdxgame/idleshare/gamelib/framework/model/grid/ITileNode.java b/idleshare/gamelib/src/hundun/gdxgame/idleshare/gamelib/framework/model/grid/ITileNode.java new file mode 100644 index 0000000..3c42164 --- /dev/null +++ b/idleshare/gamelib/src/hundun/gdxgame/idleshare/gamelib/framework/model/grid/ITileNode.java @@ -0,0 +1,22 @@ +package hundun.gdxgame.idleshare.gamelib.framework.model.grid; + +import lombok.Getter; +import lombok.Setter; + +import java.util.Map; + +public interface ITileNode { + GridPosition getPosition(); + void setPosition(GridPosition value); + Map> getNeighbors(); + void setNeighbors(Map> value); + public enum TileNeighborDirection + { + LEFT_UP, + LEFT_MID, + LEFT_DOWN, + RIGHT_UP, + RIGHT_MID, + RIGHT_DOWN + } +} diff --git a/idleshare/gamelib/src/hundun/gdxgame/idleshare/gamelib/framework/model/grid/ITileNodeMap.java b/idleshare/gamelib/src/hundun/gdxgame/idleshare/gamelib/framework/model/grid/ITileNodeMap.java new file mode 100644 index 0000000..69a20a5 --- /dev/null +++ b/idleshare/gamelib/src/hundun/gdxgame/idleshare/gamelib/framework/model/grid/ITileNodeMap.java @@ -0,0 +1,6 @@ +package hundun.gdxgame.idleshare.gamelib.framework.model.grid; + +public interface ITileNodeMap { + + ITileNode getValidNodeOrNull(GridPosition position); +} diff --git a/idleshare/gamelib/src/hundun/gdxgame/idleshare/gamelib/framework/model/grid/TileNodeUtils.java b/idleshare/gamelib/src/hundun/gdxgame/idleshare/gamelib/framework/model/grid/TileNodeUtils.java new file mode 100644 index 0000000..954aafd --- /dev/null +++ b/idleshare/gamelib/src/hundun/gdxgame/idleshare/gamelib/framework/model/grid/TileNodeUtils.java @@ -0,0 +1,155 @@ +package hundun.gdxgame.idleshare.gamelib.framework.model.grid; + +import hundun.gdxgame.gamelib.base.util.JavaFeatureForGwt; +import hundun.gdxgame.idleshare.gamelib.framework.model.grid.ITileNode.TileNeighborDirection; + +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +public class TileNodeUtils { + public static List values = JavaFeatureForGwt.listOf(new TileNeighborDirection[]{ + TileNeighborDirection.LEFT_UP, + TileNeighborDirection.LEFT_MID, + TileNeighborDirection.LEFT_DOWN, + TileNeighborDirection.RIGHT_UP, + TileNeighborDirection.RIGHT_MID, + TileNeighborDirection.RIGHT_DOWN + }); + + public static void updateNeighborsAllStep(ITileNode target, ITileNodeMap map) { + // update self + updateNeighborsOneStep(target, map); + // update new neighbors + target.getNeighbors().values().stream() + .filter(it -> it != null) + .forEach(it -> updateNeighborsOneStep(it, map)); + } + + public static void updateNeighborsOneStep(ITileNode target, ITileNodeMap map) + { + + target.setNeighbors(new HashMap<>()); + + values.forEach(it -> { + GridPosition position = tileNeighborPosition(target, map, it); + ITileNode neighbor = map.getValidNodeOrNull(position); + target.getNeighbors().put(it, neighbor); + }); + + } + + + public static GridPosition tileNeighborPosition(ITileNode target, ITileNodeMap map, TileNeighborDirection direction) + { + switch (direction) { + case LEFT_UP: + return tileLeftUpNeighbor(target, map); + case LEFT_MID: + return tileLeftMidNeighbor(target, map); + case LEFT_DOWN: + return tileLeftDownNeighbor(target, map); + case RIGHT_UP: + return tileRightUpNeighbor(target, map); + case RIGHT_MID: + return tileRightMidNeighbor(target, map); + case RIGHT_DOWN: + return tileRightDownNeighbor(target, map); + } + return null; + } + + + + public static GridPosition tileRightMidNeighbor(ITileNode target, ITileNodeMap map) + { + int y; + int x; + y = target.getPosition().y; + x = target.getPosition().x + 1; + return new GridPosition(x, y); + } + + + public static GridPosition tileRightUpNeighbor(ITileNode target, ITileNodeMap map) + { + int y; + int x; + if (target.getPosition().y % 2 == 0) + { + y = target.getPosition().y + 1; + x = target.getPosition().x + 1; + } + else + { + y = target.getPosition().y + 1; + x = target.getPosition().x; + } + return new GridPosition(x, y); + } + + + public static GridPosition tileRightDownNeighbor(ITileNode target, ITileNodeMap map) + { + int y; + int x; + if (target.getPosition().y % 2 == 0) + { + y = target.getPosition().y - 1; + x = target.getPosition().x + 1; + } + else + { + y = target.getPosition().y - 1; + x = target.getPosition().x; + } + return new GridPosition(x, y); + } + + public static GridPosition tileLeftUpNeighbor(ITileNode target, ITileNodeMap map) + { + int y; + int x; + if (target.getPosition().y % 2 == 0) + { + y = target.getPosition().y + 1; + x = target.getPosition().x; + } + else + { + y = target.getPosition().y + 1; + x = target.getPosition().x - 1; + } + return new GridPosition(x, y); + } + + public static GridPosition tileLeftMidNeighbor(ITileNode target, ITileNodeMap map) + { + int y; + int x; + y = target.getPosition().y; + x = target.getPosition().x - 1; + return new GridPosition(x, y); + } + + public static GridPosition tileLeftDownNeighbor(ITileNode target, ITileNodeMap map) + { + int y; + int x; + if (target.getPosition().y % 2 == 0) + { + y = target.getPosition().y - 1; + x = target.getPosition().x; + } + else + { + y = target.getPosition().y - 1; + x = target.getPosition().x - 1; + } + return new GridPosition(x, y); + } + + + + +} diff --git a/idleshare/gamelib/src/hundun/gdxgame/idleshare/gamelib/framework/model/manager/AchievementManager.java b/idleshare/gamelib/src/hundun/gdxgame/idleshare/gamelib/framework/model/manager/AchievementManager.java index 5c34776..2f58ad0 100644 --- a/idleshare/gamelib/src/hundun/gdxgame/idleshare/gamelib/framework/model/manager/AchievementManager.java +++ b/idleshare/gamelib/src/hundun/gdxgame/idleshare/gamelib/framework/model/manager/AchievementManager.java @@ -4,38 +4,64 @@ * Created on 2021/11/12 */ -import java.util.HashMap; -import java.util.HashSet; -import java.util.List; -import java.util.Map; +import java.util.*; import java.util.Map.Entry; +import java.util.stream.Collectors; import hundun.gdxgame.gamelib.starter.listerner.IGameStartListener; import hundun.gdxgame.idleshare.gamelib.framework.IdleGameplayContext; import hundun.gdxgame.idleshare.gamelib.framework.listener.IBuffChangeListener; import hundun.gdxgame.idleshare.gamelib.framework.listener.IOneFrameResourceChangeListener; -import hundun.gdxgame.idleshare.gamelib.framework.model.AchievementPrototype; +import hundun.gdxgame.idleshare.gamelib.framework.model.AbstractAchievement; +import lombok.AllArgsConstructor; import lombok.Getter; import lombok.Setter; -import java.util.Set; - public class AchievementManager implements IBuffChangeListener, IOneFrameResourceChangeListener, IGameStartListener { IdleGameplayContext gameContext; - Map prototypes = new HashMap<>(); - + Map prototypes = new HashMap<>(); + private List totalAchievementIds = new ArrayList<>(); + private List achievementQueue = new ArrayList<>(); @Getter @Setter - Set unlockedAchievementNames = new HashSet<>(); - + Set unlockedAchievementIds = new HashSet<>(); + + @AllArgsConstructor + public static class AchievementInfoPackage + { + AbstractAchievement firstLockedAchievement; + int total; + int unLockedSize; + List allAchievementList; + Set unlockedAchievementIds; + } public AchievementManager(IdleGameplayContext gameContext) { this.gameContext = gameContext; gameContext.getEventManager().registerListener(this); } - public void addPrototype(AchievementPrototype prototype) { + public AchievementInfoPackage getAchievementInfoPackage() + { + List allAchievementList = achievementQueue.stream() + .map(it -> prototypes.get(it)) + .collect(Collectors.toList()); + + AbstractAchievement firstLockedAchievement = allAchievementList.stream() + .filter(it -> !unlockedAchievementIds.contains(it.getId())) + .findFirst() + .orElse(null); + return new AchievementInfoPackage( + firstLockedAchievement, + totalAchievementIds.size(), + unlockedAchievementIds.size(), + allAchievementList, + unlockedAchievementIds + ); + } + + public void addPrototype(AbstractAchievement prototype) { prototypes.put(prototype.getName(), prototype); } @@ -67,16 +93,18 @@ private boolean checkRequiredBuffs(Map map) { private void checkAllAchievementUnlock() { //Gdx.app.log(this.getClass().getSimpleName(), "checkAllAchievementUnlock"); - for (AchievementPrototype prototype : prototypes.values()) { - if (unlockedAchievementNames.contains(prototype.getName())) { + for (AbstractAchievement prototype : prototypes.values()) { + if (unlockedAchievementIds.contains(prototype.getId())) { continue; } - boolean resourceMatched = checkRequiredResources(prototype.getRequiredResources()); - boolean buffMatched = checkRequiredBuffs(prototype.getRequiredBuffs()); - boolean allMatched = resourceMatched && buffMatched; - if (allMatched) { - unlockedAchievementNames.add(prototype.getName()); + boolean resourceMatched = prototype.checkUnlock(); + if (resourceMatched) { + unlockedAchievementIds.add(prototype.getId()); gameContext.getEventManager().notifyAchievementUnlock(prototype); + if (prototype.getAwardResourceMap() != null) + { + gameContext.getStorageManager().modifyAllResourceNum(prototype.getAwardResourceMap(), true); + } } } } @@ -87,12 +115,14 @@ public void onBuffChange() { checkAllAchievementUnlock(); } - public void lazyInit(List achievementPrototypes) { - achievementPrototypes.forEach(item -> addPrototype(item)); + public void lazyInit(Map achievementProviderMap, List achievementPrototypeIds) { + achievementPrototypeIds.forEach(it -> addPrototype(achievementProviderMap.get(it))); + this.totalAchievementIds = achievementPrototypeIds; + this.achievementQueue = new ArrayList<>(achievementPrototypeIds); } @Override - public void onResourceChange(Map changeMap) { + public void onResourceChange(Map changeMap, Map> deltaHistoryMap) { checkAllAchievementUnlock(); } diff --git a/idleshare/gamelib/src/hundun/gdxgame/idleshare/gamelib/framework/model/manager/ConstructionManager.java b/idleshare/gamelib/src/hundun/gdxgame/idleshare/gamelib/framework/model/manager/ConstructionManager.java index ce9cd83..0dc9393 100644 --- a/idleshare/gamelib/src/hundun/gdxgame/idleshare/gamelib/framework/model/manager/ConstructionManager.java +++ b/idleshare/gamelib/src/hundun/gdxgame/idleshare/gamelib/framework/model/manager/ConstructionManager.java @@ -8,90 +8,178 @@ import java.util.stream.Collectors; import hundun.gdxgame.idleshare.gamelib.framework.IdleGameplayContext; +import hundun.gdxgame.idleshare.gamelib.framework.data.ConstructionSaveData; +import hundun.gdxgame.idleshare.gamelib.framework.model.construction.AbstractConstructionPrototype; import hundun.gdxgame.idleshare.gamelib.framework.model.construction.base.BaseConstruction; +import hundun.gdxgame.idleshare.gamelib.framework.model.grid.GridPosition; +import hundun.gdxgame.idleshare.gamelib.framework.model.grid.ITileNode; +import hundun.gdxgame.idleshare.gamelib.framework.model.grid.ITileNodeMap; +import hundun.gdxgame.idleshare.gamelib.framework.model.grid.TileNodeUtils; /** * @author hundun * Created on 2021/11/29 */ -public class ConstructionManager { +public class ConstructionManager implements ITileNodeMap { IdleGameplayContext gameContext; + /** + * 运行中的设施集合。key: constructionId + */ + public Map runningConstructionModelMap = new HashMap<>(); + private List removeQueue = new ArrayList<>(); + private List createQueue = new ArrayList<>(); public ConstructionManager(IdleGameplayContext gameContext) { this.gameContext = gameContext; } - /** - * 运行中的设施集合。key: constructionId + * 根据GameArea显示不同的ConstructionVM集合 */ - Map runningConstructionModelMap = new HashMap<>(); + Map> areaControlableConstructionVMPrototypeIds; /** - * 根据GameArea显示不同的Construction集合 + * 根据GameArea显示不同的ConstructionPrototypeVM集合 */ - Map> areaControlableConstructions; - - public void lazyInit(Map> areaControlableConstructionIds) { - areaControlableConstructions = new HashMap<>(); - if (areaControlableConstructionIds != null) { - for (Entry> entry : areaControlableConstructionIds.entrySet()) { - areaControlableConstructions.put( - entry.getKey(), - entry.getValue() - .stream() - .map(id -> gameContext.getConstructionFactory().getConstruction(id)) - .collect(Collectors.toList()) - ); - } - } + Map> areaControlableConstructionPrototypeVMPrototypeIds; + + public void lazyInit( + Map> areaControlableConstructionVMPrototypeIds, + Map> areaControlableConstructionPrototypeVMPrototypeIds + ) { + this.areaControlableConstructionVMPrototypeIds = areaControlableConstructionVMPrototypeIds; + this.areaControlableConstructionPrototypeVMPrototypeIds = areaControlableConstructionPrototypeVMPrototypeIds; -// areaControlableConstructions.put(String.BEE_FARM, Arrays.asList( -// modelContext.getConstructionFactory().getConstruction(ConstructionId.BEE_GATHER_HOUSE), -// modelContext.getConstructionFactory().getConstruction(ConstructionId.SMALL_BEEHIVE), -// modelContext.getConstructionFactory().getConstruction(ConstructionId.MID_BEEHIVE), -// modelContext.getConstructionFactory().getConstruction(ConstructionId.BIG_BEEHIVE), -// modelContext.getConstructionFactory().getConstruction(ConstructionId.QUEEN_BEEHIVE) -// )); -// areaControlableConstructions.put(String.FOREST_FARM, Arrays.asList( -// modelContext.getConstructionFactory().getConstruction(ConstructionId.WOOD_GATHER_HOUSE), -// modelContext.getConstructionFactory().getConstruction(ConstructionId.WOOD_KEEPING), -// modelContext.getConstructionFactory().getConstruction(ConstructionId.WOOD_BOARD_MAKER), -// modelContext.getConstructionFactory().getConstruction(ConstructionId.WIN_THE_GAME) -// )); -// areaControlableConstructions.put(String.SHOP, Arrays.asList( -// modelContext.getConstructionFactory().getConstruction(ConstructionId.WOOD_SELL_HOUSE), -// modelContext.getConstructionFactory().getConstruction(ConstructionId.WOOD_BOARD_SELL_HOUSE), -// modelContext.getConstructionFactory().getConstruction(ConstructionId.BEE_SELL_HOUSE), -// modelContext.getConstructionFactory().getConstruction(ConstructionId.HONEY_SELL_HOUSE), -// modelContext.getConstructionFactory().getConstruction(ConstructionId.BEEWAX_SELL_HOUSE) -// )); - areaControlableConstructions.values().forEach(items -> items.forEach(item -> runningConstructionModelMap.putIfAbsent(item.getId(), item))); } public void onSubLogicFrame() { - runningConstructionModelMap.values().forEach(item -> item.onLogicFrame()); + createQueue.forEach(it -> { + runningConstructionModelMap.put(it.getId(), it); + TileNodeUtils.updateNeighborsAllStep(it, this); + }); + + removeQueue.forEach(it -> { + runningConstructionModelMap.remove(it.getId()); + TileNodeUtils.updateNeighborsAllStep(it, this); + }); + + if (removeQueue.size() > 0 || createQueue.size() > 0) + { + this.gameContext.getEventManager().notifyConstructionCollectionChange(); + } + removeQueue.clear(); + createQueue.clear(); + + runningConstructionModelMap.values().forEach(item -> item.onSubLogicFrame()); } - public List getAreaShownConstructionsOrEmpty(String gameArea) { - areaControlableConstructions.computeIfAbsent(gameArea, gameArea2 -> new ArrayList<>()); - List constructions = areaControlableConstructions.get(gameArea); - return constructions; + public List getAreaControlableConstructionsOrEmpty(String gameArea) + { + return runningConstructionModelMap.values().stream() + .filter(it -> areaControlableConstructionVMPrototypeIds.containsKey(gameArea) + && areaControlableConstructionVMPrototypeIds.get(gameArea).contains(it.getPrototypeId())) + .collect(Collectors.toList()); } - public Integer getConstructionLevelOrNull(String constructionId) { - if (!runningConstructionModelMap.containsKey(constructionId)) { - return null; + public BaseConstruction getConstruction(String id) + { + BaseConstruction result = runningConstructionModelMap.get(id); + if (result == null) + { + throw new RuntimeException("getConstruction " + id + " not found"); } - return runningConstructionModelMap.get(constructionId).getSaveData().getLevel(); + return result; } + public BaseConstruction getConstructionAt(GridPosition target) + { + return runningConstructionModelMap.values().stream() + .filter(it -> it.getSaveData().getPosition().equals(target)) + .findAny() + .orElse(null); + } + + public List getConstructions() + { + return runningConstructionModelMap.values().stream().collect(Collectors.toList()); + } + + public List getConstructionsOfPrototype(String prototypeId) + { + return runningConstructionModelMap.values().stream() + .filter(it -> it.getPrototypeId().equals(prototypeId)) + .collect(Collectors.toList()); + } + + + private void addToRemoveQueueAt(GridPosition position) + { + runningConstructionModelMap.entrySet().stream() + .filter(pair -> pair.getValue().getPosition().equals(position)) + .forEach(pair -> removeQueue.add(pair.getValue())); + } + + + public void addToRemoveQueue(BaseConstruction construction) + { + removeQueue.add(construction); + } + public void loadInstance(ConstructionSaveData saveData) + { + String prototypeId = saveData.prototypeId; + GridPosition position = saveData.getPosition(); + BaseConstruction construction = gameContext.getConstructionFactory().getInstanceOfPrototype(prototypeId, position); + construction.setSaveData(saveData); + construction.updateModifiedValues(); + + runningConstructionModelMap.put(construction.getId(), construction); + TileNodeUtils.updateNeighborsAllStep(construction, this); + } + + public boolean canBuyInstanceOfPrototype(String prototypeId, GridPosition position) + { + AbstractConstructionPrototype prototype = gameContext.getConstructionFactory().getPrototype(prototypeId); + boolean isCostEnough = this.gameContext.getStorageManager().isEnough(prototype.getBuyInstanceCostPack().getModifiedValues()); + boolean positionAllowCase1 = runningConstructionModelMap.entrySet().stream().noneMatch(pair -> pair.getValue().getPosition().equals(position)); + boolean positionAllowCase2 = runningConstructionModelMap.entrySet().stream().filter(pair -> pair.getValue().getPosition().equals(position) && pair.getValue().isAllowPositionOverwrite()).count() == 1; + return isCostEnough && (positionAllowCase1 || positionAllowCase2); + + } + + + + public void buyInstanceOfPrototype(String prototypeId, GridPosition position) + { + AbstractConstructionPrototype prototype = gameContext.getConstructionFactory().getPrototype(prototypeId); + this.gameContext.getStorageManager().modifyAllResourceNum(prototype.getBuyInstanceCostPack().getModifiedValues(), false); + addToRemoveQueueAt(position); + addToCreateQueue(prototypeId, position); + } + + public void addToCreateQueue(String prototypeId, GridPosition position) + { + BaseConstruction construction = gameContext.getConstructionFactory().getInstanceOfPrototype(prototypeId, position); + createQueue.add(construction); + } + + + + public void AddToRemoveQueue(BaseConstruction construction) + { + throw new RuntimeException("NotImplementedException"); + } + + + @Override + public ITileNode getValidNodeOrNull(GridPosition position) { + return getConstructionAt(position); + } } diff --git a/idleshare/gamelib/src/hundun/gdxgame/idleshare/gamelib/framework/model/manager/EventManager.java b/idleshare/gamelib/src/hundun/gdxgame/idleshare/gamelib/framework/model/manager/EventManager.java index 0a34a65..89d3152 100644 --- a/idleshare/gamelib/src/hundun/gdxgame/idleshare/gamelib/framework/model/manager/EventManager.java +++ b/idleshare/gamelib/src/hundun/gdxgame/idleshare/gamelib/framework/model/manager/EventManager.java @@ -6,9 +6,11 @@ import hundun.gdxgame.idleshare.gamelib.framework.IdleGameplayContext; import hundun.gdxgame.idleshare.gamelib.framework.callback.IAchievementUnlockCallback; +import hundun.gdxgame.idleshare.gamelib.framework.callback.IConstructionCollectionListener; +import hundun.gdxgame.idleshare.gamelib.framework.callback.INotificationBoardCallerAndCallback; import hundun.gdxgame.idleshare.gamelib.framework.listener.IBuffChangeListener; import hundun.gdxgame.idleshare.gamelib.framework.listener.IOneFrameResourceChangeListener; -import hundun.gdxgame.idleshare.gamelib.framework.model.AchievementPrototype; +import hundun.gdxgame.idleshare.gamelib.framework.model.AbstractAchievement; @@ -19,8 +21,9 @@ public class EventManager { List buffChangeListeners = new ArrayList<>(); List achievementUnlockListeners = new ArrayList<>(); + List notificationBoardCallerAndCallbacks = new ArrayList<>(); List oneFrameResourceChangeListeners = new ArrayList<>(); - + List constructionCollectionListeners = new ArrayList<>(); IdleGameplayContext gameContext; @@ -35,9 +38,41 @@ public void registerListener(Object listener) { if (listener instanceof IAchievementUnlockCallback && !achievementUnlockListeners.contains(listener)) { achievementUnlockListeners.add((IAchievementUnlockCallback) listener); } + if (listener instanceof INotificationBoardCallerAndCallback && !notificationBoardCallerAndCallbacks.contains(listener)) + { + notificationBoardCallerAndCallbacks.add((INotificationBoardCallerAndCallback)listener); + } if (listener instanceof IOneFrameResourceChangeListener && !oneFrameResourceChangeListeners.contains(listener)) { oneFrameResourceChangeListeners.add((IOneFrameResourceChangeListener) listener); } + if (listener instanceof IConstructionCollectionListener && !constructionCollectionListeners.contains(listener)) + { + constructionCollectionListeners.add((IConstructionCollectionListener)listener); + } + } + + public void unregisterListener(Object listener) + { + if (listener instanceof IBuffChangeListener) + { + buffChangeListeners.remove((IBuffChangeListener)listener); + } + if (listener instanceof IAchievementUnlockCallback) + { + achievementUnlockListeners.remove((IAchievementUnlockCallback)listener); + } + if (listener instanceof INotificationBoardCallerAndCallback) + { + notificationBoardCallerAndCallbacks.remove((INotificationBoardCallerAndCallback)listener); + } + if (listener instanceof IOneFrameResourceChangeListener) + { + oneFrameResourceChangeListeners.remove((IOneFrameResourceChangeListener)listener); + } + if (listener instanceof IConstructionCollectionListener) + { + constructionCollectionListeners.remove((IConstructionCollectionListener)listener); + } } public void notifyBuffChange() { @@ -54,17 +89,35 @@ public void notifyBuffChange() { // } // } - public void notifyOneFrameResourceChange(Map changeMap) { + public void notifyOneFrameResourceChange(Map changeMap, Map> deltaHistoryMap) { //Gdx.app.log(this.getClass().getSimpleName(), "notifyOneFrameResourceChange"); for (IOneFrameResourceChangeListener listener : oneFrameResourceChangeListeners) { - listener.onResourceChange(changeMap); + listener.onResourceChange(changeMap, deltaHistoryMap); } } - public void notifyAchievementUnlock(AchievementPrototype prototype) { + public void notifyAchievementUnlock(AbstractAchievement prototype) { gameContext.getFrontEnd().log(this.getClass().getSimpleName(), "notifyAchievementUnlock"); for (IAchievementUnlockCallback listener : achievementUnlockListeners) { - listener.onAchievementUnlock(prototype); + listener.showAchievementMaskBoard(prototype); + } + } + + public void notifyNotification(String data) + { + gameContext.getFrontEnd().log(this.getClass().getSimpleName(), "notifyNotification"); + for (INotificationBoardCallerAndCallback listener : notificationBoardCallerAndCallbacks) + { + listener.showNotificationMaskBoard(data); + } + } + + public void notifyConstructionCollectionChange() + { + //Gdx.app.log(this.getClass().getSimpleName(), "notifyOneFrameResourceChange"); + for (IConstructionCollectionListener listener : constructionCollectionListeners) + { + listener.onConstructionCollectionChange(); } } } diff --git a/idleshare/gamelib/src/hundun/gdxgame/idleshare/gamelib/framework/model/manager/StorageManager.java b/idleshare/gamelib/src/hundun/gdxgame/idleshare/gamelib/framework/model/manager/StorageManager.java index 57c0835..a0a89e4 100644 --- a/idleshare/gamelib/src/hundun/gdxgame/idleshare/gamelib/framework/model/manager/StorageManager.java +++ b/idleshare/gamelib/src/hundun/gdxgame/idleshare/gamelib/framework/model/manager/StorageManager.java @@ -1,9 +1,6 @@ package hundun.gdxgame.idleshare.gamelib.framework.model.manager; -import java.util.HashMap; -import java.util.HashSet; -import java.util.List; -import java.util.Map; +import java.util.*; import java.util.Map.Entry; import hundun.gdxgame.gamelib.starter.listerner.ILogicFrameListener; @@ -12,8 +9,6 @@ import lombok.Getter; import lombok.Setter; -import java.util.Set; - /** * @author hundun * Created on 2021/11/02 @@ -33,6 +28,8 @@ public class StorageManager { Map oneFrameDeltaResoueces = new HashMap<>(); + private Map> deltaHistoryMap = new HashMap<>(); + private final int HISTORY_SIZE = 100; public StorageManager(IdleGameplayContext gameContext) { this.gameContext = gameContext; } @@ -84,10 +81,16 @@ public boolean isEnough(List pairs) { public void onSubLogicFrame() { // ------ frameDeltaAmountClear ------ - Map temp = new HashMap<>(oneFrameDeltaResoueces); + Map changeMap = new HashMap<>(oneFrameDeltaResoueces); oneFrameDeltaResoueces.clear(); - //Gdx.app.log(this.getClass().getSimpleName(), "frameDeltaAmountClear: " + temp); - gameContext.getEventManager().notifyOneFrameResourceChange(temp); + changeMap.keySet().forEach(resourceType -> deltaHistoryMap.computeIfAbsent(resourceType, it -> new ArrayList<>())); + deltaHistoryMap.forEach((resourceType, value) -> { + value.add(changeMap.getOrDefault(resourceType, 0L)); + while (value.size() > HISTORY_SIZE) { + value.remove(0); + } + }); + gameContext.getEventManager().notifyOneFrameResourceChange(changeMap, deltaHistoryMap); } // public void addResourceNum(String key, int add) { diff --git a/idleshare/gamelib/src/hundun/gdxgame/idleshare/gamelib/framework/model/resource/ResourcePack.java b/idleshare/gamelib/src/hundun/gdxgame/idleshare/gamelib/framework/model/resource/ResourcePack.java index 1ef20aa..d70212e 100644 --- a/idleshare/gamelib/src/hundun/gdxgame/idleshare/gamelib/framework/model/resource/ResourcePack.java +++ b/idleshare/gamelib/src/hundun/gdxgame/idleshare/gamelib/framework/model/resource/ResourcePack.java @@ -1,6 +1,7 @@ package hundun.gdxgame.idleshare.gamelib.framework.model.resource; import java.util.List; +import java.util.stream.Collectors; import lombok.Data; @@ -14,4 +15,11 @@ public class ResourcePack { List baseValues; List modifiedValues; String modifiedValuesDescription; + + public static String toDescription(List list) { + return list.stream() + .map(pair -> pair.getType() + "x" + pair.getAmount()) + .collect(Collectors.joining(", ")) + + "; "; + } } diff --git a/idleshare/gamelib/src/hundun/gdxgame/idleshare/gamelib/framework/util/text/IGameDictionary.java b/idleshare/gamelib/src/hundun/gdxgame/idleshare/gamelib/framework/util/text/IGameDictionary.java index 139a8f2..b6dadc0 100644 --- a/idleshare/gamelib/src/hundun/gdxgame/idleshare/gamelib/framework/util/text/IGameDictionary.java +++ b/idleshare/gamelib/src/hundun/gdxgame/idleshare/gamelib/framework/util/text/IGameDictionary.java @@ -11,8 +11,11 @@ public interface IGameDictionary { - String constructionIdToShowName(Language language, String constructionId); - String constructionIdToDetailDescroptionConstPart(Language language, String constructionId); + String constructionPrototypeIdToShowName(Language language, String prototypeId); + String constructionPrototypeIdToDetailDescroptionConstPart(Language language, String prototypeId); List getMemuScreenTexts(Language language); + List getPlayScreenTexts(Language language); + List getAchievementTexts(Language language); Map getLanguageShowNameMap(); + List getStageSelectMaskBoardTexts(Language language); }