Item BuildWeapon(RustItem sItem, ulong skin = ulong.MaxValue) { Item item = ItemManager.CreateByItemID(sItem.itemid, 1, skin != ulong.MaxValue ? skin : sItem.skinid); if (item.hasCondition) { item.condition = sItem.condition; } var weapon = item.GetHeldEntity() as BaseProjectile; if (weapon != null) { var def = ItemManager.FindItemDefinition(sItem.ammotype); weapon.primaryMagazine.ammoType = def; weapon.primaryMagazine.contents = sItem.ammoamount; } if (sItem.mods != null) { foreach (var mod in sItem.mods) { item.contents.AddItem(BuildItem(mod).info, 1); } } return(item); }
public static RustItem fromItem(Item item, string container) { RustItem iItem = new RustItem { shortname = item.info?.shortname, amount = item.amount, mods = new List <RustItem>(), container = container, skinid = item.skin }; if (item.info == null) { return(iItem); } iItem.itemid = item.info.itemid; iItem.weapon = false; if (item.hasCondition) { iItem.condition = item.condition; iItem.maxCondition = item.maxCondition; } FlameThrower flameThrower = item.GetHeldEntity()?.GetComponent <FlameThrower>(); if (flameThrower != null) { iItem.flamefuel = flameThrower.ammo; } BaseProjectile weapon = item.GetHeldEntity() as BaseProjectile; if (weapon == null) { return(iItem); } if (weapon.primaryMagazine == null) { return(iItem); } iItem.ammoamount = weapon.primaryMagazine.contents; iItem.ammotype = weapon.primaryMagazine.ammoType.shortname; iItem.weapon = true; if (item.contents != null) { foreach (var mod in item.contents.itemList) { if (mod.info.itemid != 0) { iItem.mods.Add(fromItem(mod, "noun")); } } } return(iItem); }
public static RustItemContainer fromContainer(ItemContainer cont, string pType) { RustItemContainer itemContainer = new RustItemContainer(cont.itemList.Count) { type = pType }; for (int i = 0; i < itemContainer.container.Count <RustItem>(); i++) { itemContainer.container[i] = RustItem.fromItem(cont.itemList[i], pType); } return(itemContainer); }
Item BuildItem(RustItem sItem, ulong skin = ulong.MaxValue) { if (sItem.amount < 1) { sItem.amount = 1; } Item item = ItemManager.CreateByItemID(sItem.itemid, sItem.amount, skin != ulong.MaxValue ? skin : sItem.skinid); if (item.hasCondition) { item.condition = sItem.condition; item.maxCondition = sItem.maxCondition; } FlameThrower flameThrower = item.GetHeldEntity()?.GetComponent <FlameThrower>(); if (flameThrower) { flameThrower.ammo = sItem.flamefuel; } return(item); }