Data_UserGame.php 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217
  1. <?php
  2. namespace loyalsoft;
  3. /**
  4. * Description of UserGameModel
  5. * 游戏数据
  6. * @author gwang (mail@wanggangzero.cn)
  7. */
  8. class Data_UserGame extends HashSaver {
  9. /**
  10. * @var Info_UserBase 基础数据
  11. */
  12. public $baseInfo;
  13. /**
  14. * 背包
  15. * @var Info_Store
  16. */
  17. public $store;
  18. /**
  19. * 关卡
  20. * @var Info_Gates
  21. */
  22. public $gates;
  23. /**
  24. * 关卡
  25. * @var Info_Heros
  26. */
  27. public $heros;
  28. /**
  29. * 私有信息
  30. * @var Info_PrivateState
  31. */
  32. public $privateState;
  33. /**
  34. * 任务
  35. * @var Info_Task
  36. */
  37. public $task;
  38. /**
  39. * @var string token
  40. */
  41. public $TK = "";
  42. public function RegenNewToken() {
  43. $arr = str_split(GameConstants::GetCipherString());
  44. shuffle($arr);
  45. $ntk = join('', array_slice($arr, 3, 8));
  46. $this->TK = $ntk;
  47. }
  48. /**
  49. * 用于给各个字段赋默认初始值
  50. * @return \UserGameModel
  51. */
  52. public function initialize() {
  53. //my_Assert(GameConfig::primordial_data(), "找不到账号初始化数据"); # 防御
  54. //$this->baseInfo = new Info_UserBase();
  55. $this->baseInfo->initialize();
  56. $this->store->initialize();
  57. $this->gates->initialize();
  58. $this->heros->initialize();
  59. $this->privateState->initialize();
  60. $this->task->initialize();
  61. }
  62. /**
  63. * 构造函数
  64. * @param type $arg
  65. */
  66. public function __construct($arg = null) {
  67. if (null === $arg) { # 未传参数的情况下
  68. $this->baseInfo = new Info_UserBase();
  69. $this->store = new Info_Store();
  70. $this->gates = new Info_Gates();
  71. $this->heros = new Info_Heros();
  72. $this->privateState = new Info_PrivateState();
  73. $this->task = new Info_Task();
  74. } else { # 实参
  75. parent::__construct($arg); # 调用Object的构造函数
  76. $this->base()->fixArray();
  77. $this->privateData()->fixArray();
  78. $this->gates()->fixArray();
  79. }
  80. }
  81. // <editor-fold defaultstate="collapsed" desc="实例方法">
  82. /**
  83. * 关卡数据
  84. * @param bool $save 是否需要回存
  85. * @return Info_UserGateDifficulty
  86. */
  87. public function gates($save = true) {
  88. $this->gates = new Info_Gates($this->gates);
  89. if ($save) {
  90. $this->save_tag("gates");
  91. }
  92. return $this->gates;
  93. }
  94. /**
  95. * 基础信息
  96. * @param bool $save 是否需要回存
  97. * @return Info_UserBase
  98. */
  99. public function base($save = true) {
  100. $this->baseInfo = new Info_UserBase($this->baseInfo);
  101. if ($save) {
  102. $this->save_tag("baseInfo");
  103. }
  104. return $this->baseInfo;
  105. }
  106. /**
  107. * 玩家仓库
  108. * @param bool $save 是否需要回存
  109. * @return Info_Store
  110. */
  111. public function store($save = true) {
  112. $this->store = new Info_Store($this->store);
  113. if ($save) {
  114. $this->save_tag("store");
  115. }
  116. return $this->store;
  117. }
  118. /**
  119. * 商店数据
  120. * @param bool $save 是否需要回存
  121. * @return Info_UserShop
  122. */
  123. public function shop($save = true) {
  124. $this->shopdata = new Info_UserShop($this->shopdata);
  125. if ($save) {
  126. $this->save_tag("shopdata");
  127. }
  128. return $this->shopdata;
  129. }
  130. /**
  131. * 神秘商店
  132. * @param bool $save 是否需要回存
  133. * @return Info_UserSecretshop
  134. */
  135. public function secretshop($save = true) {
  136. $this->userSecretshop = new Info_UserSecretshop($this->userSecretshop);
  137. if ($save) {
  138. $this->save_tag("userSecretshop");
  139. }
  140. return $this->userSecretshop;
  141. }
  142. /**
  143. * 英雄数据
  144. * @param bool $save 是否需要回存
  145. * @return Info_UserGameHero
  146. */
  147. public function heros($save = true) {
  148. $this->heros = new Info_Heros($this->heros);
  149. if ($save) {
  150. $this->save_tag("heros");
  151. }
  152. return $this->heros;
  153. }
  154. /**
  155. * 私有数据
  156. * @param bool $save 是否需要回存
  157. * @return Info_PrivateState
  158. */
  159. public function privateData($save = true) {
  160. $this->privateState = new Info_PrivateState($this->privateState);
  161. if ($save) {
  162. $this->save_tag("privateState");
  163. }
  164. return $this->privateState;
  165. }
  166. /**
  167. * 任务卡商店
  168. * @param bool $save 是否需要回存
  169. * @return Info_TaskCard_Shop
  170. */
  171. public function taskCard($save = true) {
  172. $this->task = new Info_Task($this->task);
  173. if ($save) {
  174. $this->save_tag("task");
  175. }
  176. return $this->task;
  177. }
  178. /**
  179. * 角色画像数据
  180. * @param bool $save 是否需要回存
  181. * @return Data_UserProfile
  182. */
  183. public function profile($save = true) {
  184. $this->profile = new Data_UserProfile($this->profile);
  185. if ($save) {
  186. $this->save_tag("profile");
  187. }
  188. return $this->profile;
  189. }
  190. //
  191. // </editor-fold>
  192. }