using System; using System.Collections.Generic; using Photon.Pun; using UnityEngine; public class CharacterData : MonoBehaviour { public Vector3 aimDirection; public List currentCards; public float sinceGroundedMultiplierWhenWallGrab = 0.2f; public PlayerActions playerActions; public ParticleSystem[] landParts; public int jumps = 1; public int currentJumps = 1; public bool isPlaying; public bool dead; public bool isStunned; public bool isSilenced; public float stunTime; public float silenceTime; public float health = 100f; public float maxHealth = 100f; public AnimationCurve slamCurve; public Vector3 wallPos; public Vector2 wallNormal; public Vector3 groundPos; public Transform hand; public float sinceWallGrab = float.PositiveInfinity; public bool isWallGrab; public float wallDistance = 1f; private bool wasWallGrabLastFrame; public float sinceGrounded; public bool isGrounded = true; private bool wasGroundedLastFrame = true; public Player player; public float sinceJump = 1f; public PlayerVelocity playerVel; public HealthHandler healthHandler; public GeneralInput input; public PlayerMovement movement; public PlayerJump jump; public Block block; public CharacterStatModifiers stats; public WeaponHandler weaponHandler; public StunHandler stunHandler; public SilenceHandler silenceHandler; public Player lastSourceOfDamage; public Player master; public Player lastDamagedPlayer; public Collider2D mainCol; public PlayerSounds playerSounds; private Transform wobblePos; private LayerMask groundMask; public PhotonView view; private CrownPos crownPos; public Rigidbody2D standOnRig; public Action TouchGroundAction; public Action TouchWallAction; public float HealthPercentage { get { return health / maxHealth; } internal set { } } private void Awake() { crownPos = GetComponentInChildren(); view = GetComponent(); mainCol = GetComponent(); wobblePos = GetComponentInChildren().transform; stats = GetComponent(); player = GetComponent(); weaponHandler = GetComponent(); block = GetComponent(); input = GetComponent(); movement = GetComponent(); jump = GetComponent(); stunHandler = GetComponent(); silenceHandler = GetComponent(); hand = GetComponentInChildren().transform; playerVel = GetComponent(); healthHandler = GetComponent(); playerSounds = GetComponent(); } internal Vector3 GetCrownPos() { if ((bool)crownPos) { return crownPos.transform.position + Vector3.up * crownPos.GetOffset(); } Debug.LogError("NO CROWN POS!?"); return Vector3.up * 1000f; } private void Start() { groundMask = LayerMask.GetMask("Default"); if (!view.IsMine) { PlayerManager.RegisterPlayer(player); } } private void Update() { if (!playerVel.simulated) { sinceGrounded = 0f; } sinceJump += TimeHandler.deltaTime; Wall(); } private void FixedUpdate() { Ground(); } private void Ground() { if (!isPlaying) { return; } if (!isGrounded) { sinceGrounded += TimeHandler.fixedDeltaTime * ((isWallGrab && wallDistance < 0.7f) ? sinceGroundedMultiplierWhenWallGrab : 1f); if (sinceGrounded < 0f) { sinceGrounded = Mathf.Lerp(sinceGrounded, 0f, TimeHandler.fixedDeltaTime * 15f); } } if (!wasGroundedLastFrame) { isGrounded = false; } wasGroundedLastFrame = false; } private void Wall() { if (!isWallGrab) { sinceWallGrab += TimeHandler.deltaTime; } if (!wasWallGrabLastFrame) { isWallGrab = false; } wasWallGrabLastFrame = false; } public void TouchGround(Vector3 pos, Vector3 groundNormal, Rigidbody2D groundRig, Transform groundTransform = null) { if (sinceJump > 0.2f) { currentJumps = jumps; } if (TouchGroundAction != null) { TouchGroundAction(sinceGrounded, pos, groundNormal, groundTransform); } if (groundRig == null) { standOnRig = null; } else if (!groundRig.GetComponent()) { standOnRig = groundRig; } if (playerVel.velocity.y < -20f && !isGrounded) { for (int i = 0; i < landParts.Length; i++) { landParts[i].transform.localScale = Vector3.one * Mathf.Clamp((0f - playerVel.velocity.y) / 40f, 0.5f, 1f) * 0.5f; landParts[i].transform.position = new Vector3(base.transform.position.x + playerVel.velocity.x * 0.03f, pos.y, 5f); landParts[i].transform.rotation = Quaternion.LookRotation(groundNormal); landParts[i].Play(); } GamefeelManager.instance.AddGameFeel(Vector2.down * Mathf.Clamp((sinceGrounded - 0.5f) * 1f, 0f, 4f)); } groundPos = pos; wasGroundedLastFrame = true; isGrounded = true; sinceGrounded = 0f; } public void TouchWall(Vector2 normal, Vector3 pos) { if (isGrounded) { return; } wallNormal = normal; wallPos = pos; groundPos = pos; wallDistance = Vector2.Distance(base.transform.position, pos); if (!(sinceJump < 0.15f)) { currentJumps = jumps; if (TouchWallAction != null) { TouchWallAction(sinceWallGrab, pos, normal); } _ = sinceWallGrab; _ = 0.15f; sinceWallGrab = 0f; wasWallGrabLastFrame = true; isWallGrab = true; } } public bool ThereIsGroundBelow(Vector3 pos, float range = 5f) { RaycastHit2D raycastHit2D = Physics2D.Raycast(pos, Vector2.down, range, groundMask); if ((bool)raycastHit2D.transform && raycastHit2D.distance > 0.1f) { return true; } return false; } public void SetAI(Player aiMaster = null) { master = aiMaster; input.controlledElseWhere = true; GetComponent().enabled = true; } public void SetWobbleObjectChild(Transform obj) { obj.transform.SetParent(wobblePos, worldPositionStays: true); } }