MapProc.php 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335
  1. <?php
  2. namespace loyalsoft;
  3. /**
  4. * Description of MapProc
  5. * 地图数据处理逻辑
  6. * @author gwang
  7. */
  8. class MapProc {
  9. /**
  10. * 地图处理逻辑分发
  11. * 所有的Proc中必须有这样一个方法
  12. */
  13. static function procMain() {
  14. switch (req()->cmd) {
  15. case CmdCode::map_EnterFootHold: # [7501] 进入地图
  16. return self::EnterFootHold();
  17. case CmdCode::map_FixUpTransmission: # [7502] 开启传送阵
  18. return self::FixUpTransmision();
  19. case CmdCode::map_UpdateExplorerationProgress: # [7503] 更新探索进度
  20. return self::UpdateExplorationProgress();
  21. case CmdCode::map_UnlockMap: # [7504] 解锁地图
  22. return self::UnlockMap();
  23. // case CmdCode::map_getUnlockInfoList: # [7505] 获取mapid下已经解锁的列表
  24. // return self::getUnlockInfoList();
  25. case CmdCode::map_unlockInfoSva: # [7505] 保存mapid下已经解锁的
  26. return self::unlockInfoSva();
  27. case CmdCode::map_reviceExplorerReward: # [7506] 领取探索奖励cmd_store_huichengQuanUse
  28. return self::reviceExplorerReward();
  29. case CmdCode::map_huichengQuanUse: # [7507]
  30. return self::huichengQuanUse();
  31. case CmdCode::map_huichengQuanEnd: # [7508]
  32. return self::huichengQuanEnd();
  33. default: # err: 未知的命令码
  34. return Resp::err(ErrCode::cmd_err);
  35. }
  36. }
  37. /**
  38. * [7507]
  39. * @return Resp
  40. */
  41. public static function huichengQuanUse() {
  42. $mapId = req()->paras[0]; #使用传送门的场景的地图id
  43. $x = req()->paras[1]; # 提取参数
  44. $y = req()->paras[2];
  45. $z = req()->paras[3];
  46. $newMap = ctx()->newMap(true);
  47. //$curMapId = $newMap->curMapId;
  48. $itemId = 0;
  49. $dic = ctx()->store()->items;
  50. foreach ($dic as $id => $num) {
  51. $subType = GameConfig::item_base_getItem($id)->subType;
  52. if($subType == 344){
  53. $itemId = $id;
  54. break;
  55. }
  56. }
  57. my_Assert($itemId != 0, ErrCode::err_const_no);
  58. StoreProc::removeItemFromStore(ctx()->store, $itemId);
  59. //找据点,地图在gate_zone里有配置;没有的就算是副本--暂时先这么着
  60. // $gateZone = GameConfig::gate_zone();
  61. // my_Assert($gateZone != null, ErrCode::err_const_no);
  62. // foreach ($gateZone as $zoneid => $val) {
  63. // $list = explode(',', $val->contains);
  64. // if(in_array($curMapId, $list)){
  65. // $mid = $list[0];
  66. // break;
  67. // }
  68. // }
  69. $curFootholdId = $newMap->curFootholdId;
  70. if($curFootholdId == null){
  71. $curFootholdId = 503099;
  72. }
  73. $newMap->curMapId = $curFootholdId;
  74. $data = new Ins_ChuansongzhenMapData();
  75. $data->mapId = $curFootholdId;
  76. $data->lastMapId = $mapId;
  77. $data->position_x = $x;
  78. $data->position_y = $y;
  79. $data->position_z = $z;
  80. $newMap->huichengquanRecord->$mapId = $data;
  81. $newMap->lastMapId = $mapId;
  82. ctx()->newMap = $newMap;
  83. UserProc::updateUserInfo();
  84. return Resp::ok(
  85. array("newMap" => $newMap,)
  86. );
  87. }
  88. /**
  89. * [7508] 回城券的传送阵结束
  90. * @return Resp
  91. */
  92. public static function huichengQuanEnd() {
  93. //$mapid = req()->paras[0]; # 提取参数
  94. $newMap = ctx()->newMap();
  95. $curMapId = $newMap->curMapId;
  96. $lastMapid = $newMap->lastMapId;
  97. // $lastMapid = $curMapId;
  98. // $gateZone = GameConfig::gate_zone();
  99. // my_Assert($gateZone != null, ErrCode::err_const_no);
  100. // foreach ($gateZone as $zoneid => $val) {
  101. // $list = explode(',', $val->contains);
  102. // if(in_array($curMapId, $list)){
  103. // $lastMapid = $list[0];
  104. // break;
  105. // }
  106. // }
  107. if(StlUtil::dictHasProperty($newMap->huichengquanRecord, $lastMapid)){
  108. StlUtil::dictRemove($newMap->huichengquanRecord, $lastMapid);
  109. }
  110. ctx()->newMap = $newMap;
  111. UserProc::updateUserInfo();
  112. return Resp::ok(
  113. array("newMap" => $newMap,)
  114. );
  115. }
  116. /**
  117. * [7506] 领取探索奖励
  118. * @return Resp
  119. */
  120. public static function reviceExplorerReward() {
  121. $mapid = req()->paras[0]; # 提取参数
  122. $newMap = ctx()->newMap();
  123. $newMap->unlockedFootholds->$mapid->exploreRewardGeted = true;
  124. $cost = GameConfig::gate_getItem($mapid)->exploreReward;
  125. StoreProc::AddMultiItemInStore($cost);
  126. ctx()->newMap = $newMap;
  127. UserProc::updateUserInfo();
  128. return Resp::ok(
  129. array("newMap" => $newMap, "cost" => $cost,)
  130. );
  131. }
  132. /**
  133. * 7505
  134. * @return Resp
  135. */
  136. public static function unlockInfoSva() {
  137. $unlockStr = req()->paras[0]; # 提取参数
  138. $newMap = ctx()->newMap();
  139. if (!StlUtil::dictHasProperty($newMap, 'unlockMapTypeList')) {
  140. $newMap->unlockMapTypeList = new \stdClass();
  141. }
  142. $mapid = explode('_', $unlockStr)[0];
  143. $type = explode('_', $unlockStr)[1];
  144. $typeid = explode('_', $unlockStr)[2];
  145. if (!StlUtil::dictHasProperty($newMap->unlockMapTypeList, $mapid)) {
  146. $newMap->unlockMapTypeList->$mapid = array();
  147. }
  148. $tag = 1;
  149. $tylist = $newMap->unlockMapTypeList->$mapid;
  150. foreach ($tylist as $str) {
  151. $slist = explode('_', $str);
  152. if ($slist[0] == $mapid && $slist[1] == $type && $slist[2] == $typeid) {
  153. $tag = 0;
  154. break;
  155. }
  156. }
  157. $num = 0;
  158. if ($tag) {
  159. $newMap->unlockMapTypeList->$mapid[] = $unlockStr;
  160. my_Assert(StlUtil::dictHasProperty($newMap->unlockedFootholds, $mapid), ErrCode::map_Unlocked);
  161. $newMap->curMapId = $mapid;
  162. $arr = self::countFootHoldExplorerNum($mapid, $type, $typeid, $newMap);
  163. $explorerNum = $arr[0];
  164. $num = $arr[1];
  165. $newMap->unlockedFootholds->$mapid->curExploreProgress = $explorerNum;
  166. if ($type == Enum_ExploreType::Npc && $newMap->unlockedFootholds->$mapid->transmissionIsOk == false) {
  167. $subtype = GameConfig::npc_getItem($typeid)->subtype;
  168. if ($subtype == Enum_ExploreSubType::Teleporter) {//传送带
  169. $newMap->unlockedFootholds->$mapid->transmissionIsOk = true;
  170. }
  171. }
  172. $mapArr = GameConfig::map_explorer_getItemArray($mapid);
  173. foreach ($mapArr as $mapItem) {
  174. $paras = explode(',', $mapItem->paras);
  175. if($mapItem->cmd == $type && $paras[0] == $typeid){
  176. ctx()->base(true)->Add_Exp($mapItem->exp);
  177. break;
  178. }
  179. }
  180. }
  181. ctx()->newMap = $newMap;
  182. UserProc::updateUserInfo();
  183. return Resp::ok(array("newMap" => $newMap, "tag" => $tag, 'num' => $num,"exp"=> ctx()->baseInfo->xp,"maxXp"=> ctx()->baseInfo->maxXp,"level"=> ctx()->baseInfo->level,));
  184. }
  185. /*
  186. * 计算探索度值
  187. */
  188. public static function countFootHoldExplorerNum($mapid, $type, $id, $newMap) {
  189. $explorer = 0;
  190. $num = 0;
  191. $retArr = array();
  192. if (StlUtil::dictHasProperty($newMap->unlockMapTypeList, $mapid)) {
  193. $list = $newMap->unlockMapTypeList->$mapid;
  194. $mapList = GameConfig::map_explorer_getItemArray($mapid);
  195. $tempList = array();
  196. if ($mapList != null) {
  197. foreach ($mapList as $item) {
  198. if ($item->paras == null) {
  199. continue;
  200. }
  201. $cmd = $item->cmd;
  202. $parasList = explode(',', $item->paras);
  203. if ($type == $cmd && $id == $parasList[0]) {
  204. $num = $parasList[1];
  205. }
  206. foreach ($list as $para) {
  207. $strList = explode('_', $para);
  208. $tempStr = $strList[1] . '-' . $strList[2];
  209. if (in_array($tempStr, $tempList)) {
  210. continue;
  211. }
  212. if ($strList[1] == $cmd && $strList[2] == $parasList[0]) {
  213. $tempList[] = $tempStr;
  214. $explorer += $parasList[1];
  215. }
  216. }
  217. }
  218. }
  219. }
  220. $retArr[] = $explorer;
  221. $retArr[] = $num;
  222. return $retArr;
  223. }
  224. /**
  225. * 7504 解锁地图
  226. * @return Resp
  227. */
  228. public static function UnlockMap() {
  229. $targetMapId = req()->paras[0]; # 提取参数
  230. $newMap = ctx()->newMap();
  231. # 检查目标地图是否已经解锁
  232. my_Assert(!isset($newMap->unlockedFootholds->$targetMapId), ErrCode::map_Unlocked);
  233. $mo = GameConfig::gate_getItem($targetMapId);
  234. $footHold = new Ins_FootHold();
  235. $footHold->mapId = $mo->gateId;
  236. $footHold->curMapType = $mo->mapType;
  237. $this->unlockedFootholds->$targetMapId = $footHold; # 添加解锁据点数据
  238. ctx()->newMap = $newMap;
  239. UserProc::updateUserInfo();
  240. return Resp::ok($newMap);
  241. }
  242. /**
  243. * 7501 进入据点
  244. * @return Resp
  245. */
  246. public static function EnterFootHold() {
  247. $targetMapId = req()->paras[0]; # 提取参数
  248. $newMap = ctx()->newMap();
  249. if(!StlUtil::dictHasProperty($newMap->unlockedFootholds,$targetMapId)){
  250. $mo = GameConfig::gate_getItem($targetMapId);
  251. $footHold = new Ins_FootHold();
  252. $footHold->mapId = $mo->gateId;
  253. $footHold->curMapType = $mo->mapType;
  254. $newMap->unlockedFootholds->$targetMapId = $footHold; # 初始化解锁新手村据点数据
  255. }
  256. # 检查目标地图是否已经解锁
  257. my_Assert(isset($newMap->unlockedFootholds->$targetMapId), ErrCode::map_NotUnlocked);
  258. $newMap->curMapId = $targetMapId;
  259. $gateZone = GameConfig::gate_zone();
  260. my_Assert($gateZone != null, ErrCode::err_const_no);
  261. foreach ($gateZone as $zoneid => $val) {
  262. $list = explode(',', $val->contains);
  263. if(in_array($targetMapId, $list)){
  264. $mid = $list[0];
  265. break;
  266. }
  267. }
  268. if($mid != null){//更新据点id
  269. $newMap->curFootholdId = $mid;
  270. }
  271. ctx()->newMap = $newMap;
  272. UserProc::updateUserInfo();
  273. return Resp::ok($newMap);
  274. }
  275. /**
  276. * 7502 开启传送阵
  277. * @return Resp
  278. */
  279. public static function FixUpTransmision() {
  280. }
  281. /**
  282. * 7503 更新探索进度
  283. * @return Resp
  284. */
  285. public static function UpdateExplorationProgress() {
  286. }
  287. }