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. $this->save_tag("TK"); # 标记回存
  48. }
  49. /**
  50. * 用于给各个字段赋默认初始值
  51. * @return \UserGameModel
  52. */
  53. public function initialize() {
  54. $this->base(true)->initialize();
  55. $this->store(true)->initialize();
  56. $this->gates(true)->initialize();
  57. $this->heros(true)->initialize();
  58. $this->privateData(true)->initialize();
  59. $this->task(true)->initialize();
  60. }
  61. /**
  62. * 构造函数
  63. * @param type $arg
  64. */
  65. public function __construct($arg = null) {
  66. if (null === $arg) { # 未传参数的情况下
  67. $this->baseInfo = new Info_UserBase();
  68. $this->store = new Info_Store();
  69. $this->gates = new Info_Gates();
  70. $this->heros = new Info_Heros();
  71. $this->privateState = new Info_PrivateState();
  72. $this->task = new Info_Task();
  73. } else { # 实参
  74. parent::__construct($arg); # 调用Object的构造函数
  75. $this->base()->fixArray();
  76. $this->privateData()->fixArray();
  77. $this->gates()->fixArray();
  78. $this->heros()->fixArray();
  79. $this->task()->fixArray();
  80. }
  81. }
  82. // <editor-fold defaultstate="collapsed" desc="实例方法">
  83. /**
  84. * 关卡数据
  85. * @param bool $save 是否需要回存
  86. * @return Info_Gates
  87. */
  88. public function gates($save = true) {
  89. $this->gates = new Info_Gates($this->gates);
  90. if ($save) {
  91. $this->save_tag("gates");
  92. }
  93. return $this->gates;
  94. }
  95. /**
  96. * 基础信息
  97. * @param bool $save 是否需要回存
  98. * @return Info_UserBase
  99. */
  100. public function base($save = true) {
  101. $this->baseInfo = new Info_UserBase($this->baseInfo);
  102. if ($save) {
  103. $this->save_tag("baseInfo");
  104. }
  105. return $this->baseInfo;
  106. }
  107. /**
  108. * 玩家仓库
  109. * @param bool $save 是否需要回存
  110. * @return Info_Store
  111. */
  112. public function store($save = true) {
  113. $this->store = new Info_Store($this->store);
  114. if ($save) {
  115. $this->save_tag("store");
  116. }
  117. return $this->store;
  118. }
  119. /**
  120. * 商店数据
  121. * @param bool $save 是否需要回存
  122. * @return Info_UserShop
  123. */
  124. public function shop($save = true) {
  125. $this->shopdata = new Info_UserShop($this->shopdata);
  126. if ($save) {
  127. $this->save_tag("shopdata");
  128. }
  129. return $this->shopdata;
  130. }
  131. /**
  132. * 神秘商店
  133. * @param bool $save 是否需要回存
  134. * @return Info_UserSecretshop
  135. */
  136. public function secretshop($save = true) {
  137. $this->userSecretshop = new Info_UserSecretshop($this->userSecretshop);
  138. if ($save) {
  139. $this->save_tag("userSecretshop");
  140. }
  141. return $this->userSecretshop;
  142. }
  143. /**
  144. * 英雄数据
  145. * @param bool $save 是否需要回存
  146. * @return Info_UserGameHero
  147. */
  148. public function heros($save = true) {
  149. $this->heros = new Info_Heros($this->heros);
  150. if ($save) {
  151. $this->save_tag("heros");
  152. }
  153. return $this->heros;
  154. }
  155. /**
  156. * 私有数据
  157. * @param bool $save 是否需要回存
  158. * @return Info_PrivateState
  159. */
  160. public function privateData($save = true) {
  161. $this->privateState = new Info_PrivateState($this->privateState);
  162. if ($save) {
  163. $this->save_tag("privateState");
  164. }
  165. return $this->privateState;
  166. }
  167. /**
  168. * 任务卡商店
  169. * @param bool $save 是否需要回存
  170. * @return Info_Task
  171. */
  172. public function task($save = true) {
  173. $this->task = new Info_Task($this->task);
  174. if ($save) {
  175. $this->save_tag("task");
  176. }
  177. return $this->task;
  178. }
  179. /**
  180. * 角色画像数据
  181. * @param bool $save 是否需要回存
  182. * @return Data_UserProfile
  183. */
  184. public function profile($save = true) {
  185. $this->profile = new Data_UserProfile($this->profile);
  186. if ($save) {
  187. $this->save_tag("profile");
  188. }
  189. return $this->profile;
  190. }
  191. //
  192. // </editor-fold>
  193. }