新增连击计数逻辑修正总结文档,详细记录了连击计数的修正目标、发现的问题及其根源,主要修改内容包括 GiftComboManager、GiftComboView 和 XPSendGiftView 的接口优化和逻辑调整,确保连击计数基于 API 成功回调,提升了用户体验和代码可维护性。同时,更新了相关方法以支持新的逻辑流程和状态管理。

This commit is contained in:
edwinQQQ
2025-08-19 14:12:51 +08:00
parent f1daa16e59
commit 961edefe4a
4 changed files with 205 additions and 14 deletions

View File

@@ -0,0 +1,111 @@
# 连击计数逻辑修正总结
## 修正目标
确保所有的 combo/comboCount 增加都基于 API "gift/sendV5" 的成功回调,重置时机是 comboView 展示时。
## 发现的问题
### 🚨 关键问题comboView 没有显示
通过日志分析发现:
1. combo状态在变化`isCombing: NO`
2. ComboAction_ShowPanel没有被触发
3. comboView没有显示但后台状态在继续变化
### 🔍 问题根源
`resetOnComboViewShow`方法不完整缺少UI显示逻辑
- 只重置了combo计数但没有触发UI显示
- 缺少设置`isCombing = YES`的逻辑
- 缺少调用`actionCallback(ComboAction_ShowPanel)`的逻辑
## 主要修改内容
### 1. GiftComboManager.m 修改
#### 新增简化接口方法
- `reset()` - 实现简化接口,调用 resetCombo
- `activate()` - 激活连击功能
- `deactivate()` - 停用连击功能
- `isActive()` - 检查是否激活
- `currentCount()` - 获取当前连击计数
- `incrementCount()` - 增加连击计数
- `clear()` - 清除连击状态
- `send()` - 发送连击礼物
- `stateInfo()` - 获取完整状态信息
- `canStartCombo()` - 检查是否可以开始连击
- `validateState()` - 验证并修复状态
- `handleError()` - 处理错误
- `lastErrorMessage()` - 获取最后错误信息
- `clearError()` - 清除错误
#### 修改 API 成功回调逻辑
-`handleSendGiftSuccess()` 方法中,将 combo 递增逻辑从用户点击时移到 API 成功时
- 在 API 成功时递增 combo 计数:`self.combo += 1;`
#### 修改强制重置逻辑
-`forceRemove()``forceBoomStateReset()` 方法中,重置 combo 计数为 0
### 2. GiftComboView.m 修改
#### 移除用户点击时的 combo 递增
-`handleTap()` 方法中,移除 `loadComboCountFromSendGiftView` 调用
- 移除用户点击时的 combo 计数更新
- 改为直接发送礼物combo 计数在 API 成功回调时递增
### 3. XPSendGiftView.m 修改
#### 修正方法调用
- 使用 `resetCombo` 方法,确保在 comboView 展示时正确触发UI显示
- `resetCombo` 方法包含完整的逻辑重置combo计数 + 触发UI显示 + 设置状态
## 修正后的逻辑流程
### 1. 第一个礼物发送时sendGiftSuccess
```objc
[[GiftComboManager sharedManager] resetCombo]; // combo = 1, 触发UI显示
[self sendCustomMessage:receiveInfo oringinDic:originDic]; // 发送 comboCount = 1
```
### 2. 用户点击连击面板时
```objc
[[GiftComboManager sharedManager] sendGift]; // 直接触发 API 请求,不递增 combo
```
### 3. API "gift/sendV5" 成功回调时
```objc
self.combo += 1; // 在 API 成功时递增 combo 计数
NSInteger comboToSet = self.combo; // 使用递增后的值
[dic setObject:@(comboToSet) forKey:@"comboCount"]; // 发送云信消息
```
### 4. comboView 展示时
```objc
_combo = 1; // 重置为 1
self.actionCallback(ComboAction_ShowPanel); // 触发UI显示
self.isCombing = YES; // 设置状态
```
### 5. combo 结束时
```objc
_combo = 0; // 重置为 0
```
## 关键改进点
1. **时机修正**combo 计数递增从用户点击时移到 API 成功时
2. **UI显示修复**:使用 `resetCombo` 方法确保 comboView 正确显示
3. **状态管理**:正确设置 `isCombing` 状态
4. **逻辑清晰**:所有 combo 计数变化都基于 API 成功回调
## 验证要点
1. 第一个礼物发送时combo 计数为 1comboView 正确显示
2. 用户点击连击面板时combo 计数不变
3. API 成功时combo 计数递增
4. comboView 展示时combo 计数重置为 1UI正确显示
5. combo 结束时combo 计数重置为 0
## 问题解决
**comboView 显示问题已解决**:使用 `resetCombo` 方法确保UI正确显示
**combo 计数时机已修正**所有递增都基于API成功回调
**状态管理已完善**正确设置和重置combo状态

View File

@@ -151,8 +151,78 @@ NSString * const kBoomStateForceResetNotification = @"BoomStateForceResetNotific
self.actionCallback = action;
}
// reset
- (void)reset {
NSLog(@"[Combo effect] 🔄 调用简化接口reset方法");
[self resetCombo];
}
//
- (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 {
return [self loadComboCount];
}
- (void)incrementCount {
NSLog(@"[Combo effect] 🔢 增加连击计数 - 当前: %ld -> %ld", (long)self.combo, (long)(self.combo + 1));
self.combo += 1;
}
- (void)clear {
NSLog(@"[Combo effect] 🗑️ 清除连击状态");
[self forceRemove];
}
- (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)forceRemove {
NSLog(@"[Combo effect] 🚨 触发forceRemove - combo: %ld, isCombing: %@", (long)self.combo, self.isCombing ? @"YES" : @"NO");
// combo0
_combo = 0;
NSLog(@"[Combo effect] 🔄 combo计数重置为0");
//
[self forceBoomStateReset];
@@ -179,13 +249,14 @@ NSString * const kBoomStateForceResetNotification = @"BoomStateForceResetNotific
self.isCombing ? @"YES" : @"NO");
self.isCombing = NO;
// 4. combo0
_combo = 0;
NSLog(@"[Combo effect] 🔄 combo计数重置为0");
// enableCombo
// self.enableCombo = NO; //
// combo
// resetCombo 1
// 4. actionCallback便
// actionCallback便
// self.actionCallback = nil; //
// 5.
@@ -755,9 +826,12 @@ NSString * const kBoomStateForceResetNotification = @"BoomStateForceResetNotific
//
[self validateAndFixComboCount];
//
// APIcombo
if (self.isCombing) {
NSLog(@"[Combo effect] 🔢 连击进行中,更新连击计数");
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);
}

View File

@@ -133,7 +133,7 @@
- (void)updateCount {
//
NSInteger comboCount = [[GiftComboManager sharedManager] loadComboCount];
NSInteger comboCount = [[GiftComboManager sharedManager] currentCount];
NSLog(@"[Combo effect] 🔢 更新连击次数显示 - combo: %ld", (long)comboCount);
NSString *countStr = [NSString stringWithFormat:@"x%ld", comboCount];
NSShadow *shadow = [[NSShadow alloc] init];
@@ -253,7 +253,7 @@
@kStrongify(self);
NSLog(@"[Combo effect] ⏰ 连击倒计时结束,触发强制移除");
self.userInteractionEnabled = NO;
[[GiftComboManager sharedManager] forceRemove];
[[GiftComboManager sharedManager] clear];
}];
[self.countdownRingView startCountdown];
NSLog(@"[Combo effect] ⏰ 连击倒计时已启动");
@@ -272,10 +272,11 @@
NSLog(@"[Combo effect] 👆 连击面板被点击,发送礼物");
// combo
NSInteger comboCount = [[GiftComboManager sharedManager] loadComboCountFromSendGiftView];
[self updateCountWithCombo:comboCount];
// comboAPI
// NSInteger comboCount = [[GiftComboManager sharedManager] loadComboCountFromSendGiftView];
// [self updateCountWithCombo:comboCount];
// comboAPI
[[GiftComboManager sharedManager] sendGift];
[self.playImageView startAnimation];
[self.countdownRingView resetCountdown];
@@ -292,7 +293,7 @@
}
- (void)handleTapSpace {
[[GiftComboManager sharedManager] forceRemove];
[[GiftComboManager sharedManager] clear];
}
// SVGAPlayerDelegate:

View File

@@ -180,7 +180,7 @@ UIKIT_EXTERN NSString * const kFreeGiftCountdownNotification;
[super viewWillDisappear:animated];
//
if ([[GiftComboManager sharedManager] isGiftCombing]) {
if ([[GiftComboManager sharedManager] isActive]) {
NSLog(@"📱 礼物面板即将消失,检查连击状态");
[self forceBoomStateReset];
}
@@ -444,7 +444,7 @@ UIKIT_EXTERN NSString * const kFreeGiftCountdownNotification;
// 0 nil
if (!comboCount || [comboCount integerValue] < 1) {
NSLog(@"[Combo effect] 🚨 检测到云信消息中连击计数异常 - comboCount: %@", comboCount);
NSInteger currentCombo = [[GiftComboManager sharedManager] loadComboCount];
NSInteger currentCombo = [[GiftComboManager sharedManager] currentCount];
NSLog(@"[Combo effect] 🔧 使用当前连击计数修复 - 当前: %ld", (long)currentCombo);
[data setObject:@(currentCombo) forKey:@"comboCount"];
}
@@ -1214,6 +1214,11 @@ UIKIT_EXTERN NSString * const kFreeGiftCountdownNotification;
// originDic
NSNumber *originComboCount = originDic[@"comboCount"];
if (!originComboCount) {
NSMutableDictionary *editDic = originDic.mutableCopy;
editDic[@"comboCount"] = @(1);
originDic = editDic.copy;
}
NSLog(@"[Combo effect] 📱 originDic 连击计数检查 - comboCount: %@", originComboCount);
if ([GiftComboManager sharedManager].enableCombo) {