Skip to main content

A lightweight Python library for building dynamic game economies with shared item values, local inventories, and adaptive pricing.

Project description

DyEcon

A lightweight Python library for building dynamic game economies with shared item values, local inventories, and adaptive pricing.

Concepts

DyEcon is built around two classes:

Economy

Stores the global base values for items.

economy = Economy({
	wood: 5,
	ore: 10,
})

SubEconomy

Stores local inventory quantities and price modifiers.

town = SubEconomy(economy)
merchant = SubEconomy(economy)

Each SubEconomy can have different quantities and prices for the same items.


Quick Start

from dyecon import Economy, SubEconomy

wood = "Wood"
ore = "Ore"

economy = Economy({
	wood: 5,
	ore: 10,
})

town = SubEconomy(economy)

town.add_item(wood, 50)
town.add_item(ore, 10)

town.change_modifier(wood, -20)
town.change_modifier(ore, 50)

print(town.get_quantity(wood))
print(town.get_value(wood))

print(town.get_quantity(ore))
print(town.get_value(ore))

Output:

50
4

10
15

Economy

Create an Economy

economy = Economy()

Create an Economy with Items

economy = Economy({
	wood: 5,
	ore: 10,
})

Set Base Value

economy.set_base_value(wood, 5)

Get Base Value

economy.get_base_value(wood)

Get Modified Value

economy.get_value(wood, modifier=25)

SubEconomy

Create a SubEconomy

town = SubEconomy(economy)

Set Quantity

town.set_quantity(wood, 100)

Get Quantity

town.get_quantity(wood)

Add Items

town.add_item(wood, 10)

Remove Items

town.remove_item(wood, 5)

Returns:

True

or

False

if insufficient quantity exists.

Check Inventory

town.has_item(wood, 10)

Returns:

True

or

False

Set Modifier

town.set_modifier(wood, 25)

Change Modifier

town.change_modifier(wood, -5)

Get Modifier

town.get_modifier(wood)

Get Item Value

town.get_value(wood)

This automatically applies the local modifier to the item's global base value.

Iterate Through Inventory

for item, quantity in town.get_items():
	print(item, quantity)

Example: Town Economy

from dyecon import Economy, SubEconomy

wood = "Wood"
ore = "Ore"

economy = Economy({
	wood: 5,
	ore: 10,
})

town = SubEconomy(economy)

town.add_item(wood, 100)
town.add_item(ore, 2)

town.change_modifier(wood, -20)
town.change_modifier(ore, 50)

print(f"Wood Price: {town.get_value(wood)}")
print(f"Ore Price: {town.get_value(ore)}")

Output:

Wood Price: 4
Ore Price: 15

Use Cases

DyEcon can be used for:

  • Town economies
  • Shops
  • Traveling merchants
  • Guild inventories
  • Trading systems
  • Resource management games
  • RPG economies
  • Simulation games

License

MIT License

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

dyecon-0.1.0.tar.gz (3.8 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

dyecon-0.1.0-py3-none-any.whl (3.8 kB view details)

Uploaded Python 3

File details

Details for the file dyecon-0.1.0.tar.gz.

File metadata

  • Download URL: dyecon-0.1.0.tar.gz
  • Upload date:
  • Size: 3.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.12.7

File hashes

Hashes for dyecon-0.1.0.tar.gz
Algorithm Hash digest
SHA256 3506407aa02b80f424f5be270ecba6efb6606fb11d3fb86634e47e8d5e485feb
MD5 dbf0f32cdae8ec923a69a5e7d64c48a3
BLAKE2b-256 d430e8034816ca5c013e694cc12eb61f0086bcd1205f8103c8457a06b55bb854

See more details on using hashes here.

File details

Details for the file dyecon-0.1.0-py3-none-any.whl.

File metadata

  • Download URL: dyecon-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 3.8 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.12.7

File hashes

Hashes for dyecon-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 b9af1ca1dda1bc9eb36fc47b6e0a5988997e256507f5d40eb598091ad248387b
MD5 a47784a85d209b156b7b781345b1317a
BLAKE2b-256 9eb89d8587e485d2b218d696f2a0337fc420f1cd5b5554952b7c98b8f46b6236

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page