예제 #1
0
파일: NPC.cs 프로젝트: ebakkedahl/WCell
 /// <summary>
 /// Sets this NPC's equipment to the given entry
 /// </summary>
 public void SetEquipment(NPCEquipmentEntry equipment)
 {
     for (var i = 0; i < equipment.ItemIds.Length; i++)
     {
         var itemId = equipment.ItemIds[i];
         if (itemId != 0)
         {
             var item = ItemMgr.GetTemplate(itemId);
             if (item != null)
             {
                 SheathType = item.SheathType;		// TODO: How to use the sheath type of all items?
             }
             SetUInt32(UnitFields.VIRTUAL_ITEM_SLOT_ID + i, (uint)itemId);
         }
     }
 }
예제 #2
0
		/// <summary>
		/// Is called to initialize the object; usually after a set of other operations have been performed or if
		/// the right time has come and other required steps have been performed.
		/// </summary>
		public void FinalizeDataHolder()
		{
			if (string.IsNullOrEmpty(DefaultName))
			{
				ContentMgr.OnInvalidDBData("NPCEntry has no name: " + this);
				return;
			}

			if (Titles == null)
			{
				Titles = new string[(int)ClientLocale.End];
			}

			if (DefaultTitle == null)
			{
				DefaultTitle = "";
			}

			if (SpellGroupId != 0 && NPCMgr.PetSpells != null)
			{
				var spells = NPCMgr.PetSpells.Get(SpellGroupId) ?? Spell.EmptyArray;
				foreach (var spell in spells)
				{
					AddSpell(spell);
				}
			}

			if (MinMana > MaxMana)
			{
				MaxMana = MinMana;
			}

			if (MaxDamage > 0)
			{
				if (MinDamage < 1)
				{
					MinDamage = 1;
				}
				if (MaxDamage < MinDamage)
				{
					MaxDamage = MinDamage;
				}
			}

			if (RangedMaxDamage > 0 && RangedMinDamage > 0)
			{
				if (RangedMaxDamage < RangedMinDamage)
				{
					RangedMaxDamage = RangedMinDamage;
				}
				if (RangedAttackTime == 0)
				{
					RangedAttackTime = AttackTime;
				}
			}

			AggroBaseRange = AggroBaseRangeDefault;

			NPCId = (NPCId)Id;

			DefaultDecayDelayMillis = _DefaultDecayDelayMillis;
			Family = NPCMgr.GetFamily(FamilyId);

			if (Type == CreatureType.NotSpecified || VehicleEntry != null)
			{
				IsIdle = true;
			}
			
			if (Type == CreatureType.NotSpecified && UnitFlags.HasFlag((UnitFlags.Passive | UnitFlags.NotSelectable)))
			{
				IsEventTrigger = true;
				IsIdle = false;
			}

			if (Resistances == null)
			{
				Resistances = new int[ItemConstants.MaxResCount];
			}

			SetFlagIndices = Utility.GetSetIndices((uint)NPCFlags);

			// set/fix factions
			HordeFaction = FactionMgr.Get(HordeFactionId);
			AllianceFaction = FactionMgr.Get(AllianceFactionId);
			if (HordeFaction == null)
			{
				HordeFaction = AllianceFaction;
				HordeFactionId = AllianceFactionId;
			}
			else if (AllianceFaction == null)
			{
				AllianceFaction = HordeFaction;
				AllianceFactionId = HordeFactionId;
			}
			if (AllianceFaction == null)
			{
				ContentMgr.OnInvalidDBData("NPCEntry has no valid Faction: " + this);
				HordeFaction = AllianceFaction = NPCMgr.DefaultFaction;
				HordeFactionId = AllianceFactionId = (FactionTemplateId) HordeFaction.Template.Id;
			}

			// speeds
			if (SpeedFactor < 0.01)
			{
				SpeedFactor = 1;
			}

			if (WalkSpeed == 0)
			{
				WalkSpeed = NPCMgr.DefaultNPCWalkSpeed * SpeedFactor;
			}
			if (RunSpeed == 0)
			{
				RunSpeed = NPCMgr.DefaultNPCRunSpeed * SpeedFactor;
			}
			if (FlySpeed == 0)
			{
				FlySpeed = NPCMgr.DefaultNPCFlySpeed * SpeedFactor;
			}

			// Add all default spells
			if (FixedSpells != null)
			{
				foreach (var spell in FixedSpells)
				{
					AddSpell(spell);
				}
			}

			InstanceTypeHandlers = NPCMgr.GetNPCTypeHandlers(this);
			SpawnTypeHandlers = NPCMgr.GetNPCSpawnTypeHandlers(this);

			//ArrayUtil.PruneVals(ref DisplayIds);

			if (EquipmentId != 0)
			{
				Equipment = NPCMgr.GetEquipment(EquipmentId);
			}

			ModelInfos = new UnitModelInfo[DisplayIds.Length];

			GeneratesXp = (Type != CreatureType.Critter && Type != CreatureType.None && !ExtraFlags.HasFlag(UnitExtraFlags.NoXP));

			var x = 0;
			for (var i = 0; i < DisplayIds.Length; i++)
			{
				var did = DisplayIds[i];
				if (did > 0)
				{
					var model = UnitMgr.GetModelInfo(did);
					if (model != null)
					{
						ModelInfos[x++] = model;
					}
				}
			}

			if (x == 0)
			{
				ContentMgr.OnInvalidDBData("NPCEntry has no valid DisplayId: {0} ({1})", this, DisplayIds.ToString(", "));
				return;
			}

            if(TrainerTemplateId != 0)
            {
                if (!NPCMgr.TrainerSpellTemplates.ContainsKey(TrainerTemplateId))
                {
                    ContentMgr.OnInvalidDBData("NPCEntry has invalid TrainerTemplateId: {0} ({1})", this, TrainerTemplateId);
                }
                else
                {
                    if (TrainerEntry == null)
                    {
                        TrainerEntry = new TrainerEntry();
                    }
                    foreach (var trainerSpell in NPCMgr.TrainerSpellTemplates[TrainerTemplateId])
                    {
                        TrainerEntry.AddSpell(trainerSpell);
                    }
                }
            }

			if (AddonData != null)
			{
				AddonData.InitAddonData(this);
			}

			if (x < ModelInfos.Length)
			{
				Array.Resize(ref ModelInfos, x);
			}

			// add to container
			if (Id < NPCMgr.Entries.Length)
			{
				NPCMgr.Entries[Id] = this;
			}
			else
			{
				NPCMgr.CustomEntries[Id] = this;
			}
			++NPCMgr.EntryCount;

			if (BrainCreator == null)
			{
				BrainCreator = DefaultBrainCreator;
			}

			if (NPCCreator == null)
			{
				NPCCreator = DefaultCreator;
			}
		}
예제 #3
0
        /// <summary>
        /// Is called to initialize the object; usually after a set of other operations have been performed or if
        /// the right time has come and other required steps have been performed.
        /// </summary>
        public void FinalizeDataHolder()
        {
            if (string.IsNullOrEmpty(DefaultName))
            {
                ContentMgr.OnInvalidDBData("NPCEntry has no name: " + this);
                return;
            }

            if (Titles == null)
            {
                Titles = new string[(int)ClientLocale.End];
            }

            if (DefaultTitle == null)
            {
                DefaultTitle = "";
            }

            if (SpellGroupId != 0 && NPCMgr.PetSpells != null)
            {
                var spells = NPCMgr.PetSpells.Get(SpellGroupId) ?? Spell.EmptyArray;
                foreach (var spell in spells)
                {
                    AddSpell(spell);
                }
            }

            if (MinMana > MaxMana)
            {
                MaxMana = MinMana;
            }

            if (MaxDamage > 0)
            {
                if (MinDamage < 1)
                {
                    MinDamage = 1;
                }
                if (MaxDamage < MinDamage)
                {
                    MaxDamage = MinDamage;
                }
            }

            if (RangedMaxDamage > 0 && RangedMinDamage > 0)
            {
                if (RangedMaxDamage < RangedMinDamage)
                {
                    RangedMaxDamage = RangedMinDamage;
                }
                if (RangedAttackTime == 0)
                {
                    RangedAttackTime = AttackTime;
                }
            }

            AggroBaseRange = AggroBaseRangeDefault;

            NPCId = (NPCId)Id;

            DefaultDecayDelayMillis = _DefaultDecayDelayMillis;
            Family = NPCMgr.GetFamily(FamilyId);

            if (Type == CreatureType.NotSpecified || VehicleEntry != null)
            {
                IsIdle = true;
            }

            if (Type == CreatureType.NotSpecified && UnitFlags.HasFlag((UnitFlags.Passive | UnitFlags.NotSelectable)))
            {
                IsEventTrigger = true;
                IsIdle         = false;
            }

            if (Resistances == null)
            {
                Resistances = new int[ItemConstants.MaxResCount];
            }

            SetFlagIndices = Utility.GetSetIndices((uint)NPCFlags);

            // set/fix factions
            HordeFaction    = FactionMgr.Get(HordeFactionId);
            AllianceFaction = FactionMgr.Get(AllianceFactionId);
            if (HordeFaction == null)
            {
                HordeFaction   = AllianceFaction;
                HordeFactionId = AllianceFactionId;
            }
            else if (AllianceFaction == null)
            {
                AllianceFaction   = HordeFaction;
                AllianceFactionId = HordeFactionId;
            }
            if (AllianceFaction == null)
            {
                ContentMgr.OnInvalidDBData("NPCEntry has no valid Faction: " + this);
                HordeFaction   = AllianceFaction = NPCMgr.DefaultFaction;
                HordeFactionId = AllianceFactionId = (FactionTemplateId)HordeFaction.Template.Id;
            }

            // speeds
            if (SpeedFactor < 0.01)
            {
                SpeedFactor = 1;
            }

            if (WalkSpeed == 0)
            {
                WalkSpeed = NPCMgr.DefaultNPCWalkSpeed * SpeedFactor;
            }
            if (RunSpeed == 0)
            {
                RunSpeed = NPCMgr.DefaultNPCRunSpeed * SpeedFactor;
            }
            if (FlySpeed == 0)
            {
                FlySpeed = NPCMgr.DefaultNPCFlySpeed * SpeedFactor;
            }

            // Add all default spells
            if (FixedSpells != null)
            {
                foreach (var spell in FixedSpells)
                {
                    AddSpell(spell);
                }
            }

            InstanceTypeHandlers = NPCMgr.GetNPCTypeHandlers(this);
            SpawnTypeHandlers    = NPCMgr.GetNPCSpawnTypeHandlers(this);

            //ArrayUtil.PruneVals(ref DisplayIds);

            if (EquipmentId != 0)
            {
                Equipment = NPCMgr.GetEquipment(EquipmentId);
            }

            ModelInfos = new UnitModelInfo[DisplayIds.Length];

            GeneratesXp = (Type != CreatureType.Critter && Type != CreatureType.None && !ExtraFlags.HasFlag(UnitExtraFlags.NoXP));

            var x = 0;

            for (var i = 0; i < DisplayIds.Length; i++)
            {
                var did = DisplayIds[i];
                if (did > 0)
                {
                    var model = UnitMgr.GetModelInfo(did);
                    if (model != null)
                    {
                        ModelInfos[x++] = model;
                    }
                }
            }

            if (x == 0)
            {
                ContentMgr.OnInvalidDBData("NPCEntry has no valid DisplayId: {0} ({1})", this, DisplayIds.ToString(", "));
                return;
            }

            if (TrainerTemplateId != 0)
            {
                if (!NPCMgr.TrainerSpellTemplates.ContainsKey(TrainerTemplateId))
                {
                    ContentMgr.OnInvalidDBData("NPCEntry has invalid TrainerTemplateId: {0} ({1})", this, TrainerTemplateId);
                }
                else
                {
                    if (TrainerEntry == null)
                    {
                        TrainerEntry = new TrainerEntry();
                    }
                    foreach (var trainerSpell in NPCMgr.TrainerSpellTemplates[TrainerTemplateId])
                    {
                        TrainerEntry.AddSpell(trainerSpell);
                    }
                }
            }

            if (AddonData != null)
            {
                AddonData.InitAddonData(this);
            }

            if (x < ModelInfos.Length)
            {
                Array.Resize(ref ModelInfos, x);
            }

            // add to container
            if (Id < NPCMgr.Entries.Length)
            {
                NPCMgr.Entries[Id] = this;
            }
            else
            {
                NPCMgr.CustomEntries[Id] = this;
            }
            ++NPCMgr.EntryCount;

            if (BrainCreator == null)
            {
                BrainCreator = DefaultBrainCreator;
            }

            if (NPCCreator == null)
            {
                NPCCreator = DefaultCreator;
            }
        }
예제 #4
0
파일: NPCEntry.cs 프로젝트: WCellFR/WCellFR
		/// <summary>
		/// Is called to initialize the object; usually after a set of other operations have been performed or if
		/// the right time has come and other required steps have been performed.
		/// </summary>
		public void FinalizeDataHolder()
		{
			if (string.IsNullOrEmpty(DefaultName))
			{
				ContentHandler.OnInvalidDBData("NPCEntry has no name: " + this);
				return;
			}

			if (Titles == null)
			{
				Titles = new string[(int)ClientLocale.End];
			}

			if (DefaultTitle == null)
			{
				DefaultTitle = "";
			}

			if (SpellGroupId != 0 && NPCMgr.PetSpells != null)
			{
				var spells = NPCMgr.PetSpells.Get(SpellGroupId) ?? Spell.EmptyArray;
				foreach (var spell in spells)
				{
					AddSpell(spell);
				}
			}

			if (MinMana > MaxMana)
			{
				MaxMana = MinMana;
			}

			if (MaxDamage > 0)
			{
				if (MinDamage < 1)
				{
					MinDamage = 1;
				}
				if (MaxDamage < MinDamage)
				{
					MaxDamage = MinDamage;
				}
			}

			if (RangedMaxDamage > 0 && RangedMinDamage > 0)
			{
				if (RangedMaxDamage < RangedMinDamage)
				{
					RangedMaxDamage = RangedMinDamage;
				}
				if (RangedAttackTime == 0)
				{
					RangedAttackTime = AttackTime;
				}
			}

			MovesRandomly = NPCFlags == NPCFlags.None;

			NPCId = (NPCId)Id;

			DefaultDecayDelay = _DefaultDecayDelay;
			Family = NPCMgr.GetFamily(FamilyId);

			if (Type == NPCType.NotSpecified)
			{
				IsIdle = true;
			}

			const uint gossipStartId = 200231u; // random fixed Id
			NameGossipId = gossipStartId + Id;
			new GossipEntry(NameGossipId, DefaultName + " (" + Id + ")");		// entry adds itself to GossipMgr

			if (Resistances == null)
			{
				Resistances = new int[ItemConstants.MaxResCount];
			}

			SetFlagIndices = Utility.GetSetIndices((uint)NPCFlags);
			HordeFaction = FactionMgr.Get(HordeFactionId);
			AllianceFaction = FactionMgr.Get(AllianceFactionId);

			if (HordeFaction == null)
			{
				HordeFaction = AllianceFaction;
			}
			else if (AllianceFaction == null)
			{
				AllianceFaction = HordeFaction;
			}

			if (AllianceFaction == null)
			{
				ContentHandler.OnInvalidDBData("NPCEntry has no valid Faction: " + this);
				AllianceFaction = NPCMgr.DefaultFaction;
				HordeFaction = AllianceFaction;
			}

			if (SpeedFactor < 0.01)
			{
				SpeedFactor = 1;
			}

			if (WalkSpeed == 0)
			{
				WalkSpeed = NPCMgr.DefaultNPCWalkSpeed * SpeedFactor;
			}
			if (RunSpeed == 0)
			{
				RunSpeed = NPCMgr.DefaultNPCRunSpeed * SpeedFactor;
			}
			if (FlySpeed == 0)
			{
				FlySpeed = NPCMgr.DefaultNPCFlySpeed * SpeedFactor;
			}

			// Add all default spells
			if (FixedSpells != null)
			{
				foreach (var spell in FixedSpells)
				{
					AddSpell(spell);
				}
			}

			InstanceTypeHandlers = NPCMgr.GetNPCTypeHandlers(this);
			SpawnTypeHandlers = NPCMgr.GetNPCSpawnTypeHandlers(this);

			//ArrayUtil.PruneVals(ref DisplayIds);

			if (EquipmentId != 0)
			{
				Equipment = NPCMgr.GetEquipment(EquipmentId);
			}

			ModelInfos = new UnitModelInfo[DisplayIds.Length];

			GeneratesXp = Type != NPCType.Critter && Type != NPCType.None;

			var x = 0;
			for (var i = 0; i < DisplayIds.Length; i++)
			{
				var did = DisplayIds[i];
				if (did > 0)
				{
					var model = UnitMgr.GetModelInfo(did);
					if (model != null)
					{
						ModelInfos[x++] = model;
					}
				}
			}

			if (x == 0)
			{
				ContentHandler.OnInvalidDBData("NPCEntry has no valid DisplayId: {0} ({1})", this, DisplayIds.ToString(", "));
				return;
			}

			if (x < ModelInfos.Length)
			{
				Array.Resize(ref ModelInfos, x);
			}

			// add to container
			if (Id < NPCMgr.Entries.Length)
			{
				NPCMgr.Entries[Id] = this;
			}
			else
			{
				NPCMgr.CustomEntries[Id] = this;
			}
			++NPCMgr.EntryCount;

			if (BrainCreator == null)
			{
				BrainCreator = DefaultBrainCreator;
			}

			if (NPCCreator == null)
			{
				NPCCreator = DefaultCreator;
			}
		}
예제 #5
0
파일: SpawnEntry.cs 프로젝트: NVN/WCell
		//public int GetRandomCriticalDelay()
		//{
		//    return (int)Utility.Random(CriticalDelayMin, CriticalDelayMax);
		//}

		public void FinalizeDataHolder()
		{
			if (Entry == null)
			{
				Entry = NPCMgr.GetEntry(EntryId);
				if (Entry == null)
				{
					ContentMgr.OnInvalidDBData("{0} had an invalid EntryId.", this);
					return;
				}
			}

			var entry = Entry;

			foreach (var handler in entry.SpawnTypeHandlers)
			{
				if (handler != null)
				{
					handler(this);
				}
			}

			if (MaxAmount == 0)
			{
				MaxAmount = 1;
			}

			var def = RespawnSeconds != 0 ? RespawnSeconds : NPCMgr.DefaultMinRespawnDelay;

			if (RespawnSecondsMin == 0)
			{
				RespawnSecondsMin = def;
			}

			if (RespawnSecondsMax == 0)
			{
				RespawnSecondsMax = Math.Max(def, RespawnSecondsMin);
			}

			if (PhaseMask == 0)
			{
				PhaseMask = 1;
			}

			if (EquipmentId != 0)
			{
				Equipment = NPCMgr.GetEquipment(EquipmentId);
			}

			// seems to be a DB issue where the id was inserted as a float
			if (DisplayIdOverride == 16777215)
			{
				DisplayIdOverride = 0;
			}

			if (SpawnId > highestSpawnId)
			{
				highestSpawnId = SpawnId;
			}
			else if (SpawnId == 0)
			{
				SpawnId = GenerateSpawnId();
			}

			if (AddonData != null)
			{
				AddonData.InitAddonData(this);
			}

			if (RegionId != MapId.End)
			{
				Entry.SpawnEntries.Add(this);
				ArrayUtil.Set(ref NPCMgr.SpawnEntries, SpawnId, this);

				if ((uint)RegionId >= NPCMgr.SpawnEntriesByMap.Length)
				{
					ArrayUtil.EnsureSize(ref NPCMgr.SpawnEntriesByMap, (int)RegionId + 100);
				}

				var list = NPCMgr.SpawnEntriesByMap[(uint)RegionId];
				if (list == null)
				{
					list = NPCMgr.SpawnEntriesByMap[(uint)RegionId] = new List<SpawnEntry>(5000);
				}

				list.Add(this);

				if (RealmServer.Instance.IsRunning && AutoSpawn)
				{
					var rgn = World.GetRegion(RegionId);
					if (rgn != null && rgn.NPCsSpawned)
					{
						rgn.ExecuteInContext(() => rgn.AddSpawn(this));
					}
				}
			}
		}