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

public class KnifeThrow : MonoBehaviour
{
    [SerializeField]
    private float lifespan = 4;
    [SerializeField]
    private float speed = 3;
    [SerializeField]
    private Vector3 vel;
    private bool collided = false;
    public GameObject killMarker;

    public AudioClip fallenSound;
    public AudioClip playerHitSound;
    public AudioClip blockHitSound;
    public AudioSource audioSource;
    private GameObject tosser;
    private float soundTimer = 0;
    private float soundCooldown = 1;
    private bool expired = false;

    // Use this for initialization
    void Start() { }
    void Kill(AudioClip clip)
    {
        expired = true;
        audioSource.Stop();

        audioSource.PlayOneShot(clip, 1);
        soundCooldown = clip.length;

        //  Hide and stop the object
        GetComponent<MeshRenderer>().enabled = false;
        Destroy(GetComponent<Rigidbody2D>());
    }
    public void Setup(GameObject shooter)
    {
        GetComponent<MeshRenderer>().enabled = true;
        transform.forward = shooter.transform.up;
        transform.position = shooter.transform.position + transform.forward;
        vel = transform.forward * speed;
        GetComponent<PhotonView>().RPC("SetKnife", PhotonTargets.Others, vel, transform.position);
        Debug.Log(transform.position);
        GetComponent<Rigidbody2D>().velocity = vel;
    }
    // Update is called once per frame
    void Update()
    {
        if (GetComponent<PhotonView>().isMine)
        {
            if (!collided)
                GetComponent<Rigidbody2D>().velocity = vel;
            lifespan -= Time.deltaTime;
            if (lifespan <= 0)
            {
                Kill(fallenSound);
                collided = true;
            }
            if (expired)
            {
                //  We have either gone too far, hit a player, or hit a wall
                soundTimer += Time.deltaTime;
                if (soundTimer > soundCooldown)
                {
                    PhotonNetwork.Destroy(gameObject);
                }
            }
            GetComponent<PhotonView>().RPC("SetKnife", PhotonTargets.Others, vel, transform.position);
        }
    }
    void OnCollisionEnter2D(Collision2D o)
    {
        Debug.Log(o.gameObject.tag);
        if (o.gameObject.tag == "Player" && lifespan < 3.9)
        {
            collided = true;
            o.gameObject.GetComponent<PhotonView>().RPC("Respawn", PhotonTargets.All);
            PhotonNetwork.Instantiate(killMarker.name, transform.position, Quaternion.Euler(0, 0, Random.Range(0, 360)), 0);
            if (GetComponent<PhotonView>().isMine)
                Kill(playerHitSound);
        }
        else if (o.gameObject.tag == "Wind")
        {


        }
        else {
            collided = true;
            //Embed self in object, stop moving.
            transform.position += transform.forward * 0.1f;
            Kill(blockHitSound);
        }
    }
    [PunRPC]
    void SetKnife(Vector3 vel, Vector3 pos)
    {
        transform.position = pos;
        this.vel = vel;
    }
}
//=======<commit_msg>Testing new knife<commit_after>﻿using UnityEngine;
using System.Collections;

public class KnifeThrow : MonoBehaviour
{
    [SerializeField]
    private float lifespan = 4;
    [SerializeField]
    private float speed = 3;
    [SerializeField]
    private Vector3 vel;
    private bool collided = false;
    public GameObject killMarker;

    public AudioClip fallenSound;
    public AudioClip playerHitSound;
    public AudioClip blockHitSound;
    public AudioSource audioSource;
    private int id;
    private float soundTimer = 0;
    private float soundCooldown = 1;
    private bool expired = false;

    // Use this for initialization
    void Start() { }
    void Kill(AudioClip clip)
    {
        expired = true;
        audioSource.Stop();

        audioSource.PlayOneShot(clip, 1);
        soundCooldown = clip.length;

        //  Hide and stop the object
        GetComponent<MeshRenderer>().enabled = false;
        Destroy(GetComponent<Rigidbody2D>());
    }
    public void Setup(GameObject shooter)
    {
        id = shooter.GetInstanceID();
        GetComponent<MeshRenderer>().enabled = true;
        transform.forward = shooter.transform.up;
        transform.position = shooter.transform.position + transform.forward;
        vel = transform.forward * speed;
        GetComponent<PhotonView>().RPC("SetKnife", PhotonTargets.Others, vel, transform.position, id);
        Debug.Log(transform.position);
        GetComponent<Rigidbody2D>().velocity = vel;
    }
    // Update is called once per frame
    void Update()
    {
        if (GetComponent<PhotonView>().isMine)
        {
            if (!collided)
                GetComponent<Rigidbody2D>().velocity = vel;
            lifespan -= Time.deltaTime;
            if (lifespan <= 0)
            {
                Kill(fallenSound);
                collided = true;
            }
            if (expired)
            {
                //  We have either gone too far, hit a player, or hit a wall
                soundTimer += Time.deltaTime;
                if (soundTimer > soundCooldown)
                {
                    PhotonNetwork.Destroy(gameObject);
                }
            }
            GetComponent<PhotonView>().RPC("SetKnife", PhotonTargets.Others, vel, transform.position, id);
        }
    }
    void OnCollisionEnter2D(Collision2D o)
    {
        Debug.Log(o.gameObject.tag);
        if (o.gameObject.tag == "Player" && lifespan < 3.9)
        {
            if(o.gameObject.GetInstanceID() == id)
            {
                return;
            }
            collided = true;
            o.gameObject.GetComponent<PhotonView>().RPC("Respawn", PhotonTargets.All);
            PhotonNetwork.Instantiate(killMarker.name, transform.position, Quaternion.Euler(0, 0, Random.Range(0, 360)), 0);
            if (GetComponent<PhotonView>().isMine)
                Kill(playerHitSound);
        }
        else if (o.gameObject.tag == "Wind")
        {


        }
        else {
            collided = true;
            //Embed self in object, stop moving.
            transform.position += transform.forward * 0.1f;
            Kill(blockHitSound);
        }
    }
    [PunRPC]
    void SetKnife(Vector3 vel, Vector3 pos, int owner)
    {
        id = owner;
        transform.position = pos;
        this.vel = vel;
    }
}
//=======
{'fraction_non_alphanumeric': 0.10275766445848097, 'fraction_numerical': 0.007702973347712217, 'mean_word_length': 1.9138240574506284, 'pattern_counts': {'":': 0, '<': 27, '<?xml version=': 0, '>': 25, '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': '6511374', 'n_tokens_mistral': 1899, 'n_tokens_neox': 1805, 'n_words': 409}