MapProc.php 11 KB

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