283 lines
7.0 KiB
Dart
283 lines
7.0 KiB
Dart
import 'package:flutter/cupertino.dart';
|
|
import 'package:yumi/shared/business_logic/models/res/mic_res.dart';
|
|
|
|
import 'package:yumi/app/constants/sc_global_config.dart';
|
|
import 'package:yumi/shared/tools/sc_gift_vap_svga_manager.dart';
|
|
import 'package:yumi/shared/business_logic/models/res/gift_res.dart';
|
|
import 'package:yumi/shared/data_sources/models/enum/sc_gift_type.dart';
|
|
|
|
typedef GiftProvider = SocialChatGiftSystemManager;
|
|
|
|
class SocialChatGiftSystemManager extends ChangeNotifier {
|
|
static const Map<int, String> _luckGiftComboEffectAssets = {
|
|
10: "sc_images/room/anim/luck_gift/luck_gift_combo_count_10.svga",
|
|
30: "sc_images/room/anim/luck_gift/luck_gift_combo_count_30.svga",
|
|
50: "sc_images/room/anim/luck_gift/luck_gift_combo_count_50.svga",
|
|
66: "sc_images/room/anim/luck_gift/luck_gift_combo_count_66.svga",
|
|
100: "sc_images/room/anim/luck_gift/luck_gift_combo_count_100.svga",
|
|
300: "sc_images/room/anim/luck_gift/luck_gift_combo_count_300.svga",
|
|
400: "sc_images/room/anim/luck_gift/luck_gift_combo_count_400.svga",
|
|
666: "sc_images/room/anim/luck_gift/luck_gift_combo_count_666.svga",
|
|
777: "sc_images/room/anim/luck_gift/luck_gift_combo_count_777.svga",
|
|
2000: "sc_images/room/anim/luck_gift/luck_gift_combo_count_2000.svga",
|
|
3000: "sc_images/room/anim/luck_gift/luck_gift_combo_count_3000.svga",
|
|
5000: "sc_images/room/anim/luck_gift/luck_gift_combo_count_5000.svga",
|
|
6000: "sc_images/room/anim/luck_gift/luck_gift_combo_count_6000.svga",
|
|
7000: "sc_images/room/anim/luck_gift/luck_gift_combo_count_7000.svga",
|
|
8000: "sc_images/room/anim/luck_gift/luck_gift_combo_count_8000.svga",
|
|
10000: "sc_images/room/anim/luck_gift/luck_gift_combo_count_10000.svga",
|
|
};
|
|
static const List<int> _luckGiftMilestones = <int>[
|
|
10,
|
|
20,
|
|
30,
|
|
50,
|
|
66,
|
|
88,
|
|
100,
|
|
200,
|
|
300,
|
|
400,
|
|
500,
|
|
666,
|
|
777,
|
|
888,
|
|
1000,
|
|
1500,
|
|
2000,
|
|
3000,
|
|
5000,
|
|
10000,
|
|
15000,
|
|
20000,
|
|
25000,
|
|
30000,
|
|
35000,
|
|
40000,
|
|
45000,
|
|
50000,
|
|
55000,
|
|
60000,
|
|
65000,
|
|
70000,
|
|
75000,
|
|
80000,
|
|
85000,
|
|
90000,
|
|
95000,
|
|
100000,
|
|
];
|
|
|
|
///幸运礼物就不显示这个特效
|
|
bool hideLGiftAnimal = false;
|
|
|
|
///挡位是否已经播放了
|
|
Map<num, bool> isPlayed = {
|
|
10: false,
|
|
20: false,
|
|
30: false,
|
|
50: false,
|
|
66: false,
|
|
88: false,
|
|
100: false,
|
|
200: false,
|
|
300: false,
|
|
400: false,
|
|
500: false,
|
|
666: false,
|
|
777: false,
|
|
888: false,
|
|
1000: false,
|
|
1500: false,
|
|
2000: false,
|
|
3000: false,
|
|
5000: false,
|
|
10000: false,
|
|
15000: false,
|
|
20000: false,
|
|
25000: false,
|
|
30000: false,
|
|
35000: false,
|
|
40000: false,
|
|
45000: false,
|
|
50000: false,
|
|
55000: false,
|
|
60000: false,
|
|
65000: false,
|
|
70000: false,
|
|
75000: false,
|
|
80000: false,
|
|
85000: false,
|
|
90000: false,
|
|
95000: false,
|
|
100000: false,
|
|
};
|
|
|
|
///幸运礼物获得的金币总额
|
|
num luckGiftObtainCoins = 0;
|
|
|
|
///单次中奖的金币
|
|
num awardAmount = 0;
|
|
|
|
///赠送的数量
|
|
num number = 0;
|
|
|
|
bool isManyPeople = false;
|
|
|
|
MicRes? toUser;
|
|
|
|
SocialChatGiftRes? gift;
|
|
|
|
double giftAnimSize = 1;
|
|
double obtainCoinsAnimSize = 1;
|
|
|
|
double awardAmountAnimSize = 1;
|
|
|
|
void toggleGiftAnimationVisibility(bool isHide) {
|
|
hideLGiftAnimal = isHide;
|
|
notifyListeners();
|
|
}
|
|
|
|
void clearAllGiftData() {
|
|
gift = null;
|
|
luckGiftObtainCoins = 0;
|
|
number = 0;
|
|
isManyPeople = false;
|
|
toUser = null;
|
|
|
|
isPlayed = {
|
|
10: false,
|
|
20: false,
|
|
30: false,
|
|
50: false,
|
|
66: false,
|
|
88: false,
|
|
100: false,
|
|
200: false,
|
|
300: false,
|
|
400: false,
|
|
500: false,
|
|
666: false,
|
|
777: false,
|
|
888: false,
|
|
1000: false,
|
|
1500: false,
|
|
2000: false,
|
|
3000: false,
|
|
5000: false,
|
|
10000: false,
|
|
15000: false,
|
|
20000: false,
|
|
25000: false,
|
|
30000: false,
|
|
35000: false,
|
|
40000: false,
|
|
45000: false,
|
|
50000: false,
|
|
60000: false,
|
|
65000: false,
|
|
70000: false,
|
|
75000: false,
|
|
80000: false,
|
|
85000: false,
|
|
90000: false,
|
|
95000: false,
|
|
100000: false,
|
|
};
|
|
notifyListeners();
|
|
}
|
|
|
|
void modifyLuckyGiftCount(
|
|
num n,
|
|
bool manyPeople,
|
|
MicRes first,
|
|
SocialChatGiftRes? checkedGift,
|
|
) {
|
|
number = number + n;
|
|
isManyPeople = manyPeople;
|
|
toUser = first;
|
|
gift = checkedGift;
|
|
giftAnimSize = 1.4;
|
|
notifyListeners();
|
|
startGiftAnimation();
|
|
}
|
|
|
|
void updateLuckyRewardAmount(num n) {
|
|
awardAmount = n;
|
|
luckGiftObtainCoins = luckGiftObtainCoins + n;
|
|
obtainCoinsAnimSize = 1.4;
|
|
awardAmountAnimSize = 1.4;
|
|
notifyListeners();
|
|
}
|
|
|
|
void startGiftAnimation() {
|
|
final milestone = resolveHighestReachedComboMilestone(number);
|
|
if (milestone == null || (isPlayed[milestone] ?? false)) {
|
|
return;
|
|
}
|
|
playVisualEffect(milestone);
|
|
_markMilestonesPlayedUpTo(milestone);
|
|
}
|
|
|
|
void playVisualEffect(num n) {
|
|
if (!(isPlayed[n] ?? false)) {
|
|
if (SCGlobalConfig.isLuckGiftSpecialEffects) {
|
|
final comboEffectPath = resolveComboMilestoneEffectPath(n);
|
|
if (comboEffectPath != null) {
|
|
SCGiftVapSvgaManager().play(comboEffectPath, priority: 200);
|
|
}
|
|
}
|
|
}
|
|
isPlayed[n] = true;
|
|
}
|
|
|
|
void _markMilestonesPlayedUpTo(int milestone) {
|
|
for (final threshold in _luckGiftMilestones) {
|
|
if (threshold > milestone) {
|
|
break;
|
|
}
|
|
isPlayed[threshold] = true;
|
|
}
|
|
}
|
|
|
|
static bool supportsComboMilestoneEffects(SocialChatGiftRes? gift) {
|
|
final giftTab = (gift?.giftTab ?? '').trim();
|
|
return giftTab == "LUCK" || giftTab == SCGiftType.LUCKY_GIFT.name;
|
|
}
|
|
|
|
static int? resolveHighestReachedComboMilestone(num count) {
|
|
final normalizedCount = count.floor();
|
|
int? highest;
|
|
for (final milestone in _luckGiftMilestones) {
|
|
if (milestone > normalizedCount) {
|
|
break;
|
|
}
|
|
highest = milestone;
|
|
}
|
|
return highest;
|
|
}
|
|
|
|
static int? resolveHighestReachedLuckGiftMilestone(num count) {
|
|
return resolveHighestReachedComboMilestone(count);
|
|
}
|
|
|
|
static String? resolveComboMilestoneEffectPath(num count) {
|
|
if (count % 1 != 0) {
|
|
return null;
|
|
}
|
|
final normalizedCount = count.toInt();
|
|
final comboEffectPath = _luckGiftComboEffectAssets[normalizedCount];
|
|
if (comboEffectPath != null) {
|
|
return comboEffectPath;
|
|
}
|
|
if (normalizedCount > 9999) {
|
|
return "sc_images/room/anim/luck_gift_count_5000_mor.mp4";
|
|
}
|
|
return "sc_images/room/anim/luck_gift_count_$normalizedCount.mp4";
|
|
}
|
|
|
|
static String? resolveLuckGiftComboEffectPath(num count) {
|
|
return resolveComboMilestoneEffectPath(count);
|
|
}
|
|
}
|