Skip to content

Commit

Permalink
feat: battle feature
Browse files Browse the repository at this point in the history
  • Loading branch information
tiankonglan committed Nov 13, 2023
1 parent c545d9a commit 4e7bcf4
Show file tree
Hide file tree
Showing 10 changed files with 563 additions and 71 deletions.
5 changes: 0 additions & 5 deletions .vscode/settings.json

This file was deleted.

8 changes: 4 additions & 4 deletions Scarb.lock
Original file line number Diff line number Diff line change
Expand Up @@ -3,19 +3,19 @@ version = 1

[[package]]
name = "dojo"
version = "0.3.3"
source = "git+https://github.com/dojoengine/dojo#3c9f109e667ca5d12739e6553fdb8261378f4ecf"
version = "0.3.6"
source = "git+https://github.com/dojoengine/dojo#1526f3088d6dcddf626c207af7b3769e2182c5c0"
dependencies = [
"dojo_plugin",
]

[[package]]
name = "dojo_plugin"
version = "0.3.3"
version = "0.3.6"

[[package]]
name = "pet_battle"
version = "0.3.2"
version = "0.1.0"
dependencies = [
"dojo",
]
6 changes: 3 additions & 3 deletions Scarb.toml
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
[package]
cairo-version = "2.2.0"
cairo-version = "2.3.1"
name = "pet_battle"
version = "0.3.2"
version = "0.1.0"

[cairo]
sierra-replace-ids = true

[dependencies]
dojo = { git = "https://github.com/dojoengine/dojo", version = "0.3.2" }
dojo = { git = "https://github.com/dojoengine/dojo", version = "0.3.6" }

[[target.dojo]]

Expand Down
39 changes: 0 additions & 39 deletions src/actions.cairo

This file was deleted.

70 changes: 70 additions & 0 deletions src/config.cairo
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
use starknet::{ContractAddress};

// define the interface
#[starknet::interface]
trait IConfig<TContractState> {
fn initRole(self: @TContractState);
fn initSkill(self: @TContractState);
}

// dojo decorator
#[dojo::contract]
mod config {
use pet_battle::models::{Role, Skill};
use pet_battle::constants;
use super::IConfig;

#[external(v0)]
impl ConfigImpl of IConfig<ContractState> {
fn initRole(self: @ContractState) {
let world = self.world_dispatcher.read();

let warrior = Role {
id: constants::ROLE_WARRIOR,
hp: 300,
attack: 100,
defense: 40,
hit: 0,
dodge: 0,
crit: 0,
speed: 20,
};
set!(world, (warrior));

let knight = Role {
id: constants::ROLE_KNIGHT,
hp: 400,
attack: 70,
defense: 60,
hit: 0,
dodge: 0,
crit: 0,
speed: 18,
};
set!(world, (knight));
}

fn initSkill(self: @ContractState) {
let world = self.world_dispatcher.read();

let comboAttackSkill = Skill {
id : constants::SKILL_COMBO_ATTACK,
value : 20,
};
set!(world, comboAttackSkill);

let addHpSkill = Skill{
id : constants::SKILL_ADD_HP,
value : 100,
};
set!(world, addHpSkill);

let addSpeedSkill = Skill{
id : constants::SKILL_ADD_SPEED,
value : 100,
};
set!(world, addSpeedSkill);
}
}

}
8 changes: 8 additions & 0 deletions src/constants.cairo
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
// Role Constant
const ROLE_WARRIOR: u32 = 0;
const ROLE_KNIGHT: u32 = 1;

// Skill Constant
const SKILL_COMBO_ATTACK: u32 = 0;
const SKILL_ADD_HP: u32 = 1;
const SKILL_ADD_SPEED: u32 = 2;
Loading

0 comments on commit 4e7bcf4

Please sign in to comment.