From c19a8e60f557126b46993cbeab6df853373c692f Mon Sep 17 00:00:00 2001 From: Jeann Sebold Date: Wed, 15 Nov 2023 10:51:29 -0300 Subject: [PATCH 1/8] fix map --- src/ClassicUO.Client/ClassicUO.Client.csproj | 4 + .../Dust765/Dust765/CombatCollection.cs | 54 +- .../Game/Managers/PartyManager.cs | 16 +- .../Game/Managers/WorldMapEntityManager.cs | 111 ++- .../Game/UI/Controls/PaperDollInteractable.cs | 4 +- .../Game/UI/Gumps/RaceChangeGump.cs | 813 ++++++++++++++++++ .../Game/UI/Gumps/WorldMapGump.cs | 76 +- .../Network/PacketHandlers.cs | 5 +- 8 files changed, 1005 insertions(+), 78 deletions(-) create mode 100644 src/ClassicUO.Client/Game/UI/Gumps/RaceChangeGump.cs diff --git a/src/ClassicUO.Client/ClassicUO.Client.csproj b/src/ClassicUO.Client/ClassicUO.Client.csproj index 58bb7751e..1a16d085f 100644 --- a/src/ClassicUO.Client/ClassicUO.Client.csproj +++ b/src/ClassicUO.Client/ClassicUO.Client.csproj @@ -94,6 +94,10 @@ + + + + ..\..\external\cuoapi\cuoapi.dll diff --git a/src/ClassicUO.Client/Dust765/Dust765/CombatCollection.cs b/src/ClassicUO.Client/Dust765/Dust765/CombatCollection.cs index c254f1e78..d7513a347 100644 --- a/src/ClassicUO.Client/Dust765/Dust765/CombatCollection.cs +++ b/src/ClassicUO.Client/Dust765/Dust765/CombatCollection.cs @@ -280,7 +280,7 @@ public static ushort OwnAuraColorByHP() else if (ww < 1) ww = 0; - World.Player.UpdateHits((byte) ww); + World.Player.UpdateHits((byte)ww); } if (World.Player.HitsPercentage < 20) @@ -292,7 +292,7 @@ public static ushort OwnAuraColorByHP() else if (World.Player.HitsPercentage < 80) color = 0x0035; //yellow (but shows green?) else if (World.Player.HitsPercentage == 100) - color = (ushort) Notoriety.GetHue(World.Player.NotorietyFlag); + color = (ushort)Notoriety.GetHue(World.Player.NotorietyFlag); // "original colors from overhead %, < 30 0x0021, < 50 0x0030, < 80 0x0058" return color; @@ -375,6 +375,19 @@ public static void StartSpelltime() GameCursor._startSpellTime = Time.Ticks; } + public static bool CheckHighLineToTeleport(int destinationX, int destinationY) + { + GameObject selectedObject = World.Map.GetTile(destinationX, destinationY, false); + + ref StaticTiles staticTiles = ref TileDataLoader.Instance.StaticData[selectedObject.Graphic]; + + if (!staticTiles.IsImpassable) + { + return true; + } + return false; + } + //GAME\GAMEOBJECTS\VIEWS\ - MULTIVIEW.CS - STATICVIEW.CS - TILEVIEW.CS //24 - Wall of Stone //28 - Fire Field @@ -444,6 +457,7 @@ public static bool MultiFieldPreview(Multi obj) } } } + if (GameActions.LastSpellIndexCursor == 28 || GameActions.LastSpellIndexCursor == 39 || GameActions.LastSpellIndexCursor == 47 || GameActions.LastSpellIndexCursor == 50) { //Calc _fieldEastToWest @@ -515,7 +529,7 @@ public static bool MultiFieldPreview(Multi obj) } } } - if (GameActions.LastSpellIndexCursor == 48 || GameActions.LastSpellIndexCursor == 49 || GameActions.LastSpellIndexCursor == 55) + if (GameActions.LastSpellIndexCursor == 22 || GameActions.LastSpellIndexCursor == 48 || GameActions.LastSpellIndexCursor == 49 || GameActions.LastSpellIndexCursor == 55) { if (SelectedObject.Object != null && (SelectedObject.Object.RealScreenPosition.X + 22) == obj.RealScreenPosition.X && (SelectedObject.Object.RealScreenPosition.Y + 22) == obj.RealScreenPosition.Y) { @@ -677,6 +691,7 @@ public static bool StaticFieldPreview(Static obj) } } } + if (GameActions.LastSpellIndexCursor == 28 || GameActions.LastSpellIndexCursor == 39 || GameActions.LastSpellIndexCursor == 47 || GameActions.LastSpellIndexCursor == 50) { //Calc _fieldEastToWest @@ -748,7 +763,7 @@ public static bool StaticFieldPreview(Static obj) } } } - if (GameActions.LastSpellIndexCursor == 48 || GameActions.LastSpellIndexCursor == 49 || GameActions.LastSpellIndexCursor == 55) + if (GameActions.LastSpellIndexCursor == 22 || GameActions.LastSpellIndexCursor == 48 || GameActions.LastSpellIndexCursor == 49 || GameActions.LastSpellIndexCursor == 55) { if (SelectedObject.Object != null && (SelectedObject.Object.RealScreenPosition.X + 22) == obj.RealScreenPosition.X && (SelectedObject.Object.RealScreenPosition.Y + 22) == obj.RealScreenPosition.Y) { @@ -850,6 +865,9 @@ public static bool StaticFieldPreview(Static obj) } return false; } + + + public static bool LandFieldPreview(Land obj) { if (GameCursor._spellTime >= 1) @@ -911,6 +929,7 @@ public static bool LandFieldPreview(Land obj) } } } + if (GameActions.LastSpellIndexCursor == 28 || GameActions.LastSpellIndexCursor == 39 || GameActions.LastSpellIndexCursor == 47 || GameActions.LastSpellIndexCursor == 50) { //Calc _fieldEastToWest @@ -982,7 +1001,7 @@ public static bool LandFieldPreview(Land obj) } } } - if (GameActions.LastSpellIndexCursor == 48 || GameActions.LastSpellIndexCursor == 49 || GameActions.LastSpellIndexCursor == 55) + if (GameActions.LastSpellIndexCursor == 22 || GameActions.LastSpellIndexCursor == 48 || GameActions.LastSpellIndexCursor == 49 || GameActions.LastSpellIndexCursor == 55) { if (SelectedObject.Object != null && (SelectedObject.Object.RealScreenPosition.X + 22) == obj.RealScreenPosition.X && (SelectedObject.Object.RealScreenPosition.Y + 22) == obj.RealScreenPosition.Y) { @@ -1088,6 +1107,7 @@ public static bool MobileFieldPreview(Mobile obj) { if (GameCursor._spellTime >= 1) { + if (GameActions.LastSpellIndexCursor == 24) { //Calc _fieldEastToWest @@ -1145,6 +1165,7 @@ public static bool MobileFieldPreview(Mobile obj) } } } + if (GameActions.LastSpellIndexCursor == 28 || GameActions.LastSpellIndexCursor == 39 || GameActions.LastSpellIndexCursor == 47 || GameActions.LastSpellIndexCursor == 50) { //Calc _fieldEastToWest @@ -1216,7 +1237,7 @@ public static bool MobileFieldPreview(Mobile obj) } } } - if (GameActions.LastSpellIndexCursor == 48 || GameActions.LastSpellIndexCursor == 49 || GameActions.LastSpellIndexCursor == 55) + if (GameActions.LastSpellIndexCursor == 22 || GameActions.LastSpellIndexCursor == 48 || GameActions.LastSpellIndexCursor == 49 || GameActions.LastSpellIndexCursor == 55) { if (SelectedObject.Object != null && (SelectedObject.Object.RealScreenPosition.X + 22) == obj.RealScreenPosition.X && (SelectedObject.Object.RealScreenPosition.Y + 22) == obj.RealScreenPosition.Y) { @@ -1343,7 +1364,8 @@ public static void SpellCastFromCliloc(string text) if (ProfileManager.CurrentProfile.OnCastingGump) { if (!GameActions.iscasting) - World.Player.OnCasting.Start((uint) GameActions.LastSpellIndexCursor); + World.Player.OnCasting.Start((uint)GameActions.LastSpellIndexCursor); + World.Player.Hue = 0x0023; } // ## BEGIN - END ## // ONCASTINGGUMP } @@ -1355,7 +1377,7 @@ public static ushort SpellIconHue(ushort hue) switch (TargetManager.TargetingType) { case TargetType.Neutral: - hue = 0x0000; //BETTER HUE? 0x03B2 + hue = 0x03B2; //BETTER HUE? 0x03B2 return hue; case TargetType.Harmful: @@ -1489,8 +1511,8 @@ public static void HarmOnSwing() public static Point CalcUnderChar5(Mobile mobile) { Point p = mobile.RealScreenPosition; - p.X += (int) mobile.Offset.X + 22 + 5; - p.Y += (int) (mobile.Offset.Y - mobile.Offset.Z) + 22 + 5; + p.X += (int)mobile.Offset.X + 22 + 5; + p.Y += (int)(mobile.Offset.Y - mobile.Offset.Z) + 22 + 5; p = Client.Game.Scene.Camera.WorldToScreen(p); @@ -1500,8 +1522,8 @@ public static Point CalcUnderChar5(Mobile mobile) public static Point CalcUnderChar(Mobile mobile) { Point p = mobile.RealScreenPosition; - p.X += (int) mobile.Offset.X + 22; - p.Y += (int) (mobile.Offset.Y - mobile.Offset.Z) + 22; + p.X += (int)mobile.Offset.X + 22; + p.Y += (int)(mobile.Offset.Y - mobile.Offset.Z) + 22; p = Client.Game.Scene.Camera.WorldToScreen(p); @@ -1510,8 +1532,8 @@ public static Point CalcUnderChar(Mobile mobile) public static Point CalcOverChar(Mobile mobile) { Point p = mobile.RealScreenPosition; - p.X += (int) mobile.Offset.X + 22; - p.Y += (int) (mobile.Offset.Y - mobile.Offset.Z) + 22; + p.X += (int)mobile.Offset.X + 22; + p.Y += (int)(mobile.Offset.Y - mobile.Offset.Z) + 22; AnimationsLoader.Instance.GetAnimationDimensions ( @@ -1532,8 +1554,8 @@ out int height Point p1 = p; - p1.X = (int) (mobile.RealScreenPosition.X + mobile.Offset.X + 22); - p1.Y = (int) (mobile.RealScreenPosition.Y + (mobile.Offset.Y - mobile.Offset.Z) - (height + centerY + 8 + 22) + (mobile.IsGargoyle && mobile.IsFlying ? -22 : !mobile.IsMounted ? 22 : 0)); + p1.X = (int)(mobile.RealScreenPosition.X + mobile.Offset.X + 22); + p1.Y = (int)(mobile.RealScreenPosition.Y + (mobile.Offset.Y - mobile.Offset.Z) - (height + centerY + 8 + 22) + (mobile.IsGargoyle && mobile.IsFlying ? -22 : !mobile.IsMounted ? 22 : 0)); if (mobile.ObjectHandlesStatus == ObjectHandlesStatus.DISPLAYING) { diff --git a/src/ClassicUO.Client/Game/Managers/PartyManager.cs b/src/ClassicUO.Client/Game/Managers/PartyManager.cs index 028e231e2..ebed383e0 100644 --- a/src/ClassicUO.Client/Game/Managers/PartyManager.cs +++ b/src/ClassicUO.Client/Game/Managers/PartyManager.cs @@ -31,6 +31,7 @@ #endregion using System; +using Microsoft.Extensions.Caching.Memory; using ClassicUO.Configuration; using ClassicUO.Game.Data; using ClassicUO.Game.GameObjects; @@ -38,6 +39,7 @@ using ClassicUO.IO; using ClassicUO.Network; using ClassicUO.Resources; +using System.Collections.Generic; namespace ClassicUO.Game.Managers { @@ -55,6 +57,8 @@ internal class PartyManager public long PartyHealTimer { get; set; } public uint PartyHealTarget { get; set; } + + public void ParsePacket(ref StackDataReader p) { byte code = p.ReadUInt8(); @@ -246,6 +250,7 @@ public void Clear() internal class PartyMember : IEquatable { private string _name; + public Dictionary nameCache = new Dictionary(); public PartyMember(uint serial) { @@ -262,10 +267,19 @@ public string Name if (mobile != null) { _name = mobile.Name; + nameCache[mobile.Serial] = _name; if (string.IsNullOrEmpty(_name)) { - _name = ResGeneral.NotSeeing; + if (nameCache.TryGetValue(Serial, out string cachedName)) + { + _name = string.IsNullOrEmpty(_name) ? cachedName : _name; + } + else + { + _name = ResGeneral.NotSeeing; + } + } } diff --git a/src/ClassicUO.Client/Game/Managers/WorldMapEntityManager.cs b/src/ClassicUO.Client/Game/Managers/WorldMapEntityManager.cs index 81e86ce84..1699751f4 100644 --- a/src/ClassicUO.Client/Game/Managers/WorldMapEntityManager.cs +++ b/src/ClassicUO.Client/Game/Managers/WorldMapEntityManager.cs @@ -30,6 +30,8 @@ #endregion +using System; +using Microsoft.Extensions.Caching.Memory; using System.Collections.Generic; using ClassicUO.Configuration; using ClassicUO.Game.Data; @@ -43,33 +45,76 @@ namespace ClassicUO.Game.Managers { internal class WMapEntity { + public bool IsGuild; + public uint LastUpdate; + public string Name; + public uint Serial; + public int X, Y, HP, Map; + private static readonly Dictionary nameCache = new Dictionary(); + + + public WMapEntity(uint serial) { - Serial = serial; - //var mob = World.Mobiles.Get(serial); + Serial = serial; - //if (mob != null) - // GetName(); + GetName(); } - public bool IsGuild; - public uint LastUpdate; - public string Name; - public readonly uint Serial; - public int X, Y, HP, Map; - //public string GetName() - //{ - // Entity e = World.Get(Serial); - // if (e != null && !e.IsDestroyed && !string.IsNullOrEmpty(e.Name) && Name != e.Name) - // { - // Name = e.Name; - // } + public string GetName() + { + + Mobile mob = World.Mobiles.Get(Serial); + Entity e = World.Get(Serial); + + if (mob != null) + { + WMapEntity wme = World.WMapManager.GetEntity(mob); + + if (wme != null) + { + if (string.IsNullOrEmpty(wme.Name)) + { + + wme.Name = mob.Name; + + Name = wme.Name; + nameCache[Serial] = Name; + } + } + } + if (e != null) + { + Name = e.Name; + Serial = e.Serial; + + nameCache[Serial] = Name; + } - // return string.IsNullOrEmpty(Name) ? "" : Name; - //} + + + + // Entity e = World.Get(Serial); + // Mobile mob = World.Mobiles.Get(Serial); + + // if (e != null && !e.IsDestroyed && !string.IsNullOrEmpty(e.Name) && Name != e.Name) + //{ + // Name = e.Name; + //} + + if (nameCache.TryGetValue(Serial, out string cachedName)) + { + + return string.IsNullOrEmpty(Name) ? cachedName : Name; + } + + return "out of range"; + + + } } internal class WorldMapEntityManager @@ -87,7 +132,7 @@ public bool Enabled { return ((World.ClientFeatures.Flags & CharacterListFlags.CLF_NEW_MOVEMENT_SYSTEM) == 0 || _ackReceived) && EncryptionHelper.Type == 0 && - ProfileManager.CurrentProfile != null && ProfileManager.CurrentProfile.WorldMapShowParty && + ProfileManager.CurrentProfile != null && ProfileManager.CurrentProfile.WorldMapShowParty && UIManager.GetGump() != null; // horrible, but works } } @@ -158,7 +203,10 @@ public void AddOrUpdate { entity = new WMapEntity(serial) { - X = x, Y = y, HP = hp, Map = map, + X = x, + Y = y, + HP = hp, + Map = map, LastUpdate = Time.Ticks + 1000, IsGuild = isguild, Name = name @@ -270,6 +318,29 @@ public void RequestServerPartyGuildInfo(bool force = false) } } } + else + { + foreach (Mobile mob in World.Mobiles.Values) + { + if (mob == World.Player) + { + continue; + } + + Mobile mobs = World.Mobiles.Get(mob.Serial); + if (mobs.NotorietyFlag == NotorietyFlag.Ally) + { + if (mobs == null || mobs.Distance > 2000000) + { + NetClient.Socket.Send_QueryGuildPosition(); + + break; + } + } + + } + + } } } diff --git a/src/ClassicUO.Client/Game/UI/Controls/PaperDollInteractable.cs b/src/ClassicUO.Client/Game/UI/Controls/PaperDollInteractable.cs index 797c262f1..027d2c0d4 100644 --- a/src/ClassicUO.Client/Game/UI/Controls/PaperDollInteractable.cs +++ b/src/ClassicUO.Client/Game/UI/Controls/PaperDollInteractable.cs @@ -354,7 +354,7 @@ public void RequestUpdate() _updateUI = true; } - private static ushort GetAnimID(ushort graphic, ushort animID, bool isfemale) + public static ushort GetAnimID(ushort graphic, ushort animID, bool isfemale) { int offset = isfemale ? Constants.FEMALE_GUMP_OFFSET : Constants.MALE_GUMP_OFFSET; @@ -395,7 +395,7 @@ private static ushort GetAnimID(ushort graphic, ushort animID, bool isfemale) return (ushort) (animID + offset); } - private class GumpPicEquipment : GumpPic + public class GumpPicEquipment : GumpPic { private readonly Layer _layer; diff --git a/src/ClassicUO.Client/Game/UI/Gumps/RaceChangeGump.cs b/src/ClassicUO.Client/Game/UI/Gumps/RaceChangeGump.cs new file mode 100644 index 000000000..afa2cd1bb --- /dev/null +++ b/src/ClassicUO.Client/Game/UI/Gumps/RaceChangeGump.cs @@ -0,0 +1,813 @@ +using ClassicUO.Assets; +using ClassicUO.Configuration; +using ClassicUO.Game.Data; +using ClassicUO.Game.GameObjects; +using ClassicUO.Game.Managers; +using ClassicUO.Game.UI.Controls; +using ClassicUO.Input; +using ClassicUO.Network; +using System; +using System.Collections.Generic; + +namespace ClassicUO.Game.UI.Gumps +{ + internal class RaceChangeGump : Gump + { + private bool isFemale { get; } = false; + private RaceType selectedRace { get; } = RaceType.HUMAN; + private PlayerMobile fakeMobile; + private CustomPaperDollGump paperDollInteractable; + private readonly Dictionary> CurrentColorOption = new Dictionary>(); + private readonly Dictionary CurrentOption = new Dictionary() + { + { + Layer.Hair, 1 + }, + { + Layer.Beard, 0 + } + }; + private Item hair, beard; + + #region + private ushort raceTextGraphic + { + get + { + switch (selectedRace) + { + case RaceType.HUMAN: + return 0x702; + case RaceType.ELF: + return 0x705; + case RaceType.GARGOYLE: + return 0x7D4; + } + return 0; + } + } + private int raceTextWidth + { + get + { + switch (selectedRace) + { + case RaceType.HUMAN: + return 79; + case RaceType.ELF: + return 79; + case RaceType.GARGOYLE: + return 99; + } + return 0; + } + } + private ushort genderTextGraphic + { + get + { + return (ushort)(isFemale ? 0x70D : 0x710); + } + } + #endregion + + public RaceChangeGump(bool isFemale, byte race) : base(0, 0) + { + if (race <= 0 || race > (int)RaceType.GARGOYLE) + { + //Invalid race byte + Dispose(); + return; + } + + selectedRace = (RaceType)race; + this.isFemale = isFemale; + + X = 50; + Y = 50; + CanMove = false; + CanCloseWithRightClick = true; + AcceptMouseInput = true; + + BuildGump(); + + WantUpdateSize = true; + } + + private void BuildGump() + { + #region Background elements + Add + ( + new ResizePic(0x0E10) + { + X = 0, + Y = 0, + Width = 595, + Height = 400 + }, + 1 + ); //Main background + + Add + ( + new ResizePic(0x0E10) + { + X = 25, + Y = 45, + Width = 151, + Height = 310 + }, + 1 + ); //Left side, hair style etc + + Add + ( + new ResizePic(0x0E10) + { + X = 419, + Y = 45, + Width = 151, + Height = 310 + }, + 1 + ); //Right side tone/colors + #endregion + + Add(new GumpPic(176 - raceTextWidth, 360, raceTextGraphic, 0)); //non-functional "Button" that says Human, Elf, or Gargoyle + + Add(new GumpPic(419, 360, genderTextGraphic, 0)); //non-functional "Button" that says Male or Female + + Button confirmButton; + Add(confirmButton = new Button(0, 0x15A4, 0x15A6, 0x15A5) { X = 560, Y = 360 }); //Button to confirm, in classic client it is an arrow pointing right. + confirmButton.MouseUp += ConfirmButton_MouseUp; + + //Add hair styles + BuildHairStyles(40, 60); + + //Add color pickers + BuildColorOptions(434, 60); + + //Create fake character + CreateCharacter(); + UpdateEquipments(); + + //Add the main paperdoll graphic + Add(new GumpPic(185, 25, 0x708, 0)); + Add + ( + paperDollInteractable = new CustomPaperDollGump(210, 75, fakeMobile, hair, beard) + { + AcceptMouseInput = false + } + ); + + paperDollInteractable.RequestUpdate(); + + Add(new GumpPic(211, 15, 0x769, 0)); //Character Race Changer text + } + + /// + /// Build hair options for race change gump. + /// + /// The starting point for these ui elements + /// The starting point for these ui elements + private void BuildHairStyles(int x, int y) + { + #region TextSetup + bool isAsianLang = string.Compare(Settings.GlobalSettings.Language, "CHT", StringComparison.InvariantCultureIgnoreCase) == 0 || + string.Compare(Settings.GlobalSettings.Language, "KOR", StringComparison.InvariantCultureIgnoreCase) == 0 || + string.Compare(Settings.GlobalSettings.Language, "JPN", StringComparison.InvariantCultureIgnoreCase) == 0; + + bool unicode = isAsianLang; + byte font = (byte)(isAsianLang ? 3 : 9); + ushort hue = (ushort)(isAsianLang ? 0xFFFF : 0); + #endregion + + CharacterCreationValues.ComboContent content = CharacterCreationValues.GetHairComboContent(isFemale, selectedRace); + + CurrentOption[Layer.Beard] = 0; + CurrentOption[Layer.Hair] = 1; + + #region Hair style + Add + ( + new Label(ClilocLoader.Instance.GetString(selectedRace == RaceType.GARGOYLE ? 1112309 : 3000121), unicode, hue, font: font) + { + X = x + 1, + Y = y + } + ); + y += 15; + + Combobox hair; + Add + (hair = + new Combobox + ( + x, + y, + 120, + content.Labels, + CurrentOption[Layer.Hair] + ) + ); + hair.OnOptionSelected += (s, e) => + { + CurrentOption[Layer.Hair] = e; + UpdateEquipments(); + paperDollInteractable.RequestUpdate(this.hair, beard); + }; + y += 30; + #endregion + + #region Facial Hair + if (!isFemale && selectedRace != RaceType.ELF) + { + content = CharacterCreationValues.GetFacialHairComboContent(selectedRace); + + Add + ( + new Label(ClilocLoader.Instance.GetString(selectedRace == RaceType.GARGOYLE ? 1112511 : 3000122), unicode, hue, font: font) + { + X = x + 1, + Y = y + } + ); + y += 15; + + Combobox facialHair; + Add + (facialHair = + new Combobox + ( + x, + y, + 120, + content.Labels, + CurrentOption[Layer.Beard] + ) + ); + facialHair.OnOptionSelected += (s, e) => + { + CurrentOption[Layer.Beard] = e; + UpdateEquipments(); + paperDollInteractable.RequestUpdate(this.hair, beard); + }; + } + #endregion + } + + /// + /// Build color options for race change gump + /// + /// The starting point for these ui elements + /// The starting point for these ui elements + private void BuildColorOptions(int x, int y) + { + ushort[] pallet = CharacterCreationValues.GetSkinPallet(selectedRace); + + AddCustomColorPicker + ( + x, + y, + pallet, + Layer.Invalid, + 3000183, + 8, + pallet.Length >> 3 + ); + y += 42; + + // Hair + pallet = CharacterCreationValues.GetHairPallet(selectedRace); + + AddCustomColorPicker + ( + x, + y, + pallet, + Layer.Hair, + selectedRace == RaceType.GARGOYLE ? 1112322 : 3000184, + 8, + pallet.Length >> 3 + ); + y += 42; + + if (!isFemale && selectedRace != RaceType.ELF) + { + // Facial + pallet = CharacterCreationValues.GetHairPallet(selectedRace); + + AddCustomColorPicker + ( + x, + y, + pallet, + Layer.Beard, + selectedRace == RaceType.GARGOYLE ? 1112512 : 3000446, + 8, + pallet.Length >> 3 + ); + } + } + + /// + /// Must be called *after* color options have been set up. + /// + private void CreateCharacter() + { + #region Create a fake character to use for the gump + if (fakeMobile == null || fakeMobile.IsDestroyed) + { + fakeMobile = new PlayerMobile(1); + World.Mobiles.Add(fakeMobile); + } + + LinkedObject first = fakeMobile.Items; + + while (first != null) + { + LinkedObject next = first.Next; + + World.RemoveItem((Item)first, true); + + first = next; + } + + fakeMobile.Clear(); + fakeMobile.Race = selectedRace; + fakeMobile.IsFemale = isFemale; + + if (isFemale) + { + fakeMobile.Flags |= Flags.Female; + } + else + { + fakeMobile.Flags &= ~Flags.Female; + } + #endregion + + if (selectedRace == RaceType.ELF) + { + fakeMobile.Graphic = (ushort)(isFemale ? 0x025E : 0x025D); + } + else + { + fakeMobile.Graphic = (ushort)(isFemale ? 0x0191 : 0x0190); + } + } + + private void AddCustomColorPicker + ( + int x, + int y, + ushort[] pallet, + Layer layer, + int clilocLabel, + int rows, + int columns + ) + { + CustomColorPicker colorPicker; + + Add + ( + colorPicker = new CustomColorPicker + ( + layer, + clilocLabel, + pallet, + rows, + columns + ) + { + X = x, + Y = y + }, + 1 + ); + + if (!CurrentColorOption.ContainsKey(layer)) + { + CurrentColorOption[layer] = new Tuple(0, colorPicker.HueSelected); + } + else + { + colorPicker.SetSelectedIndex(CurrentColorOption[layer].Item1); + } + + colorPicker.ColorSelected += ColorPicker_ColorSelected; + } + + private void ColorPicker_ColorSelected(object sender, ColorSelectedEventArgs e) + { + if (e.SelectedIndex == 0xFFFF) + { + return; + } + + CurrentColorOption[e.Layer] = new Tuple(e.SelectedIndex, e.SelectedHue); + + if (e.Layer != Layer.Invalid) + { + Item item = fakeMobile.FindItemByLayer(e.Layer); + + if (item != null) + { + item.Hue = e.SelectedHue; + } + } + else + { + fakeMobile.Hue = e.SelectedHue; + } + + paperDollInteractable.RequestUpdate(hair, beard); + } + + private void ConfirmButton_MouseUp(object sender, Input.MouseEventArgs e) + { + if (e.Button == Input.MouseButtonType.Left) + { + NetClient.Socket.Send_ChangeRaceRequest( + CurrentColorOption[Layer.Invalid].Item2, + (ushort)CharacterCreationValues.GetHairComboContent(isFemale, selectedRace).GetGraphic(CurrentOption[Layer.Hair]), + CurrentColorOption[Layer.Hair].Item2, + (ushort)CharacterCreationValues.GetFacialHairComboContent(selectedRace).GetGraphic(CurrentOption[Layer.Beard]), + CurrentColorOption[Layer.Beard].Item2 + ); + Dispose(); + } + } + + private void UpdateEquipments() + { + Layer layer; + CharacterCreationValues.ComboContent content; + + fakeMobile.Hue = CurrentColorOption[Layer.Invalid].Item2; + + if (!isFemale && selectedRace != RaceType.ELF) + { + layer = Layer.Beard; + content = CharacterCreationValues.GetFacialHairComboContent(selectedRace); + + beard = CreateItem(content.GetGraphic(CurrentOption[layer]), CurrentColorOption[layer].Item2, layer); + } + + layer = Layer.Hair; + content = CharacterCreationValues.GetHairComboContent(isFemale, selectedRace); + + hair = CreateItem(content.GetGraphic(CurrentOption[layer]), CurrentColorOption[layer].Item2, layer); + } + + private Item CreateItem(int id, ushort hue, Layer layer) + { + Item existsItem = fakeMobile.FindItemByLayer(layer); + + if (existsItem != null) + { + World.RemoveItem(existsItem, true); + fakeMobile.Remove(existsItem); + } + + if (id == 0) + { + return null; + } + // This is a workaround to avoid to see naked guy + // We are simulating server objects into World.Items map. + Item item = World.GetOrCreateItem(0x4000_0000 + (uint)layer); // use layer as unique Serial + fakeMobile.Remove(item); + item.Graphic = (ushort)id; + item.Hue = hue; + item.Layer = layer; + item.Container = fakeMobile; + fakeMobile.PushToBack(item); + // + + return item; + } + + #region Classes + private class ColorSelectedEventArgs : EventArgs + { + public ColorSelectedEventArgs(Layer layer, ushort[] pallet, int selectedIndex) + { + Layer = layer; + Pallet = pallet; + SelectedIndex = selectedIndex; + } + + public Layer Layer { get; } + + private ushort[] Pallet { get; } + + public int SelectedIndex { get; } + + public ushort SelectedHue => Pallet != null && SelectedIndex >= 0 && SelectedIndex < Pallet.Length ? Pallet[SelectedIndex] : (ushort)0xFFFF; + } + + private class CustomColorPicker : Control + { + //private readonly ColorBox _box; + private readonly int _cellH; + private readonly int _cellW; + private readonly ColorBox _colorPicker; + private ColorPickerBox _colorPickerBox; + private readonly int _columns, _rows; + private int _lastSelectedIndex; + private readonly Layer _layer; + private readonly ushort[] _pallet; + + public CustomColorPicker(Layer layer, int label, ushort[] pallet, int rows, int columns) + { + Width = 121; + Height = 25; + _cellW = 125 / columns; + _cellH = 280 / rows; + _columns = columns; + _rows = rows; + _layer = layer; + _pallet = pallet; + + bool isAsianLang = string.Compare(Settings.GlobalSettings.Language, "CHT", StringComparison.InvariantCultureIgnoreCase) == 0 || + string.Compare(Settings.GlobalSettings.Language, "KOR", StringComparison.InvariantCultureIgnoreCase) == 0 || + string.Compare(Settings.GlobalSettings.Language, "JPN", StringComparison.InvariantCultureIgnoreCase) == 0; + + bool unicode = isAsianLang; + byte font = (byte)(isAsianLang ? 3 : 9); + ushort hue = (ushort)(isAsianLang ? 0xFFFF : 0); + + Add + ( + new Label(ClilocLoader.Instance.GetString(label), unicode, hue, font: font) + { + X = 0, + Y = 0 + } + ); + + Add + ( + _colorPicker = new ColorBox(121, 23, (ushort)((pallet?[0] ?? 1) + 1)) + { + X = 1, + Y = 15 + } + ); + + _colorPicker.MouseUp += ColorPicker_MouseClick; + } + + public ushort HueSelected => _colorPicker.Hue; + + public event EventHandler ColorSelected; + + public void SetSelectedIndex(int index) + { + if (_colorPickerBox != null) + { + _colorPickerBox.SelectedIndex = index; + + SetCurrentHue(); + } + } + + private void SetCurrentHue() + { + _colorPicker.Hue = _colorPickerBox.SelectedHue; + _lastSelectedIndex = _colorPickerBox.SelectedIndex; + + _colorPickerBox.Dispose(); + } + + private void ColorPickerBoxOnMouseUp(object sender, MouseEventArgs e) + { + int column = e.X / _cellW; + int row = e.Y / _cellH; + int selectedIndex = row * _columns + column; + + if (selectedIndex >= 0 && selectedIndex < _colorPickerBox.Hues.Length) + { + ColorSelected?.Invoke(this, new ColorSelectedEventArgs(_layer, _colorPickerBox.Hues, selectedIndex)); + SetCurrentHue(); + } + } + + private void ColorPicker_MouseClick(object sender, MouseEventArgs e) + { + if (e.Button == MouseButtonType.Left) + { + _colorPickerBox?.Dispose(); + _colorPickerBox = null; + + if (_colorPickerBox == null) + { + _colorPickerBox = new ColorPickerBox + ( + 485, + 109, + _rows, + _columns, + _cellW, + _cellH, + _pallet + ) + { + IsModal = true, + LayerOrder = UILayer.Over, + ModalClickOutsideAreaClosesThisControl = true, + ShowLivePreview = false, + SelectedIndex = _lastSelectedIndex + }; + + UIManager.Add(_colorPickerBox); + + _colorPickerBox.ColorSelectedIndex += ColorPickerBoxOnColorSelectedIndex; + _colorPickerBox.MouseUp += ColorPickerBoxOnMouseUp; + } + } + } + + private void ColorPickerBoxOnColorSelectedIndex(object sender, EventArgs e) + { + ColorSelected?.Invoke(this, new ColorSelectedEventArgs(_layer, _colorPickerBox.Hues, _colorPickerBox.SelectedIndex)); + } + } + + /// + /// Partially custom paperdoll gump required, when in-game the fake character created gets automatically removed and breaks the original paperdoll gump. + /// + private class CustomPaperDollGump : PaperDollInteractable + { + private readonly Mobile playerMobile; + private Item hair; + private Item beard; + private bool requestUpdate = false; + + public CustomPaperDollGump(int x, int y, Mobile playerMobile, Item hair, Item beard) : base(x, y, playerMobile, null) + { + this.playerMobile = playerMobile; + this.hair = hair; + this.beard = beard; + } + + private void UpdateUI() + { + if (IsDisposed) + { + return; + } + + Mobile mobile = playerMobile; + + if (mobile == null) + { + Dispose(); + + return; + } + + Clear(); + + #region Add the base gump - the semi-naked paper doll. + ushort body; + ushort hue = mobile.Hue; + + if (mobile.Graphic == 0x0191 || mobile.Graphic == 0x0193) + { + body = 0x000D; + } + else if (mobile.Graphic == 0x025D) + { + body = 0x000E; + } + else if (mobile.Graphic == 0x025E) + { + body = 0x000F; + } + else if (mobile.Graphic == 0x029A || mobile.Graphic == 0x02B6) + { + body = 0x029A; + } + else if (mobile.Graphic == 0x029B || mobile.Graphic == 0x02B7) + { + body = 0x0299; + } + else if (mobile.Graphic == 0x04E5) + { + body = 0xC835; + } + else if (mobile.Graphic == 0x03DB) + { + body = 0x000C; + hue = 0x03EA; + } + else if (mobile.IsFemale) + { + body = 0x000D; + } + else + { + body = 0x000C; + } + + // body + Add + ( + new GumpPic(0, 0, body, hue) + { + IsPartialHue = true + } + ); + + + if (mobile.Graphic == 0x03DB) + { + Add + ( + new GumpPic(0, 0, 0xC72B, mobile.Hue) + { + AcceptMouseInput = true, + IsPartialHue = true + } + ); + } + #endregion + + // equipment + + if (hair != null) + { + ushort id = GetAnimID(mobile.Graphic, hair.ItemData.AnimID, mobile.IsFemale); + + Add + ( + new GumpPicEquipment + ( + hair.Serial, + 0, + 0, + id, + (ushort)(hair.Hue & 0x3FFF), + Layer.Hair + ) + { + AcceptMouseInput = true, + IsPartialHue = hair.ItemData.IsPartialHue, + CanLift = false + } + ); + } + + if (beard != null) + { + ushort id = GetAnimID(mobile.Graphic, beard.ItemData.AnimID, mobile.IsFemale); + + Add + ( + new GumpPicEquipment + ( + beard.Serial, + 0, + 0, + id, + (ushort)(beard.Hue & 0x3FFF), + Layer.Beard + ) + { + AcceptMouseInput = true, + IsPartialHue = beard.ItemData.IsPartialHue, + CanLift = false + } + ); + } + } + + public void RequestUpdate(Item hair, Item beard) + { + this.hair = hair; + this.beard = beard; + requestUpdate = true; + } + + public new void RequestUpdate() + { + requestUpdate = true; + } + + public override void Update() + { + if (requestUpdate) + { + UpdateUI(); + requestUpdate = false; + } + } + } + #endregion + } +} \ No newline at end of file diff --git a/src/ClassicUO.Client/Game/UI/Gumps/WorldMapGump.cs b/src/ClassicUO.Client/Game/UI/Gumps/WorldMapGump.cs index 3bbad18e1..e975239ba 100644 --- a/src/ClassicUO.Client/Game/UI/Gumps/WorldMapGump.cs +++ b/src/ClassicUO.Client/Game/UI/Gumps/WorldMapGump.cs @@ -180,7 +180,7 @@ public bool TopMost { _isTopMost = value; - SaveSettings(); + SaveSettings(); } ShowBorder = !_isTopMost; @@ -225,7 +225,7 @@ private void LoadSettings() ResizeWindow(new Point(Width, Height)); - _flipMap = ProfileManager.CurrentProfile.WorldMapFlipMap; + _flipMap = ProfileManager.CurrentProfile.WorldMapFlipMap; _showPartyMembers = ProfileManager.CurrentProfile.WorldMapShowParty; World.WMapManager.SetEnable(_showPartyMembers); @@ -433,7 +433,7 @@ private void BuildOptionDictionary() _options["add_marker_on_player"] = new ContextMenuItemEntry(ResGumps.AddMarkerOnPlayer, () => AddMarkerOnPlayer()); _options["saveclose"] = new ContextMenuItemEntry(ResGumps.SaveClose, Dispose); - _options["show_grid_if_zoomed"] = new ContextMenuItemEntry(ResGumps.GridIfZoomed, () => { _showGridIfZoomed = !_showGridIfZoomed; SaveSettings(); }, true, _showGridIfZoomed); + _options["show_grid_if_zoomed"] = new ContextMenuItemEntry(ResGumps.GridIfZoomed, () => { _showGridIfZoomed = !_showGridIfZoomed; SaveSettings(); }, true, _showGridIfZoomed); } @@ -630,8 +630,8 @@ public override void Update() private Point RotatePoint(int x, int y, float zoom, int dist, float angle = 45f) { - x = (int) (x * zoom); - y = (int) (y * zoom); + x = (int)(x * zoom); + y = (int)(y * zoom); if (angle == 0.0f) { @@ -641,7 +641,7 @@ private Point RotatePoint(int x, int y, float zoom, int dist, float angle = 45f) double cos = Math.Cos(dist * Math.PI / 4.0); double sin = Math.Sin(dist * Math.PI / 4.0); - return new Point((int) Math.Round(cos * x - sin * y), (int) Math.Round(sin * x + cos * y)); + return new Point((int)Math.Round(cos * x - sin * y), (int)Math.Round(sin * x + cos * y)); } private void AdjustPosition @@ -866,7 +866,7 @@ private class CurLoader { public static unsafe Texture2D CreateTextureFromICO_Cur(Stream stream) { - byte[] buffer = System.Buffers.ArrayPool.Shared.Rent((int) stream.Length); + byte[] buffer = System.Buffers.ArrayPool.Shared.Rent((int)stream.Length); try { @@ -1152,8 +1152,8 @@ public static unsafe Texture2D CreateTextureFromICO_Cur(Stream stream) private static unsafe IntPtr INTERNAL_convertSurfaceFormat(IntPtr surface) { IntPtr result = surface; - SDL.SDL_Surface* surPtr = (SDL.SDL_Surface*) surface; - SDL.SDL_PixelFormat* pixelFormatPtr = (SDL.SDL_PixelFormat*) surPtr->format; + SDL.SDL_Surface* surPtr = (SDL.SDL_Surface*)surface; + SDL.SDL_PixelFormat* pixelFormatPtr = (SDL.SDL_PixelFormat*)surPtr->format; // SurfaceFormat.Color is SDL_PIXELFORMAT_ABGR8888 if (pixelFormatPtr->format != SDL.SDL_PIXELFORMAT_ABGR8888) @@ -1170,7 +1170,7 @@ private static unsafe IntPtr INTERNAL_convertSurfaceFormat(IntPtr surface) #region Loading - + private unsafe void LoadMapChunk(Span buffer, Span allZ, int chunkX, int chunkY) { if (World.Map == null) @@ -1315,7 +1315,7 @@ private void LoadMapDetails(Span buffer, Span allZ) } cc = (uint)(r | (g << 8) | (b << 16) | (a << 24)); - } + } } } @@ -1647,7 +1647,7 @@ internal class ZonesFile public List Zones { get; set; } } - private class Zone + private class Zone { public string Label; public Color Color; @@ -2166,9 +2166,9 @@ public override bool Draw(UltimaBatcher2D batcher, int x, int y) int centerX = _center.X + 1; int centerY = _center.Y + 1; - int size = (int) Math.Max(gWidth * 1.75f, gHeight * 1.75f); + int size = (int)Math.Max(gWidth * 1.75f, gHeight * 1.75f); - int size_zoom = (int) (size / Zoom); + int size_zoom = (int)(size / Zoom); int size_zoom_half = size_zoom >> 1; int halfWidth = gWidth >> 1; @@ -2440,7 +2440,7 @@ private void DrawAll(UltimaBatcher2D batcher, Rectangle srcRect, int gX, int gY, { Mobile mob = World.Mobiles.Get(partyMember.Serial); - if (mob != null && mob.Distance <= World.ClientViewRange) + if (mob != null) { WMapEntity wme = World.WMapManager.GetEntity(mob); @@ -2466,12 +2466,14 @@ private void DrawAll(UltimaBatcher2D batcher, Rectangle srcRect, int gX, int gY, true, _showGroupBar ); + + } else { WMapEntity wme = World.WMapManager.GetEntity(partyMember.Serial); - if (wme != null && !wme.IsGuild) + if (wme != null && wme.IsGuild || wme != null && mob.NotorietyFlag == NotorietyFlag.Ally) { DrawWMEntity ( @@ -2832,24 +2834,24 @@ out rot.Y if (rot.X + size.X / 2 > x + Width - 8) { - rot.X = x + Width - 8 - (int) (size.X / 2); + rot.X = x + Width - 8 - (int)(size.X / 2); } else if (rot.X - size.X / 2 < x) { - rot.X = x + (int) (size.X / 2); + rot.X = x + (int)(size.X / 2); } if (rot.Y + size.Y > y + Height) { - rot.Y = y + Height - (int) size.Y; + rot.Y = y + Height - (int)size.Y; } else if (rot.Y - size.Y < y) { - rot.Y = y + (int) size.Y; + rot.Y = y + (int)size.Y; } - int xx = (int) (rot.X - size.X / 2); - int yy = (int) (rot.Y - size.Y); + int xx = (int)(rot.X - size.X / 2); + int yy = (int)(rot.Y - size.Y); hueVector.X = 0; hueVector.Y = 1; @@ -2974,7 +2976,7 @@ float zoom else { batcher.Draw(marker.MarkerIcon, new Vector2(rot.X - (marker.MarkerIcon.Width >> 1), rot.Y - (marker.MarkerIcon.Height >> 1)), hueVector); - + if (!showMarkerName) { if (Mouse.Position.X >= rot.X - (marker.MarkerIcon.Width >> 1) && @@ -3046,8 +3048,8 @@ private void DrawMarkerString(UltimaBatcher2D batcher, WMapMarker marker, int x, ( xx - 2, yy - 2, - (int) (size.X + 4), - (int) (size.Y + 4) + (int)(size.X + 4), + (int)(size.Y + 4) ), hueVector ); @@ -3102,7 +3104,7 @@ float zoom _flipMap ? 45f : 0f ); - + rot.X += x + width; rot.Y += y + height; @@ -3321,24 +3323,24 @@ out rot.Y if (rot.X + size.X / 2 > x + Width - 8) { - rot.X = x + Width - 8 - (int) (size.X / 2); + rot.X = x + Width - 8 - (int)(size.X / 2); } else if (rot.X - size.X / 2 < x) { - rot.X = x + (int) (size.X / 2); + rot.X = x + (int)(size.X / 2); } if (rot.Y + size.Y > y + Height) { - rot.Y = y + Height - (int) size.Y; + rot.Y = y + Height - (int)size.Y; } else if (rot.Y - size.Y < y) { - rot.Y = y + (int) size.Y; + rot.Y = y + (int)size.Y; } - int xx = (int) (rot.X - size.X / 2); - int yy = (int) (rot.Y - size.Y); + int xx = (int)(rot.X - size.X / 2); + int yy = (int)(rot.Y - size.Y); hueVector.X = 0; hueVector.Y = 1; @@ -3451,7 +3453,7 @@ protected override void OnMouseUp(int x, int y, MouseButtonType button) { HandlePositionTarget(); } - + if (button == MouseButtonType.Left && !Keyboard.Alt) { _isScrolling = false; @@ -3723,11 +3725,11 @@ private static void ConvertCoords(string coords, ref int xAxis, ref int yAxis) if (yCoord.Substring(yCoord.Length - 1).Equals("N")) { - yAxis = (int) (1624 - (yMinute / 60) * (4096.0 / 360) - yDegree * (4096.0 / 360)); + yAxis = (int)(1624 - (yMinute / 60) * (4096.0 / 360) - yDegree * (4096.0 / 360)); } else { - yAxis = (int) (1624 + (yMinute / 60) * (4096.0 / 360) + yDegree * (4096.0 / 360)); + yAxis = (int)(1624 + (yMinute / 60) * (4096.0 / 360) + yDegree * (4096.0 / 360)); } // Calc X next @@ -3737,11 +3739,11 @@ private static void ConvertCoords(string coords, ref int xAxis, ref int yAxis) if (xCoord.Substring(xCoord.Length - 1).Equals("W")) { - xAxis = (int) (1323 - (xMinute / 60) * (5120.0 / 360) - xDegree * (5120.0 / 360)); + xAxis = (int)(1323 - (xMinute / 60) * (5120.0 / 360) - xDegree * (5120.0 / 360)); } else { - xAxis = (int) (1323 + (xMinute / 60) * (5120.0 / 360) + xDegree * (5120.0 / 360)); + xAxis = (int)(1323 + (xMinute / 60) * (5120.0 / 360) + xDegree * (5120.0 / 360)); } // Normalize values outside of map range. diff --git a/src/ClassicUO.Client/Network/PacketHandlers.cs b/src/ClassicUO.Client/Network/PacketHandlers.cs index da51ac3d5..436517ffa 100644 --- a/src/ClassicUO.Client/Network/PacketHandlers.cs +++ b/src/ClassicUO.Client/Network/PacketHandlers.cs @@ -4787,9 +4787,10 @@ private static void ExtendedCommand(ref StackDataReader p) bool isfemale = p.ReadBool(); byte race = p.ReadUInt8(); - // TODO: gump race request + - GameActions.Print("[DEBUG]: change-race gump is not implemented yet.", 34); + UIManager.GetGump()?.Dispose(); + UIManager.Add(new RaceChangeGump(isfemale, race)); break; From 1fd94dda3c5f0dc94ca8bef06f863b8ff7e28358 Mon Sep 17 00:00:00 2001 From: Jeann Sebold Date: Wed, 15 Nov 2023 15:30:13 -0300 Subject: [PATCH 2/8] fix map --- .../Dust765/Dust765/CombatCollection.cs | 14 +------------- src/ClassicUO.Client/Game/Constants.cs | 4 ++-- .../Game/Managers/WorldMapEntityManager.cs | 17 +++++++---------- .../Game/UI/Gumps/WorldMapGump.cs | 2 +- 4 files changed, 11 insertions(+), 26 deletions(-) diff --git a/src/ClassicUO.Client/Dust765/Dust765/CombatCollection.cs b/src/ClassicUO.Client/Dust765/Dust765/CombatCollection.cs index d7513a347..f0cd01168 100644 --- a/src/ClassicUO.Client/Dust765/Dust765/CombatCollection.cs +++ b/src/ClassicUO.Client/Dust765/Dust765/CombatCollection.cs @@ -375,20 +375,8 @@ public static void StartSpelltime() GameCursor._startSpellTime = Time.Ticks; } - public static bool CheckHighLineToTeleport(int destinationX, int destinationY) - { - GameObject selectedObject = World.Map.GetTile(destinationX, destinationY, false); - - ref StaticTiles staticTiles = ref TileDataLoader.Instance.StaticData[selectedObject.Graphic]; - - if (!staticTiles.IsImpassable) - { - return true; - } - return false; - } - //GAME\GAMEOBJECTS\VIEWS\ - MULTIVIEW.CS - STATICVIEW.CS - TILEVIEW.CS + //22 - Teleport //24 - Wall of Stone //28 - Fire Field //39 - Poison Field diff --git a/src/ClassicUO.Client/Game/Constants.cs b/src/ClassicUO.Client/Game/Constants.cs index fdc909d71..40afa67c1 100644 --- a/src/ClassicUO.Client/Game/Constants.cs +++ b/src/ClassicUO.Client/Game/Constants.cs @@ -106,8 +106,8 @@ internal static class Constants public const int MIN_GUMP_DRAG_DISTANCE = 0; public const int MIN_PICKUP_DRAG_DISTANCE_PIXELS = 5; - public const int MIN_VIEW_RANGE = 5; - public const int MAX_VIEW_RANGE = 24; + public const int MIN_VIEW_RANGE = 1; + public const int MAX_VIEW_RANGE = 48; public const int MAX_CONTAINER_OPENED_ON_GROUND_RANGE = 3; public const int OUT_RANGE_COLOR = 0x038B; diff --git a/src/ClassicUO.Client/Game/Managers/WorldMapEntityManager.cs b/src/ClassicUO.Client/Game/Managers/WorldMapEntityManager.cs index 1699751f4..22c9d55be 100644 --- a/src/ClassicUO.Client/Game/Managers/WorldMapEntityManager.cs +++ b/src/ClassicUO.Client/Game/Managers/WorldMapEntityManager.cs @@ -57,18 +57,16 @@ internal class WMapEntity public WMapEntity(uint serial) { - Serial = serial; - - GetName(); + GetName(serial); } - public string GetName() + public string GetName(uint serial) { - Mobile mob = World.Mobiles.Get(Serial); - Entity e = World.Get(Serial); + Mobile mob = World.Mobiles.Get(serial); + Entity e = World.Get(serial); if (mob != null) { @@ -82,16 +80,15 @@ public string GetName() wme.Name = mob.Name; Name = wme.Name; - nameCache[Serial] = Name; + nameCache[serial] = Name; } } } if (e != null) { Name = e.Name; - Serial = e.Serial; - nameCache[Serial] = Name; + nameCache[serial] = Name; } @@ -105,7 +102,7 @@ public string GetName() // Name = e.Name; //} - if (nameCache.TryGetValue(Serial, out string cachedName)) + if (nameCache.TryGetValue(serial, out string cachedName)) { return string.IsNullOrEmpty(Name) ? cachedName : Name; diff --git a/src/ClassicUO.Client/Game/UI/Gumps/WorldMapGump.cs b/src/ClassicUO.Client/Game/UI/Gumps/WorldMapGump.cs index e975239ba..fc57e71a9 100644 --- a/src/ClassicUO.Client/Game/UI/Gumps/WorldMapGump.cs +++ b/src/ClassicUO.Client/Game/UI/Gumps/WorldMapGump.cs @@ -2473,7 +2473,7 @@ private void DrawAll(UltimaBatcher2D batcher, Rectangle srcRect, int gX, int gY, { WMapEntity wme = World.WMapManager.GetEntity(partyMember.Serial); - if (wme != null && wme.IsGuild || wme != null && mob.NotorietyFlag == NotorietyFlag.Ally) + if (wme != null && wme.IsGuild) { DrawWMEntity ( From 25d4f594914e71d26d9ca3ef8fb7ab6dfd93ab4a Mon Sep 17 00:00:00 2001 From: Jeann Sebold Date: Thu, 16 Nov 2023 17:54:53 -0300 Subject: [PATCH 3/8] fix map --- src/ClassicUO.Client/Game/Constants.cs | 4 ++-- .../Game/Managers/WorldMapEntityManager.cs | 19 +++++++++++++------ .../Game/UI/Gumps/WorldMapGump.cs | 4 ++-- 3 files changed, 17 insertions(+), 10 deletions(-) diff --git a/src/ClassicUO.Client/Game/Constants.cs b/src/ClassicUO.Client/Game/Constants.cs index 40afa67c1..fdc909d71 100644 --- a/src/ClassicUO.Client/Game/Constants.cs +++ b/src/ClassicUO.Client/Game/Constants.cs @@ -106,8 +106,8 @@ internal static class Constants public const int MIN_GUMP_DRAG_DISTANCE = 0; public const int MIN_PICKUP_DRAG_DISTANCE_PIXELS = 5; - public const int MIN_VIEW_RANGE = 1; - public const int MAX_VIEW_RANGE = 48; + public const int MIN_VIEW_RANGE = 5; + public const int MAX_VIEW_RANGE = 24; public const int MAX_CONTAINER_OPENED_ON_GROUND_RANGE = 3; public const int OUT_RANGE_COLOR = 0x038B; diff --git a/src/ClassicUO.Client/Game/Managers/WorldMapEntityManager.cs b/src/ClassicUO.Client/Game/Managers/WorldMapEntityManager.cs index 22c9d55be..f90bbb96a 100644 --- a/src/ClassicUO.Client/Game/Managers/WorldMapEntityManager.cs +++ b/src/ClassicUO.Client/Game/Managers/WorldMapEntityManager.cs @@ -50,7 +50,7 @@ internal class WMapEntity public string Name; public uint Serial; public int X, Y, HP, Map; - private static readonly Dictionary nameCache = new Dictionary(); + public static readonly Dictionary nameCache = new Dictionary(); @@ -87,6 +87,7 @@ public string GetName(uint serial) if (e != null) { Name = e.Name; + serial = e.Serial; nameCache[serial] = Name; } @@ -104,12 +105,13 @@ public string GetName(uint serial) if (nameCache.TryGetValue(serial, out string cachedName)) { - + return string.IsNullOrEmpty(Name) ? cachedName : Name; + } else + { + return string.IsNullOrEmpty(Name) ? "Player Out" : Name; } - return "out of range"; - } } @@ -119,6 +121,7 @@ internal class WorldMapEntityManager private bool _ackReceived; private uint _lastUpdate, _lastPacketSend, _lastPacketRecv; private readonly List _toRemove = new List(); + public static readonly Dictionary nameCache = new Dictionary(); // ## BEGIN - END ## // TAZUO public WMapEntity _corpse; // ## BEGIN - END ## // TAZUO @@ -198,8 +201,10 @@ public void AddOrUpdate if (!Entities.TryGetValue(serial, out WMapEntity entity) || entity == null) { + var nameFilter = name != "" ? name : entity.GetName(serial); entity = new WMapEntity(serial) { + X = x, Y = y, HP = hp, @@ -207,7 +212,7 @@ public void AddOrUpdate LastUpdate = Time.Ticks + 1000, IsGuild = isguild, Name = name - }; + }; Entities[serial] = entity; } @@ -222,7 +227,9 @@ public void AddOrUpdate if (string.IsNullOrEmpty(entity.Name) && !string.IsNullOrEmpty(name)) { - entity.Name = name; + + entity.Name = entity.IsGuild ? name : entity.GetName(serial); + } } } diff --git a/src/ClassicUO.Client/Game/UI/Gumps/WorldMapGump.cs b/src/ClassicUO.Client/Game/UI/Gumps/WorldMapGump.cs index fc57e71a9..c7c1dfcf3 100644 --- a/src/ClassicUO.Client/Game/UI/Gumps/WorldMapGump.cs +++ b/src/ClassicUO.Client/Game/UI/Gumps/WorldMapGump.cs @@ -2473,7 +2473,7 @@ private void DrawAll(UltimaBatcher2D batcher, Rectangle srcRect, int gX, int gY, { WMapEntity wme = World.WMapManager.GetEntity(partyMember.Serial); - if (wme != null && wme.IsGuild) + if (wme != null && !wme.IsGuild) { DrawWMEntity ( @@ -3318,7 +3318,7 @@ out rot.Y if (_showGroupName) { - string name = entity.Name ?? ResGumps.OutOfRange; + string name = entity.Name ?? entity.GetName(entity.Serial); Vector2 size = Fonts.Regular.MeasureString(entity.Name ?? name); if (rot.X + size.X / 2 > x + Width - 8) From 1d68041031153dfac5d2f6d8b145c4e2acb7ee5f Mon Sep 17 00:00:00 2001 From: Jeann Sebold Date: Sun, 19 Nov 2023 09:08:21 -0300 Subject: [PATCH 4/8] change to use bin --- .../Game/Managers/MapNameMobilesManager.cs | 77 ++++ .../Game/Managers/WorldMapEntityManager.cs | 387 +++++++++--------- src/ClassicUO.Client/Game/Scenes/GameScene.cs | 2 +- src/ClassicUO.Client/Game/World.cs | 1 + 4 files changed, 268 insertions(+), 199 deletions(-) create mode 100644 src/ClassicUO.Client/Game/Managers/MapNameMobilesManager.cs diff --git a/src/ClassicUO.Client/Game/Managers/MapNameMobilesManager.cs b/src/ClassicUO.Client/Game/Managers/MapNameMobilesManager.cs new file mode 100644 index 000000000..509f7493b --- /dev/null +++ b/src/ClassicUO.Client/Game/Managers/MapNameMobilesManager.cs @@ -0,0 +1,77 @@ +using ClassicUO.Configuration; +using System; +using System.Collections.Generic; +using System.IO; +using System.Runtime.Serialization.Formatters.Binary; + +namespace ClassicUO.Game.Managers +{ + internal class MapNameMobilesManager + { + public static MapNameMobilesManager Instance { get; private set; } = new MapNameMobilesManager(); + + private Dictionary nameMobiles = new Dictionary(); + + private MapNameMobilesManager() { Load(); } + + private string savePath = Path.Combine(CUOEnviroment.ExecutablePath, "Data", "Profiles", "MapNameMobile.bin"); + + public void AddNameMobile(int serial, string name) + { + // Alterei o método AddTile para corrigir a adição ao dicionário. + nameMobiles[serial] = name; + Save(); // Adicionado para salvar imediatamente após a adição. + } + + public bool IsNameMobile(int serial) + { + // Alterei o método IsTileMarked para verificar se o serial existe no dicionário. + return nameMobiles.ContainsKey(serial); + } + + public string GetTileName(int serial) + { + // Alterei o método para retornar o nome associado ao serial, se existir. + if (nameMobiles.TryGetValue(serial, out string name)) + { + return name; + } + return null; + } + + public void Save() + { + try + { + using (FileStream fs = new FileStream(savePath, FileMode.Create, FileAccess.Write)) + { + BinaryFormatter bf = new BinaryFormatter(); + bf.Serialize(fs, nameMobiles); + } + } + catch (Exception ex) + { + Console.WriteLine($"Failed to save marked tile data. {ex.Message}"); + } + } + + private void Load() + { + if (File.Exists(savePath)) + { + try + { + using (FileStream fs = File.OpenRead(savePath)) + { + BinaryFormatter bf = new BinaryFormatter(); + nameMobiles = (Dictionary)bf.Deserialize(fs); + } + } + catch (Exception ex) + { + Console.WriteLine($"Failed to load marked tile data. {ex.Message}"); + } + } + } + } +} \ No newline at end of file diff --git a/src/ClassicUO.Client/Game/Managers/WorldMapEntityManager.cs b/src/ClassicUO.Client/Game/Managers/WorldMapEntityManager.cs index f90bbb96a..fa3ba8414 100644 --- a/src/ClassicUO.Client/Game/Managers/WorldMapEntityManager.cs +++ b/src/ClassicUO.Client/Game/Managers/WorldMapEntityManager.cs @@ -50,7 +50,6 @@ internal class WMapEntity public string Name; public uint Serial; public int X, Y, HP, Map; - public static readonly Dictionary nameCache = new Dictionary(); @@ -64,295 +63,287 @@ public WMapEntity(uint serial) public string GetName(uint serial) { - Mobile mob = World.Mobiles.Get(serial); Entity e = World.Get(serial); if (mob != null) { - WMapEntity wme = World.WMapManager.GetEntity(mob); + GameActions.Print("Is Mobile in mob " + mob.Serial + " Name: " + mob.Name); + WMapEntity wme = World.WMapManager.GetEntity(mob.Serial); + GameActions.Print("Is wme in mob " + wme.Serial + " Name: " + wme.Name); if (wme != null) { if (string.IsNullOrEmpty(wme.Name)) { - wme.Name = mob.Name; - Name = wme.Name; - nameCache[serial] = Name; + // Substituído o uso do nameCache pelo MapNameMobilesManager + MapNameMobilesManager.Instance.AddNameMobile((int)wme.Serial, wme.Name); } } } + if (e != null) { - Name = e.Name; - serial = e.Serial; + WMapEntity wme = World.WMapManager.GetEntity(e.Serial); + GameActions.Print("Is wme in entity " + wme.Serial + " Name: " + wme.Name); + GameActions.Print("Is Entity in entity " + e.Serial + " Name: " + e.Name); - nameCache[serial] = Name; + // Substituído o uso do nameCache pelo MapNameMobilesManager + MapNameMobilesManager.Instance.AddNameMobile((int)e.Serial, e.Name); } + // Removido o trecho de código que atribui a variável 'serial' e 'Name' diretamente, pois parece desnecessário. - - - // Entity e = World.Get(Serial); - // Mobile mob = World.Mobiles.Get(Serial); - - // if (e != null && !e.IsDestroyed && !string.IsNullOrEmpty(e.Name) && Name != e.Name) - //{ - // Name = e.Name; - //} - - if (nameCache.TryGetValue(serial, out string cachedName)) + if (MapNameMobilesManager.Instance.IsNameMobile((int)serial)) { - - return string.IsNullOrEmpty(Name) ? cachedName : Name; - } else + // Substituído o uso do nameCache pelo MapNameMobilesManager + return MapNameMobilesManager.Instance.GetTileName((int)serial); + } + else { return string.IsNullOrEmpty(Name) ? "Player Out" : Name; } - - } - } - internal class WorldMapEntityManager - { - private bool _ackReceived; - private uint _lastUpdate, _lastPacketSend, _lastPacketRecv; - private readonly List _toRemove = new List(); - public static readonly Dictionary nameCache = new Dictionary(); - // ## BEGIN - END ## // TAZUO - public WMapEntity _corpse; - // ## BEGIN - END ## // TAZUO - - public bool Enabled + internal class WorldMapEntityManager { - get + private bool _ackReceived; + private uint _lastUpdate, _lastPacketSend, _lastPacketRecv; + private readonly List _toRemove = new List(); + // ## BEGIN - END ## // TAZUO + public WMapEntity _corpse; + // ## BEGIN - END ## // TAZUO + + public bool Enabled { - return ((World.ClientFeatures.Flags & CharacterListFlags.CLF_NEW_MOVEMENT_SYSTEM) == 0 || _ackReceived) && - EncryptionHelper.Type == 0 && - ProfileManager.CurrentProfile != null && ProfileManager.CurrentProfile.WorldMapShowParty && - UIManager.GetGump() != null; // horrible, but works + get + { + return ((World.ClientFeatures.Flags & CharacterListFlags.CLF_NEW_MOVEMENT_SYSTEM) == 0 || _ackReceived) && + EncryptionHelper.Type == 0 && + ProfileManager.CurrentProfile != null && ProfileManager.CurrentProfile.WorldMapShowParty && + UIManager.GetGump() != null; // horrible, but works + } } - } - - public readonly Dictionary Entities = new Dictionary(); - public void SetACKReceived() - { - _ackReceived = true; - } + public readonly Dictionary Entities = new Dictionary(); - public void SetEnable(bool v) - { - if ((World.ClientFeatures.Flags & CharacterListFlags.CLF_NEW_MOVEMENT_SYSTEM) != 0 && !_ackReceived) - { - Log.Warn("Server support new movement system. Can't use the 0xF0 packet to query guild/party position"); - v = false; - } - else if (EncryptionHelper.Type != 0 && !_ackReceived) + public void SetACKReceived() { - Log.Warn("Server has encryption. Can't use the 0xF0 packet to query guild/party position"); - v = false; + _ackReceived = true; } - if (v) + public void SetEnable(bool v) { - RequestServerPartyGuildInfo(true); - } - } + if ((World.ClientFeatures.Flags & CharacterListFlags.CLF_NEW_MOVEMENT_SYSTEM) != 0 && !_ackReceived) + { + Log.Warn("Server support new movement system. Can't use the 0xF0 packet to query guild/party position"); + v = false; + } + else if (EncryptionHelper.Type != 0 && !_ackReceived) + { + Log.Warn("Server has encryption. Can't use the 0xF0 packet to query guild/party position"); + v = false; + } - public void AddOrUpdate - ( - uint serial, - int x, - int y, - int hp, - int map, - bool isguild, - string name = null, - bool from_packet = false - ) - { - if (from_packet) - { - _lastPacketRecv = Time.Ticks + 10000; - } - else if (_lastPacketRecv < Time.Ticks) - { - return; + if (v) + { + RequestServerPartyGuildInfo(true); + } } - if (!Enabled) + public void AddOrUpdate + ( + uint serial, + int x, + int y, + int hp, + int map, + bool isguild, + string name = null, + bool from_packet = false + ) { - return; - } + if (from_packet) + { + _lastPacketRecv = Time.Ticks + 10000; + } + else if (_lastPacketRecv < Time.Ticks) + { + return; + } - if (string.IsNullOrEmpty(name)) - { - Entity ent = World.Get(serial); + if (!Enabled) + { + return; + } - if (ent != null && !string.IsNullOrEmpty(ent.Name)) + if (string.IsNullOrEmpty(name)) { - name = ent.Name; + Entity ent = World.Get(serial); + + if (ent != null && !string.IsNullOrEmpty(ent.Name)) + { + name = ent.Name; + } } - } - if (!Entities.TryGetValue(serial, out WMapEntity entity) || entity == null) - { - var nameFilter = name != "" ? name : entity.GetName(serial); - entity = new WMapEntity(serial) + if (!Entities.TryGetValue(serial, out WMapEntity entity) || entity == null) { - - X = x, - Y = y, - HP = hp, - Map = map, - LastUpdate = Time.Ticks + 1000, - IsGuild = isguild, - Name = name - }; - - Entities[serial] = entity; - } - else - { - entity.X = x; - entity.Y = y; - entity.HP = hp; - entity.Map = map; - entity.IsGuild = isguild; - entity.LastUpdate = Time.Ticks + 1000; - - if (string.IsNullOrEmpty(entity.Name) && !string.IsNullOrEmpty(name)) + var nameFilter = name != "" ? name : entity.GetName(serial); + entity = new WMapEntity(serial) + { + + X = x, + Y = y, + HP = hp, + Map = map, + LastUpdate = Time.Ticks + 1000, + IsGuild = isguild, + Name = nameFilter + }; + + Entities[serial] = entity; + } + else { - - entity.Name = entity.IsGuild ? name : entity.GetName(serial); + entity.X = x; + entity.Y = y; + entity.HP = hp; + entity.Map = map; + entity.IsGuild = isguild; + entity.LastUpdate = Time.Ticks + 1000; + + if (string.IsNullOrEmpty(entity.Name) && !string.IsNullOrEmpty(name)) + { + + entity.Name = entity.IsGuild ? name : entity.GetName(serial); + } } } - } - public void Remove(uint serial) - { - if (Entities.ContainsKey(serial)) + public void Remove(uint serial) { - Entities.Remove(serial); + if (Entities.ContainsKey(serial)) + { + Entities.Remove(serial); + } } - } - public void RemoveUnupdatedWEntity() - { - // ## BEGIN - END ## // TAZUO - if (_corpse != null && _corpse.LastUpdate < Time.Ticks - 1000) - { - _corpse = null; - } - // ## BEGIN - END ## // TAZUO - if (_lastUpdate > Time.Ticks) + public void RemoveUnupdatedWEntity() { - return; - } + // ## BEGIN - END ## // TAZUO + if (_corpse != null && _corpse.LastUpdate < Time.Ticks - 1000) + { + _corpse = null; + } + // ## BEGIN - END ## // TAZUO + if (_lastUpdate > Time.Ticks) + { + return; + } - _lastUpdate = Time.Ticks + 1000; + _lastUpdate = Time.Ticks + 1000; - long ticks = Time.Ticks - 1000; + long ticks = Time.Ticks - 1000; - foreach (WMapEntity entity in Entities.Values) - { - if (entity.LastUpdate < ticks) + foreach (WMapEntity entity in Entities.Values) { - _toRemove.Add(entity); + if (entity.LastUpdate < ticks) + { + _toRemove.Add(entity); + } } - } - if (_toRemove.Count != 0) - { - foreach (WMapEntity entity in _toRemove) + if (_toRemove.Count != 0) { - Entities.Remove(entity.Serial); - } + foreach (WMapEntity entity in _toRemove) + { + Entities.Remove(entity.Serial); + } - _toRemove.Clear(); + _toRemove.Clear(); + } } - } - - public WMapEntity GetEntity(uint serial) - { - Entities.TryGetValue(serial, out WMapEntity entity); - return entity; - } - - public void RequestServerPartyGuildInfo(bool force = false) - { - if (!force && !Enabled) + public WMapEntity GetEntity(uint serial) { - return; + Entities.TryGetValue(serial, out WMapEntity entity); + + return entity; } - if (World.InGame && _lastPacketSend < Time.Ticks) + public void RequestServerPartyGuildInfo(bool force = false) { - //GameActions.Print($"SENDING PACKET! {Time.Ticks}"); + if (!force && !Enabled) + { + return; + } - _lastPacketSend = Time.Ticks + 250; + if (World.InGame && _lastPacketSend < Time.Ticks) + { + //GameActions.Print($"SENDING PACKET! {Time.Ticks}"); - //if (!force && !_can_send) - //{ - // return; - //} + _lastPacketSend = Time.Ticks + 250; - NetClient.Socket.Send_QueryGuildPosition(); + //if (!force && !_can_send) + //{ + // return; + //} - if (World.Party != null && World.Party.Leader != 0) - { - foreach (PartyMember e in World.Party.Members) + NetClient.Socket.Send_QueryGuildPosition(); + + if (World.Party != null && World.Party.Leader != 0) { - if (e != null && SerialHelper.IsValid(e.Serial)) + foreach (PartyMember e in World.Party.Members) { - Mobile mob = World.Mobiles.Get(e.Serial); - - if (mob == null || mob.Distance > World.ClientViewRange) + if (e != null && SerialHelper.IsValid(e.Serial)) { - NetClient.Socket.Send_QueryPartyPosition(); + Mobile mob = World.Mobiles.Get(e.Serial); - break; + if (mob == null || mob.Distance > World.ClientViewRange) + { + NetClient.Socket.Send_QueryPartyPosition(); + + break; + } } } } - } - else - { - foreach (Mobile mob in World.Mobiles.Values) + else { - if (mob == World.Player) + foreach (Mobile mob in World.Mobiles.Values) { - continue; - } + if (mob == World.Player) + { + continue; + } - Mobile mobs = World.Mobiles.Get(mob.Serial); - if (mobs.NotorietyFlag == NotorietyFlag.Ally) - { - if (mobs == null || mobs.Distance > 2000000) + Mobile mobs = World.Mobiles.Get(mob.Serial); + if (mobs.NotorietyFlag == NotorietyFlag.Ally) { - NetClient.Socket.Send_QueryGuildPosition(); + if (mobs == null || mobs.Distance > 2000000) + { + NetClient.Socket.Send_QueryGuildPosition(); - break; + break; + } } + } } - } } - } - public void Clear() - { - Entities.Clear(); - _ackReceived = false; - SetEnable(false); + public void Clear() + { + Entities.Clear(); + _ackReceived = false; + SetEnable(false); + } } } } \ No newline at end of file diff --git a/src/ClassicUO.Client/Game/Scenes/GameScene.cs b/src/ClassicUO.Client/Game/Scenes/GameScene.cs index 81a21ab58..58161e603 100644 --- a/src/ClassicUO.Client/Game/Scenes/GameScene.cs +++ b/src/ClassicUO.Client/Game/Scenes/GameScene.cs @@ -450,7 +450,7 @@ public override void Unload() // special case for wmap. this allow us to save settings UIManager.GetGump()?.SaveSettings(); - + MapNameMobilesManager.Instance.Save(); ProfileManager.CurrentProfile?.Save(ProfileManager.ProfilePath); Macros.Save(); diff --git a/src/ClassicUO.Client/Game/World.cs b/src/ClassicUO.Client/Game/World.cs index c0d88696d..010c4efad 100644 --- a/src/ClassicUO.Client/Game/World.cs +++ b/src/ClassicUO.Client/Game/World.cs @@ -48,6 +48,7 @@ using ClassicUO.Game.Scenes; using ClassicUO.Utility.Logging; using ClassicUO.Assets; +using static ClassicUO.Game.Managers.WMapEntity; namespace ClassicUO.Game { From 3f7325b8592274f17c5731103b7ea66f77b768ab Mon Sep 17 00:00:00 2001 From: Jeann Sebold Date: Sun, 19 Nov 2023 09:37:47 -0300 Subject: [PATCH 5/8] add remote --- src/ClassicUO.Client/Game/UI/Gumps/WorldMapGump.cs | 2 +- src/ClassicUO.Client/Network/PacketHandlers.cs | 12 +++++++++++- 2 files changed, 12 insertions(+), 2 deletions(-) diff --git a/src/ClassicUO.Client/Game/UI/Gumps/WorldMapGump.cs b/src/ClassicUO.Client/Game/UI/Gumps/WorldMapGump.cs index c7c1dfcf3..d64d9e08b 100644 --- a/src/ClassicUO.Client/Game/UI/Gumps/WorldMapGump.cs +++ b/src/ClassicUO.Client/Game/UI/Gumps/WorldMapGump.cs @@ -2448,7 +2448,7 @@ private void DrawAll(UltimaBatcher2D batcher, Rectangle srcRect, int gX, int gY, { if (string.IsNullOrEmpty(wme.Name) && !string.IsNullOrEmpty(partyMember.Name)) { - wme.Name = partyMember.Name; + wme.Name = wme.GetName(partyMember.Serial); } } diff --git a/src/ClassicUO.Client/Network/PacketHandlers.cs b/src/ClassicUO.Client/Network/PacketHandlers.cs index 436517ffa..5d655bfdc 100644 --- a/src/ClassicUO.Client/Network/PacketHandlers.cs +++ b/src/ClassicUO.Client/Network/PacketHandlers.cs @@ -3401,7 +3401,17 @@ private static void UpdateName(ref StackDataReader p) if (wme != null && !string.IsNullOrEmpty(name)) { - wme.Name = name; + + if(wme.IsGuild) + { + wme.Name = wme.GetName(wme.Serial); + + } + else + { + wme.Name = name; + + } } From 80f1a48e2c26a5d24f843c0baa5aa09fa4cd3fe1 Mon Sep 17 00:00:00 2001 From: Jeann Sebold Date: Sun, 19 Nov 2023 13:11:47 -0300 Subject: [PATCH 6/8] fix to party --- .../Game/Managers/MapNameMobilesManager.cs | 9 +++------ .../Game/Managers/WorldMapEntityManager.cs | 4 ++-- src/ClassicUO.Client/Network/PacketHandlers.cs | 11 +---------- 3 files changed, 6 insertions(+), 18 deletions(-) diff --git a/src/ClassicUO.Client/Game/Managers/MapNameMobilesManager.cs b/src/ClassicUO.Client/Game/Managers/MapNameMobilesManager.cs index 509f7493b..6b1bbcee1 100644 --- a/src/ClassicUO.Client/Game/Managers/MapNameMobilesManager.cs +++ b/src/ClassicUO.Client/Game/Managers/MapNameMobilesManager.cs @@ -18,20 +18,17 @@ internal class MapNameMobilesManager public void AddNameMobile(int serial, string name) { - // Alterei o método AddTile para corrigir a adição ao dicionário. nameMobiles[serial] = name; - Save(); // Adicionado para salvar imediatamente após a adição. + Save(); } public bool IsNameMobile(int serial) { - // Alterei o método IsTileMarked para verificar se o serial existe no dicionário. return nameMobiles.ContainsKey(serial); } public string GetTileName(int serial) { - // Alterei o método para retornar o nome associado ao serial, se existir. if (nameMobiles.TryGetValue(serial, out string name)) { return name; @@ -51,7 +48,7 @@ public void Save() } catch (Exception ex) { - Console.WriteLine($"Failed to save marked tile data. {ex.Message}"); + Console.WriteLine($"Failed to save NameMobiles data. {ex.Message}"); } } @@ -69,7 +66,7 @@ private void Load() } catch (Exception ex) { - Console.WriteLine($"Failed to load marked tile data. {ex.Message}"); + Console.WriteLine($"Failed to load NameMobiles data. {ex.Message}"); } } } diff --git a/src/ClassicUO.Client/Game/Managers/WorldMapEntityManager.cs b/src/ClassicUO.Client/Game/Managers/WorldMapEntityManager.cs index fa3ba8414..1c6606cd8 100644 --- a/src/ClassicUO.Client/Game/Managers/WorldMapEntityManager.cs +++ b/src/ClassicUO.Client/Game/Managers/WorldMapEntityManager.cs @@ -65,12 +65,13 @@ public string GetName(uint serial) { Mobile mob = World.Mobiles.Get(serial); Entity e = World.Get(serial); + WMapEntity wmee = World.WMapManager.GetEntity(serial); if (mob != null) { GameActions.Print("Is Mobile in mob " + mob.Serial + " Name: " + mob.Name); WMapEntity wme = World.WMapManager.GetEntity(mob.Serial); - GameActions.Print("Is wme in mob " + wme.Serial + " Name: " + wme.Name); + if (wme != null) { @@ -87,7 +88,6 @@ public string GetName(uint serial) if (e != null) { WMapEntity wme = World.WMapManager.GetEntity(e.Serial); - GameActions.Print("Is wme in entity " + wme.Serial + " Name: " + wme.Name); GameActions.Print("Is Entity in entity " + e.Serial + " Name: " + e.Name); // Substituído o uso do nameCache pelo MapNameMobilesManager diff --git a/src/ClassicUO.Client/Network/PacketHandlers.cs b/src/ClassicUO.Client/Network/PacketHandlers.cs index 5d655bfdc..ff799beb9 100644 --- a/src/ClassicUO.Client/Network/PacketHandlers.cs +++ b/src/ClassicUO.Client/Network/PacketHandlers.cs @@ -3401,17 +3401,8 @@ private static void UpdateName(ref StackDataReader p) if (wme != null && !string.IsNullOrEmpty(name)) { - - if(wme.IsGuild) - { - wme.Name = wme.GetName(wme.Serial); - - } - else - { - wme.Name = name; - } + wme.Name = name; } From bd556062fd216beea5b25aaba9c29336f7034414 Mon Sep 17 00:00:00 2001 From: Jeann Sebold Date: Mon, 20 Nov 2023 09:01:13 -0300 Subject: [PATCH 7/8] remove bin, return use cache --- .../Game/Managers/MapNameMobilesManager.cs | 74 ---- .../Game/Managers/WorldMapEntityManager.cs | 387 +++++++++--------- src/ClassicUO.Client/Game/Scenes/GameScene.cs | 1 - .../Game/UI/Gumps/WorldMapGump.cs | 2 +- 4 files changed, 195 insertions(+), 269 deletions(-) delete mode 100644 src/ClassicUO.Client/Game/Managers/MapNameMobilesManager.cs diff --git a/src/ClassicUO.Client/Game/Managers/MapNameMobilesManager.cs b/src/ClassicUO.Client/Game/Managers/MapNameMobilesManager.cs deleted file mode 100644 index 6b1bbcee1..000000000 --- a/src/ClassicUO.Client/Game/Managers/MapNameMobilesManager.cs +++ /dev/null @@ -1,74 +0,0 @@ -using ClassicUO.Configuration; -using System; -using System.Collections.Generic; -using System.IO; -using System.Runtime.Serialization.Formatters.Binary; - -namespace ClassicUO.Game.Managers -{ - internal class MapNameMobilesManager - { - public static MapNameMobilesManager Instance { get; private set; } = new MapNameMobilesManager(); - - private Dictionary nameMobiles = new Dictionary(); - - private MapNameMobilesManager() { Load(); } - - private string savePath = Path.Combine(CUOEnviroment.ExecutablePath, "Data", "Profiles", "MapNameMobile.bin"); - - public void AddNameMobile(int serial, string name) - { - nameMobiles[serial] = name; - Save(); - } - - public bool IsNameMobile(int serial) - { - return nameMobiles.ContainsKey(serial); - } - - public string GetTileName(int serial) - { - if (nameMobiles.TryGetValue(serial, out string name)) - { - return name; - } - return null; - } - - public void Save() - { - try - { - using (FileStream fs = new FileStream(savePath, FileMode.Create, FileAccess.Write)) - { - BinaryFormatter bf = new BinaryFormatter(); - bf.Serialize(fs, nameMobiles); - } - } - catch (Exception ex) - { - Console.WriteLine($"Failed to save NameMobiles data. {ex.Message}"); - } - } - - private void Load() - { - if (File.Exists(savePath)) - { - try - { - using (FileStream fs = File.OpenRead(savePath)) - { - BinaryFormatter bf = new BinaryFormatter(); - nameMobiles = (Dictionary)bf.Deserialize(fs); - } - } - catch (Exception ex) - { - Console.WriteLine($"Failed to load NameMobiles data. {ex.Message}"); - } - } - } - } -} \ No newline at end of file diff --git a/src/ClassicUO.Client/Game/Managers/WorldMapEntityManager.cs b/src/ClassicUO.Client/Game/Managers/WorldMapEntityManager.cs index 1c6606cd8..96dc709fd 100644 --- a/src/ClassicUO.Client/Game/Managers/WorldMapEntityManager.cs +++ b/src/ClassicUO.Client/Game/Managers/WorldMapEntityManager.cs @@ -50,300 +50,301 @@ internal class WMapEntity public string Name; public uint Serial; public int X, Y, HP, Map; - - + public static readonly Dictionary nameCache = new Dictionary(); public WMapEntity(uint serial) { - GetName(serial); } - - + // ## BEGIN - START ## // DUST765 - Fix to use cache for name in Map Gump public string GetName(uint serial) { + Mobile mob = World.Mobiles.Get(serial); Entity e = World.Get(serial); - WMapEntity wmee = World.WMapManager.GetEntity(serial); + if (mob != null) { - GameActions.Print("Is Mobile in mob " + mob.Serial + " Name: " + mob.Name); - WMapEntity wme = World.WMapManager.GetEntity(mob.Serial); - + WMapEntity wme = World.WMapManager.GetEntity(mob); if (wme != null) { if (string.IsNullOrEmpty(wme.Name)) { wme.Name = mob.Name; - - // Substituído o uso do nameCache pelo MapNameMobilesManager - MapNameMobilesManager.Instance.AddNameMobile((int)wme.Serial, wme.Name); + Name = wme.Name; + nameCache[serial] = Name; } } } - - if (e != null) + if (e != null && !e.IsDestroyed) { - WMapEntity wme = World.WMapManager.GetEntity(e.Serial); - GameActions.Print("Is Entity in entity " + e.Serial + " Name: " + e.Name); - - // Substituído o uso do nameCache pelo MapNameMobilesManager - MapNameMobilesManager.Instance.AddNameMobile((int)e.Serial, e.Name); + Name = e.Name; + serial = e.Serial; + nameCache[serial] = Name; } - // Removido o trecho de código que atribui a variável 'serial' e 'Name' diretamente, pois parece desnecessário. + // Entity e = World.Get(Serial); + // Mobile mob = World.Mobiles.Get(Serial); + + // if (e != null && !e.IsDestroyed && !string.IsNullOrEmpty(e.Name) && Name != e.Name) + //{ + // Name = e.Name; + //} - if (MapNameMobilesManager.Instance.IsNameMobile((int)serial)) + if (nameCache.TryGetValue(serial, out string cachedName)) { - // Substituído o uso do nameCache pelo MapNameMobilesManager - return MapNameMobilesManager.Instance.GetTileName((int)serial); + + return string.IsNullOrEmpty(Name) ? cachedName : Name; } else { - return string.IsNullOrEmpty(Name) ? "Player Out" : Name; + return string.IsNullOrEmpty(Name) ? "Out of range" : Name; } + + // ## BEGIN - END ## // DUST765 - Fix to use cache for name in Map Gump } + } - internal class WorldMapEntityManager + internal class WorldMapEntityManager + { + private bool _ackReceived; + private uint _lastUpdate, _lastPacketSend, _lastPacketRecv; + private readonly List _toRemove = new List(); + public static readonly Dictionary nameCache = new Dictionary(); + // ## BEGIN - START ## // TAZUO + public WMapEntity _corpse; + // ## BEGIN - END ## // TAZUO + + public bool Enabled { - private bool _ackReceived; - private uint _lastUpdate, _lastPacketSend, _lastPacketRecv; - private readonly List _toRemove = new List(); - // ## BEGIN - END ## // TAZUO - public WMapEntity _corpse; - // ## BEGIN - END ## // TAZUO - - public bool Enabled + get { - get - { - return ((World.ClientFeatures.Flags & CharacterListFlags.CLF_NEW_MOVEMENT_SYSTEM) == 0 || _ackReceived) && - EncryptionHelper.Type == 0 && - ProfileManager.CurrentProfile != null && ProfileManager.CurrentProfile.WorldMapShowParty && - UIManager.GetGump() != null; // horrible, but works - } + return ((World.ClientFeatures.Flags & CharacterListFlags.CLF_NEW_MOVEMENT_SYSTEM) == 0 || _ackReceived) && + EncryptionHelper.Type == 0 && + ProfileManager.CurrentProfile != null && ProfileManager.CurrentProfile.WorldMapShowParty && + UIManager.GetGump() != null; // horrible, but works } + } - public readonly Dictionary Entities = new Dictionary(); + public readonly Dictionary Entities = new Dictionary(); - public void SetACKReceived() + public void SetACKReceived() + { + _ackReceived = true; + } + + public void SetEnable(bool v) + { + if ((World.ClientFeatures.Flags & CharacterListFlags.CLF_NEW_MOVEMENT_SYSTEM) != 0 && !_ackReceived) { - _ackReceived = true; + Log.Warn("Server support new movement system. Can't use the 0xF0 packet to query guild/party position"); + v = false; + } + else if (EncryptionHelper.Type != 0 && !_ackReceived) + { + Log.Warn("Server has encryption. Can't use the 0xF0 packet to query guild/party position"); + v = false; } - public void SetEnable(bool v) + if (v) { - if ((World.ClientFeatures.Flags & CharacterListFlags.CLF_NEW_MOVEMENT_SYSTEM) != 0 && !_ackReceived) - { - Log.Warn("Server support new movement system. Can't use the 0xF0 packet to query guild/party position"); - v = false; - } - else if (EncryptionHelper.Type != 0 && !_ackReceived) - { - Log.Warn("Server has encryption. Can't use the 0xF0 packet to query guild/party position"); - v = false; - } + RequestServerPartyGuildInfo(true); + } + } - if (v) - { - RequestServerPartyGuildInfo(true); - } + public void AddOrUpdate + ( + uint serial, + int x, + int y, + int hp, + int map, + bool isguild, + string name = null, + bool from_packet = false + ) + { + if (from_packet) + { + _lastPacketRecv = Time.Ticks + 10000; + } + else if (_lastPacketRecv < Time.Ticks) + { + return; } - public void AddOrUpdate - ( - uint serial, - int x, - int y, - int hp, - int map, - bool isguild, - string name = null, - bool from_packet = false - ) + if (!Enabled) { - if (from_packet) - { - _lastPacketRecv = Time.Ticks + 10000; - } - else if (_lastPacketRecv < Time.Ticks) - { - return; - } + return; + } - if (!Enabled) - { - return; - } + if (string.IsNullOrEmpty(name)) + { + Entity ent = World.Get(serial); - if (string.IsNullOrEmpty(name)) + if (ent != null && !string.IsNullOrEmpty(ent.Name)) { - Entity ent = World.Get(serial); - - if (ent != null && !string.IsNullOrEmpty(ent.Name)) - { - name = ent.Name; - } + name = ent.Name; } + } - if (!Entities.TryGetValue(serial, out WMapEntity entity) || entity == null) + if (!Entities.TryGetValue(serial, out WMapEntity entity) || entity == null) + { + var nameFilter = name != "" ? name : entity.GetName(serial); + entity = new WMapEntity(serial) { - var nameFilter = name != "" ? name : entity.GetName(serial); - entity = new WMapEntity(serial) - { - X = x, - Y = y, - HP = hp, - Map = map, - LastUpdate = Time.Ticks + 1000, - IsGuild = isguild, - Name = nameFilter - }; + X = x, + Y = y, + HP = hp, + Map = map, + LastUpdate = Time.Ticks + 1000, + IsGuild = isguild, + Name = nameFilter + }; - Entities[serial] = entity; - } - else + Entities[serial] = entity; + } + else + { + entity.X = x; + entity.Y = y; + entity.HP = hp; + entity.Map = map; + entity.IsGuild = isguild; + entity.LastUpdate = Time.Ticks + 1000; + + if (string.IsNullOrEmpty(entity.Name) && !string.IsNullOrEmpty(name)) { - entity.X = x; - entity.Y = y; - entity.HP = hp; - entity.Map = map; - entity.IsGuild = isguild; - entity.LastUpdate = Time.Ticks + 1000; - - if (string.IsNullOrEmpty(entity.Name) && !string.IsNullOrEmpty(name)) - { - entity.Name = entity.IsGuild ? name : entity.GetName(serial); + entity.Name = entity.IsGuild ? name : entity.GetName(serial); - } } } + } - public void Remove(uint serial) + public void Remove(uint serial) + { + if (Entities.ContainsKey(serial)) { - if (Entities.ContainsKey(serial)) - { - Entities.Remove(serial); - } + Entities.Remove(serial); } + } - public void RemoveUnupdatedWEntity() + public void RemoveUnupdatedWEntity() + { + // ## BEGIN - END ## // TAZUO + if (_corpse != null && _corpse.LastUpdate < Time.Ticks - 1000) { - // ## BEGIN - END ## // TAZUO - if (_corpse != null && _corpse.LastUpdate < Time.Ticks - 1000) - { - _corpse = null; - } - // ## BEGIN - END ## // TAZUO - if (_lastUpdate > Time.Ticks) - { - return; - } + _corpse = null; + } + // ## BEGIN - END ## // TAZUO + if (_lastUpdate > Time.Ticks) + { + return; + } - _lastUpdate = Time.Ticks + 1000; + _lastUpdate = Time.Ticks + 1000; - long ticks = Time.Ticks - 1000; + long ticks = Time.Ticks - 1000; - foreach (WMapEntity entity in Entities.Values) + foreach (WMapEntity entity in Entities.Values) + { + if (entity.LastUpdate < ticks) { - if (entity.LastUpdate < ticks) - { - _toRemove.Add(entity); - } + _toRemove.Add(entity); } + } - if (_toRemove.Count != 0) + if (_toRemove.Count != 0) + { + foreach (WMapEntity entity in _toRemove) { - foreach (WMapEntity entity in _toRemove) - { - Entities.Remove(entity.Serial); - } - - _toRemove.Clear(); + Entities.Remove(entity.Serial); } + + _toRemove.Clear(); } + } - public WMapEntity GetEntity(uint serial) - { - Entities.TryGetValue(serial, out WMapEntity entity); + public WMapEntity GetEntity(uint serial) + { + Entities.TryGetValue(serial, out WMapEntity entity); - return entity; - } + return entity; + } - public void RequestServerPartyGuildInfo(bool force = false) + public void RequestServerPartyGuildInfo(bool force = false) + { + if (!force && !Enabled) { - if (!force && !Enabled) - { - return; - } + return; + } - if (World.InGame && _lastPacketSend < Time.Ticks) - { - //GameActions.Print($"SENDING PACKET! {Time.Ticks}"); + if (World.InGame && _lastPacketSend < Time.Ticks) + { + //GameActions.Print($"SENDING PACKET! {Time.Ticks}"); - _lastPacketSend = Time.Ticks + 250; + _lastPacketSend = Time.Ticks + 250; - //if (!force && !_can_send) - //{ - // return; - //} + //if (!force && !_can_send) + //{ + // return; + //} - NetClient.Socket.Send_QueryGuildPosition(); + NetClient.Socket.Send_QueryGuildPosition(); - if (World.Party != null && World.Party.Leader != 0) + if (World.Party != null && World.Party.Leader != 0) + { + foreach (PartyMember e in World.Party.Members) { - foreach (PartyMember e in World.Party.Members) + if (e != null && SerialHelper.IsValid(e.Serial)) { - if (e != null && SerialHelper.IsValid(e.Serial)) - { - Mobile mob = World.Mobiles.Get(e.Serial); + Mobile mob = World.Mobiles.Get(e.Serial); - if (mob == null || mob.Distance > World.ClientViewRange) - { - NetClient.Socket.Send_QueryPartyPosition(); + if (mob == null || mob.Distance > World.ClientViewRange) + { + NetClient.Socket.Send_QueryPartyPosition(); - break; - } + break; } } } - else + } + else + { + foreach (Mobile mob in World.Mobiles.Values) { - foreach (Mobile mob in World.Mobiles.Values) + if (mob == World.Player) { - if (mob == World.Player) - { - continue; - } + continue; + } - Mobile mobs = World.Mobiles.Get(mob.Serial); - if (mobs.NotorietyFlag == NotorietyFlag.Ally) + Mobile mobs = World.Mobiles.Get(mob.Serial); + if (mobs.NotorietyFlag == NotorietyFlag.Ally) + { + if (mobs == null || mobs.Distance > 2000000) { - if (mobs == null || mobs.Distance > 2000000) - { - NetClient.Socket.Send_QueryGuildPosition(); + NetClient.Socket.Send_QueryGuildPosition(); - break; - } + break; } - } } + } } + } - public void Clear() - { - Entities.Clear(); - _ackReceived = false; - SetEnable(false); - } + public void Clear() + { + Entities.Clear(); + _ackReceived = false; + SetEnable(false); } } } \ No newline at end of file diff --git a/src/ClassicUO.Client/Game/Scenes/GameScene.cs b/src/ClassicUO.Client/Game/Scenes/GameScene.cs index 58161e603..be9ec33ea 100644 --- a/src/ClassicUO.Client/Game/Scenes/GameScene.cs +++ b/src/ClassicUO.Client/Game/Scenes/GameScene.cs @@ -450,7 +450,6 @@ public override void Unload() // special case for wmap. this allow us to save settings UIManager.GetGump()?.SaveSettings(); - MapNameMobilesManager.Instance.Save(); ProfileManager.CurrentProfile?.Save(ProfileManager.ProfilePath); Macros.Save(); diff --git a/src/ClassicUO.Client/Game/UI/Gumps/WorldMapGump.cs b/src/ClassicUO.Client/Game/UI/Gumps/WorldMapGump.cs index d64d9e08b..c81d165dc 100644 --- a/src/ClassicUO.Client/Game/UI/Gumps/WorldMapGump.cs +++ b/src/ClassicUO.Client/Game/UI/Gumps/WorldMapGump.cs @@ -2248,7 +2248,7 @@ public override bool Draw(UltimaBatcher2D batcher, int x, int y) // { // batcher.Draw2D(Textures.GetTexture()) // } - //} + // } return base.Draw(batcher, x, y); From 276d3901732d6ca719672650f0ed504bbb10cc4f Mon Sep 17 00:00:00 2001 From: Jeann Sebold Date: Fri, 26 Jan 2024 16:17:09 -0300 Subject: [PATCH 8/8] fix map, showhightlight with you use all spells --- .../Dust765/Dust765/CombatCollection.cs | 1 - src/ClassicUO.Client/Game/GameActions.cs | 5 ++++ .../Game/GameObjects/Views/LandView.cs | 2 +- .../Game/GameObjects/Views/MultiView.cs | 2 +- .../Game/GameObjects/Views/StaticView.cs | 2 +- .../Game/Managers/WorldMapEntityManager.cs | 27 ++++++++++--------- .../Network/PacketHandlers.cs | 2 +- 7 files changed, 23 insertions(+), 18 deletions(-) diff --git a/src/ClassicUO.Client/Dust765/Dust765/CombatCollection.cs b/src/ClassicUO.Client/Dust765/Dust765/CombatCollection.cs index f0cd01168..9ee50986c 100644 --- a/src/ClassicUO.Client/Dust765/Dust765/CombatCollection.cs +++ b/src/ClassicUO.Client/Dust765/Dust765/CombatCollection.cs @@ -1353,7 +1353,6 @@ public static void SpellCastFromCliloc(string text) { if (!GameActions.iscasting) World.Player.OnCasting.Start((uint)GameActions.LastSpellIndexCursor); - World.Player.Hue = 0x0023; } // ## BEGIN - END ## // ONCASTINGGUMP } diff --git a/src/ClassicUO.Client/Game/GameActions.cs b/src/ClassicUO.Client/Game/GameActions.cs index 2027f869c..1a6c65855 100644 --- a/src/ClassicUO.Client/Game/GameActions.cs +++ b/src/ClassicUO.Client/Game/GameActions.cs @@ -32,6 +32,7 @@ using System; using ClassicUO.Configuration; +using ClassicUO.Dust765.Dust765; using ClassicUO.Game.Data; using ClassicUO.Game.GameObjects; using ClassicUO.Game.Managers; @@ -720,6 +721,7 @@ public static void CastSpellFromBook(int index, uint bookSerial) // ## BEGIN - END ## // VISUAL HELPERS LastSpellIndexCursor = index; GameCursor._spellTime = 0; + // ## BEGIN - END ## // VISUAL HELPERS // ## BEGIN - END ## // ONCASTINGGUMP if (ProfileManager.CurrentProfile.OnCastingGump) @@ -741,6 +743,8 @@ public static void CastSpell(int index) // ## BEGIN - END ## // VISUAL HELPERS LastSpellIndexCursor = index; GameCursor._spellTime = 0; + CombatCollection.StartSpelltime(); + // ## BEGIN - END ## // VISUAL HELPERS // ## BEGIN - END ## // ONCASTINGGUMP if (ProfileManager.CurrentProfile.OnCastingGump) @@ -751,6 +755,7 @@ public static void CastSpell(int index) // ## BEGIN - END ## // ONCASTINGGUMP LastSpellIndex = index; + Socket.Send_CastSpell(index); } } diff --git a/src/ClassicUO.Client/Game/GameObjects/Views/LandView.cs b/src/ClassicUO.Client/Game/GameObjects/Views/LandView.cs index 10a4658c3..74774f580 100644 --- a/src/ClassicUO.Client/Game/GameObjects/Views/LandView.cs +++ b/src/ClassicUO.Client/Game/GameObjects/Views/LandView.cs @@ -91,7 +91,7 @@ public override bool Draw(UltimaBatcher2D batcher, int posX, int posY, float dep } if (ProfileManager.CurrentProfile.HighlightTileAtRangeSpell) { - if (GameCursor._spellTime >= 1 && Distance == ProfileManager.CurrentProfile.HighlightTileAtRangeRangeSpell) + if (GameActions.LastSpellIndexCursor > 0 && Distance == ProfileManager.CurrentProfile.HighlightTileAtRangeRangeSpell) { hueVec.X = ProfileManager.CurrentProfile.HighlightTileRangeHueSpell; hueVec.Y = 1; diff --git a/src/ClassicUO.Client/Game/GameObjects/Views/MultiView.cs b/src/ClassicUO.Client/Game/GameObjects/Views/MultiView.cs index 0f64b2bd9..74c2da8f9 100644 --- a/src/ClassicUO.Client/Game/GameObjects/Views/MultiView.cs +++ b/src/ClassicUO.Client/Game/GameObjects/Views/MultiView.cs @@ -123,7 +123,7 @@ public override bool Draw(UltimaBatcher2D batcher, int posX, int posY, float dep } if (ProfileManager.CurrentProfile.HighlightTileAtRangeSpell) { - if (GameCursor._spellTime >= 1 && Distance == ProfileManager.CurrentProfile.HighlightTileAtRangeRangeSpell) + if (GameActions.LastSpellIndexCursor > 0 && Distance == ProfileManager.CurrentProfile.HighlightTileAtRangeRangeSpell) { hueVec.X = ProfileManager.CurrentProfile.HighlightTileRangeHueSpell; hueVec.Y = 1; diff --git a/src/ClassicUO.Client/Game/GameObjects/Views/StaticView.cs b/src/ClassicUO.Client/Game/GameObjects/Views/StaticView.cs index e1a49f165..892e5233a 100644 --- a/src/ClassicUO.Client/Game/GameObjects/Views/StaticView.cs +++ b/src/ClassicUO.Client/Game/GameObjects/Views/StaticView.cs @@ -102,7 +102,7 @@ public override bool Draw(UltimaBatcher2D batcher, int posX, int posY, float dep } if (ProfileManager.CurrentProfile.HighlightTileAtRangeSpell) { - if (GameCursor._spellTime >= 1 && Distance == ProfileManager.CurrentProfile.HighlightTileAtRangeRangeSpell) + if (GameActions.LastSpellIndexCursor > 0 && Distance == ProfileManager.CurrentProfile.HighlightTileAtRangeRangeSpell) { hueVec.X = ProfileManager.CurrentProfile.HighlightTileRangeHueSpell; hueVec.Y = 1; diff --git a/src/ClassicUO.Client/Game/Managers/WorldMapEntityManager.cs b/src/ClassicUO.Client/Game/Managers/WorldMapEntityManager.cs index 96dc709fd..2d0653bf3 100644 --- a/src/ClassicUO.Client/Game/Managers/WorldMapEntityManager.cs +++ b/src/ClassicUO.Client/Game/Managers/WorldMapEntityManager.cs @@ -40,6 +40,7 @@ using ClassicUO.Network; using ClassicUO.Network.Encryption; using ClassicUO.Utility.Logging; +using static System.Net.Mime.MediaTypeNames; namespace ClassicUO.Game.Managers { @@ -65,7 +66,7 @@ public string GetName(uint serial) Entity e = World.Get(serial); - if (mob != null) + if (mob != null && !mob.IsDestroyed) { WMapEntity wme = World.WMapManager.GetEntity(mob); @@ -73,36 +74,36 @@ public string GetName(uint serial) { if (string.IsNullOrEmpty(wme.Name)) { + wme.Name = mob.Name; Name = wme.Name; nameCache[serial] = Name; + GameActions.Print("Mob is not null Is wme != null " + wme.Serial + " Name: " + mob.Name + " nameCache: " + nameCache[serial]); } } } - if (e != null && !e.IsDestroyed) + if (e != null) { Name = e.Name; serial = e.Serial; nameCache[serial] = Name; + GameActions.Print("Entity is not null Is wme != null " + e.Name + " Name: " + mob.Name + " nameCache: " + nameCache[serial]); } - - // Entity e = World.Get(Serial); - // Mobile mob = World.Mobiles.Get(Serial); - - // if (e != null && !e.IsDestroyed && !string.IsNullOrEmpty(e.Name) && Name != e.Name) - //{ - // Name = e.Name; - //} - + + if (nameCache.TryGetValue(serial, out string cachedName)) { - + var teste = string.IsNullOrEmpty(Name) ? cachedName : Name; + GameActions.Print("Entity is not null Is wme != null " + teste); return string.IsNullOrEmpty(Name) ? cachedName : Name; } else { - return string.IsNullOrEmpty(Name) ? "Out of range" : Name; + return string.IsNullOrEmpty(Name) ? "" : Name; } + + + // ## BEGIN - END ## // DUST765 - Fix to use cache for name in Map Gump } diff --git a/src/ClassicUO.Client/Network/PacketHandlers.cs b/src/ClassicUO.Client/Network/PacketHandlers.cs index ff799beb9..29ac52719 100644 --- a/src/ClassicUO.Client/Network/PacketHandlers.cs +++ b/src/ClassicUO.Client/Network/PacketHandlers.cs @@ -1798,7 +1798,7 @@ private static void DeathScreen(ref StackDataReader p) Map = World.Map.Index, LastUpdate = Time.Ticks + (1000 * 60 * 5), IsGuild = false, - Name = $"Your Corpse" + Name = $"YOUR CORPOSE" }; // ## BEGIN - END ## // TAZUO }