Example #1
0
 // Use this for initialization
 void Start()
 {
     cvar_watcher   = FindObjectOfType <Server_watcher>();
     equip          = GetComponent <Equipable_generic>();
     gameObject.tag = "pickup_gun";
     if (bullet != null && bullet.tag == "bullet_flame")
     {
         GameObject blt = Instantiate(bullet, Vector2.zero, Quaternion.identity);
         blt.GetComponent <Fluid_generic>().PS.transform.parent     = transform;
         blt.GetComponent <Fluid_generic>().PS.transform.position   = fire_point.position;
         blt.GetComponent <Fluid_generic>().PS.transform.rotation   = Quaternion.Euler(0, 0, transform.rotation.z - blt.GetComponent <Fluid_generic>().PS.shape.arc / 2);
         blt.GetComponent <Fluid_generic>().PS.transform.localScale = new Vector3(1, 1, 1);
         bullet = blt.GetComponent <Fluid_generic>().PS.gameObject;
         blt.GetComponent <Fluid_generic>().local = GetComponent <Equipable_generic>().isServer;
         blt.GetComponent <Fluid_generic>().DmgParticle_start_dmg *= thermal;
         blt.GetComponent <Fluid_generic>().DmgParticle_end_dmg   *= thermal;
     }
     if (isSemiAuto)
     {
         modes.Add(FireMode.Semi_auto);
     }
     if (isFullyAuto)
     {
         modes.Add(FireMode.Fully_auto);
     }
     for (int i = 0; i < modes.Count; i++)
     {
         if (modes[i] == firemode)
         {
             firemode_index = i;
             break;
         }
     }
 }
Example #2
0
    /// <summary>
    /// This function remove items from the cart and return resources
    /// </summary>
    /// <param name="item_idx"></param>
    public void SubPurchase_item_remove(byte item_idx)
    {
        Equipable_generic item = purchasables[item_idx].GetComponent <Equipable_generic>();

        buffer_money += item.price;
        buffer_inventory_capacity -= item.get_size();
        cart.Remove(item_idx);
        //Render
        Text_money.text = "$ " + buffer_money;
        if (item.tag == CONSTANTS.TAG_GUN)
        {
            //purchase_buttons[item_idx].colors = set_button_color(0);
        }
        else if (item.tag == CONSTANTS.TAG_AMMO)
        {
            purchase_buttons[item_idx].GetComponent <digit_mod_generic>().subtract(item.GetComponent <Ammo_generic>().amount);

            /*
             * if (!cart.Contains(item_idx))//If this ammo has reached zero, turn button unselected
             * {
             *  purchase_buttons[item_idx].colors = set_button_color(0);
             * }
             */
        }
        SubPurchase_item_refresh();
    }
Example #3
0
    /// <summary>
    /// This function evaluate if player has enough resources to purchase
    /// </summary>
    /// <param name="item_idx"></param>
    public void SubPurchase_item_add(byte item_idx)
    {
        Equipable_generic item = purchasables[item_idx].GetComponent <Equipable_generic>();
        ushort            available_inventory = (ushort)(buffer_inventory_size - buffer_inventory_capacity);
        ushort            item_size           = item.get_size();

        if (item.price <= buffer_money && item_size <= available_inventory && body.experience >= item.required_experience)
        {
            buffer_money -= item.price;
            buffer_inventory_capacity += item_size;
            cart.Add(item_idx);
            //Render
            Text_money.text = "$ " + buffer_money;
            //purchase_buttons[item_idx].colors = set_button_color(1);

            if (item.tag == CONSTANTS.TAG_AMMO)
            {
                purchase_buttons[item_idx].GetComponent <digit_mod_generic>().add(item.GetComponent <Ammo_generic>().amount);
            }
        }
        else
        {
            //Debug.Log("not enough resources");
        }
        SubPurchase_item_refresh();
    }
Example #4
0
    string print_debug_info(GameObject obj)
    {
        if (obj == null)
        {
            return("This object is NULL");
        }

        string            info = "";
        Equipable_generic item = obj.GetComponent <Equipable_generic>();
        Body_generic      body = obj.GetComponent <Body_generic>();

        if (item != null)
        {
            info += "Item: " + obj.name + "\nUser: "******"\nFaded: " + item.fade + "\n";
            Gun_generic  gun  = obj.GetComponent <Gun_generic>();
            Ammo_generic ammo = obj.GetComponent <Ammo_generic>();
            if (gun != null)
            {
                info += "Ammo: " + gun.ammo + "\n";
            }
            else if (ammo != null)
            {
                info += "Amount: " + ammo.amount + "\n";
            }
        }
        else if (body != null)
        {
            if (body.isPlayer)
            {
                info += "\nPlayer: " + obj.name;
                info += "\nEquiped: " + obj.GetComponent <Player_controller>().equiped_item;
            }
            else
            {
                info += "\nNPC: " + obj.name;
                info += "\nEquiped: " + obj.GetComponent <AI_generic>().equiped_item;
            }
            info += "\nHealth: " + body.health + "/" + body.max_health;
            info += "\nReload * " + body.reload_multiplier;
            info += "\nStress # " + body.stress_resistent;
            info += "\nStrength: " + body.strength;
            info += "\nSpeed: " + body.speed_run;
            info += "\nAim: " + body.aim_suppress;
            if (isServer)
            {
                info += "\nServer-sided Var---------------";
                info += "\nExperience # " + body.experience;
                info += "\nSPs # " + body.skill_points;
                info += "\nPhysical Resiliance # " + body.physical_resilience;
            }
        }

        return(info);
    }
Example #5
0
    //This function causes event on server and then ask everyone to spawn the effect
    public void server_shoot(GameObject gun_user, short fire_point_x, short fire_point_y, short aim_dir_short, sbyte[] blt_dir, bool dry_gun)
    {
        //GameObject user = GetComponent<Equipable_generic>().user;
        if (equip == null)
        {
            equip = GetComponent <Equipable_generic>();
        }
        if (equip.loaded != !dry_gun)//If called everytime, hook will update regardless if value changes
        {
            equip.loaded = !dry_gun;
        }

        //attract npc
        sound_watcher.summon_listener(transform.position, noise_dist, gun_user.layer);
        //If precomputed, dont spawn projectiles because they have been spawned via other means.
        if (Local_precomputation)
        {
            return;
        }
        //Spawn projectiles effects across all clients
        if (gun_user.GetComponent <Body_generic>().isPlayer)
        {
            if (blt_dir == null)// burst_shots == 1)
            {
                gun_user.GetComponent <Player_controller>().Rpc_client_shoot_optimized_single(fire_point_x, fire_point_y, aim_dir_short);
            }
            else// if(burst_shots >= 2)
            {
                gun_user.GetComponent <Player_controller>().Rpc_client_shoot_optimized(fire_point_x, fire_point_y, aim_dir_short, blt_dir);
            }


            //Simulate server-sided projectile on dedicated server
            if (cvar_watcher.isDedicated())
            {
                shoot(gun_user, fire_point_x, fire_point_y, aim_dir_short, blt_dir);
            }
        }
        else
        {
            if (blt_dir == null)//burst_shots == 1)
            {
                gun_user.GetComponent <AI_generic>().Rpc_client_shoot_optimized_single(fire_point_x, fire_point_y, aim_dir_short);
            }
            else// if(burst_shots >= 2)
            {
                gun_user.GetComponent <AI_generic>().Rpc_client_shoot_optimized(fire_point_x, fire_point_y, aim_dir_short, blt_dir);
            }
        }
    }
Example #6
0
 public void SubPurchase_item_refresh()
 {
     for (int i = 0; i < purchasables.Length; i++)
     {
         Equipable_generic item = purchasables[i].GetComponent <Equipable_generic>();
         if (cart.Contains((byte)i))//selected
         {
             purchase_buttons[i].colors = set_button_color(1);
         }
         else if (item.get_size() > buffer_inventory_size || item.price > buffer_money || item.required_experience > body.experience)//disable
         {
             purchase_buttons[i].colors = set_button_color(2);
         }
         else//unselected
         {
             purchase_buttons[i].colors = set_button_color(0);
         }
     }
 }
Example #7
0
    // Update is called once per frame
    void Update()
    {
        //Cursor
        if (cursor != null)
        {
            if (controller.equiped_item == null)
            {
                cursor_size = -1;
            }
            else
            {
                if (controller.equiped_item.tag == "pickup_ammo")
                {
                    cursor_size = -1;
                }
                else if (controller.equiped_item.tag == "pickup_grenade")
                {
                    cursor_size = -1;
                }
                else if (controller.equiped_item.tag == "pickup_gun")
                {
                    Gun_generic gun      = controller.equiped_item.GetComponent <Gun_generic>();
                    float       firecone = (gun.firecone_angle + gun.precise) * Mathf.PI / 180;
                    if (firecone != 90)
                    {
                        cursor_size = Mathf.Tan(firecone) * Vector2.Distance(controller.mousepos, transform.position);//controller.playerRB.position);
                    }
                    else
                    {
                        cursor_size = 0;
                    }
                }
            }
            cursor_anim.SetFloat(CONSTANTS.ANIM_PARAM_CURSOR_SIZE, cursor_size);
            if (cursor_size == -1)
            {
                Cursor.visible = true;
                //cursor.transform.localScale = new Vector3(0, 0, 0);
            }
            else
            {
                Cursor.visible              = false;
                cursor.transform.rotation   = main_camera.transform.rotation;
                cursor.transform.localScale = new Vector3(1, 1, 1);
                cursor.transform.position   = new Vector3(controller.mousepos.x, controller.mousepos.y, cursor.transform.position.z);
                float cam_cursor_scale = main_camera.orthographicSize / 10;

                cursor_l.localScale         = new Vector3(0.3f * cam_cursor_scale, 0.03f * cam_cursor_scale, 1);
                cursor_r.localScale         = new Vector3(0.3f * cam_cursor_scale, 0.03f * cam_cursor_scale, 1);
                cursor_u.localScale         = new Vector3(0.3f * cam_cursor_scale, 0.03f * cam_cursor_scale, 1);
                cursor_d.localScale         = new Vector3(0.3f * cam_cursor_scale, 0.03f * cam_cursor_scale, 1);
                cursor_marker_se.localScale = new Vector3(0.3f * cam_cursor_scale, 0.03f * cam_cursor_scale, 1);
                cursor_marker_sw.localScale = new Vector3(0.3f * cam_cursor_scale, 0.03f * cam_cursor_scale, 1);
                cursor_marker_ne.localScale = new Vector3(0.3f * cam_cursor_scale, 0.03f * cam_cursor_scale, 1);
                cursor_marker_nw.localScale = new Vector3(0.3f * cam_cursor_scale, 0.03f * cam_cursor_scale, 1);
            }
        }



        //Follow camera
        //HUD_camera.GetComponent<Camera>().orthographicSize = main_camera.orthographicSize;
        float cam_scale = main_camera.orthographicSize / 5;

        //HUD.localScale = new Vector3(cam_scale, cam_scale, 1);

        //Health state effect & Damage flash screen
        overlay.color = new Color(Mathf.Clamp01(overlay.color.r - overlay_update_factor), Mathf.Clamp01(overlay.color.g - overlay_update_factor), Mathf.Clamp01(overlay.color.b - overlay_update_factor));

        if (controller.reloading)
        {
            icon_field.color = Color.red;
        }
        else
        {
            icon_field.color = Color.white;
        }

        //Turn on/off icon and ammo
        if (controller.equiped_item != null)
        {
            equip = controller.equiped_item.GetComponent <Equipable_generic>();
            icon_field.enabled = true;
            ammo_field.enabled = true;
        }
        else
        {
            equip = null;
            icon_field.enabled = false;
            ammo_field.enabled = false;
        }

        //Write to icon and ammo
        if (equip != null)
        {
            int ammo_num = 0;
            if (equip.item_type == Equipable_generic.ITEM_TYPE.gun)
            {
                ammo_num = equip.GetComponent <Gun_generic>().ammo;
            }
            else if (equip.item_type == Equipable_generic.ITEM_TYPE.ammo)
            {
                ammo_num = equip.GetComponent <Ammo_generic>().amount;
            }
            else if (equip.item_type == Equipable_generic.ITEM_TYPE.grenade)
            {
                ammo_num = equip.GetComponent <Grenade_generic>().ammo;
            }

            /*
             * if(equip.GetComponent<Equipable_generic>().hud_icon_anim != null)
             * {
             *  icon_field_anim.runtimeAnimatorController = equip.GetComponent<Equipable_generic>().hud_icon_anim;
             *  icon_field.sprite = null;
             * }
             * else */if (equip.hud_icon != null)
            {
                icon_field.sprite = equip.hud_icon;
                icon_field_anim.runtimeAnimatorController = null;
            }
            else
            {
                icon_field.sprite = missing_texture;
                icon_field_anim.runtimeAnimatorController = null;
            }
            ammo_field.text = ammo_num.ToString();
        }
        else
        {
            icon_field_anim.runtimeAnimatorController = null;
        }
    }
Example #8
0
    //This function simulate bullets locally
    public void shoot(GameObject gun_user, short fire_point_x, short fire_point_y, short aim_dir, sbyte[] aim_dir_offset, float lag_prediction = 0)
    {
        Vector2 fire_point = new Vector2(fire_point_x / CONSTANTS.SYNC_POS_MUTIPLIER, fire_point_y / CONSTANTS.SYNC_POS_MUTIPLIER);

        Body_generic user_body = gun_user.GetComponent <Body_generic>();

        if (equip == null)
        {
            equip = GetComponent <Equipable_generic>();
        }
        bool hasAuthority = equip.isServer;

        if (!cvar_watcher.isDedicated() && !Local_precomputation)
        {
            spawn_muzzle();
        }                                                                            //Only spawn muzzle on clients

        float aim_dir_float = CONSTANTS.seed_short_to_float(aim_dir, 360);

        float firecone_maxrange = accuracy + precise;

        if (bullet.tag == "bullet")//Shooting bullet is local authoritative, meaning shooter decides if he hits
        {
            if (aim_dir_offset == null)
            {
                fire_bullet(gun_user, fire_point, aim_dir_float, local_player_protocol(user_body), lag_prediction);
            }
            else
            {
                for (int i = 0; i < aim_dir_offset.Length; i++)
                {
                    float blt_dir = aim_dir_float + CONSTANTS.seed_sbyte_to_float(aim_dir_offset[i], firecone_maxrange);
                    fire_bullet(gun_user, fire_point, blt_dir, local_player_protocol(user_body), lag_prediction);
                }
            }
        }
        else if (bullet.tag == "bullet_laser")//Shooting laser is local authoritative, meaning shooter decides if he hits
        {
            if (aim_dir_offset == null)
            {
                fire_laser(gun_user, fire_point, aim_dir_float, local_player_protocol(user_body));
            }
            else
            {
                for (int i = 0; i < aim_dir_offset.Length; i++)
                {
                    float blt_dir = aim_dir_float + CONSTANTS.seed_sbyte_to_float(aim_dir_offset[i], firecone_maxrange);
                    fire_laser(gun_user, fire_point, blt_dir, local_player_protocol(user_body));
                }
            }
        }
        else if (bullet.tag == "bullet_rocket")//Shooting rocket is server authoritative, meaning server decides if he hits
        {
            if (hasAuthority)
            {
                if (aim_dir_offset == null)
                {
                    fire_rocket(gun_user, fire_point, aim_dir_float, hasAuthority);
                }
                else
                {
                    for (int i = 0; i < aim_dir_offset.Length; i++)
                    {
                        float blt_dir = aim_dir_float + CONSTANTS.seed_sbyte_to_float(aim_dir_offset[i], firecone_maxrange);
                        fire_rocket(gun_user, fire_point, blt_dir, hasAuthority);
                    }
                }
            }
        }
        if (bullet.tag == "bullet_tesla")//This function only runs on local. local simulate path, broadcast path and damage to network
        {
            fire_tesla(gun_user, fire_point, aim_dir_float, local_player_protocol(user_body), null, lag_prediction);
        }
        else if (bullet.tag == "bullet_flame")//Shooting bullet is server authoritative, meaning server decides if he hits
        {
            float blt_dir = aim_dir_float + CONSTANTS.seed_sbyte_to_float(aim_dir_offset[0], firecone_maxrange);
            bullet.transform.rotation = Quaternion.Euler(0, 0, blt_dir - bullet.GetComponent <ParticleSystem>().shape.arc / 2);
            bullet.GetComponent <ParticleSystem>().Emit(burst_shots);
        }
    }