// Update is called once per frame
    void Update()
    {
        if (_isGrounded)
        {
            _jumps     = MaxJumps;
            _firstGrab = false;
        }
        _WS     = FindObjectOfType <WeaponStat>();
        _isAuto = _WS.IsAuto;

        if (Health <= 0)
        {
            Destroy(gameObject);
        }
        _isLeftWalled  = Physics2D.OverlapCircle(LeftWallPoint.position, 0.2f, WhatIsWall);
        _isRightWalled = Physics2D.OverlapCircle(RightWallPoint.position, 0.2f, WhatIsWall);

        Debug.Log(_canMove);
        if (_canRightWall && move.x > 0 && !_isGrounded)
        {
            _isRightWalled = true;
        }

        if (_canLeftWall && move.x < 0 && !_isGrounded)
        {
            _isLeftWalled = true;
        }

        HealthSlider.value = Health;
    }
    private void OnTriggerEnter2D(Collider2D collision)
    {
        if (!isAlive)
        {
            return;
        }
        removeOldHits();

        if (collision.gameObject.CompareTag("Bullet"))
        {
            int hash = collision.gameObject.GetHashCode();
            if (!recentlyHitBy.ContainsKey(hash))
            {
                WeaponStat weapon = collision.gameObject.GetComponent <WeaponStat>();
                health.reduceValue(weapon.damage);
                recentlyHitBy.Add(hash, Time.time);
                animator.SetTrigger("triggerDamage");
                StartCoroutine(flashRed());
            }
        }

        if (collision.gameObject.CompareTag("Player"))
        {
            if (player.isAlive)
            {
                //Vector2 enemyPosition = enemyCollider.transform.position;
                Vector2 playerDirection = (Vector2)transform.position - (Vector2)player.transform.position;
                Vector2 direction       = playerDirection / playerDirection.magnitude;
                playerRigidBody.AddForce(-direction * pushStrength);
                player.reduceHealth(damage);
            }
        }
    }
 public void InitBullet(WeaponStat stat, bool isCritical, bool hitPlayer)
 {
     stats[0].damage = isCritical ? stat.critDamage : stat.damage;
     //damage = isCritical ? stat.critDamage : stat.damage;
     SetProperty(EntityProperty.IsCritical, isCritical);
     collisionTags[1] = hitPlayer ? "Player" : "Enemy";
 }
 // Start is called before the first frame update
 void Start()
 {
     arrow    = FindObjectOfType <Arrow>();
     _dir     = arrow.dir;
     animator = GetComponent <Animator>();
     _WS      = FindObjectOfType <WeaponStat>();
 }
Example #5
0
 private void Update()
 {
     _WS = FindObjectOfType <WeaponStat>();
     if (Health <= 0)
     {
         Destroy(gameObject);
     }
     healthBar.SetHealth(Health);
 }
        private WeaponStat ReadWeaponStat(DbDataReader sqlReader)
        {
            WeaponStat weaponStat = new WeaponStat();

            weaponStat.Id       = sqlReader.GetInt32("id");
            weaponStat.WeaponId = sqlReader["weapon_id"].ToString();
            weaponStat.Level    = sqlReader["level"].ToString();
            weaponStat.BaseAtk  = sqlReader.GetInt32("base_atk");
            weaponStat.SubStat  = sqlReader.GetFloat("sub_stat");

            return(weaponStat);
        }
Example #7
0
    // Start is called before the first frame update
    void Start()
    {
        _rb2D = GetComponent <Rigidbody2D>();

        arrow = FindObjectOfType <Arrow>();

        Expl = FindObjectOfType <PhysicalExplosion>();

        _jumps      = MaxJumps;
        _canFire    = false;
        _isFiring   = false;
        colour      = sprite.color;
        _WS         = FindObjectOfType <WeaponStat>();
        _reloadTime = _WS.ReloadTime;
        _hangTime   = HangTimer;
    }
    // Update is called once per frame
    void FixedUpdate()
    {
        _WS = FindObjectOfType <WeaponStat>();

        if (_hitenemy)
        {
            maxRadius = Vector2.Distance(transform.position, hitEnemy.point);
        }
        else
        {
            maxRadius = _WS.WeaponRange;
        }

        Sound = _WS.Sound;

        BurstPart = _WS.BurstPart;

        Vector2 mousePosition = inputs.Player.Look.ReadValue <Vector2>();


        Vector2 pos = Camera.main.WorldToScreenPoint(transform.position);

        dir = (mousePosition - pos);
        dir.Normalize();



        angle = (Mathf.Atan2(dir.y, dir.x) * Mathf.Rad2Deg);
        transform.rotation = Quaternion.AngleAxis(angle, Vector3.forward);


        //_hitground = hitGround = Physics2D.Raycast(transform.position, dir, maxRadius, WhatIsGround);

        //_hitwall = hitWall = Physics2D.Raycast(transform.position, dir, maxRadius, WhatIsWall);


        line.SetPosition(1, new Vector3(maxRadius, 0, 0));


        if (assaultTime < AssaultTimer)
        {
            assaultTime += Time.deltaTime;
        }
    }
Example #9
0
 // Update is called once per frame
 void Update()
 {
     if (_isGrounded)
     {
         _jumps        = MaxJumps;
         _wallJumpTime = WallJumpTimer;
     }
     _WS     = FindObjectOfType <WeaponStat>();
     _isAuto = _WS.IsAuto;
     if (IsLeftWalled && _isJumping || IsRightWalled && _isJumping)
     {
         _canMove = false;
     }
     else
     {
         _canMove = true;
     }
     Debug.Log(_firingSingle);
     Debug.Log(_hangTime);
 }
Example #10
0
    //[ClientRpc]
    void RpcSwitchWeapon()
    {
        int i = -1;

        foreach (Transform weapon in transform)
        {
            if (i == currentWeaponIndex)
            {
                if (currentWeaponIndex != -1)
                {
                    weapon.gameObject.SetActive(true);
                    currentWeaponStats = weapon.gameObject.GetComponent <WeaponStat>();
                    weaponDisplays[i + 1].GetComponent <RectTransform>().localPosition = new Vector2(weaponDisplays[i + 1].GetComponent <RectTransform>().localPosition.x, 7);
                }
                else
                {
                    axe.SetActive(true);
                }
            }
            else
            {
                weapon.gameObject.SetActive(false);
            }

            if (i != -1)
            {
                weaponDisplays[i + 1].gameObject.SetActive(true);
                weaponDisplays[i + 1].transform.GetChild(0).GetComponent <Image>().sprite = weapon.GetComponent <WeaponStat>().img;
                //weaponDisplays[i+1].GetComponentInChildren<TextMeshProUGUI>().text = currentWeaponStats.ammo.ToString();
                if (i != currentWeaponIndex)
                {
                    weaponDisplays[i + 1].GetComponent <RectTransform>().localPosition = new Vector2(weaponDisplays[i + 1].GetComponent <RectTransform>().localPosition.x, 0);
                }
            }
            else
            {
            }

            i++;
        }
    }
    void Awake()
    {
        audioSource = GetComponent <AudioSource>();
        collider    = GetComponent <Collider2D>();
        rigid       = GetComponent <Rigidbody2D>();

        animator       = GetComponentInChildren <Animator>();
        camera         = GetComponentInChildren <Camera>();
        spriteRenderer = GetComponentInChildren <SpriteRenderer>();

        manager_UI = GameObject.Find("_Canvas").GetComponent <Manager_UI>();

        transform.tag = "Player";
        currentWeapon = weapons[0];

        if (!Application.isEditor)
        {
            Input.multiTouchEnabled = true;
            playingOnPC             = false;
        }
    }
    // Start is called before the first frame update
    void Start()
    {
        _rb2D = GetComponent <Rigidbody2D>();

        arrow = FindObjectOfType <Arrow>();

        Expl = FindObjectOfType <PhysicalExplosion>();

        _RV = FindObjectOfType <ReloadVisual>();

        _jumps                   = MaxJumps;
        _overheatStep            = 1;
        _overHeat                = 0;
        _canFire                 = false;
        _isFiring                = false;
        colour                   = sprite.color;
        _WS                      = FindObjectOfType <WeaponStat>();
        _reloadTime              = _WS.ReloadTime;
        _hangTime                = HangTimer;
        _ExplosionMultiplierRate = 0.9f;
        _wallJumpTime            = 0;
    }
    // Update is called once per frame
    void FixedUpdate()
    {
        _WS       = FindObjectOfType <WeaponStat>();
        maxRadius = _WS.WeaponRange;

        Vector2 mousePosition = inputs.Player.Look.ReadValue <Vector2>();


        Vector2 pos = Camera.main.WorldToScreenPoint(transform.position);

        dir = (mousePosition - pos);
        dir.Normalize();



        angle = (Mathf.Atan2(dir.y, dir.x) * Mathf.Rad2Deg);
        transform.rotation = Quaternion.AngleAxis(angle, Vector3.forward);

        _hitground = Physics2D.Raycast(transform.position, dir, maxRadius, WhatIsGround);
        _hit       = Physics2D.Raycast(transform.position, dir, maxRadius, WhatIsGround);

        Debug.DrawRay(transform.position, dir * maxRadius, Color.green);
    }
Example #14
0
    static bool ShowTextbox(TextboxTrigger trigger, DialogueBox textbox, GameObject textboxCanvas)
    {
        if (trigger)
        {
            Vector3 textboxPos = trigger.transform.position;
            switch (trigger.textboxType)
            {
            case TextboxType.None:
                return(false);    // NOTE: We never update the lastObj if the type is None

            case TextboxType.Dialogue:
            {
                textbox.ShowDialogue(null, "Press F to talk");
            } break;

            case TextboxType.Chest:
            {
                textbox.ShowDialogue(null, "Press F to open");
            } break;

            case TextboxType.Weapon:
            {
                WeaponStat stat = trigger.weapon.stat;
                System.Text.StringBuilder builder = new System.Text.StringBuilder();
                builder.Append("Damage: ").Append(stat.damage).Append("\nCritical: ").Append(stat.critDamage)
                .Append("\nFire rate:").Append(stat.fireRate).Append("\nPress F to change weapon");
                textbox.ShowDialogue("Name: " + stat.weaponName, builder.ToString());
                textboxPos = trigger.hitGroundPos;
            } break;
            }
            textboxCanvas.transform.position = textboxPos + (Vector3)trigger.textboxOffset;
        }

        textboxCanvas.SetActive(trigger);
        return(true);
    }
Example #15
0
 public int GetStrength(WeaponStat givenWeaponType)
 {
     return(m_strength[(int)givenWeaponType]);
 }
Example #16
0
    public static void OnPostprocessAllAssets(string[] importedAssets, string[] deletedAssets, string[] movedAssets, string[] movedFromAssetPaths)
    {
        foreach (string asset in importedAssets)
        {
            if (asset.EndsWith("Game_Weapons.csv"))
            {
                const string folderName = folder + "Weapon Stats/";
                EditorUtils.ReadAndProcessFile(asset, ',', folderName, stats =>
                {
                    WeaponStat weaponStat = AssetDatabase.LoadAssetAtPath <WeaponStat>(folderName + stats[(int)WeaponStats.Name] + ".asset");
                    weaponStat ??= ScriptableObject.CreateInstance <WeaponStat>();
                    bool[] isCorrect = new bool[(int)WeaponStats.StatCount];

                    isCorrect[(int)WeaponStats.Name]        = (weaponStat.weaponName = stats[(int)WeaponStats.Name]) != "";
                    isCorrect[(int)WeaponStats.Damage]      = int.TryParse(stats[(int)WeaponStats.Damage], out weaponStat.damage);
                    isCorrect[(int)WeaponStats.CritDamage]  = int.TryParse(stats[(int)WeaponStats.CritDamage], out weaponStat.critDamage);
                    isCorrect[(int)WeaponStats.CritChance]  = float.TryParse(stats[(int)WeaponStats.CritChance], out weaponStat.critChance);
                    isCorrect[(int)WeaponStats.FireRate]    = float.TryParse(stats[(int)WeaponStats.FireRate], out weaponStat.fireRate);
                    isCorrect[(int)WeaponStats.Mode]        = true; // We don't parse the fire mode anymore.
                    isCorrect[(int)WeaponStats.Ammo]        = int.TryParse(stats[(int)WeaponStats.Ammo], out weaponStat.ammo);
                    isCorrect[(int)WeaponStats.Knockback]   = float.TryParse(stats[(int)WeaponStats.Knockback], out weaponStat.knockback);
                    isCorrect[(int)WeaponStats.Price]       = int.TryParse(stats[(int)WeaponStats.Price], out weaponStat.price);
                    isCorrect[(int)WeaponStats.Standard]    = float.TryParse(stats[(int)WeaponStats.Standard], out weaponStat.standardReload);
                    isCorrect[(int)WeaponStats.Active]      = float.TryParse(stats[(int)WeaponStats.Active], out weaponStat.activeReload);
                    isCorrect[(int)WeaponStats.Perfect]     = float.TryParse(stats[(int)WeaponStats.Perfect], out weaponStat.perfectReload);
                    isCorrect[(int)WeaponStats.Failed]      = float.TryParse(stats[(int)WeaponStats.Failed], out weaponStat.failedReload);
                    isCorrect[(int)WeaponStats.Description] = (weaponStat.description = stats[(int)WeaponStats.Description]) != null;

                    for (int i = 0; i < isCorrect.Length; i++)
                    {
                        if (!isCorrect[i] && stats[i] != "")
                        {
                            Debug.LogWarning($"Can't convert {(WeaponStats)i} to {stats[i]} of {stats[(int)WeaponStats.Name]}");
                        }
                    }

                    return(weaponStat);
                }, weapon => weapon.weaponName);
            }
            else if (asset.EndsWith("Game_Dialogues.csv"))
            {
                string folderName = folder + "Dialogues/";
                EditorUtils.ReadAndProcessFile(asset, '*', folderName, data =>
                {
                    Dialogue dialogue = ScriptableObject.CreateInstance <Dialogue>();
                    Debug.Assert(data.Length == 3, data.Length); // (ID, speaker, and comma), (dialogues), (comma and responses)

                    string[] header = data[0].Split(',');
                    Debug.Assert(header.Length == 3, GameUtils.LoopThroughAndPrint(header));
                    dialogue.DialogueID = header[0];
                    dialogue.speaker    = header[1];

                    string[] sentences = data[1].Split(';');
                    dialogue.dialogues = sentences;

                    string[] responses = data[2].Split(',')[1].Split(';');
                    dialogue.responses = new Response[responses.Length];
                    for (int i = 0; i < responses.Length; i++)
                    {
                        string[] response     = responses[i].Split(':');
                        dialogue.responses[i] = new Response(response[i], i + 1 < response.Length ? response[i + 1] : null);
                    }

                    return(dialogue);
                }, dialogue => dialogue.DialogueID);
            }
        }
    }
 public static void SetStat(WeaponType weapon, WeaponStat stat, float value)
 {
     mWeaponStats [(int)weapon, (int)stat] = value;
 }
 public static float GetStat(WeaponType weapon, WeaponStat stat)
 {
     return mWeaponStats [(int)weapon, (int)stat];
 }
    public static GameObject LoadShip(string name, int id = 0, string prefabPath = null)
    {
        GameObject toBeReturn = new GameObject();

        StreamReader reader   = null;
        string       fileData = null;

        if (prefabPath == null)
        {
            reader = new StreamReader(Application.persistentDataPath + "/Save/Vessels_Save/" + name + ".json");

            if (reader == null)
            {
                throw new FileLoadException("Couldn't Load file");
            }

            fileData = reader.ReadToEnd();
            reader.Close();
        }
        else
        {
            TextAsset readerPart = Resources.Load <TextAsset>(prefabPath);
            fileData = readerPart.text;
        }

        JObject JSON_File_Root = JObject.Parse(fileData);

        toBeReturn.name = JSON_File_Root["name"].Value <string>();

        toBeReturn.tag = "Player";

        JArray datas = JSON_File_Root["parts"].Value <JArray>();

        TextAsset Stats     = Resources.Load <TextAsset>("Jsons/Weapon_Stats");
        string    statsData = Stats.text;

        var JSON_File_Stat = JObject.Parse(statsData);

        bool WeaponAdded = false;

        for (int j = 0; j < datas.Count; j++)
        {
            GameObject partHolder = new GameObject();
            partHolder.transform.SetParent(toBeReturn.transform);
            partHolder.name = datas[j]["name"].Value <string>();
            JArray subDatas = datas[j]["subParts"].Value <JArray>();
            for (int i = 0; i < subDatas.Count; i++)
            {
                GameObject part = Instantiate(Resources.Load <GameObject>(subDatas[i]["PrefabPath"].Value <string>()));
                part.name = subDatas[i]["name"].Value <string>();
                part.transform.position = new Vector3(subDatas[i]["offset_X"].Value <float>(), subDatas[i]["offset_Y"].Value <float>(), subDatas[i]["offset_Z"].Value <float>());
                part.transform.rotation = new Quaternion(subDatas[i]["rotation_X"].Value <float>(), subDatas[i]["rotation_Y"].Value <float>(), subDatas[i]["rotation_Z"].Value <float>(), subDatas[i]["rotation_W"].Value <float>());
                part.transform.SetParent(partHolder.transform);

                bool hasWeaponSpecific = false;

                if (subDatas[i]["moduleType"].Value <string>() == VesselsModulePartData.TypeOfModule.CentralHub.ToString())
                {
                    if (datas[j]["specificWeaponName"] != null)
                    {
                        hasWeaponSpecific = true;
                    }
                }

                if (subDatas[i]["moduleType"].Value <string>() == VesselsModulePartData.TypeOfModule.Weapon.ToString() || hasWeaponSpecific)
                {
                    if (!WeaponAdded)
                    {
                        toBeReturn.AddComponent <WeaponShootManager>();
                        if (id == 0)
                        {
                            toBeReturn.GetComponent <WeaponShootManager>().typeOfShip = Shoot.Origin.player;
                        }
                        else if (id == 1)
                        {
                            toBeReturn.GetComponent <WeaponShootManager>().typeOfShip = Shoot.Origin.ally;
                        }
                        else if (id == 2)
                        {
                            toBeReturn.GetComponent <WeaponShootManager>().typeOfShip = Shoot.Origin.enemy;
                        }
                        WeaponAdded = true;
                    }

                    JToken Find;
                    if (hasWeaponSpecific)
                    {
                        Find = JSON_File_Stat["uniqueIDReferencial"].Value <JArray>().Where(x => x.Value <string>() == datas[j]["specificWeaponName"].Value <string>()).Select(x => x.Value <JToken>()).First();
                    }
                    else
                    {
                        Find = JSON_File_Stat["uniqueIDReferencial"].Value <JArray>().Where(x => x.Value <string>() == subDatas[i]["name"].Value <string>()).Select(x => x.Value <JToken>()).First();
                    }

                    int index = JSON_File_Stat["uniqueIDReferencial"].Value <JArray>().IndexOf(Find);

                    WeaponStat temp = new WeaponStat(JSON_File_Stat["datas"][index].Value <JObject>(), null);

                    WeaponState newWS = null;
                    if (hasWeaponSpecific)
                    {
                        foreach (var item in part.transform.GetComponentsInChildren <Transform>())
                        {
                            if (item.name == datas[j]["specificWeaponName"].Value <string>())
                            {
                                newWS = item.gameObject.AddComponent <WeaponState>();
                                break;
                            }
                        }
                    }
                    else
                    {
                        newWS = part.AddComponent <WeaponState>();
                    }
                    newWS.canFire                = true;
                    newWS.fireRate               = 60 / temp.FireRate;
                    newWS.projectilePrefab       = Resources.Load <GameObject>(temp.projectilPrefabPath);
                    newWS.projectileImpactPrefab = Resources.Load <GameObject>(temp.projectilImpactPrefabPath);
                    newWS.timerSinceLastShot     = 0.0f;
                    newWS.speedShoot             = temp.speedShot;
                    newWS.parent = toBeReturn;
                    newWS.spawn  = part.transform.GetChild(0);
                    newWS.Range  = temp.range;
                    newWS.damage = temp.damage;
                    newWS.type   = temp.weaponType;
                    toBeReturn.GetComponent <WeaponShootManager>().AddWeaponState(newWS);
                    newWS.SetUpPool();
                }
            }
        }
        toBeReturn.GetComponent <WeaponShootManager>().lateStart();

        return(toBeReturn);
    }
Example #20
0
 // Start is called before the first frame update
 void Start()
 {
     _pm = FindObjectOfType <PlayerMovement>();
     _WS = FindObjectOfType <WeaponStat>();
 }
 // Update is called once per frame
 void Update()
 {
     _WS            = FindObjectOfType <WeaponStat>();
     animator.speed = 1 / _WS.ReloadTime;
 }
Example #22
0
 /// <summary>
 /// Returns the name of the given weapon stat, or null.
 /// </summary>
 /// <param name="stat">The weapon stat</param>
 /// <returns>The weapon stat name or null if it fails</returns>
 public static string GetName(this WeaponStat stat)
 {
     return(Enum.GetName(WeaponStatType, stat)?.ToUpper());
 }
Example #23
0
 public static float GetStat(WeaponType weapon, WeaponStat stat)
 {
     return(mWeaponStats [(int)weapon, (int)stat]);
 }
Example #24
0
 public static void SetStat(WeaponType weapon, WeaponStat stat, float value)
 {
     mWeaponStats [(int)weapon, (int)stat] = value;
 }
Example #25
0
    public virtual void Init(Creature creature, ItemWeaponData weaponData, RefMob.WeaponDesc weaponDesc)
    {
        m_creature = creature;
        m_gunPoint = creature.WeaponHolder.gameObject;
        m_refWeaponItem = weaponData.RefItem;

        m_lastCreated = Time.time;
        m_firing = false;
        m_level = 0;
        m_maxLevel = weaponDesc.maxLevel;

        m_weaponStat = new WeaponStat();
        if (weaponDesc.weaponStat == null)
        {
            m_weaponStat.OverrideStat(m_refWeaponItem.weaponStat);
        }
        else
        {
            m_weaponStat.OverrideStat(weaponDesc.weaponStat);
            m_weaponStat.OverrideStat(m_refWeaponItem.weaponStat);

        }

        for(int i = 0; i <= m_weaponStat.firingCount; ++i)
            MoreFire();

        m_evolution = weaponData.Evolution;

        if (m_evolution > 0)
        {
            for(int i = 1; i <= m_maxLevel; ++i)
            {
                if (canCreateMoreFire(i))
                    MoreFire();
            }
        }

        for(int i = 0; i < weaponData.Level; ++i)
            LevelUp();
    }