Info_UserBase.php 6.4 KB

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