Last active
June 15, 2018 01:22
-
-
Save johnX9/9966ef5813f851cf990172187cb536a5 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Players.hpp | |
//@abi action | |
void additem(const account_name account, item purchased_item); | |
# Players.cpp | |
void Players::additem(const account_name account, item purchased_item) { | |
playerIndex players(_self, _self); | |
auto iterator = players.find(account); | |
eosio_assert(iterator != players.end(), "Address for account not found"); | |
players.modify(iterator, account, [&](auto& player) { | |
player.energy_points += purchased_item.power; | |
player.health_points += purchased_item.health; | |
player.level += purchased_item.level_up; | |
player.abilities.push_back(purchased_item.ability); | |
player.inventory.push_back(item{ | |
purchased_item.item_id, | |
purchased_item.name, | |
purchased_item.power, | |
purchased_item.health, | |
purchased_item.ability, | |
purchased_item.level_up | |
}); | |
}); | |
print("Item Id: ", purchased_item.item_id); | |
print(" | Name: ", purchased_item.name.c_str()); | |
print(" | Power: ", purchased_item.power); | |
print(" | Health: ", purchased_item.health); | |
print(" | Ability: ", purchased_item.ability.c_str()); | |
print(" | Level up: ", purchased_item.level_up); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment