Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using UnityEngine;
- using System;
- using System.Collections;
- using System.Collections.Generic;
- using Commands;
- using Game;
- public class BattleViewController : MonoBehaviour {
- bool _surrender = false;
- #region Constants.
- private const float SFX_VOLUME = 0.1f;
- // Constants for my tanks moving.
- private const float MOVING_DURATION = 2;
- private const float TANKS_START_MOVING_DURATION = 1;
- private const float TANKS_END_MOVING_DURATION = 1;
- private const float MOVING_SPEED_X = 550f;
- private const float MOVING_SPEED_Y = 705f/1135f * MOVING_SPEED_X;//705/1135 - size of tile
- private const float DECORATIONS_PER_TURN = 0.66f;
- // Positions for battle turn label - it should be out of screen.
- private readonly Vector3 BATTLE_TURN_LABEL_START_POSITION = new Vector3(680, 0, -10);
- private readonly Vector3 BATTLE_TURN_LABEL_FINISH_POSITION = new Vector3(-680, 0, -10);
- // Delay between shooting in fight.
- private const float FIGHT_DELAY = 0.1f;
- // Sprite names for decorations.
- private string[] DECORATIONS = {
- "airplane1",
- "airplane2",
- "barrels",
- "boxes",
- "crater",
- "factory1",
- "factory2",
- "garage",
- "home1",
- "home2",
- "home3",
- // "barn",
- // "house",
- // "house01",
- // "house02",
- // "pillbox",
- // "pillbox01",
- // "pillbox02",
- // "pillbox03",
- // "pillbox04",
- // "pillbox05",
- // "pillbox06",
- // "wood01",
- // "wood02",
- // "wood03",
- // "wood04",
- // "tank_kaput",
- // "hedgehogs",
- };
- #endregion
- private GameObject _enemyTracks;
- private GameObject _myTracks;
- public GameObject enemyTracks {
- get {
- if (_enemyTracks == null) {
- _enemyTracks = transform.FindChild("BattleViewScene/EnemyTanks/Tracks").gameObject;
- }
- return _enemyTracks;
- }
- }
- public GameObject myTracks {
- get {
- if (_myTracks == null) {
- _myTracks = transform.FindChild("BattleViewScene/MyObjects/Tracks").gameObject;
- }
- return _myTracks;
- }
- }
- #region Class fields.
- private bool waitingForMove = true;
- public GameObject decorationPrefab;
- private List<Tank> myTanks = new List<Tank>(5);
- private List<Tank> enemyTanks = new List<Tank>(5);
- // Game objects to build tanks into.
- private GameObject[] myTanksContainers;
- // Game objects to build tanks into.
- private GameObject[] enemyTanksContainers = new GameObject[5];
- /// <summary>
- /// Used for moving tanks tween.
- /// </summary>
- AnimationCurve movingTanksCurve = new AnimationCurve(
- new Keyframe(0, 0),
- new Keyframe(0.5f, 0.5f, 2, 2),
- new Keyframe(1, 1)
- );
- // Explosions.
- private GameObject[] enemyExplosions;
- private Vector3[] originalEnemyExplosionPositions;
- private GameObject[] myExplosions;
- private Vector3[] originalMyExplosionPositions;
- private bool isInitialized;
- private Transform movingContainer;
- private Transform enemyTanksParent;
- private Transform myTanksParent;
- public GameObject lootPrefab;
- public GameObject tankPrefab;
- public GameObject repairBtnPrefab;
- public GameObject revivalBtnPrefab;
- public GameObject craterPrefab;
- // Dropped loot.
- private ArrayList items = new ArrayList();
- private List<UISprite> decorations = new List<UISprite>();
- private Transform decorationsContainer;
- private int[] playerFormation;
- public UILabel testLabel;
- private UILabel ironBoxLabel;
- private UILabel boxLabel;
- private UILabel coinsLabel;
- private UILabel turnLabel;
- private UILabel battleTurnLabel;
- private GameObject moveButton;
- #endregion
- void Init() {
- testLabel.gameObject.active = false;
- if (isInitialized)
- return;
- isInitialized = true;
- movingContainer = transform.FindChild("BattleViewScene/MovingLayer");
- enemyTanksParent = transform.FindChild("BattleViewScene/EnemyTanks");
- myTanksParent = transform.FindChild("BattleViewScene/MyObjects");
- decorationsContainer = movingContainer.FindChild("Decorations");
- Transform t = transform;
- ironBoxLabel = t.FindChild("BattleViewHUD/Top/IronBoxBar/Label").GetComponent<UILabel>();
- coinsLabel = t.FindChild("BattleViewHUD/Top/MoneyBar/Label").GetComponent<UILabel>();
- boxLabel = t.FindChild("BattleViewHUD/Top/BoxBar/Label").GetComponent<UILabel>();
- turnLabel = t.FindChild("BattleViewHUD/Top/BattleTurnsBar/Label").GetComponent<UILabel>();
- battleTurnLabel = t.FindChild("BattleViewHUD/BattleTurnLabel").GetComponent<UILabel>();
- moveButton = t.FindChild("BattleViewHUD/MoveBtnGo/MoveBtn").gameObject;
- }
- private void InitDecorations() {
- float decorationsCount = (GameManager.Instance.Battle.TotalTurns + 3) * DECORATIONS_PER_TURN * 2;
- float dx = MOVING_SPEED_X * MOVING_DURATION / DECORATIONS_PER_TURN;
- float dy = MOVING_SPEED_Y * MOVING_DURATION / DECORATIONS_PER_TURN;
- GameObject decoration;
- UISprite sprite;
- Transform decorationTransform;
- System.Random random = GameManager.RandomGenerator;
- while (decorations.Count < decorationsCount) {
- decoration = (GameObject) GameObject.Instantiate(decorationPrefab);
- decorationTransform = decoration.transform;
- decorationTransform.parent = decorationsContainer;
- sprite = decorationTransform.GetComponent<UISprite>();
- decorations.Add(sprite);
- }
- // Top line of decorations.
- // Vector3 pos = new Vector3(0, 300);
- Vector3 pos = new Vector3(-700, 83);
- int i = 0;
- float y;
- int maxYRandom = 100;
- for (; i < decorationsCount / 2; ++i) {
- sprite = decorations[i];
- sprite.spriteName = DECORATIONS[random.Next(0, DECORATIONS.Length)];
- sprite.MakePixelPerfect();
- y = pos.y;
- // pos.y += random.Next(maxYRandom);
- sprite.transform.localPosition = pos;
- pos.x += dx;
- pos.y = y + dy;
- }
- // Bottom line of decorations.
- // pos = new Vector3(500, -100);
- pos = new Vector3(400, -317);
- for (; i < decorationsCount; ++i) {
- sprite = decorations[i];
- sprite.spriteName = DECORATIONS[random.Next(0, DECORATIONS.Length)];
- sprite.MakePixelPerfect();
- y = pos.y;
- // pos.y -= random.Next(maxYRandom);
- sprite.transform.localPosition = pos;
- pos.x += dx;
- pos.y = y + dy;
- }
- }
- void PlayInfantrySFX(UISpriteAnimationExtended animation, int frameIndex) {
- SoundManager.PlaySFXFromGroup("Machinegun", null, SFX_VOLUME);
- }
- void PlayMortarSFX(UISpriteAnimationExtended animation, int frameIndex) {
- SoundManager.PlaySFXFromGroup("Mortar", null, SFX_VOLUME);
- }
- void PlayPtrSFX(UISpriteAnimationExtended animation, int frameIndex) {
- SoundManager.PlaySFXFromGroup("PTR", null, SFX_VOLUME + 0.2f);
- }
- void OnEnable() {
- Debug.Log("BattleViewController.OnEnable");
- Init();
- movingContainer.localPosition = Vector3.zero;
- enemyTanksParent.localPosition = Vector3.zero;
- battleTurnLabel.transform.localPosition = BATTLE_TURN_LABEL_START_POSITION;
- DestroyCraters();
- }
- void OnDisable() {
- Debug.Log("BattleViewController.OnDisable");
- foreach (GameObject item in items)
- {
- NGUITools.Destroy(item);
- }
- items.Clear();
- }
- #region Game events.
- public void StartNewBattle() {
- Debug.Log("StartNewBattle" + Time.time);
- UILabel lvl = transform.FindChild("BattleViewHUD/Top/lvlExpBar/lvlZoomer/lvl").GetComponent<UILabel>();
- UIFilledSprite exp = transform.FindChild("BattleViewHUD/Top/lvlExpBar/exp/Foreground").GetComponent<UIFilledSprite>();
- lvl.text = GameManager.Instance.Human.Lvl.ToString();
- //Debug.Log("expfill" + GameManager.Instance.Human.ExpFill);
- exp.fillAmount = GameManager.Instance.Human.ExpFill;
- transform.FindChild("BattleViewHUD/BottomRight/AttackButton").gameObject.SetActiveRecursively(false);
- SetButtonsActive(false);
- // Set tiles size and position.
- // Transform tiles = movingContainer.FindChild("Tiles");
- // UIDiagonalSprite sp = tiles.GetComponent<UIDiagonalSprite>();
- // Debug.Log("StartNewBattle.sp.innerUV.width: " + sp.innerUV.width/tiles.localScale.x*sp.atlas.pixelSize);
- // Size
- float width = Screen.width + GameManager.Instance.Battle.TotalTurns * MOVING_SPEED_X * (MOVING_DURATION + TANKS_START_MOVING_DURATION);
- float height = Screen.height + GameManager.Instance.Battle.TotalTurns * MOVING_SPEED_Y * (MOVING_DURATION + TANKS_START_MOVING_DURATION);
- // tiles.localScale = new Vector3(width, height, 1);
- // tiles.localPosition = new Vector3((width /*- Screen.width*/)/2, (height /*- Screen.height*/) / 2, 1);
- UpdateLabels();
- MainUIController.Instance.SetDarknessVisible(false);
- List<CardData> cards = GameManager.Instance.Human.GetBattleLine1();
- Tank tank;
- if (cards.Count > myTanks.Count) {
- while (cards.Count > myTanks.Count) {
- // create moar tanks;
- tank = NGUITools.AddChild(myTanksParent.gameObject, tankPrefab).GetComponent<Tank>();
- tank.GetComponent<UIButtonMessage>().target = gameObject;
- tank.HideAddText();
- tank.isEnemy = false;
- myTanks.Add(tank);
- GameObject tankTracksConteiner = NGUITools.AddChild(myTracks);
- tankTracksConteiner.name = "traks_" +myTanks.Count;
- tank.tracksContainer = tankTracksConteiner;
- }
- }
- for (int i = 0; i < cards.Count; ++i) {
- myTanks[i].SetTankActive(false);
- }
- // Initialize decorations.
- // InitDecorations();
- playerFormation = FormationsManager.GetCurrentFormation();
- for (int i = 0; i < cards.Count; ++i) {
- Debug.Log("myCard: " + cards[i].name);
- myTanks[i].InitWith(cards[i], 0, i);
- myTanks[i].transform.localPosition = new Vector3 (-5*100, -3*100,0) + GetTankPosition(playerFormation, i, false);
- myTanks[i].SetTankActive(true);
- myTanks[i].HideAddText();
- myTanks[i].image.gameObject.active = false;
- myTanks[i].lvl.gameObject.active = false;
- myTanks[i].nameLabel.gameObject.active = false;
- myTanks[i].AimRoot.SetActiveRecursively(false);
- myTanks[i].Bufs.Clear();
- myTanks[i].updateTracks();
- }
- StartCoroutine(StartMovingMyTanks(0.0f));
- VisualEffectManager.CreateEffect("CloudsFX", new Vector3(0, 0, -5), transform);
- //StartCoroutine(StartMovingEnemyTanks(0.0f));
- }
- public void ScaleGO(GameObject go, float duration, float startScaleKoef)
- {
- Debug.Log ("ScaleGO", go);
- Vector3 targetScale = go.transform.localScale * startScaleKoef;
- TweenScale.Begin(go, duration, targetScale);
- }
- // Called when new battle turn starts.
- public void StartBattleTurn()
- {
- _surrender = false;
- // enemyTanksParent.gameObject.SetActiveRecursively(false);
- moveButton.SetActiveRecursively(false);
- //moveButton.GetComponent<UISprite>().color = new Color(0.0f, 0.0f, 0.0f, 0.0f);
- transform.FindChild("BattleViewHUD/BottomRight/AttackButton").GetComponent<UIButtonMessage>().enabled = false;
- Debug.Log("StartBattleTurn");
- GameManager.Instance.Human.ActionInLocation++;
- waitingForMove = true;
- playerFormation = FormationsManager.GetCurrentFormation();
- // Show my tanks.
- if (GameManager.Instance.Battle.CurrentTurn == 1)
- {
- // List<CardData> cards = GameManager.Instance.Human.GetBattleLine1();
- // for (int i = 0; i < cards.Count; ++i) {
- // Debug.Log("myCard: " + cards[i].name);
- // myTanks[i].InitWith(cards[i], 0, i);
- // myTanks[i].transform.localPosition = GetTankPosition(playerFormation, i, false);
- // myTanks[i].SetTankActive(true);
- // myTanks[i].HideAddText();
- // myTanks[i].image.gameObject.active = false;
- // myTanks[i].lvl.gameObject.active = false;
- // myTanks[i].nameLabel.gameObject.active = false;
- // myTanks[i].AimRoot.SetActiveRecursively(false);
- // myTanks[i].Bufs.Clear();
- // }
- }
- else
- foreach (var tank in myTanks)
- {
- tank.Bufs.Clear();
- tank.AimRoot.SetActiveRecursively(false);
- tank.HideAddText();
- tank.ShowButtons(true);
- if (tank.Card.hp <= 0)
- {
- var reserve = GameManager.Instance.Human.GetLineCards(1 - tank.Line)[tank.Index];
- if (reserve.hp > 0)
- {
- tank.InitWith(reserve, 1 - tank.Line, tank.Index);
- }
- else
- tank.SetTankActive(false);
- }
- }
- // StartMovingMyTanks();
- UpdateLabels();
- StartCoroutine( StartMovingEnemyTanks(0));
- ShowBattleTurnLabel();
- }
- #endregion
- #region Button handlers.
- void OnAttackClicked(GameObject sender) {
- Debug.Log("OnAttackClicked", sender);
- SoundManager.PlaySFXFromGroup("Attack");
- transform.FindChild("BattleViewHUD/BottomRight/AttackButton").GetComponent<UIFramedButtonExt>().disableButton();
- SetButtonsActive(false);
- foreach (var tank in myTanks) {
- tank.ShowButtons(false);
- }
- StartCoroutine(AnimateFight());
- foreach (var t in enemyTanks)
- t.DisableAim();
- }
- void OnMoveClicked(GameObject sender) {
- //moveButton.SetActiveRecursively(false);
- //moveButton.GetComponent<UISprite>().color = new Color(0.0f, 1.0f, 0.0f, 0.0f);
- Debug.Log("OnMoveClicked", sender);
- SoundManager.PlaySFXFromGroup("TanksMove");
- transform.FindChild("BattleViewHUD/BottomRight/AttackButton").GetComponent<UIFramedButtonExt>().disableButton();
- ServerEmulation.EmulateStartBattleTurn();
- }
- void OnDefendClicked(GameObject sender) {
- SetButtonsActive(false);
- }
- void OnCapitulirenClicked(GameObject sender) {
- _surrender = true;
- ShowDefeatScreen(null);
- }
- void OnTankClicked(GameObject sender) {
- Debug.Log("BattleViewController.OnTankClicked");
- }
- #endregion
- public GUITexture Mockup
- {
- get
- {
- return UnityUtils.FindUIComponent<GUITexture>("Mockup");
- }
- }
- Rect mockupPixelInset;
- #region Animation coroutines.
- void AnimateMyMove(Vector3 offset, UITweener.OnFinished onFinished) {
- Vector3 pos;
- // Tank with this index will start moving with random delay.
- int delayedTankIndex = GameManager.RandomGenerator.Next(0, 2);
- TweenPosition tween;
- for (int i = 0; i < myTanks.Count; ++i) {
- pos = myTanks[i].transform.localPosition;
- pos += offset;
- tween = TweenPosition.Begin(myTanks[i].gameObject, 1.0f, pos);
- tween.animationCurve = movingTanksCurve;
- // There is little issue in NGUI tweens: tween start with previous delay value, even if we change it after Begin().
- // This new delay will be used for next tween execution, so random will be used anyway.
- if (delayedTankIndex == i) {
- tween.delay = GameManager.RandomGenerator.Next(1, 6) * 0.1f;
- tween.onFinished = onFinished;
- } else {
- tween.delay = 0;
- }
- }
- waitingForMove = false;
- }
- /// <summary>
- /// Raises the animation finished event.
- /// </summary>
- /// <param name='animation'>
- /// Animation that finished.
- /// </param>
- void OnAnimationFinished(UISpriteAnimationExtended animation) {
- // random delay: 2-4 sec
- float delay;
- if (waitingForMove) {
- delay = 2 + 0.1f * GameManager.RandomGenerator.Next(20);
- } else {
- delay = 0.5f;
- }
- animation.Reset(delay);
- }
- #endregion
- void ShowEnemyTanks(bool visible)
- {
- foreach(Tank tank in enemyTanks) {
- if (visible) {
- tank.FadeIn();
- }
- tank.SetTankActive(visible);
- tank.HideAddText();
- }
- }
- /*
- IEnumerator AnimateEnemyFire(MoveResponse move) {
- int count = playerFormation.Length;
- CardData card;
- int damage;
- Tank tank;
- for (int i = 0; i < enemyTanks.Count; ++i) {
- // foreach(Tank tank in enemyTanks) {
- tank = enemyTanks[i];
- tank.Attack();
- SoundManager.PlaySFXFromGroup("Tank");
- // Damage my tank.
- tank = myTanks[i];
- card = tank.Card;
- damage = card.maxHp / (GameManager.Instance.Battle.TotalTurns + 1);
- tank.Damage(damage);
- yield return new WaitForSeconds(0.2f + 0.01f * GameManager.RandomGenerator.Next(5));
- }
- }
- */
- IEnumerator AnimateTankExplosions(List<Tank> tanks, int deltaHP)
- {
- for (int i = 0; i < deltaHP; ++i) {
- VisualEffectManager.CreateEffect("Explosion01", Vector3.zero, tanks[i].transform);
- yield return new WaitForSeconds(0.15f);
- }
- for (int i = 0; i < deltaHP; ++i) {
- if (tanks[i].isEnemy) {
- tanks[i].tankParts = Tank.buildAtGameObject("burned_c_enemy_", tanks[i]);
- tanks[i].FadeOut();
- } else {
- tanks[i].tankParts = Tank.buildAtGameObject("burned_c_", tanks[i]);
- }
- }
- }
- void SetButtonsActive(bool val) {
- // Debug.Log("SetButtonsActive " + val);
- UnityUtils.FindUIComponent<UIButtonMessage>("BottomRight/AttackButton", transform).enabled = val;
- for (int i = 0; i < myTanks.Count; ++i) {
- myTanks[i].SetButtonActive(val);
- }
- }
- private void ShowVictoryScreen(BattleResult result) {
- var controller = MainUIController.Instance.VictoryScreen.GetComponent<VictoryScreenController>();
- controller.SetTrophies(result.trophies, result.coins);
- DialogsController.AddToQueue(UIState.Victory, result);
- }
- private void ShowDefeatScreen(UITweener tween) {
- DialogsController.AddToQueue(UIState.Loose, null);
- }
- float rnd() {
- return UnityEngine.Random.Range(0.0f, 1.0f);
- }
- //! private void StartMovingMyTanks() {
- //! SetButtonsActive(false);
- //!
- //! for (int i = 0; i < playerFormation.Length; ++i) {
- //! myTanks[i].StartDustMovingAnim(0);
- //! // myTanks[i].korpusMove(TANKS_START_MOVING_DURATION);
- //! }
- //!
- //! Vector3 startPos = - new Vector3(MOVING_SPEED_X * TANKS_START_MOVING_DURATION, MOVING_SPEED_Y * TANKS_START_MOVING_DURATION, 0.0f);
- //!
- //! myTanksParent.localPosition = startPos;
- //! TweenPosition tween = TweenPosition.Begin(myTanksParent.gameObject,
- //! TANKS_START_MOVING_DURATION, Vector3.zero, 0.0f);
- //! tween.onFinished = FinishMyTanksMoving;
- //! }
- //! sl func
- private IEnumerator StartMovingMyTanks(float delay) {
- yield return new WaitForSeconds(delay);
- SetButtonsActive(false);
- float timeLast = -1;
- for (int i = 0; i < playerFormation.Length; ++i) {
- myTanks[i].StartDustMovingAnim(0);
- float t = myTanks[i].beginBattleMove( 100, 0, 0.5f, 3.0f*rnd()).x;
- if (t >= timeLast) {
- timeLast = t;
- }
- }
- //! Vector3 pos = movingContainer.localPosition + new Vector3 (- 3*5*35, - 3*3*35, 0);
- //!
- //! Debug.Log ("timeLast =" +timeLast);
- //!
- //! TweenPosition tweenN = TweenPosition.Begin(movingContainer.gameObject, timeLast*0.65f, pos,timeLast*0.35f);
- //!
- //! tweenN.animationCurve = new AnimationCurve (new Keyframe(0.0f,0.0f), new Keyframe(1.0f,1.0f));
- //! StartCoroutine(OnFinishMovingMyTanks(timeLast));
- }
- //! private void FinishMyTanksMoving(UITweener tween) {
- //! for (int i = 0; i < playerFormation.Length; ++i)
- //! if (myTanks[i].Card.hp > 0)
- //! {
- //! myTanks[i].korpusMove(12);
- //! myTanks[i].StopDustMovingAnim();
- //!
- //! }
- //! SetButtonsActive(true);
- //!
- //! }
- //! sl func
- IEnumerator StartMovingEnemyTanks (float time)
- {
- yield return new WaitForSeconds(time);
- CreateEnemyTanks ();
- //! Transform enemyTanksParent = transform.FindChild("BattleViewScene/MovingLayer/EnemyTanks");
- //! enemyTanksParent.gameObject.active = true;
- //! enemyTanksParent.localPosition = enemyTanksParent.localPosition + new Vector3(+3*5*35.0f, +3*3*35.0f, 0.0f);
- float timeLast = -1;
- List<int> itemsToRemove = new List<int> ();
- //for (int i = 0; i < playerFormation.Length; ++i) {
- for (int i = 0; i < enemyTanks.Count; i++) {
- if (enemyTanks [i].Card.hp > 0) {
- enemyTanks [i].StartDustMovingAnim (0);
- float t = enemyTanks [i].beginBattleMove (100, 0, 0.5f, 3.0f * rnd ()).x;
- if (t >= timeLast) {
- timeLast = t;
- }
- } else {
- //NGUITools.Destroy (enemyTanks [i].gameObject);
- //enemyTanks.RemoveAt (i);
- itemsToRemove.Add (i);
- }
- }
- for (int i=itemsToRemove.Count-1; i>=0; i--) {
- NGUITools.Destroy (enemyTanks [itemsToRemove[i]].gameObject);
- enemyTanks.RemoveAt (itemsToRemove [i]);
- }
- StartCoroutine (OnFinishMovingEnemyTanks (timeLast));
- }
- //! private void StartMovingEnemyTanks() {
- //! CreateEnemyTanks();
- //! enemyTanksParent.gameObject.active = true;
- //! for (int i = 0; i < playerFormation.Length; ++i) {
- //! enemyTanks[i].korpusMove2();
- //! }
- //!
- //! Vector3 startPos = new Vector3(MOVING_SPEED_X * TANKS_START_MOVING_DURATION, MOVING_SPEED_Y * TANKS_START_MOVING_DURATION, 0.0f);
- //!
- //! transform.FindChild("BattleViewScene/EnemyTanks").localPosition = startPos;
- //! TweenPosition tween = TweenPosition.Begin(transform.FindChild("BattleViewScene/EnemyTanks").gameObject,
- //! TANKS_START_MOVING_DURATION, Vector3.zero, 0.0f);
- //! tween.onFinished = OnFinishEnemyMoving;
- //! }
- //! sl func
- IEnumerator OnFinishMovingEnemyTanks(float time ) {
- yield return new WaitForSeconds(time);
- UpdateLabels();
- // ShowBattleTurnLabel();
- StartCoroutine(showAims());
- }
- //! private void OnFinishInitMoving(UITweener tween) {
- //! Vector3 pos = new Vector3 (- MOVING_SPEED_X * MOVING_DURATION, - MOVING_SPEED_Y * MOVING_DURATION, 0);
- //!
- //! /*foreach(Tank tank in enemyTanks) {
- //! enemyPos = tank.transform.localPosition;
- //! enemyPos -= pos;
- //! tank.transform.localPosition = enemyPos;
- //! }*/
- //!
- //!// for (int i = 0; i < playerFormation.Length; ++i) {
- //!// myTanks[i].korpusMove(12);
- //!// }
- //!
- //!
- //! pos += movingContainer.localPosition;
- //!
- //! TweenPosition tweenN = TweenPosition.Begin(movingContainer.gameObject, MOVING_DURATION, pos);
- //! tweenN.onFinished = OnFinishEndMoving;
- //! }
- //! private void OnFinishEndMoving(UITweener tween) {
- //! for (int i = 0; i < playerFormation.Length; ++i)
- //! if (myTanks[i].Card.hp > 0)
- //! {
- //! myTanks[i].korpusMove(12);
- //! myTanks[i].StopDustMovingAnim();
- //!
- //! }
- //! Vector3 pos = new Vector3 (- MOVING_SPEED_X * TANKS_END_MOVING_DURATION, - MOVING_SPEED_Y * TANKS_END_MOVING_DURATION, 0);
- //! pos += movingContainer.localPosition;
- //! TweenPosition tweenP = TweenPosition.Begin(movingContainer.gameObject, TANKS_END_MOVING_DURATION, pos);
- //! TweenPosition tweenN = TweenPosition.Begin(transform.FindChild("BattleViewScene/MyObjects").gameObject, TANKS_END_MOVING_DURATION, transform.FindChild("BattleViewScene/MyObjects").localPosition - new Vector3(MOVING_SPEED_X * TANKS_END_MOVING_DURATION, MOVING_SPEED_Y * TANKS_END_MOVING_DURATION, 0.0f), 0.0f);
- //! tweenN.onFinished = OnFinishMoving;
- //! }
- //! private void OnFinishMoving(UITweener tween) {
- //! UpdateLabels();
- //!
- //!
- //! ShowBattleTurnLabel();
- //! CreateEnemyTanks();
- //! enemyTanksParent.gameObject.active = true;
- //! enemyTanksParent.localPosition = new Vector3(MOVING_SPEED_X * TANKS_START_MOVING_DURATION, MOVING_SPEED_Y * TANKS_START_MOVING_DURATION, 0.0f);
- //! TweenPosition tweenNew = TweenPosition.Begin(enemyTanksParent.gameObject, TANKS_START_MOVING_DURATION, - new Vector3( MOVING_SPEED_X * 2.5f, MOVING_SPEED_Y * 2.5f, 0.0f));
- //! tweenNew.onFinished = OnFinishEnemyMoving;
- //! for (int i = 0; i < playerFormation.Length; ++i) {
- //! enemyTanks[i].korpusMove2();
- //! }
- //! }
- //! private void OnFinishEnemyMoving(UITweener tween) {
- //! StartCoroutine(showAims());
- //!
- //! FinishMyTanksMoving(tween);
- //! }
- private IEnumerator showAims ()
- {
- Debug.Log ("showaims");
- SoundManager.PlaySFXFromGroup ("EnemyDetected", null, 0.5f);
- //for (int i = 0; i < playerFormation.Length; ++i) {
- for (int i = 0; i < enemyTanks.Count; ++i) {
- if (enemyTanks [i].Card.hp > 0) {
- yield return new WaitForSeconds(0.1f);
- enemyTanks [i].ShowAim ();
- // enemyTanks[i].StopDustMovingAnim();
- // enemyTanks[i].korpusMove2();
- }
- }
- transform.FindChild ("BattleViewHUD/BottomRight/AttackButton/TweenTarget/Icon").GetComponent<UISprite> ().spriteName = "attack_icon";
- transform.FindChild ("BattleViewHUD/BottomRight/AttackButton/TweenTarget/Background").GetComponent<UISprite> ().color = new Color (0.59f, 0.0f, 0.0f, 0.1f);
- transform.FindChild ("BattleViewHUD/BottomRight/AttackButton").GetComponent<UIButtonMessage> ().functionName = "OnAttackClicked";
- //transform.FindChild("BattleViewHUD/BottomRight/AttackButton").gameObject.SetActiveRecursively(true);
- transform.FindChild ("BattleViewHUD/BottomRight/AttackButton").GetComponent<UIFramedButtonExt> ().enableButton ();
- }
- private void CreateEnemyTanks ()
- {
- //Transform enemyTanksParent = transform.FindChild("BattleViewScene/EnemyTanks");
- //enemyTanksParent.gameObject.SetActiveRecursively(true);
- Battle battle = GameManager.Instance.Battle;
- Debug.Log ("Location ID = " + GameManager.Instance.Human.LocationId + " Sector ID + " + battle.SectorID);
- CardData[] cards = ContentManager.Instance.getTurnData (GameManager.Instance.Human.LocationId, battle.SectorID, battle.CurrentTurn, GameManager.Instance.Human.ActionInLocation).pveBattle.deck.ToArray ();//GameManager.Instance.Battle.TurnData.enemy.cards;
- Tank enemyTank;
- if (cards.Length > enemyTanks.Count) {
- Transform enemyTanksParent = transform.FindChild ("BattleViewScene/EnemyTanks");
- while (cards.Length > enemyTanks.Count) {
- // create moar tanks;
- enemyTank = NGUITools.AddChild (enemyTanksParent.gameObject, tankPrefab).GetComponent<Tank> ();
- enemyTank.HideAddText ();
- enemyTank.SetButtonActive (false);
- enemyTank.isEnemy = true;
- enemyTank.Bufs.Clear ();
- enemyTank.Bufs.Add (new BufData () {type = BufType.Attack, value = 0.5f});
- enemyTanks.Add (enemyTank);
- GameObject tankTracksConteiner = NGUITools.AddChild (enemyTracks);
- tankTracksConteiner.name = "traks_" + enemyTanks.Count;
- enemyTank.tracksContainer = tankTracksConteiner;
- }
- }
- foreach (Tank tank in enemyTanks) {
- tank.SetTankActive (false);
- }
- int[] formation = ContentManager.Instance.getTurnData (GameManager.Instance.Human.LocationId, battle.SectorID, battle.CurrentTurn, GameManager.Instance.Human.ActionInLocation).pveBattle.formation.positions;//GameManager.Instance.Battle.TurnData.enemy.formation.positions;// FormationsManager.GetCurrentFormation();
- int count = cards.Length;
- for (int i = 0; i < count; ++i) {
- //NB. Dirty trick - set hp to maxHP.
- cards [i].hp = cards [i].maxHp;
- enemyTanks [i].InitWith (cards [i], 0, i);
- enemyTanks [i].transform.localPosition = new Vector3 (5 * 100, 3 * 100, 0) + GetTankPosition (formation, i, true);
- enemyTanks [i].updateTracks ();
- enemyTanks [i].AimRoot.SetActiveRecursively (false);
- }
- ShowEnemyTanks (true);
- for (int i = 0; i < count; ++i) {
- enemyTanks [i].image.gameObject.active = false;
- enemyTanks [i].lvl.gameObject.active = false;
- enemyTanks [i].nameLabel.gameObject.active = false;
- enemyTanks [i].AimRoot.SetActiveRecursively (false);
- }
- }
- /*public const float HIGHLIGHT_DELAY = 0.1f;
- public const float TanksMoves.Instance.DELAY_BEFORE_FIRE = 0.1f;
- private const float TanksMoves.Instance.DELAY_BEFORE_DAMAGE = 0.2f;
- private const float TanksMoves.Instance.DELAY_AFTER_DAMAGE = 0.1f;
- private const float TanksMoves.Instance.DELAY_AFTER_END = 0.1f;*/
- void CheckIsTankAlive (Tank _attacked, int i, Tank attacker)
- {
- //TanksMoves.Instance.
- if (i<0)
- return;
- if (_attacked.Card.hp > 0) {
- //_attacked.HighlightTank(true, TanksMoves.Instance.HIGHLIGHT_DELAY, new Color(0.0f, 0.0f, 0.0f, 0.0f));
- }
- else
- {
- //_attacked.HighlightTank(true, 0.0f, new Color(0.0f, 0.0f, 0.0f, 0.0f));
- // Enemy tank is dead.
- VisualEffectManager.CreateEffect("Explosion01", Vector3.zero, _attacked.transform);
- if (_attacked.isEnemy)
- {
- _attacked.tankParts = Tank.buildAtGameObject("burned_c_enemy_", _attacked);
- _attacked.FadeOut();
- GameObject crater = (GameObject) GameObject.Instantiate(craterPrefab);
- Transform craterTransform = crater.transform;
- Vector3 scale = craterTransform.localScale;
- craterTransform.parent = decorationsContainer.FindChild("Craters");
- craterTransform.localScale = scale;
- Vector3 pos = _attacked.transform.localPosition;
- pos.x += GameManager.RandomGenerator.Next(50) - 25;
- pos.y += GameManager.RandomGenerator.Next(50) - 25;
- craterTransform.localPosition = pos;
- }
- else
- {
- _attacked.tankParts = Tank.buildAtGameObject("burned_c_", _attacked);
- }
- // Loot
- if (_attacked.isEnemy)
- {
- LootData loot = GameManager.Instance.GenerateLoot();
- int coinsCount = (int)(loot.coins / (playerFormation.Length * 10));
- if (loot.coins > 0) {
- for (int k = 0; k < coinsCount; ++k) {
- //Debug.Log("zzzzzzzzz" + (_attacked.gameObject.transform.localPosition + _attacked.gameObject.transform.parent.transform.localPosition).ToString());
- DropItem(_attacked.gameObject.transform.localPosition + _attacked.gameObject.transform.parent.transform.localPosition, "coin");
- }
- }
- if (loot.box > 0) {
- DropItem(_attacked.gameObject.transform.localPosition + _attacked.gameObject.transform.parent.transform.localPosition, "box");
- }
- if (loot.ironBox > 0) {
- DropItem(_attacked.gameObject.transform.localPosition + _attacked.gameObject.transform.parent.transform.localPosition, "iron-box");
- }
- DropStar(_attacked.gameObject.transform, attacker.transform);
- DropWrench(_attacked.gameObject.transform, attacker.transform);
- UpdateLabels();
- }
- }
- }
- int ChooseEnemyTankForAttack(List<Tank> enemyTanks, int attackerId, List<Tank> myTanks) {
- int diff = 1;
- if(myTanks.Count == enemyTanks.Count)
- diff = 0;
- else
- {
- if(enemyTanks.Count > myTanks.Count)
- diff = -1;
- }
- int returnedID = 0;
- int i = 0;
- for (i=0; i<5; i++)
- {
- int tmpid = attackerId - diff;
- if (tmpid - i >= 0 && tmpid - i < enemyTanks.Count && enemyTanks[tmpid - i] != null && enemyTanks[tmpid - i].Card.hp > 0)
- {
- returnedID = tmpid -i;
- break;
- }
- if (tmpid + i >=0 && tmpid + i < enemyTanks.Count && enemyTanks[tmpid + i] != null && enemyTanks[tmpid + i].Card.hp > 0)
- {
- returnedID = tmpid + i;
- break;
- }
- }
- Debug.Log("at" + attackerId + " ret " + returnedID + " " + enemyTanks.Count + " i=" + i);
- return returnedID;
- }
- private IEnumerator AnimateNormalAttack (Tank _attacker, List<Tank> enemiesList, int actorIndex, List<Tank> myList)
- {
- float timeLength = 0.0f;
- var _attacked = enemiesList [ChooseEnemyTankForAttack (enemiesList, actorIndex, myList)];
- yield return new WaitForSeconds(0);
- if (_attacked != null) {
- // _attacker.HighlightTank(true, TanksMoves.Instance.HIGHLIGHT_DELAY, new Color(1.0f, 1.0f, 1.0f, 1.0f));
- // _attacked.HighlightTank(true, TanksMoves.Instance.HIGHLIGHT_DELAY, new Color(1.0f, 0.0f, 0.0f, 1.0f));
- // VisualEffect effect = VisualEffectManager.CreateEffect("ColorFrameFX", Vector3.zero, _attacked.transform);
- // ColorFrameFX frame = (ColorFrameFX) effect;
- // frame.transform.rotation = _attacked.transform.rotation;
- // frame.transform.Rotate(50,10,-41);
- // frame.Color = Color.red;
- VisualEffect effect;
- SWFClipFX swf;
- /* //было
- effect = VisualEffectManager.CreateEffect ("GreenFrameFX", Vector3.zero, _attacker.transform);
- swf = (SWFClipFX)effect;
- swf.FPS = TanksMoves.Instance.HIGHLIGHT_GREEN_FPS;
- yield return new WaitForSeconds(TanksMoves.Instance.HIGHLIGHT_DELAY);
- */
- HighlightFX greenFrame = HighlightFX.CreateFX(HighlightFX._FRAME_KIND.GREEN, _attacker.gameObject);
- //greenFrame.
- Debug.Log("!!!! Starting green 1 - begin");
- yield return (greenFrame.showInState());
- Debug.Log("!!!! Starting green 1 - end");
- //UnityEditor.EditorApplication.isPaused = true;
- // effect = VisualEffectManager.CreateEffect("ColorFrameFX", Vector3.zero, _attacker.transform);
- // frame = (ColorFrameFX) effect;
- // frame.transform.rotation = _attacker.transform.rotation;
- // frame.transform.Rotate(50,10,-41);
- // frame.Color = Color.green;
- /* //было
- effect = VisualEffectManager.CreateEffect ("RedFrameFX", Vector3.zero, _attacked.transform);
- swf = (SWFClipFX)effect;
- swf.FPS = TanksMoves.Instance.HIGHLIGHT_RED_FPS;
- yield return new WaitForSeconds(TanksMoves.Instance.HIGHLIGHT_DELAY + TanksMoves.Instance.DELAY_BEFORE_FIRE);
- */
- HighlightFX redFrame = HighlightFX.CreateFX(HighlightFX._FRAME_KIND.RED, _attacked.gameObject);
- Debug.Log("!!!! Starting red 1 - begin");
- yield return (redFrame.showInState());
- Debug.Log("!!!! Starting red 1 - end");
- // We will kill enemy tank with 2 shots.
- _attacker.Attack ();
- var cardProto = _attacker.Card.GetPrototype ();
- SoundManager.PlaySFXFromGroup (string.IsNullOrEmpty (cardProto.sfx) ? "Tank" : cardProto.sfx);
- // Damage enemy tank.
- //tank = enemyTanks[i];
- if (_attacked.Card.hp > 0) {
- yield return new WaitForSeconds(TanksMoves.Instance.DELAY_BEFORE_DAMAGE);
- _attacked.Damage (ServerEmulation.GetDamage (_attacker.Card, _attacker.Bufs, _attacked.Card, _attacked.Bufs));
- VisualEffectManager.CreateEffect ("Explosion01", Vector3.zero, _attacked.transform);
- yield return new WaitForSeconds(TanksMoves.Instance.DELAY_AFTER_DAMAGE);
- CheckIsTankAlive (_attacked, enemiesList.IndexOf (_attacked), _attacker);
- }
- // _attacker.HighlightTank(true, TanksMoves.Instance.HIGHLIGHT_DELAY, new Color(1.0f, 1.0f, 1.0f, 0.0f));
- Debug.Log("!!!! Starting green 2 - begin");
- yield return (redFrame.showOutState());
- Debug.Log("!!!! Starting green 2 - end");
- Debug.Log("!!!! Starting red 2 - begin");
- yield return (greenFrame.showOutState());
- Debug.Log("!!!! Starting red 2 - end");
- yield return new WaitForSeconds(TanksMoves.Instance.HIGHLIGHT_DELAY + TanksMoves.Instance.DELAY_AFTER_END);
- }
- }
- static int Strongest(Tank x, Tank y)
- {
- if (x.Card.hp > y.Card.hp) return -1; else if (x.Card.hp == y.Card.hp) return 0; return -1;
- }
- static int Weakest(Tank x, Tank y)
- {
- if (x.Card.hp > y.Card.hp) return -1; else if (x.Card.hp == y.Card.hp) return 0; return -1;
- }
- private IEnumerator AnimateSkill (Tank _attacker, List<Tank> friendsList, List<Tank> enemiesList)
- {
- float timeLength = 0.0f;
- // TODO: Split it into server-view functions
- if (_attacker.Card.hp > 0) {
- // Get targets
- List<Tank> targets = new List<Tank> ();
- List<Tank> enemies = new List<Tank> (enemiesList);
- List<Tank> friends = new List<Tank> (friendsList);
- bool isEnemy = false;
- int actorIndex = friendsList.IndexOf (_attacker);
- friends.Remove (_attacker);
- targets.Add (_attacker);
- //if(actorIndex > enemiesList.Count)
- //actorIndex = actorIndex % enemiesList.Count;
- var targetslist = _attacker.Card.skill.GetPrototype ().targets;
- foreach (var type in targetslist) {
- Debug.Log ("SKILL: " + type);
- Tank target = null;
- switch (type) {
- case SkillTargetType.Self:
- target = _attacker;
- break;
- case SkillTargetType.NearestEnemy:
- target = enemiesList [ChooseEnemyTankForAttack (enemiesList, actorIndex, friendsList)];//.FindNearest (actorIndex, (obj) => {
- //return obj.Card.hp > 0 && enemies.Contains (obj);});
- isEnemy = true;
- break;
- case SkillTargetType.RandomEnemy:
- Debug.LogWarning ("RANDOM ENEMY SKILL!!");
- enemies.Shuffle ();
- target = enemies.Find ((obj) => {
- return obj.Card.hp > 0;});
- isEnemy = true;
- break;
- case SkillTargetType.WeakestEnemy:
- enemies.Sort (Weakest);
- target = enemies.Find ((obj) => {
- return obj.Card.hp > 0;});
- isEnemy = true;
- break;
- case SkillTargetType.StrongestEnemy:
- enemies.Sort (Strongest);
- target = enemies.Find ((obj) => {
- return obj.Card.hp > 0;});
- isEnemy = true;
- break;
- case SkillTargetType.NearestFriend:
- target = friendsList.FindNearest (actorIndex, (obj) => {
- return obj.Card.hp > 0 && friends.Contains (obj);});
- break;
- case SkillTargetType.RandomFriend:
- friends.Shuffle ();
- target = friends.Find ((obj) => {
- return obj.Card.hp > 0;});
- break;
- case SkillTargetType.WeakestFriend:
- friends.Sort (Weakest);
- target = friends.Find ((obj) => {
- return obj.Card.hp > 0;});
- break;
- case SkillTargetType.StrongestFriend:
- friends.Sort (Strongest);
- target = friends.Find ((obj) => {
- return obj.Card.hp > 0;});
- break;
- }
- targets.Add (target);
- if (target != null) {
- /*
- int targetIndex = enemies.IndexOf (target);
- if (targetIndex > 0)
- enemies.RemoveAt (targetIndex);
- else {
- targetIndex = friends.IndexOf (target);
- if (targetIndex > 0)
- friends.RemoveAt (targetIndex);
- }
- */
- if (isEnemy)
- enemies.Remove (target);
- else
- friends.Remove(target);
- }
- }
- // play effects
- /*
- var fx = VisualEffectManager.CreateEffect ("SkillFX", new Vector3 (0, 0, -100), _attacker.transform) as SkillFX;
- fx.skill = _attacker.Card.skill;
- fx.Targets = targets;
- */
- // Get random skill FX
- int skillIndex = GameManager.RandomGenerator.Next (2);
- string nameFx = "";
- if (skillIndex == 0) {
- name = "TipaSkillFX";
- } else {
- name = "SWFSkill2FX";
- }
- VisualEffect fx = VisualEffectManager.CreateEffect (name, new Vector3 (0, 0, -100), _attacker.transform);
- Debug.Log ("TYPE OF SKILL: " + fx.GetType ());
- timeLength = fx.timeLength();
- if (fx.GetType ().ToString () == "SWFClipFX") {
- SWFClipFX clip = (SWFClipFX)fx;
- //clip.skill = VisualEffectManager.CreateEffect ("SkillFX", new Vector3 (0, 0, -100), _attacker.transform) as SkillFX;
- clip.skill = _attacker.Card.skill;
- clip.Targets = targets;
- /*foreach (var t in targets) {
- Debug.Log ("-> Skill target: " + t.Card.name);
- }*/
- /*while (clip.skill.gameObject.active)
- yield return new WaitForEndOfFrame();
- */
- timeLength = clip.timeLength();
- }
- /*while (fx.gameObject.active)
- yield return new WaitForEndOfFrame();
- */
- Debug.Log("WAITING for "+timeLength+" sec");
- //UnityEditor.EditorApplication.isPaused = true;
- yield return new WaitForSeconds(timeLength);
- foreach (var target in targets) {
- CheckIsTankAlive (target, enemiesList.IndexOf (target), _attacker);
- }
- // Debug.Log("Skill animated");
- }
- }
- private IEnumerator AnimateFight ()
- {
- //TRYING TO MAKE RANDOM TURNS
- List<int> myT = new List<int> ();
- List<int> eT = new List<int> ();
- for (int i = 0; i < playerFormation.Length; ++i) {
- myT.Add (i);
- }
- for (int i = 0; i < enemyTanks.Count; i++) {
- eT.Add (i);
- }
- List<int> myTF = new List<int> ();
- List<int> eTF = new List<int> ();
- while (myT.Count > 0) {
- int position = GameManager.RandomGenerator.Next (0, myT.Count);
- myTF.Add (myT [position]);
- myT.RemoveAt (position);
- }
- while (eT.Count > 0) {
- int position = GameManager.RandomGenerator.Next (0, eT.Count);
- eTF.Add (eT [position]);
- eT.RemoveAt (position);
- }
- //TRYING TO MAKE RANDOM TURNS
- int myCount = myTanks.Count;
- int enemyCount = enemyTanks.Count;
- int currentTurn = 0;
- while (myCount > 0 && enemyCount > 0 && !_surrender) {
- //for(myTF)
- //myTF eTF != null
- foreach (var t in myTanks)
- if(t != null && t.Card.hp <= 0)
- myTF.Remove(myTanks.IndexOf (t));
- Tank myCard = myTanks[myTF [currentTurn%myTF.Count]] ;
- //Tank eACard = new Tank();//
- if (myCard.Card.hp > 0 && myCard.Card.skill != null && UnityEngine.Random.Range (0, 100) <= myCard.Card.skill.GetChance ())
- { // if use skill
- yield return StartCoroutine(AnimateSkill(myCard, myTanks, enemyTanks));
- /*
- yield return new WaitForSeconds(
- (TanksMoves.Instance.HIGHLIGHT_DELAY * 2
- + TanksMoves.Instance.DELAY_BEFORE_FIRE
- + TanksMoves.Instance.DELAY_AFTER_END
- + TanksMoves.Instance.DELAY_BEFORE_DAMAGE
- + TanksMoves.Instance.DELAY_AFTER_DAMAGE)*2.5f);
- */
- }
- else
- {
- StartCoroutine (AnimateNormalAttack (myCard, enemyTanks, myTF [currentTurn%myTF.Count], myTanks));
- yield return new WaitForSeconds(
- (TanksMoves.Instance.HIGHLIGHT_DELAY * 2
- + TanksMoves.Instance.DELAY_BEFORE_FIRE
- + TanksMoves.Instance.DELAY_AFTER_END
- + TanksMoves.Instance.DELAY_BEFORE_DAMAGE
- + TanksMoves.Instance.DELAY_AFTER_DAMAGE)*1.5f);
- }
- //Debug.Log("bcount " + eTF.Count);
- foreach (var t in enemyTanks)
- {
- //Debug.Log("hp " + t.Card.hp);
- if(t != null && t.Card.hp <= 0)
- {
- eTF.Remove(enemyTanks.IndexOf (t));
- //break;
- }
- }
- enemyCount = enemyTanks.Count ((obj) => {
- return obj.Card.hp > 0;});
- if(enemyCount <= 0)
- break;
- //for(eT)
- Tank eCard = enemyTanks[eTF [currentTurn%eTF.Count]];
- //Tank myACard = new Tank();//
- //if (_surrender)
- // continue;
- if (eCard.Card.hp > 0 && eCard.Card.skill != null && UnityEngine.Random.Range (0, 100) <= eCard.Card.skill.GetChance ())
- { // if use skill
- yield return StartCoroutine(AnimateSkill(eCard, enemyTanks, myTanks));
- /*yield return new WaitForSeconds(
- (TanksMoves.Instance.HIGHLIGHT_DELAY * 2
- + TanksMoves.Instance.DELAY_BEFORE_FIRE
- + TanksMoves.Instance.DELAY_AFTER_END
- + TanksMoves.Instance.DELAY_BEFORE_DAMAGE
- + TanksMoves.Instance.DELAY_AFTER_DAMAGE)*2.5f);
- */
- }
- else
- {
- StartCoroutine (AnimateNormalAttack (eCard, myTanks, eTF [currentTurn%eTF.Count], enemyTanks));
- yield return new WaitForSeconds(
- (TanksMoves.Instance.HIGHLIGHT_DELAY * 2
- + TanksMoves.Instance.DELAY_BEFORE_FIRE
- + TanksMoves.Instance.DELAY_AFTER_END
- + TanksMoves.Instance.DELAY_BEFORE_DAMAGE
- + TanksMoves.Instance.DELAY_AFTER_DAMAGE)*1.5f);
- }
- myCount = myTanks.Count ((obj) => {
- return obj.Card.hp > 0;});
- currentTurn++;
- /*for (int i = 0; i < playerFormation.Length; i++) {
- Debug.Log (playerFormation.Length + " " + myTanks.Count + " " + enemyTanks.Count + " " + i);
- int l = 0;
- foreach (var t in enemyTanks) {
- if (t != null)
- Debug.Log (l + " y");
- else
- Debug.Log (l + " n");
- l++;
- }
- int p = i % enemyTanks.Count;
- //for (int i = 0; i < n.Length; i++)
- if (_surrender)
- continue;
- if (myTanks [i].Card.hp > 0 && enemyCount > 0) {
- //OUR TURN
- if (myTanks [i].Card.skill != null && UnityEngine.Random.Range (0, 100) <= myTanks [i].Card.skill.GetChance ()) { // if use skill
- yield return StartCoroutine(AnimateSkill(myTanks[myTF[i]], myTanks, enemyTanks));
- } else {
- if (myTanks [myTF [i]].Card.hp > 0) {
- Debug.Log ("11");
- StartCoroutine (AnimateNormalAttack (myTanks [myTF [i]], enemyTanks, eTF [p]));
- Debug.Log ("12");
- yield return new WaitForSeconds(TanksMoves.Instance.HIGHLIGHT_DELAY * 2 + TanksMoves.Instance.DELAY_BEFORE_FIRE + TanksMoves.Instance.DELAY_AFTER_END + TanksMoves.Instance.DELAY_BEFORE_DAMAGE + TanksMoves.Instance.DELAY_AFTER_DAMAGE);
- }
- }
- Debug.Log ("2");
- enemyCount = enemyTanks.Count ((obj) => {
- return obj.Card.hp > 0;});
- }
- //ENEMY TURN
- //= 0;
- //if (i > enemyTanks.Count)
- ;
- if (enemyTanks [p].Card.hp > 0 && myCount > 0) {
- if (enemyTanks [p].Card.skill != null && UnityEngine.Random.Range (0, 100) <= enemyTanks [p].Card.skill.GetChance ()) { // if use skill
- yield return StartCoroutine(AnimateSkill(enemyTanks[eTF[p]], enemyTanks, myTanks));
- } else {
- if (myTanks [eTF [p]].Card.hp > 0) {
- StartCoroutine (AnimateNormalAttack (enemyTanks [eTF [p]], myTanks, myTF [i]));
- yield return new WaitForSeconds(TanksMoves.Instance.HIGHLIGHT_DELAY * 2 + TanksMoves.Instance.DELAY_BEFORE_FIRE + TanksMoves.Instance.DELAY_AFTER_END + TanksMoves.Instance.DELAY_BEFORE_DAMAGE + TanksMoves.Instance.DELAY_AFTER_DAMAGE);
- }
- }
- myCount = myTanks.Count ((obj) => {
- return obj.Card.hp > 0;});
- }
- }// end of for-i
- */
- }
- // bool waitForLevelup = false;
- // List<ExpReward> levelUps = new List<ExpReward>();
- // if (!_surrender) {
- // foreach (var tank in myTanks)
- // if (tank.Card.hp > 0)
- // {
- // int expReward = 5 + GameManager.Instance.Battle.CurrentTurn * 5;
- //// expReward = tank.Card.maxExp - tank.Card.exp;// use it for testing cards level up
- //
- // ExpReward reward = ServerEmulation.GetLevelUpResult(tank.Card, expReward);
- // tank.ExpReward(expReward);
- // if (reward.levelUp != null) {
- // levelUps.Add(reward);
- // VisualEffectManager.CreateEffect("LevelUpFX", Vector3.zero, tank.transform);
- // waitForLevelup = true;
- // }
- // reward.Upgraded.CopyStatsTo(tank.Card);
- // if (waitForLevelup) {
- // tank.Card.hp = tank.Card.maxHp;
- // tank.UpdateHPBar();
- // }
- // }
- // }
- // if (!_surrender) {
- // yield return new WaitForSeconds(waitForLevelup ? 3.0f : 1.0f);
- // }
- yield return new WaitForSeconds(1.0f);
- // if (levelUps.Count > 0) {
- // CardsLevelUpViewController controller = MainUIController.Instance.CardsLevelUpView.GetComponent<CardsLevelUpViewController>();
- // controller.InitWith(levelUps);
- // DialogsController.AddToQueue(UIState.CardsLevelUp, null);
- // }
- // if (battle.CurrentTurn < battle.TotalTurns) {
- // foreach (var tank in myTanks) {
- // tank.ShowButtons(true);
- // }
- // }
- UpdateLabels ();
- Battle battle = GameManager.Instance.Battle;
- if (myCount > 0) {
- if (battle.CurrentTurn < battle.TotalTurns) {
- // //moveButton.
- // //moveButton.GetComponent<UISprite>().color = new Color(1.0f, 1.0f, 1.0f, 0.0f);
- // moveButton.SetActiveRecursively(true);
- //
- // //StartCoroutine(runButtonAnimation());
- // //transform.FindChild("BattleViewHUD/BottomRight/AttackButton").gameObject.SetActiveRecursively(true);
- //
- //
- // Debug.LogWarning ("Switching on attack button");
- // transform.FindChild("BattleViewHUD/BottomRight/AttackButton/TweenTarget/Background").GetComponent<UISprite>().color = new Color(0.0f, 0.47f, 0.0f, 0.1f);
- // transform.FindChild("BattleViewHUD/BottomRight/AttackButton/TweenTarget/Icon").GetComponent<UISprite>().spriteName = "go";
- // transform.FindChild("BattleViewHUD/BottomRight/AttackButton").GetComponent<UIButtonMessage>().functionName = "OnMoveClicked";
- // transform.FindChild("BattleViewHUD/BottomRight/AttackButton").GetComponent<UIButtonMessage>().enabled = true;
- // transform.FindChild("BattleViewHUD/BottomRight/AttackButton").GetComponent<UIFramedButtonExt>().enableButton();
- //yield return new WaitForSeconds(2);
- ServerEmulation.EmulateStartBattleTurn ();
- } else {
- //TODO: show level up and victory screen
- StartCoroutine (FinishBattle ());
- // MainUIController.Instance.SetDarknessVisible(true, ShowMap);
- // // Finish battle
- // if (levelUps.Count <= 0) {
- // // Show zone if there are no level ups
- // MainUIController.Instance.SetDarknessVisible(true, ShowMap);
- // }
- }
- } else
- ShowDefeatScreen (null);
- }
- private void ShowZone(UITweener tween) {
- MainUIController.uiState = UIState.ZoneView;
- }
- private void ShowMap(UITweener tween) {
- MainUIController.uiState = UIState.Map;
- }
- IEnumerator runButtonAnimation()
- {
- yield return new WaitForSeconds(0.8f);
- transform.FindChild("BattleViewHUD/BottomRight/AttackButton").GetComponent<UIFramedButtonExt>().enableButton();
- }
- private void OnFinishButtonAnim1(UITweener tween) {
- Debug.Log ("OnFinishButtonAnim1", moveButton);
- TweenScale tweenN = TweenScale.Begin(moveButton.transform.parent.gameObject, 0.1f, new Vector3(1.0f, 1.0f, 1.0f));
- //tweenN.onFinished = OnFinishButtonAnim2;
- }
- private void OnFinishButtonColor(UITweener tween) {
- TweenColor tmp = TweenColor.Begin(moveButton, 0.3f, new Color(1.0f, 1.0f, 1.0f, 0.0f));
- }
- //
- private void DropItem(GameObject tank, string itemName) {
- DropItem(tank.transform.localPosition, itemName);
- }
- private void DropItem(Vector3 pos, string itemName) {
- GameObject item = (GameObject)GameObject.Instantiate(lootPrefab);
- items.Add(item);
- // set valid sprite
- UISprite sprite = item.GetComponent<UISprite>();
- sprite.spriteName = itemName;
- sprite.MakePixelPerfect();
- //Vector3 tankPos = tank.transform.localPosition;
- Vector3 originalScale = item.transform.localScale;
- item.transform.parent = movingContainer.gameObject.transform.parent;
- item.transform.localPosition = pos + new Vector3(0, 0, -25);
- // auto click to coin after 5 seconds
- iTween.MoveTo(item, iTween.Hash("onstart", "ClickToLoot", "onstarttarget", gameObject, "onstartparams", item,"delay", 2));
- MoveByArc dropScript = item.GetComponent<MoveByArc>();
- dropScript.dX = UnityEngine.Random.Range(-100, 100);
- dropScript.dY = UnityEngine.Random.Range(-100, -30);
- // set original scale
- item.transform.localScale = originalScale;
- // item.transform.localPosition = sectorTransform.localPosition;
- // coin is button - set target
- UIButtonMessage buttonMessage = item.GetComponent<UIButtonMessage>();
- buttonMessage.target = gameObject;
- }
- public void ClickToLoot(GameObject sender) {
- UISprite sprite = sender.GetComponent<UISprite>();
- Vector3 pos = sender.transform.localPosition;
- pos.y += 800;
- TweenPosition tween = TweenPosition.Begin(sender, 0.5f, pos);
- tween.onFinished = FinishLootMoving;
- // TODO: play sound
- }
- private void FinishLootMoving(UITweener tween) {
- // Debug.Log ("FinishLootMoving " + tween.name);
- items.Remove(tween.gameObject);
- NGUITools.Destroy(tween.gameObject);
- }
- public void ShowBattleResultScreen() {
- BattleResult result = GameManager.Instance.Battle.Result;
- if (result != null) {
- // Battle finished = handle result
- if (result.resultType == BattleResultType.Win) {
- ShowVictoryScreen(result);
- } else {
- ShowDefeatScreen(null);
- }
- }
- }
- private IEnumerator EmulateFinishBattle(){
- yield return new WaitForSeconds(3);
- ServerEmulation.EmulateFinishBattle();
- }
- // Returns position for tank in given formation and line position.
- private Vector3 GetTankPosition(int[] formation, int linePos, bool isEnemy) {
- // TODO: center 4 tanks formation
- Debug.Log(formation.Length + " " + linePos);
- int j = formation[linePos];//-1, 0, +1 - line in formation - back, center, front
- int i = linePos;// 0, 1, 2, 3, 4 - position inside formation.
- if (formation.Length == 3) {
- // Center 3 tanks formation.
- i++;
- }
- float x0;
- float y0;
- if (isEnemy) {
- j = -j;
- x0 = -10;// + MOVING_SPEED_X * MOVING_DURATION;// * (GameManager.Instance.Battle.CurrentTurn - 1);
- y0 = 210;//145;// + MOVING_SPEED_Y * MOVING_DURATION;// * (GameManager.Instance.Battle.CurrentTurn - 1);
- } else {
- x0 = -350;
- y0 = -30;
- }
- float ci = 100;
- float cj = 50;
- float k = 3.0f/5.0f;
- Vector3 beginPos = new Vector3(x0 + ci*i + cj*j, y0 + k*(-ci*i + cj*j), -1);
- return beginPos;
- }
- private void UpdateLabels() {
- Battle battle = GameManager.Instance.Battle;
- coinsLabel.text = battle.Loot.coins.ToString();
- boxLabel.text = battle.Loot.box.ToString();
- ironBoxLabel.text = battle.Loot.ironBox.ToString();//battle.CurrentTurn + "/" + battle.TotalTurns;
- turnLabel.text = battle.CurrentTurn + "/" + battle.TotalTurns;
- }
- private void ShowBattleTurnLabel() {
- Battle battle = GameManager.Instance.Battle;
- //TODO: L10n.
- battleTurnLabel.text = "Battle " + battle.CurrentTurn + "/" + battle.TotalTurns;
- battleTurnLabel.transform.localPosition = BATTLE_TURN_LABEL_START_POSITION;
- TweenPosition tween = TweenPosition.Begin(battleTurnLabel.gameObject, 0.5f, Vector3.zero);
- tween.onFinished = HideBattleTurnLabel;
- tween.method = UITweener.Method.EaseIn;//BounceIn;
- // Debug.Log("Location: " + GameManager.Instance.Human.LocationId + " Sector: " + " Turn: " + battle.CurrentTurn + " LocationAction: ");
- TurnData tmp = ContentManager.Instance.getTurnData(GameManager.Instance.Human.LocationId, battle.SectorID, battle.CurrentTurn, GameManager.Instance.Human.ActionInLocation);
- if(tmp != null)
- testLabel.text = tmp.ToString();
- else
- testLabel.text = "Null";
- }
- private void HideBattleTurnLabel(UITweener t) {
- // NB. We need to enable tween. There is no delay on next tween otherwise.
- t.enabled = false;
- TweenPosition tween = TweenPosition.Begin(battleTurnLabel.gameObject, 0.5f, BATTLE_TURN_LABEL_FINISH_POSITION, 1);
- tween.onFinished = ActivateButtonsAfterTween;
- tween.method = UITweener.Method.EaseOut;//BounceOut;
- }
- private void ActivateButtonsAfterTween(UITweener tween) {
- SetButtonsActive(true);
- }
- private IEnumerator FinishBattle() {
- bool waitForLevelup = false;
- List<ExpReward> levelUps = new List<ExpReward>();
- if (!_surrender) {
- foreach (var tank in myTanks)
- if (tank.Card.hp > 0)
- {
- int expReward = 5 + GameManager.Instance.Battle.CurrentTurn * 5;
- // expReward = tank.Card.maxExp - tank.Card.exp;// use it for testing cards level up
- ExpReward reward = ServerEmulation.GetLevelUpResult(tank.Card, expReward);
- tank.ExpReward(expReward);
- if (reward.levelUp != null) {
- levelUps.Add(reward);
- VisualEffectManager.CreateEffect("LevelUpFX", Vector3.zero, tank.transform);
- waitForLevelup = true;
- }
- reward.Upgraded.CopyStatsTo(tank.Card);
- if (waitForLevelup) {
- tank.Card.hp = tank.Card.maxHp;
- tank.UpdateHPBar();
- }
- }
- }
- if (waitForLevelup) {
- // wait for level up fx finished
- yield return new WaitForSeconds(2.0f);
- }
- if (levelUps.Count > 0) {
- CardsLevelUpViewController controller = MainUIController.Instance.CardsLevelUpView.GetComponent<CardsLevelUpViewController>();
- controller.InitWith(levelUps);
- DialogsController.AddToQueue(UIState.CardsLevelUp, null);
- }
- ServerEmulation.EmulateFinishBattle();
- }
- private void DestroyCraters() {
- Transform t = decorationsContainer.FindChild("Craters");
- int childCount = t.GetChildCount();
- for (int i = 0; i < childCount; ++i) {
- GameObject.Destroy(t.GetChild(i).gameObject);
- }
- }
- private void AirPlaneShadow() {
- float duration = 2;
- Vector3 startPosition = new Vector3(-Screen.width/2 - 100 , - Screen.height/2 - 100, -5);
- VisualEffect airplane = VisualEffectManager.CreateEffect("AirPlaneShadow", startPosition, movingContainer);
- airplane.duration = duration;
- Vector3 finishPosition = startPosition;
- finishPosition.x *= -1;
- finishPosition.y *= -1;
- TweenPosition.Begin(airplane.gameObject, duration, finishPosition);
- }
- private void DropStar(Transform t, Transform attacker) {
- Vector3 position = t.localPosition;
- position.z = -25;
- VisualEffect effect = VisualEffectManager.CreateEffect("StarIn", position, movingContainer);
- int rand;
- rand = GameManager.RandomGenerator.Next(100) - 50;
- if (rand > 0) {
- rand += 50;
- } else {
- rand -= 50;
- }
- position.x -= rand;
- rand = GameManager.RandomGenerator.Next(100) - 50;
- if (rand > 0) {
- rand += 50;
- } else {
- rand -= 50;
- }
- position.y -= rand;
- TweenPosition.Begin(effect.gameObject, 1, position);
- SWFClipFX swf = (SWFClipFX) effect;
- swf.duration = 3;
- swf.OnFinished = RemoveStar;
- effect.Assotiated.Add(attacker);
- }
- void RemoveStar(VisualEffect e) {
- Transform attacker = e.Assotiated[0];
- e.Assotiated.Clear();
- Vector3 position = e.transform.localPosition;
- VisualEffect effect = VisualEffectManager.CreateEffect("StarOut", position, movingContainer);
- position = attacker.localPosition;
- position.z = -25;
- TweenPosition.Begin(effect.gameObject, 1, position);
- }
- private void DropWrench(Transform t, Transform attacker) {
- Debug.Log("!!! WRENCH DROPPED");
- //UnityEditor.EditorApplication.isPaused = true;
- Vector3 position = t.localPosition;
- position.z = -25;
- VisualEffect effect = VisualEffectManager.CreateEffect("WrenchIn", position, movingContainer);
- int rand;
- rand = GameManager.RandomGenerator.Next(100) - 50;
- if (rand > 0) {
- rand += 50;
- } else {
- rand -= 50;
- }
- position.x -= rand;
- rand = GameManager.RandomGenerator.Next(100) - 50;
- if (rand > 0) {
- rand += 50;
- } else {
- rand -= 50;
- }
- position.y -= rand;
- TweenPosition.Begin(effect.gameObject, 1, position);
- SWFClipFX swf = (SWFClipFX) effect;
- swf.duration = 3;
- swf.OnFinished = RemoveWrench;
- effect.Assotiated.Add(attacker);
- }
- void RemoveWrench(VisualEffect e) {
- Transform attacker = e.Assotiated[0];
- //UnityEditor.EditorApplication.isPaused = true;
- e.Assotiated.Clear();
- Vector3 position = e.transform.localPosition;
- VisualEffect effect = VisualEffectManager.CreateEffect("WrenchOut", position, movingContainer);
- position = attacker.localPosition;
- position.z = -25;
- TweenPosition.Begin(effect.gameObject, 1, position);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement