Info_UserBase.php 7.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289
  1. <?php
  2. namespace loyalsoft;
  3. /**
  4. * 玩家基本信息
  5. * @author gwang(wanggangzero@qq.com)
  6. */
  7. class Info_UserBase extends Object_ext {
  8. /**
  9. * 第一次登录时间
  10. * @var int
  11. */
  12. public $firstLogin;
  13. /**
  14. * 上次登录时间
  15. * @var int
  16. */
  17. public $lastLogin;
  18. /**
  19. * 上次活动时间
  20. * @var int
  21. */
  22. public $lastSaveTs;
  23. /**
  24. * @var int 当前等级
  25. */
  26. public $level;
  27. /**
  28. * @var string 昵称
  29. */
  30. public $name;
  31. /**
  32. * @var string 头像
  33. */
  34. public $headImg;
  35. /**
  36. * @var int 头像框Id
  37. */
  38. public $imgBorderId = 0;
  39. /**
  40. * @var string 形象(龙骨)
  41. */
  42. public $img;
  43. /**
  44. * @var int 金币
  45. */
  46. public $gold;
  47. /**
  48. * 钻石
  49. * @var int
  50. */
  51. public $cash;
  52. /**
  53. * 分解后得倒的晶石
  54. * @var int
  55. */
  56. public $spar;
  57. /**
  58. * 体力值
  59. * @var int
  60. */
  61. public $tili = 120;
  62. /**
  63. * 当前经验
  64. */
  65. public $xp = 0;
  66. /**
  67. * 升级经验
  68. * @var type
  69. */
  70. public $maxXp = 0;
  71. /**
  72. * @var int 好友赠送友情点数
  73. */
  74. public $friendPoint = 0;
  75. /**
  76. * @var int 历史充值总金额(单位:分)
  77. */
  78. public $charge_amt = 0;
  79. /**
  80. * @var int 游戏内赠送游戏币总额
  81. */
  82. public $gift_cash = 0;
  83. /**
  84. * 言灵等级消耗的资源点
  85. * @var type
  86. */
  87. public $resPoint = 0;
  88. /**
  89. * 充值功能充值记录
  90. * @var type
  91. */
  92. public $rechargeFun_amt = 0;
  93. public function initialize() {
  94. my_Assert(GameConfig::primordial_data(), "找不到账号初始化数据"); # 防御
  95. $this->gold = GameConfig::primordial_data()->User_Gold;
  96. $this->cash = GameConfig::primordial_data()->User_Cash;
  97. $this->xp = GameConfig::primordial_data()->User_XP;
  98. $this->maxXp = 0;
  99. $this->level = 1;
  100. $this->name = '步惊云';
  101. $this->spar = 0;
  102. $this->headImg = GameConfig::primordial_data()->User_head;
  103. $this->img = GameConfig::primordial_data()->User_img;
  104. }
  105. // <editor-fold defaultstate="collapsed" desc=" 方法 ">
  106. //
  107. /**
  108. * 增加资源点
  109. * @param int $amt
  110. */
  111. function Add_resPoint($amt) {
  112. my_Assert($amt >= 0, "参数为负");
  113. $this->resPoint += $amt;
  114. }
  115. /**
  116. * 扣除资源点
  117. * @param type $amt
  118. * @return boolean true:成功, false:资源点不足
  119. */
  120. function Consume_ResPoint($amt) {
  121. if ($amt > 0) {
  122. if ($this->resPoint - $amt >= 0) {
  123. $this->resPoint -= $amt;
  124. return true;
  125. }
  126. }
  127. return false;
  128. }
  129. /**
  130. * 给玩家增加体力
  131. * @param int $amt
  132. */
  133. function Add_tili($amt) {
  134. my_Assert($amt >= 0, "体力amt小于0");
  135. ActiveProc::ChangeTili($amt);
  136. }
  137. /**
  138. * 用户获得金币
  139. * @param int $amt
  140. */
  141. function Add_Gold($amt,$mask = 0) {
  142. my_Assert($amt >= 0, "参数为负");
  143. if($mask == 1){
  144. UserProc::CollectUserBaseParam(req()->cmd,2, $this->gold, $amt, $this->gold+$amt, "关卡战斗掉落金币");
  145. } else {
  146. UserProc::CollectUserBaseParam(req()->cmd,2, $this->gold, $amt, $this->gold+$amt, "获得金币");
  147. }
  148. $this->gold += $amt;
  149. }
  150. /**
  151. * 扣除玩家金币
  152. * @param int $amt
  153. * @return boolean true:成功, false:金币不足
  154. */
  155. function Consume_Gold($amt,$mask = 0) {
  156. if ($amt > 0) {
  157. if ($this->gold - $amt >= 0) {
  158. UserProc::CollectUserBaseParam(req()->cmd,2, $this->gold, $amt, $this->gold-$amt, "消耗金币");
  159. $this->gold -= $amt;
  160. return true;
  161. }
  162. }
  163. return false;
  164. }
  165. /**
  166. * 增加用户钻石
  167. * @param type $amt
  168. */
  169. function Add_Cash($amt,$mask = 0) {
  170. my_Assert($amt >= 0, "amt值为负");
  171. if($mask == 1){
  172. UserProc::CollectUserBaseParam(req()->cmd, 3, $this->cash, $amt, $this->cash+$amt,"关卡战斗掉落钻石");
  173. } else {
  174. UserProc::CollectUserBaseParam(req()->cmd, 3, $this->cash, $amt, $this->cash+$amt,"获得钻石");
  175. }
  176. $this->cash += $amt;
  177. }
  178. /**
  179. * 扣除玩家钻石
  180. * @param int $amt
  181. * @return bool 成功与否
  182. */
  183. function Consume_Cash($amt,$mask = 0) {
  184. if ($amt >= 0) {
  185. if ($this->cash - $amt >= 0) {
  186. UserProc::CollectUserBaseParam(req()->cmd, 3, $this->cash, $amt, $this->cash-$amt,"消耗钻石");
  187. $this->cash -= $amt;
  188. return true;
  189. }
  190. }
  191. return false;
  192. }
  193. /**
  194. * 增加用户友情点
  195. * @param type $amt
  196. */
  197. function Add_FriendPoint($amt) {
  198. my_Assert($amt >= 0, "amt值为负");
  199. $this->friendPoint += $amt; # 业务逻辑
  200. }
  201. /**
  202. * 扣除玩家友情点
  203. * @param int $amt
  204. */
  205. function Consume_FriendShipPoint($amt) {
  206. if ($amt > 0) {
  207. if ($this->friendPoint - $amt >= 0) {
  208. $this->friendPoint -= $amt;
  209. return true;
  210. }
  211. }
  212. return false;
  213. }
  214. /**
  215. * 用户获得经验值
  216. * @param int $amt
  217. */
  218. function Add_Exp($amt) {
  219. my_Assert($amt >= 0, "amt值为负");
  220. $cfgLVs = GameConfig::playerlevel();
  221. UserProc::CollectUserBaseParam(req()->cmd, 1, $this->xp, $amt, $this->xp+$amt, "获得经验");
  222. $this->xp += $amt;
  223. $initLevel = $curLevel = $this->level;
  224. $nextLevel = $curLevel + 1;
  225. while ($this->xp >= $cfgLVs->$nextLevel->xp_need) { # 超过升级所需经验
  226. if ($this->level < glc()->Game_MaxPlayerLevel) { # 如果未到达最大等级
  227. $this->level++;
  228. $this->xp -= $cfgLVs->$nextLevel->xp_need;
  229. $curLevel = $this->level;
  230. $nextLevel = $curLevel + 1;
  231. my_Assert(CommUtil::isPropertyExists($cfgLVs, $nextLevel), ErrCode::err_const_no); // "取英雄升级常量数据失败." . $nextLevel . "级");
  232. $this->maxXp = $cfgLVs->$nextLevel->xp_need;
  233. // StatProc::UserLevel($nowlv); # 等级统计
  234. } else { # 如果已到达最大等级则仅补齐缺失的经验即可
  235. $this->xp = $this->maxXp; # 经验不能超过最大值
  236. break;
  237. }
  238. }
  239. if ($this->level != $initLevel) { # 插入玩家升级的系统消息
  240. SystemProc::UserLevelUp(req()->zoneid, $this, $this->level);
  241. TaskProc::OnUserLevelUp($this->level); # 通知任务模块,这里应该有事件模块
  242. EventProc::OnUserLevelup($initLevel, $this->level); # 事件模块
  243. StatisticsProc::TargetStatistics(Enum_TargetStatistics::userlevel, $this->level,$initLevel);
  244. RankProc::recordPlayerLevelInfo(req()->uid, $this->level, req()->zoneid);
  245. }
  246. }
  247. //
  248. // </editor-fold>
  249. }