商店:一般购物流程

This commit is contained in:
luying
2021-03-31 17:52:34 +08:00
parent e487d07bfd
commit 8c8adacfdc
21 changed files with 1631 additions and 327 deletions

View File

@@ -77,7 +77,8 @@ export class GuildHandler {
let rank = await getMyRank(REDIS_KEY.GUILD_ACTIVE_RANK, serverId, guild.code);
// 加入channel
session.set('guildCode', guild.code);
session.push('guildCode', () => {});
addRoleToGuildChannel(roleId, sid, guild.code);
// 添加动态
@@ -273,6 +274,8 @@ export class GuildHandler {
// 打开公会页面加入channel
if(userGuild.guildCode) {
addRoleToGuildChannel(roleId, sid, guild.code);
session.set('guildCode', guild.code);
session.push('guildCode', () => {});
}
// 获取排行榜
@@ -315,7 +318,7 @@ export class GuildHandler {
let hasGuild = false;
if(isAuto) { // 自动加入
const joinResult = await joinGuild(code, guild.name, lv, roleId, serverId);
const joinResult = await joinGuild(code, guild.name, lv, roleId, serverId, session);
if(joinResult.status == -1) {
return joinResult.resResult;
}
@@ -377,7 +380,7 @@ export class GuildHandler {
if(isReceived) { // 同意申请,加入
for(let { roleId } of applyList) {
const joinResult = await joinGuild(code, guild.name, guild.lv, roleId, serverId);
const joinResult = await joinGuild(code, guild.name, guild.lv, roleId, serverId, session);
if(joinResult.status == -1) continue;
let chatSid = await getGuildChannelSid(code);
// 更新人数增加
@@ -513,7 +516,7 @@ export class GuildHandler {
const { guildCode } = invite;
const guild = await GuildModel.findByCode(guildCode, serverId);
const joinResult = await joinGuild(guildCode, guild.name, guild.lv, roleId, serverId);
const joinResult = await joinGuild(guildCode, guild.name, guild.lv, roleId, serverId, session);
if(joinResult.status == -1) {
return joinResult.resResult;
}
@@ -634,6 +637,9 @@ export class GuildHandler {
let chatSid = await getGuildChannelSid(code);
this.app.rpc.chat.guildRemote.addRec.toServer(chatSid,rec);
this.app.rpc.chat.guildRemote.memberQuit.toServer(chatSid,code, roleId, guild, sid);
session.set('guildCode', '');
session.push('guild', () => {});
return resResult(STATUS.SUCCESS, { hasGuild: role.hasGuild });
}

View File

@@ -0,0 +1,148 @@
import { Application, BackendSession } from "pinus";
import { gameData } from "../../../pubUtils/data";
import { resResult } from "../../../pubUtils/util";
import { STATUS, GUILD_STRUCTURE } from "../../../consts";
import { DicShopListModel } from "../../../db/DicShopList";
import { ShopItem } from "../../../domain/dbGeneral";
import { ShopItemListParam } from '../../../domain/roleField/shop';
import { UserShopModel } from "../../../db/UserShop";
import { handleCost, addItems } from "../../../services/rewardService";
import { GuildModel } from "../../../db/Guild";
export default function(app: Application) {
return new ShopHandler(app);
}
export class ShopHandler {
constructor(private app: Application) {
}
// 获得商品列表
async getShopList(msg: { shopId: number }, session: BackendSession) {
let roleId = session.get('roleId');
let { shopId } = msg;
if(!gameData.shopList.has(shopId)) {
return resResult(STATUS.WRONG_PARMS);
}
let shopItemList = new Array<ShopItemListParam>(); // 返回
let dbDicShop = await DicShopListModel.findByShopId(shopId);
let userShopRecs = await UserShopModel.findMapByShopId(roleId, shopId);
console.log(JSON.stringify([...userShopRecs]))
if(!dbDicShop || dbDicShop.useJson) { // 完全使用json中配置的商品数据库只做排序用数据库内没有的排到最后
let items = dbDicShop?.items||[];
let map = new Map<number, ShopItem>();
for(let item of items) {
map.set(item.id, item);
}
let dicShop = gameData.shop.get(shopId)||[];
for(let { id, type } of dicShop) {
let buyCount = userShopRecs.has(id)?userShopRecs.get(id).count: 0;
if(map.has(id)) {
let item = map.get(id);
let param = new ShopItemListParam(id, item.discount, type, buyCount, item.order);
shopItemList.push(param);
} else {
let param = new ShopItemListParam(id, 1, type, buyCount, 0);
shopItemList.push(param);
}
}
} else { // 只返回数据库内的商品
let items = dbDicShop?.items||[];
for(let item of items) {
let { id, order, discount } = item;
let buyCount = userShopRecs.has(id)?userShopRecs.get(id).count: 0;
let dicShop = gameData.shopItem.get(id);
if(dicShop) {
let param = new ShopItemListParam(id, discount, dicShop.type, buyCount, order);
shopItemList.push(param);
}
}
}
shopItemList = shopItemList.sort((a, b) => b.order - a.order);
return resResult(STATUS.SUCCESS, { shopItemList });
}
// 购买商品
async purchase(msg: { shopItemId: number, count: number }, session: BackendSession) {
let roleId = session.get('roleId');
let roleName = session.get('roleName');
let sid = session.get('sid');
let guildCode = session.get('guildCode');
let serverId = session.get('serverId');
let { shopItemId, count } = msg;
let dicShopItem = gameData.shopItem.get(shopItemId);
if(!dicShopItem) return resResult(STATUS.DIC_DATA_NOT_FOUND);
if(dicShopItem.guildLvLimit) {
let myGuild = await GuildModel.findByCode(guildCode, serverId);
if(!myGuild) return resResult(STATUS.GUILD_LV_LIMIT);
let { structure } = myGuild;
let curStructure = structure.find(cur => cur.id == GUILD_STRUCTURE.STORE);
if(!curStructure || curStructure.lv < dicShopItem.guildLvLimit) {
return resResult(STATUS.GUILD_LV_LIMIT);
}
}
let dbShop = await DicShopListModel.findByShopId(dicShopItem.shop);
let discount = 1;
if(dbShop) {
let item = dbShop.items.find(cur => cur.id == shopItemId);
if(item) {
discount = item.discount;
}
}
let userShop = await UserShopModel.findByRoleAndItem(roleId, dicShopItem.id);
if(userShop && userShop.count + count > dicShopItem.purchaseLimit) {
return resResult(STATUS.BUY_COUNT_OVER);
}
// 消耗
let cost = [{
id: dicShopItem.money,
count: Math.round(dicShopItem.price * count * discount)
}];
let costResult = await handleCost(roleId, sid, cost);
if(!costResult) return resResult(STATUS.BATTLE_CONSUMES_NOT_ENOUGH);
// 次数
userShop = await UserShopModel.purchase(roleId, roleName, dicShopItem, count);
if(!userShop) return resResult(STATUS.BUY_COUNT_OVER);
// 获得
let reward = [{
id: dicShopItem.goodid,
count
}];
let goods = await addItems(roleId, roleName, sid, reward);
return resResult(STATUS.SUCCESS, {
shopItemId, count,
goods
});
}
// 将魂回收
async recycleSoul(msg: { goodsId: number, count: number }, session: BackendSession) {
}
// !测试接口初始化将json表中的内容加入数据库内
async initShopList() {
let index = gameData.shopItem.size;
for(let [id, dic] of gameData.shopItem) {
await DicShopListModel.createShop(dic.shop, true, { id, order: index--, discount: 1 })
}
}
}

View File

@@ -174,18 +174,18 @@ export async function getRaceActivityRank(guildCode: string, serverId: number) {
let guildRank = new Array<SimpleGuildRankWithTimeParam>();
for(let { rank, code, name, num } of guildRankResult.ranks) {
let _obj = await obj.getWoodenHorse(code, serverId);
let param = new SimpleGuildRankWithTimeParam(rank, code, name, num, _obj?_obj.time:0, _obj?_obj.durability:0);
let param = new SimpleGuildRankWithTimeParam(rank, code, name, _obj);
guildRank.push(param);
}
let myGuildRank: SimpleGuildRankWithTimeParam;
if(guildRankResult.myRank) {
let { rank, code, name, num } = guildRankResult.myRank;
let _obj = await obj.getWoodenHorse(code, serverId);
myGuildRank = new SimpleGuildRankWithTimeParam(rank, code, name, num, _obj?_obj.time:0, _obj?_obj.durability:0);
myGuildRank = new SimpleGuildRankWithTimeParam(rank, code, name, _obj);
} else {
let guild = await GuildModel.findByCode(guildCode, serverId, 'name');
let _obj = await obj.getWoodenHorse(guildCode, serverId);
myGuildRank = new SimpleGuildRankWithTimeParam(0, guildCode, guild?.name, 0, _obj?_obj.time:0, _obj?_obj.durability:0);
myGuildRank = new SimpleGuildRankWithTimeParam(0, guildCode, guild?.name, _obj);
}
return { guildRank, myGuildRank }
}
@@ -317,6 +317,7 @@ export async function sendGuildActEndMsg(aid: number) {
await raceActivitySettleReward(guildCode, woodenHorse);
}
}
raceActivityObj = new RaceActivityObject();
}
}
@@ -588,7 +589,7 @@ export async function calWoodenHorseAndSend(serverId: number) {
for(let i = 0; i < l; i++) {
let { rank, code, name, num } = ranks[i]
let _obj = await obj.getWoodenHorse(code, serverId);
let param = new SimpleGuildRankWithTimeParam(rank, code, name, _obj?_obj.distance:0, _obj?_obj.time:0, _obj?_obj.durability:0);
let param = new SimpleGuildRankWithTimeParam(rank, code, name, _obj);
guildRank.push(param);
}
@@ -617,7 +618,7 @@ export async function calWoodenHorseAndSend(serverId: number) {
console.log('send', woodenHorseList.length);
let curRank = ranks[rank];
let wh = await obj.getWoodenHorse(curRank.code, serverId);
let myGuildRank = new SimpleGuildRankWithTimeParam(curRank.rank, curRank.code, curRank.name, curRank.num, wh?wh.time:0, wh?wh.durability:0);
let myGuildRank = new SimpleGuildRankWithTimeParam(curRank.rank, curRank.code, curRank.name, wh);
let chatSid = await getGuildChannelSid(curRank.code);
let events = obj.getEvents(curRank.code, wh?wh.distance:0);

View File

@@ -7,7 +7,7 @@ import { UserGuildModel, UserGuildType } from "../db/UserGuild";
import { UserGuildApplyModel } from "../db/UserGuildApply";
import { SystemConfigModel } from "../db/SystemConfig";
import { nowSeconds } from "../pubUtils/timeUtil";
import { pinus } from "pinus";
import { pinus, BackendSession } from "pinus";
import { ARMY } from "../pubUtils/dicParam";
import { sendMail } from "./mailService";
import { setRank, getMyRank, initSingleRank, getRoleOnlineInfo } from "./redisService";
@@ -40,7 +40,7 @@ export async function checkAuth(func: number, roleId: string, code?: string, use
* @param lv 公会当前等级,判断人数用
* @param roleId 加入的玩家
*/
export async function joinGuild(code: string, guildName: string, lv: number, roleId: string, serverId: number) {
export async function joinGuild(code: string, guildName: string, lv: number, roleId: string, serverId: number, session: BackendSession) {
// 周结算锁
let weeklySumLock = await lockDataNoRetry(serverId, DATA_NAME.WEEKLY_GUILD_SUM, code);
@@ -86,6 +86,9 @@ export async function joinGuild(code: string, guildName: string, lv: number, rol
if (sid) {
await addRoleToGuildChannel(roleId, sid, code);
}
session.set('guildCode', code);
session.push('guildCode', () => {});
return { status: 0, guild, userGuild, roleName: role.roleName, memberCnt: guild.memberCnt, guildCe: guild.guildCe }
}

View File

@@ -353,7 +353,9 @@ export const FILENAME = {
DIC_CHAT_ACCUSE: 'dic_zyz_chat_report',
DIC_CHAT_SYSTEM: 'dic_zyz_chat_system',
DIC_CITY_ACTIVITY_REWARD: 'dic_zyz_cityActivityReward',
DIC_RACE_ACTIVITY: 'dic_zyz_raceActivity'
DIC_RACE_ACTIVITY: 'dic_zyz_raceActivity',
DIC_SHOP: 'dic_zyz_shop',
DIC_SHOP_LIST: 'dic_zyz_shopList'
}
export const WAR_RELATE_TABLES = [
@@ -445,3 +447,11 @@ export enum DEFAULT_DEVICE_ID {
// 阵容人数限制
export const LINEUP_NUM = 6;
// 商店刷新类型
export enum SHOP_REFRESH_TYPE {
DAILY = 1, // 每天刷新
WEEKLY = 2, // 每周
MONTHLY = 3, // 每月
FOREVER = 4 // 不重置
}

View File

@@ -302,6 +302,10 @@ export const STATUS = {
SPINE_NOT_FOUND: { code: 30808, simStr: '未找到形象' },
SPINE_IS_WEARING: { code: 30809, simStr: '形象已设置中' },
SPINE_IS_LOCKED: { code: 30810, simStr: '形象未解锁' },
// 商店相关 30900-31000
BUY_COUNT_OVER: { code: 30900, simStr: '已超过限购次数' },
GUILD_LV_LIMIT: { code: 30901, simStr: '军团等级不足' },
// 社交相关状态 40000 - 49999
SYS_CHANNEL_AUTH_NOT_ENOUGH: {code: 40000, simStr: '无法在系统频道发送消息'},

36
shared/db/DicShopList.ts Normal file
View File

@@ -0,0 +1,36 @@
import BaseModel from './BaseModel';
import { index, getModelForClass, prop, DocumentType, modelOptions } from '@typegoose/typegoose';
import { ShopItem } from '../domain/dbGeneral';
/**
* 分红记录表
**/
@modelOptions({ schemaOptions: { id: false } })
@index({ shopId: 1 })
export default class DicShopList extends BaseModel {
@prop({ required: true })
shopId: number; // 商店id dic_zyz_shopList内的id
@prop({ required: true, default: false })
useJson: boolean; // 如果为true则会随dic_zyz_shop表内商品增加而增加items只提供顺序折扣等为false则只提供items里的商品
@prop({ required: true, default: [], _id: false, type: () => ShopItem })
items: ShopItem[]; // 商店id dic_zyz_shopList内的id
public static async findByShopId(shopId: number) {
const rec: DicShopListType = await DicShopListModel.findOne({ shopId }).lean();
return rec;
}
public static async createShop(shopId: number, useJson: boolean, item: ShopItem) {
const rec: DicShopListType = await DicShopListModel.findOneAndUpdate({ shopId }, { useJson, $push: { items: item } }, { new: true, upsert: true }).lean();
return rec;
}
}
export const DicShopListModel = getModelForClass(DicShopList);
export interface DicShopListType extends Pick<DocumentType<DicShopList>, keyof DicShopList>{}
export type DicShopListParam = Partial<DicShopListType>;

94
shared/db/UserShop.ts Normal file
View File

@@ -0,0 +1,94 @@
import BaseModel from './BaseModel';
import { index, getModelForClass, prop, DocumentType, modelOptions } from '@typegoose/typegoose';
import { genCode } from '../pubUtils/util';
import { ShopItem } from '../domain/dbGeneral';
import { getCurWeekDate, getCurMonthDate, getTodayZeroDate } from '../pubUtils/timeUtil';
import { SHOP_REFRESH_TYPE } from '../consts';
import { DicShop } from '../pubUtils/dictionary/DicShop';
/**
* 玩家购买商店记录表,每个商品一条,每次刷新新建一条
**/
@modelOptions({ schemaOptions: { id: false } })
@index({ roleId: 1, itemId: 1 })
export default class UserShop extends BaseModel {
@prop({ required: true })
code: string; // 该记录唯一标识
@prop({ required: true })
roleId: string; // 玩家id
@prop({ required: true })
roleName: string; // 玩家名
@prop({ required: true })
shopId: number; // 商店id
@prop({ required: true })
itemId: number; // 商品id
@prop({ required: true })
goodId: number; // 商品包含的物品id
@prop({ required: true })
refreshType: number; // 商品刷新类型 1-每日 2-每周 3-每月
@prop({ required: true })
count: number; // 数量
private static getRefreshCondition() {
let today = getTodayZeroDate(5);
let cutWeek = getCurWeekDate(1, 5);
let curMonth = getCurMonthDate(1, 5);
return [
{ createdAt: { $gte: today }, refreshType: SHOP_REFRESH_TYPE.DAILY },
{ createdAt: { $gte: cutWeek }, refreshType: SHOP_REFRESH_TYPE.WEEKLY },
{ createdAt: { $gte: curMonth }, refreshType: SHOP_REFRESH_TYPE.MONTHLY },
{ refreshType: SHOP_REFRESH_TYPE.FOREVER },
]
}
public static async findByShopId(roleId: string, shopId: number) {
let timeCondition = this.getRefreshCondition();
let rec: UserShopType[] = await UserShopModel.find({ shopId, roleId, $or: timeCondition }).lean();
return rec;
}
public static async findMapByShopId(roleId: string, shopId: number) {
let rec = await this.findByShopId(roleId, shopId);
let map = new Map<number, UserShopType>();
for(let userShop of rec) {
map.set(userShop.itemId, userShop);
}
return map
}
public static async findByRoleAndItem(roleId: string, itemId: number) {
let timeCondition = this.getRefreshCondition();
let rec: UserShopType = await UserShopModel.findOne({ roleId, itemId, $or: timeCondition }).lean();
return rec;
}
public static async purchase(roleId: string, roleName: string, dicShopItem: DicShop, inc: number) {
let code = genCode(8);
let timeCondition = this.getRefreshCondition();
let { id, goodid, refreshType, shop } = dicShopItem;
let rec: UserShopType = await UserShopModel.findOneAndUpdate(
{ roleId, itemId: id, $or: timeCondition },
{ $setOnInsert: { roleName, code, goodId: goodid, refreshType, shopId: shop }, $inc: { count: inc } },
{ new: true, upsert: true }
).lean();
return rec;
}
}
export const UserShopModel = getModelForClass(UserShop);
export interface UserShopType extends Pick<DocumentType<UserShop>, keyof UserShop> { }
export type UserShopParam = Partial<UserShopType>;

View File

@@ -215,7 +215,7 @@ export class CityActivityObject {
// 军团诸侯混战等数据
export class RaceActivityObject {
private status = 0; // 活动状态 0-未开始 1-已开始 2-已结束
private status = 0; // 活动状态 0-未开始 1-已开始 2-已结束 // TODO 写进const表
public guildList: Array<{ serverId: number, guildCode: string }> = []; // 所有军团
private members: Map<string, Array<Member>> = new Map(); // 每个军团参与的成员 guildCode => [{roleId, job}]
private woodenHorses: Map<string, WoodenHorse> = new Map(); // 每个军团的木牛流马 guildCode => WoodenHorse
@@ -250,7 +250,7 @@ export class RaceActivityObject {
woodenHorse.joinMember(roleId, roleName, sid)
this.pushMember(guildCode, roleId, job);
if(this.status == 1) {
if(this.status == 1) { // TODO 写进const表
let item = getRaceEventItems();
this.handleItems(roleId, sid, item);
}
@@ -269,14 +269,14 @@ export class RaceActivityObject {
let { name: guildName, guildCe } = guild;
this.woodenHorses.set(guildCode, new WoodenHorse(guildCode, guildName, guildCe, serverId));
this.guildList.push({guildCode, serverId});
if(this.status == 1) {
if(this.status == 1) { // TODO 写进const表
this.woodenHorseStartRace(this.woodenHorses.get(guildCode));
}
}
let woodenHorse = this.woodenHorses.get(guildCode);
let events = this.events.get(guildCode)||[];
let needSendEnd = woodenHorse.calCurWoodenHorse(events);
if(woodenHorse.status == 1 || woodenHorse.status == 2) { // 更新距离
if(woodenHorse.status == 1 || woodenHorse.status == 2) { // 更新距离 // TODO 写进const表
await setRankWithoutUserInfo(REDIS_KEY.RACE_ACTIVITY, serverId, guildCode, woodenHorse.distance, Math.floor((woodenHorse.time - woodenHorse.startTime)/1000), true, false);
if (needSendEnd) { // 抵达后发送奖励,发送消息,结算
await sendSingleRaceActEndMsg(guildCode, woodenHorse);
@@ -305,7 +305,7 @@ export class RaceActivityObject {
// 定时任务到,开始比赛,设置开始赛道,发放初始道具
public startRace() {
this.status = 1;
this.status = 1; // TODO 写进const表
let guildCodes = new Array<string>();
for(let [code, woodenHorse] of this.woodenHorses) {
this.woodenHorseStartRace(woodenHorse);
@@ -315,7 +315,7 @@ export class RaceActivityObject {
}
private woodenHorseStartRace(woodenHorse: WoodenHorse) {
woodenHorse.status = 1;
woodenHorse.status = 1; // TODO 写进const表
woodenHorse.time = Date.now();
woodenHorse.startTime = Date.now();
let members = woodenHorse.members;
@@ -459,7 +459,7 @@ export class WoodenHorse {
*/
public calCurWoodenHorse(events: Event[]): boolean {
console.log('**', JSON.stringify(events))
if(this.status == 2) return false;
if(this.status == 2) return false; // TODO 写进const表
if(this.status == 0 && this.stopContinueTime && Date.now() > this.stopContinueTime) {
this.status = 1; this.stopContinueTime = 0;
}
@@ -528,7 +528,7 @@ export class WoodenHorse {
case RACE_EVENT.GUISHOUYINFU:
if (this.shieldTime < Date.now()) {
this.stopContinueTime = endTime;
this.status = 0;
this.status = 0; // TODO 写进const表
}
break;
case RACE_EVENT.FENGCHE:
@@ -538,9 +538,9 @@ export class WoodenHorse {
this.shield += count * effect[0]; break;
case RACE_EVENT.TIANSHIDUNFU:
this.shieldTime = endTime; break;
case RACE_EVENT.JIANSU_1:
case RACE_EVENT.JIASU_1:
this.speed *= 1 + effect[0]; break;
case RACE_EVENT.JIANSU_2:
case RACE_EVENT.JIASU_2:
this.speed += effect[0]; break;
case RACE_EVENT.HUIFU_1:
this.durability += effect[0];
@@ -570,7 +570,7 @@ export class WoodenHorse {
break;
}
if(this.durability <= 0) {
this.status = 0;
this.status = 0; // TODO 写进const表
this.speed = 0;
}
}

View File

@@ -279,4 +279,18 @@ export class DividendRec {
total: number; // 总分红
@prop({ required: true, default: 0 })
status: number; // 0未领取1已领取
}
/**
* @description 商店商品
* @export
* @class ShopItem
*/
export class ShopItem {
@prop({ required: true, default: 0 })
id: number; // 商品id shopItemId
@prop({ required: true, default: 0 })
order: number; // 显示排序
@prop({ required: true, default: 0 })
discount: number; // 折扣
}

View File

@@ -1,4 +1,5 @@
import { EXTERIOR } from "../pubUtils/dicParam";
import { WoodenHorse } from "./battleField/guildActivity";
// 排行榜返回玩家值
export class RankParam {
@@ -65,10 +66,10 @@ export class GuildLeader {
}
export class SimpleGuildRankParam {
rank: number;
code: string;
name: string;
num: number;
rank: number = 0;
code: string = "";
name: string = "";
num: number = 0;
constructor(rank: number, code: string, name: string, num: number) {
this.rank = rank;
@@ -79,13 +80,16 @@ export class SimpleGuildRankParam {
}
export class SimpleGuildRankWithTimeParam extends SimpleGuildRankParam {
time: number;
durability: number;
time: number = 0;
durability: number = 0;
constructor(rank: number, code: string, name: string, num: number, time: number, durability: number) {
super(rank, code, name, num);
this.time = time;
this.durability = durability;
constructor(rank: number, code: string, name: string, obj: WoodenHorse|false) {
super(rank, code, name, obj?obj.distance:0);
if(obj) {
this.num = obj.distance;
this.time = Math.floor((obj.time - obj.startTime)/1000);
this.durability = obj.durability;
}
}
}

View File

@@ -0,0 +1,17 @@
// hero表内属性基础格式
export class ShopItemListParam {
shopItemId: number;
discount: number;
typeId: number;
buyCount: number;
order: number;
constructor(shopItemId: number, discount: number, typeId: number, buyCount: number, order: number) {
this.shopItemId = shopItemId;
this.discount = discount;
this.typeId = typeId;
this.buyCount = buyCount;
this.order = order;
}
}

View File

@@ -69,6 +69,8 @@ import { dicRaceActivity, dicRaceTypes } from './dictionary/DicRaceActivity';
import { GUILDACTIVITY } from "./dicParam";
import { decodeIdCntArrayStr, parseGoodStr, decodeArrayListStr, getRandValueByMinMax } from "./util";
import { GUILD_SELECT, RACE_EVENT_TYPE } from "../consts";
import { dicShop, dicShopItem } from "./dictionary/DicShop";
import { dicShopList } from "./dictionary/DicShopList";
export const gameData = {
blurprtCompose: dicBlueprtCompose,
@@ -161,7 +163,10 @@ export const gameData = {
raceTypes: dicRaceTypes,
raceActivityEncounter: decodeRaceActivityEncounter(),
raceNormalItems: decodeRaceNormalItems(),
raceEventItems: decodeRaceEventItems()
raceEventItems: decodeRaceEventItems(),
shop: dicShop,
shopItem: dicShopItem,
shopList: dicShopList
};
// 在此提供一些原先在gamedata中提供的方法以便更方便获取gameData数据

View File

@@ -0,0 +1,45 @@
// 商店商品表
import { readJsonFile } from '../util'
import { FILENAME } from '../../consts'
export interface DicShop {
// 商品id
readonly id: number;
// 物品表id
readonly goodid: number;
// 物品表名
readonly goodname: number;
// 商店id 对应 dic_zyz_shoplist的id
readonly shop: number;
// 商店标签 对应 dic_zyz_shopType的id
readonly type: number;
// 军团等级需求
readonly guildLvLimit: number;
// 购买次数限制
readonly purchaseLimit: number;
// 刷新类型 1-每日 2-每周 3-每月
readonly refreshType: number;
// 用于购买的货币
readonly money: number;
// 价格
readonly price: number;
}
const str = readJsonFile(FILENAME.DIC_SHOP);
let arr = JSON.parse(str);
export const dicShopItem = new Map<number, DicShop>(); // itemid => DicShop
export const dicShop = new Map<number, DicShop[]>(); // shop => DicShop[]
arr.forEach(o => {
o.guildLvLimit = o.guildlvlimit == '&'?0: o.guildlvlimit;
o.purchaseLimit = o.purchaselimit == '&'?-1: o.purchaselimit;
if(!dicShop.has(o.shop)) {
dicShop.set(o.shop, [o]);
} else {
dicShop.get(o.shop).push(o);
}
dicShopItem.set(o.id, o);
});

View File

@@ -0,0 +1,26 @@
// 商店表
import { readJsonFile, parseNumberList } from '../util'
import { FILENAME } from '../../consts'
export interface DicShopList {
// 商店id
readonly shopid: number;
// 商店名
readonly shopname: number;
// 商店内标签,小分类
readonly type: number[];
// 使用的货币
readonly money: number[];
}
const str = readJsonFile(FILENAME.DIC_SHOP_LIST);
let arr = JSON.parse(str);
export const dicShopList = new Map<number, DicShopList>();
arr.forEach(o => {
o.type = parseNumberList(o.typeid);
o.money = parseNumberList(o.moneyid);
dicShopList.set(o.shopid, o);
});

View File

@@ -13,9 +13,9 @@ export function nowSeconds() {
return Math.floor(Date.now() / PER_SECOND );
}
export function getTodayZeroPoint() {
export function getTodayZeroPoint(hour = 0) {
var date = new Date();
date.setHours(0);
date.setHours(hour);
date.setMinutes(0);
date.setSeconds(0);
var time = Math.floor(date.getTime() / PER_SECOND);
@@ -78,6 +78,28 @@ export function getCurWeekTime(day: number, hour: number) {
return Math.floor(data.getTime()/PER_SECOND);
}
export function getCurMonthDate(day: number, hour: number) {
return getMonthDate(new Date(), day, hour);
}
export function getCurMonthTime(day: number, hour: number) {
let data = getMonthDate(new Date(), day, hour);
return Math.floor(data.getTime()/PER_SECOND);
}
/**
* @description 获取某个时间的当月的某一天的某一时
* @param {{Date}} now 时间
* @param {{number}} day 哪天
* @param {{number}} hour 几点
*/
export function getMonthDate(now: Date, day: number, hour: number){ //获得本周的开端日期
let nowYear = now.getFullYear(); //当前年
let nowMonth = now.getMonth(); //月
return new Date(nowYear, nowMonth, day, hour);
};
export function getHourPoint(hour: number) {
var date = new Date();
date.setHours(hour);
@@ -115,9 +137,9 @@ export function getNextHourPoint(hour: number) {
return time;
}
export function getTodayZeroDate() {
export function getTodayZeroDate(hour = 0) {
var date = new Date();
date.setHours(0);
date.setHours(hour);
date.setMinutes(0);
date.setSeconds(0);
return date;

File diff suppressed because it is too large Load Diff

134
shared/resource/jsons/dic_zyz_gk_dungeon.json Executable file → Normal file
View File

@@ -16,7 +16,7 @@
"loseInfoInUI": "我方全部阵亡",
"starInfoInUI": "1.我方无人阵亡;\r\n2.在5回合内获得胜利",
"cost": 0,
"recommendedPower": 23456,
"recommendedPower": 19875,
"previousGk": 104,
"lvLimted": 0,
"heroInUI": "2&1035",
@@ -26,30 +26,30 @@
"bossSkill": "18&19"
},
{
"war_id": 5002,
"dispatchJsonId": 5002,
"bg_img_id": 550,
"war_id": 5010,
"dispatchJsonId": 5010,
"bg_img_id": 560,
"script_id": 0,
"fixReward": "11004&1|17002&10|17007&2|17008&3",
"conditionReward": "1&1&0|31002&50&0|31002&100&1",
"warType": 6,
"gk_name": "秘境&洛阳地宫",
"gk_name": "秘境&虎牢关",
"kingExp": 100,
"turnLimted": 20,
"forcedCharactor": "&",
"fobiddenCharactor": "&",
"victoryInfoInUI": "消灭所有敌军",
"loseInfoInUI": "我方全部阵亡",
"starInfoInUI": "1.我方无人阵亡;\r\n2.在5回合内获得胜利",
"starInfoInUI": "1.我方无人阵亡;\r\n2.在6回合内获得胜利",
"cost": 0,
"recommendedPower": 45673,
"previousGk": 5001,
"recommendedPower": 22684,
"previousGk": 104,
"lvLimted": 0,
"heroInUI": "2&10",
"detailUIBg": "dengeon1",
"heroInUI": "2&44",
"detailUIBg": "1_1",
"iconName": "city",
"iconInMap": "city&2",
"bossSkill": "18&19"
"bossSkill": "249&251"
},
{
"war_id": 5003,
@@ -59,22 +59,126 @@
"fixReward": "11004&4|17002&8|17007&6|17008&5",
"conditionReward": "1&1&0|31002&50&0|31002&100&1",
"warType": 6,
"gk_name": "秘境&班图",
"gk_name": "秘境&徐州曹营",
"kingExp": 100,
"turnLimted": 20,
"forcedCharactor": "&",
"fobiddenCharactor": "&",
"victoryInfoInUI": "消灭所有敌军",
"loseInfoInUI": "我方全部阵亡",
"starInfoInUI": "1.我方无人阵亡;\r\n2.在5回合内获得胜利",
"starInfoInUI": "1.我方无人阵亡;\r\n2.在7回合内获得胜利",
"cost": 0,
"recommendedPower": 45673,
"previousGk": 5002,
"recommendedPower": 24963,
"previousGk": 208,
"lvLimted": 1,
"heroInUI": "2&10",
"detailUIBg": "dengeon1",
"iconName": "city",
"iconInMap": "city&3",
"bossSkill": "18&19"
},
{
"war_id": 5004,
"dispatchJsonId": 5004,
"bg_img_id": 550,
"script_id": 0,
"fixReward": "11004&1|17001&10|17005&2|17006&4",
"conditionReward": "1&1&0|31002&50&0|31002&100&1",
"warType": 6,
"gk_name": "秘境&乌桓部落",
"kingExp": 100,
"turnLimted": 20,
"forcedCharactor": "&",
"fobiddenCharactor": "&",
"victoryInfoInUI": "消灭所有敌军",
"loseInfoInUI": "我方全部阵亡",
"starInfoInUI": "1.我方无人阵亡;\r\n2.在8回合内获得胜利",
"cost": 0,
"recommendedPower": 27853,
"previousGk": 220,
"lvLimted": 0,
"heroInUI": "2&10",
"detailUIBg": "DD1_1",
"iconName": "city",
"iconInMap": "city&4",
"bossSkill": "18&19"
},
{
"war_id": 5005,
"dispatchJsonId": 5005,
"bg_img_id": 550,
"script_id": 0,
"fixReward": "11004&1|17002&10|17007&2|17008&4",
"conditionReward": "1&1&0|31002&50&0|31002&100&1",
"warType": 6,
"gk_name": "秘境&颖川书院",
"kingExp": 100,
"turnLimted": 20,
"forcedCharactor": "&",
"fobiddenCharactor": "&",
"victoryInfoInUI": "消灭所有敌军",
"loseInfoInUI": "我方全部阵亡",
"starInfoInUI": "1.我方无人阵亡;\r\n2.在9回合内获得胜利",
"cost": 0,
"recommendedPower": 31335,
"previousGk": 304,
"lvLimted": 0,
"heroInUI": "2&10",
"detailUIBg": "dengeon1",
"iconName": "city",
"iconInMap": "city&5",
"bossSkill": "18&19"
},
{
"war_id": 5006,
"dispatchJsonId": 5006,
"bg_img_id": 550,
"script_id": 0,
"fixReward": "11004&4|17002&8|17007&6|17008&6",
"conditionReward": "1&1&0|31002&50&0|31002&100&1",
"warType": 6,
"gk_name": "秘境&卧龙岗",
"kingExp": 100,
"turnLimted": 20,
"forcedCharactor": "&",
"fobiddenCharactor": "&",
"victoryInfoInUI": "消灭所有敌军",
"loseInfoInUI": "我方全部阵亡",
"starInfoInUI": "1.我方无人阵亡;\r\n2.在10回合内获得胜利",
"cost": 0,
"recommendedPower": 35698,
"previousGk": 310,
"lvLimted": 1,
"heroInUI": "2&10",
"detailUIBg": "dengeon1",
"iconName": "city",
"iconInMap": "city&6",
"bossSkill": "18&19"
},
{
"war_id": 5007,
"dispatchJsonId": 5007,
"bg_img_id": 550,
"script_id": 0,
"fixReward": "11004&1|17001&10|17005&2|17006&5",
"conditionReward": "1&1&0|31002&50&0|31002&100&1",
"warType": 6,
"gk_name": "秘境&樊家庄",
"kingExp": 100,
"turnLimted": 20,
"forcedCharactor": "&",
"fobiddenCharactor": "&",
"victoryInfoInUI": "消灭所有敌军",
"loseInfoInUI": "我方全部阵亡",
"starInfoInUI": "1.我方无人阵亡;\r\n2.在11回合内获得胜利",
"cost": 0,
"recommendedPower": 45673,
"previousGk": 320,
"lvLimted": 1,
"heroInUI": "2&10",
"detailUIBg": "dengeon1",
"iconName": "city",
"iconInMap": "city&7",
"bossSkill": "18&19"
}
]

View File

@@ -0,0 +1,602 @@
[
{
"id": 1,
"goodid": 1,
"goodname": "铁剑",
"shop": 2,
"type": 1,
"guildlvlimit": 2,
"purchaselimit": 10,
"refreshType": 1,
"money": 40005,
"price": 100
},
{
"id": 2,
"goodid": 1,
"goodname": "铁剑",
"shop": 3,
"type": 1,
"guildlvlimit": "&",
"purchaselimit": "&",
"refreshType": 2,
"money": 40001,
"price": 50
},
{
"id": 3,
"goodid": 1,
"goodname": "铁剑",
"shop": 7,
"type": 1,
"guildlvlimit": "&",
"purchaselimit": "&",
"refreshType": 3,
"money": 40007,
"price": 300
},
{
"id": 4,
"goodid": 5,
"goodname": "青铜剑",
"shop": 2,
"type": 1,
"guildlvlimit": "&",
"purchaselimit": "&",
"refreshType": 1,
"money": 40005,
"price": 100
},
{
"id": 5,
"goodid": 101,
"goodname": "铁枪",
"shop": 2,
"type": 1,
"guildlvlimit": "&",
"purchaselimit": "&",
"refreshType": 2,
"money": 40005,
"price": 100
},
{
"id": 6,
"goodid": 201,
"goodname": "精铁长刀",
"shop": 3,
"type": 1,
"guildlvlimit": "&",
"purchaselimit": 10,
"refreshType": 3,
"money": 40001,
"price": 50
},
{
"id": 7,
"goodid": 301,
"goodname": "弓",
"shop": 3,
"type": 1,
"guildlvlimit": "&",
"purchaselimit": "&",
"refreshType": 1,
"money": 40001,
"price": 50
},
{
"id": 8,
"goodid": 325,
"goodname": "定武弓",
"shop": 7,
"type": 1,
"guildlvlimit": "&",
"purchaselimit": "&",
"refreshType": 2,
"money": 40007,
"price": 300
},
{
"id": 9,
"goodid": 425,
"goodname": "定武法剑",
"shop": 7,
"type": 1,
"guildlvlimit": "&",
"purchaselimit": "&",
"refreshType": 3,
"money": 40007,
"price": 300
},
{
"id": 10,
"goodid": 527,
"goodname": "鹰扬羽扇",
"shop": 7,
"type": 1,
"guildlvlimit": "&",
"purchaselimit": "&",
"refreshType": 1,
"money": 40007,
"price": 300
},
{
"id": 11,
"goodid": 60001,
"goodname": "一阶赤焰钻",
"shop": 3,
"type": 2,
"guildlvlimit": "&",
"purchaselimit": 10,
"refreshType": 2,
"money": 40001,
"price": 500
},
{
"id": 12,
"goodid": 60011,
"goodname": "一阶暗芒皓",
"shop": 3,
"type": 2,
"guildlvlimit": "&",
"purchaselimit": "&",
"refreshType": 3,
"money": 40001,
"price": 500
},
{
"id": 13,
"goodid": 60021,
"goodname": "一阶昆仑玉",
"shop": 3,
"type": 2,
"guildlvlimit": "&",
"purchaselimit": "&",
"refreshType": 1,
"money": 40001,
"price": 500
},
{
"id": 14,
"goodid": 60031,
"goodname": "一阶风灵石",
"shop": 7,
"type": 2,
"guildlvlimit": "&",
"purchaselimit": 10,
"refreshType": 2,
"money": 40007,
"price": 500
},
{
"id": 15,
"goodid": 60041,
"goodname": "一阶落星壁",
"shop": 7,
"type": 2,
"guildlvlimit": "&",
"purchaselimit": "&",
"refreshType": 3,
"money": 40007,
"price": 500
},
{
"id": 16,
"goodid": 60051,
"goodname": "一阶紫荧晶",
"shop": 7,
"type": 2,
"guildlvlimit": "&",
"purchaselimit": "&",
"refreshType": 1,
"money": 40007,
"price": 500
},
{
"id": 17,
"goodid": 33001,
"goodname": "铁剑藏宝图",
"shop": 3,
"type": 3,
"guildlvlimit": "&",
"purchaselimit": 10,
"refreshType": 2,
"money": 40001,
"price": 800
},
{
"id": 18,
"goodid": 33002,
"goodname": "铁剑藏宝图",
"shop": 3,
"type": 3,
"guildlvlimit": "&",
"purchaselimit": "&",
"refreshType": 3,
"money": 40001,
"price": 800
},
{
"id": 19,
"goodid": 33003,
"goodname": "铁剑藏宝图",
"shop": 3,
"type": 3,
"guildlvlimit": "&",
"purchaselimit": "&",
"refreshType": 1,
"money": 40001,
"price": 800
},
{
"id": 20,
"goodid": 33004,
"goodname": "铁剑藏宝图",
"shop": 3,
"type": 3,
"guildlvlimit": "&",
"purchaselimit": 10,
"refreshType": 2,
"money": 40007,
"price": 800
},
{
"id": 21,
"goodid": 33093,
"goodname": "追影弓藏宝图",
"shop": 3,
"type": 3,
"guildlvlimit": "&",
"purchaselimit": "&",
"refreshType": 3,
"money": 40007,
"price": 800
},
{
"id": 22,
"goodid": 33094,
"goodname": "追影弓藏宝图",
"shop": 7,
"type": 3,
"guildlvlimit": "&",
"purchaselimit": "&",
"refreshType": 1,
"money": 40007,
"price": 100
},
{
"id": 23,
"goodid": 33095,
"goodname": "追影弓藏宝图",
"shop": 7,
"type": 3,
"guildlvlimit": "&",
"purchaselimit": 10,
"refreshType": 2,
"money": 40001,
"price": 100
},
{
"id": 24,
"goodid": 33096,
"goodname": "追影弓藏宝图",
"shop": 7,
"type": 3,
"guildlvlimit": "&",
"purchaselimit": "&",
"refreshType": 3,
"money": 40001,
"price": 100
},
{
"id": 25,
"goodid": 33125,
"goodname": "黑羽扇藏宝图",
"shop": 7,
"type": 3,
"guildlvlimit": "&",
"purchaselimit": "&",
"refreshType": 1,
"money": 40001,
"price": 100
},
{
"id": 26,
"goodid": 33126,
"goodname": "黑羽扇藏宝图",
"shop": 7,
"type": 3,
"guildlvlimit": "&",
"purchaselimit": "&",
"refreshType": 2,
"money": 40007,
"price": 100
},
{
"id": 27,
"goodid": 17047,
"goodname": "神兵精魄",
"shop": 4,
"type": 4,
"guildlvlimit": "&",
"purchaselimit": 10,
"refreshType": 3,
"money": 40004,
"price": 356
},
{
"id": 28,
"goodid": 17048,
"goodname": "宝甲精魄",
"shop": 4,
"type": 4,
"guildlvlimit": "&",
"purchaselimit": "&",
"refreshType": 1,
"money": 40004,
"price": 456
},
{
"id": 29,
"goodid": 17049,
"goodname": "冠冕精魄",
"shop": 4,
"type": 4,
"guildlvlimit": "&",
"purchaselimit": "&",
"refreshType": 2,
"money": 40004,
"price": 567
},
{
"id": 30,
"goodid": 17050,
"goodname": "行具精魄",
"shop": 6,
"type": 4,
"guildlvlimit": "&",
"purchaselimit": "&",
"refreshType": 3,
"money": 40002,
"price": 123
},
{
"id": 31,
"goodid": 17051,
"goodname": "礼器精魄",
"shop": 6,
"type": 4,
"guildlvlimit": "&",
"purchaselimit": 10,
"refreshType": 1,
"money": 40002,
"price": 234
},
{
"id": 32,
"goodid": 17052,
"goodname": "典籍精魄",
"shop": 6,
"type": 4,
"guildlvlimit": "&",
"purchaselimit": "&",
"refreshType": 2,
"money": 40002,
"price": 345
},
{
"id": 33,
"goodid": 17030,
"goodname": "朱雀符",
"shop": 1,
"type": 5,
"guildlvlimit": "&",
"purchaselimit": "&",
"refreshType": 3,
"money": 31001,
"price": 500
},
{
"id": 34,
"goodid": 17031,
"goodname": "玄武符",
"shop": 1,
"type": 5,
"guildlvlimit": "&",
"purchaselimit": "&",
"refreshType": 1,
"money": 31001,
"price": 750
},
{
"id": 35,
"goodid": 17032,
"goodname": "白虎符",
"shop": 1,
"type": 5,
"guildlvlimit": "&",
"purchaselimit": 10,
"refreshType": 2,
"money": 31001,
"price": 1000
},
{
"id": 36,
"goodid": 17033,
"goodname": "青龙符",
"shop": 1,
"type": 5,
"guildlvlimit": "&",
"purchaselimit": "&",
"refreshType": 3,
"money": 31001,
"price": 1500
},
{
"id": 37,
"goodid": 17034,
"goodname": "铁矿",
"shop": 1,
"type": 5,
"guildlvlimit": "&",
"purchaselimit": "&",
"refreshType": 1,
"money": 31002,
"price": 500
},
{
"id": 38,
"goodid": 17035,
"goodname": "铜矿",
"shop": 1,
"type": 5,
"guildlvlimit": "&",
"purchaselimit": "&",
"refreshType": 2,
"money": 31002,
"price": 750
},
{
"id": 39,
"goodid": 17036,
"goodname": "桃木",
"shop": 1,
"type": 5,
"guildlvlimit": "&",
"purchaselimit": 10,
"refreshType": 3,
"money": 31002,
"price": 1000
},
{
"id": 40,
"goodid": 17037,
"goodname": "扶桑木",
"shop": 1,
"type": 5,
"guildlvlimit": "&",
"purchaselimit": "&",
"refreshType": 1,
"money": 31002,
"price": 1500
},
{
"id": 41,
"goodid": 17038,
"goodname": "打孔器",
"shop": 1,
"type": 5,
"guildlvlimit": "&",
"purchaselimit": "&",
"refreshType": 2,
"money": 31002,
"price": 5000
},
{
"id": 42,
"goodid": 17039,
"goodname": "好运符",
"shop": 1,
"type": 5,
"guildlvlimit": "&",
"purchaselimit": "&",
"refreshType": 3,
"money": 31002,
"price": 5000
},
{
"id": 43,
"goodid": 17040,
"goodname": "洗炼石",
"shop": 1,
"type": 5,
"guildlvlimit": "&",
"purchaselimit": 10,
"refreshType": 1,
"money": 31002,
"price": 5000
},
{
"id": 44,
"goodid": 17041,
"goodname": "乾坤锁",
"shop": 1,
"type": 5,
"guildlvlimit": "&",
"purchaselimit": "&",
"refreshType": 2,
"money": 31002,
"price": 5000
},
{
"id": 45,
"goodid": 601,
"goodname": "精铁拳套",
"shop": 2,
"type": 1,
"guildlvlimit": 3,
"purchaselimit": "&",
"refreshType": 3,
"money": 40005,
"price": 100
},
{
"id": 46,
"goodid": 602,
"goodname": "精铁拳套",
"shop": 2,
"type": 1,
"guildlvlimit": 5,
"purchaselimit": "&",
"refreshType": 1,
"money": 40005,
"price": 100
},
{
"id": 47,
"goodid": 603,
"goodname": "精铁拳套",
"shop": 3,
"type": 1,
"guildlvlimit": "&",
"purchaselimit": 10,
"refreshType": 2,
"money": 40001,
"price": 50
},
{
"id": 48,
"goodid": 2101,
"goodname": "硬布皮帽",
"shop": 3,
"type": 1,
"guildlvlimit": "&",
"purchaselimit": "&",
"refreshType": 3,
"money": 40001,
"price": 50
},
{
"id": 49,
"goodid": 2102,
"goodname": "硬布皮帽",
"shop": 7,
"type": 1,
"guildlvlimit": "&",
"purchaselimit": "&",
"refreshType": 1,
"money": 40001,
"price": 300
},
{
"id": 50,
"goodid": 2103,
"goodname": "硬布皮帽",
"shop": 7,
"type": 1,
"guildlvlimit": "&",
"purchaselimit": "&",
"refreshType": 2,
"money": 40007,
"price": 300
}
]

View File

@@ -0,0 +1,51 @@
[
{
"shopid": 1,
"shopname": "商城",
"shopicon": "shoptubiaozi_shangdian",
"typeid": "5&",
"moneyid": "31001&31002"
},
{
"shopid": 2,
"shopname": "军团商店",
"shopicon": "shoptubiaozi_juntuan",
"typeid": "1&6&9",
"moneyid": "31002&40005"
},
{
"shopid": 3,
"shopname": "远征商店",
"shopicon": "shoptubiaozi_yuanzheng",
"typeid": "1&2&3",
"moneyid": "31002&40001"
},
{
"shopid": 4,
"shopname": "演武商店",
"shopicon": "shoptubiaozi_yanwu",
"typeid": "2&4",
"moneyid": "31002&40004"
},
{
"shopid": 5,
"shopname": "时装商店",
"shopicon": "shoptubiaozi_shizhuang",
"typeid": "7&",
"moneyid": "40006&"
},
{
"shopid": 6,
"shopname": "寻宝商店",
"shopicon": "shoptubiaozi_xunbao",
"typeid": "3&4",
"moneyid": "31002&40002"
},
{
"shopid": 7,
"shopname": "秘境商店",
"shopicon": "shoptubiaozi_mijing",
"typeid": "1&2&3",
"moneyid": "31002&40007"
}
]

View File

@@ -0,0 +1,30 @@
[
{
"typeid": 1,
"name": "武器"
},
{
"typeid": 2,
"name": "宝石"
},
{
"typeid": 3,
"name": "藏宝图"
},
{
"typeid": 4,
"name": "精魄"
},
{
"typeid": 5,
"name": "杂物"
},
{
"typeid": 6,
"name": "防具"
},
{
"typeid": 7,
"name": "时装"
}
]