Info_UserBase.php 6.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272
  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 $tili = 120;
  57. /**
  58. * @var int 体力时间戳
  59. */
  60. public $tili_ts = 0;
  61. /**
  62. * 当前经验
  63. */
  64. public $xp = 0;
  65. /**
  66. * 升级经验
  67. * @var type
  68. */
  69. public $maxXp = 0;
  70. /**
  71. * @var int 历史充值总金额(单位:分)
  72. */
  73. public $charge_amt = 0;
  74. /**
  75. * 新解锁的头像框
  76. * @var type
  77. */
  78. #[ArrayType]
  79. public $headImgFrameList = array();
  80. /**
  81. * 片头动画
  82. * @var type
  83. */
  84. public $animation = 0;
  85. /**
  86. * 首充奖励是否领取过
  87. * @var type
  88. */
  89. public $fRechargePriceReceived = 0;
  90. public function initialize() {
  91. // my_Assert(GameConfig::primordial_data(), "找不到账号初始化数据"); # 防御
  92. $this->gold = 1000000;
  93. $this->cash = 5000;
  94. // $this->xp = GameConfig::primordial_data()->User_XP;
  95. $this->tili = GameConfig::globalsettings()->tili_RecoverrMax; # 恢复体力上限
  96. // $this->maxXp = 0;
  97. $this->level = 1;
  98. $this->name = '';
  99. $this->headImg = "";
  100. $this->img = "";
  101. }
  102. // <editor-fold defaultstate="collapsed" desc=" 方法 ">
  103. //
  104. /**
  105. * 给玩家增加体力
  106. * @param int $amt
  107. */
  108. function Add_tili($amt) {
  109. my_Assert($amt >= 0, "体力amt小于0");
  110. //ActiveProc::ChangeTili($amt);
  111. for ($i = 0; $i < $amt; $i++) {
  112. if ((now() - $this->tili_ts) / glc()->tili_RecoverTS < glc()->tili_RecoverrMax) {
  113. $this->tili_ts -= glc()->tili_RecoverTS;
  114. } else {
  115. $this->tili++;
  116. }
  117. }
  118. }
  119. /**
  120. * 检查并修改体力ts的最小值.
  121. */
  122. function Reset_tilits() {
  123. $min = now() - glc()->tili_RecoverTS * glc()->tili_RecoverrMax;
  124. if ($this->tili_ts < $min) {
  125. $this->tili_ts = $min;
  126. }
  127. }
  128. /**
  129. * 扣除玩家体力
  130. * @param int $amt
  131. * @return bool 成功与否
  132. */
  133. function Consume_tili($amt) {
  134. if ($amt >= 0) {
  135. $cpt = glc()->tili_RecoverTS;
  136. if ($this->tili > 0) {
  137. if ($this->tili - $amt >= 0) {
  138. $this->tili -= $amt;
  139. return true;
  140. } else {
  141. $amt -= $this->tili;
  142. $this->tili = 0;
  143. $this->tili_ts += $amt * $cpt;
  144. return true;
  145. }
  146. } else if ($this->tili_ts + $amt * $cpt < now()) {
  147. $this->tili_ts += $amt * $cpt;
  148. return true;
  149. }
  150. }
  151. return false;
  152. }
  153. /**
  154. * @return int 计算当前可用体力值
  155. */
  156. function CurTili() {
  157. $rec = (now() - $this->tili_ts) / glc()->tili_RecoverTS;
  158. $rec = glc()->tili_RecoverrMax < $rec ? glc()->tili_RecoverrMax : $rec;
  159. $t = $this->tili + $rec;
  160. return $t;
  161. }
  162. /**
  163. * 用户获得金币
  164. * @param int $amt
  165. */
  166. function Add_Gold($amt, $mask = 0) {
  167. my_Assert($amt >= 0, "参数为负");
  168. $this->gold += $amt;
  169. }
  170. /**
  171. * 扣除玩家金币
  172. * @param int $amt
  173. * @return boolean true:成功, false:金币不足
  174. */
  175. function Consume_Gold($amt) {
  176. if ($amt > 0) {
  177. if ($this->gold - $amt >= 0) {
  178. $this->gold -= $amt;
  179. return true;
  180. }
  181. }
  182. return false;
  183. }
  184. /**
  185. * 增加用户钻石
  186. * @param type $amt
  187. */
  188. function Add_Cash($amt) {
  189. my_Assert($amt >= 0, "amt值为负");
  190. $this->cash += $amt;
  191. }
  192. /**
  193. * 扣除玩家钻石
  194. * @param int $amt
  195. * @return bool 成功与否
  196. */
  197. function Consume_Cash($amt) {
  198. if ($amt >= 0) {
  199. if ($this->cash - $amt >= 0) {
  200. $this->cash -= $amt;
  201. return true;
  202. }
  203. }
  204. return false;
  205. }
  206. /**
  207. * 用户获得经验值
  208. * @param int $amt
  209. */
  210. function Add_Exp($amt) {
  211. // my_Assert($amt >= 0, "amt值为负");
  212. // $cfgLVs = GameConfig::playerlevel();
  213. //
  214. // $this->xp += $amt;
  215. // $initLevel = $curLevel = $this->level;
  216. // $nextLevel = $curLevel + 1;
  217. // while ($this->xp >= $cfgLVs->$nextLevel->xp_need) { # 超过升级所需经验
  218. // if ($this->level < glc()->Game_MaxPlayerLevel) { # 如果未到达最大等级
  219. // $this->level++;
  220. // $this->xp -= $cfgLVs->$nextLevel->xp_need;
  221. // $curLevel = $this->level;
  222. // $nextLevel = $curLevel + 1;
  223. // my_Assert(CommUtil::isPropertyExists($cfgLVs, $nextLevel), ErrCode::err_const_no); // "取英雄升级常量数据失败." . $nextLevel . "级");
  224. // $this->maxXp = $cfgLVs->$nextLevel->xp_need;
  225. //// StatProc::UserLevel($nowlv); # 等级统计
  226. // } else { # 如果已到达最大等级则仅补齐缺失的经验即可
  227. // $this->xp = $this->maxXp; # 经验不能超过最大值
  228. // break;
  229. // }
  230. // }
  231. // if ($this->level != $initLevel) { # 插入玩家升级的系统消息
  232. //
  233. // }
  234. }
  235. //
  236. // </editor-fold>
  237. }