2017-06-29 17:25:38 +00:00
|
|
|
/// <reference path="MissionPart.ts" />
|
|
|
|
|
2017-09-24 22:23:22 +00:00
|
|
|
module TK.SpaceTac {
|
2017-06-29 17:25:38 +00:00
|
|
|
/**
|
2017-07-06 22:55:29 +00:00
|
|
|
* A single conversation piece
|
2017-06-29 17:25:38 +00:00
|
|
|
*/
|
2017-07-06 22:55:29 +00:00
|
|
|
interface ConversationPiece {
|
2017-06-29 17:25:38 +00:00
|
|
|
// Interlocutor (null for the player's fleet)
|
|
|
|
interlocutor: Ship | null
|
|
|
|
|
|
|
|
// Text message
|
|
|
|
message: string
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2017-07-06 22:55:29 +00:00
|
|
|
* A mission part that triggers a conversation
|
2017-06-29 17:25:38 +00:00
|
|
|
*/
|
2017-07-06 22:55:29 +00:00
|
|
|
export class MissionPartConversation extends MissionPart {
|
2017-06-29 17:25:38 +00:00
|
|
|
// Other ships with which the dialog will take place
|
|
|
|
interlocutors: Ship[]
|
|
|
|
|
|
|
|
// Pieces of dialog
|
2017-07-06 22:55:29 +00:00
|
|
|
pieces: ConversationPiece[] = []
|
2017-06-29 17:25:38 +00:00
|
|
|
|
|
|
|
// Current piece
|
|
|
|
current_piece = 0
|
|
|
|
|
2017-07-02 18:21:04 +00:00
|
|
|
constructor(mission: Mission, interlocutors: Ship[], directive?: string) {
|
|
|
|
super(mission, directive || `Speak with ${interlocutors[0].name}`);
|
2017-06-29 17:25:38 +00:00
|
|
|
|
|
|
|
this.interlocutors = interlocutors;
|
|
|
|
}
|
|
|
|
|
|
|
|
checkCompleted(): boolean {
|
|
|
|
return this.current_piece >= this.pieces.length;
|
|
|
|
}
|
|
|
|
|
|
|
|
forceComplete(): void {
|
|
|
|
this.skip();
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Add a piece of dialog
|
|
|
|
*/
|
|
|
|
addPiece(interlocutor: Ship | null, message: string): void {
|
|
|
|
this.pieces.push({
|
|
|
|
interlocutor: interlocutor,
|
|
|
|
message: message
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Go to the next dialog "screen"
|
|
|
|
*
|
|
|
|
* Returns true if there is still dialog to display.
|
|
|
|
*/
|
|
|
|
next(): boolean {
|
|
|
|
this.current_piece += 1;
|
|
|
|
return !this.checkCompleted();
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Skip to the end
|
|
|
|
*/
|
|
|
|
skip() {
|
|
|
|
while (this.next()) {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Get the current piece of dialog
|
|
|
|
*/
|
2017-07-06 22:55:29 +00:00
|
|
|
getCurrent(): ConversationPiece {
|
2017-06-29 17:25:38 +00:00
|
|
|
if (this.checkCompleted()) {
|
|
|
|
return {
|
|
|
|
interlocutor: null,
|
|
|
|
message: ""
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
let piece = this.pieces[this.current_piece];
|
|
|
|
return {
|
|
|
|
interlocutor: piece.interlocutor || this.getFleetInterlocutor(piece),
|
|
|
|
message: piece.message
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Get the interlocutor from the player fleet that will say the piece
|
|
|
|
*/
|
2017-07-06 22:55:29 +00:00
|
|
|
private getFleetInterlocutor(piece: ConversationPiece): Ship | null {
|
2017-06-29 17:25:38 +00:00
|
|
|
if (this.fleet.ships.length > 0) {
|
|
|
|
// TODO Choose a ship by its personality traits
|
|
|
|
return this.fleet.ships[0];
|
|
|
|
} else {
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|