Skip to content

Commit

Permalink
fix some naked npcs (#57)
Browse files Browse the repository at this point in the history
  • Loading branch information
gmriggs authored Feb 6, 2022
1 parent 6874f65 commit c5af1a5
Show file tree
Hide file tree
Showing 8 changed files with 167 additions and 8 deletions.
4 changes: 2 additions & 2 deletions ACViewer/ACE.Server/WorldObjects/Creature.cs
Original file line number Diff line number Diff line change
Expand Up @@ -78,9 +78,9 @@ private void SetEphemeralValues()

EquipInventoryItems();

//GenerateWieldedTreasure();
GenerateWieldedTreasure();

//EquipInventoryItems();
EquipInventoryItems();

// TODO: fix tod data
Health.Current = Health.MaxValue;
Expand Down
22 changes: 22 additions & 0 deletions ACViewer/ACE.Server/WorldObjects/Creature_Equipment.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}
}
}
110 changes: 110 additions & 0 deletions ACViewer/ACE.Server/WorldObjects/WorldObject_Equipment.cs
Original file line number Diff line number Diff line change
@@ -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<WorldObject> GenerateWieldedTreasureSets(List<TreasureWielded> items)
{
var curIdx = 0;
List<WorldObject> results = null;
GenerateWieldedTreasureSets(items, ref results, ref curIdx);
return results;
}

private static void GenerateWieldedTreasureSets(List<TreasureWielded> items, ref List<WorldObject> 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<WorldObject>();

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;
}
}
}
2 changes: 1 addition & 1 deletion ACViewer/GameView.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand Down
27 changes: 25 additions & 2 deletions ACViewer/Model/ObjDesc.cs
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@ public void Add(uint clothingTableID, PaletteTemplate paletteTemplate = PaletteT
{
var clothingTable = DatManager.PortalDat.ReadFromDat<ClothingTable>(clothingTableID);

if (!clothingTable.ClothingBaseEffects.TryGetValue(SetupId, out var baseEffect)) return;

// palette changes
if (clothingTable.ClothingSubPalEffects.TryGetValue((uint)paletteTemplate, out var palEffect))
{
Expand All @@ -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)
Expand Down Expand Up @@ -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)
Expand Down
3 changes: 2 additions & 1 deletion ACViewer/Model/PartChange.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,8 @@ public void AddTexture(uint oldTexture, uint newTexture)
if (TextureChanges == null)
TextureChanges = new Dictionary<uint, uint>();

TextureChanges.Add(oldTexture, newTexture);
//TextureChanges.Add(oldTexture, newTexture);
TextureChanges[oldTexture] = newTexture;
}
}
}
2 changes: 1 addition & 1 deletion ACViewer/Picker.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
5 changes: 4 additions & 1 deletion ACViewer/WorldObjectViewer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand Down

0 comments on commit c5af1a5

Please sign in to comment.