/// <summary>
 /// Constructs a new ExecuteCommandEventArgs
 /// </summary>
 /// <param name="source">the source that executed the command</param>
 /// <param name="command">the command which was executed.</param>
 /// <param name="pars">the pars given!</param>
 public ExecuteCommandEventArgs(GamePlayer source, ScriptMgr.GameCommand command, string[] pars)
 {
     this.source = source;
     this.command = command;
     this.pars = pars;
 }
Exemplo n.º 2
0
        /// <summary>
        /// Load from Database override to clone objects from original Region.
        /// Loads Objects, Mobs, Areas from Database using "SkinID"
        /// </summary>
        public override void LoadFromDatabase(Mob[] mobObjs, ref long mobCount, ref long merchantCount, ref long itemCount, ref long bindCount)
        {
            if (!LoadObjects)
            {
                return;
            }

            Assembly gasm       = Assembly.GetAssembly(typeof(GameServer));
            var      staticObjs = GameServer.Database.SelectObjects <WorldObject>("Region = " + Skin);
            var      areaObjs   = GameServer.Database.SelectObjects <DBArea>("Region = " + Skin);


            int count = mobObjs.Length + staticObjs.Count;

            if (count > 0)
            {
                PreAllocateRegionSpace(count + 100);
            }

            int myItemCount     = staticObjs.Count;
            int myMobCount      = 0;
            int myMerchantCount = 0;

            string allErrors = string.Empty;

            if (mobObjs.Length > 0)
            {
                foreach (Mob mob in mobObjs)
                {
                    GameNPC myMob = null;
                    string  error = string.Empty;

                    // Default Classtype
                    string classtype = ServerProperties.Properties.GAMENPC_DEFAULT_CLASSTYPE;

                    // load template if any
                    INpcTemplate template = null;
                    if (mob.NPCTemplateID != -1)
                    {
                        template = NpcTemplateMgr.GetTemplate(mob.NPCTemplateID);
                    }


                    if (mob.Guild.Length > 0 && mob.Realm >= 0 && mob.Realm <= (int)eRealm._Last)
                    {
                        Type type = ScriptMgr.FindNPCGuildScriptClass(mob.Guild, (eRealm)mob.Realm);
                        if (type != null)
                        {
                            try
                            {
                                myMob = (GameNPC)type.Assembly.CreateInstance(type.FullName);
                            }
                            catch (Exception e)
                            {
                                if (log.IsErrorEnabled)
                                {
                                    log.Error("LoadFromDatabase", e);
                                }
                            }
                        }
                    }


                    if (myMob == null)
                    {
                        if (template != null && template.ClassType != null && template.ClassType.Length > 0 && template.ClassType != Mob.DEFAULT_NPC_CLASSTYPE && template.ReplaceMobValues)
                        {
                            classtype = template.ClassType;
                        }
                        else if (mob.ClassType != null && mob.ClassType.Length > 0 && mob.ClassType != Mob.DEFAULT_NPC_CLASSTYPE)
                        {
                            classtype = mob.ClassType;
                        }

                        try
                        {
                            myMob = (GameNPC)gasm.CreateInstance(classtype, false);
                        }
                        catch
                        {
                            error = classtype;
                        }

                        if (myMob == null)
                        {
                            foreach (Assembly asm in ScriptMgr.Scripts)
                            {
                                try
                                {
                                    myMob = (GameNPC)asm.CreateInstance(classtype, false);
                                    error = string.Empty;
                                }
                                catch
                                {
                                    error = classtype;
                                }

                                if (myMob != null)
                                {
                                    break;
                                }
                            }

                            if (myMob == null)
                            {
                                myMob = new GameNPC();
                                error = classtype;
                            }
                        }
                    }

                    if (!allErrors.Contains(error))
                    {
                        allErrors += " " + error + ",";
                    }

                    if (myMob != null)
                    {
                        try
                        {
                            Mob clone = (Mob)mob.Clone();
                            clone.AllowAdd    = false;
                            clone.AllowDelete = false;
                            clone.Region      = this.ID;

                            myMob.LoadFromDatabase(clone);

                            if (myMob is GameMerchant)
                            {
                                myMerchantCount++;
                            }
                            else
                            {
                                myMobCount++;
                            }
                        }
                        catch (Exception e)
                        {
                            if (log.IsErrorEnabled)
                            {
                                log.Error("Failed: " + myMob.GetType().FullName + ":LoadFromDatabase(" + mob.GetType().FullName + ");", e);
                            }
                            throw;
                        }

                        myMob.AddToWorld();
                    }
                }
            }

            if (staticObjs.Count > 0)
            {
                foreach (WorldObject item in staticObjs)
                {
                    WorldObject itemclone = (WorldObject)item.Clone();
                    itemclone.AllowAdd    = false;
                    itemclone.AllowDelete = false;
                    itemclone.Region      = this.ID;

                    GameStaticItem myItem;
                    if (!string.IsNullOrEmpty(itemclone.ClassType))
                    {
                        myItem = gasm.CreateInstance(itemclone.ClassType, false) as GameStaticItem;
                        if (myItem == null)
                        {
                            foreach (Assembly asm in ScriptMgr.Scripts)
                            {
                                try
                                {
                                    myItem = (GameStaticItem)asm.CreateInstance(itemclone.ClassType, false);
                                }
                                catch { }
                                if (myItem != null)
                                {
                                    break;
                                }
                            }
                            if (myItem == null)
                            {
                                myItem = new GameStaticItem();
                            }
                        }
                    }
                    else
                    {
                        myItem = new GameStaticItem();
                    }

                    myItem.AddToWorld();
                }
            }

            int areaCnt = 0;

            // Add missing area
            foreach (DBArea area in areaObjs)
            {
                // Don't bind in instance.
                if (area.ClassType.Equals("DOL.GS.Area+BindArea"))
                {
                    continue;
                }

                // clone DB object.
                DBArea newDBArea = ((DBArea)area.Clone());
                newDBArea.AllowAdd = false;
                newDBArea.Region   = this.ID;
                // Instantiate Area with cloned DB object and add to region
                try
                {
                    AbstractArea newArea = (AbstractArea)gasm.CreateInstance(newDBArea.ClassType, false);
                    newArea.LoadFromDatabase(newDBArea);
                    newArea.Sound        = newDBArea.Sound;
                    newArea.CanBroadcast = newDBArea.CanBroadcast;
                    newArea.CheckLOS     = newDBArea.CheckLOS;
                    this.AddArea(newArea);
                    areaCnt++;
                }
                catch
                {
                    log.Warn("area type " + area.ClassType + " cannot be created, skipping");
                    continue;
                }
            }

            if (myMobCount + myItemCount + myMerchantCount > 0)
            {
                if (log.IsInfoEnabled)
                {
                    log.Info(String.Format("AdventureWingInstance: {0} ({1}) loaded {2} mobs, {3} merchants, {4} items, {5}/{6} areas from DB ({7})", Description, ID, myMobCount, myMerchantCount, myItemCount, areaCnt, areaObjs.Count, TimeManager.Name));
                }

                log.Debug("Used Memory: " + GC.GetTotalMemory(false) / 1024 / 1024 + "MB");

                if (allErrors != string.Empty)
                {
                    log.Error("Error loading the following NPC ClassType(s), GameNPC used instead:" + allErrors.TrimEnd(','));
                }

                Thread.Sleep(0);  // give up remaining thread time to other resources
            }
            mobCount      += myMobCount;
            merchantCount += myMerchantCount;
            itemCount     += myItemCount;
        }
Exemplo n.º 3
0
        protected void ApplyRelicEffect()
        {
            if (RelicSpell == null || m_spellHandler == null || m_gameSpellEffect == null)
            {
                return;
            }

            IList <GamePlayer> newPlayerlist = new List <GamePlayer>();

            if (m_owner != null)
            {
                switch (RelicTarget.ToLower())
                {
                case "self":
                    newPlayerlist.Add(m_owner);
                    break;

                case "group":
                    if (m_owner.Group == null)
                    {
                        newPlayerlist.Add(m_owner);
                        break;
                    }
                    else
                    {
                        foreach (GamePlayer plr in m_owner.Group.GetPlayersInTheGroup())
                        {
                            if (plr != null && !newPlayerlist.Contains(plr) && m_owner.IsWithinRadius(plr, WorldMgr.VISIBILITY_DISTANCE))
                            {
                                newPlayerlist.Add(plr);
                            }
                        }
                    }
                    break;

                case "realm":
                    foreach (GamePlayer plr in m_owner.GetPlayersInRadius(WorldMgr.VISIBILITY_DISTANCE))
                    {
                        if (plr != null && GameServer.ServerRules.IsAllowedToAttack(m_owner, plr, true) == false && !newPlayerlist.Contains(plr))
                        {
                            newPlayerlist.Add(plr);
                        }
                    }
                    break;
                }
            }
            lock (Playerlist)
            {
                foreach (GamePlayer plr in Playerlist)
                {
                    if (plr == null)
                    {
                        continue;
                    }
                    if (!newPlayerlist.Contains(plr))
                    {
                        try
                        {
                            lock (plr.EffectList)
                            {
                                GameSpellEffect check = SpellHandler.FindEffectOnTarget(plr, m_gameSpellEffect.Spell.SpellType);
                                if (check != null)
                                {
                                    check.Cancel(false);
                                }
                            }
                        }
                        catch (Exception e)
                        {
                            if (log.IsErrorEnabled)
                            {
                                log.Error("Minotaur Relics : Effect Cancel : " + e);
                            }
                        }
                    }
                }
                foreach (GamePlayer plr in newPlayerlist)
                {
                    if (plr == null)
                    {
                        continue;
                    }
                    try
                    {
                        lock (plr.EffectList)
                        {
                            GameSpellEffect check = SpellHandler.FindEffectOnTarget(plr, m_gameSpellEffect.Spell.SpellType);
                            if (check == null)
                            {
                                ISpellHandler   handler   = ScriptMgr.CreateSpellHandler(plr, RelicSpell, SkillBase.GetSpellLine(GlobalSpellsLines.Reserved_Spells));
                                GameSpellEffect plreffect = null;
                                if (handler != null)
                                {
                                    plreffect = new GameSpellEffect(handler, RelicSpell.Duration, 0);
                                }
                                if (plreffect != null)
                                {
                                    plreffect.Start(plr);
                                }
                            }
                        }
                    }
                    catch (Exception e)
                    {
                        if (log.IsErrorEnabled)
                        {
                            log.Error("Minotaur Relics : Effect Start : " + e);
                        }
                    }
                }
                Playerlist = newPlayerlist;
            }
        }