Skip to content

Commit

Permalink
No longer crashes when party members are far away.
Browse files Browse the repository at this point in the history
  • Loading branch information
ZaneDubya committed Nov 6, 2016
1 parent ada83f6 commit 067983b
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 45 deletions.
8 changes: 4 additions & 4 deletions dev/Ultima/Player/Partying/PartySystem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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()
Expand Down Expand Up @@ -215,7 +215,7 @@ public void RefreshPartyGumps()
ui.RemoveControl<PartyHealthTrackerGump>();
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<PartyGump>()) != null)
Expand All @@ -231,7 +231,7 @@ public void RemoveMember(Serial serial)
{
INetworkClient network = ServiceRegistry.GetService<INetworkClient>();
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);
Expand Down
71 changes: 31 additions & 40 deletions dev/Ultima/UI/WorldGumps/PartyHealthTrackerGump.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,42 +11,42 @@
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;

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<MobileHealthTrackerGump>() != null)
{
UserInterface.GetControl<MobileHealthTrackerGump>(serial).Dispose();
UserInterface.GetControl<MobileHealthTrackerGump>(member.Serial).Dispose();
}
IsMoveable = false;
IsUncloseableWithRMB = true;
Mobile = WorldModel.Entities.GetObject<Mobile>(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));
Expand All @@ -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
Expand All @@ -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 ???
}
}
}
2 changes: 1 addition & 1 deletion dev/Ultima/World/WorldClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down

0 comments on commit 067983b

Please sign in to comment.