예제 #1
0
    // Update is called once per frame
    void Update()
    {
        //Blood effect
        if (Client_watcher.Singleton != null && Client_watcher.Singleton.isServer)
        {
            if (Time.realtimeSinceStartup > time_to_spawn_blood)//Spawn bleed reference real time to increase effect accuracy in slow mo
            {
                time_to_spawn_blood = Time.realtimeSinceStartup + CONSTANTS.BLOOD_SPAWN_INTERVAL;
                if (bleedFX_obj_list.Count > 1)
                {
                    short[] pox = new short[bleedFX_pos_list.Count * 2];
                    short[] ang = new short[bleedFX_angle_list.Count];
                    for (int i = 0; i < bleedFX_pos_list.Count; i++)
                    {
                        pox[i] = (short)(bleedFX_pos_list[i].x * CONSTANTS.SYNC_POS_MUTIPLIER);
                        pox[bleedFX_pos_list.Count + i] = (short)(bleedFX_pos_list[i].y * CONSTANTS.SYNC_POS_MUTIPLIER);
                        ang[i] = CONSTANTS.seed_float_to_short(bleedFX_angle_list[i], 360);
                    }

                    Client_watcher.Singleton.Rpc_spawn_blood(bleedFX_obj_list.ToArray(), pox, ang, bleedFX_isHS_list.ToArray());
                }
                else if (bleedFX_obj_list.Count == 1)
                {
                    bleedFX_obj_list[0].GetComponent <Body_generic>().Rpc_bleed(bleedFX_pos_list[0], bleedFX_angle_list[0], bleedFX_isHS_list[0]);
                }
                bleedFX_obj_list.Clear();
                bleedFX_pos_list.Clear();
                bleedFX_angle_list.Clear();
                bleedFX_isHS_list.Clear();
            }
        }

        //Polygonal fluid effect
        if (particleSystems.Count == 0)
        {
            mesh.Clear();
            return;
        }
        List <Vector3> vertices_list  = new List <Vector3>();
        List <Color>   colors_list    = new List <Color>();
        List <int>     triangles_list = new List <int>();
        int            triangle_gap   = 0;
        int            reference      = 0;

        for (int x = 0; x < particleSystems.Count; x++)
        {
            ParticleSystem PS = particleSystems[x];
            if ((PS == null) || (!PS.isPlaying && PS.particleCount == 0))
            {
                particleSystems.RemoveAt(x);
                continue;
            }
            //draw
            if (PS.particleCount > 3)
            {
                //Debug.Log("burn");
                ParticleSystem.Particle[] particles = new ParticleSystem.Particle[PS.particleCount];
                PS.GetParticles(particles);

                //flame Fx

                int vertices_count = particles.Length;
                particles = particles.OrderBy(o => o.remainingLifetime).ToArray();

                for (int i = 0; i < vertices_count; i++)
                {
                    Color color = mesh_color;


                    float mean = 0;
                    if (i < particles.Length - 2)
                    {
                        mean = (Vector2.Distance(particles[i].position, particles[i + 1].position) + Vector2.Distance(particles[i].position, particles[i + 2].position) + Vector2.Distance(particles[i + 1].position, particles[i + 2].position)) / 3;
                    }
                    else if (i < particles.Length - 1)
                    {
                        mean = Vector2.Distance(particles[i].position, particles[i + 1].position);
                    }

                    color.a = (CONSTANTS.FLAME_TRI_STANDARD_DIST / mean) * particles[i].remainingLifetime / particles[i].startLifetime;
                    colors_list.Add(color);
                    Vector3 pos = particles[i].position;
                    pos.z = CONSTANTS.FX_Z;
                    vertices_list.Add(pos);
                }

                for (int i = 0; i < vertices_count - 2; i++)
                {
                    if (Mathf.Abs(particles[i].remainingLifetime - particles[i + 2].remainingLifetime) > merge_threshold)
                    {
                        triangles_list.Add(0 + triangle_gap);
                        triangles_list.Add(0 + triangle_gap);
                        triangles_list.Add(0 + triangle_gap);
                    }
                    else
                    {
                        triangles_list.Add(i + triangle_gap);
                        triangles_list.Add(i + 1 + triangle_gap);
                        triangles_list.Add(i + 2 + triangle_gap);
                        if (reference < i + 2 + triangle_gap)
                        {
                            reference = i + 2 + triangle_gap;
                        }
                    }
                }
                triangle_gap += vertices_count;
            }
        }
        mesh.Clear();
        mesh.vertices  = vertices_list.ToArray();
        mesh.triangles = triangles_list.ToArray();
        mesh.colors    = colors_list.ToArray();
        mesh.RecalculateNormals();
    }
예제 #2
0
    //This function will detect object collision
    //projectile will stop no matter what
    public void impact_object(GameObject obj, Vector2 hit_point)
    {
        float heat = Damage();

        if (obj.tag == "structure")//Structure
        {
            if (local && heat > 0)
            {
                Body_generic activator_body = activator.GetComponent <Body_generic>();
                if (activator_body.dmg_tags.Contains(obj.tag) && activator.layer != obj.layer)
                {
                    float angle = Mathf.Atan2(aimdir.y, aimdir.x) * 180 / Mathf.PI;
                    //If Client authoritates laser
                    if (activator_body.isPlayer && !activator_body.isServer)
                    {
                        activator_body.player_controller.add_to_shot_list(obj, heat, hit_point, 0, CONSTANTS.seed_float_to_short(angle, 360), false, 1);
                    }
                    else//Server client || npc authoritates laser
                    {
                        obj.GetComponent <Structure_generic>().health -= CONSTANTS.heat_to_physics(heat);
                    }
                    if (activator_body.isLocalPlayer)
                    {
                        activator_body.player_controller.hit_mark();
                    }
                }
            }
        }
        if (obj.GetComponent <Rigidbody2D>() != null)
        {
            Vector2 force = CONSTANTS.DAMAGE_FORCE_MULTIPLIER * (end - start).normalized * heat / 20;
            obj.GetComponent <Rigidbody2D>().AddForceAtPosition(force, hit_point);
        }
    }
예제 #3
0
    //This function will detect character collision and calculate damage
    //Return 1: keep the projectile going
    //Return 0: this object shouldn't be impacted
    //Return -1: this projectile is stopped by character
    public int impact_character(Body_hitbox_generic hit_box, Vector2 hit_point)
    {
        Body_generic body = hit_box.body;

        if (body.gameObject == activator)
        {
            return(-1);
        }
        if (local)
        {
            float heat_dmg = 0;
            float angle    = Mathf.Atan2(aimdir.y, aimdir.x) * 180 / Mathf.PI;
            if (activator.GetComponent <Body_generic>().dmg_tags.Contains(body.tag))
            {
                heat_dmg = Damage();
            }
            Vector2 force = CONSTANTS.DAMAGE_FORCE_MULTIPLIER * aimdir.normalized * heat_dmg / 20;

            //If Client authoritates laser
            if (activator.GetComponent <Body_generic>().isPlayer&& !activator.GetComponent <Body_generic>().isServer)
            {
                activator.GetComponent <Player_controller>().add_to_shot_list(body.gameObject, heat_dmg, hit_point, force.magnitude, CONSTANTS.seed_float_to_short(angle, 360), false, 1);
                body.GetComponent <Rigidbody2D>().AddForceAtPosition(force, hit_point);
            }
            else//Server client || npc authoritates laser
            {
                if (heat_dmg > 0)
                {
                    body.damage(activator, force, dmg_physics: CONSTANTS.heat_to_physics(heat_dmg), dmg_thermal: heat_dmg, headshot: false);
                    if (body.isPlayer && !body.hasAuthority)//Non-server client
                    {
                        body.request_bleed(hit_point, angle, false);
                        body.Rpc_add_force(force);
                    }
                    else//Host or npc
                    {
                        body.request_bleed(hit_point, angle, false);
                        body.GetComponent <Rigidbody2D>().AddForceAtPosition(force, hit_point);
                    }
                }
                //Friendly fire, just force
                else
                {
                    if (body.isPlayer && !body.hasAuthority)//Non-server client
                    {
                        body.Rpc_add_force(force);
                    }
                    else//Host or npc
                    {
                        body.GetComponent <Rigidbody2D>().AddForceAtPosition(force, hit_point);
                    }
                }
            }
        }
        return(-1);
    }
예제 #4
0
 public short get_bullet_seed_single(float aim_dir, float firecone)
 {
     return(CONSTANTS.seed_float_to_short(aim_dir + Random.Range(-precise - firecone, precise + firecone), 360));
 }
예제 #5
0
    public short get_aim_dir_short()
    {
        Vector2 aimdir = get_aim_vec();

        return(CONSTANTS.seed_float_to_short((Mathf.Atan2(aimdir.y, aimdir.x) * 180 / Mathf.PI), 360));
    }
예제 #6
0
    //This function will detect object collision
    //projectile will stop no matter what
    public void impact_object(GameObject obj, Vector2 hit_point)
    {
        if (obj.GetComponent <Rigidbody2D>() != null)
        {
            if (local)//If rigidbody, Exert force
            {
                obj.GetComponent <Rigidbody2D>().AddForceAtPosition(aimdir * speed * mass / 2, hit_point);
            }
        }
        if (obj.tag == "structure")//Structure
        {
            Body_generic activator_body = activator.GetComponent <Body_generic>();
            if (local && (activator == null || (activator_body.dmg_tags.Contains(obj.tag) && activator.layer != obj.layer)))//
            {
                float angle = Mathf.Atan2(aimdir.y, aimdir.x) * 180 / Mathf.PI;
                //If Client authoritates bullet
                if (activator != null && activator_body.isPlayer && !activator_body.isServer)
                {
                    activator_body.player_controller.add_to_shot_list(obj, Damage(), hit_point, 0, CONSTANTS.seed_float_to_short(angle, 360), false, 0);
                }
                else
                {
                    obj.GetComponent <Structure_generic>().health -= Damage();
                }
            }
        }
        if (spark != null && !isDedicated)
        {
            float angle = Mathf.Atan2(aimdir.y, aimdir.x) * 180 / Mathf.PI;
            Instantiate(spark, hit_point, Quaternion.Euler(0, 0, angle));
        }
        transform.position = hit_point;

        /*
         * if (local)
         * {
         *
         * }
         * else
         * {
         *  bulletRB.position = hit_point;//Avoid synctransform call
         * }
         */
        speed             = 0;
        time_of_collision = Time.realtimeSinceStartup;
    }