public override void DoInteraction(int actionId, Player player) { if (IsTamed) { if (Owner == player) { IsSitting = !IsSitting; BroadcastSetEntityData(); } else { // Hmm? } } else { if (player.Inventory.GetItemInHand() is ItemBone) { Log.Debug($"Wolf taming attempt by {player.Username}"); player.Inventory.RemoveItems(new ItemBone().Id, 1); var random = new Random(); if (random.Next(3) == 0) { Owner = player; IsTamed = true; IsSitting = true; IsAngry = false; AttackDamage = 4; BroadcastSetEntityData(); for (int i = 0; i < 7; ++i) { Particle particle = new HeartParticle(Level, random.Next(3)); particle.Position = KnownPosition + new Vector3(0, (float)(Height + 0.85d), 0); particle.Spawn(); } Log.Debug($"Wolf is now tamed by {player.Username}"); } else { for (int i = 0; i < 7; ++i) { Particle particle = new SmokeParticle(Level); particle.Position = KnownPosition + new Vector3(0, (float)(Height + 0.85d), 0); particle.Spawn(); } } } } }
public override void TakeHit(Entity source, int damage = 1, DamageCause cause = DamageCause.Unknown) { if (!(source is Player)) { return; } // Pets must die in void or they get stuck forever :-( if (cause == DamageCause.Void) { base.TakeHit(source, damage, cause); return; // Love denied! } int size = Entity.Level.Random.Next(0, 3); // The size of the hearts Pet pet = Entity as Pet; if (pet != null) { if (pet.AttackTarget != null) { return; } // He is still angry, better not pet him right now. if (!pet.IsInRage && IsOnFire && pet.Level.Random.Next(10) == 0) { pet.AttackTarget = (Player)source; pet.RageTick = 20 * 3; return; } // Only owner do petting with my pet! if (pet.Owner == source) { // Don't trust animals! if (pet.Level.Random.Next(500) == 0) { pet.AttackTarget = (Player)source; pet.RageTick = 20 * 2; return; } Particle particle = new HeartParticle(pet.Level, size); particle.Position = Entity.KnownPosition.ToVector3() + new Vector3(0, (float)(Entity.Height + 0.85d), 0); particle.Spawn(); } else { // HAHA Steal IT! if (pet.Level.Random.Next(50) == 0) { pet.Owner = (Player)source; pet.AttackTarget = null; pet.RageTick = 0; return; } // Don't trust animals! if (pet.Level.Random.Next(30) == 0) { pet.AttackTarget = (Player)source; pet.RageTick = 20 * 3; return; } } } }