private void HandleCraftItem(GameSession session, PacketReader packet) { int recipeId = packet.ReadInt(); // attempt to oad the recipe metadata RecipeMetadata recipe = RecipeMetadataStorage.GetRecipe(recipeId); if (recipe == null) { Logger.LogError($"Unknown recipe ID {recipeId} from user: {session.Player.Name}"); return; } // does the play have enough mesos for this recipe? if (!session.Player.Wallet.Meso.Modify(-recipe.GetMesosRequired())) { // send notice to player saying they haven't got enough mesos session.SendNotice("You don't have enough mesos."); return; } // does the player have all the required ingredients for this recipe? if (!PlayerHasAllIngredients(session, recipe)) { // send notice to player saying they haven't got enough materials session.SendNotice("You've run out of materials."); return; } // only add reward items once all required items & mesos have been removed from player if (RemoveRequiredItemsFromInventory(session, recipe)) { AddRewardItemsToInventory(session, recipe); } }
private static bool PlayerHasEnoughMesos(GameSession session, RecipeMetadata recipe) { long mesoBalance = session.Player.Wallet.Meso.Amount; if (mesoBalance == 0) { return(false); } return(mesoBalance >= recipe.GetMesosRequired()); }