修改卡组生成逻辑

This commit is contained in:
zhl 2020-12-03 11:42:30 +08:00
parent 4b6e5bdcb2
commit 203182be0f
8 changed files with 58 additions and 22 deletions

View File

@ -3,6 +3,7 @@ import {Cfg} from "../../common/DataParser";
export class EffectCardCfg implements Cfg{
public id: number;
public maxCount: number;
public typeId: number;
public eff1Id: number;
public eff2Id: number;
@ -18,5 +19,6 @@ export class EffectCardCfg implements Cfg{
this.eff3Id = data.eff3_id;
this.eff4Id = data.eff4_id;
this.eff5Id = data.eff5_id;
this.maxCount = 20;
}
}

View File

@ -6,17 +6,17 @@ export class SystemCardCfg implements Cfg {
public count: number;
public point: number;
public weight: string;
public weightArr: [];
public weightArr: number[][];
public decode(data: any) {
this.id = data.id;
this.typeId = data.type_id;
this.point = data.point;
this.count = data.count;
this.weight = data.weight;
let arr = this.weight.split('|');
this.weightArr = [];
for (let str of arr) {
let subArr = str.split(':');
// @ts-ignore
this.weightArr.push([parseInt(subArr[0]), parseInt(subArr[1])]);
}
}

View File

@ -17,13 +17,13 @@ export var DataParser = (function (){
for (let i = 0, len = data.length; i < len; i++) {
let obj = data[i];
if (!obj[idkey]) {
console.error(`配置${key}的数据有误,唯一标识 ${idkey} 值为0或者没有${idkey}`);
console.warn(`配置${key}的数据有误,唯一标识 ${idkey} 值为0或者没有${idkey}`);
continue;
}
let to = new CfgCreator();
to.decode(obj);
if (dict.has(to.id)) {
console.error(`配置${key}的数据有误,唯一标识 id 有重复值:${to.id}`)
console.warn(`配置${key}的数据有误,唯一标识 id 有重复值:${to.id}`)
process.abort();
}
dict.set(to.id, to);

11
src/global.d.ts vendored
View File

@ -1,7 +1,5 @@
export {};
declare var console1: Console;
declare global {
namespace NodeJS {
interface Global {
@ -11,3 +9,12 @@ declare global {
}
}
}
declare module colyseus {
namespace Colyseus {
class Room {
testFun(param1: string): void;
}
}
}

View File

@ -12,6 +12,7 @@ import {EatCardCommand} from "./commands/EatCardCommand";
import {GiveUpCommand} from "./commands/GiveUpCommand";
import {BattleHandler} from "./logic/Handler/BattleHandler";
export class GeneralRoom extends Room {
dispatcher = new Dispatcher(this);
maxClients = 4;
@ -68,7 +69,7 @@ export class GeneralRoom extends Room {
onJoin (client: Client, options: any) {
this.dispatcher.dispatch(new OnJoinCommand(), {
client: client,
battle: this.battleMan,
battle: this.battleMan,
});
this.clientMap.set(client.sessionId, client);
}

View File

@ -45,6 +45,7 @@ export class EatCardCommand extends Command<CardGameState, { client: Client, car
player.cardSet.delete(id+'');
}
this.state.gameState = GameStateConst.STATE_PICK_PET;
//TODO:: 调用 onCardLinkReady()
// 成功后广播吃牌成功消息
this.room.broadcast('eat_card_s2c', {player: client.sessionId, errocode: 0, errmsg: ''})
}

View File

@ -2,12 +2,13 @@ import {Schema, type, filter} from "@colyseus/schema";
export class Card extends Schema {
constructor(number: number, type: number, id: number, effect: number) {
constructor(id: number, number: number, type: number, effect: number) {
super();
this.number = number;
this.type = type;
this.id = id;
this.played = false;
this.effect = effect;
}
/**

View File

@ -6,34 +6,58 @@ import {singleton} from "../common/Singleton";
import {GameEnv} from "../cfg/GameEnv";
import {BaseConst} from "../constants/BaseConst";
import {SystemCardCfg} from "../cfg/parsers/SystemCardCfg";
import {EffectCardCfg} from "../cfg/parsers/EffectCardCfg";
let gameUtil = {
// TODO: 根据配表生成牌组
initCardQue() {
let cards: Array<Card> = [];
let numCfgMap: Map<number, SystemCardCfg> = global.$cfg.get(BaseConst.SYSTEMCARD);
let effCfgMap = global.$cfg.get(BaseConst.EFFECTCARD);
let nums: Array<number> = [];
let types : Array<number> = [];
let effCfgMap: Map<number, EffectCardCfg> = global.$cfg.get(BaseConst.EFFECTCARD);
let countMap: Map<number, number> = new Map();
let localId = 1;
for (let [id, cfg] of numCfgMap) {
for (let i = 0; i < cfg.count; i++) {
nums.push(cfg.point);
if (cfg.typeId == 1) {
let effid = this.getRandomEffect(cfg.weightArr, effCfgMap, countMap);
let card = new Card(localId ++, cfg.point, cfg.typeId, effid);
cards.push(card);
} else {
let card = new Card(localId ++, cfg.point, cfg.typeId, 0);
cards.push(card);
}
}
}
arrUtil.randomSort(nums);
for (let i = 0; i < 8; i ++) {
for (let j = 0; j < 24; j ++) {
types.push(i);
}
}
arrUtil.randomSort(types);
for (let i = 0; i < nums.length; i++) {
cards.push(new Card(nums[i] + 1, types[i], i, i));
}
arrUtil.randomSort(cards);
return cards;
},
getRandomEffect(weightArr: number[][], effCfgMap: Map<number, EffectCardCfg>, countMap: Map<number, number>) {
let total = 0;
let tmpArr:number[][] = [];
for (let data of weightArr) {
total += data[1];
tmpArr.push([data[0], total]);
}
let num = Math.random() * total;
let effid;
for (let data of tmpArr) {
if (data[1] >= num ) {
let count = countMap.has(data[0]) ? countMap.get(data[0]) : 0;
if (count < effCfgMap.get(data[0]).maxCount) {
effid = effCfgMap.get(data[0]).id;
countMap.set(effid, count + 1);
break;
}
}
}
if (!effid) {
console.warn('生成卡组时, 无法匹配效果卡, 请确认效果卡的最大数量是否等于点数卡总数')
}
return effid;
},
/**
* id是否在存在
* @param cardMap