✨ feat(活动): 节日活动-火神祭祀
This commit is contained in:
@@ -41,6 +41,7 @@ import { getPopNoticeData } from './popNoticeService';
|
||||
import { _getActivities, _getActivitiesByServerId, _getActivitiesByType, _getActivityById } from './activityRemoteService';
|
||||
import { getGroupShopDataShow } from './groupShopService';
|
||||
import { getBindPhoneDataShow } from './bindPhoneService';
|
||||
import { getPlayerForgeDataShow } from './forgeService';
|
||||
|
||||
/**
|
||||
* 获取活动数据
|
||||
@@ -232,6 +233,11 @@ export async function getActivity(serverId: number, roleId: string, uid: number,
|
||||
activityData = await getBindPhoneDataShow(activityId, roleId, serverId, uid);
|
||||
break
|
||||
}
|
||||
case ACTIVITY_TYPE.FORGE:
|
||||
{
|
||||
activityData = await getPlayerForgeDataShow(activityId, serverId, roleId);
|
||||
break
|
||||
}
|
||||
default: {
|
||||
console.log('未知活动类型.........', activityType)
|
||||
break;
|
||||
|
||||
42
game-server/app/services/activity/forgeService.ts
Normal file
42
game-server/app/services/activity/forgeService.ts
Normal file
@@ -0,0 +1,42 @@
|
||||
import { ActivityForgeModel } from "../../db/ActivityForge";
|
||||
import { ForgeData } from "../../domain/activityField/forgeField";
|
||||
import { getRoleCreateTime, getServerCreateTime } from "../redisService";
|
||||
import { getActivityById } from "./activityService";
|
||||
|
||||
/**
|
||||
* 玩家活动数据
|
||||
*
|
||||
* @param {number} serverId 区Id
|
||||
* @param {number} activityId 活动Id
|
||||
* @param {string} roleId 角色Id
|
||||
*
|
||||
*/
|
||||
export async function getPlayerForgeData(activityId: number, serverId: number, roleId: string) {
|
||||
let activityData = await getActivityById(activityId);
|
||||
let createTime = await getRoleCreateTime(roleId);
|
||||
let serverTime = await getServerCreateTime(serverId);
|
||||
let playerData = new ForgeData(activityData, createTime, serverTime);
|
||||
let playerRecords = await ActivityForgeModel.findData(serverId, activityId, playerData.roundIndex, roleId);
|
||||
playerData.setPlayerRecords(playerRecords);
|
||||
return playerData;
|
||||
}
|
||||
|
||||
/**
|
||||
* 玩家活动数据
|
||||
*
|
||||
* @param {number} serverId 区Id
|
||||
* @param {number} activityId 活动Id
|
||||
* @param {string} roleId 角色Id
|
||||
*
|
||||
*/
|
||||
export async function getPlayerForgeDataShow(activityId: number, serverId: number, roleId: string) {
|
||||
let playerData = await getPlayerForgeData(activityId, serverId, roleId);
|
||||
if(playerData && playerData.canShow && playerData.canShow()) {
|
||||
return playerData.getShowResult();
|
||||
}
|
||||
return null
|
||||
}
|
||||
|
||||
export function getMetialStr(material: { id: number, count: number }[]) {
|
||||
return material.map(({id, count}) => `${id}&${count}`).join('|')
|
||||
}
|
||||
@@ -14,6 +14,7 @@ import { recordGuildFund } from './timeLimitRankService';
|
||||
import { filterGoods, isGoodsHidden, isHeroHidden } from '../dataService';
|
||||
import { DicGiftPackagePlan } from '../../pubUtils/dictionary/DicGiftPackagePlan';
|
||||
import { Floor, GiftPackageFloorModel } from '../../db/GiftPackageFloor';
|
||||
import { isNumber } from 'underscore';
|
||||
|
||||
|
||||
|
||||
@@ -127,7 +128,7 @@ export function rewardItemData(reward: Array<RewardParam>) {
|
||||
heroes.push({ hid: obj.id, count: obj.count })
|
||||
break;
|
||||
case ACTIVITY_RESOURCES_TYPE.GOODS:
|
||||
goods.push({ id: obj.id, count: obj.count })
|
||||
goods.push({ id: obj.id, count: obj.count, expireTime: obj.expireTime })
|
||||
break;
|
||||
case ACTIVITY_RESOURCES_TYPE.GIFTPACKAGE://配置成礼包会立刻兑换,配置成物品会把礼包放入背包中
|
||||
let goodData = gameData.goods.get(obj.id);//礼包物品
|
||||
@@ -274,15 +275,19 @@ async function randomSelectedData(pool: DicGiftPackagePlan[], roleId: string, gi
|
||||
}
|
||||
|
||||
//数据格式转换'类型&id&数量|类型&id&数量|' ->> Array<RewardParam> 活动奖励
|
||||
export function stringToRewardParam(rewardStr: string): Array<RewardParam> {
|
||||
let result = new Array<{ type: number, id: number, count: number }>();
|
||||
export function stringToRewardParam(rewardStr: string, expireTime?: number): Array<RewardParam> {
|
||||
let result = new Array<{ type: number, id: number, count: number, expireTime?: number }>();
|
||||
if (!rewardStr) return result;
|
||||
let decodeArr = decodeArrayListStr(rewardStr);
|
||||
for (let [type, id, count] of decodeArr) {
|
||||
if (isNaN(parseInt(type)) || isNaN(parseInt(id)) || isNaN(parseInt(count))) {
|
||||
continue;
|
||||
}
|
||||
result.push({ type: parseInt(type), id: parseInt(id), count: parseInt(count) });
|
||||
if(expireTime && isNumber(expireTime)) {
|
||||
result.push({ type: parseInt(type), id: parseInt(id), count: parseInt(count), expireTime: Math.floor(expireTime/1000) });
|
||||
} else {
|
||||
result.push({ type: parseInt(type), id: parseInt(id), count: parseInt(count) });
|
||||
}
|
||||
}
|
||||
return result
|
||||
}
|
||||
|
||||
@@ -119,6 +119,7 @@ export function checkRouteParam(route: string, msg: any) {
|
||||
case 'activity.yuanbaoShopHandler.getShopActivity':
|
||||
case 'activity.groupShopHandler.getGroupShopPage':
|
||||
case 'activity.groupShopHandler.leaveGroupShopPage':
|
||||
case 'activity.forgeHandler.getForgeActivity':
|
||||
{
|
||||
if(!checkNaturalNumbers(msg.activityId)) return false;
|
||||
break;
|
||||
@@ -425,6 +426,22 @@ export function checkRouteParam(route: string, msg: any) {
|
||||
if(!checkNaturalNumbers(activityId, price, itemId, buyCnt)) return false;
|
||||
break;
|
||||
}
|
||||
case 'activity.forgeHandler.build':
|
||||
{
|
||||
let { activityId, id, material } = msg;
|
||||
if(!checkNaturalNumbers(activityId, id)) return false;
|
||||
if(!checkNaturalArray(material)) return false;
|
||||
for(let { id, count } of material) {
|
||||
if(!checkNaturalNumbers(id, count)) return false
|
||||
}
|
||||
break;
|
||||
}
|
||||
case 'activity.forgeHandler.buyCnt':
|
||||
{
|
||||
let { activityId, id, count } = msg;
|
||||
if(!checkNaturalNumbers(activityId, id, count)) return false;
|
||||
break;
|
||||
}
|
||||
case "battle.barrageHandler.getBarrageList":
|
||||
{
|
||||
if(!checkNaturalStrings(msg.rid)) return false;
|
||||
|
||||
@@ -8,7 +8,7 @@ import { getCurTask, getPvpTask } from './task/taskService';
|
||||
import { RoleType } from '../db/Role';
|
||||
import { Application, FrontendOrBackendSession, pinus, RpcClient } from 'pinus';
|
||||
import { getRandEelmWithWeight, resResult } from '../pubUtils/util';
|
||||
import { STATUS, PUSH_BATCH, PUSH_INTERVAL, CONSUME_TYPE, HERO_SELECT, ENTERY_ROLE_PICK, JEWEL_SELECT, ITEM_SELECT, SKIN_SELECT, PUSH_ROUTE, ARTIFACT_SELECT } from '../consts';
|
||||
import { STATUS, PUSH_BATCH, PUSH_INTERVAL, CONSUME_TYPE, HERO_SELECT, ENTERY_ROLE_PICK, JEWEL_SELECT, ITEM_SELECT, SKIN_SELECT, PUSH_ROUTE, ARTIFACT_SELECT, ACTIVITYITEM_SELECT } from '../consts';
|
||||
import { getAllShopList } from './shopService';
|
||||
import { getGeneralRank, getRankFirstReward } from './rankService';
|
||||
import { getFriendList, getApplyList } from './friendService';
|
||||
@@ -51,6 +51,7 @@ import { dispatch } from '../pubUtils/dispatcher';
|
||||
import { PvpDataReturn } from '../domain/battleField/pvp';
|
||||
import { getHiddenData } from './dataService';
|
||||
import { ArtifactModel } from '../db/Artifact';
|
||||
import { ActivityItemModel } from '../db/ActivityItem';
|
||||
|
||||
/**
|
||||
* init: 初始的时候是否推送 true-推 false-不推
|
||||
@@ -125,6 +126,7 @@ export async function getModuleData(type: string, data: { role: RoleType, sessio
|
||||
let items = await ItemModel.findbyRole(role.roleId, ITEM_SELECT.ENTRY);
|
||||
let skins = await SkinModel.findbyRole(role.roleId, SKIN_SELECT.ENTRY);
|
||||
let artifacts = await ArtifactModel.findbyRole(role.roleId, ARTIFACT_SELECT.ENTRY);
|
||||
let activityItems = await ActivityItemModel.findbyRole(role.roleId, ACTIVITYITEM_SELECT.ENTRY);
|
||||
|
||||
role['heros'] = heros.map(hero => new HeroParam(hero));
|
||||
role['jewels'] = jewels;
|
||||
@@ -134,6 +136,7 @@ export async function getModuleData(type: string, data: { role: RoleType, sessio
|
||||
role['apJson'] = apJson;
|
||||
role['ipLocation'] = role.fixedIpLocation||role.ipLocation||'未知';
|
||||
role['artifacts'] = artifacts;
|
||||
role['activityItems'] = activityItems;
|
||||
|
||||
if (!role.showLineup) role.showLineup = role.topLineup.map(cur => cur.hid);
|
||||
role.heads = role.heads.filter(cur => cur.status);
|
||||
|
||||
@@ -23,10 +23,11 @@ import { calculateCeWithHero, calculateCeWithRole } from '../playerCeService';
|
||||
import { sendMessageToUserWithSuc } from '../pushService';
|
||||
import { filterGoods } from '../dataService';
|
||||
import { ArtifactModel, ArtifactModelType, ArtifactModelUpdate } from '../../db/Artifact';
|
||||
import { ActivityItemModel } from '../../db/ActivityItem';
|
||||
|
||||
export async function handleCost(roleId: string, sid: string, goods: Array<ItemInter>, reason: ITEM_CHANGE_REASON) {
|
||||
|
||||
let { items, jewels, gold, coin, artifacts } = sortItems(goods, HANDLE_REWARD_TYPE.COST);
|
||||
let { items, jewels, gold, coin, artifacts, activityItems } = sortItems(goods, HANDLE_REWARD_TYPE.COST);
|
||||
let jewelSeqIds = jewels.map(cur => cur.seqId);
|
||||
let resJewels: JewelType[] = [];
|
||||
let artifactSeqIds = artifacts.map(cur => cur.seqId);
|
||||
@@ -59,6 +60,13 @@ export async function handleCost(roleId: string, sid: string, goods: Array<ItemI
|
||||
sendMessageToUserWithSuc(roleId, PUSH_ROUTE.ITEM_UPDATE, { goods: result.map(cur => ({...cur, reason })) }, sid);
|
||||
saveItemChangeLog(roleId, result, reason);
|
||||
}
|
||||
//检查并修改道具
|
||||
if (activityItems.length > 0) {
|
||||
let { hasError, result } = await ActivityItemModel.decreaseActivityItems(roleId, activityItems);
|
||||
if (hasError) return false;
|
||||
sendMessageToUserWithSuc(roleId, PUSH_ROUTE.ACTIVITY_ITEM_UPDATE, { goods: result.map(cur => ({...cur, reason })) }, sid);
|
||||
saveItemChangeLog(roleId, result, reason);
|
||||
}
|
||||
|
||||
//删除装备
|
||||
if (resJewels.length > 0) {
|
||||
@@ -136,8 +144,8 @@ export async function handleCost(roleId: string, sid: string, goods: Array<ItemI
|
||||
|
||||
export async function addItems(roleId: string, roleName: string, sid: string, goods: Array<ItemInter>, reason: ITEM_CHANGE_REASON) {
|
||||
goods = filterGoods(goods, obj => obj.id, roleId, reason);
|
||||
let { items, jewels, gold, coin, ap, skins, figures, artifacts } = sortItems(goods, HANDLE_REWARD_TYPE.RECEIVE);
|
||||
let showItems: { id: number, seqId?: number, count: number, isBag?: boolean }[] = [];
|
||||
let { items, jewels, gold, coin, ap, skins, figures, artifacts, activityItems } = sortItems(goods, HANDLE_REWARD_TYPE.RECEIVE);
|
||||
let showItems: { id: number, seqId?: number, count: number, isBag?: boolean, expireTime?: number }[] = [];
|
||||
let role = await RoleModel.findByRoleId(roleId);
|
||||
// 1. 装备处理
|
||||
if(jewels.length > 0) {
|
||||
@@ -283,6 +291,19 @@ export async function addItems(roleId: string, roleName: string, sid: string, go
|
||||
}
|
||||
}
|
||||
|
||||
// 7. 活动道具处理
|
||||
if(activityItems.length > 0) {
|
||||
let { items: itemInfos } = await addActivityItems(roleId, roleName, activityItems, reason);
|
||||
for (let item of activityItems) {
|
||||
showItems.push({ id: item.id, count: item.count, expireTime: item.expireTime });
|
||||
}
|
||||
//背包除去装备推送
|
||||
if (!!itemInfos.length) {
|
||||
sendMessageToUserWithSuc(roleId, PUSH_ROUTE.ACTIVITY_ITEM_UPDATE, { goods: itemInfos }, sid);
|
||||
saveItemChangeLog(roleId, itemInfos, reason);
|
||||
}
|
||||
|
||||
}
|
||||
return showItems;
|
||||
}
|
||||
|
||||
@@ -439,6 +460,21 @@ export async function addBag(roleId: string, roleName: string, data: { id: numbe
|
||||
return { id: item.id, count: item.count, inc: count, reason };
|
||||
}
|
||||
|
||||
export async function addActivityItems(roleId: string, roleName: string, datas: { id: number, count: number, expireTime?: number }[], reason: number) {
|
||||
let items: { id: number, count: number, inc: number, expireTime: number }[] = [];
|
||||
for(let data of datas) {
|
||||
let item = await addActivityItem(roleId, roleName, data, reason);
|
||||
items.push(item)
|
||||
}
|
||||
return { items }
|
||||
}
|
||||
|
||||
export async function addActivityItem(roleId: string, roleName: string, data: { id: number, count: number, expireTime?: number }, reason: number) {
|
||||
let { id, count, expireTime } = data;
|
||||
let { name: itemName, itid } = gameData.goods.get(id);
|
||||
let item = await ActivityItemModel.increaseActivityItem(roleId, id, count, { roleId, roleName, itemName, id, expireTime });
|
||||
return { id: item.id, count: item.count, inc: count, expireTime: item.expireTime, reason };
|
||||
}
|
||||
|
||||
export async function addJewels(roleId: string, roleName: string, jewels: { id: number, }[], reason: number) {
|
||||
let jewelInfo: jewelUpdate[] = [];
|
||||
|
||||
@@ -12,6 +12,7 @@ export function sortItems(goods: ItemInter[], handleType: HANDLE_REWARD_TYPE) {
|
||||
let ap: number = 0;
|
||||
let skins: number[] = [];
|
||||
let figures: number[] = [];
|
||||
let activityItems: { id: number, count: number, expireTime?: number }[] = []; // 可叠加道具
|
||||
|
||||
for(let good of goods) {
|
||||
if(good.count == 0) continue;
|
||||
@@ -85,11 +86,18 @@ export function sortItems(goods: ItemInter[], handleType: HANDLE_REWARD_TYPE) {
|
||||
artifacts.push({ seqId: good.seqId });
|
||||
}
|
||||
}
|
||||
} else if (table == ITEM_TABLE.ACTIVITY_ITEM) { // 活动道具,限时,可堆叠
|
||||
let index = activityItems.findIndex(cur => cur.id == good.id);
|
||||
if(index >= 0) {
|
||||
activityItems[index].count += good.count;
|
||||
} else {
|
||||
activityItems.push({ id: good.id, count: good.count, expireTime: good.expireTime });
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
return { items, jewels, gold, coin, ap, skins, figures, artifacts }
|
||||
return { items, jewels, gold, coin, ap, skins, figures, artifacts, activityItems }
|
||||
}
|
||||
|
||||
export function getGoldEventProperties(inc: number, count: number, reason: ITEM_CHANGE_REASON) {
|
||||
|
||||
Reference in New Issue
Block a user