StoreProc.php 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  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. default:
  24. Err(ErrCode::cmd_err);
  25. }
  26. }
  27. public static function AddItemInStore() {
  28. list($rwdStr) = req()->paras; //mask = 1:表示战斗中掉落
  29. $user = ctx();
  30. $err = self::AddMultiItemInStore($rwdStr);
  31. my_Assert(ErrCode::ok == $err, $err);
  32. UserProc::updateUserInfo();
  33. return Resp::ok(array(
  34. //'gold' => $user->baseInfo->gold,
  35. //'tili' => $user->baseInfo->tili,
  36. //'cash' => $user->baseInfo->cash,
  37. 'store' => $user->store));
  38. }
  39. /**
  40. * 具体奖励存入背包
  41. * @param type $goodsStr
  42. * @param type $src
  43. */
  44. public static function AddMultiItemInStore($goodsStr, $src = 1) {
  45. $ary = explode(";", $goodsStr);
  46. foreach ($ary as $value) {
  47. $val = explode(",", $value);
  48. my_Assert(count($val) > 1, "解析奖励字符串出错");
  49. list($itemId, $num) = $val; # ID, 数量
  50. $itemMo = GameConfig::item_getItem($itemId);
  51. switch ($itemMo->itemType) {
  52. case 1:
  53. self::PutItemsInStore($itemId, $num);
  54. break;
  55. case 2:
  56. self::PutEquipInStore($itemId, $num);
  57. break;
  58. default:
  59. break;
  60. }
  61. }
  62. }
  63. public static function PutItemsInStore($itemId,$num) {
  64. $items = ctx()->store->items;
  65. if(StlUtil::dictHasProperty($items, $itemId)){
  66. $items->$itemId += $num;
  67. } else {
  68. $items->$itemId = $num;
  69. }
  70. ctx()->store->items = $items;
  71. }
  72. public static function PutEquipInStore($equipId,$num) {
  73. $n = count((array)ctx()->store->equip);
  74. for ($index = 0; $index < $num; $index++) {
  75. $Equip = new Ins_Equip();
  76. ctx()->store->equip->$n = $Equip;
  77. }
  78. }
  79. }