SelectAttackEffect.cs 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553
  1. using Photon.Pun;
  2. using System;
  3. using System.Collections;
  4. using System.Collections.Generic;
  5. using System.Linq;
  6. using UnityEngine;
  7. public class SelectAttackEffect : MonoBehaviourPunCallbacks
  8. {
  9. public void SetUp
  10. (
  11. Permanent attacker,
  12. Func<bool> canAttackPlayerCondition,
  13. Func<Permanent, bool> defenderCondition,
  14. ICardEffect cardEffect)
  15. {
  16. _attacker = attacker;
  17. _canAttackPlayerCondition = canAttackPlayerCondition;
  18. _defenderCondition = defenderCondition;
  19. _cardEffect = cardEffect;
  20. _canSelectNotAttack = true;
  21. _withoutTap = false;
  22. _isVortex = false;
  23. _customMessage = null;
  24. _customMessage_Enemy = null;
  25. _beforeOnAttackCoroutine = null;
  26. }
  27. public void SetUpCustomMessage(string customMessage, string customMessage_Enemy)
  28. {
  29. _customMessage = customMessage;
  30. _customMessage_Enemy = customMessage_Enemy;
  31. }
  32. public void SetCanNotSelectNotAttack()
  33. {
  34. _canSelectNotAttack = false;
  35. }
  36. public void SetWithoutTap()
  37. {
  38. _withoutTap = true;
  39. }
  40. public void SetIsVortex()
  41. {
  42. _isVortex = true;
  43. }
  44. public void SetBeforeOnAttackCoroutine(Func<IEnumerator> beforeOnAttackCoroutine)
  45. {
  46. _beforeOnAttackCoroutine = beforeOnAttackCoroutine;
  47. }
  48. Permanent _attacker = null;
  49. Func<bool> _canAttackPlayerCondition = null;
  50. Func<Permanent, bool> _defenderCondition = null;
  51. bool _canSelectNotAttack = true;
  52. bool _withoutTap = false;
  53. bool _isVortex = false;
  54. bool _noSelect = false;
  55. bool _endSelect = false;
  56. string _customMessage = null;
  57. string _customMessage_Enemy = null;
  58. Permanent _defender = null;
  59. ICardEffect _cardEffect = null;
  60. Func<IEnumerator> _beforeOnAttackCoroutine = null;
  61. #region ƒp[ƒ}ƒlƒ“ƒg‚ð‘I‘ð‚Å‚«‚é‚©
  62. bool CanTarget(Permanent permanent)
  63. {
  64. if (_attacker != null)
  65. {
  66. if (_attacker.TopCard != null)
  67. {
  68. if (_attacker.CanAttack(_cardEffect, _withoutTap, _isVortex))
  69. {
  70. if (_attacker.CanAttackTargetDigimon(permanent, _cardEffect, _withoutTap, _isVortex))
  71. {
  72. if (_defenderCondition != null)
  73. {
  74. if (!_defenderCondition(permanent))
  75. {
  76. return false;
  77. }
  78. }
  79. return true;
  80. }
  81. }
  82. }
  83. }
  84. return false;
  85. }
  86. #endregion
  87. #region UŒ‚‚Å‚«‚鑊Žèƒp[ƒ}ƒlƒ“ƒg‚ª‚¢‚é‚©
  88. public bool CanAttackDigimon()
  89. {
  90. foreach (Player player in GManager.instance.turnStateMachine.gameContext.Players)
  91. {
  92. foreach (Permanent permanent in player.GetFieldPermanents())
  93. {
  94. if (CanTarget(permanent))
  95. {
  96. return true;
  97. }
  98. }
  99. }
  100. return false;
  101. }
  102. #endregion
  103. #region ƒvƒŒƒCƒ„[‚ɍUŒ‚‚ª‰Â”\‚©
  104. bool CanAttackPlayer()
  105. {
  106. if (_attacker != null)
  107. {
  108. if (_attacker.TopCard != null)
  109. {
  110. if (_attacker.CanAttack(_cardEffect, _withoutTap, _isVortex))
  111. {
  112. if (_attacker.CanAttackTargetDigimon(null, _cardEffect, _withoutTap, _isVortex))
  113. {
  114. if (_canAttackPlayerCondition != null)
  115. {
  116. if (!_canAttackPlayerCondition())
  117. {
  118. return false;
  119. }
  120. }
  121. return true;
  122. }
  123. }
  124. }
  125. }
  126. return false;
  127. }
  128. #endregion
  129. #region ‘I‘ð‚ª‰Â”\‚©‚Ç‚¤‚©
  130. public bool active()
  131. {
  132. if (!CanAttackDigimon())
  133. {
  134. if (!CanAttackPlayer())
  135. {
  136. return false;
  137. }
  138. }
  139. if (GManager.instance.attackProcess.IsAttacking)
  140. {
  141. return false;
  142. }
  143. return true;
  144. }
  145. #endregion
  146. #region I—¹‚Å‚«‚é‚©”»’è
  147. bool CanEndSelect(Permanent selectedPermanent)
  148. {
  149. if (selectedPermanent == null)
  150. {
  151. if (!CanAttackPlayer())
  152. {
  153. return false;
  154. }
  155. }
  156. else
  157. {
  158. if (!CanAttackDigimon())
  159. {
  160. return false;
  161. }
  162. }
  163. return true;
  164. }
  165. #endregion
  166. public IEnumerator Activate()
  167. {
  168. _defender = null;
  169. _noSelect = false;
  170. if (_attacker == null) yield break;
  171. if (_attacker.TopCard == null) yield break;
  172. if (!_attacker.CanAttack(_cardEffect, _withoutTap, _isVortex)) yield break;
  173. if (active())
  174. {
  175. yield return GManager.instance.photonWaitController.StartWait("SelectAttackEffect");
  176. foreach (Player player in GManager.instance.turnStateMachine.gameContext.Players)
  177. {
  178. GManager.instance.turnStateMachine.OffFieldCardTarget(player);
  179. GManager.instance.turnStateMachine.OffHandCardTarget(player);
  180. }
  181. GManager.instance.turnStateMachine.IsSelecting = true;
  182. if (_attacker != null)
  183. {
  184. if (_attacker.TopCard != null)
  185. {
  186. if (_attacker.CanAttack(_cardEffect, _withoutTap, _isVortex))
  187. {
  188. if (_attacker.TopCard.Owner.isYou)
  189. {
  190. #region ƒƒbƒZ[ƒW•\ަ
  191. if (!string.IsNullOrEmpty(_customMessage))
  192. {
  193. GManager.instance.commandText.OpenCommandText(_customMessage);
  194. }
  195. else
  196. {
  197. if (CanAttackDigimon())
  198. {
  199. GManager.instance.commandText.OpenCommandText("Which target will you attack?");
  200. }
  201. else
  202. {
  203. GManager.instance.commandText.OpenCommandText("Will you attack to the opponent?");
  204. }
  205. }
  206. #endregion
  207. Permanent selectedPermanent = null;
  208. #region ƒvƒŒƒCƒ„[‚ւ̍UŒ‚
  209. if (CanAttackPlayer())
  210. {
  211. if (_attacker.TopCard.Owner.Enemy.SecurityCards.Count >= 1)
  212. {
  213. _attacker.TopCard.Owner.Enemy.securityObject.securityBreakGlass.ShowBlueMatarial();
  214. }
  215. _attacker.TopCard.Owner.Enemy.securityObject.SetSecurityAttackObject();
  216. _attacker.TopCard.Owner.Enemy.securityObject.SetSecurityOutline(true);
  217. _attacker.TopCard.Owner.Enemy.securityObject.AddClickTarget(() =>
  218. {
  219. selectedPermanent = null;
  220. EndSelect_RPC();
  221. });
  222. }
  223. #endregion
  224. List<FieldPermanentCard> candidates = new List<FieldPermanentCard>();
  225. foreach (Player player in GManager.instance.turnStateMachine.gameContext.Players)
  226. {
  227. foreach (Permanent permanent in player.GetFieldPermanents())
  228. {
  229. if (CanTarget(permanent))
  230. {
  231. permanent.ShowingPermanentCard.AddClickTarget(OnClickFieldPermanentCard);
  232. candidates.Add(permanent.ShowingPermanentCard);
  233. }
  234. }
  235. }
  236. if (candidates.Count >= 1)
  237. {
  238. GManager.instance.hideCannotSelectObject.SetUpHideCannotSelectObject(candidates, false);
  239. }
  240. CheckEndSelect();
  241. #region ê‚̃p[ƒ}ƒlƒ“ƒg‚ªƒNƒŠƒbƒN‚³‚ê‚½Žž‚̏ˆ—
  242. void OnClickFieldPermanentCard(FieldPermanentCard fieldPermanentCard)
  243. {
  244. if (selectedPermanent == fieldPermanentCard.ThisPermanent)
  245. {
  246. selectedPermanent = null;
  247. }
  248. else
  249. {
  250. selectedPermanent = fieldPermanentCard.ThisPermanent;
  251. }
  252. CheckEndSelect();
  253. }
  254. #endregion
  255. #region ‘I‘ð‚ðI—¹‚Å‚«‚é‚©‚Ì”»’è‚ÆƒAƒEƒgƒ‰ƒCƒ“•\ަ
  256. void CheckEndSelect()
  257. {
  258. #region I—¹‚Å‚«‚é‚©‚É‚æ‚Á‚ÄUI•\ަ
  259. if (CanEndSelect(selectedPermanent))
  260. {
  261. }
  262. else
  263. {
  264. }
  265. #endregion
  266. #region ƒAƒEƒgƒ‰ƒCƒ“•\ަ
  267. foreach (Player player in GManager.instance.turnStateMachine.gameContext.Players)
  268. {
  269. foreach (Permanent permanent in player.GetFieldPermanents())
  270. {
  271. permanent.ShowingPermanentCard.RemoveSelectEffect();
  272. if (CanTarget(permanent))
  273. {
  274. if (selectedPermanent == permanent)
  275. {
  276. permanent.ShowingPermanentCard.OnSelectEffect(1.1f);
  277. permanent.ShowingPermanentCard.SetOrangeOutline();
  278. }
  279. else
  280. {
  281. permanent.ShowingPermanentCard.OnSelectEffect(1.1f);
  282. permanent.ShowingPermanentCard.SetBlueOutline();
  283. }
  284. }
  285. }
  286. }
  287. #endregion
  288. if (selectedPermanent == null)
  289. {
  290. if (_canSelectNotAttack)
  291. {
  292. GManager.instance.BackButton.OpenSelectCommandButton("Not Attack", () => { photonView.RPC("SetNotAttack", RpcTarget.All); }, 0);
  293. }
  294. GManager.instance.selectCommandPanel.CloseSelectCommandPanel();
  295. }
  296. else
  297. {
  298. GManager.instance.selectCommandPanel.SetUpCommandButton(new List<Command_SelectCommand>() { new Command_SelectCommand("End Selection", EndSelect_RPC, 0) });
  299. GManager.instance.BackButton.CloseSelectCommandButton();
  300. }
  301. }
  302. #endregion
  303. #region ‘I‘ðI—¹
  304. void EndSelect_RPC()
  305. {
  306. foreach (Player player in GManager.instance.turnStateMachine.gameContext.Players)
  307. {
  308. foreach (Permanent permanent in player.GetFieldPermanents())
  309. {
  310. permanent.ShowingPermanentCard.RemoveSelectEffect();
  311. permanent.ShowingPermanentCard.RemoveClickTarget();
  312. }
  313. }
  314. bool isPlayer = true;
  315. bool isTurnPlayer = false;
  316. int PermanentIndex = -1;
  317. if (selectedPermanent != null)
  318. {
  319. if (selectedPermanent.TopCard != null)
  320. {
  321. isPlayer = false;
  322. isTurnPlayer = selectedPermanent.TopCard.Owner == GManager.instance.turnStateMachine.gameContext.TurnPlayer;
  323. PermanentIndex = selectedPermanent.TopCard.Owner.GetFieldPermanents().IndexOf(selectedPermanent);
  324. }
  325. }
  326. photonView.RPC("SetAttackTarget", RpcTarget.All, isPlayer, isTurnPlayer, PermanentIndex);
  327. GManager.instance.BackButton.CloseSelectCommandButton();
  328. }
  329. #endregion
  330. }
  331. else
  332. {
  333. #region ƒƒbƒZ[ƒW•\ަ
  334. if (!string.IsNullOrEmpty(_customMessage_Enemy))
  335. {
  336. GManager.instance.commandText.OpenCommandText(_customMessage_Enemy);
  337. }
  338. else
  339. {
  340. GManager.instance.commandText.OpenCommandText("The opponent is selecting the attack target.");
  341. }
  342. #endregion
  343. #region AI
  344. if (GManager.instance.IsAI)
  345. {
  346. List<Permanent> AttackcTargetCandidates = new List<Permanent>();
  347. foreach (Player player in GManager.instance.turnStateMachine.gameContext.Players_ForTurnPlayer)
  348. {
  349. foreach (Permanent permanent in player.GetFieldPermanents())
  350. {
  351. if (CanTarget(permanent))
  352. {
  353. AttackcTargetCandidates.Add(permanent);
  354. }
  355. }
  356. }
  357. Permanent selectedPermanent = null;
  358. if (AttackcTargetCandidates.Count >= 1)
  359. {
  360. if (!_attacker.CanAttackTargetDigimon(null, _cardEffect, _withoutTap, _isVortex) || (_attacker.TopCard.Owner.Enemy.SecurityCards.Count >= 3 && RandomUtility.IsSucceedProbability(0.5f)))
  361. {
  362. selectedPermanent = AttackcTargetCandidates[UnityEngine.Random.Range(0, AttackcTargetCandidates.Count)];
  363. }
  364. }
  365. bool isPlayer = true;
  366. bool isTurnPlayer = false;
  367. int PermanentIndex = -1;
  368. if (selectedPermanent != null)
  369. {
  370. if (selectedPermanent.TopCard != null)
  371. {
  372. isPlayer = false;
  373. isTurnPlayer = selectedPermanent.TopCard.Owner == GManager.instance.turnStateMachine.gameContext.TurnPlayer;
  374. PermanentIndex = selectedPermanent.TopCard.Owner.GetFieldPermanents().IndexOf(selectedPermanent);
  375. }
  376. }
  377. SetAttackTarget(isPlayer, isTurnPlayer, PermanentIndex);
  378. }
  379. #endregion
  380. }
  381. }
  382. }
  383. }
  384. //‘I‘ð‚ªŠ®—¹‚·‚é‚܂őҋ@
  385. yield return new WaitWhile(() => !_endSelect);
  386. _endSelect = false;
  387. #region ƒŠƒZƒbƒg
  388. foreach (Player player in GManager.instance.turnStateMachine.gameContext.Players)
  389. {
  390. GManager.instance.turnStateMachine.OffFieldCardTarget(player);
  391. GManager.instance.turnStateMachine.OffHandCardTarget(player);
  392. foreach (Permanent permanent in player.GetFieldPermanents())
  393. {
  394. permanent.ShowingPermanentCard.RemoveSelectEffect();
  395. }
  396. player.securityObject.OffShowSecurityAttackObject();
  397. player.securityObject.RemoveClickTarget();
  398. if (_defender != null || _noSelect)
  399. {
  400. player.securityObject.securityBreakGlass.gameObject.SetActive(false);
  401. }
  402. }
  403. GManager.instance.hideCannotSelectObject.Close();
  404. GManager.instance.selectCommandPanel.CloseSelectCommandPanel();
  405. GManager.instance.BackButton.CloseSelectCommandButton();
  406. GManager.instance.commandText.CloseCommandText();
  407. yield return new WaitWhile(() => GManager.instance.commandText.gameObject.activeSelf);
  408. #endregion
  409. if (!_noSelect)
  410. {
  411. if (CanEndSelect(_defender))
  412. {
  413. yield return ContinuousController.instance.StartCoroutine(GManager.instance.attackProcess.Attack(_attacker, _defender, _cardEffect, _withoutTap, _beforeOnAttackCoroutine));
  414. }
  415. }
  416. }
  417. }
  418. #region ‘I‘ðŒˆ’è
  419. [PunRPC]
  420. public void SetAttackTarget(bool isPlayer, bool isTurnPlayer, int PermanentIndex)
  421. {
  422. _defender = null;
  423. if (!isPlayer)
  424. {
  425. Player player = null;
  426. if (isTurnPlayer)
  427. {
  428. player = GManager.instance.turnStateMachine.gameContext.TurnPlayer;
  429. }
  430. else
  431. {
  432. player = GManager.instance.turnStateMachine.gameContext.NonTurnPlayer;
  433. }
  434. Permanent permanent = null;
  435. if (0 <= PermanentIndex && PermanentIndex <= player.GetFieldPermanents().Count - 1)
  436. {
  437. permanent = player.GetFieldPermanents()[PermanentIndex];
  438. }
  439. if (permanent != null)
  440. {
  441. _defender = permanent;
  442. }
  443. }
  444. _endSelect = true;
  445. }
  446. #endregion
  447. #region ‘I‘ð‚µ‚È‚¢
  448. [PunRPC]
  449. public void SetNotAttack()
  450. {
  451. GManager.instance.selectCommandPanel.CloseSelectCommandPanel();
  452. _defender = null;
  453. _noSelect = true;
  454. _endSelect = true;
  455. }
  456. #endregion
  457. }