create-dubhe 1.2.0-pre.98 → 2.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/cli.js +1 -1
- package/dist/cli.js.map +1 -1
- package/package.json +16 -16
- package/templates/101/sui-template/docker-compose.testnet.yml +73 -0
- package/templates/101/sui-template/packages/client/src/app/page.tsx +545 -41
- package/templates/101/sui-template/packages/client/src/app/providers.tsx +12 -4
- package/templates/101/sui-template/packages/contracts/Pub.localnet.toml +4 -4
- package/templates/101/sui-template/packages/contracts/counter.lock.json +20 -0
- package/templates/101/sui-template/packages/contracts/deployment.ts +8 -3
- package/templates/101/sui-template/packages/contracts/dubhe.config.json +59 -13
- package/templates/101/sui-template/packages/contracts/dubhe.config.ts +1 -4
- package/templates/101/sui-template/packages/contracts/metadata.json +1015 -68
- package/templates/101/sui-template/packages/contracts/package.json +7 -4
- package/templates/101/sui-template/packages/contracts/src/counter/sources/codegen/dapp_key.move +45 -31
- package/templates/101/sui-template/packages/contracts/src/counter/sources/codegen/error.move +8 -0
- package/templates/101/sui-template/packages/contracts/src/counter/sources/codegen/genesis.move +30 -13
- package/templates/101/sui-template/packages/contracts/src/counter/sources/codegen/init_test.move +19 -14
- package/templates/101/sui-template/packages/contracts/src/counter/sources/codegen/resources/counter2.move +198 -0
- package/templates/101/sui-template/packages/contracts/src/counter/sources/codegen/resources/counter2withkey.move +90 -0
- package/templates/101/sui-template/packages/contracts/src/counter/sources/codegen/resources/value.move +30 -20
- package/templates/101/sui-template/packages/contracts/src/counter/sources/codegen/user_storage_init.move +26 -0
- package/templates/101/sui-template/packages/contracts/src/counter/sources/scripts/deploy_hook.move +6 -11
- package/templates/101/sui-template/packages/contracts/src/counter/sources/systems/counter.move +23 -11
- package/templates/101/sui-template/packages/contracts/src/counter/sources/tests/counter.move +15 -14
- package/templates/101/sui-template/packages/contracts/src/dubhe/Move.lock +33 -30
- package/templates/101/sui-template/packages/contracts/src/dubhe/Move.toml +8 -3
- package/templates/101/sui-template/packages/contracts/src/dubhe/sources/codegen/dapp_key.move +45 -31
- package/templates/101/sui-template/packages/contracts/src/dubhe/sources/codegen/error.move +170 -0
- package/templates/101/sui-template/packages/contracts/src/dubhe/sources/codegen/genesis.move +16 -13
- package/templates/101/sui-template/packages/contracts/src/dubhe/sources/codegen/init_test.move +8 -14
- package/templates/101/sui-template/packages/contracts/src/dubhe/sources/core/account_key.move +1 -3
- package/templates/101/sui-template/packages/contracts/src/dubhe/sources/core/dapp_service.move +1776 -137
- package/templates/101/sui-template/packages/contracts/src/dubhe/sources/core/data_key.move +1 -20
- package/templates/101/sui-template/packages/contracts/src/dubhe/sources/core/events.move +864 -25
- package/templates/101/sui-template/packages/contracts/src/dubhe/sources/scripts/deploy_hook.move +15 -16
- package/templates/101/sui-template/packages/contracts/src/dubhe/sources/scripts/migrate.move +0 -3
- package/templates/101/sui-template/packages/contracts/src/dubhe/sources/systems/address_system.move +25 -17
- package/templates/101/sui-template/packages/contracts/src/dubhe/sources/systems/dapp_system.move +2802 -343
- package/templates/101/sui-template/packages/contracts/src/dubhe/sources/systems/utils.move +1 -1
- package/templates/101/sui-template/packages/contracts/src/dubhe/sources/tests/address.move +173 -55
- package/templates/101/sui-template/packages/contracts/src/dubhe/sources/tests/dapp_test.move +769 -0
- package/templates/101/sui-template/packages/contracts/src/dubhe/sources/tests/fee_test.move +2965 -0
- package/templates/101/sui-template/packages/contracts/src/dubhe/sources/tests/integration_test.move +303 -0
- package/templates/101/sui-template/packages/contracts/src/dubhe/sources/tests/listing_test.move +1422 -0
- package/templates/101/sui-template/packages/contracts/src/dubhe/sources/tests/scene_session_test.move +269 -0
- package/templates/101/sui-template/packages/contracts/src/dubhe/sources/tests/session_test.move +624 -0
- package/templates/101/sui-template/packages/contracts/src/dubhe/sources/tests/storage_test.move +700 -0
- package/templates/101/sui-template/packages/contracts/src/dubhe/sources/tests/typed_object_test.move +177 -0
- package/templates/101/sui-template/packages/contracts/src/dubhe/sources/tests/typed_scene_test.move +452 -0
- package/templates/101/sui-template/packages/contracts/src/dubhe/sources/tests/user_storage_test.move +160 -0
- package/templates/101/sui-template/packages/contracts/src/dubhe/sources/utils/math.move +4 -3
- package/templates/101/sui-template/packages/contracts/src/dubhe/sources/utils/type_info.move +2 -2
- package/templates/contract/sui-template/dubhe.config.ts +0 -1
- package/templates/contract/sui-template/package.json +3 -3
- package/templates/contract/sui-template/src/dubhe/Move.lock +33 -30
- package/templates/contract/sui-template/src/dubhe/Move.toml +8 -3
- package/templates/contract/sui-template/src/dubhe/sources/codegen/dapp_key.move +45 -31
- package/templates/contract/sui-template/src/dubhe/sources/codegen/error.move +170 -0
- package/templates/contract/sui-template/src/dubhe/sources/codegen/genesis.move +16 -13
- package/templates/contract/sui-template/src/dubhe/sources/codegen/init_test.move +8 -14
- package/templates/contract/sui-template/src/dubhe/sources/core/account_key.move +1 -3
- package/templates/contract/sui-template/src/dubhe/sources/core/dapp_service.move +1776 -137
- package/templates/contract/sui-template/src/dubhe/sources/core/data_key.move +1 -20
- package/templates/contract/sui-template/src/dubhe/sources/core/events.move +864 -25
- package/templates/contract/sui-template/src/dubhe/sources/scripts/deploy_hook.move +15 -16
- package/templates/contract/sui-template/src/dubhe/sources/scripts/migrate.move +0 -3
- package/templates/contract/sui-template/src/dubhe/sources/systems/address_system.move +25 -17
- package/templates/contract/sui-template/src/dubhe/sources/systems/dapp_system.move +2802 -343
- package/templates/contract/sui-template/src/dubhe/sources/systems/utils.move +1 -1
- package/templates/contract/sui-template/src/dubhe/sources/tests/address.move +173 -55
- package/templates/contract/sui-template/src/dubhe/sources/tests/dapp_test.move +769 -0
- package/templates/contract/sui-template/src/dubhe/sources/tests/fee_test.move +2965 -0
- package/templates/contract/sui-template/src/dubhe/sources/tests/integration_test.move +303 -0
- package/templates/contract/sui-template/src/dubhe/sources/tests/listing_test.move +1422 -0
- package/templates/contract/sui-template/src/dubhe/sources/tests/scene_session_test.move +269 -0
- package/templates/contract/sui-template/src/dubhe/sources/tests/session_test.move +624 -0
- package/templates/contract/sui-template/src/dubhe/sources/tests/storage_test.move +700 -0
- package/templates/contract/sui-template/src/dubhe/sources/tests/typed_object_test.move +177 -0
- package/templates/contract/sui-template/src/dubhe/sources/tests/typed_scene_test.move +452 -0
- package/templates/contract/sui-template/src/dubhe/sources/tests/user_storage_test.move +160 -0
- package/templates/contract/sui-template/src/dubhe/sources/utils/math.move +4 -3
- package/templates/contract/sui-template/src/dubhe/sources/utils/type_info.move +2 -2
- package/templates/contract/sui-template/src/template/Move.toml +12 -0
- package/templates/contract/sui-template/src/template/sources/codegen/dapp_key.move +47 -0
- package/templates/contract/sui-template/src/template/sources/codegen/genesis.move +34 -0
- package/templates/contract/sui-template/src/template/sources/codegen/init_test.move +23 -0
- package/templates/contract/sui-template/src/template/sources/codegen/user_storage_init.move +27 -0
- package/templates/contract/sui-template/src/template/sources/scripts/deploy_hook.move +13 -0
- package/templates/contract/sui-template/src/template/sources/scripts/migrate.move +7 -0
- package/templates/nextjs/sui-card-duel/.gitignore_ +51 -0
- package/templates/nextjs/sui-card-duel/README.md +213 -0
- package/templates/nextjs/sui-card-duel/docker-compose.yml +34 -0
- package/templates/nextjs/sui-card-duel/mprocs.yaml +17 -0
- package/templates/nextjs/sui-card-duel/package.json +43 -0
- package/templates/nextjs/sui-card-duel/packages/client/.gitignore_ +48 -0
- package/templates/nextjs/sui-card-duel/packages/client/.prettierignore +1 -0
- package/templates/nextjs/sui-card-duel/packages/client/.prettierrc.json +8 -0
- package/templates/nextjs/sui-card-duel/packages/client/eslint.config.mjs +22 -0
- package/templates/nextjs/sui-card-duel/packages/client/next.config.mjs +8 -0
- package/templates/nextjs/sui-card-duel/packages/client/package.json +47 -0
- package/templates/nextjs/sui-card-duel/packages/client/postcss.config.mjs +8 -0
- package/templates/nextjs/sui-card-duel/packages/client/src/app/admin/ArenaPanel.tsx +307 -0
- package/templates/nextjs/sui-card-duel/packages/client/src/app/admin/page.tsx +622 -0
- package/templates/nextjs/sui-card-duel/packages/client/src/app/brawl/[id]/page.tsx +559 -0
- package/templates/nextjs/sui-card-duel/packages/client/src/app/collection/page.tsx +202 -0
- package/templates/nextjs/sui-card-duel/packages/client/src/app/components/CardView.tsx +66 -0
- package/templates/nextjs/sui-card-duel/packages/client/src/app/components/GameShell.tsx +294 -0
- package/templates/nextjs/sui-card-duel/packages/client/src/app/components/icons.tsx +101 -0
- package/templates/nextjs/sui-card-duel/packages/client/src/app/duel/[id]/page.tsx +477 -0
- package/templates/nextjs/sui-card-duel/packages/client/src/app/favicon.ico +0 -0
- package/templates/nextjs/sui-card-duel/packages/client/src/app/globals.css +85 -0
- package/templates/nextjs/sui-card-duel/packages/client/src/app/hooks/useGame.ts +313 -0
- package/templates/nextjs/sui-card-duel/packages/client/src/app/layout.tsx +24 -0
- package/templates/nextjs/sui-card-duel/packages/client/src/app/leaderboard/page.tsx +123 -0
- package/templates/nextjs/sui-card-duel/packages/client/src/app/lib/game.ts +77 -0
- package/templates/nextjs/sui-card-duel/packages/client/src/app/lib/scenes.ts +226 -0
- package/templates/nextjs/sui-card-duel/packages/client/src/app/market/page.tsx +418 -0
- package/templates/nextjs/sui-card-duel/packages/client/src/app/page.tsx +427 -0
- package/templates/nextjs/sui-card-duel/packages/client/src/app/providers.tsx +69 -0
- package/templates/nextjs/sui-card-duel/packages/client/tailwind.config.ts +21 -0
- package/templates/nextjs/sui-card-duel/packages/client/tsconfig.json +30 -0
- package/templates/nextjs/sui-card-duel/packages/contracts/.gitignore_ +51 -0
- package/templates/nextjs/sui-card-duel/packages/contracts/.prettierignore +1 -0
- package/templates/nextjs/sui-card-duel/packages/contracts/.prettierrc.json +8 -0
- package/templates/nextjs/sui-card-duel/packages/contracts/Dockerfile +5 -0
- package/templates/nextjs/sui-card-duel/packages/contracts/Pub.localnet.toml +13 -0
- package/templates/nextjs/sui-card-duel/packages/contracts/card_duel.lock.json +66 -0
- package/templates/nextjs/sui-card-duel/packages/contracts/docker-compose.yml +34 -0
- package/templates/nextjs/sui-card-duel/packages/contracts/dubhe.config.ts +150 -0
- package/templates/nextjs/sui-card-duel/packages/contracts/logs/combined.log +31383 -0
- package/templates/nextjs/sui-card-duel/packages/contracts/package.json +49 -0
- package/templates/nextjs/sui-card-duel/packages/contracts/scripts/config.ts +17 -0
- package/templates/nextjs/sui-card-duel/packages/contracts/scripts/e2e-brawl.ts +270 -0
- package/templates/nextjs/sui-card-duel/packages/contracts/scripts/e2e-duel.ts +272 -0
- package/templates/nextjs/sui-card-duel/packages/contracts/scripts/e2e-lobby.ts +177 -0
- package/templates/nextjs/sui-card-duel/packages/contracts/scripts/e2e-market.ts +219 -0
- package/templates/nextjs/sui-card-duel/packages/contracts/scripts/e2e-session.ts +342 -0
- package/templates/nextjs/sui-card-duel/packages/contracts/scripts/query-dapp-revenue.ts +95 -0
- package/templates/nextjs/sui-card-duel/packages/contracts/scripts/seed.ts +92 -0
- package/templates/nextjs/sui-card-duel/packages/contracts/scripts/withdraw-dapp-revenue.ts +56 -0
- package/templates/nextjs/sui-card-duel/packages/contracts/src/card_duel/Move.toml +15 -0
- package/templates/nextjs/sui-card-duel/packages/contracts/src/card_duel/sources/codegen/dapp_key.move +46 -0
- package/templates/nextjs/sui-card-duel/packages/contracts/src/card_duel/sources/codegen/enums/card_kind.move +47 -0
- package/templates/nextjs/sui-card-duel/packages/contracts/src/card_duel/sources/codegen/enums/match_state.move +37 -0
- package/templates/nextjs/sui-card-duel/packages/contracts/src/card_duel/sources/codegen/enums/rarity.move +37 -0
- package/templates/nextjs/sui-card-duel/packages/contracts/src/card_duel/sources/codegen/error.move +126 -0
- package/templates/nextjs/sui-card-duel/packages/contracts/src/card_duel/sources/codegen/genesis.move +33 -0
- package/templates/nextjs/sui-card-duel/packages/contracts/src/card_duel/sources/codegen/init_test.move +23 -0
- package/templates/nextjs/sui-card-duel/packages/contracts/src/card_duel/sources/codegen/objects/arena.move +137 -0
- package/templates/nextjs/sui-card-duel/packages/contracts/src/card_duel/sources/codegen/permits/brawl_permit.move +125 -0
- package/templates/nextjs/sui-card-duel/packages/contracts/src/card_duel/sources/codegen/permits/duel_permit.move +125 -0
- package/templates/nextjs/sui-card-duel/packages/contracts/src/card_duel/sources/codegen/resources/battle_state.move +255 -0
- package/templates/nextjs/sui-card-duel/packages/contracts/src/card_duel/sources/codegen/resources/card.move +282 -0
- package/templates/nextjs/sui-card-duel/packages/contracts/src/card_duel/sources/codegen/resources/deck.move +64 -0
- package/templates/nextjs/sui-card-duel/packages/contracts/src/card_duel/sources/codegen/resources/game_config.move +267 -0
- package/templates/nextjs/sui-card-duel/packages/contracts/src/card_duel/sources/codegen/resources/gold.move +205 -0
- package/templates/nextjs/sui-card-duel/packages/contracts/src/card_duel/sources/codegen/resources/profile.move +255 -0
- package/templates/nextjs/sui-card-duel/packages/contracts/src/card_duel/sources/codegen/scenes/brawl.move +313 -0
- package/templates/nextjs/sui-card-duel/packages/contracts/src/card_duel/sources/codegen/scenes/duel.move +313 -0
- package/templates/nextjs/sui-card-duel/packages/contracts/src/card_duel/sources/codegen/user_storage_init.move +26 -0
- package/templates/nextjs/sui-card-duel/packages/contracts/src/card_duel/sources/scripts/deploy_hook.move +32 -0
- package/templates/nextjs/sui-card-duel/packages/contracts/src/card_duel/sources/scripts/migrate.move +7 -0
- package/templates/nextjs/sui-card-duel/packages/contracts/src/card_duel/sources/systems/arena_system.move +57 -0
- package/templates/nextjs/sui-card-duel/packages/contracts/src/card_duel/sources/systems/brawl_system.move +559 -0
- package/templates/nextjs/sui-card-duel/packages/contracts/src/card_duel/sources/systems/card_system.move +146 -0
- package/templates/nextjs/sui-card-duel/packages/contracts/src/card_duel/sources/systems/duel_system.move +515 -0
- package/templates/nextjs/sui-card-duel/packages/contracts/src/card_duel/sources/systems/market_system.move +115 -0
- package/templates/nextjs/sui-card-duel/packages/contracts/src/card_duel/sources/systems/player_system.move +37 -0
- package/templates/nextjs/sui-card-duel/packages/contracts/src/card_duel/sources/tests/brawl_tests.move +385 -0
- package/templates/nextjs/sui-card-duel/packages/contracts/src/card_duel/sources/tests/duel_tests.move +656 -0
- package/templates/nextjs/sui-card-duel/packages/contracts/src/card_duel/sources/tests/test_helpers.move +31 -0
- package/templates/nextjs/sui-card-duel/packages/contracts/sui-indexer-schema.graphql +5973 -0
- package/templates/nextjs/sui-card-duel/pnpm-workspace.yaml +2 -0
- package/templates/nextjs/sui-farm/.gitignore_ +51 -0
- package/templates/nextjs/sui-farm/README.md +15 -0
- package/templates/nextjs/sui-farm/UPGRADE_NOTES.md +97 -0
- package/templates/nextjs/sui-farm/docker-compose.yml +34 -0
- package/templates/nextjs/sui-farm/mprocs.yaml +17 -0
- package/templates/nextjs/sui-farm/package.json +43 -0
- package/templates/nextjs/sui-farm/packages/client/.gitignore_ +48 -0
- package/templates/nextjs/sui-farm/packages/client/.prettierignore +1 -0
- package/templates/nextjs/sui-farm/packages/client/.prettierrc.json +8 -0
- package/templates/nextjs/sui-farm/packages/client/eslint.config.mjs +22 -0
- package/templates/nextjs/sui-farm/packages/client/next.config.mjs +8 -0
- package/templates/nextjs/sui-farm/packages/client/package.json +47 -0
- package/templates/nextjs/sui-farm/packages/client/postcss.config.mjs +8 -0
- package/templates/nextjs/sui-farm/packages/client/src/app/admin/page.tsx +618 -0
- package/templates/nextjs/sui-farm/packages/client/src/app/components/FarmLand.tsx +526 -0
- package/templates/nextjs/sui-farm/packages/client/src/app/components/FarmPlotCard.tsx +215 -0
- package/templates/nextjs/sui-farm/packages/client/src/app/components/PetAvatar.tsx +868 -0
- package/templates/nextjs/sui-farm/packages/client/src/app/components/PetPanel.tsx +1360 -0
- package/templates/nextjs/sui-farm/packages/client/src/app/components/PlantModal.tsx +147 -0
- package/templates/nextjs/sui-farm/packages/client/src/app/components/ProxyCard.tsx +684 -0
- package/templates/nextjs/sui-farm/packages/client/src/app/components/RanchLand.tsx +822 -0
- package/templates/nextjs/sui-farm/packages/client/src/app/components/ResourceHUD.tsx +125 -0
- package/templates/nextjs/sui-farm/packages/client/src/app/components/ShopPanel.tsx +232 -0
- package/templates/nextjs/sui-farm/packages/client/src/app/components/icons/GameIcons.tsx +574 -0
- package/templates/nextjs/sui-farm/packages/client/src/app/favicon.ico +0 -0
- package/templates/nextjs/sui-farm/packages/client/src/app/globals.css +423 -0
- package/templates/nextjs/sui-farm/packages/client/src/app/hooks/useWorldPermitId.ts +66 -0
- package/templates/nextjs/sui-farm/packages/client/src/app/layout.tsx +23 -0
- package/templates/nextjs/sui-farm/packages/client/src/app/leaderboard/page.tsx +185 -0
- package/templates/nextjs/sui-farm/packages/client/src/app/lib/crops.ts +97 -0
- package/templates/nextjs/sui-farm/packages/client/src/app/market/page.tsx +763 -0
- package/templates/nextjs/sui-farm/packages/client/src/app/page.tsx +1173 -0
- package/templates/nextjs/sui-farm/packages/client/src/app/providers.tsx +69 -0
- package/templates/nextjs/sui-farm/packages/client/src/app/state/index.tsx +5 -0
- package/templates/nextjs/sui-farm/packages/client/tailwind.config.ts +25 -0
- package/templates/nextjs/sui-farm/packages/client/tsconfig.json +30 -0
- package/templates/nextjs/sui-farm/packages/contracts/.gitignore_ +51 -0
- package/templates/nextjs/sui-farm/packages/contracts/.prettierignore +1 -0
- package/templates/nextjs/sui-farm/packages/contracts/.prettierrc.json +8 -0
- package/templates/nextjs/sui-farm/packages/contracts/Dockerfile +5 -0
- package/templates/nextjs/sui-farm/packages/contracts/Pub.localnet.toml +13 -0
- package/templates/nextjs/sui-farm/packages/contracts/counter.lock.json +14 -0
- package/templates/nextjs/sui-farm/packages/contracts/docker-compose.yml +34 -0
- package/templates/nextjs/sui-farm/packages/contracts/dubhe.config.ts +178 -0
- package/templates/nextjs/sui-farm/packages/contracts/harvest.lock.json +120 -0
- package/templates/nextjs/sui-farm/packages/contracts/package.json +48 -0
- package/templates/nextjs/sui-farm/packages/contracts/scripts/config.ts +17 -0
- package/templates/nextjs/sui-farm/packages/contracts/scripts/query-dapp-revenue.ts +95 -0
- package/templates/nextjs/sui-farm/packages/contracts/scripts/read-permit.ts +72 -0
- package/templates/nextjs/sui-farm/packages/contracts/scripts/seed.ts +85 -0
- package/templates/nextjs/sui-farm/packages/contracts/scripts/withdraw-dapp-revenue.ts +56 -0
- package/templates/nextjs/sui-farm/packages/contracts/src/counter/Move.toml +14 -0
- package/templates/nextjs/sui-farm/packages/contracts/src/counter/sources/codegen/dapp_key.move +31 -0
- package/templates/nextjs/sui-farm/packages/contracts/src/counter/sources/codegen/error.move +10 -0
- package/templates/nextjs/sui-farm/packages/contracts/src/counter/sources/codegen/genesis.move +33 -0
- package/templates/nextjs/sui-farm/packages/contracts/src/counter/sources/codegen/init_test.move +23 -0
- package/templates/nextjs/sui-farm/packages/contracts/src/counter/sources/codegen/resources/counter1.move +64 -0
- package/templates/nextjs/sui-farm/packages/contracts/src/counter/sources/codegen/resources/counter2.move +70 -0
- package/templates/nextjs/sui-farm/packages/contracts/src/counter/sources/codegen/user_storage_init.move +26 -0
- package/templates/nextjs/sui-farm/packages/contracts/src/counter/sources/scripts/deploy_hook.move +8 -0
- package/templates/nextjs/sui-farm/packages/contracts/src/counter/sources/scripts/migrate.move +8 -0
- package/templates/nextjs/sui-farm/packages/contracts/src/counter/sources/systems/counter.move +13 -0
- package/templates/nextjs/sui-farm/packages/contracts/src/counter/sources/tests/counter.move +28 -0
- package/templates/nextjs/sui-farm/packages/contracts/src/harvest/Move.toml +14 -0
- package/templates/nextjs/sui-farm/packages/contracts/src/harvest/sources/codegen/dapp_key.move +46 -0
- package/templates/nextjs/sui-farm/packages/contracts/src/harvest/sources/codegen/enums/crop_type.move +47 -0
- package/templates/nextjs/sui-farm/packages/contracts/src/harvest/sources/codegen/enums/egg_type.move +42 -0
- package/templates/nextjs/sui-farm/packages/contracts/src/harvest/sources/codegen/enums/pet_rarity.move +37 -0
- package/templates/nextjs/sui-farm/packages/contracts/src/harvest/sources/codegen/enums/pet_species.move +52 -0
- package/templates/nextjs/sui-farm/packages/contracts/src/harvest/sources/codegen/error.move +110 -0
- package/templates/nextjs/sui-farm/packages/contracts/src/harvest/sources/codegen/genesis.move +33 -0
- package/templates/nextjs/sui-farm/packages/contracts/src/harvest/sources/codegen/init_test.move +23 -0
- package/templates/nextjs/sui-farm/packages/contracts/src/harvest/sources/codegen/permits/world.move +125 -0
- package/templates/nextjs/sui-farm/packages/contracts/src/harvest/sources/codegen/resources/carrot.move +136 -0
- package/templates/nextjs/sui-farm/packages/contracts/src/harvest/sources/codegen/resources/carrot_seed.move +80 -0
- package/templates/nextjs/sui-farm/packages/contracts/src/harvest/sources/codegen/resources/common_egg.move +136 -0
- package/templates/nextjs/sui-farm/packages/contracts/src/harvest/sources/codegen/resources/corn.move +136 -0
- package/templates/nextjs/sui-farm/packages/contracts/src/harvest/sources/codegen/resources/corn_seed.move +80 -0
- package/templates/nextjs/sui-farm/packages/contracts/src/harvest/sources/codegen/resources/crow_charges.move +162 -0
- package/templates/nextjs/sui-farm/packages/contracts/src/harvest/sources/codegen/resources/crow_damage.move +207 -0
- package/templates/nextjs/sui-farm/packages/contracts/src/harvest/sources/codegen/resources/farm_plot.move +261 -0
- package/templates/nextjs/sui-farm/packages/contracts/src/harvest/sources/codegen/resources/gold.move +80 -0
- package/templates/nextjs/sui-farm/packages/contracts/src/harvest/sources/codegen/resources/pet.move +467 -0
- package/templates/nextjs/sui-farm/packages/contracts/src/harvest/sources/codegen/resources/pet_config.move +372 -0
- package/templates/nextjs/sui-farm/packages/contracts/src/harvest/sources/codegen/resources/pet_hatch.move +162 -0
- package/templates/nextjs/sui-farm/packages/contracts/src/harvest/sources/codegen/resources/pet_slot_index.move +83 -0
- package/templates/nextjs/sui-farm/packages/contracts/src/harvest/sources/codegen/resources/pet_slots.move +64 -0
- package/templates/nextjs/sui-farm/packages/contracts/src/harvest/sources/codegen/resources/profile.move +162 -0
- package/templates/nextjs/sui-farm/packages/contracts/src/harvest/sources/codegen/resources/pumpkin.move +136 -0
- package/templates/nextjs/sui-farm/packages/contracts/src/harvest/sources/codegen/resources/pumpkin_seed.move +80 -0
- package/templates/nextjs/sui-farm/packages/contracts/src/harvest/sources/codegen/resources/rare_egg.move +136 -0
- package/templates/nextjs/sui-farm/packages/contracts/src/harvest/sources/codegen/resources/scarecrow.move +64 -0
- package/templates/nextjs/sui-farm/packages/contracts/src/harvest/sources/codegen/resources/season_config.move +197 -0
- package/templates/nextjs/sui-farm/packages/contracts/src/harvest/sources/codegen/resources/season_stats.move +64 -0
- package/templates/nextjs/sui-farm/packages/contracts/src/harvest/sources/codegen/resources/seasonal_egg.move +136 -0
- package/templates/nextjs/sui-farm/packages/contracts/src/harvest/sources/codegen/resources/shop_config.move +267 -0
- package/templates/nextjs/sui-farm/packages/contracts/src/harvest/sources/codegen/resources/trophy.move +245 -0
- package/templates/nextjs/sui-farm/packages/contracts/src/harvest/sources/codegen/resources/wheat.move +136 -0
- package/templates/nextjs/sui-farm/packages/contracts/src/harvest/sources/codegen/resources/wheat_seed.move +80 -0
- package/templates/nextjs/sui-farm/packages/contracts/src/harvest/sources/codegen/resources/world_permit_id.move +64 -0
- package/templates/nextjs/sui-farm/packages/contracts/src/harvest/sources/codegen/user_storage_init.move +26 -0
- package/templates/nextjs/sui-farm/packages/contracts/src/harvest/sources/scripts/deploy_hook.move +45 -0
- package/templates/nextjs/sui-farm/packages/contracts/src/harvest/sources/scripts/migrate.move +7 -0
- package/templates/nextjs/sui-farm/packages/contracts/src/harvest/sources/systems/crow_system.move +96 -0
- package/templates/nextjs/sui-farm/packages/contracts/src/harvest/sources/systems/farm_system.move +182 -0
- package/templates/nextjs/sui-farm/packages/contracts/src/harvest/sources/systems/market_system.move +172 -0
- package/templates/nextjs/sui-farm/packages/contracts/src/harvest/sources/systems/pet_system.move +495 -0
- package/templates/nextjs/sui-farm/packages/contracts/src/harvest/sources/systems/season_system.move +70 -0
- package/templates/nextjs/sui-farm/packages/contracts/src/harvest/sources/systems/shop_system.move +112 -0
- package/templates/nextjs/sui-farm/packages/contracts/src/harvest/sources/systems/world_system.move +34 -0
- package/templates/nextjs/sui-farm/packages/contracts/src/harvest/sources/tests/farm_tests.move +1192 -0
- package/templates/nextjs/sui-farm/pnpm-workspace.yaml +2 -0
- package/templates/nextjs/sui-template/packages/client/src/app/components/ProxyCard.tsx +683 -0
- package/templates/nextjs/sui-template/packages/client/src/app/page.tsx +510 -5
- package/templates/nextjs/sui-template/packages/client/src/app/providers.tsx +13 -5
- package/templates/nextjs/sui-template/packages/contracts/Pub.localnet.toml +4 -4
- package/templates/nextjs/sui-template/packages/contracts/counter.lock.json +14 -0
- package/templates/nextjs/sui-template/packages/contracts/deployment.ts +8 -3
- package/templates/nextjs/sui-template/packages/contracts/dubhe.config.json +9 -9
- package/templates/nextjs/sui-template/packages/contracts/dubhe.config.ts +0 -4
- package/templates/nextjs/sui-template/packages/contracts/metadata.json +180 -124
- package/templates/nextjs/sui-template/packages/contracts/package.json +8 -4
- package/templates/nextjs/sui-template/packages/contracts/src/counter/Move.toml +4 -0
- package/templates/nextjs/sui-template/packages/contracts/src/counter/sources/codegen/dapp_key.move +45 -31
- package/templates/nextjs/sui-template/packages/contracts/src/counter/sources/codegen/error.move +10 -0
- package/templates/nextjs/sui-template/packages/contracts/src/counter/sources/codegen/genesis.move +30 -13
- package/templates/nextjs/sui-template/packages/contracts/src/counter/sources/codegen/init_test.move +19 -14
- package/templates/nextjs/sui-template/packages/contracts/src/counter/sources/codegen/resources/counter1.move +30 -20
- package/templates/nextjs/sui-template/packages/contracts/src/counter/sources/codegen/resources/counter2.move +35 -24
- package/templates/nextjs/sui-template/packages/contracts/src/counter/sources/codegen/user_storage_init.move +26 -0
- package/templates/nextjs/sui-template/packages/contracts/src/counter/sources/scripts/deploy_hook.move +6 -10
- package/templates/nextjs/sui-template/packages/contracts/src/counter/sources/systems/counter.move +7 -20
- package/templates/nextjs/sui-template/packages/contracts/src/counter/sources/tests/counter.move +14 -27
- package/templates/nextjs/sui-template/packages/contracts/src/dubhe/Move.lock +33 -30
- package/templates/nextjs/sui-template/packages/contracts/src/dubhe/Move.toml +8 -3
- package/templates/nextjs/sui-template/packages/contracts/src/dubhe/sources/codegen/dapp_key.move +45 -31
- package/templates/nextjs/sui-template/packages/contracts/src/dubhe/sources/codegen/error.move +170 -0
- package/templates/nextjs/sui-template/packages/contracts/src/dubhe/sources/codegen/genesis.move +16 -13
- package/templates/nextjs/sui-template/packages/contracts/src/dubhe/sources/codegen/init_test.move +8 -14
- package/templates/nextjs/sui-template/packages/contracts/src/dubhe/sources/core/account_key.move +1 -3
- package/templates/nextjs/sui-template/packages/contracts/src/dubhe/sources/core/dapp_service.move +1776 -137
- package/templates/nextjs/sui-template/packages/contracts/src/dubhe/sources/core/data_key.move +1 -20
- package/templates/nextjs/sui-template/packages/contracts/src/dubhe/sources/core/events.move +864 -25
- package/templates/nextjs/sui-template/packages/contracts/src/dubhe/sources/scripts/deploy_hook.move +15 -16
- package/templates/nextjs/sui-template/packages/contracts/src/dubhe/sources/scripts/migrate.move +0 -3
- package/templates/nextjs/sui-template/packages/contracts/src/dubhe/sources/systems/address_system.move +25 -17
- package/templates/nextjs/sui-template/packages/contracts/src/dubhe/sources/systems/dapp_system.move +2802 -343
- package/templates/nextjs/sui-template/packages/contracts/src/dubhe/sources/systems/utils.move +1 -1
- package/templates/nextjs/sui-template/packages/contracts/src/dubhe/sources/tests/address.move +173 -55
- package/templates/nextjs/sui-template/packages/contracts/src/dubhe/sources/tests/dapp_test.move +769 -0
- package/templates/nextjs/sui-template/packages/contracts/src/dubhe/sources/tests/fee_test.move +2965 -0
- package/templates/nextjs/sui-template/packages/contracts/src/dubhe/sources/tests/integration_test.move +303 -0
- package/templates/nextjs/sui-template/packages/contracts/src/dubhe/sources/tests/listing_test.move +1422 -0
- package/templates/nextjs/sui-template/packages/contracts/src/dubhe/sources/tests/scene_session_test.move +269 -0
- package/templates/nextjs/sui-template/packages/contracts/src/dubhe/sources/tests/session_test.move +624 -0
- package/templates/nextjs/sui-template/packages/contracts/src/dubhe/sources/tests/storage_test.move +700 -0
- package/templates/nextjs/sui-template/packages/contracts/src/dubhe/sources/tests/typed_object_test.move +177 -0
- package/templates/nextjs/sui-template/packages/contracts/src/dubhe/sources/tests/typed_scene_test.move +452 -0
- package/templates/nextjs/sui-template/packages/contracts/src/dubhe/sources/tests/user_storage_test.move +160 -0
- package/templates/nextjs/sui-template/packages/contracts/src/dubhe/sources/utils/math.move +4 -3
- package/templates/nextjs/sui-template/packages/contracts/src/dubhe/sources/utils/type_info.move +2 -2
- package/templates/101/sui-template/packages/contracts/src/counter/Move.lock +0 -41
- package/templates/101/sui-template/packages/contracts/src/counter/Published.toml +0 -9
- package/templates/101/sui-template/packages/contracts/src/counter/sources/codegen/errors.move +0 -12
- package/templates/101/sui-template/packages/contracts/src/dubhe/sources/codegen/errors.move +0 -140
- package/templates/101/sui-template/packages/contracts/src/dubhe/sources/codegen/resources/dapp_fee_config.move +0 -186
- package/templates/101/sui-template/packages/contracts/src/dubhe/sources/codegen/resources/dapp_fee_state.move +0 -306
- package/templates/101/sui-template/packages/contracts/src/dubhe/sources/codegen/resources/dapp_metadata.move +0 -396
- package/templates/101/sui-template/packages/contracts/src/dubhe/sources/codegen/resources/dubhe_config.move +0 -246
- package/templates/101/sui-template/packages/contracts/src/dubhe/sources/core/dapp_store.move +0 -29
- package/templates/101/sui-template/packages/contracts/src/dubhe/sources/systems/session_system.move +0 -44
- package/templates/contract/sui-template/src/dubhe/sources/codegen/errors.move +0 -140
- package/templates/contract/sui-template/src/dubhe/sources/codegen/resources/dapp_fee_config.move +0 -186
- package/templates/contract/sui-template/src/dubhe/sources/codegen/resources/dapp_fee_state.move +0 -306
- package/templates/contract/sui-template/src/dubhe/sources/codegen/resources/dapp_metadata.move +0 -396
- package/templates/contract/sui-template/src/dubhe/sources/codegen/resources/dubhe_config.move +0 -246
- package/templates/contract/sui-template/src/dubhe/sources/core/dapp_store.move +0 -29
- package/templates/contract/sui-template/src/dubhe/sources/systems/session_system.move +0 -44
- package/templates/nextjs/sui-template/packages/contracts/src/counter/Move.lock +0 -47
- package/templates/nextjs/sui-template/packages/contracts/src/counter/Published.toml +0 -9
- package/templates/nextjs/sui-template/packages/contracts/src/counter/sources/codegen/errors.move +0 -12
- package/templates/nextjs/sui-template/packages/contracts/src/dubhe/sources/codegen/errors.move +0 -140
- package/templates/nextjs/sui-template/packages/contracts/src/dubhe/sources/codegen/resources/dapp_fee_config.move +0 -186
- package/templates/nextjs/sui-template/packages/contracts/src/dubhe/sources/codegen/resources/dapp_fee_state.move +0 -306
- package/templates/nextjs/sui-template/packages/contracts/src/dubhe/sources/codegen/resources/dapp_metadata.move +0 -396
- package/templates/nextjs/sui-template/packages/contracts/src/dubhe/sources/codegen/resources/dubhe_config.move +0 -246
- package/templates/nextjs/sui-template/packages/contracts/src/dubhe/sources/core/dapp_store.move +0 -29
- package/templates/nextjs/sui-template/packages/contracts/src/dubhe/sources/systems/session_system.move +0 -44
|
@@ -0,0 +1,559 @@
|
|
|
1
|
+
/// Multiplayer brawl (1vN) built on an open-invite ScenePermit: anyone can
|
|
2
|
+
/// join the room until it is full, the pot collects every entry fee, and the
|
|
3
|
+
/// last player standing takes it (minus the arena rake).
|
|
4
|
+
///
|
|
5
|
+
/// Lifecycle:
|
|
6
|
+
/// create_brawl host opens a room with an entry fee and a player cap
|
|
7
|
+
/// join_brawl anyone joins while the room is open (pays the fee)
|
|
8
|
+
/// leave_brawl leave an open room and get the fee back
|
|
9
|
+
/// cancel_brawl host closes an open room once everyone else has left
|
|
10
|
+
/// start_brawl host starts the match with 2+ players
|
|
11
|
+
/// brawl_attack attack any alive player on your turn (cards are reusable)
|
|
12
|
+
/// brawl_defend heal / shield yourself on your turn
|
|
13
|
+
/// brawl_surrender / brawl_timeout_kick leave or remove stalling players
|
|
14
|
+
/// finish_brawl last player standing collects the pot
|
|
15
|
+
/// leave_finished_brawl / cleanup_brawl post-match hygiene
|
|
16
|
+
module card_duel::brawl_system {
|
|
17
|
+
use sui::clock::Clock;
|
|
18
|
+
use dubhe::dapp_service::{Self, DappStorage, UserStorage, ScenePermit, SceneStorage, ObjectStorage};
|
|
19
|
+
use dubhe::dapp_system;
|
|
20
|
+
use card_duel::dapp_key;
|
|
21
|
+
use card_duel::dapp_key::DappKey;
|
|
22
|
+
use card_duel::migrate;
|
|
23
|
+
use card_duel::error;
|
|
24
|
+
use card_duel::gold;
|
|
25
|
+
use card_duel::profile;
|
|
26
|
+
use card_duel::battle_state;
|
|
27
|
+
use card_duel::deck;
|
|
28
|
+
use card_duel::card;
|
|
29
|
+
use card_duel::card_system;
|
|
30
|
+
use card_duel::game_config;
|
|
31
|
+
use card_duel::brawl::{Self, Brawl};
|
|
32
|
+
use card_duel::brawl_permit::{Self, BrawlPermit};
|
|
33
|
+
use card_duel::arena::{Self, Arena};
|
|
34
|
+
|
|
35
|
+
const RATING_DELTA: u32 = 25;
|
|
36
|
+
const MIN_PLAYERS: u64 = 2;
|
|
37
|
+
const MAX_PLAYERS: u64 = 8;
|
|
38
|
+
|
|
39
|
+
const STATE_OPEN: u8 = 0;
|
|
40
|
+
const STATE_ACTIVE: u8 = 1;
|
|
41
|
+
const STATE_FINISHED: u8 = 2;
|
|
42
|
+
|
|
43
|
+
// ─── Room lifecycle ─────────────────────────────────────────────────────
|
|
44
|
+
|
|
45
|
+
/// Open a brawl room. The host pays the entry fee up front; the permit is
|
|
46
|
+
/// open-invite so anyone can join until `max_players` is reached.
|
|
47
|
+
public entry fun create_brawl(
|
|
48
|
+
dapp_storage: &DappStorage,
|
|
49
|
+
user_storage: &mut UserStorage,
|
|
50
|
+
entry_fee: u64,
|
|
51
|
+
max_players: u64,
|
|
52
|
+
clock: &Clock,
|
|
53
|
+
ctx: &mut TxContext,
|
|
54
|
+
) {
|
|
55
|
+
dapp_system::ensure_latest_version<DappKey>(dapp_storage, migrate::on_chain_version());
|
|
56
|
+
dapp_system::ensure_not_paused<DappKey>(dapp_storage);
|
|
57
|
+
// The on-scene player identity is always the canonical owner of
|
|
58
|
+
// user_storage — the transaction itself may be signed by the main
|
|
59
|
+
// wallet or by its active session key.
|
|
60
|
+
let player = dapp_service::canonical_owner(user_storage);
|
|
61
|
+
ensure_ready_for_match(user_storage);
|
|
62
|
+
error::brawl_invalid_max_players(max_players >= MIN_PLAYERS && max_players <= MAX_PLAYERS);
|
|
63
|
+
error::insufficient_gold(gold::get(user_storage) >= entry_fee);
|
|
64
|
+
|
|
65
|
+
let now = sui::clock::timestamp_ms(clock);
|
|
66
|
+
|
|
67
|
+
// Open-invite permit: the host is the first participant, anyone else
|
|
68
|
+
// can join_brawl_permit until the cap is hit. Never expires.
|
|
69
|
+
let permit = brawl_permit::new_brawl_permit(
|
|
70
|
+
dapp_storage,
|
|
71
|
+
vector[player],
|
|
72
|
+
std::option::none(),
|
|
73
|
+
std::option::some(max_players),
|
|
74
|
+
ctx,
|
|
75
|
+
);
|
|
76
|
+
|
|
77
|
+
let mut scene = brawl::new_brawl_with_permit(dapp_storage, &permit, ctx);
|
|
78
|
+
let scene_addr = sui::object::uid_to_address(dapp_service::scene_storage_id(&scene));
|
|
79
|
+
|
|
80
|
+
brawl::set_host(&permit, &mut scene, user_storage, player, ctx);
|
|
81
|
+
brawl::set_entry_fee(&permit, &mut scene, user_storage, entry_fee, ctx);
|
|
82
|
+
brawl::set_max_players(&permit, &mut scene, user_storage, max_players, ctx);
|
|
83
|
+
brawl::set_state(&permit, &mut scene, user_storage, STATE_OPEN, ctx);
|
|
84
|
+
brawl::set_round(&permit, &mut scene, user_storage, 0, ctx);
|
|
85
|
+
brawl::set_turn_index(&permit, &mut scene, user_storage, 0, ctx);
|
|
86
|
+
brawl::set_players(&permit, &mut scene, user_storage, vector[player], ctx);
|
|
87
|
+
brawl::set_alive(&permit, &mut scene, user_storage, vector::empty(), ctx);
|
|
88
|
+
brawl::set_winner(&permit, &mut scene, user_storage, @0x0, ctx);
|
|
89
|
+
brawl::set_last_action_ms(&permit, &mut scene, user_storage, now, ctx);
|
|
90
|
+
|
|
91
|
+
if (entry_fee > 0) {
|
|
92
|
+
gold::transfer_user_to_brawl(&permit, user_storage, &mut scene, entry_fee, ctx);
|
|
93
|
+
};
|
|
94
|
+
let max_hp = game_config::get_max_hp(dapp_storage);
|
|
95
|
+
battle_state::set(user_storage, scene_addr, max_hp, 0, ctx);
|
|
96
|
+
|
|
97
|
+
brawl::share_brawl(scene);
|
|
98
|
+
brawl_permit::share_brawl_permit(permit);
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
/// Join an open room: become a permit participant and pay the entry fee.
|
|
102
|
+
public entry fun join_brawl(
|
|
103
|
+
dapp_storage: &DappStorage,
|
|
104
|
+
user_storage: &mut UserStorage,
|
|
105
|
+
permit: &mut ScenePermit<BrawlPermit>,
|
|
106
|
+
scene: &mut SceneStorage<Brawl>,
|
|
107
|
+
ctx: &mut TxContext,
|
|
108
|
+
) {
|
|
109
|
+
dapp_system::ensure_latest_version<DappKey>(dapp_storage, migrate::on_chain_version());
|
|
110
|
+
dapp_system::ensure_not_paused<DappKey>(dapp_storage);
|
|
111
|
+
// Joining registers the canonical owner of user_storage as the permit
|
|
112
|
+
// participant; the transaction may be session-signed.
|
|
113
|
+
let player = dapp_service::canonical_owner(user_storage);
|
|
114
|
+
ensure_ready_for_match(user_storage);
|
|
115
|
+
ensure_scene_bound(permit, scene);
|
|
116
|
+
error::match_not_waiting(brawl::get_state(scene) == STATE_OPEN);
|
|
117
|
+
|
|
118
|
+
let mut players = brawl::get_players(scene);
|
|
119
|
+
error::already_joined(!players.contains(&player));
|
|
120
|
+
error::brawl_full(players.length() < brawl::get_max_players(scene));
|
|
121
|
+
|
|
122
|
+
let entry_fee = brawl::get_entry_fee(scene);
|
|
123
|
+
error::insufficient_gold(gold::get(user_storage) >= entry_fee);
|
|
124
|
+
|
|
125
|
+
// join_scene_permit also enforces the max_participants cap.
|
|
126
|
+
brawl_permit::join_brawl_permit(permit, user_storage, ctx);
|
|
127
|
+
if (entry_fee > 0) {
|
|
128
|
+
gold::transfer_user_to_brawl(permit, user_storage, scene, entry_fee, ctx);
|
|
129
|
+
};
|
|
130
|
+
|
|
131
|
+
players.push_back(player);
|
|
132
|
+
brawl::set_players(permit, scene, user_storage, players, ctx);
|
|
133
|
+
|
|
134
|
+
let scene_addr = sui::object::uid_to_address(dapp_service::scene_storage_id(scene));
|
|
135
|
+
let max_hp = game_config::get_max_hp(dapp_storage);
|
|
136
|
+
battle_state::set(user_storage, scene_addr, max_hp, 0, ctx);
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
/// Leave an open room (non-host): refund the entry fee and exit the permit.
|
|
140
|
+
public entry fun leave_brawl(
|
|
141
|
+
dapp_storage: &DappStorage,
|
|
142
|
+
user_storage: &mut UserStorage,
|
|
143
|
+
permit: &mut ScenePermit<BrawlPermit>,
|
|
144
|
+
scene: &mut SceneStorage<Brawl>,
|
|
145
|
+
ctx: &mut TxContext,
|
|
146
|
+
) {
|
|
147
|
+
dapp_system::ensure_latest_version<DappKey>(dapp_storage, migrate::on_chain_version());
|
|
148
|
+
ensure_scene_bound(permit, scene);
|
|
149
|
+
error::match_not_waiting(brawl::get_state(scene) == STATE_OPEN);
|
|
150
|
+
|
|
151
|
+
let player = dapp_service::canonical_owner(user_storage);
|
|
152
|
+
error::host_cannot_leave(player != brawl::get_host(scene));
|
|
153
|
+
|
|
154
|
+
let mut players = brawl::get_players(scene);
|
|
155
|
+
let (found, idx) = players.index_of(&player);
|
|
156
|
+
error::not_in_brawl(found);
|
|
157
|
+
players.remove(idx);
|
|
158
|
+
|
|
159
|
+
let entry_fee = brawl::get_entry_fee(scene);
|
|
160
|
+
if (entry_fee > 0) {
|
|
161
|
+
gold::transfer_brawl_to_user(permit, scene, user_storage, entry_fee, ctx);
|
|
162
|
+
};
|
|
163
|
+
brawl::set_players(permit, scene, user_storage, players, ctx);
|
|
164
|
+
battle_state::set(user_storage, @0x0, 0, 0, ctx);
|
|
165
|
+
brawl_permit::leave_brawl_permit(permit, user_storage, ctx);
|
|
166
|
+
}
|
|
167
|
+
|
|
168
|
+
/// Host closes an open room. Everyone else must have left already.
|
|
169
|
+
public entry fun cancel_brawl(
|
|
170
|
+
dapp_storage: &DappStorage,
|
|
171
|
+
user_storage: &mut UserStorage,
|
|
172
|
+
permit: &mut ScenePermit<BrawlPermit>,
|
|
173
|
+
scene: &mut SceneStorage<Brawl>,
|
|
174
|
+
ctx: &mut TxContext,
|
|
175
|
+
) {
|
|
176
|
+
dapp_system::ensure_latest_version<DappKey>(dapp_storage, migrate::on_chain_version());
|
|
177
|
+
ensure_scene_bound(permit, scene);
|
|
178
|
+
error::match_not_waiting(brawl::get_state(scene) == STATE_OPEN);
|
|
179
|
+
|
|
180
|
+
let player = dapp_service::canonical_owner(user_storage);
|
|
181
|
+
error::brawl_not_host(player == brawl::get_host(scene));
|
|
182
|
+
|
|
183
|
+
let players = brawl::get_players(scene);
|
|
184
|
+
error::brawl_too_few_players(players.length() == 1);
|
|
185
|
+
|
|
186
|
+
brawl::set_state(permit, scene, user_storage, STATE_FINISHED, ctx);
|
|
187
|
+
brawl::set_players(permit, scene, user_storage, vector::empty(), ctx);
|
|
188
|
+
let pot = brawl::get_gold(scene);
|
|
189
|
+
if (pot > 0) {
|
|
190
|
+
gold::transfer_brawl_to_user(permit, scene, user_storage, pot, ctx);
|
|
191
|
+
};
|
|
192
|
+
battle_state::set(user_storage, @0x0, 0, 0, ctx);
|
|
193
|
+
brawl_permit::leave_brawl_permit(permit, user_storage, ctx);
|
|
194
|
+
}
|
|
195
|
+
|
|
196
|
+
/// Start the match. Turn order = join order.
|
|
197
|
+
public entry fun start_brawl(
|
|
198
|
+
dapp_storage: &DappStorage,
|
|
199
|
+
user_storage: &UserStorage,
|
|
200
|
+
permit: &ScenePermit<BrawlPermit>,
|
|
201
|
+
scene: &mut SceneStorage<Brawl>,
|
|
202
|
+
clock: &Clock,
|
|
203
|
+
ctx: &TxContext,
|
|
204
|
+
) {
|
|
205
|
+
dapp_system::ensure_latest_version<DappKey>(dapp_storage, migrate::on_chain_version());
|
|
206
|
+
dapp_system::ensure_not_paused<DappKey>(dapp_storage);
|
|
207
|
+
ensure_scene_bound(permit, scene);
|
|
208
|
+
error::match_not_waiting(brawl::get_state(scene) == STATE_OPEN);
|
|
209
|
+
error::brawl_not_host(dapp_service::canonical_owner(user_storage) == brawl::get_host(scene));
|
|
210
|
+
|
|
211
|
+
let players = brawl::get_players(scene);
|
|
212
|
+
error::brawl_too_few_players(players.length() >= MIN_PLAYERS);
|
|
213
|
+
|
|
214
|
+
brawl::set_state(permit, scene, user_storage, STATE_ACTIVE, ctx);
|
|
215
|
+
brawl::set_alive(permit, scene, user_storage, players, ctx);
|
|
216
|
+
brawl::set_turn_index(permit, scene, user_storage, 0, ctx);
|
|
217
|
+
brawl::set_last_action_ms(permit, scene, user_storage, sui::clock::timestamp_ms(clock), ctx);
|
|
218
|
+
}
|
|
219
|
+
|
|
220
|
+
// ─── Combat ─────────────────────────────────────────────────────────────
|
|
221
|
+
|
|
222
|
+
/// Attack any alive player on your turn. Unlike duels, cards can be
|
|
223
|
+
/// replayed every turn. Eliminating the second-to-last player decides
|
|
224
|
+
/// the brawl immediately.
|
|
225
|
+
public entry fun brawl_attack(
|
|
226
|
+
dapp_storage: &DappStorage,
|
|
227
|
+
attacker_storage: &mut UserStorage,
|
|
228
|
+
target_storage: &mut UserStorage,
|
|
229
|
+
permit: &ScenePermit<BrawlPermit>,
|
|
230
|
+
scene: &mut SceneStorage<Brawl>,
|
|
231
|
+
card_id: address,
|
|
232
|
+
clock: &Clock,
|
|
233
|
+
ctx: &mut TxContext,
|
|
234
|
+
) {
|
|
235
|
+
dapp_system::ensure_latest_version<DappKey>(dapp_storage, migrate::on_chain_version());
|
|
236
|
+
dapp_system::ensure_not_paused<DappKey>(dapp_storage);
|
|
237
|
+
ensure_scene_bound(permit, scene);
|
|
238
|
+
|
|
239
|
+
// Player identity is the attacker's canonical owner — the transaction
|
|
240
|
+
// may be signed by the main wallet or its active session key.
|
|
241
|
+
let player = dapp_service::canonical_owner(attacker_storage);
|
|
242
|
+
let scene_addr = sui::object::uid_to_address(dapp_service::scene_storage_id(scene));
|
|
243
|
+
error::match_not_active(brawl::get_state(scene) == STATE_ACTIVE);
|
|
244
|
+
|
|
245
|
+
let alive = brawl::get_alive(scene);
|
|
246
|
+
let turn_index = brawl::get_turn_index(scene);
|
|
247
|
+
error::not_your_turn(*alive.borrow(turn_index) == player);
|
|
248
|
+
error::wrong_match(battle_state::get_match_id(attacker_storage) == scene_addr);
|
|
249
|
+
error::wrong_match(battle_state::get_match_id(target_storage) == scene_addr);
|
|
250
|
+
|
|
251
|
+
let target = dapp_service::canonical_owner(target_storage);
|
|
252
|
+
error::cannot_play_self(target != player);
|
|
253
|
+
error::target_not_alive(alive.contains(&target));
|
|
254
|
+
|
|
255
|
+
let kind = check_card(attacker_storage, card_id);
|
|
256
|
+
error::invalid_card_kind(card_system::is_attack_kind(kind));
|
|
257
|
+
|
|
258
|
+
let dmg = (card::get_power(attacker_storage, card_id) as u64);
|
|
259
|
+
let hp = battle_state::get_hp(target_storage);
|
|
260
|
+
let shield = battle_state::get_shield(target_storage);
|
|
261
|
+
let (new_hp, new_shield) = apply_damage(hp, shield, dmg);
|
|
262
|
+
|
|
263
|
+
if (new_hp == 0) {
|
|
264
|
+
battle_state::set_reactive(permit, attacker_storage, target_storage, @0x0, 0, 0, ctx);
|
|
265
|
+
record_loss_reactive(permit, attacker_storage, target_storage, ctx);
|
|
266
|
+
eliminate_and_advance(permit, scene, attacker_storage, target, player, ctx);
|
|
267
|
+
} else {
|
|
268
|
+
battle_state::set_reactive(
|
|
269
|
+
permit, attacker_storage, target_storage, scene_addr, new_hp, new_shield, ctx,
|
|
270
|
+
);
|
|
271
|
+
advance_turn_after(permit, scene, attacker_storage, player, ctx);
|
|
272
|
+
};
|
|
273
|
+
|
|
274
|
+
let round = brawl::get_round(scene);
|
|
275
|
+
brawl::set_round(permit, scene, attacker_storage, round + 1, ctx);
|
|
276
|
+
brawl::set_last_action_ms(permit, scene, attacker_storage, sui::clock::timestamp_ms(clock), ctx);
|
|
277
|
+
}
|
|
278
|
+
|
|
279
|
+
/// Heal or shield yourself as the turn action.
|
|
280
|
+
public entry fun brawl_defend(
|
|
281
|
+
dapp_storage: &DappStorage,
|
|
282
|
+
user_storage: &mut UserStorage,
|
|
283
|
+
permit: &ScenePermit<BrawlPermit>,
|
|
284
|
+
scene: &mut SceneStorage<Brawl>,
|
|
285
|
+
card_id: address,
|
|
286
|
+
clock: &Clock,
|
|
287
|
+
ctx: &mut TxContext,
|
|
288
|
+
) {
|
|
289
|
+
dapp_system::ensure_latest_version<DappKey>(dapp_storage, migrate::on_chain_version());
|
|
290
|
+
dapp_system::ensure_not_paused<DappKey>(dapp_storage);
|
|
291
|
+
ensure_scene_bound(permit, scene);
|
|
292
|
+
|
|
293
|
+
let player = dapp_service::canonical_owner(user_storage);
|
|
294
|
+
let scene_addr = sui::object::uid_to_address(dapp_service::scene_storage_id(scene));
|
|
295
|
+
error::match_not_active(brawl::get_state(scene) == STATE_ACTIVE);
|
|
296
|
+
|
|
297
|
+
let alive = brawl::get_alive(scene);
|
|
298
|
+
let turn_index = brawl::get_turn_index(scene);
|
|
299
|
+
error::not_your_turn(*alive.borrow(turn_index) == player);
|
|
300
|
+
error::wrong_match(battle_state::get_match_id(user_storage) == scene_addr);
|
|
301
|
+
|
|
302
|
+
let kind = check_card(user_storage, card_id);
|
|
303
|
+
error::invalid_card_kind(card_system::is_defense_kind(kind));
|
|
304
|
+
|
|
305
|
+
let power = (card::get_power(user_storage, card_id) as u64);
|
|
306
|
+
if (kind == card_system::kind_heal()) {
|
|
307
|
+
let max_hp = game_config::get_max_hp(dapp_storage);
|
|
308
|
+
let hp = battle_state::get_hp(user_storage);
|
|
309
|
+
let healed = if (hp + power > max_hp) { max_hp } else { hp + power };
|
|
310
|
+
battle_state::set_hp(user_storage, healed, ctx);
|
|
311
|
+
} else {
|
|
312
|
+
let shield = battle_state::get_shield(user_storage);
|
|
313
|
+
battle_state::set_shield(user_storage, shield + power, ctx);
|
|
314
|
+
};
|
|
315
|
+
|
|
316
|
+
advance_turn_after(permit, scene, user_storage, player, ctx);
|
|
317
|
+
let round = brawl::get_round(scene);
|
|
318
|
+
brawl::set_round(permit, scene, user_storage, round + 1, ctx);
|
|
319
|
+
brawl::set_last_action_ms(permit, scene, user_storage, sui::clock::timestamp_ms(clock), ctx);
|
|
320
|
+
}
|
|
321
|
+
|
|
322
|
+
/// Drop out of an active brawl. If only one player remains they win.
|
|
323
|
+
public entry fun brawl_surrender(
|
|
324
|
+
dapp_storage: &DappStorage,
|
|
325
|
+
user_storage: &mut UserStorage,
|
|
326
|
+
permit: &mut ScenePermit<BrawlPermit>,
|
|
327
|
+
scene: &mut SceneStorage<Brawl>,
|
|
328
|
+
clock: &Clock,
|
|
329
|
+
ctx: &mut TxContext,
|
|
330
|
+
) {
|
|
331
|
+
dapp_system::ensure_latest_version<DappKey>(dapp_storage, migrate::on_chain_version());
|
|
332
|
+
ensure_scene_bound(permit, scene);
|
|
333
|
+
|
|
334
|
+
let player = dapp_service::canonical_owner(user_storage);
|
|
335
|
+
error::match_not_active(brawl::get_state(scene) == STATE_ACTIVE);
|
|
336
|
+
error::target_not_alive(brawl::get_alive(scene).contains(&player));
|
|
337
|
+
|
|
338
|
+
record_own_loss(user_storage, ctx);
|
|
339
|
+
battle_state::set(user_storage, @0x0, 0, 0, ctx);
|
|
340
|
+
eliminate_and_advance(permit, scene, user_storage, player, player, ctx);
|
|
341
|
+
brawl::set_last_action_ms(permit, scene, user_storage, sui::clock::timestamp_ms(clock), ctx);
|
|
342
|
+
brawl_permit::leave_brawl_permit(permit, user_storage, ctx);
|
|
343
|
+
}
|
|
344
|
+
|
|
345
|
+
/// Remove the current-turn player once they stall past the turn timeout.
|
|
346
|
+
/// Any alive player can trigger the kick.
|
|
347
|
+
public entry fun brawl_timeout_kick(
|
|
348
|
+
dapp_storage: &DappStorage,
|
|
349
|
+
kicker_storage: &mut UserStorage,
|
|
350
|
+
target_storage: &mut UserStorage,
|
|
351
|
+
permit: &ScenePermit<BrawlPermit>,
|
|
352
|
+
scene: &mut SceneStorage<Brawl>,
|
|
353
|
+
clock: &Clock,
|
|
354
|
+
ctx: &mut TxContext,
|
|
355
|
+
) {
|
|
356
|
+
dapp_system::ensure_latest_version<DappKey>(dapp_storage, migrate::on_chain_version());
|
|
357
|
+
ensure_scene_bound(permit, scene);
|
|
358
|
+
|
|
359
|
+
let player = dapp_service::canonical_owner(kicker_storage);
|
|
360
|
+
error::match_not_active(brawl::get_state(scene) == STATE_ACTIVE);
|
|
361
|
+
let alive = brawl::get_alive(scene);
|
|
362
|
+
error::target_not_alive(alive.contains(&player));
|
|
363
|
+
|
|
364
|
+
let stalling = *alive.borrow(brawl::get_turn_index(scene));
|
|
365
|
+
error::not_your_turn(stalling != player);
|
|
366
|
+
error::wrong_match(dapp_service::canonical_owner(target_storage) == stalling);
|
|
367
|
+
|
|
368
|
+
let now = sui::clock::timestamp_ms(clock);
|
|
369
|
+
let timeout = game_config::get_turn_timeout_ms(dapp_storage);
|
|
370
|
+
error::turn_not_timed_out(now > brawl::get_last_action_ms(scene) + timeout);
|
|
371
|
+
|
|
372
|
+
battle_state::set_reactive(permit, kicker_storage, target_storage, @0x0, 0, 0, ctx);
|
|
373
|
+
record_loss_reactive(permit, kicker_storage, target_storage, ctx);
|
|
374
|
+
eliminate_and_advance(permit, scene, kicker_storage, stalling, player, ctx);
|
|
375
|
+
brawl::set_last_action_ms(permit, scene, kicker_storage, now, ctx);
|
|
376
|
+
}
|
|
377
|
+
|
|
378
|
+
// ─── Settlement ─────────────────────────────────────────────────────────
|
|
379
|
+
|
|
380
|
+
/// Last player standing collects the pot minus the arena rake.
|
|
381
|
+
public entry fun finish_brawl(
|
|
382
|
+
dapp_storage: &DappStorage,
|
|
383
|
+
user_storage: &mut UserStorage,
|
|
384
|
+
permit: &mut ScenePermit<BrawlPermit>,
|
|
385
|
+
scene: &mut SceneStorage<Brawl>,
|
|
386
|
+
arena: &mut ObjectStorage<Arena>,
|
|
387
|
+
ctx: &mut TxContext,
|
|
388
|
+
) {
|
|
389
|
+
dapp_system::ensure_latest_version<DappKey>(dapp_storage, migrate::on_chain_version());
|
|
390
|
+
ensure_scene_bound(permit, scene);
|
|
391
|
+
|
|
392
|
+
let player = dapp_service::canonical_owner(user_storage);
|
|
393
|
+
error::match_not_finished(brawl::get_state(scene) == STATE_FINISHED);
|
|
394
|
+
error::not_match_winner(brawl::get_winner(scene) == player);
|
|
395
|
+
|
|
396
|
+
let pot = brawl::get_gold(scene);
|
|
397
|
+
let rake = pot * game_config::get_rake_bps(dapp_storage) / 10_000;
|
|
398
|
+
if (rake > 0) {
|
|
399
|
+
arena::transfer_brawl_to_arena_gold(permit, scene, arena, user_storage, rake, ctx);
|
|
400
|
+
};
|
|
401
|
+
if (pot - rake > 0) {
|
|
402
|
+
gold::transfer_brawl_to_user(permit, scene, user_storage, pot - rake, ctx);
|
|
403
|
+
};
|
|
404
|
+
|
|
405
|
+
let (wins, losses, rating) = profile::get(user_storage);
|
|
406
|
+
profile::set(user_storage, wins + 1, losses, rating + RATING_DELTA, ctx);
|
|
407
|
+
// Prevent double-claiming the pot.
|
|
408
|
+
brawl::set_winner(permit, scene, user_storage, @0x0, ctx);
|
|
409
|
+
battle_state::set(user_storage, @0x0, 0, 0, ctx);
|
|
410
|
+
brawl_permit::leave_brawl_permit(permit, user_storage, ctx);
|
|
411
|
+
}
|
|
412
|
+
|
|
413
|
+
/// Eliminated players exit the permit once they are out of the match.
|
|
414
|
+
public entry fun leave_finished_brawl(
|
|
415
|
+
permit: &mut ScenePermit<BrawlPermit>,
|
|
416
|
+
scene: &SceneStorage<Brawl>,
|
|
417
|
+
user_storage: &UserStorage,
|
|
418
|
+
ctx: &TxContext,
|
|
419
|
+
) {
|
|
420
|
+
ensure_scene_bound(permit, scene);
|
|
421
|
+
let player = dapp_service::canonical_owner(user_storage);
|
|
422
|
+
let out = brawl::get_state(scene) == STATE_FINISHED
|
|
423
|
+
|| !brawl::get_alive(scene).contains(&player);
|
|
424
|
+
error::match_not_finished(out);
|
|
425
|
+
brawl_permit::leave_brawl_permit(permit, user_storage, ctx);
|
|
426
|
+
}
|
|
427
|
+
|
|
428
|
+
/// Destroy a fully settled brawl (empty pot, no participants left).
|
|
429
|
+
public entry fun cleanup_brawl(
|
|
430
|
+
scene: SceneStorage<Brawl>,
|
|
431
|
+
permit: ScenePermit<BrawlPermit>,
|
|
432
|
+
_ctx: &TxContext,
|
|
433
|
+
) {
|
|
434
|
+
error::match_not_finished(brawl::get_state(&scene) == STATE_FINISHED);
|
|
435
|
+
error::invalid_stake(brawl::get_gold(&scene) == 0);
|
|
436
|
+
|
|
437
|
+
let mut scene = scene;
|
|
438
|
+
brawl::remove_host_system_maintenance(&mut scene);
|
|
439
|
+
brawl::remove_entry_fee_system_maintenance(&mut scene);
|
|
440
|
+
brawl::remove_max_players_system_maintenance(&mut scene);
|
|
441
|
+
brawl::remove_state_system_maintenance(&mut scene);
|
|
442
|
+
brawl::remove_round_system_maintenance(&mut scene);
|
|
443
|
+
brawl::remove_turn_index_system_maintenance(&mut scene);
|
|
444
|
+
brawl::remove_players_system_maintenance(&mut scene);
|
|
445
|
+
brawl::remove_alive_system_maintenance(&mut scene);
|
|
446
|
+
brawl::remove_winner_system_maintenance(&mut scene);
|
|
447
|
+
brawl::remove_last_action_ms_system_maintenance(&mut scene);
|
|
448
|
+
if (dapp_system::has_scene_field<Brawl, u64>(&scene, b"gold")) {
|
|
449
|
+
dapp_system::remove_scene_field_system_maintenance<DappKey, Brawl, u64>(
|
|
450
|
+
dapp_key::new(), &mut scene, b"gold",
|
|
451
|
+
);
|
|
452
|
+
};
|
|
453
|
+
brawl::destroy_brawl(scene);
|
|
454
|
+
|
|
455
|
+
dapp_system::destroy_scene_permit<DappKey, BrawlPermit>(dapp_key::new(), permit);
|
|
456
|
+
}
|
|
457
|
+
|
|
458
|
+
// ─── Helpers ────────────────────────────────────────────────────────────
|
|
459
|
+
|
|
460
|
+
fun ensure_ready_for_match(user_storage: &UserStorage) {
|
|
461
|
+
error::not_registered(profile::has(user_storage));
|
|
462
|
+
error::card_not_in_deck(deck::has(user_storage));
|
|
463
|
+
error::already_in_match(battle_state::get_match_id(user_storage) == @0x0);
|
|
464
|
+
}
|
|
465
|
+
|
|
466
|
+
fun ensure_scene_bound(permit: &ScenePermit<BrawlPermit>, scene: &SceneStorage<Brawl>) {
|
|
467
|
+
let bound = dapp_service::scene_storage_authorized_permit_id(scene);
|
|
468
|
+
error::wrong_match(std::option::is_some(bound));
|
|
469
|
+
error::wrong_match(
|
|
470
|
+
*std::option::borrow(bound)
|
|
471
|
+
== sui::object::uid_to_address(dapp_service::scene_permit_id(permit))
|
|
472
|
+
);
|
|
473
|
+
}
|
|
474
|
+
|
|
475
|
+
/// Validate the card (owned + in deck) and return its kind.
|
|
476
|
+
/// Brawl cards have no per-match usage limit.
|
|
477
|
+
fun check_card(player_storage: &UserStorage, card_id: address): u8 {
|
|
478
|
+
error::card_not_found(card::has(player_storage, card_id));
|
|
479
|
+
let deck_ids = deck::get(player_storage);
|
|
480
|
+
error::card_not_in_deck(deck_ids.contains(&card_id));
|
|
481
|
+
card::get_kind(player_storage, card_id)
|
|
482
|
+
}
|
|
483
|
+
|
|
484
|
+
fun apply_damage(hp: u64, shield: u64, dmg: u64): (u64, u64) {
|
|
485
|
+
if (shield >= dmg) {
|
|
486
|
+
(hp, shield - dmg)
|
|
487
|
+
} else {
|
|
488
|
+
let pierce = dmg - shield;
|
|
489
|
+
if (pierce >= hp) { (0, 0) } else { (hp - pierce, 0) }
|
|
490
|
+
}
|
|
491
|
+
}
|
|
492
|
+
|
|
493
|
+
/// Remove `eliminated` from the alive list, fix up the turn pointer so it
|
|
494
|
+
/// lands on the player after `actor`, and decide the match if only one
|
|
495
|
+
/// player remains. `actor_storage` is the acting player's UserStorage,
|
|
496
|
+
/// used to authorize the scene writes.
|
|
497
|
+
fun eliminate_and_advance(
|
|
498
|
+
permit: &ScenePermit<BrawlPermit>,
|
|
499
|
+
scene: &mut SceneStorage<Brawl>,
|
|
500
|
+
actor_storage: &UserStorage,
|
|
501
|
+
eliminated: address,
|
|
502
|
+
actor: address,
|
|
503
|
+
ctx: &TxContext,
|
|
504
|
+
) {
|
|
505
|
+
let mut alive = brawl::get_alive(scene);
|
|
506
|
+
let (found, idx) = alive.index_of(&eliminated);
|
|
507
|
+
error::target_not_alive(found);
|
|
508
|
+
alive.remove(idx);
|
|
509
|
+
|
|
510
|
+
if (alive.length() == 1) {
|
|
511
|
+
brawl::set_alive(permit, scene, actor_storage, alive, ctx);
|
|
512
|
+
brawl::set_state(permit, scene, actor_storage, STATE_FINISHED, ctx);
|
|
513
|
+
brawl::set_winner(permit, scene, actor_storage, *alive.borrow(0), ctx);
|
|
514
|
+
brawl::set_turn_index(permit, scene, actor_storage, 0, ctx);
|
|
515
|
+
return
|
|
516
|
+
};
|
|
517
|
+
|
|
518
|
+
// Next turn: the player after `actor`; if the actor was the one who
|
|
519
|
+
// left (surrender/kick), the turn passes to the player at the freed slot.
|
|
520
|
+
let (actor_found, actor_idx) = alive.index_of(&actor);
|
|
521
|
+
let next = if (actor_found) {
|
|
522
|
+
(actor_idx + 1) % alive.length()
|
|
523
|
+
} else {
|
|
524
|
+
idx % alive.length()
|
|
525
|
+
};
|
|
526
|
+
brawl::set_alive(permit, scene, actor_storage, alive, ctx);
|
|
527
|
+
brawl::set_turn_index(permit, scene, actor_storage, next, ctx);
|
|
528
|
+
}
|
|
529
|
+
|
|
530
|
+
/// Standard turn rotation when nobody was eliminated.
|
|
531
|
+
fun advance_turn_after(
|
|
532
|
+
permit: &ScenePermit<BrawlPermit>,
|
|
533
|
+
scene: &mut SceneStorage<Brawl>,
|
|
534
|
+
actor_storage: &UserStorage,
|
|
535
|
+
actor: address,
|
|
536
|
+
ctx: &TxContext,
|
|
537
|
+
) {
|
|
538
|
+
let alive = brawl::get_alive(scene);
|
|
539
|
+
let (_, actor_idx) = alive.index_of(&actor);
|
|
540
|
+
brawl::set_turn_index(permit, scene, actor_storage, (actor_idx + 1) % alive.length(), ctx);
|
|
541
|
+
}
|
|
542
|
+
|
|
543
|
+
fun record_own_loss(user_storage: &mut UserStorage, ctx: &mut TxContext) {
|
|
544
|
+
let (wins, losses, rating) = profile::get(user_storage);
|
|
545
|
+
let new_rating = if (rating > RATING_DELTA) { rating - RATING_DELTA } else { 0 };
|
|
546
|
+
profile::set(user_storage, wins, losses + 1, new_rating, ctx);
|
|
547
|
+
}
|
|
548
|
+
|
|
549
|
+
fun record_loss_reactive(
|
|
550
|
+
permit: &ScenePermit<BrawlPermit>,
|
|
551
|
+
from: &mut UserStorage,
|
|
552
|
+
target: &mut UserStorage,
|
|
553
|
+
ctx: &mut TxContext,
|
|
554
|
+
) {
|
|
555
|
+
let (wins, losses, rating) = profile::get(target);
|
|
556
|
+
let new_rating = if (rating > RATING_DELTA) { rating - RATING_DELTA } else { 0 };
|
|
557
|
+
profile::set_reactive(permit, from, target, wins, losses + 1, new_rating, ctx);
|
|
558
|
+
}
|
|
559
|
+
}
|