修改卡组生成逻辑
This commit is contained in:
parent
4b6e5bdcb2
commit
203182be0f
@ -3,6 +3,7 @@ import {Cfg} from "../../common/DataParser";
|
|||||||
|
|
||||||
export class EffectCardCfg implements Cfg{
|
export class EffectCardCfg implements Cfg{
|
||||||
public id: number;
|
public id: number;
|
||||||
|
public maxCount: number;
|
||||||
public typeId: number;
|
public typeId: number;
|
||||||
public eff1Id: number;
|
public eff1Id: number;
|
||||||
public eff2Id: number;
|
public eff2Id: number;
|
||||||
@ -18,5 +19,6 @@ export class EffectCardCfg implements Cfg{
|
|||||||
this.eff3Id = data.eff3_id;
|
this.eff3Id = data.eff3_id;
|
||||||
this.eff4Id = data.eff4_id;
|
this.eff4Id = data.eff4_id;
|
||||||
this.eff5Id = data.eff5_id;
|
this.eff5Id = data.eff5_id;
|
||||||
|
this.maxCount = 20;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -6,17 +6,17 @@ export class SystemCardCfg implements Cfg {
|
|||||||
public count: number;
|
public count: number;
|
||||||
public point: number;
|
public point: number;
|
||||||
public weight: string;
|
public weight: string;
|
||||||
public weightArr: [];
|
public weightArr: number[][];
|
||||||
public decode(data: any) {
|
public decode(data: any) {
|
||||||
this.id = data.id;
|
this.id = data.id;
|
||||||
this.typeId = data.type_id;
|
this.typeId = data.type_id;
|
||||||
this.point = data.point;
|
this.point = data.point;
|
||||||
|
this.count = data.count;
|
||||||
this.weight = data.weight;
|
this.weight = data.weight;
|
||||||
let arr = this.weight.split('|');
|
let arr = this.weight.split('|');
|
||||||
this.weightArr = [];
|
this.weightArr = [];
|
||||||
for (let str of arr) {
|
for (let str of arr) {
|
||||||
let subArr = str.split(':');
|
let subArr = str.split(':');
|
||||||
// @ts-ignore
|
|
||||||
this.weightArr.push([parseInt(subArr[0]), parseInt(subArr[1])]);
|
this.weightArr.push([parseInt(subArr[0]), parseInt(subArr[1])]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -17,13 +17,13 @@ export var DataParser = (function (){
|
|||||||
for (let i = 0, len = data.length; i < len; i++) {
|
for (let i = 0, len = data.length; i < len; i++) {
|
||||||
let obj = data[i];
|
let obj = data[i];
|
||||||
if (!obj[idkey]) {
|
if (!obj[idkey]) {
|
||||||
console.error(`配置${key}的数据有误,唯一标识 ${idkey} 值为0或者没有${idkey}`);
|
console.warn(`配置${key}的数据有误,唯一标识 ${idkey} 值为0或者没有${idkey}`);
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
let to = new CfgCreator();
|
let to = new CfgCreator();
|
||||||
to.decode(obj);
|
to.decode(obj);
|
||||||
if (dict.has(to.id)) {
|
if (dict.has(to.id)) {
|
||||||
console.error(`配置${key}的数据有误,唯一标识 id 有重复值:${to.id}`)
|
console.warn(`配置${key}的数据有误,唯一标识 id 有重复值:${to.id}`)
|
||||||
process.abort();
|
process.abort();
|
||||||
}
|
}
|
||||||
dict.set(to.id, to);
|
dict.set(to.id, to);
|
||||||
|
11
src/global.d.ts
vendored
11
src/global.d.ts
vendored
@ -1,7 +1,5 @@
|
|||||||
export {};
|
export {};
|
||||||
|
|
||||||
declare var console1: Console;
|
|
||||||
|
|
||||||
declare global {
|
declare global {
|
||||||
namespace NodeJS {
|
namespace NodeJS {
|
||||||
interface Global {
|
interface Global {
|
||||||
@ -11,3 +9,12 @@ declare global {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
declare module colyseus {
|
||||||
|
namespace Colyseus {
|
||||||
|
class Room {
|
||||||
|
testFun(param1: string): void;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@ -12,6 +12,7 @@ import {EatCardCommand} from "./commands/EatCardCommand";
|
|||||||
import {GiveUpCommand} from "./commands/GiveUpCommand";
|
import {GiveUpCommand} from "./commands/GiveUpCommand";
|
||||||
import {BattleHandler} from "./logic/Handler/BattleHandler";
|
import {BattleHandler} from "./logic/Handler/BattleHandler";
|
||||||
|
|
||||||
|
|
||||||
export class GeneralRoom extends Room {
|
export class GeneralRoom extends Room {
|
||||||
dispatcher = new Dispatcher(this);
|
dispatcher = new Dispatcher(this);
|
||||||
maxClients = 4;
|
maxClients = 4;
|
||||||
@ -68,7 +69,7 @@ export class GeneralRoom extends Room {
|
|||||||
onJoin (client: Client, options: any) {
|
onJoin (client: Client, options: any) {
|
||||||
this.dispatcher.dispatch(new OnJoinCommand(), {
|
this.dispatcher.dispatch(new OnJoinCommand(), {
|
||||||
client: client,
|
client: client,
|
||||||
battle: this.battleMan,
|
battle: this.battleMan,
|
||||||
});
|
});
|
||||||
this.clientMap.set(client.sessionId, client);
|
this.clientMap.set(client.sessionId, client);
|
||||||
}
|
}
|
||||||
|
@ -45,6 +45,7 @@ export class EatCardCommand extends Command<CardGameState, { client: Client, car
|
|||||||
player.cardSet.delete(id+'');
|
player.cardSet.delete(id+'');
|
||||||
}
|
}
|
||||||
this.state.gameState = GameStateConst.STATE_PICK_PET;
|
this.state.gameState = GameStateConst.STATE_PICK_PET;
|
||||||
|
//TODO:: 调用 onCardLinkReady()
|
||||||
// 成功后广播吃牌成功消息
|
// 成功后广播吃牌成功消息
|
||||||
this.room.broadcast('eat_card_s2c', {player: client.sessionId, errocode: 0, errmsg: ''})
|
this.room.broadcast('eat_card_s2c', {player: client.sessionId, errocode: 0, errmsg: ''})
|
||||||
}
|
}
|
||||||
|
@ -2,12 +2,13 @@ import {Schema, type, filter} from "@colyseus/schema";
|
|||||||
|
|
||||||
export class Card extends 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();
|
super();
|
||||||
this.number = number;
|
this.number = number;
|
||||||
this.type = type;
|
this.type = type;
|
||||||
this.id = id;
|
this.id = id;
|
||||||
this.played = false;
|
this.played = false;
|
||||||
|
this.effect = effect;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -6,34 +6,58 @@ import {singleton} from "../common/Singleton";
|
|||||||
import {GameEnv} from "../cfg/GameEnv";
|
import {GameEnv} from "../cfg/GameEnv";
|
||||||
import {BaseConst} from "../constants/BaseConst";
|
import {BaseConst} from "../constants/BaseConst";
|
||||||
import {SystemCardCfg} from "../cfg/parsers/SystemCardCfg";
|
import {SystemCardCfg} from "../cfg/parsers/SystemCardCfg";
|
||||||
|
import {EffectCardCfg} from "../cfg/parsers/EffectCardCfg";
|
||||||
|
|
||||||
let gameUtil = {
|
let gameUtil = {
|
||||||
// TODO: 根据配表生成牌组
|
// TODO: 根据配表生成牌组
|
||||||
initCardQue() {
|
initCardQue() {
|
||||||
let cards: Array<Card> = [];
|
let cards: Array<Card> = [];
|
||||||
let numCfgMap: Map<number, SystemCardCfg> = global.$cfg.get(BaseConst.SYSTEMCARD);
|
let numCfgMap: Map<number, SystemCardCfg> = global.$cfg.get(BaseConst.SYSTEMCARD);
|
||||||
let effCfgMap = global.$cfg.get(BaseConst.EFFECTCARD);
|
let effCfgMap: Map<number, EffectCardCfg> = global.$cfg.get(BaseConst.EFFECTCARD);
|
||||||
let nums: Array<number> = [];
|
|
||||||
let types : Array<number> = [];
|
let countMap: Map<number, number> = new Map();
|
||||||
|
let localId = 1;
|
||||||
for (let [id, cfg] of numCfgMap) {
|
for (let [id, cfg] of numCfgMap) {
|
||||||
for (let i = 0; i < cfg.count; i++) {
|
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);
|
arrUtil.randomSort(cards);
|
||||||
return 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是否在存在
|
* 检查目标数组中的卡id是否在存在
|
||||||
* @param cardMap
|
* @param cardMap
|
||||||
|
Loading…
x
Reference in New Issue
Block a user