StoreProc.php 71 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885
  1. <?php
  2. /*
  3. * To change this license header, choose License Headers in Project Properties.
  4. * To change this template file, choose Tools | Templates
  5. * and open the template in the editor.
  6. */
  7. namespace loyalsoft;
  8. /**
  9. * Description of StoreProc
  10. *
  11. * @author c'y'zhao
  12. */
  13. class StoreProc {
  14. /**
  15. * 逻辑分发
  16. * 所有的Proc中必须有这样一个方法
  17. * @param Req $req
  18. */
  19. public static function procMain($req) {
  20. switch ($req->cmd) {
  21. case CmdCode::cmd_store_put: # 6401 放入仓库
  22. return StoreProc::AddItemInStore();
  23. case CmdCode::cmd_store_gemSet: # 6402 装备宝石
  24. return StoreProc::GemSet();
  25. case CmdCode::cmd_store_gemRemove: # 6403 卸下装备宝石
  26. return StoreProc::GemRemove();
  27. case CmdCode::cmd_store_equipUpgrade: # 6404 装备升级
  28. return StoreProc::EquipUpgrade();
  29. case CmdCode::cmd_store_equipUpgrade_MaxLv: # 6405 一键升级(装备)
  30. return StoreProc::EquipUpgrade_MaxLv();
  31. case CmdCode::store_gemCompose: # 6406 宝石合成
  32. return StoreProc::GemCompose();
  33. case CmdCode::store_switchEquipPag: # 6408 切换装备分页
  34. return StoreProc::SwitchEquipPag();
  35. case CmdCode::store_gemLockState: # 6409 宝石开锁解锁
  36. return StoreProc::GemLockState();
  37. case CmdCode::store_equip_removeEquipUpgradeTip: # 6410 移除装备可以升级绿点提示 -------废弃
  38. return StoreProc::RemoveEquipUpgradeTip();
  39. case CmdCode::store_equip_removeNewGemTip: # 6411 移除是新宝石绿点提示
  40. return StoreProc::RemoveNewGemTip();
  41. case CmdCode::store_allEquipUpgrade: # 6412 所有装备的一键升级-----------废弃
  42. return StoreProc::AllEquipUpgrade();
  43. case CmdCode::store_gemXiLian: # 6413 洗练
  44. return StoreProc::GemXiLian();
  45. case CmdCode::store_equiped: # 6414 装备
  46. return StoreProc::Equiped();
  47. case CmdCode::store_remove_equip: # 6415 卸下装备
  48. return StoreProc::RemoveEquip();
  49. case CmdCode::store_equip_gemSlotBuy: # 6416 购买装备宝石槽
  50. return StoreProc::Gem_BuySlot();
  51. case CmdCode::store_equip_compose: # 6417 装备合成
  52. return StoreProc::Equip_Compose();
  53. case CmdCode::store_equip_OnekeyCompose: # 6418 装备一键合成
  54. return StoreProc::Equip_OnekeyCompose_new();
  55. case CmdCode::store_equip_downGradingLevel: # 6419 降级
  56. return StoreProc::Equip_DownGradingLevel();
  57. case CmdCode::store_equip_downGradingQual: # 6420 降品
  58. return StoreProc::Equip_DownGradingQual();
  59. case CmdCode::store_pet_removeNewTip: # 6421 移除宠物上的新的标志
  60. return StoreProc::Pet_RemoveNewTip();
  61. case CmdCode::store_pet_changeFightPosition: # 6422 出战/替换/上阵
  62. return StoreProc::Pet_ChangeFightPosition();
  63. case CmdCode::store_pet_selectShowPet: # 6423 展示空闲灵宠
  64. return StoreProc::Pet_SelectShowPet();
  65. case CmdCode::store_pet_levelUpgrade: # 6424 灵宠等级提升
  66. return StoreProc::Pet_LevelUpgrade();
  67. case CmdCode::store_pet_compose: # 6425 宠物合成
  68. return StoreProc::Pet_Compose();
  69. case CmdCode::store_pet_onekeyCompose: # 6426 宠物一键合成
  70. return StoreProc::Pet_OnekeyCompose();
  71. case CmdCode::store_pet_downGradingLevel: # 6427 宠物降级
  72. return StoreProc::Pet_DownGradingLevel();
  73. case CmdCode::store_pet_downGradingQual: # 6428 宠物降品
  74. return StoreProc::Pet_DownGradingQual();
  75. default:
  76. Err(ErrCode::cmd_err);
  77. }
  78. }
  79. /**
  80. * 6428 宠物降品
  81. */
  82. public static function Pet_DownGradingQual() {
  83. list($uid) = req()->paras;
  84. $petDic = ctx()->store->pet;
  85. my_Assert(StlUtil::dictHasProperty($petDic, $uid), ErrCode::user_store_NotExistPet);
  86. $ins_pet = new Ins_Pet($petDic->$uid);
  87. $NotDownGradingList = explode(',', glc()->equipQual_NotDownGrading);
  88. my_Assert(!in_array($ins_pet->qual, $NotDownGradingList), ErrCode::user_store_equip_minQual);
  89. $itemNum = 0;
  90. for ($i = 1; $i < $ins_pet->level; $i++) {
  91. $mo = GameConfig::pet_levelupgrade_getItem($ins_pet->mo()->rarity, $ins_pet->qual, $i);
  92. $itemNum += $mo->costItem;
  93. }
  94. StoreProc::AddMultiItemInStore(6 . ',' . $itemNum);
  95. self::ComposeMaterial_Fallback_Pet($ins_pet->mo()->petType, $ins_pet->qual);
  96. $ins_pet->level = 1;
  97. $sList2 = explode(';', glc()->equipQualUnlockSkillId);
  98. foreach ($sList2 as $str3) {
  99. $s = explode(',', $str3);
  100. if (in_array($ins_pet->qual, $s)) {
  101. $ins_pet->qual = $s[0];
  102. break;
  103. }
  104. }
  105. ctx()->store->pet->$uid = $ins_pet;
  106. //FightProc::Ranking_FightPower();
  107. UserProc::updateUserInfo();
  108. return Resp::ok(array(
  109. //'gold' => ctx()->baseInfo->gold,
  110. 'store' => ctx()->store,
  111. ));
  112. }
  113. private static function ComposeMaterial_Fallback_Pet($type, $qual) {
  114. $sList2 = explode(';', glc()->equipQualUnlockSkillId);
  115. foreach ($sList2 as $str) {
  116. $s = explode(',', $str);
  117. if (in_array($qual, $s)) {
  118. $max = $qual;
  119. $min = $s[0];
  120. $num = 0;
  121. for ($i = $min; $i < $max; $i++) {
  122. $mo = GameConfig::pet_compose_getItem($i);
  123. $num += explode(',', $mo->compose_condition)[2];
  124. }
  125. $typeId = self::ComposeMaterial($type, $min,902);
  126. StoreProc::AddMultiItemInStore($typeId . ',' . $num);
  127. break;
  128. }
  129. }
  130. }
  131. /*
  132. * 6427 宠物降级
  133. */
  134. public static function Pet_DownGradingLevel() {
  135. list($uid) = req()->paras; //宠物uid
  136. $petDic = ctx()->store->pet;
  137. my_Assert(StlUtil::dictHasProperty($petDic, $uid), ErrCode::user_store_NotExistPet);
  138. $ins_pet = new Ins_Pet($petDic->$uid);
  139. my_Assert($ins_pet->level > 1, ErrCode::user_store_equip_minlevel);
  140. $itemNum = 0;
  141. for ($i = 1; $i < $ins_pet->level; $i++) {
  142. $mo = GameConfig::pet_levelupgrade_getItem($ins_pet->mo()->rarity, $ins_pet->qual, $i);
  143. $itemNum += $mo->costItem;
  144. }
  145. StoreProc::AddMultiItemInStore(6 . ',' . $itemNum);
  146. $ins_pet->level = 1;
  147. ctx()->store->pet->$uid = $ins_pet;
  148. //FightProc::Ranking_FightPower();
  149. UserProc::updateUserInfo();
  150. return Resp::ok(array(
  151. //'gold' => ctx()->baseInfo->gold,
  152. 'store' => ctx()->store,
  153. ));
  154. }
  155. /**
  156. * 6426 宠物一键合成
  157. * @return type
  158. */
  159. public static function Pet_OnekeyCompose() {
  160. $store = ctx()->store(true);
  161. $petDic = $store->pet;
  162. $arr = array(); # 待处理装备临时数组
  163. $composePet = array(); # 合成记录
  164. foreach ($petDic as $pet) {
  165. if ($pet->qual < 4) { # 4 品以上的不参与合成
  166. $arr[] = new Ins_Pet($pet);
  167. }
  168. }
  169. while (count($arr) > 0) { # 循环处理每一个装备
  170. $pet_compose = array_pop($arr); # 从末尾弹出一个元素做合成运算
  171. if (null == $pet_compose) { # 防御空对象
  172. break;
  173. }
  174. $eqQualCfg = GameConfig::pet_compose_getItem($pet_compose->qual); # 按照品阶查询合成配置数据
  175. my_Assert(null != $eqQualCfg, ErrCode::err_const_no); # 防御配置数据错误
  176. list($type, $costQual, $num) = explode(',', $eqQualCfg->compose_condition); # 从配置提取合成条件
  177. $composeArr = array(); # 消耗集合
  178. foreach ($arr as $v) { # 从剩余元素中查找合成所需
  179. if ($v->qual == $costQual) { # 同品阶
  180. if (($type == 1) ? $v->typeId == $pet_compose->typeId # # type: 1 与本体相同 2 同部位即可
  181. : $v->mo()->petType == $pet_compose->mo()->petType) {
  182. $composeArr[] = $v; # 成为消耗品
  183. }
  184. if (count($composeArr) >= $num) { # 达到消耗数量就停
  185. break;
  186. }
  187. }
  188. }
  189. if (count($composeArr) >= $num) { # 合成的回收 不合成的可不能给回收了
  190. $uid = $pet_compose->uid;
  191. $newPet = self::ComposeNewPet($pet_compose); # 原地合成
  192. self::petLevelChange_Material_Recovery($newPet->mo()->rarity, $newPet->qual, $newPet->level); # 回收材料
  193. $newPet->level = 1;
  194. $petDic->$uid = $newPet;
  195. $composePet[] = $uid; # 添加合成记录
  196. foreach ($composeArr as $val) { # 回收消耗的装备中所含材料
  197. self::petLevelChange_Material_Recovery($val->mo()->rarity, $val->qual, $val->level); # 回收材料
  198. StlUtil::dictRemove(ctx()->store(true)->pet, $val->uid); # 背包删除
  199. if(ctx()->store(true)->petUid_fight_position == $val->uid){
  200. ctx()->store(true)->petUid_fight_position = 0;
  201. }
  202. foreach (ctx()->store(true)->petUids_supportFight_position as $k => $pUid) {
  203. if($pUid == $val->uid){
  204. StlUtil::dictRemove(ctx()->store(true)->petUids_supportFight_position, $k);
  205. break;
  206. }
  207. }
  208. StlUtil::arrayRemove($arr, $val); # 从arr中删掉已消耗装备
  209. }
  210. }
  211. }
  212. UserProc::updateUserInfo(); # 回存玩家数据
  213. return Resp::ok(array(# # 返回给客户端的数据
  214. 'store' => ctx()->store,
  215. 'composeEquip' => $composePet,
  216. 'task' => ctx()->task,
  217. ));
  218. }
  219. /**
  220. * 6425 宠物合成
  221. * @return Resp
  222. */
  223. public static function Pet_Compose() {
  224. list($uid, $petUids_cost, $composeMaterial_typeIds) = req()->paras;
  225. $petDic = ctx()->store->pet;
  226. my_Assert(StlUtil::dictHasProperty($petDic, $uid), ErrCode::user_store_NotExistPet);
  227. $ins_pet = new Ins_Pet($petDic->$uid);
  228. my_Assert($ins_pet->qual < 11, ErrCode::user_store_equip_qualMaxLimit);
  229. $composeMo = GameConfig::pet_compose_getItem($ins_pet->qual);
  230. my_Assert(null != $composeMo, ErrCode::err_const_no);
  231. $arr = explode(',', $composeMo->compose_condition);
  232. $type = $arr[0];
  233. $costQual = $arr[1];
  234. $num = $arr[2];
  235. $all_num = 0;
  236. $materialItemType = 0;
  237. $materialItemNum = 0;
  238. if ($type == 2 && $composeMaterial_typeIds != null) {//部位去校验
  239. $str = explode(',', $composeMaterial_typeIds);
  240. $materialItemType = $str[0];
  241. $materialItemNum = count($str);
  242. foreach ($str as $s) {
  243. $composeMaterial_itemTypeId = self::ComposeMaterial($ins_pet->mo()->petType, $costQual,902);
  244. my_Assert($composeMaterial_itemTypeId == $s, ErrCode::user_store_equip_composeMaterialErr);
  245. $all_num += 1;
  246. }
  247. }
  248. if ($petUids_cost != null) {
  249. $costPetsArr = explode(',', $petUids_cost);
  250. $all_num += count($costPetsArr);
  251. foreach ($costPetsArr as $pUid) {
  252. my_Assert(StlUtil::dictHasProperty($petDic, $pUid), ErrCode::user_store_NotExistPet);
  253. my_Assert(ctx()->store(true)->petUid_fight_position != $pUid, ErrCode::user_store_NotSelectPet_fight);
  254. my_Assert(!in_array($pUid, ctx()->store(true)->petUids_supportFight_position), ErrCode::user_store_NotSelectPet_supportfight);
  255. $costIns_pet = new Ins_Pet($petDic->$pUid);
  256. my_Assert($costIns_pet->qual == $costQual, ErrCode::user_store_equipMaterialQualErr);
  257. if ($type == 1) {//本体
  258. my_Assert($costIns_pet->typeId == $ins_pet->typeId, ErrCode::user_store_equipMaterialTypeErr);
  259. } else {
  260. my_Assert($costIns_pet->mo()->petType == $ins_pet->mo()->petType, ErrCode::user_store_equipMaterialTypeErr);
  261. }
  262. }
  263. }
  264. my_Assert($all_num == $num, ErrCode::user_store_equipMaterialNumErr);
  265. ctx()->store(true)->pet->$uid = self::ComposeNewPet($ins_pet);
  266. //消耗的装备 回收
  267. if ($petUids_cost != null) {
  268. $costPetsArr = explode(',', $petUids_cost);
  269. foreach ($costPetsArr as $pUid) {
  270. $costIns_Equip = new Ins_Pet($petDic->$pUid);
  271. self::petLevelChange_Material_Recovery($costIns_Equip->mo()->rarity, $costIns_Equip->qual, $costIns_Equip->level);
  272. StlUtil::dictRemove(ctx()->store(true)->pet, $pUid);
  273. }
  274. }
  275. if ($materialItemType != 0) {
  276. ctx()->store(true)->removeItem($materialItemType, $materialItemNum);
  277. }
  278. UserProc::updateUserInfo();
  279. return Resp::ok(array(
  280. 'store' => ctx()->store,
  281. 'task' => ctx()->task,
  282. ));
  283. }
  284. /**
  285. * 装备等级提升 消耗的金币图纸回收
  286. * @param type $rarity
  287. * @param type $qual
  288. * @param type $posId
  289. * @param type $level
  290. */
  291. public static function petLevelChange_Material_Recovery($rarity, $qual,$level) {
  292. $num = 0;
  293. for ($i = 1; $i <= $level - 1; $i++) {
  294. $mo = GameConfig::pet_levelupgrade_getItem($rarity, $qual, $i);
  295. $num += $mo->costItem;
  296. }
  297. if ($num > 0) {
  298. StoreProc::AddMultiItemInStore(6 . ',' . $num);
  299. }
  300. }
  301. /**
  302. * 合成一个新的装备
  303. * @param type Ins_Equip
  304. */
  305. public static function ComposeNewPet(&$ins_pet) {
  306. $newPetTypeId = $ins_pet->typeId;
  307. $qual = $ins_pet->qual + 1;
  308. if ($ins_pet->qual < 4) {
  309. //$newEquipTypeId = substr($ins_pet->typeId, 0, strlen($ins_equip->typeId) - 5);
  310. $rarity = substr($ins_pet->typeId, -3);
  311. $mo = GameConfig::pet_getItem($ins_pet->typeId);
  312. $newPetTypeId = $mo->type. "0" . $qual . $rarity;
  313. }
  314. $ins_pet->typeId = $newPetTypeId;
  315. $ins_pet->qual = $qual;
  316. return $ins_pet;
  317. }
  318. /**
  319. *6424 灵宠等级提升
  320. * @return Resp
  321. */
  322. public static function Pet_LevelUpgrade(){
  323. list($uid) = req()->paras; //装备uid
  324. my_Assert(StlUtil::dictHasProperty(ctx()->store->pet, $uid), ErrCode::user_store_NotExistPet);
  325. $ins_pet = new Ins_Pet(ctx()->store->pet->$uid);
  326. my_Assert($ins_pet->level < $ins_pet->Pet_MaxLevel(), ErrCode::user_store_LevelLimit);
  327. $mo = $ins_pet->petLevelMo();
  328. $costTuzhiId = 6;
  329. $tuzhiNum = 0;
  330. if (StlUtil::dictHasProperty(ctx()->store->items, $costTuzhiId)) {
  331. $tuzhiNum = ctx()->store->items->$costTuzhiId;
  332. }
  333. my_Assert($tuzhiNum >= $mo->costItem, ErrCode::notenough_item);
  334. ctx()->store(true)->removeItem($costTuzhiId,$mo->costItem);
  335. $ins_pet->level += 1;
  336. ctx()->store->pet->$uid = $ins_pet;
  337. UserProc::updateUserInfo();
  338. return Resp::ok(array(
  339. 'store' => ctx()->store,
  340. ));
  341. }
  342. /**
  343. * 6423 展示空闲灵宠
  344. * @return Resp
  345. */
  346. public static function Pet_SelectShowPet(){
  347. list($uid) = req()->paras;
  348. $petDic = ctx()->store->pet;
  349. my_Assert(StlUtil::dictHasProperty($petDic, $uid), ErrCode::user_store_NotExistPet);
  350. my_Assert(count(ctx()->store()->mainShowPetList)< GameConfig::glc2()->Pet_MainShowPetList , ErrCode::user_store_ShowPetNumLimit);
  351. my_Assert(ctx()->store->petUid_fight_position != $uid, ErrCode::user_store_NotSelectPet_fight);
  352. my_Assert(!in_array($uid, ctx()->store->petUids_supportFight_position), ErrCode::user_store_NotSelectPet_supportfight);
  353. if(in_array($uid,ctx()->store()->mainShowPetList)){
  354. StlUtil::arrayRemove(ctx()->store()->mainShowPetList, $uid);
  355. } else {
  356. ctx()->store()->mainShowPetList[] = $uid;
  357. }
  358. UserProc::updateUserInfo();
  359. return Resp::ok(array());
  360. }
  361. /**
  362. * 6422 出战/替换/上阵
  363. */
  364. public static function Pet_ChangeFightPosition() {
  365. list($type, $uid, $index) = req()->paras;
  366. if ($type == 1) {//出战、替换
  367. ctx()->store(true)->petUid_fight_position = $uid;
  368. } else if ($type == 2) {
  369. ctx()->store(true)->petUids_supportFight_position->$index = $uid;
  370. }
  371. if ($type == 0 && $index == 0 && $uid != 0) {//上阵点击空白的地方
  372. if (ctx()->store(true)->petUid_fight_position == 0) {
  373. ctx()->store(true)->petUid_fight_position = $uid;
  374. } else {
  375. if (count(StlUtil::dictToArray(ctx()->store(true)->petUids_supportFight_position)) == 0) {
  376. $key = 1;
  377. ctx()->store(true)->petUids_supportFight_position->$key = $uid;
  378. } else {
  379. for ($i = 1; $i <= 2; $i++) {
  380. if (!StlUtil::dictHasProperty(ctx()->store(true)->petUids_supportFight_position, $i) || ctx()->store(true)->petUids_supportFight_position->$i == 0) {
  381. ctx()->store(true)->petUids_supportFight_position->$i = $uid;
  382. break;
  383. }
  384. }
  385. }
  386. }
  387. }
  388. UserProc::updateUserInfo();
  389. return Resp::ok(array());
  390. }
  391. /**
  392. * 6421 移除宠物上的新的标志
  393. */
  394. public static function Pet_RemoveNewTip() {
  395. list($uid) = req()->paras;
  396. $petDic = ctx()->store->pet;
  397. my_Assert(StlUtil::dictHasProperty($petDic, $uid), ErrCode::user_store_NotExistPet);
  398. ctx()->store->pet->$uid->isNew = 0;
  399. UserProc::updateUserInfo();
  400. return Resp::ok(array());
  401. }
  402. /**
  403. * 6420 降品
  404. */
  405. public static function Equip_DownGradingQual() {
  406. list($uid) = req()->paras;
  407. $equipDic = ctx()->store->equip;
  408. my_Assert(StlUtil::dictHasProperty($equipDic, $uid), ErrCode::user_store_NotExistEquip);
  409. $ins_equip = new Ins_Equip($equipDic->$uid);
  410. $NotDownGradingList = explode(',', glc()->equipQual_NotDownGrading);
  411. my_Assert(!in_array($ins_equip->qual, $NotDownGradingList), ErrCode::user_store_equip_minQual);
  412. self::GoldTuzhi_Fallback_Level($ins_equip);
  413. self::ComposeMaterial_Fallback($ins_equip->mo()->position, $ins_equip->qual);
  414. $ins_equip->level = 1;
  415. $sList2 = explode(';', glc()->equipQualUnlockSkillId);
  416. foreach ($sList2 as $str3) {
  417. $s = explode(',', $str3);
  418. if (in_array($ins_equip->qual, $s)) {
  419. $ins_equip->qual = $s[0];
  420. break;
  421. }
  422. }
  423. ctx()->store->equip->$uid = $ins_equip;
  424. FightProc::Ranking_FightPower();
  425. UserProc::updateUserInfo();
  426. return Resp::ok(array(
  427. 'gold' => ctx()->baseInfo->gold,
  428. 'store' => ctx()->store,
  429. ));
  430. }
  431. private static function ComposeMaterial_Fallback($posId, $qual) {
  432. $sList2 = explode(';', glc()->equipQualUnlockSkillId);
  433. foreach ($sList2 as $str) {
  434. $s = explode(',', $str);
  435. if (in_array($qual, $s)) {
  436. $max = $qual;
  437. $min = $s[0];
  438. $num = 0;
  439. for ($i = $min; $i < $max; $i++) {
  440. $mo = GameConfig::equip_compose_getItem($i);
  441. $num += explode(',', $mo->compose_condition)[2];
  442. }
  443. $typeId = self::ComposeMaterial($posId, $min);
  444. StoreProc::AddMultiItemInStore($typeId . ',' . $num);
  445. break;
  446. }
  447. }
  448. }
  449. private static function ComposeMaterial($posId, $qual,$type = 901) {
  450. $itemDic = GameConfig::item();
  451. foreach ($itemDic as $typeId => $mo) {
  452. if ($mo->itemType == $type && $typeId % 100 == $posId && floor($typeId / 100) % 100 == $qual) {
  453. return $typeId;
  454. }
  455. }
  456. return null;
  457. }
  458. private static function GoldTuzhi_Fallback_Level($ins_equip) {
  459. $gold = 0;
  460. $itemNum = 0;
  461. for ($i = 1; $i < $ins_equip->level; $i++) {
  462. $mo = GameConfig::equip_levelupgrade_getItem($ins_equip->mo()->rarity, $ins_equip->qual, $ins_equip->mo()->position, $i);
  463. $gold += $mo->needGold;
  464. $itemNum += $mo->needItemNum;
  465. }
  466. $tuzhiId = GameConfig::equip_position_getItem($ins_equip->mo()->position)->costTuzhiId;
  467. StoreProc::AddMultiItemInStore($tuzhiId . ',' . $itemNum);
  468. ctx()->base(true)->Add_Gold($gold);
  469. }
  470. /*
  471. * 6419 降级
  472. */
  473. public static function Equip_DownGradingLevel() {
  474. list($uid) = req()->paras; //装备uid
  475. $equipDic = ctx()->store->equip;
  476. my_Assert(StlUtil::dictHasProperty($equipDic, $uid), ErrCode::user_store_NotExistEquip);
  477. $ins_equip = new Ins_Equip($equipDic->$uid);
  478. my_Assert($ins_equip->level > 1, ErrCode::user_store_equip_minlevel);
  479. self::GoldTuzhi_Fallback_Level($ins_equip);
  480. $ins_equip->level = 1;
  481. ctx()->store->equip->$uid = $ins_equip;
  482. FightProc::Ranking_FightPower();
  483. UserProc::updateUserInfo();
  484. return Resp::ok(array(
  485. 'gold' => ctx()->baseInfo->gold,
  486. 'store' => ctx()->store,
  487. ));
  488. }
  489. /**
  490. * 6417 装备合成
  491. * @return type
  492. */
  493. public static function Equip_Compose() {
  494. list($uid, $equipUids_cost, $composeMaterial_typeIds) = req()->paras;
  495. $store = ctx()->store(true);
  496. $equipDic = ctx()->store->equip;
  497. my_Assert(StlUtil::dictHasProperty($equipDic, $uid), ErrCode::user_store_NotExistEquip);
  498. $ins_equip = new Ins_Equip($equipDic->$uid);
  499. my_Assert($ins_equip->qual < 16, ErrCode::user_store_equip_qualMaxLimit);
  500. $composeMo = GameConfig::equip_compose_getItem($ins_equip->qual);
  501. my_Assert(null != $composeMo, ErrCode::err_const_no);
  502. $arr = explode(',', $composeMo->compose_condition);
  503. $type = $arr[0];
  504. $costQual = $arr[1];
  505. $num = $arr[2];
  506. $all_num = 0;
  507. $materialItemType = 0;
  508. $materialItemNum = 0;
  509. if ($type == 2 && $composeMaterial_typeIds != null) {//部位去校验
  510. $str = explode(',', $composeMaterial_typeIds);
  511. $materialItemType = $str[0];
  512. $materialItemNum = count($str);
  513. foreach ($str as $s) {
  514. $composeMaterial_itemTypeId = self::ComposeMaterial($ins_equip->mo()->position, $costQual);
  515. my_Assert($composeMaterial_itemTypeId == $s, ErrCode::user_store_equip_composeMaterialErr);
  516. $all_num += 1;
  517. }
  518. }
  519. if ($equipUids_cost != null) {
  520. $costEquipsArr = explode(',', $equipUids_cost);
  521. $all_num += count($costEquipsArr);
  522. foreach ($costEquipsArr as $eqUid) {
  523. my_Assert(StlUtil::dictHasProperty($equipDic, $eqUid), ErrCode::user_store_NotExistEquip);
  524. $costIns_Equip = new Ins_Equip($equipDic->$eqUid);
  525. my_Assert($costIns_Equip->qual == $costQual, ErrCode::user_store_equipMaterialQualErr);
  526. if ($type == 1) {//本体
  527. my_Assert($costIns_Equip->typeId == $ins_equip->typeId, ErrCode::user_store_equipMaterialTypeErr);
  528. } else {
  529. my_Assert($costIns_Equip->mo()->position == $ins_equip->mo()->position, ErrCode::user_store_equipMaterialTypeErr);
  530. }
  531. }
  532. }
  533. my_Assert($all_num == $num, ErrCode::user_store_equipMaterialNumErr);
  534. ctx()->store(true)->equip->$uid = self::ComposeNewEquip($ins_equip);
  535. //消耗的装备 回收
  536. if ($equipUids_cost != null) {
  537. $costEquipsArr = explode(',', $equipUids_cost);
  538. foreach ($costEquipsArr as $eqUid) {
  539. $costIns_Equip = new Ins_Equip($equipDic->$eqUid);
  540. self::equipLevelUp_Material_Recovery($costIns_Equip->mo()->rarity, $costIns_Equip->qual, $costIns_Equip->mo()->position, $costIns_Equip->level);
  541. StlUtil::dictRemove(ctx()->store(true)->equip, $eqUid);
  542. for ($i = 1; $i <= 6; $i++) { # 清理装备信息
  543. if ($store->equipLocation->$i == $eqUid) {
  544. StlUtil::dictRemove($store->equipLocation, $i);
  545. }
  546. }
  547. }
  548. }
  549. if ($materialItemType != 0) {
  550. ctx()->store(true)->removeItem($materialItemType, $materialItemNum);
  551. }
  552. TaskProc::OnEquipComposeNum();
  553. FightProc::Ranking_FightPower();
  554. UserProc::updateUserInfo();
  555. return Resp::ok(array(
  556. 'gold' => ctx()->baseInfo->gold,
  557. 'store' => ctx()->store,
  558. 'task' => ctx()->task,
  559. ));
  560. }
  561. /**
  562. * 装备等级提升 消耗的金币图纸回收
  563. * @param type $rarity
  564. * @param type $qual
  565. * @param type $posId
  566. * @param type $level
  567. */
  568. public static function equipLevelUp_Material_Recovery($rarity, $qual, $posId, $level) {
  569. $gold = 0;
  570. $tuzhi = 0;
  571. $tuzhiId = GameConfig::equip_position_getItem($posId)->costTuzhiId;
  572. for ($i = 1; $i <= $level - 1; $i++) {
  573. $mo = GameConfig::equip_levelupgrade_getItem($rarity, $qual, $posId, $i);
  574. $gold += $mo->needGold;
  575. $tuzhi += $mo->needItemNum;
  576. }
  577. if ($gold > 0) {
  578. StoreProc::AddMultiItemInStore("1," . $gold);
  579. StoreProc::AddMultiItemInStore($tuzhiId . ',' . $tuzhi);
  580. }
  581. }
  582. /**
  583. * 合成一个新的装备
  584. * @param type Ins_Equip
  585. */
  586. public static function ComposeNewEquip(&$ins_equip) {
  587. $newEquipTypeId = $ins_equip->typeId;
  588. $qual = $ins_equip->qual + 1;
  589. if ($ins_equip->qual < 4) {
  590. $newEquipTypeId = substr($ins_equip->typeId, 0, strlen($ins_equip->typeId) - 5);
  591. $rarity = substr($ins_equip->typeId, -3);
  592. $newEquipTypeId = $newEquipTypeId . "0" . $qual . $rarity;
  593. }
  594. $ins_equip->typeId = $newEquipTypeId;
  595. $ins_equip->qual = $qual;
  596. return $ins_equip;
  597. }
  598. /**
  599. * 6418 装备一键合成 (gwang 2024年11月16日)
  600. * @return type
  601. */
  602. public static function Equip_OnekeyCompose_new() {
  603. $store = ctx()->store(true);
  604. $equipDic = $store->equip;
  605. $arr = array(); # 待处理装备临时数组
  606. $composeEquip = array(); # 合成记录
  607. foreach ($equipDic as $equip) {
  608. if ($equip->qual < 4) { # 4 品以上的不参与合成
  609. $arr[] = new Ins_Equip($equip);
  610. }
  611. }
  612. usort($arr, function ($a, $b) { # 按等级大小排序, 等级大的放最后
  613. if ($a->level > $b->level) {
  614. return 1;
  615. } else if ($a->level == $b->level) {
  616. return 0;
  617. } else {
  618. return -1;
  619. }
  620. });
  621. while (count($arr) > 0) { # 循环处理每一个装备
  622. $equip_compose = array_pop($arr); # 从末尾弹出一个元素做合成运算
  623. if (null == $equip_compose) { # 防御空对象
  624. continue;
  625. }
  626. $eqQualCfg = GameConfig::equip_compose_getItem($equip_compose->qual); # 按照品阶查询合成配置数据
  627. my_Assert(null != $eqQualCfg, ErrCode::err_const_no); # 防御配置数据错误
  628. list($type, $costQual, $num) = explode(',', $eqQualCfg->compose_condition); # 从配置提取合成条件
  629. $composeArr = array(); # 消耗集合
  630. foreach ($arr as $v) { # 从剩余元素中查找合成所需
  631. if ($v->qual == $costQual) { # 同品阶
  632. if (($type == 1) ? $v->typeId == $equip_compose->typeId # # type: 1 与本体相同 2 同部位即可
  633. : $v->mo()->position == $equip_compose->mo()->position) {
  634. $composeArr[] = $v; # 成为消耗品
  635. }
  636. if (count($composeArr) >= $num) { # 达到消耗数量就停
  637. break;
  638. }
  639. }
  640. }
  641. if (count($composeArr) >= $num) { # 合成的回收 不合成的可不能给回收了
  642. $uid = $equip_compose->uid;
  643. $newEquip = self::ComposeNewEquip($equip_compose); # 原地合成
  644. self::equipLevelUp_Material_Recovery($newEquip->mo()->rarity, $newEquip->qual, $newEquip->mo()->position, $newEquip->level); # 回收材料
  645. $newEquip->level = 1;
  646. $equipDic->$uid = $newEquip;
  647. $composeEquip[] = $uid; # 添加合成记录
  648. foreach ($composeArr as $val) { # 回收消耗的装备中所含材料
  649. self::equipLevelUp_Material_Recovery($val->mo()->rarity, $val->qual, $val->mo()->position, $val->level); # 回收材料
  650. StlUtil::dictRemove(ctx()->store(true)->equip, $val->uid); # 背包删除
  651. for ($i = 1; $i <= 6; $i++) { # 清理装备信息
  652. if ($store->equipLocation->$i == $val->uid) {
  653. StlUtil::dictRemove($store->equipLocation, $i);
  654. }
  655. }
  656. StlUtil::arrayRemove($arr, $val); # 从arr中删掉已消耗装备
  657. }
  658. }
  659. }
  660. TaskProc::OnEquipComposeNum();
  661. FightProc::Ranking_FightPower();
  662. UserProc::updateUserInfo(); # 回存玩家数据
  663. return Resp::ok(array(# # 返回给客户端的数据
  664. 'gold' => ctx()->baseInfo->gold,
  665. 'store' => ctx()->store,
  666. 'composeEquip' => $composeEquip,
  667. 'task' => ctx()->task,
  668. ));
  669. }
  670. /**
  671. * 6418 装备一键合成
  672. * @return type
  673. */
  674. public static function Equip_OnekeyCompose() {
  675. //list() = req()->paras;
  676. $equipDic = ctx()->store->equip;
  677. $arr = array();
  678. foreach ($equipDic as $uid => $equip) {
  679. $ins_equip = new Ins_Equip($equip);
  680. if ($ins_equip->qual > 4) {
  681. continue;
  682. }
  683. $arr[] = $ins_equip;
  684. }
  685. //等级从大到小
  686. $len = count($arr);
  687. for ($i = 0; $i < $len - 1; $i++) {
  688. for ($j = $len - 1; $j > $i; $j--) {
  689. if ($arr[$j]->level > $arr[$j - 1]->level) {
  690. $temp = $arr[$j];
  691. $arr[$j] = $arr[$j - 1];
  692. $arr[$j - 1] = $temp;
  693. }
  694. }
  695. }
  696. $composeEquip = array();
  697. if ($len > 0) {
  698. while (true) {
  699. $equip_compose = $arr[0];
  700. $str = explode(',', GameConfig::equip_compose_getItem($equip_compose->qual)->compose_condition);
  701. $type = $str[0];
  702. $costQual = $str[1];
  703. $num = $str[2];
  704. $n = count($arr);
  705. $composeArr = array();
  706. $tag = false;
  707. $ing_compose = false;
  708. for ($k = $n - 1; $k >= 0; $k--) {
  709. if ($arr[$k]->uid == $equip_compose->uid) {
  710. continue;
  711. }
  712. if ($type == 1 && $arr[$k]->qual == $costQual && $arr[$k]->typeId == $equip_compose->typeId) {
  713. $tag = true;
  714. } else if ($type == 2 && $arr[$k]->qual == $costQual && $arr[$k]->mo()->position == $equip_compose->mo()->position) {
  715. $tag = true;
  716. }
  717. if ($tag) {
  718. $composeArr[] = $arr[$k];
  719. if (count($composeArr) >= $num) {
  720. break;
  721. }
  722. }
  723. }
  724. if (count($composeArr) >= $num) {
  725. $newEquip = self::ComposeNewEquip($equip_compose);
  726. $uid = $newEquip->uid;
  727. ctx()->store(true)->equip->$uid = $newEquip;
  728. $composeEquip[] = $uid;
  729. $ing_compose = true;
  730. }
  731. //合成的 材料不够不能合成的都要删除
  732. foreach ($composeArr as $val) {
  733. if ($ing_compose) {//合成的回收 不合成的可不能给回收了
  734. self::equipLevelUp_Material_Recovery($val->mo()->rarity, $val->qual, $val->mo()->position, $val->level);
  735. StlUtil::dictRemove(ctx()->store(true)->equip, $val->uid);
  736. }
  737. StlUtil::arrayRemove($arr, $val);
  738. }
  739. StlUtil::arrayRemove($arr, $equip_compose);
  740. if (count($arr) <= 0) {
  741. break;
  742. }
  743. }
  744. }
  745. UserProc::updateUserInfo();
  746. return Resp::ok(array(
  747. 'gold' => ctx()->baseInfo->gold,
  748. 'store' => ctx()->store,
  749. 'composeEquip' => $composeEquip,
  750. ));
  751. }
  752. /**
  753. * 6416 购买装备宝石槽
  754. * @return type
  755. */
  756. public static function Gem_BuySlot() {
  757. list($uid) = req()->paras;
  758. $equipDic = ctx()->store->equip;
  759. my_Assert(StlUtil::dictHasProperty($equipDic, $uid), ErrCode::user_store_NotExistEquip);
  760. $ins_equip = new Ins_Equip($equipDic->$uid);
  761. $mo = GameConfig::gem_slotposition_getItem($ins_equip->qual);
  762. my_Assert(null != $mo, ErrCode::err_const_no);
  763. $initNum = $mo->initNum_slot;
  764. $buyNum = $mo->buyNum_slot;
  765. $unlockIndex = 0;
  766. if ($buyNum > 0) {
  767. for ($i = $initNum + 1; $i <= $initNum + $buyNum; $i++) {
  768. if (!StlUtil::dictHasProperty($ins_equip->gemSetSlot, $i)) {
  769. $ins_equip->gemSetSlot->$i = 0;
  770. break;
  771. }
  772. $unlockIndex += 1;
  773. }
  774. }
  775. $costArr = explode(';', $mo->cost);
  776. $cash = explode(',', $costArr[$unlockIndex]);
  777. my_Assert(ctx()->base(true)->cash >= $cash[1], ErrCode::notenough_cash_msg);
  778. ctx()->base(true)->Consume_Cash($cash[1]);
  779. ctx()->store(true)->equip->$uid = $ins_equip;
  780. UserProc::updateUserInfo();
  781. return Resp::ok(array(
  782. 'cash' => ctx()->baseInfo->cash,
  783. 'store' => ctx()->store,
  784. ));
  785. }
  786. /**
  787. * 6414 装备
  788. * @return type
  789. */
  790. public static function Equiped() {
  791. list($uid) = req()->paras;
  792. $equipDic = ctx()->store->equip;
  793. my_Assert(StlUtil::dictHasProperty($equipDic, $uid), ErrCode::user_store_NotExistEquip);
  794. $ins_equip = new Ins_Equip($equipDic->$uid);
  795. $posId = $ins_equip->mo()->position;
  796. ctx()->store(true)->equipLocation->$posId = $uid;
  797. FightProc::Ranking_FightPower();
  798. GuideProc::GateFight_Guide_Trigger();
  799. UserProc::updateUserInfo();
  800. return Resp::ok(array());
  801. }
  802. /**
  803. * 6415 卸下装备
  804. * @return type
  805. */
  806. public static function RemoveEquip() {
  807. list($uid) = req()->paras;
  808. $equipDic = ctx()->store->equip;
  809. my_Assert(StlUtil::dictHasProperty($equipDic, $uid), ErrCode::user_store_NotExistEquip);
  810. $ins_equip = new Ins_Equip($equipDic->$uid);
  811. $posId = $ins_equip->mo()->position;
  812. StlUtil::dictRemove(ctx()->store(true)->equipLocation, $posId);
  813. FightProc::Ranking_FightPower();
  814. UserProc::updateUserInfo();
  815. return Resp::ok(array());
  816. }
  817. /**
  818. * 洗练
  819. * @return Resp
  820. */
  821. public static function GemXiLian() {
  822. list($uid) = req()->paras;
  823. //把 qual pos u一样的宝石开锁关锁
  824. $gemStore = ctx()->store->gemStore;
  825. my_Assert(StlUtil::dictHasProperty($gemStore, $uid), ErrCode::user_store_NotExistGem);
  826. $gem = new Ins_Gem($gemStore->$uid);
  827. my_Assert($gem->mo()->qual >= 5, ErrCode::user_store_XilianStoneNoEnough);
  828. $arr = explode(';', glc()->XILianGemlNeedXILianStone);
  829. $needStone = 0;
  830. $xilianStoneId = 0;
  831. foreach ($arr as $val) {
  832. $str = explode(':', $val);
  833. if ($str[0] == $gem->mo()->qual) {
  834. $s = explode(',', $str[1]);
  835. $needStone = $s[1];
  836. $xilianStoneId = $s[0];
  837. break;
  838. }
  839. }
  840. my_Assert(StlUtil::dictHasProperty(ctx()->store->items, $xilianStoneId) && ctx()->store->items->$xilianStoneId >= $needStone, ErrCode::user_store_XilianStoneNoEnough);
  841. $dic = GameConfig::predicate();
  842. $pList = array();
  843. foreach ($dic as $id => $pMo) {
  844. if ($pMo->positions != null && $pMo->qual != null) {
  845. $list = explode(',', $pMo->positions);
  846. if ($pMo->id != $gem->predicateId && $pMo->qual == $gem->mo()->qual && in_array($gem->mo()->position, $list) && $pMo->attachTarget == "gem") {
  847. $pList[] = $pMo->id;
  848. }
  849. }
  850. }
  851. my_Assert(count($pList) > 0, ErrCode::user_store_NoFindPredicate);
  852. $rand = random_int(0, count($pList) - 1);
  853. $pId = $pList[$rand];
  854. ctx()->store->gemStore->$uid->predicateId = $pId;
  855. ctx()->store->removeItem($xilianStoneId, $needStone);
  856. $xilianStoneNum = 0;
  857. if (StlUtil::dictHasProperty(ctx()->store->items, $xilianStoneId)) {
  858. $xilianStoneNum = ctx()->store->items->$xilianStoneId;
  859. }
  860. FightProc::Ranking_FightPower();
  861. UserProc::updateUserInfo();
  862. return Resp::ok(array(
  863. 'xilianStoneId' => $xilianStoneId,
  864. 'xilianStone' => $xilianStoneNum,
  865. 'predicateId' => $pId,
  866. ));
  867. }
  868. /**
  869. * 宝石开锁解锁
  870. * @return Resp
  871. */
  872. public static function GemLockState() {
  873. list($uid) = req()->paras;
  874. $user = ctx();
  875. //把 qual pos u一样的宝石开锁关锁
  876. $gemStore = $user->store->gemStore;
  877. $gem = $gemStore->$uid;
  878. $tag = 0;
  879. if ($gem->isUnlock == 0) {
  880. $gem->isUnlock = 1;
  881. $tag = 1;
  882. } else {
  883. $gem->isUnlock = 0;
  884. $tag = 0;
  885. }
  886. $gemStore->$uid = $gem;
  887. foreach ($gemStore as $k => $ins_gem) {
  888. if ($ins_gem->typeId == $gem->typeId && $ins_gem->predicateId == $gem->predicateId) {
  889. $gemStore->$k->isUnlock = $tag;
  890. }
  891. }
  892. $user->store->gemStore = $gemStore;
  893. ctx($user);
  894. UserProc::updateUserInfo();
  895. return Resp::ok(array(
  896. 'gold' => 0,
  897. 'store' => $user->store,
  898. ));
  899. }
  900. /**
  901. * 切换装备分页
  902. * @return Resp
  903. */
  904. public static function SwitchEquipPag() {
  905. list($index) = req()->paras;
  906. $user = ctx();
  907. $user->store->equipPag = $index;
  908. ctx($user);
  909. UserProc::updateUserInfo();
  910. return Resp::ok(array());
  911. }
  912. /**
  913. * 所有装备的一键升级
  914. * 规则:等级不同从等级小到大,等级一样按照部位顺序
  915. *
  916. * @return Resp
  917. */
  918. public static function AllEquipUpgrade() {
  919. //list() = req()->paras;
  920. //$user = ctx();
  921. // $equipDic = $user->store->equipPosition;
  922. //
  923. // $equip_levelDic = GameConfig::equip_levelupgrade();
  924. // $maxLv = count(StlUtil::dictToArray($equip_levelDic));
  925. // $arr = array();
  926. // if ($equipDic != null) {
  927. // foreach ($equipDic as $k => &$equip) {
  928. // $equip = new Ins_EquipPosition($equip);
  929. //
  930. // if ($equip->level >= $maxLv) {
  931. // continue;
  932. // }
  933. //
  934. // $lvMo = GameConfig::equip_levelupgrade_getItem($equip->level);
  935. // $needGold = $lvMo->needGold;
  936. // $needItemNum = $lvMo->needItemNum;
  937. // $neeItemId = $equip->mo()->costTuzhiId;
  938. //
  939. // if ($user->baseInfo->gold >= $needGold && StlUtil::dictHasProperty($user->store->items, $neeItemId) && $user->store->items->$neeItemId >= $needItemNum) {
  940. // $arr[] = $equip;
  941. // }
  942. // }
  943. // }
  944. // $upLevelArr = array();
  945. // if (count($arr) > 0) {
  946. // //进行排序
  947. // $len = count($arr);
  948. // for ($i = 0; $i < $len - 1; $i++) {
  949. // for ($j = 0; $j < $len - $i - 1; $j++) {
  950. // if ($arr[$j]->level > $arr[$j + 1]->level) {//从小到大
  951. // $temp = $arr[$j];
  952. // $arr[$j] = $arr[$j + 1];
  953. // $arr[$j + 1] = $temp;
  954. // } elseif ($arr[$j]->level == $arr[$j + 1]->level) {
  955. // $j_equip = new Ins_EquipPosition($arr[$j]);
  956. // $jj_equip = new Ins_EquipPosition($arr[$j + 1]);
  957. // if ($j_equip->mo()->position > $jj_equip->mo()->position) {
  958. // $temp = $arr[$j];
  959. // $arr[$j] = $arr[$j + 1];
  960. // $arr[$j + 1] = $temp;
  961. // }
  962. // }
  963. // }
  964. // }
  965. //升级,扣除金币和图纸
  966. // while (true) {
  967. // $tag = 9999;
  968. // foreach ($arr as $index => &$equip) {
  969. // $ins_equip = new Ins_EquipPosition($equip);
  970. // $lvMo = GameConfig::equip_levelupgrade_getItem($ins_equip->level);
  971. // $needGold = $lvMo->needGold;
  972. // $needItemNum = $lvMo->needItemNum;
  973. // $neeItemId = $ins_equip->mo()->costTuzhiId;
  974. // if ($user->baseInfo->gold >= $needGold && StlUtil::dictHasProperty($user->store->items, $neeItemId) && $user->store->items->$neeItemId >= $needItemNum) {
  975. // $id = $ins_equip->typeId;
  976. // if (!in_array($id, $upLevelArr)) {
  977. // $upLevelArr[] = $id;
  978. // }
  979. //
  980. // $ins_equip->level += 1;
  981. // $equipDic->$id->level += 1;
  982. // $user->baseInfo->Consume_Gold($needGold);
  983. // $user->store->removeItem($neeItemId, $needItemNum);
  984. // if ($ins_equip->level >= 99) {
  985. // $tag = $index;
  986. // break;
  987. // }
  988. // } else {
  989. // $tag = $index;
  990. // break;
  991. // }
  992. // }
  993. // if ($tag != 9999) {
  994. // if (array_key_exists($tag, $arr)) {
  995. // StlUtil::arrayRemoveAt($arr, $tag);
  996. // }
  997. // }
  998. //
  999. // if (count($arr) <= 0) {
  1000. // break;
  1001. // }
  1002. // }
  1003. // }
  1004. // TaskProc::OnAnyEquipUpLevel_X();
  1005. // TaskProc::OnAllEquipUpLevel_X();
  1006. // TaskProc::OnEquipLevelUpNum();
  1007. // ctx($user);
  1008. //
  1009. // FightProc::Ranking_FightPower();
  1010. UserProc::updateUserInfo();
  1011. return Resp::ok(array(
  1012. 'upLevelArr' => $upLevelArr,
  1013. 'gold' => $user->baseInfo->gold,
  1014. 'store' => $user->store,
  1015. 'task' => $user->task,
  1016. ));
  1017. }
  1018. /**
  1019. * 6411 移除是新宝石绿点提示
  1020. * @return Resp
  1021. */
  1022. public static function RemoveNewGemTip() {
  1023. list($uid) = req()->paras; //宝石uid
  1024. my_Assert(StlUtil::dictHasProperty(ctx()->store->gemStore, $uid), ErrCode::user_store_NoItem);
  1025. ctx()->store(true)->gemStore->$uid->isNew = 0;
  1026. UserProc::updateUserInfo();
  1027. return Resp::ok(array());
  1028. }
  1029. /**
  1030. * 移除装备可以升级绿点提示 -------废弃
  1031. * @return Resp
  1032. */
  1033. public static function RemoveEquipUpgradeTip() {
  1034. // list($posId) = req()->paras; //装备部位
  1035. // $user = ctx();
  1036. //
  1037. // my_Assert(StlUtil::dictHasProperty($user->store->equipPosition, $posId), ErrCode::user_store_NoEquip);
  1038. //
  1039. // $user->store->equipPosition->$posId->tip = 0;
  1040. //
  1041. // ctx($user);
  1042. // UserProc::updateUserInfo();
  1043. // return Resp::ok(array(
  1044. // 'gold' => 0,
  1045. // 'store' => $user->store,));
  1046. }
  1047. /**
  1048. * 6406 合成
  1049. * @return type
  1050. */
  1051. public static function GemCompose() {
  1052. list($gemIds) = req()->paras;
  1053. $list = explode(';', $gemIds);
  1054. $gemStore = ctx()->store->gemStore;
  1055. $composeArr = array();
  1056. foreach ($list as $gems) {
  1057. $gemArr = explode('-', $gems);
  1058. $length1 = strlen($gemArr[0]);
  1059. $length2 = strlen($gemArr[1]);
  1060. $gem_composeCost = explode(',', substr($gemArr[0], 1, $length1 - 1)); //去掉逗号
  1061. $gem_composeIds = explode(',', substr($gemArr[1], 1, $length2 - 1)); //去掉逗号
  1062. $gemMo = GameConfig::gem_getItem($gem_composeIds[0]);
  1063. my_Assert(null != $gemMo, ErrCode::err_const_no);
  1064. $isCompose = true;
  1065. foreach ($gem_composeCost as $gemUid) {
  1066. if (!StlUtil::dictHasProperty($gemStore, $gemUid)) {
  1067. $isCompose = false;
  1068. break;
  1069. }
  1070. $ins_gem = new Ins_Gem($gemStore->$gemUid);
  1071. if ($ins_gem->mo()->qual + 1 != $gemMo->qual || $ins_gem->mo()->position != $gemMo->position) {
  1072. $isCompose = false;
  1073. break;
  1074. }
  1075. if (!self::GemIsCanCompose($gemUid)) {
  1076. $isCompose = false;
  1077. break;
  1078. }
  1079. }
  1080. my_Assert($isCompose == true, ErrCode::user_store_GemCanotCompose);
  1081. foreach ($gem_composeCost as $gemUid) {
  1082. self::RemoveGemInStore($gemUid);
  1083. }
  1084. foreach ($gem_composeIds as $gemTypeId) {
  1085. $composeGem = self::initGem($gemTypeId);
  1086. self::PutGemInStore($composeGem);
  1087. $composeArr[] = $composeGem->uid; //临时放这
  1088. }
  1089. }
  1090. TaskProc::OnComposeNumGem();
  1091. TaskProc::OnComposeNumGem_state();
  1092. UserProc::updateUserInfo();
  1093. return Resp::ok(array(
  1094. 'composeGemIds' => $composeArr,
  1095. 'store' => ctx()->store,
  1096. 'task' => ctx()->task,
  1097. ));
  1098. }
  1099. /**
  1100. * 该宝石是否可以参与合成,其他页镶嵌的,已经被锁的都不能参与
  1101. * @param type $uid
  1102. * @return bool
  1103. */
  1104. private static function GemIsCanCompose($uid) {
  1105. $ins_gem = new Ins_Gem($uid);
  1106. if ($ins_gem->isUnlock == 1) {
  1107. return false;
  1108. }
  1109. $isExist = true;
  1110. $equip = ctx()->store->equip;
  1111. foreach ($equip as $uid => $item) {
  1112. $arr = get_object_vars($item->gemSetSlot);
  1113. $values = array_values($arr);
  1114. if (in_array($uid, $values)) {
  1115. $isExist = false;
  1116. break;
  1117. }
  1118. }
  1119. return $isExist;
  1120. }
  1121. /**
  1122. * 装备宝石
  1123. * @return type
  1124. */
  1125. public static function GemSet() {
  1126. list($equipUid, $uid, $type, $replaceUId) = req()->paras; //宝石uid 手动的时候记得校验u $replaceUId宝石槽坑位id
  1127. my_Assert(StlUtil::dictHasProperty(ctx()->store->gemStore, $uid), ErrCode::user_store_NoItem);
  1128. my_Assert(StlUtil::dictHasProperty(ctx()->store->equip, $equipUid), ErrCode::user_store_NoEquip);
  1129. $ins_equip = new Ins_Equip(ctx()->store->equip->$equipUid);
  1130. $ins_gem = new Ins_Gem(ctx()->store->gemStore->$uid);
  1131. my_Assert($ins_equip->mo()->position == $ins_gem->mo()->position, ErrCode::user_store_PositionNotFit);
  1132. $gemSetSlotDic = $ins_equip->gemSetSlot;
  1133. $tag_index = 0;
  1134. $tag_gem = null;
  1135. foreach ($gemSetSlotDic as $slotId => $gemUid) {
  1136. if ($gemUid == 0) {
  1137. continue;
  1138. }
  1139. $gem = new Ins_Gem(ctx()->store->gemStore->$gemUid);
  1140. if ($gem->predicateMo()->uniqueKey == $ins_gem->predicateMo()->uniqueKey) {
  1141. $tag_index = $slotId;
  1142. $tag_gem = $gem;
  1143. break;
  1144. }
  1145. }
  1146. $mo = GameConfig::gem_slotposition_getItem($ins_equip->qual);
  1147. my_Assert(null != $mo, ErrCode::err_const_no);
  1148. switch ($type) {
  1149. case 1://镶嵌
  1150. my_Assert($tag_gem == null, ErrCode::user_store_GemCanotSet);
  1151. $go_index = 1;
  1152. for ($i = 1; $i <= $mo->initNum_slot + $mo->buyNum_slot; $i++) {
  1153. if (!StlUtil::dictHasProperty($gemSetSlotDic, $i)) {
  1154. //$gemSetSlotDic->$i = $ins_gem;
  1155. $go_index = $i;
  1156. break;
  1157. }
  1158. if ($gemSetSlotDic->$i == 0) {
  1159. $go_index = $i;
  1160. break;
  1161. }
  1162. }
  1163. $gemSetSlotDic->$go_index = $uid;
  1164. break;
  1165. case 2://替换
  1166. //满不满都高替低品阶
  1167. my_Assert(StlUtil::dictHasProperty($gemSetSlotDic, $replaceUId), ErrCode::user_store_NoExistGemReplace);
  1168. $gUid = $gemSetSlotDic->$replaceUId;
  1169. $replace_ins_Gem = new Ins_Gem(ctx()->store->gemStore->$gUid); //这个$replaceUId是坑位的index id
  1170. my_Assert($replace_ins_Gem->mo()->qual < $ins_gem->mo()->qual, ErrCode::user_store_NoExistGemReplace);
  1171. //$gemSetSlotDic->$replaceUId = $ins_gem;
  1172. $gemSetSlotDic->$replaceUId = $uid;
  1173. break;
  1174. case 3://手动
  1175. //my_Assert(count((array) $gemSetSlotDic) >= $mo->initNum_slot + $mo->buyNum_slot, ErrCode::user_store_GemCanotSet);
  1176. my_Assert(StlUtil::dictHasProperty($gemSetSlotDic, $replaceUId), ErrCode::user_store_NoExistGemReplace);
  1177. $gUid = $gemSetSlotDic->$replaceUId;
  1178. my_Assert(StlUtil::dictHasProperty($gemSetSlotDic, $replaceUId), ErrCode::user_store_NoExistGemReplace);
  1179. $replace_ins_Gem = new Ins_Gem(ctx()->store->gemStore->$gUid);
  1180. //$id = $replace_ins_Gem->uid;
  1181. if ($tag_gem != null) {//如果有u那
  1182. my_Assert($replace_ins_Gem->uid == $tag_gem->uid, ErrCode::user_store_SameGemCanotEquip); //点的不是u一样的,则提示同一件装备无法镶嵌多个技能相同的宝石 【错误】
  1183. //有U一样的,则点击正好是这个直接替换
  1184. //$gemSetSlotDic->$tag_index = $ins_gem;
  1185. $gemSetSlotDic->$tag_index = $uid;
  1186. } else {
  1187. // $go_index = 0;
  1188. // foreach ($gemSetSlotDic as $slotId => $gemUid) {
  1189. // if ($slotId == $replaceUId) {
  1190. // $go_index = $slotId;
  1191. // break;
  1192. // }
  1193. // }
  1194. //
  1195. // my_Assert($go_index > 0, ErrCode::user_store_NoExistGemReplace);
  1196. //$gemSetSlotDic->$go_index = $ins_gem;
  1197. $gemSetSlotDic->$replaceUId = $uid;
  1198. }
  1199. break;
  1200. case 4://不能
  1201. //1.小品阶替大品阶 或是 相等的,在不满的时候不允许 2. //满的 相等不允许替
  1202. my_Assert($uid == 0, ErrCode::user_store_SameGemCanotEquip); //点的不是u一样的,则提示同一件装备无法镶嵌多个技能相同的宝石 【错误】
  1203. break;
  1204. default:
  1205. break;
  1206. }
  1207. $ins_equip->gemSetSlot = $gemSetSlotDic;
  1208. ctx()->store(true)->equip->$equipUid = $ins_equip;
  1209. TaskProc::OnSetSpecialQualGem();
  1210. FightProc::Ranking_FightPower();
  1211. UserProc::updateUserInfo();
  1212. return Resp::ok(array(
  1213. 'gold' => 0,
  1214. 'store' => ctx()->store,
  1215. 'task' => ctx()->task,
  1216. ));
  1217. }
  1218. /**
  1219. * 卸下装备
  1220. * @return type
  1221. */
  1222. public static function GemRemove() {
  1223. list($uid) = req()->paras; //装备宝石id
  1224. $equips = ctx()->store->equip;
  1225. foreach ($equips as $eUid => $ins_equip) {
  1226. $dic = $ins_equip->gemSetSlot;
  1227. foreach ($dic as $slotId => $gemUid) {
  1228. if ($uid == $gemUid) {
  1229. ctx()->store->equip->$eUid->gemSetSlot->$slotId = 0;
  1230. break 2;
  1231. }
  1232. }
  1233. }
  1234. FightProc::Ranking_FightPower();
  1235. UserProc::updateUserInfo();
  1236. return Resp::ok(array(
  1237. 'gold' => 0,
  1238. 'store' => ctx()->store,));
  1239. }
  1240. /**
  1241. * 6404 升级装备
  1242. * @return type
  1243. */
  1244. public static function EquipUpgrade() {
  1245. list($uid) = req()->paras; //装备uid
  1246. my_Assert(StlUtil::dictHasProperty(ctx()->store->equip, $uid), ErrCode::user_store_NoEquip);
  1247. $ins_equip = new Ins_Equip(ctx()->store->equip->$uid);
  1248. my_Assert($ins_equip->level < $ins_equip->Equip_MaxLevel(), ErrCode::user_store_LevelLimit);
  1249. $mo = GameConfig::equip_levelupgrade_getItem($ins_equip->mo()->rarity, $ins_equip->qual, $ins_equip->mo()->position, $ins_equip->level);
  1250. my_Assert(null != $mo, ErrCode::err_const_no);
  1251. my_Assert(ctx()->baseInfo->gold >= $mo->needGold, ErrCode::notenough_gold_msg);
  1252. $costTuzhiId = GameConfig::equip_position_getItem($ins_equip->mo()->position)->costTuzhiId;
  1253. $tuzhiNum = 0;
  1254. if (StlUtil::dictHasProperty(ctx()->store->items, $costTuzhiId)) {
  1255. $tuzhiNum = ctx()->store->items->$costTuzhiId;
  1256. }
  1257. my_Assert($tuzhiNum >= $mo->needItemNum, ErrCode::notenough_item);
  1258. ctx()->store(true)->removeItem($costTuzhiId, $mo->needItemNum);
  1259. ctx()->base(true)->Consume_Gold($mo->needGold);
  1260. $ins_equip->level += 1;
  1261. ctx()->store->equip->$uid = $ins_equip;
  1262. TaskProc::OnAnyEquipUpLevel_X();
  1263. TaskProc::OnAllEquipUpLevel_X();
  1264. TaskProc::OnEquipLevelUpNum();
  1265. FightProc::Ranking_FightPower();
  1266. UserProc::updateUserInfo();
  1267. return Resp::ok(array(
  1268. 'gold' => ctx()->baseInfo->gold,
  1269. 'store' => ctx()->store,
  1270. 'task' => ctx()->task,
  1271. ));
  1272. }
  1273. /**
  1274. * 6405 单个装备部位一键升级
  1275. * @return type
  1276. */
  1277. public static function EquipUpgrade_MaxLv() {
  1278. list($uid) = req()->paras;
  1279. my_Assert(StlUtil::dictHasProperty(ctx()->store->equip, $uid), ErrCode::user_store_NoEquip);
  1280. $ins_equip = new Ins_Equip(ctx()->store->equip->$uid);
  1281. $maxLevel = $ins_equip->Equip_MaxLevel();
  1282. my_Assert($ins_equip->level < $ins_equip->Equip_MaxLevel(), ErrCode::user_store_LevelLimit);
  1283. $tuzhiId = GameConfig::equip_position_getItem($ins_equip->mo()->position)->costTuzhiId;
  1284. $itemNum_store = 0;
  1285. if (StlUtil::dictHasProperty(ctx()->store->items, $tuzhiId)) {
  1286. $itemNum_store = ctx()->store->items->$tuzhiId;
  1287. }
  1288. $up_Gold = 0;
  1289. $up_needItem = 0;
  1290. $up_lv = 0;
  1291. $noUp_gold = false;
  1292. $noUp_item = false;
  1293. $need_gold = 0;
  1294. $need_item = 0;
  1295. for ($i = $ins_equip->level; $i <= $maxLevel; $i++) {
  1296. $up_Gold += GameConfig::equip_levelupgrade_getItem($ins_equip->mo()->rarity, $ins_equip->qual, $ins_equip->mo()->position, $i)->needGold;
  1297. $up_needItem += GameConfig::equip_levelupgrade_getItem($ins_equip->mo()->rarity, $ins_equip->qual, $ins_equip->mo()->position, $i)->needItemNum;
  1298. if (ctx()->baseInfo->gold >= $up_Gold) {
  1299. $noUp_gold = true;
  1300. }
  1301. if ($itemNum_store >= $up_needItem) {
  1302. $noUp_item = true;
  1303. }
  1304. $up_lv = $i;
  1305. if (ctx()->baseInfo->gold >= $up_Gold && $itemNum_store >= $up_needItem) {
  1306. $need_gold = $up_Gold;
  1307. $need_item = $up_needItem;
  1308. continue;
  1309. }
  1310. break;
  1311. }
  1312. if ($up_lv == 0) {
  1313. my_Assert($noUp_gold, ErrCode::notenough_gold_msg);
  1314. my_Assert($noUp_item, ErrCode::notenough_item);
  1315. }
  1316. ctx()->base(true)->Consume_Gold($need_gold);
  1317. ctx()->store(true)->removeItem($tuzhiId, $need_item);
  1318. if ($up_lv > 0) {
  1319. ctx()->store->equip->$uid->level = $up_lv;
  1320. }
  1321. TaskProc::OnAnyEquipUpLevel_X();
  1322. TaskProc::OnAllEquipUpLevel_X();
  1323. TaskProc::OnEquipLevelUpNum();
  1324. FightProc::Ranking_FightPower();
  1325. UserProc::updateUserInfo();
  1326. return Resp::ok(array(
  1327. 'gold' => ctx()->baseInfo->gold,
  1328. 'store' => ctx()->store,
  1329. 'task' => ctx()->task,
  1330. ));
  1331. }
  1332. public static function AddItemInStore() {
  1333. list($rwdStr) = req()->paras; //mask = 1:表示战斗中掉落
  1334. $user = ctx();
  1335. $err = self::AddMultiItemInStore($rwdStr);
  1336. my_Assert(ErrCode::ok == $err, $err);
  1337. UserProc::updateUserInfo();
  1338. return Resp::ok(array(
  1339. //'gold' => $user->baseInfo->gold,
  1340. //'tili' => $user->baseInfo->tili,
  1341. //'cash' => $user->baseInfo->cash,
  1342. 'store' => $user->store));
  1343. }
  1344. static $reward = array();
  1345. static $reward_Gem = array();
  1346. static $reward_equip = array();
  1347. //static $reward_hero = array();
  1348. /**
  1349. * 具体奖励存入背包
  1350. * @param type $goodsStr
  1351. * @param type $src
  1352. */
  1353. public static function AddMultiItemInStore($goodsStr, $src = 0) {
  1354. if ($goodsStr == null) {
  1355. return;
  1356. }
  1357. $ary = explode(";", $goodsStr);
  1358. foreach ($ary as $value) {
  1359. $val = explode(",", $value);
  1360. my_Assert(count($val) > 1, "解析奖励字符串出错");
  1361. list($itemId, $num) = $val; # ID, 数量
  1362. $itemMo = GameConfig::item_getItem($itemId);
  1363. if ($itemMo->itemType != 701 && $itemMo->itemType != 201 && $itemMo->itemType != 502 && $itemMo->itemType != 101 && $src != 1) {
  1364. self::$reward[] = $value;
  1365. }
  1366. switch ($itemMo->itemType) {
  1367. case 1:
  1368. ctx()->baseInfo->Add_Gold($num);
  1369. //self::checkEquipUpgradeTip();//废弃
  1370. break;
  1371. case 2:
  1372. ctx()->baseInfo->Add_Cash($num);
  1373. break;
  1374. case 3:
  1375. ctx()->baseInfo->Add_tili($num);
  1376. break;
  1377. case 4:
  1378. ctx()->baseInfo->Add_Exp($num);
  1379. break;
  1380. case 100://图纸
  1381. case 103://钥匙
  1382. case 401://启灵石
  1383. case 301://洗练石
  1384. case 501://人物碎片
  1385. case 601://人身果
  1386. case 801://寻宝券
  1387. case 602://灵蛇果
  1388. case 802://灵蛇贺岁券
  1389. case 901:
  1390. self::PutItemsInStore($itemId, $num);
  1391. // if ($itemMo->itemType == 100) {//图纸
  1392. // self::checkEquipUpgradeTip();//废弃
  1393. // }
  1394. break;
  1395. case 502://角色卡
  1396. HeroProc::RoleCardUnlockHero($itemId, $num);
  1397. break;
  1398. case 201://宝石
  1399. for ($i = 0; $i < $num; $i++) {
  1400. $gem = self::initGem($itemId);
  1401. if ($src != 1) {
  1402. self::$reward_Gem[] = $gem->uid;
  1403. }
  1404. self::PutGemInStore($gem);
  1405. if ($src == Enum_StoreSourceType::ShopBox) {
  1406. SystemProc::GetGem_GreaterOrangeQual_ShopBox(req()->zoneid, ctx()->baseInfo->name, $gem->typeId);
  1407. }
  1408. }
  1409. break;
  1410. case 101:
  1411. //self::PutEquipInStore($itemId, $num);
  1412. for ($i = 0; $i < $num; $i++) {
  1413. FightProc::funUnlock_equip_firstTime();
  1414. $equip = self::initEquip($itemId);
  1415. $uid = $equip->uid;
  1416. ctx()->store(true)->equip->$uid = $equip;
  1417. self::$reward_equip[] = $uid;
  1418. }
  1419. break;
  1420. case 701://道具宝箱
  1421. for ($i = 0; $i < $num; $i++) {
  1422. self::DistributeItemsBox($itemId);
  1423. }
  1424. break;
  1425. default:
  1426. break;
  1427. }
  1428. }
  1429. }
  1430. /**
  1431. * 装备回存
  1432. * @param type $itemId
  1433. * @param type $num
  1434. */
  1435. public static function PutEquipInStore($itemId, $num) {
  1436. for ($i = 0; $i < $num; $i++) {
  1437. $equip = self::initEquip($itemId);
  1438. $uid = $equip->uid;
  1439. ctx()->store(true)->equip->$uid = $equip;
  1440. }
  1441. }
  1442. public static function initEquip($typeId, $uid = 0) {
  1443. if ($uid == 0) {
  1444. $uid = ctx()->store->nextUID();
  1445. }
  1446. $ins_equip = new Ins_Equip();
  1447. $ins_equip->uid = $uid;
  1448. $ins_equip->typeId = $typeId;
  1449. $ins_equip->qual = GameConfig::equip_getItem($typeId)->qual;
  1450. return $ins_equip;
  1451. }
  1452. public static function PutItemsInStore($itemId, $num) {
  1453. $items = ctx()->store->items;
  1454. if (StlUtil::dictHasProperty($items, $itemId)) {
  1455. $items->$itemId += $num;
  1456. } else {
  1457. $items->$itemId = $num;
  1458. }
  1459. ctx()->store->items = $items;
  1460. }
  1461. /**
  1462. * 拆分宝箱盒子
  1463. * @param type $reward
  1464. */
  1465. public static function DistributeItemsBox($itemId) {
  1466. $itemBoxMo = GameConfig::item_2023_box_getItem($itemId);
  1467. my_Assert($itemBoxMo != null, ErrCode::err_const_no);
  1468. if ($itemBoxMo->type == 1) {
  1469. $reward = self::Distribute_Rewards($itemBoxMo->contents);
  1470. self::AddMultiItemInStore($reward);
  1471. } else {
  1472. self::AddMultiItemInStore($itemBoxMo->contents);
  1473. }
  1474. }
  1475. public static function Distribute_Rewards($contents) {
  1476. $strList = explode(';', $contents);
  1477. $numList = explode('-', $strList[0]);
  1478. $randNum = rand($numList[0], $numList[1]);
  1479. $ctxList = explode(',', $strList[1]);
  1480. $per = 0;
  1481. foreach ($ctxList as $value) {
  1482. $ctx = explode(':', $value);
  1483. $per += $ctx[1];
  1484. }
  1485. $reward = "";
  1486. for ($i = 0; $i < $randNum; $i++) {
  1487. $ctxPer = rand(1, $per);
  1488. $start = 0;
  1489. $end = 0;
  1490. $id = 0;
  1491. foreach ($ctxList as $value) {
  1492. $ctx = explode(':', $value);
  1493. $end += $ctx[1];
  1494. if ($ctxPer > $start && $ctxPer <= $end) {
  1495. $id = $ctx[0];
  1496. break;
  1497. }
  1498. $start = $end;
  1499. }
  1500. if ($id != 0) {
  1501. $str = $id . ',1';
  1502. if ($reward == "") {
  1503. $reward = $str;
  1504. } else {
  1505. $reward = $reward . ';' . $str;
  1506. }
  1507. }
  1508. }
  1509. return $reward;
  1510. }
  1511. // public static function PutEquipInStore($equipId, $num) {
  1512. // if ($equipId == 0) {
  1513. // return;
  1514. // }
  1515. // $n = count((array) ctx()->store->equip) + 1;
  1516. //
  1517. // for ($index = 0; $index < $num; $index++) {
  1518. // $Equip = new Ins_Equip();
  1519. // $Equip->uid = $n;
  1520. // $Equip->typeId = $equipId;
  1521. // $Equip->qual = GameConfig::equip_getItem($equipId)->qual;
  1522. // ctx()->store->equip->$n = $Equip;
  1523. // $n += 1;
  1524. // }
  1525. // }
  1526. /**
  1527. * 得到金币或是图纸的时候校验下,是否满足装备升级条件,满足则tip字段设置为1 废弃
  1528. */
  1529. // public static function checkEquipUpgradeTip() {
  1530. // $equipDic = ctx()->store->equipPosition;
  1531. // if ($equipDic != null) {
  1532. // foreach ($equipDic as $k => &$equip) {
  1533. // $equip = new Ins_EquipPosition($equip);
  1534. // $lvMo = GameConfig::equip_levelupgrade_getItem($equip->level);
  1535. // $needGold = $lvMo->needGold;
  1536. // $needItemNum = $lvMo->needItemNum;
  1537. // $neeItemId = $equip->mo()->costTuzhiId;
  1538. //
  1539. // if (ctx()->baseInfo->gold >= $needGold && StlUtil::dictHasProperty(ctx()->store->items, $neeItemId) && ctx()->store->items->$neeItemId >= $needItemNum) {
  1540. // $equipDic->$k->tip = 1; //绿点是每次得到金币或是图纸了,只要满足升级条件都变绿
  1541. // }
  1542. // }
  1543. // }
  1544. // ctx()->store->equipPosition = $equipDic;
  1545. // }
  1546. /**
  1547. * 新宝石入库
  1548. */
  1549. public static function PutGemIdInStore($id, $num = 1) {
  1550. for ($i = 0; $i < $num; $i++) {
  1551. $gem = self::initGem($id);
  1552. $length = $gem->uid;
  1553. ctx()->store->gemStore->$length = $gem;
  1554. }
  1555. }
  1556. public static function PutGemInStore($gem, $num = 1) {
  1557. for ($i = 0; $i < $num; $i++) {
  1558. $length = $gem->uid;
  1559. ctx()->store->gemStore->$length = $gem;
  1560. }
  1561. }
  1562. public static function initGem($id) {
  1563. $length = ctx()->store->gemLength;
  1564. $length += 1;
  1565. $gem = new Ins_Gem();
  1566. $gem->uid = $length;
  1567. $gem->typeId = $id;
  1568. $gem->predicateId = self::RandomGemPredicateId($id);
  1569. $tag = self::CheckNewGemTip($gem);
  1570. $gem->isNew = $tag;
  1571. ctx()->store->gemLength = $length;
  1572. return $gem;
  1573. }
  1574. /**
  1575. * 从仓库移除宝石
  1576. */
  1577. public static function RemoveGemInStore($uid) {
  1578. if (StlUtil::dictHasProperty(ctx()->store->gemStore, $uid)) {
  1579. StlUtil::dictRemove(ctx()->store->gemStore, $uid);
  1580. }
  1581. return 0;
  1582. }
  1583. /**
  1584. * 新宝石随机词条 临时等刚哥
  1585. */
  1586. public static function RandomGemPredicateId($id) {
  1587. $mo = GameConfig::gem_getItem($id);
  1588. my_Assert(null != $mo, "找不到宝石{$id}的配置数据");
  1589. if ($mo->isfixed_predicateId == 1) {
  1590. return $mo->predicateId;
  1591. }
  1592. $posId = $mo->position;
  1593. $qual = $mo->qual;
  1594. $arr = array();
  1595. $predicateMo = GameConfig::predicate();
  1596. foreach ($predicateMo as $key => $value) {
  1597. if ($value->positions != null) {
  1598. $list = explode(',', $value->positions);
  1599. if ($value->qual == $qual && in_array($posId, $list) && $value->attachTarget == "gem") {
  1600. $arr[] = $value->id;
  1601. }
  1602. }
  1603. }
  1604. if (count($arr) <= 0) {
  1605. return 40;
  1606. }
  1607. my_Assert(count($arr) > 0, "宝石没有对应词条信息");
  1608. $n = mt_rand(0, count($arr) - 1);
  1609. return $arr[$n];
  1610. //return 40;
  1611. }
  1612. /**
  1613. * 新宝石提示
  1614. */
  1615. public static function CheckNewGemTip($gem) {
  1616. $gemStore = ctx()->store->gemStore;
  1617. $tag = false;
  1618. foreach ($gemStore as $k => $ins_gem) {
  1619. if ($ins_gem->typeId == $gem->typeId && $ins_gem->predicateId == $gem->predicateId) {
  1620. $tag = true;
  1621. break;
  1622. }
  1623. }
  1624. return $tag == true ? 0 : 1;
  1625. }
  1626. //临时代码
  1627. // public static function InitGemInfo() {
  1628. // if(count((array)ctx()->store->gemStore) > 0){
  1629. // return;
  1630. // }
  1631. //
  1632. // $index = 0;
  1633. // $gem = GameConfig::gem();
  1634. //
  1635. // for ($i = 1; $i <=21; $i++) {
  1636. // foreach ($gem as $key => $value) {
  1637. // if($value->id == $i){
  1638. // self::PutGemInStore($value->typeId);
  1639. // }
  1640. //
  1641. // }
  1642. // }
  1643. //
  1644. //
  1645. //
  1646. //
  1647. // }
  1648. }