Advertisement
Guest User

Untitled

a guest
Apr 23rd, 2018
69
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.70 KB | None | 0 0
  1. pragma solidity ^0.4.19;
  2. import './Ownable.sol';
  3.  
  4. /** ************************************************************************ **/
  5. /** *************************** Cuddle Data ******************************** **/
  6. /** ************************************************************************ **/
  7.  
  8. /**
  9. * @dev Holds the data for all kitty actions and all kitty effects.
  10. **/
  11. contract CuddleData is Ownable {
  12. // Action/Effect Id => struct for actions and for effects.
  13. mapping (uint256 => Action) public actions;
  14. // Actions specific to personality types.
  15. mapping (uint256 => uint256) actionLengths;
  16.  
  17. // This struct used for all moves a kitty may have.
  18. struct Action {
  19. uint256 energy;
  20. uint256[6] basePets; // Each owner is an index that has a base amount of pets.
  21. uint8[6] petsAddition; // Special effects may give extra pets.
  22. uint16[6] critChance; // Special effects may increase (or decrease?) crit chance.
  23. uint16[6] missChance; // Special effects may decrease (or increase?) miss chance.
  24. uint8 turnsAffected; // If an effect occurrs
  25. }
  26.  
  27. /** ************************** EXTERNAL VIEW ******************************* **/
  28.  
  29. /**
  30. * @dev Used by CuddleScience to get relevant info for a sequence of moves.
  31. * @param _actions The 8 length array of the move sequence.
  32. * @param _cuddleOwner The owner Id that we need info for.
  33. **/
  34. function returnActions(uint256[8] _actions, uint256 _cuddleOwner)
  35. external
  36. view
  37. returns (uint256[8] energy, uint256[8] basePets, uint256[8] petsAddition,
  38. uint256[8] critChance, uint256[8] missChance, uint256[8] turnsAffected)
  39. {
  40. for (uint256 i = 0; i < 8; i++) {
  41. if (_actions[i] == 0) break;
  42.  
  43. Action memory action = actions[_actions[i]];
  44. energy[i] = action.energy;
  45. basePets[i] = action.basePets[_cuddleOwner];
  46. petsAddition[i] = action.petsAddition[_cuddleOwner];
  47. critChance[i] = action.critChance[_cuddleOwner];
  48. missChance[i] = action.missChance[_cuddleOwner];
  49. turnsAffected[i] = action.turnsAffected;
  50. }
  51. }
  52.  
  53. function returnAction(uint256 _actionId)
  54. external
  55. view
  56. returns (uint256 energy, uint256[6] basePets, uint8[6] petsAddition, uint16[6] critChance,
  57. uint16[6] missChance, uint8 turnsAffected)
  58. {
  59. Action action = actions[_actionId];
  60. return (action.energy, action.basePets, action.petsAddition, action.critChance,
  61. action.missChance, action.turnsAffected);
  62. }
  63.  
  64. /**
  65. * @dev Returns the amount of kitty actions available.
  66. * @param _personality If we want personality actions, this is the personality index
  67. **/
  68. function getActionCount(uint256 _personality)
  69. external
  70. view
  71. returns (uint256 totalActions)
  72. {
  73. return actionLengths[_personality];
  74. }
  75.  
  76. /** ******************************* ONLY OWNER ***************************** **/
  77.  
  78. /**
  79. * @dev Used by the owner to create/edit a new action that kitties may learn.
  80. * @param _actionId The given ID of this action.
  81. * @param _newEnergy The amount of energy the action will cost.
  82. * @param _newPets The amount of base pets each owner will give to this action.
  83. * @param _petAdditions The amount of additional pets each owner will give.
  84. * @param _critChance The crit chance this move has against each owner.
  85. * @param _missChance The miss chance this move has against each owner.
  86. * @param _turnsAffected The amount of turns an effect, if any, will be applied.
  87. * @param _personality The type/personality this move is specific to (0 for any).
  88. **/
  89. function addAction(uint256 _actionId, uint256 _newEnergy, uint256[6] _newPets, uint8[6] _petAdditions,
  90. uint16[6] _critChance, uint16[6] _missChance, uint8 _turnsAffected, uint256 _personality)
  91. public
  92. onlyOwner
  93. {
  94. Action memory newAction = Action(_newEnergy, _newPets, _petAdditions, _critChance, _missChance, _turnsAffected);
  95. actions[_actionId] = newAction;
  96.  
  97. actionLengths[_personality]++;
  98. }
  99.  
  100. /**
  101. * @dev Same as add action but does not alter actionLengths.
  102. **/
  103. function editAction(uint256 _actionId, uint256 _newEnergy, uint256[6] _newPets, uint8[6] _petAdditions,
  104. uint16[6] _critChance, uint16[6] _missChance, uint8 _turnsAffected)
  105. public
  106. onlyOwner
  107. {
  108. Action memory newAction = Action(_newEnergy, _newPets, _petAdditions, _critChance, _missChance, _turnsAffected);
  109. actions[_actionId] = newAction;
  110. }
  111.  
  112. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement