void SwitchWeapon(int weaponType) { if (!CanSwitchWeapon()) { return; } int index = weaponType - 1; weaponSwitching = true; if (currentWeapon != null) { currentWeapon.SwitchingOut(); if (currentWeapon.baseWeapon.myType == (WeaponType)weaponType) { index = -1; } // reclickng the same weapon key unequps the weapon for now previousWeapon = GetWeaponByWeaponType(currentWeapon.baseWeapon.myType); } if (index < 0) // setting weapon to none { currentWeapon = null; weaponSwitching = false; } else { SetTool(PlayerTool.None); currentWeapon = GetWeaponByWeaponType((WeaponType)weaponType); } var wpTypeIndex = currentWeapon != null?currentWeapon.WeaponClassIndex() : 0; Battle.BattlePlayerInput.instance.tno.Send("SetWeaponType", Target.AllSaved, (int)wpTypeIndex); }
private void Update() { // MAIN LOOP // for (int i = InstanceList.Count; i-- > 0;) { print("Instance: " + InstanceList[i]); WeaponInstance Instance = InstanceList[i]; print("Design: " + Instance.design); // DO BEHAVIOURS if (Instance.design.HasPropulsion) { DoPropulsion(Instance, DebugTarget); } // CHECK DETONATION CONDITIONS if (CheckCollision(Instance)) { Detonate(Instance); } if (Instance.design.HasAltimiter && CheckAltitude(Instance)) { Detonate(Instance); } if (Instance.design.HasTimer && CheckTimer(Instance)) { Detonate(Instance); } print("Active Weapons: " + InstanceList.Count); } }
public void ChangeWeapon() { _weapon = Commons.RoomGenerator.RoomParameterBuilder.WeaponTemplates[UnityEngine.Random.Range(0, Commons.RoomGenerator.RoomParameterBuilder.WeaponTemplates.Count)] .CreateWeaponInstance(); _renderer.sprite = GetWeapon().Template.Icon; }
protected override void OnFire(WeaponInstance instance, WeaponShooterBase shooter, Vector2 direction) { fireingPointOrigin = shooter.gameObject.transform.position; horizontalDirection = shooter.gameObject.GetComponent <Flippable>().Direction; fireingDirectionOrigin = shooter.GetCurrentAimingDirection(); shooter.StartCoroutine(CoShootBullets(instance, shooter)); }
void UIAmmoWeapon(WeaponInstance wpn) { if (wpn == mainWeapon) { int ammoBackPack = 0; if (wpn.type == WeaponType.AR) { ammoBackPack = backpack.ammoAR; } else if (wpn.type == WeaponType.SG) { ammoBackPack = backpack.ammoSG; } textAmmoMainWpn.text = wpn.bulletInMagazine + " / " + ammoBackPack; } else if (wpn == secondWeapon) { int ammoBackPack = 0; if (wpn.type == WeaponType.AR) { ammoBackPack = backpack.ammoAR; } else if (wpn.type == WeaponType.SG) { ammoBackPack = backpack.ammoSG; } textAmmoSecondWpn.text = wpn.bulletInMagazine + " / " + ammoBackPack; } else if (wpn == pistol) { textAmmoPistol.text = wpn.bulletInMagazine + " / " + backpack.ammoPistol; } }
/// <summary> /// Shoots bullets with identical time between each bullet /// </summary> /// <param name="instance"></param> /// <param name="shooter"></param> /// <param name="direction"></param> /// <returns></returns> private IEnumerator CoShootBullets(WeaponInstance instance, WeaponShooterBase shooter) { for (int i = 0; i < ClusterCount; i++) { foreach (Projectile projectile in AmmunitionList) { //Decide the origin of each bullet Vector2 position = ForceLinear ? fireingPoint : shooter.GetProjectilesSpawnPoint(); Projectile newAmmo = Instantiate( original: projectile, position: position, rotation: Quaternion.identity ); newAmmo.Direction = ForceLinear ? fireingDirectionOrigin : shooter.GetCurrentAimingDirection(); WeaponFireHurtbox hurtbox = newAmmo.GetComponentInChildren <WeaponFireHurtbox>(); hurtbox.Shooter = shooter; hurtbox.Weapon = instance; } //Waiting for next bullet yield return(new WaitForSeconds(WaitTime)); } }
public void EquipWeapon(Weapon w) { EquippedItem = w; using (FileStream fileStream = new FileStream(w.SpritePath, FileMode.Open)) { Texture2D t = Texture2D.FromStream(FlatRedBallServices.GraphicsDevice, fileStream); WeaponInstance.SetTexture(t); } using (Weapon EquippedWeapon = ((Weapon)EquippedItem)) { WeaponInstance.RelativePosition = new Vector3(this.HandPositionX - EquippedWeapon.HandPositionX, this.HandPositionY + EquippedWeapon.HandPositionY, this.Z); switch (EquippedWeapon.Type) { case "Melee": { AttackMethod = AttackMeelee; break; } case "Ranged": { AttackMethod = AttackRanged; break; } } } }
public override void SetItemInstance(ItemInstance instance) { // TODO unsafe itemInstance = instance; _weaponInstance = (WeaponInstance)instance; _data = (WeaponData)instance.Data; }
protected override void OnFire(WeaponInstance instance, WeaponShooterBase shooter, Vector2 direction) { for (int i = 0; i < BlastCount; i++) { Vector3 newAmmoPosition; if (direction == Vector2.right || direction == Vector2.left) { newAmmoPosition = new Vector3 (shooter.GetProjectilesSpawnPoint().x, shooter.GetProjectilesSpawnPoint().y + Height / BlastCount * i); } else { newAmmoPosition = new Vector3 (shooter.GetProjectilesSpawnPoint().x + (Height / BlastCount * i - Height / 2), shooter.GetProjectilesSpawnPoint().y); } Projectile newAmmo = Instantiate( original: Ammunition, position: newAmmoPosition, rotation: Quaternion.identity ); newAmmo.Direction = direction; WeaponFireHurtbox hurtbox = newAmmo.GetComponentInChildren <WeaponFireHurtbox>(); hurtbox.Shooter = shooter; hurtbox.Weapon = instance; } }
bool CheckAltitude(WeaponInstance Instance) // This can be handled with logic on the instance itself { if (Instance.rigidbody.velocity.y <= 0) { return(true); } return(false); }
} // This can be handled with logic on the instance itself // DETONATION CHECKS // bool CheckCollision(WeaponInstance Instance) // This can be handled with logic on the instance itself { if (Instance.collisionDetector.collision != null) { return(true); } return(false); }
/// <summary> /// Shoots bullets with identical time between each bullet /// </summary> /// <param name="instance"></param> /// <param name="shooter"></param> /// <param name="direction"></param> /// <returns></returns> private IEnumerator CoShootBullets(WeaponInstance instance, WeaponShooterBase shooter) { for (int i = 0; i < ClusterCount; i++) { //Decide the origin of each bullet Vector2 position = ForceLinear ? fireingPointOrigin : shooter.GetProjectilesSpawnPoint(); Projectile newAmmo = Instantiate( original: Ammunition, position: position, rotation: Quaternion.identity ); Vector2 Aim = ForceLinear ? fireingDirectionOrigin : shooter.GetCurrentAimingDirection(); // Decides how much each bullet should ne rotated if (Aim == Vector2.left) { newAmmo.transform.Rotate(((90f / ((float)ClusterCount - 1)) * i)); } else if (Aim == Vector2.right) { newAmmo.transform.Rotate(((90f / ((float)ClusterCount - 1)) * i) * -1); } else if (Aim == Vector2.up) { if (horizontalDirection == Direction1D.Left) { newAmmo.transform.Rotate(((180f / ((float)ClusterCount - 1)) * i) * -1 + 90); } else { newAmmo.transform.Rotate(((-180f / ((float)ClusterCount - 1)) * i) * -1 - 90); } } else if (Aim == Vector2.down) { if (horizontalDirection == Direction1D.Left) { newAmmo.transform.Rotate(((-180f / ((float)ClusterCount - 1)) * i) * -1 + 90); } else { newAmmo.transform.Rotate(((180f / ((float)ClusterCount - 1)) * i) * -1 - 90); } } WeaponFireHurtbox hurtbox = newAmmo.GetComponentInChildren <WeaponFireHurtbox>(); hurtbox.Shooter = shooter; hurtbox.Weapon = instance; //Waiting for next bullet yield return(new WaitForSeconds(WaitTime)); } }
public void checkWeapon() { _currentWeaponInstance = FindObjectOfType <PlayerInventory>().currnetWeapon; current = _currentWeaponInstance.weapontype; damage = _currentWeaponInstance.damage; reloadSpeed = _currentWeaponInstance.reloadSpeed; totalAmmo = _currentWeaponInstance.totalAmmo; magSize = _currentWeaponInstance.magSize; stability = _currentWeaponInstance.stability; ammoInMag = _currentWeaponInstance.ammoInMag; fireRate = _currentWeaponInstance.fireRate; bulletVelocity = _currentWeaponInstance.bulletVelocity; projectile = _currentWeaponInstance.ammo; //// switch (current) // { //each value is set in scriptable object // case weaponType.pistol: // damage = 10; // reloadSpeed = 2; // totalAmmo = 60; // magSize = 6; // ammoInMag = 6; // fireRate = 1; // bulletVelocity = 500; // break; // // case weaponType.shotgun: // damage = 5; // reloadSpeed = 5; // totalAmmo = 25; // magSize = 5; // ammoInMag = 5; // fireRate = 1; // bulletVelocity = 500; // break; // case weaponType.assaultRifle: // damage = 10; // reloadSpeed = 5; // totalAmmo = 35; // magSize = 20; // ammoInMag = 20; // fireRate = .1f; // bulletVelocity = 500; // break; // case weaponType.DMR: // damage = 10; // reloadSpeed = 6; // totalAmmo = 15; // magSize = 3; // ammoInMag = 3; // fireRate = 3; // bulletVelocity = 700; // break; // default: // break; ////} }
public void EquipItem(WeaponInstance _weapon) { if (weapon != null) { items.Add(weapon); } weapon = _weapon; items.Remove(_weapon); OnItemUsed?.Invoke(); }
public void InitializeNewWeapon(WeaponInstance weapon) { weaponObj = weapon.weaponObj; hitDamage = weapon.hitDamage; fireRate = weapon.fireRate; clipSize = weapon.clipSize; CurrentAmmo = weapon.currentAmmo; reloadTime = weapon.reloadTime; isAutomatic = weapon.isAutomatic; _isReloading = false; IsZoomed = false; spreading = weapon.spreading; normalBurstDuration = weapon.normalBurstDuration; burstPenaltySpeed = weapon.burstPenaltySpeed; maxBurstPenalty = weapon.maxBurstPenalty; CurrentBurstPenalty = 0f; zoomRotateModifier = weapon.zoomRotateModifier; zoomSpeedModifier = weapon.zoomSpeedModifier; zoomSpreadingModifier = weapon.zoomSpreadingModifier; zoomValue = weapon.zoomValue; impactForce = weapon.impactForce; _currentMode = 1; altFireController = weapon.altFireController; tracerEffect = weapon.tracerEffect; muzzleFlash = weapon.muzzleFlash; impactEffect = weapon.impactEffect; hitDecal = weapon.hitDecal; recoilAngle = weapon.recoilAngle; Destroy(instantiatedWeapon); Destroy(instantiatedAltFireController); instantiatedWeapon = Instantiate(weaponObj, weaponPos); gunTip = instantiatedWeapon.GetComponentInChildren <GunTip>().gameObject.transform; _gunEffectsHolder = GetComponentInChildren <GunEffectsHolder>().gameObject.transform; _gunInterface = instantiatedWeapon.GetComponentInChildren <GunInterface>(); _gunInterface.SetSubText(CurrentAmmo.ToString()); instantiatedTracer = Instantiate(tracerEffect, _gunEffectsHolder); instantiatedMuzzleFlash = Instantiate(muzzleFlash, _gunEffectsHolder); if (altFireController != null) { instantiatedAltFireController = Instantiate(altFireController, weaponPos); altFire = instantiatedAltFireController.GetComponent <altFireController>().altFireScript as altFireBase; } GetComponent <ShootingSystem>().gunRecoil = instantiatedWeapon.GetComponentInChildren <RecoilGun>(); }
public void AddWeapon(Weapon weapon) { if (weapon == null) { return; } WeaponInstances[weapon] = new WeaponInstance { Weapon = weapon, Player = this }; }
protected override void Start() { if (!Template) { throw new NullReferenceException("The SpecificWeaponInstance did not have a set WeaponTemplate"); } _instance = Template.CreateWeaponInstance(); base.Start(); }
/// <summary> /// Fires the weapon from the provided weapon shooter /// </summary> public void Fire(WeaponInstance instance, WeaponShooterBase shooter) { OnFire(instance, shooter, shooter.GetCurrentAimingDirection()); if (!Cheats.InfiniteAmmo) { instance.Durability--; } instance.LastFireTime = DateTime.Now; }
protected override void Start() { base.Start(); _rigidbody = GetComponent <Rigidbody2D>(); _weaponFireHurtBox = GetComponentInChildren <WeaponFireHurtbox>(); //Create a weaponInstance for splittingprojectile SplittingProjectileWeaponInstance = GetComponentInChildren <WeaponFireHurtbox>().Weapon.Template.CreateWeaponInstance(); SplittingProjectileWeaponInstance.Range = SplittingProjectileRange; SplittingProjectileWeaponInstance.BaseDamage = SplittingProjectileDamage; }
public void Fire(WeaponInstance instance) { var currentLevel = Mathf.Min(instance.CurrentLevel, Levels.Count - 1); if (Levels[currentLevel].ProjectilePrefab == null) { return; } GameObject.Instantiate(Levels[currentLevel].ProjectilePrefab, instance.Player.GetWeaponPoint(), Quaternion.identity); instance.CurrentCooldown = Levels[currentLevel].Cooldown; }
void ApplyWeaponDesign(WeaponInstance Instance) // Reduntant, can use a prefab { // Add Components to Weapon Object and Weapon in Item Instance.rigidbody = Instance.gameObject.AddComponent <Rigidbody2D>(); Instance.collider = Instance.gameObject.AddComponent <CircleCollider2D>(); Instance.collisionDetector = Instance.gameObject.AddComponent <WeaponCollisionDetector>(); Instance.gameObject.transform.localScale = new Vector3(Instance.design.Size, Instance.design.Size, 1); // Non Design-Specific Instance.rigidbody.gravityScale = 4; Instance.rigidbody.collisionDetectionMode = CollisionDetectionMode2D.Continuous; Instance.rigidbody.interpolation = RigidbodyInterpolation2D.Interpolate; }
/// <summary> /// Creates a weapon instance from the template /// </summary> /// <returns></returns> public virtual WeaponInstance CreateWeaponInstance() { WeaponInstance weapon = new WeaponInstance() { Template = this, MaxDurability = (int)MaxDurability.Pick(), BaseDamage = (int)BaseDamage.Pick(), Range = Range.Pick() }; weapon.Durability = weapon.MaxDurability; return(weapon); }
protected virtual void Start() { transform.localScale = new Vector3( x: Commons.GetEffectValue(transform.localScale.x, EffectValueType.ProjectileSize), y: Commons.GetEffectValue(transform.localScale.y, EffectValueType.ProjectileSize), z: Commons.GetEffectValue(transform.localScale.z, EffectValueType.ProjectileSize) ); _hurtBox = GetComponentInChildren <WeaponFireHurtbox>(); _weaponInstance = _hurtBox.Weapon; _projectileSpwanPoint = transform.position; //Old code for _projectileSpawnPoint beneath // _projectileSpwanPoint = hurtBox.Shooter.GetProjectilesSpawnPoint(); }
void ApplyWeaponArtwork(WeaponInstance Instance) /// Reduntant, can use a prefab { SpriteRenderer spriteRenderer = Instance.gameObject.AddComponent <SpriteRenderer>(); spriteRenderer.sprite = Instance.design.CasingSprite; spriteRenderer.color = Instance.design.CasingColor; TrailRenderer trailRenderer; if (Instance.design.TrailMaterial != null) { trailRenderer = Instance.gameObject.AddComponent <TrailRenderer>(); trailRenderer.material = Instance.design.TrailMaterial; trailRenderer.widthCurve = Instance.design.TrailSize; } }
public void swapGun() { if (currnetWeapon == slot1) { //updates ammo left in mag on slot1 currentlyEquiped = current.slot2; slot1.ammoInMag = _playerWeapon.ammoInMag; currnetWeapon = slot2; } else if (currnetWeapon == slot2) { currentlyEquiped = current.slot1; //updates ammo left in mag on slot2 slot2.ammoInMag = _playerWeapon.ammoInMag; currnetWeapon = slot1; } }
protected override void Start() { if (Commons.RoomGenerator.CurrentRoomConfig == null) { throw new InvalidOperationException("RandomWeaponPickup cannot be used outside a generated room"); } if (!Commons.RoomGenerator.CurrentRoomConfig.WeaponEnumerator.MoveNext()) { Debug.LogWarning("WeaponEnumerator ran out of weapons to generate"); return; } _instance = Commons.RoomGenerator.CurrentRoomConfig.WeaponEnumerator.Current.CreateWeaponInstance(); base.Start(); }
void Start() { _label = GetComponent <TMP_Text>(); _unformatedText = _label.text; _pickup = GetComponentInParent <PickupBase>(); if (_pickup) { var weaponPickup = _pickup.GetComponentInChildren <WeaponPickupBase>(); if (weaponPickup) { DisplayedWeapon = weaponPickup.GetWeapon(); } } }
protected override void OnFire(WeaponInstance instance, WeaponShooterBase shooter, Vector2 direction) { for (int i = 0; i < BlastCount; i++) { Projectile newAmmo = Instantiate( original: Ammunition, position: shooter.GetProjectilesSpawnPoint(), rotation: Quaternion.identity ); newAmmo.Direction = direction; newAmmo.transform.Rotate((i - BlastCount / 2) * MaxAngle); WeaponFireHurtbox hurtbox = newAmmo.GetComponentInChildren <WeaponFireHurtbox>(); hurtbox.Shooter = shooter; hurtbox.Weapon = instance; } }
/// <summary> /// Shoots bullets with identical time between each bullet /// </summary> /// <param name="instance"></param> /// <param name="shooter"></param> /// <param name="direction"></param> /// <returns></returns> private IEnumerator CoShootBullets(WeaponInstance instance, WeaponShooterBase shooter, Vector2 direction) { for (int a = 0; a < NumberOfShots; a++) { for (int i = 0; i < BulletsPerShot; i++) { foreach (Projectile projectile in AmmunitionList) { Vector2 position = ForceLinear ? fireingPoint : shooter.GetProjectilesSpawnPoint(); Vector3 newAmmoPosition; if (direction == Vector2.right || direction == Vector2.left) { newAmmoPosition = new Vector3 (position.x, position.y + Height / BulletsPerShot * i); } else { newAmmoPosition = new Vector3 (position.x + (Height / BulletsPerShot * i - Height / 2), position.y); } Projectile newAmmo = Instantiate( original: projectile, position: newAmmoPosition, rotation: Quaternion.identity ); newAmmo.Direction = direction; WeaponFireHurtbox hurtbox = newAmmo.GetComponentInChildren <WeaponFireHurtbox>(); hurtbox.Shooter = shooter; hurtbox.Weapon = instance; newAmmo.Direction = ForceLinear ? fireingDirectionOrigin : shooter.GetCurrentAimingDirection(); } } //Waiting for next bullet yield return(new WaitForSeconds(WaitTime)); } }
void CreateWeaponInstance(Vector3 Position, Vector2 ImpulseForce, int GroupIndex, float ImpulseForceRandom = 0, float ForceX = 0, float ForceY = 0) { // Store Instance For Setup WeaponInstance Instance = new WeaponInstance(new GameObject("FK UUUUUuuuuuu")); // Add Object as an Instance to our List InstanceList.Add(Instance); print("Start: " + InstanceList[InstanceList.Count - 1]); // Set GroupIndex for reference at detonation time Instance.groupIndex = GroupIndex; print("Design " + SelectedWeapon.WeaponGroups[GroupIndex].WeaponDesign); Instance.design = SelectedWeapon.WeaponGroups[GroupIndex].WeaponDesign; // Place Object on Weapons Layer Instance.gameObject.layer = 9; // Set Object Parent Instance.gameObject.transform.SetParent(parent); // Position Instance Instance.gameObject.transform.position = Position; // Apply Artwork to Instance ApplyWeaponArtwork(Instance); // Apply Design to Instance ApplyWeaponDesign(Instance); // Add Forces to Instance Instance.rigidbody.AddForce(ImpulseForce, ForceMode2D.Impulse); Instance.rigidbody.AddForce(new Vector2(ForceX, 0), ForceMode2D.Impulse); Instance.rigidbody.AddForce(new Vector2(ForceY, 0), ForceMode2D.Impulse); Instance.rigidbody.AddForce(new Vector2( Random.Range(ImpulseForceRandom, -ImpulseForceRandom), Random.Range(ImpulseForceRandom, -ImpulseForceRandom)), ForceMode2D.Impulse); }