Exemplo n.º 1
0
    public void LoadSecondaryAmmoType(bool isSilent)
    {
        int wep16index = WeaponFire.Get16WeaponIndexFromConstIndex(weaponIndex);

        // Put bullets into the magazine
        if (WeaponAmmo.a.wepAmmoSecondary[wep16index] >= Const.a.magazinePitchCountForWeapon2[wep16index])
        {
            currentMagazineAmount2[wep16index] = Const.a.magazinePitchCountForWeapon2[wep16index];
        }
        else
        {
            currentMagazineAmount2[wep16index] = WeaponAmmo.a.wepAmmoSecondary[wep16index];
        }

        // Take bullets out of the ammo stockpile
        WeaponAmmo.a.wepAmmoSecondary[wep16index] -= currentMagazineAmount2[wep16index];

        if (!isSilent)
        {
            if (wep16index == 0 || wep16index == 3)
            {
                SFX.PlayOneShot(ReloadInStyleSFX);
            }
            else
            {
                SFX.PlayOneShot(ReloadSFX);
            }
        }

        // Update the counter on the HUD
        MFDManager.a.UpdateHUDAmmoCounts(currentMagazineAmount[wep16index]);
    }
Exemplo n.º 2
0
        public static void PlayWeaponFired(Team team, WeaponFire weapon)
        {
            switch (weapon.Weapon.Name)
            {
            case "Flashbang":
                PlayFlashbangThrowed(team);
                break;

            case "Smoke":
                PlaySmokeThrowed(team);
                break;

            case "He Grenade":
                PlayHeGrenadeThrowed(team);
                break;

            case "Decoy":
                PlayDecoyThrowed(team);
                break;

            case "Molotov":
            case "Incendiary":
                PlayMolotovThrowed(team);
                break;
            }
        }
Exemplo n.º 3
0
    // Update is called once per frame
    void Update()
    {
        if (!canAttack)
        {
            return;
        }

        if (isAutomated)
        {
            return;
        }

        if (inputDevice.LeftTrigger.WasPressed && !GUN_DISABLED)
        {
            StartCoroutine(AttackCooldown());
            GameObject spawnedGun = SpawnWeapon(gun, false, false);

            WeaponFire weaponFire = spawnedGun.GetComponent <WeaponFire> ();

            weaponFire.playerInv = this.GetComponent <PlayerInventory> ();
            weaponFire.Fire(GetComponent <PlayerTeamInfo>().GetTeam());
        }
        else if (inputDevice.Action3.WasPressed)
        {
            AudioSource.PlayClipAtPoint(swordSwingSound, Camera.main.gameObject.transform.position);
            StartCoroutine(AttackCooldown());
            SpawnWeapon(sword, true, true);
        }
    }
    void Update()
    {
        weapon = GameObject.FindObjectOfType <WeaponFire>();

        int previousSelectedWeapon = selectedWeapon;

        if (weapon == GameObject.FindObjectOfType <RevolverFire>())
        {
            selectedWeapon = 0;
        }

        if (weapon == GameObject.FindObjectOfType <RepeaterFire>())
        {
            selectedWeapon = 1;
        }

        if (weapon == GameObject.FindObjectOfType <ShotgunFire>())
        {
            selectedWeapon = 2;
        }

        if (weapon == GameObject.FindObjectOfType <BowFire>())
        {
            selectedWeapon = 3;
        }

        if (previousSelectedWeapon != selectedWeapon)
        {
            SelectWeapon();
        }

        if (selectedWeapon == 0)
        {
            CheckRemainingRevolverShots();
        }
        if (selectedWeapon == 1)
        {
            CheckRemainingRepeaterShots();
        }
        if (selectedWeapon == 2)
        {
            CheckRemainingShotgunShots();
        }
        if (selectedWeapon == 3)
        {
            CheckRemainingBowShots();
        }

        int sumOfBullets = weapon.bulletsInMagazine + weapon.additionalBullets;

        if (selectedWeapon == 3)
        {
            text.text = "" + sumOfBullets; //"Arrows: \n" + sumOfBullets;
        }
        else
        {
            text.text = weapon.bulletsInMagazine + "/" + weapon.additionalBullets; //"Bullets in the magazine: \n" + weapon.bulletsInMagazine + "/" + weapon.additionalBullets;
        }
    }
Exemplo n.º 5
0
    // Use this for initialization
    void Start()
    {
        if (!controller)	controller	=	gameObject.GetComponentInParentRecursive<PlatformerCharacter2D>();
        if (!weaponFire)	weaponFire	=	gameObject.GetComponent<WeaponFire>();
        if (!camera)		mainCamera	=	Camera.main;
        if (!arm)			arm			=	transform;

        _view = controller.GetComponent<PhotonView>();
    }
Exemplo n.º 6
0
 public void SetValue()
 {
     index    = WeaponFire.Get16WeaponIndexFromConstIndex(currentWeapon.weaponIndex);
     ener_min = Const.a.energyDrainLowForWeapon[index];
     ener_max = Const.a.energyDrainHiForWeapon[index];
     val      = slideS.value / 100f;
     val      = (val * (ener_max - ener_min)) + ener_min;
     currentWeapon.weaponEnergySetting[index] = val;
 }
Exemplo n.º 7
0
    // Used to automate swing attack for tutorial demonstration
    public void Swing()
    {
        StartCoroutine(AttackCooldown());
        GameObject spawnedGun = SpawnWeapon(gun, false, false);

        WeaponFire weaponFire = spawnedGun.GetComponent <WeaponFire>();

        weaponFire.playerInv = this.GetComponent <PlayerInventory> ();
        weaponFire.Fire(GetComponent <PlayerTeamInfo>().GetTeam());
    }
Exemplo n.º 8
0
    public void onItemClick()
    {
        ItemDrag   itemDrag = gameObject.transform.Find("ItemImage").GetComponent <ItemDrag>();
        GameObject player   = GameObject.Find("Player");

        if (player == null)
        {
            Debug.Log("player null");
        }
        ItemBaseClass item = itemDrag.Item;

        Debug.Log("CLICK" + item);
        Debug.Log(item.Name + " equipped");
        if (item.name.Equals("Pistol"))
        {
            WeaponFire Wp = GameObject.Find("Player").GetComponentInChildren <WeaponFire>();
            if (Wp == null)
            {
                Debug.Log("weapon null");
            }
            else
            {
                Debug.Log("pistol equipped");
            }
            Wp.rateOfFire     = 0;
            Wp.damage         = 50;
            Wp.weaponEquipped = true;
        }
        if (item.name.Equals("MiniGun"))
        {
            WeaponFire Wp = GameObject.Find("Player").GetComponentInChildren <WeaponFire>();
            if (Wp == null)
            {
                Debug.Log("weapon null");
            }
            else
            {
                Debug.Log("minigun equipped");
            }
            Wp.rateOfFire     = 20;
            Wp.damage         = 5;
            Wp.weaponEquipped = true;
        }
        else
        {
            WeaponFire Wp = GameObject.Find("Player").GetComponentInChildren <WeaponFire>();
            if (Wp == null)
            {
                Debug.Log("weapon null");
            }
            Wp.weaponEquipped = false;
        }
        inventory.UseItem(item);
        //		item.OnUse();
    }
Exemplo n.º 9
0
        private void Awake()
        {
            Assert.IsNotNull(this.weaponData, "Missing asset");
            Assert.IsNotNull(this.weaponEndPoint, "Missing asset");

            this.pressFire   = this.NewFireType(this.weaponData.PressFireType);
            this.holdFire    = this.NewFireType(this.weaponData.HoldFireType);
            this.releaseFire = this.NewFireType(this.weaponData.ReleaseFireType);

            Assert.IsNotNull(this.pressFire, "Missing asset");
            Assert.IsNotNull(this.holdFire, "Missing asset");
            Assert.IsNotNull(this.releaseFire, "Missing asset");
        }
Exemplo n.º 10
0
 void Awake()
 {
     shipP1Prefab    = GameObject.FindGameObjectWithTag("ShipP1");
     shipP2Prefab    = GameObject.FindGameObjectWithTag("ShipP2");
     _guiP1Object    = transform.Find("GUIP1");
     _guiP2Object    = transform.Find("GUIP2");
     _guiP1          = _guiP1Object.GetComponent <Text>();
     _guiP2          = _guiP2Object.GetComponent <Text>();
     _weaponFireP1   = shipP1Prefab.GetComponent <WeaponFire>();
     _weaponFireP2   = shipP2Prefab.GetComponent <WeaponFire>();
     _xpCollectionP1 = shipP1Prefab.GetComponent <XPCollection>();
     _xpCollectionP2 = shipP2Prefab.GetComponent <XPCollection>();
 }
Exemplo n.º 11
0
    public void OnWeaponFired(object sender, object e)
    {
        if (!_parser.MatchStarted)
        {
            return;
        }
        var eventArgs = (WeaponFiredEventArgs)e;
        var parser    = (DemoParser)sender;

        if (NadePlaybackManager.Instance.AddNadeFrame(parser, eventArgs))
        {
            return;
        }

        var shooter = eventArgs.Shooter;

        var weaponFire = new WeaponFire()
        {
            ShooterSteamID  = shooter.SteamID.ToString(),
            Weapon          = new PartialWeapon(eventArgs.Weapon),
            ShooterPosition = new Vector3(-shooter.Position.X, shooter.Position.Z, -shooter.Position.Y),
            ViewX           = shooter.ViewDirectionX,
            ViewY           = shooter.ViewDirectionY
        };

        WeaponFireFrame frame = null;

        if (PlaybackManager.Instance.WeaponFiredFrames.Any())
        {
            frame = PlaybackManager.Instance.WeaponFiredFrames.Last();
        }

        if (frame == null || frame.Tick != parser.CurrentTick)
        {
            frame = new WeaponFireFrame()
            {
                Tick        = parser.CurrentTick,
                WeaponFires = new List <WeaponFire>()
                {
                    weaponFire
                }
            };
            PlaybackManager.Instance.WeaponFiredFrames.Add(frame);
        }
        else
        {
            frame.WeaponFires.Add(weaponFire);
        }
    }
Exemplo n.º 12
0
    void SelectWeapon()
    {
        int i = 0;

        foreach (Transform weapon in transform)
        {
            if (i == selectedWeapon)
            {
                weapon.gameObject.SetActive(true);
            }
            else
            {
                weapon.gameObject.SetActive(false);
            }
            i++;
        }

        weaponScript = GameObject.FindObjectOfType <WeaponFire>();
        weaponScript.SetBullet();
    }
Exemplo n.º 13
0
    public void Reload()
    {
        int wep16index = WeaponFire.Get16WeaponIndexFromConstIndex(weaponIndex);

        if (weaponIsAlternateAmmo)
        {
            if (currentMagazineAmount2[wep16index] == Const.a.magazinePitchCountForWeapon2[wep16index])
            {
                Const.sprint("Current weapon magazine already full.", owner);
                return;
            }

            if (WeaponAmmo.a.wepAmmoSecondary[wep16index] <= 0)
            {
                Const.sprint("No more of current ammo type to load.", owner);
                return;
            }
            Unload(true);
            LoadSecondaryAmmoType(false);
        }
        else
        {
            if (currentMagazineAmount[wep16index] == Const.a.magazinePitchCountForWeapon[wep16index])
            {
                Const.sprint("Current weapon magazine already full.", owner);
                return;
            }

            if (WeaponAmmo.a.wepAmmo[wep16index] <= 0)
            {
                Const.sprint("No more of current ammo type to load.", owner);
                return;
            }

            Unload(true);
            LoadPrimaryAmmoType(false);
        }
    }
    public WeaponFireGraphics CreateWeaponFireGraphics(WeaponFire weaponFire, Vector3 position, PlaybackMode playbackMode)
    {
        var weaponFireClone = Instantiate(WeaponFirePrefab);

        var weaponGraphics = weaponFireClone.GetComponent <WeaponFireGraphics>();

        weaponGraphics.Direction = playbackMode == PlaybackMode.ThreeD
            ? DemoInfoHelper.ViewAnglesToVector3(weaponFire.ViewX, weaponFire.ViewY)
            : DemoInfoHelper.ViewAnglesToVector3(weaponFire.ViewX, 0);

        weaponGraphics.HasEndPoint = false;

        position += PlayersManager.HeadOffset;

        if (playbackMode == PlaybackMode.TwoD)
        {
            position.y = 0.3f;
        }

        weaponFireClone.transform.position = weaponGraphics.StartPoint = position;

        return(weaponGraphics);
    }
Exemplo n.º 15
0
    public void Unload(bool isSilent)
    {
        int wep16index = WeaponFire.Get16WeaponIndexFromConstIndex(weaponIndex);

        // Take bullets out of the clip, put them back into the ammo stockpile, then zero out the clip amount, did I say clip?  I mean magazine but whatever
        if (weaponIsAlternateAmmo)
        {
            WeaponAmmo.a.wepAmmoSecondary[wep16index] += currentMagazineAmount2[wep16index];
            currentMagazineAmount2[wep16index]         = 0;
        }
        else
        {
            WeaponAmmo.a.wepAmmo[wep16index] += currentMagazineAmount[wep16index];
            currentMagazineAmount[wep16index] = 0;
        }
        if (!isSilent)
        {
            SFX.PlayOneShot(ReloadSFX);
        }

        // Update the counter on the HUD
        MFDManager.a.UpdateHUDAmmoCounts(currentMagazineAmount[wep16index]);
    }
Exemplo n.º 16
0
    void Inventory_ItemUsed(object sender, InventoryEventArgs e)
    {
        ItemBaseClass item = e.Item;

        weapon.sprite = item.Image;
        GameObject player = GameObject.Find("Player");
        WeaponFire Wp     = player.GetComponent <WeaponFire>();

        Debug.Log(item.Name + " equipped");
        if (item.name.Equals("Pistol"))
        {
            Debug.Log("pistol equipped");
            Wp.UpdateWeapon(50, 0, true);
        }
        if (item.name.Equals("MiniGun"))
        {
            Debug.Log("minigun equipped");
            Wp.UpdateWeapon(5, 10, true);
        }
        else
        {
            Wp.UpdateWeapon(0, 0, false);
        }
    }
Exemplo n.º 17
0
    // Update is called once per frame
    void Update()
    {
        toPlayer     = playerGO.transform.position - bodyPart.transform.position;
        toPlayer.y   = transform.position.y;
        angleBetween = Vector3.Angle(bodyPart.transform.forward, toPlayer);

        if (Physics.Raycast(transform.position, toPlayer, out RaycastHit castHit, Mathf.Infinity, maskPlayerTerrain))
        {
            if (castHit.collider.tag == "Player")
            {
                if (angleBetween <= maxAngle)
                {
                    //for each weapon, if toPlayer.Magnitude < weaponrange, weapon.Fire()

                    foreach (GameObject indivWeapon in tankCore.weaponParts)
                    {
                        if (indivWeapon != null)
                        {
                            indivFire = indivWeapon.GetComponent <WeaponFire>();
                            if (indivFire.maxRange >= toPlayer.magnitude)
                            {
                                indivFire.Fire(playerGO.transform.position);
                            }
                        }
                    }
                }
                else
                {
                    //bodyPart.transform.rotation = Quaternion.Euler( Vector3.RotateTowards(bodyPart.transform.forward, toPlayer, tankCore.turretRotateSpeed,0));
                    //bodyPart.transform.rotation.SetLookRotation(Vector3.RotateTowards(bodyPart.transform.rotation.eulerAngles, toPlayer, tankCore.turretRotateSpeed * Time.deltaTime, 0), bodyPart.transform.up);
                    //bodyPart.transform.rotation = Quaternion.Euler(new Vector3(bodyPart.transform.rotation.eulerAngles.x, bodyPart.transform.rotation.eulerAngles.y + 1, bodyPart.transform.rotation.eulerAngles.z));
                    bodyPart.transform.rotation = Quaternion.RotateTowards(bodyPart.transform.rotation, Quaternion.LookRotation(toPlayer, Vector3.up), tankCore.turretRotateSpeed * Time.deltaTime);
                }
            }
        }
    }
Exemplo n.º 18
0
    // Update is called once per frame
    void FixedUpdate()
    {
        //Get the rb2d for the player
        rb2d     = GetComponent <Rigidbody2D>();
        animator = GetComponent <Animator>();

        //Get the raw input for the input axis
        float moveHorizontal = Input.GetAxisRaw("Horizontal");
        float moveVertical   = Input.GetAxisRaw("Vertical");



        wu = false;
        wd = false;
        wl = false;
        wr = false;


        if (moveHorizontal == 1.0)
        {
            wr = true;
        }
        if (moveHorizontal == -1.0)
        {
            wl = true;
        }
        if (moveVertical == 1.0)
        {
            wu = true;
        }
        if (moveVertical == -1.0)
        {
            wd = true;
        }


        //Get the movement vectore based on input from the player controller
        movement = pctrl.movement_calculator(moveHorizontal, moveVertical);


        //Move the player based on the player's speed/ movement vector, and time between frames.
        rb2d.MovePosition(rb2d.position + movement * speed * Time.fixedDeltaTime);

        // Shooting up
        if (Input.GetKey(KeyCode.UpArrow) || test_key_up)
        {
            au = true;
            WeaponFire weapon = GetComponent <WeaponFire>();
            weapon.set_dmg(damage);
            weapon.set_fire_rate(fire_rate);
            weapon.set_range(range);
            weapon.set_shot_speed(shot_speed);


            if (weapon != null)
            {
                // false because the player is not an enemy
                weapon.AttackUp();
            }
        }
        else
        {
            au = false;
        }

        // Shooting down
        if (Input.GetKey(KeyCode.DownArrow) || test_key_down)
        {
            ad = true;
            WeaponFire weapon = GetComponent <WeaponFire>();
            weapon.set_dmg(damage);
            weapon.set_fire_rate(fire_rate);
            weapon.set_range(range);
            weapon.set_shot_speed(shot_speed);

            if (weapon != null)
            {
                // false because the player is not an enemy
                weapon.AttackDown();
            }
        }
        else
        {
            ad = false;
        }

        // Shooting right
        if (Input.GetKey(KeyCode.RightArrow) || test_key_right)
        {
            ar = true;
            WeaponFire weapon = GetComponent <WeaponFire>();
            weapon.set_dmg(damage);
            weapon.set_fire_rate(fire_rate);
            weapon.set_range(range);
            weapon.set_shot_speed(shot_speed);

            if (weapon != null)
            {
                // false because the player is not an enemy
                weapon.AttackRight();
            }
        }
        else
        {
            ar = false;
        }

        // Shooting left
        if (Input.GetKey(KeyCode.LeftArrow) || test_key_left)
        {
            al = true;
            WeaponFire weapon = GetComponent <WeaponFire>();
            weapon.set_dmg(damage);
            weapon.set_fire_rate(fire_rate);
            weapon.set_range(range);
            weapon.set_shot_speed(shot_speed);

            if (weapon != null)
            {
                // false because the player is not an enemy
                weapon.AttackLeft();
            }
        }
        else
        {
            al = false;
        }

        //Animation controller logic
        //If attacking
        if (au || al || ar || ad)
        {
            //Set the animation bool based on attacking direction

            animator.SetBool("au", au);
            animator.SetBool("al", al);
            animator.SetBool("ar", ar);
            animator.SetBool("ad", ad);

            //move flags are set to false so we play attack and not move animations if attacking
            animator.SetBool("wl", false);
            animator.SetBool("wr", false);
            animator.SetBool("wu", false);
            animator.SetBool("wd", false);
        }
        //else -- not attacking
        else
        {
            animator.SetBool("au", au);
            animator.SetBool("al", al);
            animator.SetBool("ar", ar);
            animator.SetBool("ad", ad);
            animator.SetBool("wl", wl);
            animator.SetBool("wr", wr);
            animator.SetBool("wu", wu);
            animator.SetBool("wd", wd);
        }
    }
Exemplo n.º 19
0
        public void DrawEvent(PositionPoint positionPoint)
        {
            Type type = positionPoint.Event.GetType();

            if (type == typeof(WeaponFire))
            {
                DrawWeapon(positionPoint);
                WeaponFire e = (WeaponFire)positionPoint.Event;
                SoundService.PlayWeaponFired(positionPoint.Team, e);
            }
            else if (type == typeof(FlashbangExplodedEvent))
            {
                DrawFlashbangExploded(positionPoint);
                SoundService.PlayFlashbangExploded();
            }
            else if (type == typeof(SmokeNadeStartedEvent))
            {
                DrawSmokeStarted(positionPoint);
                SoundService.PlaySmokeDetonated();
            }
            else if (type == typeof(SmokeNadeEndedEvent))
            {
                DrawSmokeEnded(positionPoint);
            }
            else if (type == typeof(ExplosiveNadeExplodedEvent))
            {
                DrawExplosiveNadeExploded(positionPoint);
                SoundService.PlayHeExploded();
            }
            else if (type == typeof(MolotovFireStartedEvent))
            {
                DrawMolotovStarted(positionPoint);
                SoundService.PlayMolotovExploded();
            }
            else if (type == typeof(MolotovFireEndedEvent))
            {
                DrawMolotovEnded(positionPoint);
            }
            else if (type == typeof(KillEvent))
            {
                DrawKill(positionPoint);
                SoundService.PlayPlayerKilled(positionPoint.Team);
            }
            else if (type == typeof(DecoyStartedEvent))
            {
                DrawDecoyStarted(positionPoint);
            }
            else if (type == typeof(DecoyEndedEvent))
            {
                DrawDecoyEnded(positionPoint);
                SoundService.PlayDecoyExploded();
            }
            else if (type == typeof(BombPlantedEvent))
            {
                DrawBombPlanted(positionPoint);
                SoundService.PlayBombPlanted();
            }
            else if (type == typeof(BombExplodedEvent))
            {
                DrawBombExploded(positionPoint);
                SoundService.PlayBombExploded();
            }
            else if (type == typeof(BombDefusedEvent))
            {
                DrawBombDefused(positionPoint);
                SoundService.PlayBombDefused();
            }
        }
 void Awake()
 {
     _weaponFire     = GetComponent <WeaponFire>();
     _playerMovement = GetComponent <PlayerMovement>();
 }
Exemplo n.º 21
0
 void Update()
 {
     weapon = GameObject.FindObjectOfType <WeaponFire>();
     //WeaponSwitching.sWeapon.WeaponFire;
     text.text = weapon.GetWeaponInfo();
 }
Exemplo n.º 22
0
    public void Shoot(InputAction.CallbackContext ctx)
    {
        WeaponFire weapon = gameObject.GetComponentInChildren <WeaponFire>();

        weapon.Shoot(ctx);
    }
    //private bool isDead = false;
    // Use this for initialization
    void Start()
    {
        playerMovement = GetComponent<PlayerControl>();
        playerShooting = GetComponentInChildren<WeaponFire>();

        currentHealth = startingHealth;
        currentPower = startingPower;

        deathTimer = Time.deltaTime;
    }
Exemplo n.º 24
0
 private void OnWeaponFire()
 {
     WeaponFire?.Invoke();
 }
 //Sound
 // Use this for initialization
 void Start()
 {
     _rigidbody = GetComponent<Rigidbody2D>();
     playerHealth = GetComponent<PlayerStats> ();
     weaponFire = GetComponentInChildren<WeaponFire> ();
     animator = GetComponent<Animator> ();
 }