Skip to content

Commit

Permalink
fixes itemsleveledup not emitted when slaying beast (#361)
Browse files Browse the repository at this point in the history
  • Loading branch information
loothero authored Sep 23, 2023
1 parent 05e0f90 commit 95a9200
Showing 1 changed file with 19 additions and 11 deletions.
30 changes: 19 additions & 11 deletions contracts/game/src/lib.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -832,21 +832,18 @@ mod Game {
// zero out beast health
adventurer.beast_health = 0;

// give adventurer gold reward
// TODO Gas Optimization: beast.get_gold_reward and get_xp_reward both call the same
// get_base_reward from Combat module. Should refactor this to only make that call once and have
// get_gold_reward and get_xp_reward operator on the base reward
let mut gold_earned = beast.get_gold_reward(beast_seed);
let bag = _unpacked_bag(@self, adventurer_id);
// get gold reward and increase adventurers gold
let gold_earned = beast.get_gold_reward(beast_seed);
adventurer.increase_gold(gold_earned * adventurer.beast_gold_reward_multiplier().into());

// grant adventuer xp
// get xp reward and increase adventurers xp
let xp_earned_adventurer = beast.get_xp_reward();
let (previous_level, new_level) = adventurer.increase_adventurer_xp(xp_earned_adventurer);

// grant equipped items xp, items level faster than Adventurers
// items use adventurer xp with an item multplier so they level faster than Adventurer
let xp_earned_items = xp_earned_adventurer * ITEM_XP_MULTIPLIER_BEASTS;
_grant_xp_to_equipped_items(
// assigning xp to items is more complex so we delegate to an internal function
let items_leveled_up = _grant_xp_to_equipped_items(
ref self, ref adventurer, adventurer_id, xp_earned_items, attack_rnd_2
);

Expand All @@ -864,12 +861,21 @@ mod Game {
gold_earned
);

// if adventurers new level is greater than previous level
// if any items leveled up
if items_leveled_up.len() != 0 {
// emit event
__event_ItemsLeveledUp(ref self, adventurer, adventurer_id, items_leveled_up);
}

// if adventurer gained stat points
if (adventurer.stat_points_available != 0) {
// emit events
_emit_level_up_events(ref self, adventurer, adventurer_id, previous_level, new_level);
}

// if beast beast level is above collectible threshold
if beast.combat_spec.level >= BEAST_SPECIAL_NAME_LEVEL_UNLOCK {
// adventurers gets the beast
_mint_beast(@self, beast);
}
}
Expand Down Expand Up @@ -1067,7 +1073,9 @@ mod Game {
);

// generate a new adventurer using the provided started weapon and current block number
let mut new_adventurer: Adventurer = ImplAdventurer::new(starting_weapon, NUM_STARTING_STATS, block_number, adventurer_entropy);
let mut new_adventurer: Adventurer = ImplAdventurer::new(
starting_weapon, NUM_STARTING_STATS, block_number, adventurer_entropy
);

// set entropy on adventurer metadata
let adventurer_meta = AdventurerMetadata {
Expand Down

1 comment on commit 95a9200

@vercel
Copy link

@vercel vercel bot commented on 95a9200 Sep 23, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.