Aura.Channel.World.Region.AddCreature C# (CSharp) Method

AddCreature() public method

Adds creature to region, sends EntityAppears.
public AddCreature ( Creature creature ) : void
creature Aura.Channel.World.Entities.Creature
return void
		public void AddCreature(Creature creature)
		{
			//if (creature.Region != Region.Limbo)
			//	creature.Region.RemoveCreature(creature);

			_creaturesRWLS.EnterWriteLock();
			try
			{
				if (_creatures.ContainsKey(creature.EntityId))
					throw new ArgumentException("A creature with id '" + creature.EntityId.ToString("X16") + "' already exists.");

				_creatures.Add(creature.EntityId, creature);
			}
			finally
			{
				_creaturesRWLS.ExitWriteLock();
			}

			creature.Region = this;
			creature.Activate(CreatureStates.EverEnteredWorld);

			// Save reference to client if it's mainly controlling this creature.
			if (creature.Client.Controlling == creature)
			{
				lock (_clients)
					_clients.Add(creature.Client);
			}

			// Send appear packets, so there's no delay.
			Send.EntityAppears(creature);

			// Remove Spawned state, so effect only plays the first time.
			// This probably only works because of the EntityAppears above,
			// otherwise the state would be gone by the time LookAround
			// kicks in. Maybe we need a better solution.
			creature.State &= ~CreatureStates.Spawned;

			//if (creature.EntityId < MabiId.Npcs)
			//	Log.Status("Creatures currently in region {0}: {1}", this.Id, _creatures.Count);

			if (creature.IsPlayer)
			{
				ChannelServer.Instance.Events.OnPlayerEntersRegion(creature);
				this.PlayerEnters.Raise(creature);
			}
		}