Ins_UserHero.php 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579
  1. <?php
  2. namespace loyalsoft;
  3. /// <summary>
  4. /// 英雄属性
  5. /// </summary>
  6. class EHeroProperties extends Enum {
  7. /// <summary>
  8. /// 生命值
  9. /// </summary>
  10. const HP = 0;
  11. /// <summary>
  12. /// 能量值
  13. /// </summary>
  14. const NENGLIANGZHI = 1;
  15. /// <summary>
  16. /// 物理攻击
  17. /// </summary>
  18. const WULIGONGJI = 2;
  19. /// <summary>
  20. /// 防御护甲
  21. /// </summary>
  22. const FANGYUHUJIA = 3;
  23. /// <summary>
  24. /// 敏捷
  25. /// </summary>
  26. const GONGJISUDU = 4;
  27. /// <summary>
  28. /// 暴击
  29. /// </summary>
  30. const CRICITAL = 5;
  31. /// <summary>
  32. /// 法术强度
  33. /// </summary>
  34. const FASHUQIANGDU = 6;
  35. /// <summary>
  36. /// 魔法抗性
  37. /// </summary>
  38. const MOFAKANGXING = 7;
  39. }
  40. /**
  41. * 玩家的英雄的实体数据
  42. */
  43. class Ins_UserHero extends Object_ext {
  44. /**
  45. * 唯一的英雄ID
  46. * @var string
  47. */
  48. public $uid;
  49. /**
  50. * 英雄的模板ID
  51. * @var string
  52. */
  53. public $typeId;
  54. /**
  55. * 英雄的当前等级
  56. * @var int
  57. */
  58. public $level;
  59. /**
  60. * 英雄当前等阶
  61. * @var string
  62. */
  63. public $grade;
  64. /**
  65. * 英雄的收集的当前等级满级的累计经验值
  66. * @var int
  67. */
  68. public $maxXp;
  69. /**
  70. * 英雄的当前总经验值
  71. * @var int
  72. */
  73. public $xp;
  74. /**
  75. * 当前等阶 默认是0.
  76. * 0= 绿 1=蓝 2= 红 3= 紫 4= 橙 5
  77. * @var int
  78. * @deprecated since version 0
  79. */
  80. public $strengthLevel;
  81. /**
  82. * 当前星级 默认是0星
  83. * @var int
  84. * @deprecated since version 0
  85. */
  86. public $curStar;
  87. /**
  88. * 当前神血的 血脉等级 默认是0
  89. * @var int
  90. * @deprecated since version 0
  91. */
  92. public $curBloodId;
  93. /**
  94. * 当前卡牌的锁定状态
  95. * true = 锁定
  96. * @var bool
  97. * @deprecated since version 0
  98. */
  99. public $isLocked;
  100. /**
  101. * 技能数据
  102. * @var object
  103. * @deprecated since version 0
  104. */
  105. public $skills;
  106. /**
  107. * 子技能列表(已解锁子技能id)
  108. * @var dic<int,[]int>
  109. */
  110. public $subSkills;
  111. /**
  112. * 装备
  113. * @var object
  114. */
  115. public $equip;
  116. /**
  117. * 言灵
  118. * @var {}
  119. */
  120. public $yanling;
  121. /**
  122. * 当前主线的好感度进度
  123. * @var object
  124. * @deprecated since version 0
  125. */
  126. public $curMainFavor;
  127. /**
  128. * 所有的已经拥有的好感度进度
  129. * @var array
  130. * @deprecated since version 0
  131. */
  132. public $favors;
  133. /**
  134. *
  135. * 构造函数
  136. */
  137. public function __construct($arg = null) {
  138. if (null != $arg) {
  139. parent::__construct($arg);
  140. } else {
  141. $this->level = 1;
  142. $this->xp = 0;
  143. $this->maxXp = 0;
  144. $this->strengthLevel = 0;
  145. $this->curBloodId = 0;
  146. $this->curStar = 0;
  147. $this->isLocked = false;
  148. $this->curMainFavor = 'E';
  149. $this->favors = ArrayInit();
  150. $this->favors[] = 'E';
  151. $this->grade = "D";
  152. //-----------初始化技能的默认数据
  153. $temp = ObjectInit();
  154. $temp->normalSkill = JsonUtil::decode('{"level":1}');
  155. $temp->manuSkill1 = JsonUtil::decode('{"level":1}');
  156. $temp->manuSkill2 = JsonUtil::decode('{"level":1}');
  157. $temp->manuSkill3 = JsonUtil::decode('{"level":1}');
  158. $temp->passiveSkill = JsonUtil::decode('{"level":1}');
  159. $temp->captainSkill = JsonUtil::decode('{"level":1}');
  160. $this->skills = $temp;
  161. $this->subSkills = ObjectInit();
  162. //----初始化装备的默认数据
  163. $this->equip = ObjectInit();
  164. $tempEq = ObjectInit();
  165. $tempEq->weapon = JsonUtil::decode('{"itemuid":0}');
  166. $tempEq->armor = JsonUtil::decode('{"itemuid":0}');
  167. $tempEq->ring = JsonUtil::decode('{"itemuid":0}');
  168. $this->equip = $tempEq;
  169. // ------初始化言灵的默认数据
  170. $this->yanling = JsonUtil::decode('{"1":{"itemuid":0},"2":{"itemuid":0},"3":{"itemuid":0}}');
  171. }
  172. }
  173. /**
  174. * 判断技能是否可升级
  175. * @param type $mainSkillId
  176. * @param type $subSkillId Description
  177. * @return type
  178. */
  179. public function IsSkillUpdateAble($mainSkillId, $subSkillId) {
  180. $sarr = array("D" => 1, "C" => 2, "B" => 3, "A" => 4, "S" => 5);
  181. $isOk = false;
  182. if (CommUtil::isPropertyExists($this->subSkills, $mainSkillId)) {
  183. if (CommUtil::isPropertyExists($this->subSkills->$mainSkillId, $subSkillId)) {
  184. $sm = GameConfig::subSkill_getItem($subSkillId);
  185. switch ($sm->upgradeConditionType) {
  186. case 1: // 角色等级
  187. $isOk = $this->level >= int($sm->upgradeParameter);
  188. break;
  189. case 2: // 角色品阶
  190. $cur = (array_key_exists($this->grade, $sarr) ? $sarr[$this->grade] : 0);
  191. $require = (array_key_exists($sm->upgradeParameter, $sarr) ? $sarr[$sm->upgradeParameter] : 0);
  192. $isOk = $cur >= $require;
  193. break;
  194. default:
  195. break;
  196. }
  197. }
  198. }
  199. return $isOk;
  200. }
  201. /**
  202. * 判断技能是否可解锁
  203. * @param type $mainSkillId
  204. * @param type $subSkillId Description
  205. * @return type
  206. */
  207. public function IsSkillUnlockAble($mainSkillId, $subSkillId) {
  208. $sarr = array("D" => 1, "C" => 2, "B" => 3, "A" => 4, "S" => 5);
  209. $isOk = false;
  210. if (CommUtil::isPropertyExists($this->subSkills, $mainSkillId)) {
  211. if (CommUtil::isPropertyExists($this->subSkills->$mainSkillId, $subSkillId)) {
  212. $sm = GameConfig::subSkill_getItem($subSkillId);
  213. switch ($sm->unlockConditionType) {
  214. case 1: // 角色等级
  215. $isOk = $this->level >= int($sm->unlockParameter);
  216. break;
  217. case 2: // 角色品阶
  218. $cur = (array_key_exists($this->grade, $sarr) ? $sarr[$this->grade] : 0);
  219. $require = (array_key_exists($sm->unlockParameter, $sarr) ? $sarr[$sm->unlockParameter] : 0);
  220. $isOk = $cur >= $require;
  221. break;
  222. default:
  223. break;
  224. }
  225. }
  226. }
  227. return $isOk;
  228. }
  229. /**
  230. * 是否可继续升级(指挥官等级限制 + 全局限制)
  231. * @return bool
  232. */
  233. public function HeroCanLevelUp() {
  234. $maxLevel = glc()->Hero_Upgrade_BasicMaxLevel; # 全局设置限制了当前英雄的最高等级
  235. $playerLimit = GameConfig::playerlevel_getItem(ctx()->base()->level)->hero_max_level;
  236. return $this->level < min($maxLevel, $playerLimit);
  237. }
  238. /**
  239. * 获取该角色战斗力数值
  240. * 生命值+物理攻击*4+魔法强度*4+护甲*5+魔抗*5
  241. * @param Data_UserGame $user
  242. * @return type
  243. */
  244. public function GetPower($user) {
  245. return (int) ($this->getHpForBattle($user) * 1.0 //
  246. + $this->getNengLiangZhiJiForBattle($user) * 0 //
  247. + $this->getWuLiGongJiForBattle($user) * 4 //
  248. + $this->getFaShuQiangDuForBattle($user) * 4 //
  249. + $this->getFangYuHuJiaForBattle($user) * 5 //
  250. + $this->getMoFaKangXingForBattle($user) * 5 //
  251. );
  252. }
  253. //
  254. // <editor-fold defaultstate="collapsed" desc="辅助方法">
  255. /**
  256. * 获得角色装备的 物品提供的属性加成
  257. * @param type $attribute
  258. * @return type
  259. */
  260. public function getEquipExtraProperty($attribute) {
  261. $result = 0;
  262. $player = req()->userInfo->game;
  263. $equipUID = $this->equip->weapon->itemuid;
  264. if (CommUtil::isPropertyExists($player->store->equipment, $equipUID)) {
  265. $equip = $player->store->equipment->$equipUID;
  266. $itemId = my_null_default($equip->typeId, 0);
  267. $wp = GameConfig::item_weapon_getItem($itemId);
  268. my_Assert(null != $wp, ErrCode::err_const_no);
  269. switch ($attribute) {
  270. case EHeroProperties::WULIGONGJI:
  271. $result += $wp->phyAtk;
  272. break;
  273. case EHeroProperties :: FASHUQIANGDU:
  274. $result += $wp->fashuqiangdu;
  275. break;
  276. case EHeroProperties :: CRICITAL:
  277. $result += $wp->crit;
  278. break;
  279. }
  280. }
  281. return $result;
  282. }
  283. /**
  284. * 获得角色装备的言灵提供的属性加成
  285. * @param type $attribute
  286. * @param Data_UserGame $user
  287. * @return type
  288. */
  289. public function getYanlingExtraProperty($attribute, $user) {
  290. $result = 0;
  291. var_dump($this);
  292. foreach ($this->yanling as $item) {
  293. $itemUID = $item->itemuid;
  294. if ($itemUID > 0) {
  295. foreach (debug_backtrace()as $x) {
  296. echoLine(json_encode($x));
  297. }
  298. $itemId = $user->store->yanling->$itemUID->typeId;
  299. $mo = GameConfig::item_yanling_getItem($itemId);
  300. my_Assert(null != $mo, ErrCode::err_const_no); # 言灵常量找不到
  301. switch ($attribute) {
  302. case EHeroProperties ::HP:
  303. $result += $mo->hp;
  304. break;
  305. case EHeroProperties :: WULIGONGJI:
  306. $result += $mo->phyAtk;
  307. break;
  308. case EHeroProperties :: FASHUQIANGDU:
  309. $result += $mo->fashuqiangdu;
  310. break;
  311. case EHeroProperties :: CRICITAL:
  312. $result += $mo->crit;
  313. break;
  314. case EHeroProperties ::FANGYUHUJIA:
  315. $result += $mo->phyDef;
  316. break;
  317. case EHeroProperties ::MOFAKANGXING:
  318. $result += $mo->mofakangxing;
  319. break;
  320. default:
  321. break;
  322. }
  323. }
  324. }
  325. return $result;
  326. }
  327. /**
  328. * 获得 角色某个等级 等阶 状态下的属性值
  329. * @param type $modelId moID
  330. * @param type $attType
  331. * @param type $level 等级
  332. * @param type $gradeLevel 品阶(SABCD)
  333. * @return type
  334. */
  335. public function getHeroProperty($modelId, $attType, $level, $gradeLevel) {
  336. $result = 0; # 结果
  337. $gradeF = 0; # 品阶加成
  338. /* 角色成长公式
  339. 生命=初始生命+生命成长*(角色等级-1))+武器加成+言灵加成
  340. 言能=初始言能+言能成长*(角色等级-1))
  341. 物攻=初始物攻+物攻成长*(角色等级-1))+武器加成+言灵加成
  342. 护甲=初始护甲+护甲成长*(角色等级-1))+武器加成+言灵加成
  343. 言攻=初始言攻+言攻成长*(角色等级-1))+武器加成+言灵加成
  344. 言抗=初始言抗+言抗成长*(角色等级-1))+武器加成+言灵加成
  345. 暴击=初始暴击+暴击成长*(角色等级-1))+武器加成+言灵加成
  346. 暴击率=暴击/(75+角色等级*5)
  347. */
  348. // 武器成长 和 言灵成长都是直接数值, 所以放到外面再做加法也可以. Ps. 放外面了
  349. $heroMo = GameConfig::hero_getItem($modelId);
  350. my_Assert($heroMo != null, ErrCode::hero_const_no_err); # 找不到英雄模板数据
  351. $gradeLevelMo = GameConfig::heroextra_level_getItem($heroMo->heroId, $gradeLevel); # 等阶加成配置
  352. my_Assert(null != $gradeLevelMo, ErrCode::err_const_no); # 找不到常量
  353. //
  354. ////第一步, 根据玩家的等阶,来找出,对应的等阶,的各个属性成长的曲线类型,也就是说0阶的时候, 各个属性的成长系数是SABCD的哪搞一个。
  355. ////然后 根据 SABCD的类型以及 想查找的属性, 找出对应的 这个属性的成长系数
  356. //
  357. // <editor-fold defaultstate="collapsed" desc="属性成长">
  358. switch ($attType) { # 属性类型
  359. case EHeroProperties::HP:
  360. $gradeF = $gradeLevelMo->hp;
  361. break;
  362. case EHeroProperties :: MOFAKANGXING:
  363. $gradeF = $gradeLevelMo->mofakangxing;
  364. break;
  365. case EHeroProperties ::FASHUQIANGDU:
  366. $gradeF = $gradeLevelMo->fashuqiangdu;
  367. break;
  368. case EHeroProperties ::WULIGONGJI:
  369. $gradeF = $gradeLevelMo->wuligongji;
  370. break;
  371. case EHeroProperties ::FANGYUHUJIA:
  372. $gradeF = $gradeLevelMo->fangyuhujia;
  373. break;
  374. case EHeroProperties :: NENGLIANGZHI:
  375. $gradeF = $gradeLevelMo->nengliangzhi;
  376. break;
  377. case EHeroProperties :: GONGJISUDU:
  378. $gradeF = $gradeLevelMo->gongjisudu;
  379. break;
  380. case EHeroProperties ::CRICITAL:
  381. $gradeF = 0;
  382. break;
  383. }
  384. //
  385. // </editor-fold>
  386. //
  387. // <editor-fold defaultstate="collapsed" desc="叠加加成后的结果">
  388. switch ($attType) {
  389. case EHeroProperties :: HP:
  390. $result += $heroMo->hp + $gradeF * ($level - 1);
  391. break;
  392. case EHeroProperties ::NENGLIANGZHI:
  393. $result += $heroMo->nengliangzhi + $gradeF * ($level - 1);
  394. break;
  395. case EHeroProperties ::WULIGONGJI:
  396. $result += $heroMo->wuligongji + $gradeF * ($level - 1);
  397. break;
  398. case EHeroProperties ::FANGYUHUJIA:
  399. $result += $heroMo->fangyuhujia + $gradeF * ($level - 1);
  400. break;
  401. case EHeroProperties :: FASHUQIANGDU:
  402. $result += $heroMo->fashuqiangdu + $gradeF * ($level - 1);
  403. break;
  404. case EHeroProperties :: MOFAKANGXING:
  405. $result += $heroMo->mofakangxing + $gradeF * ($level - 1);
  406. break;
  407. case EHeroProperties :: GONGJISUDU:
  408. $result += $heroMo->gongjisudu + $gradeF * ($level - 1);
  409. break;
  410. case EHeroProperties :: CRICITAL:
  411. $result += $heroMo->baoji / (75 + $level * 5);
  412. break;
  413. }
  414. // </editor-fold>
  415. //
  416. return $result;
  417. }
  418. // <editor-fold defaultstate="collapsed" desc="基础(等级+品阶)属性值">
  419. /**
  420. * 基础(等级+品阶) 血量
  421. * @return type
  422. */
  423. function getHp() {
  424. return $this->getHeroProperty($this->typeId, EHeroProperties ::HP, $this->level, $this->grade);
  425. }
  426. /**
  427. * 基础(等级+品阶)能量值
  428. * @return type
  429. */
  430. function getNengLiangZhi() {
  431. return $this->getHeroProperty($this->typeId, EHeroProperties ::NENGLIANGZHI, $this->level, $this->grade);
  432. }
  433. /**
  434. * 基础(等级+品阶)物理攻击
  435. * @return type
  436. */
  437. function getWuLiGongJi() {
  438. return $this->getHeroProperty($this->typeId, EHeroProperties ::WULIGONGJI, $this->level, $this->grade);
  439. }
  440. /**
  441. * 基础(等级+品阶)法术强度
  442. * @return type
  443. */
  444. function getFaShuQiangDu() {
  445. return $this->getHeroProperty($this->typeId, EHeroProperties ::FASHUQIANGDU, $this->level, $this->grade);
  446. }
  447. /**
  448. * 基础(等级+品阶)防御护甲
  449. * @return type
  450. */
  451. function getFangYuHuJia() {
  452. return $this->getHeroProperty($this->typeId, EHeroProperties ::FANGYUHUJIA, $this->level, $this->grade);
  453. }
  454. /**
  455. * 基础(等级+品阶)魔法抗性
  456. * @return type
  457. */
  458. function getMoFaKangXing() {
  459. return $this->getHeroProperty($this->typeId, EHeroProperties ::MOFAKANGXING, $this->level, $this->grade);
  460. }
  461. // </editor-fold>
  462. //
  463. /**
  464. * 战场血量 = 基础血量 + 武器和言灵加成
  465. * @param Data_UserGame $user
  466. * @return type
  467. */
  468. public function getHpForBattle($user) {
  469. return (int) ($this->getHp() // 英雄数据
  470. + $this->getEquipExtraProperty(EHeroProperties ::HP) // 武器加成
  471. + $this->getYanlingExtraProperty(EHeroProperties :: HP, $user) // 言灵加成
  472. );
  473. }
  474. /**
  475. * 战场能量值 = 基础能量值 + 武器和言灵加成
  476. * @param Data_UserGame $user
  477. * @return type
  478. */
  479. public function getNengLiangZhiJiForBattle($user) {
  480. return (int) ($this->getNengLiangZhi() // 英雄本身
  481. + $this->getEquipExtraProperty(EHeroProperties :: NENGLIANGZHI) // + 武器加成
  482. + $this->getYanlingExtraProperty(EHeroProperties::NENGLIANGZHI, $user) // + 言灵加成
  483. );
  484. }
  485. /**
  486. * @param Data_UserGame $user
  487. * @return type
  488. */
  489. public function getWuLiGongJiForBattle($user) {
  490. return (int) ($this->getWuLiGongJi() // 英雄数据
  491. + $this->getEquipExtraProperty(EHeroProperties ::WULIGONGJI) // 武器加成
  492. + $this->getYanlingExtraProperty(EHeroProperties :: WULIGONGJI, $user) // 言灵加成
  493. );
  494. }
  495. /**
  496. * @param Data_UserGame $user
  497. * @return type
  498. */
  499. function getFaShuQiangDuForBattle($user) {
  500. return (int) ($this->getFaShuQiangDu() // 英雄数据
  501. + $this->getEquipExtraProperty(EHeroProperties ::FASHUQIANGDU) // 武器加成
  502. + $this->getYanlingExtraProperty(EHeroProperties :: FASHUQIANGDU, $user) // 言灵加成
  503. );
  504. }
  505. /**
  506. * @param Data_UserGame $user
  507. * @return type
  508. */
  509. function getFangYuHuJiaForBattle($user) {
  510. return (int) ($this->getFangYuHuJia() // 英雄数据
  511. + $this->getEquipExtraProperty(EHeroProperties ::FANGYUHUJIA) // 武器加成
  512. + $this->getYanlingExtraProperty(EHeroProperties :: FANGYUHUJIA, $user) // 言灵加成
  513. );
  514. }
  515. /**
  516. * @param Data_UserGame $user
  517. * @return type
  518. */
  519. function getMoFaKangXingForBattle($user) {
  520. return (int) ($this->getMoFaKangXing() // 英雄数据
  521. + $this->getEquipExtraProperty(EHeroProperties ::MOFAKANGXING) // 武器加成
  522. + $this->getYanlingExtraProperty(EHeroProperties :: MOFAKANGXING, $user) // 言灵加成
  523. );
  524. }
  525. //
  526. // </editor-fold>
  527. //
  528. }