Info_UserBase.php 6.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281
  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. /**
  91. * 洗练石
  92. * @var type
  93. */
  94. public $xilianStone = 0;
  95. public function initialize() {
  96. // my_Assert(GameConfig::primordial_data(), "找不到账号初始化数据"); # 防御
  97. $this->gold = 1000000;
  98. $this->cash = 5000;
  99. // $this->xp = GameConfig::primordial_data()->User_XP;
  100. $this->tili = GameConfig::globalsettings()->tili_RecoverrMax; # 恢复体力上限
  101. // $this->maxXp = 0;
  102. $this->level = 1;
  103. $this->name = '';
  104. $this->img = "";
  105. $heroMo = GameConfig::hero_getItem(1);
  106. $this->headImg = $heroMo->img;
  107. }
  108. // <editor-fold defaultstate="collapsed" desc=" 方法 ">
  109. //
  110. /**
  111. * 给玩家增加体力
  112. * @param int $amt
  113. */
  114. function Add_tili($amt) {
  115. my_Assert($amt >= 0, "体力amt小于0");
  116. //ActiveProc::ChangeTili($amt);
  117. TaskProc::OnAccumulateTiliNum($amt);
  118. for ($i = 0; $i < $amt; $i++) {
  119. if ((now() - $this->tili_ts) / glc()->tili_RecoverTS < glc()->tili_RecoverrMax) {
  120. $this->tili_ts -= glc()->tili_RecoverTS;
  121. } else {
  122. $this->tili++;
  123. }
  124. }
  125. }
  126. /**
  127. * 检查并修改体力ts的最小值.
  128. */
  129. function Reset_tilits() {
  130. $min = now() - glc()->tili_RecoverTS * glc()->tili_RecoverrMax;
  131. if ($this->tili_ts < $min) {
  132. $this->tili_ts = $min;
  133. }
  134. }
  135. /**
  136. * 扣除玩家体力
  137. * @param int $amt
  138. * @return bool 成功与否
  139. */
  140. function Consume_tili($amt) {
  141. if ($amt >= 0) {
  142. $cpt = glc()->tili_RecoverTS;
  143. if ($this->tili > 0) {
  144. if ($this->tili - $amt >= 0) {
  145. $this->tili -= $amt;
  146. return true;
  147. } else {
  148. $amt -= $this->tili;
  149. $this->tili = 0;
  150. $this->tili_ts += $amt * $cpt;
  151. return true;
  152. }
  153. } else if ($this->tili_ts + $amt * $cpt < now()) {
  154. $this->tili_ts += $amt * $cpt;
  155. return true;
  156. }
  157. }
  158. return false;
  159. }
  160. /**
  161. * @return int 计算当前可用体力值
  162. */
  163. function CurTili() {
  164. $rec = (now() - $this->tili_ts) / glc()->tili_RecoverTS;
  165. $rec = glc()->tili_RecoverrMax < $rec ? glc()->tili_RecoverrMax : $rec;
  166. $t = $this->tili + $rec;
  167. return $t;
  168. }
  169. /**
  170. * 用户获得金币
  171. * @param int $amt
  172. */
  173. function Add_Gold($amt, $mask = 0) {
  174. my_Assert($amt >= 0, "参数为负");
  175. TaskProc::OnAccumulateGoldNum($amt);
  176. $this->gold += $amt;
  177. }
  178. /**
  179. * 扣除玩家金币
  180. * @param int $amt
  181. * @return boolean true:成功, false:金币不足
  182. */
  183. function Consume_Gold($amt) {
  184. if ($amt > 0) {
  185. if ($this->gold - $amt >= 0) {
  186. $this->gold -= $amt;
  187. return true;
  188. }
  189. }
  190. return false;
  191. }
  192. /**
  193. * 增加用户钻石
  194. * @param type $amt
  195. */
  196. function Add_Cash($amt) {
  197. my_Assert($amt >= 0, "amt值为负");
  198. $this->cash += $amt;
  199. }
  200. /**
  201. * 扣除玩家钻石
  202. * @param int $amt
  203. * @return bool 成功与否
  204. */
  205. function Consume_Cash($amt) {
  206. if ($amt >= 0) {
  207. if ($this->cash - $amt >= 0) {
  208. $this->cash -= $amt;
  209. return true;
  210. }
  211. }
  212. TaskProc::OnConsumeCashNum($amt);
  213. return false;
  214. }
  215. /**
  216. * 用户获得经验值
  217. * @param int $amt
  218. */
  219. function Add_Exp($amt) {
  220. my_Assert($amt >= 0, "amt值为负");
  221. $cfgLVs = GameConfig::player_level();
  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. }
  240. //
  241. // </editor-fold>
  242. }