From 067983b3ab10c2e548b2d887e74d1844e974a4ba Mon Sep 17 00:00:00 2001 From: Zane Wagner Date: Sun, 6 Nov 2016 11:00:24 -0600 Subject: [PATCH] No longer crashes when party members are far away. --- dev/Ultima/Player/Partying/PartySystem.cs | 8 +-- .../UI/WorldGumps/PartyHealthTrackerGump.cs | 71 ++++++++----------- dev/Ultima/World/WorldClient.cs | 2 +- 3 files changed, 36 insertions(+), 45 deletions(-) diff --git a/dev/Ultima/Player/Partying/PartySystem.cs b/dev/Ultima/Player/Partying/PartySystem.cs index 2e9f25d6..aeb538c1 100644 --- a/dev/Ultima/Player/Partying/PartySystem.cs +++ b/dev/Ultima/Player/Partying/PartySystem.cs @@ -76,7 +76,7 @@ public void ReceiveInvitation(PartyInvitationInfo info) public void AddMember(Serial serial) { - int index = m_PartyMembers.FindIndex(p => p.Mobile.Serial == serial); + int index = m_PartyMembers.FindIndex(p => p.Serial == serial); if (index != -1) { m_PartyMembers.RemoveAt(index); @@ -95,7 +95,7 @@ public PartyMember GetMember(int index) public PartyMember GetMember(Serial serial) { - return m_PartyMembers.Find(p => p.Mobile.Serial == serial); + return m_PartyMembers.Find(p => p.Serial == serial); } public void LeaveParty() @@ -215,7 +215,7 @@ public void RefreshPartyGumps() ui.RemoveControl(); for (int i = 0; i < Members.Count; i++) { - ui.AddControl(new PartyHealthTrackerGump(Members[i].Serial), 5, 40 + (48 * i)); + ui.AddControl(new PartyHealthTrackerGump(Members[i]), 5, 40 + (48 * i)); } Gump gump; if ((gump = ui.GetControl()) != null) @@ -231,7 +231,7 @@ public void RemoveMember(Serial serial) { INetworkClient network = ServiceRegistry.GetService(); network.Send(new PartyRemoveMemberPacket(serial)); - int index = m_PartyMembers.FindIndex(p => p.Mobile.Serial == serial); + int index = m_PartyMembers.FindIndex(p => p.Serial == serial); if (index != -1) { m_PartyMembers.RemoveAt(index); diff --git a/dev/Ultima/UI/WorldGumps/PartyHealthTrackerGump.cs b/dev/Ultima/UI/WorldGumps/PartyHealthTrackerGump.cs index 10476879..be9c1ac6 100644 --- a/dev/Ultima/UI/WorldGumps/PartyHealthTrackerGump.cs +++ b/dev/Ultima/UI/WorldGumps/PartyHealthTrackerGump.cs @@ -11,6 +11,7 @@ using UltimaXNA.Core.Input; using UltimaXNA.Core.UI; using UltimaXNA.Ultima.Player; +using UltimaXNA.Ultima.Player.Partying; using UltimaXNA.Ultima.UI.Controls; using UltimaXNA.Ultima.World; using UltimaXNA.Ultima.World.Entities.Mobiles; @@ -18,35 +19,34 @@ namespace UltimaXNA.Ultima.UI.WorldGumps { class PartyHealthTrackerGump : Gump { + Serial m_Serial; + Button btnPrivateMsg; GumpPic[] m_BarBGs; GumpPicWithWidth[] m_Bars; + TextLabel m_Name; - public PartyHealthTrackerGump(Serial serial) - : base(serial, 0) + public PartyHealthTrackerGump(PartyMember member) + : base(member.Serial, 0) { while (UserInterface.GetControl() != null) { - UserInterface.GetControl(serial).Dispose(); + UserInterface.GetControl(member.Serial).Dispose(); } IsMoveable = false; IsUncloseableWithRMB = true; - Mobile = WorldModel.Entities.GetObject(serial, false); - if (Mobile == null) - { - PlayerState.Partying.RemoveMember(serial); - Dispose(); - return; - } + m_Serial = member.Serial; //AddControl(m_Background = new ResizePic(this, 0, 0, 3000, 131, 48));//I need opacity %1 background - AddControl(new TextLabel(this, 1, 0, 1, Mobile.Name)); + AddControl(m_Name = new TextLabel(this, 1, 0, 1, member.Name)); //m_Background.MouseDoubleClickEvent += Background_MouseDoubleClickEvent; //maybe private message calling? m_BarBGs = new GumpPic[3]; int sameX = 15; int sameY = 3; - if (WorldModel.Entities.GetPlayerEntity().Serial != serial)//you can't send a message to self - AddControl(btnPrivateMsg = new Button(this, 0, 20, 11401, 11402, ButtonTypes.Activate, serial, 0));//private party message / use bandage ?? + if (WorldModel.Entities.GetPlayerEntity().Serial != member.Serial)//you can't send a message to self + { + AddControl(btnPrivateMsg = new Button(this, 0, 20, 11401, 11402, ButtonTypes.Activate, member.Serial, 0));//private party message / use bandage ?? + } AddControl(m_BarBGs[0] = new GumpPic(this, sameX, 15 + sameY, 9750, 0)); AddControl(m_BarBGs[1] = new GumpPic(this, sameX, 24 + sameY, 9750, 0)); AddControl(m_BarBGs[2] = new GumpPic(this, sameX, 33 + sameY, 9750, 0)); @@ -62,12 +62,6 @@ public PartyHealthTrackerGump(Serial serial) } } - public Mobile Mobile - { - get; - private set; - } - public override void OnButtonClick(int buttonID) { if (buttonID == 0)//private message @@ -78,33 +72,30 @@ public override void OnButtonClick(int buttonID) public override void Update(double totalMS, double frameMS) { - if (Mobile == null) + PartyMember member = PlayerState.Partying.GetMember(m_Serial); + if (member == null) { + Dispose(); return; } - if (PlayerState.Partying.Members.Count <= 1) + m_Name.Text = member.Name; + Mobile mobile = member.Mobile; + if (mobile == null) { - Dispose(); - return; + m_Bars[0].PercentWidthDrawn = m_Bars[1].PercentWidthDrawn = m_Bars[2].PercentWidthDrawn = 0f; + } + else + { + m_Bars[0].PercentWidthDrawn = ((float)mobile.Health.Current / mobile.Health.Max); + m_Bars[1].PercentWidthDrawn = ((float)mobile.Mana.Current / mobile.Mana.Max); + m_Bars[2].PercentWidthDrawn = ((float)mobile.Stamina.Current / mobile.Stamina.Max); + // I couldn't find correct visual + //if (Mobile.Flags.IsBlessed) + // m_Bars[0].GumpID = 0x0809; + //else if (Mobile.Flags.IsPoisoned) + // m_Bars[0].GumpID = 0x0808; } - m_Bars[0].PercentWidthDrawn = ((float)Mobile.Health.Current / Mobile.Health.Max); - - // I couldn't find correct visual - //if (Mobile.Flags.IsBlessed) - // m_Bars[0].GumpID = 0x0809; - //else if (Mobile.Flags.IsPoisoned) - // m_Bars[0].GumpID = 0x0808; - - m_Bars[1].PercentWidthDrawn = ((float)Mobile.Mana.Current / Mobile.Mana.Max); - - m_Bars[2].PercentWidthDrawn = ((float)Mobile.Stamina.Current / Mobile.Stamina.Max); - base.Update(totalMS, frameMS); } - - void Background_MouseDoubleClickEvent(AControl caller, int x, int y, MouseButton button)//need opacity %1 BG for this - { - //CALL PRIVATE MESSAGE METHOD ??? - } } } \ No newline at end of file diff --git a/dev/Ultima/World/WorldClient.cs b/dev/Ultima/World/WorldClient.cs index 9ecef7d6..014ccdec 100644 --- a/dev/Ultima/World/WorldClient.cs +++ b/dev/Ultima/World/WorldClient.cs @@ -1132,7 +1132,7 @@ void ReceiveGeneralInfo(IRecvPacket packet) PartyMember member = PlayerState.Partying.GetMember(msg.Source); // note: msx752 identified hue 50 for "targeted to : " and 34 for "Help me.. I'm stunned !!" ushort hue = (ushort)(msg.IsPrivate ? Settings.UserInterface.PartyPrivateMsgColor : Settings.UserInterface.PartyMsgColor); - ReceiveTextMessage(MessageTypes.PartyDisplayOnly, msg.Message, 3, hue, 0xFFFFFFF, member.Mobile.Name, true); + ReceiveTextMessage(MessageTypes.PartyDisplayOnly, msg.Message, 3, hue, 0xFFFFFFF, member.Name, true); break; case PartyInfo.CommandInvitation: PlayerState.Partying.ReceiveInvitation(partyInfo.Info as PartyInvitationInfo);