Skip to content

Commit a6b8264

Browse files
authored
關於Twitch忠誠點數/小奇點的功能支持
1 parent 55ea938 commit a6b8264

6 files changed

Lines changed: 71 additions & 10 deletions

File tree

[BP]iiTNTC/scripts/core/EventActionForm.js

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -105,11 +105,34 @@ export class EventActionForm {
105105
if (action.actionType !== 'Clear Blocks') {
106106
form.button('Edit', () => this.showActionTypeForm(action, true, index));
107107
}
108+
109+
if (action.type) {
110+
form.button('RewardType', () => this.TypeSet(action));
111+
}
108112
form.button('Delete', () => this.showClearActionFromEvent(action, index));
109113
form.show();
110114
}
111115

112-
116+
TypeSet(action){
117+
let typeActions=[
118+
{ id: 1, type: "Bits",description:"依據觀眾花費的小奇點" },
119+
{ id: 2, type: "Reward",description:"依據頻道忠誠點數兌換" }
120+
]
121+
122+
const defaultIndex = typeActions.findIndex(t => t.type === action.type) || 0;
123+
124+
new ModalForm(this._player, "Twitch Reward Type")
125+
.dropdown("Type:", typeActions.map(action => `${action.type} - ${action.description}`), defaultIndex)
126+
.submitButton('Apply')
127+
.show(response => {
128+
const selectedIndex = response[0];
129+
const selectedType = typeActions[selectedIndex].type;
130+
// ✅ 更新 action.type
131+
action.type = selectedType;
132+
133+
console.log(`更新後的 type: ${action.type}`);
134+
});
135+
}
113136
RangeSet(action,isEdit,index){
114137
if (action.actionType !== 'RangeSet')
115138
return;

[BP]iiTNTC/scripts/game/actions/RewardAction.js

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,9 @@ export class REActionForm extends EventActionFormBase {
88
show() {
99
const chatEvents = this._eventActionForm.actionManager.getAllEvents();
1010
const form = new ActionForm(this._player, 'Reward Actions');
11+
1112
chatEvents.forEach((actions, eventKey) => {
12-
form.button(`§2§kii§r§e${eventKey} §8Chat§2§kii§r\n§2Actions: [${actions.length}]`, () => {
13+
form.button(`§2§kii§r§e${eventKey}:${actions[0].type}§2§kii§r\n§2Actions: [${actions.length}]`, () => {
1314
this.showRActionsForm(eventKey, `Actions for ${eventKey} Reward`, actions);
1415
});
1516
});
@@ -20,20 +21,31 @@ export class REActionForm extends EventActionFormBase {
2021
showCreateNewActionForm() {
2122
new ModalForm(this._player, 'Create New Reward Action')
2223
.textField('number', 'Enter the number for action', "50", "100")
24+
.dropdown('Type', ['Bits', 'Reward'], 0)
2325
.submitButton('Continue')
2426
.show(response => {
2527
const chat = response[0];
28+
const typeIndex = response[1]; // 選單的索引
29+
const types = ['Bits', 'Reward'];
30+
const chat2 = types[typeIndex]; // 真正的 type 值
31+
2632
this._eventActionForm.showCreateActionForm({
2733
eventKey: chat,
28-
chat
34+
type:chat2
2935
}, this._actionOptions);
3036
});
3137
}
3238
showRActionsForm(eventKey, formTitle, chatActions) {
3339
const form = new ActionForm(this._player, formTitle);
34-
form.body(`§2§kii§r§fTotal Actions: §d${chatActions.length}§2§kii§r\nUse Point: §e${eventKey}§f.`);
40+
console.log(JSON.stringify(chatActions,null,4))
41+
42+
let typelist=chatActions.map(action => action.type)
43+
form.body(`§2§kii§r§fTotal Actions: §d${chatActions.length}§2§kii§r\nUse Point: §e${eventKey}§f\nType:${typelist}`);
3544
chatActions.forEach((action, index) => {
3645
let text = '';
46+
if (action.type){
47+
text += ` - ${action.type}`
48+
}
3749
if (action.actionType === 'Summon') {
3850
text += ` - ${action.summonOptions.entityName.toUpperCase()} x${action.summonOptions?.amount}`;
3951
}

[BP]iiTNTC/scripts/game/events/tiktok/giftEvents.js

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,9 +67,16 @@ export default [
6767
},
6868
{
6969
"reward":100,
70+
"type":"Bits",
7071
"actionType": "Screen Title",
7172
"screenTitle": "Title"
7273
},
74+
{
75+
"reward":1002,
76+
"type":"Reward",
77+
"actionType": "Screen Title",
78+
"screenTitle": "333"
79+
},
7380
{
7481
"text":"22",
7582
"actionType":"Clear Blocks"

[BP]iiTNTC/scripts/game/events/tiktok/keyExtra.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,8 @@ export const keyExtractors = {
8181
return {
8282
key:action.reward,
8383
eventKey: action.reward,
84-
reward:action.reward
84+
reward:action.reward,
85+
type:action.type
8586
};
8687
}
8788
return null;

[BP]iiTNTC/scripts/game/events/tiktok/onAction.js

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,9 @@ export const ActionTypeDisplay = {
2121
"Screen Subtitle": "顯示副標題",
2222
"Fill":"填滿",
2323
"Clear Blocks":"清除方塊",
24-
"Command":"運行特別指令"
24+
"Command":"運行特別指令",
25+
"Bits":"依據Twitch小奇點",
26+
"Reward":"依據Twitch忠誠點數兌換"
2527
};
2628

2729
export function onAction(game, message={}) {
@@ -329,6 +331,13 @@ export function onAction(game, message={}) {
329331
let DisplayAction="運行類型:"+ActionTypeDisplay[action.actionType] || `?? ${action.actionType}`
330332
if(debug)game.player.sendMessage(DisplayAction);
331333
game.player.runCommand(`scoreboard players add "${DisplayAction}" display ${ActionSort} `)
334+
335+
ActionSort--
336+
337+
DisplayAction=ActionTypeDisplay[action.type] || `?? ${action.type}`
338+
if(debug)game.player.sendMessage(DisplayAction);
339+
game.player.runCommand(`scoreboard players add "${DisplayAction}" display ${ActionSort} `)
340+
332341
});
333342
ActionSort--
334343
}

[BP]iiTNTC/scripts/game/events/tiktok/onReward.js

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,21 @@ import { executeAction } from "../../actions/executeAction";
55
* @param {string} message the message sent by TikTokLiveMCBE
66
*/
77
export function onReward(game, message) {
8-
const { uniqueId, nickname, comment,rewardCost } = JSON.parse(message);
8+
const { uniqueId, nickname, comment,rewardCost,type } = JSON.parse(message);
99
const chatActions = game.rewardActionManager.getAllEvents();
10-
chatActions.forEach((actions, eventKey) => {
11-
if (eventKey === rewardCost) {
12-
actions.forEach(action => executeAction(game, action));
10+
11+
chatActions.forEach((actions, eventKey) => {
12+
//console.log(JSON.stringify(actions,null,4))
13+
console.log(JSON.stringify(eventKey,null,4))
14+
15+
if (eventKey === rewardCost) {
16+
actions.forEach(action => {
17+
if (action.type == type) {
18+
executeAction(game, action)
19+
}
20+
});
1321
}
22+
1423
});
1524
game.player.sendMessage(`§7[§aReward§7]: §f${nickname} §7: §f${comment}`);
1625
}

0 commit comments

Comments
 (0)