Exemple #1
0
    protected void SetWeaponSpeed(WeaponNameType weaponName)
    {
        float speed = -1;
        int   level = GetWeaponLevel(weaponName);

        if (level > 0)
        {
            if (Constant.WEAPON_SPEED_RATE.ContainsKey(weaponName) &&
                Constant.WEAPON_SPEED_RATE[weaponName].Count >= level)
            {
                speed = Constant.WEAPON_SPEED_RATE[weaponName][level - 1];
            }
        }
        if (speed >= 0)
        {
            if (d_WeaponSpeed.ContainsKey(weaponName))
            {
                d_WeaponSpeed[weaponName] = speed;
            }
            else
            {
                d_WeaponSpeed.Add(weaponName, speed);
            }
        }
    }
Exemple #2
0
    public void AddWeaponEnergy(float delta, WeaponNameType weaponName)
    {
        float curEnergy = GetWeaponEnergy(weaponName);

        curEnergy = curEnergy < 0 ? 0 : curEnergy;
        SetWeaponEnergy(delta + curEnergy, weaponName);
    }
Exemple #3
0
 public void OnRollEnd()
 {
     canControl  = true;
     rollDir     = Vector2.zero;
     inRollState = false;
     // 改变Player朝向
     faceDirection = stickLDirection;
     // 重启enemyCollider与playerCollider的碰撞
     if (!I_Manager.IsDead())
     {
         int enemyCollider  = LayerMask.NameToLayer("Enemy");
         int playerCollider = LayerMask.NameToLayer("Player");
         Physics.IgnoreLayerCollision(playerCollider, enemyCollider, false);
     }
     // 是否需要切换武器
     if (nextWeaponName != WeaponNameType.unknown)
     {
         PlayerData.Instance.curWeaponName = nextWeaponName;
         nextWeaponName = WeaponNameType.unknown;
         ChangeWeapon();
     }
     // 是否需要Reload
     if (curWeaponType == WeaponType.autoDistant || curWeaponType == WeaponType.singleLoader)
     {
         int bullets = PlayerData.Instance.GetCurLeftBullets();
         if (bullets <= 0)
         {
             ((DistantWeaponManager)I_Manager.I_WeaponManager).Reload();
         }
     }
 }
Exemple #4
0
    public void SetWeaponEnergy(float energy, WeaponNameType weaponName)
    {
        energy = energy < 0 ? 0 : energy;
        float maxEnergy = -1;

        if (Constant.MAX_WEAPON_ENERGY.ContainsKey(weaponName))
        {
            List <float> energyList = Constant.MAX_WEAPON_ENERGY[weaponName];
            maxEnergy = energyList[energyList.Count - 1];
        }
        if (maxEnergy < 0)
        {
            return;
        }
        energy = energy < maxEnergy ? energy : maxEnergy;
        if (d_WeaponEnergy.ContainsKey(weaponName))
        {
            d_WeaponEnergy[weaponName] = energy;
        }
        else if (weaponName != WeaponNameType.unknown)
        {
            d_WeaponEnergy.Add(weaponName, energy);
        }
        SetWeaponLevel(weaponName);
        SetWeaponLeftEnergy(weaponName);
        SetWeaponEnergyGap(weaponName);
        SetWeaponSpeed(weaponName);
    }
Exemple #5
0
    public void Init(Transform enemy, WeaponNameType curWeaponName, float enemyMaxHealth, Dictionary <WeaponNameType, Transform> d_EnemyWeapons, Dictionary <WeaponNameType, Transform> d_EnemyBodys)
    {
        base.Init();
        if (enemy)
        {
            this.target = enemy;
            isPlayer    = false;
            Transform leg = null;
            leg          = enemy.Find("Leg");
            legTransform = leg;
        }

        foreach (var weapon in d_EnemyWeapons)
        {
            AddToWeapons(weapon.Key, weapon.Value);
        }

        foreach (var body in d_EnemyBodys)
        {
            AddToBodys(body.Key, body.Value);
        }
        maxHealth          = enemyMaxHealth;
        curHealth          = enemyMaxHealth;
        this.curWeaponName = curWeaponName;
    }
Exemple #6
0
    public void Init(Transform player, WeaponNameType curWeaponName, float playerMaxHealth, Dictionary <WeaponNameType, Transform> d_PlayerWeapons, Dictionary <WeaponNameType, Transform> d_PlayerBodys)
    {
        base.Init();
        if (player)
        {
            this.target = player;
            isPlayer    = true;
            Transform leg = null;
            leg          = player.Find("Leg");
            legTransform = leg;
        }

        foreach (var body in d_PlayerWeapons)
        {
            AddToWeapons(body.Key, body.Value);
        }

        foreach (var body in d_PlayerBodys)
        {
            AddToBodys(body.Key, body.Value);
        }
        maxHealth          = playerMaxHealth;
        curHealth          = playerMaxHealth;
        this.curWeaponName = curWeaponName;
    }
Exemple #7
0
 public Transform GetBodyTransformByName(WeaponNameType weaponName)
 {
     if (d_Bodys.ContainsKey(weaponName))
     {
         return(d_Bodys[weaponName]);
     }
     return(null);
 }
Exemple #8
0
 public static float GetBaseDamage(WeaponNameType weaponName)
 {
     if (BaseDamage.ContainsKey(weaponName))
     {
         return(BaseDamage[weaponName]);
     }
     return(-1);
 }
    /*-------------------- FocusTargetsChangeEvent --------------------*/

    /*-------------------- DeadNotifyEvent --------------------*/
    protected override void DeadNotifyEventFunc(Transform killer, Transform dead, WeaponNameType weaponName)
    {
        base.DeadNotifyEventFunc(killer, dead, weaponName);
        if (preFocusTarget == dead)
        {
            I_PlayerManager.I_PlayerController.SetFocusTarget(null);
            preFocusTarget = null;
        }
    }
    protected virtual void CreateBullet(Transform shooter, WeaponNameType weaponName)
    {
        Vector3          firePos            = muzzle.position;
        Transform        I_Bullet           = Instantiate(bullet, firePos, body.rotation);
        BulletController I_BulletController = I_Bullet.GetComponent <BulletController>();
        bool             canPenetrate       = Utils.CanBulletPenetrate(weaponName, GetWeaponLevel(weaponName));

        I_BulletController.Init(shooter, damage, bulletSpeed, canPenetrate);
    }
Exemple #11
0
    public int GetLeftBulletsByName(WeaponNameType weaponName)
    {
        int count = -1;

        if (d_LeftBullets.ContainsKey(weaponName))
        {
            count = d_LeftBullets[weaponName];
        }
        return(count);
    }
Exemple #12
0
    public float GetWeaponSpeed(WeaponNameType weaponName)
    {
        float speed = -1;

        if (d_WeaponSpeed.ContainsKey(weaponName))
        {
            speed = d_WeaponSpeed[weaponName];
        }
        return(speed);
    }
Exemple #13
0
    public float GetWeaponLeftEnergy(WeaponNameType weaponName)
    {
        float leftEnergy = -1;

        if (d_WeaponLeftEnergy.ContainsKey(weaponName))
        {
            leftEnergy = d_WeaponLeftEnergy[weaponName];
        }
        return(leftEnergy);
    }
Exemple #14
0
    public int GetWeaponLevel(WeaponNameType weaponName)
    {
        int level = -1;

        if (d_WeaponLevel.ContainsKey(weaponName))
        {
            level = d_WeaponLevel[weaponName];
        }
        return(level);
    }
Exemple #15
0
    public float GetWeaponEnergy(WeaponNameType weaponName)
    {
        float energy = -1;

        if (d_WeaponEnergy.ContainsKey(weaponName))
        {
            energy = d_WeaponEnergy[weaponName];
        }
        return(energy);
    }
Exemple #16
0
    public float GetWeaponEnergyGap(WeaponNameType weaponName)
    {
        float gap = -1;

        if (d_WeaponEnergyGap.ContainsKey(weaponName))
        {
            gap = d_WeaponEnergyGap[weaponName];
        }
        return(gap);
    }
Exemple #17
0
 public void AddToBodys(WeaponNameType weaponName, Transform body)
 {
     if (d_Bodys.ContainsKey(weaponName))
     {
         d_Bodys[weaponName] = body;
     }
     else
     {
         d_Bodys.Add(weaponName, body);
     }
 }
Exemple #18
0
 void ShowRangeTriangleEventFunc(WeaponNameType weaponName, bool show)
 {
     if (weaponName == this.weaponName)
     {
         if (show)
         {
             UpdateRangeTriangle();
         }
         I_AimController.SetVisible(show);
     }
 }
Exemple #19
0
    /*------------------ FocusTargetsChangeEvent -------------------*/

    /*---------------------- DeadNotifyEvent ----------------------*/
    void DeadNotifyEventFunc(Transform killer, Transform dead, WeaponNameType weapon)
    {
        if (PlayerData.Instance.isDead)
        {
            DifficultyPanel.gameObject.SetActive(false);
            ResultPanel.gameObject.SetActive(true);
            ScoreText.enabled      = false;
            MaxText.enabled        = false;
            DifficultyText.enabled = false;
        }
    }
Exemple #20
0
 public void AddToWeapons(WeaponNameType weaponName, Transform weapon)
 {
     if (d_Weapons.ContainsKey(weaponName))
     {
         d_Weapons[weaponName] = weapon;
     }
     else
     {
         d_Weapons.Add(weaponName, weapon);
     }
 }
Exemple #21
0
    public void AddEnemyData(Transform enemy, WeaponNameType curWeaponName, float enemyMaxHealth, Dictionary <WeaponNameType, Transform> d_EnemyWeapons, Dictionary <WeaponNameType, Transform> d_EnemyBodys)
    {
        if (d_EnemysData.ContainsKey(enemy))
        {
            d_EnemysData.Remove(enemy);
        }
        EnemyData enemyData = new EnemyData();

        enemyData.Init(enemy, curWeaponName, enemyMaxHealth, d_EnemyWeapons, d_EnemyBodys);
        d_EnemysData.Add(enemy, enemyData);
    }
Exemple #22
0
    public static bool CanBulletPenetrate(WeaponNameType weaponName, int weaponLevel)
    {
        bool canPenetrate = false;

        if (Constant.BULLET_PENETRATE_LEVEL.ContainsKey(weaponName))
        {
            int penetrateLevel = Constant.BULLET_PENETRATE_LEVEL[weaponName];
            canPenetrate = weaponLevel >= penetrateLevel;
        }
        return(canPenetrate);
    }
Exemple #23
0
    void SetUi(WeaponNameType weaponName)
    {
        // 设置图像
        if (d_WeaponImages.ContainsKey(weaponName))
        {
            I_Image.sprite = d_WeaponImages[curWeaponNameOnBtn];
        }
        // 设置子弹数是否可见
        WeaponType weaponType = Utils.GetWeaponTypeByName(weaponName);

        I_BulletNumber.gameObject.SetActive(weaponType != WeaponType.melee);
    }
Exemple #24
0
 public static float GetWeaponDamageRate(Transform gamer, WeaponNameType weaponName)
 {
     if (Constant.WEAPON_DAMAGE_RATE.ContainsKey(weaponName))
     {
         int level = Utils.GetBaseData(gamer).curWeaponLevel;
         if (Constant.WEAPON_DAMAGE_RATE[weaponName].Count >= level)
         {
             return(Constant.WEAPON_DAMAGE_RATE[weaponName][level - 1]);
         }
     }
     return(-1);
 }
Exemple #25
0
    protected static void HurtDeal(Transform attacker, List <Transform> suffers)
    {
        var            attackerData  = Utils.GetBaseData(attacker);
        WeaponNameType atkWeaponName = WeaponNameType.unknown;

        if (attackerData != null)
        {
            atkWeaponName = attackerData.curWeaponName;
        }
        float damage     = Constant.GetBaseDamage(atkWeaponName);
        float damageRate = 0;

        if (attacker == PlayerData.Instance.target)
        {
            damageRate = Utils.GetWeaponDamageRate(attacker, atkWeaponName) / GlobalData.diffRate;
        }
        else
        {
            damageRate = Utils.GetWeaponDamageRate(attacker, atkWeaponName);
        }
        if (damageRate >= 0)
        {
            damage *= damageRate;
        }
        if (damage < 0)
        {
            return;
        }
        foreach (Transform suffer in suffers)
        {
            var   sufferData = Utils.GetBaseData(suffer);
            float trueDamage = Mathf.Min(damage, sufferData.curHealth);
            bool  isDead     = GamerHurt(suffer, damage);
            if (isDead)
            {
                sufferData.isDead = true;
                if (!sufferData.isPlayer)
                {
                    SetGlobalInfo(suffer);
                    NewEnemy(suffer);
                }
                if (DeadNotifyEvent != null)
                {
                    DeadNotifyEvent(attacker, suffer, attacker.GetComponent <Manager>().GetCurWeaponName());
                }
            }
            // 武器能量改变
            WeaponEnergyChangeDeal(attacker, suffers, damage);
            // Player生命回复
            PlayerHealthRestoreDeal(attacker, trueDamage);
        }
    }
Exemple #26
0
    public static float GetWeaponStrengthRestoreRate(WeaponNameType weaponName, int weaponLevel)
    {
        float rate = 0;

        if (Constant.WEAPON_STRENGTH_RESTORE_RATE.ContainsKey(weaponName))
        {
            if (Constant.WEAPON_STRENGTH_RESTORE_RATE[weaponName].Count >= weaponLevel)
            {
                rate = Constant.WEAPON_STRENGTH_RESTORE_RATE[weaponName][weaponLevel - 1];
            }
        }
        return(rate);
    }
Exemple #27
0
    bool HasEnemyInRange(Vector2 direction, ref Transform target)
    {
        float          maxDist       = 30;
        WeaponNameType curWeaponName = PlayerData.Instance.curWeaponName;

        if (Constant.AimMaxDist.ContainsKey(curWeaponName))
        {
            maxDist = Constant.AimMaxDist[curWeaponName];
        }
        Transform player         = PlayerData.Instance.target;
        LayerMask enemyLayerMask = LayerMask.GetMask("Enemy");

        Collider[] hitColliders = null;
        hitColliders = Physics.OverlapSphere(player.position, maxDist, enemyLayerMask);
        // 检测是否被墙格挡 是否在瞄准范围内
        if (hitColliders != null)
        {
            // 从近到远排序
            if (hitColliders.Length > 1)
            {
                for (int i = 0; i < hitColliders.Length; i++)
                {
                    for (int j = i + 1; j < hitColliders.Length; j++)
                    {
                        if ((hitColliders[i].transform.position - player.position).sqrMagnitude >
                            (hitColliders[j].transform.position - player.position).sqrMagnitude)
                        {
                            Collider temp = hitColliders[i];
                            hitColliders[i] = hitColliders[j];
                            hitColliders[j] = temp;
                        }
                    }
                }
            }
            foreach (Collider collider in hitColliders)
            {
                Vector3 p2e = collider.transform.position - player.position;
                p2e.y = 0;
                Vector3 sLD3D = new Vector3(direction.x, 0, direction.y);
                float   angle = Vector3.Angle(p2e, sLD3D);
                if (angle <= viewAngle / 2 * m_traceRate)
                {
                    target = collider.transform;
                    return(true);
                }
            }
            // 脱离追踪区域则重置traceRate
            m_traceRate = 1;
        }
        return(false);
    }
Exemple #28
0
 protected virtual void DeadNotifyEventFunc(Transform killer, Transform dead, WeaponNameType weaponName)
 {
     if (self == dead || self == killer)
     {
         if (DeadNotifyEvent != null)
         {
             DeadNotifyEvent(killer, dead);
         }
         if (self == dead)
         {
             I_Manager.SetKilledWeapon(weaponName);
         }
     }
 }
Exemple #29
0
 void ChangeWeapon(WeaponNameType weaponName)
 {
     if (PlayerChangeWeaponEvent != null)
     {
         PlayerChangeWeaponEvent(player, weaponName);
     }
     if (weaponName == curWeaponNameOnBtn)
     {
         Utils.PlayInActiveSnd();
         return;
     }
     curWeaponNameOnBtn = weaponName;
     SetUi(weaponName);
 }
Exemple #30
0
    void PlayerChangeWeaponEventFunc(Transform player, WeaponNameType weaponName)
    {
        AnimatorStateInfo stateInfo = bodyAnim.GetCurrentAnimatorStateInfo(0);

        if (!stateInfo.IsName("Base.Roll"))
        {
            PlayerData.Instance.curWeaponName = weaponName;
            ChangeWeapon();
        }
        else
        {
            // 记录下所要切换的武器,在RollEnd时进行切换
            nextWeaponName = weaponName;
        }
    }