MapProc.php 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333
  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. // $zoneId = GameConfig::map_scene_getItem($curMapId)->zoneId;
  97. // $item = GameConfig::map_scene_zoneid_getItemArray($zoneId)[0];
  98. $lastMapid = $curMapId;
  99. $gateZone = GameConfig::gate_zone();
  100. my_Assert($gateZone != null, ErrCode::err_const_no);
  101. foreach ($gateZone as $zoneid => $val) {
  102. $list = explode(',', $val->contains);
  103. if(in_array($curMapId, $list)){
  104. $lastMapid = $list[0];
  105. break;
  106. }
  107. }
  108. if(StlUtil::dictHasProperty($newMap->huichengquanRecord, $lastMapid)){
  109. StlUtil::dictRemove($newMap->huichengquanRecord, $lastMapid);
  110. }
  111. ctx()->newMap = $newMap;
  112. UserProc::updateUserInfo();
  113. return Resp::ok(
  114. array("newMap" => $newMap,)
  115. );
  116. }
  117. /**
  118. * [7506] 领取探索奖励
  119. * @return Resp
  120. */
  121. public static function reviceExplorerReward() {
  122. $mapid = req()->paras[0]; # 提取参数
  123. $newMap = ctx()->newMap();
  124. $newMap->unlockedFootholds->$mapid->exploreRewardGeted = true;
  125. $cost = GameConfig::gate_getItem($mapid)->exploreReward;
  126. StoreProc::AddMultiItemInStore($cost);
  127. ctx()->newMap = $newMap;
  128. UserProc::updateUserInfo();
  129. return Resp::ok(
  130. array("newMap" => $newMap, "cost" => $cost,)
  131. );
  132. }
  133. /**
  134. * 7505
  135. * @return Resp
  136. */
  137. public static function unlockInfoSva() {
  138. $unlockStr = req()->paras[0]; # 提取参数
  139. $newMap = ctx()->newMap();
  140. if (!StlUtil::dictHasProperty($newMap, 'unlockMapTypeList')) {
  141. $newMap->unlockMapTypeList = new \stdClass();
  142. }
  143. $mapid = explode('_', $unlockStr)[0];
  144. $type = explode('_', $unlockStr)[1];
  145. $typeid = explode('_', $unlockStr)[2];
  146. if (!StlUtil::dictHasProperty($newMap->unlockMapTypeList, $mapid)) {
  147. $newMap->unlockMapTypeList->$mapid = array();
  148. }
  149. $tag = 1;
  150. $tylist = $newMap->unlockMapTypeList->$mapid;
  151. foreach ($tylist as $str) {
  152. $slist = explode('_', $str);
  153. if ($slist[0] == $mapid && $slist[1] == $type && $slist[2] == $typeid) {
  154. $tag = 0;
  155. break;
  156. }
  157. }
  158. $num = 0;
  159. if ($tag) {
  160. $newMap->unlockMapTypeList->$mapid[] = $unlockStr;
  161. my_Assert(StlUtil::dictHasProperty($newMap->unlockedFootholds, $mapid), ErrCode::map_Unlocked);
  162. $newMap->curMapId = $mapid;
  163. $arr = self::countFootHoldExplorerNum($mapid, $type, $typeid, $newMap);
  164. $explorerNum = $arr[0];
  165. $num = $arr[1];
  166. $newMap->unlockedFootholds->$mapid->curExploreProgress = $explorerNum;
  167. if ($type == Enum_ExploreType::Npc && $newMap->unlockedFootholds->$mapid->transmissionIsOk == false) {
  168. $subtype = GameConfig::npc_getItem($typeid)->subtype;
  169. if ($subtype == Enum_ExploreSubType::Teleporter) {//传送带
  170. $newMap->unlockedFootholds->$mapid->transmissionIsOk = true;
  171. }
  172. }
  173. $mapArr = GameConfig::map_explorer_getItemArray($mapid);
  174. foreach ($mapArr as $mapItem) {
  175. $paras = explode(',', $mapItem->paras);
  176. if($mapItem->cmd == $type && $paras[0] == $typeid){
  177. ctx()->base(true)->Add_Exp($mapItem->exp);
  178. break;
  179. }
  180. }
  181. }
  182. ctx()->newMap = $newMap;
  183. UserProc::updateUserInfo();
  184. return Resp::ok(array("newMap" => $newMap, "tag" => $tag, 'num' => $num,"exp"=> ctx()->baseInfo->xp,"maxXp"=> ctx()->baseInfo->maxXp,"level"=> ctx()->baseInfo->level,));
  185. }
  186. /*
  187. * 计算探索度值
  188. */
  189. public static function countFootHoldExplorerNum($mapid, $type, $id, $newMap) {
  190. $explorer = 0;
  191. $num = 0;
  192. $retArr = array();
  193. if (StlUtil::dictHasProperty($newMap->unlockMapTypeList, $mapid)) {
  194. $list = $newMap->unlockMapTypeList->$mapid;
  195. $mapList = GameConfig::map_explorer_getItemArray($mapid);
  196. $tempList = array();
  197. if ($mapList != null) {
  198. foreach ($mapList as $item) {
  199. if ($item->paras == null) {
  200. continue;
  201. }
  202. $cmd = $item->cmd;
  203. $parasList = explode(',', $item->paras);
  204. if ($type == $cmd && $id == $parasList[0]) {
  205. $num = $parasList[1];
  206. }
  207. foreach ($list as $para) {
  208. $strList = explode('_', $para);
  209. $tempStr = $strList[1] . '-' . $strList[2];
  210. if (in_array($tempStr, $tempList)) {
  211. continue;
  212. }
  213. if ($strList[1] == $cmd && $strList[2] == $parasList[0]) {
  214. $tempList[] = $tempStr;
  215. $explorer += $parasList[1];
  216. }
  217. }
  218. }
  219. }
  220. }
  221. $retArr[] = $explorer;
  222. $retArr[] = $num;
  223. return $retArr;
  224. }
  225. /**
  226. * 7504 解锁地图
  227. * @return Resp
  228. */
  229. public static function UnlockMap() {
  230. $targetMapId = req()->paras[0]; # 提取参数
  231. $newMap = ctx()->newMap();
  232. # 检查目标地图是否已经解锁
  233. my_Assert(!isset($newMap->unlockedFootholds->$targetMapId), ErrCode::map_Unlocked);
  234. $mo = GameConfig::gate_getItem($targetMapId);
  235. $footHold = new Ins_FootHold();
  236. $footHold->mapId = $mo->gateId;
  237. $footHold->curMapType = $mo->mapType;
  238. $this->unlockedFootholds->$targetMapId = $footHold; # 添加解锁据点数据
  239. ctx()->newMap = $newMap;
  240. UserProc::updateUserInfo();
  241. return Resp::ok($newMap);
  242. }
  243. /**
  244. * 7501 进入据点
  245. * @return Resp
  246. */
  247. public static function EnterFootHold() {
  248. $targetMapId = req()->paras[0]; # 提取参数
  249. $newMap = ctx()->newMap();
  250. if(!StlUtil::dictHasProperty($newMap->unlockedFootholds,$targetMapId)){
  251. $mo = GameConfig::gate_getItem($targetMapId);
  252. $footHold = new Ins_FootHold();
  253. $footHold->mapId = $mo->gateId;
  254. $footHold->curMapType = $mo->mapType;
  255. $this->unlockedFootholds->$targetMapId = $footHold; # 初始化解锁新手村据点数据
  256. }
  257. # 检查目标地图是否已经解锁
  258. my_Assert(isset($newMap->unlockedFootholds->$targetMapId), ErrCode::map_NotUnlocked);
  259. $newMap->curMapId = $targetMapId;
  260. $gateZone = GameConfig::gate_zone();
  261. my_Assert($gateZone != null, ErrCode::err_const_no);
  262. foreach ($gateZone as $zoneid => $val) {
  263. $list = explode(',', $val->contains);
  264. if(in_array($targetMapId, $list)){
  265. $mid = $list[0];
  266. break;
  267. }
  268. }
  269. if($mid != null){//更新据点id
  270. $newMap->curFootholdId = $mid;
  271. }
  272. ctx()->newMap = $newMap;
  273. UserProc::updateUserInfo();
  274. return Resp::ok($newMap);
  275. }
  276. /**
  277. * 7502 开启传送阵
  278. * @return Resp
  279. */
  280. public static function FixUpTransmision() {
  281. }
  282. /**
  283. * 7503 更新探索进度
  284. * @return Resp
  285. */
  286. public static function UpdateExplorationProgress() {
  287. }
  288. }