diff --git a/Scarb.toml b/Scarb.toml index 361e012..390bf63 100644 --- a/Scarb.toml +++ b/Scarb.toml @@ -15,7 +15,14 @@ dojo = { git = "https://github.com/dojoengine/dojo", version = "0.4.1" } initializer_class_hash = "0xbeef" [tool.dojo.env] -rpc_url = "http://localhost:5050/" -account_address = "0x517ececd29116499f4a1b64b094da79ba08dfd54a3edaa316134c41f8160973" -private_key = "0x1800000000300000180000000000030000000000003006001800006600" -world_address="0x1374ef8311b490e1a3ae8e63f4cb1c602e6620d4a7bd87c66c44152b27770b4" \ No newline at end of file +# rpc_url = "http://localhost:5050/" +# account_address = "0x517ececd29116499f4a1b64b094da79ba08dfd54a3edaa316134c41f8160973" +# private_key = "0x1800000000300000180000000000030000000000003006001800006600" +# world_address="0x1374ef8311b490e1a3ae8e63f4cb1c602e6620d4a7bd87c66c44152b27770b4" + +rpc_url = "https://api.cartridge.gg/x/mississippi/katana" +account_address = "0x7ef05a4d3ef7cdb6ec73c8efff4e9e592d967e98642819aa294df8f2b80436b" +private_key = "0x10689f03e44d450573704d279665292b1cbb259bf38dc5a2207e3913389a80e" +world_address="0x1374ef8311b490e1a3ae8e63f4cb1c602e6620d4a7bd87c66c44152b27770b4" + + diff --git a/scripts/default_auth.sh b/scripts/default_auth.sh index fbb7796..a5ac11f 100644 --- a/scripts/default_auth.sh +++ b/scripts/default_auth.sh @@ -2,13 +2,13 @@ set -euo pipefail pushd $(dirname "$0")/.. -export RPC_URL="http://localhost:5050"; +export RPC_URL="https://api.cartridge.gg/x/mississippi/katana"; # export RPC_URL="https://starknet-goerli.infura.io/v3/5ca372516740427e97512d4dfefd9c47"; export WORLD_ADDRESS=$(cat ./target/dev/manifest.json | jq -r '.world.address') -export GAME_ADDRESS=$(cat ./target/dev/manifest.json | jq -r '.contracts[] | select(.name == "mississippi_mini::game::game" ).address') +export GAME_ADDRESS=$(cat ./target/dev/manifest.json | jq -r '.contracts[] | select(.name == "mississippi_mini::game::game").address') -export CONFIG_ADDRESS=$(cat ./target/dev/manifest.json | jq -r '.contracts[] | select(.name == "mississippi_mini::config::config" ).address') +export CONFIG_ADDRESS=$(cat ./target/dev/manifest.json | jq -r '.contracts[] | select(.name == "mississippi_mini::config::config").address') echo "---------------------------------------------------------------------------" @@ -20,7 +20,7 @@ echo config : $CONFIG_ADDRESS echo "---------------------------------------------------------------------------" # enable system -> component authorizations -game_component=("Role" "Skill" "Global" "Player" "BattleInfo" "BattleResult") +game_component=("Role" "Skill" "Global" "Player" "BattleInfo" "BattleResult", "BattleRank") config_component=("Role" "Skill" "Global") for component in ${game_component[@]}; do @@ -29,6 +29,7 @@ for component in ${game_component[@]}; do done for component in ${config_component[@]}; do + echo $component sozo auth writer $component $CONFIG_ADDRESS --world $WORLD_ADDRESS --rpc-url $RPC_URL done diff --git a/scripts/gen_init.sh b/scripts/gen_init.sh index 7c3b87c..b5a94eb 100644 --- a/scripts/gen_init.sh +++ b/scripts/gen_init.sh @@ -3,7 +3,8 @@ set -euo pipefail pushd $(dirname "$0")/.. # export RPC_URL="http://localhost:5050"; -export RPC_URL="https://starknet-goerli.infura.io/v3/5ca372516740427e97512d4dfefd9c47"; +# export RPC_URL="https://starknet-goerli.infura.io/v3/5ca372516740427e97512d4dfefd9c47"; +export RPC_URL="https://api.cartridge.gg/x/mississippi/katana"; export WORLD_ADDRESS=$(cat ./target/dev/manifest.json | jq -r '.world.address') export GAME_ADDRESS=$(cat ./target/dev/manifest.json | jq -r '.contracts[] | select(.name == "mississippi_mini::game::game" ).address') diff --git a/src/game.cairo b/src/game.cairo index 3450d73..9cdd9f8 100644 --- a/src/game.cairo +++ b/src/game.cairo @@ -14,8 +14,7 @@ trait IGame { #[dojo::contract] mod game { use starknet::{ContractAddress, get_caller_address}; - use mississippi_mini::models::{Player, BattleInfo, BattleResult, Skill, Role, Global}; - use mississippi_mini::utils::next_position; + use mississippi_mini::models::{Player, BattleInfo, BattleResult, Skill, Role, Global, BattleRank}; use mississippi_mini::constants; use mississippi_mini::random::{RandomTrait}; // use mississippi_mini::utils::battle_property_settting; @@ -177,6 +176,14 @@ mod game { }; set!(world, (battleResult)); + let mut rankInfo = get!(world, winner, (BattleRank)); + + let mut battleRank = BattleRank { + addr : winner, + score: (rankInfo.score + 1), + }; + set!(world, (battleRank)); + emit!(world, Win { battleId: attacker.battleId, winner: winner}); } diff --git a/src/lib.cairo b/src/lib.cairo index 1904cd3..ba29840 100644 --- a/src/lib.cairo +++ b/src/lib.cairo @@ -1,7 +1,7 @@ // mod actions; mod models; mod game; -mod utils; +// mod utils; mod constants; mod config; mod random; diff --git a/src/models.cairo b/src/models.cairo index 9dd71b8..bd1c7ff 100644 --- a/src/models.cairo +++ b/src/models.cairo @@ -70,96 +70,9 @@ struct BattleResult { winner: ContractAddress, } -// impl Default for MyStruct { -// fn default() -> Self { -// Self::new(0, String::default(), false) -// } -// } - #[derive(Model, Copy, Drop, Print, Serde)] -struct Room { +struct BattleRank { #[key] // primary key - roomId: u32, - battleId: u32, -} - -#[derive(Serde, Copy, Drop, Introspect)] -enum Direction { - None: (), - Left: (), - Right: (), - Up: (), - Down: (), -} - -impl DirectionIntoFelt252 of Into { - fn into(self: Direction) -> felt252 { - match self { - Direction::None(()) => 0, - Direction::Left(()) => 1, - Direction::Right(()) => 2, - Direction::Up(()) => 3, - Direction::Down(()) => 4, - } - } -} - -#[derive(Model, Drop, Serde)] -struct Moves { - #[key] - player: ContractAddress, - remaining: u8, - last_direction: Direction -} - -#[derive(Copy, Drop, Serde, Introspect)] -struct Vec2 { - x: u32, - y: u32 -} - -#[derive(Model, Copy, Drop, Serde)] -struct Position { - #[key] - player: ContractAddress, - vec: Vec2, -} - -trait Vec2Trait { - fn is_zero(self: Vec2) -> bool; - fn is_equal(self: Vec2, b: Vec2) -> bool; -} - -impl Vec2Impl of Vec2Trait { - fn is_zero(self: Vec2) -> bool { - if self.x - self.y == 0 { - return true; - } - false - } - - fn is_equal(self: Vec2, b: Vec2) -> bool { - self.x == b.x && self.y == b.y - } + addr: ContractAddress, + score: u32, } - -// #[cfg(test)] -// mod tests { -// use super::{Position, Vec2, Vec2Trait}; - -// #[test] -// #[available_gas(100000)] -// fn test_vec_is_zero() { -// assert(Vec2Trait::is_zero(Vec2 { x: 0, y: 0 }), 'not zero'); -// } - -// #[test] -// #[available_gas(100000)] -// fn test_vec_is_equal() { -// let position = Vec2 { x: 420, y: 0 }; -// assert(position.is_equal(Vec2 { x: 420, y: 0 }), 'not equal'); -// } -// } - - - diff --git a/src/utils.cairo b/src/utils.cairo deleted file mode 100644 index 995f2de..0000000 --- a/src/utils.cairo +++ /dev/null @@ -1,28 +0,0 @@ -use mississippi_mini::models::{BattleInfo, Position, Direction, Skill, Role}; -use starknet::{ContractAddress}; -use dojo::world::{IWorldDispatcher}; - -fn next_position(mut position: Position, direction: Direction) -> Position { - match direction { - Direction::None(()) => { - return position; - }, - Direction::Left(()) => { - position.vec.x -= 1; - }, - Direction::Right(()) => { - position.vec.x += 1; - }, - Direction::Up(()) => { - position.vec.y -= 1; - }, - Direction::Down(()) => { - position.vec.y += 1; - }, - }; - - position -} - - -