StoreProc.php 6.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205
  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_equip: # 6402
  24. return StoreProc::equip();
  25. case CmdCode::cmd_store_RemoveEquip: #6403卸下装备
  26. return StoreProc::RemoveEquip();
  27. case CmdCode::cmd_store_equipUpgrade: # 6403
  28. return StoreProc::equipUpgrade();
  29. case CmdCode::cmd_store_equipUpgrade_MaxLv: # 6404
  30. return StoreProc::equipUpgrade_MaxLv();
  31. default:
  32. Err(ErrCode::cmd_err);
  33. }
  34. }
  35. /**
  36. * 装备
  37. * @return type
  38. */
  39. public static function equip() {
  40. list($uid) = req()->paras;
  41. $user = ctx();
  42. my_Assert(StlUtil::dictHasProperty($user->store->equip, $uid), ErrCode::user_store_NoEquip);
  43. $mo = GameConfig::equip_getItem($user->store->equip->$uid->typeId);
  44. my_Assert($mo != null, ErrCode::err_const_no);
  45. $posId = $mo->position;
  46. $heroId = $user->heros->CurrentHeroId;
  47. $user->store->equip->$uid->posId = $posId;
  48. if($user->heros->Dic->$heroId->equipPosition->$posId > 0){
  49. $oldUid = $user->heros->Dic->$heroId->equipPosition->$posId;
  50. $user->store->equip->$oldUid->posId = 0;
  51. }
  52. $user->heros->Dic->$heroId->equipPosition->$posId = $uid;
  53. UserProc::updateUserInfo();
  54. return Resp::ok(array(
  55. 'heros' => $user->heros,
  56. 'store' => $user->store,));
  57. }
  58. /**
  59. * 卸下装备
  60. * @return type
  61. */
  62. public static function RemoveEquip() {
  63. list($posId) = req()->paras;
  64. $user = ctx();
  65. $heroId = $user->heros->CurrentHeroId;
  66. if($user->heros->Dic->$heroId->equipPosition->$posId > 0){
  67. $oldUid = $user->heros->Dic->$heroId->equipPosition->$posId;
  68. $user->store->equip->$oldUid->posId = 0;
  69. $user->heros->Dic->$heroId->equipPosition->$posId = 0;
  70. }
  71. UserProc::updateUserInfo();
  72. return Resp::ok(array(
  73. 'heros' => $user->heros,
  74. 'store' => $user->store,));
  75. }
  76. /**
  77. * 升级装备
  78. * @return type
  79. */
  80. public static function equipUpgrade() {
  81. list($uid) = req()->paras; //mask = 1:表示战斗中掉落
  82. $user = ctx();
  83. $lv = $user->store->equip->$uid->level;
  84. $Mo = GameConfig::equip_levelupgrade_getItem($lv+1);
  85. my_Assert($user->baseInfo->gold >= $Mo->needGold, ErrCode::notenough_gold_msg);
  86. $typeId = GameConfig::equip_getItem($user->store->equip->$uid->typeId)->needTuzhiId;//图纸
  87. $num = $Mo->needItemNum;
  88. if (StlUtil::dictHasProperty($user->store->items,$typeId) && $user->store->items->$typeId >= $num)
  89. {
  90. $user->store->removeItem($typeId, $num);
  91. }
  92. $user->store->equip->$uid->level += 1;
  93. UserProc::updateUserInfo();
  94. return Resp::ok(array(
  95. 'gold' => $user->baseInfo->gold,
  96. 'store' => $user->store));
  97. }
  98. /**
  99. * 装备一键升级
  100. * @return type
  101. */
  102. public static function equipUpgrade_MaxLv() {
  103. list($uid) = req()->paras; //mask = 1:表示战斗中掉落
  104. $user = ctx();
  105. UserProc::updateUserInfo();
  106. return Resp::ok(array(
  107. //'gold' => $user->baseInfo->gold,
  108. //'tili' => $user->baseInfo->tili,
  109. //'cash' => $user->baseInfo->cash,
  110. 'store' => $user->store));
  111. }
  112. public static function AddItemInStore() {
  113. list($rwdStr) = req()->paras; //mask = 1:表示战斗中掉落
  114. $user = ctx();
  115. $err = self::AddMultiItemInStore($rwdStr);
  116. my_Assert(ErrCode::ok == $err, $err);
  117. UserProc::updateUserInfo();
  118. return Resp::ok(array(
  119. //'gold' => $user->baseInfo->gold,
  120. //'tili' => $user->baseInfo->tili,
  121. //'cash' => $user->baseInfo->cash,
  122. 'store' => $user->store));
  123. }
  124. /**
  125. * 具体奖励存入背包
  126. * @param type $goodsStr
  127. * @param type $src
  128. */
  129. public static function AddMultiItemInStore($goodsStr, $src = 1) {
  130. $ary = explode(";", $goodsStr);
  131. foreach ($ary as $value) {
  132. $val = explode(",", $value);
  133. my_Assert(count($val) > 1, "解析奖励字符串出错");
  134. list($itemId, $num) = $val; # ID, 数量
  135. $itemMo = GameConfig::item_getItem($itemId);
  136. switch ($itemMo->itemType) {
  137. case 1:
  138. self::PutItemsInStore($itemId, $num);
  139. break;
  140. case 2:
  141. self::PutEquipInStore($itemId, $num);
  142. break;
  143. default:
  144. break;
  145. }
  146. }
  147. }
  148. public static function PutItemsInStore($itemId,$num) {
  149. $items = ctx()->store->items;
  150. if(StlUtil::dictHasProperty($items, $itemId)){
  151. $items->$itemId += $num;
  152. } else {
  153. $items->$itemId = $num;
  154. }
  155. ctx()->store->items = $items;
  156. }
  157. public static function PutEquipInStore($equipId,$num) {
  158. $n = count((array)ctx()->store->equip);
  159. for ($index = 0; $index < $num; $index++) {
  160. $Equip = new Ins_Equip();
  161. ctx()->store->equip->$n = $Equip;
  162. }
  163. }
  164. }