| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563 |
- using Photon.Pun;
- using System;
- using System.Collections;
- using System.Collections.Generic;
- using System.Linq;
- using UnityEngine;
- public class SelectAttackEffect : MonoBehaviourPunCallbacks
- {
- public void SetUp
- (
- Permanent attacker,
- Func<bool> canAttackPlayerCondition,
- Func<Permanent, bool> defenderCondition,
- ICardEffect cardEffect)
- {
- _attacker = attacker;
- _canAttackPlayerCondition = canAttackPlayerCondition;
- _defenderCondition = defenderCondition;
- _cardEffect = cardEffect;
- _canSelectNotAttack = true;
- _withoutTap = false;
- _isVortex = false;
- _customMessage = null;
- _customMessage_Enemy = null;
- _beforeOnAttackCoroutine = null;
- _afterOnAttackCoroutine = null;
- }
- public void SetUpCustomMessage(string customMessage, string customMessage_Enemy)
- {
- _customMessage = customMessage;
- _customMessage_Enemy = customMessage_Enemy;
- }
- public void SetCanNotSelectNotAttack()
- {
- _canSelectNotAttack = false;
- }
- public void SetWithoutTap()
- {
- _withoutTap = true;
- }
-
- public void SetIsVortex()
- {
- _isVortex = true;
- }
- public void SetBeforeOnAttackCoroutine(Func<IEnumerator> beforeOnAttackCoroutine)
- {
- _beforeOnAttackCoroutine = beforeOnAttackCoroutine;
- }
- public void SetAfterOnAttackCoroutine(Func<IEnumerator> afterOnAttackCoroutine)
- {
- _afterOnAttackCoroutine = afterOnAttackCoroutine;
- }
- Permanent _attacker = null;
- Func<bool> _canAttackPlayerCondition = null;
- Func<Permanent, bool> _defenderCondition = null;
- bool _canSelectNotAttack = true;
- bool _withoutTap = false;
- bool _isVortex = false;
- bool _noSelect = false;
- bool _endSelect = false;
- string _customMessage = null;
- string _customMessage_Enemy = null;
- Permanent _defender = null;
- ICardEffect _cardEffect = null;
- Func<IEnumerator> _beforeOnAttackCoroutine = null;
- Func<IEnumerator> _afterOnAttackCoroutine = null;
- #region ƒp[ƒ}ƒlƒ“ƒg‚ð‘I‘ð‚Å‚«‚é‚©
- bool CanTarget(Permanent permanent)
- {
- if (_attacker != null)
- {
- if (_attacker.TopCard != null)
- {
- if (_attacker.CanAttack(_cardEffect, _withoutTap, _isVortex))
- {
- if (_attacker.CanAttackTargetDigimon(permanent, _cardEffect, _withoutTap, _isVortex))
- {
- if (_defenderCondition != null)
- {
- if (!_defenderCondition(permanent))
- {
- return false;
- }
- }
- return true;
- }
- }
- }
- }
- return false;
- }
- #endregion
- #region UŒ‚‚Å‚«‚鑊Žèƒp[ƒ}ƒlƒ“ƒg‚ª‚¢‚é‚©
- public bool CanAttackDigimon()
- {
- foreach (Player player in GManager.instance.turnStateMachine.gameContext.Players)
- {
- foreach (Permanent permanent in player.GetFieldPermanents())
- {
- if (CanTarget(permanent))
- {
- return true;
- }
- }
- }
- return false;
- }
- #endregion
- #region ƒvƒŒƒCƒ„[‚ÉUŒ‚‚ª‰Â”\‚©
- bool CanAttackPlayer()
- {
- if (_attacker != null)
- {
- if (_attacker.TopCard != null)
- {
- if (_attacker.CanAttack(_cardEffect, _withoutTap, _isVortex))
- {
- if (_attacker.CanAttackTargetDigimon(null, _cardEffect, _withoutTap, _isVortex))
- {
- if (_canAttackPlayerCondition != null)
- {
- if (!_canAttackPlayerCondition())
- {
- return false;
- }
- }
- return true;
- }
- }
- }
- }
- return false;
- }
- #endregion
- #region ‘I‘ð‚ª‰Â”\‚©‚Ç‚¤‚©
- public bool active()
- {
- if (!CanAttackDigimon())
- {
- if (!CanAttackPlayer())
- {
- return false;
- }
- }
- if (GManager.instance.attackProcess.IsAttacking)
- {
- return false;
- }
- return true;
- }
- #endregion
- #region I—¹‚Å‚«‚é‚©”»’è
- bool CanEndSelect(Permanent selectedPermanent)
- {
- if (selectedPermanent == null)
- {
- if (!CanAttackPlayer())
- {
- return false;
- }
- }
- else
- {
- if (!CanAttackDigimon())
- {
- return false;
- }
- }
- return true;
- }
- #endregion
- public IEnumerator Activate()
- {
- _defender = null;
- _noSelect = false;
- if (_attacker == null) yield break;
- if (_attacker.TopCard == null) yield break;
- if (!_attacker.CanAttack(_cardEffect, _withoutTap, _isVortex)) yield break;
- if (active())
- {
- yield return GManager.instance.photonWaitController.StartWait("SelectAttackEffect");
- foreach (Player player in GManager.instance.turnStateMachine.gameContext.Players)
- {
- GManager.instance.turnStateMachine.OffFieldCardTarget(player);
- GManager.instance.turnStateMachine.OffHandCardTarget(player);
- }
- GManager.instance.turnStateMachine.IsSelecting = true;
- if (_attacker != null)
- {
- if (_attacker.TopCard != null)
- {
- if (_attacker.CanAttack(_cardEffect, _withoutTap, _isVortex))
- {
- if (_attacker.TopCard.Owner.isYou)
- {
- #region Select Attack Target
- if (!string.IsNullOrEmpty(_customMessage))
- {
- GManager.instance.commandText.OpenCommandText(_customMessage);
- }
- else
- {
- if (CanAttackDigimon())
- {
- GManager.instance.commandText.OpenCommandText("Which target will you attack?");
- }
- else
- {
- GManager.instance.commandText.OpenCommandText("Will you attack to the opponent?");
- }
- }
- #endregion
- Permanent selectedPermanent = null;
- #region Can Attack Player
- if (CanAttackPlayer())
- {
- if (_attacker.TopCard.Owner.Enemy.SecurityCards.Count >= 1)
- {
- _attacker.TopCard.Owner.Enemy.securityObject.securityBreakGlass.ShowBlueMatarial();
- }
- _attacker.TopCard.Owner.Enemy.securityObject.SetSecurityAttackObject();
- _attacker.TopCard.Owner.Enemy.securityObject.SetSecurityOutline(true);
- _attacker.TopCard.Owner.Enemy.securityObject.AddClickTarget(() =>
- {
- selectedPermanent = null;
- EndSelect_RPC();
- });
- }
- #endregion
- List<FieldPermanentCard> candidates = new List<FieldPermanentCard>();
- foreach (Player player in GManager.instance.turnStateMachine.gameContext.Players)
- {
- foreach (Permanent permanent in player.GetFieldPermanents())
- {
- if (CanTarget(permanent))
- {
- permanent.ShowingPermanentCard.AddClickTarget(OnClickFieldPermanentCard);
- candidates.Add(permanent.ShowingPermanentCard);
- }
- }
- }
- if (candidates.Count >= 1)
- {
- GManager.instance.hideCannotSelectObject.SetUpHideCannotSelectObject(candidates, false);
- }
- CheckEndSelect();
- #region Selecting field permanent
- void OnClickFieldPermanentCard(FieldPermanentCard fieldPermanentCard)
- {
- if (selectedPermanent == fieldPermanentCard.ThisPermanent)
- {
- selectedPermanent = null;
- }
- else
- {
- selectedPermanent = fieldPermanentCard.ThisPermanent;
- }
- CheckEndSelect();
- }
- #endregion
- #region End Selectiong "Not Attack"
- void CheckEndSelect()
- {
- #region CanEndSelect
- if (CanEndSelect(selectedPermanent))
- {
- }
- else
- {
- }
- #endregion
- #region Visually Select Target
- foreach (Player player in GManager.instance.turnStateMachine.gameContext.Players)
- {
- foreach (Permanent permanent in player.GetFieldPermanents())
- {
- permanent.ShowingPermanentCard.RemoveSelectEffect();
- if (CanTarget(permanent))
- {
- if (selectedPermanent == permanent)
- {
- permanent.ShowingPermanentCard.OnSelectEffect(1.1f);
- permanent.ShowingPermanentCard.SetOrangeOutline();
- }
- else
- {
- permanent.ShowingPermanentCard.OnSelectEffect(1.1f);
- permanent.ShowingPermanentCard.SetBlueOutline();
- }
- }
- }
- }
- #endregion
- if (selectedPermanent == null)
- {
- if (_canSelectNotAttack)
- {
- GManager.instance.BackButton.OpenSelectCommandButton("Not Attack", () => { photonView.RPC("SetNotAttack", RpcTarget.All); }, 0);
- }
- GManager.instance.selectCommandPanel.CloseSelectCommandPanel();
- }
- else
- {
- GManager.instance.selectCommandPanel.SetUpCommandButton(new List<Command_SelectCommand>() { new Command_SelectCommand("End Selection", EndSelect_RPC, 0) });
- GManager.instance.BackButton.CloseSelectCommandButton();
- }
- }
- #endregion
- #region End Selection RPC
- void EndSelect_RPC()
- {
- foreach (Player player in GManager.instance.turnStateMachine.gameContext.Players)
- {
- foreach (Permanent permanent in player.GetFieldPermanents())
- {
- permanent.ShowingPermanentCard.RemoveSelectEffect();
- permanent.ShowingPermanentCard.RemoveClickTarget();
- }
- }
- bool isPlayer = true;
- bool isTurnPlayer = false;
- int PermanentIndex = -1;
- if (selectedPermanent != null)
- {
- if (selectedPermanent.TopCard != null)
- {
- isPlayer = false;
- isTurnPlayer = selectedPermanent.TopCard.Owner == GManager.instance.turnStateMachine.gameContext.TurnPlayer;
- PermanentIndex = selectedPermanent.TopCard.Owner.GetFieldPermanents().IndexOf(selectedPermanent);
- }
- }
- photonView.RPC("SetAttackTarget", RpcTarget.All, isPlayer, isTurnPlayer, PermanentIndex);
- GManager.instance.BackButton.CloseSelectCommandButton();
- }
- #endregion
- }
- else
- {
- #region Showing Enemy Message
- if (!string.IsNullOrEmpty(_customMessage_Enemy))
- {
- GManager.instance.commandText.OpenCommandText(_customMessage_Enemy);
- }
- else
- {
- GManager.instance.commandText.OpenCommandText("The opponent is selecting the attack target.");
- }
- #endregion
- #region AI
- if (GManager.instance.IsAI)
- {
- List<Permanent> AttackcTargetCandidates = new List<Permanent>();
- foreach (Player player in GManager.instance.turnStateMachine.gameContext.Players_ForTurnPlayer)
- {
- foreach (Permanent permanent in player.GetFieldPermanents())
- {
- if (CanTarget(permanent))
- {
- AttackcTargetCandidates.Add(permanent);
- }
- }
- }
- Permanent selectedPermanent = null;
- if (AttackcTargetCandidates.Count >= 1)
- {
- if (!_attacker.CanAttackTargetDigimon(null, _cardEffect, _withoutTap, _isVortex) || (_attacker.TopCard.Owner.Enemy.SecurityCards.Count >= 3 && RandomUtility.IsSucceedProbability(0.5f)))
- {
- selectedPermanent = AttackcTargetCandidates[UnityEngine.Random.Range(0, AttackcTargetCandidates.Count)];
- }
- }
- bool isPlayer = true;
- bool isTurnPlayer = false;
- int PermanentIndex = -1;
- if (selectedPermanent != null)
- {
- if (selectedPermanent.TopCard != null)
- {
- isPlayer = false;
- isTurnPlayer = selectedPermanent.TopCard.Owner == GManager.instance.turnStateMachine.gameContext.TurnPlayer;
- PermanentIndex = selectedPermanent.TopCard.Owner.GetFieldPermanents().IndexOf(selectedPermanent);
- }
- }
- SetAttackTarget(isPlayer, isTurnPlayer, PermanentIndex);
- }
- #endregion
- }
- }
- }
- }
- //Wait until selection ends
- yield return new WaitWhile(() => !_endSelect);
- _endSelect = false;
- #region Clean up visual selections and UI
- foreach (Player player in GManager.instance.turnStateMachine.gameContext.Players)
- {
- GManager.instance.turnStateMachine.OffFieldCardTarget(player);
- GManager.instance.turnStateMachine.OffHandCardTarget(player);
- foreach (Permanent permanent in player.GetFieldPermanents())
- {
- permanent.ShowingPermanentCard.RemoveSelectEffect();
- }
- player.securityObject.OffShowSecurityAttackObject();
- player.securityObject.RemoveClickTarget();
- if (_defender != null || _noSelect)
- {
- player.securityObject.securityBreakGlass.gameObject.SetActive(false);
- }
- }
- GManager.instance.hideCannotSelectObject.Close();
- GManager.instance.selectCommandPanel.CloseSelectCommandPanel();
- GManager.instance.BackButton.CloseSelectCommandButton();
- GManager.instance.commandText.CloseCommandText();
- yield return new WaitWhile(() => GManager.instance.commandText.gameObject.activeSelf);
- #endregion
- if (!_noSelect)
- {
- if (CanEndSelect(_defender))
- {
- yield return ContinuousController.instance.StartCoroutine(GManager.instance.attackProcess.Attack(_attacker, _defender, _cardEffect, _withoutTap, _beforeOnAttackCoroutine));
- if(_afterOnAttackCoroutine != null)
- yield return ContinuousController.instance.StartCoroutine(_afterOnAttackCoroutine());
- }
- }
- }
- }
- #region ‘I‘ðŒˆ’è
- [PunRPC]
- public void SetAttackTarget(bool isPlayer, bool isTurnPlayer, int PermanentIndex)
- {
- _defender = null;
- if (!isPlayer)
- {
- Player player = null;
- if (isTurnPlayer)
- {
- player = GManager.instance.turnStateMachine.gameContext.TurnPlayer;
- }
- else
- {
- player = GManager.instance.turnStateMachine.gameContext.NonTurnPlayer;
- }
- Permanent permanent = null;
- if (0 <= PermanentIndex && PermanentIndex <= player.GetFieldPermanents().Count - 1)
- {
- permanent = player.GetFieldPermanents()[PermanentIndex];
- }
- if (permanent != null)
- {
- _defender = permanent;
- }
- }
- _endSelect = true;
- }
- #endregion
- #region ‘I‘ð‚µ‚È‚¢
- [PunRPC]
- public void SetNotAttack()
- {
- GManager.instance.selectCommandPanel.CloseSelectCommandPanel();
- _defender = null;
- _noSelect = true;
- _endSelect = true;
- }
- #endregion
- }
|