From 6d81ff156430f1f9ca6888ec8bc37b8bfe36d4e3 Mon Sep 17 00:00:00 2001 From: Jose Henrique Date: Wed, 12 Feb 2025 21:22:43 -0300 Subject: [PATCH] Add GameDataController for item icon retrieval; update GameItemsRepository and GameItemService for new action effects --- Controllers/GameDataController.cs | 36 +++++++++++++++++ GameItemsData.csv | 28 +++++++------- README.md | 2 +- Repositories/GameItemsRepository.cs | 10 +++++ Services/GameItemService.cs | 60 ++++++++++++++++++++++++----- 5 files changed, 112 insertions(+), 24 deletions(-) create mode 100644 Controllers/GameDataController.cs diff --git a/Controllers/GameDataController.cs b/Controllers/GameDataController.cs new file mode 100644 index 0000000..8d8110b --- /dev/null +++ b/Controllers/GameDataController.cs @@ -0,0 +1,36 @@ +using Microsoft.AspNetCore.Mvc; +using PetCompanion.Repositories; + +namespace PetCompanion.Controllers +{ + [ApiController] + [Route("api/v1/[controller]")] + public class GameDataController : Controller + { + private readonly GameItemsRepository gameItemsRepository; + private readonly ILogger logger; + private readonly Guid userId = Guid.Parse("f5f4b3b3-3b7b-4b7b-8b7b-7b7b7b7b7b7b"); + + public GameDataController( + ILogger logger, + GameItemsRepository gameItemsRepository) + { + this.logger = logger; + this.gameItemsRepository = gameItemsRepository; + } + + [HttpGet("item/icon/{itemId}")] + public IActionResult GetItemIcon(int itemId) + { + try + { + var iconBytes = gameItemsRepository.GetItemIcon(itemId); + return File(iconBytes, "image/png"); + } + catch (Exception ex) + { + return BadRequest(ex.Message); + } + } + } +} diff --git a/GameItemsData.csv b/GameItemsData.csv index 2c58ec1..c304648 100644 --- a/GameItemsData.csv +++ b/GameItemsData.csv @@ -1,21 +1,21 @@ Id,Name,Type,Rarity,Description,Price,Effect,EquipTarget 1,Apple,Material,Common,Crafting material (coming soon),0,Nothing,None -2,Superfood Smoothie,Consumable,Uncommon,Adds +30 food resources; Restores 5 Intelligence,0,ADD_FOOD_RESOURCES_30,None +2,Superfood Smoothie,Consumable,Uncommon,Adds +30 food resources; Restores 5 Intelligence,0,ADD_FOOD_30,None 3,Energy Drink,Consumable,Rare,Reduces Cooldown by 5 min,0,REDUCE_COOLDOWN_5,None 4,Golden Apple,Consumable,Legendary,Adds +20 Intelligence (Permanent); Adds +100 food resources,0,ADD_INTELLIGENCE_20,None -5,Healing Potion,Consumable,Uncommon,Adds +20 to Health; Adds +20 food resources,0,ADD_HEALTH_20_AND_FOOD_20,None +5,Healing Potion,Consumable,Uncommon,Adds +20 to Health; Adds +20 food resources,0,ADD_HEALTH_20;ADD_FOOD_20,None 6,Charisma Cookie,Consumable,Rare,Adds +2 Charisma (Permanent),0,ADD_CHARISMA_2,None -7,XP Booster,Consumable,Rare,Award +10 XP,0,ADD_XP_10,None -8,Sleeping Draught,Consumable,Common,Reduces Cooldown for resting by 10 min,0,REDUCE_REST_COOLDOWN_10,None -9,Mystery Meat,Consumable,Uncommon,Randomly ±2 to one stat (Permanent),0,ADD_RANDOM_STAT_2,None -10,Elixir of Vitality,Consumable,Legendary,Fully restores all stats and health; Adds +1 Level,0,RESTORE_STATS;ADD_LEVEL_1,None -11,Leather Hat,Equipment,Common,Helmet: +5 Max Health,0,ADD_MAX_HEALTH_5,Head -12,Wizard Hat,Equipment,Rare,Helmet: +15 Max Intelligence,0,ADD_MAX_INTELLIGENCE_15,Head -13,Knight's Armor,Equipment,Rare,Chest: +15 Max Strength,0,ADD_MAX_STRENGTH_15,Body -14,Golden Boots,Equipment,Uncommon,Legging: +10 Max Charisma,0,ADD_MAX_CHARISMA_10,Legs -15,Laser Pointer,Equipment,Common,Weapon: +5 Max Strength,0,ADD_MAX_STRENGTH_5,Weapon -16,Celestial Crown,Equipment,Legendary,Helmet: +20 max to all stats,0,ADD_MAX_ALL_STATS_20,Head -17,Dragon Scale Shield,Equipment,Legendary,Weapon: +50 Max Health,0,ADD_MAX_HEALTH_50,Weapon +7,Strength Serum,Consumable,Uncommon,Adds +5 Strength (Permanent),0,ADD_STRENGTH_5,None +8,Sleeping Draught,Consumable,Common,Reduces Cooldown by 10 min,0,REDUCE_COOLDOWN_10,None +9,Mystery Meat,Consumable,Uncommon,Randomly ±2 to one stat (Permanent),0,ADD_RANDOMSTAT_2,None +10,Elixir of Vitality,Consumable,Legendary,Fully restores all stats and health,0,RESTORE_STATS,None +11,Leather Hat,Equipment,Common,Helmet: +10 Max Health,0,ADD_MAXHEALTH_5,Head +12,Wizard Hat,Equipment,Rare,Helmet: +15 Max Intelligence,0,ADD_MAXINTELLIGENCE_15,Head +13,Knight's Armor,Equipment,Rare,Chest: +15 Max Strength,0,ADD_MAXSTRENGTH_15,Body +14,Golden Boots,Equipment,Uncommon,Legging: +10 Max Charisma,0,ADD_MAXCHARISMA_10,Legs +15,Laser Pointer,Equipment,Common,Weapon: +5 Max Strength,0,ADD_MAXSTRENGTH_5,Weapon +16,Celestial Crown,Equipment,Legendary,Helmet: +20 max to all stats,0,ADD_MAXALLSTATS_20,Head +17,Dragon Scale Shield,Equipment,Legendary,Chest: +50 Max Health,0,ADD_MAXHEALTH_50,Weapon 18,Feathers,Material,Common,Crafting material (coming soon),0,Nothing,None 19,Phoenix Feather,Material,Legendary,Crafting material (coming soon),0,Nothing,None -21,Basic Kibble,Consumable,Common,Adds +20 food resources,0,ADD_FOOD_RESOURCES_20,None \ No newline at end of file +21,Basic Kibble,Consumable,Common,Adds +20 food resources,0,ADD_FOOD_20,None \ No newline at end of file diff --git a/README.md b/README.md index 97acc28..de982ea 100644 --- a/README.md +++ b/README.md @@ -9,7 +9,7 @@ - [ ] User profile/settings system ### V1.5: -- [ ] +- [ ] Icons and images optimization ### V2: - [ ] Quest system diff --git a/Repositories/GameItemsRepository.cs b/Repositories/GameItemsRepository.cs index e2db7c4..c300bdb 100644 --- a/Repositories/GameItemsRepository.cs +++ b/Repositories/GameItemsRepository.cs @@ -22,6 +22,16 @@ namespace PetCompanion.Repositories return _context.GameItems; } + public byte[] GetItemIcon(int itemId) + { + if (_context.GameItems.Find(itemId) == null) + { + throw new Exception("Item not found"); + } + + return File.ReadAllBytes($"game-data/item/icons/{itemId}.png"); + } + public void Add(GameItem item) { _context.GameItems.Add(item); diff --git a/Services/GameItemService.cs b/Services/GameItemService.cs index e2defb3..196e017 100644 --- a/Services/GameItemService.cs +++ b/Services/GameItemService.cs @@ -72,19 +72,59 @@ namespace PetCompanion.Services switch ($"{action}_{target}") { - case "ADD_FOOD_RESOURCES": + case "ADD_FOOD": pet.Resources.Food += value; break; case "ADD_INTELLIGENCE": - pet.Stats.Intelligence += value; + pet.IncrementIntelligence(value); + break; + case "REDUCE_COOLDOWN": + pet.BasicActionCooldown = pet.BasicActionCooldown.AddMinutes(-value); break; case "ADD_HEALTH": pet.Health = Math.Min(pet.Health + value, pet.MaxHealth); break; - case "ADD_MAX_HEALTH": + case "ADD_CHARISMA": + pet.IncrementCharisma(value); + break; + case "ADD_STRENGTH": + pet.IncrementStrength(value); + break; + case "ADD_RANDOMSTAT": + var random = new Random(); + var stat = random.Next(4); + switch (stat) + { + case 0: pet.IncrementStrength(value); break; + case 1: pet.IncrementIntelligence(value); break; + case 2: pet.IncrementCharisma(value); break; + case 3: pet.Health = Math.Min(pet.Health + value, pet.MaxHealth); break; + } + break; + case "RESTORE_STATS": + pet.Health = pet.MaxHealth; + pet.Stats.Intelligence = pet.Stats.MaxIntelligence; + pet.Stats.Strength = pet.Stats.MaxStrength; + pet.Stats.Charisma = pet.Stats.MaxCharisma; + break; + case "ADD_MAXHEALTH": pet.MaxHealth += value; break; - // Add more effect handlers as needed + case "ADD_MAXINTELLIGENCE": + pet.Stats.MaxIntelligence += value; + break; + case "ADD_MAXSTRENGTH": + pet.Stats.MaxStrength += value; + break; + case "ADD_MAXCHARISMA": + pet.Stats.MaxCharisma += value; + break; + case "ADD_MAXALLSTATS": + pet.MaxHealth += value; + pet.Stats.MaxIntelligence += value; + pet.Stats.MaxStrength += value; + pet.Stats.MaxCharisma += value; + break; } } @@ -99,26 +139,28 @@ namespace PetCompanion.Services switch ($"{action}_{target}") { - case "ADD_MAX_HEALTH": + case "ADD_MAXHEALTH": pet.MaxHealth -= value; pet.Health = Math.Min(pet.Health, pet.MaxHealth); break; - case "ADD_MAX_INTELLIGENCE": + case "ADD_MAXINTELLIGENCE": pet.Stats.MaxIntelligence -= value; pet.Stats.Intelligence = Math.Min(pet.Stats.Intelligence, pet.Stats.MaxIntelligence); break; - case "ADD_MAX_STRENGTH": + case "ADD_MAXSTRENGTH": pet.Stats.MaxStrength -= value; pet.Stats.Strength = Math.Min(pet.Stats.Strength, pet.Stats.MaxStrength); break; - case "ADD_MAX_CHARISMA": + case "ADD_MAXCHARISMA": pet.Stats.MaxCharisma -= value; pet.Stats.Charisma = Math.Min(pet.Stats.Charisma, pet.Stats.MaxCharisma); break; - case "ADD_MAX_ALL_STATS": + case "ADD_MAXALLSTATS": + pet.MaxHealth -= value; pet.Stats.MaxIntelligence -= value; pet.Stats.MaxStrength -= value; pet.Stats.MaxCharisma -= value; + pet.Health = Math.Min(pet.Health, pet.MaxHealth); pet.Stats.Intelligence = Math.Min(pet.Stats.Intelligence, pet.Stats.MaxIntelligence); pet.Stats.Strength = Math.Min(pet.Stats.Strength, pet.Stats.MaxStrength); pet.Stats.Charisma = Math.Min(pet.Stats.Charisma, pet.Stats.MaxCharisma);