Info_UserBase.php 7.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307
  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 = 0;
  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. public $accumulateYuanBao = 0;
  79. /**
  80. * 新解锁的头像框
  81. * @var type
  82. */
  83. #[ArrayType]
  84. public $headImgFrameList = array();
  85. /**
  86. * 片头动画
  87. * @var type
  88. */
  89. public $animation = 0;
  90. /**
  91. * 首充奖励是否领取过首充奖励是否领取过
  92. * @var type
  93. */
  94. public $fRechargePriceReceived = 0;
  95. /**
  96. * 消耗体力统计
  97. * @var type
  98. */
  99. public $cost_tili = 0;
  100. public function initialize() {
  101. // my_Assert(GameConfig::primordial_data(), "找不到账号初始化数据"); # 防御
  102. $this->gold = glc()->Init_Player_gold;
  103. $this->cash = glc()->Init_Player_cash;
  104. $this->xp = 0;
  105. $this->maxXp = GameConfig::player_level_getItem(2)->xp_need;
  106. $this->level = 1;
  107. $this->name = '';
  108. $this->img = "";
  109. $heroMo = GameConfig::hero_getItem(glc()->CreateUserGame_defaultHeroId);
  110. $this->headImg = $heroMo->img;
  111. }
  112. // <editor-fold defaultstate="collapsed" desc=" 方法 ">
  113. //
  114. /**
  115. * 给玩家增加体力
  116. * @param int $amt
  117. */
  118. function Add_tili($amt) {
  119. my_Assert($amt >= 0, "体力amt小于0");
  120. //ActiveProc::ChangeTili($amt);
  121. for ($i = 0; $i < $amt; $i++) {
  122. if ((now() - $this->tili_ts) / glc()->tili_RecoverTS < $this->GetTili_RecoverrMax()) {
  123. $this->tili_ts -= glc()->tili_RecoverTS;
  124. } else {
  125. $this->tili++;
  126. }
  127. }
  128. }
  129. /**
  130. * 体力恢复的最大值(购买或者邮件领取的可以超出,超出后体力恢复失效)
  131. */
  132. function GetTili_RecoverrMax() {
  133. $maxTili = glc()->tili_RecoverrMax;
  134. $monthTs = 30 * 24 * 60 * 60;
  135. if (ctx()->privateState->honourCardShop_ts > 0 && now() - ctx()->privateState->honourCardShop_ts < $monthTs) {
  136. $maxTili += glc()->tili_RecoverrMax_Add_HonourCard;
  137. }
  138. return $maxTili;
  139. }
  140. /**
  141. * 检查并修改体力ts的最小值.
  142. */
  143. function Reset_tilits() {
  144. $maxTili = $this->GetTili_RecoverrMax();
  145. $min = now() - glc()->tili_RecoverTS * $maxTili;
  146. if ($this->tili_ts < $min) {
  147. $this->tili_ts = $min;
  148. }
  149. }
  150. /**
  151. * 扣除玩家体力
  152. * @param int $amt
  153. * @return bool 成功与否
  154. */
  155. function Consume_tili($amt) {
  156. if ($amt >= 0) {
  157. TaskProc::OnAccumulateTiliNum($amt);
  158. $cpt = glc()->tili_RecoverTS;
  159. if ($this->tili > 0) {
  160. if ($this->tili - $amt >= 0) {
  161. $this->tili -= $amt;
  162. return true;
  163. } else {
  164. $amt -= $this->tili;
  165. $this->tili = 0;
  166. $this->tili_ts += $amt * $cpt;
  167. return true;
  168. }
  169. } else if ($this->tili_ts + $amt * $cpt < now()) {
  170. $this->tili_ts += $amt * $cpt;
  171. return true;
  172. }
  173. }
  174. return false;
  175. }
  176. /**
  177. * @return int 计算当前可用体力值
  178. */
  179. function CurTili() {
  180. $maxTili = $this->GetTili_RecoverrMax();
  181. $rec = (now() - $this->tili_ts) / glc()->tili_RecoverTS;
  182. $rec = $maxTili < $rec ? $maxTili : $rec;
  183. $t = $this->tili + $rec;
  184. return $t;
  185. }
  186. /**
  187. * 用户获得金币
  188. * @param int $amt
  189. */
  190. function Add_Gold($amt, $mask = 0) {
  191. my_Assert($amt >= 0, "参数为负");
  192. TaskProc::OnAccumulateGoldNum($amt);
  193. $this->gold += $amt;
  194. }
  195. /**
  196. * 扣除玩家金币
  197. * @param int $amt
  198. * @return boolean true:成功, false:金币不足
  199. */
  200. function Consume_Gold($amt) {
  201. if ($amt > 0) {
  202. if ($this->gold - $amt >= 0) {
  203. $this->gold -= $amt;
  204. return true;
  205. }
  206. }
  207. return false;
  208. }
  209. /**
  210. * 增加用户钻石
  211. * @param type $amt
  212. */
  213. function Add_Cash($amt) {
  214. my_Assert($amt >= 0, "amt值为负");
  215. $this->cash += $amt;
  216. }
  217. /**
  218. * 扣除玩家钻石
  219. * @param int $amt
  220. * @return bool 成功与否
  221. */
  222. function Consume_Cash($amt) {
  223. if ($amt >= 0) {
  224. if ($this->cash - $amt >= 0) {
  225. $this->cash -= $amt;
  226. TaskProc::OnConsumeCashNum($amt);
  227. return true;
  228. }
  229. }
  230. return false;
  231. }
  232. /**
  233. * 用户获得经验值
  234. * @param int $amt
  235. */
  236. function Add_Exp($amt) {
  237. my_Assert($amt >= 0, "amt值为负");
  238. $cfgLVs = GameConfig::player_level();
  239. $this->xp += $amt;
  240. $initLevel = $curLevel = $this->level;
  241. $nextLevel = $curLevel + 1;
  242. while ($this->xp >= $cfgLVs->$nextLevel->xp_need) { # 超过升级所需经验
  243. if ($this->level < glc()->Game_MaxPlayerLevel) { # 如果未到达最大等级
  244. StoreProc::AddMultiItemInStore(GameConfig::player_level_getItem($this->level)->reward, Enum_StoreSourceType::AddExp);
  245. $this->level++;
  246. FightProc::funUnlock_userLv($this->level);
  247. $this->xp -= $cfgLVs->$nextLevel->xp_need;
  248. $curLevel = $this->level;
  249. $nextLevel = $curLevel + 1;
  250. my_Assert(CommUtil::isPropertyExists($cfgLVs, $nextLevel), ErrCode::err_const_no); // "取英雄升级常量数据失败." . $nextLevel . "级");
  251. $this->maxXp = $cfgLVs->$nextLevel->xp_need;
  252. TaskProc::OnUserLevel_X($this->level);
  253. FightProc::skillUnlock_userLevel($this->level); # 等级解锁技能
  254. // StatProc::UserLevel($nowlv); # 等级统计
  255. } else { # 如果已到达最大等级则仅补齐缺失的经验即可
  256. $this->xp = $this->maxXp; # 经验不能超过最大值
  257. break;
  258. }
  259. }
  260. }
  261. //
  262. // </editor-fold>
  263. }