Skip to content

Commit

Permalink
fix bug, add COOKIE_AUTO_SELLER
Browse files Browse the repository at this point in the history
  • Loading branch information
hundun000 committed Jul 22, 2023
1 parent deef35c commit 1cd3856
Show file tree
Hide file tree
Showing 16 changed files with 141 additions and 43 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -28,14 +28,12 @@ public DemoChildGameConfig() {

Map<String, List<String>> areaControlableConstructionVMPrototypeIds = new HashMap<>();
areaControlableConstructionVMPrototypeIds.put(GameArea.AREA_COOKIE, JavaFeatureForGwt.arraysAsList(
ConstructionPrototypeId.COOKIE_AUTO_PROVIDER
ConstructionPrototypeId.COOKIE_AUTO_PROVIDER,
ConstructionPrototypeId.COOKIE_AUTO_SELLER
));
this.setAreaControlableConstructionVMPrototypeIds(areaControlableConstructionVMPrototypeIds);

Map<String, List<String>> areaControlableConstructionPrototypeVMPrototypeIds = new HashMap<>();
areaControlableConstructionPrototypeVMPrototypeIds.put(GameArea.AREA_COOKIE, JavaFeatureForGwt.arraysAsList(
ConstructionPrototypeId.COOKIE_AUTO_PROVIDER
));
this.setAreaControlableConstructionPrototypeVMPrototypeIds(areaControlableConstructionPrototypeVMPrototypeIds);


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,5 @@ public class ConstructionPrototypeId {


public static final String COOKIE_AUTO_PROVIDER = "ENUM_CSTR@COOKIE_AUTO_PROVIDER";

public static final String COOKIE_AUTO_SELLER = "ENUM_CSTR@COOKIE_AUTO_SELLER";
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@

import hundun.gdxgame.gamelib.base.util.JavaFeatureForGwt;
import hundun.gdxgame.idledemo.logic.prototype.CookieAutoProviderPrototype;
import hundun.gdxgame.idledemo.logic.prototype.CookieAutoSellerPrototype;
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;
Expand All @@ -25,6 +26,7 @@ public class DemoBuiltinConstructionsLoader implements IBuiltinConstructionsLoad
public Map<String, AbstractConstructionPrototype> getProviderMap(Language language) {
Map<String, AbstractConstructionPrototype> result = new HashMap<>();
result.put(ConstructionPrototypeId.COOKIE_AUTO_PROVIDER, new CookieAutoProviderPrototype(language));
result.put(ConstructionPrototypeId.COOKIE_AUTO_SELLER, new CookieAutoSellerPrototype(language));
return result;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,18 @@ protected RootSaveData genereateStarterRootSaveData() {
ConstructionSaveData.builder()
.prototypeId(ConstructionPrototypeId.COOKIE_AUTO_PROVIDER)
.level(1)
.workingLevel(1)
.position(USELESS_POSITON)
.build(),
ConstructionPrototypeId.COOKIE_AUTO_SELLER,
ConstructionSaveData.builder()
.prototypeId(ConstructionPrototypeId.COOKIE_AUTO_SELLER)
.level(1)
.workingLevel(0)
.position(USELESS_POSITON)
.build())
.build()
)

)
.ownResoueces(new HashMap<>())
.unlockedResourceTypes(new HashSet<>())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,11 @@ public IdleForestOutputComponent(BaseConstruction construction) {

@Override
public long calculateModifiedOutputGain(long baseValue, int level, int proficiency) {
return (long)((baseValue * level) * (0.5 + proficiency / construction.getProficiencyComponent().maxProficiency * 0.5));
return (long)((baseValue * level));
}

@Override
public long calculateModifiedOutputCost(long baseValue, int level, int proficiency) {
return (long)((baseValue * level) * (0.5 + proficiency / construction.getProficiencyComponent().maxProficiency * 0.5));
return (long)((baseValue * level));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -41,9 +41,7 @@ public CookieAutoProviderPrototype(Language language) {
super(
ConstructionPrototypeId.COOKIE_AUTO_PROVIDER,
language,
DemoBuiltinConstructionsLoader.toPack(JavaFeatureForGwt.mapOf(
ResourceType.COIN, 40
))
DemoBuiltinConstructionsLoader.toPack(JavaFeatureForGwt.mapOf())
);
switch (language)
{
Expand All @@ -64,7 +62,7 @@ public BaseConstruction getInstance(GridPosition position) {

construction.getOutputComponent().setOutputCostPack(DemoBuiltinConstructionsLoader.toPack(new HashMap<>()));
construction.getOutputComponent().setOutputGainPack(DemoBuiltinConstructionsLoader.toPack(JavaFeatureForGwt.mapOf(
ResourceType.COOKIE, 5
ResourceType.COOKIE, 1
)));

construction.getUpgradeComponent().setUpgradeCostPack(DemoBuiltinConstructionsLoader.toPack(JavaFeatureForGwt.mapOf(
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
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 CookieAutoSellerPrototype extends AbstractConstructionPrototype {

public CookieAutoSellerPrototype(Language language) {
super(
ConstructionPrototypeId.COOKIE_AUTO_SELLER,
language,
DemoBuiltinConstructionsLoader.toPack(JavaFeatureForGwt.mapOf())
);
switch (language)
{
case CN:
this.descriptionPackage = CookieAutoProviderPrototype.descriptionPackageCN;
break;
default:
this.descriptionPackage = CookieAutoProviderPrototype.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(JavaFeatureForGwt.mapOf(
ResourceType.COOKIE, 1
)));
construction.getOutputComponent().setOutputGainPack(DemoBuiltinConstructionsLoader.toPack(JavaFeatureForGwt.mapOf(
ResourceType.COIN, 5
)));

construction.getUpgradeComponent().setUpgradeCostPack(DemoBuiltinConstructionsLoader.toPack(JavaFeatureForGwt.mapOf(
ResourceType.COIN, 50
)));
construction.getLevelComponent().setWorkingLevelChangable(true);

return construction;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import com.badlogic.gdx.scenes.scene2d.ui.Label;
import com.badlogic.gdx.scenes.scene2d.ui.Table;
import com.badlogic.gdx.scenes.scene2d.ui.TextButton;
import com.badlogic.gdx.scenes.scene2d.utils.ChangeListener;
import com.badlogic.gdx.scenes.scene2d.utils.ClickListener;
import com.badlogic.gdx.utils.Align;

Expand All @@ -30,7 +31,9 @@ public class ConstructionControlNode<T_GAME extends BaseIdleGame<T_SAVE>, T_SAVE
Label workingLevelLabel;
Label proficiencyLabel;
Label positionLabel;

TextButton clickEffectButton;
TextButton upgradeButton;
TextButton destoryButton;
TextButton transformButton;

Expand All @@ -51,22 +54,31 @@ public ConstructionControlNode(BaseIdlePlayScreen<T_GAME, T_SAVE> parent, int in
constructionNameLabel.setWrap(true);

this.clickEffectButton = new TextButton("", parent.getGame().getMainSkin());
clickEffectButton.addListener(new ClickListener() {
clickEffectButton.addListener(new ChangeListener() {
@Override
public void clicked(InputEvent event, float x, float y) {
Gdx.app.log("ConstructionView", "clicked");
public void changed(ChangeEvent event, Actor actor) {
Gdx.app.log(ConstructionControlNode.class.getSimpleName(), "clickEffectButton changed");
model.getOutputComponent().doOutput();
}
});

this.upgradeButton = new TextButton("", parent.getGame().getMainSkin());
upgradeButton.addListener(new ChangeListener() {
@Override
public void changed(ChangeEvent event, Actor actor) {
Gdx.app.log(ConstructionControlNode.class.getSimpleName(), "upgradeButton changed");
model.getUpgradeComponent().doUpgrade();
}
});

this.addListener(new ClickListener() {

@Override
public void clicked(InputEvent event, float x, float y) {
if (model != null) {
parent.showAndUpdateGuideInfo(model);
}
Gdx.app.log(ConstructionControlNode.class.getSimpleName(), "exit event");
Gdx.app.log(ConstructionControlNode.class.getSimpleName(), "this clicked event");
super.clicked(event, x, y);
}

Expand Down Expand Up @@ -121,41 +133,32 @@ public void clicked(InputEvent event, float x, float y) {
// ------ this ------
this.add(constructionNameLabel).size(CHILD_WIDTH, NAME_CHILD_HEIGHT).row();
this.add(clickEffectButton).size(CHILD_WIDTH, CHILD_HEIGHT).row();
this.add(upgradeButton).size(CHILD_WIDTH, CHILD_HEIGHT).row();
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));
}


private void initAsNormalStyle() {

this.upWorkingLevelButton.setVisible(false);
this.downWorkingLevelButton.setVisible(false);

//changeWorkingLevelGroup.setVisible(false);

//this.debug();
}


private void initAsChangeWorkingLevelStyle() {
//clearStyle();

//changeWorkingLevelGroup.setVisible(true);
this.upWorkingLevelButton.setVisible(true);
this.downWorkingLevelButton.setVisible(true);



}

public void setModel(BaseConstruction constructionExportProxy) {
this.model = constructionExportProxy;
if (constructionExportProxy != null) {
if (constructionExportProxy.getLevelComponent().isWorkingLevelChangable()) {
initAsChangeWorkingLevelStyle();
this.upWorkingLevelButton.setVisible(true);
this.downWorkingLevelButton.setVisible(true);
} else {
initAsNormalStyle();
this.upWorkingLevelButton.setVisible(false);
this.downWorkingLevelButton.setVisible(false);
}
if (constructionExportProxy.getOutputComponent().isTypeClickOutput()) {
this.clickEffectButton.setVisible(true);
} else {
this.clickEffectButton.setVisible(false);
}
}
update();
Expand All @@ -176,6 +179,7 @@ public void update() {
// ------ update text ------
constructionNameLabel.setText(model.getName());
clickEffectButton.setText(model.getDescriptionPackage().getButtonDescroption());
upgradeButton.setText(model.getDescriptionPackage().getButtonDescroption());
workingLevelLabel.setText(model.getLevelComponent().getWorkingLevelDescroption());
proficiencyLabel.setText(model.getProficiencyComponent().getProficiencyDescroption());
positionLabel.setText(model.getSaveData().getPosition().toShowText());
Expand All @@ -189,6 +193,13 @@ public void update() {
clickEffectButton.setDisabled(true);
clickEffectButton.getLabel().setColor(Color.RED);
}
if (model.getUpgradeComponent().canUpgrade()) {
upgradeButton.setDisabled(false);
upgradeButton.getLabel().setColor(Color.WHITE);
} else {
upgradeButton.setDisabled(true);
upgradeButton.getLabel().setColor(Color.RED);
}
if (model.getExistenceComponent().canDestory())
{
destoryButton.setDisabled(false);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -122,8 +122,8 @@ public void setNeighbors(Map<TileNeighborDirection, ITileNode<Void>> neighbors)
public void lazyInitDescription(IdleGameplayContext gameContext, Language language) {
this.gameplayContext = gameContext;

this.name = gameContext.getGameDictionary().constructionPrototypeIdToShowName(language, id);
this.detailDescroptionConstPart = gameContext.getGameDictionary().constructionPrototypeIdToDetailDescroptionConstPart(language, id);
this.name = gameContext.getGameDictionary().constructionPrototypeIdToShowName(language, prototypeId);
this.detailDescroptionConstPart = gameContext.getGameDictionary().constructionPrototypeIdToDetailDescroptionConstPart(language, prototypeId);

outputComponent.lazyInitDescription();
upgradeComponent.lazyInitDescription();
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package hundun.gdxgame.idleshare.gamelib.framework.model.construction.base;

import lombok.Getter;
import lombok.Setter;


/**
Expand All @@ -11,8 +12,9 @@ public class LevelComponent {

private final BaseConstruction construction;

@Setter
@Getter
private final boolean workingLevelChangable;
private 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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,10 @@ public abstract class OutputComponent {
@Setter
protected int autoOutputSecondCountMax = DEFAULT_AUTO_OUPUT_SECOND_MAX;

@Getter
@Setter
protected boolean typeClickOutput;

public OutputComponent(BaseConstruction construction) {
this.construction = construction;
}
Expand All @@ -61,8 +65,8 @@ public void updateModifiedValues() {
construction.saveData.getWorkingLevel(),
construction.saveData.getProficiency()
);
return new ResourcePair(pair.getType(), newAmout);
})
return new ResourcePair(pair.getType(), newAmout);
})
.collect(Collectors.toList())
);
this.outputGainPack.setModifiedValuesDescription(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ else if (this.canDemote())


public abstract void afterUpgrade();

public abstract boolean isEnoughProficiencyForUpgrade();
public boolean isMaxProficiency()
{
return construction.saveData.getProficiency() >= maxProficiency;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -105,11 +105,11 @@ public void updateModifiedValues() {
}
}

protected boolean canUpgrade() {
public boolean canUpgrade() {
if (construction.levelComponent.isReachMaxLevel() || upgradeCostPack == null) {
return false;
}
if (!construction.proficiencyComponent.isMaxProficiency()) {
if (!construction.proficiencyComponent.isEnoughProficiencyForUpgrade()) {
return false;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,5 +37,15 @@ public void afterUpgrade() {
}
}


@Override
public boolean isEnoughProficiencyForUpgrade() {
if (upgradeLostProficiency != null) {
return isMaxProficiency();
} else {
return true;
}
}

protected abstract void tryProficiencyOnce();
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,4 +18,9 @@ public void onSubLogicFrame() {
public void afterUpgrade() {
// do nothing
}

@Override
public boolean isEnoughProficiencyForUpgrade() {
return true;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,11 @@
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.Getter;
import lombok.NoArgsConstructor;

@Getter
@AllArgsConstructor
@NoArgsConstructor
public class GridPosition {

int x;
Expand Down

0 comments on commit 1cd3856

Please sign in to comment.