Files
peko-ios/YuMi/Modules/YMRoom/View/SendGiftView/GiftComboManager.m

843 lines
30 KiB
Mathematica
Raw Normal View History

//
// GiftComboManager.m
// YuMi
//
// Created by P on 2024/9/5.
//
//
#import "GiftComboManager.h"
#import <Foundation/Foundation.h>
#import <UIKit/UIKit.h>
2025-04-21 13:52:13 +08:00
#import <Bugly/Bugly.h>
#import "Api+Gift.h"
#import "UserInfoModel.h"
#import "AttachmentModel.h"
2024-09-12 14:01:12 +08:00
#import "XPGiftCountModel.h"
#import "GiftReceiveInfoModel.h"
#import "XPMessageRemoteExtModel.h"
#import "GiftComboFlagView.h"
//
NSString * const kBoomStateForceResetNotification = @"BoomStateForceResetNotification";
@interface GiftComboManager ()
@property (nonatomic, assign) BOOL enableCombo;
@property (nonatomic, strong) NSMutableArray *requestQueue;
// GiftReceiveInfoModel NSDictionary
@property (nonatomic, strong) NSMutableArray *giftComboQueue;
@property (nonatomic, strong) NSMutableArray *comboFlagQueue;
@property (nonatomic, strong) dispatch_source_t comboFlagTimer;
@property (nonatomic, strong) UIView *containerView;
//
@property (nonatomic, strong) dispatch_source_t timer;
@property (nonatomic, copy) NSArray *sendGiftToUIDs;
@property (nonatomic, assign) GiftSourceType giftSourceType;
@property (nonatomic, strong) GiftInfoModel *giftInfo;
@property (nonatomic, assign) RoomSendGiftType roomSendGiftType;
@property (nonatomic, copy) NSString *roomUID;
@property (nonatomic, copy) NSString *giftNumPerTimes;
@property (nonatomic, strong) UserInfoModel *sendGiftUserInfo;
@property (nonatomic, copy) NSString *sessionID;
2024-09-12 14:01:12 +08:00
@property (nonatomic, strong) XPGiftCountModel *countModel;
@property (nonatomic, assign) NSInteger combo;
@property (nonatomic, assign) bool isCombing;
@property (nonatomic, copy) void (^actionCallback)(ComboActionType type);
2024-09-12 18:49:42 +08:00
@property (nonatomic, copy) NSString *errorMessage;
@property (nonatomic, strong) NSMutableArray<GiftComboFlagView *> *activeViews; // 2
@end
@implementation GiftComboManager
#pragma mark -
- (void)dealloc {
[self stopProcessingGiftComboFlagQueue];
if (self.comboFlagQueue) {
self.comboFlagQueue = NULL;
}
}
+ (instancetype)sharedManager {
static GiftComboManager *sharedInstance = nil;
static dispatch_once_t onceToken;
dispatch_once(&onceToken, ^{
sharedInstance = [[self alloc] init];
sharedInstance.giftComboQueue = [NSMutableArray array];
sharedInstance.activeViews = [NSMutableArray array];
sharedInstance.comboFlagQueue = [NSMutableArray array];
sharedInstance.requestQueue = [NSMutableArray array];
[sharedInstance startProcessingGiftComboFlagQueue];
});
return sharedInstance;
}
//// GiftReceiveInfoModel metadata
- (void)addGiftComboWithInfo:(GiftReceiveInfoModel *)info andMetadata:(NSDictionary *)metadata {
if (info && metadata) {
//
@synchronized (self) {
NSDictionary *comboData = @{@"info": info, @"metadata": metadata};
[self.giftComboQueue addObject:comboData];
}
//
[self startProcessingQueue];
}
}
- (void)addComboFromNIMAttachment:(AttachmentModel *)attachment {
if (attachment) {
//
@synchronized (self) {
[self.giftComboQueue addObject:attachment];
}
//
[self startProcessingQueue];
}
}
//
- (void)reset {
NSLog(@"[Combo effect] 🔄 开始连击重置 - combo: %ld -> 1, enableCombo: %@, actionCallback: %@",
(long)self.combo,
self.enableCombo ? @"YES" : @"NO",
self.actionCallback ? @"可用" : @"为空");
// 1
_combo = 1;
2024-09-12 18:49:42 +08:00
_errorMessage = @"";
//
NSLog(@"[Combo effect] 🔍 重置后验证 - combo: %ld", (long)self.combo);
// GiftComboView
[[NSNotificationCenter defaultCenter] postNotificationName:@"ComboCountReset" object:nil];
//
if (self.actionCallback && self.enableCombo) {
NSLog(@"[Combo effect] 📱 触发连击面板显示回调");
self.actionCallback(ComboAction_ShowPanel);
self.isCombing = YES;
} else if (self.actionCallback && !self.enableCombo) {
NSLog(@"[Combo effect] ⚠️ enableCombo为NO不显示连击面板");
} else if (!self.actionCallback) {
NSLog(@"[Combo effect] ⚠️ actionCallback为空不显示连击面板");
}
2024-12-04 21:22:38 +08:00
if (self.handleRoomUIChanged) {
NSLog(@"[Combo effect] 🎮 隐藏房间UI元素");
2024-12-04 21:22:38 +08:00
self.handleRoomUIChanged(YES);
}
NSLog(@"[Combo effect] ✅ 连击重置完成 - isCombing: %@", self.isCombing ? @"YES" : @"NO");
}
- (void)registerActions:(void (^)(ComboActionType))action {
2024-09-18 17:04:07 +08:00
_combo = 1;
_errorMessage = @"";
self.actionCallback = action;
}
//
- (void)activate {
NSLog(@"[Combo effect] 🔧 激活连击功能");
self.enableCombo = YES;
}
- (void)deactivate {
NSLog(@"[Combo effect] 🔧 停用连击功能");
self.enableCombo = NO;
}
- (BOOL)isActive {
return self.isCombing && self.enableCombo;
}
- (NSInteger)currentCount {
// 1
if (self.combo < 1) {
NSLog(@"[Combo effect] ⚠️ currentCount: 连击计数异常重置为1 - 当前: %ld", (long)self.combo);
self.combo = 1;
}
return self.combo;
}
- (void)incrementCount {
NSLog(@"[Combo effect] 🔢 增加连击计数 - 当前: %ld -> %ld", (long)self.combo, (long)(self.combo + 1));
self.combo += 1;
}
- (void)clear {
NSLog(@"[Combo effect] 🗑️ 清除连击状态");
[self forceBoomStateReset];
// UI
if (self.actionCallback) {
NSLog(@"[Combo effect] 📱 触发连击面板移除回调");
self.actionCallback(ComboAction_RemovePanel);
}
}
- (void)send {
NSLog(@"[Combo effect] 📤 发送连击礼物");
[self sendGift];
}
- (NSDictionary *)stateInfo {
return [self getComboStateInfo];
}
- (BOOL)canStartCombo {
return self.enableCombo && self.giftInfo != nil && self.sendGiftToUIDs.count > 0;
}
- (void)validateState {
[self validateAndFixComboCount];
}
- (void)handleError:(NSError *)error {
NSLog(@"[Combo effect] ❌ 处理错误: %@", error.localizedDescription);
self.errorMessage = error.localizedDescription;
}
- (NSString *)lastErrorMessage {
return self.errorMessage ?: @"";
}
- (void)clearError {
self.errorMessage = @"";
}
- (void)forceBoomStateReset {
NSLog(@"[Combo effect] 🚨 执行强制Boom连击状态重置");
// 1.
NSLog(@"[Combo effect] ⏰ 停止所有定时器");
[self forceStopAllTimers];
// 2.
NSLog(@"[Combo effect] 🗑️ 清空所有队列");
[self clearAllQueues];
// 3.
NSLog(@"[Combo effect] 🔄 重置状态标志 - isCombing: %@ -> NO",
self.isCombing ? @"YES" : @"NO");
self.isCombing = NO;
// 4. combo0
_combo = 0;
NSLog(@"[Combo effect] 🔄 combo计数重置为0");
// enableCombo
// self.enableCombo = NO; //
// actionCallback便
// self.actionCallback = nil; //
// 5.
NSLog(@"[Combo effect] 📢 发送强制重置通知");
dispatch_async(dispatch_get_main_queue(), ^{
[[NSNotificationCenter defaultCenter] postNotificationName:kBoomStateForceResetNotification
object:nil];
});
// 6. UI
2024-12-04 21:22:38 +08:00
if (self.handleRoomUIChanged) {
NSLog(@"[Combo effect] 🎮 恢复房间UI元素");
dispatch_async(dispatch_get_main_queue(), ^{
self.handleRoomUIChanged(NO);
});
}
NSLog(@"[Combo effect] ✅ 强制重置完成 - enableCombo保持: %@, actionCallback保持: %@",
self.enableCombo ? @"YES" : @"NO",
self.actionCallback ? @"可用" : @"为空");
}
//
- (void)forceStopAllTimers {
if (self.timer) {
dispatch_source_cancel(self.timer);
self.timer = nil; //
}
if (self.comboFlagTimer) {
dispatch_source_cancel(self.comboFlagTimer);
self.comboFlagTimer = nil;
}
}
//
- (void)clearAllQueues {
@synchronized (self) {
[self.requestQueue removeAllObjects];
[self.giftComboQueue removeAllObjects];
[self.comboFlagQueue removeAllObjects];
2024-12-04 21:22:38 +08:00
}
}
2024-09-12 14:01:12 +08:00
2024-09-12 14:01:12 +08:00
- (NSInteger)loadTotalGiftNum {
return self.combo * self.countModel.giftNumber.integerValue * self.sendGiftToUIDs.count;
}
//
- (BOOL)isComboStateValid {
@synchronized (self) {
return self.isCombing &&
self.enableCombo &&
self.combo > 0 &&
self.giftInfo != nil &&
self.sendGiftToUIDs.count > 0;
}
}
//
- (NSDictionary *)getComboStateInfo {
@synchronized (self) {
return @{
@"isCombing": @(self.isCombing),
@"enableCombo": @(self.enableCombo),
@"combo": @(self.combo),
@"hasGiftInfo": @(self.giftInfo != nil),
@"targetCount": @(self.sendGiftToUIDs.count),
@"errorMessage": self.errorMessage ?: @""
};
}
}
//
- (void)printComboState {
NSDictionary *stateInfo = [self getComboStateInfo];
NSLog(@"[Combo effect] 📊 当前连击状态:");
NSLog(@"[Combo effect] - isCombing: %@", [stateInfo[@"isCombing"] boolValue] ? @"YES" : @"NO");
NSLog(@"[Combo effect] - enableCombo: %@", [stateInfo[@"enableCombo"] boolValue] ? @"YES" : @"NO");
NSLog(@"[Combo effect] - combo: %@", stateInfo[@"combo"]);
NSLog(@"[Combo effect] - hasGiftInfo: %@", [stateInfo[@"hasGiftInfo"] boolValue] ? @"YES" : @"NO");
NSLog(@"[Combo effect] - targetCount: %@", stateInfo[@"targetCount"]);
NSLog(@"[Combo effect] - errorMessage: %@", stateInfo[@"errorMessage"]);
//
[self validateAndFixComboCount];
}
//
- (void)validateAndFixComboCount {
@synchronized (self) {
if (self.combo < 1) {
NSLog(@"[Combo effect] 🚨 检测到连击计数异常,自动修复 - 当前: %ld -> 1", (long)self.combo);
self.combo = 1;
}
if (self.combo > 1000) {
NSLog(@"[Combo effect] 🚨 检测到连击计数异常,自动修复 - 当前: %ld -> 100", (long)self.combo);
self.combo = 100;
}
}
}
#pragma mark -
- (void)receiveGiftInfoForDisplayComboFlags:(GiftReceiveInfoModel *)receiveInfo
container:(UIView *)container {
NSLog(@"[Combo effect] 🎪 收到连击飘屏请求 - combo: %ld, giftId: %ld", (long)receiveInfo.comboCount, (long)receiveInfo.gift.giftId);
self.containerView = container;
[self.giftComboQueue addObject:receiveInfo];
NSLog(@"[Combo effect] 📊 连击飘屏队列数量: %ld", (long)self.giftComboQueue.count);
[self startProcessingGiftComboFlagQueue];
}
2025-01-15 19:02:58 +08:00
- (void)removeComboFlag {
self.containerView = nil;
[self stopProcessingQueue];
[self stopProcessingGiftComboFlagQueue];
}
- (void)startProcessingGiftComboFlagQueue {
if (self.comboFlagTimer) {
return;
}
dispatch_source_t timer = dispatch_source_create(DISPATCH_SOURCE_TYPE_TIMER, 0, 0,
dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0));
dispatch_source_set_timer(timer,
DISPATCH_TIME_NOW,
0.2 * NSEC_PER_SEC,
0.01 * NSEC_PER_SEC);
@kWeakify(self);
dispatch_source_set_event_handler(timer, ^{
@kStrongify(self);
[self processGiftFlagQueue];
});
dispatch_resume(timer);
self.comboFlagTimer = timer;
}
- (void)stopProcessingGiftComboFlagQueue {
if (self.comboFlagTimer) {
dispatch_source_cancel(self.comboFlagTimer);
@kWeakify(self);
dispatch_source_set_cancel_handler(self.comboFlagTimer, ^{
@kStrongify(self);
self.comboFlagTimer = nil;
});
}
}
- (void)processGiftFlagQueue {
if (self.giftComboQueue.count == 0) {
return;
}
GiftReceiveInfoModel *receiveInfo = [self.giftComboQueue firstObject];
NSLog(@"[Combo effect] 🎪 处理连击飘屏 - combo: %ld, giftId: %ld", (long)receiveInfo.comboCount, (long)receiveInfo.gift.giftId);
[self.giftComboQueue xpSafeRemoveObjectAtIndex:0];
NSLog(@"[Combo effect] 📊 移除后连击飘屏队列数量: %ld", (long)self.giftComboQueue.count);
dispatch_async(dispatch_get_main_queue(), ^{
[self handleGiftInfo:receiveInfo];
});
}
- (void)handleGiftInfo:(GiftReceiveInfoModel *)receiveInfo {
2024-09-12 18:49:42 +08:00
if (receiveInfo.comboCount < 1) {
//
return;
}
if ([self updateExistingViewWithModel:receiveInfo]) {
//
return;
}
if (self.activeViews.count >= 2) {
GiftComboFlagView *oldestView = [self.activeViews firstObject];
[self animateRemoveView:oldestView];
}
CGFloat positionY = kGetScaleWidth(380);
CGFloat positionX = isMSRTL() ? -self.containerView.bounds.size.width : self.containerView.bounds.size.width;
GiftComboFlagView *flagView = [[GiftComboFlagView alloc] initWithFrame:CGRectMake(positionX,
positionY,
kGetScaleWidth(300),
50)];
@kWeakify(self);
@kWeakify(flagView);
[flagView setTimerEnd:^{
@kStrongify(self);
@kStrongify(flagView);
2024-09-12 14:01:12 +08:00
[self animateRemoveView:flagView];
}];
[flagView updateReceiveInfoModel:receiveInfo animationType:0];
2024-09-12 14:01:12 +08:00
[self allCurrentFlagMoveDown];
[self.containerView addSubview:flagView];
2024-09-12 18:49:42 +08:00
[self.activeViews insertObject:flagView atIndex:0];
2024-09-12 14:01:12 +08:00
[self animateView:flagView positionY:positionY];
}
- (void)allCurrentFlagMoveDown {
2024-09-12 14:01:12 +08:00
CGFloat positionY = kGetScaleWidth(380);
2024-09-12 18:49:42 +08:00
[self.activeViews enumerateObjectsWithOptions:NSEnumerationConcurrent usingBlock:^(GiftComboFlagView * _Nonnull obj, NSUInteger idx, BOOL * _Nonnull stop) {
dispatch_async(dispatch_get_main_queue(), ^{
CGRect rect = obj.frame;
rect.origin.y = positionY + idx * 50;
obj.frame = rect;
});
}];
}
- (void)animateView:(GiftComboFlagView *)flagView positionY:(CGFloat)positionY {
[UIView animateWithDuration:0.1
animations:^{
if (isMSRTL()) {
//
CGFloat screenWidth = [UIScreen mainScreen].bounds.size.width;
// x - -
CGFloat newX = screenWidth - 20 - kGetScaleWidth(300);
// flagView frame使 20
flagView.frame = CGRectMake(newX, positionY, kGetScaleWidth(300), 50);
} else {
flagView.frame = CGRectMake(20, positionY, kGetScaleWidth(300), 50);
}
2024-09-12 14:01:12 +08:00
} completion:^(BOOL finished) {
[self allCurrentFlagMoveDown];
}];
}
- (void)animateRemoveView:(GiftComboFlagView *)flagView {
[flagView removeFromSuperview];
if ([self.activeViews containsObject:flagView]) {
[self.activeViews removeObject:flagView];
flagView = nil;
}
2024-09-12 18:49:42 +08:00
[self allCurrentFlagMoveDown];
}
// View ID
- (BOOL)updateExistingViewWithModel:(GiftReceiveInfoModel *)model {
NSInteger index = 0;
for (GiftComboFlagView *existingFlag in self.activeViews) {
2024-09-12 14:01:12 +08:00
if (existingFlag.superview == nil) {
continue;
}
if ([existingFlag.receiveInfo isEqual:model]) {
[self updateComboFlag:existingFlag with:model];
return YES;
}
index++;
}
return NO;
}
- (void)updateComboFlag:(GiftComboFlagView *)flagView with:(GiftReceiveInfoModel *)model {
[flagView updateReceiveInfoModel:model animationType:1];
}
// MARK: Logic is 0.25s
#pragma mark -
//
- (void)startProcessingQueue {
if (self.timer) {
return; //
}
// GCD
self.timer = dispatch_source_create(DISPATCH_SOURCE_TYPE_TIMER, 0, 0, dispatch_get_main_queue());
//#if DEBUG
// dispatch_source_set_timer(self.timer, DISPATCH_TIME_NOW, 0.01 * NSEC_PER_SEC, 0.01 * NSEC_PER_SEC);
//#else
// 0.25
dispatch_source_set_timer(self.timer, DISPATCH_TIME_NOW, 0.25 * NSEC_PER_SEC, 0.01 * NSEC_PER_SEC);
//#endif
//
dispatch_source_set_event_handler(self.timer, ^{
[self processRequestQueue];
2024-12-11 10:48:01 +08:00
[self processGiftComboQueue];
});
2025-03-06 15:26:44 +08:00
// ****
2024-12-11 10:48:01 +08:00
[self processRequestQueue];
[self processGiftComboQueue];
//
dispatch_resume(self.timer);
}
//
- (void)stopProcessingQueue {
if (self.timer) {
if (self.requestQueue.count == 0 && self.giftComboQueue.count == 0) {
2024-12-11 10:48:01 +08:00
//
dispatch_source_cancel(self.timer);
2024-12-11 10:48:01 +08:00
// timer nil
@kWeakify(self);
dispatch_source_set_cancel_handler(self.timer, ^{
@kStrongify(self);
self.timer = nil;
});
}
}
}
//
- (void)processGiftComboQueue {
@synchronized (self) {
if (self.giftComboQueue.count > 0) {
//
AttachmentModel *attachment = [self.giftComboQueue firstObject];
[self.giftComboQueue xpSafeRemoveObjectAtIndex:0];
//
[self processGiftComboWith:attachment];
} else {
[self stopProcessingQueue];
}
}
}
//
- (void)processGiftComboWith:(AttachmentModel *)info {
[self sendCustomMessage:info];
}
2024-09-12 18:49:42 +08:00
- (NSString *)loadErrorMessage {
return self.errorMessage;
}
- (void)processRequestQueue {
@synchronized (self) {
if (self.requestQueue.count > 0) {
//
NSDictionary *dic = [self.requestQueue xpSafeObjectAtIndex:0];
if (dic) {
[self handleSendGift:dic];
[self.requestQueue removeObject:dic];
}
} else {
[self stopProcessingQueue];
}
}
}
#pragma mark - Gift meta data
// save
- (void)configureWithGiftInfo:(GiftInfoModel *)giftInfo
targetUIDs:(NSArray *)UIDs
roomUID:(NSString *)roomUID
sessionID:(NSString *)sessionID
userInfo:(UserInfoModel *)userInfo
countModel:(XPGiftCountModel *)countModel
sourceType:(GiftSourceType)sourceType
sendType:(RoomSendGiftType)sendType
giftNum:(NSString *)giftNum {
NSLog(@"[Combo effect] 🔧 统一配置连击参数");
self.giftInfo = giftInfo;
self.sendGiftToUIDs = UIDs;
self.roomUID = roomUID;
self.sessionID = sessionID;
self.sendGiftUserInfo = userInfo;
self.countModel = countModel;
self.giftSourceType = sourceType;
self.roomSendGiftType = sendType;
self.giftNumPerTimes = giftNum;
NSLog(@"[Combo effect] ✅ 连击参数配置完成 - giftId: %ld, targetCount: %ld",
(long)giftInfo.giftId, (long)UIDs.count);
}
- (BOOL)loadEnable {
return self.enableCombo;
}
#pragma mark - XPGiftPresenter
- (void)sendGift {
NSLog(@"[Combo effect] 🎁 开始发送连击礼物 - combo: %ld, isCombing: %@", (long)self.combo, self.isCombing ? @"YES" : @"NO");
NSString *allUIDs = @"";
for (NSString *item in self.sendGiftToUIDs) {
if (allUIDs.length > 0) {
allUIDs = [allUIDs stringByAppendingString:@","];
}
allUIDs = [allUIDs stringByAppendingString:item];
}
NSDictionary *dic = @{
@"targetUids":allUIDs,
@"giftNum":self.giftNumPerTimes,
@"sendType":[NSString stringWithFormat:@"%ld", GiftSendType_OnMic],
@"giftId":[NSString stringWithFormat:@"%ld", self.giftInfo.giftId],
@"giftSource":[NSString stringWithFormat:@"%ld", self.giftSourceType],
@"giftType":[NSString stringWithFormat:@"%ld", self.roomSendGiftType],
@"roomUid":self.roomUID
};
NSLog(@"[Combo effect] 📦 添加礼物请求到队列 - giftId: %ld, targetUids: %@", (long)self.giftInfo.giftId, allUIDs);
[self.requestQueue addObject:dic];
[self startProcessingQueue];
}
- (void)handleSendGift:(NSDictionary *)dic {
NSString *allUIDs = [dic objectForKey:@"targetUids"];
NSString *giftId = [dic objectForKey:@"giftId"];
NSLog(@"[Combo effect] 🌐 开始调用送礼API - giftId: %@, targetUids: %@", giftId, allUIDs);
@kWeakify(self);
[Api requestSendGift:^(BaseModel * _Nullable data, NSInteger code, NSString * _Nullable msg) {
@kStrongify(self);
2024-09-12 18:49:42 +08:00
if (!self) {
NSLog(@"[Combo effect] ⚠️ self已释放忽略API回调");
2024-09-12 18:49:42 +08:00
return;
}
if (code == 200) {
NSLog(@"[Combo effect] ✅ 送礼API成功 - giftId: %@, combo: %ld", giftId, (long)self.combo);
GiftReceiveInfoModel *receive = [GiftReceiveInfoModel modelWithJSON:data.data];
receive.sourceType = [[dic objectForKey:@"giftSource"] integerValue];
receive.roomSendGiftType = [[dic objectForKey:@"giftType"] integerValue];
NSArray *array = [allUIDs componentsSeparatedByString:@","];
receive.receiveGiftNumberUser = array.count;
[self handleSendGiftSuccess:receive sourceData:data];
2024-12-04 21:22:38 +08:00
[[NSNotificationCenter defaultCenter] postNotificationName:@"receiveLuckGiftWinning"
object:@{@"CurrentGold": receive.userPurse.diamonds,
@"Price": @(receive.gift.goldPrice * receive.giftNum * array.count),
@"isFromWinning":@(NO)}];
} else {
NSLog(@"[Combo effect] ❌ 送礼API失败 - code: %ld, msg: %@", (long)code, msg);
//
if (code > 500 && code < 600) {
//
NSLog(@"[Combo effect] 🔄 服务器错误,保持连击状态 - code: %ld", (long)code);
#if DEBUG
self.errorMessage = [NSString stringWithFormat:@"服务器繁忙,请稍后重试 - %@", msg];
#else
self.errorMessage = @"Over Heat & try later";
dispatch_async(dispatch_get_global_queue(0, 0), ^{
NSMutableDictionary *logDic = [@{@"targetUids": allUIDs,
@"giftNum": self.giftNumPerTimes} mutableCopy];
[logDic addEntriesFromDictionary:dic];
[logDic setObject:[NSThread callStackSymbols] forKey:@"call stack symbols"];
[logDic setObject:msg forKey:@"error message"];
[logDic setObject:@"gift/sendV5" forKey:@"http method"];
[Bugly reportError:[NSError errorWithDomain:[NSString stringWithFormat:@"UID: %@,API: %@ 异常",
[AccountInfoStorage instance].getUid,
@"gift/sendV5"]
code:code
userInfo:logDic]];
});
#endif
//
} else if (code == 31005) {
//
NSLog(@"[Combo effect] 💰 余额不足,强制移除连击状态");
self.errorMessage = YMLocalizedString(@"XPCandyTreeInsufficientBalanceView1");
[self clear];
} else if (code == 8535) {
// VIP,
NSLog(@"[Combo effect] 👑 VIP等级不足强制移除连击状态");
self.errorMessage = @"";
[self clear];
} else {
//
self.errorMessage = msg;
//
if (code >= 1000 && code < 2000) {
//
NSLog(@"[Combo effect] 🌐 网络错误,保持连击状态 - code: %ld", (long)code);
} else {
//
NSLog(@"[Combo effect] 🚨 其他错误,强制移除连击状态 - code: %ld", (long)code);
[self clear];
}
}
2024-12-06 14:38:45 +08:00
if (self.actionCallback) {
self.actionCallback(ComboAction_Error);
}
}
}
targetUids:allUIDs
giftNum:self.giftNumPerTimes
sendType:[dic objectForKey:@"sendType"]
giftId:[dic objectForKey:@"giftId"]
giftSource:[dic objectForKey:@"giftSource"]
giftType:[dic objectForKey:@"giftType"]
roomUid:[dic objectForKey:@"roomUid"]
msg:@""
uid:[AccountInfoStorage instance].getUid];
}
- (void)handleSendGiftSuccess:(GiftReceiveInfoModel *)receive
sourceData:(BaseModel *)response {
NSLog(@"[Combo effect] 🎉 连击礼物发送成功 - 当前combo: %ld", (long)self.combo);
//
[self validateAndFixComboCount];
// APIcombo
if (self.isCombing) {
NSLog(@"[Combo effect] 🔢 API成功递增连击计数 - 当前: %ld -> %ld", (long)self.combo, (long)(self.combo + 1));
self.combo += 1;
// UI
if (self.actionCallback) {
self.actionCallback(ComboAction_Combo_Count_Update);
}
}
NSMutableDictionary *dic = [NSMutableDictionary dictionaryWithDictionary:response.data];
// 1
NSInteger comboToSet = self.combo;
if (comboToSet < 1) {
NSLog(@"[Combo effect] 🚨 发送云信消息时连击计数异常,修复为 1 - 当前: %ld", (long)comboToSet);
comboToSet = 1;
}
[dic setObject:@(comboToSet) forKey:@"comboCount"];
//
NSNumber *setComboCount = dic[@"comboCount"];
NSLog(@"[Combo effect] 🔍 连击计数设置验证 - 设置值: %@, 当前combo: %ld", setComboCount, (long)self.combo);
2024-12-06 14:38:45 +08:00
self.sendGiftReceiveInfo = receive;
if (self.handleComboSuccess) {
NSLog(@"[Combo effect] 📨 调用连击成功回调,发送云信消息");
self.handleComboSuccess(receive, dic);
}
2024-12-06 14:38:45 +08:00
if (self.actionCallback) {
self.actionCallback(ComboAction_Update_After_Send_Success);
}
NSLog(@"[Combo effect] ✅ 连击礼物处理完成");
}
- (void)sendCustomMessage:(AttachmentModel *)attachment {
NSLog(@"[Combo effect] 📨 发送云信自定义消息 - combo: %ld", (long)self.combo);
NIMMessage *message = [[NIMMessage alloc]init];
NIMCustomObject *object = [[NIMCustomObject alloc] init];
object.attachment = attachment;
message.messageObject = object;
UserInfoModel *userInfo = self.sendGiftUserInfo;
XPMessageRemoteExtModel *extModel = [[XPMessageRemoteExtModel alloc] init];
extModel.androidBubbleUrl = userInfo.androidBubbleUrl;
extModel.iosBubbleUrl = userInfo.iosBubbleUrl;
extModel.fromSayHelloChannel = userInfo.fromSayHelloChannel;
2025-01-22 21:22:58 +08:00
extModel.platformRole = userInfo.platformRole;
NSMutableDictionary *remoteExt = [NSMutableDictionary dictionaryWithObject:extModel.model2dictionary forKey:[NSString stringWithFormat:@"%ld", userInfo.uid]];
message.remoteExt = remoteExt;
//
NIMSession *session = [NIMSession session:self.sessionID type:NIMSessionTypeChatroom];
NSError *error = nil;
[[NIMSDK sharedSDK].chatManager sendMessage:message toSession:session error:&error];
if (error) {
NSLog(@"[Combo effect] ❌ 云信消息发送失败 - error: %@", error.localizedDescription);
} else {
NSLog(@"[Combo effect] ✅ 云信消息发送成功");
}
}
@end