Пример #1
0
        public void RemoveScriptTriggerLookup() // used when an xmlscript is removed
        {
            if (this.AttachedTo == null)
            {
                return;
            }

            // clear it out from the triggerlookup and rebuild it
            if (XmlScript.ScriptTriggerLookup.ContainsKey(this.AttachedTo.Serial.Value))
            {
                XmlScript.ScriptTriggerLookup.Remove(this.AttachedTo.Serial.Value);
            }

            if (this.AttachedTo.Deleted)
            {
                return;                          // leave it empty
            }
            List <XmlScript> scripts = XmlAttach.GetScripts(this.AttachedTo);

            foreach (XmlScript script in scripts)
            {
                if (script != this)
                {
                    script.UpdateScriptTriggerLookup();
                }
            }
        }
Пример #2
0
        /// <summary>
        ///     Checks for any triggers existing on "thisMob", returns true if a trigger signalled to override the
        ///     handler that it came from
        /// </summary>
        /// <returns>true if a trigger execution signalled to override the handler that called Trigger</returns>
        public static bool Trigger(
            IEntity thisObj,
            Mobile trigMob,
            TriggerName trigName,
            Item item           = null,
            string spoken       = null,
            Spell spell         = null,
            int damage          = 0,
            object targeted     = null,
            SkillName skillName = SkillName.Spellweaving,
            double skillValue   = 0.0)           // spellweaving is just a placeholder
        {
            var  scripts = XmlAttach.GetScripts(thisObj);
            bool result  = false;

            if (scripts != null)
            {
                TriggerObject trigObject = new TriggerObject
                {
                    TrigName   = trigName,
                    This       = thisObj,
                    TrigMob    = trigMob,
                    TrigItem   = item,
                    Spell      = spell,
                    Damage     = damage,
                    Speech     = spoken,
                    Targeted   = targeted,
                    SkillName  = skillName,
                    SkillValue = skillValue
                };

                int count = 0;

                foreach (XmlScript script in scripts)
                {
                    count++;

                    // make sure each script has its own TriggerObjects
                    if (script.Execute(count < scripts.Count ? trigObject.Dupe() : trigObject, true))
                    {
                        // returns true if there is an override
                        result = true;
                    }
                }
            }

            return(result);
        }