123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153 |
- using System.Timers;
- using Comp;
- using HttpApi;
- using UnityEngine;
- namespace Game
- {
- public class GameBattleState : GameState
- {
- private Timer _battleTimer;
- private bool _runBattle = false;
- public GameBattleState(GameCore gameCore) : base(gameCore)
- {
- }
- public override void PlayBattle()
- {
-
- }
- public override void BattleStart()
- {
- Debug.Log("battle start");
- if (_battleTimer == null)
- {
- Debug.Log("battle timer start");
- foreach (var cockActionComp in _gameCore.cockActionComps)
- {
- if (cockActionComp.Key == _gameCore.localPlayer.playerId)
- {
- cockActionComp.Value.gameObject.GetComponent<CockActionComp>().rightForward = true;
- }
- else
- {
- cockActionComp.Value.gameObject.GetComponent<CockActionComp>().rightForward = false;
- }
- cockActionComp.Value.gameObject.GetComponent<CockActionComp>().CockController.JumpAndAttack();
- }
- var followObject = _gameCore.GetCockActionCompByPlayerId(_gameCore.localPlayer.playerId).gameObject;
- _gameCore.camera.AddComponent<CameraFollow>().SetTarget(followObject.transform);
- _battleTimer = new Timer();
- _battleTimer.Interval = 1000;
- _battleTimer.Enabled = true;
- _battleTimer.Elapsed += OnBattleTimer;
- _battleTimer.Start();
- }
- }
- public override void LiftCock()
- {
- if (_gameCore.liftTimes > 0)
- _gameCore.TransitionToState(_gameCore.liftState);
- }
- public override void ExitBattle()
- {
- _runBattle = false;
- if (_battleTimer != null)
- {
- _battleTimer.Dispose();
- _battleTimer = null;
- }
- }
- public override void EndBattle()
- {
- }
- public override void EnterState()
- {
- _runBattle = true;
- }
- public override void ExitState()
- {
- _runBattle = false;
- }
- private void OnBattleTimer(object o, ElapsedEventArgs args)
- {
- if (!_runBattle)
- return;
- if (_gameCore.battleDetailObjs == null || _gameCore.battleDetailObjs.Count < 0)
- return;
- ExecuteBattleObj(_gameCore.battleDetailObjs.Last.Value);
- _gameCore.battleDetailObjs.RemoveLast();
- if (_gameCore.battleDetailObjs.Count != 0) return;
- Debug.Log("end battle");
- ExecuteLastBattleObj();
- _gameCore.battleMainComp.end = true;
- _battleTimer.Dispose();
- _battleTimer = null;
- }
- private void ExecuteBattleObj(BattleDetailObj battleDetailObj)
- {
- for (int i = 0; i <= battleDetailObj.logs.Length - 1; i++)
- {
- var log = battleDetailObj.logs[i];
- var attackCockActionComp = _gameCore.GetCockActionCompByPlayerId(log.from);
- attackCockActionComp.SetHighJump(i == 0);
- var counterattackCockActionComp = _gameCore.GetCockActionCompByPlayerId(log.to);
- var counterattackPlayer = _gameCore.localPlayer.playerId == log.to
- ? _gameCore.localPlayer
- : _gameCore.antiPlayer;
- counterattackPlayer.runTimeHp -= log.value;
- if (i == 0 && log.value == 0)
- {
- counterattackCockActionComp.CreateMiss();
- }
- else if (i == 0 && log.value > 0)
- {
- var cockHpComp = _gameCore.GetCockHpCompByPlayerId(log.to);
- cockHpComp.reduceHp = log.value;
- }
- switch (log.type)
- {
- case 1:
- attackCockActionComp.curAction = attackCockActionComp.CockController.JumpAndAttack;
- break;
- case 2:
- attackCockActionComp.curAction = attackCockActionComp.CockController.Attack;
- break;
- }
- }
- }
- private void ExecuteLastBattleObj()
- {
- var fromComp = _gameCore.GetCockActionCompByPlayerId(_gameCore.winPlayerId);
- int toPlayerId;
- if (_gameCore.winPlayerId == _gameCore.localPlayer.playerId)
- {
- toPlayerId = _gameCore.antiPlayer.playerId;
- }
- else
- {
- toPlayerId = _gameCore.localPlayer.playerId;
- }
- var toComp = _gameCore.GetCockActionCompByPlayerId(toPlayerId);
- fromComp.SetHighJump(true);
- toComp.SetHighJump(false);
- fromComp.curAction = fromComp.CockController.JumpAndAttack;
- toComp.curAction = toComp.CockController.Die;
- }
- }
- }
|