Skip to content

Commit c5af1a5

Browse files
authored
fix some naked npcs (#57)
1 parent 6874f65 commit c5af1a5

File tree

8 files changed

+167
-8
lines changed

8 files changed

+167
-8
lines changed

ACViewer/ACE.Server/WorldObjects/Creature.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -78,9 +78,9 @@ private void SetEphemeralValues()
7878

7979
EquipInventoryItems();
8080

81-
//GenerateWieldedTreasure();
81+
GenerateWieldedTreasure();
8282

83-
//EquipInventoryItems();
83+
EquipInventoryItems();
8484

8585
// TODO: fix tod data
8686
Health.Current = Health.MaxValue;

ACViewer/ACE.Server/WorldObjects/Creature_Equipment.cs

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -399,5 +399,27 @@ public bool TryWieldObject(WorldObject worldObject, EquipMask wieldedLocation)
399399
return true;
400400
}
401401

402+
public void GenerateWieldedTreasure()
403+
{
404+
if (WieldedTreasure == null) return;
405+
406+
//var table = new TreasureWieldedTable(WieldedTreasure);
407+
408+
var wieldedTreasure = GenerateWieldedTreasureSets(WieldedTreasure);
409+
410+
if (wieldedTreasure == null)
411+
return;
412+
413+
foreach (var item in wieldedTreasure)
414+
{
415+
//if (item.ValidLocations == null || (ItemCapacity ?? 0) > 0)
416+
{
417+
if (!TryAddToInventory(item))
418+
item.Destroy();
419+
}
420+
//else
421+
//TryWieldObject(item, (EquipMask)item.ValidLocations);
422+
}
423+
}
402424
}
403425
}
Lines changed: 110 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,110 @@
1+
using System;
2+
using System.Collections.Generic;
3+
4+
using ACE.Common;
5+
using ACE.Common.Extensions;
6+
using ACE.Database.Models.World;
7+
using ACE.Server.Factories;
8+
9+
namespace ACE.Server.WorldObjects
10+
{
11+
partial class WorldObject
12+
{
13+
public static List<WorldObject> GenerateWieldedTreasureSets(List<TreasureWielded> items)
14+
{
15+
var curIdx = 0;
16+
List<WorldObject> results = null;
17+
GenerateWieldedTreasureSets(items, ref results, ref curIdx);
18+
return results;
19+
}
20+
21+
private static void GenerateWieldedTreasureSets(List<TreasureWielded> items, ref List<WorldObject> results, ref int curIdx, bool skip = false)
22+
{
23+
var rng = ThreadSafeRandom.Next(0.0f, 1.0f);
24+
var probability = 0.0f;
25+
var rolled = false;
26+
var continued = false;
27+
28+
for (; curIdx < items.Count; curIdx++)
29+
{
30+
var item = items[curIdx];
31+
32+
if (item.ContinuesPreviousSet)
33+
{
34+
if (!continued)
35+
{
36+
curIdx--;
37+
return;
38+
}
39+
else
40+
continued = false;
41+
}
42+
43+
var skipNext = true;
44+
45+
if (!skip)
46+
{
47+
if (item.SetStart || probability >= 1.0f)
48+
{
49+
rng = ThreadSafeRandom.Next(0.0f, 1.0f);
50+
probability = 0.0f;
51+
rolled = false;
52+
}
53+
54+
probability += item.Probability;
55+
56+
if (rng < probability && !rolled)
57+
{
58+
rolled = true;
59+
skipNext = false;
60+
61+
// item roll successful, add to generated list
62+
var wo = CreateWieldedTreasure(item);
63+
64+
if (wo != null)
65+
{
66+
if (results == null)
67+
results = new List<WorldObject>();
68+
69+
results.Add(wo);
70+
}
71+
}
72+
}
73+
74+
if (item.HasSubSet)
75+
{
76+
curIdx++;
77+
GenerateWieldedTreasureSets(items, ref results, ref curIdx, skipNext);
78+
continued = true;
79+
}
80+
}
81+
}
82+
83+
public static WorldObject CreateWieldedTreasure(TreasureWielded item)
84+
{
85+
var wo = WorldObjectFactory.CreateNewWorldObject(item.WeenieClassId);
86+
if (wo == null) return null;
87+
88+
if (item.PaletteId > 0)
89+
wo.PaletteTemplate = (int)item.PaletteId;
90+
91+
if (item.Shade > 0)
92+
wo.Shade = item.Shade;
93+
94+
if (item.StackSize > 0)
95+
{
96+
var stackSize = item.StackSize;
97+
98+
var hasVariance = item.StackSizeVariance > 0;
99+
if (hasVariance)
100+
{
101+
var minStack = Math.Max(1, (item.StackSize * (1.0f - item.StackSizeVariance)).Round());
102+
var maxStack = item.StackSize;
103+
stackSize = ThreadSafeRandom.Next(minStack, maxStack);
104+
}
105+
wo.SetStackSize(stackSize);
106+
}
107+
return wo;
108+
}
109+
}
110+
}

ACViewer/GameView.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -141,7 +141,7 @@ protected override void Update(GameTime time)
141141
/*if (keyboardState.IsKeyDown(Keys.L) && !PrevKeyboardState.IsKeyDown(Keys.L))
142142
{
143143
ViewMode = ViewMode.WorldObject;
144-
WorldObjectViewer.Instance.LoadModel(44896);
144+
WorldObjectViewer.Instance.LoadModel(42809);
145145
}*/
146146

147147
if (!_graphicsDeviceManager.PreferMultiSampling && UseMSAA && DateTime.Now - LastResizeEvent >= TimeSpan.FromSeconds(1))

ACViewer/Model/ObjDesc.cs

Lines changed: 25 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,8 @@ public void Add(uint clothingTableID, PaletteTemplate paletteTemplate = PaletteT
3131
{
3232
var clothingTable = DatManager.PortalDat.ReadFromDat<ClothingTable>(clothingTableID);
3333

34+
if (!clothingTable.ClothingBaseEffects.TryGetValue(SetupId, out var baseEffect)) return;
35+
3436
// palette changes
3537
if (clothingTable.ClothingSubPalEffects.TryGetValue((uint)paletteTemplate, out var palEffect))
3638
{
@@ -40,8 +42,6 @@ public void Add(uint clothingTableID, PaletteTemplate paletteTemplate = PaletteT
4042
PaletteChanges.Add(palEffect.CloSubPalettes, shade);
4143
}
4244

43-
if (!clothingTable.ClothingBaseEffects.TryGetValue(SetupId, out var baseEffect)) return;
44-
4545
foreach (var objEffect in baseEffect.CloObjectEffects)
4646
{
4747
if (PartChanges == null)
@@ -132,6 +132,29 @@ public void AddBaseModelData(WorldObject wo)
132132
// Mouth
133133
if (wo.DefaultMouthTextureDID != null && wo.MouthTextureDID != null)
134134
headChange.AddTexture(wo.DefaultMouthTextureDID.Value, wo.MouthTextureDID.Value);
135+
136+
// oh god why
137+
if (wo.Weenie.PropertiesPalette != null)
138+
{
139+
foreach (var palette in wo.Weenie.PropertiesPalette)
140+
AddPaletteChange(palette.SubPaletteId, palette.Offset, palette.Length);
141+
}
142+
143+
if (wo.Weenie.PropertiesAnimPart != null)
144+
{
145+
foreach (var animPart in wo.Weenie.PropertiesAnimPart)
146+
GetPartChange(animPart.Index, animPart.AnimationId);
147+
}
148+
149+
if (wo.Weenie.PropertiesTextureMap != null)
150+
{
151+
foreach (var textureMap in wo.Weenie.PropertiesTextureMap)
152+
{
153+
var partChange = GetPartChange(textureMap.PartIndex);
154+
155+
partChange.AddTexture(textureMap.OldTexture, textureMap.NewTexture);
156+
}
157+
}
135158
}
136159

137160
private PartChange GetPartChange(uint partIdx, uint? newGfxObjId = null)

ACViewer/Model/PartChange.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,8 @@ public void AddTexture(uint oldTexture, uint newTexture)
1717
if (TextureChanges == null)
1818
TextureChanges = new Dictionary<uint, uint>();
1919

20-
TextureChanges.Add(oldTexture, newTexture);
20+
//TextureChanges.Add(oldTexture, newTexture);
21+
TextureChanges[oldTexture] = newTexture;
2122
}
2223
}
2324
}

ACViewer/Picker.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ public static void HandleLeftClick(int mouseX, int mouseY)
4040

4141
var transform = projectionInverse * viewInverse;
4242

43-
// convert viewport coords [-1, 1]
43+
// convert viewport coords to [-1, 1]
4444
var nx = mouseX * 2.0f / Viewport.Width - 1.0f;
4545
var ny = 1.0f - mouseY * 2.0f / Viewport.Height; // invert y
4646

ACViewer/WorldObjectViewer.cs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,9 @@ public void LoadModel(uint wcid)
8888

8989
if (!LoadedOnce)
9090
{
91+
//Camera.Position = Vector3.Zero;
92+
//Camera.Dir = Vector3.Normalize(new Vector3(1, 1, 0));
93+
9194
Camera.Position = new Vector3(11.782367f, 12.763985f, 1.6514041f);
9295
Camera.Dir = new Vector3(0.30761153f, -0.94673103f, 0.093334414f);
9396
Camera.Up = Vector3.UnitZ;
@@ -97,7 +100,7 @@ public void LoadModel(uint wcid)
97100
Camera.Speed = Camera.Model_Speed;
98101
}
99102

100-
Buffer.BuildTextureAtlases();
103+
Buffer.BuildTextureAtlases(Buffer.InstanceTextureAtlasChains);
101104
Buffer.BuildBuffer(Buffer.RB_Instances);
102105
Server.InstancesLoaded = true;
103106
Server.Initting = false;

0 commit comments

Comments
 (0)