Skip to content

Commit

Permalink
Merge pull request Card-Forge#248 from magpie514/master
Browse files Browse the repository at this point in the history
Adventure mode - Revert RNG
  • Loading branch information
kevlahnota authored May 5, 2022
2 parents 9fd90a6 + 509ba33 commit 631ae3f
Show file tree
Hide file tree
Showing 4 changed files with 43 additions and 59 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -11,19 +11,18 @@
* Class to save point of interest changes, like sold cards and dead enemies
*/
public class PointOfInterestChanges implements SaveFileContent {
private final HashSet<Integer> deletedObjects=new HashSet<>();
private final HashMap<Integer, HashSet<Integer>> cardsBought = new HashMap<>();
private java.util.Map<String, Byte> mapFlags = new HashMap<>();

public static class Map extends HashMap<String,PointOfInterestChanges> implements SaveFileContent
{

public static class Map extends HashMap<String,PointOfInterestChanges> implements SaveFileContent {
@Override
public void load(SaveFileData data) {

this.clear();
if(data==null||!data.containsKey("keys"))
return;
if(data==null || !data.containsKey("keys")) return;

String[] keys= (String[]) data.readObject("keys");
for(int i=0;i<keys.length;i++)
{
for(int i=0;i<keys.length;i++) {
SaveFileData elementData = data.readSubData("value_"+i);
PointOfInterestChanges newChanges=new PointOfInterestChanges();
newChanges.load(elementData);
Expand Down Expand Up @@ -66,35 +65,21 @@ public SaveFileData save() {
return data;
}

private final HashSet<Integer> deletedObjects=new HashSet<>();
private final HashMap<Integer, HashSet<Integer>> cardsBought=new HashMap<>();
private java.util.Map<String, Byte> mapFlags = new HashMap<>();

public boolean isObjectDeleted(int objectID)
{
return deletedObjects.contains(objectID);
}
public boolean deleteObject(int objectID)
{
return deletedObjects.add(objectID);
}
public boolean isObjectDeleted(int objectID) { return deletedObjects.contains(objectID); }
public boolean deleteObject(int objectID) { return deletedObjects.add(objectID); }

public java.util.Map<String, Byte> getMapFlags() {
return mapFlags;
}

public void buyCard(int objectID, int cardIndex)
{
if( !cardsBought.containsKey(objectID))
{
public void buyCard(int objectID, int cardIndex) {
if( !cardsBought.containsKey(objectID)) {
cardsBought.put(objectID,new HashSet<>());
}
cardsBought.get(objectID).add(cardIndex);
}
public boolean wasCardBought(int objectID, int cardIndex)
{
if( !cardsBought.containsKey(objectID))
{
public boolean wasCardBought(int objectID, int cardIndex) {
if( !cardsBought.containsKey(objectID)) {
return false;
}
return cardsBought.get(objectID).contains(cardIndex);
Expand Down
38 changes: 19 additions & 19 deletions forge-gui-mobile/src/forge/adventure/scene/RewardScene.java
Original file line number Diff line number Diff line change
Expand Up @@ -269,25 +269,25 @@ public BuyButton(int id, int i, PointOfInterestChanges ch, RewardActor actor, Te
addListener(new ClickListener() {
@Override
public void clicked(InputEvent event, float x, float y) {
if (Current.player().getGold() >= price) {
if(changes!=null)
changes.buyCard(objectID, index);
Current.player().takeGold(price);
Current.player().addReward(reward.getReward());

Gdx.input.vibrate(5);
SoundSystem.instance.play(SoundEffectType.FlipCoin, false);

updateBuyButtons();
goldLabel.setText("Gold: " + String.valueOf(AdventurePlayer.current().getGold()));
if(changes==null)
return;
setDisabled(true);
reward.sold();
getColor().a = 0.5f;
setText("SOLD");
removeListener(this);
}
if (Current.player().getGold() >= price) {
if(changes!=null)
changes.buyCard(objectID, index);
Current.player().takeGold(price);
Current.player().addReward(reward.getReward());

Gdx.input.vibrate(5);
SoundSystem.instance.play(SoundEffectType.FlipCoin, false);

updateBuyButtons();
goldLabel.setText("Gold: " + String.valueOf(AdventurePlayer.current().getGold()));
if(changes==null)
return;
setDisabled(true);
reward.sold();
getColor().a = 0.5f;
setText("SOLD");
removeListener(this);
}
}
});
}
Expand Down
19 changes: 9 additions & 10 deletions forge-gui-mobile/src/forge/adventure/stage/MapStage.java
Original file line number Diff line number Diff line change
Expand Up @@ -373,7 +373,7 @@ public void run() {
case "shop":
String shopList = prop.get("shopList").toString();
shopList=shopList.replaceAll("\\s","");
List possibleShops = Arrays.asList(shopList.split(","));
List<String> possibleShops = Arrays.asList(shopList.split(","));
Array<ShopData> shops;
if (possibleShops.size() == 0 || shopList.equals(""))
shops = WorldData.getShopList();
Expand All @@ -385,8 +385,7 @@ public void run() {
}
}
}
if (shops.size == 0)
continue;
if(shops.size == 0) continue;

ShopData data = shops.get(WorldSave.getCurrentSave().getWorld().getRandom().nextInt(shops.size));
Array<Reward> ret = new Array<>();
Expand All @@ -406,6 +405,8 @@ public void run() {
}
}
break;
default:
System.err.println("Unexpected value: " + type);
}
}
}
Expand Down Expand Up @@ -494,16 +495,14 @@ protected void getReward() {
}
currentMob = null;
}
public void removeAllEnemies()
{
public void removeAllEnemies() {
List<Integer> idsToRemove=new ArrayList<>();
for (MapActor actor : new Array.ArrayIterator<>(actors)) {
if (actor instanceof EnemySprite) {
idsToRemove.add(actor.getObjectId());
}
if (actor instanceof EnemySprite) {
idsToRemove.add(actor.getObjectId());
}
}
for(Integer i:idsToRemove)
deleteObject(i);
for(Integer i:idsToRemove) deleteObject(i);
}

@Override
Expand Down
4 changes: 2 additions & 2 deletions forge-gui-mobile/src/forge/adventure/world/World.java
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
import forge.adventure.util.Paths;
import forge.adventure.util.SaveFileContent;
import forge.adventure.util.SaveFileData;
import forge.util.MyRandom;
//import forge.util.MyRandom;
import org.apache.commons.lang3.tuple.Pair;

import java.util.ArrayList;
Expand All @@ -46,7 +46,7 @@ public class World implements Disposable, SaveFileContent {
private PointOfInterestMap mapPoiIds;
private BiomeTexture[] biomeTexture;
private long seed;
private final Random random = MyRandom.getRandom();
private final Random random = new Random();
private boolean worldDataLoaded=false;
private Texture globalTexture = null;

Expand Down

0 comments on commit 631ae3f

Please sign in to comment.