public void PlaceItem(ItemObject item) { Ray ray = _camera.ScreenPointToRay(Input.mousePosition); if (Physics.Raycast(ray, out var hitCell, float.PositiveInfinity, whatIsGrid) == false) { Destroy(_tempObject); return; } if (_tempObject.GetComponent <TempObjectHandler>().CanPlaceHere() == false) { Destroy(_tempObject); return; } TempObjectHandler tempObjectHandler = _tempObject.GetComponent <TempObjectHandler>(); tempObjectHandler.MarkCellsAsOccupied(); GameObject newObject = Instantiate(item.prefab, hitCell.transform.position, Quaternion.identity, transform); Rigidbody newObjectRb = newObject.AddComponent <Rigidbody>(); newObjectRb.isKinematic = true; GameData.Main.spawnedItems.Add(item); ItemInfoHolder newObjectInfo = newObject.GetComponent <ItemInfoHolder>(); newObjectInfo.itemObject = item; newObjectInfo.id = GameData.Main.spawnedItems.Count - 1; newObjectInfo.itemObject.sizeOnGrid = tempObjectHandler.GetCellCount(); LeanAudio.play(endPlacingAudio, 0.5f); Destroy(_tempObject); }
public static void Notify(ReceivablePacket packet) { // Read Data int listSize = packet.ReadInt(); ArrayList itemList = new ArrayList(listSize); for (int i = 0; i < listSize; i++) { int itemId = packet.ReadInt(); bool equiped = packet.ReadInt() == 1 ? true : false; int amount = packet.ReadInt(); int enchant = packet.ReadInt(); ItemInfoHolder itemData = new ItemInfoHolder(itemId, equiped, amount, enchant); itemList.Add(itemData); } InventoryManager.Instance.CharacterItems(itemList); }
public CharacterInventoryResult(Player player) { List <ItemInfoHolder> itemList = new List <ItemInfoHolder>(); try { MySqlConnection con = DatabaseManager.GetConnection(); MySqlCommand cmd = new MySqlCommand(CHARACTER_INVENTORY_ITEMS, con); cmd.Parameters.AddWithValue("owner", player.GetName()); MySqlDataReader reader = cmd.ExecuteReader(); while (reader.Read()) { int itemId = reader.GetInt32("item_id"); bool equipped = reader.GetBoolean("equiped"); int amount = reader.GetInt32("amount"); int enchantLvl = reader.GetInt32("enchant"); ItemInfoHolder item = new ItemInfoHolder(itemId, equipped, amount, enchantLvl); itemList.Add(item); } con.Close(); } catch (Exception e) { LogManager.Log(e.ToString()); } WriteShort(13); // Packet id. WriteInt(itemList.Count); foreach (ItemInfoHolder item in itemList) { WriteInt(item.GetItemId()); WriteInt(item.IsEquipped() ? 1 : 0); WriteInt(item.GetAmount()); WriteInt(item.GetEnchantLvl()); } }