Data_UserGame.php 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370
  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 {}
  21. */
  22. public $shopdata;
  23. /**
  24. * 英雄
  25. * @var Info_UserGameHero
  26. */
  27. public $heros;
  28. /**
  29. * 私有字段
  30. * @var Info_PrivateState
  31. */
  32. public $privateState;
  33. /**
  34. * @var Info_UserSecretshop 玩家神秘商城数据
  35. */
  36. public $userSecretshop;
  37. /**
  38. * 关卡
  39. * @var Info_UserGateDifficulty
  40. */
  41. public $gates;
  42. /**
  43. * 地图解锁信息
  44. * @var Info_Map
  45. */
  46. public $map;
  47. // /**
  48. // * @var Info_UserTask 玩家任务数据
  49. // */
  50. // public $task;
  51. /**
  52. * 玩家任务卡商店数据
  53. * @var Info_TaskCard_Shop
  54. */
  55. public $taskCardShop;
  56. /**
  57. *
  58. * @var Info_UserPVP pvp信息
  59. */
  60. public $pvp;
  61. /**
  62. * 战斗队伍配置信息(使用时必须先json_decode)
  63. * @var dictionary
  64. */
  65. public $heroTeamConfig;
  66. /**
  67. * 新手引导
  68. * @var object
  69. */
  70. public $NewbieGuide;
  71. /**
  72. * 新手引导是否已经结束
  73. * @var type
  74. */
  75. public $NewbieGuideOver = 1;
  76. /**
  77. * @var Data_UserProfile 角色画像
  78. */
  79. public $profile;
  80. /**
  81. * 圣哲学院
  82. * @var Info_College
  83. */
  84. public $college;
  85. /**
  86. * 用于给各个字段赋默认初始值
  87. * @return \UserGameModel
  88. */
  89. public function initialize() {
  90. my_Assert(GameConfig::primordial_data(), "找不到账号初始化数据"); # 防御
  91. $this->baseInfo = new Info_UserBase();
  92. $this->baseInfo->initialize();
  93. # 添加默认战队设置
  94. $this->heroTeamConfig = JsonUtil::encode(GameConfig::primordial_data()->User_HeroTeamConfig);
  95. $this->store->initialize(); # 添加默认物品
  96. $this->privateState->currentId = count((array) $this->store->equipment) + 1;
  97. $this->heros->InitializeHero(); # 添加初始英雄
  98. $this->pvp = new Info_UserPVP();
  99. // $this->task->initialize(); # 任务初始化
  100. $this->taskCardShop = new Info_TaskCard_Shop();
  101. $this->college->initialize();
  102. }
  103. /**
  104. * 构造函数
  105. * @param type $arg
  106. */
  107. public function __construct($arg = null) {
  108. if (null === $arg) { # 未传参数的情况下
  109. $this->shopdata = ObjectInit(); # 商城数据
  110. $this->privateState = new Info_PrivateState(); # 私有字段
  111. $this->privateState->initialize(); # 初始化默认数据
  112. $this->store = new Info_Store(); # 背包数据
  113. // $this->store->initialize(); # 添加默认物品
  114. $this->heros = new Info_UserGameHero(); # 英雄数据
  115. // $this->heros->InitializeHero(); # 添加初始英雄
  116. $this->gates = new Info_UserGateDifficulty(); # 初始化关卡默认数据
  117. $this->map = new Info_Map(); # 初始化地图解锁数据
  118. // $this->heroManual = new HeroManualModel(); # 初始化图鉴数据结构
  119. $this->NewbieGuide = ObjectInit(); # 初始化新手引导结构
  120. // $this->pvp = new UserPVPModel(); # 初始化pvp模块
  121. $this->userSecretshop = new Info_UserSecretshop(); # 神秘商店
  122. // $this->task = new Info_UserTask(); # 任务数据
  123. $this->taskCardShop = new Info_TaskCard_Shop(); # 任务卡商店
  124. $this->college = new Info_College();
  125. } else { # 实参
  126. parent::__construct($arg); # 调用Object的构造函数
  127. // $this->shopdata = new Info_UserShop($this->shopdata);
  128. //// $this->NewbieGuide= new info_us
  129. // $this->baseInfo = new Info_UserBase($this->baseInfo);
  130. // $this->gates = new Info_UserGateDifficulty($this->gates);
  131. // $this->heros = new Info_UserGameHero($this->heros);
  132. // $this->privateState = new Info_PrivateState($this->privateState);
  133. //// $this->profile = n
  134. // $this->pvp = new Info_UserPVP($this->pvp);
  135. // $this->store = new Info_Store($this->store);
  136. // $this->taskCardShop = new Info_TaskCard_Shop($this->taskCardShop);
  137. // $this->userSecretshop = new Info_UserSecretshop($this->userSecretshop);
  138. }
  139. $this->profile = new Data_UserProfile(); # 初始化用户画像模块
  140. }
  141. // <editor-fold defaultstate="collapsed" desc=" functions ">
  142. /**
  143. * 设置钻石数
  144. * @param Data_UserGame $user
  145. * @param int $amt 数量
  146. */
  147. static public function set_Cash($user, $amt) {
  148. my_Assert($amt >= 0, "数量小于0");
  149. my_Assert($user, "user为空");
  150. my_Assert(isset($user->cash), "找不到cash字段");
  151. $user->cash = $amt; # 实际逻辑
  152. }
  153. /**
  154. * 扣除玩家晶石
  155. * @param Data_UserGame $user
  156. * @param int $amt
  157. */
  158. static public function Consume_Spar($user, $amt) {
  159. if ($amt > 0 && isset($user) && isset($user->spar)) {
  160. if ($user->spar - $amt >= 0) {
  161. $user->spar -= $amt;
  162. return true;
  163. }
  164. }
  165. return false;
  166. }
  167. /**
  168. * 扣除玩家钻石
  169. * @param Info_UserBase $user
  170. * @param int $amt
  171. * @return bool 成功与否
  172. */
  173. static public function Consume_Cash($user, $amt) {
  174. if ($amt >= 0 && isset($user) && isset($user->cash)) {
  175. if ($user->cash - $amt >= 0) {
  176. $user->cash -= $amt;
  177. return true;
  178. }
  179. }
  180. return false;
  181. }
  182. /**
  183. * 扣除玩家金币
  184. * @param Info_UserBase $user
  185. * @param int $amt
  186. * @return boolean true:成功, false:金币不足
  187. */
  188. static public function Consume_Gold($user, $amt) {
  189. if ($amt > 0 && isset($user) && isset($user->gold)) {
  190. if ($user->gold - $amt >= 0) {
  191. $user->gold -= $amt;
  192. return true;
  193. }
  194. }
  195. return false;
  196. }
  197. /**
  198. * 扣除资源点
  199. * @param Info_UserBase $user
  200. * @param type $amt
  201. * @return boolean true:成功, false:资源点不足
  202. */
  203. static public function Consume_ResPoint($user, $amt) {
  204. if ($amt > 0 && isset($user) && isset($user->resPoint)) {
  205. if ($user->resPoint - $amt >= 0) {
  206. $user->resPoint -= $amt;
  207. return true;
  208. }
  209. }
  210. return false;
  211. }
  212. /**
  213. * 扣除玩家友情点
  214. * @param Info_UserBase $user
  215. * @param int $amt
  216. */
  217. static public function Consume_FriendShipPoint($user, $amt) {
  218. if ($amt > 0 && isset($user) && isset($user->friendPoint)) {
  219. if ($user->friendPoint - $amt >= 0) {
  220. $user->friendPoint -= $amt;
  221. return true;
  222. }
  223. }
  224. return false;
  225. }
  226. /**
  227. * 扣除玩家碎片
  228. * @param Data_UserGame $user
  229. * @param int $segmentId 碎片ID
  230. * @param int $amt 数量
  231. * @return boolean true 成功, false 失败
  232. */
  233. static public function Consume_HeroSegment($user, $segmentId, $amt) {
  234. if ($amt > 0 && isset($user)) {
  235. if (CommUtil::isPropertyExists($user->store->items, $segmentId)) {
  236. if ($user->store->items->$segmentId - $amt >= 0) {
  237. $user->store->items->$segmentId -= $amt;
  238. return true;
  239. }
  240. }
  241. }
  242. return false;
  243. }
  244. /**
  245. * 增加用户钻石
  246. * @param Info_UserBase $user
  247. * @param type $amt
  248. * @return type
  249. */
  250. static function Add_Cash($user, $amt) {
  251. my_Assert($user, "user为空");
  252. my_Assert($amt >= 0, "amt值为负");
  253. $user->cash += $amt;
  254. }
  255. /**
  256. * 增加用户友情点
  257. * @param Info_UserBase $user
  258. * @param type $amt
  259. * @return type
  260. */
  261. static function Add_FriendPoint($user, $amt) {
  262. my_Assert($user, "user为空");
  263. my_Assert($amt >= 0, "amt值为负");
  264. $user->friendPoint += $amt; # 业务逻辑
  265. }
  266. /**
  267. * 用户获得经验值
  268. * @param Info_UserBase $user Description
  269. * @param int $amt
  270. */
  271. static function Add_Exp($user, $amt) {
  272. my_Assert($user, "user为空");
  273. my_Assert($amt >= 0, "amt值为负");
  274. $cfgLVs = GameConfig::playerlevel();
  275. $user->xp += $amt;
  276. $initLevel = $curLevel = $user->level;
  277. $nextLevel = $curLevel + 1;
  278. while ($user->xp >= $cfgLVs->$nextLevel->xp_need) { # 超过升级所需经验
  279. if ($user->level < glc()->Game_MaxPlayerLevel) { # 如果未到达最大等级
  280. $user->level++;
  281. $user->xp -= $cfgLVs->$nextLevel->xp_need;
  282. $curLevel = $user->level;
  283. $nextLevel = $curLevel + 1;
  284. my_Assert(CommUtil::isPropertyExists($cfgLVs, $nextLevel), ErrCode::err_const_no); // "取英雄升级常量数据失败." . $nextLevel . "级");
  285. $user->maxXp = $cfgLVs->$nextLevel->xp_need;
  286. // StatProc::UserLevel($nowlv); // 等级统计
  287. // todo:: 发发宝箱奖励, 如果有的话
  288. } else { // 如果已到达最大等级则仅补齐缺失的经验即可
  289. $user->xp = $user->maxXp; # 经验不能超过最大值
  290. break;
  291. }
  292. }
  293. if ($user->level != $initLevel) { # 插入玩家升级的系统消息
  294. SystemProc::UserLevelUp(req()->zoneid, $user, $user->level);
  295. TaskProc::OnUserLevelUp($user->level); # 通知任务模块,这里应该有事件模块
  296. EventProc::OnUserLevelup($initLevel, $user->level); # 事件模块
  297. }
  298. }
  299. /**
  300. * 用户获得金币
  301. * @param Info_UserBase $user 玩家数据
  302. * @param int $amt
  303. */
  304. static function Add_Gold(&$user, $amt) {
  305. my_Assert($user, "参数null");
  306. my_Assert($amt >= 0, "参数为负");
  307. $user->gold += $amt;
  308. }
  309. /**
  310. * 给玩家增加体力
  311. * @param int $amt
  312. * @return type
  313. */
  314. static function Add_tili($amt) {
  315. $user = req()->userInfo->game;
  316. my_Assert($user, "user为空");
  317. my_Assert($amt >= 0, "体力amt小于0");
  318. ActiveProc::ChangeTili($amt);
  319. }
  320. /**
  321. * 增加资源点
  322. * @param Info_UserBase $user
  323. * @param type $amt
  324. */
  325. static function Add_resPoint(&$user, $amt) {
  326. my_Assert($user, "参数null");
  327. my_Assert($amt >= 0, "参数为负");
  328. $user->resPoint += $amt;
  329. }
  330. // </editor-fold>
  331. // <editor-fold defaultstate="collapsed" desc="私有方法">
  332. //
  333. // </editor-fold>
  334. }