/// <summary> /// Attempt to trap a soul. /// </summary> /// <returns>True if entity is allowed to die after trap attempt.</returns> bool AttemptSoulTrap() { // Must have a peered DaggerfallEntityBehaviour and EntityEffectManager EntityEffectManager manager = (EntityBehaviour) ? EntityBehaviour.GetComponent <EntityEffectManager>() : null; if (!manager) { return(true); } // Find the soul trap incumbent SoulTrap soulTrapEffect = (SoulTrap)manager.FindIncumbentEffect <SoulTrap>(); if (soulTrapEffect == null) { return(true); } // Roll chance for trap // If trap fails then entity should die as normal without trapping a soul // If trap succeeds and player has a free soul gem then entity should die after storing soul // If trap succeeds and player has no free soul gems then entity will not die until effect expires or fails if (soulTrapEffect.RollTrapChance()) { // Attempt to fill an empty soul trap if (SoulTrap.FillEmptyTrapItem((MobileTypes)mobileEnemy.ID)) { // Trap filled, allow entity to die normally DaggerfallUI.AddHUDText(TextManager.Instance.GetLocalizedText("trapSuccess"), 1.5f); return(true); } else { // No empty gems, keep entity tethered to life - player is alerted so they know what's happening currentHealth = 1; DaggerfallUI.AddHUDText(TextManager.Instance.GetLocalizedText("trapNoneEmpty")); return(false); } } else { // Trap failed DaggerfallUI.AddHUDText(TextManager.Instance.GetLocalizedText("trapFail"), 1.5f); return(true); } }
/// <summary> /// Attempt to trap a soul. /// </summary> /// <returns>True if entity is allowed to die after trap attempt.</returns> bool AttemptSoulTrap() { // Must have a peered DaggerfallEntityBehaviour and EntityEffectManager EntityEffectManager manager = (EntityBehaviour) ? EntityBehaviour.GetComponent <EntityEffectManager>() : null; if (!manager) { return(true); } // Find the soul trap incumbent SoulTrap soulTrapEffect = (SoulTrap)manager.FindIncumbentEffect <SoulTrap>(); if (soulTrapEffect == null) { return(true); } // Roll chance for trap, or always succeed if Azura's Star is equipped. // If trap fails then entity should die as normal without trapping a soul // If trap succeeds and player has a free soul gem then entity should die after storing soul // If trap succeeds and player has no free soul gems then entity will not die until effect expires or fails bool azurasStarEquipped = false; DaggerfallUnityItem azurasStar = GameManager.Instance.PlayerEntity.ItemEquipTable.GetItem(EquipSlots.Amulet0); if (azurasStar != null && azurasStar.ContainsEnchantment(EnchantmentTypes.SpecialArtifactEffect, (short)ArtifactsSubTypes.Azuras_Star)) { azurasStarEquipped = true; } else { azurasStar = GameManager.Instance.PlayerEntity.ItemEquipTable.GetItem(Game.Items.EquipSlots.Amulet1); if (azurasStar != null && azurasStar.ContainsEnchantment(EnchantmentTypes.SpecialArtifactEffect, (short)ArtifactsSubTypes.Azuras_Star)) { azurasStarEquipped = true; } } if (azurasStarEquipped || soulTrapEffect.RollTrapChance()) { // Attempt to fill an empty soul trap if (soulTrapEffect.FillEmptyTrapItem((MobileTypes)mobileEnemy.ID)) { // Trap filled, allow entity to die normally DaggerfallUI.AddHUDText(TextManager.Instance.GetText("ClassicEffects", "trapSuccess"), 1.5f); return(true); } else { // No empty gems, keep entity tethered to life - player is alerted so they know what's happening currentHealth = 1; DaggerfallUI.AddHUDText(TextManager.Instance.GetText("ClassicEffects", "trapNoneEmpty")); return(false); } } else { // Trap failed DaggerfallUI.AddHUDText(TextManager.Instance.GetText("ClassicEffects", "trapFail"), 1.5f); return(true); } }
/// <summary> /// Handle shared logic when player attacks entity. /// </summary> public void HandleAttackFromSource(DaggerfallEntityBehaviour sourceEntityBehaviour) { // Break "normal power" concealment effects on source if (sourceEntityBehaviour && sourceEntityBehaviour.Entity.IsMagicallyConcealedNormalPower) { EntityEffectManager.BreakNormalPowerConcealmentEffects(sourceEntityBehaviour); } // When source is player if (sourceEntityBehaviour == GameManager.Instance.PlayerEntityBehaviour) { PlayerEntity playerEntity = GameManager.Instance.PlayerEntity; // Handle civilian NPC crime reporting if (EntityType == EntityTypes.CivilianNPC) { MobilePersonNPC mobileNpc = transform.GetComponent <MobilePersonNPC>(); if (mobileNpc) { // Handle assault or murder if (Entity.CurrentHealth > 0) { playerEntity.CrimeCommitted = PlayerEntity.Crimes.Assault; playerEntity.SpawnCityGuards(true); } else { if (!mobileNpc.IsGuard) { playerEntity.TallyCrimeGuildRequirements(false, 5); playerEntity.CrimeCommitted = PlayerEntity.Crimes.Murder; playerEntity.SpawnCityGuards(true); } else { playerEntity.CrimeCommitted = PlayerEntity.Crimes.Assault; playerEntity.SpawnCityGuard(mobileNpc.transform.position, mobileNpc.transform.forward); } // Disable when dead mobileNpc.Motor.gameObject.SetActive(false); } } } // Handle equipped Azura's Star trapping slain enemy monsters // This is always successful if Azura's Star is empty and equipped if (EntityType == EntityTypes.EnemyMonster && playerEntity.IsAzurasStarEquipped && entity.CurrentHealth <= 0) { EnemyEntity enemyEntity = entity as EnemyEntity; if (SoulTrap.FillEmptyTrapItem((MobileTypes)enemyEntity.MobileEnemy.ID, true)) { DaggerfallUI.AddHUDText(TextManager.Instance.GetLocalizedText("trapSuccess"), 1.5f); } } // Handle mobile enemy aggro if (EntityType == EntityTypes.EnemyClass || EntityType == EntityTypes.EnemyMonster) { // Make enemy aggressive to player EnemyMotor enemyMotor = transform.GetComponent <EnemyMotor>(); if (enemyMotor) { if (!enemyMotor.IsHostile) { GameManager.Instance.MakeEnemiesHostile(); } enemyMotor.MakeEnemyHostileToAttacker(GameManager.Instance.PlayerEntityBehaviour); } // Handle killing guards EnemyEntity enemyEntity = entity as EnemyEntity; if (enemyEntity.MobileEnemy.ID == (int)MobileTypes.Knight_CityWatch && entity.CurrentHealth <= 0) { playerEntity.TallyCrimeGuildRequirements(false, 1); playerEntity.CrimeCommitted = PlayerEntity.Crimes.Murder; } } } }