Files

418 lines
14 KiB
C#
Raw Permalink Normal View History

2021-09-10 20:18:02 +02:00
using UnityEngine;
2021-09-11 14:08:35 +02:00
public class CpuController : BaseController
2021-09-10 20:18:02 +02:00
{
2022-11-16 12:28:39 +02:00
private Transform _otherPlayer;
2022-11-19 12:19:42 +02:00
private int _movementInputX;
private float _distance;
private float _arcanaTimer;
private float _attackTimer;
private float _movementTimer;
2022-11-16 12:28:39 +02:00
private bool _crouch;
private bool _jump;
private bool _reset;
2022-11-19 12:19:42 +02:00
2022-11-16 12:28:39 +02:00
public void SetOtherPlayer(Transform otherPlayer)
{
_otherPlayer = otherPlayer;
}
2021-09-11 16:32:11 +02:00
2023-01-19 17:07:46 +02:00
void FixedUpdate()
2022-11-16 12:28:39 +02:00
{
2022-12-04 21:35:31 +02:00
if (GameplayManager.Instance.HasGameStarted)
2022-11-16 12:28:39 +02:00
{
if (!TrainingSettings.CpuOff || !SceneSettings.IsTrainingMode)
{
NetworkInput.ONE_LIGHT_INPUT = false;
NetworkInput.ONE_MEDIUM_INPUT = false;
NetworkInput.ONE_HEAVY_INPUT = false;
NetworkInput.ONE_ARCANA_INPUT = false;
NetworkInput.ONE_GRAB_INPUT = false;
NetworkInput.ONE_SHADOW_INPUT = false;
NetworkInput.TWO_LIGHT_INPUT = false;
NetworkInput.TWO_MEDIUM_INPUT = false;
NetworkInput.TWO_HEAVY_INPUT = false;
NetworkInput.TWO_ARCANA_INPUT = false;
NetworkInput.TWO_GRAB_INPUT = false;
NetworkInput.TWO_SHADOW_INPUT = false;
2022-11-16 12:28:39 +02:00
_reset = false;
2022-11-18 00:36:16 +02:00
Movement();
bool attacked = true;
2023-01-19 17:07:46 +02:00
if (_distance <= 80)
2023-01-17 00:02:29 +02:00
Attack();
if (!attacked)
Specials();
2022-11-16 12:28:39 +02:00
}
else
{
if (!_reset)
{
2022-12-21 16:07:24 +02:00
if (_player.IsPlayerOne)
{
NetworkInput.ONE_UP_INPUT = false;
NetworkInput.ONE_DOWN_INPUT = false;
NetworkInput.ONE_RIGHT_INPUT = false;
NetworkInput.ONE_LEFT_INPUT = false;
}
else
{
NetworkInput.TWO_UP_INPUT = false;
NetworkInput.TWO_DOWN_INPUT = false;
NetworkInput.TWO_RIGHT_INPUT = false;
NetworkInput.TWO_LEFT_INPUT = false;
}
2022-11-16 12:28:39 +02:00
_reset = true;
InputDirection = Vector2Int.zero;
}
}
}
else
{
InputDirection = Vector2Int.zero;
}
}
2021-09-10 20:18:02 +02:00
2022-11-18 00:36:16 +02:00
private void Movement()
{
2022-11-19 12:19:42 +02:00
_distance = Mathf.Abs(_otherPlayer.transform.position.x - transform.position.x);
_movementTimer -= Time.deltaTime;
_jump = false;
if (_movementTimer < 0)
2022-11-18 00:36:16 +02:00
{
2022-11-19 12:19:42 +02:00
int movementRandom;
2023-01-19 17:07:46 +02:00
if (_distance <= 80)
2022-11-18 00:36:16 +02:00
{
2022-11-19 12:19:42 +02:00
movementRandom = Random.Range(0, 6);
2022-11-18 00:36:16 +02:00
}
2022-11-19 12:19:42 +02:00
else
{
movementRandom = Random.Range(0, 9);
}
int jumpRandom = Random.Range(0, 12);
int crouchRandom = Random.Range(0, 12);
int standingRandom = Random.Range(0, 4);
int dashRandom = Random.Range(0, 8);
2022-12-21 16:07:24 +02:00
if (_player.IsPlayerOne)
{
NetworkInput.ONE_UP_INPUT = false;
}
else
{
NetworkInput.TWO_UP_INPUT = false;
}
2022-11-19 12:19:42 +02:00
switch (movementRandom)
{
case 0:
2022-12-21 16:07:24 +02:00
if (_player.IsPlayerOne)
{
NetworkInput.ONE_RIGHT_INPUT = false;
NetworkInput.ONE_LEFT_INPUT = false;
}
else
{
NetworkInput.TWO_RIGHT_INPUT = false;
NetworkInput.TWO_LEFT_INPUT = false;
}
2022-11-19 12:19:42 +02:00
_movementInputX = 0;
break;
case > 0 and <= 4:
_movementInputX = (int)(transform.localScale.x * -1);
if (_movementInputX == 1.0f)
{
2022-12-21 16:07:24 +02:00
if (_player.IsPlayerOne)
{
2023-01-19 17:07:46 +02:00
NetworkInput.ONE_RIGHT_INPUT = false;
2022-12-21 16:07:24 +02:00
NetworkInput.ONE_LEFT_INPUT = true;
}
else
{
2023-01-19 17:07:46 +02:00
NetworkInput.TWO_RIGHT_INPUT = false;
2022-12-21 16:07:24 +02:00
NetworkInput.TWO_LEFT_INPUT = true;
}
2022-11-19 12:19:42 +02:00
}
else if (_movementInputX == -1.0f)
{
2022-12-21 16:07:24 +02:00
if (_player.IsPlayerOne)
{
2023-01-19 17:07:46 +02:00
NetworkInput.ONE_LEFT_INPUT = false;
2022-12-21 16:07:24 +02:00
NetworkInput.ONE_RIGHT_INPUT = true;
}
else
{
2023-01-19 17:07:46 +02:00
NetworkInput.TWO_LEFT_INPUT = false;
2022-12-21 16:07:24 +02:00
NetworkInput.TWO_RIGHT_INPUT = true;
}
2022-11-19 12:19:42 +02:00
}
break;
case > 5:
_movementInputX = (int)(transform.localScale.x * 1);
if (_movementInputX == 1.0f)
{
2022-12-21 16:07:24 +02:00
if (_player.IsPlayerOne)
{
2023-01-19 17:07:46 +02:00
NetworkInput.ONE_RIGHT_INPUT = false;
2022-12-21 16:07:24 +02:00
NetworkInput.ONE_LEFT_INPUT = true;
}
else
{
2023-01-19 17:07:46 +02:00
NetworkInput.TWO_RIGHT_INPUT = false;
2022-12-21 16:07:24 +02:00
NetworkInput.TWO_LEFT_INPUT = true;
}
2022-11-19 12:19:42 +02:00
}
else if (_movementInputX == -1.0f)
{
2022-12-21 16:07:24 +02:00
if (_player.IsPlayerOne)
{
2023-01-19 17:07:46 +02:00
NetworkInput.ONE_LEFT_INPUT = false;
2022-12-21 16:07:24 +02:00
NetworkInput.ONE_RIGHT_INPUT = true;
}
else
{
2023-01-19 17:07:46 +02:00
NetworkInput.TWO_LEFT_INPUT = false;
2022-12-21 16:07:24 +02:00
NetworkInput.TWO_RIGHT_INPUT = true;
}
2022-11-19 12:19:42 +02:00
}
break;
}
if (jumpRandom == 2)
{
_jump = true;
_movementInputX = (int)(transform.localScale.x * 1.0f);
2022-12-21 16:07:24 +02:00
if (_player.IsPlayerOne)
{
2023-01-19 17:07:46 +02:00
NetworkInput.ONE_UP_INPUT = true;
2022-12-21 16:07:24 +02:00
}
else
{
2023-01-19 17:07:46 +02:00
NetworkInput.TWO_UP_INPUT = true;
2022-12-21 16:07:24 +02:00
}
2022-11-19 12:19:42 +02:00
}
if (crouchRandom == 2)
{
_crouch = true;
2022-12-21 16:07:24 +02:00
if (_player.IsPlayerOne)
{
2023-01-19 17:07:46 +02:00
NetworkInput.ONE_DOWN_INPUT = true;
2022-12-21 16:07:24 +02:00
}
else
{
2023-01-19 17:07:46 +02:00
NetworkInput.TWO_DOWN_INPUT = true;
2022-12-21 16:07:24 +02:00
}
2022-11-19 12:19:42 +02:00
}
if (standingRandom == 2)
{
2022-12-21 16:07:24 +02:00
if (_player.IsPlayerOne)
{
NetworkInput.ONE_DOWN_INPUT = false;
}
else
{
NetworkInput.TWO_DOWN_INPUT = false;
}
2022-11-19 12:19:42 +02:00
}
InputDirection = new Vector2Int(_movementInputX, 0);
_movementTimer = Random.Range(0.2f, 0.35f);
2022-11-18 00:36:16 +02:00
}
}
2022-11-16 12:28:39 +02:00
private void Attack()
{
if (IsControllerEnabled)
{
2022-11-19 12:19:42 +02:00
_attackTimer -= Time.deltaTime;
if (_attackTimer < 0)
2022-11-16 12:28:39 +02:00
{
2023-01-19 17:07:46 +02:00
int lowRandom = Random.Range(0, 2);
2023-01-17 00:02:29 +02:00
int attackRandom = Random.Range(0, 7);
2022-11-16 12:28:39 +02:00
if (attackRandom <= 2)
{
2023-01-19 17:07:46 +02:00
if (lowRandom == 0)
2023-01-17 00:02:29 +02:00
{
2023-01-19 17:07:46 +02:00
if (_player.IsPlayerOne)
{
NetworkInput.ONE_DOWN_INPUT = false;
NetworkInput.ONE_LIGHT_INPUT = true;
}
else
{
NetworkInput.TWO_DOWN_INPUT = false;
NetworkInput.TWO_LIGHT_INPUT = true;
}
2023-01-17 00:02:29 +02:00
}
2023-01-19 17:07:46 +02:00
else if (lowRandom == 1)
2023-01-17 00:02:29 +02:00
{
2023-01-19 17:07:46 +02:00
if (_player.IsPlayerOne)
{
NetworkInput.ONE_DOWN_INPUT = true;
NetworkInput.ONE_LIGHT_INPUT = true;
}
else
{
NetworkInput.TWO_DOWN_INPUT = true;
NetworkInput.TWO_LIGHT_INPUT = true;
}
2023-01-17 00:02:29 +02:00
}
2022-11-16 12:28:39 +02:00
}
else if (attackRandom <= 4 && attackRandom > 2)
2022-11-16 12:28:39 +02:00
{
2023-01-19 17:07:46 +02:00
if (lowRandom == 0)
2023-01-17 00:02:29 +02:00
{
2023-01-19 17:07:46 +02:00
if (_player.IsPlayerOne)
{
NetworkInput.ONE_DOWN_INPUT = false;
NetworkInput.ONE_MEDIUM_INPUT = true;
}
else
{
NetworkInput.TWO_DOWN_INPUT = false;
NetworkInput.TWO_MEDIUM_INPUT = true;
}
2023-01-17 00:02:29 +02:00
}
2023-01-19 17:07:46 +02:00
else if (lowRandom == 1)
2023-01-17 00:02:29 +02:00
{
2023-01-19 17:07:46 +02:00
if (_player.IsPlayerOne)
{
NetworkInput.ONE_DOWN_INPUT = false;
NetworkInput.ONE_MEDIUM_INPUT = true;
}
else
{
NetworkInput.TWO_DOWN_INPUT = true;
NetworkInput.TWO_MEDIUM_INPUT = true;
}
2023-01-17 00:02:29 +02:00
}
2022-11-16 12:28:39 +02:00
}
else if (attackRandom <= 6 && attackRandom > 4)
2022-11-16 12:28:39 +02:00
{
2023-01-19 17:07:46 +02:00
if (lowRandom == 0)
2023-01-17 00:02:29 +02:00
{
2023-01-19 17:07:46 +02:00
if (_player.IsPlayerOne)
{
NetworkInput.ONE_DOWN_INPUT = false;
NetworkInput.ONE_HEAVY_INPUT = true;
}
else
{
NetworkInput.TWO_DOWN_INPUT = false;
NetworkInput.TWO_HEAVY_INPUT = true;
}
2023-01-17 00:02:29 +02:00
}
2023-01-19 17:07:46 +02:00
else if (lowRandom == 1)
2023-01-17 00:02:29 +02:00
{
2023-01-19 17:07:46 +02:00
if (_player.IsPlayerOne)
{
NetworkInput.ONE_DOWN_INPUT = true;
NetworkInput.ONE_HEAVY_INPUT = true;
}
else
{
NetworkInput.TWO_DOWN_INPUT = true;
NetworkInput.TWO_HEAVY_INPUT = true;
}
2023-01-17 00:02:29 +02:00
}
2022-11-16 12:28:39 +02:00
}
else
{
2023-01-17 00:02:29 +02:00
if (_player.IsPlayerOne)
{
NetworkInput.ONE_GRAB_INPUT = true;
}
else
{
NetworkInput.TWO_GRAB_INPUT = true;
}
2022-11-16 12:28:39 +02:00
}
2023-01-19 17:07:46 +02:00
_attackTimer = Random.Range(0.15f, 0.3f);
2022-11-16 12:28:39 +02:00
}
}
}
2022-04-28 03:00:02 +02:00
2022-11-16 12:28:39 +02:00
private void Specials()
{
if (IsControllerEnabled)
{
2022-11-19 12:19:42 +02:00
_arcanaTimer -= Time.deltaTime;
if (_arcanaTimer < 0)
2022-11-16 12:28:39 +02:00
{
int arcanaRandom = Random.Range(0, 2);
2023-01-19 17:07:46 +02:00
int lowRandom = Random.Range(0, 2);
2022-11-16 12:28:39 +02:00
if (arcanaRandom == 0)
{
2023-01-17 00:02:29 +02:00
if (_player.IsPlayerOne)
{
NetworkInput.ONE_SHADOW_INPUT = true;
}
else
{
NetworkInput.TWO_SHADOW_INPUT = true;
}
2022-11-16 12:28:39 +02:00
}
else if (arcanaRandom == 1)
{
2023-01-19 17:07:46 +02:00
if (lowRandom == 0)
2023-01-17 00:02:29 +02:00
{
2023-01-19 17:07:46 +02:00
if (_player.IsPlayerOne)
{
NetworkInput.ONE_DOWN_INPUT = false;
NetworkInput.ONE_ARCANA_INPUT = true;
}
else
{
NetworkInput.TWO_DOWN_INPUT = false;
NetworkInput.TWO_ARCANA_INPUT = true;
}
2023-01-17 00:02:29 +02:00
}
else
{
2023-01-19 17:07:46 +02:00
if (_player.IsPlayerOne)
{
NetworkInput.ONE_DOWN_INPUT = true;
NetworkInput.ONE_ARCANA_INPUT = true;
}
else
{
NetworkInput.TWO_DOWN_INPUT = true;
NetworkInput.TWO_ARCANA_INPUT = true;
}
2023-01-17 00:02:29 +02:00
}
2023-01-19 17:07:46 +02:00
_attackTimer = Random.Range(0.15f, 0.35f);
_arcanaTimer = Random.Range(0.4f, 0.85f);
2022-11-16 12:28:39 +02:00
}
}
}
}
2021-12-23 15:05:41 +01:00
2022-11-16 12:28:39 +02:00
public override bool Crouch()
{
2022-11-19 12:19:42 +02:00
return _crouch;
2022-11-16 12:28:39 +02:00
}
2022-05-27 16:49:15 +02:00
2022-11-16 12:28:39 +02:00
public override bool StandUp()
{
2022-11-19 12:19:42 +02:00
return !_crouch;
}
public override bool Jump()
{
return _jump;
2022-11-16 12:28:39 +02:00
}
2022-05-27 16:49:15 +02:00
2022-11-16 12:28:39 +02:00
public override void ActivateInput()
{
if (!TrainingSettings.CpuOff)
{
base.ActivateInput();
}
}
2021-11-11 16:12:10 +01:00
2022-11-16 12:28:39 +02:00
public override void DeactivateInput()
{
if (!TrainingSettings.CpuOff)
{
base.DeactivateInput();
}
}
2021-09-10 20:18:02 +02:00
}