示例#1
0
 private void GetWarshipMoveStateInStep(long warshipID,
                                        GameData.BattleGameData.BattleStep stepData, out int moveState)
 {
     moveState = -1;
     foreach (GameData.BattleGameData.BattleShip battleShip in stepData.BattleShips)
     {
         if (battleShip.ShipID == warshipID)
         {
             moveState = (int)battleShip.MoveState;
             break;
         }
     }         // End foreach
 }
示例#2
0
        /**
         * @tzz
         * read from the Text stream
         *
         * @param _reader		reader stream (file or other stream)
         */
        public void ReadFromStream(StreamReader MReader)
        {
            int fleetCount = StrParser.ParseDecInt(MReader.ReadLine(), -1);

            for (int fleetIdx = 0; fleetIdx < fleetCount; ++fleetIdx)
            {
                Fleet fleetData = new Fleet();

                fleetData.FleetID    = StrParser.ParseDecInt(MReader.ReadLine(), -1);
                fleetData.NPCFleet   = StrParser.ParseBool(MReader.ReadLine(), false);
                fleetData.IsAttacker = StrParser.ParseBool(MReader.ReadLine(), false);

                int shipCount = StrParser.ParseDecInt(MReader.ReadLine(), -1);
                for (int shipIdx = 0; shipIdx < shipCount; ++shipIdx)
                {
                    Ship shipData = new Ship();
                    shipData.ShipID             = StrParser.ParseDecInt(MReader.ReadLine(), -1);
                    shipData.LogicShipID        = StrParser.ParseDecInt(MReader.ReadLine(), -1);
                    shipData.InitialCurrentLife = StrParser.ParseDecInt(MReader.ReadLine(), -1);
                    shipData.MaxLife            = StrParser.ParseDecInt(MReader.ReadLine(), -1);
                    shipData.Position           = MReader.ReadLine();
                    shipData.IsNpc  = StrParser.ParseBool(MReader.ReadLine(), false);
                    shipData.TypeID = StrParser.ParseDecInt(MReader.ReadLine(), -1);

                    fleetData.Ships.Add(shipData);
                }

                this.Fleets.Add(fleetData);
            }

            int battleStepCount = StrParser.ParseDecInt(MReader.ReadLine(), -1);

            for (int battleStepIdx = 0; battleStepIdx < battleStepCount; ++battleStepIdx)
            {
                BattleStep battleStep = new BattleStep();
                battleStep.StepID     = StrParser.ParseDecInt(MReader.ReadLine(), -1);
                battleStep.NextStepID = StrParser.ParseDecInt(MReader.ReadLine(), -1);
                int battleShipCount = StrParser.ParseDecInt(MReader.ReadLine(), -1);
                for (int battleShipIdx = 0; battleShipIdx < battleShipCount; ++battleShipIdx)
                {
                    BattleShip battleship = new BattleShip();
                    battleship.ShipID           = StrParser.ParseDecInt(MReader.ReadLine(), -1);
                    battleship.CurrentLife      = StrParser.ParseDecInt(MReader.ReadLine(), -1);
                    battleship.CurrentPower     = StrParser.ParseDecInt(MReader.ReadLine(), -1);
                    battleship.CurrentPosition  = MReader.ReadLine();
                    battleship.CurrentFillSpeed = StrParser.ParseDecInt(MReader.ReadLine(), -1);
                    battleship.MoveState        = (GameData.BattleGameData.MoveState)StrParser.ParseDecInt(MReader.ReadLine(), -1);
                    battleship.AttackState      = (GameData.BattleGameData.AttackState)StrParser.ParseDecInt(MReader.ReadLine(), -1);
                    battleship.SkillLogicID     = StrParser.ParseDecInt(MReader.ReadLine(), -1);

                    int targetCount = StrParser.ParseDecInt(MReader.ReadLine(), -1);
                    for (int targetIdx = 0; targetIdx < targetCount; ++targetIdx)
                    {
                        AttackedTarget target = new AttackedTarget();

                        target.ShipID        = StrParser.ParseDecInt(MReader.ReadLine(), -1);
                        target.Damage        = StrParser.ParseDecInt(MReader.ReadLine(), -1);
                        target.AttackedState = (AttackedState)StrParser.ParseDecInt(MReader.ReadLine(), -1);

                        battleship.AttackedTargets.Add(target);
                    }

                    battleStep.BattleShips.Add(battleship);
                }
                this.BattleSteps.Add(battleStep);
            }

            bool t_hasNPCDropItem = StrParser.ParseBool(MReader.ReadLine(), false);

            if (t_hasNPCDropItem)
            {
                _npcDropData = new DropData();

                _npcDropData.BasicContribution = StrParser.ParseDecInt(MReader.ReadLine(), -1);
                _npcDropData.BasicExp          = StrParser.ParseDecInt(MReader.ReadLine(), -1);
                _npcDropData.CopyScore         = StrParser.ParseDecInt(MReader.ReadLine(), -1);
                _npcDropData.Feat  = StrParser.ParseDecInt(MReader.ReadLine(), -1);
                _npcDropData.Ingot = StrParser.ParseDecInt(MReader.ReadLine(), -1);
                _npcDropData.Oil   = StrParser.ParseDecInt(MReader.ReadLine(), -1);
                _npcDropData.Type  = (DropType)StrParser.ParseDecInt(MReader.ReadLine(), -1);

                int t_dorpNum = StrParser.ParseDecInt(MReader.ReadLine(), 0);
                for (int i = 0; i < t_dorpNum; i++)
                {
                    ItemSlotData t_item = new ItemSlotData();
                    t_item.LocationID = StrParser.ParseDecInt(MReader.ReadLine(), -1);
                    // TODO: read the drop item
                }
            }

            _battleWinResult = (EBattleWinResult)StrParser.ParseDecInt(MReader.ReadLine(), 0);
            _chestID         = StrParser.ParseDecInt(MReader.ReadLine(), -1);
            _errorCode       = StrParser.ParseDecInt(MReader.ReadLine(), -1);

            // calculate fire buffer
            CalcFireBuffer();
        }
示例#3
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);
    }
示例#4
0
    public virtual void UpdateBattleLogic()
    {
        UnityEngine.Profiling.Profiler.BeginSample("BattleStatus.UpdateBattleLogic");

        switch (_mBattleState)
        {
        case EBattleState.DO_STEP:
        {
            // Per step execute GameDefines.BATTLE_STEP_TIME time
            if (_isChangeStep)
            {
                // Per battle step
                GameData.BattleGameData.BattleStep oneStepData = _battleResult.BattleSteps[battleStepFlag];
                OneBattleStep(battleStepFlag, oneStepData);

                _isChangeStep = false;

                battleStepFlag++;
                battleStepDuration = GameDefines.BATTLE_STEP_TIME;
            }

            battleStepDuration -= Time.deltaTime;
            if (battleStepDuration <= 0.0f)
            {
                if (battleStepFlag >= _battleResult.BattleSteps.Count)
                {
                    _mBattleState = EBattleState.DELAY;
                    UnityEngine.Profiling.Profiler.EndSample();
                    return;
                }
                else
                {
                    // Execute one battle step settlement
                    OnOneBattleStepEnd();

                    // Terminate current step, and prepare the next step
                    _isChangeStep = true;
                }
            }

            _mPublisher.NotifyOnStep();

            break;
        }

        case EBattleState.DELAY:
        {
            _mDelayTime += Time.deltaTime;
            if (_mDelayTime > DELAY_TIME)
            {
                _mBattleState = EBattleState.END;
            }

            _mPublisher.NotifyBattleDelay();
            break;
        }

        case EBattleState.END:
        {
            _isBattleEnd = true;
            EndBattleLogic();
            break;
        }
        }

        UnityEngine.Profiling.Profiler.EndSample();
    }