This commit is contained in:
2025-12-10 23:47:40 +09:00
parent 2de58a6525
commit c029cd1e10
12 changed files with 602 additions and 306 deletions
+26 -89
View File
@@ -83,110 +83,47 @@ class ItemTable {
static List<ItemTemplate> armors = [];
static List<ItemTemplate> shields = [];
static List<ItemTemplate> accessories = [];
static List<ItemTemplate> consumables = []; // New: Potions
static List<ItemTemplate> consumables = [];
static final Map<String, ItemTemplate> _items = {};
static void initialize() {
// 0. Consumables (Potions)
// Manually added for now, later move to JSON if preferred.
List<ItemTemplate> potionTemplates = [
ItemTemplate(
id: "potion_heal_small",
name: "Healing Potion",
description: "Restores 20 HP instantly.",
slot: EquipmentSlot.consumable,
atkBonus: 0,
hpBonus: 20, // Used as heal amount
armorBonus: 0,
effects: [],
price: 15,
rarity: ItemRarity.normal,
tier: ItemTier.tier1,
image: "assets/images/items/potion.png", // Valid placeholder
),
ItemTemplate(
id: "potion_armor_small",
name: "Iron Skin Potion",
description: "Grants +10 Armor instantly.",
slot: EquipmentSlot.consumable,
atkBonus: 0,
hpBonus: 0,
armorBonus: 10, // Used as armor amount
effects: [],
price: 20,
rarity: ItemRarity.normal,
tier: ItemTier.tier1,
image: "assets/images/items/potion.png",
),
ItemTemplate(
id: "potion_strength_small",
name: "Strength Potion",
description: "Increases Attack Power for 1 turn.",
slot: EquipmentSlot.consumable,
atkBonus: 0,
hpBonus: 0,
armorBonus: 0,
effects: [
ItemEffect(
type: StatusEffectType.attackUp,
probability: 100,
duration: 1,
value: 5, // Flat +5 Attack (simple implementation)
),
],
price: 25,
rarity: ItemRarity.magic,
tier: ItemTier.tier1,
image: "assets/images/items/potion.png",
),
];
consumables = potionTemplates;
for (var p in potionTemplates) {
_items[p.id] = p; // Register to map
}
// This function is now a placeholder. All loading is handled in load().
}
static Future<void> load() async {
// Initialize Manual Items first
initialize();
// Clear previous data
_items.clear();
final String jsonString = await rootBundle.loadString(
'assets/data/items.json',
);
final String jsonString =
await rootBundle.loadString('assets/data/items.json');
final Map<String, dynamic> data = jsonDecode(jsonString);
weapons = (data['weapons'] as List)
.map((e) => ItemTemplate.fromJson(e))
.toList();
armors = (data['armors'] as List)
.map((e) => ItemTemplate.fromJson(e))
.toList();
shields = (data['shields'] as List)
.map((e) => ItemTemplate.fromJson(e))
.toList();
accessories = (data['accessories'] as List)
.map((e) => ItemTemplate.fromJson(e))
.toList();
// Helper function to load and register items
void _loadAndRegister(String key, List<ItemTemplate> list) {
if (data[key] != null) {
list.clear();
var loadedItems =
(data[key] as List).map((e) => ItemTemplate.fromJson(e)).toList();
list.addAll(loadedItems);
for (var item in loadedItems) {
_items[item.id] = item;
}
}
}
_loadAndRegister('weapons', weapons);
_loadAndRegister('armors', armors);
_loadAndRegister('shields', shields);
_loadAndRegister('accessories', accessories);
_loadAndRegister('consumables', consumables);
}
static List<ItemTemplate> get allItems => [
...weapons,
...armors,
...shields,
...accessories,
...consumables,
];
static List<ItemTemplate> get allItems => _items.values.toList();
static ItemTemplate? get(String id) {
try {
return allItems.firstWhere((item) => item.id == id);
} catch (e) {
return null;
}
return _items[id];
}
static final Random _random = Random();
/// Returns all items matching the given tier.
+20
View File
@@ -11,6 +11,26 @@ class LootGenerator {
/// Generates an Item instance from a template, applying prefixes/suffixes based on rarity.
static Item generate(ItemTemplate template) {
// Consumables have fixed stats and no prefixes.
if (template.slot == EquipmentSlot.consumable) {
return Item(
id: template.id,
name: template.name,
description: template.description,
atkBonus: template.atkBonus,
hpBonus: template.hpBonus,
armorBonus: template.armorBonus,
dodge: template.dodge,
slot: template.slot,
effects: template.effects,
price: template.price,
image: template.image,
luck: template.luck,
rarity: template.rarity,
tier: template.tier,
);
}
String finalName = template.name;
int finalAtk = template.atkBonus;
int finalHp = template.hpBonus;
+11 -2
View File
@@ -650,8 +650,17 @@ class _BattleScreenState extends State<BattleScreen> {
child: Stack(
key: _stackKey,
children: [
// 1. Background (Black)
Container(color: ThemeConfig.battleBg),
// 1. Background Image
Container(
decoration: const BoxDecoration(
image: DecorationImage(
image: AssetImage('assets/images/background/tier_1.jpg'),
fit: BoxFit.cover,
),
),
),
// 1.1 Opacity Layer
Container(color: Colors.black.withValues(alpha: 0.7)),
// 2. Battle Content (Top Bar + Characters)
Column(
@@ -131,6 +131,8 @@ class CharacterStatusCard extends StatelessWidget {
width: 200,
height: 200,
fit: BoxFit.contain,
// color: Colors.white,
// colorBlendMode: BlendMode.screen,
errorBuilder: (context, error, stackTrace) {
return const Icon(
Icons.psychology,