update
This commit is contained in:
@@ -11,6 +11,12 @@ enum StatusEffectType {
|
||||
defenseForbidden, // Cannot use Defend action
|
||||
}
|
||||
|
||||
/// 공격 실패 시 이펙트 피드백 타입 정의
|
||||
enum BattleFeedbackType {
|
||||
miss, // 공격이 빗나감
|
||||
failed, // 방어 실패
|
||||
}
|
||||
|
||||
/// 스탯에 적용될 수 있는 수정자(Modifier)의 타입 정의.
|
||||
/// Flat: 기본 값에 직접 더해지는 값.
|
||||
/// Percent: 기본 값에 비율로 곱해지는 값.
|
||||
@@ -26,3 +32,4 @@ enum StageType {
|
||||
enum EquipmentSlot { weapon, armor, shield, accessory }
|
||||
|
||||
enum DamageType { normal, bleed, vulnerable }
|
||||
|
||||
|
||||
@@ -6,10 +6,12 @@ class EffectEvent {
|
||||
final ActionType type; // attack, defend
|
||||
final RiskLevel risk;
|
||||
final EffectTarget target; // 이펙트가 표시될 위치의 대상
|
||||
final BattleFeedbackType? feedbackType; // 새로운 피드백 타입
|
||||
|
||||
EffectEvent({
|
||||
required this.type,
|
||||
required this.risk,
|
||||
required this.target,
|
||||
this.feedbackType, // feedbackType 필드를 생성자에 추가
|
||||
});
|
||||
}
|
||||
|
||||
@@ -235,13 +235,14 @@ class BattleProvider with ChangeNotifier {
|
||||
return;
|
||||
|
||||
// Update Enemy Status Effects at the start of Player's turn (user request)
|
||||
|
||||
enemy.updateStatusEffects();
|
||||
|
||||
// 1. Check for Defense Forbidden status
|
||||
if (type == ActionType.defend &&
|
||||
player.hasStatus(StatusEffectType.defenseForbidden)) {
|
||||
_addLog("Cannot defend! You are under Defense Forbidden status.");
|
||||
notifyListeners(); // 상태 변경을 알림
|
||||
_endPlayerTurn();
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -283,10 +284,9 @@ class BattleProvider with ChangeNotifier {
|
||||
_effectEventController.sink.add(
|
||||
EffectEvent(
|
||||
type: ActionType.attack,
|
||||
|
||||
risk: risk,
|
||||
|
||||
target: EffectTarget.enemy,
|
||||
feedbackType: null, // 공격 성공이므로 feedbackType 없음
|
||||
),
|
||||
);
|
||||
|
||||
@@ -313,27 +313,43 @@ class BattleProvider with ChangeNotifier {
|
||||
}
|
||||
|
||||
// Try applying status effects from items
|
||||
|
||||
_tryApplyStatusEffects(player, enemy);
|
||||
} else {
|
||||
_effectEventController.sink.add(
|
||||
EffectEvent(
|
||||
type: ActionType.defend,
|
||||
|
||||
risk: risk,
|
||||
|
||||
target: EffectTarget.player,
|
||||
feedbackType: null, // 방어 성공이므로 feedbackType 없음
|
||||
),
|
||||
);
|
||||
|
||||
int armorGained = (player.totalDefense * efficiency).toInt();
|
||||
|
||||
player.armor += armorGained;
|
||||
|
||||
_addLog("Player gained $armorGained armor.");
|
||||
}
|
||||
} else {
|
||||
_addLog("Player's action missed!");
|
||||
if (type == ActionType.attack) {
|
||||
_addLog("Player's attack missed!");
|
||||
_effectEventController.sink.add(
|
||||
EffectEvent(
|
||||
type: type,
|
||||
risk: risk,
|
||||
target: EffectTarget.enemy, // 공격 실패는 적 위치에 MISS
|
||||
feedbackType: BattleFeedbackType.miss,
|
||||
),
|
||||
);
|
||||
} else {
|
||||
_addLog("Player's defense failed!");
|
||||
_effectEventController.sink.add(
|
||||
EffectEvent(
|
||||
type: type,
|
||||
risk: risk,
|
||||
target: EffectTarget.player, // 방어 실패는 내 위치에 FAILED
|
||||
feedbackType: BattleFeedbackType.failed,
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
if (enemy.isDead) {
|
||||
@@ -394,6 +410,7 @@ class BattleProvider with ChangeNotifier {
|
||||
type: ActionType.attack,
|
||||
risk: intent.risk,
|
||||
target: EffectTarget.player,
|
||||
feedbackType: null, // 공격 성공이므로 feedbackType 없음
|
||||
),
|
||||
);
|
||||
|
||||
@@ -421,6 +438,14 @@ class BattleProvider with ChangeNotifier {
|
||||
}
|
||||
} else {
|
||||
_addLog("Enemy's ${intent.risk.name} attack missed!");
|
||||
_effectEventController.sink.add(
|
||||
EffectEvent(
|
||||
type: ActionType.attack, // 적의 공격이므로 ActionType.attack
|
||||
risk: intent.risk,
|
||||
target: EffectTarget.player, // 플레이어가 회피했으므로 플레이어 위치에 이펙트
|
||||
feedbackType: BattleFeedbackType.miss, // 변경: MISS 피드백
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
} else if (!canAct) {
|
||||
@@ -636,6 +661,10 @@ class BattleProvider with ChangeNotifier {
|
||||
// Decide Action Type
|
||||
// If baseDefense is 0, CANNOT defend.
|
||||
bool canDefend = enemy.baseDefense > 0;
|
||||
// Check for DefenseForbidden status
|
||||
if (enemy.hasStatus(StatusEffectType.defenseForbidden)) {
|
||||
canDefend = false;
|
||||
}
|
||||
bool isAttack = true;
|
||||
|
||||
if (canDefend) {
|
||||
@@ -662,9 +691,8 @@ class BattleProvider with ChangeNotifier {
|
||||
|
||||
if (isAttack) {
|
||||
// Attack Intent
|
||||
// Variance: +/- 20%
|
||||
double variance = 0.8 + random.nextDouble() * 0.4;
|
||||
int damage = (enemy.totalAtk * efficiency * variance).toInt();
|
||||
// Variance removed as per request
|
||||
int damage = (enemy.totalAtk * efficiency).toInt();
|
||||
if (damage < 1) damage = 1;
|
||||
|
||||
// Calculate success immediately
|
||||
@@ -692,9 +720,8 @@ class BattleProvider with ChangeNotifier {
|
||||
} else {
|
||||
// Defend Intent
|
||||
int baseDef = enemy.totalDefense;
|
||||
// Variance
|
||||
double variance = 0.8 + random.nextDouble() * 0.4;
|
||||
int armor = (baseDef * 2 * efficiency * variance).toInt();
|
||||
// Variance removed
|
||||
int armor = (baseDef * 2 * efficiency).toInt();
|
||||
|
||||
// Calculate success immediately
|
||||
bool success = false;
|
||||
@@ -728,6 +755,7 @@ class BattleProvider with ChangeNotifier {
|
||||
type: ActionType.defend,
|
||||
risk: risk,
|
||||
target: EffectTarget.enemy,
|
||||
feedbackType: null, // 방어 성공이므로 feedbackType 없음
|
||||
),
|
||||
);
|
||||
} else {
|
||||
|
||||
+195
-21
@@ -21,6 +21,7 @@ class _BattleScreenState extends State<BattleScreen> {
|
||||
final ScrollController _scrollController = ScrollController();
|
||||
final List<_DamageTextData> _floatingDamageTexts = [];
|
||||
final List<_FloatingEffectData> _floatingEffects = [];
|
||||
final List<_FeedbackTextData> _floatingFeedbackTexts = [];
|
||||
StreamSubscription<DamageEvent>? _damageSubscription;
|
||||
StreamSubscription<EffectEvent>? _effectSubscription;
|
||||
final GlobalKey _playerKey = GlobalKey();
|
||||
@@ -131,6 +132,51 @@ class _BattleScreenState extends State<BattleScreen> {
|
||||
position +
|
||||
Offset(renderBox.size.width / 2 - 30, renderBox.size.height / 2 - 30);
|
||||
|
||||
// feedbackType이 존재하면 해당 텍스트를 표시하고 기존 이펙트 아이콘은 건너뜜
|
||||
if (event.feedbackType != null) {
|
||||
String feedbackText;
|
||||
Color feedbackColor;
|
||||
switch (event.feedbackType) {
|
||||
case BattleFeedbackType.miss:
|
||||
feedbackText = "MISS";
|
||||
feedbackColor = Colors.grey;
|
||||
break;
|
||||
case BattleFeedbackType.failed:
|
||||
feedbackText = "FAILED";
|
||||
feedbackColor = Colors.redAccent;
|
||||
break;
|
||||
default:
|
||||
feedbackText = ""; // Should not happen with current enums
|
||||
feedbackColor = Colors.white;
|
||||
}
|
||||
|
||||
final String id = UniqueKey().toString();
|
||||
setState(() {
|
||||
_floatingFeedbackTexts.add(
|
||||
_FeedbackTextData(
|
||||
id: id,
|
||||
widget: Positioned(
|
||||
left: position.dx,
|
||||
top: position.dy,
|
||||
child: _FloatingFeedbackText(
|
||||
key: ValueKey(id),
|
||||
feedback: feedbackText,
|
||||
color: feedbackColor,
|
||||
onRemove: () {
|
||||
if (mounted) {
|
||||
setState(() {
|
||||
_floatingFeedbackTexts.removeWhere((e) => e.id == id);
|
||||
});
|
||||
}
|
||||
},
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
});
|
||||
return; // feedbackType이 있으면 아이콘 이펙트는 표시하지 않음
|
||||
}
|
||||
|
||||
IconData icon;
|
||||
Color color;
|
||||
double size;
|
||||
@@ -321,29 +367,34 @@ class _BattleScreenState extends State<BattleScreen> {
|
||||
|
||||
// Battle Area
|
||||
Expanded(
|
||||
child: Center(
|
||||
child: Row(
|
||||
mainAxisAlignment: MainAxisAlignment.spaceEvenly,
|
||||
child: Padding(
|
||||
// padding: const EdgeInsets.symmetric(horizontal: 40.0),
|
||||
padding: const EdgeInsets.all(70.0),
|
||||
child: Column(
|
||||
children: [
|
||||
_buildCharacterStatus(
|
||||
battleProvider.player,
|
||||
isPlayer: true,
|
||||
isTurn: battleProvider.isPlayerTurn,
|
||||
key: _playerKey,
|
||||
// 적 영역 (우측 상단)
|
||||
Expanded(
|
||||
child: Align(
|
||||
alignment: Alignment.topRight,
|
||||
child: _buildCharacterStatus(
|
||||
battleProvider.enemy,
|
||||
isPlayer: false,
|
||||
isTurn: !battleProvider.isPlayerTurn,
|
||||
key: _enemyKey,
|
||||
),
|
||||
),
|
||||
),
|
||||
// const Text(
|
||||
// "VS",
|
||||
// style: TextStyle(
|
||||
// color: Colors.red,
|
||||
// fontSize: 24,
|
||||
// fontWeight: FontWeight.bold,
|
||||
// ),
|
||||
// ),
|
||||
_buildCharacterStatus(
|
||||
battleProvider.enemy,
|
||||
isPlayer: false,
|
||||
isTurn: !battleProvider.isPlayerTurn,
|
||||
key: _enemyKey,
|
||||
// 플레이어 영역 (좌측 하단)
|
||||
Expanded(
|
||||
child: Align(
|
||||
alignment: Alignment.bottomLeft,
|
||||
child: _buildCharacterStatus(
|
||||
battleProvider.player,
|
||||
isPlayer: true,
|
||||
isTurn: battleProvider.isPlayerTurn,
|
||||
key: _playerKey,
|
||||
),
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
@@ -470,6 +521,7 @@ class _BattleScreenState extends State<BattleScreen> {
|
||||
),
|
||||
..._floatingDamageTexts.map((e) => e.widget),
|
||||
..._floatingEffects.map((e) => e.widget),
|
||||
..._floatingFeedbackTexts.map((e) => e.widget), // 새로운 피드백 텍스트 추가
|
||||
],
|
||||
);
|
||||
},
|
||||
@@ -609,6 +661,31 @@ class _BattleScreenState extends State<BattleScreen> {
|
||||
),
|
||||
Text("ATK: ${character.totalAtk}"),
|
||||
Text("DEF: ${character.totalDefense}"),
|
||||
// 캐릭터 아이콘/이미지 영역 추가
|
||||
Container(
|
||||
width: 100, // 임시 크기
|
||||
height: 100, // 임시 크기
|
||||
decoration: BoxDecoration(
|
||||
color: isPlayer
|
||||
? Colors.lightBlue
|
||||
: Colors.deepOrange, // 플레이어/적 구분 색상
|
||||
borderRadius: BorderRadius.circular(8),
|
||||
),
|
||||
child: Center(
|
||||
child: isPlayer
|
||||
? const Icon(
|
||||
Icons.person,
|
||||
size: 60,
|
||||
color: Colors.white,
|
||||
) // 플레이어 아이콘
|
||||
: const Icon(
|
||||
Icons.psychology,
|
||||
size: 60,
|
||||
color: Colors.white,
|
||||
), // 적 아이콘 (몬스터 대신)
|
||||
),
|
||||
),
|
||||
const SizedBox(height: 8), // 아이콘과 정보 사이 간격
|
||||
|
||||
if (!isPlayer)
|
||||
Consumer<BattleProvider>(
|
||||
@@ -863,3 +940,100 @@ class _FloatingEffectData {
|
||||
|
||||
_FloatingEffectData({required this.id, required this.widget});
|
||||
}
|
||||
|
||||
// 새로운 _FloatingFeedbackText 위젯
|
||||
class _FloatingFeedbackText extends StatefulWidget {
|
||||
final String feedback;
|
||||
final Color color;
|
||||
final VoidCallback onRemove;
|
||||
|
||||
const _FloatingFeedbackText({
|
||||
Key? key,
|
||||
required this.feedback,
|
||||
required this.color,
|
||||
required this.onRemove,
|
||||
}) : super(key: key);
|
||||
|
||||
@override
|
||||
__FloatingFeedbackTextState createState() => __FloatingFeedbackTextState();
|
||||
}
|
||||
|
||||
class __FloatingFeedbackTextState extends State<_FloatingFeedbackText>
|
||||
with SingleTickerProviderStateMixin {
|
||||
late AnimationController _controller;
|
||||
late Animation<Offset> _offsetAnimation;
|
||||
late Animation<double> _opacityAnimation;
|
||||
|
||||
@override
|
||||
void initState() {
|
||||
super.initState();
|
||||
_controller = AnimationController(
|
||||
duration: const Duration(milliseconds: 1000),
|
||||
vsync: this,
|
||||
);
|
||||
|
||||
_offsetAnimation = Tween<Offset>(
|
||||
begin: const Offset(0.0, 0.0),
|
||||
end: const Offset(0.0, -1.5),
|
||||
).animate(CurvedAnimation(parent: _controller, curve: Curves.easeOut));
|
||||
|
||||
_opacityAnimation = Tween<double>(begin: 1.0, end: 0.0).animate(
|
||||
CurvedAnimation(
|
||||
parent: _controller,
|
||||
curve: const Interval(0.5, 1.0, curve: Curves.easeOut),
|
||||
),
|
||||
);
|
||||
|
||||
_controller.forward().then((_) {
|
||||
if (mounted) {
|
||||
widget.onRemove();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@override
|
||||
void dispose() {
|
||||
_controller.dispose();
|
||||
super.dispose();
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return AnimatedBuilder(
|
||||
animation: _controller,
|
||||
builder: (context, child) {
|
||||
return FractionalTranslation(
|
||||
translation: _offsetAnimation.value,
|
||||
child: Opacity(
|
||||
opacity: _opacityAnimation.value,
|
||||
child: Material(
|
||||
color: Colors.transparent,
|
||||
child: Text(
|
||||
widget.feedback,
|
||||
style: TextStyle(
|
||||
color: widget.color,
|
||||
fontSize: 20,
|
||||
fontWeight: FontWeight.bold,
|
||||
shadows: const [
|
||||
Shadow(
|
||||
blurRadius: 2.0,
|
||||
color: Colors.black,
|
||||
offset: Offset(1.0, 1.0),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
},
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
class _FeedbackTextData {
|
||||
final String id;
|
||||
final Widget widget;
|
||||
|
||||
_FeedbackTextData({required this.id, required this.widget});
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user