Example #1
0
    public void projectileHitAction(WeaponKind weapon, GameObject target, Vector3 position, Vector3 normal)
    {
        var hitTarget = target.GetComponent <Hitable>();
        var hitResult = new Hitable.HitResult(false, false);

        if (hitTarget != null)
        {
            var weaponDamage = weaponDamages[(int)weapon];
            hitResult = hitTarget.Hit(weaponDamage, position, normal);
        }

        if (!hitResult.soundPlayed)
        {
            if (projectileHitSound != null)
            {
                AudioSource.PlayClipAtPoint(projectileHitSound, position);
            }
        }

        if (!hitResult.effectShown)
        {
            var        rot             = Quaternion.FromToRotation(Vector3.right, normal);
            GameObject projectileClone = Instantiate(projectileHitEffect, position, rot);
        }
    }
Example #2
0
    public void ShootKnife(GameObject shooter, WeaponKind weapon, Vector3 source, Vector3 direction)
    {
        Debug.Log("Knife shot.");
        // melee weapon - hit all enemies in radius.
        var weaponDamage = weaponDamages[(int)weapon];

        var colliders = Physics2D.OverlapCircleAll(source, knifeRadius); //, hitablesMask);

        foreach (var collider in colliders)
        {
            var targetRadius = collider.bounds.size.x / 2;
            var dirToSource  = source - collider.transform.position;
            var hitPosition  = collider.transform.position + dirToSource.normalized * targetRadius;

            var hitTarget = collider.GetComponent <Hitable>();
            if (hitTarget == null)
            {
                Debug.LogWarning("Knife hit non-hittable: " + collider.gameObject.name);
                continue;
            }

            if (hitTarget.gameObject == shooter)
            {
                continue;
            }
            projectileHitAction(weapon, collider.gameObject, hitPosition, -dirToSource.normalized);
        }
    }
Example #3
0
 public void playReloadFailedSound(WeaponKind currentWeapon, Vector3 position)
 {
     if (reloadFailedSound != null)
     {
         AudioSource.PlayClipAtPoint(reloadFailedSound, position);
     }
 }
Example #4
0
 protected Weapon(string id, decimal price, double weight, int damage, WeaponTypes type, WeaponKind kind)
     : base(id, price, weight)
 {
     this.Damage = damage;
     this.WeaponType = type;
     this.WeaponKind = kind;
 }
Example #5
0
    public void ShootShotgun(WeaponKind weapon, Vector3 source, Vector3 direction)
    {
        // raycast weapon
        var rayCount = shotgunRayCount;

        for (var i = 0; i < rayCount; ++i)
        {
            var angleDiff = Random.Range(-shotgunSpreadAngle, shotgunSpreadAngle);
            var rayDir    = Quaternion.Euler(0, 0, angleDiff) * direction;
            var hit       = Physics2D.Raycast(source, rayDir, shotgunDistance);

            var hitPoint = source + rayDir * shotgunDistance;
            if (hit.collider != null)
            {
                hitPoint = hit.point;
                projectileHitAction(weapon, hit.collider.gameObject, hitPoint, -direction);
            }

            LineRenderer rayTrail    = Instantiate(shotgunShotTrail, transform);
            var          pointsCount = 30;
            var          points      = new Vector3[pointsCount];
            for (var p = 0; p < pointsCount; ++p)
            {
                var q     = 1.0f * p / (pointsCount - 1);
                var point = source * q + hitPoint * (1 - q);
                points[p] = point;
            }
            rayTrail.positionCount = points.Length;
            rayTrail.SetPositions(points);
            //rayTrail.SetPositions(new Vector3[] { source, hitPoint });
            Destroy(rayTrail.gameObject, shotgunShotTrailDuration);
        }
    }
Example #6
0
    private void WeaponListSetting(int num) //무기리스트를 파악하여 아이템리스트창에 정보를 채운다.
    {
        WeaponKind _temp = (WeaponKind)num;

        if (num == (int)WeaponKind.BaseWeapon)
        {
            if (baseWeaponKind == 3)
            {
                _temp = WeaponKind.BaseTWeapon;
            }
        }
        weaponListText = itemList[num].GetComponentsInChildren <Text>();

        ItemInfo _item = weaponList[_temp];

        weaponListText[0].text = _item.skillIncrease + "티어 " + _item.itemName;
        weaponListText[1].text = _item.kind;
        weaponListText[2].text = _item.grade;
        switch (_temp)
        {
        case WeaponKind.HAND_N:
            if (_item.skillIncrease == weaponMaxLevel.Hand_N)
            {
                ListDisable(num);
            }
            break;

        case WeaponKind.HAND_R:
            if (_item.skillIncrease == weaponMaxLevel.Hand_R)
            {
                ListDisable(num);
            }
            break;

        case WeaponKind.THAND_N:
            if (_item.skillIncrease == weaponMaxLevel.THand_N)
            {
                ListDisable(num);
            }
            break;

        case WeaponKind.THAND_R:
            if (_item.skillIncrease == weaponMaxLevel.THand_R)
            {
                ListDisable(num);
            }
            break;

        case WeaponKind.BaseWeapon:
            if (_item.skillIncrease == weaponMaxLevel.Dagger_N)
            {
                ListDisable(num);
            }
            break;
            //case WeaponKind.DAGGER_R:
            //    if (_item.skillIncrease == weaponMaxLevel.Dagger_R) ListDisable(num);
            //    break;
        }
    }
Example #7
0
    public void ShootRifle(WeaponKind weapon, Vector3 source, Vector3 direction)
    {
        // projectile weapon - shoot a projectile
        var         weaponProjectile = weaponProjectiles[(int)weapon];
        var         rot             = Quaternion.FromToRotation(Vector3.right, direction);
        Rigidbody2D projectileClone = Instantiate(weaponProjectile, source, rot).GetComponent <Rigidbody2D>();

        projectileClone.velocity = direction * bulletSpeed;

        // You can also access other components / scripts of the clone
        //projectileClone.GetComponent<Bullet>().isPlayerBullet = true;
    }
Example #8
0
 public WeaponSkill(string fullName, int baseChance, WeaponKind use, int maxRank, int minStength, int minDex)
 {
     ExceptionUtils.CheckArgumentNotNull(fullName);
     ExceptionUtils.MustBeTrue(baseChance >= 0 && baseChance <= 100);
     ExceptionUtils.MustBeTrue(maxRank >= 0 && maxRank <= 10);
     this.FullName = fullName;
     this.BaseChance = baseChance;
     this.Use = use;
     this.MaxRank = maxRank;
     this.PhysicalStengthRequired = minStength;
     this.ManualDexterityRequired = minDex;
 }
#pragma warning restore 649

    public Weapon GetObject(WeaponKind info)
    {
        if (!m_WeaponPoolKeyDict.TryGetValue(info, out var key))
        {
            return(null);
        }
        if (!ObjectPool.I.TrySpawn(key, out var obj))
        {
            return(null);
        }
        return(obj.GetComponent <Weapon>());
    }
Example #10
0
 public void NetSetSpectateWeapon(WeaponKind Kind)
 {
     GD.Print($"Set spectate weapon {Id}, {Kind}");
     if (Kind == WeaponKind.PISTOL)
     {
         Holder.EquipPistol();
     }
     else if (Kind == WeaponKind.AK)
     {
         Holder.EquipAk();
     }
     else if (Kind == WeaponKind.SHOTGUN)
     {
         Holder.EquipShotgun();
     }
 }
Example #11
0
    public void Shoot(GameObject shooter, WeaponKind weapon, Vector3 source, Vector3 direction)
    {
        var weaponShootSound = weaponShootSounds[(int)weapon];

        if (weaponShootSound != null)
        {
            AudioSource.PlayClipAtPoint(weaponShootSound, source);
        }

        switch (weapon)
        {
        case WeaponKind.Knife: ShootKnife(shooter, weapon, source, direction); break;

        case WeaponKind.Pistol: ShootRifle(weapon, source, direction); break;

        case WeaponKind.Rifle: ShootRifle(weapon, source, direction); break;

        case WeaponKind.Shotgun: ShootShotgun(weapon, source, direction); break;
        }
    }
Example #12
0
 protected Weapon(string id, decimal price, double weight, int damage, WeaponTypes type, WeaponKind kind)
     : base(id, price, weight)
 {
     this.Damage     = damage;
     this.WeaponType = type;
     this.WeaponKind = kind;
 }
Example #13
0
 protected void SetWeaponKind(WeaponKind kind)
 {
     this.weaponKind = kind;
     SetAmmoByKind();
 }
Example #14
0
    private void WeaponListSerch() //무기리스트중 없는 종류는 베이스 무기를 리스트에 넣어놓는다.
    {
        for (int i = 0; i < maxWeapon; i++)
        {
            WeaponKind _temp = (WeaponKind)i;
            if (weaponList.ContainsKey(_temp) == false)
            {
                switch (_temp)
                {
                case WeaponKind.HAND_N:
                    weaponList.Add((WeaponKind)i, CSVData.Instance.find(baseWeaponID.Hand_N));
                    break;

                case WeaponKind.HAND_R:
                    weaponList.Add((WeaponKind)i, CSVData.Instance.find(baseWeaponID.Hand_R));
                    if (!weaponList.ContainsKey(WeaponKind.BaseWeapon))
                    {
                        maxWeapon++; baseWeaponKind = 1;
                    }                                      //baseWeaponKind는 베이스 무기가 필요한 종류를 나눈것
                    break;

                case WeaponKind.THAND_N:
                    weaponList.Add((WeaponKind)i, CSVData.Instance.find(baseWeaponID.THand_N));
                    isTHandBase = true;
                    break;

                case WeaponKind.THAND_R:
                    weaponList.Add((WeaponKind)i, CSVData.Instance.find(baseWeaponID.THand_R));
                    if (!weaponList.ContainsKey(WeaponKind.BaseTWeapon) && !isTHandBase)
                    {
                        ++maxWeapon; if (maxWeapon < 6)
                        {
                            baseWeaponKind = 3;
                        }
                        else
                        {
                            baseWeaponKind = 2;
                        }
                    }
                    break;

                case WeaponKind.BaseWeapon:
                    switch (baseWeaponKind)
                    {
                    case 1:         // 1= 한손검만
                    case 2:         // 2 = 둘다
                        weaponList.Add((WeaponKind)i, CSVData.Instance.find(baseWeaponID.Hand_N));
                        break;
                    }
                    break;

                case WeaponKind.BaseTWeapon:
                    weaponList.Add((WeaponKind)i, CSVData.Instance.find(baseWeaponID.THand_N));
                    break;
                }
            }
        }
        if (maxWeapon == 5 && baseWeaponKind == 3)
        {
            weaponList.Add(WeaponKind.BaseTWeapon, CSVData.Instance.find(baseWeaponID.THand_N));
        }
    }
 public bool TryGetObject(WeaponKind info, out Weapon obj)
 {
     obj = GetObject(info);
     return(obj != null);
 }