Info_UserBase.php 7.5 KB

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