underscore读取,排行榜保护

This commit is contained in:
mamengke01
2021-01-12 14:12:19 +08:00
parent 58f3e94fc0
commit 22f2eed34e
16 changed files with 53 additions and 51 deletions

View File

@@ -1,5 +1,5 @@
import {Application, BackendSession} from 'pinus';
const _ = require('underscore');
import { uniq, findWhere, findIndex } from 'underscore';
import { gameData, getPvpBoxs } from '../../../pubUtils/data';
import { refreshEnemies, getEnemies, getLvByScore, defaultHeroes, comsumeChallengeCnt, refresh, findPvpDefByRoleId, checkRoleIsRobot, getRefOppCnt, findPvpDefAllByRoleId, generPVPOppRecInfo, generMyRecInfo, getRobotLineup, getPlayerLineup } from '../../../services/pvpService';
import { RoleModel, RoleType } from '../../../db/Role';
@@ -63,7 +63,7 @@ export class PvpHandler {
async getData (msg: {}, session: BackendSession) {
let roleId = session.get('roleId');
let {pvpDefense, warId} = await findPvpDefAllByRoleId(roleId);
let { pvpDefense, warId } = await findPvpDefAllByRoleId(roleId);
let oppPlayers = await getEnemies(pvpDefense.oppPlayers, pvpDefense.winStreakNum);
let { isDefaultHero, heroes, score, pLv, winStreakNum, refOppCnt, challengeCnt, challengeRefTime, receivedBox, hisScore, heroScores, isFirstEntry, seasonNum, seasonEndTime } = pvpDefense;
if (isFirstEntry) {
@@ -262,7 +262,7 @@ export class PvpHandler {
if (heroes.length > 5) {
return resResult(STATUS.WRONG_PARMS);
}
heroes = _.uniq(heroes, function(item) {
heroes = uniq(heroes, function(item) {
return item.order;
});
let { heroes: defHeros, seasonEndTime, challengeCnt: lastChallengeCnt, challengeRefTime: lastChallengeRefTime } = await PvpDefenseModel.findByRoleId(roleId);
@@ -275,8 +275,8 @@ export class PvpHandler {
return resResult(STATUS.SUCCESS, { heroes: resHeroes, challengeCnt, challengeRefTime, isDefaultHero} );
} else {
for (let dataId = PVP_HERO_POS.START; dataId <= PVP_HERO_POS.END; dataId++) {
let index = _.findIndex(heroes, {dataId});
let defIndex = _.findIndex(defHeros, {dataId});
let index = findIndex(heroes, {dataId});
let defIndex = findIndex(defHeros, {dataId});
if (defIndex == -1) {
defIndex = defHeros.length;
defHeros.push({actorId:0, order:0,ce:0, hero:null,dataId});
@@ -396,7 +396,7 @@ export class PvpHandler {
let roleName = session.get('roleName');
let { hisScore, receivedBox, challengeCnt: lastChallengeCnt, challengeRefTime: lastChallengeRefTime, seasonEndTime } = await PvpDefenseModel.findByRoleIdIncludeAll(roleId);
let pvpBoxs = getPvpBoxs();
let pvpBox = _.findWhere(pvpBoxs, {id})
let pvpBox = findWhere(pvpBoxs, {id});
if (hisScore < pvpBox.score) {
return resResult(STATUS.PVP_NOT_REACH_BOX_SCORE);
}

View File

@@ -14,7 +14,7 @@ import { EQUIP } from "../../../pubUtils/dicParam";
import { ITID, SPEICAL_ITEM, RANDOM_SE_COUNT } from "../../../consts/constModules/itemConst";
import { changeEquip, dressEquip, checkMaterialEnough, takeOffEquipAndCalPlayerCe } from "../../../services/equipService";
const _ = require('underscore');
import { indexOf, findIndex } from 'underscore';
export default function (app: Application) {
return new EquipHandler(app);
@@ -433,9 +433,9 @@ export class EquipHandler {
let { jobid } = gameData.hero.get(hid);
let { job_class } = getHeroJob(jobid);
let { classId } = getHeroEquipByClassId(goodInfo.itid);
if (_.indexOf(classId, job_class) < 0)
if (indexOf(classId, job_class) < 0)
return resResult(STATUS.EQUIP_NOT_EQUIPED_HERO);
let index = _.findIndex(hero.ePlace, { id });
let index = findIndex(hero.ePlace, { id });
if (index < 0)
return resResult(STATUS.WRONG_PARMS);
let equipOffInfo = <EquipType>hero.ePlace[index].equip;
@@ -460,7 +460,7 @@ export class EquipHandler {
let roleId: string = session.get('roleId');
let sid: string = session.get('sid');
let equip = await EquipModel.getEquip(eid);
let index = _.findIndex(equip.holes, { id });
let index = findIndex(equip.holes, { id });
if (index < 0)
return resResult(STATUS.EQUIP_HOLE_NOT_FIND);
if (equip.holes[index].isOpen)
@@ -494,7 +494,7 @@ export class EquipHandler {
let jewelInfo = getGoodById(jewel);
if (jewelInfo.itid != equipJewel)
return resResult(STATUS.EQUIP_NOT_MATCH_JEWEL);
let index = _.findIndex(equip.holes, { id });
let index = findIndex(equip.holes, { id });
if (index < 0)
return resResult(STATUS.EQUIP_HOLE_NOT_FIND);
if (!equip.holes[index].isOpen)
@@ -549,7 +549,7 @@ export class EquipHandler {
let sid: string = session.get('sid');
let goods: Array<{ id: number, count: number }> = [];
let equip = await EquipModel.getEquip(eid);
let index = _.findIndex(equip.holes, { id });
let index = findIndex(equip.holes, { id });
if (index > 0)
return resResult(STATUS.EQUIP_HOLE_NOT_FIND);
let jewel = equip.holes[index].jewel;
@@ -623,7 +623,7 @@ export class EquipHandler {
let equip;
if (!!eid) {
equip = await EquipModel.getEquip(eid);
let index = _.findIndex(equip.holes,{id});
let index = findIndex(equip.holes,{id});
if (!!equip.holes[index] && equip.holes[index].jewel == goodInfo.composeMaterial[0].id) {
oldJewel = equip.holes[index].jewel;
equip.holes[index].jewel = jewel;

View File

@@ -7,7 +7,7 @@ import { handleCost } from '../../../services/rewardService';
import { getTitle, getTeraph, gameData, getScollByStar } from '../../../pubUtils/data';
import { SCHOOL, SCROLL } from '../../../pubUtils/dicParam';
import { getTeraphAttr, getAtrrNameById } from '../../../consts/constModules/abilityConst'
const _ = require('underscore');
import { findIndex } from 'underscore';
import { SclResultInter, SclPosInter } from '../../../pubUtils/interface';
import { SchoolModel } from '../../../db/School';
import { checkMaterialEnough } from '../../../services/roleService'
@@ -103,7 +103,7 @@ export class RoleHandler {
let roleId = session.get('roleId');
let role = await RoleModel.findByRoleId(roleId);
let sid: string = session.get('sid');
let index = _.findIndex(role.teraphs, {id});
let index = findIndex(role.teraphs, {id});
if (index < 0)
return resResult(STATUS.WRONG_PARMS);
let teraph = role.teraphs[index];
@@ -138,7 +138,7 @@ export class RoleHandler {
let roleId = session.get('roleId');
let role = await RoleModel.findByRoleId(roleId);
let sid: string = session.get('sid');
let index = _.findIndex(role.teraphs, {id});
let index = findIndex(role.teraphs, {id});
if (index < 0)
return resResult(STATUS.WRONG_PARMS);
let teraph = role.teraphs[index];

View File

@@ -7,7 +7,7 @@ import { calPlayerCeAndSave } from "./playerCeService";
import { HERO_SYSTEM_TYPE } from "../consts";
import { EquipType } from "../db/Equip";
import { calEquipSeids } from '../pubUtils/playerCe';
const _ = require('underscore');
import { indexOf, findIndex } from 'underscore';
export function checkMaterialEnough(consumes:Array<{id: number, count: number}>, jewel: number, jewelCount: number) {
let comJewelMap = {};
consumes = mergeSameGoods(consumes);
@@ -51,7 +51,7 @@ export async function changeEquip(roleId: string, sid: string, equip: EquipType,
let { jobid } = gameData.hero.get(hid);
let { job_class } = getHeroJob(jobid);
let { classId } = getHeroEquipByClassId(goodInfo.itid);
if (_.indexOf(classId, job_class) < 0)
if (indexOf(classId, job_class) < 0)
return takeOffEquip(equip.seqId);
return dressEquip(roleId, sid, hero, equip);
} else {
@@ -63,7 +63,7 @@ export async function changeEquip(roleId: string, sid: string, equip: EquipType,
}
export async function takeOffEquipAndCalPlayerCe(roleId: string, sid: string, seqId: number, hero:HeroType, id: number ) {
let index = _.findIndex(hero.ePlace, { id });
let index = findIndex(hero.ePlace, { id });
if (index < 0)
return;
await EquipModel.updateEquipInfo(seqId, { hid: 0 });

View File

@@ -8,7 +8,6 @@ import { STATUS } from '../consts/statusCode';
import { resResult, reduceCe } from '../pubUtils/util';
import { calPlayerCeAndSave as pubCalPlayerCeAndSave, reCalAllHeroCe } from '../pubUtils/playerCe';
import { HeroType } from '../db/Hero';
const _ = require('underscore');
import { defaultHeroes } from './pvpService';
//修改并下发战力

View File

@@ -18,7 +18,7 @@ import { HeroModel, HeroType } from '../db/Hero';
import { CeAttrNumber, CeAttr, CeAttrRole } from '../db/generalField';
import { DicWarJson } from '../pubUtils/dictionary/DicWarJson';
import { OutliningSpanKind } from 'typescript';
const _ = require('underscore');
import { findWhere, findIndex } from 'underscore';
export async function initPvpInfo(role: RoleType) {
@@ -251,7 +251,7 @@ export async function defaultHeroes ( role:RoleType, challengeCnt?:number, chall
return b.ce - b.dataId - a.ce + a.dataId;
});
for (let hero of heroes) {
if (!!hero.order&& !!hero.hero && _.findIndex(role.topFive, {hid: hero.actorId}) != -1) {
if (!!hero.order&& !!hero.hero && findIndex(role.topFive, {hid: hero.actorId}) != -1) {
let index = orders.indexOf(hero.order);
orders.splice(index, 1);
}
@@ -260,14 +260,14 @@ export async function defaultHeroes ( role:RoleType, challengeCnt?:number, chall
let num = 0;
for (let i = 0; i < role.topFive.length; i++) {
let item = role.topFive[i];
let index = _.findIndex(heroes, {actorId: item.hid});
let index = findIndex(heroes, {actorId: item.hid});
if (index == -1) {
for (let j = num; j < heroes.length; j++) {
let hero = heroes[j];
if (num >= 5) {
break;
}
if (!!_.findWhere(role.topFive, {hid: hero.actorId})) {
if (!!findWhere(role.topFive, {hid: hero.actorId})) {
continue;
}
if (!orders[0]) {

View File

@@ -39,6 +39,9 @@ export async function initRank(serverId: number) {
let pvpRank = await PvpDefenseModel.getRank();
for(let {roleId, role: _role, score, updatedAt } of pvpRank) {
let role = <RoleType>_role;
if (!role) {
continue;
}
let { roleName, headHid, sHid, title, lv, vLv } = role;
await client.zaddAsync(getKeyName(REDIS_KEY.PVP_RANK), encodeScoreWithTime(score, updatedAt?updatedAt.getTime():0), roleId);

View File

@@ -11,7 +11,7 @@ import { pinus } from 'pinus';
import { addEquips, addBags, addSkins } from '../pubUtils/itemUtils';
import { EquipInter, ItemInter, BagInter } from '../pubUtils/interface';
import { gameData } from '../pubUtils/data';
const _ = require('underscore');
import { indexOf, findIndex } from 'underscore';
export async function handleFixedReward(roleId: string, roleName: string, sid: string, rewardStr: string, multi: number) {
let reward = parseGoodStr(rewardStr);
@@ -79,7 +79,7 @@ function sortConsumes(goods: Array<ItemInter>, bags: Array<ItemInter>, currencys
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 {
@@ -177,7 +177,7 @@ function sortItems (goods: Array<ItemInter>, bags: Array<BagInter>, skins: Array
}
} else if (table == ITEM_TABLE.ITEM) {
let index = _.indexOf(bags, {id: good.id});
let index = findIndex(bags, {id: good.id});
if (index > 0) {
bags[index].count = bags[index].count + good.count;
} else {
@@ -186,7 +186,7 @@ function sortItems (goods: Array<ItemInter>, bags: Array<BagInter>, skins: Array
} else if (table == ITEM_TABLE.HERO) {
if (type == CONSUME_TYPE.SKIN) {
let index = _.indexOf(skins, good.id);
let index = indexOf(skins, good.id);
if (index == -1) {
skins.push(good.id);
}
@@ -196,7 +196,7 @@ 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 {

View File

@@ -1,6 +1,6 @@
import { getRandNum, getRandomArr } from '../pubUtils/util';
import { TERAPH_RANDOM } from "../consts/consts";
const _ = require('underscore');
import { indexOf } from 'underscore';
const TERAPH_STRENGTHEN = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10];
export function checkMaterialEnough(count: number, attrs:Array<any>, teraphInfo: any, teraph: any) {
let res = {};
@@ -22,7 +22,7 @@ export function checkMaterialEnough(count: number, attrs:Array<any>, teraphInfo:
res[attrName] = teraphInfo[attrName] * criEffect;
if (teraph[attrName] + res[attrName] > teraphInfo[attrNameMax]) {
res[attrName] = teraphInfo[attrNameMax] - teraph[attrName];
let attrIndex = _.indexOf(attrs, attrName);
let attrIndex = indexOf(attrs, attrName);
attrs.splice(attrIndex, 1);
}
}
@@ -35,7 +35,7 @@ export function checkMaterialEnough(count: number, attrs:Array<any>, teraphInfo:
break;
}
let criEffect = 1;
let index = _.indexOf(criticalArr, {item});
let index = indexOf(criticalArr, {item});
if (index > 0) {
criEffect = teraphInfo.criEffect;
}
@@ -46,7 +46,7 @@ export function checkMaterialEnough(count: number, attrs:Array<any>, teraphInfo:
let attrNameMax = attrName+'Max';
if (teraph[attrName] + res[attrName] > teraphInfo[attrNameMax]) {
res[attrName] = teraphInfo[attrNameMax] - teraph[attrName];
let attrIndex = _.indexOf(attrs, attrName);
let attrIndex = indexOf(attrs, attrName);
attrs.splice(attrIndex, 1);
}
}

View File

@@ -16,7 +16,7 @@ import { RankParam } from '../pubUtils/interface';
import { RoleModel } from '../db/Role';
import { MailModel, MailType } from '../db/Mail';
import { pinus } from 'pinus';
const _ = require('underscore');
import { indexOf } from 'underscore';
const PER_SECOND = 1 * 1000;
const PER_DAY = 24 * 60 * 60;
const SETTLE_DIFF = 29 * 60;
@@ -133,7 +133,7 @@ export async function resetPvpWarId() {
console.log('resetPvpWarId');
let systemConfig = await SystemConfigModel.findSystemConfig();
let warIds = deepCopy(getPvpGkWarIds());
let index = _.indexOf(warIds, systemConfig.warId);
let index = indexOf(warIds, systemConfig.warId);
if (index != -1) {
warIds.splice(index, 1);
}

View File

@@ -1,6 +1,6 @@
import BaseModel from './BaseModel';
import { index, getModelForClass, prop, DocumentType, modelOptions } from '@typegoose/typegoose';
const _ = require('underscore');
import { findIndex } from 'underscore';
// const Transaction = require("mongoose-transactions");
@index({ roleId: 1, id: 1 })
@index({ seqId: 1 })
@@ -60,7 +60,7 @@ export default class Item extends BaseModel {
rec = await ItemModel.findOneAndUpdate({ roleId, id }, { $inc: { count: ratio * count } }, { new: true, upsert: true }).lean(lean);
}
if (!!rec) {
let index = _.findIndex(result,{id})
let index = findIndex(result,{id})
if (!!result[index]) {
result[index] = { id: rec.id, count: rec.count }
} else {

View File

@@ -3,7 +3,7 @@ import {decodeArrayListStr, readJsonFile, parseGoodStr, parseNumberList, decodeA
import { FILENAME, IT_TYPE, ABI_TYPE , GOOD_TYPE} from '../../consts'
import { RewardInter } from '../interface';
const _ = require('lodash');
const underscore = require('underscore');
import { findWhere } from 'underscore';
export interface SpecialMaterial {
readonly ids: number[];
@@ -107,7 +107,7 @@ arr.forEach(o => {
} else if (o.goodType == GOOD_TYPE.JEWEL) {
let material = o.composeMaterial[0];
if (!!material && !!material.id) {
let lastJewel = underscore.findWhere(arr,{good_id:material.id});
let lastJewel = findWhere(arr,{good_id:material.id});
if (!!lastJewel) {
lastJewel.count = material.count;
lastJewel.nextJewelId = o.good_id;

View File

@@ -8,7 +8,7 @@ import { gameData } from './data';
import { RANDOM_SE_COUNT, FIX_ATTRIBUTES_RAN, ITID } from '../consts';
import { getRandValueByMinMax, getRandEelm } from './util';
const _ = require('underscore');
import { findWhere } from 'underscore';
export async function addSkins(roleId: string, id: number) {
let skinInfo = gameData.fashion.get(id);
@@ -17,7 +17,7 @@ export async function addSkins(roleId: string, id: number) {
let hero = await HeroModel.findByHidAndRole(skinInfo.actorId, roleId);
if (!hero)
return false;
if (!!_.findWhere(hero.skins, { id }))
if (!!findWhere(hero.skins, { id }))
return false;
hero.skins.push({ id, enable: false });
await HeroModel.updateHeroInfo(roleId, hero.hid, hero);

View File

@@ -16,9 +16,9 @@ import { DicRandomEffectPool } from './dictionary/DicRandomEffectPool';
import { getGoodById } from './gamedata';
import { SchoolModel } from '../db/School';
import { getTeraphAttr, HEROTARIN } from '../consts/constModules/abilityConst'
// import { PvpDefenseModel } from '../db/PvpDefense';
import { PvpDefenseModel } from '../db/PvpDefense';
const HERO_CE_RATIO = 100;
const _ = require('underscore');
import { findIndex } from 'underscore';
//战力计算TODO
export function calPlayerCe(globalCeAttr: CeAttrRole, hero: HeroType, type: number, args: Array<number> = []) {
let heroCe = 0;
@@ -108,7 +108,7 @@ export async function calPlayerCeAndSave(roleId: string, heros: Array<HeroType>,
incPlayerCe += incHeroCe;
await calculateTopFive(role, hero.hid, hero.ce, hero._id); // 计算更新最强五人战力
await HeroModel.updateHeroInfo(roleId, hero.hid, hero);
//await PvpDefenseModel.updateCe(roleId, hero.hid, hero.ce); // 更新pvp防守阵最强五人战力
await PvpDefenseModel.updateCe(roleId, hero.hid, hero.ce); // 更新pvp防守阵战力
pushHeros.push({
hid: hero.hid,
ce: reduceCe(hero.ce),
@@ -294,13 +294,13 @@ export function calHeroJobStageUpIncAttr(hero: HeroType, args: Array<number>, ad
let lastJob = gameData.job.get(args[0]) || { seid: [] };
let currentJob = gameData.job.get(hero.job);
for (let seid of currentJob.seid) {
let index = _.findIndex(lastJob.seid, seid);
let index = findIndex(lastJob.seid, seid);
if (index < 0) {
addSeidList.push(seid, 0);
}
}
for (let seid of lastJob.seid) {
let index = _.findIndex(currentJob.seid, seid);
let index = findIndex(currentJob.seid, seid);
if (index < 0) {
removeSeidList.push(seid, 0);
}

View File

@@ -7,7 +7,7 @@ import path = require('path');
import { DicRandomEffectPool } from './dictionary/DicRandomEffectPool';
import { HERO_CE_RATIO, ABI_STAGE } from '../consts';
const _ = require('underscore');
import { uniq, findWhere, findIndex } from 'underscore';
const moment = require('moment');
@@ -475,7 +475,7 @@ export function parseNumberList(str: string) {
export function mergeSameGoods(goods: Array<{ id: number, count: number }>) {
let resGoods = [];
for (let { id, count } of goods) {
let index = _.findIndex(resGoods, { id });
let index = findIndex(resGoods, { id });
if (index > -1) {
resGoods[index].count += count;
} else {

View File

@@ -10,7 +10,7 @@ import Counter from '@db/Counter';
import { getHeroInfoById } from 'app/pubUtils/gamedata';
import { calPlayerCeAndSave } from 'app/pubUtils/playerCe';
import { getExpByLv, getHeroExpByLv, gameData } from 'app/pubUtils/data';
const _ = require('underscore');
import { isString } from 'underscore';
/**
* Test Service
@@ -18,7 +18,7 @@ const _ = require('underscore');
export default class Auth extends Service {
public checkTelNo(telNo) {
if (!_.isString(telNo)) {
if (!isString(telNo)) {
return { status: 1, data: '参数类型错误' };
}
if (telNo.length !== 11) {
@@ -92,7 +92,7 @@ export default class Auth extends Service {
if (telVerify.status !== 0) {
return telVerify;
}
if (!_.isString(code) || code.length !== 6) {
if (!isString(code) || code.length !== 6) {
return ctx.service.utils.resResult(STATUS.WRONG_PARMS);
}