expanding look command
All checks were successful
studiorailgun/trpg/pipeline/head This commit looks good

This commit is contained in:
austin 2025-01-06 15:34:30 -05:00
parent 01559b9283
commit 8e5546d772
3 changed files with 48 additions and 4 deletions

View File

@ -21,6 +21,11 @@ public class Character {
*/
int id;
/**
* The name of the character
*/
String name;
/**
* The physical appearance of the character
*/
@ -126,6 +131,21 @@ public class Character {
this.needs = needs;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
/**
* Describes the character
*/
public void describe(){
System.out.println("A " + this.getAppearance().getRace() + ".");
}

View File

@ -1,6 +1,7 @@
package org.studiorailgun.sim.eval.command;
import org.studiorailgun.Globals;
import org.studiorailgun.sim.character.Character;
import org.studiorailgun.sim.space.Location;
/**
@ -13,7 +14,27 @@ public class LookCommand {
*/
public static void handle(String input){
Location playerLoc = Globals.playerCharacter.getLocation();
playerLoc.describe();
if(LookCommand.scanForNames(input, playerLoc) != null){
Character character = LookCommand.scanForNames(input, playerLoc);
character.describe();
} else {
playerLoc.describe();
}
}
/**
* Scans the input for character names and returns the character that is found.
* @param input The input string
* @param loc The location to scan within
* @return The character if one is found, false otherwise
*/
private static Character scanForNames(String input, Location loc){
for(Character character : loc.getChars()){
if(input.contains(character.getName())){
return character;
}
}
return null;
}
}

View File

@ -2,7 +2,9 @@ package org.studiorailgun.sim.space;
import java.util.LinkedList;
import java.util.List;
import java.util.stream.Collectors;
import org.studiorailgun.Globals;
import org.studiorailgun.sim.character.Character;
import org.studiorailgun.sim.item.Item;
import org.studiorailgun.sim.writing.GroupDescriber;
@ -38,12 +40,13 @@ public class Location {
* Describes the location
*/
public void describe(){
System.out.println("You are in a " + this.type);
System.out.println("You are in a " + this.type + ".");
if(chars.size() > 1){
GroupDescriber.summarize(chars);
List<Character> filtered = chars.stream().filter(chara -> chara != Globals.playerCharacter).collect(Collectors.toList());
GroupDescriber.summarize(filtered);
}
if(items.size() > 0){
System.out.println("There are " + items.size() + " items in the " + this.type);
System.out.println("There are " + items.size() + " items in the " + this.type + ".");
}
}