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

@ -20,6 +20,11 @@ public class Character {
* The id of the character * The id of the character
*/ */
int id; int id;
/**
* The name of the character
*/
String name;
/** /**
* The physical appearance of the character * The physical appearance of the character
@ -126,6 +131,21 @@ public class Character {
this.needs = needs; 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; package org.studiorailgun.sim.eval.command;
import org.studiorailgun.Globals; import org.studiorailgun.Globals;
import org.studiorailgun.sim.character.Character;
import org.studiorailgun.sim.space.Location; import org.studiorailgun.sim.space.Location;
/** /**
@ -13,7 +14,27 @@ public class LookCommand {
*/ */
public static void handle(String input){ public static void handle(String input){
Location playerLoc = Globals.playerCharacter.getLocation(); 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.LinkedList;
import java.util.List; import java.util.List;
import java.util.stream.Collectors;
import org.studiorailgun.Globals;
import org.studiorailgun.sim.character.Character; import org.studiorailgun.sim.character.Character;
import org.studiorailgun.sim.item.Item; import org.studiorailgun.sim.item.Item;
import org.studiorailgun.sim.writing.GroupDescriber; import org.studiorailgun.sim.writing.GroupDescriber;
@ -38,12 +40,13 @@ public class Location {
* Describes the location * Describes the location
*/ */
public void describe(){ 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){ 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){ 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 + ".");
} }
} }