Skip to content

Commit

Permalink
Make sure attacks works
Browse files Browse the repository at this point in the history
  • Loading branch information
RolandoDrRobot committed Jul 5, 2024
1 parent f836625 commit 6d2246a
Show file tree
Hide file tree
Showing 16 changed files with 62 additions and 125 deletions.
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Generated by dojo-bindgen on Fri, 5 Jul 2024 13:09:26 +0000. Do not modify this file manually.
// Generated by dojo-bindgen on Fri, 5 Jul 2024 15:17:15 +0000. Do not modify this file manually.
using System;
using System.Threading.Tasks;
using Dojo;
Expand Down Expand Up @@ -68,9 +68,9 @@ public async Task<FieldElement> move(Account account, Direction direction) {

// Call the `attack` system with the specified Account and calldata
// Returns the transaction hash. Use `WaitForTransaction` to wait for the transaction to be confirmed.
public async Task<FieldElement> attack(Account account, uint beast_id, uint damage) {
public async Task<FieldElement> attack(Account account, FieldElement beast_id, uint damage) {
List<dojo.FieldElement> calldata = new List<dojo.FieldElement>();
calldata.Add(new FieldElement(beast_id).Inner);
calldata.Add(beast_id.Inner);
calldata.Add(new FieldElement(damage).Inner);

return await account.ExecuteRaw(new dojo.Call[] {
Expand All @@ -81,12 +81,12 @@ public async Task<FieldElement> attack(Account account, uint beast_id, uint dama
}
});
}

// Call the `createBeast` system with the specified Account and calldata
// Returns the transaction hash. Use `WaitForTransaction` to wait for the transaction to be confirmed.
public async Task<FieldElement> createBeast(Account account, uint beast_id, FieldElement beast_type, uint hp, uint currentHp, ulong mp, ulong currentMp, ulong strength, ulong defense, FieldElement equipped_weapon, byte wpn_power, FieldElement equipped_armor, ulong armor_power, ulong experience_to_nex_level) {
public async Task<FieldElement> createBeast(Account account, FieldElement beast_id, FieldElement beast_type, uint hp, uint currentHp, ulong mp, ulong currentMp, ulong strength, ulong defense, FieldElement equipped_weapon, byte wpn_power, FieldElement equipped_armor, ulong armor_power, ulong experience_to_nex_level) {
List<dojo.FieldElement> calldata = new List<dojo.FieldElement>();
calldata.Add(new FieldElement(beast_id).Inner);
calldata.Add(beast_id.Inner);
calldata.Add(beast_type.Inner);
calldata.Add(new FieldElement(hp).Inner);
calldata.Add(new FieldElement(currentHp).Inner);
Expand Down
63 changes: 0 additions & 63 deletions bindings/unity/Models/Beast.gen.cs

This file was deleted.

2 changes: 1 addition & 1 deletion bindings/unity/Models/DirectionsAvailable.gen.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Generated by dojo-bindgen on Fri, 5 Jul 2024 13:09:26 +0000. Do not modify this file manually.
// Generated by dojo-bindgen on Fri, 5 Jul 2024 15:17:15 +0000. Do not modify this file manually.
using System;
using Dojo;
using Dojo.Starknet;
Expand Down
11 changes: 10 additions & 1 deletion bindings/unity/Models/Moved.gen.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Generated by dojo-bindgen on Fri, 5 Jul 2024 13:09:26 +0000. Do not modify this file manually.
// Generated by dojo-bindgen on Fri, 5 Jul 2024 15:17:15 +0000. Do not modify this file manually.
using System;
using Dojo;
using Dojo.Starknet;
Expand All @@ -7,6 +7,15 @@
using System.Collections.Generic;
using Enum = Dojo.Starknet.Enum;

// Type definition for `dojo_starter::models::moves::Direction` enum
public abstract record Direction() : Enum {
public record None() : Direction;
public record Left() : Direction;
public record Right() : Direction;
public record Up() : Direction;
public record Down() : Direction;
}


// Model definition for `dojo_starter::systems::actions::actions::Moved` model
public class Moved : ModelInstance {
Expand Down
25 changes: 1 addition & 24 deletions bindings/unity/Models/Moves.gen.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Generated by dojo-bindgen on Fri, 5 Jul 2024 13:09:26 +0000. Do not modify this file manually.
// Generated by dojo-bindgen on Fri, 5 Jul 2024 15:17:15 +0000. Do not modify this file manually.
using System;
using Dojo;
using Dojo.Starknet;
Expand All @@ -7,29 +7,6 @@
using System.Collections.Generic;
using Enum = Dojo.Starknet.Enum;

// Type definition for `core::byte_array::ByteArray` struct
[Serializable]
public struct ByteArray {
public string[] data;
public FieldElement pending_word;
public uint pending_word_len;
}

// Type definition for `dojo_starter::models::moves::Direction` enum
public abstract record Direction() : Enum {
public record None() : Direction;
public record Left() : Direction;
public record Right() : Direction;
public record Up() : Direction;
public record Down() : Direction;
}

// Type definition for `core::option::Option::<core::integer::u32>` enum
public abstract record Option<A>() : Enum {
public record Some(A value) : Option<A>;
public record None() : Option<A>;
}


// Model definition for `dojo_starter::models::moves::Moves` model
public class Moves : ModelInstance {
Expand Down
16 changes: 15 additions & 1 deletion bindings/unity/Models/Position.gen.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Generated by dojo-bindgen on Fri, 5 Jul 2024 13:09:26 +0000. Do not modify this file manually.
// Generated by dojo-bindgen on Fri, 5 Jul 2024 15:17:15 +0000. Do not modify this file manually.
using System;
using Dojo;
using Dojo.Starknet;
Expand All @@ -14,6 +14,20 @@ public struct Vec2 {
public uint y;
}

// Type definition for `core::byte_array::ByteArray` struct
[Serializable]
public struct ByteArray {
public string[] data;
public FieldElement pending_word;
public uint pending_word_len;
}

// Type definition for `core::option::Option::<core::integer::u32>` enum
public abstract record Option<A>() : Enum {
public record Some(A value) : Option<A>;
public record None() : Option<A>;
}


// Model definition for `dojo_starter::models::position::Position` model
public class Position : ModelInstance {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@
"inputs": [
{
"name": "beast_id",
"type": "core::integer::u32"
"type": "core::felt252"
},
{
"name": "damage",
Expand All @@ -129,7 +129,7 @@
"inputs": [
{
"name": "beast_id",
"type": "core::integer::u32"
"type": "core::felt252"
},
{
"name": "beast_type",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -328,7 +328,7 @@
"members": [
{
"name": "beast_id",
"type": "core::integer::u32"
"type": "core::felt252"
},
{
"name": "player_id",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@
"inputs": [
{
"name": "beast_id",
"type": "core::integer::u32"
"type": "core::felt252"
},
{
"name": "damage",
Expand All @@ -129,7 +129,7 @@
"inputs": [
{
"name": "beast_id",
"type": "core::integer::u32"
"type": "core::felt252"
},
{
"name": "beast_type",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -328,7 +328,7 @@
"members": [
{
"name": "beast_id",
"type": "core::integer::u32"
"type": "core::felt252"
},
{
"name": "player_id",
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
kind = "DojoContract"
class_hash = "0x2f93ef02c13183550d5a6132cf31de73371f52670ad8cb9c3eaa5e2aeeabd43"
original_class_hash = "0x2f93ef02c13183550d5a6132cf31de73371f52670ad8cb9c3eaa5e2aeeabd43"
class_hash = "0x23660f8b5dd0b445a2edb889ea5c25b9a9116ef97ef15e9e93567a0bd801fdc"
original_class_hash = "0x23660f8b5dd0b445a2edb889ea5c25b9a9116ef97ef15e9e93567a0bd801fdc"
base_class_hash = "0x0"
abi = "manifests/dev/abis/base/contracts/dojo_starter_systems_actions_actions.json"
reads = []
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
kind = "DojoModel"
class_hash = "0x73c0915d3d9cb8deb698e4a6018acdee182f104b2c3b57627f25ea5d103d0ce"
original_class_hash = "0x73c0915d3d9cb8deb698e4a6018acdee182f104b2c3b57627f25ea5d103d0ce"
class_hash = "0x6f2ab954389d07486646883c96410be229d5261bf02a398a3b6e58e0fb953df"
original_class_hash = "0x6f2ab954389d07486646883c96410be229d5261bf02a398a3b6e58e0fb953df"
abi = "manifests/dev/abis/base/models/dojo_starter_models_beast_beast.json"
name = "dojo_starter::models::beast::beast"

[[members]]
name = "beast_id"
type = "u32"
type = "felt252"
key = true

[[members]]
Expand Down
16 changes: 8 additions & 8 deletions manifests/dev/manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -1020,8 +1020,8 @@
{
"kind": "DojoContract",
"address": "0x3610b797baec740e2fa25ae90b4a57d92b04f48a1fdbae1ae203eaf9723c1a0",
"class_hash": "0x2f93ef02c13183550d5a6132cf31de73371f52670ad8cb9c3eaa5e2aeeabd43",
"original_class_hash": "0x2f93ef02c13183550d5a6132cf31de73371f52670ad8cb9c3eaa5e2aeeabd43",
"class_hash": "0x23660f8b5dd0b445a2edb889ea5c25b9a9116ef97ef15e9e93567a0bd801fdc",
"original_class_hash": "0x23660f8b5dd0b445a2edb889ea5c25b9a9116ef97ef15e9e93567a0bd801fdc",
"base_class_hash": "0x22f3e55b61d86c2ac5239fa3b3b8761f26b9a5c0b5f61ddbd5d756ced498b46",
"abi": [
{
Expand Down Expand Up @@ -1138,7 +1138,7 @@
"inputs": [
{
"name": "beast_id",
"type": "core::integer::u32"
"type": "core::felt252"
},
{
"name": "damage",
Expand All @@ -1154,7 +1154,7 @@
"inputs": [
{
"name": "beast_id",
"type": "core::integer::u32"
"type": "core::felt252"
},
{
"name": "beast_type",
Expand Down Expand Up @@ -1305,7 +1305,7 @@
"members": [
{
"name": "beast_id",
"type": "u32",
"type": "felt252",
"key": true
},
{
Expand Down Expand Up @@ -1374,8 +1374,8 @@
"key": false
}
],
"class_hash": "0x73c0915d3d9cb8deb698e4a6018acdee182f104b2c3b57627f25ea5d103d0ce",
"original_class_hash": "0x73c0915d3d9cb8deb698e4a6018acdee182f104b2c3b57627f25ea5d103d0ce",
"class_hash": "0x6f2ab954389d07486646883c96410be229d5261bf02a398a3b6e58e0fb953df",
"original_class_hash": "0x6f2ab954389d07486646883c96410be229d5261bf02a398a3b6e58e0fb953df",
"abi": [
{
"type": "impl",
Expand Down Expand Up @@ -1706,7 +1706,7 @@
"members": [
{
"name": "beast_id",
"type": "core::integer::u32"
"type": "core::felt252"
},
{
"name": "player_id",
Expand Down
10 changes: 5 additions & 5 deletions manifests/dev/manifest.toml
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@ name = "dojo::base::base"
[[contracts]]
kind = "DojoContract"
address = "0x3610b797baec740e2fa25ae90b4a57d92b04f48a1fdbae1ae203eaf9723c1a0"
class_hash = "0x2f93ef02c13183550d5a6132cf31de73371f52670ad8cb9c3eaa5e2aeeabd43"
original_class_hash = "0x2f93ef02c13183550d5a6132cf31de73371f52670ad8cb9c3eaa5e2aeeabd43"
class_hash = "0x23660f8b5dd0b445a2edb889ea5c25b9a9116ef97ef15e9e93567a0bd801fdc"
original_class_hash = "0x23660f8b5dd0b445a2edb889ea5c25b9a9116ef97ef15e9e93567a0bd801fdc"
base_class_hash = "0x22f3e55b61d86c2ac5239fa3b3b8761f26b9a5c0b5f61ddbd5d756ced498b46"
abi = "manifests/dev/abis/deployments/contracts/dojo_starter_systems_actions_actions.json"
reads = []
Expand All @@ -38,14 +38,14 @@ name = "dojo_starter::systems::actions::actions"

[[models]]
kind = "DojoModel"
class_hash = "0x73c0915d3d9cb8deb698e4a6018acdee182f104b2c3b57627f25ea5d103d0ce"
original_class_hash = "0x73c0915d3d9cb8deb698e4a6018acdee182f104b2c3b57627f25ea5d103d0ce"
class_hash = "0x6f2ab954389d07486646883c96410be229d5261bf02a398a3b6e58e0fb953df"
original_class_hash = "0x6f2ab954389d07486646883c96410be229d5261bf02a398a3b6e58e0fb953df"
abi = "manifests/dev/abis/deployments/models/dojo_starter_models_beast_beast.json"
name = "dojo_starter::models::beast::beast"

[[models.members]]
name = "beast_id"
type = "u32"
type = "felt252"
key = true

[[models.members]]
Expand Down
2 changes: 1 addition & 1 deletion src/models/beast.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ use starknet::ContractAddress;
#[dojo::model]
struct Beast {
#[key]
beast_id: u32,
beast_id: felt252,
player_id: ContractAddress,
beast_type: felt252,
hp: u32,
Expand Down
8 changes: 4 additions & 4 deletions src/systems/actions.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ use dojo_starter::models::beast::Beast;
trait IActions {
fn spawn(ref world: IWorldDispatcher);
fn move(ref world: IWorldDispatcher, direction: Direction);
fn attack(ref world: IWorldDispatcher, beast_id: u32, damage: u32);
fn createBeast(ref world: IWorldDispatcher, beast_id: u32, beast_type: felt252, hp: u32, currentHp: u32, mp: u64, currentMp: u64, strength: u64, defense: u64, equipped_weapon: felt252, wpn_power: u8, equipped_armor: felt252, armor_power: u64, experience_to_nex_level: u64);
fn attack(ref world: IWorldDispatcher, beast_id: felt252, damage: u32);
fn createBeast(ref world: IWorldDispatcher, beast_id: felt252, beast_type: felt252, hp: u32, currentHp: u32, mp: u64, currentMp: u64, strength: u64, defense: u64, equipped_weapon: felt252, wpn_power: u8, equipped_armor: felt252, armor_power: u64, experience_to_nex_level: u64);
}

// dojo decorator
Expand Down Expand Up @@ -87,15 +87,15 @@ mod actions {
emit!(world, (Moved { player, direction }));
}

fn attack(ref world: IWorldDispatcher, beast_id: u32, damage: u32) {
fn attack(ref world: IWorldDispatcher, beast_id: felt252, damage: u32) {
let mut beast = get!(world, (beast_id), (Beast));
beast.hp = beast.hp - damage;
set!(world, (beast));
}

fn createBeast(
ref world: IWorldDispatcher,
beast_id: u32,
beast_id: felt252,
beast_type: felt252,
hp: u32,
currentHp: u32,
Expand Down

0 comments on commit 6d2246a

Please sign in to comment.