Exemplo n.º 1
0
		public NPC CreateVendor(Faction faction)
		{
			var npc = DefaultVendorEntry.Create();
			npc.Name = "Dummy Vendor";
			npc.Faction = faction;
			npc.BaseHealth = 100;
			return npc;
		}
Exemplo n.º 2
0
 public NPC CreateDummy(Faction faction)
 {
     var npc = DefaultMobEntry.Create();
     npc.Name = "Dummy NPC";
     npc.Faction = faction;
     npc.BaseHealth = 100;
     return npc;
 }
Exemplo n.º 3
0
		public Reputation(ReputationRecord record, Faction faction, int defaultValue, ReputationFlags defaultFlags)
		{
			m_record = record;
			m_record.ReputationIndex = faction.ReputationIndex;
			m_record.Value = defaultValue;
		    m_record.Flags = defaultFlags;

			Faction = faction;
			m_standing = GetStanding(defaultValue);

			RealmWorldDBMgr.DatabaseProvider.SaveOrUpdate(m_record);
		}
Exemplo n.º 4
0
		public Reputation(ReputationRecord record, Faction faction, int defaultValue, ReputationFlags defaultFlags)
		{
			m_record = record;
			m_record.ReputationIndex = faction.ReputationIndex;
			m_record.Value = defaultValue;
		    m_record.Flags = defaultFlags;

			Faction = faction;
			m_standing = GetStanding(defaultValue);

		    m_record.Save();
		}
Exemplo n.º 5
0
		/// <summary>
		/// Loads an existing Reputation from the given Record.
		/// </summary>
		public Reputation(ReputationRecord record, Faction faction)
		{
			m_record = record;
			Faction = faction;
			m_standing = GetStanding(record.Value);
		}
Exemplo n.º 6
0
        internal void InitializeTemplate()
        {
            if (Names == null)
            {
                Names = new string[(int)ClientLocale.End];
            }

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

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

            if (string.IsNullOrEmpty(DefaultName) || Id == 0)
            {
                // something's off with these entries
                return;
            }

            ItemId = (ItemId)Id;
            //Faction = (FactionId)Faction; // faction, 3.2.2
            RequiredSkill = SkillHandler.Get(RequiredSkillId);
            Set = ItemMgr.GetSet(SetId);
            Lock = LockEntry.Entries.Get(LockId);
            RequiredFaction = FactionMgr.Get(RequiredFactionId);
            RequiredProfession = SpellHandler.Get(RequiredProfessionId);
            SubClassMask = (ItemSubClassMask)(1 << (int)SubClass);
            EquipmentSlots = ItemMgr.EquipmentSlotsByInvSlot.Get((uint)InventorySlotType);
            InventorySlotMask = (InventorySlotTypeMask)(1 << (int)InventorySlotType);
            IsAmmo = InventorySlotType == InventorySlotType.Ammo;
            IsKey = Class == ItemClass.Key;
            IsBag = InventorySlotType == InventorySlotType.Bag;
            IsContainer = Class == ItemClass.Container || Class == ItemClass.Quiver;

            // enchantables can't be stacked
            IsStackable = MaxAmount > 1 && RandomSuffixId == 0 && RandomPropertiesId == 0;
            IsTwoHandWeapon = InventorySlotType == InventorySlotType.TwoHandWeapon;
            SetIsWeapon();

            if (ToolCategory != 0)// && TotemCategory != TotemCategory.SkinningKnife)
            {
                ItemMgr.FirstTotemsPerCat[(uint)ToolCategory] = this;
            }

            if (GemPropertiesId != 0)
            {
                GemProperties = EnchantMgr.GetGemproperties(GemPropertiesId);
                if (GemProperties != null)
                {
                    GemProperties.Enchantment.GemTemplate = this;
                }
            }

            if (Sockets == null)
            {
                Sockets = new SocketInfo[ItemConstants.MaxSocketCount];
            }
            else if (Sockets.Contains(sock => sock.Color != 0))
            {
                HasSockets = true;
            }

            if (Damages == null)
            {
                Damages = DamageInfo.EmptyArray;
            }

            if (Resistances == null)
            {
                Resistances = new int[(int)DamageSchool.Count];
            }

            if (SocketBonusEnchantId != 0)
            {
                SocketBonusEnchant = EnchantMgr.GetEnchantmentEntry(SocketBonusEnchantId);
            }

            switch (Class)
            {
                case ItemClass.Weapon:
                    ItemProfession = ItemProfessions.WeaponSubClassProfessions.Get((uint)SubClass);
                    break;
                case ItemClass.Armor:
                    ItemProfession = ItemProfessions.ArmorSubClassProfessions.Get((uint)SubClass);
                    break;
            }

            if (SheathType == SheathType.Undetermined)
            {
                // TODO: Read sheath-id from Item.dbc
            }

            // spells
            if (Spells != null)
            {
                ArrayUtil.Prune(ref Spells);
                for (int i = 0; i < 5; i++)
                {
                    Spells[i].Index = (uint)i;
                    Spells[i].FinalizeAfterLoad();
                }
            }
            else
            {
                Spells = ItemSpell.EmptyArray;
            }

            UseSpell = Spells.Where(itemSpell => itemSpell.Trigger == ItemSpellTrigger.Use && itemSpell.Spell != null).FirstOrDefault();
            if (UseSpell != null)
            {
                UseSpell.Spell.RequiredTargetType = RequiredTargetType;
                UseSpell.Spell.RequiredTargetId = RequiredTargetId;
            }

            EquipSpells = Spells.Where(spell => spell.Trigger == ItemSpellTrigger.Equip && spell.Spell != null).Select(itemSpell =>
                    itemSpell.Spell).ToArray();

            SoulstoneSpell = Spells.Where(spell => spell.Trigger == ItemSpellTrigger.Soulstone && spell.Spell != null).Select(itemSpell =>
                    itemSpell.Spell).FirstOrDefault();

            HitSpells = Spells.Where(spell => spell.Trigger == ItemSpellTrigger.ChanceOnHit && spell.Spell != null).Select(itemSpell =>
                    itemSpell.Spell).ToArray();

            if (UseSpell != null && (UseSpell.Id == SpellId.Learning || UseSpell.Id == SpellId.Learning_2))
            {
                // Teaching
                TeachSpell = Spells.Where(spell => spell.Trigger == ItemSpellTrigger.Consume).FirstOrDefault();
            }

            ConsumesAmount =
                (Class == ItemClass.Consumable ||
                Spells.Contains(spell => spell.Trigger == ItemSpellTrigger.Consume)) &&
                (UseSpell == null || !UseSpell.HasCharges);

            IsHearthStone = UseSpell != null && UseSpell.Spell.IsHearthStoneSpell;

            IsInventory = InventorySlotType != InventorySlotType.None &&
                InventorySlotType != InventorySlotType.Bag &&
                InventorySlotType != InventorySlotType.Quiver &&
                InventorySlotType != InventorySlotType.Relic;

            // find set
            if (SetId != 0)
            {
                var set = ItemMgr.Sets.Get((uint)SetId);
                if (set != null)
                {
                    ArrayUtil.Add(ref set.Templates, this);
                }
            }

            // truncate arrays
            if (Mods != null)
            {
                ArrayUtil.TruncVals(ref Mods);
            }
            else
            {
                Mods = StatModifier.EmptyArray;
            }

            IsCharter = Flags.HasFlag(ItemFlags.Charter);

            RandomSuffixFactor = EnchantMgr.GetRandomSuffixFactor(this);

            if (IsCharter)
            {
                Creator = () => new PetitionCharter();
            }
            else if (IsContainer)
            {
                Creator = () => new Container();
            }
            else
            {
                Creator = () => new Item();
            }
        }
Exemplo n.º 7
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 FinalizeAfterLoad()
		{
			NPCId = (NPCId)Id;
			SetFlagIndeces = Utility.GetSetIndices((uint)Flags);
			DefaultFaction = FactionMgr.Get(DefaultFactionId);

			if (AuraIds != null)
			{
				var auras = new List<Spell>(AuraIds.Length);
				foreach (var auraId in AuraIds)
				{
					var spell = SpellHandler.Get(auraId);
					if (spell != null)
					{
						auras.Add(spell);
					}
				}
				Auras = auras.ToArray();
			}
			else
			{
				Auras = Spell.EmptyArray;
			}

			var entry = NPCMgr.GetEntry(Id);
			if (entry != null)
			{
				// set the prototype
				entry.Prototype = this;
				Entry = entry;
			}

			InstanceTypeHandlers = NPCMgr.GetNPCTypeHandlers(this);
			SpawnTypeHandlers = NPCMgr.GetNPCSpawnTypeHandlers(this);
		}
Exemplo n.º 8
0
        public bool IsHostile(Faction faction)
        {
            var rep = GetOrCreate(faction.ReputationIndex);

            return(rep != null && rep.Hostile);
        }
Exemplo n.º 9
0
        private ReputationFlags GetDefaultReputationFlags(Faction faction)
        {
            var entry = faction.Entry;
            for (int i = 0; i < 4; i++)
            {
				if ((entry.ClassMask[i] == 0 || entry.ClassMask[i].HasAnyFlag(Owner.ClassMask)) &&
					(entry.RaceMask[i] == 0 || entry.RaceMask[i].HasAnyFlag(Owner.RaceMask)))
                {
                    return (ReputationFlags) entry.BaseFlags[i];
                }
            }
            return ReputationFlags.None;
        }
Exemplo n.º 10
0
		public bool CanAttack(Faction faction)
		{
			var rep = GetOrCreate(faction.ReputationIndex);
			return rep == null || rep.Hostile;
		}
Exemplo n.º 11
0
		/// <summary>
		/// Initialize the GO
		/// </summary>
		/// <param name="entry"></param>
		/// <param name="templ"></param>
		internal virtual void Init(GOEntry entry, GOTemplate templ)
		{
			EntityId = EntityId.GetGameObjectId((uint)Interlocked.Increment(ref _lastGOUID), entry.GOId);
			Type |= ObjectTypes.GameObject;
			//DynamicFlagsLow = GameObjectDynamicFlagsLow.Activated;
			m_entry = entry;
			m_template = templ;

			DisplayId = entry.DisplayId;
			EntryId = entry.Id;
			GOType = entry.Type;
			Flags = m_entry.Flags;
			m_faction = m_entry.Faction ?? Faction.NullFaction;
			ScaleX = m_entry.DefaultScale;

			if (templ != null)
			{
				Phase = templ.PhaseMask;
				State = templ.State;
				if (templ.Scale != 1)
				{
					ScaleX = templ.Scale;
				}
				Orientation = templ.Orientation;
				AnimationProgress = templ.AnimProgress;
				SetRotationFields(templ.Rotations);
			}

			m_entry.InitGO(this);
		}
Exemplo n.º 12
0
		public bool IsNeutralWith(Faction otherFaction)
		{
			return Neutrals.Contains(otherFaction);
		}
Exemplo n.º 13
0
		private static void InitFactionTemplateDBC()
		{
			var dbcRdr =
				new MappedDBCReader<FactionTemplateEntry, FactionTemplateConverter>(
					RealmServerConfiguration.GetDBCFile(WCellDef.DBC_FACTION_TEMPLATES));

			foreach (var templ in dbcRdr.Entries.Values)
			{
				FactionTplEntries[templ.Id] = templ;

				if (templ.FactionId == 0)
				{
					// some templates do not have an actual faction
					continue;
				}

				var entry = FactionEntries[templ.FactionId];
				var faction = new Faction(entry, templ);
				ArrayUtil.Set(ref ByTemplateId, templ.Id, faction);

				// there are several templates for one faction
				if (Get(templ.FactionId) != null)
				{
					continue;
				}

				ArrayUtil.Set(ref ById, (uint)entry.Id, faction);

				if (entry.FactionIndex > 0)
				{
					ArrayUtil.Set(ref ByReputationIndex, (uint)entry.FactionIndex, faction);
				}
			}

			// add Factions for Races and set their faction-group
			Faction fac;
			ByRace[(uint)RaceId.Human] = fac = ById[(uint)FactionId.PLAYERHuman];
			fac.SetAlliancePlayer();

			ByRace[(uint)RaceId.Dwarf] = fac = ById[(uint)FactionId.PLAYERDwarf];
			fac.SetAlliancePlayer();

			ByRace[(uint)RaceId.NightElf] = fac = ById[(uint)FactionId.PLAYERNightElf];
			fac.SetAlliancePlayer();

			ByRace[(uint)RaceId.Gnome] = fac = ById[(uint)FactionId.PLAYERGnome];
			fac.SetAlliancePlayer();

			ByRace[(uint)RaceId.Draenei] = fac = ById[(uint)FactionId.PLAYERDraenei];
			fac.SetAlliancePlayer();


			ByRace[(uint)RaceId.Orc] = fac = ById[(uint)FactionId.PLAYEROrc];
			fac.SetHordePlayer();

			ByRace[(uint)RaceId.Undead] = fac = ById[(uint)FactionId.PLAYERUndead];
			fac.SetHordePlayer();

			ByRace[(uint)RaceId.Tauren] = fac = ById[(uint)FactionId.PLAYERTauren];
			fac.SetHordePlayer();

			ByRace[(uint)RaceId.Troll] = fac = ById[(uint)FactionId.PLAYERTroll];
			fac.SetHordePlayer();

			ByRace[(uint)RaceId.BloodElf] = fac = ById[(uint)FactionId.PLAYERBloodElf];
			fac.SetHordePlayer();

			foreach (var faction in ById)
			{
				if (faction != null)
				{
					faction.Init();
					if (faction.Entry.ParentId != FactionId.None)
					{
						var parent = Get(faction.Entry.ParentId);
						// some factions are pointing to invalid other factions (so we have to use TryGetValue)
						if (parent != null)
						{
							parent.Children.Add(faction);
						}
					}
				}
			}
		}
Exemplo n.º 14
0
        public bool IsHostileTowards(Faction otherFaction)
        {
            // Start out with specific checks
            if (Template.EnemyFactions.Length > 0)
            {
                for (int i = 0; i < Template.EnemyFactions.Length; i++)
                {
                    // Are they an enemy?
                    if (Template.EnemyFactions[i] == otherFaction.Template.FactionId)
                        return true;

                    // or a friend?
                    if (Template.FriendlyFactions[i] == otherFaction.Template.FactionId)
                        return false;
                }
            }

            // Fall back to a general check
            return Template.EnemyGroup.Has(otherFaction.Template.FactionGroup);
        }
Exemplo n.º 15
0
		public virtual void FinalizeDataHolder()
		{
			if (Id != 0)
			{
				GOId = (GOEntryId)Id;
			}
			else
			{
				Id = (uint)GOId;
			}

			if (FactionId != 0)
			{
				Faction = FactionMgr.Get(FactionId);
			}

			InitEntry();

			if (HandlerCreator == null)
			{
				HandlerCreator = GOMgr.Handlers[(int) Type];
			}

			if (GOCreator == null)
			{
				if (IsTransport)
				{
					GOCreator = () => new Transport();
				}
				else
				{
					GOCreator = () => new GameObject();
				}
			}

			if (Fields != null)		// ignore invalid ones
			{
				//Fields = null;
				GOMgr.Entries[Id] = this;
			}
		}
Exemplo n.º 16
0
        public bool CanAttack(Faction faction)
        {
            var rep = GetOrCreate(faction.ReputationIndex);

            return(rep == null || rep.Hostile);
        }
Exemplo n.º 17
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))
			{
				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;
			}
		}
Exemplo n.º 18
0
        public bool IsFriendlyTowards(Faction otherFaction)
        {
			if (Friends.Contains(otherFaction))
			{
				return true;
			}

            // specific checks
            if (Template.EnemyFactions.Length > 0)
            {
                for (int i = 0; i < Template.FriendlyFactions.Length; i++)
                {
                    // Are they a friend?
                    if (Template.FriendlyFactions[i] == otherFaction.Template.FactionId)
                        return true;
                    // or an enemy?
                    if (Template.EnemyFactions[i] == otherFaction.Template.FactionId)
                        return false;
                }
            }

            // Fall back to a general check
			return Template.FriendGroup.HasAnyFlag(otherFaction.Template.FactionGroup);
        }
Exemplo n.º 19
0
		public bool IsHostile(Faction faction)
		{
			var rep = GetOrCreate(faction.ReputationIndex);
			return rep != null && rep.Hostile;
		}
Exemplo n.º 20
0
 public NPC CreateMob(Faction faction)
 {
     Setup.EnsureNPCsLoaded();
     var newNpc = NPCMgr.GetEntry(DefaultMobId).Create();
     return newNpc;
 }
Exemplo n.º 21
0
		/// <summary>
		/// Creates a Reputation object that represents the relation to the given faction, or null
		/// </summary>
		/// <param name="faction">The Faction which the Reputation should be with</param>
		private Reputation Create(Faction faction)
		{
		    var defaultValue = GetDefaultReputationValue(faction);
		    var defaultFlags = GetDefaultReputationFlags(faction);
		    var newRecord = m_owner.Record.CreateReputationRecord();
		    var rep = new Reputation(newRecord, faction, defaultValue, defaultFlags);
			m_byIndex.Add(faction.ReputationIndex, rep);
            
            // For some reason, this also makes the faction visible ...
		    FactionHandler.SendReputationStandingUpdate(m_owner.Client, rep);
			return rep;
		}
Exemplo n.º 22
0
		/// <summary>
		/// Initialize the GO
		/// </summary>
		/// <param name="entry"></param>
		/// <param name="templ"></param>
		internal virtual void Init(GOEntry entry, GOSpawnEntry spawnEntry, GOSpawnPoint spawnPoint)
		{
			EntityId = EntityId.GetGameObjectId((uint)Interlocked.Increment(ref _lastGOUID), entry.GOId);
			Type |= ObjectTypes.GameObject;
			//DynamicFlagsLow = GameObjectDynamicFlagsLow.Activated;
			m_entry = entry;
			m_spawnPoint = spawnPoint;

			DisplayId = entry.DisplayId;
			EntryId = entry.Id;
			GOType = entry.Type;
			Flags = m_entry.Flags;
			m_faction = m_entry.Faction ?? Faction.NullFaction;
			ScaleX = m_entry.Scale;

			spawnEntry = spawnEntry ?? entry.FirstSpawnEntry;
			if (spawnEntry != null)
			{
				Phase = spawnEntry.Phase;
				State = spawnEntry.State;
				if (spawnEntry.Scale != 1)
				{
					ScaleX = spawnEntry.Scale;
				}
				Orientation = spawnEntry.Orientation;
				AnimationProgress = spawnEntry.AnimProgress;
				SetRotationFields(spawnEntry.Rotations);
			}

			m_entry.InitGO(this);
		}
Exemplo n.º 23
0
	    private int GetDefaultReputationValue(Faction faction)
        {
            var entry = faction.Entry;
            for (int i = 0; i < 4; i++)
            {
				if ((entry.ClassMask[i] == 0 || entry.ClassMask[i].HasAnyFlag(Owner.ClassMask)) &&
					(entry.RaceMask[i] == 0 || entry.RaceMask[i].HasAnyFlag(Owner.RaceMask)))
                {
                    return entry.BaseRepValue[i];
                }
            }
            return 0;
        }
Exemplo n.º 24
0
 public bool IsNeutralWith(Faction otherFaction)
 {
     return(Neutrals.Contains(otherFaction));
 }