Aura.Channel.World.Entities.Creature.TakeDamage C# (CSharp) Method

TakeDamage() public method

Applies damage to Life, kills creature if necessary.
public TakeDamage ( float damage, Creature from ) : void
damage float
from Creature
return void
		public void TakeDamage(float damage, Creature from)
		{
			var lifeBefore = this.Life;

			this.Life -= damage;

			// Track hit
			if (from != null)
			{
				HitTracker tracker;
				lock (_hitTrackers)
				{
					// Create new tracker if there is none yet
					if (!_hitTrackers.TryGetValue(from.EntityId, out tracker))
					{
						var newId = Interlocked.Increment(ref _hitTrackerIds);
						_hitTrackers[from.EntityId] = (tracker = new HitTracker(newId, this, from));
					}
				}
				tracker.RegisterHit(damage);
				_totalHits = Interlocked.Increment(ref _totalHits);
			}

			// Update equip
			var mainArmors = this.Inventory.GetMainEquipment(a => a.Info.Pocket.IsMainArmor());
			if (mainArmors.Length != 0)
			{
				// Select a random armor item to gain proficiency and lose
				// durability, as the one that was "hit" by the damage.
				var item = mainArmors.Random();

				// Give proficiency
				var profAmount = Item.GetProficiencyGain(this.Age, ProficiencyGainType.Damage);
				this.Inventory.AddProficiency(item, profAmount);

				// Reduce durability
				var duraAmount = RandomProvider.Get().Next(1, 30);
				this.Inventory.ReduceDurability(item, duraAmount);
			}

			// Kill if life too low
			if (this.Life < 0 && !this.ShouldSurvive(damage, from, lifeBefore))
				this.Kill(from);
		}

Usage Example

Beispiel #1
0
		/// <summary>
		/// Bolt specific use code.
		/// </summary>
		/// <param name="attacker"></param>
		/// <param name="skill"></param>
		/// <param name="target"></param>
		protected override void UseSkillOnTarget(Creature attacker, Skill skill, Creature target)
		{
			attacker.StopMove();
			target.StopMove();

			// Create actions
			var aAction = new AttackerAction(CombatActionType.RangeHit, attacker, target.EntityId);
			aAction.Set(AttackerOptions.Result);

			var tAction = new TargetAction(CombatActionType.TakeHit, target, attacker, skill.Info.Id);
			tAction.Set(TargetOptions.Result);
			tAction.Stun = TargetStun;

			var cap = new CombatActionPack(attacker, skill.Info.Id, aAction, tAction);

			// Damage
			var damage = this.GetDamage(attacker, skill);

			// Elements
			damage *= this.GetElementalDamageMultiplier(attacker, target);

			// Reduce damage
			SkillHelper.HandleMagicDefenseProtection(target, ref damage);
			ManaShield.Handle(target, ref damage, tAction);
			ManaDeflector.Handle(attacker, target, ref damage, tAction);

			// Deal damage
			if (damage > 0)
				target.TakeDamage(tAction.Damage = damage, attacker);
			target.Aggro(attacker);

			// Knock down on deadly
			if (target.Conditions.Has(ConditionsA.Deadly))
			{
				tAction.Set(TargetOptions.KnockDown);
				tAction.Stun = TargetStun;
			}

			// Death/Knockback
			attacker.Shove(target, KnockbackDistance);
			if (target.IsDead)
				tAction.Set(TargetOptions.FinishingKnockDown);
			else
				tAction.Set(TargetOptions.KnockDown);

			// Override stun set by defense
			aAction.Stun = AttackerStun;

			Send.Effect(attacker, Effect.UseMagic, EffectSkillName);
			Send.SkillUseStun(attacker, skill.Info.Id, aAction.Stun, 1);

			skill.Stacks = 0;

			cap.Handle();
		}
All Usage Examples Of Aura.Channel.World.Entities.Creature::TakeDamage