Data_UserGame.php 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218
  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. $this->store()->fixArray();
  81. }
  82. }
  83. // <editor-fold defaultstate="collapsed" desc="实例方法">
  84. /**
  85. * 关卡数据
  86. * @param bool $save 是否需要回存
  87. * @return Info_Gates
  88. */
  89. public function gates($save = true) {
  90. $this->gates = new Info_Gates($this->gates);
  91. if ($save) {
  92. $this->save_tag("gates");
  93. }
  94. return $this->gates;
  95. }
  96. /**
  97. * 基础信息
  98. * @param bool $save 是否需要回存
  99. * @return Info_UserBase
  100. */
  101. public function base($save = true) {
  102. $this->baseInfo = new Info_UserBase($this->baseInfo);
  103. if ($save) {
  104. $this->save_tag("baseInfo");
  105. }
  106. return $this->baseInfo;
  107. }
  108. /**
  109. * 玩家仓库
  110. * @param bool $save 是否需要回存
  111. * @return Info_Store
  112. */
  113. public function store($save = true) {
  114. $this->store = new Info_Store($this->store);
  115. if ($save) {
  116. $this->save_tag("store");
  117. }
  118. return $this->store;
  119. }
  120. /**
  121. * 商店数据
  122. * @param bool $save 是否需要回存
  123. * @return Info_UserShop
  124. */
  125. public function shop($save = true) {
  126. $this->shopdata = new Info_UserShop($this->shopdata);
  127. if ($save) {
  128. $this->save_tag("shopdata");
  129. }
  130. return $this->shopdata;
  131. }
  132. /**
  133. * 神秘商店
  134. * @param bool $save 是否需要回存
  135. * @return Info_UserSecretshop
  136. */
  137. public function secretshop($save = true) {
  138. $this->userSecretshop = new Info_UserSecretshop($this->userSecretshop);
  139. if ($save) {
  140. $this->save_tag("userSecretshop");
  141. }
  142. return $this->userSecretshop;
  143. }
  144. /**
  145. * 英雄数据
  146. * @param bool $save 是否需要回存
  147. * @return Info_UserGameHero
  148. */
  149. public function heros($save = true) {
  150. $this->heros = new Info_Heros($this->heros);
  151. if ($save) {
  152. $this->save_tag("heros");
  153. }
  154. return $this->heros;
  155. }
  156. /**
  157. * 私有数据
  158. * @param bool $save 是否需要回存
  159. * @return Info_PrivateState
  160. */
  161. public function privateData($save = true) {
  162. $this->privateState = new Info_PrivateState($this->privateState);
  163. if ($save) {
  164. $this->save_tag("privateState");
  165. }
  166. return $this->privateState;
  167. }
  168. /**
  169. * 任务卡商店
  170. * @param bool $save 是否需要回存
  171. * @return Info_Task
  172. */
  173. public function task($save = true) {
  174. $this->task = new Info_Task($this->task);
  175. if ($save) {
  176. $this->save_tag("task");
  177. }
  178. return $this->task;
  179. }
  180. /**
  181. * 角色画像数据
  182. * @param bool $save 是否需要回存
  183. * @return Data_UserProfile
  184. */
  185. public function profile($save = true) {
  186. $this->profile = new Data_UserProfile($this->profile);
  187. if ($save) {
  188. $this->save_tag("profile");
  189. }
  190. return $this->profile;
  191. }
  192. //
  193. // </editor-fold>
  194. }