微件

微件:配队模拟器

来自卡厄思梦境WIKI

律Rhyme留言 | 贡献2025年10月18日 (六) 20:03的版本 (创建页面,内容为“<script> (function() { 'use strict'; // ========== 工具函数 ========== function show(el) { if (el) el.style.display = 'block'; } function hide(el) { if (el) el.style.display = 'none'; } // ========== 战斗员选择 ========== const characterBox = document.getElementById('character-box'); const selectedCharacter = document.getElementById('selected-character'); characterBox.addEventListener('click', function(e) { e.…”)
(差异) ←上一版本 | 最后版本 (差异) | 下一版本→ (差异)

<script> (function() {

   'use strict';
   // ========== 工具函数 ==========
   function show(el) { if (el) el.style.display = 'block'; }
   function hide(el) { if (el) el.style.display = 'none'; }
   // ========== 战斗员选择 ==========
   const characterBox = document.getElementById('character-box');
   const selectedCharacter = document.getElementById('selected-character');
   characterBox.addEventListener('click', function(e) {
       e.stopPropagation();
       // 创建选择层
       const overlay = document.createElement('div');
       overlay.style.cssText = `
           position: fixed; top: 0; left: 0; width: 100%; height: 100%; background: rgba(0,0,0,0.8);
           z-index: 10000; display: flex; align-items: center; justify-content: center; overflow-y: auto;
       `;
       overlay.innerHTML = `
×

选择战斗员

       `;
       document.body.appendChild(overlay);
       // 关闭按钮
       overlay.querySelector('div').firstChild.onclick = function() {
           document.body.removeChild(overlay);
       };
       // 获取战斗员列表(使用你提供的SMW查询)
       fetch(mw.util.wikiScript('api'), {
           method: 'POST',
           headers: { 'Content-Type': 'application/x-www-form-urlencoded' },
           body: new URLSearchParams({
               action: 'parse',
               format: 'json',

text: '

凯隆
小春
雨果
蕾欧娜
维若妮卡
梅铃
奥尔莱亚
麦格纳
卡莉佩
路克
蕾伊
欧文
凯西乌斯
百丽儿
米卡
玛丽贝尔
卢卡斯
艾美
德蕾莎
席琳娜
妮雅

'

           })
       })
       .then(r => r.json())
       .then(data => {
           const listContainer = overlay.querySelector('#character-list');
           listContainer.innerHTML = data.parse.text['*'];
           // 为每个角色绑定点击事件
           const characterItems = listContainer.querySelectorAll('.rarity-1, .rarity-2, .rarity-3, .rarity-4, .rarity-5');
           characterItems.forEach(item => {
               item.addEventListener('click', function(e) {
                   e.stopPropagation();
                   const name = this.previousElementSibling.textContent.trim(); // 名称在底部黑条内
                   const imgSrc = this.parentElement.querySelector('img').src;
                   // 更新显示
                   selectedCharacter.innerHTML = `<img src="${imgSrc}" style="width:100%; height:100%; object-fit: cover;">`;
                   show(selectedCharacter);
                   hide(characterBox.querySelector('span'));
                   document.body.removeChild(overlay);
               });
           });
       });
   });
   // ========== 伙伴选择 ==========
   const partnerBox = document.getElementById('partner-box');
   const selectedPartner = document.getElementById('selected-partner');
   partnerBox.addEventListener('click', function(e) {
       e.stopPropagation();
       const overlay = document.createElement('div');
       overlay.style.cssText = `
           position: fixed; top: 0; left: 0; width: 100%; height: 100%; background: rgba(0,0,0,0.8);
           z-index: 10000; display: flex; align-items: center; justify-content: center; overflow-y: auto;
       `;
       overlay.innerHTML = `
×

选择伙伴

       `;
       document.body.appendChild(overlay);
       overlay.querySelector('div').firstChild.onclick = function() {
           document.body.removeChild(overlay);
       };
       fetch(mw.util.wikiScript('api'), {
           method: 'POST',
           headers: { 'Content-Type': 'application/x-www-form-urlencoded' },
           body: new URLSearchParams({
               action: 'parse',
               format: 'json',

text: '

'

           })
       })
       .then(r => r.json())
       .then(data => {
           const listContainer = overlay.querySelector('#partner-list');
           listContainer.innerHTML = data.parse.text['*'];
           const partnerItems = listContainer.querySelectorAll('.rarity-1, .rarity-2, .rarity-3, .rarity-4, .rarity-5');
           partnerItems.forEach(item => {
               item.addEventListener('click', function(e) {
                   e.stopPropagation();
                   const name = this.previousElementSibling.textContent.trim();
                   // 注意:伙伴使用 face_character_wide_{id}.png
                   const id = this.parentElement.querySelector('img').alt.match(/portrait_character_crop_half_(\d+)/)?.[1] || '0000';
                   const imgSrc = mw.util.getUrl(`File:face_character_wide_${id}.png`, { action: 'view' }); // 构建图片URL
                   selectedPartner.innerHTML = `<img src="${imgSrc}" style="width:100%; height:100%; object-fit: cover;">`;
                   show(selectedPartner);
                   hide(partnerBox.querySelector('span'));
                   document.body.removeChild(overlay);
               });
           });
       });
   });
   // ========== 卡牌选择 ==========
   const addCardButton = document.getElementById('add-card-button');
   const cardDeckBox = document.getElementById('card-deck-box');
   const cardSelectionModal = document.getElementById('card-selection-modal');
   const cardListContainer = document.getElementById('card-list');
   addCardButton.addEventListener('click', function() {
       show(cardSelectionModal);
       loadCharacterCards(); // 加载当前所选角色的卡牌(需要你提供角色→模块映射表,这里先模拟)
   });
   function loadCharacterCards() {
       // 示例:假设选择的角色是"艾莉丝",对应 Module:卡牌/艾莉丝
       // 实际应从 selectedCharacter 获取角色名,然后查映射 → 这里简化处理
       const moduleName = "示例角色"; // 替换为实际逻辑
       // 假设我们有一个 API 或模板能列出某角色的所有卡牌
       // 这里我们伪造一些卡牌供演示,你应该替换为真实的 SMW 查询或 Lua 输出
       const sampleCards = [
           { module: "示例角色", name: "起始卡牌_1" },
           { module: "示例角色", name: "起始卡牌_2" },
           { module: "示例角色", name: "独特卡牌_1" }
       ];
       cardListContainer.innerHTML = ; // 清空
       sampleCards.forEach(card => {
           const cardDiv = document.createElement('div');
           // 使用Module:卡牌渲染单张卡牌
           fetch(mw.util.wikiScript('api'), {
               method: 'POST',
               headers: { 'Content-Type': 'application/x-www-form-urlencoded' },
               body: new URLSearchParams({
                   action: 'parse',
                   format: 'json',
                   text: `错误: 找不到模块 "Module:卡牌/${card.module}"}`
               })
           })
           .then(r => r.json())
           .then(data => {
               cardDiv.innerHTML = data.parse.text['*'];
               cardListContainer.appendChild(cardDiv);
               // 绑定点击加入卡组
               const smallCard = cardDiv.querySelector('.card-small-wrapper');
               if (smallCard) {
                   smallCard.addEventListener('click', function(e) {
                       e.stopPropagation();
                       const clone = this.cloneNode(true);
                       clone.style.width = '180px';
                       clone.style.height = 'auto';
                       cardDeckBox.appendChild(clone);
                       cardDeckBox.querySelector('div[style*="margin-top: 100px"]')?.remove(); // 移除提示占位符
                   });
               }
           });
       });
   }
   // ========== 装备选择 ==========
   const equipmentSlots = document.querySelectorAll('.equipment-slot');
   const equipmentModal = document.getElementById('equipment-modal');
   const equipmentListContainer = document.getElementById('equipment-list');
   const equipmentTitle = document.getElementById('equipment-title');
   equipmentSlots.forEach(slot => {
       slot.addEventListener('click', function() {
           const type = this.getAttribute('data-type');
           equipmentTitle.textContent = `选择${type}`;
           show(equipmentModal);
           // 使用 Module:装备 生成列表
           fetch(mw.util.wikiScript('api'), {
               method: 'POST',
               headers: { 'Content-Type': 'application/x-www-form-urlencoded' },
               body: new URLSearchParams({
                   action: 'parse',
                   format: 'json',

text: '

'

               })
           })
           .then(r => r.json())
           .then(data => {
               equipmentListContainer.innerHTML = data.parse.text['*'];
               // 筛选类型 & 绑定点击
               const allCards = equipmentListContainer.querySelectorAll('.equipment-wrapper');
               allCards.forEach(card => {
                   const cardType = card.getAttribute('data-param3');
                   if (cardType !== type) {
                       hide(card);
                   } else {
                       show(card);
                       const clickableCard = card.querySelector('.equipment-card');
                       clickableCard.addEventListener('click', function(e) {
                           e.stopPropagation();
                           // 获取装备名
                           const equipName = clickableCard.getAttribute('data-equipment');
                           // 渲染单张装备卡片到槽位
                           renderEquipmentToSlot(slot, equipName);
                           hide(equipmentModal);
                       });
                   }
               });
           });
       });
   });
   function renderEquipmentToSlot(slot, equipName) {
       const outputDiv = slot.querySelector('.selected-equipment');
       fetch(mw.util.wikiScript('api'), {
           method: 'POST',
           headers: { 'Content-Type': 'application/x-www-form-urlencoded' },
           body: new URLSearchParams({
               action: 'parse',
               format: 'json',
               text: `装备不存在: ${equipName}` // 默认5星
           })
       })
       .then(r => r.json())
       .then(data => {
           outputDiv.innerHTML = data.parse.text['*'];
           show(outputDiv);
           hide(slot.querySelector('span'));
       });
   }
   // ESC关闭模态框
   document.addEventListener('keydown', function(e) {
       if (e.key === 'Escape') {
           hide(cardSelectionModal);
           hide(equipmentModal);
           document.querySelectorAll('.modal').forEach(modal => hide(modal));
       }
   });

})(); </script>