import axios from 'axios' import { Config } from '../cfg/Config' import { debugRoom, error } from './Debug' let config: Config = require('../../config/config.json') /** * 获取卡组详情 * @param {string} accountid * @param {number} heroid * @param {string} cardgroup * @return {Promise>} */ export function getCardGroup(accountid: string, heroid: number, cardgroup: string) { return axios.get(`${ config.info_svr }/${ accountid }/group_info/${ heroid }/${ cardgroup }`) .then(function (response) { let res = response.data if (res.errcode) { throw new Error(res.errmsg) } else { return res.data } }) } /** * 解锁英雄 * @param {string} accountid * @param {number | string} heroid * @return {Promise>} */ export function requestUnlockHero(accountid: string, heroid: number | string) { let data = { 'type': 0 } return axios.post(`${ config.info_svr }/${ accountid }/hero/unlock/${ heroid }`, data) } /** * 上报游戏结果 * @param data */ export async function reportGameResult(data: any) { let dataStr = JSON.stringify(data) let reqConfig = { method: 'post', url: `${ config.info_svr }/record/save`, headers: { 'Content-Type': 'application/json' }, data: dataStr } // @ts-ignore return axios(reqConfig) } /** * 使用物品 * @param {string} accountid * @param {number} itemid * @param {number} count */ export async function useItem(accountid: string, itemid: number, count: number) { const data = { itemid, count } let dataStr = JSON.stringify(data) let reqConfig = { method: 'post', url: `${ config.info_svr }/${ accountid }/useitem`, headers: { 'Content-Type': 'application/json' }, data: dataStr } // @ts-ignore return axios(reqConfig) } /** * 检查匹配所需的资源是否足够 * @param {string} accountid * @param {string} matchid * @return {Promise} */ export async function checkMatchTicket(accountid: string, matchid: string) { const data = { matchid } const url = `${ config.info_svr }/${ accountid }/beginmatch` let reqConfig = { method: 'post', url, headers: { 'Content-Type': 'application/json' }, data: JSON.stringify(data) } // @ts-ignore return axios(reqConfig).then(function (response) { let res = response.data if (res.errcode) { throw new Error(res.errmsg) } else { return {} } }) } /** * 创建机器人 * @param data */ export function createRobot(data: any) { axios.get('http://127.0.0.1:2500/robot/create', { params: data }).then((res) => { debugRoom(`caeate robot result: `, res.data) }).catch((err) => { error(err) }) }