Data_UserGame.php 9.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334
  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_UserShop
  21. */
  22. public $shopdata;
  23. /**
  24. * @var Info_UserSecretshop 玩家神秘商城数据
  25. */
  26. public $userSecretshop;
  27. /**
  28. * 英雄
  29. * @var Info_UserGameHero
  30. */
  31. public $heros;
  32. /**
  33. * 私有字段
  34. * @var Info_PrivateState
  35. */
  36. public $privateState;
  37. /**
  38. * 关卡
  39. * @var Info_UserGateDifficulty
  40. */
  41. public $gates;
  42. /**
  43. * 新版地图信息v2022.3
  44. * @var Info_NewMap
  45. */
  46. public $newMap;
  47. /**
  48. * 玩家任务卡商店数据
  49. * @var Info_TaskCard_Shop
  50. */
  51. public $taskCardShop;
  52. /**
  53. *
  54. * @var Info_UserPVP pvp信息
  55. */
  56. public $pvp;
  57. /**
  58. * 战斗队伍配置信息(使用时必须先json_decode)
  59. * @var dictionary
  60. */
  61. public $heroTeamConfig;
  62. /**
  63. * 新手引导
  64. * @var object
  65. */
  66. public $NewbieGuide;
  67. /**
  68. * @var Data_UserProfile 角色画像
  69. */
  70. public $profile;
  71. /**
  72. *
  73. * @var Info_Pay
  74. */
  75. public $pay;
  76. /**
  77. * @var string token
  78. */
  79. public $TK = "";
  80. public function RegenNewToken() {
  81. $arr = str_split(GameConstants::GetCipherString());
  82. shuffle($arr);
  83. $ntk = join('', array_slice($arr, 3, 8));
  84. $this->TK = $ntk;
  85. }
  86. /**
  87. * 用于给各个字段赋默认初始值
  88. * @return \UserGameModel
  89. */
  90. public function initialize() {
  91. my_Assert(GameConfig::primordial_data(), "找不到账号初始化数据"); # 防御
  92. $this->baseInfo = new Info_UserBase();
  93. $this->baseInfo->initialize();
  94. # 添加默认战队设置
  95. $this->heroTeamConfig = GameConfig::primordial_data()->User_HeroTeamConfig;
  96. $this->store->initialize(); # 添加默认物品
  97. $this->privateState->currentId = count((array) $this->store->equipment) + 1;
  98. $this->heros->InitializeHero(); # 添加初始英雄
  99. $this->pvp = new Info_UserPVP();
  100. // $this->task->initialize(); # 任务初始化
  101. $this->taskCardShop = new Info_TaskCard_Shop();
  102. //$this->college->initialize();//改为按天解锁了
  103. }
  104. /**
  105. * 构造函数
  106. * @param type $arg
  107. */
  108. public function __construct($arg = null) {
  109. if (null === $arg) { # 未传参数的情况下
  110. $this->shopdata = ObjectInit(); # 商城数据
  111. $this->privateState = new Info_PrivateState(); # 私有字段
  112. $this->privateState->initialize(); # 初始化默认数据
  113. $this->store = new Info_Store(); # 背包数据
  114. // $this->store->initialize(); # 添加默认物品
  115. $this->heros = new Info_UserGameHero(); # 英雄数据
  116. // $this->heros->InitializeHero(); # 添加初始英雄
  117. $this->gates = new Info_UserGateDifficulty(); # 初始化关卡默认数据
  118. $this->newMap = new Info_NewMap(); # 初始化改版地图2022.3
  119. $this->NewbieGuide = new Info_NewbieGuide(); # 初始化新手引导结构
  120. $this->userSecretshop = new Info_UserSecretshop(); # 神秘商店
  121. $this->taskCardShop = new Info_TaskCard_Shop(); # 任务卡商店
  122. $this->pay = new Info_Pay();
  123. $this->profile = new Data_UserProfile(); # 初始化用户画像模块
  124. } else { # 实参
  125. parent::__construct($arg); # 调用Object的构造函数
  126. $this->base()->fixArray();
  127. $this->privateData()->fixArray();
  128. $this->taskCardShop()->fixArray();
  129. $this->college()->fixArray();
  130. $this->store()->fixArray();
  131. // echoLine($this->shop());
  132. $this->shop()->fixArray();
  133. // echoLine($this->shop());
  134. }
  135. }
  136. // <editor-fold defaultstate="collapsed" desc="实例方法">
  137. /**
  138. * 基础信息
  139. * @param bool $save 是否需要回存
  140. * @return Info_UserBase
  141. */
  142. public function base($save = true) {
  143. $this->baseInfo = new Info_UserBase($this->baseInfo);
  144. if ($save) {
  145. self::save_tag("baseInfo");
  146. }
  147. return $this->baseInfo;
  148. }
  149. /**
  150. * 玩家仓库
  151. * @param bool $save 是否需要回存
  152. * @return Info_Store
  153. */
  154. public function store($save = true) {
  155. $this->store = new Info_Store($this->store);
  156. if ($save) {
  157. self::save_tag("store");
  158. }
  159. return $this->store;
  160. }
  161. /**
  162. * 商店数据
  163. * @param bool $save 是否需要回存
  164. * @return Info_UserShop
  165. */
  166. public function shop($save = true) {
  167. $this->shopdata = new Info_UserShop($this->shopdata);
  168. if ($save) {
  169. self::save_tag("shopdata");
  170. }
  171. return $this->shopdata;
  172. }
  173. /**
  174. * 神秘商店
  175. * @param bool $save 是否需要回存
  176. * @return Info_UserSecretshop
  177. */
  178. public function secretshop($save = true) {
  179. $this->userSecretshop = new Info_UserSecretshop($this->userSecretshop);
  180. if ($save) {
  181. self::save_tag("userSecretshop");
  182. }
  183. return $this->userSecretshop;
  184. }
  185. /**
  186. * 英雄数据
  187. * @param bool $save 是否需要回存
  188. * @return Info_UserGameHero
  189. */
  190. public function heros($save = true) {
  191. $this->heros = new Info_UserGameHero($this->heros);
  192. if ($save) {
  193. self::save_tag("heros");
  194. }
  195. return $this->heros;
  196. }
  197. /**
  198. * 私有数据
  199. * @param bool $save 是否需要回存
  200. * @return Info_PrivateState
  201. */
  202. public function privateData($save = true) {
  203. $this->privateState = new Info_PrivateState($this->privateState);
  204. if ($save) {
  205. self::save_tag("privateState");
  206. }
  207. return $this->privateState;
  208. }
  209. /**
  210. * 关卡数据
  211. * @param bool $save 是否需要回存
  212. * @return Info_UserGateDifficulty
  213. */
  214. public function gates($save = true) {
  215. $this->gates = new Info_UserGateDifficulty($this->gates);
  216. if ($save) {
  217. self::save_tag("gates");
  218. }
  219. return $this->gates;
  220. }
  221. /**
  222. * 新地图数据
  223. * @param bool $save 是否需要回存
  224. * @return Info_NewMap
  225. */
  226. public function newMap($save = true) {
  227. $this->newMap = new Info_NewMap($this->newMap);
  228. if ($save) {
  229. self::save_tag(__FUNCTION__);
  230. }
  231. return $this->newMap;
  232. }
  233. /**
  234. * 任务卡商店
  235. * @param bool $save 是否需要回存
  236. * @return Info_TaskCard_Shop
  237. */
  238. public function taskCardShop($save = true) {
  239. $this->taskCardShop = new Info_TaskCard_Shop($this->taskCardShop);
  240. if ($save) {
  241. self::save_tag("taskCardShop");
  242. }
  243. return $this->taskCardShop;
  244. }
  245. /**
  246. * pvp数据
  247. * @param bool $save 是否需要回存
  248. * @return Info_UserPVP
  249. */
  250. public function pvp($save = true) {
  251. $this->pvp = new Info_UserPVP($this->pvp);
  252. if ($save) {
  253. self::save_tag("pvp");
  254. }
  255. return $this->pvp;
  256. }
  257. /**
  258. * 角色画像数据
  259. * @param bool $save 是否需要回存
  260. * @return Data_UserProfile
  261. */
  262. public function profile($save = true) {
  263. $this->profile = new Data_UserProfile($this->profile);
  264. if ($save) {
  265. self::save_tag("profile");
  266. }
  267. return $this->profile;
  268. }
  269. /**
  270. * 新手引导
  271. * @param bool $save 是否需要回存
  272. * @return Info_NewbieGuide
  273. */
  274. public function newbieGuide($save = true) {
  275. $this->NewbieGuide = new Info_NewbieGuide($this->NewbieGuide);
  276. if ($save) {
  277. self::save_tag("NewbieGuide");
  278. }
  279. return $this->NewbieGuide;
  280. }
  281. /**
  282. * 战队配置
  283. * @param bool $save 是否需要回存
  284. * @return Info_NewbieGuide
  285. */
  286. public function &teamConfig($save = true) {
  287. // $this->NewbieGuide = new Info_NewbieGuide($this->NewbieGuide);
  288. if ($save) {
  289. self::save_tag("heroTeamConfig");
  290. }
  291. return $this->heroTeamConfig;
  292. }
  293. //
  294. // </editor-fold>
  295. }