fix: Codegens fillable containers (#862)
- [X] Fillable containers now relock/retrap after respawn. - [X] Optimized the lookup and serialization.
This commit is contained in:
parent
db20722711
commit
59e1793c2d
16 changed files with 1435 additions and 1612 deletions
|
|
@ -0,0 +1,102 @@
|
|||
using System;
|
||||
|
||||
namespace Server.Items;
|
||||
|
||||
public class FillableEntry
|
||||
{
|
||||
protected Type[] _types;
|
||||
protected int _weight;
|
||||
|
||||
public FillableEntry(Type type) : this(1, new[] { type })
|
||||
{
|
||||
}
|
||||
|
||||
public FillableEntry(int weight, Type type) : this(weight, new[] { type })
|
||||
{
|
||||
}
|
||||
|
||||
public FillableEntry(Type[] types) : this(1, types)
|
||||
{
|
||||
}
|
||||
|
||||
public FillableEntry(int weight, Type[] types)
|
||||
{
|
||||
_weight = weight;
|
||||
_types = types;
|
||||
}
|
||||
|
||||
public FillableEntry(int weight, Type[] types, int offset, int count)
|
||||
{
|
||||
_weight = weight;
|
||||
_types = new Type[count];
|
||||
Array.Copy(types, offset, _types, 0, count);
|
||||
}
|
||||
|
||||
public Type[] Types => _types;
|
||||
public int Weight => _weight;
|
||||
|
||||
public virtual Item Construct()
|
||||
{
|
||||
var item = Loot.Construct(_types);
|
||||
|
||||
if (item is Key key)
|
||||
{
|
||||
key.ItemID = Utility.RandomList(
|
||||
(int)KeyType.Copper,
|
||||
(int)KeyType.Gold,
|
||||
(int)KeyType.Iron,
|
||||
(int)KeyType.Rusty
|
||||
);
|
||||
}
|
||||
else if (item is Arrow or Bolt)
|
||||
{
|
||||
item.Amount = Utility.RandomMinMax(2, 6);
|
||||
}
|
||||
else if (item is Bandage or Lockpick)
|
||||
{
|
||||
item.Amount = Utility.RandomMinMax(1, 3);
|
||||
}
|
||||
|
||||
return item;
|
||||
}
|
||||
}
|
||||
|
||||
public class FillableBvrge : FillableEntry
|
||||
{
|
||||
public FillableBvrge(Type type, BeverageType content) : this(1, type, content)
|
||||
{
|
||||
}
|
||||
|
||||
public FillableBvrge(int weight, Type type, BeverageType content) : base(weight, type) =>
|
||||
Content = content;
|
||||
|
||||
public BeverageType Content { get; }
|
||||
|
||||
public override Item Construct()
|
||||
{
|
||||
Item item;
|
||||
|
||||
var index = Utility.Random(_types.Length);
|
||||
|
||||
if (_types[index] == typeof(BeverageBottle))
|
||||
{
|
||||
item = new BeverageBottle(Content);
|
||||
}
|
||||
else if (_types[index] == typeof(Jug))
|
||||
{
|
||||
item = new Jug(Content);
|
||||
}
|
||||
else
|
||||
{
|
||||
item = base.Construct();
|
||||
|
||||
if (item is BaseBeverage bev)
|
||||
{
|
||||
bev.Content = Content;
|
||||
bev.Quantity = bev.MaxQuantity;
|
||||
}
|
||||
}
|
||||
|
||||
return item;
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue