Skip to content

Item

tibiawikisql.models.item

Classes:

Name Description
ItemAttribute

Represents an Item's attribute.

ItemOffer

Represents an offer to buy or sell the item.

ItemStoreOffer

Represents an offer for an item on the Tibia Store.

ItemDrop

Represents a creature that drops the item.

ItemQuestReward

A quest where the item is awarded.

Item

Represents an Item.

Book

Represents a book or written document in Tibia.

Key

Represents a key item.

ItemAttribute pydantic-model

Bases: BaseModel

Represents an Item's attribute.

Show JSON schema:
{
  "description": "Represents an Item's attribute.",
  "properties": {
    "name": {
      "title": "Name",
      "type": "string"
    },
    "value": {
      "title": "Value",
      "type": "string"
    }
  },
  "required": [
    "name",
    "value"
  ],
  "title": "ItemAttribute",
  "type": "object"
}

Fields:

name pydantic-field
name: str

The name of the attribute.

value pydantic-field
value: str

The value of the attribute.

ItemOffer pydantic-model

Bases: BaseModel

Represents an offer to buy or sell the item.

Show JSON schema:
{
  "description": "Represents an offer to buy or sell the item.",
  "properties": {
    "npc_id": {
      "title": "Npc Id",
      "type": "integer"
    },
    "npc_title": {
      "title": "Npc Title",
      "type": "string"
    },
    "currency_id": {
      "title": "Currency Id",
      "type": "integer"
    },
    "currency_title": {
      "title": "Currency Title",
      "type": "string"
    },
    "value": {
      "title": "Value",
      "type": "integer"
    }
  },
  "required": [
    "npc_id",
    "npc_title",
    "currency_id",
    "currency_title",
    "value"
  ],
  "title": "ItemOffer",
  "type": "object"
}

Fields:

npc_id pydantic-field
npc_id: int

The article ID of the npc offering the item

npc_title pydantic-field
npc_title: str

The title of the npc offering the item.

currency_id pydantic-field
currency_id: int

The article ID of the currency used.

currency_title pydantic-field
currency_title: str

The title of the currency used.

value pydantic-field
value: int

The value of the item.

ItemStoreOffer pydantic-model

Bases: BaseModel

Represents an offer for an item on the Tibia Store.

Show JSON schema:
{
  "description": "Represents an offer for an item on the Tibia Store.",
  "properties": {
    "price": {
      "title": "Price",
      "type": "integer"
    },
    "amount": {
      "title": "Amount",
      "type": "integer"
    },
    "currency": {
      "title": "Currency",
      "type": "string"
    }
  },
  "required": [
    "price",
    "amount",
    "currency"
  ],
  "title": "ItemStoreOffer",
  "type": "object"
}

Fields:

price pydantic-field
price: int

The price of the item.

amount pydantic-field
amount: int

The amount of the item.

currency pydantic-field
currency: str

The currency used. In most of the times it is Tibia Coins.

ItemDrop pydantic-model

Bases: BaseModel

Represents a creature that drops the item.

Show JSON schema:
{
  "description": "Represents a creature that drops the item.",
  "properties": {
    "creature_id": {
      "anyOf": [
        {
          "type": "integer"
        },
        {
          "type": "null"
        }
      ],
      "default": null,
      "title": "Creature Id"
    },
    "creature_title": {
      "title": "Creature Title",
      "type": "string"
    },
    "min": {
      "title": "Min",
      "type": "integer"
    },
    "max": {
      "title": "Max",
      "type": "integer"
    },
    "chance": {
      "anyOf": [
        {
          "type": "number"
        },
        {
          "type": "null"
        }
      ],
      "default": null,
      "title": "Chance"
    }
  },
  "required": [
    "creature_title",
    "min",
    "max"
  ],
  "title": "ItemDrop",
  "type": "object"
}

Fields:

creature_id pydantic-field
creature_id: int | None = None

The article id of the creature.

creature_title pydantic-field
creature_title: str

The title of the creature that drops the item.

min pydantic-field
min: int

The minimum possible amount of the dropped item.

max pydantic-field
max: int

The maximum possible amount of the dropped item.

chance pydantic-field
chance: float | None = None

The chance percentage of getting this item dropped by this creature.

ItemQuestReward pydantic-model

Bases: BaseModel

A quest where the item is awarded.

Show JSON schema:
{
  "description": "A quest where the item is awarded.",
  "properties": {
    "quest_id": {
      "title": "Quest Id",
      "type": "integer"
    },
    "quest_title": {
      "title": "Quest Title",
      "type": "string"
    }
  },
  "required": [
    "quest_id",
    "quest_title"
  ],
  "title": "ItemQuestReward",
  "type": "object"
}

Fields:

quest_id pydantic-field
quest_id: int

The article ID of the quest.

quest_title pydantic-field
quest_title: str

The title of the quest.

Item pydantic-model

Bases: WikiEntry, WithVersion, WithStatus, WithImage, RowModel

Represents an Item.

Show JSON schema:
{
  "$defs": {
    "ItemAttribute": {
      "description": "Represents an Item's attribute.",
      "properties": {
        "name": {
          "title": "Name",
          "type": "string"
        },
        "value": {
          "title": "Value",
          "type": "string"
        }
      },
      "required": [
        "name",
        "value"
      ],
      "title": "ItemAttribute",
      "type": "object"
    },
    "ItemDrop": {
      "description": "Represents a creature that drops the item.",
      "properties": {
        "creature_id": {
          "anyOf": [
            {
              "type": "integer"
            },
            {
              "type": "null"
            }
          ],
          "default": null,
          "title": "Creature Id"
        },
        "creature_title": {
          "title": "Creature Title",
          "type": "string"
        },
        "min": {
          "title": "Min",
          "type": "integer"
        },
        "max": {
          "title": "Max",
          "type": "integer"
        },
        "chance": {
          "anyOf": [
            {
              "type": "number"
            },
            {
              "type": "null"
            }
          ],
          "default": null,
          "title": "Chance"
        }
      },
      "required": [
        "creature_title",
        "min",
        "max"
      ],
      "title": "ItemDrop",
      "type": "object"
    },
    "ItemOffer": {
      "description": "Represents an offer to buy or sell the item.",
      "properties": {
        "npc_id": {
          "title": "Npc Id",
          "type": "integer"
        },
        "npc_title": {
          "title": "Npc Title",
          "type": "string"
        },
        "currency_id": {
          "title": "Currency Id",
          "type": "integer"
        },
        "currency_title": {
          "title": "Currency Title",
          "type": "string"
        },
        "value": {
          "title": "Value",
          "type": "integer"
        }
      },
      "required": [
        "npc_id",
        "npc_title",
        "currency_id",
        "currency_title",
        "value"
      ],
      "title": "ItemOffer",
      "type": "object"
    },
    "ItemQuestReward": {
      "description": "A quest where the item is awarded.",
      "properties": {
        "quest_id": {
          "title": "Quest Id",
          "type": "integer"
        },
        "quest_title": {
          "title": "Quest Title",
          "type": "string"
        }
      },
      "required": [
        "quest_id",
        "quest_title"
      ],
      "title": "ItemQuestReward",
      "type": "object"
    },
    "ItemStoreOffer": {
      "description": "Represents an offer for an item on the Tibia Store.",
      "properties": {
        "price": {
          "title": "Price",
          "type": "integer"
        },
        "amount": {
          "title": "Amount",
          "type": "integer"
        },
        "currency": {
          "title": "Currency",
          "type": "string"
        }
      },
      "required": [
        "price",
        "amount",
        "currency"
      ],
      "title": "ItemStoreOffer",
      "type": "object"
    }
  },
  "description": "Represents an Item.",
  "properties": {
    "image": {
      "anyOf": [
        {
          "format": "binary",
          "type": "string"
        },
        {
          "type": "null"
        }
      ],
      "default": null,
      "title": "Image"
    },
    "status": {
      "title": "Status",
      "type": "string"
    },
    "version": {
      "anyOf": [
        {
          "type": "string"
        },
        {
          "type": "null"
        }
      ],
      "title": "Version"
    },
    "article_id": {
      "title": "Article Id",
      "type": "integer"
    },
    "title": {
      "title": "Title",
      "type": "string"
    },
    "timestamp": {
      "format": "date-time",
      "title": "Timestamp",
      "type": "string"
    },
    "name": {
      "title": "Name",
      "type": "string"
    },
    "actual_name": {
      "anyOf": [
        {
          "type": "string"
        },
        {
          "type": "null"
        }
      ],
      "title": "Actual Name"
    },
    "plural": {
      "anyOf": [
        {
          "type": "string"
        },
        {
          "type": "null"
        }
      ],
      "title": "Plural"
    },
    "article": {
      "anyOf": [
        {
          "type": "string"
        },
        {
          "type": "null"
        }
      ],
      "title": "Article"
    },
    "is_marketable": {
      "title": "Is Marketable",
      "type": "boolean"
    },
    "is_stackable": {
      "title": "Is Stackable",
      "type": "boolean"
    },
    "is_pickupable": {
      "title": "Is Pickupable",
      "type": "boolean"
    },
    "is_immobile": {
      "title": "Is Immobile",
      "type": "boolean"
    },
    "value_sell": {
      "anyOf": [
        {
          "type": "integer"
        },
        {
          "type": "null"
        }
      ],
      "title": "Value Sell"
    },
    "value_buy": {
      "anyOf": [
        {
          "type": "integer"
        },
        {
          "type": "null"
        }
      ],
      "title": "Value Buy"
    },
    "weight": {
      "anyOf": [
        {
          "type": "number"
        },
        {
          "type": "null"
        }
      ],
      "title": "Weight"
    },
    "item_class": {
      "anyOf": [
        {
          "type": "string"
        },
        {
          "type": "null"
        }
      ],
      "title": "Item Class"
    },
    "item_type": {
      "anyOf": [
        {
          "type": "string"
        },
        {
          "type": "null"
        }
      ],
      "title": "Item Type"
    },
    "type_secondary": {
      "anyOf": [
        {
          "type": "string"
        },
        {
          "type": "null"
        }
      ],
      "title": "Type Secondary"
    },
    "flavor_text": {
      "anyOf": [
        {
          "type": "string"
        },
        {
          "type": "null"
        }
      ],
      "title": "Flavor Text"
    },
    "light_color": {
      "anyOf": [
        {
          "type": "integer"
        },
        {
          "type": "null"
        }
      ],
      "default": null,
      "title": "Light Color"
    },
    "light_radius": {
      "anyOf": [
        {
          "type": "integer"
        },
        {
          "type": "null"
        }
      ],
      "title": "Light Radius"
    },
    "client_id": {
      "anyOf": [
        {
          "type": "integer"
        },
        {
          "type": "null"
        }
      ],
      "title": "Client Id"
    },
    "attributes": {
      "items": {
        "$ref": "#/$defs/ItemAttribute"
      },
      "title": "Attributes",
      "type": "array"
    },
    "dropped_by": {
      "items": {
        "$ref": "#/$defs/ItemDrop"
      },
      "title": "Dropped By",
      "type": "array"
    },
    "sold_by": {
      "items": {
        "$ref": "#/$defs/ItemOffer"
      },
      "title": "Sold By",
      "type": "array"
    },
    "bought_by": {
      "items": {
        "$ref": "#/$defs/ItemOffer"
      },
      "title": "Bought By",
      "type": "array"
    },
    "awarded_in": {
      "items": {
        "$ref": "#/$defs/ItemQuestReward"
      },
      "title": "Awarded In",
      "type": "array"
    },
    "sounds": {
      "items": {
        "type": "string"
      },
      "title": "Sounds",
      "type": "array"
    },
    "store_offers": {
      "items": {
        "$ref": "#/$defs/ItemStoreOffer"
      },
      "title": "Store Offers",
      "type": "array"
    }
  },
  "required": [
    "status",
    "version",
    "article_id",
    "title",
    "timestamp",
    "name",
    "actual_name",
    "plural",
    "article",
    "is_marketable",
    "is_stackable",
    "is_pickupable",
    "is_immobile",
    "value_sell",
    "value_buy",
    "weight",
    "item_class",
    "item_type",
    "type_secondary",
    "flavor_text",
    "light_radius",
    "client_id"
  ],
  "title": "Item",
  "type": "object"
}

Fields:

name pydantic-field
name: str

The in-game name of the item.

actual_name pydantic-field
actual_name: str | None

The name of the item as it appears in game when looked at.

plural pydantic-field
plural: str | None

The plural of the name.

article pydantic-field
article: str | None

The article that goes before the name when looking at the item.

is_marketable pydantic-field
is_marketable: bool

Whether the item can be traded on the Market or not.

is_stackable pydantic-field
is_stackable: bool

Whether the item can be stacked or not.

is_pickupable pydantic-field
is_pickupable: bool

Whether the item can be picked up or not.

is_immobile pydantic-field
is_immobile: bool

Whether the item can be moved around the map or not.

value_sell pydantic-field
value_sell: int | None

The highest price an NPC will buy this item for.

value_buy pydantic-field
value_buy: int | None

The lowest price an NPC will sell this item for.

weight pydantic-field
weight: float | None

The item's weight in ounces.

item_class pydantic-field
item_class: str | None

The item class the item belongs to.

item_type pydantic-field
item_type: str | None

The item's type.

type_secondary pydantic-field
type_secondary: str | None

The item's secondary type, if any.

flavor_text pydantic-field
flavor_text: str | None

The extra text that is displayed when some items are looked at.

light_color pydantic-field
light_color: int | None = None

The color of the light emitted by this item in RGB, if any.

light_radius pydantic-field
light_radius: int | None

The radius of the light emitted by this item, if any.

client_id pydantic-field
client_id: int | None

The internal id of the item in the client.

attributes pydantic-field
attributes: list[ItemAttribute]

The item's attributes.

dropped_by pydantic-field
dropped_by: list[ItemDrop]

List of creatures that drop this item, with the chances.

sold_by pydantic-field
sold_by: list[ItemOffer]

List of NPCs that sell this item.

bought_by pydantic-field
bought_by: list[ItemOffer]

List of NPCs that buy this item.

awarded_in pydantic-field
awarded_in: list[ItemQuestReward]

List of quests that give this item as reward.

sounds pydantic-field
sounds: list[str]

List of sounds made when using the item.

attributes_dict property
attributes_dict: dict[str, str]

A mapping of the attributes this item has.

resistances property
resistances: dict[str, int]

A mapping of the elemental resistances of this item.

look_text property
look_text: str

The item's look text.

insert
insert(conn: Connection | Cursor) -> None

Insert the model into its respective database table.

Parameters:

Name Type Description Default
conn Connection | Cursor

A cursor or connection to the database.

required
Source code in tibiawikisql/models/item.py
def insert(self, conn: Connection | Cursor) -> None:
    super().insert(conn)
    for attribute in self.attributes:
        ItemAttributeTable.insert(conn, item_id=self.article_id, **attribute.model_dump())
    for sound in self.sounds:
        ItemSoundTable.insert(conn, item_id=self.article_id, content=sound)
    for offer in self.store_offers:
        ItemStoreOfferTable.insert(conn, item_id=self.article_id, **offer.model_dump())
get_one_by_field classmethod
get_one_by_field(
    conn: Connection | Cursor,
    field: str,
    value: Any,
    use_like: bool = False,
) -> Self | None

Get a single element matching the field's value.

Parameters:

Name Type Description Default
conn Connection | Cursor

A connection or cursor of the database.

required
field str

The field to filter with.

required
value Any

The value to look for.

required
use_like bool

Whether to use LIKE as a comparator instead of =.

False

Returns:

Type Description
Self | None

The object found, or None if no entries match.

Raises:

Type Description
ValueError

The specified field doesn't exist in the table.

Source code in tibiawikisql/models/item.py
@classmethod
def get_one_by_field(cls, conn: Connection | Cursor, field: str, value: Any, use_like: bool = False) -> Self | None:
    item: Self = super().get_one_by_field(conn, field, value, use_like)
    if not item:
        return None
    attributes = ItemAttributeTable.get_list_by_field(conn, "item_id", item.article_id)
    item.attributes = [ItemAttribute(**(dict(row))) for row in attributes]

    dropped_by = CreatureDropTable.get_by_item_id(conn, item.article_id)
    item.dropped_by = [ItemDrop(**dict(r)) for r in dropped_by]

    store_offers = ItemStoreOfferTable.get_list_by_field(conn, "item_id", item.article_id)
    item.store_offers = [ItemStoreOffer(**dict(r)) for r in store_offers]

    sounds = ItemSoundTable.get_list_by_field(conn, "item_id", item.article_id)
    item.sounds = [r["content"] for r in sounds]

    item.bought_by = [
        ItemOffer(
            npc_id=r["npc_id"],
            npc_title=r["npc_title"],
            currency_id=r["currency_id"],
            currency_title=r["currency_title"],
            value=r["value"],
        ) for r in NpcBuyingTable.get_by_item_id(conn, item.article_id)
    ]
    item.sold_by = [
        ItemOffer(
            npc_id=r["npc_id"],
            npc_title=r["npc_title"],
            currency_id=r["currency_id"],
            currency_title=r["currency_title"],
            value=r["value"],
        ) for r in NpcSellingTable.get_by_item_id(conn, item.article_id)
    ]

    awarded_in = QuestRewardTable.get_list_by_item_id(conn, item.article_id)
    item.awarded_in = [ItemQuestReward(**(dict(row))) for row in awarded_in]
    return item

Book pydantic-model

Bases: WikiEntry, WithStatus, WithVersion, RowModel

Represents a book or written document in Tibia.

Show JSON schema:
{
  "description": "Represents a book or written document in Tibia.",
  "properties": {
    "version": {
      "anyOf": [
        {
          "type": "string"
        },
        {
          "type": "null"
        }
      ],
      "title": "Version"
    },
    "status": {
      "title": "Status",
      "type": "string"
    },
    "article_id": {
      "title": "Article Id",
      "type": "integer"
    },
    "title": {
      "title": "Title",
      "type": "string"
    },
    "timestamp": {
      "format": "date-time",
      "title": "Timestamp",
      "type": "string"
    },
    "name": {
      "title": "Name",
      "type": "string"
    },
    "book_type": {
      "title": "Book Type",
      "type": "string"
    },
    "item_id": {
      "anyOf": [
        {
          "type": "integer"
        },
        {
          "type": "null"
        }
      ],
      "default": null,
      "title": "Item Id"
    },
    "location": {
      "anyOf": [
        {
          "type": "string"
        },
        {
          "type": "null"
        }
      ],
      "title": "Location"
    },
    "blurb": {
      "anyOf": [
        {
          "type": "string"
        },
        {
          "type": "null"
        }
      ],
      "title": "Blurb"
    },
    "author": {
      "anyOf": [
        {
          "type": "string"
        },
        {
          "type": "null"
        }
      ],
      "title": "Author"
    },
    "prev_book": {
      "anyOf": [
        {
          "type": "string"
        },
        {
          "type": "null"
        }
      ],
      "title": "Prev Book"
    },
    "next_book": {
      "anyOf": [
        {
          "type": "string"
        },
        {
          "type": "null"
        }
      ],
      "title": "Next Book"
    },
    "text": {
      "title": "Text",
      "type": "string"
    }
  },
  "required": [
    "version",
    "status",
    "article_id",
    "title",
    "timestamp",
    "name",
    "book_type",
    "location",
    "blurb",
    "author",
    "prev_book",
    "next_book",
    "text"
  ],
  "title": "Book",
  "type": "object"
}

Fields:

name pydantic-field
name: str

The name of the book.

book_type pydantic-field
book_type: str

The type of item this book can be found in.

item_id pydantic-field
item_id: int | None = None

The ID of the item this book is written in.

location pydantic-field
location: str | None

Where the book can be found.

blurb pydantic-field
blurb: str | None

A short introduction text of the book.

author pydantic-field
author: str | None

The person that wrote the book, if known.

prev_book pydantic-field
prev_book: str | None

If the book is part of a series, the book that precedes this one.

next_book pydantic-field
next_book: str | None

If the book is part of a series, the book that follows this one.

text pydantic-field
text: str

The content of the book.

insert
insert(conn: Connection | Cursor) -> None

Insert the model into its respective database table.

Parameters:

Name Type Description Default
conn Connection | Cursor

A cursor or connection to the database.

required
Source code in tibiawikisql/models/item.py
def insert(self, conn: Connection | Cursor) -> None:
    if self.item_id is not None:
        super().insert(conn)
        return

    book_table = self.table.__table__
    item_table = ItemTable.__table__

    q = (
        Query.into(book_table)
        .columns(
            "article_id",
            "title",
            "name",
            "book_type",
            "item_id",
            "location",
            "blurb",
            "author",
            "prev_book",
            "next_book",
            "text",
            "version",
            "status",
            "timestamp",
        )
        .insert(
            Parameter(":article_id"),
            Parameter(":title"),
            Parameter(":name"),
            Parameter(":book_type"),
            (
                Query.from_(item_table)
                .select(item_table.article_id)
                .where(item_table.title == Parameter(":book_type"))
            ),
            Parameter(":location"),
            Parameter(":blurb"),
            Parameter(":author"),
            Parameter(":prev_book"),
            Parameter(":next_book"),
            Parameter(":text"),
            Parameter(":version"),
            Parameter(":status"),
            Parameter(":timestamp"),
        )
    )

    query_str = q.get_sql()
    conn.execute(query_str, self.model_dump(mode="json"))

Key pydantic-model

Bases: WikiEntry, WithStatus, WithVersion, RowModel

Represents a key item.

Show JSON schema:
{
  "description": "Represents a key item.",
  "properties": {
    "version": {
      "anyOf": [
        {
          "type": "string"
        },
        {
          "type": "null"
        }
      ],
      "title": "Version"
    },
    "status": {
      "title": "Status",
      "type": "string"
    },
    "article_id": {
      "title": "Article Id",
      "type": "integer"
    },
    "title": {
      "title": "Title",
      "type": "string"
    },
    "timestamp": {
      "format": "date-time",
      "title": "Timestamp",
      "type": "string"
    },
    "name": {
      "anyOf": [
        {
          "type": "string"
        },
        {
          "type": "null"
        }
      ],
      "default": null,
      "title": "Name"
    },
    "number": {
      "title": "Number",
      "type": "integer"
    },
    "item_id": {
      "anyOf": [
        {
          "type": "integer"
        },
        {
          "type": "null"
        }
      ],
      "default": null,
      "title": "Item Id"
    },
    "material": {
      "title": "Material",
      "type": "string"
    },
    "location": {
      "anyOf": [
        {
          "type": "string"
        },
        {
          "type": "null"
        }
      ],
      "title": "Location"
    },
    "notes": {
      "anyOf": [
        {
          "type": "string"
        },
        {
          "type": "null"
        }
      ],
      "title": "Notes"
    },
    "origin": {
      "anyOf": [
        {
          "type": "string"
        },
        {
          "type": "null"
        }
      ],
      "title": "Origin"
    }
  },
  "required": [
    "version",
    "status",
    "article_id",
    "title",
    "timestamp",
    "number",
    "material",
    "location",
    "notes",
    "origin"
  ],
  "title": "Key",
  "type": "object"
}

Fields:

name pydantic-field
name: str | None = None

The name of the creature, as displayed in-game.

number pydantic-field
number: int

The key's number.

item_id pydantic-field
item_id: int | None = None

The article id of the item this key is based on.

material pydantic-field
material: str

The key's material.

location pydantic-field
location: str | None

The key's location.

notes pydantic-field
notes: str | None

Notes about the key.

origin pydantic-field
origin: str | None

Notes about the origin of the key.

insert
insert(conn: Connection | Cursor) -> None

Insert the model into its respective database table.

Parameters:

Name Type Description Default
conn Connection | Cursor

A cursor or connection to the database.

required
Source code in tibiawikisql/models/item.py
def insert(self, conn: Connection | Cursor) -> None:
    if self.item_id is not None:
        super().insert(conn)
        return

    key_table = Table(self.table.__tablename__)
    item_table = Table(ItemTable.__tablename__)

    q = (
        Query.into(key_table)
        .columns(
            "article_id",
            "title",
            "name",
            "number",
            "item_id",
            "material",
            "location",
            "notes",
            "origin",
            "version",
            "status",
            "timestamp",
        )
        .insert(
            Parameter(":article_id"),
            Parameter(":title"),
            Parameter(":name"),
            Parameter(":number"),
            (
                Query.from_(item_table)
                .select(item_table.article_id)
                .where(item_table.title == LiteralValue(":material || ' Key'"))
            ),
            Parameter(":material"),
            Parameter(":location"),
            Parameter(":notes"),
            Parameter(":origin"),
            Parameter(":version"),
            Parameter(":status"),
            Parameter(":timestamp"),
        )
    )

    query_str = q.get_sql()
    conn.execute(query_str, self.model_dump(mode="json"))