mirror of
https://github.com/OMGeeky/andors-trail.git
synced 2026-01-08 04:27:18 +01:00
Refactor conversations to state machine - Move responsibility for starting combat & removing npcs from map from MainActivity into the ConversationController.
This commit is contained in:
@@ -137,19 +137,6 @@ public final class MainActivity extends Activity implements PlayerMovementListen
|
||||
break;
|
||||
case INTENTREQUEST_CONVERSATION:
|
||||
MovementController.refreshMonsterAggressiveness(world.model.currentMap, world.model.player);
|
||||
if (resultCode == ConversationActivity.ACTIVITYRESULT_ATTACK) {
|
||||
final Coord p = world.model.player.nextPosition;
|
||||
Monster m = world.model.currentMap.getMonsterAt(p);
|
||||
if (m == null) return; //Shouldn't happen.
|
||||
m.forceAggressive();
|
||||
controllers.combatController.setCombatSelection(m, p);
|
||||
controllers.combatController.enterCombat(CombatController.BEGIN_TURN_PLAYER);
|
||||
} else if (resultCode == ConversationActivity.ACTIVITYRESULT_REMOVE) {
|
||||
final Coord p = world.model.player.nextPosition;
|
||||
Monster m = world.model.currentMap.getMonsterAt(p);
|
||||
if (m == null) return;
|
||||
controllers.monsterSpawnController.remove(world.model.currentMap, m);
|
||||
}
|
||||
break;
|
||||
case INTENTREQUEST_PREFERENCES:
|
||||
AndorsTrailApplication app = AndorsTrailApplication.getApplicationFromActivity(this);
|
||||
|
||||
@@ -20,6 +20,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.util.ConstRange;
|
||||
import com.gpl.rpg.AndorsTrail.util.Coord;
|
||||
|
||||
import java.util.ArrayList;
|
||||
|
||||
@@ -218,10 +219,10 @@ public final class ConversationController {
|
||||
listener.onConversationEndedWithShop(npc);
|
||||
return;
|
||||
} else if (phraseID.equalsIgnoreCase(ConversationCollection.PHRASE_ATTACK)) {
|
||||
listener.onConversationEndedWithCombat(npc);
|
||||
endConversationWithCombat();
|
||||
return;
|
||||
} else if (phraseID.equalsIgnoreCase(ConversationCollection.PHRASE_REMOVE)) {
|
||||
listener.onConversationEndedWithRemoval(npc);
|
||||
endConversationWithRemovingNPC();
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -247,7 +248,19 @@ public final class ConversationController {
|
||||
requestReplies();
|
||||
}
|
||||
|
||||
private void requestReplies() {
|
||||
private void endConversationWithRemovingNPC() {
|
||||
controllers.monsterSpawnController.remove(world.model.currentMap, npc);
|
||||
listener.onConversationEndedWithRemoval(npc);
|
||||
}
|
||||
|
||||
private void endConversationWithCombat() {
|
||||
npc.forceAggressive();
|
||||
controllers.combatController.setCombatSelection(npc);
|
||||
controllers.combatController.enterCombat(CombatController.BEGIN_TURN_PLAYER);
|
||||
listener.onConversationEndedWithCombat(npc);
|
||||
}
|
||||
|
||||
private void requestReplies() {
|
||||
if (hasOnlyOneNextReply()) {
|
||||
listener.onConversationCanProceedWithNext();
|
||||
return;
|
||||
|
||||
Reference in New Issue
Block a user