/// <summary> /// Maps a mob level to a friendly name /// </summary> /// <param name="mobLevel"></param> /// <returns></returns> public static string MapName(MobLevel mobLevel) { switch (mobLevel) { case MobLevel.Pathetic: return("pathetic"); case MobLevel.Meek: return("meek"); case MobLevel.Minor: return("minor"); case MobLevel.Fair: return("fair"); case MobLevel.Heightened: return("heightened"); case MobLevel.Great: return("great"); case MobLevel.Legendary: return("legendary"); default: return(""); } }
/// <summary> /// Creates a new mob of the given level /// </summary> /// <param name="level">The level multipler of the mob</param> private Mob(MobLevel level) : base() { Level = level; LevelEffect = Effect.NewMultiplier(MobLevelModifier.Map(level)); ModifiedPools.CopyTo(CurrentPools); }
/// <summary> /// Spawns an instance of the mob from prototype and adds it to the cache. /// </summary> /// <param name="level">The level of the mob to spawn</param> /// <param name="withEntities">Whether to also spawn contained entities</param> /// <param name="parent">The parent room instance ID</param> /// <returns>The instance ID of the spawned mob. Will return null if the method is called from an instanced object.</returns> public uint?Spawn(MobLevel level, bool withEntities, uint parent) { if (CacheType != CacheType.Prototype) { return(null); } var parentContainer = DataAccess.Get <EntityContainer>(parent, CacheType.Instance); var parentRoom = DataAccess.Get <Room>(parentContainer.InstanceParent, CacheType.Instance); if (parentContainer == null || parentRoom == null) { throw new LocaleException("Parent cannot be null when spawning a mob."); } Logger.Info(nameof(Mob), nameof(Spawn), "Spawning mob: " + Name + ": ProtoID=" + Prototype.ToString()); // Create new instance mob and add to parent room var newMob = SpawnWithoutParent(level, withEntities); DataAccess.Get <Room>(parentRoom.Instance, CacheType.Instance).Animates.AddEntity(newMob.Instance, newMob, false); Logger.Info(nameof(Mob), nameof(Spawn), "Finished spawning mob."); return(newMob.Instance); }
public override int GetHashCode() { int hash = 1; if (MobLevel != 0) { hash ^= MobLevel.GetHashCode(); } if (MobAffinity.Length != 0) { hash ^= MobAffinity.GetHashCode(); } if (PlayerProfessionRank != 0) { hash ^= PlayerProfessionRank.GetHashCode(); } if (PlayerProfessionGmtId.Length != 0) { hash ^= PlayerProfessionGmtId.GetHashCode(); } if (IsMobAlreadyEngaged != 0) { hash ^= IsMobAlreadyEngaged.GetHashCode(); } if (_unknownFields != null) { hash ^= _unknownFields.GetHashCode(); } return(hash); }
/// <summary> /// Provides the level multiplier /// </summary> /// <param name="mobLevel">The level of the mob</param> /// <returns>The multiplier value for the corresponding level</returns> public static float Map(MobLevel mobLevel) { try { return(_levelMap[mobLevel]); } catch { return(_levelMap[MobLevel.Fair]); } }
/// <summary> /// Creates a new mob and adds it to the Prototype cache /// </summary> /// <param name="parentID">The parent ID of the room to add this mob to; may be null</param> /// <param name="level">The optional level of the mob</param> /// <returns>The new prototype mob</returns> public static Mob NewPrototype(uint?parentID, MobLevel level = MobLevel.Fair) { var newMob = new Mob(level); newMob._inventory.CacheType = CacheType.Prototype; newMob._equipment.CacheType = CacheType.Prototype; var room = DataAccess.Get <Room>(parentID, CacheType.Prototype); DataAccess.Add <EntityContainer>(newMob._inventory, CacheType.Prototype); DataAccess.Add <EntityContainer>(newMob._equipment, CacheType.Prototype); DataAccess.Add <Mob>(newMob, CacheType.Prototype); if (room != null) { room.Animates.AddEntity(newMob.Prototype, newMob, true); } DataPersistence.SaveObject(newMob); return(newMob); }
/// <summary> /// Spawns a mob from a prototype without a parent /// </summary> /// <param name="level">The level of the mob to spawn</param> /// <param name="withEntities">Whether to also spawn contained entities</param> /// <returns>The new mob</returns> private Mob SpawnWithoutParent(MobLevel level, bool withEntities) { if (CacheType != CacheType.Prototype) { return(null); } var newMob = DataAccess.Get <Mob>(DataAccess.Add <Mob>(new Mob(level), CacheType.Instance), CacheType.Instance); // Set remaining properties newMob.Prototype = Prototype; CopyTo(newMob); // Spawn contained entities if (withEntities) { newMob._inventory = _inventory.SpawnAsObject <EntityContainer>(!withEntities, (uint)newMob.Instance); foreach (var animate in _inventory.GetAllEntitiesAsObjects <EntityAnimate>()) { animate.Spawn(withEntities, (uint)newMob._inventory.Instance); } newMob._equipment = _equipment.SpawnAsObject <EntityContainer>(!withEntities, (uint)newMob.Instance); foreach (var animate in _equipment.GetAllEntitiesAsObjects <EntityAnimate>()) { animate.Spawn(withEntities, (uint)newMob._equipment.Instance); } } else { newMob._inventory = _inventory.SpawnAsObject <EntityContainer>(!withEntities, (uint)newMob.Instance); newMob._equipment = _equipment.SpawnAsObject <EntityContainer>(!withEntities, (uint)newMob.Instance); } return(newMob); }
/// <summary> /// Creates a new mob and adds it to the Instance cache /// </summary> /// <param name="withPrototype">Whether to also create a backing prototype</param> /// <param name="parentID">The parent ID of the room to add this mob to; may be null</param> /// <returns>The new instanced mob</returns> public static Mob NewInstance(bool withPrototype, uint?parentID, MobLevel level = MobLevel.Fair) { Mob newMob; var instanceRoom = DataAccess.Get <Room>(parentID, CacheType.Instance); if (withPrototype) { var protoRoom = DataAccess.Get <Room>(instanceRoom.Prototype, CacheType.Prototype); var newProtoMob = NewPrototype((uint)protoRoom.Prototype, level); protoRoom?.Animates.AddEntity(newProtoMob.Prototype, newProtoMob, true); newMob = newProtoMob.SpawnWithoutParent(level, false); } else { newMob = DataAccess.Get <Mob>(DataAccess.Add <Mob>(new Mob(), CacheType.Instance), CacheType.Instance); DataAccess.Add <EntityContainer>(newMob._inventory, CacheType.Instance); DataAccess.Add <EntityContainer>(newMob._equipment, CacheType.Instance); } instanceRoom?.Animates.AddEntity(newMob.Instance, newMob, false); return(newMob); }
/// <summary> /// Spawns an instance of the mob from prototype and adds it to the cache. /// </summary> /// <param name="level">The level of the mob to spawn</param> /// <param name="withEntities">Whether to also spawn contained entities</param> /// <param name="parent">The parent room instance ID</param> /// <returns>The spawned mob. Will return null if the method is called from an instanced object.</returns> /// <remarks>Parent cannot be null. Adds new mob to instanced room.</remarks> public T SpawnAsObject <T>(MobLevel level, bool withEntities, uint parent) where T : CacheableObject { return(DataAccess.Get <T>(Spawn(level, withEntities, parent), CacheType.Instance)); }