Repository: CryptoBlades/cryptoblades
File: contracts/cryptoblades.sol (Solidity)

Code before:

        uint256 skillAmount = usdToSkill(mintCharacterFee);
        (,, uint256 fromUserWallet) =
            getSkillToSubtract(
                0,
                tokenRewards[msg.sender],
                skillAmount
            );
        require(skillToken.balanceOf(msg.sender) >= fromUserWallet && promos.getBit(msg.sender, 4) == false);

        uint256 convertedAmount = usdToSkill(getMintCharacterFee());
        _payContractTokenOnly(msg.sender, convertedAmount);

        uint256 seed = randoms.getRandomSeed(msg.sender);
        characters.mint(msg.sender, seed);

        // first weapon free with a character mint, max 1 star
        if(weapons.balanceOf(msg.sender) == 0) {
            weapons.mintWeaponWithStars(msg.sender, 0, uint256(keccak256(abi.encodePacked(blockhash(block.number - 1), msg.sender))), 100);
        }

        _updateCharacterMintFee();
    }

    function generateWeaponSeed(uint32 quantity, uint8 chosenElement, uint256 eventId) external onlyNonContract oncePerBlock(msg.sender) {
        require(quantity > 0 && quantity <= 10);
        uint8 chosenElementFee = chosenElement == 100 ? 1 : 2;
        int128 mintWeaponFee =
            getMintWeaponFee()
                .mul(ABDKMath64x64.fromUInt(quantity))
                .mul(ABDKMath64x64.fromUInt(chosenElementFee));
        _payContractConvertedSupportingStaked(msg.sender, usdToSkill(mintWeaponFee));
        _updateWeaponMintFee(quantity);
        if (eventId > 0) {
            specialWeaponsManager.addShards(msg.sender, eventId, quantity);
        }
        SafeRandoms(links[LINK_SAFE_RANDOMS]).requestSingleSeed(msg.sender, getSeed(uint(WEAPON_SEED), quantity, chosenElement));
        userVars[msg.sender][USERVAR_CLAIM_WEAPON_DATA] = uint256(uint256(chosenElement) | (uint256(quantity) << 32));
    }

    function generateWeaponSeedUsingStakedSkill(uint32 quantity, uint8 chosenElement, uint256 eventId) external onlyNonContract oncePerBlock(msg.sender) {
        require(quantity > 0 && quantity <= 10);
        uint8 chosenElementFee = chosenElement == 100 ? 1 : 2;
        int128 discountedMintWeaponFee =
            getMintWeaponFee()
                .mul(PAYMENT_USING_STAKED_SKILL_COST_AFTER_DISCOUNT)
                .mul(ABDKMath64x64.fromUInt(quantity))
                .mul(ABDKMath64x64.fromUInt(chosenElementFee));
        _payContractStakedOnly(msg.sender, usdToSkill(discountedMintWeaponFee));
        _updateWeaponMintFee(quantity);
        if (eventId > 0) {

Review comment (suggestion):
adding
userVars[msg.sender][USERVAR_CLAIM_WEAPON_DATA] == 0
to the require statement here and in the other generate statement would be user friendly, to prevent accidental loss of funds. But in any case this is fine.

Code after:

        uint256 skillAmount = usdToSkill(mintCharacterFee);
        (,, uint256 fromUserWallet) =
            getSkillToSubtract(
                0,
                tokenRewards[msg.sender],
                skillAmount
            );
        require(skillToken.balanceOf(msg.sender) >= fromUserWallet && promos.getBit(msg.sender, 4) == false);

        uint256 convertedAmount = usdToSkill(getMintCharacterFee());
        _payContractTokenOnly(msg.sender, convertedAmount);

        uint256 seed = randoms.getRandomSeed(msg.sender);
        characters.mint(msg.sender, seed);

        // first weapon free with a character mint, max 1 star
        if(weapons.balanceOf(msg.sender) == 0) {
            weapons.mintWeaponWithStars(msg.sender, 0, uint256(keccak256(abi.encodePacked(blockhash(block.number - 1), msg.sender))), 100);
        }

        _updateCharacterMintFee();
    }

    function generateWeaponSeed(uint32 quantity, uint8 chosenElement, uint256 eventId) external onlyNonContract oncePerBlock(msg.sender) {
        require(quantity > 0 && quantity <= 10);
        require(userVars[msg.sender][USERVAR_CLAIM_WEAPON_DATA] == 0);
        uint8 chosenElementFee = chosenElement == 100 ? 1 : 2;
        int128 mintWeaponFee =
            getMintWeaponFee()
                .mul(ABDKMath64x64.fromUInt(quantity))
                .mul(ABDKMath64x64.fromUInt(chosenElementFee));
        _payContractConvertedSupportingStaked(msg.sender, usdToSkill(mintWeaponFee));
        _updateWeaponMintFee(quantity);
        if (eventId > 0) {
            specialWeaponsManager.addShards(msg.sender, eventId, quantity);
        }
        SafeRandoms(links[LINK_SAFE_RANDOMS]).requestSingleSeed(msg.sender, getSeed(uint(WEAPON_SEED), quantity, chosenElement));
        userVars[msg.sender][USERVAR_CLAIM_WEAPON_DATA] = uint256(uint256(chosenElement) | (uint256(quantity) << 32));
    }

    function generateWeaponSeedUsingStakedSkill(uint32 quantity, uint8 chosenElement, uint256 eventId) external onlyNonContract oncePerBlock(msg.sender) {
        require(quantity > 0 && quantity <= 10);
        require(userVars[msg.sender][USERVAR_CLAIM_WEAPON_DATA] == 0);
        uint8 chosenElementFee = chosenElement == 100 ? 1 : 2;
        int128 discountedMintWeaponFee =
            getMintWeaponFee()
                .mul(PAYMENT_USING_STAKED_SKILL_COST_AFTER_DISCOUNT)
                .mul(ABDKMath64x64.fromUInt(quantity))
                .mul(ABDKMath64x64.fromUInt(chosenElementFee));
        _payContractStakedOnly(msg.sender, usdToSkill(discountedMintWeaponFee));