コード例 #1
0
        /// <summary>
        /// 玩家战斗胜利逻辑
        /// </summary>
        /// <param name="monsterTransArray">Monster trans array.</param>
        public void BattlePlayerWin(Transform[] monsterTransArray)
        {
            // 如果没有传入敌人,直接返回
            if (monsterTransArray.Length <= 0)
            {
                return;
            }

            // 记录击败的怪物数
            Player.mainPlayer.totaldefeatMonsterCount++;

            // 重置角色骨骼动画速率
            battlePlayerCtr.SetRoleAnimTimeScale(1.0f);
            battleMonsterCtr.SetRoleAnimTimeScale(1.0f);

            Transform trans = monsterTransArray [0];

            BattleMonsterController bmCtr = trans.GetComponent <BattleMonsterController> ();

            Monster monster = trans.GetComponent <Monster> ();

            MapWalkableEvent walkableEvent = trans.GetComponent <MapWalkableEvent> ();

            Player player = Player.mainPlayer;

            // 执行战斗结束的回调
            FightEndCallBacks();

            // 重置所有技能产生的属性变化
            battlePlayerCtr.agent.ClearPropertyChangesFromSkill();

            // 重置角色属性【按照脱离战斗时持有装备的正常情况重新计算一遍人物属性】
            battlePlayerCtr.agent.ResetBattleAgentProperties(false);

            // 怪物清空所有技能产生的属性变化
            battleMonsterCtr.agent.ClearPropertyChangesFromSkill();

            // 怪物重置属性
            battleMonsterCtr.agent.ResetBattleAgentProperties(false);

            // 玩家位置修正到标准位置【整数点位置】
            battlePlayerCtr.FixPositionToStandard();

            // 玩家等待当前动作结束
            battlePlayerCtr.ResetToWaitAfterCurrentRoleAnimEnd();

            Vector3 monsterPos = trans.position;

            walkableEvent.RefreshWalkableInfoWhenQuit(true);

            MapMonster mm = bmCtr.GetComponent <MapMonster> ();

            if (mm != null)
            {
                // 生成奖励物品
                Item rewardItem = mm.GenerateRewardItem();

                if (rewardItem != null)
                {
                    newMapGenerator.SetUpRewardInMap(rewardItem, trans.position);
                }

                if (mm.pairEventPos != -Vector3.one)
                {
                    newMapGenerator.ChangeMapEventStatusAtPosition(mm.pairEventPos);
                }

                if (monster.isBoss)
                {
                    MapEventsRecord.AddEventTriggeredRecord(mm.mapIndex, mm.oriPos);
                }
            }


            // 目前npc不参与战斗,下面的代码后续扩展可用
            MapNPC mn = bmCtr.GetComponent <MapNPC> ();

            if (mn != null)
            {
                Item rewardItem = Item.NewItemWith(mn.fightReward.rewardValue, 1);

                if (rewardItem != null)
                {
                    if (rewardItem.itemType == ItemType.Equipment)
                    {
                        Equipment        eqp     = rewardItem as Equipment;
                        EquipmentQuality quality = (EquipmentQuality)mn.fightReward.attachValue;
                        eqp.ResetPropertiesByQuality(quality);
                    }

                    newMapGenerator.SetUpRewardInMap(rewardItem, trans.position);
                }
            }


            // 开启屏幕行走点击
            EnableExploreInteractivity();
            // 标记不在战斗
            battlePlayerCtr.isInFight = false;
            // 标记不再地图事件中
            battlePlayerCtr.isInEvent = false;
            // 角色包围盒开启
            battlePlayerCtr.boxCollider.enabled = true;
            // 清除敌方信息
            battlePlayerCtr.enemy = null;

            //更新玩家金钱
            int goldGain = monster.rewardGold + player.extraGold;

            player.totalGold += goldGain;

            GameManager.Instance.soundManager.PlayAudioClip(CommonData.goldAudioName);

            expUICtr.SetUpGoldGainTintHUD(goldGain);

            player.experience += monster.rewardExperience + player.extraExperience; //更新玩家经验值

            bool isLevelUp = player.LevelUpIfExperienceEnough();                    //判断是否升级

            newMapGenerator.allMonstersInMap.Remove(mm);

            if (isLevelUp)
            {
                PlayLevelUpAnim();// 升级时播放升级动画

                DisableExploreInteractivity();

                expUICtr.ShowLevelUpPlane();
            }
            else
            {
                MapWalkableEventsStartAction();
            }

            // 更新角色状态栏
            battlePlayerCtr.UpdateStatusPlane();
        }