예제 #1
0
        /// <summary>
        /// 玩家战斗结算 - 合作模式
        /// </summary>
        private static ErrorCode SettleUserCoop(int userId, TBattleSettle settle)
        {
            if (settle == null)
            {
                Logger.LogError($"User[{userId}]: SettleUserCoop Para TBattleSettle settle is null");
                return(ErrorCode.FuncParameterIsNull);
            }
            var battleRes = BattleResConfig.Cache.FindKey((int)BattleType.COOP);

            if (battleRes == null)
            {
                Logger.LogError($"User[{userId}]: BattleResConfig.Cache.FindKey({(int)BattleType.COOP}) == null");
                return(ErrorCode.DataNotFound);
            }
            var profile = TUserProfile.Cache.FindKey(userId);

            if (profile == null)
            {
                Logger.LogError($"User[{userId}]: TUserProfile.Cache.FindKey({userId}) == null");
                return(ErrorCode.DataNotFound);
            }
            //顺序敏感
            //触发任务 - 完成任意战斗
            TaskCenterService.Update(userId, ConditionType.BATTLE, TaskOpType.Add, 1);
            //触发任务 - 完成PVE战斗
            TaskCenterService.Update(userId, ConditionType.PVE, TaskOpType.Add, 1);
            //触发任务 - 完成PVE回合数
            TaskCenterService.Update(userId, ConditionType.STAGE, TaskOpType.Equal, settle.Round);
            //更新合作档案
            ProfileService.UpdateCoopBattle(profile, settle.Round);
            TUserProfile.Cache.AddOrUpdate(profile);
            //回合数大于0时结算奖励
            if (settle.Round > 0)
            {
                //触发任务 - 累计PVE回合数
                TaskCenterService.Update(userId, ConditionType.STAGEADD, TaskOpType.Add, settle.Round);
                //战斗前广告加成
                var beforeAD = UserService.CheckBattleExtraBonus(userId, settle.BattleType, true);
                if (beforeAD)
                {
                    settle.ExtraBonusFlag = 1;
                }
                //合作奖励列表
                var coopBonusList = new TBonusList();
                //宝箱碎片=基础奖励 + 战前广告加成
                var err = GetCoopRewardCount(userId, settle.Round, battleRes.rewardChestCountList, beforeAD, out int shardCount, out int adsCount, out int extraCount);
                if (err != ErrorCode.Success)
                {
                    return(err);
                }
                // 基础
                err = coopBonusList.AddItem(userId, ConfigConstants.COOP_CHESTSHARD_ITEMID, shardCount);
                if (err != ErrorCode.Success)
                {
                    return(err);
                }
                // 广告
                err = coopBonusList.AddItem(userId, ConfigConstants.COOP_CHESTSHARD_ITEMID, adsCount);
                if (err != ErrorCode.Success)
                {
                    return(err);
                }
                // 活动or状态
                err = coopBonusList.AddItem(userId, ConfigConstants.COOP_CHESTSHARD_ITEMID, extraCount);
                if (err != ErrorCode.Success)
                {
                    return(err);
                }
                //添加奖励
                err = ItemService.AddBonus(userId, coopBonusList, AssetReason.BattleSettleCoop);
                if (err != ErrorCode.Success)
                {
                    return(err);
                }
                //返回奖励
                settle.BonusOutput = new TBonusOutput()
                {
                    BonusList = coopBonusList,
                };
            }
            return(ErrorCode.Success);
        }
예제 #2
0
        /// <summary>
        /// 玩家战斗结算 - 挑战模式
        /// </summary>
        private static ErrorCode SettleUserPK(int userId, TBattleSettle settle)
        {
            if (settle == null)
            {
                Logger.LogError($"User[{userId}]: SettleUserPk Para TBattleSettle settle is null");
                return(ErrorCode.FuncParameterIsNull);
            }
            //玩家创建房间的战斗不结算
            if (settle.IsManual)
            {
                return(ErrorCode.Success);
            }

            var profile = TUserProfile.Cache.FindKey(userId);

            if (profile == null)
            {
                Logger.LogError($"User[{userId}]: TUserProfile.Cache.FindKey({userId}) == null");
                return(ErrorCode.DataNotFound);
            }
            //顺序敏感
            //触发任务 - 完成任意战斗
            TaskCenterService.Update(userId, ConditionType.BATTLE, TaskOpType.Add, 1);
            //胜利
            if (settle.IsMyWin)
            {
                //触发任务 - 完成PVP战斗胜利
                TaskCenterService.Update(userId, ConditionType.PKWIN, TaskOpType.Add, 1);
                //战斗前广告加成
                bool beforeAD = UserService.CheckBattleExtraBonus(userId, settle.BattleType, true);
                if (beforeAD)
                {
                    settle.ExtraBonusFlag = 1;
                }
                //更新挑战档案
                ProfileService.UpdatePKBattle(profile, settle.IsMyWin, beforeAD, out int addScore, out int addGold);
                //创建结算奖励
                var bonusList = new TBonusList();
                //金币奖励
                var err = bonusList.AddItem(userId, ConfigConstants.COIN_ITEMID, addGold);
                if (err != ErrorCode.Success)
                {
                    return(err);
                }
                //添加奖励
                err = ItemService.AddBonus(userId, bonusList, AssetReason.BattleSettlePK);
                if (err != ErrorCode.Success)
                {
                    return(err);
                }
                //返回奖励
                settle.BonusOutput = new TBonusOutput()
                {
                    BonusList = bonusList,
                };

                //创建预存战斗后胜利看广告的奖励
                var afterADBonusList = new TBonusList(userId, bonusList);
                err = afterADBonusList.AddItem(userId, ConfigConstants.SCORE_ITEMID, addScore);
                if (err != ErrorCode.Success)
                {
                    return(err);
                }
                //返回战斗后胜利看广告的奖励倍数
                bonusList.ExtraFactor = ExtraBonusService.TrySaveExtraBonus(userId, ExtraBonusType.PKWINBONUS, afterADBonusList);
            }
            //失败
            else
            {
                //更新挑战档案
                ProfileService.UpdatePKBattle(profile, settle.IsMyWin, false, out int addScore, out int addGold);
                settle.ExtraBonusFlag = ExtraBonusService.TrySaveExtraBonus(userId, ExtraBonusType.PKLOSECHEST, null) > 0 ? 2 : 0;
            }
            TUserProfile.Cache.AddOrUpdate(profile);
            return(ErrorCode.Success);
        }