public virtual void Damage(int damageAmount, Entity origin, DamageType damageSource) { // Abort if already dead, unless the 'corpse' can be desecrated further if (IsDead && allowPostmortemDamage == false) { return; } values.current -= damageAmount; lastAttacker = origin; lastDamageSource = damageSource; // Play appropriate event if (damageAmount >= 0) { onDamage.Invoke(); } else { onHeal.Invoke(); } EventJunction.Transmit(new DamageMessage(origin, this, damageSource, damageAmount)); if (values.current <= 0) { Die(lastDamageSource, lastAttacker); } }
public virtual void OnInteract(PlayerHandler ph) { onInteract.Invoke(ph); EventJunction.Transmit(new InteractMessage(ph, this)); if (cooldown > 0) { coolingDown = Cooldown(cooldown); StartCoroutine(coolingDown); } }
public override void Telegraph() { base.Telegraph(); //Vector3 direction = wielder.currentTarget.transform.position - wielder.LookOrigin; Vector3 direction = DetermineEnemyPosition() - wielder.LookOrigin; AttackMessage m = AttackMessage.Ranged(wielder.characterData, wielder.LookOrigin, direction, stats.range, stats.projectilePrefab.diameter, stats.projectileSpread, stats.projectilePrefab.velocity, stats.projectilePrefab.hitDetection); EventJunction.Transmit(m); //EventObserver.TransmitAttack(m); // Transmits a message of the attack the player is about to perform }
public virtual void Die(DamageType causeOfDeath, Entity lastAttacker) { if (IsDead) { return; // Character is already dead, no need to do anything } IsDead = true; onDeath.Invoke(); EventJunction.Transmit(new KillMessage(lastAttacker, this, causeOfDeath)); }
void Update() { // Ensure things don't happen if the game is paused. if (Time.timeScale == 0) { return; } attackMessageLimitTimer += Time.deltaTime; // If the player is not switching weapons or fire modes, and is therefore able to operate the weapon if (isSwitchingWeapon == false && isSwitchingFireMode == false && playerHolding.weaponSelector.InSelection == false) { #region Firing mode controls float scrollInput = Input.GetAxis("Mouse ScrollWheel"); if (scrollInput != 0 && firingModes.Length > 1) // Switch firing modes with the scroll wheel { int i = firingModeIndex; i -= (int)new Vector2(scrollInput, 0).normalized.x; i = (int)Misc.InverseClamp(i, 0, firingModes.Length - 1); StartCoroutine(SwitchMode(i)); } #endregion #region Fire controls fireControls.fireTimer += Time.deltaTime; // If player is active // If player is pressing fire button // If fireTimer has finished // If burst count has not exceeded the limit OR there is no burst limit // If ammo is available OR not required // If magazine is not empty OR null if (playerHolding.handler.PlayerState() == GameState.Active && Input.GetButton("Fire") && fireControls.fireTimer >= 60 / fireControls.roundsPerMinute && (fireControls.burstCounter < fireControls.maxBurst || fireControls.maxBurst <= 0) && (general.consumesAmmo == false || (playerHolding.handler.ammo.GetStock(general.ammoType) >= general.ammoPerShot)) && (magazine == null || (magazine.data.current >= general.ammoPerShot && reloading == null))) { CancelReloadSequence(); fireControls.fireTimer = 0; // Reset fire timer to count up to next shot fireControls.burstCounter += 1; if (general.consumesAmmo == true) { playerHolding.handler.ammo.Spend(general.ammoType, general.ammoPerShot); } if (magazine != null) { magazine.data.current -= general.ammoPerShot; } recoilToApply += general.recoil; #region Calculate and fire shot Transform head = playerHolding.handler.movement.head; Vector3 aimDirection = head.forward; if (optics == null || isAiming == false) { float accuracy = playerHolding.standingAccuracy.Calculate(); aimDirection = Quaternion.Euler(Random.Range(-accuracy, accuracy), Random.Range(-accuracy, accuracy), Random.Range(-accuracy, accuracy)) * aimDirection; } general.Shoot(playerHolding.handler, head.position, aimDirection, head.up); #endregion #region Send attack message if the timer is right if (attackMessageLimitTimer >= attackMessageLimitDelay) // Sends attack message { AttackMessage am = AttackMessage.Ranged(playerHolding.handler, transform.position, transform.forward, general.range, general.projectilePrefab.diameter, playerHolding.standingAccuracy.Calculate() + general.projectileSpread, general.projectilePrefab.velocity, general.projectilePrefab.hitDetection); EventJunction.Transmit(am); attackMessageLimitTimer = 0; } #endregion } else if (!Input.GetButton("Fire")) { fireControls.burstCounter = 0; } #endregion #region ADS and reload controls ADSHandler(); /* * if (optics != null) * { * optics.ADSHandler(this, currentMode); * } */ ReloadHandler(); #endregion } RecoilHandler(general.recoilApplyRate, playerHolding); }