<commit_before>﻿using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class EnemyAttack : MonoBehaviour
{
    public float range = 10.0f;

    public float blinkRate = 0.3f;
    public float tellLength = 2.0f;
    public float attackLength = 1.0f;
    public float damagePerSecond = 0.5f;
    private bool telling = false;
    private bool attacking = false;

    // Attack cooldown
    public float cooldown = 5.0f;
    private float timeleft = 0.0f;

    public float tellWidth = 1.0f;
    public float attackWidth = 3.0f;

    private GameObject player;
    private GameManager mgr;
    private LineRenderer lr;
    private Vector3 target;

    public enum Phase { IDLE, TELLING, ATTACKING }
    private Phase _phase = Phase.IDLE;
    public Phase phase
    {
        get
        {
            return _phase;
        }
    }

    private EnemyMovement movement;
    private HoverCar hover;
    private Rigidbody rb;

    // Use this for initialization
    void Start()
    {
        mgr = GameObject.FindObjectOfType<GameManager>();
        lr = GetComponentInChildren<LineRenderer>();

        hover = GetComponent<HoverCar>();
        movement = GetComponent<EnemyMovement>();
        rb = GetComponent<Rigidbody>();
    }

    // Update is called once per frame
    void Update()
    {
        float deltaTime = Time.deltaTime;
        Vector3 playerPosition = mgr.playerPosition;

        float dist = Vector3.Distance(transform.position, playerPosition);
        if (dist > range)
        {
            if (_phase != Phase.IDLE) timeleft = cooldown;
            lr.enabled = false;
            _phase = Phase.IDLE;
        }
        else
        {

            switch (_phase)
            {
                case Phase.IDLE:
                    if (timeleft <= 0)
                    {
                        target = mgr.playerPosition;
                        _phase = Phase.TELLING;
                        UpdateLine();

                        DisableMovement();

                        lr.startWidth = tellWidth;
                        lr.endWidth = tellWidth;

                        timeleft = tellLength;
                        StartCoroutine(LineFlash());
                    }
                    break;

                case Phase.TELLING:
                    if (timeleft <= 0)
                    {
                        _phase = Phase.ATTACKING;
                        timeleft = attackLength;
                    }
                    break;

                case Phase.ATTACKING:
                    // Update line renderer target
                    lr.startWidth = attackWidth;
                    lr.endWidth = attackWidth;
                    lr.enabled = true;
                    if (timeleft <= 0)
                    {
                        EnableMovement();
                        lr.enabled = false;
                        _phase = Phase.IDLE;
                        timeleft = cooldown;
                    }
                    mgr.DamagePlayer(deltaTime * damagePerSecond);
                    break;

            }
        }

        timeleft -= Time.deltaTime;
    }


    private void UpdateLine()
    {
        lr.SetPositions(new Vector3[] {
            transform.position,
            target
        });
    }

    private void DisableMovement()
    {
        movement.enabled = false;
        hover.enabled = false;
        rb.useGravity = false;
        rb.velocity = Vector3.zero;
        rb.angularVelocity = Vector3.zero;
    }

    private void EnableMovement()
    {
        movement.enabled = true;
        hover.enabled = true;
        rb.useGravity = true;
    }

    IEnumerator LineFlash()
    {
        while (_phase == Phase.TELLING)
        {
            float t = (timeleft / tellLength) / 2.0f;
            //Debug.Log(t);
            lr.enabled = !lr.enabled;
            yield return new WaitForSeconds(t);
        }
    }

}
<commit_msg>enemy attacks follow the player<commit_after>﻿using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class EnemyAttack : MonoBehaviour
{
    public float range = 10.0f;

    public float blinkRate = 0.3f;
    public float tellLength = 2.0f;
    public float attackLength = 1.0f;
    public float damagePerSecond = 0.5f;
    private bool telling = false;
    private bool attacking = false;

    // Attack cooldown
    public float cooldown = 5.0f;
    private float timeleft = 0.0f;

    public float tellWidth = 1.0f;
    public float attackWidth = 3.0f;

    private GameObject player;
    private GameManager mgr;
    private LineRenderer lr;
    private Vector3 target;
    private Vector3 targettingVelocity = Vector3.zero;
    public float attackFollowRate = 0.5f;

    public enum Phase { IDLE, TELLING, ATTACKING }
    private Phase _phase = Phase.IDLE;
    public Phase phase
    {
        get
        {
            return _phase;
        }
    }

    private EnemyMovement movement;
    private HoverCar hover;
    private Rigidbody rb;

    // Use this for initialization
    void Start()
    {
        mgr = GameObject.FindObjectOfType<GameManager>();
        lr = GetComponentInChildren<LineRenderer>();

        hover = GetComponent<HoverCar>();
        movement = GetComponent<EnemyMovement>();
        rb = GetComponent<Rigidbody>();
    }

    // Update is called once per frame
    void Update()
    {
        float deltaTime = Time.deltaTime;
        Vector3 playerPosition = mgr.playerPosition;

        float dist = Vector3.Distance(transform.position, playerPosition);
        if (dist > range)
        {
            if (_phase != Phase.IDLE) timeleft = cooldown;
            lr.enabled = false;
            _phase = Phase.IDLE;
        }
        else
        {

            switch (_phase)
            {
                case Phase.IDLE:
                    if (timeleft <= 0)
                    {
                        target = mgr.playerPosition;
                        _phase = Phase.TELLING;

                        DisableMovement();

                        lr.startWidth = tellWidth;
                        lr.endWidth = tellWidth;

                        timeleft = tellLength;
                        StartCoroutine(LineFlash());
                    }
                    break;

                case Phase.TELLING:
                    UpdateLine();
                    if (timeleft <= 0)
                    {
                        _phase = Phase.ATTACKING;
                        timeleft = attackLength;
                    }
                    break;

                case Phase.ATTACKING:
                    UpdateLine();
                    lr.startWidth = attackWidth;
                    lr.endWidth = attackWidth;
                    lr.enabled = true;
                    if (timeleft <= 0)
                    {
                        EnableMovement();
                        lr.enabled = false;
                        _phase = Phase.IDLE;
                        timeleft = cooldown;
                    }
                    mgr.DamagePlayer(deltaTime * damagePerSecond);
                    break;

            }
        }

        timeleft -= Time.deltaTime;
    }


    private void UpdateLine()
    {
        // Lag target behind player
        target = Vector3.SmoothDamp(target, mgr.player.transform.position, ref targettingVelocity, attackFollowRate);
        lr.SetPositions(new Vector3[] {
            transform.position,
            target
        });
    }

    private void DisableMovement()
    {
        movement.enabled = false;
        hover.enabled = false;
        rb.useGravity = false;
        rb.velocity = Vector3.zero;
        rb.angularVelocity = Vector3.zero;
    }

    private void EnableMovement()
    {
        movement.enabled = true;
        hover.enabled = true;
        rb.useGravity = true;
    }

    IEnumerator LineFlash()
    {
        while (_phase == Phase.TELLING)
        {
            float t = (timeleft / tellLength) / 2.0f;
            lr.enabled = !lr.enabled;
            yield return new WaitForSeconds(t);
        }
    }

}

{'fraction_non_alphanumeric': 0.07889546351084813, 'fraction_numerical': 0.008012820512820512, 'mean_word_length': 1.3146932952924393, 'pattern_counts': {'":': 0, '<': 19, '<?xml version=': 0, '>': 15, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6060776', 'n_tokens_mistral': 2220, 'n_tokens_neox': 2051, 'n_words': 506}