public AttachmentTimer(XmlAttachment attachment, TimeSpan delay) : base(delay) { Priority = TimerPriority.OneSecond; m_Attachment = attachment; }
public void CheckAutoReward() { if (!this.Deleted && AutoReward && IsCompleted && Owner != null && ((RewardItem != null && !m_RewardItem.Deleted) || (RewardAttachment != null && !m_RewardAttachment.Deleted))) { if (RewardItem != null) { // make sure nothing has been added to the pack other than the original reward items CheckRewardItem(); m_RewardItem.Movable = true; if (m_Pack != null) { // make sure all of the items in the pack are movable as well PackItemsMovable(m_Pack, true); } //RefreshPackLocation(Owner, false); Owner.AddToBackpack(m_RewardItem); //AddMobileWeight(Owner,m_RewardItem); m_RewardItem = null; } if (RewardAttachment != null) { Timer.DelayCall(TimeSpan.Zero, new TimerStateCallback(AttachToCallback), new object[] { Owner, m_RewardAttachment }); m_RewardAttachment = null; } Owner.SendMessage(String.Format("{0} completed. You receive the quest reward!", Name)); this.Delete(); } }
public override void OnKill(Mobile killed, Mobile killer) { base.OnKill(killed, killer); // supports ignoring XmlPoints challenges if (m_ChallengeStatus) { m_ChallengeStatus = false; return; } if (killed == null || killer == null || killer == killed) { return; } // check for within guild kills and ignore them if (SameGuild(killed, killer)) { return; } // this calculates the base faction level that will be gained/lost based upon the fame of the killed mob double value = (double)(killed.Fame / 1000.0); if (value <= 0) { value = 1; } // calculates credits gained in a similar way int cval = (int)(killed.Fame * m_CreditScale); if (cval <= 0) { cval = 1; } Credits += cval; // prepare the group lists that will be checked for faction List <XmlMobFactions.Group> glist = null; List <XmlMobFactions.Group> dglist = null; // check to see whether this mob type has already been hashed into a group list if (!GroupHash.TryGetValue(killed.GetType(), out glist) || glist == null) { // otherwise look it up the slow way and prepare a hash entry for it at the same time // unless it is using dynamic faction glist = new List <XmlMobFactions.Group>(); foreach (Group g in KillGroups) { if (MatchType(g.Members, killed)) { glist.Add(g); } } GroupHash[killed.GetType()] = glist; } // have to look up dynamic factions the exhaustive way // does this mob have dynamic faction assignments? XmlAttachment dynam = XmlAttach.FindAttachment(killed, typeof(XmlDynamicFaction)); if (dynam != null) { //if(XmlAttach.FindAttachment(XmlAttach.MobileAttachments, killed, typeof(XmlDynamicFaction)) != null) //{ dglist = new List <XmlMobFactions.Group>(); foreach (Group g in KillGroups) { if (XmlDynamicFaction.MatchFaction(killed, g.DynamicFaction)) { dglist.Add(g); } } } List <List <XmlMobFactions.Group> > alist = new List <List <XmlMobFactions.Group> >(); if (glist != null && glist.Count > 0) { alist.Add(glist); } if (dglist != null && dglist.Count > 0) { alist.Add(dglist); } // go through this with static and dynamic factions foreach (List <XmlMobFactions.Group> al in alist) { foreach (Group g in al) { // tabulate the faction loss from target group allies if (g.Allies != null && g.Allies.Length > 0) { for (int i = 0; i < g.Allies.Length; i++) { Group ally = g.Allies[i]; int facloss = 0; try { facloss = (int)(value * g.AllyLoss[i]); } catch {} if (facloss <= 0) { facloss = 1; } int p = GetFactionLevel(ally.GroupType) - facloss; SetFactionLevel(ally.GroupType, p); if (verboseMobFactions) { killer.SendMessage("lost {0} faction {1}", ally.GroupType, facloss); } } } // tabulate the faction gain from target group opponents if (g.Opponents != null && g.Opponents.Length > 0) { for (int i = 0; i < g.Opponents.Length; i++) { Group opp = g.Opponents[i]; int facgain = 0; try { facgain = (int)(value * g.OpponentGain[i]); } catch {} if (facgain <= 0) { facgain = 1; } int p = GetFactionLevel(opp.GroupType) + facgain; SetFactionLevel(opp.GroupType, p); if (verboseMobFactions) { killer.SendMessage("gained {0} faction {1}", opp.GroupType, facgain); } } } } } m_EndTime = DateTime.UtcNow + Refractory; }
public AttachmentTimer(XmlAttachment attachment, TimeSpan delay) : base(delay) { this.Priority = TimerPriority.OneSecond; this.m_Attachment = attachment; }
private void RestoreRewardAttachment() { m_RewardAttachment = XmlAttach.FindAttachmentBySerial(m_RewardAttachmentSerialNumber); }
private static bool AttachTo(object from, object o, XmlAttachment attachment, bool first) { if (!(o is Item || o is Mobile) || attachment == null) return false; Hashtable attachments = null; if (o is Item) { if (ItemAttachments == null) { ItemAttachments = new Hashtable(); } attachments = ItemAttachments; } else if (o is Mobile) { if (MobileAttachments == null) { MobileAttachments = new Hashtable(); } attachments = MobileAttachments; } XmlAttach.Defrag(o); // see if there is already an attachment list for the object ArrayList attachmententry = FindAttachments(attachments, o, true); if (attachmententry != null) { // if an existing entry list was found then just add the attachment to that list after making sure there is not a duplicate foreach (XmlAttachment i in attachmententry) { // and attachment is considered a duplicate if both the type and name match if (i != null && !i.Deleted && i.GetType() == attachment.GetType() && i.Name == attachment.Name) { // duplicate found so replace it i.Delete(); } } attachmententry.Add(attachment); } else { // otherwise make a new entry list attachmententry = new ArrayList(1); // containing the attachment attachmententry.Add(attachment); // and add it to the hash table attachments.Add(o, attachmententry); } attachment.AttachedTo = o; attachment.OwnedBy = o; if (from is Mobile) { attachment.SetAttachedBy(((Mobile)from).Name); } else if (from is Item) { attachment.SetAttachedBy(((Item)from).Name); } // if this is being attached for the first time, then call the OnAttach method // if it is being reattached due to deserialization then dont if (first) { attachment.OnAttach(); } else { attachment.OnReattach(); } return !attachment.Deleted; }
private static void SerialDefrag(XmlAttachment a) { if (a != null && a.Deleted) AllAttachments.Remove(a.Serial.Value); }
public static bool AttachTo(object from, object o, XmlAttachment attachment) { return AttachTo(from, o, attachment, true); }
public static bool AttachTo(object o, XmlAttachment attachment, bool first) { return AttachTo(null, o, attachment, first); }
public void CheckAutoReward() { if (!this.Deleted && this.AutoReward && this.IsCompleted && this.Owner != null && ((this.RewardItem != null && !this.m_RewardItem.Deleted) || (this.RewardAttachment != null && !this.m_RewardAttachment.Deleted))) { if (this.RewardItem != null) { // make sure nothing has been added to the pack other than the original reward items this.CheckRewardItem(); this.m_RewardItem.Movable = true; // make sure all of the items in the pack are movable as well this.PackItemsMovable(this, true); this.Owner.AddToBackpack(this.m_RewardItem); //AddMobileWeight(Owner,m_RewardItem); this.m_RewardItem = null; } if (this.RewardAttachment != null) { Timer.DelayCall(TimeSpan.Zero, new TimerStateCallback(AttachToCallback), new object[] { this.Owner, this.m_RewardAttachment }); this.m_RewardAttachment = null; } this.Owner.SendMessage(String.Format("{0} completed. You receive the quest reward!", this.Name)); this.Delete(); } }
public static void ATTACH(TriggerObject trigObj, IEntity target, XmlAttachment xmlattachment) { Mobile targetMobile = target as Mobile; Item targetItem = target as Item; if (targetMobile == null && targetItem == null) { throw new UberScriptException( "ATTACH function requires either Mobile or Item target, but had a " + target + " target"); } if (xmlattachment == null) { throw new UberScriptException("ATTACH function requires non-null xmlattachment!"); } XmlAttach.AttachTo(target, xmlattachment); }
public static void HashSerial(ASerial key, XmlAttachment o) { if (key.Value != 0) { AllAttachments.Add(key.Value, o); } else { UnassignedAttachments.Add(o); } }
public static void Save(WorldSaveEventArgs e) { if (EntityAttachments == null) { return; } CleanUp(); if (!Directory.Exists("Saves/Attachments")) { Directory.CreateDirectory("Saves/Attachments"); } string filePath = Path.Combine("Saves/Attachments", "Attachments.bin"); // the attachment serializations string imaPath = Path.Combine("Saves/Attachments", "Attachments.ima"); // the item/mob attachment tables string fpiPath = Path.Combine("Saves/Attachments", "Attachments.fpi"); // the file position indices BinaryFileWriter writer = null; BinaryFileWriter imawriter = null; BinaryFileWriter fpiwriter = null; try { writer = new BinaryFileWriter(filePath, true); imawriter = new BinaryFileWriter(imaPath, true); fpiwriter = new BinaryFileWriter(fpiPath, true); } catch (Exception err) { ErrorReporter.GenerateErrorReport(err.ToString()); return; } if (writer != null && imawriter != null && fpiwriter != null) { // save the current global attachment serial state ASerial.GlobalSerialize(writer); // remove all deleted attachments FullDefrag(); // save the attachments themselves if (AllAttachments != null) { writer.Write(AllAttachments.Count); var valuearray = new XmlAttachment[AllAttachments.Count]; AllAttachments.Values.CopyTo(valuearray, 0); var keyarray = new int[AllAttachments.Count]; AllAttachments.Keys.CopyTo(keyarray, 0); for (int i = 0; i < keyarray.Length; i++) { // write the key writer.Write(keyarray[i]); XmlAttachment a = valuearray[i]; // write the value type writer.Write(a.GetType().ToString()); // serialize the attachment itself a.Serialize(writer); // save the fileposition index fpiwriter.Write(writer.Position); } } else { writer.Write(0); } writer.Close(); /* // Collapsed into a single IEntity Hash // save the hash table info for items and mobiles // mobile attachments if (XmlAttach.MobileAttachments != null) { imawriter.Write(XmlAttach.MobileAttachments.Count); object[] valuearray = new object[XmlAttach.MobileAttachments.Count]; XmlAttach.MobileAttachments.Values.CopyTo(valuearray, 0); object[] keyarray = new object[XmlAttach.MobileAttachments.Count]; XmlAttach.MobileAttachments.Keys.CopyTo(keyarray, 0); for (int i = 0; i < keyarray.Length; i++) { // write the key imawriter.Write((Mobile)keyarray[i]); // write out the attachments ArrayList alist = (ArrayList)valuearray[i]; imawriter.Write((int)alist.Count); foreach (XmlAttachment a in alist) { // write the attachment serial imawriter.Write((int)a.Serial.Value); // write the value type imawriter.Write((string)a.GetType().ToString()); // save the fileposition index fpiwriter.Write((long)imawriter.Position); } } } else { // no mobile attachments imawriter.Write((int)0); } // item attachments if (XmlAttach.ItemAttachments != null) { imawriter.Write(XmlAttach.ItemAttachments.Count); object[] valuearray = new object[XmlAttach.ItemAttachments.Count]; XmlAttach.ItemAttachments.Values.CopyTo(valuearray, 0); object[] keyarray = new object[XmlAttach.ItemAttachments.Count]; XmlAttach.ItemAttachments.Keys.CopyTo(keyarray, 0); for (int i = 0; i < keyarray.Length; i++) { // write the key imawriter.Write((Item)keyarray[i]); // write out the attachments ArrayList alist = (ArrayList)valuearray[i]; imawriter.Write((int)alist.Count); foreach (XmlAttachment a in alist) { // write the attachment serial imawriter.Write((int)a.Serial.Value); // write the value type imawriter.Write((string)a.GetType().ToString()); // save the fileposition index fpiwriter.Write((long)imawriter.Position); } } } else { // no item attachments imawriter.Write((int)0); }*/ // Alan MOD // save the hash table info for items and mobiles // mobile attachments if (EntityAttachments != null) { imawriter.Write(EntityAttachments.Count); var valuearray = new ArrayList[EntityAttachments.Count]; EntityAttachments.Values.CopyTo(valuearray, 0); var keyarray = new int[EntityAttachments.Count]; EntityAttachments.Keys.CopyTo(keyarray, 0); for (int i = 0; i < keyarray.Length; i++) { // write the key imawriter.Write(keyarray[i]); // write out the attachments ArrayList alist = valuearray[i]; imawriter.Write(alist.Count); foreach (XmlAttachment a in alist) { // write the attachment serial imawriter.Write(a.Serial.Value); // write the value type imawriter.Write(a.GetType().ToString()); // save the fileposition index fpiwriter.Write(imawriter.Position); } } } else { // no mobile attachments imawriter.Write(0); } imawriter.Write(0); // pretend no item attachments and leave the deserialization as-is -- this way deserialization will still work with older saves -Alan // END ALAN MOD imawriter.Close(); fpiwriter.Close(); } }
private static bool AttachTo(object from, IEntity o, XmlAttachment attachment, bool first) { if (o == null || attachment == null) { return false; } if (EntityAttachments == null) { EntityAttachments = new Dictionary<int, ArrayList>(); } if (o is AddonComponent) { // add the attachment to the parent addon instead AddonComponent component = (AddonComponent)o; if (component.Addon != null) { o = component.Addon; } } Defrag(o.Serial); // see if there is already an attachment list for the object ArrayList attachmententry = FindAttachments(o, true); if (attachmententry != null) { // if an existing entry list was found then just add the attachment to that list after making sure there is not a duplicate foreach (XmlAttachment i in attachmententry) { // and attachment is considered a duplicate if both the type and name match if (i != null && !i.Deleted && i.GetType() == attachment.GetType() && i.Name == attachment.Name) { // duplicate found so replace it i.Delete(); } } attachmententry.Add(attachment); } else { // otherwise make a new entry list attachmententry = new ArrayList(1); // containing the attachment attachmententry.Add(attachment); // and add it to the hash table EntityAttachments.Add(o.Serial.Value, attachmententry); } attachment.AttachedTo = o; attachment.OwnedBy = o; if (from is Mobile) { attachment.SetAttachedBy(((Mobile)from).Name); } else if (from is Item) { attachment.SetAttachedBy(((Item)from).Name); } // if this is being attached for the first time, then call the OnAttach method // if it is being reattached due to deserialization then dont if (first) { attachment.OnAttach(); } else { attachment.OnReattach(); } return !attachment.Deleted; }
public static bool AttachTo(IEntity o, XmlAttachment attachment, bool first) { return AttachTo(null, o, attachment, first); }
public static bool AttachTo(IEntity o, XmlAttachment attachment) { return AttachTo(null, o, attachment, true); }