Skip to content

Commit

Permalink
change u128 for u64
Browse files Browse the repository at this point in the history
  • Loading branch information
dpinones committed Dec 24, 2023
1 parent 44ba4c0 commit 5679d26
Show file tree
Hide file tree
Showing 12 changed files with 48 additions and 46 deletions.
2 changes: 1 addition & 1 deletion src/constants.cairo
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
fn MAP_1() -> (Array<felt252>, (u128, u128)) {
fn MAP_1() -> (Array<felt252>, (u64, u64)) {
let mut map = array![
'G',
'G',
Expand Down
12 changes: 6 additions & 6 deletions src/models/data/starkane.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -50,26 +50,26 @@ impl CharacterPlayerProgressImpl of CharacterPlayerProgressTrait {
struct PlayerStadistics {
#[key]
owner: felt252,
matchs_won: u128,
matchs_lost: u128,
matchs_won: u64,
matchs_lost: u64,
characters_owned: u32,
total_score: u128,
total_score: u64,
}

#[derive(Model, Copy, Drop, Serde)]
struct Ranking {
#[key]
id: u32,
player: felt252,
score: u128
score: u64
}

trait RankingTrait {
fn new(id: u32, player: felt252, score: u128) -> Ranking;
fn new(id: u32, player: felt252, score: u64) -> Ranking;
}

impl RankingImpl of RankingTrait {
fn new(id: u32, player: felt252, score: u128) -> Ranking {
fn new(id: u32, player: felt252, score: u64) -> Ranking {
Ranking { id, player, score }
}
}
Expand Down
16 changes: 8 additions & 8 deletions src/models/entities/character.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,14 @@ struct Character {
#[key]
character_id: u32,
character_type: u8,
hp: u128,
mp: u128,
attack: u128,
defense: u128,
evasion: u128,
crit_chance: u128,
crit_rate: u128,
movement_range: u128,
hp: u64,
mp: u64,
attack: u64,
defense: u64,
evasion: u64,
crit_chance: u64,
crit_rate: u64,
movement_range: u64,
}

trait CharacterTrait {
Expand Down
8 changes: 4 additions & 4 deletions src/models/entities/map.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ use starkane::constants;
struct Map {
#[key]
id: u32,
width: u128,
height: u128,
width: u64,
height: u64,
}

#[derive(Model, Copy, Drop, Serde)]
Expand All @@ -28,7 +28,7 @@ enum TerrainType {

trait MapTrait {
fn new(id: u32) -> (Map, Array<Tile>);
fn is_inside(self: Map, position: (u128, u128)) -> bool;
fn is_inside(self: Map, position: (u64, u64)) -> bool;
}

impl MapImpl of MapTrait {
Expand All @@ -37,7 +37,7 @@ impl MapImpl of MapTrait {
create_map_1()
}

fn is_inside(self: Map, position: (u128, u128)) -> bool {
fn is_inside(self: Map, position: (u64, u64)) -> bool {
let (x, y) = position;
x >= 0 && x < self.width && y >= 0 && y < self.height
}
Expand Down
6 changes: 3 additions & 3 deletions src/models/entities/skill.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,9 @@ struct Skill {
level: u8,
character_level_required: u8,
skill_type: u8,
power: u128,
mp_cost: u128,
range: u128,
power: u64,
mp_cost: u64,
range: u64,
}

trait SkillTrait {
Expand Down
24 changes: 12 additions & 12 deletions src/models/states/character_state.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -32,21 +32,21 @@ struct CharacterState {
character_id: u32,
#[key]
player: felt252,
remain_hp: u128,
remain_mp: u128,
x: u128,
y: u128,
remain_hp: u64,
remain_mp: u64,
x: u64,
y: u64,
}

trait CharacterStateTrait {
fn new(
match_id: u32,
character_id: u32,
player: felt252,
remain_hp: u128,
remain_mp: u128,
x: u128,
y: u128
remain_hp: u64,
remain_mp: u64,
x: u64,
y: u64
) -> CharacterState;
}

Expand All @@ -55,10 +55,10 @@ impl CharacterStateImpl of CharacterStateTrait {
match_id: u32,
character_id: u32,
player: felt252,
remain_hp: u128,
remain_mp: u128,
x: u128,
y: u128
remain_hp: u64,
remain_mp: u64,
x: u64,
y: u64
) -> CharacterState {
CharacterState { match_id, character_id, player, remain_hp, remain_mp, x, y, }
}
Expand Down
6 changes: 3 additions & 3 deletions src/systems/action_system.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -182,14 +182,14 @@ mod action_system {
// Check if the receiver evades the attack
let mut randomizer = RandomImpl::new(world);
randomizer.next_seed();
let receiver_evade_attack = randomizer.between::<u128>(0, 100) < receiver.evasion;
let receiver_evade_attack = randomizer.between::<u64>(0, 100) < receiver.evasion;

if !receiver_evade_attack {
let mut receiver_state = receiver_state;
let mut damage = attacker.attack + skill.power;

randomizer.next_seed();
let attacker_crit_attack = randomizer.between::<u128>(0, 100) < attacker.crit_chance;
let attacker_crit_attack = randomizer.between::<u64>(0, 100) < attacker.crit_chance;

if attacker_crit_attack {
damage = damage * attacker.crit_rate;
Expand Down Expand Up @@ -236,7 +236,7 @@ mod action_system {
set!(world, (receiver_state));
}

fn distance(from: (u128, u128), to: (u128, u128)) -> u128 {
fn distance(from: (u64, u64), to: (u64, u64)) -> u64 {
let (from_x, from_y) = from;
let (to_x, to_y) = to;

Expand Down
2 changes: 1 addition & 1 deletion src/systems/match_system.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ mod match_system {
}
}

fn obtain_position(player_index: u32, i: u32) -> (u128, u128) {
fn obtain_position(player_index: u32, i: u32) -> (u64, u64) {
if player_index == 0 {
(5 + i.into(), 5)
} else if player_index == 1 {
Expand Down
6 changes: 3 additions & 3 deletions src/systems/move_system.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ trait IMoveSystem<TContractState> {
match_id: u32,
player: felt252,
character_id: u32,
position: (u128, u128)
position: (u64, u64)
);
}

Expand Down Expand Up @@ -33,7 +33,7 @@ mod move_system {
match_id: u32,
player: felt252,
character_id: u32,
position: (u128, u128)
position: (u64, u64)
) {
// [Setup] Datastore
let world = self.world();
Expand Down Expand Up @@ -79,7 +79,7 @@ mod move_system {
}
}

fn distance(from: (u128, u128), to: (u128, u128)) -> u128 {
fn distance(from: (u64, u64), to: (u64, u64)) -> u64 {
let (from_x, from_y) = from;
let (to_x, to_y) = to;

Expand Down
6 changes: 3 additions & 3 deletions src/systems/ranking_system.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ use starkane::models::data::starkane::Ranking;

#[starknet::interface]
trait IRankingSystem<TContractState> {
fn update(self: @TContractState, player: felt252, score: u128);
fn update(self: @TContractState, player: felt252, score: u64);
}

#[dojo::contract]
Expand All @@ -23,7 +23,7 @@ mod ranking_system {

#[external(v0)]
impl RankingSystem of IRankingSystem<ContractState> {
fn update(self: @ContractState, player: felt252, score: u128) {
fn update(self: @ContractState, player: felt252, score: u64) {
// [Setup] Datastore
let mut store: Store = StoreTrait::new(self.world());
let ranking_count = store.get_ranking_count(RANKING_COUNT_KEY).index;
Expand Down Expand Up @@ -53,7 +53,7 @@ mod ranking_system {
}

fn get_rankings(
ref store: Store, player: felt252, ranking_len: u32, score: u128
ref store: Store, player: felt252, ranking_len: u32, score: u64
) -> (Array<Ranking>, bool) {
let mut rankings = array![];
let mut founded = false;
Expand Down
2 changes: 1 addition & 1 deletion src/systems/stadistics_system.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ mod stadistics_system {
}
}

fn calculate_score(match_state: MatchState, characters_states: @Array<CharacterState>) -> u128 {
fn calculate_score(match_state: MatchState, characters_states: @Array<CharacterState>) -> u64 {
let mut score = 0;
let mut i = 0;
loop {
Expand Down
4 changes: 3 additions & 1 deletion src/utils/random.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,10 @@ impl RandomImpl of RandomTrait {

fn between<
T,
+Into<T, u64>,
+Into<T, u128>,
+Into<T, u256>,
+TryInto<u64, T>,
+TryInto<u128, T>,
+PartialOrd<T>,
+Zeroable<T>,
Expand All @@ -70,4 +72,4 @@ fn seed() -> felt252 {
data.append(get_contract_address().into());
data.append(get_block_timestamp().into());
poseidon_hash_span(data.span())
}
}

0 comments on commit 5679d26

Please sign in to comment.