diff --git a/ACViewer/ACE.Server/WorldObjects/Creature.cs b/ACViewer/ACE.Server/WorldObjects/Creature.cs index 5a60a94..7585f74 100644 --- a/ACViewer/ACE.Server/WorldObjects/Creature.cs +++ b/ACViewer/ACE.Server/WorldObjects/Creature.cs @@ -78,9 +78,9 @@ private void SetEphemeralValues() EquipInventoryItems(); - //GenerateWieldedTreasure(); + GenerateWieldedTreasure(); - //EquipInventoryItems(); + EquipInventoryItems(); // TODO: fix tod data Health.Current = Health.MaxValue; diff --git a/ACViewer/ACE.Server/WorldObjects/Creature_Equipment.cs b/ACViewer/ACE.Server/WorldObjects/Creature_Equipment.cs index 15a6200..0ed70fb 100644 --- a/ACViewer/ACE.Server/WorldObjects/Creature_Equipment.cs +++ b/ACViewer/ACE.Server/WorldObjects/Creature_Equipment.cs @@ -399,5 +399,27 @@ public bool TryWieldObject(WorldObject worldObject, EquipMask wieldedLocation) return true; } + public void GenerateWieldedTreasure() + { + if (WieldedTreasure == null) return; + + //var table = new TreasureWieldedTable(WieldedTreasure); + + var wieldedTreasure = GenerateWieldedTreasureSets(WieldedTreasure); + + if (wieldedTreasure == null) + return; + + foreach (var item in wieldedTreasure) + { + //if (item.ValidLocations == null || (ItemCapacity ?? 0) > 0) + { + if (!TryAddToInventory(item)) + item.Destroy(); + } + //else + //TryWieldObject(item, (EquipMask)item.ValidLocations); + } + } } } diff --git a/ACViewer/ACE.Server/WorldObjects/WorldObject_Equipment.cs b/ACViewer/ACE.Server/WorldObjects/WorldObject_Equipment.cs new file mode 100644 index 0000000..bc9b377 --- /dev/null +++ b/ACViewer/ACE.Server/WorldObjects/WorldObject_Equipment.cs @@ -0,0 +1,110 @@ +using System; +using System.Collections.Generic; + +using ACE.Common; +using ACE.Common.Extensions; +using ACE.Database.Models.World; +using ACE.Server.Factories; + +namespace ACE.Server.WorldObjects +{ + partial class WorldObject + { + public static List GenerateWieldedTreasureSets(List items) + { + var curIdx = 0; + List results = null; + GenerateWieldedTreasureSets(items, ref results, ref curIdx); + return results; + } + + private static void GenerateWieldedTreasureSets(List items, ref List results, ref int curIdx, bool skip = false) + { + var rng = ThreadSafeRandom.Next(0.0f, 1.0f); + var probability = 0.0f; + var rolled = false; + var continued = false; + + for (; curIdx < items.Count; curIdx++) + { + var item = items[curIdx]; + + if (item.ContinuesPreviousSet) + { + if (!continued) + { + curIdx--; + return; + } + else + continued = false; + } + + var skipNext = true; + + if (!skip) + { + if (item.SetStart || probability >= 1.0f) + { + rng = ThreadSafeRandom.Next(0.0f, 1.0f); + probability = 0.0f; + rolled = false; + } + + probability += item.Probability; + + if (rng < probability && !rolled) + { + rolled = true; + skipNext = false; + + // item roll successful, add to generated list + var wo = CreateWieldedTreasure(item); + + if (wo != null) + { + if (results == null) + results = new List(); + + results.Add(wo); + } + } + } + + if (item.HasSubSet) + { + curIdx++; + GenerateWieldedTreasureSets(items, ref results, ref curIdx, skipNext); + continued = true; + } + } + } + + public static WorldObject CreateWieldedTreasure(TreasureWielded item) + { + var wo = WorldObjectFactory.CreateNewWorldObject(item.WeenieClassId); + if (wo == null) return null; + + if (item.PaletteId > 0) + wo.PaletteTemplate = (int)item.PaletteId; + + if (item.Shade > 0) + wo.Shade = item.Shade; + + if (item.StackSize > 0) + { + var stackSize = item.StackSize; + + var hasVariance = item.StackSizeVariance > 0; + if (hasVariance) + { + var minStack = Math.Max(1, (item.StackSize * (1.0f - item.StackSizeVariance)).Round()); + var maxStack = item.StackSize; + stackSize = ThreadSafeRandom.Next(minStack, maxStack); + } + wo.SetStackSize(stackSize); + } + return wo; + } + } +} diff --git a/ACViewer/GameView.cs b/ACViewer/GameView.cs index 424bd6a..dfa9539 100644 --- a/ACViewer/GameView.cs +++ b/ACViewer/GameView.cs @@ -141,7 +141,7 @@ protected override void Update(GameTime time) /*if (keyboardState.IsKeyDown(Keys.L) && !PrevKeyboardState.IsKeyDown(Keys.L)) { ViewMode = ViewMode.WorldObject; - WorldObjectViewer.Instance.LoadModel(44896); + WorldObjectViewer.Instance.LoadModel(42809); }*/ if (!_graphicsDeviceManager.PreferMultiSampling && UseMSAA && DateTime.Now - LastResizeEvent >= TimeSpan.FromSeconds(1)) diff --git a/ACViewer/Model/ObjDesc.cs b/ACViewer/Model/ObjDesc.cs index fbd44db..664c7a8 100644 --- a/ACViewer/Model/ObjDesc.cs +++ b/ACViewer/Model/ObjDesc.cs @@ -31,6 +31,8 @@ public void Add(uint clothingTableID, PaletteTemplate paletteTemplate = PaletteT { var clothingTable = DatManager.PortalDat.ReadFromDat(clothingTableID); + if (!clothingTable.ClothingBaseEffects.TryGetValue(SetupId, out var baseEffect)) return; + // palette changes if (clothingTable.ClothingSubPalEffects.TryGetValue((uint)paletteTemplate, out var palEffect)) { @@ -40,8 +42,6 @@ public void Add(uint clothingTableID, PaletteTemplate paletteTemplate = PaletteT PaletteChanges.Add(palEffect.CloSubPalettes, shade); } - if (!clothingTable.ClothingBaseEffects.TryGetValue(SetupId, out var baseEffect)) return; - foreach (var objEffect in baseEffect.CloObjectEffects) { if (PartChanges == null) @@ -132,6 +132,29 @@ public void AddBaseModelData(WorldObject wo) // Mouth if (wo.DefaultMouthTextureDID != null && wo.MouthTextureDID != null) headChange.AddTexture(wo.DefaultMouthTextureDID.Value, wo.MouthTextureDID.Value); + + // oh god why + if (wo.Weenie.PropertiesPalette != null) + { + foreach (var palette in wo.Weenie.PropertiesPalette) + AddPaletteChange(palette.SubPaletteId, palette.Offset, palette.Length); + } + + if (wo.Weenie.PropertiesAnimPart != null) + { + foreach (var animPart in wo.Weenie.PropertiesAnimPart) + GetPartChange(animPart.Index, animPart.AnimationId); + } + + if (wo.Weenie.PropertiesTextureMap != null) + { + foreach (var textureMap in wo.Weenie.PropertiesTextureMap) + { + var partChange = GetPartChange(textureMap.PartIndex); + + partChange.AddTexture(textureMap.OldTexture, textureMap.NewTexture); + } + } } private PartChange GetPartChange(uint partIdx, uint? newGfxObjId = null) diff --git a/ACViewer/Model/PartChange.cs b/ACViewer/Model/PartChange.cs index f15ba0e..546a94c 100644 --- a/ACViewer/Model/PartChange.cs +++ b/ACViewer/Model/PartChange.cs @@ -17,7 +17,8 @@ public void AddTexture(uint oldTexture, uint newTexture) if (TextureChanges == null) TextureChanges = new Dictionary(); - TextureChanges.Add(oldTexture, newTexture); + //TextureChanges.Add(oldTexture, newTexture); + TextureChanges[oldTexture] = newTexture; } } } diff --git a/ACViewer/Picker.cs b/ACViewer/Picker.cs index b009ad5..94555f0 100644 --- a/ACViewer/Picker.cs +++ b/ACViewer/Picker.cs @@ -40,7 +40,7 @@ public static void HandleLeftClick(int mouseX, int mouseY) var transform = projectionInverse * viewInverse; - // convert viewport coords [-1, 1] + // convert viewport coords to [-1, 1] var nx = mouseX * 2.0f / Viewport.Width - 1.0f; var ny = 1.0f - mouseY * 2.0f / Viewport.Height; // invert y diff --git a/ACViewer/WorldObjectViewer.cs b/ACViewer/WorldObjectViewer.cs index 0c125e7..ea201c5 100644 --- a/ACViewer/WorldObjectViewer.cs +++ b/ACViewer/WorldObjectViewer.cs @@ -88,6 +88,9 @@ public void LoadModel(uint wcid) if (!LoadedOnce) { + //Camera.Position = Vector3.Zero; + //Camera.Dir = Vector3.Normalize(new Vector3(1, 1, 0)); + Camera.Position = new Vector3(11.782367f, 12.763985f, 1.6514041f); Camera.Dir = new Vector3(0.30761153f, -0.94673103f, 0.093334414f); Camera.Up = Vector3.UnitZ; @@ -97,7 +100,7 @@ public void LoadModel(uint wcid) Camera.Speed = Camera.Model_Speed; } - Buffer.BuildTextureAtlases(); + Buffer.BuildTextureAtlases(Buffer.InstanceTextureAtlasChains); Buffer.BuildBuffer(Buffer.RB_Instances); Server.InstancesLoaded = true; Server.Initting = false;