/// <summary> /// Loads from a GameObject /// </summary> /// <returns></returns> public static ArkInventory LoadFromAsset(ArkWorld world, DotArkGameObject r) { //Get a list of all items List <ObjectProperty> inventoryItems; if (!r.PropExistsName("InventoryItems")) { inventoryItems = new List <ObjectProperty>(); } else { inventoryItems = ((ArrayProperty <ObjectProperty>)r.GetPropsByName("InventoryItems")[0]).items; } //Now, loop through and create items ArkInventory inventory = new ArkInventory(); inventory.items = new List <ArkPrimalItem>(); foreach (var o in inventoryItems) { ArkPrimalItem item = new ArkPrimalItem(world, o.gameObjectRef); if (item.isEngram) { continue; } inventory.items.Add(item); } //Return return(inventory); }
public ArkPrimalItem(ArkWorld world, DotArkGameObject orig) : base(world, orig) { //Check if this is claimed not to be an item if (!isItem) { throw new Exception("Cannot read ArkPrimalItem when property 'isItem' is false!"); } //Read in values. Start with values that will never be null classname = orig.classname.classname; stackSize = 1; if (orig.PropExistsName("ItemQuantity")) { stackSize = (int)orig.GetPropByName("ItemQuantity").data; } owner = new HighLevelArkGameObjectRef(world, (orig.GetPropsByName <ObjectProperty>("OwnerInventory")[0]).gameObjectRef); //Convert ItemID ArkStructProps itemIdStruct = (ArkStructProps)orig.GetPropsByName <StructProperty>("ItemId")[0].structData; byte[] buf = new byte[8]; BitConverter.GetBytes((UInt32)itemIdStruct.props_string["ItemID1"].data).CopyTo(buf, 0); BitConverter.GetBytes((UInt32)itemIdStruct.props_string["ItemID2"].data).CopyTo(buf, 4); itemId = BitConverter.ToUInt64(buf, 0); //Read booleans isBlueprint = GetBooleanProperty("bIsBlueprint"); isEngram = GetBooleanProperty("bIsEngram"); //Read props that may not exist if (CheckIfValueExists("SavedDurability")) { savedDurability = GetFloatProperty("SavedDurability"); } else { savedDurability = 1; } if (CheckIfValueExists("CrafterCharacterName")) { crafterName = GetStringProperty("CrafterCharacterName"); } else { crafterName = null; } if (CheckIfValueExists("CrafterTribeName")) { crafterTribe = GetStringProperty("CrafterTribeName"); } else { crafterTribe = null; } if (CheckIfValueExists("LastAutoDurabilityDecreaseTime")) { lastDurabilityDecreaseTime = (double)orig.GetPropsByName <DoubleProperty>("LastAutoDurabilityDecreaseTime")[0].data; } else { lastDurabilityDecreaseTime = -1; } }