活动:清理数据

This commit is contained in:
陆莹
2022-03-21 19:50:46 +08:00
parent 1c3d1c209c
commit 4f5edb7386
60 changed files with 1447 additions and 1076 deletions
@@ -4,7 +4,7 @@
import { ActionPointModel, ActionPointType } from '../db/ActionPoint';
import { TASK_TYPE, STATUS, TA_EVENT, ITEM_CHANGE_REASON } from '../consts';
import { checkActivityTask, checkTask } from './task/taskService';
import { checkTask } from './task/taskService';
import { getDicApByLv } from '../pubUtils/data';
import { pinus } from 'pinus';
import { resResult, shouldRefresh } from '../pubUtils/util';
@@ -68,7 +68,7 @@ function getApWithDataAp(roleId: string, ip: string, lv: number, dataAp: ActionP
* @param changeAp 体力变化,正是加,负是减
* @param sid
*/
export async function setAp(roleId: string, ip: string, lv: number, changeAp: number, sid: string, reason: ITEM_CHANGE_REASON) {
export async function setAp(serverId: number, roleId: string, ip: string, lv: number, changeAp: number, sid: string, reason: ITEM_CHANGE_REASON) {
// console.log('***** setAp', roleId, ip, lv, changeAp)
const now = Date.now();
const dicAp = getDicApByLv(lv);
@@ -89,9 +89,7 @@ export async function setAp(roleId: string, ip: string, lv: number, changeAp: nu
}
if (changeAp < 0) {
await checkTask(roleId, sid, TASK_TYPE.BATTLE_COST_AP, -1 * changeAp, true, {});
let { serverId } = await RoleModel.findByRoleId(roleId);
await checkActivityTask(serverId, sid, roleId, TASK_TYPE.BATTLE_COST_AP, -1 * changeAp,);
await checkTask(serverId, roleId, sid, TASK_TYPE.BATTLE_COST_AP, { count: -changeAp });
// reportTAEvent(roleId, TA_EVENT.AP_CONSUME, { change_count: -1 * changeAp, change_after: ap, change_reason: reason }, ip)
} else {
reportTAEvent(roleId, TA_EVENT.AP_GET, { change_count: changeAp, change_after: ap, change_reason: reason }, ip)
@@ -8,10 +8,10 @@ import { gameData, getDicGachaFloor } from "../../pubUtils/data";
import { RoleModel } from "../../db/Role";
import { RewardInter } from "../../pubUtils/interface";
import { CreateHeroParam } from "../../domain/roleField/hero";
import { transPiece } from "../../pubUtils/itemUtils";
import { HeroType } from "../../db/Hero";
import { NewHeroGachaItem } from "../../domain/activityField/newHeroGachaField";
import { getActivityById } from "./activityService";
import { transPiece } from "../role/util";
/**
* 获取招募列表
@@ -1,11 +1,12 @@
import { GIFT_PACKAGE_TYPE, ACTIVITY_RESOURCES_TYPE, ITEM_CHANGE_REASON } from '../../consts';
import { gameData } from '../../pubUtils/data';
import { addItems, createHeroes } from '../role/rewardService';
import { addItems } from '../role/rewardService';
import { RewardParam } from '../../domain/activityField/rewardField';
import { CreateHeroParam } from '../../domain/roleField/hero';
import { DicGiftPackage } from '../../pubUtils/dictionary/DicGiftPackage';
import { ItemInter, RewardInter } from '../../pubUtils/interface';
import { decodeArrayListStr } from '../../pubUtils/util';
import { createHeroes } from '../role/createHero';
@@ -10,10 +10,10 @@ import { sendMailByContent } from './../mailService';
import { RoleModel, RoleType } from '../../db/Role';
import { getActivityById } from './activityService';
import { RewardInter } from '../../pubUtils/interface';
import { getGoldId } from '../../pubUtils/itemUtils';
import { DUNGEON_CONST, PVP, VIP } from '../../pubUtils/dicParam';
import { cal } from '../../pubUtils/util';
import { pinus } from 'pinus';
import { getGoldId } from '../role/rewardService';
/**
* 获取活动数据
@@ -39,7 +39,7 @@ export async function getPopUpShopDataShow(activityId: number, serverId: number,
return null
}
export async function checkPopUpConditionInCreateHero(serverId, roleId, heroes: HeroType[]) {
export async function checkPopUpConditionInCreateHero(serverId: number, roleId: string, heroes: HeroType[]) {
let conditions = heroes.map(hero => ({ conditionType: POP_UP_SHOP_CONDITION_TYPE.GET_HERO_BY_QUALITY, param: { quality: hero.quality } }));
return await checkPopUpConditions(serverId, roleId, conditions);
}
+2 -3
View File
@@ -9,7 +9,7 @@ import { STATUS } from '../consts/statusCode';
import { HangUpSpdUpRecModel } from '../db/HangUpSpdUpRec';
import { TaskHero, TowerTaskRecModel, TowerTaskRecType } from '../db/TowerTaskRec';
import { Rank } from './rankService';
import { checkActivityTask, checkTask } from './task/taskService';
import { checkTask } from './task/taskService';
import { getRandExpedition, gameData } from '../pubUtils/data';
import { ItemInter, RewardInter } from '../pubUtils/interface';
import { getTimeFunM } from '../pubUtils/timeUtil';
@@ -237,8 +237,7 @@ export async function towerBattleEnd(sid: string, roleId: string, serverId: numb
if (reward) towerReward = reward;
await checkAndStartHungUp(roleId, roleName, role.towerLv - 1);
// 任务
await checkTask(roleId, sid, TASK_TYPE.BATTLE_TOWER_LV, role.towerLv - 1, false, {});
await checkActivityTask(serverId, sid, roleId, TASK_TYPE.BATTLE_TOWER_LV, 1, { towerLv: role.towerLv - 1 });
await checkTask(serverId, roleId, sid, TASK_TYPE.BATTLE_TOWER_LV, { towerLv: role.towerLv - 1 });
}
return {
status: 0,
+13 -92
View File
@@ -2,10 +2,8 @@ import { getRandEelm, } from '../pubUtils/util';
import { EPlace, Stone } from "../db/Hero";
import { gameData, getRandEffectByGroupAndLevel } from "../pubUtils/data";
import { JewelType, RandSe } from '../db/Jewel';
import { getJewelRandSe } from '../pubUtils/itemUtils';
import { checkActivityTask, checkTask, checkTaskWithEplaces, checkTaskWithEplace } from './task/taskService';
import { TASK_TYPE } from '../consts';
import { DicRandomEffectPool } from '../pubUtils/dictionary/DicRandomEffectPool';
import { getJewelRandSe } from './role/rewardService';
export function getRandSeResult(id: number, randSe: RandSe[], originSe: RandSe[] = [], originId?: number) {
let { randomEffect, effectCount, lv } = gameData.jewel.get(id);
@@ -129,98 +127,21 @@ export function checkStoneCanPutOnEquip(equip: EPlace, id: number, stone: number
return true;
}
export async function checkTaskInComposeEquip(serverId: number, roleId: string, sid: string, oldEplace: EPlace[], newEplace: EPlace[], ePlaceId: number) {
await checkTask(roleId, sid, TASK_TYPE.EQUIP_COMPOSE, newEplace.length - oldEplace.length, true, {});
await checkTaskWithEplaces(roleId, sid, TASK_TYPE.EQUIP_COMPOSE_CNT, oldEplace, newEplace, [ePlaceId]);
await checkActivityTask(serverId, sid, roleId, TASK_TYPE.EQUIP_COMPOSE, newEplace.length - oldEplace.length);
await checkActivityTask(serverId, sid, roleId, TASK_TYPE.EQUIP_COMPOSE_CNT, 1, { oldEplace, newEplace });
}
export async function checkTaskInEquipLvUp(serverId: number, roleId: string, sid: string, oldEplace: EPlace[], newEplace: EPlace[], ePlaceIds: number[]) {
await checkTaskWithEplaces(roleId, sid, TASK_TYPE.EQUIP_LV_TO, oldEplace, newEplace, ePlaceIds);
await checkTask(roleId, sid, TASK_TYPE.EQUIP_LV_UP, ePlaceIds.length, true, {});
await checkActivityTask(serverId, sid, roleId, TASK_TYPE.EQUIP_LV_TO, 1, { oldEplace, newEplace, ePlaceIds });
await checkActivityTask(serverId, sid, roleId, TASK_TYPE.EQUIP_LV_UP, ePlaceIds.length, true);
}
export async function checkTaskInPutJewel(serverId: number, roleId: string, sid: string, oldEplace: EPlace[], newEplace: EPlace[], ePlaceId: number, originJewel: JewelType, curJewel: JewelType) {
let { oldEquip, newEquip } = getEquipById(oldEplace, newEplace, ePlaceId);
await checkTaskWithEplace(roleId, sid, TASK_TYPE.EQUIP_PUT_JEWEL, oldEquip, newEquip, { jewels: [originJewel, curJewel ] });
await checkTaskWithEplace(roleId, sid, TASK_TYPE.EQUIP_PUT_JEWEL_CNT, oldEquip, newEquip);
await checkTaskWithEplace(roleId, sid, TASK_TYPE.EQUIP_JEWEL_RANDSE_CNT, oldEquip, newEquip, { jewels: [originJewel, curJewel ] });
await checkActivityTask(serverId, sid, roleId, TASK_TYPE.EQUIP_PUT_JEWEL, 1, { oldEquip, newEquip, jewels: [originJewel, curJewel ] });
await checkActivityTask(serverId, sid, roleId, TASK_TYPE.EQUIP_PUT_JEWEL_CNT, 1, { oldEquip, newEquip });
await checkActivityTask(serverId, sid, roleId, TASK_TYPE.EQUIP_JEWEL_RANDSE_CNT, 1, { oldEquip, newEquip, jewels: [originJewel, curJewel ] });
}
export async function checkTaskInPutStone(serverId: number, roleId: string, sid: string, oldEplace: EPlace[], newEplace: EPlace[], ePlaceId: number, jewel: JewelType) {
let { oldEquip, newEquip } = getEquipById(oldEplace, newEplace, ePlaceId);
await checkTaskWithEplace(roleId, sid, TASK_TYPE.EQUIP_PUT_STONE, oldEquip, newEquip);
await checkTaskWithEplace(roleId, sid, TASK_TYPE.EQUIP_PUT_STONE_CNT, oldEquip, newEquip);
await checkTaskWithEplace(roleId, sid, TASK_TYPE.EQUIP_STONE_CNT, oldEquip, newEquip);
await checkTaskWithEplace(roleId, sid, TASK_TYPE.EQUIP_STONE_CNT_LV, oldEquip, newEquip);
await checkTaskWithEplace(roleId, sid, TASK_TYPE.EQUIP_JEWEL_RANDSE_CNT, oldEquip, newEquip, { jewels: [ jewel ] });
await checkActivityTask(serverId, sid, roleId, TASK_TYPE.EQUIP_PUT_STONE, 1, { oldEquip, newEquip });
await checkActivityTask(serverId, sid, roleId, TASK_TYPE.EQUIP_PUT_STONE_CNT, 1, { oldEquip, newEquip });
await checkActivityTask(serverId, sid, roleId, TASK_TYPE.EQUIP_STONE_CNT, 1, { oldEquip, newEquip });
await checkActivityTask(serverId, sid, roleId, TASK_TYPE.EQUIP_STONE_CNT_LV, 1, { oldEquip, newEquip });
await checkActivityTask(serverId, sid, roleId, TASK_TYPE.EQUIP_JEWEL_RANDSE_CNT, 1, { oldEquip, newEquip, jewels: [ jewel ] });
}
export async function checkTaskInEquipStarUp(serverId: number, roleId: string, sid: string, oldEplace: EPlace[], newEplace: EPlace[], ePlaceId: number, hid: number, isUpStar: boolean) {
if(isUpStar) {
let { oldEquip, newEquip } = getEquipById(oldEplace, newEplace, ePlaceId);
await checkTaskWithEplace(roleId, sid, TASK_TYPE.EQUIP_STAR_UP_TO, oldEquip, newEquip);
await checkTaskWithEplaces(roleId, sid, TASK_TYPE.EQUIP_SUIT_SEID_NUM, oldEplace, newEplace, [ePlaceId], { hid });
await checkActivityTask(serverId, sid, roleId, TASK_TYPE.EQUIP_STAR_UP_TO, 1, { oldEquip, newEquip });
await checkActivityTask(serverId, sid, roleId, TASK_TYPE.EQUIP_SUIT_SEID_NUM, 1, { oldEplace, newEplace, ePlaceId, hid });
}
await checkTask(roleId, sid, TASK_TYPE.EQUIP_STAR_UP_CNT, 1, true, {});
await checkActivityTask(serverId, sid, roleId, TASK_TYPE.EQUIP_STAR_UP_CNT, 1, {});
}
export async function checkTaskInEquipQualityUp(serverId: number, roleId: string, sid: string, oldEplace: EPlace[], newEplace: EPlace[], ePlaceId: number, hid: number, isUpQuality: boolean) {
if(isUpQuality) {
let { oldEquip, newEquip } = getEquipById(oldEplace, newEplace, ePlaceId);
await checkTaskWithEplace(roleId, sid, TASK_TYPE.EQUIP_QUALITY_UP, oldEquip, newEquip, { hid });
await checkTaskWithEplace(roleId, sid, TASK_TYPE.EQUIP_QUALITY_UP_TO, oldEquip, newEquip);
await checkActivityTask(serverId, sid, roleId, TASK_TYPE.EQUIP_QUALITY_UP, 1, { ePlaceId, hid });
await checkActivityTask(serverId, sid, roleId, TASK_TYPE.EQUIP_QUALITY_UP_TO, 1, { oldEquip, newEquip, hid });
}
await checkTask(roleId, sid, TASK_TYPE.EQUIP_QUALITY_UP_CNT, 1, true, {});
await checkActivityTask(serverId, sid, roleId, TASK_TYPE.EQUIP_QUALITY_UP_CNT, 1);
}
export async function checkTaskInEquipReset(serverId: number, roleId: string, sid: string) {
await checkTask(roleId, sid, TASK_TYPE.JEWEL_RESET, 1, true, {});
await checkActivityTask(serverId, sid, roleId, TASK_TYPE.JEWEL_RESET, 1);
}
export async function checkTaskInEquipQuench(serverId: number, roleId: string, sid: string, isSuccess: boolean) {
await checkTask(roleId, sid, TASK_TYPE.JEWEL_QUENCH, 1, true, {});
await checkActivityTask(serverId, sid, roleId, TASK_TYPE.JEWEL_QUENCH, 1);
if(isSuccess) {
await checkTask(roleId, sid, TASK_TYPE.JEWEL_QUENCH_SUCCESS, 1, true, {});
await checkActivityTask(serverId, sid, roleId, TASK_TYPE.JEWEL_QUENCH_SUCCESS, 1);
}
}
export async function checkTaskInComposeStone(serverId: number, roleId: string, sid: string, count: number) {
await checkTask(roleId, sid, TASK_TYPE.STONE_COMPOSE, count, true, {});
await checkActivityTask(serverId, sid, roleId, TASK_TYPE.STONE_COMPOSE, count);
}
function getEquipById(oldEplace: EPlace[], newEplace: EPlace[], eplaceId: number) {
let oldEquip = oldEplace.find(cur => cur.id == eplaceId)||new EPlace(eplaceId, 0);
let newEquip = newEplace.find(cur => cur.id == eplaceId)||new EPlace(eplaceId, 0);
return { oldEquip, newEquip }
}
export function isLocked(randSe: RandSe[]) {
for(let { locked } of randSe) {
if(locked) return true;
}
return false;
}
export function getEquipById(oldEplace: EPlace[], newEplace: EPlace[], eplaceId: number) {
let oldEquip = oldEplace.find(cur => cur.id == eplaceId)||new EPlace(eplaceId, 0);
let newEquip = newEplace.find(cur => cur.id == eplaceId)||new EPlace(eplaceId, 0);
return { oldEquip, newEquip }
}
export function getJewelByEquip(oldEquip: EPlace, newEquip: EPlace, jewels: JewelType[]) {
let oldJewel = jewels.find(cur => cur && cur.seqId == oldEquip.jewel);
let newJewel = jewels.find(cur => cur && cur.seqId == newEquip.jewel);
return { oldJewel, newJewel }
}
@@ -15,7 +15,6 @@ import { pinus } from "pinus";
import { GuildActivityRecordModel } from "../../db/GuildActivityRec";
import { genAuction } from "../auctionService";
import { sendMailByContent } from "../mailService";
import { getHonourObject } from '../../pubUtils/itemUtils';
import { GuildActivityCityType, GuildActivityCityModel } from "../../db/GuildActivityCity";
import { DicCityActivity } from "../../pubUtils/dictionary/DicCityActivity";
import { CityActivityObject } from "./cityActivityObj";
@@ -26,9 +25,9 @@ import { BossInstanceModel } from "../../db/BossInstance";
import { UserGuildModel } from "../../db/UserGuild";
import { raceActivityEnd } from "../timeTaskService";
import { addActive } from "../guildService";
import { checkTask, checkActivityTask } from "../task/taskService";
import { ActivePlayer, GuildRecord, ServerRecordModel } from "../../db/ServerRecords";
import { Attack } from "../../domain/battleField/pvp";
import { getHonourObject } from "../role/rewardService";
let gateActivityObj: GateActivityObject;
let cityActivityObj: CityActivityObject;
+3 -4
View File
@@ -16,7 +16,7 @@ import { ErrLogModel } from '../db/ErrLog';
import { DATA_NAME } from '../consts/dataName';
import { addRoleToGuildChannel } from "./chatService";
import { Rank } from "./rankService";
import { checkActivityTask, checkTask } from "./task/taskService";
import { checkTask } from "./task/taskService";
import { CounterModel } from "../db/Counter";
import { getAuction } from "./auctionService";
import { changeGuildActivity } from "./activity/guildPayService";
@@ -126,8 +126,7 @@ export async function joinGuild(code: string, guildName: string, lv: number, rol
}
//成长任务-加入军团
await checkActivityTask(serverId, sid, roleId, TASK_TYPE.GUILD_JOIN, 1);
await checkTask(roleId, sid, TASK_TYPE.GUILD_JOIN, 1, true, {});
await checkTask(serverId, roleId, sid, TASK_TYPE.GUILD_JOIN);
return { status: 0, guild, userGuild, roleName: role.roleName, memberCnt: guild.memberCnt, guildCe: guild.guildCe }
}
@@ -316,7 +315,7 @@ export async function settleGuildWeekly() {
});
await sendMailByContent(MAIL_TYPE.GUILD_ACTIVE_REWARD, roleId, { goods: reward });
// 任务
await checkTask(roleId, null, TASK_TYPE.GUILD_JOB, 1, false, { job });
await checkTask(serverId, roleId, null, TASK_TYPE.GUILD_JOB, { guildJob: job });
}
await GuildModel.updateInfo(code, { activeWeekly: 0 }, {});
@@ -68,7 +68,7 @@ export async function roleLevelup(type: KING_EXP_RATIO_TYPE, roleId: string, kin
});
if(i != lv) { // 升级加体力
let dicAp = getDicApByLv(i);
await setAp(roleId, ip, i, dicAp.restoreAp, sid, ITEM_CHANGE_REASON.LV_UP);
await setAp(serverId, roleId, ip, i, dicAp.restoreAp, sid, ITEM_CHANGE_REASON.LV_UP);
}
}
// 推送
+2 -2
View File
@@ -22,7 +22,7 @@ import { resResult } from '../pubUtils/util';
import { checkOrderWX } from './pay/weixinPay';
import { addRechargeMoney } from './activity/rechargeMoneyService';
import { addVipRechargeMoney } from './activity/vipRechargeMoneyService';
import { checkActivityTask } from './task/taskService';
import { checkTask } from './task/taskService';
import { checkOrderALI } from './pay/aliPay';
import { getRoleOnlineInfo } from './redisService';
import { PayCallback37Data } from '../domain/sdk';
@@ -183,7 +183,7 @@ export async function settleOrder(order: UserOrderModelType, serverId: number, s
addVipRechargeMoney(order.roleId, serverId, order.price);
addGuildPay(result.roleInfo, order.price)
//成长任务
await checkActivityTask(serverId, sid, order.roleId, TASK_TYPE.ACTIVITY_RMB, order.price, { activityId: order.activityId });
await checkTask(serverId, order.roleId, sid, TASK_TYPE.ACTIVITY_RMB, { count: order.price });
if(order.payType != PAY_TYPE.TEST) {
reportTAEvent(order.roleId, TA_EVENT.RECHARGE_SUCCESS, { pay_id: order.localOrderID, charge_id: order.productID, pay_name: order.message, pay_amount: order.price, pay_channel: order.payType })
reportTAUserSet(TA_USERSET_TYPE.SET_ONCE, order.roleId, { first_pay_time: new Date() });
+2 -2
View File
@@ -630,8 +630,8 @@ export async function savePvpSeasonResult(pvpDefense: PvpDefenseType, seasonNum:
}
// 更新任务
await checkTask(pvpDefense.roleId, null, TASK_TYPE.PVP_HERO_SCORE, 0, false, { heroScores: pvpDefense.heroScores });
await checkTask(pvpDefense.roleId, null, TASK_TYPE.PVP_RANK, 1, false, { rankLv });
await checkTask(pvpDefense.serverId, pvpDefense.roleId, null, TASK_TYPE.PVP_HERO_SCORE, { heroScores: pvpDefense.heroScores });
await checkTask(pvpDefense.serverId, pvpDefense.roleId, null, TASK_TYPE.PVP_RANK, { pvpRank: rankLv });
return pvpSeasonResult;
}
@@ -0,0 +1,136 @@
import { CURRENCY_TYPE, HANDLE_REWARD_TYPE, CURRENCY_BY_TYPE } from '../../consts';
import { RoleModel, RoleType } from '../../db/Role';
import { ItemModel, ItemType } from '../../db/Item';
import { ItemInter, RewardInter, } from '../../pubUtils/interface';
import { gameData } from '../../pubUtils/data';
import { sortItems } from './util';
export class CheckMeterial {
private roleId: string;
private itemsIndb: Map<number, number> = new Map(); // 玩家已有的东西
private notEnoughItems: Map<number, number> = new Map(); // 缺少的数量
private consumes: ItemInter[] = []; // 消耗,正向数
private goldId = CURRENCY_BY_TYPE.get(CURRENCY_TYPE.GOLD);
private coinId = CURRENCY_BY_TYPE.get(CURRENCY_TYPE.COIN);
constructor(roleId: string, role?: RoleType, items?: ItemType[]) {
this.roleId = roleId;
if(role) {
this.itemsIndb.set(this.goldId, role.gold);
this.itemsIndb.set(this.coinId, role.coin);
}
if(items && items.length) {
for(let {id, count} of items) {
this.itemsIndb.set(id, count);
}
}
}
private pushToNotEnoughItems(id: number, count: number) {
if(!this.notEnoughItems.has(id)) {
this.notEnoughItems.set(id, 0);
}
this.notEnoughItems.set(id, this.notEnoughItems.get(id) + count);
}
private getNotEnoughItems() {
let map = new Map<number, number>();
for(let [ id, count ] of this.notEnoughItems) {
map.set(id, count);
}
return map;
}
public async decrease(goods: {id: number, count: number}[]) {
this.notEnoughItems.clear();
let { items, gold, coin } = sortItems(goods, HANDLE_REWARD_TYPE.COST);
let isEnough = true;
for(let { id, count} of items) {
if(!this.itemsIndb.has(id)) {
let item = await ItemModel.findbyRoleAndGid(this.roleId, id);
if(!item) {
this.pushToNotEnoughItems(id, count);
isEnough = false; break;
}
this.itemsIndb.set(id, item.count);
}
if(this.itemsIndb.get(id) < count) {
this.pushToNotEnoughItems(id, count - this.itemsIndb.get(id));
isEnough = false; break;
}
this.itemsIndb.set(id, this.itemsIndb.get(id) - count);
}
if(gold.length > 0) {
if(!this.itemsIndb.has(this.goldId)) {
let role = await RoleModel.findByRoleId(this.roleId, 'gold coin');
this.itemsIndb.set(this.goldId, role.gold);
this.itemsIndb.set(this.coinId, role.coin);
}
let goldCost = gold.reduce((pre, cur) => { return pre + cur.count }, 0);
if(this.itemsIndb.get(this.goldId) < goldCost) {
this.pushToNotEnoughItems(this.goldId, goldCost - this.itemsIndb.get(this.goldId));
isEnough = false;
}
this.itemsIndb.set(this.goldId, this.itemsIndb.get(this.goldId) - goldCost);
}
if(isEnough && coin.length > 0) {
if(!this.itemsIndb.has(this.coinId)) {
let role = await RoleModel.findByRoleId(this.roleId, 'gold coin');
this.itemsIndb.set(this.goldId, role.gold);
this.itemsIndb.set(this.coinId, role.coin);
}
let coinCost = coin.reduce((pre, cur) => pre + cur, 0);
if(this.itemsIndb.get(this.coinId) < coinCost) {
this.pushToNotEnoughItems(this.coinId, coinCost - this.itemsIndb.get(this.coinId));
isEnough = false;
}
this.itemsIndb.set(this.coinId, this.itemsIndb.get(this.coinId) - coinCost);
}
if(isEnough) this.consumes.push(...goods);
return isEnough;
}
private getMaterialEnough(materials: RewardInter[], notEnoughItems: Map<number, number>) {
let newMaterials: RewardInter[] = [];
for(let {id, count} of materials) {
if(notEnoughItems.has(id)) {
newMaterials.push({ id, count: count - notEnoughItems.get(id) });
} else {
newMaterials.push({ id, count });
}
}
return newMaterials;
}
// 检查地玉石是否可以合成
public async composeStone(id: number, count: number) {
let dicStone = gameData.stone.get(id);
if(!dicStone || dicStone.composeMaterial.length <= 0) return false; // 1阶石头不能再从下合成返回不行
let materials = dicStone.composeMaterial.map(cur => ({...cur, count: cur.count * count }));
let isEnough = await this.decrease(materials);
if(!isEnough) {
let notEnoughItems = this.getNotEnoughItems();
let newMaterials = this.getMaterialEnough(materials, notEnoughItems);
let isEnough = await this.decrease(newMaterials); // 消耗掉除了不足的部分以外的其他部分
if(!isEnough) return false;
let isAllOK = true; // 如果有石头不足,向下补充,isAllOK标识不足的都能补充上
for(let [id, count] of notEnoughItems) {
let isEnough = await this.composeStone(id, count);
if(!isEnough) {
isAllOK = false; break;
}
}
return isAllOK;
} else {
return true;
}
}
public getConsume() {
return this.consumes;
}
}
+67 -3
View File
@@ -4,7 +4,6 @@ import { HeroModel, HeroSkin, HeroType, HeroUpdate } from "../../db/Hero";
import { RoleModel, RoleType, RoleUpdate } from "../../db/Role";
import { SkinUpdate } from "../../db/Skin";
import { Figure, TopHero } from "../../domain/dbGeneral";
import { combineFigureInfo, unlockFigureWithoutSave } from '../../pubUtils/itemUtils';
import { TaskListReturn } from "../../domain/roleField/task";
import { GuildModel, GuildType } from "../../db/Guild";
import { PvpDefenseModel } from "../../db/PvpDefense";
@@ -12,12 +11,16 @@ import { pick } from "underscore";
import { calculatetopLineup } from "../../pubUtils/playerCe";
import { nowSeconds } from "../../pubUtils/timeUtil";
import { saveCeChangeLog } from "../../pubUtils/logUtil";
import { reduceCe, resResult } from "../../pubUtils/util";
import { getRandSingleEelm, reduceCe, resResult } from "../../pubUtils/util";
import { AttributeCal } from "../../domain/roleField/attribute";
import { HeroShowParam } from "../../domain/roleField/hero";
import { CreateHeroParam, HeroShowParam } from "../../domain/roleField/hero";
import { pinus } from "pinus";
import { Rank } from "../rankService";
import { checkTaskInCreateHero } from "../task/taskService";
import { ItemInter, RewardInter } from "../../pubUtils/interface";
import { transPiece } from "./util";
import { getInitHeroById } from "../roleService";
import { addItems, combineFigureInfo, unlockFigureWithoutSave } from "./rewardService";
export class UpdateHeroes {
roleId: string;
@@ -210,4 +213,65 @@ export class CreateHeroes extends UpdateHeroes {
return { ...hero, ce: reduceCe(cur.ce)}
});
}
}
/**
* 创建多个武将
* @param roleId
* @param sid
* @param serverId
* @param heroInfo
*/
export async function createHeroes(roleId: string, roleName: string, sid: string, serverId: number, heroInfo: CreateHeroParam[]) {
let hids = heroInfo.map(cur => cur.hid);
let userHeroesMap = await HeroModel.findMapByHidRange(hids, roleId);
let infos: Map<number, { heroInfo: HeroUpdate, skinInfo: SkinUpdate }> = new Map(), pieces: ItemInter[] = [];
for (let h of heroInfo) {
let heroCount = h.count || 1;
if (userHeroesMap.has(h.hid)) {
let { pieceId, count } = transPiece(h.hid);
pieces.push({ id: pieceId, count: count * heroCount });
} else {
let initInfo: { heroInfo: HeroUpdate, skinInfo: SkinUpdate };
if(pinus.app.getServerType() == 'role') {
initInfo = getInitHeroById(h.hid);
} else {
let roleServers = pinus.app.getServersByType('role');
let server = getRandSingleEelm(roleServers);
initInfo = await pinus.app.rpc.role.roleRemote.getInitHeroById.toServer(server.id, h.hid);
}
initInfo.heroInfo = { ...initInfo.heroInfo, ...h };
infos.set(h.hid, initInfo);
userHeroesMap.set(h.hid, null);
if (heroCount > 1) {
let { pieceId, count } = transPiece(h.hid);
pieces.push({ id: pieceId, count: count * (heroCount - 1) });
}
}
}
let resultHeroes: HeroType[] = [], resultItems: RewardInter[] = [], heroes: HeroShowParam[] = [];
if (infos.size > 0) {
let createHero = new CreateHeroes(roleId, roleName, serverId);
await createHero.createWithHeroInfo(infos);
await createHero.pushMessage(sid);
await createHero.updateRedisRank();
heroes = createHero.getShowHeroes();
resultHeroes = createHero.getResultHeroes();
}
if (pieces.length > 0) {
let goods = await addItems(roleId, roleName, sid, pieces, ITEM_CHANGE_REASON.HERO_TRANSFER_PIECE);
resultItems = goods;
}
return { heroes, resultHeroes, goods: resultItems }
}
export async function createHero(roleId: string, roleName: string, sid: string, serverId: number, heroInfo: CreateHeroParam) {
let result = await createHeroes(roleId, roleName, sid, serverId, [heroInfo]);
return result;
}
@@ -5,7 +5,7 @@ import { SkinModel, SkinUpdate } from "../../db/Skin";
import { TopHero } from "../../domain/dbGeneral";
import { CalHeroCe, CalRoleCe } from "../../domain/roleField/calCe";
import { gameData, getHeroExpByLv } from "../../pubUtils/data";
import { unlockFigureWithoutSave } from "../../pubUtils/itemUtils";
import { unlockFigureWithoutSave } from "./rewardService";
// 储存在内存中的初始数据
export function getInitRoleInfo() {
+355 -336
View File
@@ -1,163 +1,33 @@
import { ITID, CONSUME_TYPE, ITEM_TABLE, CURRENCY, CURRENCY_TYPE, MAIL_TYPE, HANDLE_REWARD_TYPE, HERO_SYSTEM_TYPE, CURRENCY_BY_TYPE, ITEM_CHANGE_REASON, TA_USERSET_TYPE, TA_EVENT, POP_UP_SHOP_CONDITION_TYPE } from '../../consts';
import { getRandSingleEelm, resResult } from '../../pubUtils/util';
import { ITID, CONSUME_TYPE, ITEM_TABLE, CURRENCY, CURRENCY_TYPE, MAIL_TYPE, HANDLE_REWARD_TYPE, HERO_SYSTEM_TYPE, CURRENCY_BY_TYPE, ITEM_CHANGE_REASON, TA_USERSET_TYPE, TA_EVENT, POP_UP_SHOP_CONDITION_TYPE, ROLE_SELECT, FIGURE_UNLOCK_CONDITION } from '../../consts';
import { getDecimalCnt, getRandEelm, getRandEelmWithWeight, getRandSingleEelm, getRandValueByMinMax, resResult } from '../../pubUtils/util';
import { RoleModel, RoleType } from '../../db/Role';
import { setAp } from '../actionPointService';
import { pushCalAllHeroCe, calPlayerCeAndSave } from '../playerCeService';
import { pushCalAllHeroCe, calPlayerCeAndSave, calAllHeroCe } from '../playerCeService';
import { ItemModel, ItemType } from '../../db/Item';
import { STATUS } from '../../consts/statusCode';
import { pinus } from 'pinus';
import { addJewels, addBags, addSkin, addFigure, unlockFigure as pubUnlockFigure, transPiece, getGoldObject, getCoinObject, getApObject } from '../../pubUtils/itemUtils';
import { ItemInter, RewardInter, } from '../../pubUtils/interface';
import { gameData } from '../../pubUtils/data';
import { uniq } from 'underscore';
import { EPlace, HeroModel, HeroType, HeroUpdate } from '../../db/Hero';
import { Figure } from '../../domain/dbGeneral';
import { Rank } from '../rankService';
import { pushTaskUpdate } from '../task/taskService';
import { CreateHeroParam, HeroShowParam } from '../../domain/roleField/hero';
import { HeroSkin } from '../../db/Hero';
import { errlogger } from '../../util/logger';
import { BAG } from '../../pubUtils/dicParam';
import { sendMailByContent } from '../mailService';
import { SkinUpdate } from '../../db/Skin';
import { SkinModel, SkinUpdate } from '../../db/Skin';
import { getInitHeroById } from '../roleService';
import { getActivities } from '../activity/activityService';
import { reportTAEvent, reportTAUserSet } from '../sdkService';
import { saveCoinChangeLog, saveFigureInfoLog, saveGoldChangeLog, saveItemChangeLog } from '../../pubUtils/logUtil';
import { JewelModel, JewelType } from '../../db/Jewel';
import { JewelModel, JewelType, jewelUpdate, RandSe } from '../../db/Jewel';
import { updateEplaces } from '../equipService';
import { checkPopUpConditionInCreateHero } from '../activity/popUpShopService';
import { CreateHeroes } from './createHero';
import { combineItems, getCoinEventProperties, getGoldEventProperties, sortItems } from './util';
import { nowSeconds } from '../../pubUtils/timeUtil';
export class CheckMeterial {
private roleId: string;
private itemsIndb: Map<number, number> = new Map(); // 玩家已有的东西
private notEnoughItems: Map<number, number> = new Map(); // 缺少的数量
private consumes: ItemInter[] = []; // 消耗,正向数
private goldId = CURRENCY_BY_TYPE.get(CURRENCY_TYPE.GOLD);
private coinId = CURRENCY_BY_TYPE.get(CURRENCY_TYPE.COIN);
constructor(roleId: string, role?: RoleType, items?: ItemType[]) {
this.roleId = roleId;
if(role) {
this.itemsIndb.set(this.goldId, role.gold);
this.itemsIndb.set(this.coinId, role.coin);
}
if(items && items.length) {
for(let {id, count} of items) {
this.itemsIndb.set(id, count);
}
}
}
private pushToNotEnoughItems(id: number, count: number) {
if(!this.notEnoughItems.has(id)) {
this.notEnoughItems.set(id, 0);
}
this.notEnoughItems.set(id, this.notEnoughItems.get(id) + count);
}
private getNotEnoughItems() {
let map = new Map<number, number>();
for(let [ id, count ] of this.notEnoughItems) {
map.set(id, count);
}
return map;
}
public async decrease(goods: {id: number, count: number}[]) {
this.notEnoughItems.clear();
let { items, gold, coin } = sortItems(goods, HANDLE_REWARD_TYPE.COST);
let isEnough = true;
for(let { id, count} of items) {
if(!this.itemsIndb.has(id)) {
let item = await ItemModel.findbyRoleAndGid(this.roleId, id);
if(!item) {
this.pushToNotEnoughItems(id, count);
isEnough = false; break;
}
this.itemsIndb.set(id, item.count);
}
if(this.itemsIndb.get(id) < count) {
this.pushToNotEnoughItems(id, count - this.itemsIndb.get(id));
isEnough = false; break;
}
this.itemsIndb.set(id, this.itemsIndb.get(id) - count);
}
if(gold.length > 0) {
if(!this.itemsIndb.has(this.goldId)) {
let role = await RoleModel.findByRoleId(this.roleId, 'gold coin');
this.itemsIndb.set(this.goldId, role.gold);
this.itemsIndb.set(this.coinId, role.coin);
}
let goldCost = gold.reduce((pre, cur) => { return pre + cur.count }, 0);
if(this.itemsIndb.get(this.goldId) < goldCost) {
this.pushToNotEnoughItems(this.goldId, goldCost - this.itemsIndb.get(this.goldId));
isEnough = false;
}
this.itemsIndb.set(this.goldId, this.itemsIndb.get(this.goldId) - goldCost);
}
if(isEnough && coin.length > 0) {
if(!this.itemsIndb.has(this.coinId)) {
let role = await RoleModel.findByRoleId(this.roleId, 'gold coin');
this.itemsIndb.set(this.goldId, role.gold);
this.itemsIndb.set(this.coinId, role.coin);
}
let coinCost = coin.reduce((pre, cur) => pre + cur, 0);
if(this.itemsIndb.get(this.coinId) < coinCost) {
this.pushToNotEnoughItems(this.coinId, coinCost - this.itemsIndb.get(this.coinId));
isEnough = false;
}
this.itemsIndb.set(this.coinId, this.itemsIndb.get(this.coinId) - coinCost);
}
if(isEnough) this.consumes.push(...goods);
return isEnough;
}
private getMaterialEnough(materials: RewardInter[], notEnoughItems: Map<number, number>) {
let newMaterials: RewardInter[] = [];
for(let {id, count} of materials) {
if(notEnoughItems.has(id)) {
newMaterials.push({ id, count: count - notEnoughItems.get(id) });
} else {
newMaterials.push({ id, count });
}
}
return newMaterials;
}
// 检查地玉石是否可以合成
public async composeStone(id: number, count: number) {
let dicStone = gameData.stone.get(id);
if(!dicStone || dicStone.composeMaterial.length <= 0) return false; // 1阶石头不能再从下合成返回不行
let materials = dicStone.composeMaterial.map(cur => ({...cur, count: cur.count * count }));
let isEnough = await this.decrease(materials);
if(!isEnough) {
let notEnoughItems = this.getNotEnoughItems();
let newMaterials = this.getMaterialEnough(materials, notEnoughItems);
let isEnough = await this.decrease(newMaterials); // 消耗掉除了不足的部分以外的其他部分
if(!isEnough) return false;
let isAllOK = true; // 如果有石头不足,向下补充,isAllOK标识不足的都能补充上
for(let [id, count] of notEnoughItems) {
let isEnough = await this.composeStone(id, count);
if(!isEnough) {
isAllOK = false; break;
}
}
return isAllOK;
} else {
return true;
}
}
public getConsume() {
return this.consumes;
}
}
export async function handleCost(roleId: string, sid: string, goods: Array<ItemInter>, reason: ITEM_CHANGE_REASON) {
@@ -264,7 +134,7 @@ export async function addItems(roleId: string, roleName: string, sid: string, go
}
// 直接加的
let { jewels: jewelInfos, pushMessages } = await addJewels(roleId, roleName, <{id: number, hid?: number}[]>incJewels, reason);
let { jewels: jewelInfos } = await addJewels(roleId, roleName, <{id: number, hid?: number}[]>incJewels, reason);
for (let jewel of jewelInfos) {
showItems.push({ seqId: jewel.seqId, id: jewel.id, count: 1, isBag: true });
}
@@ -274,7 +144,6 @@ export async function addItems(roleId: string, roleName: string, sid: string, go
//装备推送
if (!!jewelInfos.length)
pinus.app.get('channelService').pushMessageByUids('onJewelAdd', resResult(STATUS.SUCCESS, { jewelInfos }), uids);
pushTaskUpdate(roleId, sid, pushMessages);
//统计装备
if (jewelInfos.length > 0) {
saveItemChangeLog(roleId, jewelInfos, reason);
@@ -301,7 +170,7 @@ export async function addItems(roleId: string, roleName: string, sid: string, go
// 3. 货币推送
if(gold.length > 0 || coin.length > 0 || ap > 0) {
await setAp(roleId, null, role.lv, ap, sid, reason);
await setAp(role.serverId, roleId, null, role.lv, ap, sid, reason);
let incCoin = coin.reduce((pre, cur) => pre + cur, 0);
let incGold = gold.reduce((pre, cur) => pre + cur.count, 0);
role = await RoleModel.increaseGoldAndCoin(roleId, gold, incCoin);
@@ -337,15 +206,10 @@ export async function addItems(roleId: string, roleName: string, sid: string, go
let calAllHeroResult = undefined; // 全局战力变化推送
for (let skinId of skins) {//皮肤推送
let result = await addSkin(roleId, roleName, skinId, false);
if (!!result) {
let hero = await addSkin(roleId, roleName, sid, skinId, false);
if (!!hero) {
showItems.push({ id: skinId, count: 1 });
figureInfos.push(result.figureInfo);
if(result.hero) {
heroskins.push({ skins: result.hero.skins, hid: result.hero.hid });
if(result.calAllHeroResult) calAllHeroResult = result.calAllHeroResult;
}
skinInfos.push({ id: skinId, hid: result.hero?.hid||0, count: 1, inc: 1, reason })
skinInfos.push({ id: skinId, hid: hero?.hid||0, count: 1, inc: 1, reason })
}
}
if (!!skinInfos.length) {
@@ -376,127 +240,6 @@ export async function addItems(roleId: string, roleName: string, sid: string, go
return showItems;
}
function getGoldEventProperties(inc: number, count: number, reason: ITEM_CHANGE_REASON) {
let id = CURRENCY_BY_TYPE.get(CURRENCY_TYPE.GOLD);
let dicGoods = gameData.goods.get(id);
return { item_id: id, item_name: dicGoods.name, item_itid: dicGoods.itid, change_count: inc, change_after: count, change_reason: reason }
}
function getCoinEventProperties(inc: number, count: number, reason: ITEM_CHANGE_REASON) {
let id = CURRENCY_BY_TYPE.get(CURRENCY_TYPE.COIN);
let dicGoods = gameData.goods.get(id);
return { item_id: id, item_name: dicGoods.name, item_itid: dicGoods.itid, change_count: inc, change_after: count, change_reason: reason }
}
export function combineItems(items: { id?: number, count?: number }[]) {
let result: { id: number, count: number }[] = [];
for(let { id, count = 1 } of items) {
let index = result.findIndex(cur => cur.id == id);
if(index == -1) {
result.push({ id, count });
} else {
result[index].count += count;
}
}
return result;
}
export function combineItemAndJewels(items: { id?: number, count?: number }[]) {
let result: { id: number, count: number }[] = [];
for(let { id, count = 1 } of items) {
let dicGoods = gameData.goods.get(id);
let dicItid = ITID.get(dicGoods.itid);
if(dicItid.table != 'jewel') {
let index = result.findIndex(cur => cur.id == id);
if(index == -1) {
result.push({ id, count });
} else {
result[index].count += count;
}
} else {
result.push({ id, count });
}
}
return result;
}
function sortItems(goods: ItemInter[], handleType: HANDLE_REWARD_TYPE) {
let items: { id: number, count: number }[] = []; // 可叠加道具
let jewels: { seqId?: number, id?: number, hid?: number }[] = []; // 不可叠加装备
let gold: { count: number, isPay: boolean }[] = []; // 金币
let coin: number[] = [];
let ap: number = 0;
let skins: number[] = [];
let figures: number[] = [];
for(let good of goods) {
if(good.count == 0) continue;
let dicGood = gameData.goods.get(good.id);
if(!dicGood) {
errlogger.error(`物品 ${good.id} 未配置`);
continue;
}
let dicItid = ITID.get(dicGood.itid);
if(!dicItid) {
errlogger.error(`itid ${dicGood.itid} 未配置`);
continue;
}
let { type, table, isCurrency } = dicItid;
if(table == ITEM_TABLE.JEWEL) { // 装备
if(handleType == HANDLE_REWARD_TYPE.RECEIVE) {
for(let i = 0; i < good.count; i++) {
jewels.push({ id: good.id, hid: good.hid })
}
} else {
if(!!good.seqId) {
jewels.push({ seqId: good.seqId });
}
}
} else if (table == ITEM_TABLE.ITEM) { // 可叠加道具
let index = items.findIndex(cur => cur.id == good.id);
if(index > 0) {
items[index].count += good.count;
} else {
items.push({ id: good.id, count: good.count });
}
} else if (table == ITEM_TABLE.SKIN) { // 皮肤,不可重复获得,不可删
if(handleType == HANDLE_REWARD_TYPE.RECEIVE) {
let index = skins.indexOf(good.id);
if (index == -1) {
skins.push(good.id);
}
}
} else if (table == ITEM_TABLE.ROLE) {
if(isCurrency) { // 3种货币
let dicCurrency = CURRENCY.get(good.id);
if(dicCurrency) {
if(dicCurrency.type == CURRENCY_TYPE.GOLD) { // 金币,区分付费和免费,默认免费
let index = gold.findIndex(cur => cur.isPay == !!good.isPay);
if(index > 0) {
gold[index].count += good.count;
} else {
gold.push({ count: good.count, isPay: !!good.isPay });
}
} else if (dicCurrency.type == CURRENCY_TYPE.COIN) { // 铜钱
coin.push(good.count);
} else if (dicCurrency.type == CURRENCY_TYPE.ACTION_POINT) { // 体力
ap += good.count;
}
}
} else {
if (type == CONSUME_TYPE.HEAD || type == CONSUME_TYPE.FRAME || type == CONSUME_TYPE.SPINE) { // 头像等,不可重复获得,不可删
let index = figures.indexOf(good.id);
if (index == -1) {
figures.push(good.id);
}
}
}
}
}
return { items, jewels, gold, coin, ap, skins, figures }
}
export async function checkGoods(roleId: string, goodIds: Array<number>) {
let jewelSeqIds: Array<number> = [];
@@ -546,79 +289,24 @@ export async function checkHeroEquips(roleId: string, quality: number) {
return await HeroModel.checkEquipByQuality(roleId, quality);
}
/**
* 解锁头像/相框
* @param roleId 玩家id
* @param conditions 解锁条件
* @param role 如果已查询过role表就直接可以使用
*/
export async function unlockFigure(sid: string, roleId: string, conditions: { type: number, paramHid?: number, paramFavourLv?: number, paramSkinId?: number, paramWinStreakNum?: number }[], role?: RoleType) {
let figureInfo = await pubUnlockFigure(roleId, conditions, role);
await pushFigureUpdate(roleId, sid, figureInfo);
}
export async function pushFigureUpdate(roleId: string, sid: string, figureInfo: { heads: Figure[], frames: Figure[], spines: Figure[] }) {
if (!role || !role.heads || !role.frames) {
role = await RoleModel.findByRoleId(roleId, ROLE_SELECT.GET_HEADS);
}
let { figureInfo, heads, frames, spines } = unlockFigureWithoutSave(conditions, role);
role = await RoleModel.updateRoleInfo(roleId, { heads, frames, spines });
if (!!figureInfo && (figureInfo.heads.length > 0 || figureInfo.frames.length > 0 || figureInfo.spines.length > 0)) {
let uids = [{ uid: roleId, sid }];
pinus.app.get('channelService').pushMessageByUids('onHeadChange', resResult(STATUS.SUCCESS, { ...figureInfo }), uids);
}
}
/**
* 创建多个武将
* @param roleId
* @param sid
* @param serverId
* @param heroInfo
*/
export async function createHeroes(roleId: string, roleName: string, sid: string, serverId: number, heroInfo: CreateHeroParam[]) {
let hids = heroInfo.map(cur => cur.hid);
let userHeroesMap = await HeroModel.findMapByHidRange(hids, roleId);
let infos: Map<number, { heroInfo: HeroUpdate, skinInfo: SkinUpdate }> = new Map(), pieces: ItemInter[] = [];
for (let h of heroInfo) {
let heroCount = h.count || 1;
if (userHeroesMap.has(h.hid)) {
let { pieceId, count } = transPiece(h.hid);
pieces.push({ id: pieceId, count: count * heroCount });
} else {
let initInfo: { heroInfo: HeroUpdate, skinInfo: SkinUpdate };
if(pinus.app.getServerType() == 'role') {
initInfo = getInitHeroById(h.hid);
} else {
let roleServers = pinus.app.getServersByType('role');
let server = getRandSingleEelm(roleServers);
initInfo = await pinus.app.rpc.role.roleRemote.getInitHeroById.toServer(server.id, h.hid);
}
initInfo.heroInfo = { ...initInfo.heroInfo, ...h };
infos.set(h.hid, initInfo);
userHeroesMap.set(h.hid, null);
if (heroCount > 1) {
let { pieceId, count } = transPiece(h.hid);
pieces.push({ id: pieceId, count: count * (heroCount - 1) });
}
}
}
let resultHeroes: HeroType[] = [], resultItems: RewardInter[] = [], heroes: HeroShowParam[] = [];
if (infos.size > 0) {
let createHero = new CreateHeroes(roleId, roleName, serverId);
await createHero.createWithHeroInfo(infos);
await createHero.pushMessage(sid);
await createHero.updateRedisRank();
heroes = createHero.getShowHeroes();
resultHeroes = createHero.getResultHeroes();
await checkPopUpConditionInCreateHero(serverId, roleId, resultHeroes);
}
if (pieces.length > 0) {
let goods = await addItems(roleId, roleName, sid, pieces, ITEM_CHANGE_REASON.HERO_TRANSFER_PIECE);
resultItems = goods;
}
return { heroes, resultHeroes, goods: resultItems }
}
export async function createHero(roleId: string, roleName: string, sid: string, serverId: number, heroInfo: CreateHeroParam) {
let result = await createHeroes(roleId, roleName, sid, serverId, [heroInfo]);
return result;
}
/**
* 皮肤数据变化去重、推送
@@ -640,4 +328,335 @@ function pushHeroSkinMsg(heroskins: {skins: HeroSkin[], hid: number}[], skinInf
if(pushSkinInfos.length > 0 || skinInfos.length > 0) {
pinus.app.get('channelService').pushMessageByUids('onHeroSkinChange', resResult(STATUS.SUCCESS, { heros: heroskins, skins: skinInfos }), uids);
}
}
}
/**
* 只插入皮肤,不管那么多的
* @param roleId
* @param roleName
* @param skinId
* @returns
*/
export async function increaseSkin(roleId:string, roleName: string, skinId: number) {
let dicSkin = gameData.fashion.get(skinId);
if (!dicSkin) return false;
let skin = await SkinModel.increaseSkin(roleId, skinId, { roleId, roleName, id: skinId, skinName: dicSkin.name, hid: dicSkin.actorId, skinId: dicSkin.heroId });
if(!skin) return false; // 插入失败
return skin
}
/**
* 添加皮肤
* @param roleId 玩家id
* @param roleName 玩家名
* @param id 皮肤id
* @param hero 武将,如果已经查询过这个武将就不用再查询一次,主意要select skins字段
* @returns {{ hero, figureInfo, calAllHeroResult }} hero:添加皮肤后的武将 figureInfo: 触发头像添加信息 calAllHeroResult:全局战力加成后结果
*/
export async function addSkin(roleId: string, roleName: string, sid: string, skinId: number, enable: boolean, hero?: HeroType) {
let skin = await increaseSkin(roleId, roleName, skinId);
if(!skin) return false;
if(skin.hid && !hero) hero = await HeroModel.findByHidAndRole(skin.hid, roleId);
let condition = { type: FIGURE_UNLOCK_CONDITION.GET_SKIN, paramSkinId: skinId };
await unlockFigure(sid, roleId, [condition]); // 解锁头像
await calAllHeroCe(HERO_SYSTEM_TYPE.ADD_SKIN, sid, roleId, {}, [skinId]); // 全局加成
if (hero) { // 有武将的,将皮肤链接到武将上
let curSkin = hero.skins.find(cur => cur.id == skinId);
if (!curSkin) {
hero.skins.push({ id: skinId, skin: skin._id, enable, skinId: skin.skinId });
await HeroModel.updateHeroInfo(roleId, hero.hid, hero);
}
return hero;
} else {
return null
}
}
export async function addBags(roleId: string, roleName: string, datas: { id: number, count: number }[], reason: number) {
let items: { id: number, count: number, inc: number }[] = [];
for(let data of datas) {
let item = await addBag(roleId, roleName, data, reason);
items.push(item)
}
return { items }
}
export async function addBag(roleId: string, roleName: string, data: { id: number, count: number }, reason: number) {
let { id, count } = data;
let { name: itemName, itid, hid } = gameData.goods.get(id);
let { type } = ITID.get(itid);
let item = await ItemModel.increaseItem(roleId, id, count, { roleId, roleName, itemName, id, type, hid });
return { id: item.id, count: item.count, inc: count, reason };
}
export async function addJewels(roleId: string, roleName: string, jewels: { id: number, }[], reason: number) {
let jewelInfo: jewelUpdate[] = [];
for(let jewel of jewels) {
let info = await getAddJewelInfo(roleId, roleName, jewel);
jewelInfo.push(info);
}
const jewelResult = await JewelModel.createJewels(roleId, jewelInfo);
return { jewels: jewelResult.map(jewel => {
return { ...jewel, count: 1, inc: 1, reason }
})}
}
export async function getAddJewelInfo(roleId: string, roleName: string, jewel: { id: number, }) {
let { id, } = jewel;
let { name, randomEffect, effectCount } = gameData.jewel.get(id);
// 随机属性
let randomResult: number[] = getRandEelm(randomEffect, effectCount);
let randSe: Array<RandSe> = randomResult.map((id: number, index: number) => {
return getJewelRandSe(index + 1, id);
});
return { roleId, roleName, id, name, randSe };
}
/**
* 天晶石已知词条随机值
* @param id 词条位置,第几条
* @param seid 词条id
* @returns
*/
export function getJewelRandSe(id: number, seid: number) {
let dicRandom = gameData.randomEffectPool.get(seid)
let rand = 0;
if (dicRandom.id > 0) {
let randRange = getRandEelmWithWeight(dicRandom.rate);
let randResult = getRandValueByMinMax(randRange.dic.min, randRange.dic.max, getDecimalCnt(dicRandom.gap));
let n = Math.floor((randResult - dicRandom.Min)/dicRandom.gap);
rand = dicRandom.Min + n * dicRandom.gap;
}
return new RandSe(id, dicRandom.id, rand);
}
export function getGoldId() {
return CURRENCY_BY_TYPE.get(CURRENCY_TYPE.GOLD);
}
/**
* @description 获取元宝物品 { id, count }
* @param count 元宝数量
*/
export function getGoldObject(count: number) {
return { id: CURRENCY_BY_TYPE.get(CURRENCY_TYPE.GOLD), count };
}
/**
* @description 获取金币物品 { id, count }
* @param count 元宝数量
*/
export function getCoinObject(count: number) {
return { id: CURRENCY_BY_TYPE.get(CURRENCY_TYPE.COIN), count };
}
/**
* @description 获取体力物品 { id, count }
* @param count 体力数量
*/
export function getApObject(count: number) {
return { id: CURRENCY_BY_TYPE.get(CURRENCY_TYPE.ACTION_POINT), count };
}
/**
* @description 获取友情点物品 { id, count }
* @param count 友情点数量
*/
export function getFriendPointObject(count: number) {
return { id: CURRENCY_BY_TYPE.get(CURRENCY_TYPE.FRIEND_POINT), count };
}
/**
* @description 获取功勋物品 { id, count }
* @param count 功勋数量
*/
export function getHonourObject(count: number) {
return { id: CURRENCY_BY_TYPE.get(CURRENCY_TYPE.HONOUR), count };
}
/**
* 返回 解锁头像/相框
* @param conditions 解锁条件
* @param role 如果已查询过role表就直接可以使用
*/
export function unlockFigureWithoutSave(conditions: { type: number, paramHid?: number, paramFavourLv?: number, paramSkinId?: number, paramWinStreakNum?: number }[], role: RoleType) {
let { heads, frames, spines } = role;
let figureInfo = { heads: new Array<Figure>(), frames: new Array<Figure>(), spines: new Array<Figure>() };
for (let { type, paramHid, paramFavourLv, paramSkinId, paramWinStreakNum } of conditions) {
let canUnLockList = gameData.figureCondition.get(type);
if (canUnLockList) {
let reason = 0;
for (let { id, params, gid } of canUnLockList) {
let flag = false; // 是否达成条件
if (type == FIGURE_UNLOCK_CONDITION.GET_HERO) {
let [hid] = params;
if (paramHid == hid) flag = true;
reason = ITEM_CHANGE_REASON.GET_HERO_UNLOCK_FIGURE;
} else if (type == FIGURE_UNLOCK_CONDITION.HERO_FAVOR) {
let [hid, favourLv] = params;
if (paramHid == hid && paramFavourLv >= favourLv) flag = true;
reason = ITEM_CHANGE_REASON.HERO_FAVOR_UNLOCK_FIGURE;
} else if (type == FIGURE_UNLOCK_CONDITION.GET_SKIN) {
let [id] = params;
if (paramSkinId == id) flag = true;
reason = ITEM_CHANGE_REASON.ADD_SKIN_UNLOCK_FIGURE;
} else if (type == FIGURE_UNLOCK_CONDITION.PVP_WIN_SERIES) {
let [winStreakNum] = params;
if (paramWinStreakNum >= winStreakNum) flag = true;
reason = ITEM_CHANGE_REASON.PVP_SERIES_UNLOCK_FIGURE;
}
if (!flag) continue;
let dicGood = gameData.goods.get(gid);
if (!dicGood) continue;
let dicItid = ITID.get(dicGood.itid);
if (!dicItid) continue;
if (dicItid.type == CONSUME_TYPE.HEAD) {
let figure = unlockSingleFigure(heads, gid, reason, false, id);
if (figure && figure.unlocked) figureInfo.heads.push(figure);
} else if (dicItid.type == CONSUME_TYPE.FRAME) {
let figure = unlockSingleFigure(frames, gid, reason, false, id);
if (figure && figure.unlocked) figureInfo.frames.push(figure);
} else if (dicItid.type == CONSUME_TYPE.SPINE) {
let figure = unlockSingleFigure(spines, gid, reason, false, id);
if (figure && figure.unlocked) figureInfo.spines.push(figure);
} else {
continue;
}
}
}
}
return { figureInfo, heads, frames, spines };
}
// 直接获得形象/相框
export async function addFigure(roleId: string, ids: number[], reason: number) {
let role = await RoleModel.findByRoleId(roleId, ROLE_SELECT.GET_HEADS);
if (!role) return false;
let { heads, frames, spines } = role;
let figureInfo = { heads: [], frames: [], spines: [] };
for (let gid of ids) {
let dicGoods = gameData.goods.get(gid);
if (!dicGoods) continue;
let dicItid = ITID.get(dicGoods.itid);
if (!dicItid) continue;
if (dicItid.type == CONSUME_TYPE.HEAD) {
let figure = unlockSingleFigure(heads, gid, reason, true);
if (figure && figure.unlocked) figureInfo.heads.push(figure);
} else if (dicItid.type == CONSUME_TYPE.FRAME) {
let figure = unlockSingleFigure(frames, gid, reason, true);
if (figure && figure.unlocked) figureInfo.frames.push(figure);
} else if (dicItid.type == CONSUME_TYPE.SPINE) {
let figure = unlockSingleFigure(spines, gid, reason, true);
if (figure && figure.unlocked) figureInfo.spines.push(figure);
} else {
continue;
}
}
role = await RoleModel.updateRoleInfo(roleId, { heads, frames, spines });
return figureInfo;
}
/**
* 根据物品id解锁/获得玩家数据
* @param dbFigures 数据库内字段
* @param id 物品id
* @param unlockDirect 是否不计算解锁条件直接解锁
* @param conditionId 条件id
*/
function unlockSingleFigure(dbFigures: Figure[], id: number, reason: number, unlockDirect = false, conditionId?: number) {
let index = dbFigures.findIndex(cur => cur.id == id);
let figure = dbFigures[index];
if (index == -1) {
figure = new Figure(id, false);
dbFigures.push(figure);
index = dbFigures.length - 1;
}
if (figure.unlocked) return; // 已解锁过
if (!figure.unlockedId) figure.unlockedId = new Array<number>();
let dicGoods = gameData.goods.get(id);
let hasUnlockedAll = true;
if (!unlockDirect) { // 不能直接获得,需要通过type解锁
if (figure.unlockedId.includes(conditionId)) return;
figure.unlockedId.push(conditionId);
for (let { id: cid } of dicGoods.condition) {
if (!figure.unlockedId.includes(cid)) {
hasUnlockedAll = false; break;
}
}
}
if (hasUnlockedAll) {
figure.unlocked = true;
delete figure.unlockedId;
if (dicGoods.timeLimit) {
figure.time = nowSeconds() + dicGoods.timeLimit * 86400
}
}
figure.inc = 1;
figure.reason = reason;
dbFigures[index] = figure;
return figure
}
// async function getSkinsOfThisHero(roleId: string, roleName: string, hid: number, initialSkin: number, allSkins?: SkinType[]) {
// if(!allSkins) allSkins = await SkinModel.findbyRoleAndHid(roleId, hid);
// let skin = await increaseSkin(roleId, roleName, initialSkin);
// if(skin) allSkins.push(skin);
// let skins: { id: number, skin: string, enable: boolean }[] = [];
// for(let skin of allSkins) {
// skins.push({ id: skin.id, skin: skin._id, enable: skin.id == initialSkin });
// }
// return skins
// }
export function combineFigureInfo(figureInfos: { heads: Figure[], frames: Figure[], spines: Figure[] }[]) {
let figureInfo = { heads: new Array<Figure>(), frames: new Array<Figure>(), spines: new Array<Figure>() };
for(let {heads, frames, spines} of figureInfos) {
for(let head of heads) {
figureInfo.heads.push(head);
}
for(let frame of frames) {
figureInfo.frames.push(frame);
}
for(let spine of spines) {
figureInfo.spines.push(spine);
}
}
return figureInfo;
}
// export class CreateHero {
// roleId: string;
// roleName: string;
// serverId: number;
// constructor(roleId: string, roleName: string, serverId: number) {
// }
// }
+133
View File
@@ -0,0 +1,133 @@
import { ITID, CONSUME_TYPE, ITEM_TABLE, CURRENCY, CURRENCY_TYPE, HANDLE_REWARD_TYPE, ITEM_CHANGE_REASON, CURRENCY_BY_TYPE } from '../../consts';
import { ItemInter, RewardInter, } from '../../pubUtils/interface';
import { gameData } from '../../pubUtils/data';
import { errlogger } from '../../util/logger';
export function sortItems(goods: ItemInter[], handleType: HANDLE_REWARD_TYPE) {
let items: { id: number, count: number }[] = []; // 可叠加道具
let jewels: { seqId?: number, id?: number, hid?: number }[] = []; // 不可叠加装备
let gold: { count: number, isPay: boolean }[] = []; // 金币
let coin: number[] = [];
let ap: number = 0;
let skins: number[] = [];
let figures: number[] = [];
for(let good of goods) {
if(good.count == 0) continue;
let dicGood = gameData.goods.get(good.id);
if(!dicGood) {
errlogger.error(`物品 ${good.id} 未配置`);
continue;
}
let dicItid = ITID.get(dicGood.itid);
if(!dicItid) {
errlogger.error(`itid ${dicGood.itid} 未配置`);
continue;
}
let { type, table, isCurrency } = dicItid;
if(table == ITEM_TABLE.JEWEL) { // 装备
if(handleType == HANDLE_REWARD_TYPE.RECEIVE) {
for(let i = 0; i < good.count; i++) {
jewels.push({ id: good.id, hid: good.hid })
}
} else {
if(!!good.seqId) {
jewels.push({ seqId: good.seqId });
}
}
} else if (table == ITEM_TABLE.ITEM) { // 可叠加道具
let index = items.findIndex(cur => cur.id == good.id);
if(index > 0) {
items[index].count += good.count;
} else {
items.push({ id: good.id, count: good.count });
}
} else if (table == ITEM_TABLE.SKIN) { // 皮肤,不可重复获得,不可删
if(handleType == HANDLE_REWARD_TYPE.RECEIVE) {
let index = skins.indexOf(good.id);
if (index == -1) {
skins.push(good.id);
}
}
} else if (table == ITEM_TABLE.ROLE) {
if(isCurrency) { // 3种货币
let dicCurrency = CURRENCY.get(good.id);
if(dicCurrency) {
if(dicCurrency.type == CURRENCY_TYPE.GOLD) { // 金币,区分付费和免费,默认免费
let index = gold.findIndex(cur => cur.isPay == !!good.isPay);
if(index > 0) {
gold[index].count += good.count;
} else {
gold.push({ count: good.count, isPay: !!good.isPay });
}
} else if (dicCurrency.type == CURRENCY_TYPE.COIN) { // 铜钱
coin.push(good.count);
} else if (dicCurrency.type == CURRENCY_TYPE.ACTION_POINT) { // 体力
ap += good.count;
}
}
} else {
if (type == CONSUME_TYPE.HEAD || type == CONSUME_TYPE.FRAME || type == CONSUME_TYPE.SPINE) { // 头像等,不可重复获得,不可删
let index = figures.indexOf(good.id);
if (index == -1) {
figures.push(good.id);
}
}
}
}
}
return { items, jewels, gold, coin, ap, skins, figures }
}
export function getGoldEventProperties(inc: number, count: number, reason: ITEM_CHANGE_REASON) {
let id = CURRENCY_BY_TYPE.get(CURRENCY_TYPE.GOLD);
let dicGoods = gameData.goods.get(id);
return { item_id: id, item_name: dicGoods.name, item_itid: dicGoods.itid, change_count: inc, change_after: count, change_reason: reason }
}
export function getCoinEventProperties(inc: number, count: number, reason: ITEM_CHANGE_REASON) {
let id = CURRENCY_BY_TYPE.get(CURRENCY_TYPE.COIN);
let dicGoods = gameData.goods.get(id);
return { item_id: id, item_name: dicGoods.name, item_itid: dicGoods.itid, change_count: inc, change_after: count, change_reason: reason }
}
export function combineItems(items: { id?: number, count?: number }[]) {
let result: { id: number, count: number }[] = [];
for(let { id, count = 1 } of items) {
let index = result.findIndex(cur => cur.id == id);
if(index == -1) {
result.push({ id, count });
} else {
result[index].count += count;
}
}
return result;
}
export function combineItemAndJewels(items: { id?: number, count?: number }[]) {
let result: { id: number, count: number }[] = [];
for(let { id, count = 1 } of items) {
let dicGoods = gameData.goods.get(id);
let dicItid = ITID.get(dicGoods.itid);
if(dicItid.table != 'jewel') {
let index = result.findIndex(cur => cur.id == id);
if(index == -1) {
result.push({ id, count });
} else {
result[index].count += count;
}
} else {
result.push({ id, count });
}
}
return result;
}
export function transPiece(hid: number) {
let dicHero = gameData.hero.get(hid);
let count = gameData.heroTransPiece.get(dicHero.quality);
return { pieceId: dicHero.pieceId, count }
}
+1 -1
View File
@@ -8,12 +8,12 @@ import { SCHOOL } from '../pubUtils/dicParam';
import { gameData } from '../pubUtils/data';
import { SchoolModel } from '../db/School';
import { SclResultInter, SclPosInter, RewardInter, ItemInter } from '../pubUtils/interface';
import { CheckMeterial } from './role/rewardService';
import { HeroUpdate } from '../db/Hero';
import { SkinUpdate } from '../db/Skin';
import { Figure } from '../domain/dbGeneral';
import { pick } from 'underscore';
import { Reward } from '../domain/battleField/pvp';
import { CheckMeterial } from './role/checkMaterial';
export async function getTeraphStrengthenResult(role: RoleType, count: number, dicTeraph: DicTeraph, teraph: Teraph) {
let criAttr: number[] = [], times = 0;
+1 -1
View File
@@ -3,7 +3,6 @@
import { RoleModel, RoleType } from "../db/Role";
import { Chat37Params, CheckGuild37Params, CheckName37Params, GetWordParam } from "../domain/sdk";
import { sendMailByContent, sendMailToGuildByContent } from './mailService';
import { getGoldObject } from '../pubUtils/itemUtils';
import { NAMEPLATE } from '../pubUtils/dicParam';
import { CHANNEL_PREFIX, FILENAME, getSdkChannelId, MAIL_TYPE, REDIS_KEY, SDK_37_ADDR, SDK_37_CONST, SDK_TA_CONST, STATUS, TA_USERSET_TYPE, THINKING_DATA_MODE, THINKING_DATA_MODE_LIST } from "../consts";
import { UserModel } from "../db/User";
@@ -16,6 +15,7 @@ import { getRandSingleEelm, readWordTxt, resResult, writeWordTxt } from "../pubU
const ThinkingAnalytics = require("thinkingdata-node");
import Trie from '../pubUtils/trie';
import _ = require("underscore");
import { getGoldObject } from "./role/rewardService";
// 检查私聊是否合法
+491 -25
View File
@@ -17,11 +17,13 @@ import { SevenDaysData } from "../../domain/activityField/sevenDaysField";
import { ThirtyDaysData } from "../../domain/activityField/thirtyDaysField";
import { TreasureHuntData } from "../../domain/activityField/treasureHuntField";
import { TaskListReturn, TaskParam, TaskParamInter, UpdateTaskParam } from "../../domain/roleField/task";
import { gameData } from "../../pubUtils/data";
import { gameData, getDicBlueprtById, getEquipSuitByHero } from "../../pubUtils/data";
import { getZeroPoint } from "../../pubUtils/timeUtil";
import { resResult } from "../../pubUtils/util";
import { getActivities, getActivitiesByType, getActivityByServerId } from "../activity/activityService";
import { getRoleCreateTime, getRoleOnlineInfo, getServerCreateTime } from "../redisService";
import { getEquipById, getJewelByEquip } from "../equipService";
import { isRandSeUnLock } from "../../pubUtils/playerCe";
export class CheckTask {
serverId: number; // 区id
@@ -167,18 +169,28 @@ export class CheckSingleTask {
// 检查一般任务
let dicTasks = gameData.taskType.get(taskType);
for (let dicTask of dicTasks) {
let groups = new Map<string, { type: number, group: string, taskParam: number[], taskIds: number[] }>(); // 以group做区分
for (let { id, type, group, taskParam } of dicTasks) {
if (!groups.has(`${type}_${group}`)) {
groups.set(`${type}_${group}`, { type, group, taskParam, taskIds: [] });
}
groups.get(`${type}_${group}`).taskIds.push(id);
}
for (let [_typeAndGroup, { type, group, taskParam, taskIds }] of groups) {
let taskUpdateParam = await this.checkIsMatch(dicTask.taskParam, async () => {
let data = await UserTaskRecModel.findByRoleAndGroup(roleId, dicTask.type, taskType, dicTask.group);
let taskUpdateParam = await this.checkIsMatch(taskParam, async () => {
let data = await UserTaskRecModel.findByRoleAndGroup(roleId, type, taskType, group);
return data? data.records: []
});
if (taskUpdateParam) {
let rec = await UserTaskRecModel.setOrIncTask(roleId, dicTask.type, taskType, dicTask.group, taskUpdateParam);
let rec = await UserTaskRecModel.setOrIncTask(roleId, type, taskType, group, taskUpdateParam);
if (!rec) continue;
if (rec.received && rec.received.includes(dicTask.id)) continue; // 已领取,不再推送
let received = rec.received || [];
this.addTaskPushMessage({ type: dicTask.type, id: dicTask.id, count: rec.count, received: received.includes(dicTask.id) });
for (let id of taskIds) {
if (rec.received && rec.received.includes(id)) continue; // 已领取,不再推送
let received = rec.received || [];
this.addTaskPushMessage({ type, id: id, count: rec.count, received: received.includes(id) });
}
}
}
@@ -354,7 +366,7 @@ export class CheckSingleTask {
case TASK_TYPE.ROLE_LV: // 3. 主公达x级
{
let { lv, oldLv } = param;
if(oldLv < dicTaskParam[0] && lv >= dicTaskParam[0]) {
if(lv > oldLv) {
result = { set: lv }
}
break;
@@ -384,11 +396,14 @@ export class CheckSingleTask {
break;
}
}
if(count + 1 >= dicTaskParam[1]) {
if(index == -1) {
records.push(`${hero.hid}_${count + 1}`);
} else {
records[index] = `${hero.hid}_${count + 1}`;
}
if(count + 1 >= dicTaskParam[1]) {
result = { inc: 1, records }
} else {
records.push(`${hero.hid}_${count + 1}`);
result = { records }
}
break;
@@ -457,11 +472,14 @@ export class CheckSingleTask {
break;
}
}
if( count < dicTaskParam[1] && count + trainCount >= dicTaskParam[1]) {
if(index == -1) {
records[index] = `${hero.hid}_${count + trainCount}`;
result = { inc: 1, records }
} else {
records.push(`${hero.hid}_${count + trainCount}`);
}
if( count < dicTaskParam[1] && count + trainCount >= dicTaskParam[1]) {
result = { inc: 1, records }
} else {
result = { records }
}
break;
@@ -503,11 +521,14 @@ export class CheckSingleTask {
break;
}
}
if( count < dicTaskParam[1] && count + stageUpCnt >= dicTaskParam[1]) {
if(index == -1) {
records[index] = `${hero.hid}_${count + stageUpCnt}`;
result = { inc: 1, records }
} else {
records.push(`${hero.hid}_${count + stageUpCnt}`);
}
if( count < dicTaskParam[1] && count + stageUpCnt >= dicTaskParam[1]) {
result = { inc: 1, records }
} else {
result = { records }
}
break;
@@ -528,19 +549,73 @@ export class CheckSingleTask {
}
break;
}
case TASK_TYPE.CHAT:
case TASK_TYPE.ROLE_SCHOOL_UNLOCK: // 17. 百家学宫解锁x个安置位
{
if (dicTaskParam[0] == 0 || dicTaskParam[0] == param.chatType) {
result = { inc: param.count };
result = { inc: 1 };
break;
}
case TASK_TYPE.ROLE_SCHOOL_PUT_HERO: // 18. 百家学宫放置x个武将
{
let { hid, preHid } = param;
if (hid > 0 && preHid <= 0) { // 放置
result = { inc: 1 };
} else if (hid <= 0 && preHid > 0) { // 卸下
result = { inc: -1 };
}
break;
}
case TASK_TYPE.FRIEND_NUM:
case TASK_TYPE.ROLE_TITLE: // 19. 爵位升至x
{
let { title, oldTitle } = param;
if(title > oldTitle) {
result = { set: title };
}
break;
}
case TASK_TYPE.ROLE_TERAPH_STRENGTHEN: // 20. 神像强化x次
{
let { count } = param;
result = { inc: count };
break;
}
case TASK_TYPE.ROLE_SCROLL_ACTIVE: // 21. 名将谱激活x武将
{
let { scrollActive } = param;
if(scrollActive) {
result = { inc: 1 };
}
break;
}
case TASK_TYPE.FRIEND_NUM: // 34. 拥有x名好友
{
let role = this.getRole();
result = { set: role.friendCnt };
break;
}
case TASK_TYPE.FRIEND_SEND_HEART: // 35. 赠送x次友情点
{
let { count } = param;
if(count > 0) {
result = { inc: count };
}
break;
}
case TASK_TYPE.CHAT: // 36. 聊天频道发言x次
{
let { chatType, count = 1 } = param;
if (dicTaskParam[0] == 0 || dicTaskParam[0] == chatType) {
result = { inc: count };
}
break;
}
case TASK_TYPE.BATTLE_COST_AP: // 37. 消耗体力
{
let { count } = param;
if(count > 0) {
result = { inc: count };
}
break;
}
case TASK_TYPE.BATTLE_WITH_HERO: // 38. 使用hId武将挑战x关卡x次
{
let { warId, battleHeroes } = param;
@@ -553,7 +628,7 @@ export class CheckSingleTask {
{
let { warId, count } = param;
let dicWar = gameData.war.get(warId);
if (dicWar.warType == WAR_TYPE.NORMAL) {
if (dicWar.warType == WAR_TYPE.NORMAL && this.checkIdList(dicTaskParam, 0, warId)) {
result = { inc: count };
}
break;
@@ -567,6 +642,14 @@ export class CheckSingleTask {
}
break;
}
case TASK_TYPE.BATTLE_EVENT: // 41. 奇遇(答题/解救百姓/劫匪) x 次
{
let { eventType } = param;
if(dicTaskParam[0] == 0|| dicTaskParam[0] == eventType) {
result = { inc: 1 };
}
break;
}
case TASK_TYPE.BATTLE_DAILY_STAR: // 42. 每日x星通关 x 次
{
let { warId, battleStar } = param;
@@ -603,6 +686,12 @@ export class CheckSingleTask {
}
break;
}
case TASK_TYPE.BATTLE_TOWER_LV: // 46. 通关镇念塔x层
{
let { towerLv } = param;
result = { set: towerLv };
break;
}
case TASK_TYPE.BATTLE_TOWER: // 47. 通关镇念塔x次
{
let { warId, count } = param;
@@ -630,11 +719,20 @@ export class CheckSingleTask {
}
break;
}
case TASK_TYPE.BATTLE_EXPEDITION_BOX: // 50. 领取x次远征 x宝箱
{
let { point } = param;
if(dicTaskParam[0] == 0 || dicTaskParam[0] == point) {
result = { inc: 1 };
}
break;
}
case TASK_TYPE.COM_BATTLE_CREATE_TEAM: // 51. 寻宝招募队友x次
{
result = { inc: 1 };
break;
}
case TASK_TYPE.COM_BATTLE_ASSIST_TEAM: // 53. 协助寻宝x次
{
result = { inc: 1 };
@@ -645,11 +743,6 @@ export class CheckSingleTask {
result = { inc: 1 };
break;
}
case TASK_TYPE.PVP_RECEIVE_BOX: // 59. 领取x次pvp巅峰之路宝箱
{
result = { inc: 1 };
break;
}
case TASK_TYPE.PVP: // 57. pvp挑战 x 次
{
result = { inc: 1 };
@@ -663,6 +756,11 @@ export class CheckSingleTask {
}
break;
}
case TASK_TYPE.PVP_RECEIVE_BOX: // 59. 领取x次pvp巅峰之路宝箱
{
result = { inc: 1 };
break;
}
case TASK_TYPE.PVP_WIN_SERIES: // 60. pvp连胜x次
{
let { isSuccess } = param;
@@ -688,6 +786,87 @@ export class CheckSingleTask {
break;
}
case TASK_TYPE.PVP_RANK: // 62. pvp赛季排名达到 x 名
{
let { pvpRank } = param;
let records = await getRecord();
let oldPvpRank = parseInt(records[0]);
if(isNaN(oldPvpRank)) oldPvpRank = 0;
if(pvpRank > oldPvpRank) {
records[0] = `${pvpRank}`;
result = { set: pvpRank, records }
}
break;
}
case TASK_TYPE.GUILD_JOB: // 63. 军团官职晋升为x
{
let { guildJob } = param;
let records = await getRecord();
let oldGuildJob = parseInt(records[0]);
if(isNaN(oldGuildJob)) oldGuildJob = 0;
if(guildJob > oldGuildJob) {
records[0] = `${guildJob}`;
result = { set: guildJob, records }
}
break;
}
case TASK_TYPE.GUILD_DONATE: // 64. 军团捐献x次
{
result = { inc: 1 };
break;
}
case TASK_TYPE.GUILD_RECEIVE_BOX: //65. 领取x次军团活跃宝箱
{
result = { inc: 1 };
break;
}
case TASK_TYPE.GUILD_ASSIST_REFINE: // 67. 助力炼器堂研发加速x次
{
result = { inc: 1 };
break;
}
case TASK_TYPE.GUILD_TRAIN_SUCESS: // 68. 练兵场军团成功压制x次
{
let { isSuccess } = param;
if(isSuccess) {
result = { inc: 1 };
}
break;
}
case TASK_TYPE.GUILD_BOSS: // 69. 演武台军团挑战x次boss
{
result = { inc: 1 };
break;
}
case TASK_TYPE.GUILD_TRAIN: // 70. 挑战练兵场X次
{
result = { inc: 1 };
break;
}
case TASK_TYPE.GUILD_ACTIVITY: // 71. 参与 xxx 军团活动 x 次
{
let { aid } = param;
if (dicTaskParam[0] == 0 || aid == dicTaskParam[0]) {
result = { inc: 1 };
}
break;
}
case TASK_TYPE.GUILD_JOIN: // 72. 加入军团
{
result = { set: 1 };
break;
}
case TASK_TYPE.BATTLE_MAIN_ELITE: // 73. 精英通关第x关
{
let { warId, count } = param;
let dicWar = gameData.war.get(warId);
if (dicWar.warType == WAR_TYPE.MAIN_ELITE && this.checkIdList(dicTaskParam, 0, warId)) {
result = { inc: count };
}
break;
}
case TASK_TYPE.HERO_QUALITY_TO_QUALITY_COUNT: // 74. x名初始x品质武将升至X品质
{
let { hero } = param;
@@ -714,6 +893,23 @@ export class CheckSingleTask {
}
break;
}
case TASK_TYPE.GUILD_TRAIN_COUNT: // 79. 练兵场通关x关x次
{
let { warId, isComplete } = param;
if(isComplete && this.checkIdList(dicTaskParam, 0, warId)) {
result = { inc: 1 };
}
break;
}
case TASK_TYPE.HERO_UNLOCK: // 80. 名将谱x阵营全部激活
{
let { hero } = param;
let dicHero = gameData.hero.get(hero.hid);
if(dicHero && dicHero.camp == dicTaskParam[1]) {
result = { inc: 1 };
}
break;
}
case TASK_TYPE.GACHA_QUALITY_COUNT: // 81. 抽到*次品质*武将
{
let { heroes } = param;
@@ -727,6 +923,11 @@ export class CheckSingleTask {
}
break;
}
case TASK_TYPE.ROLE_TERAPH_STAGE_UP: // 82. 神像进阶
{
result = { inc: 1 };
break;
}
case TASK_TYPE.HERO_WAKE_UP_COUNT: // 84. x名武将觉醒
{
let { hero, oldColorStar } = param;
@@ -735,6 +936,271 @@ export class CheckSingleTask {
}
break;
}
case TASK_TYPE.ACTIVITY_RMB: // 86. 某个活动充值*元
{
let { count } = param;
result = { inc: count };
break;
}
case TASK_TYPE.EQUIP_LV_TO: // 87. x件装备强化至x级
{
let { oldEplace, newEplace, ePlaceIds } = param;
let addCount = 0;
for(let eplaceId of ePlaceIds) {
let { oldEquip, newEquip } = getEquipById(oldEplace, newEplace, eplaceId);
if(oldEquip.lv < param[1] && newEquip.lv >= param[1]) {
addCount += 1;
} else if (oldEquip.lv >= param[1] && newEquip.lv < param[1]) {
addCount -= 1;
}
}
if(addCount != 0) {
result = { inc: addCount };
}
break;
}
case TASK_TYPE.EQUIP_PUT_JEWEL: // 88. x件装备镶嵌X阶天晶石
{
let { oldEquip, newEquip, jewels } = param;
let { oldJewel, newJewel } = getJewelByEquip(oldEquip, newEquip, jewels);
let oldLv = gameData.jewel.get(oldJewel?.id)?.lv || 0;
let lv = gameData.jewel.get(newJewel?.id)?.lv || 0;
if(lv >= dicTaskParam[1] && oldLv < dicTaskParam[1]) {
result = { inc: 1 };
} else if (lv < dicTaskParam[1] && oldLv >= dicTaskParam[1]) {
result = { inc: -1 };
}
break;
}
case TASK_TYPE.EQUIP_PUT_STONE: // 89. x件装备镶嵌X个地玉石
{
let { oldEquip, newEquip } = param;
let oldStoneCnt = oldEquip.stones.filter(cur => cur.stone != 0).length;
let newStoneCnt = newEquip.stones.filter(cur => cur.stone != 0).length;
if(oldStoneCnt < param[1] && newStoneCnt >= param[1]) {
result = { inc: 1 };
} else if (oldStoneCnt >= param[1] && newStoneCnt < param[1]) {
result = { inc: -1 };
}
break;
}
case TASK_TYPE.EQUIP_STAR_UP_TO: // 90. x件装备升至X星
{
let { oldEquip, newEquip } = param;
let oldStar = oldEquip?.star||0;
let star = newEquip?.star||0
if(oldStar < param[1] && star >= param[1]) {
result = { inc: 1 };
};
break;
}
case TASK_TYPE.EQUIP_STAR_UP_CNT: // 91. x件装备升星X次
{
let { hid, ePlaceId } = param;
let records = await getRecord();
let count = 0, index = -1;
for(let i = 0; i < records.length; i++) {
let arr = records[i].split('|');
if(parseInt(arr[0]) == hid && parseInt(arr[1]) == ePlaceId) {
count = parseInt(arr[2]);
index = i;
break;
}
}
if(index == -1) {
records.push(`${hid}_${ePlaceId}_${count + 1}`);
} else {
records[index] = `${hid}_${ePlaceId}_${count + 1}`;
}
if(count + 1 >= dicTaskParam[1]) {
result = { inc: 1, records }
} else {
result = { records }
}
break;
}
case TASK_TYPE.EQUIP_SUIT_SEID_NUM: // 92. x名武将激活X条套装属性
{
let { oldEplace, newEplace, hid } = param;
let dicEquipSuit = getEquipSuitByHero(hid);
let oldSuitStars: number[] = [], newSuitStars: number[] = [];
for(let equipId of dicEquipSuit.equips) {
let oldEquip = oldEplace.find(cur => cur.equipId == equipId);
oldSuitStars.push(oldEquip? oldEquip.star: 0);
let newEquip = newEplace.find(cur => cur.equipId == equipId);
newSuitStars.push(newEquip? newEquip.star: 0);
}
let oldStar = Math.min(...oldSuitStars);
let newStar = Math.min(...newSuitStars);
let oldCount = 0, count = 0;
for(let { star } of dicEquipSuit.effect) {
if(oldStar >= star) oldCount++;
if(newStar >= star) count++;
}
if(oldCount < param[1] && count >= param[1]) {
result = { inc: 1 };
}
break;
}
case TASK_TYPE.EQUIP_QUALITY_UP: // 93. x件装备进行升品
{
let { hid, ePlaceId } = param;
let records = await getRecord();
if(records.indexOf(`${hid}_${ePlaceId}`) == -1) {
result = { inc: 1 };
}
break;
}
case TASK_TYPE.EQUIP_QUALITY_UP_CNT: // 94. 装备升品X次
{
result = { inc: 1 };
break;
}
case TASK_TYPE.EQUIP_QUALITY_UP_TO: // 95. X件装备升品至Y品质
{
let { oldEquip, newEquip } = param;
let oldQuality = oldEquip?.quality||0;
let quality = newEquip?.quality||0;
if(oldQuality < param[1] && quality >= param[1]) {
result = { inc: 1 };
}
break;
}
case TASK_TYPE.EQUIP_COMPOSE: // 96. 装备X件装备
{
let { count } = param;
result = { inc: count };
break;
}
case TASK_TYPE.EQUIP_COMPOSE_CNT: // 97. x名武将各装备x件装备
{
let { oldEplace, newEplace } = param;
if(oldEplace.length < dicTaskParam[1] && newEplace.length >= dicTaskParam[1]) {
result = { inc: 1 };
}
break;
}
case TASK_TYPE.EQUIP_LV_UP: // 98. 装备强化X次
{
let { count } = param;
result = { inc: count };
break;
}
case TASK_TYPE.EQUIP_PUT_JEWEL_CNT: // 99. X件装备镶嵌天晶
{
let { oldEquip, newEquip } = param;
if(oldEquip.jewel && !newEquip.jewel) {
result = { inc: -1 };
} else if (!oldEquip.jewel && newEquip.jewel) {
result = { inc: 1 };
}
break;
}
case TASK_TYPE.EQUIP_PUT_STONE_CNT: // 100. X件装备镶嵌地玉
{
let { oldEquip, newEquip } = param;
let oldStoneCnt = oldEquip.stones.filter(cur => cur.stone != 0).length;
let newStoneCnt = newEquip.stones.filter(cur => cur.stone != 0).length;
if(oldStoneCnt > 0 && newStoneCnt == 0) {
result = { inc: -1 };
} else if (oldStoneCnt == 0 && newStoneCnt > 0) {
result = { inc: 1 };
}
break;
}
case TASK_TYPE.EQUIP_STONE_CNT: // 101. 镶嵌X个地玉
{
let { oldEquip, newEquip } = param;
let oldStoneCnt = oldEquip.stones.filter(cur => cur.stone != 0).length;
let newStoneCnt = newEquip.stones.filter(cur => cur.stone != 0).length;
result = { inc: newStoneCnt - oldStoneCnt };
break;
}
case TASK_TYPE.EQUIP_STONE_CNT_LV: // 102. X件装备镶嵌X个大于等于X阶地玉
{
let { oldEquip, newEquip } = param;
let oldStoneLvs = oldEquip.stones.map(cur => {
let dicStone = gameData.stone.get(cur.stone);
return dicStone?dicStone.lv: 0;
});
let newStoneLvs = newEquip.stones.map(cur => {
let dicStone = gameData.stone.get(cur.stone);
return dicStone?dicStone.lv: 0;
});
let oldCount = oldStoneLvs.filter(lv => lv >= param[2]).length;
let newCount = newStoneLvs.filter(lv => lv >= param[2]).length;
if(oldCount < param[1] && newCount >= param[1]) {
result = { inc: 1 };
} else if (oldCount >= param[1] && newCount < param[1]) {
result = { inc: -1 }
}
break;
}
case TASK_TYPE.EQUIP_JEWEL_RANDSE_CNT: // 103.X个天晶的Y条特性词条被激活
{
let { oldEquip, newEquip, jewels } = param;
let { oldJewel, newJewel } = getJewelByEquip(oldEquip, newEquip, jewels);
let oldRandSe = oldJewel?.randSe||[];
let oldUnlockSeCnt = oldRandSe.filter(se => {
return isRandSeUnLock(oldJewel.id, se.id, oldEquip.stones);
}).length;
let newRandSe = newJewel?.randSe||[];
let newUnlockSeCnt = newRandSe.filter(se => {
return isRandSeUnLock(newJewel.id, se.id, newEquip.stones);
}).length;
if(oldUnlockSeCnt < param[1] && newUnlockSeCnt >= param[1]) {
result = { inc: -1 };
} else if (oldUnlockSeCnt >= param[1] && newUnlockSeCnt < param[1]) {
result = { inc: 1 };
}
break;
}
case TASK_TYPE.STONE_COMPOSE: // 104. 地玉合成X次
{
let { count } = param;
result = { inc: count };
break;
}
case TASK_TYPE.JEWEL_RESET: // 105. 天晶洗炼X次
{
result = { inc: 1 };
break;
}
case TASK_TYPE.JEWEL_QUENCH: // 106. 天晶淬炼X次
{
result = { inc: 1 };
break;
}
case TASK_TYPE.JEWEL_QUENCH_SUCCESS: // 107. 天晶成功淬炼X次
{
let { isSuccess } = param;
if(isSuccess) {
result = { inc: 1 };
}
break;
}
case TASK_TYPE.COM_BATTLE_LV: // 108. 寻宝x品阶x次
{
let { gid } = param;
let dicJewel = getDicBlueprtById(gid);
if(dicTaskParam[0] == dicJewel.lv) {
result = { inc: 1 };
}
break
}
case TASK_TYPE.GUILD_REFINE: // 109. 炼器堂兑换X品阶天晶X次
{
let { quality, count } = param;
if(dicTaskParam[0] == quality) {
result = { inc: count };
}
break;
}
}
return result
}
+117 -16
View File
@@ -4,7 +4,6 @@ import { resResult, shouldRefresh } from '../../pubUtils/util';
import { STATUS, TASK_TYPE, TASK_FUN_TYPE, SHOP_REFRESH_TYPE, WAR_TYPE } from '../../consts';
import { TaskParamInter, TaskListReturn } from '../../domain/roleField/task';
import { EPlace, HeroType } from '../../db/Hero';
import { getRoleOnlineInfo } from '../redisService';
import { HeroScores } from '../../db/PvpHistoryOpp';
import { ItemInter } from '../../pubUtils/interface';
import { UserTaskModel, UserTaskType } from '../../db/UserTask';
@@ -15,6 +14,9 @@ import { getSeconds, getZeroPointD } from '../../pubUtils/timeUtil';
import { RoleStatus } from '../../db/ComBattleTeam';
import { getActivities } from '../activity/activityService';
import { CheckTask } from './taskObj';
import { getEquipById } from '../equipService';
import { JewelType } from '../../db/Jewel';
import { checkPopUpConditionInCreateHero } from '../activity/popUpShopService';
export async function checkTaskWithRoles(serverId: number, roleId: string, sid: string, taskType: TASK_TYPE, roles: RoleType[]) {
for (let role of roles) {
@@ -52,6 +54,7 @@ export async function checkTaskInCreateHero(serverId: number, roleId: string, si
task.setParam(TASK_TYPE.HERO_QUALITY_STAR_UP, { heroes });
task.setParam(TASK_TYPE.HERO_LV, { heroes });
await task.saveAndPush(sid);
await checkPopUpConditionInCreateHero(serverId, roleId, heroes);
}
export async function checkTaskInHeroStarUp(serverId: number, roleId: string, sid: string, hero: HeroType, oldStar: number) {
@@ -72,11 +75,10 @@ export async function checkTaskInHeroWakeUp(serverId: number, roleId: string, si
}
export async function checkTaskInHeroQUalityUp(serverId: number, roleId: string, sid: string, hero: HeroType) {
// 任务
await checkTask(serverId, roleId, sid, TASK_TYPE.HERO_QUALITY_UP, { hero });
// 任务
await checkTask(serverId, sid, roleId, TASK_TYPE.HERO_QUALITY_TO_QUALITY_COUNT, { hero });
let task = new CheckTask(serverId, roleId);
task.setParam(TASK_TYPE.HERO_QUALITY_UP, { hero });
task.setParam(TASK_TYPE.HERO_QUALITY_TO_QUALITY_COUNT, { hero });
await task.saveAndPush(sid);
}
export async function checkTaskInHeroTrain(serverId: number, roleId: string, sid: string, hero: HeroType, trainCount: number) {
@@ -86,6 +88,23 @@ export async function checkTaskInHeroTrain(serverId: number, roleId: string, sid
await task.saveAndPush(sid);
}
export async function checkTaskInActiveScroll(serverId: number, roleId: string, sid: string, scrollActive: boolean, hero: HeroType) {
if (!scrollActive) {
let task = new CheckTask(serverId, roleId);
task.setParam(TASK_TYPE.HERO_UNLOCK, { hero });
task.setParam(TASK_TYPE.ROLE_SCROLL_ACTIVE, { scrollActive });
await task.saveAndPush(sid);
}
}
export async function checkTaskInGuildTrain(serverId: number, roleId: string, sid: string, warId: number, isSuccess: boolean, isComplete: boolean) {
let task = new CheckTask(serverId, roleId);
task.setParam(TASK_TYPE.GUILD_TRAIN_SUCESS, { isSuccess });
task.setParam(TASK_TYPE.GUILD_TRAIN, {});
task.setParam(TASK_TYPE.GUILD_TRAIN_COUNT, { isComplete, warId });
await task.saveAndPush(sid);
}
/**
* battle.normalBattleHandler.battleEnd 中会触发的任务,因为有点多提出来了
*/
@@ -100,6 +119,7 @@ export async function checkTaskInHeroTrain(serverId: number, roleId: string, sid
task.setParam(TASK_TYPE.BATTLE_TOWER, { warId, count: 1 });
task.setParam(TASK_TYPE.BATTLE_VESTIGE, { warId, count: 1 });
task.setParam(TASK_TYPE.BATTLE_EXPEDITION, { warId, count: 1 });
task.setParam(TASK_TYPE.BATTLE_MAIN_ELITE, { warId, count: 1 });
await task.saveAndPush(sid);
}
@@ -118,33 +138,114 @@ export async function checkTaskInBattleSweep(serverId: number, roleId: string, s
}
export async function checkTaskInComBattleStart(roleStatus: RoleStatus[], capId: string) {
export async function checkTaskInComBattleStart(roleStatus: RoleStatus[], capId: string, blueprtId: number) {
// console.log('********', JSON.stringify(roleStatus), capId, quality)
for (let { roleId, isRobot } of roleStatus) {
if (!isRobot) {
let role = await RoleModel.findByRoleId(roleId);
let task = new CheckTask(role.serverId, roleId);
task.setRole(role);
if (roleId == capId && roleStatus.length > 1) { // 招募队友
await checkTaskWithRole(role.serverId, roleId, null, TASK_TYPE.COM_BATTLE_CREATE_TEAM, role);
task.setParam(TASK_TYPE.COM_BATTLE_CREATE_TEAM, {});
} else if (roleId !== capId) { // 协助寻宝
await checkTaskWithRole(role.serverId, roleId, null, TASK_TYPE.COM_BATTLE_ASSIST_TEAM, role);
task.setParam(TASK_TYPE.COM_BATTLE_ASSIST_TEAM, {});
}
await checkTaskWithRole(role.serverId, roleId, null, TASK_TYPE.COM_BATTLE, role);
task.setParam(TASK_TYPE.COM_BATTLE, {});
task.setParam(TASK_TYPE.COM_BATTLE_LV, { gid: blueprtId });
}
}
}
export async function checkTaskInPvpEnd(serverId: number, roleId: string, sid: string, isSuccess: boolean, heroScores: HeroScores[]) {
await checkTask(serverId, roleId, sid, TASK_TYPE.PVP_WIN, { isSuccess })
await checkTask(serverId, roleId, sid, TASK_TYPE.PVP_WIN_SERIES, { isSuccess });
await checkTask(serverId, roleId, sid, TASK_TYPE.PVP_HERO_SCORE, { heroScores });
let task = new CheckTask(serverId, roleId);
task.setParam(TASK_TYPE.PVP_WIN, { isSuccess });
task.setParam(TASK_TYPE.PVP_WIN_SERIES, { isSuccess });
task.setParam(TASK_TYPE.PVP_HERO_SCORE, { heroScores });
await task.saveAndPush(sid);
}
export async function checkTaskInGacha(serverId: number, roleId: string, sid: string, count: number, heroes: HeroType[]) {
await checkTask(serverId, roleId, sid, TASK_TYPE.GACHA, { count });
await checkTask(serverId, roleId, sid, TASK_TYPE.GACHA_QUALITY_COUNT, { heroes });
let task = new CheckTask(serverId, roleId);
task.setParam(TASK_TYPE.GACHA, { count });
task.setParam(TASK_TYPE.GACHA_QUALITY_COUNT, { heroes });
await task.saveAndPush(sid);
}
export async function checkTaskInComposeEquip(serverId: number, roleId: string, sid: string, oldEplace: EPlace[], newEplace: EPlace[]) {
let task = new CheckTask(serverId, roleId);
task.setParam(TASK_TYPE.EQUIP_COMPOSE, { count: newEplace.length - oldEplace.length });
task.setParam(TASK_TYPE.EQUIP_COMPOSE_CNT, { oldEplace, newEplace });
await task.saveAndPush(sid);
}
export async function checkTaskInEquipLvUp(serverId: number, roleId: string, sid: string, oldEplace: EPlace[], newEplace: EPlace[], ePlaceIds: number[]) {
let task = new CheckTask(serverId, roleId);
task.setParam(TASK_TYPE.EQUIP_LV_TO, { oldEplace, newEplace, ePlaceIds });
task.setParam(TASK_TYPE.EQUIP_LV_UP, { count: ePlaceIds.length });
await task.saveAndPush(sid);
}
export async function checkTaskInPutJewel(serverId: number, roleId: string, sid: string, oldEplace: EPlace[], newEplace: EPlace[], ePlaceId: number, originJewel: JewelType, curJewel: JewelType) {
let { oldEquip, newEquip } = getEquipById(oldEplace, newEplace, ePlaceId);
let task = new CheckTask(serverId, roleId);
task.setParam(TASK_TYPE.EQUIP_PUT_JEWEL, { oldEquip, newEplace, jewels: [originJewel, curJewel ] });
task.setParam(TASK_TYPE.EQUIP_PUT_JEWEL_CNT, { oldEquip, newEquip });
task.setParam(TASK_TYPE.EQUIP_JEWEL_RANDSE_CNT, { oldEquip, newEplace, jewels: [originJewel, curJewel ] });
await task.saveAndPush(sid);
}
export async function checkTaskInPutStone(serverId: number, roleId: string, sid: string, oldEplace: EPlace[], newEplace: EPlace[], ePlaceId: number, jewel: JewelType) {
let { oldEquip, newEquip } = getEquipById(oldEplace, newEplace, ePlaceId);
let task = new CheckTask(serverId, roleId);
task.setParam(TASK_TYPE.EQUIP_PUT_STONE, { oldEquip, newEquip });
task.setParam(TASK_TYPE.EQUIP_PUT_STONE_CNT, { oldEquip, newEquip });
task.setParam(TASK_TYPE.EQUIP_STONE_CNT, { oldEquip, newEquip });
task.setParam(TASK_TYPE.EQUIP_STONE_CNT_LV, { oldEquip, newEquip });
task.setParam(TASK_TYPE.EQUIP_JEWEL_RANDSE_CNT, { oldEquip, newEplace, jewels: [jewel ] });
await task.saveAndPush(sid);
}
export async function checkTaskInEquipStarUp(serverId: number, roleId: string, sid: string, oldEplace: EPlace[], newEplace: EPlace[], ePlaceId: number, hid: number, isUpStar: boolean) {
let task = new CheckTask(serverId, roleId);
if(isUpStar) {
let { oldEquip, newEquip } = getEquipById(oldEplace, newEplace, ePlaceId);
task.setParam(TASK_TYPE.EQUIP_STAR_UP_TO, { oldEquip, newEquip });
task.setParam(TASK_TYPE.EQUIP_SUIT_SEID_NUM, { oldEplace, newEplace, ePlaceId, hid });
}
task.setParam(TASK_TYPE.EQUIP_STAR_UP_CNT, { hid, ePlaceId });
await task.saveAndPush(sid);
}
export async function checkTaskInEquipQualityUp(serverId: number, roleId: string, sid: string, oldEplace: EPlace[], newEplace: EPlace[], ePlaceId: number, hid: number, isUpQuality: boolean) {
let task = new CheckTask(serverId, roleId);
if(isUpQuality) {
let { oldEquip, newEquip } = getEquipById(oldEplace, newEplace, ePlaceId);
task.setParam(TASK_TYPE.EQUIP_QUALITY_UP, { hid, ePlaceId });
task.setParam(TASK_TYPE.EQUIP_QUALITY_UP_TO, { oldEquip, newEquip })
}
task.setParam(TASK_TYPE.EQUIP_QUALITY_UP_CNT, {});
await task.saveAndPush(sid);
}
export async function checkTaskInEquipReset(serverId: number, roleId: string, sid: string) {
await checkTask(serverId, roleId, sid, TASK_TYPE.JEWEL_RESET);
}
export async function checkTaskInEquipQuench(serverId: number, roleId: string, sid: string, isSuccess: boolean) {
let task = new CheckTask(serverId, roleId);
task.setParam(TASK_TYPE.JEWEL_QUENCH, {});
if(isSuccess) {
task.setParam(TASK_TYPE.JEWEL_QUENCH_SUCCESS, { isSuccess });
}
await task.saveAndPush(sid);
}
export async function checkTaskInComposeStone(serverId: number, roleId: string, sid: string, count: number) {
await checkTask(serverId, roleId, sid, TASK_TYPE.STONE_COMPOSE, { count });
}
// 获取task状态
export async function getCurTask(roleId: string, session: FrontendOrBackendSession) {
let userTask = await UserTaskModel.findByRole(roleId);
+2 -1
View File
@@ -6,12 +6,13 @@
import { BattleDropModel } from '../db/BattleDrop';
import { getRandEelmWithWeight, getRandSingleEelm, getReasonByWarType } from '../pubUtils/util';
import { BATTLE_REWARD_TYPE, BLUEPRT_CONST } from '../consts';
import { addItems, combineItemAndJewels } from './role/rewardService';
import { addItems } from './role/rewardService';
import { RoleModel } from '../db/Role';
import { gameData } from '../pubUtils/data';
import { DicWar } from '../pubUtils/dictionary/DicWar';
import { RewardInter } from '../pubUtils/interface';
import { getZeroPointD } from '../pubUtils/timeUtil';
import { combineItemAndJewels } from './role/util';
export class WarReward {
private roleId: string;