feat(活动): 添加弹出礼包逻辑

This commit is contained in:
luying
2023-10-11 21:11:35 +08:00
parent e4e692458b
commit 92e9549a21
3 changed files with 53 additions and 8 deletions

View File

@@ -44,7 +44,11 @@ export class PopUpShopHandler {
let { conditionType } = msg;
if(
conditionType != POP_UP_SHOP_CONDITION_TYPE.GACHA_RES_NOT_ENOUGH &&
conditionType != POP_UP_SHOP_CONDITION_TYPE.TERAPH_RES_NOT_ENOUGH
conditionType != POP_UP_SHOP_CONDITION_TYPE.TERAPH_RES_NOT_ENOUGH &&
conditionType != POP_UP_SHOP_CONDITION_TYPE.STONE_NOT_ENOUGH &&
conditionType != POP_UP_SHOP_CONDITION_TYPE.EQUIP_STAR_NOT_ENOUGH &&
conditionType != POP_UP_SHOP_CONDITION_TYPE.FAVOR_NOT_ENOUGH &&
conditionType != POP_UP_SHOP_CONDITION_TYPE.EXP_NOT_ENOUGH
) {
return resResult(STATUS.WRONG_PARMS);
}

View File

@@ -218,6 +218,10 @@ export enum POP_UP_SHOP_CONDITION_TYPE {
AUCTION = 8, // 拍卖行
TITLE = 9, // 爵位到达x
TOWER = 10, // 镇念塔到达x层
STONE_NOT_ENOUGH = 11, // 地魄石不足
EQUIP_STAR_NOT_ENOUGH = 12, // 精炼道具不足
FAVOR_NOT_ENOUGH = 13, // 好感道具不足
EXP_NOT_ENOUGH = 14, // 经验道具不足
}
export enum POP_UP_SHOP_REFRESH_TIME_TYPE {

View File

@@ -19,6 +19,7 @@ interface PopUpShopPackageInDb {
id: number; // 弹出礼包id
conditionType: number; // 条件类型
canLvUp: number; // 是否可升降
canVipLvFirst: number; // 是否优先vip等级当不购买的时候就降级
items: PopUpShopItemInDb[]; // 礼包
duration: number; // 礼包弹出之后,持续时间,单位小时
keyItem: PopUpShopKeyItemIbDb[]; // 关键资源限制refreshDay内可以获得Y个
@@ -154,6 +155,7 @@ export class PopUpShopPackage {
id: number; // 弹出礼包id
conditionType: number; // 条件类型
canLvUp: number; // 是否可升降
canVipLvFirst: number; // 是否优先vip等级当不购买的时候就降级
checkPushingItem: number; // 是否在同类型礼包
duration: number; // 礼包弹出之后,持续时间,单位小时
refreshTimeType: number; // 刷新时间类型0-不复现 1-自然日 2-自然周 3-自然月 4-从beginTime开始固定天
@@ -170,6 +172,7 @@ export class PopUpShopPackage {
// setPlayerRecord的时候处理的数据
hasPushCnt: number = 0; // 已经推过几次了
hasPassCnt: number = 0; // 已经被连续无视过几次
latestPassItemId: number = 0; // 最近一次无视了的
latestItemId: number = 0; // 升降礼包最近一次的那档id
latestBought: boolean = false; // 最近一次是否购买
@@ -180,6 +183,7 @@ export class PopUpShopPackage {
this.id = data.id;
this.conditionType = data.conditionType;
this.canLvUp = data.canLvUp;
this.canVipLvFirst = data.canVipLvFirst;
this.duration = data.duration;
this.checkPushingItem = data.checkPushingItem;
this.refreshTimeType = data.refreshTimeType;
@@ -234,8 +238,10 @@ export class PopUpShopPackage {
} else if (data.beginTime < now && data.endTime < now) { // 已经结束了的
if(data.hasBought) { // 是否看到了,但是没有买
this.hasPassCnt = 0;
this.latestPassItemId = 0;
} else {
this.hasPassCnt ++;
this.latestPassItemId = data.items[0].id;
}
}
@@ -277,20 +283,46 @@ export class PopUpShopPackage {
if(!minItem) minItem = item;
if(!maxItem || maxItem.id > item.id) maxItem = item;
if(this.canLvUp == 1) { // 升降礼包
if(this.latestBought && item.id == this.latestItemId + 1 ) { // 最近一次买了,升级
items.push(item);
} else if(!this.latestBought && item.id == this.latestItemId - 1 ) {
items.push(item);
}
} else {
if(this.checkLvUpCanPush(item) && this.checkVipUpFirstCanPush(item)) {
items.push(item);
}
}
if (this.canVipLvFirst == 1) {
items.sort((a, b) => a.id - b.id);
let maxItem = items[items.length - 1];
if (maxItem) {
items = items.filter(cur => cur.param == maxItem.param);
}
}
if(!items.length && maxItem && minItem) items.push(this.latestBought? maxItem: minItem);
return items;
}
private checkLvUpCanPush(item: PopShopItem) {
if(this.canLvUp == 1) { // 升降礼包
if(this.latestBought && item.id == this.latestItemId + 1 ) { // 最近一次买了,升级
return true
} else if(!this.latestBought && item.id == this.latestItemId - 1 ) {
return true
} else {
return false
}
} else {
return true
}
}
// 优先显示vip等级如果忽视过了就降级
private checkVipUpFirstCanPush(item: PopShopItem) {
if (this.canVipLvFirst == 1) {
let maxPassItemId = this.latestPassItemId;
let dicItem = maxPassItemId > 0 && this.findItemById(maxPassItemId);
if (dicItem && dicItem.param == item.param) return false;
}
return true;
}
public async getEffectTime() {
let now = new Date();
let beginTime = now;
@@ -440,6 +472,11 @@ export class PopShopItem {
return param.oldLv < this.conditionParam[0] && param.newLv >= this.conditionParam[0];
case POP_UP_SHOP_CONDITION_TYPE.TOWER:
return param.oldLv < this.conditionParam[0] && param.newLv >= this.conditionParam[0];
case POP_UP_SHOP_CONDITION_TYPE.STONE_NOT_ENOUGH:
case POP_UP_SHOP_CONDITION_TYPE.EQUIP_STAR_NOT_ENOUGH:
case POP_UP_SHOP_CONDITION_TYPE.FAVOR_NOT_ENOUGH:
case POP_UP_SHOP_CONDITION_TYPE.EXP_NOT_ENOUGH:
return true;
default:
return false;
}