Example #1
0
    public Tesla_generic request_tsla()
    {
        if (tesla_pool.Count <= 0)
        {
            return(null);
        }

        Tesla_generic ret = tesla_pool[0];

        tesla_pool.RemoveAt(0);

        ret.gameObject.SetActive(true);
        ret.reset();
        return(ret);
    }
Example #2
0
 public void recycle_tsla(Tesla_generic tsla)
 {
     tesla_pool.Add(tsla);
     tsla.gameObject.SetActive(false);
 }
Example #3
0
    public void fire_tesla(GameObject activator, Vector2 fire_point, float blt_dir, bool hasAuthority, GameObject[] serialized_path, float lag_prediction = 0)
    {
        //Withdraw from pool
        Tesla_generic tesla = Pool_watcher.Singleton.request_tsla();

        //Get new ones
        if (tesla == null)
        {
            tesla = Instantiate(this.bullet, fire_point, Quaternion.identity).GetComponent <Tesla_generic>();
            tesla.pool_watcher     = Pool_watcher.Singleton;
            tesla.initial_hit_fltr = tesla.hit_fltr;
        }
        else
        {
            tesla.transform.position = fire_point;
        }

        tesla.aimdir = (new Vector2(Mathf.Cos(blt_dir * Mathf.PI / 180), Mathf.Sin(blt_dir * Mathf.PI / 180))).normalized;
        //tesla.GetComponent<TrailRenderer>().widthMultiplier = GetComponent<Gun_generic>().blt_mass / 20;

        tesla.local     = hasAuthority;
        tesla.activator = activator;

        //Remove hit collision for ally if server flag is off
        if (cvar_watcher.allyBulletPassThru)
        {
            tesla.hit_fltr.value = tesla.initial_hit_fltr.value - (1 << activator.GetComponent <Body_generic>().hitbox_main.gameObject.layer);
        }



        //If local, initialize the tesla path and use it, otherwise have network download the path from the local client
        if (hasAuthority && serialized_path == null)
        {
            serialized_path = fire_tesla_init(activator, fire_point, blt_dir, tesla.max_bounce_range, tesla.hit_fltr, tesla.obstacle_fltr);
        }

        //Spawn effect
        if (serialized_path == null)
        {
            return;
        }
        int num_trails = 0;

        for (int i = 0; i < serialized_path.Length; i++)
        {
            if (serialized_path[i] == null)
            {
                num_trails++;
            }
        }
        tesla.stream_path = new List <GameObject> [num_trails];
        int j = 0;

        for (int i = 0; i < serialized_path.Length; i++)
        {
            if (serialized_path[i] == null)
            {
                j++;
            }
            else
            {
                if (tesla.stream_path[j] == null)
                {
                    tesla.stream_path[j] = new List <GameObject>();
                }
                tesla.stream_path[j].Add(serialized_path[i]);
            }
        }

        tesla.emit();
    }