Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- pragma solidity ^0.4.19;
- import './Ownable.sol';
- /** ************************************************************************ **/
- /** *************************** Cuddle Data ******************************** **/
- /** ************************************************************************ **/
- /**
- * @dev Holds the data for all kitty actions and all kitty effects.
- **/
- contract CuddleData is Ownable {
- // Action/Effect Id => struct for actions and for effects.
- mapping (uint256 => Action) public actions;
- // Actions specific to personality types.
- mapping (uint256 => uint256) actionLengths;
- // This struct used for all moves a kitty may have.
- struct Action {
- uint256 energy;
- uint256[6] basePets; // Each owner is an index that has a base amount of pets.
- uint8[6] petsAddition; // Special effects may give extra pets.
- uint16[6] critChance; // Special effects may increase (or decrease?) crit chance.
- uint16[6] missChance; // Special effects may decrease (or increase?) miss chance.
- uint8 turnsAffected; // If an effect occurrs
- }
- /** ************************** EXTERNAL VIEW ******************************* **/
- /**
- * @dev Used by CuddleScience to get relevant info for a sequence of moves.
- * @param _actions The 8 length array of the move sequence.
- * @param _cuddleOwner The owner Id that we need info for.
- **/
- function returnActions(uint256[8] _actions, uint256 _cuddleOwner)
- external
- view
- returns (uint256[8] energy, uint256[8] basePets, uint256[8] petsAddition,
- uint256[8] critChance, uint256[8] missChance, uint256[8] turnsAffected)
- {
- for (uint256 i = 0; i < 8; i++) {
- if (_actions[i] == 0) break;
- Action memory action = actions[_actions[i]];
- energy[i] = action.energy;
- basePets[i] = action.basePets[_cuddleOwner];
- petsAddition[i] = action.petsAddition[_cuddleOwner];
- critChance[i] = action.critChance[_cuddleOwner];
- missChance[i] = action.missChance[_cuddleOwner];
- turnsAffected[i] = action.turnsAffected;
- }
- }
- function returnAction(uint256 _actionId)
- external
- view
- returns (uint256 energy, uint256[6] basePets, uint8[6] petsAddition, uint16[6] critChance,
- uint16[6] missChance, uint8 turnsAffected)
- {
- Action action = actions[_actionId];
- return (action.energy, action.basePets, action.petsAddition, action.critChance,
- action.missChance, action.turnsAffected);
- }
- /**
- * @dev Returns the amount of kitty actions available.
- * @param _personality If we want personality actions, this is the personality index
- **/
- function getActionCount(uint256 _personality)
- external
- view
- returns (uint256 totalActions)
- {
- return actionLengths[_personality];
- }
- /** ******************************* ONLY OWNER ***************************** **/
- /**
- * @dev Used by the owner to create/edit a new action that kitties may learn.
- * @param _actionId The given ID of this action.
- * @param _newEnergy The amount of energy the action will cost.
- * @param _newPets The amount of base pets each owner will give to this action.
- * @param _petAdditions The amount of additional pets each owner will give.
- * @param _critChance The crit chance this move has against each owner.
- * @param _missChance The miss chance this move has against each owner.
- * @param _turnsAffected The amount of turns an effect, if any, will be applied.
- * @param _personality The type/personality this move is specific to (0 for any).
- **/
- function addAction(uint256 _actionId, uint256 _newEnergy, uint256[6] _newPets, uint8[6] _petAdditions,
- uint16[6] _critChance, uint16[6] _missChance, uint8 _turnsAffected, uint256 _personality)
- public
- onlyOwner
- {
- Action memory newAction = Action(_newEnergy, _newPets, _petAdditions, _critChance, _missChance, _turnsAffected);
- actions[_actionId] = newAction;
- actionLengths[_personality]++;
- }
- /**
- * @dev Same as add action but does not alter actionLengths.
- **/
- function editAction(uint256 _actionId, uint256 _newEnergy, uint256[6] _newPets, uint8[6] _petAdditions,
- uint16[6] _critChance, uint16[6] _missChance, uint8 _turnsAffected)
- public
- onlyOwner
- {
- Action memory newAction = Action(_newEnergy, _newPets, _petAdditions, _critChance, _missChance, _turnsAffected);
- actions[_actionId] = newAction;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement