market search

This commit is contained in:
2026-01-20 18:38:37 +08:00
parent 41cd99fa36
commit af565b166f
4 changed files with 342 additions and 96 deletions
+1 -1
View File
@@ -1 +1 @@
g_game.bcm_tool.queryPlayerInfo(g_game.bcm_tool.getPlayerIds()); g_game.bcm_tool.ExportPlayerInfo(g_game.bcm_tool.EetPlayerIds());
+121 -20
View File
@@ -1,10 +1,17 @@
"use strict"; "use strict";
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
return new (P || (P = Promise))(function (resolve, reject) {
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
step((generator = generator.apply(thisArg, _arguments || [])).next());
});
};
class BcmTool { class BcmTool {
constructor() { constructor() {
this.mgrTeamInfo = g_game.mgr.mgr_team_player_team_info; this.attributes = new Map([
} ['年龄', -100],
queryPlayerInfo(playersToQuery) {
const attributes = [
['速度', 1], ['速度', 1],
['力量', 2], ['力量', 2],
['内攻', 3], ['内攻', 3],
@@ -49,47 +56,141 @@ class BcmTool {
['进攻技能', 44], ['进攻技能', 44],
['防守技能', 48], ['防守技能', 48],
['身体素质', 50], ['身体素质', 50],
]; ]);
var form = new Form(); this.mgrTeamInfo = g_game.mgr.mgr_team_player_team_info;
for (let i = 0; i != attributes.length; ++i) { this.mgrMarket = g_game.mgr.mgr_market;
form.SetCell(i + 1, 0, attributes[i][0]); }
ExportPlayerInfo(playersToQuery) {
const lstAttributes = [...this.attributes];
const form = new Form();
for (let i = 0; i != lstAttributes.length; ++i) {
form.SetCell(i + 1, 0, lstAttributes[i][0]);
} }
for (let i = 0; i != playersToQuery.length; ++i) { for (let i = 0; i != playersToQuery.length; ++i) {
const playerId = playersToQuery[i]; const playerId = playersToQuery[i];
if (!this.checkInfo(playerId)) { if (!this.CheckInfo(playerId)) {
console.log('找不到id', playerId); console.log('找不到id', playerId);
continue; continue;
} }
form.SetCell(0, i + 1, this.queryName(playerId)); form.SetCell(0, i + 1, this.QueryName(playerId));
for (let j = 0; j != attributes.length; ++j) { for (let j = 0; j != lstAttributes.length; ++j) {
const record = this.queryInfo(playerId, attributes[j][1]); const record = this.QueryInfo(playerId, lstAttributes[j][1]);
form.SetCell(j + 1, i + 1, record.toString()); form.SetCell(j + 1, i + 1, record.toString());
} }
} }
console.log(form); console.log(form);
g_game.tools.CopyStrToClipboard(form.ToString()); g_game.tools.CopyStrToClipboard(form.ToString());
} }
checkInfo(playerId) { BulkSearchMarket(searchStr, maxIterate = 100) {
searchStr = searchStr.replace(/ /g, '');
const strs = searchStr.split('&&');
const operators = ['>', '<', '=='];
const handlers = [
(id, attri, value) => {
return this.QueryInfo(id, attri) > value;
},
(id, attri, value) => {
return this.QueryInfo(id, attri) < value;
},
(id, attri, value) => {
return Math.floor(this.QueryInfo(id, attri)) == value;
},
(id, attri, value) => {
return this.QueryInfo(id, attri) >= value;
},
(id, attri, value) => {
return this.QueryInfo(id, attri) <= value;
},
];
const conditions = [];
const requireAttributes = [];
const requireSearch = [];
const requireValues = [];
for (let i = 0; i != strs.length; ++i) {
const str = strs[i];
const operator = operators.find(e => str.search(e) != -1);
if (operator == null) {
console.log('条件解析失败', str);
continue;
}
const handler = handlers[operators.indexOf(operator)];
const requires = str.split(operator);
const attribute = this.attributes.get(requires[0]);
const value = Number(requires[1]);
if (attribute == null || handler == null) {
console.log('条件解析失败', str);
continue;
}
conditions.push(handler);
requireAttributes.push(attribute);
requireValues.push(value);
requireSearch.push(requires[0]);
}
this.mgrMarket.SendSynOpenMarketInfoByFilter(() => __awaiter(this, void 0, void 0, function* () {
var results = [];
const ids = Object.keys(this.mgrMarket._map_player_infos);
for (const id of ids) {
if (maxIterate < 0) {
break;
}
const info = this.mgrMarket._map_player_infos[id];
yield this.RefreshPlayerInTransaction(info.teamId, info.playerId);
if (conditions.every((e, i) => e(info.playerId, requireAttributes[i], requireValues[i]))) {
results.push(info);
}
maxIterate -= 1;
}
const displays = new Set(requireAttributes);
for (const result of results) {
const displayStr = [...displays].map(e => {
const idx = requireAttributes.indexOf(e);
const search = requireSearch[idx];
const value = result.GetSingleAttribute(e, true);
return `${search}:${value}`;
});
console.log(result.playerName, ...displayStr);
}
}));
}
RefreshPlayerInTransaction(teamId, playerId) {
return new Promise(resolve => {
this.mgrTeamInfo.OpenPlayerDetailInTransaction(teamId, playerId, e => {
resolve();
return true;
}, e => {
resolve();
});
});
}
CheckInfo(playerId) {
const data = this.mgrTeamInfo.GetPlayerData(playerId); const data = this.mgrTeamInfo.GetPlayerData(playerId);
return data != null; return data != null;
} }
queryName(playerId) { QueryName(playerId) {
const data = this.mgrTeamInfo.GetPlayerData(playerId); const data = this.mgrTeamInfo.GetPlayerData(playerId);
return data.playerName; return data.playerName;
} }
queryInfo(playerId, attri) { QueryInfo(playerId, attri) {
const data = this.mgrTeamInfo.GetPlayerData(playerId); const data = this.mgrTeamInfo.GetPlayerData(playerId);
return data.GetSingleAttribute(attri).toFixed(2); if (attri == -100) {
return data.playerAge;
}
return data.GetSingleAttribute(attri);
} }
getPlayerIds() { GetPlayerIds() {
return Object.keys(this.mgrTeamInfo._map_player_detail); return Object.keys(this.mgrTeamInfo._map_player_detail);
} }
listPlayers() { ListPlayers() {
const ids = Object.keys(this.mgrTeamInfo._map_player_detail); const ids = Object.keys(this.mgrTeamInfo._map_player_detail);
for (const id of ids) { for (const id of ids) {
console.log(this.queryName(id), id); console.log(this.QueryName(id), id);
} }
} }
ListMarketPlayers() {
this.mgrMarket.SendSynOpenMarketInfoByFilter(() => {
console.log(this.mgrMarket._map_player_infos);
});
}
} }
class Logger { class Logger {
constructor() { constructor() {
@@ -122,7 +223,7 @@ class Form {
} }
ToString() { ToString() {
var _a; var _a;
var logger = new Logger(); const logger = new Logger();
for (let col = 0; col != this.records.length; ++col) { for (let col = 0; col != this.records.length; ++col) {
for (let row = 0; row != this.records[col].length; ++row) { for (let row = 0; row != this.records[col].length; ++row) {
logger.Info((_a = this.records[col][row]) !== null && _a !== void 0 ? _a : ''); logger.Info((_a = this.records[col][row]) !== null && _a !== void 0 ? _a : '');
+182 -63
View File
@@ -1,74 +1,76 @@
class BcmTool class BcmTool
{ {
private attributes = new Map<string, number>([
['年龄', -100],
['速度', 1],
['力量', 2],
['内攻', 3],
['中投', 4],
['三分', 5],
['三分急停跳投倾向', 6],
['内线防守能力', 7],
['外线防守能力', 8],
['突破能力', 9],
['上篮能力', 10],
['控球能力', 11],
['传球能力', 12],
['传球视野', 13],
['干扰投篮', 14],
['篮板能力', 15],
['*出手时间', 16],
['*进攻IQ', 17],
['*防守IQ', 18],
['体能', 19],
['卡位能力', 20],
['罚球能力', 21],
['抢断能力', 22],
['盖帽能力', 23],
['*进攻犯规', 24],
['*防守犯规', 25],
['扣篮能力', 26],
['勾手倾向', 27],
['*后仰倾向', 28],
['打板倾向', 29],
['*反应时间', 30],
['拉开空间', 31],
['补防、协防', 32],
['*造进攻犯规', 33],
['快下', 34],
['无球跑动', 35],
['挡拆', 36],
['*造防守犯规', 37],
['无球掩护', 38],
['进攻篮板', 39],
['*假动作', 40],
['攻转守', 41],
['进攻技能', 44],
['防守技能', 48],
['身体素质', 50],
]);
private mgrTeamInfo = g_game.mgr.mgr_team_player_team_info; private mgrTeamInfo = g_game.mgr.mgr_team_player_team_info;
private mgrMarket = g_game.mgr.mgr_market;
public queryPlayerInfo(playersToQuery: string[]) public ExportPlayerInfo(playersToQuery: string[])
{ {
const attributes = [ const lstAttributes = [...this.attributes];
['速度', 1], const form = new Form();
['力量', 2], for (let i = 0; i != lstAttributes.length; ++i)
['内攻', 3],
['中投', 4],
['三分', 5],
['三分急停跳投倾向', 6],
['内线防守能力', 7],
['外线防守能力', 8],
['突破能力', 9],
['上篮能力', 10],
['控球能力', 11],
['传球能力', 12],
['传球视野', 13],
['干扰投篮', 14],
['篮板能力', 15],
['*出手时间', 16],
['*进攻IQ', 17],
['*防守IQ', 18],
['体能', 19],
['卡位能力', 20],
['罚球能力', 21],
['抢断能力', 22],
['盖帽能力', 23],
['*进攻犯规', 24],
['*防守犯规', 25],
['扣篮能力', 26],
['勾手倾向', 27],
['*后仰倾向', 28],
['打板倾向', 29],
['*反应时间', 30],
['拉开空间', 31],
['补防、协防', 32],
['*造进攻犯规', 33],
['快下', 34],
['无球跑动', 35],
['挡拆', 36],
['*造防守犯规', 37],
['无球掩护', 38],
['进攻篮板', 39],
['*假动作', 40],
['攻转守', 41],
['进攻技能', 44],
['防守技能', 48],
['身体素质', 50],
];
var form = new Form();
for (let i = 0; i != attributes.length; ++i)
{ {
form.SetCell(i + 1, 0, attributes[i][0] as string); form.SetCell(i + 1, 0, lstAttributes[i][0] as string);
} }
for (let i = 0; i != playersToQuery.length; ++i) for (let i = 0; i != playersToQuery.length; ++i)
{ {
const playerId = playersToQuery[i]; const playerId = playersToQuery[i];
if (!this.checkInfo(playerId)) if (!this.CheckInfo(playerId))
{ {
console.log('找不到id', playerId); console.log('找不到id', playerId);
continue; continue;
} }
form.SetCell(0, i + 1, this.queryName(playerId)); form.SetCell(0, i + 1, this.QueryName(playerId));
for (let j = 0; j != attributes.length; ++j) for (let j = 0; j != lstAttributes.length; ++j)
{ {
const record = this.queryInfo(playerId, attributes[j][1] as number); const record = this.QueryInfo(playerId, lstAttributes[j][1] as number);
form.SetCell(j + 1, i + 1, record.toString()); form.SetCell(j + 1, i + 1, record.toString());
} }
} }
@@ -76,38 +78,155 @@ class BcmTool
g_game.tools.CopyStrToClipboard(form.ToString()); g_game.tools.CopyStrToClipboard(form.ToString());
} }
public checkInfo(playerId: string) public BulkSearchMarket(searchStr: string, maxIterate = 100)
{
searchStr = searchStr.replace(/ /g, '');
const strs = searchStr.split('&&');
const operators = ['>', '<', '=='];
const handlers: ((id: string, attri: number, value: number) => boolean)[] = [
(id: string, attri: number, value: number) =>
{
return this.QueryInfo(id, attri) > value;
},
(id: string, attri: number, value: number) =>
{
return this.QueryInfo(id, attri) < value;
},
(id: string, attri: number, value: number) =>
{
return Math.floor(this.QueryInfo(id, attri)) == value;
},
(id: string, attri: number, value: number) =>
{
return this.QueryInfo(id, attri) >= value;
},
(id: string, attri: number, value: number) =>
{
return this.QueryInfo(id, attri) <= value;
},
];
const conditions: ((id: string, attri: number, value: number) => boolean)[] = [];
const requireAttributes: number[] = [];
const requireSearch: string[] = [];
const requireValues: number[] = [];
for (let i = 0; i != strs.length; ++i)
{
const str = strs[i];
const operator = operators.find(e => str.search(e) != -1);
if (operator == null)
{
console.log('条件解析失败', str);
continue;
}
const handler = handlers[operators.indexOf(operator)];
const requires = str.split(operator);
const attribute = this.attributes.get(requires[0]);
const value = Number(requires[1]);
if (attribute == null || handler == null)
{
console.log('条件解析失败', str);
continue;
}
conditions.push(handler);
requireAttributes.push(attribute);
requireValues.push(value);
requireSearch.push(requires[0]);
}
this.mgrMarket.SendSynOpenMarketInfoByFilter(async () =>
{
var results: CPlayerData[] = [];
const ids = Object.keys(this.mgrMarket._map_player_infos);
for (const id of ids)
{
if (maxIterate < 0)
{
break;
}
const info = this.mgrMarket._map_player_infos[id];
await this.RefreshPlayerInTransaction(info.teamId, info.playerId);
if (conditions.every((e, i) => e(info.playerId, requireAttributes[i], requireValues[i])))
{
results.push(info);
}
maxIterate -= 1;
}
const displays = new Set<number>(requireAttributes);
for (const result of results)
{
const displayStr = [...displays].map(e =>
{
const idx = requireAttributes.indexOf(e);
const search = requireSearch[idx];
const value = result.GetSingleAttribute(e, true);
return `${search}:${value}`;
});
console.log(result.playerName, ...displayStr);
}
});
}
private RefreshPlayerInTransaction(teamId: string, playerId: string)
{
return new Promise<void>(resolve =>
{
this.mgrTeamInfo.OpenPlayerDetailInTransaction(teamId, playerId, e =>
{
resolve()
return true;
}, e =>
{
resolve();
});
});
}
public CheckInfo(playerId: string)
{ {
const data = this.mgrTeamInfo.GetPlayerData(playerId); const data = this.mgrTeamInfo.GetPlayerData(playerId);
return data != null; return data != null;
} }
public queryName(playerId: string) public QueryName(playerId: string)
{ {
const data = this.mgrTeamInfo.GetPlayerData(playerId); const data = this.mgrTeamInfo.GetPlayerData(playerId);
return data.playerName; return data.playerName;
} }
public queryInfo(playerId: string, attri: number) public QueryInfo(playerId: string, attri: number)
{ {
const data = this.mgrTeamInfo.GetPlayerData(playerId); const data = this.mgrTeamInfo.GetPlayerData(playerId);
return data.GetSingleAttribute(attri).toFixed(2); if (attri == -100)
{
return data.playerAge;
}
return data.GetSingleAttribute(attri);
} }
public getPlayerIds() public GetPlayerIds()
{ {
return Object.keys(this.mgrTeamInfo._map_player_detail); return Object.keys(this.mgrTeamInfo._map_player_detail);
} }
public listPlayers() public ListPlayers()
{ {
const ids = Object.keys(this.mgrTeamInfo._map_player_detail); const ids = Object.keys(this.mgrTeamInfo._map_player_detail);
for (const id of ids) for (const id of ids)
{ {
console.log(this.queryName(id), id); console.log(this.QueryName(id), id);
} }
} }
public ListMarketPlayers()
{
this.mgrMarket.SendSynOpenMarketInfoByFilter(() =>
{
console.log(this.mgrMarket._map_player_infos);
});
}
} }
class Logger class Logger
@@ -153,7 +272,7 @@ class Form
public ToString() public ToString()
{ {
var logger = new Logger(); const logger = new Logger();
for (let col = 0; col != this.records.length; ++col) for (let col = 0; col != this.records.length; ++col)
{ {
for (let row = 0; row != this.records[col].length; ++row) for (let row = 0; row != this.records[col].length; ++row)
+38 -12
View File
@@ -2,29 +2,55 @@ export { };
declare global declare global
{ {
interface BGameMgr { interface BGameMgr
public mgr_team_player_team_info: MgrTeamPlayerInfo; {
public mgr_team_player_team_info: MgrTeamPlayerInfo;
public mgr_market: MgrMarket;
} }
interface BGameTools { interface BGameTools
public CopyStrToClipboard(str:string, success?:Function); {
public CopyStrToClipboard(str: string, success?: Function);
} }
interface MgrTeamPlayerInfo { interface MgrTeamPlayerInfo
public _map_player_detail:{ [key:string]:CPlayerData } {
public GetPlayerData(player_id:string):CPlayerData; public _map_player_detail: { [key: string]: CPlayerData }
public UpdateFromMessage(msg:BMProto.S2CGetPlayerDetailResp):void; public GetPlayerData(player_id: string): CPlayerData;
public UpdateFromMessage(msg: BMProto.S2CGetPlayerDetailResp): void;
public OpenPlayerDetailInTransaction(team_id: string, player_id: string, filter?: (data: CPlayerData) => boolean, error_callback?: (code: number, msg: BMProto.S2CGetPlayerDetailResp, msgid: EnumCommandId) => void): void;
} }
interface CPlayerData { interface MgrMarket
{
public _map_player_infos: { [key: string]: CMarketPlayerInfo };
public SendSynOpenMarketInfoByFilter(callback?: () => void);
}
interface BNetManager
{
public SendHttpEx<T extends BMProto.S2CMessage>(cmd: EnumCommandId, data: BMProto.C2SMessage, respClass: new () => T, success: (msg: T) => void, fail: (code: number, msg: T, msgid: EnumCommandId) => void = null, callback: () => void = null)
}
interface CPlayerData
{
public playerId: string;
public playerName: string; public playerName: string;
public playerAge: number;
public teamName: string;
public teamId: string;
public GetSingleAttribute(PlayerAttribute: number, is_floor?: boolean): number;
}
interface CMarketPlayerInfo extends CPlayerData
{
public GetSingleAttribute(PlayerAttribute:number,is_floor?:boolean):number;
} }
var g_game: { var g_game: {
mgr: BGameMgr;
bcm_tool: BcmTool; bcm_tool: BcmTool;
tools: BGameTools; mgr: BGameMgr;
tools: BGameTools;
net: BNetManager;
}; };
} }