Info_UserBase.php 6.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280
  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. TaskProc::OnAccumulateTiliNum($amt);
  117. for ($i = 0; $i < $amt; $i++) {
  118. if ((now() - $this->tili_ts) / glc()->tili_RecoverTS < glc()->tili_RecoverrMax) {
  119. $this->tili_ts -= glc()->tili_RecoverTS;
  120. } else {
  121. $this->tili++;
  122. }
  123. }
  124. }
  125. /**
  126. * 检查并修改体力ts的最小值.
  127. */
  128. function Reset_tilits() {
  129. $min = now() - glc()->tili_RecoverTS * glc()->tili_RecoverrMax;
  130. if ($this->tili_ts < $min) {
  131. $this->tili_ts = $min;
  132. }
  133. }
  134. /**
  135. * 扣除玩家体力
  136. * @param int $amt
  137. * @return bool 成功与否
  138. */
  139. function Consume_tili($amt) {
  140. if ($amt >= 0) {
  141. $cpt = glc()->tili_RecoverTS;
  142. if ($this->tili > 0) {
  143. if ($this->tili - $amt >= 0) {
  144. $this->tili -= $amt;
  145. return true;
  146. } else {
  147. $amt -= $this->tili;
  148. $this->tili = 0;
  149. $this->tili_ts += $amt * $cpt;
  150. return true;
  151. }
  152. } else if ($this->tili_ts + $amt * $cpt < now()) {
  153. $this->tili_ts += $amt * $cpt;
  154. return true;
  155. }
  156. }
  157. return false;
  158. }
  159. /**
  160. * @return int 计算当前可用体力值
  161. */
  162. function CurTili() {
  163. $rec = (now() - $this->tili_ts) / glc()->tili_RecoverTS;
  164. $rec = glc()->tili_RecoverrMax < $rec ? glc()->tili_RecoverrMax : $rec;
  165. $t = $this->tili + $rec;
  166. return $t;
  167. }
  168. /**
  169. * 用户获得金币
  170. * @param int $amt
  171. */
  172. function Add_Gold($amt, $mask = 0) {
  173. my_Assert($amt >= 0, "参数为负");
  174. TaskProc::OnAccumulateGoldNum($amt);
  175. $this->gold += $amt;
  176. }
  177. /**
  178. * 扣除玩家金币
  179. * @param int $amt
  180. * @return boolean true:成功, false:金币不足
  181. */
  182. function Consume_Gold($amt) {
  183. if ($amt > 0) {
  184. if ($this->gold - $amt >= 0) {
  185. $this->gold -= $amt;
  186. return true;
  187. }
  188. }
  189. return false;
  190. }
  191. /**
  192. * 增加用户钻石
  193. * @param type $amt
  194. */
  195. function Add_Cash($amt) {
  196. my_Assert($amt >= 0, "amt值为负");
  197. $this->cash += $amt;
  198. }
  199. /**
  200. * 扣除玩家钻石
  201. * @param int $amt
  202. * @return bool 成功与否
  203. */
  204. function Consume_Cash($amt) {
  205. if ($amt >= 0) {
  206. if ($this->cash - $amt >= 0) {
  207. $this->cash -= $amt;
  208. return true;
  209. }
  210. }
  211. TaskProc::OnConsumeCashNum($amt);
  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. //
  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. //
  241. // }
  242. }
  243. //
  244. // </editor-fold>
  245. }