Upload from upload_mods.ps1
This commit is contained in:
98
Scripts/MinEvents/NPCs/MinEventActionGiveNPCItemRebirth.cs
Normal file
98
Scripts/MinEvents/NPCs/MinEventActionGiveNPCItemRebirth.cs
Normal file
@@ -0,0 +1,98 @@
|
||||
using Audio;
|
||||
using System.Globalization;
|
||||
using System.Xml.Linq;
|
||||
|
||||
public class MinEventActionGiveNPCItemRebirth : MinEventActionRemoveBuff
|
||||
{
|
||||
private int numItems = 1;
|
||||
private string strNumItems = "";
|
||||
private int numMining = 0;
|
||||
private string itemName = "";
|
||||
|
||||
public override void Execute(MinEventParams _params)
|
||||
{
|
||||
var entity = _params.Self as EntityNPCRebirth;
|
||||
|
||||
ItemValue item = ItemClass.GetItem(itemName, false);
|
||||
ItemValue itemValue = new ItemValue(ItemClass.GetItem(itemName, false).type, true);
|
||||
|
||||
if (strNumItems.Contains("-"))
|
||||
{
|
||||
string[] array = strNumItems.Split(new char[]
|
||||
{
|
||||
'-'
|
||||
});
|
||||
int min = StringParsers.ParseSInt32(array[0], 0, -1, NumberStyles.Integer);
|
||||
int maxExclusive = StringParsers.ParseSInt32(array[1], 0, -1, NumberStyles.Integer) + 1;
|
||||
numItems = Manager.random.RandomRange(min, maxExclusive);
|
||||
}
|
||||
else
|
||||
{
|
||||
numItems = StringParsers.ParseSInt32(strNumItems, 0, -1, NumberStyles.Integer);
|
||||
}
|
||||
|
||||
int num = numItems;
|
||||
|
||||
if (itemValue.HasQuality)
|
||||
{
|
||||
itemValue = new ItemValue(item.type, num, num, true, null, 1f);
|
||||
num = 1;
|
||||
}
|
||||
else
|
||||
{
|
||||
itemValue = new ItemValue(item.type, true);
|
||||
}
|
||||
|
||||
if (numMining > 0)
|
||||
{
|
||||
float flNPCMiningLevel = entity.Buffs.GetCustomVar("$FR_NPC_MiningLevel");
|
||||
|
||||
num = (int)((1 + (flNPCMiningLevel / 5)) * num);
|
||||
}
|
||||
|
||||
if (entity.lootContainer != null)
|
||||
{
|
||||
//Log.Out("MinEventActionGiveNPCItemRebirth-Execute Item Nalue: " + itemValue.ItemClass.GetItemName());
|
||||
ValueTuple<bool, bool> tryStack = entity.lootContainer.TryStackItem(0, new ItemStack(itemValue, num));
|
||||
|
||||
if (!tryStack.Item1)
|
||||
{
|
||||
if (!entity.lootContainer.AddItem(new ItemStack(itemValue, num)))
|
||||
{
|
||||
entity.world.gameManager.ItemDropServer(new ItemStack(itemValue, num), entity.GetPosition(), Vector3.zero);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public override bool ParseXmlAttribute(XAttribute _attribute)
|
||||
{
|
||||
var flag = base.ParseXmlAttribute(_attribute);
|
||||
if (flag) return true;
|
||||
var name = _attribute.Name;
|
||||
|
||||
if (name == null)
|
||||
{
|
||||
return flag;
|
||||
}
|
||||
else if (name == "numMining")
|
||||
{
|
||||
numMining = numItems = StringParsers.ParseSInt32(_attribute.Value, 0, -1, NumberStyles.Integer);
|
||||
return true;
|
||||
}
|
||||
else if (name == "numItems")
|
||||
{
|
||||
strNumItems = _attribute.Value;
|
||||
return true;
|
||||
}
|
||||
else if (name == "itemName")
|
||||
{
|
||||
itemName = _attribute.Value;
|
||||
return true;
|
||||
}
|
||||
else
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user