今日挑战互动接口
This commit is contained in:
@@ -0,0 +1,24 @@
|
||||
import { ActivityModel, ActivityModelType } from '../db/Activity';
|
||||
import { ActivityDailyChallengesModel, ActivityDailyChallengesModelType } from '../db/ActivityDailyChallenges';
|
||||
import { DailyChallengesData, DailyItem } from '../domain/activityField/dailyChallengesField';
|
||||
|
||||
|
||||
/**
|
||||
* 玩家玩家活动数据
|
||||
*
|
||||
* @param {number} serverId 区Id
|
||||
* @param {number} activityId 活动Id
|
||||
* @param {string} roleId 角色Id
|
||||
*
|
||||
*/
|
||||
export async function getPlayerDailyChallengesData(activityId: number, serverId: number, roleId: string) {
|
||||
let activityData: ActivityModelType = await ActivityModel.findActivity(activityId, true);
|
||||
let playerRecords: ActivityDailyChallengesModelType[] = await ActivityDailyChallengesModel.findData(activityId, roleId);
|
||||
|
||||
let playerData = new DailyChallengesData(activityData);
|
||||
playerData.setPlayerRecords(playerRecords);
|
||||
|
||||
return playerData;
|
||||
}
|
||||
|
||||
|
||||
@@ -3,7 +3,7 @@ import { EquipModel } from './../db/Equip';
|
||||
import { resResult, parseGoodStr } from '../pubUtils/util';
|
||||
import { getGoodById } from '../pubUtils/gamedata';
|
||||
import { RoleModel, RoleType } from '../db/Role';
|
||||
import { setAp } from './actionPointService';
|
||||
import { setAp } from './actionPointService';
|
||||
import { calAllHeroCe, pushCalPlayerCe, pushCalAllHeroCe } from './playerCeService';
|
||||
import { ItemModel } from '../db/Item';
|
||||
import { STATUS } from '../consts/statusCode';
|
||||
@@ -21,8 +21,8 @@ import { CreateHeroParam } from '../domain/roleField/hero';
|
||||
export async function handleFixedReward(roleId: string, roleName: string, sid: string, rewardStr: string, multi: number) {
|
||||
let reward = parseGoodStr(rewardStr);
|
||||
let rewards = [];
|
||||
for(let obj of reward)
|
||||
rewards.push({ ...obj, count: Math.ceil(obj.count * multi)});
|
||||
for (let obj of reward)
|
||||
rewards.push({ ...obj, count: Math.ceil(obj.count * multi) });
|
||||
const result = await addItems(roleId, roleName, sid, reward);
|
||||
return result;
|
||||
}
|
||||
@@ -30,8 +30,8 @@ export async function handleFixedReward(roleId: string, roleName: string, sid: s
|
||||
export async function handleCost(roleId: string, sid: string, goods: Array<ItemInter>) {
|
||||
let currencysMap: any = {};
|
||||
let equips: Array<number> = [];
|
||||
let bags: Array<{id: number, count: number}> = [];
|
||||
let uids = [{uid: roleId, sid}];
|
||||
let bags: Array<{ id: number, count: number }> = [];
|
||||
let uids = [{ uid: roleId, sid }];
|
||||
if (!sortConsumes(goods, bags, currencysMap, equips))
|
||||
return false;
|
||||
// 检查货币是否充足
|
||||
@@ -47,44 +47,44 @@ export async function handleCost(roleId: string, sid: string, goods: Array<ItemI
|
||||
//检查装备是否存在
|
||||
if (!!equips.length) {
|
||||
let resEquips = await EquipModel.getEquips(equips);
|
||||
if (resEquips.length < equips.length)
|
||||
if (resEquips.length < equips.length)
|
||||
return false;
|
||||
}
|
||||
//检查并修改道具
|
||||
if(bags.length > 0) {
|
||||
let {hasError, result} = await ItemModel.decreaseItems(roleId, bags);
|
||||
if(hasError) return false;
|
||||
pinus.app.get('channelService').pushMessageByUids('onItemUpdate', resResult(STATUS.SUCCESS, {goods: result} ), uids);
|
||||
if (bags.length > 0) {
|
||||
let { hasError, result } = await ItemModel.decreaseItems(roleId, bags);
|
||||
if (hasError) return false;
|
||||
pinus.app.get('channelService').pushMessageByUids('onItemUpdate', resResult(STATUS.SUCCESS, { goods: result }), uids);
|
||||
}
|
||||
|
||||
//删除装备
|
||||
if (!!equips.length) {
|
||||
await EquipModel.deleteEquips(equips);
|
||||
pinus.app.get('channelService').pushMessageByUids('onEquipDel', resResult(STATUS.SUCCESS, {equips}), uids);
|
||||
pinus.app.get('channelService').pushMessageByUids('onEquipDel', resResult(STATUS.SUCCESS, { equips }), uids);
|
||||
}
|
||||
|
||||
|
||||
//消耗玩家货币
|
||||
if (!!Object.keys(currencysMap).length) {
|
||||
await RoleModel.updateRoleInfo(roleId, currencysMap);
|
||||
pinus.app.get('channelService').pushMessageByUids('onPlayerDataChange', resResult(STATUS.SUCCESS, currencysMap), uids);
|
||||
}
|
||||
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
function sortConsumes(goods: Array<ItemInter>, bags: Array<ItemInter>, currencysMap: any, equips: Array<number>) {
|
||||
for (let good of goods) {
|
||||
let goodInfo = getGoodById(good.id);
|
||||
let {type, table } = ITID.get(goodInfo.itid);
|
||||
let { type, table } = ITID.get(goodInfo.itid);
|
||||
|
||||
if(table == ITEM_TABLE.EQUIP) {
|
||||
if (table == ITEM_TABLE.EQUIP) {
|
||||
if (!!good.seqId) {
|
||||
equips.push(good.seqId);
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
} else if (table == ITEM_TABLE.ITEM) {
|
||||
let index = indexOf(bags, {id: good.id});
|
||||
let index = indexOf(bags, { id: good.id });
|
||||
if (index > 0) {
|
||||
bags[index].count = bags[index].count + good.count;
|
||||
} else {
|
||||
@@ -96,7 +96,7 @@ function sortConsumes(goods: Array<ItemInter>, bags: Array<ItemInter>, currencys
|
||||
let curname = getCurNameById(goodInfo.good_id);
|
||||
if (!!curname) {
|
||||
if (curname != 'ap') {
|
||||
currencysMap[curname] = (currencysMap[curname]||0) + good.count;
|
||||
currencysMap[curname] = (currencysMap[curname] || 0) + good.count;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
@@ -114,18 +114,18 @@ export async function addItems(roleId: string, roleName: string, sid: string, go
|
||||
let bags: Array<BagInter> = [];
|
||||
let skins: Array<number> = [];
|
||||
let figures: Array<number> = [];
|
||||
let uids = [{uid: roleId, sid}];
|
||||
let uids = [{ uid: roleId, sid }];
|
||||
sortItems(goods, bags, skins, figures, currencysMap, equips, showItems);
|
||||
let equipInfos = [], taskPushMessage = [];
|
||||
for (let equip of equips) {
|
||||
let { equipInfo, pushMessage } = await addEquips(roleId, roleName, equip);
|
||||
showItems.push({seqId: equipInfo.seqId, id: equip.id, count: 1});
|
||||
showItems.push({ seqId: equipInfo.seqId, id: equip.id, count: 1 });
|
||||
equipInfos.push(equipInfo);
|
||||
taskPushMessage.concat(pushMessage);
|
||||
}
|
||||
//装备推送
|
||||
if (!!equipInfos.length)
|
||||
pinus.app.get('channelService').pushMessageByUids('onEquipAdd', resResult(STATUS.SUCCESS, {equipInfos}), uids);
|
||||
if (!!equipInfos.length)
|
||||
pinus.app.get('channelService').pushMessageByUids('onEquipAdd', resResult(STATUS.SUCCESS, { equipInfos }), uids);
|
||||
|
||||
pushTaskUpdate(roleId, sid, null, taskPushMessage);
|
||||
|
||||
@@ -134,7 +134,7 @@ export async function addItems(roleId: string, roleName: string, sid: string, go
|
||||
let role = await RoleModel.findByRoleId(roleId);
|
||||
for (let key in currencysMap) {
|
||||
if (key == 'ap') {
|
||||
let {ap} = await setAp(Date.now(), roleId, sid, null, currencysMap[key]);
|
||||
let { ap } = await setAp(Date.now(), roleId, sid, null, currencysMap[key]);
|
||||
currencysMap.ap = ap;
|
||||
} else {
|
||||
currencysMap[key] += role[key];
|
||||
@@ -147,17 +147,17 @@ export async function addItems(roleId: string, roleName: string, sid: string, go
|
||||
let bagInfos = [];
|
||||
for (let item of bags) {
|
||||
let bagInfo = await addBags(roleId, roleName, item);
|
||||
showItems.push({id: item.id, count: item.count});
|
||||
showItems.push({ id: item.id, count: item.count });
|
||||
bagInfos.push(bagInfo);
|
||||
}
|
||||
//背包除去装备推送
|
||||
if (!!bagInfos.length)
|
||||
pinus.app.get('channelService').pushMessageByUids('onItemUpdate', resResult(STATUS.SUCCESS, {goods: bagInfos}), uids);
|
||||
if (!!bagInfos.length)
|
||||
pinus.app.get('channelService').pushMessageByUids('onItemUpdate', resResult(STATUS.SUCCESS, { goods: bagInfos }), uids);
|
||||
|
||||
|
||||
let figureInfo = await addFigure(roleId, figures);
|
||||
for (let id of figures) {//皮肤推送
|
||||
showItems.push({id, count: 1});
|
||||
showItems.push({ id, count: 1 });
|
||||
}
|
||||
if (!!figureInfo && (figureInfo.heads.length > 0 || figureInfo.frames.length > 0 || figureInfo.spines.length > 0)) {
|
||||
pinus.app.get('channelService').pushMessageByUids('onHeadChange', resResult(STATUS.SUCCESS, { ...figureInfo }), uids);
|
||||
@@ -169,7 +169,7 @@ export async function addItems(roleId: string, roleName: string, sid: string, go
|
||||
for (let skinId of skins) {//皮肤推送
|
||||
let result = await addSkins(roleId, skinId);
|
||||
if (!!result) {
|
||||
showItems.push({id: skinId, count: 1});
|
||||
showItems.push({ id: skinId, count: 1 });
|
||||
skinInfos.push(result);
|
||||
addSkinIds.push(skinId);
|
||||
}
|
||||
@@ -178,12 +178,12 @@ export async function addItems(roleId: string, roleName: string, sid: string, go
|
||||
let unlockedType = addSkinIds.map(cur => { return { type: FIGURE_UNLOCK_CONDITION.GET_SKIN, paramSkinId: cur } });
|
||||
await unlockFigure(sid, roleId, unlockedType);
|
||||
calAllHeroCe(HERO_SYSTEM_TYPE.ADD_SKIN, sid, roleId, {}, addSkinIds);
|
||||
pinus.app.get('channelService').pushMessageByUids('onHeroSkinChange', resResult(STATUS.SUCCESS, {skinInfos}), uids);
|
||||
pinus.app.get('channelService').pushMessageByUids('onHeroSkinChange', resResult(STATUS.SUCCESS, { skinInfos }), uids);
|
||||
}
|
||||
return showItems;
|
||||
}
|
||||
|
||||
function sortItems (goods: Array<ItemInter>, bags: Array<BagInter>, skins: Array<number>, figures: Array<number>, currencysMap: any, equips: Array<EquipInter>, showItems: Array<ItemInter>) {
|
||||
function sortItems(goods: Array<ItemInter>, bags: Array<BagInter>, skins: Array<number>, figures: Array<number>, currencysMap: any, equips: Array<EquipInter>, showItems: Array<ItemInter>) {
|
||||
for (let good of goods) {
|
||||
let goodInfo = gameData.goods.get(good.id);
|
||||
// 道具不存在时先跳过
|
||||
@@ -192,18 +192,18 @@ function sortItems (goods: Array<ItemInter>, bags: Array<BagInter>, skins: Array
|
||||
continue;
|
||||
}
|
||||
|
||||
let {type, table, isCurrency} = ITID.get(goodInfo.itid);
|
||||
if(table == ITEM_TABLE.EQUIP) {
|
||||
let { type, table, isCurrency } = ITID.get(goodInfo.itid);
|
||||
if (table == ITEM_TABLE.EQUIP) {
|
||||
for (let i = 0; i < good.count; i++) {
|
||||
equips.push({id: good.id, ...goodInfo});
|
||||
equips.push({ id: good.id, ...goodInfo });
|
||||
}
|
||||
} else if (table == ITEM_TABLE.ITEM) {
|
||||
|
||||
let index = findIndex(bags, {id: good.id});
|
||||
let index = findIndex(bags, { id: good.id });
|
||||
if (index > 0) {
|
||||
bags[index].count = bags[index].count + good.count;
|
||||
} else {
|
||||
bags.push({id: good.id, count: good.count, itemName: goodInfo.name, hid: goodInfo.hid||0, type});
|
||||
bags.push({ id: good.id, count: good.count, itemName: goodInfo.name, hid: goodInfo.hid || 0, type });
|
||||
}
|
||||
|
||||
} else if (table == ITEM_TABLE.HERO) {
|
||||
@@ -218,16 +218,16 @@ function sortItems (goods: Array<ItemInter>, bags: Array<BagInter>, skins: Array
|
||||
if (!!isCurrency) {
|
||||
let curname = getCurNameById(goodInfo.good_id);
|
||||
if (!!curname) {
|
||||
let index = findIndex(showItems, {id: good.id});
|
||||
let index = findIndex(showItems, { id: good.id });
|
||||
if (index > 0) {
|
||||
showItems[index].count = showItems[index].count + good.count;
|
||||
} else {
|
||||
showItems.push(good);
|
||||
}
|
||||
currencysMap[curname] = (currencysMap[curname]||0 )+ good.count;
|
||||
currencysMap[curname] = (currencysMap[curname] || 0) + good.count;
|
||||
}
|
||||
} else {
|
||||
if (type == CONSUME_TYPE.HEAD || type == CONSUME_TYPE.FRAME || type == CONSUME_TYPE.SPINE ) {
|
||||
if (type == CONSUME_TYPE.HEAD || type == CONSUME_TYPE.FRAME || type == CONSUME_TYPE.SPINE) {
|
||||
let index = indexOf(figures, good.id);
|
||||
if (index == -1) {
|
||||
figures.push(good.id);
|
||||
@@ -238,18 +238,18 @@ function sortItems (goods: Array<ItemInter>, bags: Array<BagInter>, skins: Array
|
||||
}
|
||||
}
|
||||
|
||||
export async function decreaseItems(roleId: string, sid: string, bags: Array<{id: number, count:number, ratio?: number}>) {
|
||||
let uids = [{uid: roleId, sid}];
|
||||
if(bags.length > 0) {
|
||||
let {hasError, result} = await ItemModel.decreaseItems(roleId, bags);
|
||||
if(hasError) return true;
|
||||
pinus.app.get('channelService').pushMessageByUids('onItemUpdate', resResult(STATUS.SUCCESS, {goods: result} ), uids);
|
||||
export async function decreaseItems(roleId: string, sid: string, bags: Array<{ id: number, count: number, ratio?: number }>) {
|
||||
let uids = [{ uid: roleId, sid }];
|
||||
if (bags.length > 0) {
|
||||
let { hasError, result } = await ItemModel.decreaseItems(roleId, bags);
|
||||
if (hasError) return true;
|
||||
pinus.app.get('channelService').pushMessageByUids('onItemUpdate', resResult(STATUS.SUCCESS, { goods: result }), uids);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
export async function checkGoods(roleId: string, goodIds: Array<number>) {
|
||||
export async function checkGoods(roleId: string, goodIds: Array<number>) {
|
||||
let equipIds: Array<number> = [];
|
||||
let itemIds: Array<number> = [];
|
||||
let hids: Array<number> = [];
|
||||
@@ -258,7 +258,7 @@ export async function checkGoods(roleId: string, goodIds: Array<number>) {
|
||||
let goodInfo = getGoodById(goodId);
|
||||
if (!!goodInfo) {
|
||||
let { table } = ITID.get(goodInfo.itid);
|
||||
if(table == ITEM_TABLE.EQUIP) {
|
||||
if (table == ITEM_TABLE.EQUIP) {
|
||||
equipIds.push(goodId);
|
||||
} else if (table == ITEM_TABLE.ITEM) {
|
||||
itemIds.push(goodId);
|
||||
@@ -270,24 +270,24 @@ export async function checkGoods(roleId: string, goodIds: Array<number>) {
|
||||
|
||||
if (!!hids.length) {
|
||||
let heros = await HeroModel.findByHidRange(hids, roleId);
|
||||
if (heros.length < hids.length)
|
||||
if (heros.length < hids.length)
|
||||
return false;
|
||||
}
|
||||
|
||||
//检查装备是否存在
|
||||
if (!!equipIds.length) {
|
||||
let resEquips = await EquipModel.getEquipsByIds(roleId, equipIds);
|
||||
resEquips = uniq(resEquips, function(resEquip){
|
||||
return resEquip.id;
|
||||
resEquips = uniq(resEquips, function (resEquip) {
|
||||
return resEquip.id;
|
||||
});
|
||||
if (resEquips.length < equipIds.length)
|
||||
if (resEquips.length < equipIds.length)
|
||||
return false;
|
||||
}
|
||||
//检查并修改道具
|
||||
if(itemIds.length > 0) {
|
||||
if (itemIds.length > 0) {
|
||||
let items = await ItemModel.findbyRoleAndIds(roleId, itemIds);
|
||||
if (items.length < itemIds.length)
|
||||
return false;
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
@@ -300,7 +300,7 @@ export async function unlockFigure(sid: string, roleId: string, conditions: { ty
|
||||
|
||||
export async function pushFigureUpdate(roleId: string, sid: string, figureInfo: { heads: Figure[], frames: Figure[], spines: Figure[] }) {
|
||||
if (!!figureInfo && (figureInfo.heads.length > 0 || figureInfo.frames.length > 0 || figureInfo.spines.length > 0)) {
|
||||
let uids = [{uid: roleId, sid}];
|
||||
let uids = [{ uid: roleId, sid }];
|
||||
pinus.app.get('channelService').pushMessageByUids('onHeadChange', resResult(STATUS.SUCCESS, { ...figureInfo }), uids);
|
||||
}
|
||||
}
|
||||
@@ -316,22 +316,26 @@ export async function createHeroes(roleId: string, roleName: string, sid: string
|
||||
|
||||
let hids = heroInfo.map(cur => cur.hid);
|
||||
let userHeroesMap = await HeroModel.findMapByHidRange(hids, roleId);
|
||||
|
||||
|
||||
|
||||
let newHeroInfo: CreateHeroParam[] = [], pieces: ItemInter[] = [];
|
||||
for(let h of heroInfo) {
|
||||
if(userHeroesMap.has(h.hid)) {
|
||||
let {pieceId, count} = transPiece(h.hid);
|
||||
pieces.push({ id: pieceId, count });
|
||||
for (let h of heroInfo) {
|
||||
if (userHeroesMap.has(h.hid)) {
|
||||
let { pieceId, count } = transPiece(h.hid);
|
||||
pieces.push({ id: pieceId, count: count * h.count });
|
||||
} else {
|
||||
newHeroInfo.push(h)
|
||||
userHeroesMap.set(h.hid, null);
|
||||
if (h.count > 1) {
|
||||
let { pieceId, count } = transPiece(h.hid);
|
||||
pieces.push({ id: pieceId, count: count * (h.count - 1) });
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
let resultHeroes: HeroType[] = [], resultItems: ItemInter[] = [];
|
||||
if(newHeroInfo.length > 0) {
|
||||
|
||||
if (newHeroInfo.length > 0) {
|
||||
|
||||
let { heroes, role, figureInfo, calHeroResults, calAllHeroResults, taskPushMessage } = await pubCreateHeroes(roleId, roleName, serverId, newHeroInfo, funcs);
|
||||
|
||||
let r = new Rank(REDIS_KEY.HERO_NUM_RANK, { serverId });
|
||||
@@ -339,18 +343,18 @@ export async function createHeroes(roleId: string, roleName: string, sid: string
|
||||
|
||||
await pushFigureUpdate(roleId, sid, figureInfo);
|
||||
|
||||
for(let calHeroResult of calHeroResults) {
|
||||
for (let calHeroResult of calHeroResults) {
|
||||
await pushCalPlayerCe(roleId, sid, calHeroResult);
|
||||
}
|
||||
for(let calAllHeroResult of calAllHeroResults) {
|
||||
for (let calAllHeroResult of calAllHeroResults) {
|
||||
await pushCalAllHeroCe(roleId, sid, calAllHeroResult);
|
||||
}
|
||||
|
||||
pushTaskUpdate(roleId, sid, null, taskPushMessage);
|
||||
resultHeroes = heroes;
|
||||
}
|
||||
}
|
||||
|
||||
if(pieces.length > 0) {
|
||||
if (pieces.length > 0) {
|
||||
let goods = await addItems(roleId, roleName, sid, pieces);
|
||||
resultItems = goods;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user