-
Notifications
You must be signed in to change notification settings - Fork 28
Implement GearDetails Struct and Update Spawn Logic #155
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -3,10 +3,10 @@ | |
| /// | ||
| /// Spawn tournamemnts and side quests here, if necessary. | ||
|
|
||
| use coa::models::gear::Gear; | ||
| use coa::models::gear::{Gear, GearDetails}; | ||
| #[starknet::interface] | ||
| pub trait ICore<TContractState> { | ||
| fn spawn_items(ref self: TContractState, amount: u256); | ||
| fn spawn_items(ref self: TContractState, gear_details: Array<GearDetails>); | ||
| // move to market only items that have been spawned. | ||
| // if caller is admin, check spawned items and relocate | ||
| // if caller is player, | ||
|
|
@@ -74,8 +74,8 @@ pub mod CoreActions { | |
|
|
||
| #[abi(embed_v0)] | ||
| pub impl CoreActionsImpl of super::ICore<ContractState> { | ||
| //@ryzen-xp | ||
| fn spawn_items(ref self: ContractState, mut amount: u256) { | ||
| //@ryzen-xp, @truthixify | ||
| fn spawn_items(ref self: ContractState, gear_details: Array<GearDetails>) { | ||
| let caller = get_caller_address(); | ||
| let mut world = self.world_default(); | ||
| let contract: Contract = world.read_model(COA_CONTRACTS); | ||
|
|
@@ -86,23 +86,43 @@ pub mod CoreActions { | |
| }; | ||
|
|
||
| let mut items = array![]; | ||
| let mut i = 0; | ||
|
|
||
| while amount != 0 { | ||
| let mut gear: Gear = self.random_gear_generator(); | ||
|
|
||
| assert(!gear.spawned, 'Gear_already_spawned'); | ||
| while i < gear_details.len() { | ||
| let details = *gear_details.at(i); | ||
| assert(details.validate(), 'Invalid gear details'); | ||
|
|
||
| let item_id: u256 = self.generate_incremental_ids(details.gear_type.into()); | ||
| let item_type: felt252 = details.gear_type.into(); | ||
|
Comment on lines
+95
to
+96
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 💡 Verification agent 🧩 Analysis chainVerify GearType → u256 mapping suits ID partitioning. generate_incremental_ids groups by item_id.high; confirm Into for GearType sets the gear type in the high 128 bits (low = 0), else IDs won’t partition per type. Run: 🏁 Script executed: #!/bin/bash
# Locate GearType->u256 conversion
rg -n -C3 'impl\s+(Into|From)<\s*u256\s*>\s+for\s+GearType' src models helpers
rg -n -C3 'fn\s+into\(\)\s*->\s*u256' src models helpersLength of output: 189 #!/bin/bash
# 1. List all Cairo files containing GearType
rg -l 'GearType' -g '*.cairo'
# 2. For each of those files, search for any Into/From<u256> impls or into() calls
for f in $(rg -l 'GearType' -g '*.cairo'); do
echo "=== $f ==="
rg -n -C3 'impl\s+(Into|From)<\s*u256\s*>\s+for\s+GearType' "$f"
rg -n -C3 'into\(' "$f" | grep -i GearType || true
done🏁 Script executed: #!/bin/bash
# 1. Locate GearType definition
rg -l 'enum GearType' -g '*.cairo'
rg -n -C3 'enum GearType' -g '*.cairo'
# 2. Search for any explicit impl converting GearType to u256
rg -n -C3 'impl\s+(Into|From)<\s*u256\s*>\s+for\s+GearType' -g '*.cairo'
# 3. Inspect generate_incremental_ids to verify how high/low bits are used
rg -n -C3 'func generate_incremental_ids' -g '*.cairo'Length of output: 347 Map GearType into high 128 bits for proper ID partitioning. The call let type_prefix: u256 = u256{ high: details.gear_type.into(), low: 0 };
let item_id: u256 = self.generate_incremental_ids(type_prefix);🤖 Prompt for AI Agents |
||
|
|
||
| let mut gear = Gear { | ||
| id: item_id, | ||
| item_type, | ||
| asset_id: item_id, | ||
| variation_ref: details.variation_ref, | ||
| total_count: details.total_count, | ||
| in_action: false, | ||
| upgrade_level: 0, | ||
| owner: contract_address_const::<0>(), | ||
| max_upgrade_level: details.max_upgrade_level, | ||
| min_xp_needed: details.min_xp_needed, | ||
| spawned: false, | ||
| }; | ||
|
|
||
| assert(!gear.spawned, 'Gear already spawned'); | ||
| gear.spawned = true; | ||
| gear.owner = contract_address_const::<0>(); | ||
| world.write_model(@gear); | ||
|
|
||
| items.append(gear.id); | ||
| amount -= 1; | ||
| // mint to warehouse | ||
| erc1155_dispatcher.mint(contract.warehouse, gear.id, 1, array![].span()); | ||
| erc1155_dispatcher | ||
| .mint(contract.warehouse, gear.id, details.total_count.into(), array![].span()); | ||
| i += 1; | ||
| }; | ||
|
|
||
| let event = GearSpawned { admin: caller, items }; | ||
| world.emit_event(@event); | ||
| } | ||
|
|
||
| // move to market only items that have been spawned. | ||
| // if caller is admin, check spawned items and relocate | ||
| // if caller is player, | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
💡 Verification agent
🧩 Analysis chain
Confirm validation enforces safe mint bounds (non-zero, sane caps).
Ensure details.validate() guarantees:
Run:
Also applies to: 117-119
🏁 Script executed:
Length of output: 1006
Validate must enforce total_count, max_upgrade_level, and variation_ref constraints
validate() currently only checks
Add checks for:
File: src/models/gear.cairo, fn validate (around lines 210–213)