Info_UserBase.php 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255
  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. public function initialize() {
  86. // my_Assert(GameConfig::primordial_data(), "找不到账号初始化数据"); # 防御
  87. $this->gold = 1000000;
  88. $this->cash = 5000;
  89. // $this->xp = GameConfig::primordial_data()->User_XP;
  90. $this->tili = GameConfig::globalsettings()->tili_RecoverrMax; # 恢复体力上限
  91. // $this->maxXp = 0;
  92. $this->level = 1;
  93. $this->name = '';
  94. $this->headImg = "";
  95. $this->img = "";
  96. }
  97. // <editor-fold defaultstate="collapsed" desc=" 方法 ">
  98. //
  99. /**
  100. * 给玩家增加体力
  101. * @param int $amt
  102. */
  103. function Add_tili($amt) {
  104. my_Assert($amt >= 0, "体力amt小于0");
  105. //ActiveProc::ChangeTili($amt);
  106. for ($i = 0; $i < $amt; $i++) {
  107. if ((now() - $this->tili_ts) / glc()->tili_RecoverTS < glc()->tili_RecoverrMax) {
  108. $this->tili_ts -= glc()->tili_RecoverTS;
  109. } else {
  110. $this->tili++;
  111. }
  112. }
  113. }
  114. /**
  115. * 扣除玩家体力
  116. * @param int $amt
  117. * @return bool 成功与否
  118. */
  119. function Consume_tili($amt) {
  120. if ($amt >= 0) {
  121. $cpt = glc()->tili_RecoverTS;
  122. if ($this->tili > 0) {
  123. if ($this->tili - $amt >= 0) {
  124. $this->tili -= $amt;
  125. return true;
  126. } else {
  127. $amt -= $this->tili;
  128. $this->tili = 0;
  129. $this->tili_ts += $amt * $cpt;
  130. return true;
  131. }
  132. } else if ($this->tili_ts + $amt * $cpt < now()) {
  133. $this->tili_ts += $amt * $cpt;
  134. return true;
  135. }
  136. }
  137. return false;
  138. }
  139. /**
  140. * @return int 计算当前可用体力值
  141. */
  142. function CurTili() {
  143. $rec = (now() - $this->tili_ts) / glc()->tili_RecoverTS;
  144. $t = $this->tili + $rec;
  145. return $t;
  146. }
  147. /**
  148. * 用户获得金币
  149. * @param int $amt
  150. */
  151. function Add_Gold($amt, $mask = 0) {
  152. my_Assert($amt >= 0, "参数为负");
  153. $this->gold += $amt;
  154. }
  155. /**
  156. * 扣除玩家金币
  157. * @param int $amt
  158. * @return boolean true:成功, false:金币不足
  159. */
  160. function Consume_Gold($amt) {
  161. if ($amt > 0) {
  162. if ($this->gold - $amt >= 0) {
  163. $this->gold -= $amt;
  164. return true;
  165. }
  166. }
  167. return false;
  168. }
  169. /**
  170. * 增加用户钻石
  171. * @param type $amt
  172. */
  173. function Add_Cash($amt) {
  174. my_Assert($amt >= 0, "amt值为负");
  175. $this->cash += $amt;
  176. }
  177. /**
  178. * 扣除玩家钻石
  179. * @param int $amt
  180. * @return bool 成功与否
  181. */
  182. function Consume_Cash($amt) {
  183. if ($amt >= 0) {
  184. if ($this->cash - $amt >= 0) {
  185. $this->cash -= $amt;
  186. return true;
  187. }
  188. }
  189. return false;
  190. }
  191. /**
  192. * 用户获得经验值
  193. * @param int $amt
  194. */
  195. function Add_Exp($amt) {
  196. // my_Assert($amt >= 0, "amt值为负");
  197. // $cfgLVs = GameConfig::playerlevel();
  198. //
  199. // $this->xp += $amt;
  200. // $initLevel = $curLevel = $this->level;
  201. // $nextLevel = $curLevel + 1;
  202. // while ($this->xp >= $cfgLVs->$nextLevel->xp_need) { # 超过升级所需经验
  203. // if ($this->level < glc()->Game_MaxPlayerLevel) { # 如果未到达最大等级
  204. // $this->level++;
  205. // $this->xp -= $cfgLVs->$nextLevel->xp_need;
  206. // $curLevel = $this->level;
  207. // $nextLevel = $curLevel + 1;
  208. // my_Assert(CommUtil::isPropertyExists($cfgLVs, $nextLevel), ErrCode::err_const_no); // "取英雄升级常量数据失败." . $nextLevel . "级");
  209. // $this->maxXp = $cfgLVs->$nextLevel->xp_need;
  210. //// StatProc::UserLevel($nowlv); # 等级统计
  211. // } else { # 如果已到达最大等级则仅补齐缺失的经验即可
  212. // $this->xp = $this->maxXp; # 经验不能超过最大值
  213. // break;
  214. // }
  215. // }
  216. // if ($this->level != $initLevel) { # 插入玩家升级的系统消息
  217. //
  218. // }
  219. }
  220. //
  221. // </editor-fold>
  222. }