Role-playing character, controlled by players.
Inheritance: Aura.Channel.World.Entities.PlayerCreature
Esempio n. 1
0
		/// <summary>
		/// Called after an RP character was created, but before the player
		/// is warped into the dungeon.
		/// </summary>
		/// <remarks>
		/// Allows changes to the RP character, which are created based on
		/// actor data.
		/// </remarks>
		/// <param name="dungeon"></param>
		/// <param name="rpCharacter"></param>
		public virtual void OnRpCharacterCreated(Dungeon dungeon, RpCharacter rpCharacter)
		{
		}
Esempio n. 2
0
		/// <summary>
		/// Creates a dungeon with the given parameters and warps the creature's
		/// party inside.
		/// </summary>
		/// <param name="dungeonName"></param>
		/// <param name="itemId"></param>
		/// <param name="leader"></param>
		/// <returns></returns>
		public bool CreateDungeonAndWarp(string dungeonName, int itemId, Creature leader)
		{
			lock (_createAndCleanUpLock)
			{
				try
				{
					var dungeon = this.CreateDungeon(dungeonName, itemId, leader);
					var regionId = dungeon.Regions.First().Id;

					// Warp the party currently standing on the altar into the dungeon.
					var party = leader.Party;
					var creators = party.GetCreaturesOnAltar(leader.RegionId);

					// Add creature to list in case something went wrong.
					// For example, there might be no altar, because the call
					// came from the dungeon command.
					if (creators.Count == 0)
						creators.Add(leader);

					// RP dungeon
					if (dungeon.HasRoles)
					{
						// Get roles
						var roles = dungeon.GetRoles();

						if (roles.Count < creators.Count)
						{
							Send.Notice(leader, Localization.Get("Your party has too few members for this role-playing dungeon."));
							return false;
						}

						// Create RP characters
						var rpCharacters = new List<RpCharacter>();
						for (int i = 0, j = 1; i < creators.Count; ++i)
						{
							var creator = creators[i];
							var pos = creator.GetPosition();

							// Get first role for leader or next available
							// one for members.
							var role = (creator == leader ? roles[0] : roles[j++]);

							// Get actor data
							var actorData = AuraData.ActorDb.Find(role);
							if (actorData == null)
							{
								Log.Error("DungeonManager.CreateDungeonAndWarp: Actor data not found for '{0}'.", role);
								return false;
							}

							try
							{
								var rpCharacter = new RpCharacter(actorData, creator, null);
								rpCharacter.SetLocation(regionId, pos.X, pos.Y);

								dungeon.RpCharacters.Add(rpCharacter.EntityId);
								dungeon.Script.OnRpCharacterCreated(dungeon, rpCharacter);

								rpCharacters.Add(rpCharacter);
							}
							catch
							{
								Log.Error("DungeonManager.CreateDungeonAndWarp: Failed to create RP character '{0}'.", role);
								throw;
							}
						}

						// Start RP sessions, which makes the players switch
						// to the RP characters inside the dungeon.
						foreach (var character in rpCharacters)
							character.Start();
					}
					// Normal dungeon
					else
					{
						// Warp in
						foreach (var creator in creators)
						{
							// Warp member to same position in the lobby region.
							var pos = creator.GetPosition();
							creator.Warp(regionId, pos);

							// TODO: This is a bit hacky, needs to be moved to Creature.Warp, with an appropriate check.
							Send.EntitiesDisappear(creator.Client, creators);
						}
					}

					return true;
				}
				catch (Exception ex)
				{
					Log.Exception(ex, "Failed to create and warp to dungeon.");
					return false;
				}
			}
		}