形象:解锁头像相框形象

This commit is contained in:
luying
2021-03-11 10:34:10 +08:00
parent e888ab916d
commit 95f4221217
13 changed files with 145 additions and 65 deletions

View File

@@ -110,6 +110,7 @@ export class EntryHandler {
let apJson = await getAp(Date.now(), role.roleId);
role['apJson'] = apJson;
role['mails'] = mails;
if(!role['showLineup']) role['showLineup'] = role.topLineup.map(cur => cur.hid);
const recentPrivateChats = await recentPrivateChatInfos(role.roleId, role.roleName);
if (recentPrivateChats) {

View File

@@ -456,9 +456,9 @@ export class RoleHandler {
let { frames } = role;
let curFrame = frames.find(cur => cur.id == id);
if(!curFrame) return resResult(STATUS.HEAD_NOT_FOUND);
if(curFrame.enable) return resResult(STATUS.HEAD_IS_WEARING);
if(!curFrame.status) return resResult(STATUS.HEAD_IS_LOCKED);
if(!curFrame) return resResult(STATUS.FRAME_NOT_FOUND);
if(curFrame.enable) return resResult(STATUS.FRAME_IS_WEARING);
if(!curFrame.status) return resResult(STATUS.FRAME_IS_LOCKED);
let oldHead = frames.find(cur => cur.enable); // 穿戴中的头像
if(oldHead) {
@@ -478,18 +478,20 @@ export class RoleHandler {
let role = await RoleModel.findByRoleId(roleId, ROLE_SELECT.GET_HEADS);
if(!role) return resResult(STATUS.ROLE_NOT_FOUND);
let { spine } = role;
if(spine == id) {
return resResult(STATUS.SPINE_IS_WEARING);
}
let checkSkinResult = await HeroModel.checkSkin(roleId, spine);
if(!checkSkinResult) {
return resResult(STATUS.SPINE_NOT_FOUND);
}
let { spines } = role;
let curSpine = spines.find(cur => cur.id == id);
if(!curSpine) return resResult(STATUS.SPINE_NOT_FOUND);
if(curSpine.enable) return resResult(STATUS.SPINE_IS_WEARING);
if(!curSpine.status) return resResult(STATUS.SPINE_IS_LOCKED);
role = await RoleModel.updateRoleInfo(roleId, { spine: id });
let oldHead = spines.find(cur => cur.enable); // 穿戴中的头像
if(oldHead) {
oldHead.enable = false;
}
curSpine.enable = true;
return resResult(STATUS.SUCCESS, { spine: role.spine });
role = await RoleModel.updateRoleInfo(roleId, { spines });
return resResult(STATUS.SUCCESS, { spines: role.spines, spine: role.spine });
}
}

View File

@@ -265,9 +265,9 @@ export async function recentPrivateChatInfos(roleId: string, roleName: string) {
const roleInfos = await RoleModel.findRoleByField('roleId', recentPrivateChats.map(chat => { return chat.targetRoleId }));
const chatInfos = recentPrivateChats.map( chat => {
for (let { roleId: targetRoleId, quitTime, roleName: targetRoleName, title, guildName, headHid, sHid, lv } of roleInfos) {
for (let { roleId: targetRoleId, quitTime, roleName: targetRoleName, title, guildName, head, frame, spine, lv } of roleInfos) {
if (targetRoleId === chat.targetRoleId) {
return { ...chat, quitTime, targetRoleName, title, guildName, headHid, sHid, lv };
return { ...chat, quitTime, targetRoleName, title, guildName, head, frame, spine, lv };
}
}
});

View File

@@ -4,7 +4,11 @@ import { getRandNum, getRandomArr } from '../pubUtils/util';
import { TERAPH_RANDOM } from "../consts/consts";
import { indexOf } from 'underscore';
import { DicTeraph } from '../pubUtils/dictionary/DicTeraph';
import { Teraph } from '../db/Role';
import { Teraph, RoleType, RoleModel } from '../db/Role';
import { ROLE_SELECT, FIGURE_UNLOCK_CONDITION, ITID, CONSUME_TYPE } from '../consts';
import { gameData } from '../pubUtils/data';
import { Figure } from '../domain/dbGeneral';
import { getBeforeDaySeconds } from '../pubUtils/timeUtil';
const TERAPH_STRENGTHEN = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10];
/**
* 计算强化次数和消耗
@@ -85,4 +89,74 @@ export function addUserToChannel(channel: Channel, user: ChannelUser) {
if (users.indexOf(uid) === -1) {
channel.add(uid, sid);
}
}
/**
* 解锁头像/相框
* @param type 解锁类型(获得武将/好感达到)
* @param num 参数武将id/好感等级)
*/
export async function unlockFigure(roleId: string, type: number, num: number, role?: RoleType) {
if(!role || !role.heads || !role.frames) {
role = await RoleModel.findByRoleId(roleId, ROLE_SELECT.GET_HEADS);
}
let { heads, frames, spines } = role;
let canUnLockList = gameData.figureCondition.get(type);
if(canUnLockList) {
for(let {id, param} of canUnLockList) {
let flag = false; // 是否达成条件
if(type == FIGURE_UNLOCK_CONDITION.GET_HERO) {
if(num == param) flag = true;
} else if (type == FIGURE_UNLOCK_CONDITION.HERO_FAVOR) {
if(num >= param) flag = true;
}
if(!flag) continue;
let dicGood = gameData.goods.get(id);
if(!dicGood) continue;
let dicItid = ITID.get(dicGood.itid);
if(!dicItid) continue;
if(dicItid.type == CONSUME_TYPE.HEAD) {
unlockSingleFigure(heads, id, type);
} else if (dicItid.type == CONSUME_TYPE.FRAME) {
unlockSingleFigure(frames, id, type);
} else if (dicItid.type == CONSUME_TYPE.SPINE) {
unlockSingleFigure(spines, id, type);
} else {
continue;
}
}
role = await RoleModel.updateRoleInfo(roleId, { heads, frames, spines });
}
}
function unlockSingleFigure(dbFigures: Figure[], id: number, type: number) {
let figure = dbFigures.find(cur => cur.id == id);
if(!figure) {
figure = new Figure(id, false);
dbFigures.push(figure);
}
if(figure.unlocked) return; // 已解锁过
if(figure.unlockedType.includes(type)) return;
figure.unlockedType.push(type);
let dicGoods = gameData.goods.get(id);
let hasUnlockedAll = true;
for(let {type} of dicGoods.condition) {
if(!figure.unlockedType.includes(type)) {
hasUnlockedAll = false; break;
}
}
if(hasUnlockedAll) {
figure.unlocked = true;
if(dicGoods.timeLimit) {
figure.time = getBeforeDaySeconds(-1 * dicGoods.timeLimit); // timeLimit天以后
}
}
}

View File

@@ -28,6 +28,9 @@ export const CONSUME_TYPE = {
PIECE: 8, // 装备碎片
JEWEL: 9, //宝石
FRIEND_FAVOUR: 10, // 好友道具
HEAD: 11, // 头像
FRAME: 12, // 相框
SPINE: 13, // 形象
};
export enum ROLE_TERAPH {
@@ -127,7 +130,10 @@ const itid_array = [
{ id: 46, name: '礼器宝石', table: 'item', type: CONSUME_TYPE.JEWEL },
{ id: 47, name: '典籍宝石', table: 'item', type: CONSUME_TYPE.JEWEL },
{ id: 48, name: '灵玄石', table: 'item', type: CONSUME_TYPE.JEWEL },
{ id: 49, name: '玩家好感道具', table: 'item', type: CONSUME_TYPE.FRIEND_FAVOUR }
{ id: 49, name: '玩家好感道具', table: 'item', type: CONSUME_TYPE.FRIEND_FAVOUR },
{ id: 50, name: '形象', table: 'hero', type: CONSUME_TYPE.FRIEND_FAVOUR },
{ id: 51, name: '相框', table: 'hero', type: CONSUME_TYPE.FRIEND_FAVOUR },
{ id: 52, name: '玩家形象', table: 'hero', type: CONSUME_TYPE.FRIEND_FAVOUR }
];
export const ITID = new Map<number, {id: number, name: string, table: string, type?: number, isCurrency?: boolean, equipJewel?: number}>();
@@ -235,4 +241,11 @@ export function getDropItems() {
{ id:2008 ,count: 2 },{ id:2012 ,count: 2 },{ id:2208 ,count: 2 },{ id:2016 ,count: 2 },{ id:2120 ,count: 2 },{ id:2220 ,count: 2 },{ id:50031, count: 1000}
]
return items;
}
// 头像/相框 获取条件
export enum FIGURE_UNLOCK_CONDITION {
GET_HERO = 1, // 获取武将
HERO_FAVOR = 2, // 武将好感度达到
}

View File

@@ -1,7 +1,7 @@
export enum ROLE_SELECT {
// 初始登录数据
ENTRY = 'serverId userInfo.uid userInfo.tel userInfo.serverType ce topLineupCe teraphs roleId roleName tili lv exp gold coin vLv title hasGuild funcs eventStatus heads head frames frame spine guildCode frdCnt',
ENTRY = 'serverId userInfo.uid userInfo.tel userInfo.serverType ce topLineup topLineupCe teraphs roleId roleName tili lv exp gold coin vLv title hasGuild funcs eventStatus heads head frames frame spines spine guildCode frdCnt showLineup',
// 玩家列表显示基础数据
SHOW_SIMPLE = 'roleId roleName ce head frame spine lv title job quitTime vLv guildName serverId userInfo.serverType',
// 显示申请需要的信息
@@ -12,7 +12,7 @@ export enum ROLE_SELECT {
GET_ROLE_ID = 'roleId',
GET_MY_SERVER = 'lv serverId userInfo.serverType',
COM_BATTLE = 'lv head frame spine topLineupCe',
GET_HEADS = 'heads head frames frame spine'
GET_HEADS = 'heads head frames frame spines spine'
};
export enum HERO_SELECT {

View File

@@ -423,4 +423,4 @@ export enum DEFAULT_DEVICE_ID {
}
// 阵容人数限制
export const LINEUP_NUM = 6;
export const LINEUP_NUM = 6;

View File

@@ -278,8 +278,9 @@ export const STATUS = {
FRAME_NOT_FOUND: { code: 30805, simStr: '未找到相框' },
FRAME_IS_WEARING: { code: 30806, simStr: '相框已设置中' },
FRAME_IS_LOCKED: { code: 30807, simStr: '相框未解锁' },
SPINE_IS_WEARING: { code: 30808, simStr: '形象已设置中' },
SPINE_NOT_FOUND: { code: 30809, simStr: '形象未解锁' },
SPINE_NOT_FOUND: { code: 30808, simStr: '未找到形象' },
SPINE_IS_WEARING: { code: 30809, simStr: '形象已设置中' },
SPINE_IS_LOCKED: { code: 30810, simStr: '形象未解锁' },
// 社交相关状态 40000 - 49999
SYS_CHANNEL_AUTH_NOT_ENOUGH: {code: 40000, simStr: '无法在系统频道发送消息'},

View File

@@ -266,11 +266,6 @@ export default class Hero extends BaseModel {
const user: HeroType[] = await HeroModel.find(searchObj).lean(lean);
return user;
}
public static async checkSkin(roleId: string, skinId: number) {
let hero = await HeroModel.findOne({ roleId, 'skins.id': skinId }).lean();
return !!hero;
}
}
export const HeroModel = getModelForClass(Hero);

View File

@@ -124,12 +124,12 @@ export default class Role extends BaseModel {
@prop({ required: true, type: Number })
showLineup: number[]; // 展示阵容
@prop({ required: true, type: Figure, default: [] })
@prop({ required: true, type: Figure, default: [], _id: false })
heads: Figure[]; // 拥有头像列表
@prop({ required: true, type: Figure, default: [] })
@prop({ required: true, type: Figure, default: [], _id: false })
frames: Figure[]; // 拥有相框列表
@prop({ required: true, default: FIGURE.DEFAULT_SPINE })
spine: number; // 显示形象
@prop({ required: true, type: Figure, default: [], _id: false })
spines: Figure[]; // 拥有的形象
public get head () { // 虚拟字段head 当前头像
let curHead = this.heads?.find(cur => cur.enable && cur.time > nowSeconds());
@@ -141,6 +141,11 @@ export default class Role extends BaseModel {
return curFrame?curFrame.id: FIGURE.DEFAULT_FRAME;
}
public get spine () { // 虚拟字段spine 当前形象
let curSpine = this.spines?.find(cur => cur.enable && cur.time > nowSeconds());
return curSpine?curSpine.id: FIGURE.DEFAULT_SPINE;
}
@prop({ required: true, default: 0 })
exp: number; // 经验值
@prop({ required: true, default: 1 })

View File

@@ -208,46 +208,24 @@ export class Figure {
id: number; // 头像id
@prop({ required: true, default: false })
enable: boolean = false; // 是否启用
@prop({ required: false, default: 0 })
@prop({ required: false })
time?: number; // 到期时间
@prop({ required: true, default: [] })
unlockedType: number[] = []; // 当前已经解锁了的type
@prop({ required: true, default: false })
unlocked: boolean = false; // 是否已解锁
public get status () { // 虚拟字段status当前头像是否已经解锁
let dicGoods = gameData.goods.get(this.id);
if(!dicGoods) return false;
let hasUnlockedAll = true;
for(let {type} of dicGoods.condition) {
if(!this.unlockedType.includes(type)) {
hasUnlockedAll = false; break;
}
}
if(!hasUnlockedAll) return true;
if(dicGoods.timeLimit) { // 超时
if(this.time < nowSeconds()) return false;
}
if(!this.unlocked) return this.unlocked; // 未解锁
if(this.time && this.time < nowSeconds()) return false; // 已解锁过时
return true;
}
constructor(id: number, unlockedType?: number[]) {
let dicGoods = gameData.goods.get(id);
if(dicGoods) {
this.id = id;
if(!unlockedType) unlockedType = dicGoods.condition.map(cur => cur.type);
this.unlockedType = unlockedType;
let hasUnlockedAll = true;
for(let {type} of dicGoods.condition) {
if(!this.unlockedType.includes(type)) {
hasUnlockedAll = false; break;
}
}
if(hasUnlockedAll && dicGoods.timeLimit) {
this.time = getBeforeDaySeconds(-1 * dicGoods.timeLimit); // timeLimit天以后
}
}
constructor(id: number, unlocked: boolean, time?: number, enable = false) {
this.id = id;
this.unlocked = unlocked;
if(time) this.time = time;
this.enable = enable;
}
}

View File

@@ -11,6 +11,9 @@ export class RankParam {
spine: number = FIGURE.DEFAULT_SPINE;
title: number;
headHid: number = 19; // TODO 等客户端接完将这些删除
sHid: number = 19;
constructor(roleName: string, lv: number, vLv: number, head: number, frame: number, spine: number, title: number) {
this.roleName = roleName;
this.lv = lv;
@@ -34,6 +37,10 @@ export class GuildRankParam {
head: number;
frame: number;
spine: number;
headHid: number;
sHid: number;
}
constructor(icon: number, name: string, lv: number, leader: {roleName: string, title: number, lv: number, head: number, frame: number, spine: number}) {
@@ -53,6 +60,9 @@ export class GuildLeader {
frame: number;
spine: number;
headHid: number = 19;
sHid: number = 19;
constructor(leader: {roleName: string, title: number, lv: number, head: number, frame: number, spine: number}) {
this.roleName = leader.roleName;
this.title = leader.title;

View File

@@ -1,5 +1,5 @@
import { dicHero } from "./dictionary/DicHero";
import { dicGoods, blueprt, dicJewel } from "./dictionary/DicGoods";
import { dicGoods, blueprt, dicJewel, figureCondition } from "./dictionary/DicGoods";
import { dicBlueprtCompose } from "./dictionary/DicBlueprtCompose";
import { dicBlueprtPossibility } from "./dictionary/DicBlueprtPossibility";
import { dicDaily } from "./dictionary/DicDaily";
@@ -139,6 +139,7 @@ export const gameData = {
armyDonateBox: dicArmyDonate,
roleFriend: dicRoleFriend,
roleFriendLv: dicRoleFriendLv,
figureCondition: figureCondition
};
// 在此提供一些原先在gamedata中提供的方法以便更方便获取gameData数据