public void EquipWeapon(WeaponRecord weapon, bool playSound = true) { // Play equip sound if needed (Don't want to play it when NPC's spawn for example) if (playSound) { weapon.PickupSound.PlaySoundAtPoint(transform.position); } // If a weapon is equipped, unequip it and equip the new one if (weaponEquipped) { // Unequip any existing weapons from the character's hands // Need this null check, as hand-to-hand could be equipped if (EquippedWeapon != null) { (EquippedWeapon as IEquippable).Unequip(body.PartParts); } (weapon as IEquippable).Equip(body.PartParts); OnWeaponChanged?.Invoke(weapon.Data.type); } EquippedWeapon = weapon; equippedItems[EquipmentSlot.Weapon] = weapon; animation.SetParameter("WeaponType", EquippedWeapon.Data.type); }
// todo: make this a callback // todo: set FX in SO private void OnWeaponChangedInternal(WeaponDescription desc) { if (desc.type == ElementType.Light) { playerStatus.AddStatus(speedUpStatus); } else { playerStatus.RemoveStatus(speedUpStatus); } OnWeaponChanged?.Invoke(desc); }
public void SetWeapon(WeaponBase weapon) { Assert.IsNotNull(weapon, "weapon != null"); if (_weapon != null) { _weapon.gameObject.SetActive(false); } _weapon = weapon; _weapon.gameObject.SetActive(true); OnWeaponChanged?.Invoke(_weapon); }
public ItemStack RemoveStackAtSlot(int index) { if (index != 0) { return(ItemStack.Empty); } ItemStack result = weapon.Copy; weapon.Clear(); OnWeaponChanged?.Invoke(GameManager.Instance.noWeaponClass); return(result); }
void Update() { if (EntityShouldAttack()) { weapons[currentWeapon].TryToAttackTarget(); } if (isPlayer) { SlowlyReloadOtherWeapons(); int oldCurrentWeapon = currentWeapon; if (Input.GetKeyDown(KeyCode.Q)) { PickWeapon(currentWeapon + 1); } else { KeyCode keyCode; for (int i = 0; i < weapons.Length; i++) { keyCode = (KeyCode)((int)KeyCode.Alpha1 + i); if (Input.GetKeyDown(keyCode)) { PickWeapon(i); } } } if (currentWeapon != oldCurrentWeapon) { OnWeaponChanged?.Invoke(currentWeapon); } ChangeWeaponMesh(weapons[currentWeapon].GetWeaponItem()); return; } if (target == null) { return; } PickWeaponForEnemy(); }
public void SelectWeapon() { currentWeapon = GetSelectedWeaponObject; currentShootParameters = GetSelectedShootParameters; if (cadenceTimerSystem != null) { cadenceTimerSystem.ChangeTimerValue(currentShootParameters.GetShootCadence); } if (cadenceTimerSystem != null) { serialShotTimerSystem.ChangeTimerValue(currentShootParameters.GetTimeBetweenEachSerialShot); serialShotTimerSystem.ChangeIterationValue(currentShootParameters.GetNumberOfSerialShots - 1); } OnWeaponChanged?.Invoke(GetSelectedWeaponParameters.weaponName); }
public void SetActiveWeapon(int index) { if (index > -1 && index < configs.Length) { if (_activeWeaponState != null) { _activeWeaponState.isActive = false; } _activeConfigIndex = index; _activeConfig = configs[_activeConfigIndex]; _activeWeaponState = _weaponStates[_activeConfigIndex]; _activeWeaponState.isActive = true; ResetActiveWeaponDispersionRate(); OnWeaponChanged?.Invoke(_activeWeaponState); } }
public ItemStack AddStackAtSlot(ItemStack stack, int index) { if (index != 0 || !(stack.Item is WeaponItem)) { return(stack); } ItemStack result = weapon.Copy; weapon.Item = stack.Item; weapon.Amount = stack.Amount; if (((WeaponItem)weapon.Item).WeaponClass != null) { OnWeaponChanged?.Invoke(((WeaponItem)weapon.Item).WeaponClass); } return(result); }
private void PickWeapon(int id, bool forceReloadTime = false) { if (currentWeapon == id && !forceReloadTime) { return; } if (id < 0) { id = weapons.Length; } else { id %= weapons.Length; } currentWeapon = id; OnWeaponChanged?.Invoke(currentWeapon); weapons[currentWeapon].SetLastAttackTime(); }
public void EquipWeapon(WeaponBase weapon) { if (this.Weapon != null) { ThrowWeapon(this.Weapon); } this.Weapon = weapon; OnWeaponChanged?.Invoke(); OnWeaponDurabilityChanged?.Invoke(); if (weapon == null) { ItemBase createdItem = ItemFactory.Instance.Create("Basic_Weapon"); createdItem.Use(ActorContainer.Instance.LocalCharacter); return; } this.Weapon.transform.SetParent(_weaponParent.transform, false); this.Weapon.transform.localPosition = Vector2.zero; AppSound.instance.SE_itembox_open.Play(); }
/// <summary> /// Changes the current weapon to the weapon at index "index" in the weapon list. /// </summary> /// <param name="index">The index to use when changing weapon.</param> public void SetWeapon(int index) { // CurrentWeapon?.gameObject.SetActive(false/true) doesn't work... void SetWeaponActive(bool active) { if (CurrentWeapon != null) { CurrentWeapon.gameObject.SetActive(active); } } if (index < 0) { index = TotalWeapons - 1; } else if (index >= TotalWeapons) { index = 0; } SetWeaponActive(false); int lastIndex = weaponIndex; weaponIndex = index; CurrentWeapon = weapons[weaponIndex]; SetWeaponActive(true); EnableCorrectWeaponController(); if (lastIndex != weaponIndex) { if (OnWeaponChanged != null && CurrentWeapon.TryGetComponent <IWeapon>(out IWeapon newWeapon)) { OnWeaponChanged.Invoke(newWeapon, null); } } }
public void SetWeapon(Weapon weapon) { this.weapon = weapon; //playerMain.PlayerSwapAimNormal.SetWeapon(weapon); OnWeaponChanged?.Invoke(this, EventArgs.Empty); }
// Public access to invoke the OnWeaponChanged event. public void WeaponChanged() { OnWeaponChanged?.Invoke(currentWeapon); }
void ControlManager() { mousePos = Camera.main.ScreenToWorldPoint(Input.mousePosition); if (Input.GetAxis("Fire1") == 1) { //print("Ping"); if (currentWeapon) { // Attempt to fire the weapon, if the weapon does fire, increase bullets shot. if (currentWeapon.PrimaryFire()) { stats.BulletsShot++; } OnWeaponChanged?.Invoke(currentWeapon); } } if (Input.GetAxis("Fire2") == 1) { if (currentWeapon) { currentWeapon.SecondaryFire(); OnWeaponChanged?.Invoke(currentWeapon); } } if (Input.GetButtonDown("Reload")) { if (currentWeapon) { currentWeapon.ReloadAll(); OnWeaponChanged?.Invoke(currentWeapon); } } if (Input.GetButtonDown("Ability1")) { try { if (!AbilityController) { return; } AbilityController.UseAbility(0); } catch (Exception e) { Debug.LogWarning("Ability 1 not found"); } } if (Input.GetButtonDown("Ability2")) { try { AbilityController.UseAbility(1); } catch (Exception e) { Debug.LogWarning("Ability 2 not found"); } } if (Input.GetButton("CharJump")) { if (jumpController.Jump(out var newEnemy)) { controlledObject = newEnemy; GetComponent <AudioSource>().PlayOneShot(AudioDatabase.GetClip("Body Swap")); HandleNewControlledObject(); } } }
void HandleNewControlledObject() { // So many try-catches ;) try { lastControlled.GetComponent <IDamageable>().OnHealthChanged -= HandleHealthChange; lastControlled.GetComponent <CharacterMotor>().TakenOver(); } catch (Exception e) { Debug.LogWarning("Could not unsubscribe OnHealthChange from last controlled object. Ignore if this is the first controller."); } try { GetControlledIDamagable().OnHealthChanged += HandleHealthChange; OnHealthChange?.Invoke(GetControlledIDamagable()); } catch (NullReferenceException e) { Debug.LogWarning($"Could not subscribe to OnHealthChanged for currently controlled object as {controlledObject.name} does not have an IDamagable interface."); } try { currentCharacterMotor = controlledObject.GetComponent <CharacterMotor>(); AbilityController = controlledObject.GetComponent <AbilityController>(); currentCharacterMotor.TakenOver(); } catch (Exception e) { Debug.LogWarning("No character motor or ability controller found on controlled object."); } lastControlled = controlledObject; try { if (currentWeapon != null) { currentWeapon.IsPlayer = false; } currentWeapon = controlledObject.GetComponentInChildren <Weapon>(); currentWeapon.IsPlayer = true; OnWeaponChanged?.Invoke(currentWeapon); if (!currentCharacterMotor.previouslyControlled && PerkController.CanUse("jugg")) { var enemyComp = currentCharacterMotor.GetComponent <Enemy>(); enemyComp.Health = enemyComp.MaxHealth; OnHealthChange?.Invoke(GetControlledIDamagable()); } OnTakeover?.Invoke(); } catch (Exception e) { Debug.LogWarning("No weapon found on controlled object."); } jumpController.SetCurrentControlledEnemy(controlledObject); }