示例#1
0
    public virtual bool OneBattleStep(int step, GameData.BattleGameData.BattleStep stepData)
    {
        UnityEngine.Profiling.Profiler.BeginSample("BattleStatus.OneBattleStep");

        // Has 3 parts

        /**Part1:
         * 1).Trim the basic data of all warships in this step
         * 2).Calculate the count of a warship is attacked
         * */

        /**Part2:
         * 1).Simulate the all warships running logic
         * 2).Display its
         * */

        /**Part3: Implement in OnOneBattleStepEnd()
         * 1).Trim all warships InitialLife for the next step simulate
         * */
        // Debug.Log("The current stepID is : " + stepData.StepID.ToString());

        foreach (GameData.BattleGameData.BattleShip battleShip in stepData.BattleShips)
        {
            // // Search the Warship
            // WarshipL warship = Globals.Instance.MPlayerManager.GetWarship(battleShip.ShipID);
            //
            // // Assign the base value
            // warship.Property.WarshipCurrentLife = battleShip.CurrentLife;
            // warship.Property.WarshipCurrentPower = (short)battleShip.CurrentPower;

            // Attack is the separate logic
            GameData.BattleGameData.AttackState attackState = battleShip.AttackState;
            if (attackState == GameData.BattleGameData.AttackState.IDLE)
            {
                continue;
            }

            // Construct a skill or a attackEvent? Include multiple be attacked target
            foreach (GameData.BattleGameData.AttackedTarget attackedTarget in battleShip.AttackedTargets)
            {
                // Stat. the num of be attacked
                WarshipL targetWarship = Globals.Instance.MPlayerManager.GetWarship(attackedTarget.ShipID);
                if (null == targetWarship)
                {
                    Debug.Log("[BattleStatus]: Why the target ship " + attackedTarget.ShipID + " is null?");
                    continue;
                }

                targetWarship._numBeAttacked += 1;
            }
        }

        // Part2
        foreach (GameData.BattleGameData.BattleShip battleShip in stepData.BattleShips)
        {
            // Search the Warship
            WarshipL warship = Globals.Instance.MPlayerManager.GetWarship(battleShip.ShipID);
            if (null == warship)
            {
                Debug.Log("[BattleStatus]: Why the ship " + battleShip.ShipID + " is null?");
                continue;
            }

            // Assign the base value
            warship.Property.WarshipCurrentLife  = battleShip.CurrentLife;
            warship.Property.WarshipCurrentPower = (short)battleShip.CurrentPower;

            // tzz added for modify some bug
            //
            warship.GirlData.PropertyData.Life  = battleShip.CurrentLife;
            warship.GirlData.PropertyData.Power = battleShip.CurrentPower;

            Vector3 currentPosition = warship.U3DGameObject.transform.position;

            Vector3 targetPosition = HelpUtil.GetWarFiledGridPosition(battleShip.CurrentPosition);
            targetPosition += SceneOffset;

            // Perform the step logci
            GameData.BattleGameData.MoveState moveState = battleShip.MoveState;
            switch (moveState)
            {
            case GameData.BattleGameData.MoveState.MOVE:
            {
                // move speed
                warship.MoveTo(targetPosition);

                // tzz added
                // for teach first move in Teach first enter scene
                // check TeachFirstEnterGame.cs for detail
                //if(m_teachStartMovingEvent != null){
                //	m_teachStartMovingEvent(TeachBattleEvent.e_startMoving);
                //	m_teachStartMovingEvent = null;
                //
                //	battleStepDuration = 0.0f;
                //	_mDelayTime = DELAY_TIME;
                //}
                break;
            }

            case GameData.BattleGameData.MoveState.STOP:
            {
                warship.ForceMoveTo(targetPosition);
                break;
            }

            case GameData.BattleGameData.MoveState.SINK:
            {
                //warship.ForceSink();
                break;
            }
            }

            // Attack is the separate logic
            GameData.BattleGameData.AttackState attackState = battleShip.AttackState;
            if (attackState == GameData.BattleGameData.AttackState.IDLE)
            {
                continue;
            }

            // tzz added for setting buffer of fire
            if (warship.WarshipHeader != null && battleShip.BattleBuffersList != null)
            {
                warship.WarshipHeader.SetBufferStepInterval(battleShip.BattleBuffersList, step);
            }

            // Only perform the skill effect, construct the skill data now
            SkillDataSlot skillData = new SkillDataSlot(battleShip.SkillLogicID, warship._warshipID, (int)attackState);

            // Construct a skill or a attackEvent? Include multiple be attacked target
            int targetIndex = 0;
            foreach (GameData.BattleGameData.AttackedTarget attackedTarget in battleShip.AttackedTargets)
            {
                WarshipL targetWarship = Globals.Instance.MPlayerManager.GetWarship(attackedTarget.ShipID);
                if (null == targetWarship)
                {
                    Debug.Log("[BattleStatus]: Why the target ship " + attackedTarget.ShipID + " is null?");
                    continue;
                }

                int targetMoveState;
                GetWarshipMoveStateInStep(attackedTarget.ShipID, stepData, out targetMoveState);

                SkillDataSlot.AttackTargetData attackTargetData = new SkillDataSlot.AttackTargetData();

                attackTargetData._targetID         = attackedTarget.ShipID;
                attackTargetData._moveState        = targetMoveState;
                attackTargetData._beAttackedState  = (int)attackedTarget.AttackedState;
                attackTargetData._beAttackedDamage = attackedTarget.Damage;

                if (targetIndex == 0)
                {
                    skillData._primaryTargetID        = attackTargetData._targetID;
                    attackTargetData._isPrimaryTarget = true;
                }
                else
                {
                    attackTargetData._isPrimaryTarget = false;
                }

                skillData._attackTargetDataList.Add(attackedTarget.ShipID, attackTargetData);

                // tzz added for general command show
                if (warship.WarshipHeader != null && warship.WarshipHeader.Avatar != null &&
                    !skillData.MSkillData.BasicData.SkillIsNormalAttack &&             // is NOT normal skill
                    targetIndex == 0)                   // is first target
                {
                    BattleGeneralCmd.ShowGeneralCmd(warship.WarshipHeader.Avatar,
                                                    Globals.Instance.MDataTableManager.GetWordText(skillData.MSkillData.BasicData.SkillWord));
                }

                targetIndex++;
            }

            warship.Attack(skillData);
        }

        UnityEngine.Profiling.Profiler.EndSample();
        return(true);
    }
示例#2
0
    // 2012.04.05 LiHaojie Begin the battle logic
    public virtual void BeginBattleLogic()
    {
        // Recalculate the formation bounds
        actorFormations.Clear();
        enemyFormations.Clear();

        FleetL   fleet   = null;
        WarshipL warship = null;

        foreach (GameData.BattleGameData.Fleet fleetData in _battleResult.Fleets)
        {
            List <GameData.BattleGameData.Ship> shipDatas = fleetData.Ships;

            fleet = Globals.Instance.MPlayerManager.CreateFleet(fleetData.FleetID);
            fleet._isActorFleet  = !fleetData.NPCFleet;
            fleet._isAttachFleet = fleetData.IsAttacker;

            PlayerData data = null;
            if (_battleResult.BattleType == GameData.BattleGameData.BattleType.PORT_VIE_BATTLE &&
                Globals.Instance.MPortVieManager.puFlagReverseFleetPosition)
            {
                if (fleet._isAttachFleet)
                {
                    data = Globals.Instance.MGameDataManager.MEnemyData;
                }
                else
                {
                    data = Globals.Instance.MGameDataManager.MActorData;
                }
            }
            else
            {
                if (fleet._isAttachFleet)
                {
                    data = Globals.Instance.MGameDataManager.MActorData;
                }
                else
                {
                    data = Globals.Instance.MGameDataManager.MEnemyData;
                }
            }

            foreach (GameData.BattleGameData.Ship shipData in shipDatas)
            {
                GirlData wsData = data.GetGirlData(shipData.ShipID);

                //tzz added
                wsData.WarshipGeneralLogicID = shipData.GeneralLogicID;
                wsData.WarshipGeneralAvatar  = shipData.GeneralAvatar;

                fleet.CreateWarship(wsData, delegate(WarshipL ws)
                {
                    warship = ws;
                    warship.setBloodDisplay(true);
                    warship._warshipLogicID = shipData.LogicShipID;
//					warship.U3DGameObject.name = wsData.BasicData.Name;
                    warship.GameObjectTag = TagMaskDefine.GFAN_FIGHT_WARSHIP;

                    // Fleet data
                    warship.Property.WarshipFleetID    = fleet._fleetID;
                    warship.Property.WarshipIsAttacker = fleet._isAttachFleet;
                    warship.Property.WarshipIsNpc      = shipData.IsNpc;

                    // // A specifical value, use to simulate server running
                    warship._numBeAttacked = 0;

                    Vector3 position = HelpUtil.GetWarFiledGridPosition(shipData.Position);
                    position        += SceneOffset;
                    warship.ForceMoveTo(position);

                    // Rotate 180 around y axis
                    if (!fleet._isAttachFleet)
                    {
                        warship.U3DGameObject.transform.rotation = Quaternion.AngleAxis(180, Vector3.up);
                    }
                });

                if (fleet._isAttachFleet)
                {
                    AddFormationCell(shipData.Position, actorFormations);
                }
                else
                {
                    AddFormationCell(shipData.Position, enemyFormations);
                }
            }

            // If is Npc fleet
            if (fleetData.NPCFleet == true)
            {
                // The enemy fleet information
                _enemyFleet = fleet;
            }
            else
            {
                // The actor information
                _actorFleet = fleet;
            }

            _currentFleets.Add(fleet._fleetID, fleet);
        }

        //tzz added for store the fov in order restore when Battle end
        //
        CustomCameraFormerFov = Globals.Instance.MSceneManager.mMainCamera.fov;
        Globals.Instance.MSceneManager.mMainCamera.fov = 60;
    }