mirror of
https://github.com/OMGeeky/andors-trail.git
synced 2026-02-23 15:38:29 +01:00
Refactor: Rename PhraseReward -> ScriptEffect
* This commit does not contain changes to json field names when parsing phrases though.
This commit is contained in:
@@ -66,11 +66,11 @@ public final class Dialogs {
|
||||
showConversation(currentActivity, context, phraseID, npc, true);
|
||||
}
|
||||
|
||||
private static void showConversation(final MainActivity currentActivity, final ControllerContext context, final String phraseID, final Monster npc, boolean giveRewardsForFirstPhrase) {
|
||||
private static void showConversation(final MainActivity currentActivity, final ControllerContext context, final String phraseID, final Monster npc, boolean applyScriptEffectsForFirstPhrase) {
|
||||
context.gameRoundController.pause();
|
||||
Intent intent = new Intent(currentActivity, ConversationActivity.class);
|
||||
intent.setData(Uri.parse("content://com.gpl.rpg.AndorsTrail/conversation/" + phraseID));
|
||||
intent.putExtra("giveRewardsForFirstPhrase", giveRewardsForFirstPhrase);
|
||||
intent.putExtra("applyScriptEffectsForFirstPhrase", applyScriptEffectsForFirstPhrase);
|
||||
addMonsterIdentifiers(intent, npc);
|
||||
currentActivity.startActivityForResult(intent, MainActivity.INTENTREQUEST_CONVERSATION);
|
||||
}
|
||||
|
||||
@@ -108,21 +108,21 @@ public final class ConversationActivity
|
||||
statementList.setFocusableInTouchMode(false);
|
||||
|
||||
String phraseID;
|
||||
boolean giveRewardsForFirstPhrase;
|
||||
boolean applyScriptEffectsForFirstPhrase;
|
||||
boolean displayLastMessage = true;
|
||||
if (savedInstanceState != null) {
|
||||
conversationState.setCurrentNPC(Dialogs.getMonsterFromBundle(savedInstanceState, world));
|
||||
ArrayList<ConversationStatement> savedConversationHistory = savedInstanceState.getParcelableArrayList("conversationHistory");
|
||||
if (savedConversationHistory != null) conversationHistory.addAll(savedConversationHistory);
|
||||
phraseID = savedInstanceState.getString("phraseID");
|
||||
giveRewardsForFirstPhrase = false;
|
||||
applyScriptEffectsForFirstPhrase = false;
|
||||
displayLastMessage = false;
|
||||
} else {
|
||||
conversationState.setCurrentNPC(Dialogs.getMonsterFromIntent(getIntent(), world));
|
||||
phraseID = getIntent().getData().getLastPathSegment();
|
||||
giveRewardsForFirstPhrase = getIntent().getBooleanExtra("giveRewardsForFirstPhrase", true);
|
||||
applyScriptEffectsForFirstPhrase = getIntent().getBooleanExtra("applyScriptEffectsForFirstPhrase", true);
|
||||
}
|
||||
conversationState.proceedToPhrase(getResources(), phraseID, giveRewardsForFirstPhrase, displayLastMessage);
|
||||
conversationState.proceedToPhrase(getResources(), phraseID, applyScriptEffectsForFirstPhrase, displayLastMessage);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -351,10 +351,10 @@ public final class ConversationActivity
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onPlayerReceivedRewards(ConversationController.PhraseRewards phraseRewards) {
|
||||
Loot loot = phraseRewards.loot;
|
||||
public void onScriptEffectsApplied(ConversationController.ScriptEffectResult scriptEffectResult) {
|
||||
Loot loot = scriptEffectResult.loot;
|
||||
|
||||
for (QuestProgress reward : phraseRewards.questProgress) {
|
||||
for (QuestProgress reward : scriptEffectResult.questProgress) {
|
||||
Quest q = world.quests.getQuest(reward.questID);
|
||||
if (!q.showInLog) continue;
|
||||
QuestLogEntry logEntry = q.getQuestLogEntry(reward.progress);
|
||||
|
||||
@@ -15,6 +15,7 @@ import com.gpl.rpg.AndorsTrail.model.item.Loot;
|
||||
import com.gpl.rpg.AndorsTrail.model.quest.QuestLogEntry;
|
||||
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.util.ConstRange;
|
||||
import com.gpl.rpg.AndorsTrail.util.L;
|
||||
|
||||
@@ -32,7 +33,7 @@ public final class ConversationController {
|
||||
|
||||
private static final ConstRange always = new ConstRange(1, 1);
|
||||
|
||||
public static final class PhraseRewards {
|
||||
public static final class ScriptEffectResult {
|
||||
public final Loot loot = new Loot();
|
||||
public final ArrayList<ActorConditionEffect> actorConditions = new ArrayList<ActorConditionEffect>();
|
||||
public final ArrayList<SkillInfo> skillIncrease = new ArrayList<SkillInfo>();
|
||||
@@ -47,32 +48,32 @@ public final class ConversationController {
|
||||
}
|
||||
}
|
||||
|
||||
private PhraseRewards applyPhraseRewards(final Player player, final Phrase phrase) {
|
||||
if (phrase.rewards == null || phrase.rewards.length == 0) return null;
|
||||
private ScriptEffectResult applyScriptEffectsForPhrase(final Player player, final Phrase phrase) {
|
||||
if (phrase.scriptEffects == null || phrase.scriptEffects.length == 0) return null;
|
||||
|
||||
final PhraseRewards result = new PhraseRewards();
|
||||
for (Reward reward : phrase.rewards) {
|
||||
switch (reward.rewardType) {
|
||||
final ScriptEffectResult result = new ScriptEffectResult();
|
||||
for (ScriptEffect effect : phrase.scriptEffects) {
|
||||
switch (effect.type) {
|
||||
case actorCondition:
|
||||
addActorConditionReward(player, reward.rewardID, reward.value, result);
|
||||
addActorConditionReward(player, effect.effectID, effect.value, result);
|
||||
break;
|
||||
case skillIncrease:
|
||||
addSkillReward(player, SkillCollection.SkillID.valueOf(reward.rewardID), result);
|
||||
addSkillReward(player, SkillCollection.SkillID.valueOf(effect.effectID), result);
|
||||
break;
|
||||
case dropList:
|
||||
addDropListReward(player, reward.rewardID, result);
|
||||
addDropListReward(player, effect.effectID, result);
|
||||
break;
|
||||
case questProgress:
|
||||
addQuestProgressReward(player, reward.rewardID, reward.value, result);
|
||||
addQuestProgressReward(player, effect.effectID, effect.value, result);
|
||||
break;
|
||||
case alignmentChange:
|
||||
addAlignmentReward(player, reward.rewardID, reward.value);
|
||||
addAlignmentReward(player, effect.effectID, effect.value);
|
||||
break;
|
||||
case giveItem:
|
||||
addItemReward(reward.rewardID, reward.value, result);
|
||||
addItemReward(effect.effectID, effect.value, result);
|
||||
break;
|
||||
case createTimer:
|
||||
world.model.worldData.createTimer(reward.rewardID);
|
||||
world.model.worldData.createTimer(effect.effectID);
|
||||
break;
|
||||
}
|
||||
}
|
||||
@@ -90,7 +91,7 @@ public final class ConversationController {
|
||||
MovementController.refreshMonsterAggressiveness(world.model.currentMap, world.model.player);
|
||||
}
|
||||
|
||||
private void addQuestProgressReward(Player player, String questID, int questProgress, PhraseRewards result) {
|
||||
private void addQuestProgressReward(Player player, String questID, int questProgress, ScriptEffectResult result) {
|
||||
QuestProgress progress = new QuestProgress(questID, questProgress);
|
||||
boolean added = player.addQuestProgress(progress);
|
||||
if (!added) return; // Only apply exp reward if the quest stage was reached just now (and not re-reached)
|
||||
@@ -101,15 +102,15 @@ public final class ConversationController {
|
||||
result.questProgress.add(progress);
|
||||
}
|
||||
|
||||
private void addDropListReward(Player player, String droplistID, PhraseRewards result) {
|
||||
private void addDropListReward(Player player, String droplistID, ScriptEffectResult result) {
|
||||
world.dropLists.getDropList(droplistID).createRandomLoot(result.loot, player);
|
||||
}
|
||||
|
||||
private void addItemReward(String itemTypeID, int quantity, PhraseRewards result) {
|
||||
private void addItemReward(String itemTypeID, int quantity, ScriptEffectResult result) {
|
||||
result.loot.add(world.itemTypes.getItemType(itemTypeID), quantity);
|
||||
}
|
||||
|
||||
private void addSkillReward(Player player, SkillCollection.SkillID skillID, PhraseRewards result) {
|
||||
private void addSkillReward(Player player, SkillCollection.SkillID skillID, ScriptEffectResult result) {
|
||||
SkillInfo skill = world.skills.getSkill(skillID);
|
||||
boolean addedSkill = controllers.skillController.levelUpSkillByQuest(player, skill);
|
||||
if (addedSkill) {
|
||||
@@ -117,7 +118,7 @@ public final class ConversationController {
|
||||
}
|
||||
}
|
||||
|
||||
private void addActorConditionReward(Player player, String conditionTypeID, int value, PhraseRewards result) {
|
||||
private void addActorConditionReward(Player player, String conditionTypeID, int value, ScriptEffectResult result) {
|
||||
int magnitude = 1;
|
||||
int duration = value;
|
||||
if (value == ActorCondition.DURATION_FOREVER) duration = ActorCondition.DURATION_FOREVER;
|
||||
@@ -149,7 +150,7 @@ public final class ConversationController {
|
||||
public static boolean canFulfillRequirement(WorldContext world, Requirement requirement) {
|
||||
Player player = world.model.player;
|
||||
GameStatistics stats = world.model.statistics;
|
||||
boolean result = false;
|
||||
boolean result;
|
||||
switch (requirement.requireType) {
|
||||
case questProgress:
|
||||
result = player.hasExactQuestProgress(requirement.requireID, requirement.value);
|
||||
@@ -247,7 +248,7 @@ public final class ConversationController {
|
||||
void onConversationEndedWithShop(Monster npc);
|
||||
void onConversationEndedWithCombat(Monster npc);
|
||||
void onConversationEndedWithRemoval(Monster npc);
|
||||
void onPlayerReceivedRewards(ConversationController.PhraseRewards phraseRewards);
|
||||
void onScriptEffectsApplied(ScriptEffectResult scriptEffectResult);
|
||||
void onConversationCanProceedWithNext();
|
||||
void onConversationHasReply(Reply r, String message);
|
||||
}
|
||||
@@ -263,7 +264,7 @@ public final class ConversationController {
|
||||
}
|
||||
}
|
||||
|
||||
public void proceedToPhrase(final Resources res, String phraseID, boolean giveRewards, boolean displayPhraseMessage) {
|
||||
public void proceedToPhrase(final Resources res, String phraseID, boolean applyScriptEffects, boolean displayPhraseMessage) {
|
||||
if (phraseID.equalsIgnoreCase(ConversationCollection.PHRASE_CLOSE)) {
|
||||
listener.onConversationEnded();
|
||||
return;
|
||||
@@ -280,10 +281,10 @@ public final class ConversationController {
|
||||
|
||||
setCurrentPhrase(res, phraseID);
|
||||
|
||||
if (giveRewards) {
|
||||
ConversationController.PhraseRewards phraseRewards = controllers.conversationController.applyPhraseRewards(player, currentPhrase);
|
||||
if (phraseRewards != null) {
|
||||
listener.onPlayerReceivedRewards(phraseRewards);
|
||||
if (applyScriptEffects) {
|
||||
ScriptEffectResult scriptEffectResult = controllers.conversationController.applyScriptEffectsForPhrase(player, currentPhrase);
|
||||
if (scriptEffectResult != null) {
|
||||
listener.onScriptEffectsApplied(scriptEffectResult);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -291,7 +292,7 @@ public final class ConversationController {
|
||||
for (Reply r : currentPhrase.replies) {
|
||||
if (!canSelectReply(world, r)) continue;
|
||||
applyReplyEffect(world, r);
|
||||
proceedToPhrase(res, r.nextPhrase, giveRewards, displayPhraseMessage);
|
||||
proceedToPhrase(res, r.nextPhrase, applyScriptEffects, displayPhraseMessage);
|
||||
return;
|
||||
}
|
||||
} else if (displayPhraseMessage) {
|
||||
|
||||
@@ -201,7 +201,7 @@ public final class MapController {
|
||||
public void onTextPhraseReached(String message, Actor actor, String phraseID) {
|
||||
worldEventListeners.onScriptAreaStartedConversation(phraseID);
|
||||
}
|
||||
@Override public void onPlayerReceivedRewards(ConversationController.PhraseRewards phraseRewards) { }
|
||||
@Override public void onScriptEffectsApplied(ConversationController.ScriptEffectResult scriptEffectResult) { }
|
||||
@Override public void onConversationEnded() { }
|
||||
@Override public void onConversationEndedWithShop(Monster npc) { }
|
||||
@Override public void onConversationEndedWithCombat(Monster npc) { }
|
||||
|
||||
@@ -1,23 +1,25 @@
|
||||
package com.gpl.rpg.AndorsTrail.model.conversation;
|
||||
|
||||
import com.gpl.rpg.AndorsTrail.model.script.ScriptEffect;
|
||||
|
||||
public final class Phrase {
|
||||
private static final Reply[] NO_REPLIES = new Reply[0];
|
||||
|
||||
public final String message;
|
||||
public final Reply[] replies;
|
||||
public final Reward[] rewards; // If this phrase is reached, player will be awarded all these rewards
|
||||
public final ScriptEffect[] scriptEffects; // If this phrase is reached, all these effects will run
|
||||
public final String switchToNPC;
|
||||
|
||||
public Phrase(
|
||||
String message
|
||||
, Reply[] replies
|
||||
, Reward[] rewards
|
||||
, ScriptEffect[] scriptEffects
|
||||
, String switchToNPC
|
||||
) {
|
||||
this.message = message;
|
||||
if (replies == null || replies.length == 0) replies = NO_REPLIES;
|
||||
this.replies = replies;
|
||||
this.rewards = rewards;
|
||||
this.scriptEffects = scriptEffects;
|
||||
this.switchToNPC = switchToNPC;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,27 +1,27 @@
|
||||
package com.gpl.rpg.AndorsTrail.model.conversation;
|
||||
package com.gpl.rpg.AndorsTrail.model.script;
|
||||
|
||||
public final class Reward {
|
||||
public static enum RewardType {
|
||||
public final class ScriptEffect {
|
||||
public static enum ScriptEffectType {
|
||||
questProgress
|
||||
,dropList
|
||||
,skillIncrease
|
||||
,actorCondition
|
||||
,alignmentChange
|
||||
,giveItem
|
||||
,createTimer
|
||||
, dropList
|
||||
, skillIncrease
|
||||
, actorCondition
|
||||
, alignmentChange
|
||||
, giveItem
|
||||
, createTimer
|
||||
}
|
||||
|
||||
public final RewardType rewardType;
|
||||
public final String rewardID;
|
||||
public final ScriptEffectType type;
|
||||
public final String effectID;
|
||||
public final int value;
|
||||
|
||||
public Reward(
|
||||
RewardType rewardType
|
||||
, String rewardID
|
||||
public ScriptEffect(
|
||||
ScriptEffectType type
|
||||
, String effectID
|
||||
, int value
|
||||
) {
|
||||
this.rewardType = rewardType;
|
||||
this.rewardID = rewardID;
|
||||
this.type = type;
|
||||
this.effectID = effectID;
|
||||
this.value = value;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -3,7 +3,7 @@ package com.gpl.rpg.AndorsTrail.resource.parsers;
|
||||
import com.gpl.rpg.AndorsTrail.AndorsTrailApplication;
|
||||
import com.gpl.rpg.AndorsTrail.model.conversation.Phrase;
|
||||
import com.gpl.rpg.AndorsTrail.model.conversation.Reply;
|
||||
import com.gpl.rpg.AndorsTrail.model.conversation.Reward;
|
||||
import com.gpl.rpg.AndorsTrail.model.script.ScriptEffect;
|
||||
import com.gpl.rpg.AndorsTrail.model.script.Requirement;
|
||||
import com.gpl.rpg.AndorsTrail.resource.TranslationLoader;
|
||||
import com.gpl.rpg.AndorsTrail.resource.parsers.json.JsonArrayParserFor;
|
||||
@@ -41,11 +41,11 @@ public final class ConversationListParser extends JsonCollectionParserFor<Phrase
|
||||
}
|
||||
};
|
||||
|
||||
private final JsonArrayParserFor<Reward> rewardParser = new JsonArrayParserFor<Reward>(Reward.class) {
|
||||
private final JsonArrayParserFor<ScriptEffect> scriptEffectParser = new JsonArrayParserFor<ScriptEffect>(ScriptEffect.class) {
|
||||
@Override
|
||||
protected Reward parseObject(JSONObject o) throws JSONException {
|
||||
return new Reward(
|
||||
Reward.RewardType.valueOf(o.getString(JsonFieldNames.PhraseReward.rewardType))
|
||||
protected ScriptEffect parseObject(JSONObject o) throws JSONException {
|
||||
return new ScriptEffect(
|
||||
ScriptEffect.ScriptEffectType.valueOf(o.getString(JsonFieldNames.PhraseReward.rewardType))
|
||||
,o.getString(JsonFieldNames.PhraseReward.rewardID)
|
||||
,o.optInt(JsonFieldNames.PhraseReward.value, 0)
|
||||
);
|
||||
@@ -61,10 +61,10 @@ public final class ConversationListParser extends JsonCollectionParserFor<Phrase
|
||||
final String id = o.getString(JsonFieldNames.Phrase.phraseID);
|
||||
|
||||
Reply[] _replies = null;
|
||||
Reward[] _rewards = null;
|
||||
ScriptEffect[] _scriptEffects = null;
|
||||
try {
|
||||
_replies = replyParser.parseArray(o.optJSONArray(JsonFieldNames.Phrase.replies));
|
||||
_rewards = rewardParser.parseArray(o.optJSONArray(JsonFieldNames.Phrase.rewards));
|
||||
_scriptEffects = scriptEffectParser.parseArray(o.optJSONArray(JsonFieldNames.Phrase.rewards));
|
||||
} catch (JSONException e) {
|
||||
if (AndorsTrailApplication.DEVELOPMENT_DEBUGMESSAGES) {
|
||||
L.log("ERROR: parsing phrase " + id + " : " + e.getMessage());
|
||||
@@ -74,7 +74,7 @@ public final class ConversationListParser extends JsonCollectionParserFor<Phrase
|
||||
return new Pair<String, Phrase>(id, new Phrase(
|
||||
translationLoader.translateConversationPhrase(o.optString(JsonFieldNames.Phrase.message, null))
|
||||
, _replies
|
||||
, _rewards
|
||||
, _scriptEffects
|
||||
, o.optString(JsonFieldNames.Phrase.switchToNPC, null)
|
||||
));
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user