Skip to content

Commit

Permalink
new encounters wip
Browse files Browse the repository at this point in the history
  • Loading branch information
notV4l committed Apr 3, 2024
1 parent cac50f3 commit e5842a0
Show file tree
Hide file tree
Showing 12 changed files with 768 additions and 18 deletions.
2 changes: 2 additions & 0 deletions scripts/default_auth.sh
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,8 @@ sozo -P $PROFILE auth grant --world $WORLD_ADDRESS --wait writer\
DrugConfig,$CONFIG_ADDRESS \
LocationConfig,$CONFIG_ADDRESS \
HustlerItemBaseConfig,$CONFIG_ADDRESS \
HustlerItemTiersConfig,$CONFIG_ADDRESS \
EncounterConfig,$CONFIG_ADDRESS \
Game,$GAME_ADDRESS \
GameStorePacked,$GAME_ADDRESS \
RyoConfig,$GAME_ADDRESS \
Expand Down
12 changes: 8 additions & 4 deletions src/config/config.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ trait IConfig<T> {
struct Config {
layouts: LayoutsConfig,
hustlers: Array<HustlerConfig>,
game_config: GameConfig,
game_config: GameConfig, // TODO: query torii instead
}

#[derive(Drop, Serde)]
Expand Down Expand Up @@ -50,7 +50,8 @@ mod config {
initialize_feet_config, initialize_transport_config, initialize_weapons_tiers_config,
initialize_clothes_tiers_config, initialize_feet_tiers_config,
initialize_transport_tiers_config,
}
},
encounters::{initialize_encounter_config, EncounterConfig, Encounters},
},
packing::{
game_store_layout::{
Expand Down Expand Up @@ -91,6 +92,9 @@ mod config {
initialize_feet_tiers_config(world);
initialize_transport_tiers_config(world);

// encounters
initialize_encounter_config(world);

// game
initialize_game_config(world);
}
Expand Down Expand Up @@ -144,13 +148,13 @@ mod config {
Option::None => { break; }
};
};

//

let game_config = GameConfigImpl::get(world);

//
Config { game_config, layouts: LayoutsConfig { game_store, player }, hustlers }
Config { game_config, hustlers, layouts: LayoutsConfig { game_store, player } }
}

fn update_game_config(self: @ContractState, game_config: GameConfig) {
Expand Down
11 changes: 8 additions & 3 deletions src/config/drugs.cairo
Original file line number Diff line number Diff line change
@@ -1,9 +1,14 @@
use dojo::world::{IWorldDispatcher, IWorldDispatcherTrait};

use rollyourown::utils::bytes16::{Bytes16, Bytes16Impl, Bytes16Trait};
use rollyourown::utils::introspect::Bytes16IntrospectionImpl;
use rollyourown::{
traits::{Enumerable}, utils::introspect::{Bytes31IntrospectionImpl},
utils::{
bytes16::{Bytes16, Bytes16Impl, Bytes16Trait},
introspect::Bytes16IntrospectionImpl
}
};


use rollyourown::{traits::{Enumerable}, utils::introspect::{Bytes31IntrospectionImpl}};


#[derive(Copy, Drop, Serde, PartialEq, Introspect)]
Expand Down
243 changes: 243 additions & 0 deletions src/config/encounters.cairo
Original file line number Diff line number Diff line change
@@ -0,0 +1,243 @@
use starknet::ContractAddress;
use dojo::world::{IWorldDispatcher, IWorldDispatcherTrait};
use rollyourown::{
utils::{
random::{Random, RandomImpl}, math::{MathTrait, MathImplU8},
bits::{Bits, BitsImpl, BitsTrait, BitsMathImpl},
bytes16::{Bytes16, Bytes16Impl, Bytes16Trait}
}
};


//
//
//


#[derive(Model, Copy, Drop, Serde)]
struct EncounterConfig {
// name: Bytes16,
#[key]
id: u8,
encounter: Encounters,
//
level: u8,
health: u8,
attack: u8,
defense: u8,
// 32
payout: u32,
// 32
demand_pct: u8,
rep_pay: u8, // reputation modifier for paying NEGATIVE
rep_run: u8, // reputation modifier for running
rep_fight: u8, // reputation modifier for fighting
// 16
min_rep: u8,
max_rep: u8,
//
// crit_rate:u8,
// incorruptible: bool,
// challenger: bool,
// challenger: bool,
}

//
//
//

#[generate_trait]
impl EncounterConfigImpl of EncounterConfigTrait {
#[inline(always)]
fn get(world: IWorldDispatcher, id: u8) -> EncounterConfig {
get!(world, (id), EncounterConfig)
}
}

//
//
//

#[derive(Copy, Drop, Serde, PartialEq, Introspect)]
enum Encounters {
Cops,
Gang,
}

impl EncountersIntoFelt252 of Into<Encounters, felt252> {
fn into(self: Encounters) -> felt252 {
match self {
Encounters::Cops => 'Cops',
Encounters::Gang => 'Gang',
}
}
}

impl EncountersIntoU8 of Into<Encounters, u8> {
fn into(self: Encounters) -> u8 {
match self {
Encounters::Cops => 0,
Encounters::Gang => 1,
}
}
}


//
//
//



fn initialize_encounter_config(world: IWorldDispatcher) {

//////// COPS ////////

set!(
world,
EncounterConfig {
// name: Bytes16Impl::from('Cops LVL 1'),
id:0,
encounter: Encounters::Cops,
//
level: 1,
health: 16,
attack: 8,
defense: 5,
//
payout: 420,
demand_pct: 20,
//
rep_pay: 10,
rep_run: 0,
rep_fight: 2,
//
min_rep: 0,
max_rep: 40,
}
);

set!(
world,
EncounterConfig {
// name: Bytes16Impl::from('Cops LVL 2'),
id:1,
encounter: Encounters::Cops,
//
level: 2,
health: 26,
attack: 16,
defense: 11,
//
payout: 2500,
demand_pct: 30,
//
rep_pay: 6,
rep_run: 2,
rep_fight: 4,
//
min_rep: 20,
max_rep: 60,
}
);

set!(
world,
EncounterConfig {
// name: Bytes16Impl::from('Cops LVL 3'),
id:2,
encounter: Encounters::Cops,
//
level: 3,
health: 42,
attack: 25,
defense: 15,
//
payout: 20000,
demand_pct: 30,
//
rep_pay: 5,
rep_run: 3,
rep_fight: 6,
//
min_rep: 40,
max_rep: 100,
}
);


//////// GANGS ////////

set!(
world,
EncounterConfig {
// name: Bytes16Impl::from('GANG LVL 1'),
id:7,
encounter: Encounters::Gang,
//
level: 1,
health: 16,
attack: 8,
defense: 5,
//
payout: 420,
demand_pct: 20,
//
rep_pay: 10,
rep_run: 0,
rep_fight: 2,
//
min_rep: 0,
max_rep: 40,
}
);

set!(
world,
EncounterConfig {
// name: Bytes16Impl::from('GANG LVL 2'),
id:8,
encounter: Encounters::Gang,
//
level: 2,
health: 26,
attack: 16,
defense: 11,
//
payout: 2500,
demand_pct: 30,
//
rep_pay: 6,
rep_run: 2,
rep_fight: 4,
//
min_rep: 20,
max_rep: 60,
}
);

set!(
world,
EncounterConfig {
// name: Bytes16Impl::from('GANG LVL 3'),
id:9,
encounter: Encounters::Gang,
//
level: 3,
health: 42,
attack: 25,
defense: 15,
//
payout: 20000,
demand_pct: 30,
//
rep_pay: 5,
rep_run: 3,
rep_fight: 6,
//
min_rep: 40,
max_rep: 100,
}
);

}
3 changes: 2 additions & 1 deletion src/lib.cairo
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
mod config {
mod config;
mod drugs;
mod locations;
mod encounters;
mod game;
mod hustlers;
mod locations;
mod ryo;
mod ryo_address;
}
Expand Down
1 change: 0 additions & 1 deletion src/packing/game_store.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ use rollyourown::{
wanted_packed::{WantedPacked, WantedPackedImpl},
markets_packed::{MarketsPacked, MarketsPackedImpl},
items_packed::{ItemsPacked, ItemsPackedImpl},
encounters_packed::{EncountersPacked, EncountersPackedImpl},
player::{Player, PlayerImpl, PlayerPackerImpl, PlayerUnpackerImpl},
},
utils::bits::{Bits, BitsImpl, BitsTrait, BitsDefaultImpl}, traits::{Packable, Packer, Unpacker}
Expand Down
1 change: 0 additions & 1 deletion src/packing/player.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ use rollyourown::{
game_store::{GameStore},
player_layout::{PlayerLayout, PlayerLayoutEnumerableImpl, PlayerLayoutPackableImpl},
drugs_packed::{DrugsPacked, DrugsPackedImpl},
encounters_packed::{EncountersPacked, EncountersPackedImpl, Encounters},
markets_packed::{MarketsPacked, MarketsPackedImpl, MarketsPackedTrait}
},
};
Expand Down
2 changes: 1 addition & 1 deletion src/systems/game.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ mod game {
},
packing::{
game_store::{GameStore, GameStoreImpl, GameStorePackerImpl, GameMode},
encounters_packed::{Encounters}, player::{Player, PlayerImpl},
player::{Player, PlayerImpl},
},
systems::{
trading, shopping, traveling, traveling::EncounterOutcomes, game_loop,
Expand Down
5 changes: 3 additions & 2 deletions src/systems/traveling.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -8,17 +8,18 @@ use rollyourown::{
},
config::{
hustlers::{HustlerItemConfig,HustlerItemTiersConfig, ItemSlot}, locations::{Locations, LocationsRandomizableImpl},
game::{GameConfig, GameConfigImpl}
encounters::{Encounters},
game::{GameConfig, GameConfigImpl},
},
packing::{
game_store::{GameStore}, player::{PlayerImpl, PlayerStatus},
wanted_packed::{WantedPacked, WantedPackedImpl}, items_packed::{ItemsPackedImpl, ItemsPackedTrait},
encounters_packed::{Encounters, EncountersPackedImpl, EncountersPackedTrait},
drugs_packed::{DrugsPacked, DrugsPackedImpl, DrugsUnpacked, DrugsPackedTrait}
},
systems::game::{EncounterActions, game::TravelEncounterResult, game::Event}
};


#[derive(Copy, Drop, Serde, PartialEq)]
enum EncounterOutcomes {
Died,
Expand Down
Loading

0 comments on commit e5842a0

Please sign in to comment.