Skip to content

Npc

tibiawikisql.models.npc

Classes:

Name Description
NpcOffer

Represents an NPC buy or sell offer.

NpcDestination

Represents a NPC's travel destination.

RashidPosition

Represents a Rashid position.

Npc

Represents a non-playable character.

NpcOffer pydantic-model

Bases: BaseModel

Represents an NPC buy or sell offer.

Show JSON schema:
{
  "description": "Represents an NPC buy or sell offer.",
  "properties": {
    "item_id": {
      "title": "Item Id",
      "type": "integer"
    },
    "item_title": {
      "title": "Item Title",
      "type": "string"
    },
    "currency_id": {
      "title": "Currency Id",
      "type": "integer"
    },
    "currency_title": {
      "title": "Currency Title",
      "type": "string"
    },
    "value": {
      "title": "Value",
      "type": "integer"
    }
  },
  "required": [
    "item_id",
    "item_title",
    "currency_id",
    "currency_title",
    "value"
  ],
  "title": "NpcOffer",
  "type": "object"
}

Fields:

item_id pydantic-field
item_id: int

The article ID of the item being offered.

item_title pydantic-field
item_title: str

The title of the item being offered.

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 being offered.

NpcDestination pydantic-model

Bases: BaseModel

Represents a NPC's travel destination.

Show JSON schema:
{
  "description": "Represents a NPC's travel destination.",
  "properties": {
    "name": {
      "title": "Name",
      "type": "string"
    },
    "price": {
      "title": "Price",
      "type": "integer"
    },
    "notes": {
      "anyOf": [
        {
          "type": "string"
        },
        {
          "type": "null"
        }
      ],
      "title": "Notes"
    }
  },
  "required": [
    "name",
    "price",
    "notes"
  ],
  "title": "NpcDestination",
  "type": "object"
}

Fields:

name pydantic-field
name: str

The name of the destination

price pydantic-field
price: int

The price in gold to travel.

notes pydantic-field
notes: str | None

Notes about the destination, such as requirements.

RashidPosition pydantic-model

Bases: BaseModel

Represents a Rashid position.

Show JSON schema:
{
  "description": "Represents a Rashid position.",
  "properties": {
    "day": {
      "title": "Day",
      "type": "integer"
    },
    "x": {
      "title": "X",
      "type": "integer"
    },
    "y": {
      "title": "Y",
      "type": "integer"
    },
    "z": {
      "title": "Z",
      "type": "integer"
    },
    "city": {
      "title": "City",
      "type": "string"
    },
    "location": {
      "title": "Location",
      "type": "string"
    }
  },
  "required": [
    "day",
    "x",
    "y",
    "z",
    "city",
    "location"
  ],
  "title": "RashidPosition",
  "type": "object"
}

Fields:

day pydantic-field
day: int

Day of the week, Monday starts at 0.

x pydantic-field
x: int

The x coordinate of Rashid that day.

y pydantic-field
y: int

The y coordinate of Rashid that day.

z pydantic-field
z: int

The z coordinate of Rashid that day.

city pydantic-field
city: str

The city where Rashid is that day.

location pydantic-field
location: str

The location where Rashid is that day.

Npc pydantic-model

Bases: WikiEntry, WithVersion, WithStatus, WithImage, RowModel

Represents a non-playable character.

Show JSON schema:
{
  "$defs": {
    "NpcDestination": {
      "description": "Represents a NPC's travel destination.",
      "properties": {
        "name": {
          "title": "Name",
          "type": "string"
        },
        "price": {
          "title": "Price",
          "type": "integer"
        },
        "notes": {
          "anyOf": [
            {
              "type": "string"
            },
            {
              "type": "null"
            }
          ],
          "title": "Notes"
        }
      },
      "required": [
        "name",
        "price",
        "notes"
      ],
      "title": "NpcDestination",
      "type": "object"
    },
    "NpcOffer": {
      "description": "Represents an NPC buy or sell offer.",
      "properties": {
        "item_id": {
          "title": "Item Id",
          "type": "integer"
        },
        "item_title": {
          "title": "Item Title",
          "type": "string"
        },
        "currency_id": {
          "title": "Currency Id",
          "type": "integer"
        },
        "currency_title": {
          "title": "Currency Title",
          "type": "string"
        },
        "value": {
          "title": "Value",
          "type": "integer"
        }
      },
      "required": [
        "item_id",
        "item_title",
        "currency_id",
        "currency_title",
        "value"
      ],
      "title": "NpcOffer",
      "type": "object"
    }
  },
  "description": "Represents a non-playable character.",
  "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"
    },
    "gender": {
      "anyOf": [
        {
          "type": "string"
        },
        {
          "type": "null"
        }
      ],
      "title": "Gender"
    },
    "races": {
      "items": {
        "type": "string"
      },
      "title": "Races",
      "type": "array"
    },
    "jobs": {
      "items": {
        "type": "string"
      },
      "title": "Jobs",
      "type": "array"
    },
    "location": {
      "anyOf": [
        {
          "type": "string"
        },
        {
          "type": "null"
        }
      ],
      "title": "Location"
    },
    "subarea": {
      "anyOf": [
        {
          "type": "string"
        },
        {
          "type": "null"
        }
      ],
      "title": "Subarea"
    },
    "city": {
      "title": "City",
      "type": "string"
    },
    "x": {
      "anyOf": [
        {
          "type": "integer"
        },
        {
          "type": "null"
        }
      ],
      "title": "X"
    },
    "y": {
      "anyOf": [
        {
          "type": "integer"
        },
        {
          "type": "null"
        }
      ],
      "title": "Y"
    },
    "z": {
      "anyOf": [
        {
          "type": "integer"
        },
        {
          "type": "null"
        }
      ],
      "title": "Z"
    },
    "sell_offers": {
      "items": {
        "$ref": "#/$defs/NpcOffer"
      },
      "title": "Sell Offers",
      "type": "array"
    },
    "buy_offers": {
      "items": {
        "$ref": "#/$defs/NpcOffer"
      },
      "title": "Buy Offers",
      "type": "array"
    },
    "destinations": {
      "items": {
        "$ref": "#/$defs/NpcDestination"
      },
      "title": "Destinations",
      "type": "array"
    }
  },
  "required": [
    "status",
    "version",
    "article_id",
    "title",
    "timestamp",
    "name",
    "gender",
    "location",
    "subarea",
    "city",
    "x",
    "y",
    "z"
  ],
  "title": "Npc",
  "type": "object"
}

Fields:

name pydantic-field
name: str

The in-game name of the NPC.

gender pydantic-field
gender: str | None

The gender of the NPC.

races pydantic-field
races: list[str]

The races of the NPC.

jobs pydantic-field
jobs: list[str]

The jobs of the NPC.

location pydantic-field
location: str | None

The location of the NPC.

subarea pydantic-field
subarea: str | None

A finer location of the NPC.

city pydantic-field
city: str

The nearest city to where the NPC is located.

x pydantic-field
x: int | None

The x coordinates of the NPC.

y pydantic-field
y: int | None

The y coordinates of the NPC.

z pydantic-field
z: int | None

The z coordinates of the NPC.

sell_offers pydantic-field
sell_offers: list[NpcOffer]

Items sold by the NPC.

buy_offers pydantic-field
buy_offers: list[NpcOffer]

Items bought by the NPC.

destinations pydantic-field
destinations: list[NpcDestination]

Places where the NPC can travel to.

job property
job: str | None

Get the first listed job of the NPC, if any.

race property
race: str | None

Get the first listed race of the NPC, if any.

insert
insert(conn: Connection | Cursor)

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/npc.py
def insert(self, conn: sqlite3.Connection | sqlite3.Cursor):
    super().insert(conn)
    for destination in self.destinations:
        NpcDestinationTable.insert(
            conn,
            npc_id=self.article_id,
            name=destination.name,
            price=destination.price,
            notes=destination.notes,
        )
    for job in self.jobs:
        NpcJobTable.insert(conn, npc_id=self.article_id, name=job)
    for race in self.races:
        NpcRaceTable.insert(conn, npc_id=self.article_id, name=race)
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/npc.py
@classmethod
def get_one_by_field(cls, conn: Connection | Cursor, field: str, value: Any, use_like: bool = False) -> Self | None:
    npc: Self = super().get_one_by_field(conn, field, value, use_like)
    if npc is None:
        return None
    npc.jobs = [j["name"] for j in NpcJobTable.get_list_by_field(conn, "npc_id", npc.article_id)]
    npc.races = [j["name"] for j in NpcRaceTable.get_list_by_field(conn, "npc_id", npc.article_id)]
    npc.sell_offers = [
        NpcOffer(
            item_id=r["item_id"],
            item_title=r["item_title"],
            currency_id=r["currency_id"],
            currency_title=r["currency_title"],
            value=r["value"],
        ) for r in NpcBuyingTable.get_by_npc_id(conn, npc.article_id)
    ]
    npc.buy_offers = [
        NpcOffer(
            item_id=r["item_id"],
            item_title=r["item_title"],
            currency_id=r["currency_id"],
            currency_title=r["currency_title"],
            value=r["value"],
        ) for r in NpcSellingTable.get_by_npc_id(conn, npc.article_id)
    ]
    npc.destinations = [
        NpcDestination.model_validate(dict(r))
        for r in NpcDestinationTable.get_list_by_field(conn, "npc_id", npc.article_id)
    ]
    return npc