Пример #1
0
    void Weapons()
    {
        int active = -1 + (Input.GetKeyDown(KeyCode.Alpha1) ? 1 : 0) + 2 * (Input.GetKeyDown(KeyCode.Alpha2) ? 1 : 0) + 3 * (Input.GetKeyDown(KeyCode.Alpha3) ? 1 : 0);

        if (active > -1 && active < 3)
        {
            if (!handsWeaponsManager.weapons[active].activeInHierarchy)
            {
                for (int i = 0; i < handsWeaponsManager.weapons.Length; i++)
                {
                    handsWeaponsManager.weapons[i].SetActive(false);
                }
                handsWeaponsManager.weapons[active].SetActive(true);
                handsWeapon = handsWeaponsManager.weapons[active].GetComponent <FPSHands>();
            }

            if (!weaponsManager.weapons[active].activeInHierarchy)
            {
                for (int i = 0; i < weaponsManager.weapons.Length; i++)
                {
                    weaponsManager.weapons[i].SetActive(false);
                }
                weaponsManager.weapons[active].SetActive(true);
                weapon = weaponsManager.weapons[active].GetComponent <FPSWeapon>();
                anims.ChangeController((active == 0) ? true : false);
                nextTimeToFire = Time.time + 1.25f;
            }
        }
    }
Пример #2
0
    void LocalSelectWeapon(int index)
    {
        var weapons     = _weaponManager.weapons;
        var handWeapons = _weaponHandManager.weapons;

        weaponIndex = index;
        if (weaponIndex <= weapons.Length - 1)
        {
            if (!weapons[weaponIndex].activeInHierarchy)
            {
                // 3d view
                for (int i = 0; i < weapons.Length; i++)
                {
                    weapons[i].SetActive(false);
                }

                _currentWeapon = null;
                weapons[weaponIndex].SetActive(true);
                _currentWeapon = weapons[weaponIndex].GetComponent <FPSWeapon>();


                // local user view
                for (int i = 0; i < handWeapons.Length; i++)
                {
                    handWeapons[i].SetActive(false);
                }

                _currentHandWeapon = null;
                handWeapons[weaponIndex].SetActive(true);
                _currentHandWeapon = handWeapons[weaponIndex].GetComponent <FPSHandWeapon>();

                animController.ChangeAnimationController(_currentWeapon.CurrentWeaponType == FPSWeaponBase.WeaponType.Pistol);
            }
        }
    }
Пример #3
0
    // Throw the object
    public void Action(FPSWeapon script)
    {
        // Is the object currently being held?
        if (m_Held)
        {
            script.PlayAnim("v_portalgun.qc_skeleton|release");
            Drop();

            // Force the object away in the opposite direction of the player
            Vector3 forceDir = transform.position - script.m_HandTransform.position;
            m_ThisRigidbody.AddForce(forceDir * script.m_ThrowForce);
        }
    }
        public override void OnWeaponHitEntity(PlayerEntity playerEntity, DaggerfallEntity targetEntity = null)
        {
            const int chanceOfAttackSound = 10;
            const int chanceOfBarkSound   = 20;

            // Check if we killed an innocent and update satiation - do not need to be transformed
            if (KilledInnocent(targetEntity))
            {
                UpdateSatiation();
            }

            // Do nothing further if not transformed
            if (!isTransformed)
            {
                return;
            }

            // Lycanthrope characters emit both attack and bark sounds while attacking
            SoundClips customSound = SoundClips.None;

            if (infectionType == LycanthropyTypes.Werewolf)
            {
                if (Dice100.SuccessRoll(chanceOfAttackSound))
                {
                    customSound = SoundClips.EnemyWerewolfAttack;
                }
                else if (Dice100.SuccessRoll(chanceOfBarkSound))
                {
                    customSound = SoundClips.EnemyWerewolfBark;
                }
            }
            else if (infectionType == LycanthropyTypes.Wereboar)
            {
                if (Dice100.SuccessRoll(chanceOfAttackSound))
                {
                    customSound = SoundClips.EnemyWereboarAttack;
                }
                else if (Dice100.SuccessRoll(chanceOfBarkSound))
                {
                    customSound = SoundClips.EnemyWereboarBark;
                }
            }

            // Play sound through weapon
            FPSWeapon screenWeapon = GameManager.Instance.WeaponManager.ScreenWeapon;

            if (screenWeapon && customSound != SoundClips.None)
            {
                screenWeapon.PlayAttackVoice(customSound);
            }
        }
        public override bool SetFPSWeapon(FPSWeapon target)
        {
            if (isTransformed)
            {
                target.WeaponType       = WeaponTypes.Werecreature;
                target.MetalType        = MetalTypes.None;
                target.DrawWeaponSound  = SoundClips.None;
                target.SwingWeaponSound = SoundClips.SwingHighPitch;
                target.Reach            = WeaponManager.defaultWeaponReach;
                return(true);
            }

            return(false);
        }
Пример #6
0
    public int UnlockWeapon(FPSWeapon weapon)
    {
        var gm = GameManager.Instance;

        Debug.Log(weapon.name);
        if (gm.saveData.weapons.Contains(weapon.name))
        {
            Debug.LogErrorFormat("Weapon {0} purchased, but already owned", weapon.name);
        }
        gm.saveData.weapons.Add(weapon.name);
        // todo: create a scriptableObject around weapons, or else figure out a different way to represent
        // them in the UI
        // saveData.currency -= weapon.purchasePrice;
        return(gm.saveData.currency);
    }
    void Start()
    {
        firstPerson_View = transform.Find("FPS View").transform;
        charController   = GetComponent <CharacterController>();
        speed            = walkSpeed;
        is_Moving        = false;

        rayDistance = charController.height * 0.5f + charController.radius;
        default_ControllerHeight = charController.height;
        default_CamPos           = firstPerson_View.localPosition;

        playerAnimation = GetComponent <FPSPlayerAnimation>();

        weapon_Manager.weapons[0].SetActive(true);
        current_Weapon = weapon_Manager.weapons[0].GetComponent <FPSWeapon>();
    }
Пример #8
0
        public override void OnWeaponHitEnemy(PlayerEntity playerEntity, EnemyEntity enemyEntity)
        {
            const int chanceOfAttackSound = 10;
            const int chanceOfBarkSound   = 20;

            // Do nothing if not transformed
            if (!isTransformed)
            {
                return;
            }

            // Lycanthrope characters emit both attack and bark sounds while attacking
            SoundClips customSound = SoundClips.None;

            if (infectionType == LycanthropyTypes.Werewolf)
            {
                if (Dice100.SuccessRoll(chanceOfAttackSound))
                {
                    customSound = SoundClips.EnemyWerewolfAttack;
                }
                else if (Dice100.SuccessRoll(chanceOfBarkSound))
                {
                    customSound = SoundClips.EnemyWerewolfBark;
                }
            }
            else if (infectionType == LycanthropyTypes.Wereboar)
            {
                if (Dice100.SuccessRoll(chanceOfAttackSound))
                {
                    customSound = SoundClips.EnemyWereboarAttack;
                }
                else if (Dice100.SuccessRoll(chanceOfBarkSound))
                {
                    customSound = SoundClips.EnemyWereboarBark;
                }
            }

            // Play sound through weapon
            FPSWeapon screenWeapon = GameManager.Instance.WeaponManager.ScreenWeapon;

            if (screenWeapon && customSound != SoundClips.None)
            {
                screenWeapon.PlayAttackVoice(customSound);
            }
        }
Пример #9
0
    void Start()
    {
        view       = transform.Find("FPS View").transform;
        controller = GetComponent <CharacterController>();
        shooter    = GetComponent <FPSShooting>();
        anims      = GetComponent <FPSAnimations>();

        speed         = walkSpeed;
        moving        = false;
        rayDistance   = controller.height * 0.5f + controller.radius;
        defaultHeight = controller.height;
        defaultCamPos = view.localPosition;

        nextTimeToFire = Time.time + 1.25f;
        weaponsManager.weapons[0].SetActive(true);
        weapon = weaponsManager.weapons[0].GetComponent <FPSWeapon>();
        handsWeaponsManager.weapons[0].SetActive(true);
        handsWeapon = handsWeaponsManager.weapons[0].GetComponent <FPSHands>();

        playerHolder.layer = LayerMask.NameToLayer(isLocalPlayer ? "Player" : "Default");
        foreach (Transform child in playerHolder.transform)
        {
            child.gameObject.layer = LayerMask.NameToLayer(isLocalPlayer ? "Player" : "Default");
        }
        for (int i = 0; i < weapons.Length; i++)
        {
            weapons[i].layer = LayerMask.NameToLayer(isLocalPlayer ? "Player" : "Default");
        }

        weaponsHolder.layer = LayerMask.NameToLayer(isLocalPlayer ? "Default" : "Player");
        foreach (Transform child in weaponsHolder.transform)
        {
            child.gameObject.layer = LayerMask.NameToLayer(isLocalPlayer ? "Default" : "Player");
        }

        if (!isLocalPlayer)
        {
            for (int i = 0; i < mouseLook.Length; i++)
            {
                mouseLook[i].enabled = false;
            }
        }

        transform.Find("FPS View").Find("FPS Camera").gameObject.SetActive(isLocalPlayer);
    }
Пример #10
0
    // Pick up the object, or drop it if it is already being held
    public void Interact(FPSWeapon script)
    {
        // Is the object currently being held?
        if (m_Held)
        {
            script.PlayAnim("v_portalgun.qc_skeleton|release");
            Drop();
        }
        else
        {
            script.PlayAnim("v_portalgun.qc_skeleton|pickup");
            script.holding             = true;
            m_Held                     = true;
            m_ThisRigidbody.useGravity = false;

            m_HoldJoint = script.m_HandTransform.gameObject.AddComponent <FixedJoint>();
            //m_HoldJoint.breakForce = 10000f; // Play with this value
            m_HoldJoint.breakForce    = 5000f;
            m_HoldJoint.connectedBody = m_ThisRigidbody;
        }
    }
Пример #11
0
        void PlayLycanthropeMoveSound()
        {
            // Get sound based on infection type
            SoundClips customSound = SoundClips.None;

            if (infectionType == LycanthropyTypes.Werewolf)
            {
                customSound = SoundClips.EnemyWerewolfMove;
            }
            else if (infectionType == LycanthropyTypes.Wereboar)
            {
                customSound = SoundClips.EnemyWereboarMove;
            }

            // Play sound through weapon
            FPSWeapon screenWeapon = GameManager.Instance.WeaponManager.ScreenWeapon;

            if (screenWeapon && customSound != SoundClips.None)
            {
                screenWeapon.PlayAttackVoice(customSound);
            }
        }
Пример #12
0
        // The following method is a pared down version of WeaponManager.MeleeDamage as of version 0.10.27
        private void MeleeDamage(FPSWeapon weapon, out bool hitEnemy)
        {
            hitEnemy = false;

            if (!mainCamera || !weapon)
            {
                return;
            }

            // Fire ray along player facing using weapon range
            Ray        ray = new Ray(mainCamera.transform.position, mainCamera.transform.forward);
            RaycastHit hit;

            if (Physics.SphereCast(ray, 0.25f, out hit, weapon.Reach, playerLayerMask))
            {
                if (!GameManager.Instance.WeaponManager.WeaponEnvDamage(null, hit) ||
                    Physics.Raycast(ray, out hit, weapon.Reach, playerLayerMask))
                {
                    hitEnemy = weaponManager.WeaponDamage(null, false, hit.transform, hit.point, mainCamera.transform.forward);
                }
            }
        }
Пример #13
0
 void OnTriggerEnter(Collider other)
 {
     playerwep = other.gameObject.GetComponent <FPSWeapon>();
     if (other.CompareTag("Player"))
     {
         //Destroy(other.gameObject.GetComponent<Weapon>().dupe1);
         playerwep.dupe1.SetActive(false);
         playerwep.dupe1.GetComponent <Portalold>().pairPortal = null;
         playerwep.dupe1.GetComponent <Portalold>().plane.GetComponent <SeamlessTeleport>().receiver = null;
         //Destroy(other.gameObject.GetComponent<Weapon>().dupe2);
         playerwep.dupe2.SetActive(false);
         playerwep.dupe2.GetComponent <Portalold>().pairPortal = null;
         playerwep.dupe2.GetComponent <Portalold>().plane.GetComponent <SeamlessTeleport>().receiver = null;
         //Debug.Log(other.gameObject + " a touché le cleanser");
     }
     if (other.CompareTag("Interactable"))
     {
         other.gameObject.GetComponent <PhysicsObject>().m_Cleanser = true;
         other.gameObject.GetComponent <PhysicsObject>().counter    = 2f;
         other.gameObject.GetComponent <Dead>().Burn();
         //Debug.Log(other.gameObject + " a touché le cleanser");
     }
 }
Пример #14
0
        public static int CalculateWeaponDamage(Entity.DaggerfallEntity attacker, Entity.DaggerfallEntity target, FPSWeapon onScreenWeapon)
        {
            // In classic, hand-to-hand damage is not affected by the strength modifier, by the type of swing or by hand-to-hand proficiency.
            // Both the game manual and strength attribute description say that the strength modifier applies to hand-to-hand damage,
            // and hand-to-hand proficiency would have no effect if it didn't do something for damage and chance to hit.

            int damage_low    = 0;
            int damage_high   = 0;
            int damage_result = 0;

            // TODO: Damage from AI characters.
            if (attacker == GameManager.Instance.PlayerEntity)
            {
                Items.DaggerfallUnityItem weapon;
                if (GameManager.Instance.WeaponManager.UsingRightHand)
                {
                    weapon = attacker.ItemEquipTable.GetItem(Items.EquipSlots.RightHand);
                }
                else
                {
                    weapon = attacker.ItemEquipTable.GetItem(Items.EquipSlots.LeftHand);
                }

                if (weapon == null)
                {
                    damage_low  = CalculateHandToHandMinDamage(attacker.Skills.HandToHand);
                    damage_high = CalculateHandToHandMaxDamage(attacker.Skills.HandToHand);
                }
                else
                {
                    damage_low  = weapon.GetBaseDamageMin();
                    damage_high = weapon.GetBaseDamageMax();
                }

                damage_result = UnityEngine.Random.Range(damage_low, damage_high + 1);

                if (onScreenWeapon != null)
                {
                    // Apply swing modifier.
                    if (onScreenWeapon.WeaponState == WeaponStates.StrikeUp)
                    {
                        damage_result += -2;
                    }
                    if (onScreenWeapon.WeaponState == WeaponStates.StrikeDownLeft ||
                        onScreenWeapon.WeaponState == WeaponStates.StrikeDownRight)
                    {
                        damage_result += 1;
                    }
                    if (onScreenWeapon.WeaponState == WeaponStates.StrikeDown)
                    {
                        damage_result += 3;
                    }

                    // Apply weapon expertise modifier
                    if (weapon != null && ((int)attacker.Career.ExpertProficiencies & weapon.GetWeaponSkillUsed()) != 0)
                    {
                        damage_result += ((attacker.Level / 3) + 1);
                    }

                    // Apply hand-to-hand expertise modifier
                    else if (weapon == null && ((int)attacker.Career.ExpertProficiencies & (int)(DaggerfallConnect.DFCareer.ProficiencyFlags.HandToHand)) != 0)
                    {
                        damage_result += ((attacker.Level / 3) + 1);
                    }
                }

                // Apply the strength modifier.
                damage_result += DamageModifier(attacker.Stats.Strength);

                // Apply the material modifier
                if (weapon != null)
                {
                    damage_result += weapon.GetMaterialDamageModifier();
                }

                // 0 damage is possible. Plays no hit sound or blood splash.
                damage_result = Mathf.Max(0, damage_result);
            }

            return(damage_result);
        }
Пример #15
0
    void SelectWeapon()
    {
        if (Input.GetKeyDown(KeyCode.Alpha1))
        {
            if (!handsWeapon_Manager.weapons [0].activeInHierarchy)
            {
                for (int i = 0; i < handsWeapon_Manager.weapons.Length; i++)
                {
                    handsWeapon_Manager.weapons [i].SetActive(false);
                }
                current_Hands_Weapon = null;
                handsWeapon_Manager.weapons [0].SetActive(true);
                current_Hands_Weapon = handsWeapon_Manager.weapons [0].GetComponent <FPSHandsWeapon> ();
            }

            if (!weapon_manage.weapons [0].activeInHierarchy)
            {
                for (int i = 0; i < weapon_manage.weapons.Length; i++)
                {
                    weapon_manage.weapons [i].SetActive(false);
                }
                current_Weapon = null;
                weapon_manage.weapons [0].SetActive(true);
                current_Weapon = weapon_manage.weapons [0].GetComponent <FPSWeapon> ();

                playerAnimation.ChangeController(true);
            }
        }
        if (Input.GetKeyDown(KeyCode.Alpha2))
        {
            if (!handsWeapon_Manager.weapons [1].activeInHierarchy)
            {
                for (int i = 0; i < handsWeapon_Manager.weapons.Length; i++)
                {
                    handsWeapon_Manager.weapons [i].SetActive(false);
                }
                current_Hands_Weapon = null;
                handsWeapon_Manager.weapons [1].SetActive(true);
                current_Hands_Weapon = handsWeapon_Manager.weapons [1].GetComponent <FPSHandsWeapon> ();
            }

            if (!weapon_manage.weapons [1].activeInHierarchy)
            {
                for (int i = 0; i < weapon_manage.weapons.Length; i++)
                {
                    weapon_manage.weapons [i].SetActive(false);
                }
                current_Weapon = null;
                weapon_manage.weapons [1].SetActive(true);
                current_Weapon = weapon_manage.weapons [1].GetComponent <FPSWeapon> ();

                playerAnimation.ChangeController(false);
            }
        }
        if (Input.GetKeyDown(KeyCode.Alpha3))
        {
            if (!handsWeapon_Manager.weapons [2].activeInHierarchy)
            {
                for (int i = 0; i < handsWeapon_Manager.weapons.Length; i++)
                {
                    handsWeapon_Manager.weapons [i].SetActive(false);
                }
                current_Hands_Weapon = null;
                handsWeapon_Manager.weapons [2].SetActive(true);
                current_Hands_Weapon = handsWeapon_Manager.weapons [2].GetComponent <FPSHandsWeapon> ();
            }

            if (!weapon_manage.weapons [2].activeInHierarchy)
            {
                for (int i = 0; i < weapon_manage.weapons.Length; i++)
                {
                    weapon_manage.weapons [i].SetActive(false);
                }
                current_Weapon = null;
                weapon_manage.weapons [2].SetActive(true);
                current_Weapon = weapon_manage.weapons [2].GetComponent <FPSWeapon> ();

                playerAnimation.ChangeController(false);
            }
        }
    }
Пример #16
0
    // Use this for initialization
    void Start()
    {
        firstPerson_View = transform.Find("FPS View").transform;
        charController   = GetComponent <CharacterController> ();
        speed            = walkSpeed;
        is_Moving        = false;

        rayDistance = charController.height * 0.5f + charController.radius;
        default_ControllerHeight = charController.height;
        default_CamPos           = firstPerson_View.localPosition;

        playerAnimation = GetComponent <FPSPlayerAnimations> ();
        weapon_manage.weapons [0].SetActive(true);
        current_Weapon = weapon_manage.weapons [0].GetComponent <FPSWeapon> ();

        handsWeapon_Manager.weapons [0].SetActive(true);
        current_Hands_Weapon = handsWeapon_Manager.weapons [0].GetComponent <FPSHandsWeapon> ();

        if (isLocalPlayer)
        {
            playerHolder.layer = LayerMask.NameToLayer("Player");
            foreach (Transform child in playerHolder.transform)
            {
                child.gameObject.layer = LayerMask.NameToLayer("Player");
            }
            for (int i = 0; i < weapons_FPS.Length; i++)
            {
                weapons_FPS [i].layer = LayerMask.NameToLayer("Player");
            }

            weaponsHolder.layer = LayerMask.NameToLayer("Enemy");

            foreach (Transform child in weaponsHolder.transform)
            {
                child.gameObject.layer = LayerMask.NameToLayer("Enemy");
            }
        }

        if (!isLocalPlayer)
        {
            playerHolder.layer = LayerMask.NameToLayer("Enemy");
            foreach (Transform child in playerHolder.transform)
            {
                child.gameObject.layer = LayerMask.NameToLayer("Enemy");
            }
            for (int i = 0; i < weapons_FPS.Length; i++)
            {
                weapons_FPS [i].layer = LayerMask.NameToLayer("Enemy");
            }

            weaponsHolder.layer = LayerMask.NameToLayer("Player");

            foreach (Transform child in weaponsHolder.transform)
            {
                child.gameObject.layer = LayerMask.NameToLayer("Player");
            }
        }

        if (!isLocalPlayer)
        {
            for (int i = 0; i < mouseLook.Length; i++)
            {
                mouseLook [i].enabled = false;
            }
        }
        mainCam = transform.Find("FPS View").Find("FPS Camera").GetComponent <Camera> ();
        mainCam.gameObject.SetActive(false);

        if (!isLocalPlayer)
        {
            for (int i = 0; i < PlayerRender.materials.Length; i++)
            {
                PlayerRender.materials [i].color = playerColors [i];
            }
        }
    }
    // Use this for initialization
    void Start()
    {
        this.m_firstPersonView = this.transform.Find("FPS View").transform;
        //transform.Find會從自己的遊戲物件子列表中去尋找對應的物件,這個方法會比GameObject.find還要快
        this.m_charController = this.GetComponent <CharacterController>();
        this.m_fSpeed         = this.m_fWalkSpeed;
        this.m_bIsMoving      = false;

        this.m_fRayDis = this.m_charController.height + this.m_charController.radius;
        print("射線距離 " + this.m_fRayDis);
        this.m_fDefaultControllerHeight = this.m_charController.height;
        this.m_defaulCamPos             = this.m_firstPersonView.localPosition;
        this.m_playerAnim = this.GetComponent <FPSPlayerAnim>();

        this.m_weaponManager.Weapons[0].SetActive(true);
        this.m_currentWeapon = this.m_weaponManager.Weapons[0].GetComponent <FPSWeapon>();

        this.m_handsWeaponManager.Weapons[0].SetActive(true);
        this.m_curHandsWeapon = this.m_handsWeaponManager.Weapons[0].GetComponent <FPSHandsWeapon>();

        if (this.isLocalPlayer)
        {
            this.m_playerHolder.layer = LayerMask.NameToLayer("Player");
            foreach (Transform child in m_playerHolder.transform)
            {
                child.gameObject.layer = LayerMask.NameToLayer("Player");
            }
            for (int i = 0; i < m_arrWeaponsFPS.Length; i++)
            {
                m_arrWeaponsFPS[i].layer = LayerMask.NameToLayer("Player");
            }
            m_weaponsHolder.layer = LayerMask.NameToLayer("Enemy");
            foreach (Transform child in m_weaponsHolder.transform)
            {
                child.gameObject.layer = LayerMask.NameToLayer("Enemy");
            }
        }
        //if (!this.isLocalPlayer)
        else
        {
            this.m_playerHolder.layer = LayerMask.NameToLayer("Enemy");
            foreach (Transform child in m_playerHolder.transform)
            {
                child.gameObject.layer = LayerMask.NameToLayer("Enemy");
            }
            for (int i = 0; i < m_arrWeaponsFPS.Length; i++)
            {
                m_arrWeaponsFPS[i].layer = LayerMask.NameToLayer("Enemy");
            }
            m_weaponsHolder.layer = LayerMask.NameToLayer("Player");
            foreach (Transform child in m_weaponsHolder.transform)
            {
                child.gameObject.layer = LayerMask.NameToLayer("Player");
            }
            for (int i = 0; i < m_arrMouseLook.Length; i++)
            {
                m_arrMouseLook[i].enabled = false;
            }
            this.m_mainCam.gameObject.SetActive(false);
        }
    }
    void SelectWeapon()
    {
        if (Input.GetKeyDown(KeyCode.Alpha1))
        {
            if (!m_handsWeaponManager.Weapons[0].activeInHierarchy)
            {
                for (int i = 0; i < m_handsWeaponManager.Weapons.Count; i++)
                {
                    this.m_handsWeaponManager.Weapons[i].SetActive(false);
                }
                this.m_curHandsWeapon = null;
                this.m_handsWeaponManager.Weapons[0].SetActive(true);
                this.m_curHandsWeapon = this.m_handsWeaponManager.Weapons[0].GetComponent <FPSHandsWeapon>();
            }

            if (!this.m_weaponManager.Weapons[0].activeInHierarchy)
            {
                for (int i = 0; i < this.m_weaponManager.Weapons.Count; i++)
                {
                    this.m_weaponManager.Weapons[i].SetActive(false);
                }
                this.m_currentWeapon = null;
                this.m_weaponManager.Weapons[0].SetActive(true);
                this.m_currentWeapon = this.m_weaponManager.Weapons[0].GetComponent <FPSWeapon>();
                this.m_playerAnim.ChangeController(true);
            }
        }
        else if (Input.GetKeyDown(KeyCode.Alpha2))
        {
            if (!m_handsWeaponManager.Weapons[1].activeInHierarchy)
            {
                for (int i = 0; i < m_handsWeaponManager.Weapons.Count; i++)
                {
                    this.m_handsWeaponManager.Weapons[i].SetActive(false);
                }
                this.m_curHandsWeapon = null;
                this.m_handsWeaponManager.Weapons[1].SetActive(true);
                this.m_curHandsWeapon = this.m_handsWeaponManager.Weapons[1].GetComponent <FPSHandsWeapon>();
            }

            if (!this.m_weaponManager.Weapons[1].activeInHierarchy)
            {
                for (int i = 0; i < this.m_weaponManager.Weapons.Count; i++)
                {
                    this.m_weaponManager.Weapons[i].SetActive(false);
                }
                this.m_currentWeapon = null;
                this.m_weaponManager.Weapons[1].SetActive(true);
                this.m_currentWeapon = this.m_weaponManager.Weapons[1].GetComponent <FPSWeapon>();
                this.m_playerAnim.ChangeController(false);
            }
        }
        else if (Input.GetKeyDown(KeyCode.Alpha3))
        {
            if (!m_handsWeaponManager.Weapons[2].activeInHierarchy)
            {
                for (int i = 0; i < m_handsWeaponManager.Weapons.Count; i++)
                {
                    this.m_handsWeaponManager.Weapons[i].SetActive(false);
                }
                this.m_curHandsWeapon = null;
                this.m_handsWeaponManager.Weapons[2].SetActive(true);
                this.m_curHandsWeapon = this.m_handsWeaponManager.Weapons[2].GetComponent <FPSHandsWeapon>();
            }

            if (!this.m_weaponManager.Weapons[2].activeInHierarchy)
            {
                for (int i = 0; i < this.m_weaponManager.Weapons.Count; i++)
                {
                    this.m_weaponManager.Weapons[i].SetActive(false);
                }
                this.m_currentWeapon = null;
                this.m_weaponManager.Weapons[2].SetActive(true);
                this.m_currentWeapon = this.m_weaponManager.Weapons[2].GetComponent <FPSWeapon>();
                this.m_playerAnim.ChangeController(false);
            }
        }
    }
Пример #19
0
    void Start()
    {
        //0 - smoke. 1 - sparks for terrain. 2 - sparks for hilling shields!
        hitParticles    = new GameObject[3];
        hitParticles[0] = Resources.Load("My/Prefabs/Particles/New/DestructionSmoke") as GameObject;
        hitParticles[1] = Resources.Load("My/Prefabs/Particles/New/WallHitParticle") as GameObject;
        hitParticles[2] = Resources.Load("My/Prefabs/Particles/New/ArmorHitSparks") as GameObject;

        //load kill camera
        if (enableKillCamInspector)
        {
            enableKillCam = true;//killCam = Resources.Load("My/Prefabs/Items/KillCamera") as GameObject;
        }

        deathMessage      = Resources.Load("My/Prefabs/DeathMessage") as GameObject;
        playerBoxCollider = GetComponent <BoxCollider> ();
        fpsWeapon         = GameObject.Find("Gun").GetComponent <FPSWeapon> (); //get the gun (used to draw fps gun on screen)
        //the sound of reloading
        reloadAudioSource                       = gameObject.AddComponent <AudioSource>();
        reloadAudioSource.clip                  = reloadAmmoSound;
        reloadAudioSource.playOnAwake           = false;
        reloadAudioSource.loop                  = false;
        reloadAudioSource.outputAudioMixerGroup = mixer;
        reloadAudioSource.spatialBlend          = 0f;
        reloadAudioSource.volume                = 0.5f;
        //the sound of reloading
        slashParticle = GameObject.Find("Slash").GetComponent <ParticleSystem> (); //when melee attack particle

        saveCube      = GameObject.Find("SaveCube");                               //find the save cube
        fpsController = GetComponent <FirstPersonController> ();
        //mixer = Resources.Load ("MasterMixer") as AudioMixer;
        music = GameObject.FindGameObjectsWithTag("Music");

        //decals
        //bulletHoleDecal = GameObject.Find ("BulletHoleDecal");
        splashBloodDecal = GameObject.Find("SplashBloodDecal");
        //decals

        playerStats = GameObject.Find("SavePlayerStats").GetComponent <SavePlayerStats> ();
        //SAVE MANAGER HERE
        try
        {
            saveManager = playerStats.gameObject.GetComponent <SaveManager> ();
        }
        catch
        {
            Debug.Log("No Save Manager! Shit");
        }
        //SAVE MANAGER HERE
        weaponFireParticle            = Resources.Load("My/Prefabs/Particles/New/WeaponShootParticle") as GameObject;//GameObject.Find ("FiringParticle");
        weaponHitParticle             = GameObject.Find("BulletHitExplosion");
        weaponBloodParticle           = GameObject.Find("BloodParticle");
        weaponBloodParticleAdditional = Resources.Load("My/Prefabs/Particles/New/BloodParticleAdditional") as GameObject;
        gunBarrel = GameObject.Find("GunBarrel");

        //hud texts
//		hudText = GameObject.Find ("PlayerHPText").GetComponent<Text> ();
//		rangedWeaponText = GameObject.Find ("RangedWeaponText").GetComponent<Text> ();
//		ammoText = GameObject.Find ("AmmoText").GetComponent<Text> ();
//		totalAmmo = GameObject.Find ("TotalAmmo").GetComponent<Text> ();
//		meleeWeaponText = GameObject.Find ("MeleeWeaponText").GetComponent<Text> ();

        mainText = GetComponent <PlayerConversations> ().mainText;
        //hud texts

        //sound for firing the gun
        audioSourceRangeHit             = gameObject.AddComponent <AudioSource> ();
        audioSourceRangeHit.playOnAwake = false;
        //audioSourceRangeHit.spread = 180;
        //audioSourceRangeHit.spatialBlend = 360;
        audioSourceRangeHit.volume = 0.5f;
        audioSourceRangeHit.outputAudioMixerGroup = mixer;
    }
Пример #20
0
 /// <summary>
 /// Set state of current FPS weapon from WeaponManager.
 /// Allows the racial override to set a unique weapon type such as wereclaws.
 /// </summary>
 /// <param name="target">Target FPSWeapon to change.</param>
 /// <returns>True if weapon changed.</returns>
 public virtual bool SetFPSWeapon(FPSWeapon target)
 {
     return(false);
 }
Пример #21
0
        public static int CalculateWeaponDamage(Entity.DaggerfallEntity attacker, Entity.DaggerfallEntity target, FPSWeapon onscreenWeapon)
        {
            if (attacker == null || target == null)
            {
                return(0);
            }

            int damageLow       = 0;
            int damageHigh      = 0;
            int damageModifiers = 0;
            int baseDamage      = 0;
            int damageResult    = 0;
            int chanceToHitMod  = 0;

            Items.DaggerfallUnityItem weapon     = null;
            Entity.PlayerEntity       player     = GameManager.Instance.PlayerEntity;
            Entity.EnemyEntity        AIAttacker = null;
            Entity.EnemyEntity        AITarget   = null;

            if (attacker != player)
            {
                AIAttacker = attacker as Entity.EnemyEntity;
            }

            if (target != player)
            {
                AITarget = target as Entity.EnemyEntity;
            }

            // TODO: Get weapons of enemy classes and monsters.
            if (attacker == player)
            {
                if (GameManager.Instance.WeaponManager.UsingRightHand)
                {
                    weapon = attacker.ItemEquipTable.GetItem(Items.EquipSlots.RightHand);
                }
                else
                {
                    weapon = attacker.ItemEquipTable.GetItem(Items.EquipSlots.LeftHand);
                }
            }

            // If the player is attacking with no weapon equipped, use hand-to-hand skill for damage
            if (weapon == null && attacker == player)
            {
                damageLow      = CalculateHandToHandMinDamage(attacker.Skills.HandToHand);
                damageHigh     = CalculateHandToHandMaxDamage(attacker.Skills.HandToHand);
                chanceToHitMod = attacker.Skills.HandToHand;
            }
            // If a monster is attacking, use damage values from enemy definitions
            else if (weapon == null && AIAttacker != null)
            {
                damageLow      = AIAttacker.MobileEnemy.MinDamage;
                damageHigh     = AIAttacker.MobileEnemy.MaxDamage;
                chanceToHitMod = attacker.Skills.HandToHand;
            }
            // If the player is attacking with a weapon equipped, use the weapon's damage
            else if (attacker == player)
            {
                damageLow  = weapon.GetBaseDamageMin();
                damageHigh = weapon.GetBaseDamageMax();
                short skillID = weapon.GetWeaponSkillID();
                chanceToHitMod = attacker.Skills.GetSkillValue(skillID);
            }

            baseDamage = UnityEngine.Random.Range(damageLow, damageHigh + 1);

            if (onscreenWeapon != null && (attacker == player))
            {
                // Apply swing modifiers for player.
                // The Daggerfall manual groups diagonal slashes to the left and right as if they are the same, but they are different.
                // Classic does not apply swing modifiers to hand-to-hand.
                if (onscreenWeapon.WeaponState == WeaponStates.StrikeUp)
                {
                    damageModifiers += -4;
                    chanceToHitMod  += 10;
                }
                if (onscreenWeapon.WeaponState == WeaponStates.StrikeDownRight)
                {
                    damageModifiers += -2;
                    chanceToHitMod  += 5;
                }
                if (onscreenWeapon.WeaponState == WeaponStates.StrikeDownLeft)
                {
                    damageModifiers += 2;
                    chanceToHitMod  += -5;
                }
                if (onscreenWeapon.WeaponState == WeaponStates.StrikeDown)
                {
                    damageModifiers += 4;
                    chanceToHitMod  += -10;
                }
            }

            // Apply weapon proficiency modifiers for player.
            if ((attacker == player) && weapon != null && ((int)attacker.Career.ExpertProficiencies & weapon.GetWeaponSkillUsed()) != 0)
            {
                damageModifiers += ((attacker.Level / 3) + 1);
                chanceToHitMod  += attacker.Level;
            }
            // Apply hand-to-hand proficiency modifiers for player. Hand-to-hand proficiencty is not applied in classic.
            else if ((attacker == player) && weapon == null && ((int)attacker.Career.ExpertProficiencies & (int)(DaggerfallConnect.DFCareer.ProficiencyFlags.HandToHand)) != 0)
            {
                damageModifiers += ((attacker.Level / 3) + 1);
                chanceToHitMod  += attacker.Level;
            }

            // Apply modifiers for Skeletal Warrior.
            // In classic these appear to be applied after the swing and weapon proficiency modifiers but before all other
            // damage modifiers. Doing the same here.
            // DF Chronicles just says "Edged weapons inflict 1/2 damage"
            if (weapon != null && (target != player) && AITarget.CareerIndex == (int)Entity.MonsterCareers.SkeletalWarrior)
            {
                if (weapon.NativeMaterialValue == (int)Items.WeaponMaterialTypes.Silver)
                {
                    baseDamage      *= 2;
                    damageModifiers *= 2;
                }
                if (weapon.GetWeaponSkillUsed() != (int)DaggerfallConnect.DFCareer.ProficiencyFlags.BluntWeapons)
                {
                    baseDamage      /= 2;
                    damageModifiers /= 2;
                }
            }

            // Apply bonus or penalty by opponent type.
            // In classic this is broken and only works if the attack is done with a weapon that has the maximum number of enchantments.
            if ((target != player) && (AITarget.GetEnemyGroup() == DaggerfallConnect.DFCareer.EnemyGroups.Undead))
            {
                if (((int)attacker.Career.UndeadAttackModifier & (int)DaggerfallConnect.DFCareer.AttackModifier.Bonus) != 0)
                {
                    damageModifiers += attacker.Level;
                }
                if (((int)attacker.Career.UndeadAttackModifier & (int)DaggerfallConnect.DFCareer.AttackModifier.Phobia) != 0)
                {
                    damageModifiers -= attacker.Level;
                }
            }
            else if ((target != player) && (AITarget.GetEnemyGroup() == DaggerfallConnect.DFCareer.EnemyGroups.Daedra))
            {
                if (((int)attacker.Career.DaedraAttackModifier & (int)DaggerfallConnect.DFCareer.AttackModifier.Bonus) != 0)
                {
                    damageModifiers += attacker.Level;
                }
                if (((int)attacker.Career.DaedraAttackModifier & (int)DaggerfallConnect.DFCareer.AttackModifier.Phobia) != 0)
                {
                    damageModifiers -= attacker.Level;
                }
            }
            else if ((target != player) && (AITarget.GetEnemyGroup() == DaggerfallConnect.DFCareer.EnemyGroups.Humanoid))
            {
                if (((int)attacker.Career.HumanoidAttackModifier & (int)DaggerfallConnect.DFCareer.AttackModifier.Bonus) != 0)
                {
                    damageModifiers += attacker.Level;
                }
                if (((int)attacker.Career.HumanoidAttackModifier & (int)DaggerfallConnect.DFCareer.AttackModifier.Phobia) != 0)
                {
                    damageModifiers -= attacker.Level;
                }
            }
            else if ((target != player) && (AITarget.GetEnemyGroup() == DaggerfallConnect.DFCareer.EnemyGroups.Animals))
            {
                if (((int)attacker.Career.AnimalsAttackModifier & (int)DaggerfallConnect.DFCareer.AttackModifier.Bonus) != 0)
                {
                    damageModifiers += attacker.Level;
                }
                if (((int)attacker.Career.AnimalsAttackModifier & (int)DaggerfallConnect.DFCareer.AttackModifier.Phobia) != 0)
                {
                    damageModifiers -= attacker.Level;
                }
            }

            // Apply racial modifiers for player.
            if ((attacker == player) && weapon != null)
            {
                if (player.RaceTemplate.ID == (int)Entity.Races.DarkElf)
                {
                    damageModifiers += (attacker.Level / 4);
                    chanceToHitMod  += (attacker.Level / 4);
                }
                else if (weapon.GetWeaponSkillUsed() == (int)DaggerfallConnect.DFCareer.ProficiencyFlags.MissileWeapons)
                {
                    if (player.RaceTemplate.ID == (int)Entity.Races.WoodElf)
                    {
                        damageModifiers += (attacker.Level / 3);
                        chanceToHitMod  += (attacker.Level / 3);
                    }
                }
                else if (player.RaceTemplate.ID == (int)Entity.Races.Redguard)
                {
                    damageModifiers += (attacker.Level / 3);
                    chanceToHitMod  += (attacker.Level / 3);
                }
            }

            // Apply strength modifier for player or for AI characters using weapons.
            // The in-game display of the strength modifier in Daggerfall is incorrect. It is actually ((STR - 50) / 5).
            if ((attacker == player) || (weapon != null))
            {
                damageModifiers += DamageModifier(attacker.Stats.Strength);
            }

            // Apply material modifier.
            // The in-game display in Daggerfall of weapon damages with material modifiers is incorrect. The material modifier is half of what the display suggests.
            if (weapon != null)
            {
                damageModifiers += weapon.GetWeaponMaterialModifier();
            }

            // Check for a successful hit.
            if (CalculateSuccessfulHit(attacker, target, chanceToHitMod, weapon) == true)
            {
                // 0 damage is possible. Creates no blood splash.
                damageResult = Mathf.Max(0, (baseDamage + damageModifiers));
            }

            // If attack was by player or weapon-based, end here
            if ((attacker == player) || (weapon != null))
            {
                return(damageResult);
            }
            // Handle multiple attacks by AI characters.
            else
            {
                if (AIAttacker.MobileEnemy.MaxDamage2 != 0 && (CalculateSuccessfulHit(attacker, target, chanceToHitMod, weapon) == true))
                {
                    baseDamage    = UnityEngine.Random.Range(AIAttacker.MobileEnemy.MinDamage2, AIAttacker.MobileEnemy.MaxDamage2 + 1);
                    damageResult += Mathf.Max(0, (baseDamage + damageModifiers));
                }
                if (AIAttacker.MobileEnemy.MaxDamage3 != 0 && (CalculateSuccessfulHit(attacker, target, chanceToHitMod, weapon) == true))
                {
                    baseDamage    = UnityEngine.Random.Range(AIAttacker.MobileEnemy.MinDamage3, AIAttacker.MobileEnemy.MaxDamage3 + 1);
                    damageResult += Mathf.Max(0, (baseDamage + damageModifiers));
                }
                return(damageResult);
            }
        }
Пример #22
0
        public static int CalculateAttackDamage(Entity.DaggerfallEntity attacker, Entity.DaggerfallEntity target, int weaponEquipSlot, int enemyAnimStateRecord)
        {
            if (attacker == null || target == null)
            {
                return(0);
            }

            int minBaseDamage     = 0;
            int maxBaseDamage     = 0;
            int damageModifiers   = 0;
            int damage            = 0;
            int chanceToHitMod    = 0;
            int backstabbingLevel = 0;

            Entity.PlayerEntity       player = GameManager.Instance.PlayerEntity;
            Items.DaggerfallUnityItem weapon = attacker.ItemEquipTable.GetItem((Items.EquipSlots)weaponEquipSlot);
            short skillID = 0;

            // Choose whether weapon-wielding enemies use their weapons or weaponless attacks.
            // In classic, weapon-wielding enemies use the damage values of their weapons
            // instead of their weaponless values.
            // For some enemies this gives lower damage than similar-tier monsters
            // and the weaponless values seems more appropriate, so here
            // enemies will choose to use their weaponless attack if it is more damaging.
            Entity.EnemyEntity AIAttacker = attacker as Entity.EnemyEntity;
            if (AIAttacker != null && weapon != null)
            {
                int weaponAverage   = ((minBaseDamage + maxBaseDamage) / 2);
                int noWeaponAverage = ((AIAttacker.MobileEnemy.MinDamage + AIAttacker.MobileEnemy.MaxDamage) / 2);

                if (noWeaponAverage > weaponAverage)
                {
                    // Use hand-to-hand
                    weapon = null;
                }
            }

            if (weapon != null)
            {
                // If the attacker is using a weapon, check if the material is high enough to damage the target
                if (target.MinMetalToHit > (Items.WeaponMaterialTypes)weapon.NativeMaterialValue)
                {
                    if (attacker == player)
                    {
                        DaggerfallUI.Instance.PopupMessage(UserInterfaceWindows.HardStrings.materialIneffective);
                    }

                    return(0);
                }

                // Get weapon skill used
                skillID = weapon.GetWeaponSkillIDAsShort();
            }
            else
            {
                skillID = (short)DFCareer.Skills.HandToHand;
            }

            chanceToHitMod = attacker.Skills.GetLiveSkillValue(skillID);

            Entity.EnemyEntity AITarget = null;
            if (target != player)
            {
                AITarget = target as Entity.EnemyEntity;
            }

            if (attacker == player)
            {
                // Apply swing modifiers. Not applied to hand-to-hand in classic.
                FPSWeapon onscreenWeapon = GameManager.Instance.WeaponManager.ScreenWeapon;

                if (onscreenWeapon != null)
                {
                    // The Daggerfall manual groups diagonal slashes to the left and right as if they are the same, but they are different.
                    // Classic does not apply swing modifiers to hand-to-hand.
                    if (onscreenWeapon.WeaponState == WeaponStates.StrikeUp)
                    {
                        damageModifiers += -4;
                        chanceToHitMod  += 10;
                    }
                    if (onscreenWeapon.WeaponState == WeaponStates.StrikeDownRight)
                    {
                        damageModifiers += -2;
                        chanceToHitMod  += 5;
                    }
                    if (onscreenWeapon.WeaponState == WeaponStates.StrikeDownLeft)
                    {
                        damageModifiers += 2;
                        chanceToHitMod  += -5;
                    }
                    if (onscreenWeapon.WeaponState == WeaponStates.StrikeDown)
                    {
                        damageModifiers += 4;
                        chanceToHitMod  += -10;
                    }
                }

                if (weapon != null)
                {
                    // Apply weapon proficiency
                    if (((int)attacker.Career.ExpertProficiencies & weapon.GetWeaponSkillUsed()) != 0)
                    {
                        damageModifiers += ((attacker.Level / 3) + 1);
                        chanceToHitMod  += attacker.Level;
                    }
                }
                // Apply hand-to-hand proficiency. Hand-to-hand proficiency is not applied in classic.
                else if (((int)attacker.Career.ExpertProficiencies & (int)(DFCareer.ProficiencyFlags.HandToHand)) != 0)
                {
                    damageModifiers += ((attacker.Level / 3) + 1);
                    chanceToHitMod  += attacker.Level;
                }

                // Apply racial bonuses
                if (weapon != null)
                {
                    if (player.RaceTemplate.ID == (int)Entity.Races.DarkElf)
                    {
                        damageModifiers += (attacker.Level / 4);
                        chanceToHitMod  += (attacker.Level / 4);
                    }
                    else if (skillID == (short)DFCareer.Skills.Archery)
                    {
                        if (player.RaceTemplate.ID == (int)Entity.Races.WoodElf)
                        {
                            damageModifiers += (attacker.Level / 3);
                            chanceToHitMod  += (attacker.Level / 3);
                        }
                    }
                    else if (player.RaceTemplate.ID == (int)Entity.Races.Redguard)
                    {
                        damageModifiers += (attacker.Level / 3);
                        chanceToHitMod  += (attacker.Level / 3);
                    }
                }

                // Apply backstabbing
                if (enemyAnimStateRecord % 5 > 2) // Facing away from player
                {
                    chanceToHitMod += attacker.Skills.GetLiveSkillValue(DFCareer.Skills.Backstabbing);
                    attacker.TallySkill(DFCareer.Skills.Backstabbing, 1); // backstabbing
                    backstabbingLevel = attacker.Skills.GetLiveSkillValue(DFCareer.Skills.Backstabbing);
                }
            }

            // Choose struck body part
            int[] bodyParts      = { 0, 0, 1, 1, 1, 2, 2, 2, 3, 3, 3, 3, 4, 4, 4, 4, 5, 5, 5, 6 };
            int   struckBodyPart = bodyParts[UnityEngine.Random.Range(0, bodyParts.Length)];

            // Get damage for weaponless attacks
            if (skillID == (short)DFCareer.Skills.HandToHand)
            {
                if (attacker == player)
                {
                    if (CalculateSuccessfulHit(attacker, target, chanceToHitMod, null, struckBodyPart))
                    {
                        minBaseDamage = CalculateHandToHandMinDamage(attacker.Skills.GetLiveSkillValue(DFCareer.Skills.HandToHand));
                        maxBaseDamage = CalculateHandToHandMaxDamage(attacker.Skills.GetLiveSkillValue(DFCareer.Skills.HandToHand));
                        damage        = UnityEngine.Random.Range(minBaseDamage, maxBaseDamage + 1);

                        // Apply damage modifiers.
                        damage += damageModifiers;
                        // Apply strength modifier. It is not applied in classic despite what the in-game description for the Strength attribute says.
                        damage += DamageModifier(attacker.Stats.LiveStrength);

                        // Handle backstabbing
                        if (backstabbingLevel > 0 && UnityEngine.Random.Range(1, 101) <= backstabbingLevel)
                        {
                            damage *= 3;
                            string backstabMessage = UserInterfaceWindows.HardStrings.successfulBackstab;
                            DaggerfallUI.Instance.PopupMessage(backstabMessage);
                        }
                    }
                }
                else // attacker is monster
                {
                    // Handle multiple attacks by AI
                    int attackNumber = 0;
                    while (attackNumber < 3) // Classic supports up to 5 attacks but no monster has more than 3
                    {
                        if (attackNumber == 0)
                        {
                            minBaseDamage = AIAttacker.MobileEnemy.MinDamage;
                            maxBaseDamage = AIAttacker.MobileEnemy.MaxDamage;
                        }
                        else if (attackNumber == 1)
                        {
                            minBaseDamage = AIAttacker.MobileEnemy.MinDamage2;
                            maxBaseDamage = AIAttacker.MobileEnemy.MaxDamage2;
                        }
                        else if (attackNumber == 2)
                        {
                            minBaseDamage = AIAttacker.MobileEnemy.MinDamage3;
                            maxBaseDamage = AIAttacker.MobileEnemy.MaxDamage3;
                        }

                        if (DFRandom.rand() % 100 < 50 && minBaseDamage > 0 && CalculateSuccessfulHit(attacker, target, chanceToHitMod, null, struckBodyPart))
                        {
                            damage += UnityEngine.Random.Range(minBaseDamage, maxBaseDamage + 1);
                        }
                        ++attackNumber;
                    }
                }
            }
            // Handle weapon attacks
            else
            {
                if (CalculateSuccessfulHit(attacker, target, chanceToHitMod, weapon, struckBodyPart))
                {
                    damage  = UnityEngine.Random.Range(weapon.GetBaseDamageMin(), weapon.GetBaseDamageMax() + 1);
                    damage += damageModifiers;

                    // Apply modifiers for Skeletal Warrior.
                    if (AITarget != null && AITarget.CareerIndex == (int)Entity.MonsterCareers.SkeletalWarrior)
                    {
                        if (weapon.NativeMaterialValue == (int)Items.WeaponMaterialTypes.Silver)
                        {
                            damage *= 2;
                        }
                        if ((weapon.flags & 0x10) == 0) // not a blunt weapon
                        {
                            damage /= 2;
                        }
                    }

                    // Apply strength modifier
                    damage += DamageModifier(attacker.Stats.LiveStrength);

                    // Apply material modifier.
                    // The in-game display in Daggerfall of weapon damages with material modifiers is incorrect. The material modifier is half of what the display suggests.
                    damage += weapon.GetWeaponMaterialModifier();

                    if (damage < 1)
                    {
                        damage = 0;
                    }

                    damage += GetBonusOrPenaltyByEnemyType(attacker, AITarget);

                    if (backstabbingLevel > 1 && UnityEngine.Random.Range(1, 100 + 1) <= backstabbingLevel)
                    {
                        damage *= 3;
                        string backstabMessage = UserInterfaceWindows.HardStrings.successfulBackstab;
                        DaggerfallUI.Instance.PopupMessage(backstabMessage);
                    }
                }
            }

            damage = Mathf.Max(0, damage);

            // If damage was done by a weapon, damage the weapon and armor of the hit body part.
            // In classic, shields are never damaged, only armor specific to the hitbody part is.
            // Here, if an equipped shield covers the hit body part, it takes damage instead.
            if (weapon != null && damage > 0)
            {
                weapon.DamageThroughPhysicalHit(damage, attacker);

                Items.DaggerfallUnityItem shield = target.ItemEquipTable.GetItem(Items.EquipSlots.LeftHand);
                bool shieldTakesDamage           = false;
                if (shield != null)
                {
                    Items.BodyParts[] protectedBodyParts = shield.GetShieldProtectedBodyParts();

                    for (int i = 0; (i < protectedBodyParts.Length) && !shieldTakesDamage; i++)
                    {
                        if (protectedBodyParts[i] == (Items.BodyParts)struckBodyPart)
                        {
                            shieldTakesDamage = true;
                        }
                    }
                }

                if (shieldTakesDamage)
                {
                    shield.DamageThroughPhysicalHit(damage, target);
                }
                else
                {
                    Items.EquipSlots          hitSlot = Items.DaggerfallUnityItem.GetEquipSlotForBodyPart((Items.BodyParts)struckBodyPart);
                    Items.DaggerfallUnityItem armor   = target.ItemEquipTable.GetItem(hitSlot);
                    if (armor != null)
                    {
                        armor.DamageThroughPhysicalHit(damage, target);
                    }
                }
            }

            return(damage);
        }
Пример #23
0
        public static int CalculateWeaponDamage(Entity.DaggerfallEntity attacker, Entity.DaggerfallEntity target, FPSWeapon onscreenWeapon)
        {
            if (attacker == null || target == null)
            {
                return(0);
            }

            int damageLow       = 0;
            int damageHigh      = 0;
            int damageModifiers = 0;
            int baseDamage      = 0;
            int damageResult    = 0;
            int chanceToHitMod  = 0;

            Items.DaggerfallUnityItem weapon     = null;
            Entity.PlayerEntity       player     = GameManager.Instance.PlayerEntity;
            Entity.EnemyEntity        AIAttacker = null;
            Entity.EnemyEntity        AITarget   = null;

            if (attacker != player)
            {
                AIAttacker = attacker as Entity.EnemyEntity;
                weapon     = attacker.ItemEquipTable.GetItem(Items.EquipSlots.RightHand);
                if (weapon == null)
                {
                    weapon = attacker.ItemEquipTable.GetItem(Items.EquipSlots.LeftHand);
                }
            }
            else
            {
                if (GameManager.Instance.WeaponManager.UsingRightHand)
                {
                    weapon = attacker.ItemEquipTable.GetItem(Items.EquipSlots.RightHand);
                }
            }

            if (target != player)
            {
                AITarget = target as Entity.EnemyEntity;
            }

            if (weapon != null)
            {
                // If the attacker has a weapon equipped, check if the material is high enough to damage the target
                if (target.MinMetalToHit > (Items.WeaponMaterialTypes)weapon.NativeMaterialValue)
                {
                    if (attacker == player)
                    {
                        DaggerfallUI.Instance.PopupMessage(UserInterfaceWindows.HardStrings.materialIneffective);
                    }
                    return(0);
                }

                // If the attacker has a weapon equipped, get the weapon's damage
                damageLow  = weapon.GetBaseDamageMin();
                damageHigh = weapon.GetBaseDamageMax();
                short skillID = weapon.GetWeaponSkillIDAsShort();
                chanceToHitMod = attacker.Skills.GetSkillValue(skillID);
            }
            else if (attacker == player)
            {
                // If the player is attacking with no weapon equipped, use hand-to-hand skill for damage
                damageLow      = CalculateHandToHandMinDamage(attacker.Skills.HandToHand);
                damageHigh     = CalculateHandToHandMaxDamage(attacker.Skills.HandToHand);
                chanceToHitMod = attacker.Skills.HandToHand;
            }

            if (AIAttacker != null)
            {
                // Note: In classic, for enemies that have weapons, the damage values in the enemy
                // definitions are overridden by the weapon stats. This is fine for enemy classes,
                // who have non-weapon damage values of 0, but for the monsters that use weapons,
                // they may have a better attack if they don't use a weapon.
                // In DF Unity, enemies are using whichever is more damaging, the weapon or non-weapon attack.
                int weaponAverage   = ((damageLow + damageHigh) / 2);
                int noWeaponAverage = ((AIAttacker.MobileEnemy.MinDamage + AIAttacker.MobileEnemy.MaxDamage) / 2);

                if (noWeaponAverage > weaponAverage)
                {
                    damageLow      = AIAttacker.MobileEnemy.MinDamage;
                    damageHigh     = AIAttacker.MobileEnemy.MaxDamage;
                    chanceToHitMod = attacker.Skills.HandToHand;
                }
            }

            baseDamage = UnityEngine.Random.Range(damageLow, damageHigh + 1);

            if (onscreenWeapon != null && (attacker == player))
            {
                // Apply swing modifiers for player.
                // The Daggerfall manual groups diagonal slashes to the left and right as if they are the same, but they are different.
                // Classic does not apply swing modifiers to hand-to-hand.
                if (onscreenWeapon.WeaponState == WeaponStates.StrikeUp)
                {
                    damageModifiers += -4;
                    chanceToHitMod  += 10;
                }
                if (onscreenWeapon.WeaponState == WeaponStates.StrikeDownRight)
                {
                    damageModifiers += -2;
                    chanceToHitMod  += 5;
                }
                if (onscreenWeapon.WeaponState == WeaponStates.StrikeDownLeft)
                {
                    damageModifiers += 2;
                    chanceToHitMod  += -5;
                }
                if (onscreenWeapon.WeaponState == WeaponStates.StrikeDown)
                {
                    damageModifiers += 4;
                    chanceToHitMod  += -10;
                }
            }

            // Apply weapon proficiency modifiers for player.
            if ((attacker == player) && weapon != null && ((int)attacker.Career.ExpertProficiencies & weapon.GetWeaponSkillUsed()) != 0)
            {
                damageModifiers += ((attacker.Level / 3) + 1);
                chanceToHitMod  += attacker.Level;
            }
            // Apply hand-to-hand proficiency modifiers for player. Hand-to-hand proficiencty is not applied in classic.
            else if ((attacker == player) && weapon == null && ((int)attacker.Career.ExpertProficiencies & (int)(DaggerfallConnect.DFCareer.ProficiencyFlags.HandToHand)) != 0)
            {
                damageModifiers += ((attacker.Level / 3) + 1);
                chanceToHitMod  += attacker.Level;
            }

            // Apply modifiers for Skeletal Warrior.
            // In classic these appear to be applied after the swing and weapon proficiency modifiers but before all other
            // damage modifiers. Doing the same here.
            // DF Chronicles just says "Edged weapons inflict 1/2 damage"
            if (weapon != null && (target != player) && AITarget.CareerIndex == (int)Entity.MonsterCareers.SkeletalWarrior)
            {
                if (weapon.NativeMaterialValue == (int)Items.WeaponMaterialTypes.Silver)
                {
                    baseDamage      *= 2;
                    damageModifiers *= 2;
                }
                if (weapon.GetWeaponSkillUsed() != (int)DaggerfallConnect.DFCareer.ProficiencyFlags.BluntWeapons)
                {
                    baseDamage      /= 2;
                    damageModifiers /= 2;
                }
            }

            // Apply bonus or penalty by opponent type.
            // In classic this is broken and only works if the attack is done with a weapon that has the maximum number of enchantments.
            if ((target != player) && (AITarget.GetEnemyGroup() == DaggerfallConnect.DFCareer.EnemyGroups.Undead))
            {
                if (((int)attacker.Career.UndeadAttackModifier & (int)DaggerfallConnect.DFCareer.AttackModifier.Bonus) != 0)
                {
                    damageModifiers += attacker.Level;
                }
                if (((int)attacker.Career.UndeadAttackModifier & (int)DaggerfallConnect.DFCareer.AttackModifier.Phobia) != 0)
                {
                    damageModifiers -= attacker.Level;
                }
            }
            else if ((target != player) && (AITarget.GetEnemyGroup() == DaggerfallConnect.DFCareer.EnemyGroups.Daedra))
            {
                if (((int)attacker.Career.DaedraAttackModifier & (int)DaggerfallConnect.DFCareer.AttackModifier.Bonus) != 0)
                {
                    damageModifiers += attacker.Level;
                }
                if (((int)attacker.Career.DaedraAttackModifier & (int)DaggerfallConnect.DFCareer.AttackModifier.Phobia) != 0)
                {
                    damageModifiers -= attacker.Level;
                }
            }
            else if ((target != player) && (AITarget.GetEnemyGroup() == DaggerfallConnect.DFCareer.EnemyGroups.Humanoid))
            {
                if (((int)attacker.Career.HumanoidAttackModifier & (int)DaggerfallConnect.DFCareer.AttackModifier.Bonus) != 0)
                {
                    damageModifiers += attacker.Level;
                }
                if (((int)attacker.Career.HumanoidAttackModifier & (int)DaggerfallConnect.DFCareer.AttackModifier.Phobia) != 0)
                {
                    damageModifiers -= attacker.Level;
                }
            }
            else if ((target != player) && (AITarget.GetEnemyGroup() == DaggerfallConnect.DFCareer.EnemyGroups.Animals))
            {
                if (((int)attacker.Career.AnimalsAttackModifier & (int)DaggerfallConnect.DFCareer.AttackModifier.Bonus) != 0)
                {
                    damageModifiers += attacker.Level;
                }
                if (((int)attacker.Career.AnimalsAttackModifier & (int)DaggerfallConnect.DFCareer.AttackModifier.Phobia) != 0)
                {
                    damageModifiers -= attacker.Level;
                }
            }

            // Apply racial modifiers for player.
            if ((attacker == player) && weapon != null)
            {
                if (player.RaceTemplate.ID == (int)Entity.Races.DarkElf)
                {
                    damageModifiers += (attacker.Level / 4);
                    chanceToHitMod  += (attacker.Level / 4);
                }
                else if (weapon.GetWeaponSkillUsed() == (int)DaggerfallConnect.DFCareer.ProficiencyFlags.MissileWeapons)
                {
                    if (player.RaceTemplate.ID == (int)Entity.Races.WoodElf)
                    {
                        damageModifiers += (attacker.Level / 3);
                        chanceToHitMod  += (attacker.Level / 3);
                    }
                }
                else if (player.RaceTemplate.ID == (int)Entity.Races.Redguard)
                {
                    damageModifiers += (attacker.Level / 3);
                    chanceToHitMod  += (attacker.Level / 3);
                }
            }

            // Apply strength modifier for player or for AI characters using weapons.
            // The in-game display of the strength modifier in Daggerfall is incorrect. It is actually ((STR - 50) / 5).
            if ((attacker == player) || (weapon != null))
            {
                damageModifiers += DamageModifier(attacker.Stats.Strength);
            }

            // Apply material modifier.
            // The in-game display in Daggerfall of weapon damages with material modifiers is incorrect. The material modifier is half of what the display suggests.
            if (weapon != null)
            {
                damageModifiers += weapon.GetWeaponMaterialModifier();
            }

            // Choose struck body part
            int[] bodyParts      = { 0, 0, 1, 1, 1, 2, 2, 2, 3, 3, 3, 3, 4, 4, 4, 4, 5, 5, 5, 6 };
            int   struckBodyPart = bodyParts[UnityEngine.Random.Range(0, bodyParts.Length)];

            // Check for a successful hit.
            if (CalculateSuccessfulHit(attacker, target, chanceToHitMod, weapon, struckBodyPart) == true)
            {
                // 0 damage is possible. Creates no blood splash.
                damageResult = Mathf.Max(0, (baseDamage + damageModifiers));
            }

            // If damage was done by a weapon, damage condition of weapon and armor of hit body part
            // In classic, shields are never damaged because the item in the equip slot of the hit
            // body part is all that is handled.
            // Here, if an equipped shield covered the hit body part, it takes damage instead.
            if (weapon != null && damageResult > 0)
            {
                weapon.DamageThroughPhysicalHit(damageResult, attacker);

                Items.DaggerfallUnityItem shield = target.ItemEquipTable.GetItem(Items.EquipSlots.LeftHand);
                bool shieldTakesDamage           = false;
                if (shield != null)
                {
                    Items.BodyParts[] protectedBodyParts = shield.GetShieldProtectedBodyParts();

                    for (int i = 0; (i < protectedBodyParts.Length) && !shieldTakesDamage; i++)
                    {
                        if (protectedBodyParts[i] == (Items.BodyParts)struckBodyPart)
                        {
                            shieldTakesDamage = true;
                        }
                    }
                }

                if (shieldTakesDamage)
                {
                    shield.DamageThroughPhysicalHit(damageResult, target);
                }
                else
                {
                    Items.EquipSlots          hitSlot = Items.DaggerfallUnityItem.GetEquipSlotForBodyPart((Items.BodyParts)struckBodyPart);
                    Items.DaggerfallUnityItem armor   = target.ItemEquipTable.GetItem(hitSlot);
                    if (armor != null)
                    {
                        armor.DamageThroughPhysicalHit(damageResult, target);
                    }
                }
            }

            // If attack was by player or weapon-based, end here
            if ((attacker == player) || (weapon != null))
            {
                return(damageResult);
            }
            // Handle multiple attacks by AI characters.
            else
            {
                if (AIAttacker.MobileEnemy.MaxDamage2 != 0 && (CalculateSuccessfulHit(attacker, target, chanceToHitMod, weapon, struckBodyPart) == true))
                {
                    baseDamage    = UnityEngine.Random.Range(AIAttacker.MobileEnemy.MinDamage2, AIAttacker.MobileEnemy.MaxDamage2 + 1);
                    damageResult += Mathf.Max(0, (baseDamage + damageModifiers));
                }
                if (AIAttacker.MobileEnemy.MaxDamage3 != 0 && (CalculateSuccessfulHit(attacker, target, chanceToHitMod, weapon, struckBodyPart) == true))
                {
                    baseDamage    = UnityEngine.Random.Range(AIAttacker.MobileEnemy.MinDamage3, AIAttacker.MobileEnemy.MaxDamage3 + 1);
                    damageResult += Mathf.Max(0, (baseDamage + damageModifiers));
                }
                return(damageResult);
            }
        }
Пример #24
0
    private void Awake()
    {
        controls = new FPSPlayerControls();

        // Fire controls
        playerActions = controls.Player;
        playerActions.Fire.performed += ctx => { isFiring = true; };
        playerActions.Fire.canceled  += ctx => { isFiring = false; };

        // Movement controls
        playerActions.Move.performed += ctx =>
        {
            isMoving = true;
        };
        playerActions.Move.canceled += ctx =>
        {
            isMoving = false;
        };
        playerActions.Jump.performed += ctx =>
        {
            isJumping = true;
        };
        playerActions.Jump.canceled += ctx =>
        {
            isJumping = false;
        };
        playerActions.Dash.performed += ctx =>
        {
            if (canDash)
            {
                StartCoroutine(Dash());
            }
        };
        playerActions.Interact.performed += ctx =>
        {
            if (interactionTarget)
            {
                interactionTarget.started += () =>
                {
                    Cursor.lockState = CursorLockMode.None;
                    Cursor.visible   = true;
                    playerActions.Disable();
                };
                interactionTarget.finished += () =>
                {
                    Cursor.lockState = CursorLockMode.Locked;
                    Cursor.visible   = false;
                    playerActions.Enable();
                };
                interactionTarget.HandleInteraction(gameObject);
            }
        };

        // Swap Weapon Controls
        playerActions.ScrollWeapon.performed += ctx => {
            if (!isSwitchingWeapon)
            {
                var input = ctx.ReadValue <Vector2>();
                var scrollDirectionRaw = Mathf.RoundToInt(input.y == 0 ? input.x : input.y);
                StartCoroutine(SwitchingWeaponDelay(weaponSwitchDuration));
                OnWeaponScroll?.Invoke(Mathf.RoundToInt(scrollDirectionRaw));
                activeWeapon = weaponSwitcher.GetActiveWeapon()?.GetComponent <FPSWeapon>();
            }
        };
    }
Пример #25
0
    void SelectWeapon()
    {
        if (Input.GetKeyDown(KeyCode.Alpha1))
        {
            ak47Back.SetActive(true);
            m4a1Back.SetActive(true);
            ammo.value = PlayerPrefs.GetInt("DEAGLE");

            if (!handsWeapon_Manager.weapons [0].activeInHierarchy)
            {
                for (int i = 0; i < handsWeapon_Manager.weapons.Length; i++)
                {
                    handsWeapon_Manager.weapons[i].SetActive(false);
                }
                current_hands_Weapon = null;
                handsWeapon_Manager.weapons[0].SetActive(true);
                if (isFpsActive)
                {
                    current_hands_Weapon = handsWeapon_Manager.weapons[0].GetComponent <FPSHandsWeapon>();
                }
            }
            if (!weapon_Manager.weapons [0].activeInHierarchy)
            {
                for (int i = 0; i < weapon_Manager.weapons.Length; i++)
                {
                    weapon_Manager.weapons[i].SetActive(false);
                }

                current_Weapon = null;
                weapon_Manager.weapons[0].SetActive(true);
                current_Weapon = weapon_Manager.weapons[0].GetComponent <FPSWeapon> ();
                playerAnimations.ChangeController(true);
            }
        }
        if (Input.GetKeyDown(KeyCode.Alpha2))
        {
            ak47Back.SetActive(false);
            m4a1Back.SetActive(true);
            ammo.value = PlayerPrefs.GetInt("AK47");
            if (!handsWeapon_Manager.weapons [1].activeInHierarchy)
            {
                for (int i = 0; i < handsWeapon_Manager.weapons.Length; i++)
                {
                    handsWeapon_Manager.weapons[i].SetActive(false);
                }
                current_hands_Weapon = null;
                handsWeapon_Manager.weapons[1].SetActive(true);
                if (isFpsActive)
                {
                    current_hands_Weapon = handsWeapon_Manager.weapons[1].GetComponent <FPSHandsWeapon>();
                }
            }
            if (!weapon_Manager.weapons [1].activeInHierarchy)
            {
                for (int i = 0; i < weapon_Manager.weapons.Length; i++)
                {
                    weapon_Manager.weapons[i].SetActive(false);
                }

                current_Weapon = null;
                weapon_Manager.weapons[1].SetActive(true);
                current_Weapon = weapon_Manager.weapons[1].GetComponent <FPSWeapon> ();
                playerAnimations.ChangeController(false);
            }
        }
        if (Input.GetKeyDown(KeyCode.Alpha3))
        {
            ak47Back.SetActive(true);
            m4a1Back.SetActive(false);
            ammo.value = PlayerPrefs.GetInt("M4A1");

            if (!handsWeapon_Manager.weapons [2].activeInHierarchy)
            {
                for (int i = 0; i < handsWeapon_Manager.weapons.Length; i++)
                {
                    handsWeapon_Manager.weapons[i].SetActive(false);
                }
                current_hands_Weapon = null;
                handsWeapon_Manager.weapons[2].SetActive(true);
                if (isFpsActive)
                {
                    current_hands_Weapon = handsWeapon_Manager.weapons[2].GetComponent <FPSHandsWeapon>();
                }
            }
            if (!weapon_Manager.weapons [2].activeInHierarchy)
            {
                for (int i = 0; i < weapon_Manager.weapons.Length; i++)
                {
                    weapon_Manager.weapons[i].SetActive(false);
                }
                current_Weapon = null;
                weapon_Manager.weapons[2].SetActive(true);
                current_Weapon = weapon_Manager.weapons[2].GetComponent <FPSWeapon> ();
                playerAnimations.ChangeController(false);
            }
        }
    }
Пример #26
0
    void Start()
    {
        firstPerson_view  = transform.Find("FPS VIEW").transform;
        charController    = GetComponent <CharacterController> ();
        speed             = walkSpeed;
        is_moving         = false;
        isShooting.value  = 1;
        reloadNoification = GameObject.Find("ReloadNotification");
        reloadNoification.GetComponent <Animator>().enabled = false;
        reloadNoification.transform.localScale = Vector3.zero;
        rayDistance = charController.height * 0.5f + charController.radius;
        default_controllerHeight = charController.height;
        default_CamPos           = firstPerson_view.localPosition;
        playerAnimations         = GetComponent <FPSPlayerAnimations>();
        weapon_Manager.weapons[0].SetActive(true);
        current_Weapon = weapon_Manager.weapons[0].GetComponent <FPSWeapon>();
        handsWeapon_Manager.weapons[0].SetActive(true);
        if (isFpsActive)
        {
            current_hands_Weapon = handsWeapon_Manager.weapons[0].GetComponent <FPSHandsWeapon> ();
        }



        // if(isLocalPlayer) {
        //     playerHolder.layer = LayerMask.NameToLayer ("Player");

        //     foreach (Transform child in playerHolder.transform) {
        //         child.gameObject.layer = LayerMask.NameToLayer ("Player");
        //     }
        //     for(int i = 0; i < weapons_FPS.Length; i++) {
        //         weapons_FPS [i].layer = LayerMask.NameToLayer("Player");
        //     }
        //     weaponsHolder.layer = LayerMask.NameToLayer ("Enemy");

        //     foreach(Transform child in weaponsHolder.transform) {
        //         child.gameObject.layer = LayerMask.NameToLayer("Enemy");
        //     }

        // }
        // if(!isLocalPlayer) {
        //     playerHolder.layer = LayerMask.NameToLayer ("Enemy");

        //     foreach (Transform child in playerHolder.transform) {
        //         child.gameObject.layer = LayerMask.NameToLayer ("Enemy");
        //     }
        //     for(int i = 0; i < weapons_FPS.Length; i++) {
        //         weapons_FPS [i].layer = LayerMask.NameToLayer("Enemy");
        //     }
        //     weaponsHolder.layer = LayerMask.NameToLayer ("Player");

        //     foreach(Transform child in weaponsHolder.transform) {
        //         child.gameObject.layer = LayerMask.NameToLayer("Player");
        //     }
        // }

        if (!isLocalPlayer)
        {
            for (int i = 0; i < mouseLooks.Length; i++)
            {
                mouseLooks[i].enabled = false;
            }
        }
        mainCam = transform.Find("FPS VIEW").Find("FPS Camera").GetComponent <Camera>();
        mainCam.gameObject.SetActive(false);

        if (!isLocalPlayer)
        {
            tag = "Enemy";
            for (int i = 0; i < playererRendered.materials.Length; i++)
            {
                /// RANDOM SKIN IN FUTURE;
            }
        }
    }
Пример #27
0
    void Start () {
        // Find is not optimal
        firstPerson_View = transform.Find ("FPS View").transform;
        charController = GetComponent<CharacterController> ();
        speed = walkSpeed;
        isMoving = false;

        rayDistance = charController.height * 0.5f + charController.radius;
        default_ControllerHeight = charController.height;
        default_CameraPosition = firstPerson_View.localPosition;

        playerAnimations = GetComponent<FPSPlayerAnimations> ();

        weaponManager.weapons[0].SetActive (true);
        currentWeapon = weaponManager.weapons[0].GetComponent<FPSWeapon> ();

        handsWeaponManager.weapons[0].SetActive (true);
        currentHandsWeapon = handsWeaponManager.weapons[0].GetComponent<FPSHandsWeapon> ();

        if (isLocalPlayer) {
            playerHolder.layer = LayerMask.NameToLayer ("Player");

            foreach (Transform child in playerHolder.transform) {
                child.gameObject.layer = LayerMask.NameToLayer ("Player");
            }

            for (int i = 0; i < weaponsFPS.Length; i++) {
                weaponsFPS[i].layer = LayerMask.NameToLayer ("Player");
            }

            weaponsHolder.layer = LayerMask.NameToLayer ("Enemy");

            foreach (Transform child in weaponsHolder.transform) {
                child.gameObject.layer = LayerMask.NameToLayer ("Enemy");
            }
        }

        if (!isLocalPlayer) {
            playerHolder.layer = LayerMask.NameToLayer ("Enemy");

            foreach (Transform child in playerHolder.transform) {
                child.gameObject.layer = LayerMask.NameToLayer ("Enemy");
            }

            for (int i = 0; i < weaponsFPS.Length; i++) {
                weaponsFPS[i].layer = LayerMask.NameToLayer ("Enemy");
            }

            weaponsHolder.layer = LayerMask.NameToLayer ("Player");

            foreach (Transform child in weaponsHolder.transform) {
                child.gameObject.layer = LayerMask.NameToLayer ("Player");
            }
        }

        if (!isLocalPlayer) {
            for (int i = 0; i < mouseLook.Length; i++) {
                mouseLook[i].enabled = false;
            }
        }

        // Deactivates all FPS Cameras
        mainCam = transform.Find ("FPS View").Find ("FPS Camera").GetComponent<Camera> ();
        mainCam.gameObject.SetActive (false);

        if (!isLocalPlayer) {
            for (int i = 0; i < playerRenderer1.materials.Length; i++) {
                //playerRenderer1.materials[i].color = playerColors[i];
                //playerRenderer2.materials[i].color = playerColors[i];
                //playerRenderer3.materials[i].color = playerColors[i];

                // Players on server are set to delta skin
                playerRenderer1.material = delta;
                playerRenderer2.material = delta;
                playerRenderer3.material = delta;
            }
        } else {
            // Local player is set to swat skin
            playerRenderer1.material = swat;
            playerRenderer2.material = swat;
            playerRenderer3.material = swat;
        }

    }
Пример #28
0
    private void SelectWeapon()
    {
        if (Input.GetKeyDown(KeyCode.Alpha1))
        {
            isReloading = false; // instant refresh the cooldown of gun
            if (!handsWeaponManager.weapons[0].activeInHierarchy)
            {
                for (int i = 0; i < handsWeaponManager.weapons.Length; i++)
                {
                    handsWeaponManager.weapons[i].SetActive(false);
                }

                currentHandsWeapon = null;
                handsWeaponManager.weapons[0].SetActive(true);
                currentHandsWeapon = handsWeaponManager.weapons[0].GetComponent <FPSHandsWeapon>();
                if (_audioSource.clip != currentHandsWeapon.drawClip)
                {
                    _audioSource.clip = currentHandsWeapon.drawClip;
                }

                _audioSource.Play();
            }

            if (!weaponManager.weapons[0].activeInHierarchy)
            {
                for (int i = 0; i < weaponManager.weapons.Length; i++)
                {
                    weaponManager.weapons[i].SetActive(false);
                }

                currentWeapon = null;
                weaponManager.weapons[0].SetActive(true);
                currentWeapon = weaponManager.weapons[0].GetComponent <FPSWeapon>();
                playerAnimation.ChangeController(true);
            }
        }

        if (Input.GetKeyDown(KeyCode.Alpha2))
        {
            isReloading = false; // instant refresh the cooldown of gun

            if (!handsWeaponManager.weapons[1].activeInHierarchy)
            {
                for (int i = 0; i < handsWeaponManager.weapons.Length; i++)
                {
                    handsWeaponManager.weapons[i].SetActive(false);
                }

                currentWeapon = null;
                handsWeaponManager.weapons[1].SetActive(true);
                currentHandsWeapon = handsWeaponManager.weapons[1].GetComponent <FPSHandsWeapon>();
                playerAnimation.ChangeController(false);
                if (_audioSource.clip != currentHandsWeapon.drawClip)
                {
                    _audioSource.clip = currentHandsWeapon.drawClip;
                }

                _audioSource.Play();
            }

            if (!weaponManager.weapons[1].activeInHierarchy)
            {
                for (int i = 0; i < weaponManager.weapons.Length; i++)
                {
                    weaponManager.weapons[i].SetActive(false);
                }

                currentWeapon = null;
                weaponManager.weapons[1].SetActive(true);
                currentWeapon = weaponManager.weapons[1].GetComponent <FPSWeapon>();
                playerAnimation.ChangeController(true);
            }
        }

        if (Input.GetKeyDown(KeyCode.Alpha3))
        {
            isReloading = false; // instant refresh the cooldown of gun

            if (!handsWeaponManager.weapons[2].activeInHierarchy)
            {
                for (int i = 0; i < handsWeaponManager.weapons.Length; i++)
                {
                    handsWeaponManager.weapons[i].SetActive(false);
                }

                currentHandsWeapon = null;
                handsWeaponManager.weapons[2].SetActive(true);
                currentHandsWeapon = handsWeaponManager.weapons[2].GetComponent <FPSHandsWeapon>();
                playerAnimation.ChangeController(false);
                if (_audioSource.clip != currentHandsWeapon.drawClip)
                {
                    _audioSource.clip = currentHandsWeapon.drawClip;
                }

                _audioSource.Play();
            }

            if (!weaponManager.weapons[2].activeInHierarchy)
            {
                for (int i = 0; i < weaponManager.weapons.Length; i++)
                {
                    weaponManager.weapons[i].SetActive(false);
                }

                currentWeapon = null;
                weaponManager.weapons[2].SetActive(true);
                currentWeapon = weaponManager.weapons[2].GetComponent <FPSWeapon>();
                playerAnimation.ChangeController(false);
            }
        }
    }
Пример #29
0
    // Use this for initialization
    void Start()
    {
        firstPersonView = transform.Find("FPS View").transform;

        charController = GetComponent <CharacterController> ();

        speed = walkSpeed;

        isMoving = false;

        rayDistance = charController.height * 0.5f + charController.radius;

        defaultControllerHeight = charController.height;

        defaultCamPos = firstPersonView.localPosition;

        playerAnimations = GetComponent <FPSPlayerAnimations> ();

        weaponsManager.weapons [0].SetActive(true);

        currentWeapon = weaponsManager.weapons [0].GetComponent <FPSWeapon> ();

        handsWeaponsManager.weapons [0].SetActive(true);

        currentHandsWeapon = handsWeaponsManager.weapons [0].GetComponent <FPSHandsWeapon> ();

        // Change the view based on whether or not the current player
        // is a local player or a remote player
        if (isLocalPlayer)
        {
            playerHolder.layer = LayerMask.NameToLayer("Player");

            foreach (Transform child in playerHolder.transform)
            {
                child.gameObject.layer = LayerMask.NameToLayer("Player");
            }

            for (int i = 0; i < weaponsFPS.Length; i++)
            {
                weaponsFPS [i].layer = LayerMask.NameToLayer("Player");
            }

            weaponsHolder.layer = LayerMask.NameToLayer("Enemy");

            foreach (Transform child in weaponsHolder.transform)
            {
                child.gameObject.layer = LayerMask.NameToLayer("Enemy");
            }
        }
        else
        {
            playerHolder.layer = LayerMask.NameToLayer("Enemy");

            foreach (Transform child in playerHolder.transform)
            {
                child.gameObject.layer = LayerMask.NameToLayer("Enemy");
            }

            for (int i = 0; i < weaponsFPS.Length; i++)
            {
                weaponsFPS [i].layer = LayerMask.NameToLayer("Enemy");
            }

            weaponsHolder.layer = LayerMask.NameToLayer("Player");

            foreach (Transform child in weaponsHolder.transform)
            {
                child.gameObject.layer = LayerMask.NameToLayer("Player");
            }
        }

        if (!isLocalPlayer)
        {
            for (int i = 0; i < mouseLook.Length; i++)
            {
                mouseLook [i].enabled = false;
            }
        }

        mainCam = transform.Find("FPS View").Find("FPS Camera").GetComponent <Camera> ();
        mainCam.gameObject.SetActive(false);
    }