Skip to content

Commit

Permalink
Merge pull request #588 from UQcsse3200/team1/debugging
Browse files Browse the repository at this point in the history
Team1/debugging
  • Loading branch information
benjamin-wang1 authored Oct 15, 2024
2 parents 349a6c1 + af324e5 commit 7415b35
Show file tree
Hide file tree
Showing 9 changed files with 179 additions and 71 deletions.
Binary file modified source/core/assets/images/customer_faces/angry_face.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified source/core/assets/images/customer_faces/frown_face.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified source/core/assets/images/customer_faces/grin_face.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified source/core/assets/images/customer_faces/neutral_face.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified source/core/assets/images/customer_faces/smile_face.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
import com.badlogic.gdx.scenes.scene2d.Stage;
import com.csse3200.game.rendering.RenderComponent;
import com.csse3200.game.services.ServiceLocator;
import com.csse3200.game.components.npc.CustomerComponent;

public class HoverBoxComponent extends RenderComponent {
private Texture hoverImage;
Expand All @@ -29,14 +28,6 @@ public void setTexture(Texture newTexture) {
public void create() {
super.create();
shapeRenderer = new ShapeRenderer();
/*
try {
hoverImage = new Texture("images/customer_faces/angry_face.png");
} catch (Exception e) {
System.err.println("Failed to load hover box image: " + e.getMessage());
}
*/

ServiceLocator.getRenderService().register(this);
}

Expand Down Expand Up @@ -70,17 +61,6 @@ public void draw(SpriteBatch batch) {

}

private String getEntityInfo() {
String entityId = entity.toString(); // This gives us "Entity{id=XXX}"
CustomerComponent customerComponent = entity.getComponent(CustomerComponent.class);
if (customerComponent != null) {
String name = customerComponent.getName();
return name != null && !name.isEmpty() ? entityId + " (Customer: " + name + ")"
: entityId + " (Unnamed Customer)";
}
return entityId + " (Not a Customer)";
}

@Override
public void dispose() {
super.dispose();
Expand All @@ -97,6 +77,6 @@ public int getLayer() {

@Override
public void setStage(Stage mock) {

// setStage is empty
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,15 @@
import com.csse3200.game.components.Component;

public class ScoreSystem extends Component {
public static int compareLists(List<String> playerIngredients, List<String> orderIngredients) {

/**
* Function that is called to retrieve the accuracy of the player's meal.
*
* @param playerIngredients - the ingredients used in the player's meal.
* @param orderIngredients - the ingredients needed to make the ordered meal.
*/
public static int getAccuracyScore(List<String> playerIngredients, List<String> orderIngredients) {
int score = 0;
// Determine the size of the longer ingredient list
int longerIngredientList = Math.max(playerIngredients.size(), orderIngredients.size());

Expand All @@ -17,13 +25,64 @@ public static int compareLists(List<String> playerIngredients, List<String> orde
}

// Calculate percentage score
double percentage = ((double) matchingIngredients / longerIngredientList) * 100;
if (longerIngredientList > 0) {
double fraction = (double) matchingIngredients / longerIngredientList;
score = (int) Math.round(fraction * 100);
}

// Round to nearest whole digit
return (int) Math.round(percentage);
return score;
}

/**
* Function that is called to retrieve the score based on the time remaining before the ticket expires.
*
* @param orderTime - the time that is remaining before the order ticket disappears.
*/
public static int getTimeScore(String orderTime) {
float time = Float.parseFloat(orderTime);
int score;
if (time >= 15) {
score = 100;
} else if (time >= 10 && time < 15) {
score = 75;
} else if (time >= 5 && time < 10) {
score = 50;
} else if (time > 0 && time < 5) {
score = 25;
} else {
score = 0;
}

return score;
}

public static String getScoreDescription(int score) {
/**
* Function that is called to retrieve the score based on the how 'chopped' or 'cooked' an ingredient is.
*
* @param ingredients - the ingredients that were used to create the player's meal.
*/
public static int getCompletionScore(List<Float> ingredients) {
int totalScore = 0;
int score;
for (Float ingredient : ingredients) {
int completionPercent = Math.round(ingredient);
totalScore += completionPercent;
}
score = totalScore / ingredients.size();
return score;
}

/**
* Function that is called to retrieve the final score based on all considered factors.
*
* @param accuracyScore - the score that measures the accuracy of the player's meal.
* @param timeScore - the score that is dependent on how much time remains on the ticket.
* @param completionScore - the score that indicates how 'cooked' or 'chopped' the ingredients are.
*/
public static String getFinalScore(int accuracyScore, int timeScore, int completionScore) {
int score;
score = (accuracyScore + timeScore + completionScore) / 3;

if (score > 100 || score < 0) {
throw new IllegalArgumentException(
Expand All @@ -38,5 +97,4 @@ public static String getScoreDescription(int score) {
default -> "Angry Face"; // 0-19
};
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,12 @@
import com.csse3200.game.components.Component;
import com.csse3200.game.components.ScoreSystem.HoverBoxComponent;
import com.csse3200.game.components.ScoreSystem.ScoreSystem;
import com.csse3200.game.components.items.ChopIngredientComponent;
import com.csse3200.game.components.items.CookIngredientComponent;
import com.csse3200.game.components.items.IngredientComponent;
import com.csse3200.game.components.items.ItemComponent;
import com.csse3200.game.components.items.ItemTimerComponent;
import com.csse3200.game.components.items.MealComponent;
import com.csse3200.game.components.npc.CustomerComponent;
import com.csse3200.game.components.ordersystem.OrderManager;
import com.csse3200.game.components.ordersystem.Recipe;
Expand All @@ -24,6 +29,7 @@
import org.slf4j.LoggerFactory;

import java.util.List;
import java.util.ArrayList;

/**
* StationServingComponent.java
Expand All @@ -42,7 +48,7 @@ public class StationServingComponent extends Component {
AnimationRenderComponent animator;
TicketDetails bigTicket;

private final String SALAD = "salad";
private static final String SALAD = "salad";

/**
* On creation a listener for Submit Meal will be added to the station.
Expand Down Expand Up @@ -97,7 +103,7 @@ public void handleInteraction(InventoryComponent playerInventoryComponent, Inven
logger.error("No recipe found for this item: {}", itemName);
return; // Exit the method
}
scoreMeal(playerMeal);
scoreMeal(playerMeal, item);
playerInventoryComponent.removeAt(0);
inventoryDisplay.update();
submitMeal(item);
Expand Down Expand Up @@ -130,7 +136,6 @@ public void submitMeal(ItemComponent item) {
CustomerManager.removeCustomerByOrder(bigTicketInfo[0]);

// Call to team 1's function with the big ticket info
//TBD(item, bigTicketInfo[0], bigTicketInfo[1], bigTicketInfo[2]);
// remove ticket
logger.info("Submitting meal and removing docket");
ServiceLocator.getDocketService().getEvents().trigger("removeOrder", -1); // removes the order from the order action list
Expand All @@ -149,9 +154,10 @@ public void submitMeal(ItemComponent item) {
* Updates the HoverBoxComponent to display customer satisfaction by face types.
* Increments the gold and updates the gold in the UI according to customer satisfaction and actual ordered meal price.
*
* @param playerMeal - the meal that the player is currently submitting to the customer.
* @param playerMeal - the name of the meal that the player is currently submitting to the customer.
* @param meal - the meal item that the player is submitting to the customer.
*/
private void scoreMeal(String playerMeal) {
private void scoreMeal(String playerMeal, ItemComponent meal) {
String[] bigTicketInfo = bigTicket.getCurrentBigTicketInfo();
if (bigTicketInfo == null || bigTicketInfo.length < 2) {
logger.warn("No current order to score the meal for.");
Expand All @@ -160,30 +166,80 @@ private void scoreMeal(String playerMeal) {

String orderNumber = bigTicketInfo[0];
String orderedMeal = bigTicketInfo[1];
logger.info("Ordered meal: {}", orderedMeal);

// Retrieves the ingredients of the customer's order
Recipe orderRecipe = OrderManager.getRecipe(orderedMeal);
List<String> orderIngredients = orderRecipe.getIngredients();
logger.info("Order ingredients: {}", orderIngredients);

int orderedMealPrice = getMealPrice(orderedMeal);

logger.info("Player meal: {}", playerMeal);
// Retrieves the ingredients of the player's meal
Recipe playerRecipe = OrderManager.getRecipe(playerMeal);
List<String> playerIngredients = playerRecipe.getIngredients();
logger.info("Player ingredients: {}", playerIngredients);

int score = ScoreSystem.compareLists(playerIngredients, orderIngredients);
String scoreDescription = ScoreSystem.getScoreDescription(score);
// Determines the accuracy of the player's meal against the customer's order
int accuracyScore = ScoreSystem.getAccuracyScore(playerIngredients, orderIngredients);

// Retrieves the time remaining when the meal is submitted
// Then determines the score based on the time remaining
String orderTime = bigTicketInfo[2];
int timeScore = ScoreSystem.getTimeScore(orderTime);

// Retrieves the completion percentages of the ingredients in the player's meal
// Then determines the score based on how 'cooked' or 'chopped' the ingredients are
List<Float> completionList = getCompletionList(meal);
int completionScore = ScoreSystem.getCompletionScore(completionList);

logOrderDetails(orderNumber, score, scoreDescription);
// Determines the final score based on the three previous scoring criteria
String finalScore = ScoreSystem.getFinalScore(accuracyScore, timeScore, completionScore);

// Updating the gold amount and the HoverBox display based on the final score
Entity customer = CustomerManager.getCustomerByOrder(orderNumber);
int orderedMealPrice = getMealPrice(orderedMeal);
if (customer != null) {
processCustomerReaction(customer, scoreDescription, orderedMealPrice);
processCustomerReaction(customer, finalScore, orderedMealPrice);
}
}

/**
* Function that is called to retrieve the completion statuses of the ingredients used in the player's meal.
*
* @param meal - the meal item that the player is submitting to the customer.
*/
private List<Float> getCompletionList(ItemComponent meal) {
List<Float> ingredientCompletionList = new ArrayList<>();
if (meal instanceof MealComponent) {
MealComponent mealComponent = (MealComponent) meal;
List<IngredientComponent> ingredients = mealComponent.getIngredients();
for (IngredientComponent ingredient : ingredients) {
logger.info(ingredient.getItemName());
Entity ingredientEntity = ingredient.getEntity();
ItemTimerComponent timerComponent = null;

if (ingredientEntity != null) {

// Check for ChopIngredientComponent
if (ingredientEntity.getComponent(ChopIngredientComponent.class) != null) {
timerComponent = ingredientEntity.getComponent(ChopIngredientComponent.class);
}
// Check for CookIngredientComponent
else if (ingredientEntity.getComponent(CookIngredientComponent.class) != null) {
timerComponent = ingredientEntity.getComponent(CookIngredientComponent.class);
}
}

Float ingredientCompletionPercent = timerComponent.getCompletionPercent();
ingredientCompletionList.add(ingredientCompletionPercent);
}
} else {
logger.error("The provided meal is not a MealComponent.");
}
return ingredientCompletionList;
}

/**
* Function that is called to retrieve the meal price.
*
* @param orderedMeal - the name of the meal that the player is currently submitting to the customer.
*/
private int getMealPrice(String orderedMeal) {
return switch (orderedMeal) {
case "acaiBowl", "fruitSalad" -> 20;
Expand All @@ -193,45 +249,59 @@ private int getMealPrice(String orderedMeal) {
};
}

private void logOrderDetails(String orderNumber, int score, String scoreDescription) {
logger.info("Order number: {}", orderNumber);
logger.info("Score: {}%", score);
logger.info("Description: {}", scoreDescription);
}

private void processCustomerReaction(Entity customer, String scoreDescription, int mealPrice) {
/**
* Function that is called to process the customer reaction, and increments the gold.
*
* @param customer - the customer entity.
* @param finalScore - the final score that is assigned to a meal.
* @param mealPrice - the price of the meal.
*/
private void processCustomerReaction(Entity customer, String finalScore, int mealPrice) {
HoverBoxComponent hoverBox = customer.getComponent(HoverBoxComponent.class);
if (hoverBox == null) return;

String faceImagePath = getFaceImagePath(scoreDescription);
int gold = updateGoldBasedOnScore(ServiceLocator.getLevelService().getCurrGold(), scoreDescription, mealPrice);
String faceImagePath = getFaceImagePath(finalScore);
int gold = updateGoldBasedOnScore(ServiceLocator.getLevelService().getCurrGold(), finalScore, mealPrice);

hoverBox.setTexture(new Texture(faceImagePath));
ServiceLocator.getLevelService().setCurrGold(gold);
updateGoldUI(gold);
}

private String getFaceImagePath(String scoreDescription) {
return switch (scoreDescription) {
/**
* Function that is called to retrieve the path to update the HoverBox Display.
*
* @param finalScore - the final score that is assigned to a meal.
*/
private String getFaceImagePath(String finalScore) {
return switch (finalScore) {
case "Grin Face" -> "images/customer_faces/grin_face.png";
case "Smile Face" -> "images/customer_faces/smile_face.png";
case "Neutral Face" -> "images/customer_faces/neutral_face.png";
case "Frown Face" -> "images/customer_faces/frown_face.png";
case "Angry Face" -> "images/customer_faces/angry_face.png";
default -> {
logger.error("No image found for preference: {}", scoreDescription);
logger.error("No image found for preference: {}", finalScore);
yield "images/customer_faces/angry_face.png"; // Provide a default image
}
};
}

private int updateGoldBasedOnScore(int currentGold, String scoreDescription, int mealPrice) {
/**
* Function that is called to update the gold based on the meal price.
*
* @param currentGold - the current amount of gold the player has.
* @param finalScore - the final score that is assigned to a meal.
* @param mealPrice - the price of the meal.
*/
private int updateGoldBasedOnScore(int currentGold, String finalScore, int mealPrice) {
int gold = currentGold + mealPrice;
switch (scoreDescription) {
switch (finalScore) {
case "Grin Face" -> gold += 10;
case "Smile Face" -> gold += 5;
case "Frown Face" -> gold -= 5;
case "Angry Face" -> gold -= 10;
default -> gold += 0;
}
return gold;
}
Expand Down
Loading

0 comments on commit 7415b35

Please sign in to comment.