From 9a0f183392fed7247d0ef632129601bafbaf9857 Mon Sep 17 00:00:00 2001 From: Gonk Date: Wed, 24 Apr 2019 23:03:36 +0200 Subject: [PATCH 1/2] Added random requirement using the same format like the droplist chance encoded in the requireID. --- .../controller/ConversationController.java | 4 ++ .../AndorsTrail/model/script/Requirement.java | 54 ++++++++++--------- 2 files changed, 33 insertions(+), 25 deletions(-) diff --git a/AndorsTrail/src/com/gpl/rpg/AndorsTrail/controller/ConversationController.java b/AndorsTrail/src/com/gpl/rpg/AndorsTrail/controller/ConversationController.java index 9d57477df..dd956ff08 100644 --- a/AndorsTrail/src/com/gpl/rpg/AndorsTrail/controller/ConversationController.java +++ b/AndorsTrail/src/com/gpl/rpg/AndorsTrail/controller/ConversationController.java @@ -28,6 +28,7 @@ import com.gpl.rpg.AndorsTrail.model.quest.QuestProgress; import com.gpl.rpg.AndorsTrail.model.script.Requirement; import com.gpl.rpg.AndorsTrail.model.script.ScriptEffect; +import com.gpl.rpg.AndorsTrail.resource.parsers.ResourceParserUtils; import com.gpl.rpg.AndorsTrail.util.ConstRange; import com.gpl.rpg.AndorsTrail.util.L; @@ -295,6 +296,9 @@ public static boolean canFulfillRequirement(WorldContext world, Requirement requ case spentGold: result = stats.getSpentGold() >= requirement.value; break; + case random: + result = Constants.rollResult(ResourceParserUtils.parseChance(requirement.requireID)); + break; case consumedBonemeals: result = stats.getNumberOfUsedBonemealPotions() >= requirement.value; break; diff --git a/AndorsTrail/src/com/gpl/rpg/AndorsTrail/model/script/Requirement.java b/AndorsTrail/src/com/gpl/rpg/AndorsTrail/model/script/Requirement.java index bcd2b65d7..7555e4fe0 100644 --- a/AndorsTrail/src/com/gpl/rpg/AndorsTrail/model/script/Requirement.java +++ b/AndorsTrail/src/com/gpl/rpg/AndorsTrail/model/script/Requirement.java @@ -17,6 +17,7 @@ public static enum RequirementType { ,consumedBonemeals ,hasActorCondition ,factionScore + ,random } public final RequirementType requireType; @@ -34,8 +35,9 @@ public Requirement( this.requireID = requireID; this.value = value; this.negate = negate; + } - + public Requirement(QuestProgress qp) { this.requireType = RequirementType.questProgress; this.requireID = qp.questID; @@ -52,32 +54,34 @@ public String toString() { buf.append(value); return buf.toString(); } - + public boolean isValid() { switch (this.requireType) { - case consumedBonemeals: - return value >= 0; - case hasActorCondition: - return requireID != null; - case inventoryKeep: - case inventoryRemove: - case usedItem: - return requireID != null && value >= 0; - case killedMonster: - return requireID != null && value >= 0; - case questLatestProgress: - case questProgress: - return requireID != null && value >= 0; - case skillLevel: - return requireID != null && value >= 0; - case spentGold: - return value >= 0; - case timerElapsed: - return requireID != null && value >= 0; - case wear: - return requireID != null; - default: - return false; + case consumedBonemeals: + return value >= 0; + case hasActorCondition: + return requireID != null; + case inventoryKeep: + case inventoryRemove: + case usedItem: + return requireID != null && value >= 0; + case killedMonster: + return requireID != null && value >= 0; + case questLatestProgress: + case questProgress: + return requireID != null && value >= 0; + case skillLevel: + return requireID != null && value >= 0; + case spentGold: + return value >= 0; + case random: + return requireID != null; + case timerElapsed: + return requireID != null && value >= 0; + case wear: + return requireID != null; + default: + return false; } } } From 176cf1dd764b41064b2f830ef186d1640aeecf1d Mon Sep 17 00:00:00 2001 From: Gonk Date: Sat, 11 May 2019 21:27:11 +0200 Subject: [PATCH 2/2] Use chance member in Requirement for random requirements - it is based on the text in requireID - adjusted parsing --- .../controller/ConversationController.java | 3 +-- .../rpg/AndorsTrail/model/map/TMXMapTranslator.java | 11 ++++++++++- .../gpl/rpg/AndorsTrail/model/script/Requirement.java | 8 ++++++-- .../resource/parsers/ConversationListParser.java | 7 +++++-- 4 files changed, 22 insertions(+), 7 deletions(-) diff --git a/AndorsTrail/src/com/gpl/rpg/AndorsTrail/controller/ConversationController.java b/AndorsTrail/src/com/gpl/rpg/AndorsTrail/controller/ConversationController.java index dd956ff08..5834be335 100644 --- a/AndorsTrail/src/com/gpl/rpg/AndorsTrail/controller/ConversationController.java +++ b/AndorsTrail/src/com/gpl/rpg/AndorsTrail/controller/ConversationController.java @@ -28,7 +28,6 @@ import com.gpl.rpg.AndorsTrail.model.quest.QuestProgress; import com.gpl.rpg.AndorsTrail.model.script.Requirement; import com.gpl.rpg.AndorsTrail.model.script.ScriptEffect; -import com.gpl.rpg.AndorsTrail.resource.parsers.ResourceParserUtils; import com.gpl.rpg.AndorsTrail.util.ConstRange; import com.gpl.rpg.AndorsTrail.util.L; @@ -297,7 +296,7 @@ public static boolean canFulfillRequirement(WorldContext world, Requirement requ result = stats.getSpentGold() >= requirement.value; break; case random: - result = Constants.rollResult(ResourceParserUtils.parseChance(requirement.requireID)); + result = Constants.rollResult(requirement.chance); break; case consumedBonemeals: result = stats.getNumberOfUsedBonemealPotions() >= requirement.value; diff --git a/AndorsTrail/src/com/gpl/rpg/AndorsTrail/model/map/TMXMapTranslator.java b/AndorsTrail/src/com/gpl/rpg/AndorsTrail/model/map/TMXMapTranslator.java index 133ee1a61..1b9f50b1d 100644 --- a/AndorsTrail/src/com/gpl/rpg/AndorsTrail/model/map/TMXMapTranslator.java +++ b/AndorsTrail/src/com/gpl/rpg/AndorsTrail/model/map/TMXMapTranslator.java @@ -27,7 +27,9 @@ import com.gpl.rpg.AndorsTrail.model.map.TMXMapFileParser.TMXTileSet; import com.gpl.rpg.AndorsTrail.model.quest.QuestProgress; import com.gpl.rpg.AndorsTrail.model.script.Requirement; +import com.gpl.rpg.AndorsTrail.resource.parsers.ResourceParserUtils; import com.gpl.rpg.AndorsTrail.resource.tiles.TileCache; +import com.gpl.rpg.AndorsTrail.util.ConstRange; import com.gpl.rpg.AndorsTrail.util.Coord; import com.gpl.rpg.AndorsTrail.util.CoordRect; import com.gpl.rpg.AndorsTrail.util.L; @@ -227,6 +229,7 @@ private static Requirement parseRequirement(TMXObject object) { String requireId = null; int requireValue = 0; boolean requireNegation = false; + ConstRange requireChance = null; for (TMXProperty p : object.properties) { if (p.name.equalsIgnoreCase("requireType")) { try { @@ -246,7 +249,13 @@ private static Requirement parseRequirement(TMXObject object) { } } if (requireType == null) return null; - return new Requirement(requireType, requireId, requireValue, requireNegation); + if (requireType == Requirement.RequirementType.random) + { + requireChance = ResourceParserUtils.parseChance(requireId); + requireId = null; + } + + return new Requirement(requireType, requireId, requireValue, requireNegation, requireChance); } private static CoordRect getTMXObjectPosition(TMXObject object, TMXMap m) { diff --git a/AndorsTrail/src/com/gpl/rpg/AndorsTrail/model/script/Requirement.java b/AndorsTrail/src/com/gpl/rpg/AndorsTrail/model/script/Requirement.java index 7555e4fe0..d12f71ec1 100644 --- a/AndorsTrail/src/com/gpl/rpg/AndorsTrail/model/script/Requirement.java +++ b/AndorsTrail/src/com/gpl/rpg/AndorsTrail/model/script/Requirement.java @@ -1,6 +1,7 @@ package com.gpl.rpg.AndorsTrail.model.script; import com.gpl.rpg.AndorsTrail.model.quest.QuestProgress; +import com.gpl.rpg.AndorsTrail.util.ConstRange; public final class Requirement { public static enum RequirementType { @@ -24,18 +25,20 @@ public static enum RequirementType { public final String requireID; public final int value; public final boolean negate; + public final ConstRange chance; public Requirement( RequirementType requireType , String requireID , int value , boolean negate + , ConstRange chance ) { this.requireType = requireType; this.requireID = requireID; this.value = value; this.negate = negate; - + this.chance = chance; } public Requirement(QuestProgress qp) { @@ -43,6 +46,7 @@ public Requirement(QuestProgress qp) { this.requireID = qp.questID; this.value = qp.progress; this.negate = false; + this.chance = null; } public String toString() { @@ -75,7 +79,7 @@ public boolean isValid() { case spentGold: return value >= 0; case random: - return requireID != null; + return chance != null; case timerElapsed: return requireID != null && value >= 0; case wear: diff --git a/AndorsTrail/src/com/gpl/rpg/AndorsTrail/resource/parsers/ConversationListParser.java b/AndorsTrail/src/com/gpl/rpg/AndorsTrail/resource/parsers/ConversationListParser.java index aef8b1c0f..215c984b2 100644 --- a/AndorsTrail/src/com/gpl/rpg/AndorsTrail/resource/parsers/ConversationListParser.java +++ b/AndorsTrail/src/com/gpl/rpg/AndorsTrail/resource/parsers/ConversationListParser.java @@ -22,11 +22,14 @@ public final class ConversationListParser extends JsonCollectionParserFor requirementParser = new JsonArrayParserFor(Requirement.class) { @Override protected Requirement parseObject(JSONObject o) throws JSONException { + Requirement.RequirementType type = Requirement.RequirementType.valueOf(o.getString(JsonFieldNames.ReplyRequires.requireType)); + String requireID = o.getString(JsonFieldNames.ReplyRequires.requireID); return new Requirement( - Requirement.RequirementType.valueOf(o.getString(JsonFieldNames.ReplyRequires.requireType)) - ,o.getString(JsonFieldNames.ReplyRequires.requireID) + type + ,type == Requirement.RequirementType.random ? null : requireID ,o.optInt(JsonFieldNames.ReplyRequires.value, 0) ,o.optBoolean(JsonFieldNames.ReplyRequires.negate, false) + ,type == Requirement.RequirementType.random ? ResourceParserUtils.parseChance(requireID) : null ); } };