功能:自动钓鱼卡持续循环钓鱼
有自动钓鱼卡时: - 点一次「钓鱼」自动循环:抛竿→收竿→冷却→抛竿... - 冷却期间按钮显示倒计时「⏳ 冷却 Xs」 - 屏幕右下角显示「🛑 停止自动钓鱼」悬浮按钮 - 点击停止或卡到期后自动退出循环 - 出错时也自动停止循环
This commit is contained in:
@@ -192,6 +192,7 @@ class FishingController extends Controller
|
|||||||
'result' => $result,
|
'result' => $result,
|
||||||
'exp_num' => $user->exp_num,
|
'exp_num' => $user->exp_num,
|
||||||
'jjb' => $user->jjb,
|
'jjb' => $user->jjb,
|
||||||
|
'cooldown_seconds' => $cooldown, // 前端自动钓鱼卡循环等待用
|
||||||
]);
|
]);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1623,6 +1623,9 @@
|
|||||||
let fishingTimer = null;
|
let fishingTimer = null;
|
||||||
let fishingReelTimeout = null;
|
let fishingReelTimeout = null;
|
||||||
let _fishToken = null; // 当次钓鱼的 token
|
let _fishToken = null; // 当次钓鱼的 token
|
||||||
|
let _autoFishing = false; // 是否处于自动钓鱼循环中
|
||||||
|
let _autoFishCdTimer = null; // 自动钓鱼冷却计时器
|
||||||
|
let _autoFishCdCountdown = null; // 冷却倒计时 interval
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 创建浮漂 DOM 元素(绝对定位在聊天框上层)
|
* 创建浮漂 DOM 元素(绝对定位在聊天框上层)
|
||||||
@@ -1707,6 +1710,7 @@
|
|||||||
|
|
||||||
// 保存本次 token(收竿时提交)
|
// 保存本次 token(收竿时提交)
|
||||||
_fishToken = data.token;
|
_fishToken = data.token;
|
||||||
|
_autoFishing = !!data.auto_fishing; // 持有自动钓鱼卡则开启循环模式
|
||||||
|
|
||||||
// 聊天框提示
|
// 聊天框提示
|
||||||
const castDiv = document.createElement('div');
|
const castDiv = document.createElement('div');
|
||||||
@@ -1830,25 +1834,139 @@
|
|||||||
` <span style="color:#666;font-size:11px;">(经验:${data.exp_num} 金币:${data.jjb})</span>` +
|
` <span style="color:#666;font-size:11px;">(经验:${data.exp_num} 金币:${data.jjb})</span>` +
|
||||||
`<span class="msg-time">(${timeStr})</span>`;
|
`<span class="msg-time">(${timeStr})</span>`;
|
||||||
container2.appendChild(resultDiv);
|
container2.appendChild(resultDiv);
|
||||||
|
|
||||||
|
// 自动钓鱼卡循环:等冷却时间后自动再次抛竿
|
||||||
|
if (_autoFishing) {
|
||||||
|
const cooldown = data.cooldown_seconds || 300;
|
||||||
|
const btn = document.getElementById('fishing-btn');
|
||||||
|
btn.disabled = true;
|
||||||
|
btn.textContent = `⏳ 冷却 ${cooldown}s`;
|
||||||
|
btn.onclick = null;
|
||||||
|
|
||||||
|
// 显示停止按钮
|
||||||
|
_showAutoFishStopBtn(cooldown);
|
||||||
|
|
||||||
|
// 倒计时更新文字
|
||||||
|
let remaining = cooldown;
|
||||||
|
_autoFishCdCountdown = setInterval(() => {
|
||||||
|
remaining--;
|
||||||
|
const b = document.getElementById('fishing-btn');
|
||||||
|
if (b) b.textContent = `⏳ 冷却 ${remaining}s`;
|
||||||
|
if (remaining <= 0) {
|
||||||
|
clearInterval(_autoFishCdCountdown);
|
||||||
|
_autoFishCdCountdown = null;
|
||||||
|
}
|
||||||
|
}, 1000);
|
||||||
|
|
||||||
|
// 冷却结束后自动抛竿
|
||||||
|
_autoFishCdTimer = setTimeout(() => {
|
||||||
|
_autoFishCdTimer = null;
|
||||||
|
_hideAutoFishStopBtn();
|
||||||
|
if (_autoFishing) startFishing(); // 仍未停止 → 继续
|
||||||
|
}, cooldown * 1000);
|
||||||
|
|
||||||
|
if (autoScroll) container2.scrollTop = container2.scrollHeight;
|
||||||
|
return; // 不走 resetFishingBtn
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
const errDiv = document.createElement('div');
|
const errDiv = document.createElement('div');
|
||||||
errDiv.className = 'msg-line';
|
errDiv.className = 'msg-line';
|
||||||
errDiv.innerHTML =
|
errDiv.innerHTML =
|
||||||
`<span style="color:red;">【钓鱼】${data.message || '操作失败'}</span><span class="msg-time">(${timeStr})</span>`;
|
`<span style="color:red;">【钓鱼】${data.message || '操作失败'}</span><span class="msg-time">(${timeStr})</span>`;
|
||||||
container2.appendChild(errDiv);
|
container2.appendChild(errDiv);
|
||||||
|
_autoFishing = false; // 出错时停止循环
|
||||||
}
|
}
|
||||||
if (autoScroll) container2.scrollTop = container2.scrollHeight;
|
if (autoScroll) container2.scrollTop = container2.scrollHeight;
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
window.chatDialog.alert('网络错误:' + e.message, '网络异常', '#cc4444');
|
window.chatDialog.alert('网络错误:' + e.message, '网络异常', '#cc4444');
|
||||||
|
_autoFishing = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
resetFishingBtn();
|
resetFishingBtn();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 重置钓鱼按钮状态
|
* 显示「停止自动钓鱼」悬浮按钮
|
||||||
|
* @param {number} cooldown 冷却秒数(用于倒计时提示)
|
||||||
|
*/
|
||||||
|
function _showAutoFishStopBtn(cooldown) {
|
||||||
|
if (document.getElementById('auto-fish-stop-btn')) return;
|
||||||
|
const stopBtn = document.createElement('button');
|
||||||
|
stopBtn.id = 'auto-fish-stop-btn';
|
||||||
|
stopBtn.innerHTML = '🛑 停止自动钓鱼';
|
||||||
|
stopBtn.style.cssText = `
|
||||||
|
position: fixed;
|
||||||
|
bottom: 80px;
|
||||||
|
right: 20px;
|
||||||
|
z-index: 10000;
|
||||||
|
background: linear-gradient(135deg, #dc2626, #b91c1c);
|
||||||
|
color: #fff;
|
||||||
|
border: none;
|
||||||
|
border-radius: 20px;
|
||||||
|
padding: 8px 18px;
|
||||||
|
font-size: 13px;
|
||||||
|
font-weight: bold;
|
||||||
|
cursor: pointer;
|
||||||
|
box-shadow: 0 4px 12px rgba(220,38,38,0.4);
|
||||||
|
animation: autoFishBtnPulse 1.8s ease-in-out infinite;
|
||||||
|
`;
|
||||||
|
if (!document.getElementById('auto-fish-stop-style')) {
|
||||||
|
const s = document.createElement('style');
|
||||||
|
s.id = 'auto-fish-stop-style';
|
||||||
|
s.textContent = `@keyframes autoFishBtnPulse {
|
||||||
|
0%,100% { transform: scale(1); }
|
||||||
|
50% { transform: scale(1.05); }
|
||||||
|
}`;
|
||||||
|
document.head.appendChild(s);
|
||||||
|
}
|
||||||
|
stopBtn.onclick = stopAutoFishing;
|
||||||
|
document.body.appendChild(stopBtn);
|
||||||
|
}
|
||||||
|
|
||||||
|
/** 隐藏停止按钮 */
|
||||||
|
function _hideAutoFishStopBtn() {
|
||||||
|
const el = document.getElementById('auto-fish-stop-btn');
|
||||||
|
if (el) el.remove();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 手动停止自动钓鱼循环
|
||||||
|
*/
|
||||||
|
function stopAutoFishing() {
|
||||||
|
_autoFishing = false;
|
||||||
|
if (_autoFishCdTimer) {
|
||||||
|
clearTimeout(_autoFishCdTimer);
|
||||||
|
_autoFishCdTimer = null;
|
||||||
|
}
|
||||||
|
if (_autoFishCdCountdown) {
|
||||||
|
clearInterval(_autoFishCdCountdown);
|
||||||
|
_autoFishCdCountdown = null;
|
||||||
|
}
|
||||||
|
_hideAutoFishStopBtn();
|
||||||
|
|
||||||
|
const noticeDiv = document.createElement('div');
|
||||||
|
noticeDiv.className = 'msg-line';
|
||||||
|
noticeDiv.innerHTML = '<span style="color:#6b7280;">🛑 已停止自动钓鱼。</span>';
|
||||||
|
container2.appendChild(noticeDiv);
|
||||||
|
if (autoScroll) container2.scrollTop = container2.scrollHeight;
|
||||||
|
|
||||||
|
resetFishingBtn();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 重置钓鱼按钮状态(停止自动循环后调用)
|
||||||
*/
|
*/
|
||||||
function resetFishingBtn() {
|
function resetFishingBtn() {
|
||||||
|
_autoFishing = false;
|
||||||
|
_hideAutoFishStopBtn();
|
||||||
|
if (_autoFishCdTimer) {
|
||||||
|
clearTimeout(_autoFishCdTimer);
|
||||||
|
_autoFishCdTimer = null;
|
||||||
|
}
|
||||||
|
if (_autoFishCdCountdown) {
|
||||||
|
clearInterval(_autoFishCdCountdown);
|
||||||
|
_autoFishCdCountdown = null;
|
||||||
|
}
|
||||||
const btn = document.getElementById('fishing-btn');
|
const btn = document.getElementById('fishing-btn');
|
||||||
btn.textContent = '🎣 钓鱼';
|
btn.textContent = '🎣 钓鱼';
|
||||||
btn.disabled = false;
|
btn.disabled = false;
|
||||||
|
|||||||
Reference in New Issue
Block a user