From d563c5e1da43620d7abc18ef0726fb69baebf0f0 Mon Sep 17 00:00:00 2001 From: Starknet Dev Date: Fri, 24 May 2024 00:03:14 +0100 Subject: [PATCH 01/18] working pragma version (no persistent data) --- .gitignore | 2 +- indexer/env-sepolia | 4 +- indexer/graphql/Dockerfile.sepolia | 2 +- indexer/graphql/src/indexer/graphql.py | 4 + indexer/sepolia-compose.yaml | 12 +- indexer/src/adventurers.ts | 1 + indexer/src/utils/events.ts | 3 +- indexer/src/utils/helpers.ts | 3 + ui/src/app/abi/Game.json | 883 +++++++++++------- ui/src/app/api/checkEntropy.ts | 34 + ui/src/app/api/getItems.ts | 34 + ui/src/app/components/CountDown.tsx | 64 -- .../components/actions/DiscoveryDisplay.tsx | 10 - ui/src/app/components/beast/BattleDisplay.tsx | 19 - ui/src/app/components/intro/ArcadeIntro.tsx | 350 ------- ui/src/app/components/leaderboard/LiveRow.tsx | 4 - .../app/components/leaderboard/LiveTable.tsx | 6 - ui/src/app/components/navigation/Header.tsx | 22 - .../notifications/NotificationHandler.tsx | 28 +- ui/src/app/components/start/Spawn.tsx | 47 +- ui/src/app/containers/ActionsScreen.tsx | 1 + ui/src/app/containers/BeastScreen.tsx | 55 +- ui/src/app/containers/InterludeScreen.tsx | 91 +- ui/src/app/containers/LeaderboardScreen.tsx | 76 +- ui/src/app/containers/UpgradeScreen.tsx | 64 +- ui/src/app/hooks/useUIStore.ts | 12 +- ui/src/app/lib/burner.ts | 17 +- ui/src/app/lib/constants.ts | 3 +- ui/src/app/lib/data/GameData.tsx | 3 - ui/src/app/lib/utils/parseEvents.ts | 389 ++++---- ui/src/app/lib/utils/processData.ts | 62 +- ui/src/app/lib/utils/syscalls.ts | 230 +---- ui/src/app/page.tsx | 9 +- ui/src/app/types/events.ts | 8 +- ui/src/app/types/index.ts | 1 + 35 files changed, 992 insertions(+), 1561 deletions(-) create mode 100644 ui/src/app/api/checkEntropy.ts create mode 100644 ui/src/app/api/getItems.ts delete mode 100644 ui/src/app/components/intro/ArcadeIntro.tsx diff --git a/.gitignore b/.gitignore index 8e9ca9850..c758e9bb5 100644 --- a/.gitignore +++ b/.gitignore @@ -12,7 +12,7 @@ contracts/beasts/target/CACHEDIR.TAG keys account -loot-survivor.pem +ls1.5.pem contracts/game_entropy/target/CACHEDIR.TAG contracts/game_entropy/target/dev/game_entropy.sierra diff --git a/indexer/env-sepolia b/indexer/env-sepolia index 9a2f23753..b08e55389 100644 --- a/indexer/env-sepolia +++ b/indexer/env-sepolia @@ -1,5 +1,5 @@ -GAME="0x02b66531874c952844913b8cbc573878c794112b546cbf39409013e33d4777fe" -START=60000 +GAME="0x06c63851635f1e0ee0695a157292892cabaa030a8eca20a32b6a86c968c47c33" +START=68300 MONGO_CONNECTION_STRING="mongodb://mongo:mongo@mongo:27017" MONGO_DB="mongo" STREAM_URL='https://sepolia.starknet.a5a.ch' \ No newline at end of file diff --git a/indexer/graphql/Dockerfile.sepolia b/indexer/graphql/Dockerfile.sepolia index 344e9fb3a..eb760de58 100644 --- a/indexer/graphql/Dockerfile.sepolia +++ b/indexer/graphql/Dockerfile.sepolia @@ -11,4 +11,4 @@ RUN python3 -m pip install pycryptodome RUN poetry config virtualenvs.create false RUN poetry install -ENTRYPOINT [ "indexer", "graphql", "--mongo", "mongodb://${MONGO_USERNAME}:${MONGO_PASSWORD}@54.74.126.103:27017", "--port", "8080" ] +ENTRYPOINT [ "indexer", "graphql", "--mongo", "mongodb://${MONGO_USERNAME}:${MONGO_PASSWORD}@54.157.59.41:27017", "--port", "8080" ] diff --git a/indexer/graphql/src/indexer/graphql.py b/indexer/graphql/src/indexer/graphql.py index bb40d8a4f..124b453ef 100644 --- a/indexer/graphql/src/indexer/graphql.py +++ b/indexer/graphql/src/indexer/graphql.py @@ -653,6 +653,7 @@ class OrderByInput: @strawberry.input class AdventurersFilter: id: Optional[FeltValueFilter] = None + entropy: Optional[HexValueFilter] = None lastAction: Optional[FeltValueFilter] = None owner: Optional[HexValueFilter] = None name: Optional[StringFilter] = None @@ -778,6 +779,7 @@ class ItemsFilter: @strawberry.input class AdventurersOrderByInput: id: Optional[OrderByInput] = None + entropy: Optional[OrderByInput] = None lastAction: Optional[OrderByInput] = None owner: Optional[OrderByInput] = None name: Optional[OrderByInput] = None @@ -905,6 +907,7 @@ class ItemsOrderByInput: @strawberry.type class Adventurer: id: Optional[FeltValue] + entropy: Optional[HexValue] lastAction: Optional[FeltValue] owner: Optional[HexValue] name: Optional[StringValue] @@ -939,6 +942,7 @@ class Adventurer: def from_mongo(cls, data): return cls( id=data["id"], + entropy=data["entropy"], lastAction=data["lastAction"], owner=data["owner"], name=data["name"], diff --git a/indexer/sepolia-compose.yaml b/indexer/sepolia-compose.yaml index d1fa1e0f4..2543314a2 100644 --- a/indexer/sepolia-compose.yaml +++ b/indexer/sepolia-compose.yaml @@ -26,7 +26,7 @@ services: adventurers_indexer: - image: quay.io/apibara/sink-mongo:0.4.2 + image: quay.io/apibara/sink-mongo:0.8.0 depends_on: - etcd - mongo @@ -45,7 +45,7 @@ services: - indexer battles_indexer: - image: quay.io/apibara/sink-mongo:0.4.2 + image: quay.io/apibara/sink-mongo:0.8.0 depends_on: - etcd - mongo @@ -64,7 +64,7 @@ services: - indexer beasts_indexer: - image: quay.io/apibara/sink-mongo:0.4.2 + image: quay.io/apibara/sink-mongo:0.8.0 depends_on: - etcd - mongo @@ -83,7 +83,7 @@ services: - indexer discoveries_indexer: - image: quay.io/apibara/sink-mongo:0.4.2 + image: quay.io/apibara/sink-mongo:0.8.0 depends_on: - etcd - mongo @@ -102,7 +102,7 @@ services: - indexer items_indexer: - image: quay.io/apibara/sink-mongo:0.4.2 + image: quay.io/apibara/sink-mongo:0.8.0 depends_on: - etcd - mongo @@ -121,7 +121,7 @@ services: - indexer scores_indexer: - image: quay.io/apibara/sink-mongo:0.4.2 + image: quay.io/apibara/sink-mongo:0.8.0 depends_on: - etcd - mongo diff --git a/indexer/src/adventurers.ts b/indexer/src/adventurers.ts index 65e67ee6d..2bc6681b4 100644 --- a/indexer/src/adventurers.ts +++ b/indexer/src/adventurers.ts @@ -107,6 +107,7 @@ export default function transform({ header, events }: Block) { insertAdventurer({ id: as.adventurerId, owner: as.owner, + entropy: as.adventurerEntropy, lastAction: as.adventurer.lastActionBlock, health: as.adventurer.health, xp: as.adventurer.xp, diff --git a/indexer/src/utils/events.ts b/indexer/src/utils/events.ts index 950952328..58669790b 100644 --- a/indexer/src/utils/events.ts +++ b/indexer/src/utils/events.ts @@ -99,7 +99,8 @@ export const parseAdventurer = combineParsers({ export const parseAdventurerState = combineParsers({ owner: { index: 0, parser: parseFelt252 }, adventurerId: { index: 1, parser: parseFelt252 }, - adventurer: { index: 2, parser: parseAdventurer }, + adventurerEntropy: { index: 2, parser: parseFelt252 }, + adventurer: { index: 3, parser: parseAdventurer }, }); export const parseSpecialPowers = combineParsers({ diff --git a/indexer/src/utils/helpers.ts b/indexer/src/utils/helpers.ts index 698aa0455..acb50bc36 100644 --- a/indexer/src/utils/helpers.ts +++ b/indexer/src/utils/helpers.ts @@ -4,6 +4,7 @@ import { encodeIntAsBytes, checkExistsInt } from "./encode.ts"; export function insertAdventurer({ id, owner, + entropy, lastAction, health, xp, @@ -42,6 +43,7 @@ export function insertAdventurer({ update: { $set: { ...entity, + entropy: encodeIntAsBytes(BigInt(entropy)), lastAction: encodeIntAsBytes(BigInt(lastAction)), health: encodeIntAsBytes(BigInt(health)), xp: encodeIntAsBytes(BigInt(xp)), @@ -171,6 +173,7 @@ export function updateAdventurer({ update: { $set: { ...entity, + entropy: encodeIntAsBytes(BigInt(adventurerState.adventurerEntropy)), lastAction: encodeIntAsBytes(BigInt(adventurer.lastActionBlock)), health: encodeIntAsBytes(BigInt(adventurer.health)), xp: encodeIntAsBytes(BigInt(adventurer.xp)), diff --git a/ui/src/app/abi/Game.json b/ui/src/app/abi/Game.json index 0da7aea16..bd6f11c59 100644 --- a/ui/src/app/abi/Game.json +++ b/ui/src/app/abi/Game.json @@ -4,6 +4,16 @@ "type": "impl", "interface_name": "game::game::interfaces::IGame" }, + { + "name": "core::array::Span::", + "type": "struct", + "members": [ + { + "name": "snapshot", + "type": "@core::array::Array::" + } + ] + }, { "name": "core::integer::u256", "type": "struct", @@ -173,24 +183,264 @@ ] }, { - "name": "game_entropy::game_entropy::GameEntropy", + "name": "survivor::adventurer_meta::AdventurerMetadata", "type": "struct", "members": [ { - "name": "hash", - "type": "core::felt252" + "name": "start_block", + "type": "core::integer::u64" }, { - "name": "last_updated_block", - "type": "core::integer::u64" + "name": "starting_stats", + "type": "survivor::stats::Stats" }, { - "name": "last_updated_time", - "type": "core::integer::u64" + "name": "name", + "type": "core::integer::u128" }, { - "name": "next_update_block", - "type": "core::integer::u64" + "name": "interface_camel", + "type": "core::bool" + } + ] + }, + { + "name": "survivor::bag::Bag", + "type": "struct", + "members": [ + { + "name": "item_1", + "type": "survivor::item_primitive::ItemPrimitive" + }, + { + "name": "item_2", + "type": "survivor::item_primitive::ItemPrimitive" + }, + { + "name": "item_3", + "type": "survivor::item_primitive::ItemPrimitive" + }, + { + "name": "item_4", + "type": "survivor::item_primitive::ItemPrimitive" + }, + { + "name": "item_5", + "type": "survivor::item_primitive::ItemPrimitive" + }, + { + "name": "item_6", + "type": "survivor::item_primitive::ItemPrimitive" + }, + { + "name": "item_7", + "type": "survivor::item_primitive::ItemPrimitive" + }, + { + "name": "item_8", + "type": "survivor::item_primitive::ItemPrimitive" + }, + { + "name": "item_9", + "type": "survivor::item_primitive::ItemPrimitive" + }, + { + "name": "item_10", + "type": "survivor::item_primitive::ItemPrimitive" + }, + { + "name": "item_11", + "type": "survivor::item_primitive::ItemPrimitive" + }, + { + "name": "mutated", + "type": "core::bool" + } + ] + }, + { + "name": "survivor::item_meta::ItemSpecials", + "type": "struct", + "members": [ + { + "name": "special1", + "type": "core::integer::u8" + }, + { + "name": "special2", + "type": "core::integer::u8" + }, + { + "name": "special3", + "type": "core::integer::u8" + } + ] + }, + { + "name": "survivor::item_meta::ItemSpecialsStorage", + "type": "struct", + "members": [ + { + "name": "item_1", + "type": "survivor::item_meta::ItemSpecials" + }, + { + "name": "item_2", + "type": "survivor::item_meta::ItemSpecials" + }, + { + "name": "item_3", + "type": "survivor::item_meta::ItemSpecials" + }, + { + "name": "item_4", + "type": "survivor::item_meta::ItemSpecials" + }, + { + "name": "item_5", + "type": "survivor::item_meta::ItemSpecials" + }, + { + "name": "item_6", + "type": "survivor::item_meta::ItemSpecials" + }, + { + "name": "item_7", + "type": "survivor::item_meta::ItemSpecials" + }, + { + "name": "item_8", + "type": "survivor::item_meta::ItemSpecials" + }, + { + "name": "item_9", + "type": "survivor::item_meta::ItemSpecials" + }, + { + "name": "item_10", + "type": "survivor::item_meta::ItemSpecials" + }, + { + "name": "mutated", + "type": "core::bool" + } + ] + }, + { + "name": "combat::constants::CombatEnums::Tier", + "type": "enum", + "variants": [ + { + "name": "None", + "type": "()" + }, + { + "name": "T1", + "type": "()" + }, + { + "name": "T2", + "type": "()" + }, + { + "name": "T3", + "type": "()" + }, + { + "name": "T4", + "type": "()" + }, + { + "name": "T5", + "type": "()" + } + ] + }, + { + "name": "combat::constants::CombatEnums::Type", + "type": "enum", + "variants": [ + { + "name": "None", + "type": "()" + }, + { + "name": "Magic_or_Cloth", + "type": "()" + }, + { + "name": "Blade_or_Hide", + "type": "()" + }, + { + "name": "Bludgeon_or_Metal", + "type": "()" + }, + { + "name": "Necklace", + "type": "()" + }, + { + "name": "Ring", + "type": "()" + } + ] + }, + { + "name": "combat::combat::SpecialPowers", + "type": "struct", + "members": [ + { + "name": "special1", + "type": "core::integer::u8" + }, + { + "name": "special2", + "type": "core::integer::u8" + }, + { + "name": "special3", + "type": "core::integer::u8" + } + ] + }, + { + "name": "combat::combat::CombatSpec", + "type": "struct", + "members": [ + { + "name": "tier", + "type": "combat::constants::CombatEnums::Tier" + }, + { + "name": "item_type", + "type": "combat::constants::CombatEnums::Type" + }, + { + "name": "level", + "type": "core::integer::u16" + }, + { + "name": "specials", + "type": "combat::combat::SpecialPowers" + } + ] + }, + { + "name": "beasts::beast::Beast", + "type": "struct", + "members": [ + { + "name": "id", + "type": "core::integer::u8" + }, + { + "name": "starting_health", + "type": "core::integer::u16" + }, + { + "name": "combat_spec", + "type": "combat::combat::CombatSpec" } ] }, @@ -234,6 +484,41 @@ "name": "game::game::interfaces::IGame", "type": "interface", "items": [ + { + "name": "get_randomness_address", + "type": "function", + "inputs": [], + "outputs": [ + { + "type": "core::starknet::contract_address::ContractAddress" + } + ], + "state_mutability": "view" + }, + { + "name": "receive_random_words", + "type": "function", + "inputs": [ + { + "name": "requestor_address", + "type": "core::starknet::contract_address::ContractAddress" + }, + { + "name": "request_id", + "type": "core::integer::u64" + }, + { + "name": "random_words", + "type": "core::array::Span::" + }, + { + "name": "calldata", + "type": "core::array::Array::" + } + ], + "outputs": [], + "state_mutability": "external" + }, { "name": "new_game", "type": "function", @@ -257,22 +542,10 @@ { "name": "interface_camel", "type": "core::bool" - } - ], - "outputs": [], - "state_mutability": "external" - }, - { - "name": "set_starting_entropy", - "type": "function", - "inputs": [ - { - "name": "adventurer_id", - "type": "core::felt252" }, { - "name": "block_hash", - "type": "core::felt252" + "name": "vrf_fee_limit", + "type": "core::integer::u128" } ], "outputs": [], @@ -383,52 +656,94 @@ "state_mutability": "external" }, { - "name": "slay_idle_adventurers", + "name": "update_cost_to_play", + "type": "function", + "inputs": [], + "outputs": [], + "state_mutability": "external" + }, + { + "name": "get_adventurer", "type": "function", "inputs": [ { - "name": "adventurer_ids", - "type": "core::array::Array::" + "name": "adventurer_id", + "type": "core::felt252" } ], - "outputs": [], - "state_mutability": "external" + "outputs": [ + { + "type": "survivor::adventurer::Adventurer" + } + ], + "state_mutability": "view" }, { - "name": "slay_invalid_adventurers", + "name": "get_adventurer_entropy", "type": "function", "inputs": [ { - "name": "adventurer_ids", - "type": "core::array::Array::" + "name": "adventurer_id", + "type": "core::felt252" } ], - "outputs": [], - "state_mutability": "external" + "outputs": [ + { + "type": "core::felt252" + } + ], + "state_mutability": "view" }, { - "name": "rotate_game_entropy", + "name": "get_adventurer_no_boosts", "type": "function", - "inputs": [], - "outputs": [], - "state_mutability": "external" + "inputs": [ + { + "name": "adventurer_id", + "type": "core::felt252" + } + ], + "outputs": [ + { + "type": "survivor::adventurer::Adventurer" + } + ], + "state_mutability": "view" }, { - "name": "update_cost_to_play", + "name": "get_adventurer_meta", "type": "function", - "inputs": [], - "outputs": [], - "state_mutability": "external" + "inputs": [ + { + "name": "adventurer_id", + "type": "core::felt252" + } + ], + "outputs": [ + { + "type": "survivor::adventurer_meta::AdventurerMetadata" + } + ], + "state_mutability": "view" }, { - "name": "initiate_price_change", + "name": "get_health", "type": "function", - "inputs": [], - "outputs": [], - "state_mutability": "external" + "inputs": [ + { + "name": "adventurer_id", + "type": "core::felt252" + } + ], + "outputs": [ + { + "type": "core::integer::u16" + } + ], + "state_mutability": "view" }, { - "name": "get_adventurer", + "name": "get_xp", "type": "function", "inputs": [ { @@ -438,13 +753,13 @@ ], "outputs": [ { - "type": "survivor::adventurer::Adventurer" + "type": "core::integer::u16" } ], "state_mutability": "view" }, { - "name": "get_base_stats", + "name": "get_level", "type": "function", "inputs": [ { @@ -454,51 +769,193 @@ ], "outputs": [ { - "type": "survivor::stats::Stats" + "type": "core::integer::u8" } ], "state_mutability": "view" }, { - "name": "next_game_entropy_rotation", + "name": "get_gold", "type": "function", - "inputs": [], + "inputs": [ + { + "name": "adventurer_id", + "type": "core::felt252" + } + ], "outputs": [ { + "type": "core::integer::u16" + } + ], + "state_mutability": "view" + }, + { + "name": "get_stat_upgrades_available", + "type": "function", + "inputs": [ + { + "name": "adventurer_id", "type": "core::felt252" } ], + "outputs": [ + { + "type": "core::integer::u8" + } + ], "state_mutability": "view" }, { - "name": "game_rate_limit", + "name": "get_bag", "type": "function", - "inputs": [], + "inputs": [ + { + "name": "adventurer_id", + "type": "core::felt252" + } + ], "outputs": [ { - "type": "core::integer::u64" + "type": "survivor::bag::Bag" + } + ], + "state_mutability": "view" + }, + { + "name": "get_special_storage", + "type": "function", + "inputs": [ + { + "name": "adventurer_id", + "type": "core::felt252" + }, + { + "name": "storage_index", + "type": "core::integer::u8" + } + ], + "outputs": [ + { + "type": "survivor::item_meta::ItemSpecialsStorage" + } + ], + "state_mutability": "view" + }, + { + "name": "get_items_on_market", + "type": "function", + "inputs": [ + { + "name": "adventurer_id", + "type": "core::felt252" + } + ], + "outputs": [ + { + "type": "core::array::Array::" + } + ], + "state_mutability": "view" + }, + { + "name": "get_attacking_beast", + "type": "function", + "inputs": [ + { + "name": "adventurer_id", + "type": "core::felt252" + } + ], + "outputs": [ + { + "type": "beasts::beast::Beast" + } + ], + "state_mutability": "view" + }, + { + "name": "get_beast_health", + "type": "function", + "inputs": [ + { + "name": "adventurer_id", + "type": "core::felt252" + } + ], + "outputs": [ + { + "type": "core::integer::u16" + } + ], + "state_mutability": "view" + }, + { + "name": "get_beast_type", + "type": "function", + "inputs": [ + { + "name": "beast_id", + "type": "core::integer::u8" + } + ], + "outputs": [ + { + "type": "core::integer::u8" + } + ], + "state_mutability": "view" + }, + { + "name": "get_beast_tier", + "type": "function", + "inputs": [ + { + "name": "beast_id", + "type": "core::integer::u8" + } + ], + "outputs": [ + { + "type": "core::integer::u8" + } + ], + "state_mutability": "view" + }, + { + "name": "owner_of", + "type": "function", + "inputs": [ + { + "name": "adventurer_id", + "type": "core::felt252" + } + ], + "outputs": [ + { + "type": "core::starknet::contract_address::ContractAddress" } ], "state_mutability": "view" }, { - "name": "get_game_entropy", + "name": "get_dao_address", "type": "function", "inputs": [], "outputs": [ { - "type": "game_entropy::game_entropy::GameEntropy" + "type": "core::starknet::contract_address::ContractAddress" } ], "state_mutability": "view" }, { - "name": "get_idle_penalty_blocks", + "name": "get_lords_address", "type": "function", "inputs": [], "outputs": [ { - "type": "core::integer::u64" + "type": "core::starknet::contract_address::ContractAddress" } ], "state_mutability": "view" @@ -566,46 +1023,40 @@ { "name": "terminal_timestamp", "type": "core::integer::u64" - } - ] - }, - { - "name": "game::Game::AdventurerState", - "type": "struct", - "members": [ + }, { - "name": "owner", + "name": "randomness_contract_address", "type": "core::starknet::contract_address::ContractAddress" }, { - "name": "adventurer_id", - "type": "core::felt252" + "name": "randomness_rotation_interval", + "type": "core::integer::u8" }, { - "name": "adventurer", - "type": "survivor::adventurer::Adventurer" + "name": "oracle_address", + "type": "core::starknet::contract_address::ContractAddress" } ] }, { - "name": "survivor::adventurer_meta::AdventurerMetadata", + "name": "game::Game::AdventurerState", "type": "struct", "members": [ { - "name": "start_block", - "type": "core::integer::u64" + "name": "owner", + "type": "core::starknet::contract_address::ContractAddress" }, { - "name": "starting_stats", - "type": "survivor::stats::Stats" + "name": "adventurer_id", + "type": "core::felt252" }, { - "name": "name", - "type": "core::integer::u128" + "name": "adventurer_entropy", + "type": "core::felt252" }, { - "name": "interface_camel", - "type": "core::bool" + "name": "adventurer", + "type": "survivor::adventurer::Adventurer" } ] }, @@ -758,106 +1209,6 @@ } ] }, - { - "name": "combat::constants::CombatEnums::Tier", - "type": "enum", - "variants": [ - { - "name": "None", - "type": "()" - }, - { - "name": "T1", - "type": "()" - }, - { - "name": "T2", - "type": "()" - }, - { - "name": "T3", - "type": "()" - }, - { - "name": "T4", - "type": "()" - }, - { - "name": "T5", - "type": "()" - } - ] - }, - { - "name": "combat::constants::CombatEnums::Type", - "type": "enum", - "variants": [ - { - "name": "None", - "type": "()" - }, - { - "name": "Magic_or_Cloth", - "type": "()" - }, - { - "name": "Blade_or_Hide", - "type": "()" - }, - { - "name": "Bludgeon_or_Metal", - "type": "()" - }, - { - "name": "Necklace", - "type": "()" - }, - { - "name": "Ring", - "type": "()" - } - ] - }, - { - "name": "combat::combat::SpecialPowers", - "type": "struct", - "members": [ - { - "name": "special1", - "type": "core::integer::u8" - }, - { - "name": "special2", - "type": "core::integer::u8" - }, - { - "name": "special3", - "type": "core::integer::u8" - } - ] - }, - { - "name": "combat::combat::CombatSpec", - "type": "struct", - "members": [ - { - "name": "tier", - "type": "combat::constants::CombatEnums::Tier" - }, - { - "name": "item_type", - "type": "combat::constants::CombatEnums::Type" - }, - { - "name": "level", - "type": "core::integer::u16" - }, - { - "name": "specials", - "type": "combat::combat::SpecialPowers" - } - ] - }, { "name": "game::Game::BattleDetails", "type": "struct", @@ -1086,60 +1437,6 @@ } ] }, - { - "name": "survivor::bag::Bag", - "type": "struct", - "members": [ - { - "name": "item_1", - "type": "survivor::item_primitive::ItemPrimitive" - }, - { - "name": "item_2", - "type": "survivor::item_primitive::ItemPrimitive" - }, - { - "name": "item_3", - "type": "survivor::item_primitive::ItemPrimitive" - }, - { - "name": "item_4", - "type": "survivor::item_primitive::ItemPrimitive" - }, - { - "name": "item_5", - "type": "survivor::item_primitive::ItemPrimitive" - }, - { - "name": "item_6", - "type": "survivor::item_primitive::ItemPrimitive" - }, - { - "name": "item_7", - "type": "survivor::item_primitive::ItemPrimitive" - }, - { - "name": "item_8", - "type": "survivor::item_primitive::ItemPrimitive" - }, - { - "name": "item_9", - "type": "survivor::item_primitive::ItemPrimitive" - }, - { - "name": "item_10", - "type": "survivor::item_primitive::ItemPrimitive" - }, - { - "name": "item_11", - "type": "survivor::item_primitive::ItemPrimitive" - }, - { - "name": "mutated", - "type": "core::bool" - } - ] - }, { "name": "game::Game::AdventurerStateWithBag", "type": "struct", @@ -1357,24 +1654,6 @@ } ] }, - { - "name": "survivor::item_meta::ItemSpecials", - "type": "struct", - "members": [ - { - "name": "special1", - "type": "core::integer::u8" - }, - { - "name": "special2", - "type": "core::integer::u8" - }, - { - "name": "special3", - "type": "core::integer::u8" - } - ] - }, { "name": "game::Game::ItemLeveledUp", "type": "struct", @@ -1474,33 +1753,6 @@ } ] }, - { - "kind": "struct", - "name": "game::Game::IdleDeathPenalty", - "type": "event", - "members": [ - { - "kind": "data", - "name": "adventurer_state", - "type": "game::Game::AdventurerState" - }, - { - "kind": "data", - "name": "idle_blocks", - "type": "core::integer::u16" - }, - { - "kind": "data", - "name": "penalty_threshold", - "type": "core::integer::u64" - }, - { - "kind": "data", - "name": "caller", - "type": "core::starknet::contract_address::ContractAddress" - } - ] - }, { "name": "game::Game::PlayerReward", "type": "struct", @@ -1569,58 +1821,6 @@ } ] }, - { - "kind": "struct", - "name": "game::Game::GameEntropyRotatedEvent", - "type": "event", - "members": [ - { - "kind": "data", - "name": "prev_hash", - "type": "core::felt252" - }, - { - "kind": "data", - "name": "prev_block_number", - "type": "core::integer::u64" - }, - { - "kind": "data", - "name": "prev_block_timestamp", - "type": "core::integer::u64" - }, - { - "kind": "data", - "name": "prev_next_rotation_block", - "type": "core::integer::u64" - }, - { - "kind": "data", - "name": "new_hash", - "type": "core::felt252" - }, - { - "kind": "data", - "name": "new_block_number", - "type": "core::integer::u64" - }, - { - "kind": "data", - "name": "new_block_timestamp", - "type": "core::integer::u64" - }, - { - "kind": "data", - "name": "new_next_rotation_block", - "type": "core::integer::u64" - }, - { - "kind": "data", - "name": "blocks_per_hour", - "type": "core::integer::u64" - } - ] - }, { "kind": "struct", "name": "game::Game::PriceChangeEvent", @@ -1628,23 +1828,18 @@ "members": [ { "kind": "data", - "name": "previous_cost_to_play", + "name": "previous_price", "type": "core::integer::u128" }, { "kind": "data", - "name": "new_cost_to_play", + "name": "new_price", "type": "core::integer::u128" }, { "kind": "data", - "name": "global_games_per_day", - "type": "core::integer::u64" - }, - { - "kind": "data", - "name": "snapshot_games_per_day", - "type": "core::integer::u64" + "name": "lords_price", + "type": "core::integer::u128" }, { "kind": "data", @@ -1768,21 +1963,11 @@ "name": "NewHighScore", "type": "game::Game::NewHighScore" }, - { - "kind": "nested", - "name": "IdleDeathPenalty", - "type": "game::Game::IdleDeathPenalty" - }, { "kind": "nested", "name": "RewardDistribution", "type": "game::Game::RewardDistribution" }, - { - "kind": "nested", - "name": "GameEntropyRotatedEvent", - "type": "game::Game::GameEntropyRotatedEvent" - }, { "kind": "nested", "name": "PriceChangeEvent", diff --git a/ui/src/app/api/checkEntropy.ts b/ui/src/app/api/checkEntropy.ts new file mode 100644 index 000000000..8b3790de7 --- /dev/null +++ b/ui/src/app/api/checkEntropy.ts @@ -0,0 +1,34 @@ +export const getEntropy = async () => { + const rpcUrl = process.env.NEXT_PUBLIC_RPC_URL!; + const gameAddress = process.env.NEXT_PUBLIC_GAME_ADDRESS!; + const response = await fetch(rpcUrl, { + method: "POST", + headers: { + "Content-Type": "application/json", + }, + body: JSON.stringify({ + jsonrpc: "2.0", + method: "starknet_call", + params: [ + { + contract_address: gameAddress, + entry_point_selector: + "0xb0d944377304e5d17e57a0404b4c1714845736851cfe18cc171a33868091be", // get_adveturer_entropy + calldata: [], + }, + "pending", + ], + id: 0, + }), + }); + + const data = await response.json(); + + if (response.ok) { + console.log("Interface fetched successfully"); + } else { + console.error("Error in response:", data); + } + + return data; +}; diff --git a/ui/src/app/api/getItems.ts b/ui/src/app/api/getItems.ts new file mode 100644 index 000000000..3331fd435 --- /dev/null +++ b/ui/src/app/api/getItems.ts @@ -0,0 +1,34 @@ +export const getItems = async () => { + const rpcUrl = process.env.NEXT_PUBLIC_RPC_URL!; + const gameAddress = process.env.NEXT_PUBLIC_GAME_ADDRESS!; + const response = await fetch(rpcUrl, { + method: "POST", + headers: { + "Content-Type": "application/json", + }, + body: JSON.stringify({ + jsonrpc: "2.0", + method: "starknet_call", + params: [ + { + contract_address: gameAddress, + entry_point_selector: + "0xb0d944377304e5d17e57a0404b4c1714845736851cfe18cc171a33868091be", // get_marketplace_items + calldata: [], + }, + "pending", + ], + id: 0, + }), + }); + + const data = await response.json(); + + if (response.ok) { + console.log("Interface fetched successfully"); + } else { + console.error("Error in response:", data); + } + + return data; +}; diff --git a/ui/src/app/components/CountDown.tsx b/ui/src/app/components/CountDown.tsx index 1fce6a145..948518729 100644 --- a/ui/src/app/components/CountDown.tsx +++ b/ui/src/app/components/CountDown.tsx @@ -1,7 +1,6 @@ import { useEffect, useRef } from "react"; import { useCountUp } from "react-countup"; import { useState } from "react"; -import { penaltyTime } from "../lib/constants"; const formatTime = (totalSeconds: number) => { const hours = Math.floor(totalSeconds / 3600); @@ -36,69 +35,6 @@ export const HealthCountDown = ({ health }: any) => { ); }; -export interface PenaltyCountDownProps { - dataLoading: boolean; - startCountdown: boolean; - updateDeathPenalty: boolean; - setUpdateDeathPenalty: (value: boolean) => void; -} - -export const PenaltyCountDown: React.FC = ({ - dataLoading, - startCountdown, - updateDeathPenalty, - setUpdateDeathPenalty, -}) => { - const [seconds, setSeconds] = useState(penaltyTime); - const [intervalId, setIntervalId] = useState(null); - - useEffect(() => { - const startTimer = () => { - setSeconds(penaltyTime); - const targetTime = new Date().getTime() + penaltyTime * 1000; - - // Clear previous interval if it exists - if (intervalId !== null) { - window.clearInterval(intervalId); - } - - const newIntervalId = window.setInterval(() => { - const currentTime = new Date().getTime(); - const timeRemaining = Math.max( - 0, - Math.floor((targetTime - currentTime) / 1000) - ); - setSeconds(timeRemaining); - }, 1000); - - // Store the new interval ID - setIntervalId(newIntervalId); - }; - - if (updateDeathPenalty) { - startTimer(); - setUpdateDeathPenalty(false); - } - }, [updateDeathPenalty]); - - return ( -
- {startCountdown ? ( - seconds > 0 ? ( - -

Penalty:

-

{formatTime(seconds)}

-
- ) : ( -

Penalty Reached!

- ) - ) : ( -

Not Started

- )} -
- ); -}; - export interface EntropyCountDownProps { targetTime: number | null; countDownExpired: () => void; diff --git a/ui/src/app/components/actions/DiscoveryDisplay.tsx b/ui/src/app/components/actions/DiscoveryDisplay.tsx index 1d76e5e96..40294b0d1 100644 --- a/ui/src/app/components/actions/DiscoveryDisplay.tsx +++ b/ui/src/app/components/actions/DiscoveryDisplay.tsx @@ -4,7 +4,6 @@ import { GiBruteIcon, SkullCrossedBonesIcon, SpikedWallIcon, - GiSandsOfTimeIcon, TwoCoinIcon, HealthPotionIcon, } from "@/app/components/icons/Icons"; @@ -103,15 +102,6 @@ export const DiscoveryDisplay = ({ discoveryData }: DiscoveryProps) => { } } - if (!discoveryData?.discoveryType) { - return ( - -

OOPS! Killed by idle death penalty!

- -
- ); - } - if (discoveryData?.discoveryType === "Item") { if (discoveryData?.subDiscoveryType === "Gold") { return ( diff --git a/ui/src/app/components/beast/BattleDisplay.tsx b/ui/src/app/components/beast/BattleDisplay.tsx index 5a22165e6..465991acb 100644 --- a/ui/src/app/components/beast/BattleDisplay.tsx +++ b/ui/src/app/components/beast/BattleDisplay.tsx @@ -30,7 +30,6 @@ export const BattleDisplay = ({ const AdventurerHealthExists = (battleData.adventurerHealth ?? 0) > 0; const NoDamageDealt = battleData.damageDealt === 0; const NoDamageTaken = battleData.damageTaken === 0; - const IdleDamagePenalty = !battleData.beast; const CriticalHit = battleData.criticalHit; const renderDiscoveryMessage = () => { @@ -130,15 +129,6 @@ export const BattleDisplay = ({ ); } - - if (IdleDamagePenalty) { - return ( - -

OOPS! Killed by idle death penalty!

- -
- ); - } }; return ( @@ -218,8 +208,6 @@ export const NotificationBattleDisplay = ({ battleData.some( (data) => data.attacker === "Beast" && (data.adventurerHealth ?? 0) === 0 ); - const IdleDeathPenalty = - isArray && battleData.length == 1 && !battleData[0].beast; const renderBattleNotification = () => { if (BeastFled) { @@ -342,13 +330,6 @@ export const NotificationBattleDisplay = ({ /> ); - } else if (IdleDeathPenalty) { - return ( - -

Killed from the idle death penalty!

- -
- ); } }; return ( diff --git a/ui/src/app/components/intro/ArcadeIntro.tsx b/ui/src/app/components/intro/ArcadeIntro.tsx deleted file mode 100644 index 7299444c4..000000000 --- a/ui/src/app/components/intro/ArcadeIntro.tsx +++ /dev/null @@ -1,350 +0,0 @@ -import { useEffect, useState } from "react"; -import { MdClose } from "react-icons/md"; -import { Contract } from "starknet"; -import { useAccount, useConnect, useDisconnect } from "@starknet-react/core"; -import { ETH_PREFUND_AMOUNT, useBurner } from "@/app/lib/burner"; -import { Button } from "@/app/components/buttons/Button"; -import useUIStore from "@/app/hooks/useUIStore"; -import { getWalletConnectors } from "@/app/lib/connectors"; -import ArcadeLoader from "@/app/components/animations/ArcadeLoader"; -import Lords from "public/icons/lords.svg"; -import QuantityButtons from "../buttons/QuantityButtons"; -import { indexAddress } from "@/app/lib/utils"; - -interface ArcadeIntroProps { - ethBalance: bigint; - lordsBalance: bigint; - gameContract: Contract; - lordsContract: Contract; - ethContract: Contract; - updateConnectors: () => void; - mintLords: () => Promise; -} - -export const ArcadeIntro = ({ - ethBalance, - lordsBalance, - gameContract, - lordsContract, - ethContract, - updateConnectors, - mintLords, -}: ArcadeIntroProps) => { - const { account, address, connector } = useAccount(); - const { connect, connectors } = useConnect(); - const { disconnect } = useDisconnect(); - const [step, setStep] = useState(1); - const [fullDeployment, setFullDeployment] = useState(false); - const [gamesPrefundAmount, setGamesPrefundAmount] = useState(1); - const [readDisclaimer, setReadDisclaimer] = useState(false); - const [buyLordsLater, setBuyLordsLater] = useState(false); - const isWrongNetwork = useUIStore((state) => state.isWrongNetwork); - const showArcadeIntro = useUIStore((state) => state.showArcadeIntro); - const setClosedArcadeIntro = useUIStore( - (state) => state.setClosedArcadeIntro - ); - const { - create, - isPrefunding, - isDeploying, - isSettingPermissions, - listConnectors, - showLoader, - } = useBurner({ - walletAccount: account, - gameContract, - lordsContract, - ethContract, - }); - const walletConnectors = getWalletConnectors(connectors); - const setScreen = useUIStore((state) => state.setScreen); - const lords = Number(lordsBalance); - const eth = Number(ethBalance); - - const checkNotEnoughPrefundEth = eth < parseInt(ETH_PREFUND_AMOUNT); - const checkNotEnoughPrefundLords = lords < parseInt("1000000000000"); - - useEffect(() => { - if ( - account && - (!checkNotEnoughPrefundLords || buyLordsLater) && - readDisclaimer - ) { - setStep(4); - } else if (account && readDisclaimer) { - setStep(3); - } else if (account) { - setStep(2); - } else { - setStep(1); - } - }, [account, checkNotEnoughPrefundLords, readDisclaimer, buyLordsLater]); - - const formattedLords = lords / 10 ** 18; - - const maxGames = Math.min(Math.floor(formattedLords / 25), 100); - - const onMainnet = process.env.NEXT_PUBLIC_NETWORK === "mainnet"; - - return ( - <> -
-
- - {step == 1 && ( -
-

Create Arcade Account

-

- Welcome to Arcade Accounts! Follow three steps now to enjoy - signature-free speed runs in Loot Survivor. -

-

- Your Arcade Account's key is securely stored in your browser - and is linked to your main wallet with limited permissions. This - provides a low-risk, superfast onchain gaming experience. -

-

- Please choose a Starknet Wallet below. -

-
- - {walletConnectors.map((connector, index) => ( - - ))} -
-
- )} - {step == 2 && ( -
-

Disclaimers

-

- The game is still in testing and there may be things outside of - our control that cause incomplete games after Lords have been - inserted. We kindly advise that any problems encountered are - reported to the discord channel within Biblithecadao. -

-

- The game has an idle penalty counter that will kill the adventurer - if a move isn't made within a certain number of blocks (~ - 7-10 mins). To avoid frustration please keep an eye on the idle - penalty. -

- -
- )} - {step == 3 && ( -
-

- {onMainnet ? "Buy Lords" : "Mint Lords"} -

-
-

- In order to play Loot Survivor you must insert at least 25 - Lords. -

-

- {onMainnet - ? "If you do not have any LORDS please select the button below to buy from a DEX." - : "Mint 250 (10 games worth) with the button below"} -

-

- Please ensure that your Account is deployed! -

-
-
- -
- - -
-
-
- )} - {step == 4 && ( -
-

Deploy Arcade Account

-
-

- You are about to deploy a new Arcade Account (AA)! You will be - asked to sign 2 transactions: -

-
    -
  • Pre-fund the AA with ETH and LORDS
  • -
  • - Set Permissions on the AA to play Loot Survivor and transfer - back -
  • -
-

- Transactions may take some time, please be patient. Avoid - refreshing as it could lead to loss of funds. -

-
-
- {checkNotEnoughPrefundEth ? ( - - ) : ( -
-

- How many games would you like to fund? -

-
-
- { - setGamesPrefundAmount(value); - }} - /> -
- -
- -
- )} -
-
- )} -
-
-
= 1 ? "bg-terminal-green" : "border border-terminal-green" - }`} - /> -
= 2 ? "bg-terminal-green" : "border border-terminal-green" - }`} - /> -
= 3 ? "bg-terminal-green" : "border border-terminal-green" - }`} - /> -
-
-
- -
- - ); -}; diff --git a/ui/src/app/components/leaderboard/LiveRow.tsx b/ui/src/app/components/leaderboard/LiveRow.tsx index 478b99607..5dd0be358 100644 --- a/ui/src/app/components/leaderboard/LiveRow.tsx +++ b/ui/src/app/components/leaderboard/LiveRow.tsx @@ -12,8 +12,6 @@ interface LiveLeaderboardRowProps { adventurer: Adventurer; handleRowSelected: (id: number) => void; gameContract: Contract; - gameEntropyUpdateTime: number; - currentBlock: number; idleAdventurers?: string[]; } @@ -21,8 +19,6 @@ const LiveLeaderboardRow = ({ adventurer, handleRowSelected, gameContract, - gameEntropyUpdateTime, - currentBlock, idleAdventurers, }: LiveLeaderboardRowProps) => { const { play: clickPlay } = useUiSounds(soundSelector.click); diff --git a/ui/src/app/components/leaderboard/LiveTable.tsx b/ui/src/app/components/leaderboard/LiveTable.tsx index 0e19d2be8..eba2ec3c9 100644 --- a/ui/src/app/components/leaderboard/LiveTable.tsx +++ b/ui/src/app/components/leaderboard/LiveTable.tsx @@ -10,8 +10,6 @@ export interface LiveLeaderboardTableProps { handleFetchProfileData: (adventurerId: number) => void; adventurers: Adventurer[]; gameContract: Contract; - gameEntropyUpdateTime: number; - currentBlock: number; idleAdventurers?: string[]; } @@ -20,8 +18,6 @@ const LiveLeaderboardTable = ({ handleFetchProfileData, adventurers, gameContract, - gameEntropyUpdateTime, - currentBlock, idleAdventurers, }: LiveLeaderboardTableProps) => { const [currentPage, setCurrentPage] = useState(1); @@ -72,8 +68,6 @@ const LiveLeaderboardTable = ({ adventurer={adventurer} handleRowSelected={handleRowSelected} gameContract={gameContract} - gameEntropyUpdateTime={gameEntropyUpdateTime} - currentBlock={currentBlock} idleAdventurers={idleAdventurers} /> ) diff --git a/ui/src/app/components/navigation/Header.tsx b/ui/src/app/components/navigation/Header.tsx index f0246d3e0..6daa0f7ea 100644 --- a/ui/src/app/components/navigation/Header.tsx +++ b/ui/src/app/components/navigation/Header.tsx @@ -8,7 +8,6 @@ import { useUiSounds } from "@/app/hooks/useUiSound"; import { soundSelector } from "@/app/hooks/useUiSound"; import Logo from "public/icons/logo.svg"; import Lords from "public/icons/lords.svg"; -import { PenaltyCountDown } from "@/app/components/CountDown"; import { Button } from "@/app/components/buttons/Button"; import { formatNumber, displayAddress, indexAddress } from "@/app/lib/utils"; import { @@ -57,7 +56,6 @@ export default function Header({ const adventurer = useAdventurerStore((state) => state.adventurer); const setAdventurer = useAdventurerStore((state) => state.setAdventurer); const resetData = useQueriesStore((state) => state.resetData); - const isLoading = useQueriesStore((state) => state.isLoading); const setDisconnected = useUIStore((state) => state.setDisconnected); const arcadeDialog = useUIStore((state) => state.arcadeDialog); @@ -70,12 +68,6 @@ export default function Header({ const displayHistory = useUIStore((state) => state.displayHistory); const setDisplayHistory = useUIStore((state) => state.setDisplayHistory); const setScreen = useUIStore((state) => state.setScreen); - const updateDeathPenalty = useUIStore((state) => state.updateDeathPenalty); - const setUpdateDeathPenalty = useUIStore( - (state) => state.setUpdateDeathPenalty - ); - const startPenalty = useUIStore((state) => state.startPenalty); - const setStartPenalty = useUIStore((state) => state.setStartPenalty); const calls = useTransactionCartStore((state) => state.calls); const txInCart = calls.length > 0; @@ -100,12 +92,6 @@ export default function Header({ handleApibaraStatus(); }, []); - useEffect(() => { - if (startPenalty) { - setStartPenalty(false); - } - }, [adventurer]); - const isOnMainnet = process.env.NEXT_PUBLIC_NETWORK === "mainnet"; const appUrl = process.env.NEXT_PUBLIC_APP_URL; @@ -124,14 +110,6 @@ export default function Header({ )} - {adventurer?.id && ( - 1} - updateDeathPenalty={updateDeathPenalty} - setUpdateDeathPenalty={setUpdateDeathPenalty} - /> - )} -
- )} -
- -
-
- {onMainnet && ( -
-
Long Wait?
-

- Play a quick game for free. Don't forget to set a timer! -

- -
- )} - - )} +
+
+

Loading Entropy

+
+ +
+
); } diff --git a/ui/src/app/containers/LeaderboardScreen.tsx b/ui/src/app/containers/LeaderboardScreen.tsx index 6df875e17..7387d2490 100644 --- a/ui/src/app/containers/LeaderboardScreen.tsx +++ b/ui/src/app/containers/LeaderboardScreen.tsx @@ -1,6 +1,5 @@ import React, { useEffect, useState } from "react"; -import { Block, Contract } from "starknet"; -import { useBlock } from "@starknet-react/core"; +import { Contract } from "starknet"; import { getAdventurerByXP, getAdventurerById, @@ -10,13 +9,12 @@ import { Button } from "@/app/components/buttons/Button"; import { useQueriesStore } from "@/app/hooks/useQueryStore"; import useUIStore from "@/app/hooks/useUIStore"; import useCustomQuery from "@/app/hooks/useCustomQuery"; -import { Adventurer, GameEntropy } from "@/app/types"; +import { Adventurer } from "@/app/types"; import ScoreTable from "@/app/components/leaderboard/ScoreTable"; import LiveTable from "@/app/components/leaderboard/LiveTable"; import { RefreshIcon } from "@/app/components/icons/Icons"; import LootIconLoader from "@/app/components/icons/Loader"; import { ProfileIcon, SkullIcon } from "@/app/components/icons/Icons"; -import { IsIdleResult } from "@/app/types"; interface LeaderboardScreenProps { slayIdles: (slayAdventurers: string[]) => Promise; @@ -33,19 +31,10 @@ export default function LeaderboardScreen({ }: LeaderboardScreenProps) { const itemsPerPage = 10; const [showScores, setShowScores] = useState(false); - const [gameEntropyUpdateTime, setGameEntropyUpdateTime] = useState< - number | null - >(); - const [idleAdventurers, setIdleAdventurers] = useState< + const [idleAdventurers, _setIdleAdventurers] = useState< string[] | undefined >(); - const [loadingIdles, setLoadingIdles] = useState(false); - - const { data: blockData } = useBlock({ - refetchInterval: false, - }); - - const currentBlock = (blockData as Block)?.block_number; + const [loadingIdles, _setLoadingIdles] = useState(false); const { data, refetch, setData, setIsLoading, setNotLoading } = useQueriesStore(); @@ -109,40 +98,27 @@ export default function LeaderboardScreen({ } }, [adventurersByXPdata]); - const getGameEntropy = async () => { - const gameEntropy = await gameContract.call("get_game_entropy"); - const formattedEntropy = gameEntropy as GameEntropy; - const gameEntropyUpdateTime = - Number(formattedEntropy.next_update_block) - - Number(formattedEntropy.last_updated_block); - setGameEntropyUpdateTime(gameEntropyUpdateTime); - }; - - const getIdleAdventurers = async (adventurers: Adventurer[]) => { - setLoadingIdles(true); - const idleAdventurers = []; - for (let adventurer of adventurers) { - const isIdleResult = await gameContract.call("is_idle", [ - adventurer?.id ?? "0", - ]); - const isIdle = (isIdleResult as IsIdleResult)["0"]; - if (isIdle) { - idleAdventurers.push(adventurer?.id?.toString() ?? "0"); - } - } - setIdleAdventurers(idleAdventurers); - setLoadingIdles(false); - }; - - useEffect(() => { - getGameEntropy(); - }, []); - - useEffect(() => { - if (data.adventurersByXPQuery?.adventurers) { - getIdleAdventurers(aliveAdventurers); - } - }, [adventurers]); + // const getIdleAdventurers = async (adventurers: Adventurer[]) => { + // setLoadingIdles(true); + // const idleAdventurers = []; + // for (let adventurer of adventurers) { + // const isIdleResult = await gameContract.call("is_idle", [ + // adventurer?.id ?? "0", + // ]); + // const isIdle = (isIdleResult as IsIdleResult)["0"]; + // if (isIdle) { + // idleAdventurers.push(adventurer?.id?.toString() ?? "0"); + // } + // } + // setIdleAdventurers(idleAdventurers); + // setLoadingIdles(false); + // }; + + // useEffect(() => { + // if (data.adventurersByXPQuery?.adventurers) { + // getIdleAdventurers(aliveAdventurers); + // } + // }, [adventurers]); return (
@@ -197,8 +173,6 @@ export default function LeaderboardScreen({ handleFetchProfileData={handlefetchProfileData} adventurers={aliveAdventurers} gameContract={gameContract} - gameEntropyUpdateTime={gameEntropyUpdateTime!} - currentBlock={currentBlock!} idleAdventurers={idleAdventurers} />
diff --git a/ui/src/app/containers/UpgradeScreen.tsx b/ui/src/app/containers/UpgradeScreen.tsx index 7bae7ddb9..0aa7effee 100644 --- a/ui/src/app/containers/UpgradeScreen.tsx +++ b/ui/src/app/containers/UpgradeScreen.tsx @@ -38,6 +38,7 @@ import Summary from "@/app/components/upgrade/Summary"; import { HealthCountDown } from "@/app/components/CountDown"; import { calculateVitBoostRemoved } from "@/app/lib/utils"; import { useQueriesStore } from "@/app/hooks/useQueryStore"; +import InterludeScreen from "@/app/containers/InterludeScreen"; interface UpgradeScreenProps { upgrade: ( @@ -79,6 +80,8 @@ export default function UpgradeScreen({ const purchaseItems = useUIStore((state) => state.purchaseItems); const setPurchaseItems = useUIStore((state) => state.setPurchaseItems); const dropItems = useUIStore((state) => state.dropItems); + const entropyReady = useUIStore((state) => state.entropyReady); + const setEntropyReady = useUIStore((state) => state.setEntropyReady); const pendingMessage = useLoadingStore((state) => state.pendingMessage); const [summary, setSummary] = useState({ Stats: { ...ZeroUpgrade }, @@ -86,6 +89,58 @@ export default function UpgradeScreen({ Potions: 0, }); + useEffect(() => { + const interval = setInterval(async () => { + const entropy = await gameContract!.call("get_adventurer_entropy", [ + adventurer?.id!, + ]); + console.log(entropy); + if (entropy !== BigInt(0)) { + setEntropyReady(true); + clearInterval(interval); + } + }, 10000); // We call the getAdventurerEntropy function every 30 seconds + + return () => clearInterval(interval); // Cleanup on component unmount + }, []); + + const setData = useQueriesStore((state) => state.setData); + + useEffect(() => { + const fetchMarketItems = async () => { + if (entropyReady) { + const marketItems = (await gameContract!.call("get_items_on_market", [ + adventurer?.id!, + ])) as string[]; + const itemData = []; + console.log(marketItems); + for (let item of marketItems) { + itemData.unshift({ + item: gameData.ITEMS[parseInt(item)], + adventurerId: adventurer?.id, + owner: false, + equipped: false, + ownerAddress: adventurer?.owner, + xp: 0, + special1: null, + special2: null, + special3: null, + isAvailable: false, + purchasedTime: null, + timestamp: new Date(), + }); + } + setData("latestMarketItemsQuery", { + items: itemData, + }); + } + }; + + fetchMarketItems(); + }, [entropyReady]); + + console.log(entropyReady); + const gameData = new GameData(); const checkTransacting = @@ -361,11 +416,11 @@ export default function UpgradeScreen({ ); const getNoBoostedStats = async () => { - const stats = await gameContract?.call( - "get_base_stats", + const baseAdventurer = (await gameContract?.call( + "get_adventurer_no_boosts", CallData.compile({ token_id: adventurer?.id! }) - ); // check whether player can use the current token - setNonBoostedStats(stats); + )) as any; // check whether player can use the current token + setNonBoostedStats(baseAdventurer.stats); }; useEffect(() => { @@ -380,6 +435,7 @@ export default function UpgradeScreen({ return ( <> + {!entropyReady && } {hasStatUpgrades ? (
diff --git a/ui/src/app/hooks/useUIStore.ts b/ui/src/app/hooks/useUIStore.ts index 7c6ad9c30..3cb765ad4 100644 --- a/ui/src/app/hooks/useUIStore.ts +++ b/ui/src/app/hooks/useUIStore.ts @@ -87,10 +87,8 @@ type State = { setIsMintingLords: (value: boolean) => void; averageBlockTime: number; setAverageBlockTime: (value: number) => void; - updateDeathPenalty: boolean; - setUpdateDeathPenalty: (value: boolean) => void; - startPenalty: boolean; - setStartPenalty: (value: boolean) => void; + entropyReady: boolean; + setEntropyReady: (value: boolean) => void; }; const useUIStore = create((set) => ({ @@ -158,10 +156,8 @@ const useUIStore = create((set) => ({ setIsMintingLords: (value) => set({ isMintingLords: value }), averageBlockTime: 0, setAverageBlockTime: (value) => set({ averageBlockTime: value }), - updateDeathPenalty: false, - setUpdateDeathPenalty: (value) => set({ updateDeathPenalty: value }), - startPenalty: false, - setStartPenalty: (value) => set({ startPenalty: value }), + entropyReady: false, + setEntropyReady: (value) => set({ entropyReady: value }), })); export default useUIStore; diff --git a/ui/src/app/lib/burner.ts b/ui/src/app/lib/burner.ts index 9f2fa806e..8b6fe6ce4 100644 --- a/ui/src/app/lib/burner.ts +++ b/ui/src/app/lib/burner.ts @@ -16,7 +16,6 @@ import Storage from "@/app/lib/storage"; import { ArcadeConnector } from "@/app/lib/arcade"; import { BurnerStorage } from "@/app/types"; import { padAddress } from "@/app/lib/utils"; -import { TRANSACTION_WAIT_RETRY_INTERVAL } from "@/app/lib/constants"; const isMainnet = process.env.NEXT_PUBLIC_NETWORK == "mainnet"; const isSepolia = process.env.NEXT_PUBLIC_NETWORK == "sepolia"; @@ -168,9 +167,7 @@ export const useBurner = ({ const { transaction_hash } = await account.execute(prefundCalls); - const result = await provider.waitForTransaction(transaction_hash, { - retryInterval: TRANSACTION_WAIT_RETRY_INTERVAL, - }); + const result = await provider.waitForTransaction(transaction_hash); if (!result) { throw new Error("Transaction did not complete successfully."); @@ -378,9 +375,7 @@ export const useBurner = ({ ]), }); - const result = await provider.waitForTransaction(transaction_hash, { - retryInterval: TRANSACTION_WAIT_RETRY_INTERVAL, - }); + const result = await provider.waitForTransaction(transaction_hash); if (!result) { throw new Error("Transaction did not complete successfully."); @@ -415,9 +410,7 @@ export const useBurner = ({ }; const { transaction_hash } = await account.execute([lordsTransferTx]); - const result = await provider.waitForTransaction(transaction_hash, { - retryInterval: TRANSACTION_WAIT_RETRY_INTERVAL, - }); + const result = await provider.waitForTransaction(transaction_hash); if (!result) { throw new Error("Transaction did not complete successfully."); @@ -500,9 +493,7 @@ export const useBurner = ({ const { transaction_hash } = await account.execute(calls); - const result = await provider.waitForTransaction(transaction_hash, { - retryInterval: TRANSACTION_WAIT_RETRY_INTERVAL, - }); + const result = await provider.waitForTransaction(transaction_hash); if (!result) { throw new Error("Transaction did not complete successfully."); diff --git a/ui/src/app/lib/constants.ts b/ui/src/app/lib/constants.ts index 4a768458e..9c15658ea 100644 --- a/ui/src/app/lib/constants.ts +++ b/ui/src/app/lib/constants.ts @@ -28,13 +28,12 @@ let onMainnet = process.env.NEXT_PUBLIC_NETWORK === "mainnet"; let onSepolia = process.env.NEXT_PUBLIC_NETWORK === "sepolia"; // ---- CONTRACT PARAMS -// Penalty time is 12 blocks, where each block is ~ 15 seconds -export const penaltyTime = 420; export const itemCharismaDiscount = 1; export const itemBasePrice = 4; export const itemMinimumPrice = 1; export const potionCharismaDiscount = 2; export const potionBasePrice = 2; +export const VRF_FEE_LIMIT = 5000000000000000; // 0.005 ETH // UI PARAMS export const MIN_BALANCE = 100000000000000; // 0.00001ETH or $0.15 diff --git a/ui/src/app/lib/data/GameData.tsx b/ui/src/app/lib/data/GameData.tsx index 1a7e06fc3..16fdab114 100644 --- a/ui/src/app/lib/data/GameData.tsx +++ b/ui/src/app/lib/data/GameData.tsx @@ -1097,8 +1097,6 @@ export class GameData { HitByObstacle: "damage", Multicall: "purchaseItem", HitByBeast: "damage", - IdleDamagePenalty: "damage", - IdleDamagePenaltyDead: "die", Suicide: "die", }; @@ -1142,7 +1140,6 @@ export class GameData { AdventurerDied: hash.getSelectorFromName("AdventurerDied"), AdventurerLeveledUp: hash.getSelectorFromName("AdventurerLeveledUp"), UpgradesAvailable: hash.getSelectorFromName("UpgradesAvailable"), - IdleDeathPenalty: hash.getSelectorFromName("IdleDeathPenalty"), Transfer: hash.getSelectorFromName("Transfer"), }; diff --git a/ui/src/app/lib/utils/parseEvents.ts b/ui/src/app/lib/utils/parseEvents.ts index 2312e3a86..55ee87018 100644 --- a/ui/src/app/lib/utils/parseEvents.ts +++ b/ui/src/app/lib/utils/parseEvents.ts @@ -25,7 +25,6 @@ import { AdventurerDiedEvent, AdventurerLeveledUpEvent, UpgradesAvailableEvent, - IdleDeathPenaltyEvent, AdventurerUpgradedEvent, ERC721TransferEvent, } from "@/app/types/events"; @@ -36,64 +35,65 @@ function parseAdventurerState(data: string[]) { return { owner: data[0], adventurerId: parseInt(data[1]), + adventurerEntropy: data[2], adventurer: { - lastAction: parseInt(data[2]), - health: parseInt(data[3]), - xp: parseInt(data[4]), + lastAction: parseInt(data[3]), + health: parseInt(data[4]), + xp: parseInt(data[5]), stats: { - strength: parseInt(data[5]), - dexterity: parseInt(data[6]), - vitality: parseInt(data[7]), - intelligence: parseInt(data[8]), - wisdom: parseInt(data[9]), - charisma: parseInt(data[10]), - luck: parseInt(data[11]), + strength: parseInt(data[6]), + dexterity: parseInt(data[7]), + vitality: parseInt(data[8]), + intelligence: parseInt(data[9]), + wisdom: parseInt(data[10]), + charisma: parseInt(data[11]), + luck: parseInt(data[12]), }, - gold: parseInt(data[12]), + gold: parseInt(data[13]), weapon: { - id: parseInt(data[13]), - xp: parseInt(data[14]), - metadata: parseInt(data[15]), + id: parseInt(data[14]), + xp: parseInt(data[15]), + metadata: parseInt(data[16]), }, chest: { - id: parseInt(data[16]), - xp: parseInt(data[17]), - metadata: parseInt(data[18]), + id: parseInt(data[17]), + xp: parseInt(data[18]), + metadata: parseInt(data[19]), }, head: { - id: parseInt(data[19]), - xp: parseInt(data[20]), - metadata: parseInt(data[21]), + id: parseInt(data[20]), + xp: parseInt(data[21]), + metadata: parseInt(data[22]), }, waist: { - id: parseInt(data[22]), - xp: parseInt(data[23]), - metadata: parseInt(data[24]), + id: parseInt(data[23]), + xp: parseInt(data[24]), + metadata: parseInt(data[25]), }, foot: { - id: parseInt(data[25]), - xp: parseInt(data[26]), - metadata: parseInt(data[27]), + id: parseInt(data[26]), + xp: parseInt(data[27]), + metadata: parseInt(data[28]), }, hand: { - id: parseInt(data[28]), - xp: parseInt(data[29]), - metadata: parseInt(data[30]), + id: parseInt(data[29]), + xp: parseInt(data[30]), + metadata: parseInt(data[31]), }, neck: { - id: parseInt(data[31]), - xp: parseInt(data[32]), - metadata: parseInt(data[33]), + id: parseInt(data[32]), + xp: parseInt(data[33]), + metadata: parseInt(data[34]), }, ring: { - id: parseInt(data[34]), - xp: parseInt(data[35]), - metadata: parseInt(data[36]), + id: parseInt(data[35]), + xp: parseInt(data[36]), + metadata: parseInt(data[37]), }, - beastHealth: parseInt(data[37]), - statPointsAvailable: parseInt(data[38]), - actionsPerBlock: parseInt(data[39]), - mutated: convertToBoolean(parseInt(data[40])), + beastHealth: parseInt(data[38]), + statPointsAvailable: parseInt(data[39]), + actionsPerBlock: parseInt(data[40]), + mutated: convertToBoolean(parseInt(data[41])), }, }; } @@ -251,22 +251,22 @@ export async function parseEvents( switch (eventName) { case "StartGame": const startGameData: StartGameEvent = { - adventurerState: parseAdventurerState(raw.data.slice(0, 40)), + adventurerState: parseAdventurerState(raw.data.slice(0, 41)), adventurerMeta: { - startBlock: parseInt(raw.data[41]), + startBlock: parseInt(raw.data[42]), startingStats: { - strength: parseInt(raw.data[42]), - dexterity: parseInt(raw.data[43]), - vitality: parseInt(raw.data[44]), - intelligence: parseInt(raw.data[45]), - wisdom: parseInt(raw.data[46]), - charisma: parseInt(raw.data[47]), - luck: parseInt(raw.data[48]), + strength: parseInt(raw.data[43]), + dexterity: parseInt(raw.data[44]), + vitality: parseInt(raw.data[45]), + intelligence: parseInt(raw.data[46]), + wisdom: parseInt(raw.data[47]), + charisma: parseInt(raw.data[48]), + luck: parseInt(raw.data[49]), }, - name: parseInt(raw.data[49]), - interfaceCamel: convertToBoolean(parseInt(raw.data[50])), + name: parseInt(raw.data[50]), + interfaceCamel: convertToBoolean(parseInt(raw.data[51])), }, - revealBlock: parseInt(raw.data[51]), + revealBlock: parseInt(raw.data[52]), }; const startGameEvent = processData( startGameData, @@ -278,15 +278,15 @@ export async function parseEvents( case "AdventurerUpgraded": const upgradeAvailableData: AdventurerUpgradedEvent = { adventurerStateWithBag: { - adventurerState: parseAdventurerState(raw.data.slice(0, 40)), - bag: parseBag(raw.data.slice(41, 74)), + adventurerState: parseAdventurerState(raw.data.slice(0, 41)), + bag: parseBag(raw.data.slice(42, 75)), }, - strengthIncrease: parseInt(raw.data[75]), - dexterityIncrease: parseInt(raw.data[76]), - vitalityIncrease: parseInt(raw.data[77]), - intelligenceIncrease: parseInt(raw.data[78]), - wisdomIncrease: parseInt(raw.data[79]), - charismaIncrease: parseInt(raw.data[80]), + strengthIncrease: parseInt(raw.data[76]), + dexterityIncrease: parseInt(raw.data[77]), + vitalityIncrease: parseInt(raw.data[78]), + intelligenceIncrease: parseInt(raw.data[79]), + wisdomIncrease: parseInt(raw.data[80]), + charismaIncrease: parseInt(raw.data[81]), }; const upgradeAvailableEvent = processData( upgradeAvailableData, @@ -298,8 +298,8 @@ export async function parseEvents( break; case "DiscoveredHealth": const discoveredHealthData: DiscoveredHealthEvent = { - adventurerState: parseAdventurerState(raw.data.slice(0, 40)), - healthAmount: parseInt(raw.data[41]), + adventurerState: parseAdventurerState(raw.data.slice(0, 41)), + healthAmount: parseInt(raw.data[42]), }; const discoveredHealthEvent = processData( discoveredHealthData, @@ -311,8 +311,8 @@ export async function parseEvents( break; case "DiscoveredGold": const discoveredGoldData: DiscoveredGoldEvent = { - adventurerState: parseAdventurerState(raw.data.slice(0, 40)), - goldAmount: parseInt(raw.data[41]), + adventurerState: parseAdventurerState(raw.data.slice(0, 41)), + goldAmount: parseInt(raw.data[42]), }; const discoveredGoldEvent = processData( discoveredGoldData, @@ -324,8 +324,8 @@ export async function parseEvents( break; case "DiscoveredXP": const discoveredXPData: DiscoveredXPEvent = { - adventurerState: parseAdventurerState(raw.data.slice(0, 40)), - xpAmount: parseInt(raw.data[41]), + adventurerState: parseAdventurerState(raw.data.slice(0, 41)), + xpAmount: parseInt(raw.data[42]), }; const discoveredXPEvent = processData( discoveredXPData, @@ -337,13 +337,13 @@ export async function parseEvents( break; case "DodgedObstacle": const dodgedObstacleData: DodgedObstacleEvent = { - adventurerState: parseAdventurerState(raw.data.slice(0, 40)), - id: parseInt(raw.data[41]), - level: parseInt(raw.data[42]), - damageTaken: parseInt(raw.data[43]), - damageLocation: parseInt(raw.data[44]), - xpEarnedAdventurer: parseInt(raw.data[45]), - xpEarnedItems: parseInt(raw.data[46]), + adventurerState: parseAdventurerState(raw.data.slice(0, 41)), + id: parseInt(raw.data[42]), + level: parseInt(raw.data[43]), + damageTaken: parseInt(raw.data[44]), + damageLocation: parseInt(raw.data[45]), + xpEarnedAdventurer: parseInt(raw.data[46]), + xpEarnedItems: parseInt(raw.data[47]), }; const dodgedObstacleEvent = processData( dodgedObstacleData, @@ -355,13 +355,13 @@ export async function parseEvents( break; case "HitByObstacle": const hitByObstacleData: HitByObstacleEvent = { - adventurerState: parseAdventurerState(raw.data.slice(0, 40)), - id: parseInt(raw.data[41]), - level: parseInt(raw.data[42]), - damageTaken: parseInt(raw.data[43]), - damageLocation: parseInt(raw.data[44]), - xpEarnedAdventurer: parseInt(raw.data[45]), - xpEarnedItems: parseInt(raw.data[46]), + adventurerState: parseAdventurerState(raw.data.slice(0, 41)), + id: parseInt(raw.data[42]), + level: parseInt(raw.data[43]), + damageTaken: parseInt(raw.data[44]), + damageLocation: parseInt(raw.data[45]), + xpEarnedAdventurer: parseInt(raw.data[46]), + xpEarnedItems: parseInt(raw.data[47]), }; const hitByObstacleEvent = processData( hitByObstacleData, @@ -373,17 +373,17 @@ export async function parseEvents( break; case "DiscoveredBeast": const discoveredBeastData: DiscoveredBeastEvent = { - adventurerState: parseAdventurerState(raw.data.slice(0, 40)), - seed: parseInt(raw.data[41]), - id: parseInt(raw.data[42]), + adventurerState: parseAdventurerState(raw.data.slice(0, 41)), + seed: parseInt(raw.data[42]), + id: parseInt(raw.data[43]), beastSpecs: { - tier: parseInt(raw.data[43]), - itemType: parseInt(raw.data[44]), - level: parseInt(raw.data[45]), + tier: parseInt(raw.data[44]), + itemType: parseInt(raw.data[45]), + level: parseInt(raw.data[46]), specials: { - special1: parseInt(raw.data[46]), - special2: parseInt(raw.data[47]), - special3: parseInt(raw.data[48]), + special1: parseInt(raw.data[47]), + special2: parseInt(raw.data[48]), + special3: parseInt(raw.data[49]), }, }, }; @@ -397,22 +397,22 @@ export async function parseEvents( break; case "AmbushedByBeast": const ambushedByBeastData: AmbushedByBeastEvent = { - adventurerState: parseAdventurerState(raw.data.slice(0, 40)), - seed: parseInt(raw.data[41]), - id: parseInt(raw.data[42]), + adventurerState: parseAdventurerState(raw.data.slice(0, 41)), + seed: parseInt(raw.data[42]), + id: parseInt(raw.data[43]), beastSpecs: { - tier: parseInt(raw.data[43]), - itemType: parseInt(raw.data[44]), - level: parseInt(raw.data[45]), + tier: parseInt(raw.data[44]), + itemType: parseInt(raw.data[45]), + level: parseInt(raw.data[46]), specials: { - special1: parseInt(raw.data[46]), - special2: parseInt(raw.data[47]), - special3: parseInt(raw.data[48]), + special1: parseInt(raw.data[47]), + special2: parseInt(raw.data[48]), + special3: parseInt(raw.data[49]), }, }, - damage: parseInt(raw.data[49]), - criticalHit: convertToBoolean(parseInt(raw.data[50])), - location: parseInt(raw.data[51]), + damage: parseInt(raw.data[50]), + criticalHit: convertToBoolean(parseInt(raw.data[51])), + location: parseInt(raw.data[52]), }; const ambushedByBeastEvent = processData( ambushedByBeastData, @@ -424,22 +424,22 @@ export async function parseEvents( break; case "AttackedBeast": const attackedBeastData: AttackedBeastEvent = { - adventurerState: parseAdventurerState(raw.data.slice(0, 40)), - seed: parseInt(raw.data[41]), - id: parseInt(raw.data[42]), + adventurerState: parseAdventurerState(raw.data.slice(0, 41)), + seed: parseInt(raw.data[42]), + id: parseInt(raw.data[43]), beastSpecs: { - tier: parseInt(raw.data[43]), - itemType: parseInt(raw.data[44]), - level: parseInt(raw.data[45]), + tier: parseInt(raw.data[44]), + itemType: parseInt(raw.data[45]), + level: parseInt(raw.data[46]), specials: { - special1: parseInt(raw.data[46]), - special2: parseInt(raw.data[47]), - special3: parseInt(raw.data[48]), + special1: parseInt(raw.data[47]), + special2: parseInt(raw.data[48]), + special3: parseInt(raw.data[49]), }, }, - damage: parseInt(raw.data[49]), - criticalHit: convertToBoolean(parseInt(raw.data[50])), - location: parseInt(raw.data[51]), + damage: parseInt(raw.data[50]), + criticalHit: convertToBoolean(parseInt(raw.data[51])), + location: parseInt(raw.data[52]), }; const attackedBeastEvent = processData( attackedBeastData, @@ -451,22 +451,22 @@ export async function parseEvents( break; case "AttackedByBeast": const attackedByBeastData: AttackedByBeastEvent = { - adventurerState: parseAdventurerState(raw.data.slice(0, 40)), - seed: parseInt(raw.data[41]), - id: parseInt(raw.data[42]), + adventurerState: parseAdventurerState(raw.data.slice(0, 41)), + seed: parseInt(raw.data[42]), + id: parseInt(raw.data[43]), beastSpecs: { - tier: parseInt(raw.data[43]), - itemType: parseInt(raw.data[44]), - level: parseInt(raw.data[45]), + tier: parseInt(raw.data[44]), + itemType: parseInt(raw.data[45]), + level: parseInt(raw.data[46]), specials: { - special1: parseInt(raw.data[46]), - special2: parseInt(raw.data[47]), - special3: parseInt(raw.data[48]), + special1: parseInt(raw.data[47]), + special2: parseInt(raw.data[48]), + special3: parseInt(raw.data[49]), }, }, - damage: parseInt(raw.data[49]), - criticalHit: convertToBoolean(parseInt(raw.data[50])), - location: parseInt(raw.data[51]), + damage: parseInt(raw.data[50]), + criticalHit: convertToBoolean(parseInt(raw.data[51])), + location: parseInt(raw.data[52]), }; const attackedByBeastEvent = processData( attackedByBeastData, @@ -478,24 +478,24 @@ export async function parseEvents( break; case "SlayedBeast": const slayedBeastData: SlayedBeastEvent = { - adventurerState: parseAdventurerState(raw.data.slice(0, 40)), - seed: parseInt(raw.data[41]), - id: parseInt(raw.data[42]), + adventurerState: parseAdventurerState(raw.data.slice(0, 41)), + seed: parseInt(raw.data[42]), + id: parseInt(raw.data[43]), beastSpecs: { - tier: parseInt(raw.data[43]), - itemType: parseInt(raw.data[44]), - level: parseInt(raw.data[45]), + tier: parseInt(raw.data[44]), + itemType: parseInt(raw.data[45]), + level: parseInt(raw.data[46]), specials: { - special1: parseInt(raw.data[46]), - special2: parseInt(raw.data[47]), - special3: parseInt(raw.data[48]), + special1: parseInt(raw.data[47]), + special2: parseInt(raw.data[48]), + special3: parseInt(raw.data[49]), }, }, - damageDealt: parseInt(raw.data[49]), - criticalHit: convertToBoolean(parseInt(raw.data[50])), - xpEarnedAdventurer: parseInt(raw.data[51]), - xpEarnedItems: parseInt(raw.data[52]), - goldEarned: parseInt(raw.data[53]), + damageDealt: parseInt(raw.data[50]), + criticalHit: convertToBoolean(parseInt(raw.data[51])), + xpEarnedAdventurer: parseInt(raw.data[52]), + xpEarnedItems: parseInt(raw.data[53]), + goldEarned: parseInt(raw.data[54]), }; const slayedBeastEvent = processData( slayedBeastData, @@ -507,17 +507,17 @@ export async function parseEvents( break; case "FleeFailed": const fleeFailedData: FleeFailedEvent = { - adventurerState: parseAdventurerState(raw.data.slice(0, 40)), - seed: parseInt(raw.data[41]), - id: parseInt(raw.data[42]), + adventurerState: parseAdventurerState(raw.data.slice(0, 41)), + seed: parseInt(raw.data[42]), + id: parseInt(raw.data[43]), beastSpecs: { - tier: parseInt(raw.data[43]), - itemType: parseInt(raw.data[44]), - level: parseInt(raw.data[45]), + tier: parseInt(raw.data[44]), + itemType: parseInt(raw.data[45]), + level: parseInt(raw.data[46]), specials: { - special1: parseInt(raw.data[46]), - special2: parseInt(raw.data[47]), - special3: parseInt(raw.data[48]), + special1: parseInt(raw.data[47]), + special2: parseInt(raw.data[48]), + special3: parseInt(raw.data[49]), }, }, }; @@ -531,17 +531,17 @@ export async function parseEvents( break; case "FleeSucceeded": const fleeSucceededData: FleeSucceededEvent = { - adventurerState: parseAdventurerState(raw.data.slice(0, 40)), - seed: parseInt(raw.data[41]), - id: parseInt(raw.data[42]), + adventurerState: parseAdventurerState(raw.data.slice(0, 41)), + seed: parseInt(raw.data[42]), + id: parseInt(raw.data[43]), beastSpecs: { - tier: parseInt(raw.data[43]), - itemType: parseInt(raw.data[44]), - level: parseInt(raw.data[45]), + tier: parseInt(raw.data[44]), + itemType: parseInt(raw.data[45]), + level: parseInt(raw.data[46]), specials: { - special1: parseInt(raw.data[46]), - special2: parseInt(raw.data[47]), - special3: parseInt(raw.data[48]), + special1: parseInt(raw.data[47]), + special2: parseInt(raw.data[48]), + special3: parseInt(raw.data[49]), }, }, }; @@ -556,11 +556,11 @@ export async function parseEvents( case "PurchasedItems": const purchasedItemsData: PurchasedItemsEvent = { adventurerStateWithBag: { - adventurerState: parseAdventurerState(raw.data.slice(0, 40)), - bag: parseBag(raw.data.slice(41, 74)), + adventurerState: parseAdventurerState(raw.data.slice(0, 41)), + bag: parseBag(raw.data.slice(42, 75)), }, // Skip array length - purchases: parseItems(raw.data.slice(76)), + purchases: parseItems(raw.data.slice(77)), }; const purchasedItemsEvent = processData( purchasedItemsData, @@ -572,10 +572,10 @@ export async function parseEvents( break; case "PurchasedPotions": const purchasedPotionsData: PurchasedPotionsEvent = { - adventurerState: parseAdventurerState(raw.data.slice(0, 40)), - quantity: parseInt(raw.data[41]), - cost: parseInt(raw.data[42]), - health: parseInt(raw.data[43]), + adventurerState: parseAdventurerState(raw.data.slice(0, 41)), + quantity: parseInt(raw.data[42]), + cost: parseInt(raw.data[43]), + health: parseInt(raw.data[44]), }; const purchasedPotionsEvent = processData( purchasedPotionsData, @@ -588,12 +588,12 @@ export async function parseEvents( case "EquippedItems": const { equippedItems, unequippedItems } = parseEquippedItems( // Include equipped array length - raw.data.slice(75) + raw.data.slice(76) ); const equippedItemsData: EquippedItemsEvent = { adventurerStateWithBag: { - adventurerState: parseAdventurerState(raw.data.slice(0, 40)), - bag: parseBag(raw.data.slice(41, 74)), + adventurerState: parseAdventurerState(raw.data.slice(0, 41)), + bag: parseBag(raw.data.slice(42, 75)), }, equippedItems: equippedItems, unequippedItems: unequippedItems, @@ -609,14 +609,14 @@ export async function parseEvents( case "DroppedItems": const itemIds = []; // Skip array length - const itemsData = raw.data.slice(76); + const itemsData = raw.data.slice(77); for (let i = 0; i < itemsData.length; i++) { itemIds.push(parseInt(itemsData[i])); } const droppedItemsData: DroppedItemsEvent = { adventurerStateWithBag: { - adventurerState: parseAdventurerState(raw.data.slice(0, 40)), - bag: parseBag(raw.data.slice(41, 74)), + adventurerState: parseAdventurerState(raw.data.slice(0, 41)), + bag: parseBag(raw.data.slice(42, 75)), }, itemIds: itemIds, }; @@ -630,10 +630,10 @@ export async function parseEvents( break; case "GreatnessIncreased": const greatnessIncreasedData: GreatnessIncreasedEvent = { - adventurerState: parseAdventurerState(raw.data.slice(0, 40)), - itemId: parseInt(raw.data[41]), - previousLevel: parseInt(raw.data[42]), - newLevel: parseInt(raw.data[43]), + adventurerState: parseAdventurerState(raw.data.slice(0, 41)), + itemId: parseInt(raw.data[42]), + previousLevel: parseInt(raw.data[43]), + newLevel: parseInt(raw.data[44]), }; const greatnessIncreasedEvent = processData( greatnessIncreasedData, @@ -645,9 +645,9 @@ export async function parseEvents( break; case "ItemsLeveledUp": const itemsLeveledUpData: ItemsLeveledUpEvent = { - adventurerState: parseAdventurerState(raw.data.slice(0, 40)), + adventurerState: parseAdventurerState(raw.data.slice(0, 41)), // Skip items length - items: parseItemLevels(raw.data.slice(42)), + items: parseItemLevels(raw.data.slice(43)), }; const itemsLeveledUpEvent = processData( itemsLeveledUpData, @@ -659,8 +659,8 @@ export async function parseEvents( break; case "NewHighScore": const newHighScoreData: NewHighScoreEvent = { - adventurerState: parseAdventurerState(raw.data.slice(0, 40)), - rank: parseInt(raw.data[41]), + adventurerState: parseAdventurerState(raw.data.slice(0, 41)), + rank: parseInt(raw.data[42]), }; const newHighScoreEvent = processData( newHighScoreData, @@ -672,10 +672,10 @@ export async function parseEvents( break; case "AdventurerDied": const adventurerDiedData: AdventurerDiedEvent = { - adventurerState: parseAdventurerState(raw.data.slice(0, 40)), - killedByBeast: parseInt(raw.data[41]), - killedByObstacle: parseInt(raw.data[42]), - callerAddress: raw.data[43], + adventurerState: parseAdventurerState(raw.data.slice(0, 41)), + killedByBeast: parseInt(raw.data[42]), + killedByObstacle: parseInt(raw.data[43]), + callerAddress: raw.data[44], }; const adventurerDiedEvent = processData( adventurerDiedData, @@ -687,9 +687,9 @@ export async function parseEvents( break; case "AdventurerLeveledUp": const adventurerLeveledUpData: AdventurerLeveledUpEvent = { - adventurerState: parseAdventurerState(raw.data.slice(0, 40)), - previousLevel: parseInt(raw.data[41]), - newLevel: parseInt(raw.data[42]), + adventurerState: parseAdventurerState(raw.data.slice(0, 41)), + previousLevel: parseInt(raw.data[42]), + newLevel: parseInt(raw.data[43]), }; const adventurerLeveledUpEvent = processData( adventurerLeveledUpData, @@ -701,13 +701,13 @@ export async function parseEvents( break; case "UpgradesAvailable": // Skip array length - const newItems = raw.data.slice(42); + const newItems = raw.data.slice(43); const newItemsIds = []; for (let i = 0; i < newItems.length; i++) { newItemsIds.push(parseInt(newItems[i])); } const upgradesAvailableData: UpgradesAvailableEvent = { - adventurerState: parseAdventurerState(raw.data.slice(0, 40)), + adventurerState: parseAdventurerState(raw.data.slice(0, 41)), // Skip array length items: newItemsIds, }; @@ -719,21 +719,6 @@ export async function parseEvents( ); events.push({ name: eventName, data: upgradesAvailableEvent }); break; - case "IdleDeathPenalty": - const idleDeathPenaltyData: IdleDeathPenaltyEvent = { - adventurerState: parseAdventurerState(raw.data.slice(0, 40)), - idleBlocks: parseInt(raw.data[41]), - penaltyThreshold: parseInt(raw.data[42]), - caller: raw.data[43], - }; - const idleDeathPenaltyEvent = processData( - idleDeathPenaltyData, - eventName, - receipt.transaction_hash, - currentAdventurer - ); - events.push({ name: eventName, data: idleDeathPenaltyEvent }); - break; case "Transfer": const beastTransferData: ERC721TransferEvent = { from: raw.data[0], diff --git a/ui/src/app/lib/utils/processData.ts b/ui/src/app/lib/utils/processData.ts index 26e676550..c7c82965a 100644 --- a/ui/src/app/lib/utils/processData.ts +++ b/ui/src/app/lib/utils/processData.ts @@ -23,7 +23,6 @@ import { AdventurerDiedEvent, AdventurerLeveledUpEvent, UpgradesAvailableEvent, - IdleDeathPenaltyEvent, AdventurerUpgradedEvent, } from "@/app/types/events"; import { @@ -62,7 +61,6 @@ type EventData = | AdventurerDiedEvent | AdventurerLeveledUpEvent | UpgradesAvailableEvent - | IdleDeathPenaltyEvent | AdventurerUpgradedEvent; function processAdventurerState( @@ -73,6 +71,7 @@ function processAdventurerState( const updateAdventurerDoc: Adventurer = { id: data.adventurerState["adventurerId"], owner: data.adventurerState["owner"], + entropy: data.adventurerState["adventurerEntropy"], lastAction: data.adventurerState["adventurer"]["lastAction"], health: data.adventurerState["adventurer"]["health"], xp: data.adventurerState["adventurer"]["xp"], @@ -171,6 +170,7 @@ export function processData( const updateAdventurerDoc: Adventurer = { id: startGameEvent.adventurerState["adventurerId"], owner: startGameEvent.adventurerState["owner"], + entropy: startGameEvent.adventurerState["adventurerEntropy"], lastAction: startGameEvent.adventurerState["adventurer"]["lastAction"], health: startGameEvent.adventurerState["adventurer"]["health"], xp: startGameEvent.adventurerState["adventurer"]["xp"], @@ -893,63 +893,5 @@ export function processData( formattedNewItems.push(gameData.ITEMS[upgradesAvailableEvent.items[i]]); } return [upgradesAvailableData, formattedNewItems]; - case "IdleDeathPenalty": - const idleDeathPenaltyEvent = event as IdleDeathPenaltyEvent; - const penaltyAdventurerData = processAdventurerState( - idleDeathPenaltyEvent, - currentAdventurer - ); - const penaltyBattleData: Battle = { - txHash: txHash, - beast: undefined, - beastHealth: 0, - beastLevel: 0, - special1: undefined, - special2: undefined, - special3: undefined, - seed: 0, - adventurerId: idleDeathPenaltyEvent.adventurerState["adventurerId"], - adventurerHealth: - idleDeathPenaltyEvent.adventurerState["adventurer"]["health"], - attacker: undefined, - fled: undefined, - damageDealt: 0, - criticalHit: false, - damageTaken: 0, - damageLocation: undefined, - xpEarnedAdventurer: 0, - xpEarnedItems: 0, - goldEarned: 0, - discoveryTime: new Date(), - blockTime: new Date(), - timestamp: new Date(), - }; - const penaltyDiscoveryData: Discovery = { - txHash: txHash, - adventurerId: idleDeathPenaltyEvent.adventurerState["adventurerId"], - adventurerHealth: - idleDeathPenaltyEvent.adventurerState["adventurer"]["health"], - discoveryType: undefined, - subDiscoveryType: undefined, - outputAmount: 0, - obstacle: undefined, - obstacleLevel: undefined, - dodgedObstacle: false, - damageTaken: 0, - damageLocation: undefined, - xpEarnedAdventurer: undefined, - xpEarnedItems: undefined, - entity: undefined, - entityLevel: undefined, - entityHealth: 0, - special1: undefined, - special2: undefined, - special3: undefined, - ambushed: false, - seed: 0, - discoveryTime: new Date(), - timestamp: new Date(), - }; - return [penaltyAdventurerData, penaltyBattleData, penaltyDiscoveryData]; } } diff --git a/ui/src/app/lib/utils/syscalls.ts b/ui/src/app/lib/utils/syscalls.ts index 997b68a4f..3ab08ce17 100644 --- a/ui/src/app/lib/utils/syscalls.ts +++ b/ui/src/app/lib/utils/syscalls.ts @@ -34,7 +34,10 @@ import { import { QueryData, QueryKey } from "@/app/hooks/useQueryStore"; import { AdventurerClass } from "@/app/lib/classes"; import { ScreenPage } from "@/app/hooks/useUIStore"; -import { TRANSACTION_WAIT_RETRY_INTERVAL } from "@/app/lib/constants"; +import { + TRANSACTION_WAIT_RETRY_INTERVAL, + VRF_FEE_LIMIT, +} from "@/app/lib/constants"; const rpc_addr = process.env.NEXT_PUBLIC_RPC_URL; const provider = new Provider({ @@ -89,16 +92,14 @@ export interface SyscallsProps { ethBalance: bigint; showTopUpDialog: (value: boolean) => void; setTopUpAccount: (value: string) => void; - setEstimatingFee: (value: boolean) => void; account: AccountInterface; - resetCalls: () => void; setSpecialBeastDefeated: (value: boolean) => void; setSpecialBeast: (value: SpecialBeast) => void; connector?: Connector; getEthBalance: () => Promise; getBalances: () => Promise; setIsMintingLords: (value: boolean) => void; - setUpdateDeathPenalty: (value: boolean) => void; + setEntropyReady: (value: boolean) => void; } function handleEquip( @@ -199,15 +200,13 @@ export function syscalls({ ethBalance, showTopUpDialog, setTopUpAccount, - setEstimatingFee, - resetCalls, setSpecialBeastDefeated, setSpecialBeast, connector, getEthBalance, getBalances, setIsMintingLords, - setUpdateDeathPenalty, + setEntropyReady, }: SyscallsProps) { const gameData = new GameData(); @@ -304,6 +303,7 @@ export function syscalls({ goldenTokenId, "0", interfaceCamel, + VRF_FEE_LIMIT.toString(), ], }; @@ -370,6 +370,7 @@ export function syscalls({ createdTime: new Date(), } ); + console.log(startGameEvents); const adventurerState = events.find( (event) => event.name === "AmbushedByBeast" ).data[0]; @@ -596,19 +597,6 @@ export function syscalls({ } } - const idleDeathPenaltyEvents = events.filter( - (event) => event.name === "IdleDeathPenalty" - ); - if (idleDeathPenaltyEvents.length > 0) { - for (let idleDeathPenaltyEvent of idleDeathPenaltyEvents) { - setData("adventurerByIdQuery", { - adventurers: [idleDeathPenaltyEvent.data[0]], - }); - setAdventurer(idleDeathPenaltyEvent.data[0]); - discoveries.unshift(idleDeathPenaltyEvent.data[2]); - } - } - const reversedDiscoveries = discoveries.slice().reverse(); const adventurerDiedEvents = events.filter( @@ -628,13 +616,10 @@ export function syscalls({ const killedByObstacle = reversedDiscoveries[0]?.discoveryType == "Obstacle" && reversedDiscoveries[0]?.adventurerHealth == 0; - const killedByPenalty = - !reversedDiscoveries[0]?.discoveryType && - reversedDiscoveries[0]?.adventurerHealth == 0; const killedByAmbush = reversedDiscoveries[0]?.ambushed && reversedDiscoveries[0]?.adventurerHealth == 0; - if (killedByObstacle || killedByPenalty || killedByAmbush) { + if (killedByObstacle || killedByAmbush) { setDeathNotification( "Explore", discoveries.reverse(), @@ -645,37 +630,10 @@ export function syscalls({ setStartOption("create adventurer"); } - const upgradesAvailableEvents = events.filter( - (event) => event.name === "UpgradesAvailable" + const leveledUpEvents = events.filter( + (event) => event.name === "AdventurerLeveledUp" ); - if (upgradesAvailableEvents.length > 0) { - for (let upgradesAvailableEvent of upgradesAvailableEvents) { - setData("adventurerByIdQuery", { - adventurers: [upgradesAvailableEvent.data[0]], - }); - setAdventurer(upgradesAvailableEvent.data[0]); - const newItems = upgradesAvailableEvent.data[1]; - const itemData = []; - for (let newItem of newItems) { - itemData.unshift({ - item: newItem, - adventurerId: upgradesAvailableEvent.data[0]["id"], - owner: false, - equipped: false, - ownerAddress: upgradesAvailableEvent.data[0]["owner"], - xp: 0, - special1: null, - special2: null, - special3: null, - isAvailable: false, - purchasedTime: null, - timestamp: new Date(), - }); - } - setData("latestMarketItemsQuery", { - items: itemData, - }); - } + if (leveledUpEvents.length > 0) { setScreen("upgrade"); } @@ -693,7 +651,6 @@ export function syscalls({ setDropItems([]); stopLoading(reversedDiscoveries, false, "Explore"); getEthBalance(); - setUpdateDeathPenalty(true); } catch (e) { console.log(e); stopLoading(e, true); @@ -876,19 +833,6 @@ export function syscalls({ } } - const idleDeathPenaltyEvents = events.filter( - (event) => event.name === "IdleDeathPenalty" - ); - if (idleDeathPenaltyEvents.length > 0) { - for (let idleDeathPenaltyEvent of idleDeathPenaltyEvents) { - setData("adventurerByIdQuery", { - adventurers: [idleDeathPenaltyEvent.data[0]], - }); - setAdventurer(idleDeathPenaltyEvent.data[0]); - battles.unshift(idleDeathPenaltyEvent.data[1]); - } - } - const reversedBattles = battles.slice().reverse(); const adventurerDiedEvents = events.filter( @@ -908,10 +852,7 @@ export function syscalls({ const killedByBeast = battles.some( (battle) => battle.attacker == "Beast" && battle.adventurerHealth == 0 ); - const killedByPenalty = battles.some( - (battle) => !battle.attacker && battle.adventurerHealth == 0 - ); - if (killedByBeast || killedByPenalty) { + if (killedByBeast) { setDeathNotification( "Attack", reversedBattles, @@ -922,37 +863,10 @@ export function syscalls({ setStartOption("create adventurer"); } - const upgradesAvailableEvents = events.filter( - (event) => event.name === "UpgradesAvailable" + const leveledUpEvents = events.filter( + (event) => event.name === "AdventurerLeveledUp" ); - if (upgradesAvailableEvents.length > 0) { - for (let upgradesAvailableEvent of upgradesAvailableEvents) { - setData("adventurerByIdQuery", { - adventurers: [upgradesAvailableEvent.data[0]], - }); - setAdventurer(upgradesAvailableEvent.data[0]); - const newItems = upgradesAvailableEvent.data[1]; - const itemData = []; - for (let newItem of newItems) { - itemData.unshift({ - item: newItem, - adventurerId: upgradesAvailableEvent.data[0]["id"], - owner: false, - equipped: false, - ownerAddress: upgradesAvailableEvent.data[0]["owner"], - xp: 0, - special1: null, - special2: null, - special3: null, - isAvailable: false, - purchasedTime: null, - timestamp: new Date(), - }); - } - setData("latestMarketItemsQuery", { - items: itemData, - }); - } + if (leveledUpEvents.length > 0) { setScreen("upgrade"); } @@ -976,7 +890,7 @@ export function syscalls({ setEquipItems([]); setDropItems([]); getEthBalance(); - setUpdateDeathPenalty(true); + setEntropyReady(false); } catch (e) { console.log(e); stopLoading(e, true); @@ -1078,19 +992,6 @@ export function syscalls({ battles.unshift(fleeSucceededEvent.data[1]); } - const idleDeathPenaltyEvents = events.filter( - (event) => event.name === "IdleDeathPenalty" - ); - if (idleDeathPenaltyEvents.length > 0) { - for (let idleDeathPenaltyEvent of idleDeathPenaltyEvents) { - setData("adventurerByIdQuery", { - adventurers: [idleDeathPenaltyEvent.data[0]], - }); - setAdventurer(idleDeathPenaltyEvent.data[0]); - battles.unshift(idleDeathPenaltyEvent.data[1]); - } - } - const reversedBattles = battles.slice().reverse(); const adventurerDiedEvents = events.filter( @@ -1110,10 +1011,7 @@ export function syscalls({ const killedByBeast = battles.some( (battle) => battle.attacker == "Beast" && battle.adventurerHealth == 0 ); - const killedByPenalty = battles.some( - (battle) => !battle.attacker && battle.adventurerHealth == 0 - ); - if (killedByBeast || killedByPenalty) { + if (killedByBeast) { setDeathNotification( "Flee", reversedBattles, @@ -1124,33 +1022,10 @@ export function syscalls({ setStartOption("create adventurer"); } - const upgradesAvailableEvents = events.filter( - (event) => event.name === "UpgradesAvailable" + const leveledUpEvents = events.filter( + (event) => event.name === "AdventurerLeveledUp" ); - if (upgradesAvailableEvents.length > 0) { - for (let upgradesAvailableEvent of upgradesAvailableEvents) { - const newItems = upgradesAvailableEvent.data[1]; - const itemData = []; - for (let newItem of newItems) { - itemData.unshift({ - item: newItem, - adventurerId: upgradesAvailableEvent.data[0]["id"], - owner: false, - equipped: false, - ownerAddress: upgradesAvailableEvent.data[0]["owner"], - xp: 0, - special1: null, - special2: null, - special3: null, - isAvailable: false, - purchasedTime: null, - timestamp: new Date(), - }); - } - setData("latestMarketItemsQuery", { - items: itemData, - }); - } + if (leveledUpEvents.length > 0) { setScreen("upgrade"); } @@ -1173,7 +1048,6 @@ export function syscalls({ setEquipItems([]); setDropItems([]); getEthBalance(); - setUpdateDeathPenalty(true); } catch (e) { console.log(e); stopLoading(e, true); @@ -1293,47 +1167,27 @@ export function syscalls({ items: [...filteredDrops, ...purchasedItems], }); - const adventurerDiedEvents = events.filter( - (event) => event.name === "AdventurerDied" - ); - if (adventurerDiedEvents.length > 0) { - for (let adventurerDiedEvent of adventurerDiedEvents) { - setData("adventurerByIdQuery", { - adventurers: [adventurerDiedEvent.data[0]], - }); - const deadAdventurerIndex = - queryData.adventurersByOwnerQuery?.adventurers.findIndex( - (adventurer: Adventurer) => - adventurer.id == adventurerDiedEvent.data[0].id - ); - setData("adventurersByOwnerQuery", 0, "health", deadAdventurerIndex); - setAdventurer(adventurerDiedEvent.data[0]); - setDeathNotification("Upgrade", "Death Penalty"); - setScreen("start"); - setStartOption("create adventurer"); - } - } + console.log({ + Stats: upgrades, + Items: purchaseItems, + Potions: potionAmount, + }); // Reset items to no availability setData("latestMarketItemsQuery", null); - if (events.some((event) => event.name === "AdventurerDied")) { - setScreen("start"); - setStartOption("create adventurer"); - stopLoading("Death Penalty"); - } else { - stopLoading( - { - Stats: upgrades, - Items: purchaseItems, - Potions: potionAmount, - }, - false, - "Upgrade" - ); - setScreen("play"); - } + stopLoading( + { + Stats: upgrades, + Items: purchaseItems, + Potions: potionAmount, + }, + false, + "Upgrade" + ); + setScreen("play"); + getEthBalance(); - setUpdateDeathPenalty(true); + setEntropyReady(false); } catch (e) { console.log(e); stopLoading(e, true); @@ -1531,15 +1385,12 @@ export function syscalls({ (battle) => battle.attacker == "Beast" && battle.adventurerHealth == 0 ); - // In a multicall someone can either die from swapping inventory or the death penalty. Here we handle those cases if (killedByBeast) { setDeathNotification( "Multicall", ["You equipped"], adventurerDiedEvent.data[0] ); - } else { - setDeathNotification("Upgrade", "Death Penalty"); } setScreen("start"); setStartOption("create adventurer"); @@ -1575,7 +1426,6 @@ export function syscalls({ // Reset items to no availability setData("latestMarketItemsQuery", null); setScreen("play"); - setUpdateDeathPenalty(true); } const droppedItems = handleDrop(events, setData, setAdventurer); @@ -1633,8 +1483,8 @@ export function syscalls({ const mintLords = async () => { const mintLords: Call = { contractAddress: lordsContract?.address ?? "", - entrypoint: "mint_lords", - calldata: [], + entrypoint: "mint", + calldata: [account.address, "50000000000000000000000", "0"], }; const isArcade = checkArcadeConnector(connector!); try { diff --git a/ui/src/app/page.tsx b/ui/src/app/page.tsx index fd39254cf..27bbbcbd5 100644 --- a/ui/src/app/page.tsx +++ b/ui/src/app/page.tsx @@ -148,7 +148,6 @@ function Home({ updateConnectors }: HomeProps) { const topUpDialog = useUIStore((state) => state.topUpDialog); const showTopUpDialog = useUIStore((state) => state.showTopUpDialog); const setTopUpAccount = useUIStore((state) => state.setTopUpAccount); - const setEstimatingFee = useUIStore((state) => state.setEstimatingFee); const setSpecialBeast = useUIStore((state) => state.setSpecialBeast); const setIsMintingLords = useUIStore((state) => state.setIsMintingLords); const hash = useLoadingStore((state) => state.hash); @@ -193,9 +192,7 @@ function Home({ updateConnectors }: HomeProps) { const setDeathMessage = useLoadingStore((state) => state.setDeathMessage); const showDeathDialog = useUIStore((state) => state.showDeathDialog); const setStartOption = useUIStore((state) => state.setStartOption); - const setUpdateDeathPenalty = useUIStore( - (state) => state.setUpdateDeathPenalty - ); + const setEntropyReady = useUIStore((state) => state.setEntropyReady); const [accountChainId, setAccountChainId] = useState< constants.StarknetChainId | undefined >(); @@ -264,16 +261,14 @@ function Home({ updateConnectors }: HomeProps) { ethBalance: ethBalance, showTopUpDialog, setTopUpAccount, - setEstimatingFee, account: account!, - resetCalls, setSpecialBeastDefeated, setSpecialBeast, connector, getEthBalance, getBalances, setIsMintingLords, - setUpdateDeathPenalty, + setEntropyReady, }); const playState = useMemo( diff --git a/ui/src/app/types/events.ts b/ui/src/app/types/events.ts index d30dcc051..88e1709ca 100644 --- a/ui/src/app/types/events.ts +++ b/ui/src/app/types/events.ts @@ -113,6 +113,7 @@ type ContractAddress = string; export type AdventurerState = { owner: ContractAddress; adventurerId: u128; + adventurerEntropy: string; adventurer: Adventurer; }; @@ -306,13 +307,6 @@ export type UpgradesAvailableEvent = { items: number[]; }; -export type IdleDeathPenaltyEvent = { - adventurerState: AdventurerState; - idleBlocks: u16; - penaltyThreshold: u16; - caller: ContractAddress; -}; - export type AdventurerUpgradedEvent = { adventurerStateWithBag: AdventurerStateWithBag; strengthIncrease: u8; diff --git a/ui/src/app/types/index.ts b/ui/src/app/types/index.ts index 5eda4fa90..a4b88f188 100644 --- a/ui/src/app/types/index.ts +++ b/ui/src/app/types/index.ts @@ -6,6 +6,7 @@ export interface Adventurer { [key: string]: number | string | Date | undefined; id?: number; // Adventurer ID lastAction?: number; // Block number from last action + entropy?: string; // Entropy of the adventurer owner?: string; // Hex address of the owner classType?: string; // Class of the adventurer homeRealm?: number; // Home Realm of the adventurer From 5cfe76bcb660259fdba83a3eaedb3e0671255ea1 Mon Sep 17 00:00:00 2001 From: Starknet Dev Date: Fri, 24 May 2024 08:51:08 +0100 Subject: [PATCH 02/18] update env variables --- ui/.env.preview | 8 ++++---- ui/.env.production | 4 ++-- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/ui/.env.preview b/ui/.env.preview index 9f24bc390..5f5147202 100644 --- a/ui/.env.preview +++ b/ui/.env.preview @@ -1,12 +1,12 @@ NEXT_PUBLIC_NETWORK=sepolia -NEXT_PUBLIC_RPC_URL=https://starknet-sepolia.blastapi.io/efb20d63-c5e0-4f5d-ab72-ef7add92779f -NEXT_PUBLIC_RPC_API_KEY=efb20d63-c5e0-4f5d-ab72-ef7add92779f +NEXT_PUBLIC_RPC_URL=https://starknet-sepolia.blastapi.io/5ef61753-e7c1-4593-bc62-97fdf96f8de5 +NEXT_PUBLIC_RPC_API_KEY=5ef61753-e7c1-4593-bc62-97fdf96f8de5 NEXT_PUBLIC_LS_GQL_URL=https://survivor-sepolia-indexer.realms.world/graphql NEXT_PUBLIC_TOKENS_GQL_URL=https://testnet.realms.world/api/graphql NEXT_PUBLIC_ETH_ADDRESS=0x049d36570d4e46f48e99674bd3fcc84644ddd6b96f7c741b1562b82f9e004dc7 -NEXT_PUBLIC_GAME_ADDRESS=0x02b66531874c952844913b8cbc573878c794112b546cbf39409013e33d4777fe +NEXT_PUBLIC_GAME_ADDRESS=0x06c63851635f1e0ee0695a157292892cabaa030a8eca20a32b6a86c968c47c33 NEXT_PUBLIC_OLD_GAME_ADDRESS=0x0 -NEXT_PUBLIC_LORDS_ADDRESS=0x019c92fa87f4d5e3be25c3dd6a284f30282a07e87cd782f5fd387b82c8142017 +NEXT_PUBLIC_LORDS_ADDRESS=0x024cadb6d8592309d08a7a4e3b00017f8431759ee6c3d09b2ce37c693c786da7 NEXT_PUBLIC_BEASTS_ADDRESS=0x020c7c02c973ffa3a48fb78e9472b679c72c11b59512f524154ade0a39f54136 NEXT_PUBLIC_GOLDEN_TOKEN_ADDRESS=0x07626660faba349aad9ad2aaa0ff8645c079fa8e043a168d640d92472806eeac NEXT_PUBLIC_ARCADE_ACCOUNT_CLASS_HASH=0x0251830adc3d8b4d818c2c309d71f1958308e8c745212480c26e01120c69ee49 diff --git a/ui/.env.production b/ui/.env.production index a241d67fc..ad4cd2eb4 100644 --- a/ui/.env.production +++ b/ui/.env.production @@ -1,6 +1,6 @@ NEXT_PUBLIC_NETWORK=mainnet -NEXT_PUBLIC_RPC_URL=https://starknet-mainnet.g.alchemy.com/v2/cEfO6n3pAtw6ThcuhH-ixLdqXykEO51z -NEXT_PUBLIC_RPC_API_KEY=cEfO6n3pAtw6ThcuhH-ixLdqXykEO51z +NEXT_PUBLIC_RPC_URL=https://starknet-sepolia.blastapi.io/5ef61753-e7c1-4593-bc62-97fdf96f8de5 +NEXT_PUBLIC_RPC_API_KEY=5ef61753-e7c1-4593-bc62-97fdf96f8de5 NEXT_PUBLIC_LS_GQL_URL=https://survivor-mainnet-indexer.realms.world/graphql NEXT_PUBLIC_TOKENS_GQL_URL=https://realmsworld-8gqj4xan8-loot-bibliotheca.vercel.app/api/graphql NEXT_PUBLIC_ETH_ADDRESS=0x049d36570d4e46f48e99674bd3fcc84644ddd6b96f7c741b1562b82f9e004dc7 From c92ef2e424a7af40c56ba6e4f1e5d42eed0e9ca6 Mon Sep 17 00:00:00 2001 From: Starknet Dev Date: Fri, 24 May 2024 09:12:31 +0100 Subject: [PATCH 03/18] only call beast entropy on level 1 --- ui/src/app/containers/BeastScreen.tsx | 24 +++++++++++++----------- 1 file changed, 13 insertions(+), 11 deletions(-) diff --git a/ui/src/app/containers/BeastScreen.tsx b/ui/src/app/containers/BeastScreen.tsx index 759b31e5b..8717ad8c4 100644 --- a/ui/src/app/containers/BeastScreen.tsx +++ b/ui/src/app/containers/BeastScreen.tsx @@ -173,18 +173,20 @@ export default function BeastScreen({ ); useEffect(() => { - const interval = setInterval(async () => { - const entropy = await gameContract!.call("get_adventurer_entropy", [ - adventurer?.id!, - ]); - console.log(entropy); - if (entropy !== BigInt(0)) { - setEntropyReady(true); - clearInterval(interval); - } - }, 10000); // We call the getAdventurerEntropy function every 30 seconds + if (adventurer?.level == 1) { + const interval = setInterval(async () => { + const entropy = await gameContract!.call("get_adventurer_entropy", [ + adventurer?.id!, + ]); + console.log(entropy); + if (entropy !== BigInt(0)) { + setEntropyReady(true); + clearInterval(interval); + } + }, 10000); // We call the getAdventurerEntropy function every 30 seconds - return () => clearInterval(interval); // Cleanup on component unmount + return () => clearInterval(interval); // Cleanup on component unmount + } }, []); console.log(entropyReady); From 3981b9d91faeca7822f294a7c7423ba1284192a1 Mon Sep 17 00:00:00 2001 From: Starknet Dev Date: Fri, 24 May 2024 15:19:56 +0100 Subject: [PATCH 04/18] fix best screen interlude popup --- ui/src/app/containers/BeastScreen.tsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ui/src/app/containers/BeastScreen.tsx b/ui/src/app/containers/BeastScreen.tsx index 8717ad8c4..8fda4fec8 100644 --- a/ui/src/app/containers/BeastScreen.tsx +++ b/ui/src/app/containers/BeastScreen.tsx @@ -197,7 +197,7 @@ export default function BeastScreen({ return (
- {!entropyReady && } + {adventurer?.level == 1 && !entropyReady && }
{hasBeast ? ( From 6c3ce9287167abdbac3c6051e66c539a4c2422c8 Mon Sep 17 00:00:00 2001 From: Starknet Dev Date: Sun, 26 May 2024 11:18:36 +0100 Subject: [PATCH 05/18] update graphql domain --- indexer/graphql/src/indexer/graphql.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/indexer/graphql/src/indexer/graphql.py b/indexer/graphql/src/indexer/graphql.py index 124b453ef..34fca33dd 100644 --- a/indexer/graphql/src/indexer/graphql.py +++ b/indexer/graphql/src/indexer/graphql.py @@ -1605,8 +1605,8 @@ async def run_graphql_api(mongo=None, port="8080"): ssl_context = ssl.create_default_context(ssl.Purpose.CLIENT_AUTH) ssl_context.load_cert_chain( - "/etc/letsencrypt/live/survivor-sepolia-indexer.realms.world/fullchain.pem", - "/etc/letsencrypt/live/survivor-sepolia-indexer.realms.world/privkey.pem", + "/etc/letsencrypt/live/ls-indexer-sepolia.provable.games/fullchain.pem", + "/etc/letsencrypt/live/ls-indexer-sepolia.provable.games/privkey.pem", ) runner = web.AppRunner(app) From c1cb52bfa43da3e81a76ba6222f00183e419dfe8 Mon Sep 17 00:00:00 2001 From: Starknet Dev Date: Mon, 27 May 2024 20:12:09 +0100 Subject: [PATCH 06/18] - update abi - increase max stats on all to 31 - increase max health - update indexer events with new contract changes --- .gitignore | 1 + indexer/graphql/src/indexer/graphql.py | 8 +- indexer/src/adventurers.ts | 22 +- indexer/src/utils/events.ts | 37 +- indexer/src/utils/helpers.ts | 62 +-- ui/src/app/abi/Game.json | 508 +++++++++++++----- .../app/components/upgrade/StatAttribute.tsx | 3 +- ui/src/app/containers/UpgradeScreen.tsx | 2 +- ui/src/app/lib/utils/parseEvents.ts | 463 ++++++++-------- ui/src/app/lib/utils/processData.ts | 96 ++-- ui/src/app/types/events.ts | 35 +- 11 files changed, 746 insertions(+), 491 deletions(-) diff --git a/.gitignore b/.gitignore index c758e9bb5..29d137ef6 100644 --- a/.gitignore +++ b/.gitignore @@ -13,6 +13,7 @@ contracts/beasts/target/CACHEDIR.TAG keys account ls1.5.pem +ls1.5-2.pem contracts/game_entropy/target/CACHEDIR.TAG contracts/game_entropy/target/dev/game_entropy.sierra diff --git a/indexer/graphql/src/indexer/graphql.py b/indexer/graphql/src/indexer/graphql.py index 34fca33dd..eba5db332 100644 --- a/indexer/graphql/src/indexer/graphql.py +++ b/indexer/graphql/src/indexer/graphql.py @@ -908,7 +908,6 @@ class ItemsOrderByInput: class Adventurer: id: Optional[FeltValue] entropy: Optional[HexValue] - lastAction: Optional[FeltValue] owner: Optional[HexValue] name: Optional[StringValue] health: Optional[FeltValue] @@ -930,9 +929,8 @@ class Adventurer: ring: Optional[ItemValue] beastHealth: Optional[FeltValue] statUpgrades: Optional[FeltValue] - startBlock: Optional[FeltValue] + startEntropy: Optional[FeltValue] revealBlock: Optional[FeltValue] - actionsPerBlock: Optional[FeltValue] gold: Optional[FeltValue] createdTime: Optional[str] lastUpdatedTime: Optional[str] @@ -943,7 +941,6 @@ def from_mongo(cls, data): return cls( id=data["id"], entropy=data["entropy"], - lastAction=data["lastAction"], owner=data["owner"], name=data["name"], health=data["health"], @@ -965,9 +962,8 @@ def from_mongo(cls, data): ring=data["ring"], beastHealth=data["beastHealth"], statUpgrades=data["statUpgrades"], - startBlock=data["startBlock"], + startEntropy=data["startEntropy"], revealBlock=data["revealBlock"], - actionsPerBlock=data["actionsPerBlock"], gold=data["gold"], createdTime=data["createdTime"], lastUpdatedTime=data["lastUpdatedTime"], diff --git a/indexer/src/adventurers.ts b/indexer/src/adventurers.ts index 2bc6681b4..87c103073 100644 --- a/indexer/src/adventurers.ts +++ b/indexer/src/adventurers.ts @@ -108,7 +108,6 @@ export default function transform({ header, events }: Block) { id: as.adventurerId, owner: as.owner, entropy: as.adventurerEntropy, - lastAction: as.adventurer.lastActionBlock, health: as.adventurer.health, xp: as.adventurer.xp, strength: as.adventurer.stats.strength, @@ -119,19 +118,18 @@ export default function transform({ header, events }: Block) { charisma: as.adventurer.stats.charisma, luck: as.adventurer.stats.luck, gold: as.adventurer.gold, - weapon: as.adventurer.weapon.id, - chest: as.adventurer.chest.id, - head: as.adventurer.head.id, - waist: as.adventurer.waist.id, - foot: as.adventurer.foot.id, - hand: as.adventurer.hand.id, - neck: as.adventurer.neck.id, - ring: as.adventurer.ring.id, + weapon: as.adventurer.equipment.weapon.id, + chest: as.adventurer.equipment.chest.id, + head: as.adventurer.equipment.head.id, + waist: as.adventurer.equipment.waist.id, + foot: as.adventurer.equipment.foot.id, + hand: as.adventurer.equipment.hand.id, + neck: as.adventurer.equipment.neck.id, + ring: as.adventurer.equipment.ring.id, beastHealth: as.adventurer.beastHealth, - statUpgrades: as.adventurer.statsPointsAvailable, - actionsPerBlock: as.adventurer.actionsPerBlock, + statUpgrades: as.adventurer.statsUpgradesAvailable, name: am.name, - startBlock: am.startBlock, + startEntropy: am.startEntropy, revealBlock: value.revealBlock, createdTime: new Date().toISOString(), lastUpdatedTime: new Date().toISOString(), diff --git a/indexer/src/utils/events.ts b/indexer/src/utils/events.ts index 58669790b..3d183b39a 100644 --- a/indexer/src/utils/events.ts +++ b/indexer/src/utils/events.ts @@ -61,7 +61,6 @@ export const parseStats = combineParsers({ export const parseLootStatistics = combineParsers({ id: { index: 0, parser: parseU8 }, xp: { index: 1, parser: parseU16 }, - metadata: { index: 2, parser: parseU8 }, }); export const parseLoot = combineParsers({ @@ -76,24 +75,26 @@ export const parseLootWithPrice = combineParsers({ price: { index: 1, parser: parseU16 }, }); +export const parseEquipment = combineParsers({ + weapon: { index: 0, parser: parseLootStatistics }, + chest: { index: 1, parser: parseLootStatistics }, + head: { index: 2, parser: parseLootStatistics }, + waist: { index: 3, parser: parseLootStatistics }, + foot: { index: 4, parser: parseLootStatistics }, + hand: { index: 5, parser: parseLootStatistics }, + neck: { index: 6, parser: parseLootStatistics }, + ring: { index: 7, parser: parseLootStatistics }, +}); + export const parseAdventurer = combineParsers({ - lastActionBlock: { index: 0, parser: parseU16 }, - health: { index: 1, parser: parseU16 }, - xp: { index: 2, parser: parseU16 }, - stats: { index: 3, parser: parseStats }, + health: { index: 0, parser: parseU16 }, + xp: { index: 1, parser: parseU16 }, + beastHealth: { index: 2, parser: parseU16 }, + statsUpgradesAvailable: { index: 3, parser: parseU8 }, gold: { index: 4, parser: parseU16 }, - weapon: { index: 5, parser: parseLootStatistics }, - chest: { index: 6, parser: parseLootStatistics }, - head: { index: 7, parser: parseLootStatistics }, - waist: { index: 8, parser: parseLootStatistics }, - foot: { index: 9, parser: parseLootStatistics }, - hand: { index: 10, parser: parseLootStatistics }, - neck: { index: 11, parser: parseLootStatistics }, - ring: { index: 12, parser: parseLootStatistics }, - beastHealth: { index: 13, parser: parseU16 }, - statsPointsAvailable: { index: 14, parser: parseU8 }, - actionsPerBlock: { index: 15, parser: parseU8 }, - mutated: { index: 16, parser: parseBoolean }, + stats: { index: 5, parser: parseStats }, + equipment: { index: 6, parser: parseEquipment }, + mutated: { index: 7, parser: parseBoolean }, }); export const parseAdventurerState = combineParsers({ @@ -173,7 +174,7 @@ export const parseAdventurerDied = combineParsers({ }); export const parseAdventurerMetadata = combineParsers({ - startBlock: { index: 0, parser: parseU128 }, + startEntropy: { index: 0, parser: parseU128 }, startingStats: { index: 1, parser: parseStats }, name: { index: 2, parser: parseU128 }, interfaceCamel: { index: 3, parser: parseBoolean }, diff --git a/indexer/src/utils/helpers.ts b/indexer/src/utils/helpers.ts index acb50bc36..65919ef84 100644 --- a/indexer/src/utils/helpers.ts +++ b/indexer/src/utils/helpers.ts @@ -5,7 +5,6 @@ export function insertAdventurer({ id, owner, entropy, - lastAction, health, xp, strength, @@ -25,9 +24,8 @@ export function insertAdventurer({ ring, beastHealth, statUpgrades, - actionsPerBlock, name, - startBlock, + startEntropy, revealBlock, createdTime, lastUpdatedTime, @@ -44,7 +42,6 @@ export function insertAdventurer({ $set: { ...entity, entropy: encodeIntAsBytes(BigInt(entropy)), - lastAction: encodeIntAsBytes(BigInt(lastAction)), health: encodeIntAsBytes(BigInt(health)), xp: encodeIntAsBytes(BigInt(xp)), strength: encodeIntAsBytes(BigInt(strength)), @@ -64,9 +61,8 @@ export function insertAdventurer({ ring: checkExistsInt(BigInt(ring)), beastHealth: encodeIntAsBytes(BigInt(beastHealth)), statUpgrades: checkExistsInt(BigInt(statUpgrades)), - actionsPerBlock: encodeIntAsBytes(BigInt(actionsPerBlock)), name: checkExistsInt(BigInt(name)), - startBlock: encodeIntAsBytes(BigInt(startBlock)), + startEntropy: encodeIntAsBytes(BigInt(startEntropy)), revealBlock: encodeIntAsBytes(BigInt(revealBlock)), createdTime: createdTime, lastUpdatedTime: lastUpdatedTime, @@ -174,7 +170,6 @@ export function updateAdventurer({ $set: { ...entity, entropy: encodeIntAsBytes(BigInt(adventurerState.adventurerEntropy)), - lastAction: encodeIntAsBytes(BigInt(adventurer.lastActionBlock)), health: encodeIntAsBytes(BigInt(adventurer.health)), xp: encodeIntAsBytes(BigInt(adventurer.xp)), strength: encodeIntAsBytes(BigInt(adventurer.stats.strength)), @@ -185,17 +180,18 @@ export function updateAdventurer({ charisma: encodeIntAsBytes(BigInt(adventurer.stats.charisma)), luck: encodeIntAsBytes(BigInt(adventurer.stats.luck)), gold: encodeIntAsBytes(BigInt(adventurer.gold)), - weapon: checkExistsInt(BigInt(adventurer.weapon.id)), - chest: checkExistsInt(BigInt(adventurer.chest.id)), - head: checkExistsInt(BigInt(adventurer.head.id)), - waist: checkExistsInt(BigInt(adventurer.waist.id)), - foot: checkExistsInt(BigInt(adventurer.foot.id)), - hand: checkExistsInt(BigInt(adventurer.hand.id)), - neck: checkExistsInt(BigInt(adventurer.neck.id)), - ring: checkExistsInt(BigInt(adventurer.ring.id)), + weapon: checkExistsInt(BigInt(adventurer.equipment.weapon.id)), + chest: checkExistsInt(BigInt(adventurer.equipment.chest.id)), + head: checkExistsInt(BigInt(adventurer.equipment.head.id)), + waist: checkExistsInt(BigInt(adventurer.equipment.waist.id)), + foot: checkExistsInt(BigInt(adventurer.equipment.foot.id)), + hand: checkExistsInt(BigInt(adventurer.equipment.hand.id)), + neck: checkExistsInt(BigInt(adventurer.equipment.neck.id)), + ring: checkExistsInt(BigInt(adventurer.equipment.ring.id)), beastHealth: encodeIntAsBytes(BigInt(adventurer.beastHealth)), - statUpgrades: encodeIntAsBytes(BigInt(adventurer.statsPointsAvailable)), - actionsPerBlock: encodeIntAsBytes(BigInt(adventurer.actionsPerBlock)), + statUpgrades: encodeIntAsBytes( + BigInt(adventurer.statsUpgradesAvailable) + ), lastUpdatedTime: timestamp, timestamp, }, @@ -434,58 +430,58 @@ export function updateItemsXP({ const itemUpdates: any[] = []; itemUpdates.push( updateItemXP({ - item: adventurer.weapon.id, + item: adventurer.equipment.weapon.id, adventurerId: adventurerState.adventurerId, - xp: adventurer.weapon.xp, + xp: adventurer.equipment.weapon.xp, }) ); itemUpdates.push( updateItemXP({ - item: adventurer.chest.id, + item: adventurer.equipment.chest.id, adventurerId: adventurerState.adventurerId, - xp: adventurer.chest.xp, + xp: adventurer.equipment.chest.xp, }) ); itemUpdates.push( updateItemXP({ - item: adventurer.head.id, + item: adventurer.equipment.head.id, adventurerId: adventurerState.adventurerId, - xp: adventurer.head.xp, + xp: adventurer.equipment.head.xp, }) ); itemUpdates.push( updateItemXP({ - item: adventurer.waist.id, + item: adventurer.equipment.waist.id, adventurerId: adventurerState.adventurerId, - xp: adventurer.waist.xp, + xp: adventurer.equipment.waist.xp, }) ); itemUpdates.push( updateItemXP({ - item: adventurer.foot.id, + item: adventurer.equipment.foot.id, adventurerId: adventurerState.adventurerId, - xp: adventurer.foot.xp, + xp: adventurer.equipment.foot.xp, }) ); itemUpdates.push( updateItemXP({ - item: adventurer.hand.id, + item: adventurer.equipment.hand.id, adventurerId: adventurerState.adventurerId, - xp: adventurer.hand.xp, + xp: adventurer.equipment.hand.xp, }) ); itemUpdates.push( updateItemXP({ - item: adventurer.neck.id, + item: adventurer.equipment.neck.id, adventurerId: adventurerState.adventurerId, - xp: adventurer.neck.xp, + xp: adventurer.equipment.neck.xp, }) ); itemUpdates.push( updateItemXP({ - item: adventurer.ring.id, + item: adventurer.equipment.ring.id, adventurerId: adventurerState.adventurerId, - xp: adventurer.ring.xp, + xp: adventurer.equipment.ring.xp, }) ); const filteredUpdates = itemUpdates.filter((value) => value !== undefined); diff --git a/ui/src/app/abi/Game.json b/ui/src/app/abi/Game.json index bd6f11c59..24bee1bee 100644 --- a/ui/src/app/abi/Game.json +++ b/ui/src/app/abi/Game.json @@ -43,7 +43,7 @@ ] }, { - "name": "survivor::stats::Stats", + "name": "adventurer::stats::Stats", "type": "struct", "members": [ { @@ -91,7 +91,7 @@ ] }, { - "name": "survivor::item_primitive::ItemPrimitive", + "name": "adventurer::item::Item", "type": "struct", "members": [ { @@ -101,80 +101,78 @@ { "name": "xp", "type": "core::integer::u16" - }, - { - "name": "metadata", - "type": "core::integer::u8" } ] }, { - "name": "survivor::adventurer::Adventurer", + "name": "adventurer::equipment::Equipment", "type": "struct", "members": [ - { - "name": "last_action_block", - "type": "core::integer::u16" - }, - { - "name": "health", - "type": "core::integer::u16" - }, - { - "name": "xp", - "type": "core::integer::u16" - }, - { - "name": "stats", - "type": "survivor::stats::Stats" - }, - { - "name": "gold", - "type": "core::integer::u16" - }, { "name": "weapon", - "type": "survivor::item_primitive::ItemPrimitive" + "type": "adventurer::item::Item" }, { "name": "chest", - "type": "survivor::item_primitive::ItemPrimitive" + "type": "adventurer::item::Item" }, { "name": "head", - "type": "survivor::item_primitive::ItemPrimitive" + "type": "adventurer::item::Item" }, { "name": "waist", - "type": "survivor::item_primitive::ItemPrimitive" + "type": "adventurer::item::Item" }, { "name": "foot", - "type": "survivor::item_primitive::ItemPrimitive" + "type": "adventurer::item::Item" }, { "name": "hand", - "type": "survivor::item_primitive::ItemPrimitive" + "type": "adventurer::item::Item" }, { "name": "neck", - "type": "survivor::item_primitive::ItemPrimitive" + "type": "adventurer::item::Item" }, { "name": "ring", - "type": "survivor::item_primitive::ItemPrimitive" + "type": "adventurer::item::Item" + } + ] + }, + { + "name": "adventurer::adventurer::Adventurer", + "type": "struct", + "members": [ + { + "name": "health", + "type": "core::integer::u16" + }, + { + "name": "xp", + "type": "core::integer::u16" + }, + { + "name": "gold", + "type": "core::integer::u16" }, { "name": "beast_health", "type": "core::integer::u16" }, { - "name": "stat_points_available", + "name": "stat_upgrades_available", "type": "core::integer::u8" }, { - "name": "actions_per_block", - "type": "core::integer::u8" + "name": "stats", + "type": "adventurer::stats::Stats" + }, + { + "name": "equipment", + "type": "adventurer::equipment::Equipment" }, { "name": "mutated", @@ -183,142 +181,90 @@ ] }, { - "name": "survivor::adventurer_meta::AdventurerMetadata", + "name": "adventurer::adventurer_meta::AdventurerMetadata", "type": "struct", "members": [ { - "name": "start_block", + "name": "start_entropy", "type": "core::integer::u64" }, { "name": "starting_stats", - "type": "survivor::stats::Stats" - }, - { - "name": "name", - "type": "core::integer::u128" + "type": "adventurer::stats::Stats" }, { "name": "interface_camel", "type": "core::bool" + }, + { + "name": "name", + "type": "core::integer::u128" } ] }, { - "name": "survivor::bag::Bag", + "name": "adventurer::bag::Bag", "type": "struct", "members": [ { "name": "item_1", - "type": "survivor::item_primitive::ItemPrimitive" + "type": "adventurer::item::Item" }, { "name": "item_2", - "type": "survivor::item_primitive::ItemPrimitive" + "type": "adventurer::item::Item" }, { "name": "item_3", - "type": "survivor::item_primitive::ItemPrimitive" + "type": "adventurer::item::Item" }, { "name": "item_4", - "type": "survivor::item_primitive::ItemPrimitive" + "type": "adventurer::item::Item" }, { "name": "item_5", - "type": "survivor::item_primitive::ItemPrimitive" + "type": "adventurer::item::Item" }, { "name": "item_6", - "type": "survivor::item_primitive::ItemPrimitive" + "type": "adventurer::item::Item" }, { "name": "item_7", - "type": "survivor::item_primitive::ItemPrimitive" + "type": "adventurer::item::Item" }, { "name": "item_8", - "type": "survivor::item_primitive::ItemPrimitive" + "type": "adventurer::item::Item" }, { "name": "item_9", - "type": "survivor::item_primitive::ItemPrimitive" + "type": "adventurer::item::Item" }, { "name": "item_10", - "type": "survivor::item_primitive::ItemPrimitive" + "type": "adventurer::item::Item" }, { "name": "item_11", - "type": "survivor::item_primitive::ItemPrimitive" - }, - { - "name": "mutated", - "type": "core::bool" - } - ] - }, - { - "name": "survivor::item_meta::ItemSpecials", - "type": "struct", - "members": [ - { - "name": "special1", - "type": "core::integer::u8" - }, - { - "name": "special2", - "type": "core::integer::u8" - }, - { - "name": "special3", - "type": "core::integer::u8" - } - ] - }, - { - "name": "survivor::item_meta::ItemSpecialsStorage", - "type": "struct", - "members": [ - { - "name": "item_1", - "type": "survivor::item_meta::ItemSpecials" - }, - { - "name": "item_2", - "type": "survivor::item_meta::ItemSpecials" - }, - { - "name": "item_3", - "type": "survivor::item_meta::ItemSpecials" - }, - { - "name": "item_4", - "type": "survivor::item_meta::ItemSpecials" - }, - { - "name": "item_5", - "type": "survivor::item_meta::ItemSpecials" - }, - { - "name": "item_6", - "type": "survivor::item_meta::ItemSpecials" + "type": "adventurer::item::Item" }, { - "name": "item_7", - "type": "survivor::item_meta::ItemSpecials" + "name": "item_12", + "type": "adventurer::item::Item" }, { - "name": "item_8", - "type": "survivor::item_meta::ItemSpecials" + "name": "item_13", + "type": "adventurer::item::Item" }, { - "name": "item_9", - "type": "survivor::item_meta::ItemSpecials" + "name": "item_14", + "type": "adventurer::item::Item" }, { - "name": "item_10", - "type": "survivor::item_meta::ItemSpecials" + "name": "item_15", + "type": "adventurer::item::Item" }, { "name": "mutated", @@ -445,7 +391,7 @@ ] }, { - "name": "survivor::leaderboard::Score", + "name": "adventurer::leaderboard::Score", "type": "struct", "members": [ { @@ -463,20 +409,20 @@ ] }, { - "name": "survivor::leaderboard::Leaderboard", + "name": "adventurer::leaderboard::Leaderboard", "type": "struct", "members": [ { "name": "first", - "type": "survivor::leaderboard::Score" + "type": "adventurer::leaderboard::Score" }, { "name": "second", - "type": "survivor::leaderboard::Score" + "type": "adventurer::leaderboard::Score" }, { "name": "third", - "type": "survivor::leaderboard::Score" + "type": "adventurer::leaderboard::Score" } ] }, @@ -645,7 +591,7 @@ }, { "name": "stat_upgrades", - "type": "survivor::stats::Stats" + "type": "adventurer::stats::Stats" }, { "name": "items", @@ -673,7 +619,7 @@ ], "outputs": [ { - "type": "survivor::adventurer::Adventurer" + "type": "adventurer::adventurer::Adventurer" } ], "state_mutability": "view" @@ -705,7 +651,7 @@ ], "outputs": [ { - "type": "survivor::adventurer::Adventurer" + "type": "adventurer::adventurer::Adventurer" } ], "state_mutability": "view" @@ -721,7 +667,7 @@ ], "outputs": [ { - "type": "survivor::adventurer_meta::AdventurerMetadata" + "type": "adventurer::adventurer_meta::AdventurerMetadata" } ], "state_mutability": "view" @@ -806,6 +752,182 @@ ], "state_mutability": "view" }, + { + "name": "get_stats", + "type": "function", + "inputs": [ + { + "name": "adventurer_id", + "type": "core::felt252" + } + ], + "outputs": [ + { + "type": "adventurer::stats::Stats" + } + ], + "state_mutability": "view" + }, + { + "name": "get_base_stats", + "type": "function", + "inputs": [ + { + "name": "adventurer_id", + "type": "core::felt252" + } + ], + "outputs": [ + { + "type": "adventurer::stats::Stats" + } + ], + "state_mutability": "view" + }, + { + "name": "get_equipped_items", + "type": "function", + "inputs": [ + { + "name": "adventurer_id", + "type": "core::felt252" + } + ], + "outputs": [ + { + "type": "core::array::Array::" + } + ], + "state_mutability": "view" + }, + { + "name": "get_weapon_greatness", + "type": "function", + "inputs": [ + { + "name": "adventurer_id", + "type": "core::felt252" + } + ], + "outputs": [ + { + "type": "core::integer::u8" + } + ], + "state_mutability": "view" + }, + { + "name": "get_chest_greatness", + "type": "function", + "inputs": [ + { + "name": "adventurer_id", + "type": "core::felt252" + } + ], + "outputs": [ + { + "type": "core::integer::u8" + } + ], + "state_mutability": "view" + }, + { + "name": "get_head_greatness", + "type": "function", + "inputs": [ + { + "name": "adventurer_id", + "type": "core::felt252" + } + ], + "outputs": [ + { + "type": "core::integer::u8" + } + ], + "state_mutability": "view" + }, + { + "name": "get_waist_greatness", + "type": "function", + "inputs": [ + { + "name": "adventurer_id", + "type": "core::felt252" + } + ], + "outputs": [ + { + "type": "core::integer::u8" + } + ], + "state_mutability": "view" + }, + { + "name": "get_foot_greatness", + "type": "function", + "inputs": [ + { + "name": "adventurer_id", + "type": "core::felt252" + } + ], + "outputs": [ + { + "type": "core::integer::u8" + } + ], + "state_mutability": "view" + }, + { + "name": "get_hand_greatness", + "type": "function", + "inputs": [ + { + "name": "adventurer_id", + "type": "core::felt252" + } + ], + "outputs": [ + { + "type": "core::integer::u8" + } + ], + "state_mutability": "view" + }, + { + "name": "get_necklace_greatness", + "type": "function", + "inputs": [ + { + "name": "adventurer_id", + "type": "core::felt252" + } + ], + "outputs": [ + { + "type": "core::integer::u8" + } + ], + "state_mutability": "view" + }, + { + "name": "get_ring_greatness", + "type": "function", + "inputs": [ + { + "name": "adventurer_id", + "type": "core::felt252" + } + ], + "outputs": [ + { + "type": "core::integer::u8" + } + ], + "state_mutability": "view" + }, { "name": "get_bag", "type": "function", @@ -817,13 +939,29 @@ ], "outputs": [ { - "type": "survivor::bag::Bag" + "type": "adventurer::bag::Bag" + } + ], + "state_mutability": "view" + }, + { + "name": "get_items_on_market", + "type": "function", + "inputs": [ + { + "name": "adventurer_id", + "type": "core::felt252" + } + ], + "outputs": [ + { + "type": "core::array::Array::" } ], "state_mutability": "view" }, { - "name": "get_special_storage", + "name": "get_items_on_market_by_slot", "type": "function", "inputs": [ { @@ -831,24 +969,28 @@ "type": "core::felt252" }, { - "name": "storage_index", + "name": "slot", "type": "core::integer::u8" } ], "outputs": [ { - "type": "survivor::item_meta::ItemSpecialsStorage" + "type": "core::array::Array::" } ], "state_mutability": "view" }, { - "name": "get_items_on_market", + "name": "get_items_on_market_by_tier", "type": "function", "inputs": [ { "name": "adventurer_id", "type": "core::felt252" + }, + { + "name": "tier", + "type": "core::integer::u8" } ], "outputs": [ @@ -858,6 +1000,42 @@ ], "state_mutability": "view" }, + { + "name": "get_potion_price", + "type": "function", + "inputs": [ + { + "name": "adventurer_id", + "type": "core::felt252" + } + ], + "outputs": [ + { + "type": "core::integer::u16" + } + ], + "state_mutability": "view" + }, + { + "name": "get_item_price", + "type": "function", + "inputs": [ + { + "name": "adventurer_id", + "type": "core::felt252" + }, + { + "name": "item_id", + "type": "core::integer::u8" + } + ], + "outputs": [ + { + "type": "core::integer::u16" + } + ], + "state_mutability": "view" + }, { "name": "get_attacking_beast", "type": "function", @@ -966,7 +1144,7 @@ "inputs": [], "outputs": [ { - "type": "survivor::leaderboard::Leaderboard" + "type": "adventurer::leaderboard::Leaderboard" } ], "state_mutability": "view" @@ -1056,7 +1234,7 @@ }, { "name": "adventurer", - "type": "survivor::adventurer::Adventurer" + "type": "adventurer::adventurer::Adventurer" } ] }, @@ -1073,7 +1251,7 @@ { "kind": "data", "name": "adventurer_meta", - "type": "survivor::adventurer_meta::AdventurerMetadata" + "type": "adventurer::adventurer_meta::AdventurerMetadata" }, { "kind": "data", @@ -1447,7 +1625,7 @@ }, { "name": "bag", - "type": "survivor::bag::Bag" + "type": "adventurer::bag::Bag" } ] }, @@ -1494,7 +1672,7 @@ ] }, { - "name": "lootitems::loot::Loot", + "name": "loot::loot::Loot", "type": "struct", "members": [ { @@ -1521,7 +1699,7 @@ "members": [ { "name": "item", - "type": "lootitems::loot::Loot" + "type": "loot::loot::Loot" }, { "name": "price", @@ -1680,7 +1858,7 @@ }, { "name": "specials", - "type": "survivor::item_meta::ItemSpecials" + "type": "combat::combat::SpecialPowers" } ] }, @@ -1848,6 +2026,50 @@ } ] }, + { + "kind": "struct", + "name": "game::Game::ReceivedEntropy", + "type": "event", + "members": [ + { + "kind": "data", + "name": "adventurer_id", + "type": "core::felt252" + }, + { + "kind": "data", + "name": "vrf_address", + "type": "core::starknet::contract_address::ContractAddress" + }, + { + "kind": "data", + "name": "rnd", + "type": "core::felt252" + } + ] + }, + { + "kind": "struct", + "name": "game::Game::ClearedEntropy", + "type": "event", + "members": [ + { + "kind": "data", + "name": "adventurer_id", + "type": "core::felt252" + }, + { + "kind": "data", + "name": "vrf_address", + "type": "core::starknet::contract_address::ContractAddress" + }, + { + "kind": "data", + "name": "seed", + "type": "core::integer::u64" + } + ] + }, { "kind": "enum", "name": "game::Game::Event", @@ -1972,6 +2194,16 @@ "kind": "nested", "name": "PriceChangeEvent", "type": "game::Game::PriceChangeEvent" + }, + { + "kind": "nested", + "name": "ReceivedEntropy", + "type": "game::Game::ReceivedEntropy" + }, + { + "kind": "nested", + "name": "ClearedEntropy", + "type": "game::Game::ClearedEntropy" } ] } diff --git a/ui/src/app/components/upgrade/StatAttribute.tsx b/ui/src/app/components/upgrade/StatAttribute.tsx index 95d4d809d..6a9cb3fb4 100644 --- a/ui/src/app/components/upgrade/StatAttribute.tsx +++ b/ui/src/app/components/upgrade/StatAttribute.tsx @@ -43,8 +43,7 @@ export const StatAttribute = ({ amount + ((adventurer?.statUpgrades ?? 0) - upgradesTotal); const maxNonBoosted = - (nonBoostedStat ?? BigInt(0)) + BigInt(amount) >= - (name === "Strength" || name === "Vitality" ? BigInt(31) : BigInt(15)); + (nonBoostedStat ?? BigInt(0)) + BigInt(amount) >= BigInt(31); useEffect(() => { if (buttonClicked) { diff --git a/ui/src/app/containers/UpgradeScreen.tsx b/ui/src/app/containers/UpgradeScreen.tsx index 0aa7effee..113cf190c 100644 --- a/ui/src/app/containers/UpgradeScreen.tsx +++ b/ui/src/app/containers/UpgradeScreen.tsx @@ -344,7 +344,7 @@ export default function UpgradeScreen({ adventurerItems ); - const maxHealth = Math.min(100 + totalVitality * 10, 511); + const maxHealth = Math.min(100 + totalVitality * 10, 1023); const newMaxHealth = 100 + (totalVitality - vitBoostRemoved) * 10; const currentHealth = adventurer?.health! + selectedVitality * 10; const healthPlusPots = Math.min( diff --git a/ui/src/app/lib/utils/parseEvents.ts b/ui/src/app/lib/utils/parseEvents.ts index 55ee87018..10087b101 100644 --- a/ui/src/app/lib/utils/parseEvents.ts +++ b/ui/src/app/lib/utils/parseEvents.ts @@ -37,63 +37,55 @@ function parseAdventurerState(data: string[]) { adventurerId: parseInt(data[1]), adventurerEntropy: data[2], adventurer: { - lastAction: parseInt(data[3]), - health: parseInt(data[4]), - xp: parseInt(data[5]), + health: parseInt(data[3]), + xp: parseInt(data[4]), + gold: parseInt(data[5]), + beastHealth: parseInt(data[6]), + statUpgradesAvailable: parseInt(data[7]), stats: { - strength: parseInt(data[6]), - dexterity: parseInt(data[7]), - vitality: parseInt(data[8]), - intelligence: parseInt(data[9]), - wisdom: parseInt(data[10]), - charisma: parseInt(data[11]), - luck: parseInt(data[12]), - }, - gold: parseInt(data[13]), - weapon: { - id: parseInt(data[14]), - xp: parseInt(data[15]), - metadata: parseInt(data[16]), - }, - chest: { - id: parseInt(data[17]), - xp: parseInt(data[18]), - metadata: parseInt(data[19]), - }, - head: { - id: parseInt(data[20]), - xp: parseInt(data[21]), - metadata: parseInt(data[22]), - }, - waist: { - id: parseInt(data[23]), - xp: parseInt(data[24]), - metadata: parseInt(data[25]), - }, - foot: { - id: parseInt(data[26]), - xp: parseInt(data[27]), - metadata: parseInt(data[28]), - }, - hand: { - id: parseInt(data[29]), - xp: parseInt(data[30]), - metadata: parseInt(data[31]), + strength: parseInt(data[8]), + dexterity: parseInt(data[9]), + vitality: parseInt(data[10]), + intelligence: parseInt(data[11]), + wisdom: parseInt(data[12]), + charisma: parseInt(data[13]), + luck: parseInt(data[14]), }, - neck: { - id: parseInt(data[32]), - xp: parseInt(data[33]), - metadata: parseInt(data[34]), + equipment: { + weapon: { + id: parseInt(data[15]), + xp: parseInt(data[16]), + }, + chest: { + id: parseInt(data[17]), + xp: parseInt(data[18]), + }, + head: { + id: parseInt(data[19]), + xp: parseInt(data[20]), + }, + waist: { + id: parseInt(data[21]), + xp: parseInt(data[22]), + }, + foot: { + id: parseInt(data[23]), + xp: parseInt(data[24]), + }, + hand: { + id: parseInt(data[25]), + xp: parseInt(data[26]), + }, + neck: { + id: parseInt(data[27]), + xp: parseInt(data[28]), + }, + ring: { + id: parseInt(data[29]), + xp: parseInt(data[30]), + }, }, - ring: { - id: parseInt(data[35]), - xp: parseInt(data[36]), - metadata: parseInt(data[37]), - }, - beastHealth: parseInt(data[38]), - statPointsAvailable: parseInt(data[39]), - actionsPerBlock: parseInt(data[40]), - mutated: convertToBoolean(parseInt(data[41])), + mutated: convertToBoolean(parseInt(data[31])), }, }; } @@ -103,59 +95,64 @@ function parseBag(data: string[]) { item1: { id: parseInt(data[0]), xp: parseInt(data[1]), - metadata: parseInt(data[2]), }, item2: { - id: parseInt(data[3]), - xp: parseInt(data[4]), - metadata: parseInt(data[5]), + id: parseInt(data[2]), + xp: parseInt(data[3]), }, item3: { - id: parseInt(data[6]), - xp: parseInt(data[7]), - metadata: parseInt(data[8]), + id: parseInt(data[4]), + xp: parseInt(data[5]), }, item4: { - id: parseInt(data[9]), - xp: parseInt(data[10]), - metadata: parseInt(data[11]), + id: parseInt(data[6]), + xp: parseInt(data[7]), }, item5: { - id: parseInt(data[12]), - xp: parseInt(data[13]), - metadata: parseInt(data[14]), + id: parseInt(data[8]), + xp: parseInt(data[9]), }, item6: { - id: parseInt(data[15]), - xp: parseInt(data[16]), - metadata: parseInt(data[17]), + id: parseInt(data[10]), + xp: parseInt(data[11]), }, item7: { - id: parseInt(data[18]), - xp: parseInt(data[19]), - metadata: parseInt(data[20]), + id: parseInt(data[12]), + xp: parseInt(data[13]), }, item8: { - id: parseInt(data[21]), - xp: parseInt(data[22]), - metadata: parseInt(data[23]), + id: parseInt(data[14]), + xp: parseInt(data[15]), }, item9: { - id: parseInt(data[24]), - xp: parseInt(data[25]), - metadata: parseInt(data[26]), + id: parseInt(data[16]), + xp: parseInt(data[17]), }, item10: { - id: parseInt(data[27]), - xp: parseInt(data[28]), - metadata: parseInt(data[29]), + id: parseInt(data[18]), + xp: parseInt(data[19]), }, item11: { - id: parseInt(data[30]), - xp: parseInt(data[31]), - metadata: parseInt(data[32]), + id: parseInt(data[20]), + xp: parseInt(data[21]), + }, + item12: { + id: parseInt(data[22]), + xp: parseInt(data[23]), + }, + item13: { + id: parseInt(data[24]), + xp: parseInt(data[25]), + }, + item14: { + id: parseInt(data[26]), + xp: parseInt(data[27]), + }, + item15: { + id: parseInt(data[28]), + xp: parseInt(data[29]), }, - mutated: convertToBoolean(parseInt(data[33])), + mutated: convertToBoolean(parseInt(data[30])), }; } @@ -251,22 +248,22 @@ export async function parseEvents( switch (eventName) { case "StartGame": const startGameData: StartGameEvent = { - adventurerState: parseAdventurerState(raw.data.slice(0, 41)), + adventurerState: parseAdventurerState(raw.data.slice(0, 31)), adventurerMeta: { - startBlock: parseInt(raw.data[42]), + startEntropy: parseInt(raw.data[32]), startingStats: { - strength: parseInt(raw.data[43]), - dexterity: parseInt(raw.data[44]), - vitality: parseInt(raw.data[45]), - intelligence: parseInt(raw.data[46]), - wisdom: parseInt(raw.data[47]), - charisma: parseInt(raw.data[48]), - luck: parseInt(raw.data[49]), + strength: parseInt(raw.data[33]), + dexterity: parseInt(raw.data[34]), + vitality: parseInt(raw.data[35]), + intelligence: parseInt(raw.data[36]), + wisdom: parseInt(raw.data[37]), + charisma: parseInt(raw.data[38]), + luck: parseInt(raw.data[39]), }, - name: parseInt(raw.data[50]), - interfaceCamel: convertToBoolean(parseInt(raw.data[51])), + interfaceCamel: convertToBoolean(parseInt(raw.data[40])), + name: parseInt(raw.data[41]), }, - revealBlock: parseInt(raw.data[52]), + revealBlock: parseInt(raw.data[42]), }; const startGameEvent = processData( startGameData, @@ -278,15 +275,15 @@ export async function parseEvents( case "AdventurerUpgraded": const upgradeAvailableData: AdventurerUpgradedEvent = { adventurerStateWithBag: { - adventurerState: parseAdventurerState(raw.data.slice(0, 41)), - bag: parseBag(raw.data.slice(42, 75)), + adventurerState: parseAdventurerState(raw.data.slice(0, 31)), + bag: parseBag(raw.data.slice(32, 63)), }, - strengthIncrease: parseInt(raw.data[76]), - dexterityIncrease: parseInt(raw.data[77]), - vitalityIncrease: parseInt(raw.data[78]), - intelligenceIncrease: parseInt(raw.data[79]), - wisdomIncrease: parseInt(raw.data[80]), - charismaIncrease: parseInt(raw.data[81]), + strengthIncrease: parseInt(raw.data[64]), + dexterityIncrease: parseInt(raw.data[65]), + vitalityIncrease: parseInt(raw.data[66]), + intelligenceIncrease: parseInt(raw.data[67]), + wisdomIncrease: parseInt(raw.data[68]), + charismaIncrease: parseInt(raw.data[69]), }; const upgradeAvailableEvent = processData( upgradeAvailableData, @@ -298,8 +295,8 @@ export async function parseEvents( break; case "DiscoveredHealth": const discoveredHealthData: DiscoveredHealthEvent = { - adventurerState: parseAdventurerState(raw.data.slice(0, 41)), - healthAmount: parseInt(raw.data[42]), + adventurerState: parseAdventurerState(raw.data.slice(0, 31)), + healthAmount: parseInt(raw.data[32]), }; const discoveredHealthEvent = processData( discoveredHealthData, @@ -311,8 +308,8 @@ export async function parseEvents( break; case "DiscoveredGold": const discoveredGoldData: DiscoveredGoldEvent = { - adventurerState: parseAdventurerState(raw.data.slice(0, 41)), - goldAmount: parseInt(raw.data[42]), + adventurerState: parseAdventurerState(raw.data.slice(0, 31)), + goldAmount: parseInt(raw.data[32]), }; const discoveredGoldEvent = processData( discoveredGoldData, @@ -324,8 +321,8 @@ export async function parseEvents( break; case "DiscoveredXP": const discoveredXPData: DiscoveredXPEvent = { - adventurerState: parseAdventurerState(raw.data.slice(0, 41)), - xpAmount: parseInt(raw.data[42]), + adventurerState: parseAdventurerState(raw.data.slice(0, 31)), + xpAmount: parseInt(raw.data[32]), }; const discoveredXPEvent = processData( discoveredXPData, @@ -337,13 +334,13 @@ export async function parseEvents( break; case "DodgedObstacle": const dodgedObstacleData: DodgedObstacleEvent = { - adventurerState: parseAdventurerState(raw.data.slice(0, 41)), - id: parseInt(raw.data[42]), - level: parseInt(raw.data[43]), - damageTaken: parseInt(raw.data[44]), - damageLocation: parseInt(raw.data[45]), - xpEarnedAdventurer: parseInt(raw.data[46]), - xpEarnedItems: parseInt(raw.data[47]), + adventurerState: parseAdventurerState(raw.data.slice(0, 31)), + id: parseInt(raw.data[32]), + level: parseInt(raw.data[33]), + damageTaken: parseInt(raw.data[34]), + damageLocation: parseInt(raw.data[35]), + xpEarnedAdventurer: parseInt(raw.data[36]), + xpEarnedItems: parseInt(raw.data[37]), }; const dodgedObstacleEvent = processData( dodgedObstacleData, @@ -355,13 +352,13 @@ export async function parseEvents( break; case "HitByObstacle": const hitByObstacleData: HitByObstacleEvent = { - adventurerState: parseAdventurerState(raw.data.slice(0, 41)), - id: parseInt(raw.data[42]), - level: parseInt(raw.data[43]), - damageTaken: parseInt(raw.data[44]), - damageLocation: parseInt(raw.data[45]), - xpEarnedAdventurer: parseInt(raw.data[46]), - xpEarnedItems: parseInt(raw.data[47]), + adventurerState: parseAdventurerState(raw.data.slice(0, 31)), + id: parseInt(raw.data[32]), + level: parseInt(raw.data[33]), + damageTaken: parseInt(raw.data[34]), + damageLocation: parseInt(raw.data[35]), + xpEarnedAdventurer: parseInt(raw.data[36]), + xpEarnedItems: parseInt(raw.data[37]), }; const hitByObstacleEvent = processData( hitByObstacleData, @@ -373,17 +370,17 @@ export async function parseEvents( break; case "DiscoveredBeast": const discoveredBeastData: DiscoveredBeastEvent = { - adventurerState: parseAdventurerState(raw.data.slice(0, 41)), - seed: parseInt(raw.data[42]), - id: parseInt(raw.data[43]), + adventurerState: parseAdventurerState(raw.data.slice(0, 31)), + seed: parseInt(raw.data[32]), + id: parseInt(raw.data[33]), beastSpecs: { - tier: parseInt(raw.data[44]), - itemType: parseInt(raw.data[45]), - level: parseInt(raw.data[46]), + tier: parseInt(raw.data[34]), + itemType: parseInt(raw.data[35]), + level: parseInt(raw.data[36]), specials: { - special1: parseInt(raw.data[47]), - special2: parseInt(raw.data[48]), - special3: parseInt(raw.data[49]), + special1: parseInt(raw.data[37]), + special2: parseInt(raw.data[38]), + special3: parseInt(raw.data[39]), }, }, }; @@ -397,22 +394,22 @@ export async function parseEvents( break; case "AmbushedByBeast": const ambushedByBeastData: AmbushedByBeastEvent = { - adventurerState: parseAdventurerState(raw.data.slice(0, 41)), - seed: parseInt(raw.data[42]), - id: parseInt(raw.data[43]), + adventurerState: parseAdventurerState(raw.data.slice(0, 31)), + seed: parseInt(raw.data[32]), + id: parseInt(raw.data[33]), beastSpecs: { - tier: parseInt(raw.data[44]), - itemType: parseInt(raw.data[45]), - level: parseInt(raw.data[46]), + tier: parseInt(raw.data[34]), + itemType: parseInt(raw.data[35]), + level: parseInt(raw.data[36]), specials: { - special1: parseInt(raw.data[47]), - special2: parseInt(raw.data[48]), - special3: parseInt(raw.data[49]), + special1: parseInt(raw.data[37]), + special2: parseInt(raw.data[38]), + special3: parseInt(raw.data[39]), }, }, - damage: parseInt(raw.data[50]), - criticalHit: convertToBoolean(parseInt(raw.data[51])), - location: parseInt(raw.data[52]), + damage: parseInt(raw.data[40]), + criticalHit: convertToBoolean(parseInt(raw.data[41])), + location: parseInt(raw.data[42]), }; const ambushedByBeastEvent = processData( ambushedByBeastData, @@ -424,22 +421,22 @@ export async function parseEvents( break; case "AttackedBeast": const attackedBeastData: AttackedBeastEvent = { - adventurerState: parseAdventurerState(raw.data.slice(0, 41)), - seed: parseInt(raw.data[42]), - id: parseInt(raw.data[43]), + adventurerState: parseAdventurerState(raw.data.slice(0, 31)), + seed: parseInt(raw.data[32]), + id: parseInt(raw.data[33]), beastSpecs: { - tier: parseInt(raw.data[44]), - itemType: parseInt(raw.data[45]), - level: parseInt(raw.data[46]), + tier: parseInt(raw.data[34]), + itemType: parseInt(raw.data[35]), + level: parseInt(raw.data[36]), specials: { - special1: parseInt(raw.data[47]), - special2: parseInt(raw.data[48]), - special3: parseInt(raw.data[49]), + special1: parseInt(raw.data[37]), + special2: parseInt(raw.data[38]), + special3: parseInt(raw.data[39]), }, }, - damage: parseInt(raw.data[50]), - criticalHit: convertToBoolean(parseInt(raw.data[51])), - location: parseInt(raw.data[52]), + damage: parseInt(raw.data[40]), + criticalHit: convertToBoolean(parseInt(raw.data[41])), + location: parseInt(raw.data[42]), }; const attackedBeastEvent = processData( attackedBeastData, @@ -451,22 +448,22 @@ export async function parseEvents( break; case "AttackedByBeast": const attackedByBeastData: AttackedByBeastEvent = { - adventurerState: parseAdventurerState(raw.data.slice(0, 41)), - seed: parseInt(raw.data[42]), - id: parseInt(raw.data[43]), + adventurerState: parseAdventurerState(raw.data.slice(0, 31)), + seed: parseInt(raw.data[32]), + id: parseInt(raw.data[33]), beastSpecs: { - tier: parseInt(raw.data[44]), - itemType: parseInt(raw.data[45]), - level: parseInt(raw.data[46]), + tier: parseInt(raw.data[34]), + itemType: parseInt(raw.data[35]), + level: parseInt(raw.data[36]), specials: { - special1: parseInt(raw.data[47]), - special2: parseInt(raw.data[48]), - special3: parseInt(raw.data[49]), + special1: parseInt(raw.data[37]), + special2: parseInt(raw.data[38]), + special3: parseInt(raw.data[39]), }, }, - damage: parseInt(raw.data[50]), - criticalHit: convertToBoolean(parseInt(raw.data[51])), - location: parseInt(raw.data[52]), + damage: parseInt(raw.data[40]), + criticalHit: convertToBoolean(parseInt(raw.data[41])), + location: parseInt(raw.data[42]), }; const attackedByBeastEvent = processData( attackedByBeastData, @@ -478,24 +475,24 @@ export async function parseEvents( break; case "SlayedBeast": const slayedBeastData: SlayedBeastEvent = { - adventurerState: parseAdventurerState(raw.data.slice(0, 41)), - seed: parseInt(raw.data[42]), - id: parseInt(raw.data[43]), + adventurerState: parseAdventurerState(raw.data.slice(0, 31)), + seed: parseInt(raw.data[32]), + id: parseInt(raw.data[33]), beastSpecs: { - tier: parseInt(raw.data[44]), - itemType: parseInt(raw.data[45]), - level: parseInt(raw.data[46]), + tier: parseInt(raw.data[34]), + itemType: parseInt(raw.data[35]), + level: parseInt(raw.data[36]), specials: { - special1: parseInt(raw.data[47]), - special2: parseInt(raw.data[48]), - special3: parseInt(raw.data[49]), + special1: parseInt(raw.data[37]), + special2: parseInt(raw.data[38]), + special3: parseInt(raw.data[39]), }, }, - damageDealt: parseInt(raw.data[50]), - criticalHit: convertToBoolean(parseInt(raw.data[51])), - xpEarnedAdventurer: parseInt(raw.data[52]), - xpEarnedItems: parseInt(raw.data[53]), - goldEarned: parseInt(raw.data[54]), + damageDealt: parseInt(raw.data[40]), + criticalHit: convertToBoolean(parseInt(raw.data[41])), + xpEarnedAdventurer: parseInt(raw.data[42]), + xpEarnedItems: parseInt(raw.data[43]), + goldEarned: parseInt(raw.data[44]), }; const slayedBeastEvent = processData( slayedBeastData, @@ -507,17 +504,17 @@ export async function parseEvents( break; case "FleeFailed": const fleeFailedData: FleeFailedEvent = { - adventurerState: parseAdventurerState(raw.data.slice(0, 41)), - seed: parseInt(raw.data[42]), - id: parseInt(raw.data[43]), + adventurerState: parseAdventurerState(raw.data.slice(0, 31)), + seed: parseInt(raw.data[32]), + id: parseInt(raw.data[33]), beastSpecs: { - tier: parseInt(raw.data[44]), - itemType: parseInt(raw.data[45]), - level: parseInt(raw.data[46]), + tier: parseInt(raw.data[34]), + itemType: parseInt(raw.data[35]), + level: parseInt(raw.data[36]), specials: { - special1: parseInt(raw.data[47]), - special2: parseInt(raw.data[48]), - special3: parseInt(raw.data[49]), + special1: parseInt(raw.data[37]), + special2: parseInt(raw.data[38]), + special3: parseInt(raw.data[39]), }, }, }; @@ -531,17 +528,17 @@ export async function parseEvents( break; case "FleeSucceeded": const fleeSucceededData: FleeSucceededEvent = { - adventurerState: parseAdventurerState(raw.data.slice(0, 41)), - seed: parseInt(raw.data[42]), - id: parseInt(raw.data[43]), + adventurerState: parseAdventurerState(raw.data.slice(0, 31)), + seed: parseInt(raw.data[32]), + id: parseInt(raw.data[33]), beastSpecs: { - tier: parseInt(raw.data[44]), - itemType: parseInt(raw.data[45]), - level: parseInt(raw.data[46]), + tier: parseInt(raw.data[34]), + itemType: parseInt(raw.data[35]), + level: parseInt(raw.data[36]), specials: { - special1: parseInt(raw.data[47]), - special2: parseInt(raw.data[48]), - special3: parseInt(raw.data[49]), + special1: parseInt(raw.data[37]), + special2: parseInt(raw.data[38]), + special3: parseInt(raw.data[39]), }, }, }; @@ -556,11 +553,11 @@ export async function parseEvents( case "PurchasedItems": const purchasedItemsData: PurchasedItemsEvent = { adventurerStateWithBag: { - adventurerState: parseAdventurerState(raw.data.slice(0, 41)), - bag: parseBag(raw.data.slice(42, 75)), + adventurerState: parseAdventurerState(raw.data.slice(0, 31)), + bag: parseBag(raw.data.slice(32, 63)), }, // Skip array length - purchases: parseItems(raw.data.slice(77)), + purchases: parseItems(raw.data.slice(65)), }; const purchasedItemsEvent = processData( purchasedItemsData, @@ -572,10 +569,10 @@ export async function parseEvents( break; case "PurchasedPotions": const purchasedPotionsData: PurchasedPotionsEvent = { - adventurerState: parseAdventurerState(raw.data.slice(0, 41)), - quantity: parseInt(raw.data[42]), - cost: parseInt(raw.data[43]), - health: parseInt(raw.data[44]), + adventurerState: parseAdventurerState(raw.data.slice(0, 31)), + quantity: parseInt(raw.data[32]), + cost: parseInt(raw.data[33]), + health: parseInt(raw.data[34]), }; const purchasedPotionsEvent = processData( purchasedPotionsData, @@ -588,12 +585,12 @@ export async function parseEvents( case "EquippedItems": const { equippedItems, unequippedItems } = parseEquippedItems( // Include equipped array length - raw.data.slice(76) + raw.data.slice(65) ); const equippedItemsData: EquippedItemsEvent = { adventurerStateWithBag: { - adventurerState: parseAdventurerState(raw.data.slice(0, 41)), - bag: parseBag(raw.data.slice(42, 75)), + adventurerState: parseAdventurerState(raw.data.slice(0, 31)), + bag: parseBag(raw.data.slice(32, 63)), }, equippedItems: equippedItems, unequippedItems: unequippedItems, @@ -609,14 +606,14 @@ export async function parseEvents( case "DroppedItems": const itemIds = []; // Skip array length - const itemsData = raw.data.slice(77); + const itemsData = raw.data.slice(65); for (let i = 0; i < itemsData.length; i++) { itemIds.push(parseInt(itemsData[i])); } const droppedItemsData: DroppedItemsEvent = { adventurerStateWithBag: { - adventurerState: parseAdventurerState(raw.data.slice(0, 41)), - bag: parseBag(raw.data.slice(42, 75)), + adventurerState: parseAdventurerState(raw.data.slice(0, 31)), + bag: parseBag(raw.data.slice(32, 63)), }, itemIds: itemIds, }; @@ -630,10 +627,10 @@ export async function parseEvents( break; case "GreatnessIncreased": const greatnessIncreasedData: GreatnessIncreasedEvent = { - adventurerState: parseAdventurerState(raw.data.slice(0, 41)), - itemId: parseInt(raw.data[42]), - previousLevel: parseInt(raw.data[43]), - newLevel: parseInt(raw.data[44]), + adventurerState: parseAdventurerState(raw.data.slice(0, 31)), + itemId: parseInt(raw.data[32]), + previousLevel: parseInt(raw.data[33]), + newLevel: parseInt(raw.data[34]), }; const greatnessIncreasedEvent = processData( greatnessIncreasedData, @@ -645,9 +642,9 @@ export async function parseEvents( break; case "ItemsLeveledUp": const itemsLeveledUpData: ItemsLeveledUpEvent = { - adventurerState: parseAdventurerState(raw.data.slice(0, 41)), + adventurerState: parseAdventurerState(raw.data.slice(0, 31)), // Skip items length - items: parseItemLevels(raw.data.slice(43)), + items: parseItemLevels(raw.data.slice(33)), }; const itemsLeveledUpEvent = processData( itemsLeveledUpData, @@ -659,8 +656,8 @@ export async function parseEvents( break; case "NewHighScore": const newHighScoreData: NewHighScoreEvent = { - adventurerState: parseAdventurerState(raw.data.slice(0, 41)), - rank: parseInt(raw.data[42]), + adventurerState: parseAdventurerState(raw.data.slice(0, 31)), + rank: parseInt(raw.data[32]), }; const newHighScoreEvent = processData( newHighScoreData, @@ -672,10 +669,10 @@ export async function parseEvents( break; case "AdventurerDied": const adventurerDiedData: AdventurerDiedEvent = { - adventurerState: parseAdventurerState(raw.data.slice(0, 41)), - killedByBeast: parseInt(raw.data[42]), - killedByObstacle: parseInt(raw.data[43]), - callerAddress: raw.data[44], + adventurerState: parseAdventurerState(raw.data.slice(0, 31)), + killedByBeast: parseInt(raw.data[32]), + killedByObstacle: parseInt(raw.data[33]), + callerAddress: raw.data[34], }; const adventurerDiedEvent = processData( adventurerDiedData, @@ -687,9 +684,9 @@ export async function parseEvents( break; case "AdventurerLeveledUp": const adventurerLeveledUpData: AdventurerLeveledUpEvent = { - adventurerState: parseAdventurerState(raw.data.slice(0, 41)), - previousLevel: parseInt(raw.data[42]), - newLevel: parseInt(raw.data[43]), + adventurerState: parseAdventurerState(raw.data.slice(0, 31)), + previousLevel: parseInt(raw.data[32]), + newLevel: parseInt(raw.data[33]), }; const adventurerLeveledUpEvent = processData( adventurerLeveledUpData, @@ -701,13 +698,13 @@ export async function parseEvents( break; case "UpgradesAvailable": // Skip array length - const newItems = raw.data.slice(43); + const newItems = raw.data.slice(33); const newItemsIds = []; for (let i = 0; i < newItems.length; i++) { newItemsIds.push(parseInt(newItems[i])); } const upgradesAvailableData: UpgradesAvailableEvent = { - adventurerState: parseAdventurerState(raw.data.slice(0, 41)), + adventurerState: parseAdventurerState(raw.data.slice(0, 31)), // Skip array length items: newItemsIds, }; diff --git a/ui/src/app/lib/utils/processData.ts b/ui/src/app/lib/utils/processData.ts index c7c82965a..f1ae37802 100644 --- a/ui/src/app/lib/utils/processData.ts +++ b/ui/src/app/lib/utils/processData.ts @@ -72,7 +72,6 @@ function processAdventurerState( id: data.adventurerState["adventurerId"], owner: data.adventurerState["owner"], entropy: data.adventurerState["adventurerEntropy"], - lastAction: data.adventurerState["adventurer"]["lastAction"], health: data.adventurerState["adventurer"]["health"], xp: data.adventurerState["adventurer"]["xp"], strength: data.adventurerState["adventurer"]["stats"]["strength"], @@ -83,19 +82,37 @@ function processAdventurerState( charisma: data.adventurerState["adventurer"]["stats"]["charisma"], luck: data.adventurerState["adventurer"]["stats"]["luck"], gold: data.adventurerState["adventurer"]["gold"], - weapon: gameData.ITEMS[data.adventurerState["adventurer"]["weapon"]["id"]], - chest: gameData.ITEMS[data.adventurerState["adventurer"]["chest"]["id"]], - head: gameData.ITEMS[data.adventurerState["adventurer"]["head"]["id"]], - waist: gameData.ITEMS[data.adventurerState["adventurer"]["waist"]["id"]], - foot: gameData.ITEMS[data.adventurerState["adventurer"]["foot"]["id"]], - hand: gameData.ITEMS[data.adventurerState["adventurer"]["hand"]["id"]], - neck: gameData.ITEMS[data.adventurerState["adventurer"]["neck"]["id"]], - ring: gameData.ITEMS[data.adventurerState["adventurer"]["ring"]["id"]], + weapon: + gameData.ITEMS[ + data.adventurerState["adventurer"]["equipment"]["weapon"]["id"] + ], + chest: + gameData.ITEMS[ + data.adventurerState["adventurer"]["equipment"]["chest"]["id"] + ], + head: gameData.ITEMS[ + data.adventurerState["adventurer"]["equipment"]["head"]["id"] + ], + waist: + gameData.ITEMS[ + data.adventurerState["adventurer"]["equipment"]["waist"]["id"] + ], + foot: gameData.ITEMS[ + data.adventurerState["adventurer"]["equipment"]["foot"]["id"] + ], + hand: gameData.ITEMS[ + data.adventurerState["adventurer"]["equipment"]["hand"]["id"] + ], + neck: gameData.ITEMS[ + data.adventurerState["adventurer"]["equipment"]["neck"]["id"] + ], + ring: gameData.ITEMS[ + data.adventurerState["adventurer"]["equipment"]["ring"]["id"] + ], beastHealth: data.adventurerState["adventurer"]["beastHealth"], - statUpgrades: data.adventurerState["adventurer"]["statPointsAvailable"], - actionsPerBlock: data.adventurerState["adventurer"]["actionsPerBlock"], + statUpgrades: data.adventurerState["adventurer"]["statUpgradesAvailable"], name: currentAdventurer!["name"], - startBlock: currentAdventurer!["startBlock"], + startEntropy: currentAdventurer!["startEntropy"], revealBlock: currentAdventurer!["revealBlock"], createdTime: currentAdventurer?.createdTime, lastUpdatedTime: new Date(), // Use this date for now though it is block_timestamp in indexer @@ -128,14 +145,14 @@ export function processPurchases(data: any, adventurerState: any) { export function processItemsXP(data: any) { const itemsXP = [ - data.adventurerState["adventurer"]["weapon"]["xp"], - data.adventurerState["adventurer"]["chest"]["xp"], - data.adventurerState["adventurer"]["head"]["xp"], - data.adventurerState["adventurer"]["waist"]["xp"], - data.adventurerState["adventurer"]["foot"]["xp"], - data.adventurerState["adventurer"]["hand"]["xp"], - data.adventurerState["adventurer"]["neck"]["xp"], - data.adventurerState["adventurer"]["ring"]["xp"], + data.adventurerState["adventurer"]["equipment"]["weapon"]["xp"], + data.adventurerState["adventurer"]["equipment"]["chest"]["xp"], + data.adventurerState["adventurer"]["equipment"]["head"]["xp"], + data.adventurerState["adventurer"]["equipment"]["waist"]["xp"], + data.adventurerState["adventurer"]["equipment"]["foot"]["xp"], + data.adventurerState["adventurer"]["equipment"]["hand"]["xp"], + data.adventurerState["adventurer"]["equipment"]["neck"]["xp"], + data.adventurerState["adventurer"]["equipment"]["ring"]["xp"], ]; return itemsXP; } @@ -171,7 +188,6 @@ export function processData( id: startGameEvent.adventurerState["adventurerId"], owner: startGameEvent.adventurerState["owner"], entropy: startGameEvent.adventurerState["adventurerEntropy"], - lastAction: startGameEvent.adventurerState["adventurer"]["lastAction"], health: startGameEvent.adventurerState["adventurer"]["health"], xp: startGameEvent.adventurerState["adventurer"]["xp"], strength: @@ -189,39 +205,53 @@ export function processData( gold: startGameEvent.adventurerState["adventurer"]["gold"], weapon: gameData.ITEMS[ - startGameEvent.adventurerState["adventurer"]["weapon"]["id"] + startGameEvent.adventurerState["adventurer"]["equipment"]["weapon"][ + "id" + ] ], chest: gameData.ITEMS[ - startGameEvent.adventurerState["adventurer"]["chest"]["id"] + startGameEvent.adventurerState["adventurer"]["equipment"]["chest"][ + "id" + ] ], head: gameData.ITEMS[ - startGameEvent.adventurerState["adventurer"]["head"]["id"] + startGameEvent.adventurerState["adventurer"]["equipment"]["head"][ + "id" + ] ], waist: gameData.ITEMS[ - startGameEvent.adventurerState["adventurer"]["waist"]["id"] + startGameEvent.adventurerState["adventurer"]["equipment"]["waist"][ + "id" + ] ], foot: gameData.ITEMS[ - startGameEvent.adventurerState["adventurer"]["foot"]["id"] + startGameEvent.adventurerState["adventurer"]["equipment"]["foot"][ + "id" + ] ], hand: gameData.ITEMS[ - startGameEvent.adventurerState["adventurer"]["hand"]["id"] + startGameEvent.adventurerState["adventurer"]["equipment"]["hand"][ + "id" + ] ], neck: gameData.ITEMS[ - startGameEvent.adventurerState["adventurer"]["neck"]["id"] + startGameEvent.adventurerState["adventurer"]["equipment"]["neck"][ + "id" + ] ], ring: gameData.ITEMS[ - startGameEvent.adventurerState["adventurer"]["ring"]["id"] + startGameEvent.adventurerState["adventurer"]["equipment"]["ring"][ + "id" + ] ], beastHealth: startGameEvent.adventurerState["adventurer"]["beastHealth"], statUpgrades: - startGameEvent.adventurerState["adventurer"]["statPointsAvailable"], - actionsPerBlock: - startGameEvent.adventurerState["adventurer"]["actionsPerBlock"], + startGameEvent.adventurerState["adventurer"]["statUpgradesAvailable"], name: feltToString(startGameEvent.adventurerMeta["name"]), - startBlock: startGameEvent.adventurerMeta["startBlock"], + startEntropy: startGameEvent.adventurerMeta["startEntropy"], revealBlock: startGameEvent.revealBlock, createdTime: new Date(), lastUpdatedTime: new Date(), // Use this date for now though it is block_timestamp in indexer diff --git a/ui/src/app/types/events.ts b/ui/src/app/types/events.ts index 88e1709ca..5a60de73f 100644 --- a/ui/src/app/types/events.ts +++ b/ui/src/app/types/events.ts @@ -9,10 +9,10 @@ type u16 = number; type u8 = number; type AdventurerMetadata = { - startBlock: u64; + startEntropy: u64; startingStats: Stats; - name: u128; interfaceCamel: boolean; + name: u128; }; type Stats = { @@ -25,29 +25,30 @@ type Stats = { luck: u8; }; +type Equipment = { + weapon: LootStatistics; + chest: LootStatistics; + head: LootStatistics; + waist: LootStatistics; + foot: LootStatistics; + hand: LootStatistics; + neck: LootStatistics; + ring: LootStatistics; +}; + type LootStatistics = { id: u8; xp: u16; - metadata: u8; }; type Adventurer = { - lastAction: u16; health: u16; xp: u16; - stats: Stats; gold: u16; - weapon: LootStatistics; - chest: LootStatistics; - head: LootStatistics; - waist: LootStatistics; - foot: LootStatistics; - hand: LootStatistics; - neck: LootStatistics; - ring: LootStatistics; beastHealth: u16; - statPointsAvailable: u8; - actionsPerBlock: u8; + statUpgradesAvailable: u8; + stats: Stats; + equipment: Equipment; mutated: boolean; }; @@ -63,6 +64,10 @@ type Bag = { item9: LootStatistics; item10: LootStatistics; item11: LootStatistics; + item12: LootStatistics; + item13: LootStatistics; + item14: LootStatistics; + item15: LootStatistics; mutated: boolean; }; From 8833502e4a99c21178ebab20655c711520e1d582 Mon Sep 17 00:00:00 2001 From: Starknet Dev Date: Mon, 27 May 2024 21:22:45 +0100 Subject: [PATCH 07/18] fix indexer event handling --- indexer/src/utils/events.ts | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/indexer/src/utils/events.ts b/indexer/src/utils/events.ts index 3d183b39a..91617da7c 100644 --- a/indexer/src/utils/events.ts +++ b/indexer/src/utils/events.ts @@ -89,9 +89,9 @@ export const parseEquipment = combineParsers({ export const parseAdventurer = combineParsers({ health: { index: 0, parser: parseU16 }, xp: { index: 1, parser: parseU16 }, - beastHealth: { index: 2, parser: parseU16 }, - statsUpgradesAvailable: { index: 3, parser: parseU8 }, - gold: { index: 4, parser: parseU16 }, + gold: { index: 2, parser: parseU16 }, + beastHealth: { index: 3, parser: parseU16 }, + statsUpgradesAvailable: { index: 4, parser: parseU8 }, stats: { index: 5, parser: parseStats }, equipment: { index: 6, parser: parseEquipment }, mutated: { index: 7, parser: parseBoolean }, @@ -176,8 +176,8 @@ export const parseAdventurerDied = combineParsers({ export const parseAdventurerMetadata = combineParsers({ startEntropy: { index: 0, parser: parseU128 }, startingStats: { index: 1, parser: parseStats }, - name: { index: 2, parser: parseU128 }, - interfaceCamel: { index: 3, parser: parseBoolean }, + interfaceCamel: { index: 2, parser: parseBoolean }, + name: { index: 3, parser: parseU128 }, }); export const parseStartGame = combineParsers({ From e619ea3939ce72ef6118b9f9e5c01c4467a38e66 Mon Sep 17 00:00:00 2001 From: Starknet Dev Date: Mon, 27 May 2024 21:36:15 +0100 Subject: [PATCH 08/18] update graphql certificate --- indexer/graphql/src/indexer/graphql.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/indexer/graphql/src/indexer/graphql.py b/indexer/graphql/src/indexer/graphql.py index eba5db332..537bc8de8 100644 --- a/indexer/graphql/src/indexer/graphql.py +++ b/indexer/graphql/src/indexer/graphql.py @@ -1601,8 +1601,8 @@ async def run_graphql_api(mongo=None, port="8080"): ssl_context = ssl.create_default_context(ssl.Purpose.CLIENT_AUTH) ssl_context.load_cert_chain( - "/etc/letsencrypt/live/ls-indexer-sepolia.provable.games/fullchain.pem", - "/etc/letsencrypt/live/ls-indexer-sepolia.provable.games/privkey.pem", + "/etc/letsencrypt/live/ls-indexer-sepolia-temp.provable.games/fullchain.pem", + "/etc/letsencrypt/live/ls-indexer-sepolia-temp.provable.games/privkey.pem", ) runner = web.AppRunner(app) From 02184b2765375bbee8b50695b4feb5e5a255e6c1 Mon Sep 17 00:00:00 2001 From: Starknet Dev Date: Tue, 28 May 2024 08:59:56 +0100 Subject: [PATCH 09/18] - increase max bag amount - remove interlude on beast screen - fetch entropy on initial load and after 10 secs - update contracts --- indexer/env-sepolia | 2 +- .../components/marketplace/MarketplaceRow.tsx | 2 +- .../marketplace/MarketplaceTable.tsx | 2 +- ui/src/app/containers/BeastScreen.tsx | 105 +++++------------- ui/src/app/containers/InventoryScreen.tsx | 2 +- ui/src/app/containers/UpgradeScreen.tsx | 10 +- 6 files changed, 42 insertions(+), 81 deletions(-) diff --git a/indexer/env-sepolia b/indexer/env-sepolia index b08e55389..04bcd44ef 100644 --- a/indexer/env-sepolia +++ b/indexer/env-sepolia @@ -1,4 +1,4 @@ -GAME="0x06c63851635f1e0ee0695a157292892cabaa030a8eca20a32b6a86c968c47c33" +GAME="0xa2516792efec852999cfd1d69a3caab70a168f7bb59c257065f64281df93a5" START=68300 MONGO_CONNECTION_STRING="mongodb://mongo:mongo@mongo:27017" MONGO_DB="mongo" diff --git a/ui/src/app/components/marketplace/MarketplaceRow.tsx b/ui/src/app/components/marketplace/MarketplaceRow.tsx index a901644e6..3d22fae05 100644 --- a/ui/src/app/components/marketplace/MarketplaceRow.tsx +++ b/ui/src/app/components/marketplace/MarketplaceRow.tsx @@ -108,7 +108,7 @@ const MarketplaceRow = ({ ).length; const equipFull = equippedItems + purchaseEquipItems === 8; - const bagFull = baggedItems + purchaseNoEquipItems === 11; + const bagFull = baggedItems + purchaseNoEquipItems === 15; useEffect(() => { if (isActive) { diff --git a/ui/src/app/components/marketplace/MarketplaceTable.tsx b/ui/src/app/components/marketplace/MarketplaceTable.tsx index 9eeb20463..4c482f66e 100644 --- a/ui/src/app/components/marketplace/MarketplaceTable.tsx +++ b/ui/src/app/components/marketplace/MarketplaceTable.tsx @@ -152,7 +152,7 @@ const MarketplaceTable = ({ {(() => { const item = sortedMarketLatestItems[showEquipQ ?? 0]; const bagFull = - adventurerItems.filter((obj) => !obj.equipped).length == 11; + adventurerItems.filter((obj) => !obj.equipped).length == 15; return (
state.adventurer); const loading = useLoadingStore((state) => state.loading); const estimatingFee = useUIStore((state) => state.estimatingFee); - const entropyReady = useUIStore((state) => state.entropyReady); - const setEntropyReady = useUIStore((state) => state.setEntropyReady); const resetNotification = useLoadingStore((state) => state.resetNotification); const [showBattleLog, setShowBattleLog] = useState(false); const hasBeast = useAdventurerStore((state) => state.computed.hasBeast); @@ -172,32 +169,12 @@ export default function BeastScreen({
); - useEffect(() => { - if (adventurer?.level == 1) { - const interval = setInterval(async () => { - const entropy = await gameContract!.call("get_adventurer_entropy", [ - adventurer?.id!, - ]); - console.log(entropy); - if (entropy !== BigInt(0)) { - setEntropyReady(true); - clearInterval(interval); - } - }, 10000); // We call the getAdventurerEntropy function every 30 seconds - - return () => clearInterval(interval); // Cleanup on component unmount - } - }, []); - - console.log(entropyReady); - if (showBattleLog) { return ; } return (
- {adventurer?.level == 1 && !entropyReady && }
{hasBeast ? ( @@ -213,62 +190,40 @@ export default function BeastScreen({
{isAlive && ( <> - {entropyReady ? ( - <> -
-
- -
-
- -
+ <> +
+
+ +
+
+
-
-
- -
-
- -
+
+
+
+
- - ) : ( -
- {/*
-
- Current: -
-

{currentBlockNumber}

-
-
-
- Reveal: -
- {adventurer?.revealBlock} -
-
+
+
-

- Waiting for Block Reveal -

*/}
- )} + )} diff --git a/ui/src/app/containers/InventoryScreen.tsx b/ui/src/app/containers/InventoryScreen.tsx index df24398a1..1b64cd23f 100644 --- a/ui/src/app/containers/InventoryScreen.tsx +++ b/ui/src/app/containers/InventoryScreen.tsx @@ -296,7 +296,7 @@ export default function InventoryScreen({ - {`${bagItems.length}/${11}`} + {`${bagItems.length}/${15}`} diff --git a/ui/src/app/containers/UpgradeScreen.tsx b/ui/src/app/containers/UpgradeScreen.tsx index 113cf190c..9e1311ec5 100644 --- a/ui/src/app/containers/UpgradeScreen.tsx +++ b/ui/src/app/containers/UpgradeScreen.tsx @@ -90,7 +90,7 @@ export default function UpgradeScreen({ }); useEffect(() => { - const interval = setInterval(async () => { + const fetchEntropy = async () => { const entropy = await gameContract!.call("get_adventurer_entropy", [ adventurer?.id!, ]); @@ -99,7 +99,13 @@ export default function UpgradeScreen({ setEntropyReady(true); clearInterval(interval); } - }, 10000); // We call the getAdventurerEntropy function every 30 seconds + }; + + // Call the function immediately + fetchEntropy(); + + // Set up the interval to call the function every 10 seconds + const interval = setInterval(fetchEntropy, 10000); return () => clearInterval(interval); // Cleanup on component unmount }, []); From 1bc00c420de6d83f785ee031e85a5c31da5623e2 Mon Sep 17 00:00:00 2001 From: Starknet Dev Date: Tue, 28 May 2024 10:02:24 +0100 Subject: [PATCH 10/18] - fix indexer items script - update UI queries - add fetch adventurer stats after 1st entropy --- indexer/src/items.ts | 5 ++--- ui/src/app/containers/BeastScreen.tsx | 7 +------ ui/src/app/containers/UpgradeScreen.tsx | 24 ++++++++++++++++++++++++ ui/src/app/hooks/graphql/queries.ts | 5 ++--- ui/src/app/hooks/useAdventurerStore.ts | 8 ++++++++ ui/src/app/lib/classes.ts | 9 +++------ ui/src/app/lib/utils/parseEvents.ts | 2 +- ui/src/app/lib/utils/syscalls.ts | 19 +++---------------- ui/src/app/types/events.ts | 2 +- ui/src/app/types/index.ts | 3 +-- 10 files changed, 46 insertions(+), 38 deletions(-) diff --git a/indexer/src/items.ts b/indexer/src/items.ts index 845defc82..9b58e5410 100644 --- a/indexer/src/items.ts +++ b/indexer/src/items.ts @@ -71,16 +71,15 @@ export default function transform({ header, events }: Block) { case START_GAME: { const { value } = parseStartGame(event.data, 0); const as = value.adventurerState; - const itemInserts: any[] = []; console.log("START_GAME", "->", "ITEMS UPDATES"); const starterWeapon = { entity: { - item: checkExistsInt(BigInt(as.adventurer.weapon.id)), + item: checkExistsInt(BigInt(as.adventurer.equipment.weapon.id)), adventurerId: checkExistsInt(BigInt(as.adventurerId)), }, update: { $set: { - item: checkExistsInt(BigInt(as.adventurer.weapon.id)), + item: checkExistsInt(BigInt(as.adventurer.equipment.weapon.id)), adventurerId: checkExistsInt(BigInt(as.adventurerId)), owner: true, equipped: true, diff --git a/ui/src/app/containers/BeastScreen.tsx b/ui/src/app/containers/BeastScreen.tsx index 9bbf1e364..e4a43b3e4 100644 --- a/ui/src/app/containers/BeastScreen.tsx +++ b/ui/src/app/containers/BeastScreen.tsx @@ -63,12 +63,7 @@ export default function BeastScreen({ label: "ONCE", action: async () => { resetNotification(); - if (adventurer?.level === 1) { - const entropyBlockData = await getBlock(adventurer?.startBlock! + 1); - await attack(false, beastData, entropyBlockData?.block_hash ?? 0); - } else { - await attack(false, beastData); - } + await attack(false, beastData); }, disabled: adventurer?.beastHealth == undefined || diff --git a/ui/src/app/containers/UpgradeScreen.tsx b/ui/src/app/containers/UpgradeScreen.tsx index 9e1311ec5..71d5bfd7d 100644 --- a/ui/src/app/containers/UpgradeScreen.tsx +++ b/ui/src/app/containers/UpgradeScreen.tsx @@ -39,6 +39,7 @@ import { HealthCountDown } from "@/app/components/CountDown"; import { calculateVitBoostRemoved } from "@/app/lib/utils"; import { useQueriesStore } from "@/app/hooks/useQueryStore"; import InterludeScreen from "@/app/containers/InterludeScreen"; +import { stat } from "fs"; interface UpgradeScreenProps { upgrade: ( @@ -59,6 +60,9 @@ export default function UpgradeScreen({ gameContract, }: UpgradeScreenProps) { const adventurer = useAdventurerStore((state) => state.adventurer); + const updateAdventurerStats = useAdventurerStore( + (state) => state.updateAdventurerStats + ); const loading = useLoadingStore((state) => state.loading); const estimatingFee = useUIStore((state) => state.estimatingFee); const resetNotification = useLoadingStore((state) => state.resetNotification); @@ -142,10 +146,30 @@ export default function UpgradeScreen({ } }; + const fetchAdventurerStats = async () => { + if (entropyReady && adventurer?.level == 2) { + const stats = (await gameContract!.call("get_stats", [ + adventurer?.id!, + ])) as any; + console.log(stats); + updateAdventurerStats({ + strength: parseInt(stats.strength), + dexterity: parseInt(stats.dexterity), + vitality: parseInt(stats.vitality), + intelligence: parseInt(stats.intelligence), + wisdom: parseInt(stats.wisdom), + charisma: parseInt(stats.charisma), + luck: parseInt(stats.luck), + }); + } + }; + fetchMarketItems(); + fetchAdventurerStats(); }, [entropyReady]); console.log(entropyReady); + console.log(adventurer); const gameData = new GameData(); diff --git a/ui/src/app/hooks/graphql/queries.ts b/ui/src/app/hooks/graphql/queries.ts index 019945342..c9e27d6e6 100644 --- a/ui/src/app/hooks/graphql/queries.ts +++ b/ui/src/app/hooks/graphql/queries.ts @@ -2,8 +2,8 @@ import { gql } from "@apollo/client"; const ADVENTURER_FIELDS = ` id - lastAction owner + entropy name health strength @@ -24,9 +24,8 @@ const ADVENTURER_FIELDS = ` ring beastHealth statUpgrades - startBlock + startEntropy revealBlock - actionsPerBlock gold createdTime lastUpdatedTime diff --git a/ui/src/app/hooks/useAdventurerStore.ts b/ui/src/app/hooks/useAdventurerStore.ts index 76c3d4d89..2e5e9a199 100644 --- a/ui/src/app/hooks/useAdventurerStore.ts +++ b/ui/src/app/hooks/useAdventurerStore.ts @@ -10,6 +10,7 @@ export interface AdventurerProps { type State = { adventurer?: AdventurerClass | undefined; setAdventurer: (value: Adventurer) => void; + updateAdventurerStats: (stats: Partial) => void; image?: string; setImage: (value: string) => void; computed: { @@ -28,6 +29,13 @@ const useAdventurerStore = create((set, get) => ({ ...state, adventurer: new AdventurerClass(value), })), + updateAdventurerStats: (stats: Partial) => + set((state) => ({ + adventurer: { + ...state.adventurer, + ...stats, + }, + })), image: undefined, setImage: (value) => set({ image: value }), computed: { diff --git a/ui/src/app/lib/classes.ts b/ui/src/app/lib/classes.ts index c089f1e44..908e038aa 100644 --- a/ui/src/app/lib/classes.ts +++ b/ui/src/app/lib/classes.ts @@ -4,7 +4,6 @@ import { calculateLevel, getItemData } from "@/app/lib/utils"; export class AdventurerClass implements Adventurer { [key: string]: number | string | Date | undefined; id?: number; // Adventurer ID - lastAction?: number; // Block number from last action owner?: string; // Hex address of the owner name?: string; // Name of the adventurer order?: string; // Order of the adventurer @@ -28,7 +27,7 @@ export class AdventurerClass implements Adventurer { ring?: string; // Ring of the adventure beastHealth?: number; // Beast health adventurer is engaging statUpgrades?: number; // Stat upgrades adventurer has - startBlock?: number; // The block number the adventurer was minted + startEntropy?: string; // The block number the adventurer was minted revealBlock?: number; // The next block number that the game entropy rotates from spawn gold?: number; // Gold adventurer has createdTime?: Date; // Block time the adventurer was created @@ -37,7 +36,6 @@ export class AdventurerClass implements Adventurer { constructor(adventurer: Adventurer) { const { id, - lastAction, owner, name, order, @@ -60,7 +58,7 @@ export class AdventurerClass implements Adventurer { ring, beastHealth, statUpgrades, - startBlock, + startEntropy, revealBlock, gold, createdTime, @@ -69,7 +67,6 @@ export class AdventurerClass implements Adventurer { } = adventurer; this.id = id; - this.lastAction = lastAction; this.owner = owner; this.name = name; this.order = order; @@ -95,7 +92,7 @@ export class AdventurerClass implements Adventurer { this.ring = ring; this.beastHealth = beastHealth; this.statUpgrades = statUpgrades; - this.startBlock = startBlock; + this.startEntropy = startEntropy; this.revealBlock = revealBlock; this.gold = gold; this.createdTime = createdTime; diff --git a/ui/src/app/lib/utils/parseEvents.ts b/ui/src/app/lib/utils/parseEvents.ts index 10087b101..363dd1cff 100644 --- a/ui/src/app/lib/utils/parseEvents.ts +++ b/ui/src/app/lib/utils/parseEvents.ts @@ -250,7 +250,7 @@ export async function parseEvents( const startGameData: StartGameEvent = { adventurerState: parseAdventurerState(raw.data.slice(0, 31)), adventurerMeta: { - startEntropy: parseInt(raw.data[32]), + startEntropy: raw.data[32], startingStats: { strength: parseInt(raw.data[33]), dexterity: parseInt(raw.data[34]), diff --git a/ui/src/app/lib/utils/syscalls.ts b/ui/src/app/lib/utils/syscalls.ts index 3ab08ce17..a61e120c0 100644 --- a/ui/src/app/lib/utils/syscalls.ts +++ b/ui/src/app/lib/utils/syscalls.ts @@ -657,27 +657,14 @@ export function syscalls({ } }; - const attack = async ( - tillDeath: boolean, - beastData: Beast, - blockHash?: string - ) => { + const attack = async (tillDeath: boolean, beastData: Beast) => { resetData("latestMarketItemsQuery"); - // First we send the current block hash to the contract - const setBlockHashTx: Call = { - contractAddress: gameContract?.address ?? "", - entrypoint: "set_starting_entropy", - calldata: [adventurer?.id?.toString() ?? "", blockHash!], - }; const attackTx: Call = { contractAddress: gameContract?.address ?? "", entrypoint: "attack", calldata: [adventurer?.id?.toString() ?? "", tillDeath ? "1" : "0"], }; - const attackCalls = - process.env.NEXT_PUBLIC_NETWORK === "mainnet" - ? [setBlockHashTx, attackTx] - : [attackTx]; + addToCalls(attackTx); const isArcade = checkArcadeConnector(connector!); @@ -685,7 +672,7 @@ export function syscalls({ try { const tx = await handleSubmitCalls( account, - [...calls, ...attackCalls], + [...calls, attackTx], isArcade, Number(ethBalance), showTopUpDialog, diff --git a/ui/src/app/types/events.ts b/ui/src/app/types/events.ts index 5a60de73f..0c0134339 100644 --- a/ui/src/app/types/events.ts +++ b/ui/src/app/types/events.ts @@ -9,7 +9,7 @@ type u16 = number; type u8 = number; type AdventurerMetadata = { - startEntropy: u64; + startEntropy: string; startingStats: Stats; interfaceCamel: boolean; name: u128; diff --git a/ui/src/app/types/index.ts b/ui/src/app/types/index.ts index a4b88f188..45a575d5b 100644 --- a/ui/src/app/types/index.ts +++ b/ui/src/app/types/index.ts @@ -5,7 +5,6 @@ import { ScreenPage } from "@/app/hooks/useUIStore"; export interface Adventurer { [key: string]: number | string | Date | undefined; id?: number; // Adventurer ID - lastAction?: number; // Block number from last action entropy?: string; // Entropy of the adventurer owner?: string; // Hex address of the owner classType?: string; // Class of the adventurer @@ -32,7 +31,7 @@ export interface Adventurer { ring?: string; // Ring of the adventure beastHealth?: number; // Beast health adventurer is engaging statUpgrades?: number; // Stat upgrades adventurer has - startBlock?: number; // The block number the adventurer was minted + startEntropy?: string; // The entropy when the adventurer was minted revealBlock?: number; // The next block number that the game entropy rotates from spawn gold?: number; // Gold adventurer has createdTime?: Date; // Block time the adventurer was created From 5ad31bae79d35a6a3fcf338b19211110fc9766a8 Mon Sep 17 00:00:00 2001 From: Starknet Dev Date: Tue, 28 May 2024 10:54:15 +0100 Subject: [PATCH 11/18] - fix indexer bag parsing --- indexer/src/items.ts | 2 ++ indexer/src/utils/events.ts | 6 +++++- ui/src/app/components/adventurer/Info.tsx | 3 +++ 3 files changed, 10 insertions(+), 1 deletion(-) diff --git a/indexer/src/items.ts b/indexer/src/items.ts index 9b58e5410..656eae653 100644 --- a/indexer/src/items.ts +++ b/indexer/src/items.ts @@ -100,6 +100,7 @@ export default function transform({ header, events }: Block) { const { value } = parsePurchasedItems(event.data, 0); const as = value.adventurerStateWithBag.adventurerState; console.log("PURCHASED_ITEMS", "->", "ITEMS UPDATES"); + console.log(value.purchases); const result = value.purchases.map((item) => ({ entity: { item: checkExistsInt(BigInt(item.item.id)), @@ -123,6 +124,7 @@ export default function transform({ header, events }: Block) { const { value } = parseEquippedItems(event.data, 0); const as = value.adventurerStateWithBag.adventurerState; console.log("EQUIPPED_ITEMS", "->", "ITEMS UPDATES"); + console.log(value.equippedItems); const equippedResult = value.equippedItems.map((item) => ({ entity: { item: checkExistsInt(BigInt(item)), diff --git a/indexer/src/utils/events.ts b/indexer/src/utils/events.ts index 91617da7c..6e61b6a25 100644 --- a/indexer/src/utils/events.ts +++ b/indexer/src/utils/events.ts @@ -198,7 +198,11 @@ export const parseBag = combineParsers({ item9: { index: 8, parser: parseLootStatistics }, item10: { index: 9, parser: parseLootStatistics }, item11: { index: 10, parser: parseLootStatistics }, - mutated: { index: 11, parser: parseBoolean }, + item12: { index: 11, parser: parseLootStatistics }, + item13: { index: 12, parser: parseLootStatistics }, + item14: { index: 13, parser: parseLootStatistics }, + item15: { index: 14, parser: parseLootStatistics }, + mutated: { index: 15, parser: parseBoolean }, }); export const parseAdventurerStateWithBag = combineParsers({ diff --git a/ui/src/app/components/adventurer/Info.tsx b/ui/src/app/components/adventurer/Info.tsx index dadc972f9..56c4c0b33 100644 --- a/ui/src/app/components/adventurer/Info.tsx +++ b/ui/src/app/components/adventurer/Info.tsx @@ -50,6 +50,9 @@ export default function Info({ ? data.itemsByAdventurerQuery.items : []; + console.log(items); + console.log(formatAdventurer); + const handleDropItems = (item: string) => { const newDropItems = [ ...dropItems, From ec3c95a20cc80378afeb8ea40b6f4e1e0c68f1ec Mon Sep 17 00:00:00 2001 From: Starknet Dev Date: Tue, 28 May 2024 11:54:07 +0100 Subject: [PATCH 12/18] - update health + stats - fix event processing for new cairo - clean logs --- indexer/src/items.ts | 2 -- ui/src/app/components/adventurer/Info.tsx | 3 -- .../notifications/NotificationHandler.tsx | 2 -- ui/src/app/containers/UpgradeScreen.tsx | 32 +++++++++---------- ui/src/app/lib/utils/parseEvents.ts | 4 +-- ui/src/app/lib/utils/syscalls.ts | 7 ---- 6 files changed, 18 insertions(+), 32 deletions(-) diff --git a/indexer/src/items.ts b/indexer/src/items.ts index 656eae653..9b58e5410 100644 --- a/indexer/src/items.ts +++ b/indexer/src/items.ts @@ -100,7 +100,6 @@ export default function transform({ header, events }: Block) { const { value } = parsePurchasedItems(event.data, 0); const as = value.adventurerStateWithBag.adventurerState; console.log("PURCHASED_ITEMS", "->", "ITEMS UPDATES"); - console.log(value.purchases); const result = value.purchases.map((item) => ({ entity: { item: checkExistsInt(BigInt(item.item.id)), @@ -124,7 +123,6 @@ export default function transform({ header, events }: Block) { const { value } = parseEquippedItems(event.data, 0); const as = value.adventurerStateWithBag.adventurerState; console.log("EQUIPPED_ITEMS", "->", "ITEMS UPDATES"); - console.log(value.equippedItems); const equippedResult = value.equippedItems.map((item) => ({ entity: { item: checkExistsInt(BigInt(item)), diff --git a/ui/src/app/components/adventurer/Info.tsx b/ui/src/app/components/adventurer/Info.tsx index 56c4c0b33..dadc972f9 100644 --- a/ui/src/app/components/adventurer/Info.tsx +++ b/ui/src/app/components/adventurer/Info.tsx @@ -50,9 +50,6 @@ export default function Info({ ? data.itemsByAdventurerQuery.items : []; - console.log(items); - console.log(formatAdventurer); - const handleDropItems = (item: string) => { const newDropItems = [ ...dropItems, diff --git a/ui/src/app/components/notifications/NotificationHandler.tsx b/ui/src/app/components/notifications/NotificationHandler.tsx index 3c6bf4463..aff96e4b1 100644 --- a/ui/src/app/components/notifications/NotificationHandler.tsx +++ b/ui/src/app/components/notifications/NotificationHandler.tsx @@ -21,8 +21,6 @@ import LootIcon from "@/app/components/icons/LootIcon"; import { HealthPotionIcon } from "@/app/components/icons/Icons"; const handleUpgrade = (notificationData: any, notifications: any[]) => { - console.log("here"); - console.log(notificationData, notifications); const gameData = new GameData(); notifications.push({ message: ( diff --git a/ui/src/app/containers/UpgradeScreen.tsx b/ui/src/app/containers/UpgradeScreen.tsx index 71d5bfd7d..7b66c7a80 100644 --- a/ui/src/app/containers/UpgradeScreen.tsx +++ b/ui/src/app/containers/UpgradeScreen.tsx @@ -98,7 +98,6 @@ export default function UpgradeScreen({ const entropy = await gameContract!.call("get_adventurer_entropy", [ adventurer?.id!, ]); - console.log(entropy); if (entropy !== BigInt(0)) { setEntropyReady(true); clearInterval(interval); @@ -123,7 +122,6 @@ export default function UpgradeScreen({ adventurer?.id!, ])) as string[]; const itemData = []; - console.log(marketItems); for (let item of marketItems) { itemData.unshift({ item: gameData.ITEMS[parseInt(item)], @@ -148,18 +146,18 @@ export default function UpgradeScreen({ const fetchAdventurerStats = async () => { if (entropyReady && adventurer?.level == 2) { - const stats = (await gameContract!.call("get_stats", [ + const updatedAdventurer = (await gameContract!.call("get_adventurer", [ adventurer?.id!, ])) as any; - console.log(stats); updateAdventurerStats({ - strength: parseInt(stats.strength), - dexterity: parseInt(stats.dexterity), - vitality: parseInt(stats.vitality), - intelligence: parseInt(stats.intelligence), - wisdom: parseInt(stats.wisdom), - charisma: parseInt(stats.charisma), - luck: parseInt(stats.luck), + health: parseInt(updatedAdventurer.health), + strength: parseInt(updatedAdventurer.stats.strength), + dexterity: parseInt(updatedAdventurer.stats.dexterity), + vitality: parseInt(updatedAdventurer.stats.vitality), + intelligence: parseInt(updatedAdventurer.stats.intelligence), + wisdom: parseInt(updatedAdventurer.stats.wisdom), + charisma: parseInt(updatedAdventurer.stats.charisma), + luck: parseInt(updatedAdventurer.stats.luck), }); } }; @@ -168,9 +166,6 @@ export default function UpgradeScreen({ fetchAdventurerStats(); }, [entropyReady]); - console.log(entropyReady); - console.log(adventurer); - const gameData = new GameData(); const checkTransacting = @@ -307,8 +302,13 @@ export default function UpgradeScreen({ const selectedCharisma = upgrades["Charisma"] ?? 0; const selectedVitality = upgrades["Vitality"] ?? 0; - const totalVitality = (adventurer?.vitality ?? 0) + selectedVitality; - const totalCharisma = (adventurer?.charisma ?? 0) + selectedCharisma; + const [totalVitality, setTotalVitality] = useState(0); + const [totalCharisma, setTotalCharisma] = useState(0); + + useEffect(() => { + setTotalVitality((adventurer?.vitality ?? 0) + selectedVitality); + setTotalCharisma((adventurer?.charisma ?? 0) + selectedCharisma); + }, [adventurer, selectedVitality, selectedCharisma]); const purchaseGoldAmount = potionAmount * getPotionPrice(adventurer?.level ?? 0, totalCharisma); diff --git a/ui/src/app/lib/utils/parseEvents.ts b/ui/src/app/lib/utils/parseEvents.ts index 363dd1cff..4ed151481 100644 --- a/ui/src/app/lib/utils/parseEvents.ts +++ b/ui/src/app/lib/utils/parseEvents.ts @@ -557,7 +557,7 @@ export async function parseEvents( bag: parseBag(raw.data.slice(32, 63)), }, // Skip array length - purchases: parseItems(raw.data.slice(65)), + purchases: parseItems(raw.data.slice(64)), }; const purchasedItemsEvent = processData( purchasedItemsData, @@ -585,7 +585,7 @@ export async function parseEvents( case "EquippedItems": const { equippedItems, unequippedItems } = parseEquippedItems( // Include equipped array length - raw.data.slice(65) + raw.data.slice(63) ); const equippedItemsData: EquippedItemsEvent = { adventurerStateWithBag: { diff --git a/ui/src/app/lib/utils/syscalls.ts b/ui/src/app/lib/utils/syscalls.ts index a61e120c0..709fc9159 100644 --- a/ui/src/app/lib/utils/syscalls.ts +++ b/ui/src/app/lib/utils/syscalls.ts @@ -370,7 +370,6 @@ export function syscalls({ createdTime: new Date(), } ); - console.log(startGameEvents); const adventurerState = events.find( (event) => event.name === "AmbushedByBeast" ).data[0]; @@ -1154,12 +1153,6 @@ export function syscalls({ items: [...filteredDrops, ...purchasedItems], }); - console.log({ - Stats: upgrades, - Items: purchaseItems, - Potions: potionAmount, - }); - // Reset items to no availability setData("latestMarketItemsQuery", null); stopLoading( From f1372a022e1fec2c0c806041890c4e5253b9bf8c Mon Sep 17 00:00:00 2001 From: Starknet Dev Date: Tue, 28 May 2024 11:57:29 +0100 Subject: [PATCH 13/18] - update .env preview --- ui/.env.preview | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/ui/.env.preview b/ui/.env.preview index 5f5147202..d3a85821f 100644 --- a/ui/.env.preview +++ b/ui/.env.preview @@ -1,12 +1,12 @@ NEXT_PUBLIC_NETWORK=sepolia NEXT_PUBLIC_RPC_URL=https://starknet-sepolia.blastapi.io/5ef61753-e7c1-4593-bc62-97fdf96f8de5 NEXT_PUBLIC_RPC_API_KEY=5ef61753-e7c1-4593-bc62-97fdf96f8de5 -NEXT_PUBLIC_LS_GQL_URL=https://survivor-sepolia-indexer.realms.world/graphql +NEXT_PUBLIC_LS_GQL_URL=https://ls-indexer-sepolia-temp.provable.games/graphql NEXT_PUBLIC_TOKENS_GQL_URL=https://testnet.realms.world/api/graphql NEXT_PUBLIC_ETH_ADDRESS=0x049d36570d4e46f48e99674bd3fcc84644ddd6b96f7c741b1562b82f9e004dc7 -NEXT_PUBLIC_GAME_ADDRESS=0x06c63851635f1e0ee0695a157292892cabaa030a8eca20a32b6a86c968c47c33 +NEXT_PUBLIC_GAME_ADDRESS=0x0496eb7a811ae24e0b88b3abc97abd3e084c0c58ad8de34051f60903fa2aa4db NEXT_PUBLIC_OLD_GAME_ADDRESS=0x0 -NEXT_PUBLIC_LORDS_ADDRESS=0x024cadb6d8592309d08a7a4e3b00017f8431759ee6c3d09b2ce37c693c786da7 +NEXT_PUBLIC_LORDS_ADDRESS=0xa2516792efec852999cfd1d69a3caab70a168f7bb59c257065f64281df93a5 NEXT_PUBLIC_BEASTS_ADDRESS=0x020c7c02c973ffa3a48fb78e9472b679c72c11b59512f524154ade0a39f54136 NEXT_PUBLIC_GOLDEN_TOKEN_ADDRESS=0x07626660faba349aad9ad2aaa0ff8645c079fa8e043a168d640d92472806eeac NEXT_PUBLIC_ARCADE_ACCOUNT_CLASS_HASH=0x0251830adc3d8b4d818c2c309d71f1958308e8c745212480c26e01120c69ee49 From e34d8d9af8ad4b78c6ea45fff8fb628fc557dc03 Mon Sep 17 00:00:00 2001 From: Starknet Dev Date: Tue, 28 May 2024 12:18:07 +0100 Subject: [PATCH 14/18] - remove leaderboard campaign table - fix build --- .../app/components/leaderboard/ScoreTable.tsx | 36 ++----------------- ui/src/app/containers/BeastScreen.tsx | 3 +- ui/src/app/containers/UpgradeScreen.tsx | 1 - 3 files changed, 4 insertions(+), 36 deletions(-) diff --git a/ui/src/app/components/leaderboard/ScoreTable.tsx b/ui/src/app/components/leaderboard/ScoreTable.tsx index 0a252dde8..c16fe9104 100644 --- a/ui/src/app/components/leaderboard/ScoreTable.tsx +++ b/ui/src/app/components/leaderboard/ScoreTable.tsx @@ -21,20 +21,10 @@ const ScoreLeaderboardTable = ({ const [currentPage, setCurrentPage] = useState(1); const setScreen = useUIStore((state) => state.setScreen); const setProfile = useUIStore((state) => state.setProfile); - const campaignAdventurers = adventurers.filter( - (score) => score.startBlock! > 942308 - ); - const displayScores = adventurers?.slice( (currentPage - 1) * itemsPerPage, currentPage * itemsPerPage ); - - const campaignDisplayScores = campaignAdventurers?.slice( - (currentPage - 1) * itemsPerPage, - currentPage * itemsPerPage - ); - const scoreIds = adventurers?.map((score) => score.id ?? 0); const scoresData = useCustomQuery("topScoresQuery", getScoresInList, { @@ -52,27 +42,12 @@ const ScoreLeaderboardTable = ({ }; }); - const campaignMergedScores = campaignDisplayScores.map((item1) => { - const matchingItem2 = scoresData?.scores.find( - (item2: Score) => item2.adventurerId === item1.id - ); - - return { - ...item1, - ...matchingItem2, - }; - }); - const scoresWithLords = mergedScores; const onMainnet = process.env.NEXT_PUBLIC_NETWORK === "mainnet"; const onSepolia = process.env.NEXT_PUBLIC_NETWORK === "sepolia"; - const totalPages = Math.ceil( - (!onMainnet && !onSepolia && !showAllTime - ? campaignAdventurers.length - : adventurers.length) / itemsPerPage - ); + const totalPages = Math.ceil(adventurers.length / itemsPerPage); let previousXp = -1; let currentRank = 0; @@ -137,10 +112,7 @@ const ScoreLeaderboardTable = ({ - {(!onMainnet && !onSepolia && !showAllTime - ? campaignMergedScores - : scoresWithLords - ).map((adventurer: any, index: number) => ( + {scoresWithLords.map((adventurer: any, index: number) => ( - {(!onMainnet && !onSepolia && !showAllTime - ? campaignAdventurers.length - : adventurers.length) > 10 && ( + {adventurers.length > 10 && (