public void CreateMoneyTask()
		{
			GamePlayer player = CreateMockGamePlayer();

			GameMerchant merchant = new GameMerchant();
			merchant.Name = "Tester";
			merchant.Realm = eRealm.Albion;
			Console.WriteLine(player.Name);

			if (MoneyTask.CheckAvailability(player, merchant))
			{
				if (MoneyTask.BuildTask(player, merchant))
				{
					MoneyTask task = (MoneyTask)player.Task;


					Assert.IsNotNull(task);
					Console.WriteLine("XP" + task.RewardXP);
					Console.WriteLine("Item:" + task.ItemName);
					Console.WriteLine("Item:" + task.Name);
					Console.WriteLine("Item:" + task.Description);

					// Check Notify Event handling
					InventoryItem item = GameInventoryItem.Create(new ItemTemplate());
					item.Name = task.ItemName;

					GameNPC npc = new GameNPC();
					npc.Name = task.RecieverName;
					task.Notify(GamePlayerEvent.GiveItem, player, new GiveItemEventArgs(player, npc, item));

					if (player.Task.TaskActive || player.Task == null)
						Assert.Fail("Task did not finished proper in Notify");
				}
			}
		}
Example #2
0
        public static void ScriptLoaded(DOLEvent e, object sender, EventArgs args)
        {
            if (!ServerProperties.Properties.LOAD_EXAMPLES)
                return;

            #region defineNPCs

            GameNPC[] npcs = WorldMgr.GetNPCsByName("Sir Quait", eRealm.Albion);
            npcs = WorldMgr.GetNPCsByName("Sir Quait", (eRealm)1);
            GameNPC SirQuait = null;
            if (npcs.Length == 0)
            {
                SirQuait = new DOL.GS.GameNPC();
                SirQuait.Model = 40;
                SirQuait.Name = "Sir Quait";
                if (log.IsWarnEnabled)
                    log.Warn("Could not find " + SirQuait.Name + ", creating ...");
                SirQuait.Realm = eRealm.Albion;
                SirQuait.CurrentRegionID = 1;
                SirQuait.Size = 50;
                SirQuait.Level = 10;
                SirQuait.MaxSpeedBase = 100;
                SirQuait.Faction = FactionMgr.GetFactionByID(0);
                SirQuait.X = 531971;
                SirQuait.Y = 478955;
                SirQuait.Z = 0;
                SirQuait.Heading = 3570;
                SirQuait.RespawnInterval = 0;
                SirQuait.BodyType = 0;

                StandardMobBrain brain = new StandardMobBrain();
                brain.AggroLevel = 0;
                brain.AggroRange = 0;
                SirQuait.SetOwnBrain(brain);

                SirQuait.AddToWorld();
            }
            else
            {
                SirQuait = npcs[0];
            }

            #endregion

            #region defineBehaviours

            BaseBehaviour b = new BaseBehaviour(SirQuait);
            MessageAction a = new MessageAction(SirQuait,"This is just a simple test bahaviour.",eTextType.Emote);
            b.AddAction(a);
            InteractTrigger t = new InteractTrigger(SirQuait,b.NotifyHandler,SirQuait);
            b.AddTrigger(t);

            // store the behaviour in a list so it won't be garbage collected
            behaviours.Add(b);

            #endregion

            log.Info("Simple Test Behaviour added");
        }
Example #3
0
        public void CreateKillTask()
        {
            GamePlayer player = CreateMockGamePlayer();
            player.Level=5;
            player.AddToWorld();

            // Trainer for taks
            GameTrainer trainer = new GameTrainer();
            trainer.Name ="Tester";

            Console.WriteLine(player.Name);

            // player must have trainer selected when task given.
            player.TargetObject = trainer;

            // mob for task
            if (KillTask.BuildTask(player,trainer))
            {
                KillTask task =(KillTask) player.Task;

                Assert.IsNotNull(task);
                Assert.IsTrue(task.TaskActive);

                Console.WriteLine("Mob:"+ task.MobName);
                Console.WriteLine("Item:"+ task.ItemName);
                Console.WriteLine(""+ task.Description);

                // Check Notify Event handling
                InventoryItem item = GameInventoryItem.Create<ItemTemplate>(new ItemTemplate());
                item.Name = task.ItemName;

                GameNPC mob = new GameNPC();
                mob.Name = task.MobName;
                mob.X = player.X;
                mob.Y = player.Y;
                mob.Z = player.Z;
                mob.Level = player.Level;
                mob.CurrentRegionID = player.CurrentRegionID;
                mob.AddToWorld();

                // First we kill mob
                mob.XPGainers.Add(player,1.0F);
                task.Notify(GameNPCEvent.EnemyKilled,player,new EnemyKilledEventArgs(mob));

                // arificial pickup Item
                player.Inventory.AddItem(eInventorySlot.FirstEmptyBackpack, item);

                // Check item in Inventory
                if (player.Inventory.GetFirstItemByName(task.ItemName,eInventorySlot.FirstBackpack,eInventorySlot.LastBackpack) != null)
                    Assert.Fail("Player didn't recieve task item.");

                // Now give item tro trainer
                task.Notify(GamePlayerEvent.GiveItem,player,new GiveItemEventArgs(player,trainer,item));

                if (player.Task.TaskActive || player.Task==null)
                    Assert.Fail("Task did not finished proper in Notify");
            }
        }
Example #4
0
        public void AddRemoveObjects()
        {
            const int count = 30000;
            GameNPC[] mobs = new GameNPC[count];

            Console.Out.WriteLine("[{0}] init {1} mobs", id, count);
            // init mobs
            for (int i = 0; i < count; i++)
            {
                GameNPC mob = mobs[i] = new GameNPC();
                Assert.IsTrue(mob.ObjectID == -1, "mob {0} oid={1}, should be -1", i, mob.ObjectID);
                Assert.IsFalse(mob.ObjectState == GameObject.eObjectState.Active, "mob {0} state={1}, should be not Active", i, mob.ObjectState);
                mob.Name = "test mob " + i;
                mob.CurrentRegion = m_reg;
                m_reg.PreAllocateRegionSpace(1953);
            }

            for (int x = 10; x > 0; x--)
            {
                Console.Out.WriteLine("[{0}] loop {1} add mobs", id, count-x);
                // add mobs
                for (int i = 0; i <= count-x; i++)
                {
            //					Console.Out.WriteLine("add "+i);
                    GameNPC mob = mobs[i];
                    Assert.IsTrue(mob.AddToWorld(), "failed to add {0} to the world", mob.Name);
                    Assert.IsTrue(mob.ObjectID > 0 && mob.ObjectID <= DOL.GS.ServerProperties.Properties.REGION_MAX_OBJECTS, "{0} oid={1}", mob.Name, mob.ObjectID);
                }

                for (int i = count-x; i >= 0; i--)
                {
            //					Console.Out.WriteLine("check "+i);
                    GameNPC mob = mobs[i];
                    GameNPC regMob = (GameNPC)m_reg.GetObject((ushort)mob.ObjectID);
                    Assert.AreSame(mob, regMob, "expected to read '{0}' oid={1} but read '{2}' oid={3}", mob.Name, mob.ObjectID, regMob==null?"null":regMob.Name, regMob==null?"null":regMob.ObjectID.ToString());
                }

                Console.Out.WriteLine("[{0}] loop {1} remove mobs", id, count-x);
                // remove mobs
                for (int i = count-x; i >= 0; i--)
                {
            //					Console.Out.WriteLine("remove "+i);
                    GameNPC mob = mobs[i];
                    int oid = mob.ObjectID;
                    Assert.IsTrue(mob.RemoveFromWorld(), "failed to remove {0}", mob.Name);
                    Assert.IsTrue(mob.ObjectID == -1, "{0}: oid is not -1 (oid={1})", mob.Name, mob.ObjectID);
                    Assert.IsFalse(mob.ObjectState == GameObject.eObjectState.Active, "{0} is still active after remove", mob.Name);
                    GameNPC regMob = (GameNPC)m_reg.GetObject((ushort)oid);
                    Assert.IsNull(regMob, "{0} was removed from the region but oid {1} is still used by {2}", mob.Name, oid, regMob==null?"null":regMob.Name);
                }
            }
        }
Example #5
0
		[Test] public void AddObject()
		{
			Region region = WorldMgr.GetRegion(1);
			GameObject obj = new GameNPC();
			obj.Name="TestObject";
			obj.X = 400000;
			obj.Y = 200000;
			obj.Z = 2000;
			obj.CurrentRegion = region;

			obj.AddToWorld();

			if (obj.ObjectID<0)
				Assert.Fail("Failed to add object to Region. ObjectId < 0");

			Assert.AreEqual(region.GetObject((ushort)obj.ObjectID),obj);
		}
Example #6
0
        public void TestLootGenerator()
        {
            GameNPC mob = new GameNPC();
            mob.Level = 6;
            mob.Name="impling";

            for (int i=0;i< 15; i++)
            {
                Console.WriteLine("Loot "+i);
                ItemTemplate[] loot = LootMgr.GetLoot(mob, null);
                foreach (ItemTemplate item in loot)
                {
                    Console.WriteLine(mob.Name+" drops "+item.Name);
                }
            }

            Console.WriteLine("Drops finished");
        }
Example #7
0
        /// <summary>
        /// An account vault that masquerades as a house vault to the game client
        /// </summary>
        /// <param name="player">Player who owns the vault</param>
        /// <param name="vaultNPC">NPC controlling the interaction between player and vault</param>
        /// <param name="vaultOwner">ID of vault owner (can be anything unique, if it's the account name then all toons on account can access the items)</param>
        /// <param name="vaultNumber">Valid vault IDs are 0-3</param>
        /// <param name="dummyTemplate">An ItemTemplate to satisfy the base class's constructor</param>
        public AccountVault(GamePlayer player, GameNPC vaultNPC, string vaultOwner, int vaultNumber, ItemTemplate dummyTemplate)
            : base(dummyTemplate, vaultNumber)
        {
            m_player = player;
            m_vaultNPC = vaultNPC;
            m_vaultOwner = vaultOwner;
            m_vaultNumber = vaultNumber;

            DBHouse dbh = new DBHouse();
            //was allowsave = false but uhh i replaced with allowadd = false
            dbh.AllowAdd = false;
            dbh.GuildHouse = false;
            dbh.HouseNumber = player.ObjectID;
            dbh.Name = player.Name + "'s House";
            dbh.OwnerID = player.DBCharacter.ObjectId;
            dbh.RegionID = player.CurrentRegionID;

            CurrentHouse = new House(dbh);
        }
Example #8
0
		/// <summary>
		/// called when spell effect has to be started and applied to targets
		/// </summary>
		public override bool StartSpell(GameLiving target)
		{
			if (m_charmedNpc == null)
				m_charmedNpc = target as GameNPC; // save target on first start
			else
				target = m_charmedNpc; // reuse for pulsing spells

			if (target == null) return false;
			if (Util.Chance(CalculateSpellResistChance(target)))
			{
				OnSpellResisted(target);
			}
			else
			{
				ApplyEffectOnTarget(target, 1);
			}

			return true;
		}
Example #9
0
        public static bool LockRelic()
        {
            //make sure the relic exists before you lock it!
            if (Relic == null)
                return false;

            LockedEffect = new GameNPC();
            LockedEffect.Model = 1583;
            LockedEffect.Name = "LOCKED_RELIC";
            LockedEffect.X = Relic.X;
            LockedEffect.Y = Relic.Y;
            LockedEffect.Z = Relic.Z;
            LockedEffect.Heading = Relic.Heading;
            LockedEffect.CurrentRegionID = Relic.CurrentRegionID;
            LockedEffect.Flags = GameNPC.eFlags.CANTTARGET;
            LockedEffect.AddToWorld();

            return true;
        }
Example #10
0
		/// <summary>
        /// Generate loot for given mob
		/// </summary>
		/// <param name="mob"></param>
		/// <param name="killer"></param>
		/// <returns></returns>
		public override LootList GenerateLoot(GameNPC mob, GameObject killer)
		{
			LootList loot = base.GenerateLoot(mob, killer);

			int lvl = mob.Level + 1;
			if (lvl < 1) lvl = 1;
			int minLoot = 2 + ((lvl * lvl * lvl) >> 3);

			long moneyCount = minLoot + Util.Random(minLoot >> 1);
			moneyCount = (long)((double)moneyCount * ServerProperties.Properties.MONEY_DROP);

			ItemTemplate money = new ItemTemplate();
			money.Model = 488;
			money.Name = "bag of coins";
			money.Level = 0;

			money.Price = moneyCount;
			
			loot.AddFixed(money, 1);
			return loot;
		}
		/// <summary>
		/// Create a copy of the GameNPC
		/// </summary>
		/// <param name="copyTarget">A GameNPC to copy this GameNPC to (can be null)</param>
		/// <returns>The GameNPC this GameNPC was copied to</returns>
		public GameNPC Copy( GameNPC copyTarget )
		{
			if ( copyTarget == null )
				copyTarget = new GameNPC();

			copyTarget.TranslationId = TranslationId;
			copyTarget.BlockChance = BlockChance;
			copyTarget.BodyType = BodyType;
			copyTarget.CanUseLefthandedWeapon = CanUseLefthandedWeapon;
			copyTarget.Charisma = Charisma;
			copyTarget.Constitution = Constitution;
			copyTarget.CurrentRegion = CurrentRegion;
			copyTarget.Dexterity = Dexterity;
			copyTarget.Empathy = Empathy;
			copyTarget.Endurance = Endurance;
			copyTarget.EquipmentTemplateID = EquipmentTemplateID;
			copyTarget.EvadeChance = EvadeChance;
			copyTarget.Faction = Faction;
			copyTarget.Flags = Flags;
			copyTarget.GuildName = GuildName;
			copyTarget.ExamineArticle = ExamineArticle;
			copyTarget.MessageArticle = MessageArticle;
			copyTarget.Heading = Heading;
			copyTarget.Intelligence = Intelligence;
			copyTarget.IsCloakHoodUp = IsCloakHoodUp;
			copyTarget.IsCloakInvisible = IsCloakInvisible;
			copyTarget.IsHelmInvisible = IsHelmInvisible;
			copyTarget.LeftHandSwingChance = LeftHandSwingChance;
			copyTarget.Level = Level;
			copyTarget.LoadedFromScript = LoadedFromScript;
			copyTarget.MaxSpeedBase = MaxSpeedBase;
			copyTarget.MeleeDamageType = MeleeDamageType;
			copyTarget.Model = Model;
			copyTarget.Name = Name;
			copyTarget.Suffix = Suffix;
			copyTarget.NPCTemplate = NPCTemplate;
			copyTarget.ParryChance = ParryChance;
			copyTarget.PathID = PathID;
			copyTarget.PathingNormalSpeed = PathingNormalSpeed;
			copyTarget.Quickness = Quickness;
			copyTarget.Piety = Piety;
			copyTarget.Race = Race;
			copyTarget.Realm = Realm;
			copyTarget.RespawnInterval = RespawnInterval;
			copyTarget.RoamingRange = RoamingRange;
			copyTarget.Size = Size;
			copyTarget.SaveInDB = SaveInDB;
			copyTarget.Strength = Strength;
			copyTarget.TetherRange = TetherRange;
			copyTarget.MaxDistance = MaxDistance;
			copyTarget.X = X;
			copyTarget.Y = Y;
			copyTarget.Z = Z;
			copyTarget.OwnerID = OwnerID;
			copyTarget.PackageID = PackageID;

			if ( Abilities != null && Abilities.Count > 0 )
			{
				foreach (Ability targetAbility in Abilities.Values)
				{
					if ( targetAbility != null )
						copyTarget.AddAbility( targetAbility );
				}
			}

			ABrain brain = null;
			foreach ( Assembly assembly in AppDomain.CurrentDomain.GetAssemblies() )
			{
				brain = (ABrain)assembly.CreateInstance( Brain.GetType().FullName, true );
				if ( brain != null )
					break;
			}

			if ( brain == null )
			{
				log.Warn( "GameNPC.Copy():  Unable to create brain:  " + Brain.GetType().FullName + ", using StandardMobBrain." );
				brain = new StandardMobBrain();
			}

			StandardMobBrain newBrainSMB = brain as StandardMobBrain;
			StandardMobBrain thisBrainSMB = this.Brain as StandardMobBrain;

			if ( newBrainSMB != null && thisBrainSMB != null )
			{
				newBrainSMB.AggroLevel = thisBrainSMB.AggroLevel;
				newBrainSMB.AggroRange = thisBrainSMB.AggroRange;
			}

			copyTarget.SetOwnBrain( brain );

			if ( Inventory != null && Inventory.AllItems.Count > 0 )
			{
				GameNpcInventoryTemplate inventoryTemplate = Inventory as GameNpcInventoryTemplate;

				if( inventoryTemplate != null )
					copyTarget.Inventory = inventoryTemplate.CloneTemplate();
			}

			if (Spells != null && Spells.Count > 0)
				copyTarget.Spells = new List<Spell>(Spells.Cast<Spell>());

			if ( Styles != null && Styles.Count > 0 )
				copyTarget.Styles = new ArrayList( Styles );

			if ( copyTarget.Inventory != null )
				copyTarget.SwitchWeapon( ActiveWeaponSlot );

			return copyTarget;
		}
		/// <summary>
		/// Whether this NPC is a friend or not.
		/// </summary>
		/// <param name="npc">The NPC that is checked against.</param>
		/// <returns></returns>
		public virtual bool IsFriend(GameNPC npc)
		{
			if (Faction == null || npc.Faction == null)
				return false;
			return (npc.Faction == Faction || Faction.FriendFactions.Contains(npc.Faction));
		}
		/// <summary>
		/// Removes the npc from the world
		/// </summary>
		/// <returns>true if the npc has been successfully removed</returns>
		public override bool RemoveFromWorld()
		{
			if (IsMovingOnPath)
				StopMovingOnPath();
			if (MAX_PASSENGERS > 0)
			{
				foreach (GamePlayer player in CurrentRiders)
				{
					player.DismountSteed(true);
				}
			}

			if (ObjectState == eObjectState.Active)
			{
				foreach (GamePlayer player in GetPlayersInRadius(WorldMgr.VISIBILITY_DISTANCE))
					player.Out.SendObjectRemove(this);
			}
			if (!base.RemoveFromWorld()) return false;

			lock (BrainSync)
			{
				ABrain brain = Brain;
				brain.Stop();
			}
			EffectList.CancelAll();

			if (ShowTeleporterIndicator && m_teleporterIndicator != null)
			{
				m_teleporterIndicator.RemoveFromWorld();
				m_teleporterIndicator = null;
			}

			return true;
		}
		/// <summary>
		/// Adds the npc to the world
		/// </summary>
		/// <returns>true if the npc has been successfully added</returns>
		public override bool AddToWorld()
		{
			if (!base.AddToWorld()) return false;

			if (MAX_PASSENGERS > 0)
				Riders = new GamePlayer[MAX_PASSENGERS];

			bool anyPlayer = false;
			foreach (GamePlayer player in GetPlayersInRadius(WorldMgr.VISIBILITY_DISTANCE))
			{
				if (player == null) continue;
				player.Out.SendNPCCreate(this);
				if (m_inventory != null)
					player.Out.SendLivingEquipmentUpdate(this);
				
				// If any player was initialized, update last visible tick to enable brain
				anyPlayer = true;
			}
			
			if (anyPlayer)
				m_lastVisibleToPlayerTick = (uint)Environment.TickCount;
			
			m_spawnPoint.X = X;
			m_spawnPoint.Y = Y;
			m_spawnPoint.Z = Z;
			m_spawnHeading = Heading;
			lock (BrainSync)
			{
				ABrain brain = Brain;
				if (brain != null)
					brain.Start();
			}

			if (Mana <= 0 && MaxMana > 0)
				Mana = MaxMana;
			else if (Mana > 0 && MaxMana > 0)
				StartPowerRegeneration();

			//If the Mob has a Path assigned he will now walk on it!
			if (MaxSpeedBase > 0 && CurrentSpellHandler == null && !IsMoving
			    && !AttackState && !InCombat && !IsMovingOnPath && !IsReturningHome
			    //Check everything otherwise the Server will crash
			    && PathID != null && PathID != "" && PathID != "NULL")
			{
				PathPoint path = MovementMgr.LoadPath(PathID);
				if(path != null)
				{
					CurrentWayPoint = path;
					MoveOnPath((short)path.MaxSpeed);
				}
			}

			if (m_houseNumber > 0 && !(this is GameConsignmentMerchant))
			{
				log.Info("NPC '" + Name + "' added to house " + m_houseNumber);
				CurrentHouse = HouseMgr.GetHouse(m_houseNumber);
				if (CurrentHouse == null)
					log.Warn("House " + CurrentHouse + " for NPC " + Name + " doesn't exist !!!");
				else
					log.Info("Confirmed number: " + CurrentHouse.HouseNumber.ToString());
			}
			
			// [Ganrod] Nidel: spawn full life
			if (!InCombat && IsAlive && base.Health < MaxHealth)
			{
				base.Health = MaxHealth;
			}
			
			// create the ambiant text list for this NPC
			BuildAmbientTexts();
			if (GameServer.Instance.ServerStatus == eGameServerStatus.GSS_Open)
				FireAmbientSentence(eAmbientTrigger.spawning);


			if (ShowTeleporterIndicator)
			{
				if (m_teleporterIndicator == null)
				{
					m_teleporterIndicator = new GameNPC();
					m_teleporterIndicator.Name = "";
					m_teleporterIndicator.Model = 1923;
					m_teleporterIndicator.Flags ^= eFlags.PEACE;
					m_teleporterIndicator.Flags ^= eFlags.CANTTARGET;
					m_teleporterIndicator.Flags ^= eFlags.DONTSHOWNAME;
					m_teleporterIndicator.Flags ^= eFlags.FLYING;
					m_teleporterIndicator.X = X;
					m_teleporterIndicator.Y = Y;
					m_teleporterIndicator.Z = Z + 1;
					m_teleporterIndicator.CurrentRegionID = CurrentRegionID;
				}

				m_teleporterIndicator.AddToWorld();
			}
			
			return true;
		}
Example #15
0
		/// <summary>
		/// Generate loot for given mob
		/// </summary>
		/// <param name="mob"></param>
		/// <param name="killer"></param>
		/// <returns></returns>
		public virtual LootList GenerateLoot(GameNPC mob, GameObject killer)
		{
			LootList loot = new LootList();
			return loot;
		}
Example #16
0
        /// <summary>
        /// Create an add from the specified template.
        /// </summary>
        /// <param name="templateID"></param>
        /// <param name="level"></param>
        /// <param name="x"></param>
        /// <param name="y"></param>
        /// <param name="uptime"></param>
        /// <returns></returns>
        protected GameNPC SpawnTimedAdd(int templateID, int level, int x, int y, int uptime, bool isRetriever)
        {
            GameNPC add = null;

            try
            {
                if (m_addTemplate == null || m_addTemplate.TemplateId != templateID)
                {
                    m_addTemplate = NpcTemplateMgr.GetTemplate(templateID);
                }

                // Create add from template.
                // The add will automatically despawn after 30 seconds.

                if (m_addTemplate != null)
                {
                    add = new GameNPC(m_addTemplate);

                    if (isRetriever)
                    {
                        add.SetOwnBrain(new RetrieverMobBrain());
                    }
                    add.CurrentRegion = this.CurrentRegion;
                    add.Heading = (ushort)(Util.Random(0, 4095));
                    add.Realm = 0;
                    add.X = x;
                    add.Y = y;
                    add.Z = Z;
                    add.CurrentSpeed = 0;
                    add.Level = (byte)level;
                    add.RespawnInterval = -1;
                    add.AddToWorld();
                    new DespawnTimer(this, add, uptime * 1000);
                }
            }
            catch
            {
                log.Warn(String.Format("Unable to get template for {0}", Name));
            }
            return add;
        }
		/// <summary>
		/// Reload the loot templates for this mob
		/// </summary>
		/// <param name="mob"></param>
		public override void Refresh(GameNPC mob)
		{
			if (mob == null)
				return;

			bool isDefaultLootTemplateRefreshed = false;

			// First see if there are any MobXLootTemplates associated with this mob

			IList<MobXLootTemplate> mxlts = GameServer.Database.SelectObjects<MobXLootTemplate>("`MobName` = @MobName", new QueryParameter("@MobName", mob.Name));

			if (mxlts != null)
			{
				lock (m_mobXLootTemplates)
				{
					foreach (MobXLootTemplate mxlt in mxlts)
					{
						List<MobXLootTemplate> mobxLootTemplates;
						if (!m_mobXLootTemplates.TryGetValue(mxlt.MobName.ToLower(), out mobxLootTemplates))
						{
							mobxLootTemplates = new List<MobXLootTemplate>();
							m_mobXLootTemplates[mxlt.MobName.ToLower()] = mobxLootTemplates;
						}
						mobxLootTemplates.Add(mxlt);

						RefreshLootTemplate(mxlt.LootTemplateName);


						if (mxlt.LootTemplateName.ToLower() == mob.Name.ToLower())
							isDefaultLootTemplateRefreshed = true;
					}
				}
			}

			// now force a refresh of the mobs default loot template

			if (isDefaultLootTemplateRefreshed == false)
				RefreshLootTemplate(mob.Name);
		}
Example #18
0
            /// <summary>
            /// Called on every timer tick.
            /// </summary>
            protected override void OnTick()
            {
                // Remove the NPC from the world.

                if (m_npc != null)
                {
                    m_npc.Delete();
                    m_npc = null;
                }
            }
Example #19
0
        /// <summary>
        /// Invoked when retriever type mob has reached its target location.
        /// </summary>
        /// <param name="sender">The retriever mob.</param>
        public override void OnRetrieverArrived(GameNPC sender)
        {
            base.OnRetrieverArrived(sender);
            if (sender == null || sender == this) return;

            // Spawn nasty adds.

            if (m_retrieverList.Contains(sender))
                SpawnDrakulvs(Util.Random(7, 10), sender.X, sender.Y);
        }
Example #20
0
		/// <summary>
		/// Returns the ILootGenerators for the given mobs
		/// </summary>
		/// <param name="mob"></param>
		/// <returns></returns>
		public static IList GetLootGenerators(GameNPC mob)
		{
			IList filteredGenerators = new ArrayList();
			ILootGenerator exclusiveGenerator = null;

			IList nameGenerators = (IList)m_mobNameGenerators[mob.Name];
			IList guildGenerators = (IList)m_mobGuildGenerators[mob.GuildName];
			IList regionGenerators = (IList)m_mobRegionGenerators[(int)mob.CurrentRegionID];

			//IList factionGenerators = m_mobFactionGenerators[mob.Faction]; not implemented

			ArrayList allGenerators = new ArrayList();

			allGenerators.AddRange(m_globalGenerators);

			if (nameGenerators != null)
				allGenerators.AddRange(nameGenerators);
			if (guildGenerators != null)
				allGenerators.AddRange(guildGenerators);
			if (regionGenerators != null)
				allGenerators.AddRange(regionGenerators);

			foreach (ILootGenerator generator in allGenerators)
			{
				if (generator.ExclusivePriority > 0)
				{
					if (exclusiveGenerator == null || exclusiveGenerator.ExclusivePriority < generator.ExclusivePriority)
						exclusiveGenerator = generator;
				}

				// if we found a exclusive generator skip adding other generators, since list will only contain exclusive generator.
				if (exclusiveGenerator != null)
					continue;

				if (!filteredGenerators.Contains(generator))
					filteredGenerators.Add(generator);
			}

			// if an exclusivegenerator is found only this one is used.
			if (exclusiveGenerator != null)
			{
				filteredGenerators.Clear();
				filteredGenerators.Add(exclusiveGenerator);
			}

			return filteredGenerators;
		}
Example #21
0
		/// <summary>
		/// Returns the loot for the given Mob
		/// </summary>		
		/// <param name="mob"></param>
		/// <param name="killer"></param>
		/// <returns></returns>
		public static ItemTemplate[] GetLoot(GameNPC mob, GameObject killer)
		{
			LootList lootList = null;
			IList generators = GetLootGenerators(mob);
			foreach (ILootGenerator generator in generators)
			{
				try
				{
					if (lootList == null)
						lootList = generator.GenerateLoot(mob, killer);
					else
						lootList.AddAll(generator.GenerateLoot(mob, killer));
				}
				catch (Exception e)
				{
					if (log.IsErrorEnabled)
						log.Error("GetLoot", e);
				}
			}
			if (lootList != null)
				return lootList.GetLoot();
			else
				return new ItemTemplate[0];
		}
Example #22
0
        /// <summary>
        /// Call the refresh method for each generator to update loot, if implemented
        /// </summary>
        /// <param name="mob"></param>
        public static void RefreshGenerators(GameNPC mob)
        {
			if (mob != null)
			{
				foreach (ILootGenerator gen in m_globalGenerators)
				{
					gen.Refresh(mob);
				}
			}
        }
 public CastingBehaviour(GameNPC body)
 {
     Body = body;
 }
		/// <summary>
        /// Generate loot for given mob
		/// </summary>
		/// <param name="mob"></param>
		/// <param name="killer"></param>
		/// <returns></returns>
		public override LootList GenerateLoot(GameNPC mob, GameObject killer)
		{
			LootList loot = base.GenerateLoot(mob, killer);
			
			try
			{
				GamePlayer player = killer as GamePlayer;
				if (killer is GameNPC && ((GameNPC)killer).Brain is IControlledBrain)
					player = ((ControlledNpcBrain)((GameNPC)killer).Brain).GetPlayerOwner();
				if (player == null)
					return loot;			
			
				
				ItemTemplate atlanteanGlass = new ItemTemplate(m_atlanteanglass);

				int killedcon = (int)player.GetConLevel(mob)+3;
				
				if(killedcon <= 0)
					return loot;
								
				int lvl = mob.Level + 1;
				if (lvl < 1) lvl = 1;
				int maxcount = 1;
				
				//Switch pack size
				if (lvl > 0 && lvl < 10) 
				{
					//Single AtlanteanGlass
					maxcount = (int)Math.Floor((double)(lvl/2))+1;
				}
				else if (lvl >= 10 && lvl < 20)
				{
					//Double
					atlanteanGlass.PackSize = 2;
					maxcount = (int)Math.Floor((double)((lvl-10)/2))+1;
				}
				else if (lvl >= 20 && lvl < 30)
				{
					//Triple
					atlanteanGlass.PackSize = 3;
					maxcount = (int)Math.Floor((double)((lvl-20)/2))+1;
					
				}
				else if (lvl >=30 && lvl < 40) 
				{
					//Quad
					atlanteanGlass.PackSize = 4;
					maxcount = (int)Math.Floor((double)((lvl-30)/2))+1;
				}
				else if (lvl >= 40 && lvl < 50)
				{
					//Quint
					atlanteanGlass.PackSize = 5;
					maxcount = (int)Math.Floor((double)((lvl-40)/2))+1;
				}
				else 
				{
					//Cache (x10)
					atlanteanGlass.PackSize = 10;
					maxcount = (int)Math.Round((double)(lvl/10));
				}
				
				if (!mob.Name.ToLower().Equals(mob.Name))
				{
					//Named mob, more cash !
					maxcount = (int)Math.Round(maxcount*ServerProperties.Properties.LOOTGENERATOR_ATLANTEANGLASS_NAMED_COUNT);
				}
				
				if(maxcount > 0 && Util.Chance(ServerProperties.Properties.LOOTGENERATOR_ATLANTEANGLASS_BASE_CHANCE+Math.Max(10, killedcon)))
				{
					loot.AddFixed(atlanteanGlass, maxcount);
				}
					
			}
			catch
			{
				return loot;
			}
			
			return loot;
		}
			/// <summary>
			/// Creates a new TurnBackAction
			/// </summary>
			/// <param name="actionSource">The source of action</param>
			public RestoreHeadingAction(GameNPC actionSource)
				: base(actionSource)
			{
				m_oldHeading = actionSource.Heading;
				m_oldPosition = new Point3D(actionSource);
			}
		public override LootList GenerateLoot(GameNPC mob, GameObject killer)
		{
			LootList loot = base.GenerateLoot(mob, killer);

			try
			{
				GamePlayer player = null;

				if (killer is GamePlayer)
				{
					player = killer as GamePlayer;
				}
				else if (killer is GameNPC && (killer as GameNPC).Brain is IControlledBrain)
				{
					player = ((killer as GameNPC).Brain as ControlledNpcBrain).GetPlayerOwner();
				}

				// allow the leader to decide the loot realm
				if (player != null && player.Group != null)
				{
					player = player.Group.Leader;
				}

				if (player != null)
				{
					List<MobXLootTemplate> killedMobXLootTemplates = null;
					
					// Graveen: we first privilegiate the loottemplate named 'templateid' if it exists	
					if (mob.NPCTemplate != null && m_mobXLootTemplates.ContainsKey(mob.NPCTemplate.TemplateId.ToString()))
					{
						killedMobXLootTemplates = m_mobXLootTemplates[mob.NPCTemplate.TemplateId.ToString()];
					}
					// else we are choosing the loottemplate named 'mob name'
					// this is easily allowing us to affect different level choosen loots to different level choosen mobs
					// with identical names
					else if (m_mobXLootTemplates.ContainsKey(mob.Name.ToLower()))
					{
						killedMobXLootTemplates = m_mobXLootTemplates[mob.Name.ToLower()];
					}

					// MobXLootTemplate contains a loot template name and the max number of drops allowed for that template.
					// We don't need an entry in MobXLootTemplate in order to drop loot, only to control the max number of drops.

					// LootTemplate contains a template name and an itemtemplateid (id_nb).
					// TemplateName usually equals Mob name, so if you want to know what drops for a mob:
					// select * from LootTemplate where templatename = 'mob name';
					// It is possible to have TemplateName != MobName but this works only if there is an entry in MobXLootTemplate for the MobName.

					if (killedMobXLootTemplates == null)
					{
						// If there is no MobXLootTemplate entry then every item in this mobs LootTemplate can drop.
						// In addition, we can use LootTemplate.Count to determine how many of a fixed (100% chance) item can drop
						if (m_lootTemplates.ContainsKey(mob.Name.ToLower()))
						{
							Dictionary<string, LootTemplate> lootTemplatesToDrop = m_lootTemplates[mob.Name.ToLower()];

							if (lootTemplatesToDrop != null)
							{
								foreach (LootTemplate lootTemplate in lootTemplatesToDrop.Values)
								{
									ItemTemplate drop = GameServer.Database.FindObjectByKey<ItemTemplate>(lootTemplate.ItemTemplateID);

									if (drop != null && (drop.Realm == (int)player.Realm || drop.Realm == 0 || player.CanUseCrossRealmItems))
									{
										if (lootTemplate.Chance == 100)
										{
											loot.AddFixed(drop, lootTemplate.Count);
										}
										else
										{
											loot.AddRandom(lootTemplate.Chance, drop, 1);
										}
									}
								}
							}
						}
					}
					else
					{
						// MobXLootTemplate exists and tells us the max number of items that can drop.
						// Because we are restricting the max number of items to drop we need to traverse the list
						// and add every 100% chance items to the loots Fixed list and add the rest to the Random list
						// due to the fact that 100% items always drop regardless of the drop limit

						List<LootTemplate> lootTemplatesToDrop = new List<LootTemplate>();
						foreach (MobXLootTemplate mobXLootTemplate in killedMobXLootTemplates)
						{
							loot = GenerateLootFromMobXLootTemplates(mobXLootTemplate, lootTemplatesToDrop, loot, player);

							if (lootTemplatesToDrop != null)
							{
								foreach (LootTemplate lootTemplate in lootTemplatesToDrop)
								{
									ItemTemplate drop = GameServer.Database.FindObjectByKey<ItemTemplate>(lootTemplate.ItemTemplateID);

									if (drop != null && (drop.Realm == (int)player.Realm || drop.Realm == 0 || player.CanUseCrossRealmItems))
									{
										loot.AddRandom(lootTemplate.Chance, drop, 1);
									}
								}
							}
						}
					}
				}
			}
			catch (Exception ex)
			{
				log.ErrorFormat("Error in LootGeneratorTemplate for mob {0}.  Exception: {1} {2}", mob.Name, ex.Message, ex.StackTrace);
			}

			return loot;
		}
			/// <summary>
			/// Constructs a new ArriveAtTargetAction
			/// </summary>
			/// <param name="actionSource">The action source</param>
			public ArriveAtTargetAction(GameNPC actionSource)
				: base(actionSource)
			{
			}
Example #28
0
 /// <summary>
 /// Constructs a new DespawnTimer.
 /// </summary>
 /// <param name="timerOwner">The owner of this timer.</param>
 /// <param name="npc">The GameNPC to despawn when the time is up.</param>
 /// <param name="delay">The time after which the add is supposed to despawn.</param>
 public DespawnTimer(GameObject timerOwner, GameNPC npc, int delay)
     : base(timerOwner.CurrentRegion.TimeManager)
 {
     m_npc = npc;
     Start(delay);
 }
Example #29
0
		public virtual void Refresh(GameNPC mob)
		{
		}
Example #30
0
 /// <summary>
 /// Invoked when retriever type mob has reached its target location.
 /// </summary>
 /// <param name="sender">The retriever mob.</param>
 public virtual void OnRetrieverArrived(GameNPC sender)
 {
 }
Example #31
0
        public static void ScriptLoaded(DOLEvent e, object sender, EventArgs args)
        {
            if (!ServerProperties.Properties.LOAD_EXAMPLES)
            {
                return;
            }

            #region defineNPCs

            GameNPC[] npcs = WorldMgr.GetNPCsByName("Sir Quait", eRealm.Albion);
            npcs = WorldMgr.GetNPCsByName("Sir Quait", (eRealm)1);
            GameNPC SirQuait = null;
            if (npcs.Length == 0)
            {
                SirQuait       = new DOL.GS.GameNPC();
                SirQuait.Model = 40;
                SirQuait.Name  = "Sir Quait";
                if (log.IsWarnEnabled)
                {
                    log.Warn("Could not find " + SirQuait.Name + ", creating ...");
                }
                SirQuait.Realm           = eRealm.Albion;
                SirQuait.CurrentRegionID = 1;
                SirQuait.Size            = 50;
                SirQuait.Level           = 10;
                SirQuait.MaxSpeedBase    = 100;
                SirQuait.Faction         = FactionMgr.GetFactionByID(0);
                SirQuait.X               = 531971;
                SirQuait.Y               = 478955;
                SirQuait.Z               = 0;
                SirQuait.Heading         = 3570;
                SirQuait.RespawnInterval = 0;
                SirQuait.BodyType        = 0;


                StandardMobBrain brain = new StandardMobBrain();
                brain.AggroLevel = 0;
                brain.AggroRange = 0;
                SirQuait.SetOwnBrain(brain);

                SirQuait.AddToWorld();
            }
            else
            {
                SirQuait = npcs[0];
            }

            #endregion

            #region defineBehaviours

            BaseBehaviour b = new BaseBehaviour(SirQuait);
            MessageAction a = new MessageAction(SirQuait, "This is just a simple test bahaviour.", eTextType.Emote);
            b.AddAction(a);
            InteractTrigger t = new InteractTrigger(SirQuait, b.NotifyHandler, SirQuait);
            b.AddTrigger(t);

            // store the behaviour in a list so it won't be garbage collected
            behaviours.Add(b);

            #endregion

            log.Info("Simple Test Behaviour added");
        }