sm

立即登录 | 账号注册

积分: 0 |用户组: 游客

搜索
服务器租用 传奇3一条龙 支付平台源码 无法下载点击此处反馈
查看: 593|回复: 0

[传奇手游源码] 战神引擎地图明文代码mir2.scenes.main.map.map

[复制链接]

826

主题

36

回帖

23万

积分

霸王教主

积分
236104
发表于 2023-5-15 18:02:11 | 显示全部楼层 |阅读模式
战神引擎地图明文代码,直接复制保存到 mir2.scenes.main.map.map.lua

修改后加密覆盖到,或者热更新到 客户端Mir2.zip即可

  1. local current = ...
  2. local mapDef = import(".def")
  3. local maptile = import(".maptile")
  4. local role = import("..role.role")
  5. local hero = import("..role.hero")
  6. local npc = import("..role.npc")
  7. local mon = import("..role.mon")
  8. local roleInfo = import("..role.info")
  9. local stall = import("..role.stall")
  10. local magic = import("..common.magic")
  11. local settingLogic = import("..common.settingLogic")
  12. local map = class("map", function ()
  13.         return ycMap:create()
  14. end)
  15. local __position = cc.Node.setPosition

  16. table.merge(map, {
  17.         isStage = false
  18. })

  19. map.ctor = function (self, mapid)
  20.         self.mapid = mapid
  21.         self.replaceMapid = g_data.map.mapReplace[mapid]
  22.         self.hasRes = def.map.isHasRes(self.mapid) or def.map.isHasRes(self.replaceMapid)
  23.         self.player = nil
  24.         self.gray = false
  25.         self.mons = {}
  26.         self.npcs = {}
  27.         self.heros = {}
  28.         self.items = {}
  29.         self.doors = {}
  30.         self.stalls = {}
  31.         self.safezoneEffs = {}
  32.         self.events = {}
  33.         self.readyTiles = {}
  34.         self.roleXYs = {}
  35.         self.msgs = newList()
  36.         self.file = res.loadmap(self.replaceMapid or self.mapid)

  37.         print("=====================================\nself.file", self.file)

  38.         self.h = self.file:geth()
  39.         self.w = self.file:getw()
  40.         self.layers = {
  41.                 bg = display.newNode():addto(self),
  42.                 mid = display.newNode():addto(self),
  43.                 obj = display.newNode():addto(self),
  44.                 itemName = display.newNode():addto(self),
  45.                 itemEff = display.newNode():addto(self),
  46.                 infoHpBg = display.newNode():addto(self),
  47.                 infoHpSpr = display.newNode():addto(self),
  48.                 infoHpOut = display.newNode():addto(self)
  49.         }
  50.         self.tiles = {}

  51.         self.size(self, self.file:getw()*mapDef.tile.w, self.file:geth()*mapDef.tile.h)
  52.         self.runForever(self, transition.sequence({
  53.                 cc.DelayTime:create(20),
  54.                 cc.CallFunc:create(handler(self, self.clearTiles))
  55.         }))

  56.         if not self.hasRes and main_scene and main_scene.ui then
  57.                 main_scene.ui:tip("该地图的环境正在施工中.")
  58.         end

  59.         self.relationHandler = handler(self, self.onRelationUpdate)

  60.         g_data.relation:addNotifyListener(self.relationHandler)

  61.         self.onCleanup = function ()
  62.                 g_data.relation:removeNotifyListener(self.relationHandler)

  63.                 return
  64.         end
  65.         self.blocks = {}

  66.         self.updateMapScale(self)

  67.         return
  68. end
  69. map.onRelationUpdate = function (self, _, rel, ole, new)
  70.         if (rel == "attention" or rel == "attentionColor") and (ole or new) then
  71.                 local name = (ole and ole.get(ole, "name")) or new.get(new, "name")
  72.                 local role = nil

  73.                 for k, v in pairs(self.heros) do
  74.                         print(v.info:getName(), name)

  75.                         if v.info:getName() == name then
  76.                                 role = v

  77.                                 break
  78.                         end
  79.                 end

  80.                 if role then
  81.                         if new then
  82.                                 role.info:setNameColor(new.get(new, "color"))
  83.                         elseif ole.realNameColor then
  84.                                 role.info:setNameColor(ole.realNameColor)
  85.                         end
  86.                 end
  87.         end

  88.         return
  89. end
  90. map.updateMapScale = function (self, s)
  91.         local scale = s or g_data.setting.display.mapScale
  92.         self.screenw = math.ceil(display.width/mapDef.tile.w/scale)
  93.         self.screenh = math.ceil(display.height/mapDef.tile.h/scale)

  94.         return
  95. end
  96. map.setAllRoleInScreen = function (self, inScreen)
  97.         for k, roles in pairs(self.roleXYs) do
  98.                 for k, v in pairs(roles) do
  99.                         if v.isInScreen ~= inScreen then
  100.                                 v.isInScreen = inScreen

  101.                                 v.uptIsIgnore(v)
  102.                         end
  103.                 end
  104.         end

  105.         return
  106. end
  107. map.updateRoleInScreen = function (self, x, y, endx, endy, inScreen)
  108.         if endx < x then
  109.                 endx = x
  110.                 x = endx
  111.         end

  112.         if endy < y then
  113.                 endy = y
  114.                 y = endy
  115.         end

  116.         local uptIsIgnore = role.uptIsIgnore

  117.         for mx = x, endx, 1 do
  118.                 mx = mx*10000

  119.                 for my = y + mx, endy + mx, 1 do
  120.                         local roles = self.roleXYs[my]

  121.                         if roles then
  122.                                 for k, v in pairs(roles) do
  123.                                         if v.isInScreen ~= inScreen then
  124.                                                 v.isInScreen = inScreen

  125.                                                 uptIsIgnore(v)
  126.                                         else
  127.                                                 break
  128.                                         end
  129.                                 end
  130.                         end
  131.                 end
  132.         end

  133.         return
  134. end
  135. map.load = function (self, x, y, ofsx, ofsy)
  136.         local function loadArea(beginx, beginy, endx, endy)
  137.                 beginx = math.max(0, math.min(self.w, beginx))
  138.                 endx = math.max(0, math.min(self.w, endx))
  139.                 beginy = math.max(0, math.min(self.h, beginy))
  140.                 endy = math.max(0, math.min(self.h, endy))

  141.                 for i = beginx, endx, 1 do
  142.                         for j = beginy, endy, 1 do
  143.                                 self:addTile(i, j)
  144.                         end
  145.                 end

  146.                 return
  147.         end

  148.         local screenw = self.screenw
  149.         local screenh = self.screenh
  150.         local rangew = screenw + mapDef.loadOutsideArea*2
  151.         local newx = x
  152.         local newy = y
  153.         local beginx, endx, beginy, endy = nil

  154.         if ofsx and ofsy then
  155.                 newy = y + ofsy
  156.                 newx = x + ofsx

  157.                 if ofsx ~= 0 then
  158.                         local rbeginx, rendx, ey = nil

  159.                         if 0 < ofsx then
  160.                                 beginx = math.floor(x + rangew/2)
  161.                                 endx = beginx + ofsx
  162.                                 rendx = math.floor(x - rangew/2) - 1
  163.                                 rbeginx = rendx - ofsx - 1
  164.                         else
  165.                                 endx = math.floor(x - rangew/2) - 1
  166.                                 beginx = (endx + ofsx) - 1
  167.                                 rbeginx = math.floor(x + rangew/2)
  168.                                 rendx = rbeginx - ofsx
  169.                         end

  170.                         beginy = math.floor(y - screenh/2 - mapDef.loadOutsideArea) + ofsy
  171.                         ey = beginy + screenh
  172.                         endy = ey + mapDef.loadOutsideAreaBottom + mapDef.loadOutsideArea

  173.                         loadArea(beginx, beginy, endx, endy)

  174.                         if screenw <= 24 then
  175.                                 self.updateRoleInScreen(self, rbeginx, beginy, rendx, ey, false)
  176.                                 self.updateRoleInScreen(self, beginx, beginy, endx, ey, true)
  177.                         end
  178.                 end

  179.                 if ofsy ~= 0 then
  180.                         local rbeginy, rendy, by, ey = nil

  181.                         if 0 < ofsy then
  182.                                 beginy = math.floor(y + screenh/2 + mapDef.loadOutsideAreaBottom)
  183.                                 by = beginy - mapDef.loadOutsideAreaBottom
  184.                                 endy = beginy + ofsy
  185.                                 ey = endy
  186.                                 rendy = math.floor(y - screenh/2)
  187.                                 rbeginy = rendy - ofsy
  188.                         else
  189.                                 endy = math.floor(y - screenh/2 - mapDef.loadOutsideArea)
  190.                                 ey = endy + mapDef.loadOutsideArea
  191.                                 beginy = endy + ofsy
  192.                                 by = beginy
  193.                                 rbeginy = math.floor(y + screenh/2)
  194.                                 rendy = rbeginy - ofsy
  195.                         end

  196.                         beginx = math.floor(x - rangew/2 + ofsx)
  197.                         endx = beginx + rangew

  198.                         loadArea(beginx, beginy, endx, endy)

  199.                         if screenh <= 24 then
  200.                                 self.updateRoleInScreen(self, beginx, rbeginy + 2, endx, rendy + 1, false)
  201.                                 self.updateRoleInScreen(self, beginx, by, endx, ey, true)
  202.                         end
  203.                 end
  204.         else
  205.                 endx = math.floor(x + rangew/2)
  206.                 beginx = math.floor(x - rangew/2)
  207.                 endy = math.floor(y + screenh/2 + mapDef.loadOutsideAreaBottom)
  208.                 beginy = math.floor(y - screenh/2 - mapDef.loadOutsideArea)

  209.                 loadArea(beginx, beginy, endx, endy)

  210.                 if 24 < screenh and 24 < screenw then
  211.                         self.setAllRoleInScreen(self, true)
  212.                 else
  213.                         self.setAllRoleInScreen(self, false)
  214.                         self.updateRoleInScreen(self, beginx, math.floor(y - screenh/2), endx, math.floor(y + screenh/2), true)
  215.                 end
  216.         end

  217.         local safezonexDatas = g_data.map:isSeeSafeZoneEdge(self.mapid, newx, newy, screenw, screenh)

  218.         if safezonexDatas then
  219.                 for i, v in ipairs(safezonexDatas) do
  220.                         self.addSafeZoneEff(self, v.x, v.y, v.rang)
  221.                 end
  222.         end

  223.         return
  224. end
  225. map.updateLookArea = function (self, x, y)
  226.         self.lookArea = cc.rect(x - display.cx/g_data.setting.display.mapScale, y - display.cy/g_data.setting.display.mapScale, display.width/g_data.setting.display.mapScale, display.height/g_data.setting.display.mapScale + 500)

  227.         return
  228. end
  229. map.scroll = function (self, isAnima, dura)
  230.         local tw = mapDef.tile.w
  231.         local th = mapDef.tile.h
  232.         local x, y = self.player.node:getPosition()

  233.         if isAnima then
  234.                 self.moveTo(self, dura or 0.2, (-x + display.cx) - tw/2, (-y + display.cy) - th/2)
  235.         else
  236.                 self.pos(self, (-x + display.cx) - tw/2, (-y + display.cy) - th/2)
  237.         end

  238.         self.updateLookArea(self, x, y)

  239.         return
  240. end
  241. map.setGrayState = function (self)
  242.         self.gray = true
  243.         local f = res.getFilter("gray")

  244.         for k, v in pairs(self.tiles) do
  245.                 for k2, v2 in pairs(v) do
  246.                         if v2.sprites.bg then
  247.                                 v2.sprites.bg:setFilter(f)
  248.                         end

  249.                         if v2.sprites.mid then
  250.                                 v2.sprites.mid:setFilter(f)
  251.                         end

  252.                         if v2.sprites.midAni then
  253.                                 v2.sprites.midAni:setFilter(f)
  254.                         end

  255.                         if v2.sprites.obj then
  256.                                 v2.sprites.obj:setFilter(f)
  257.                         end

  258.                         if v2.sprites.ani then
  259.                                 v2.sprites.ani:setFilter(f)
  260.                         end
  261.                 end
  262.         end

  263.         for k, v in pairs(self.heros) do
  264.                 v.openFilter(v, "die")
  265.         end

  266.         for k, v in pairs(self.mons) do
  267.                 v.openFilter(v, "die")
  268.         end

  269.         for k, v in pairs(self.npcs) do
  270.                 v.openFilter(v, "die")
  271.         end

  272.         return
  273. end
  274. map.getMapPosWithScreenPos = function (self, x, y)
  275.         local tw = mapDef.tile.w
  276.         local th = mapDef.tile.h
  277.         local diffx = x - display.cx
  278.         local diffy = y - display.cy
  279.         local node = self.player.node

  280.         return node.getPositionX(node) + tw/2 + diffx/main_scene.ground:getScale(), node.getPositionY(node) + th/2 + diffy/main_scene.ground:getScale()
  281. end
  282. map.getMapPos = function (self, gameX, gameY)
  283.         return gameX*mapDef.tile.w, (self.h - gameY)*mapDef.tile.h
  284. end
  285. map.getGamePos = function (self, x, y)
  286.         return math.floor(x/mapDef.tile.w), math.floor(self.h - y/mapDef.tile.h + 1)
  287. end
  288. map.addDoorTile = function (self, data, x, y)
  289.         local idx = ycFunction:band(data.doorIndex, 127)
  290.         local door = self.doors[idx]

  291.         if not door then
  292.                 door = {}
  293.                 self.doors[idx] = door
  294.         end

  295.         for k, v in pairs(door) do
  296.                 if v.x == x and v.y == y then
  297.                         return
  298.                 end
  299.         end

  300.         door[#door + 1] = {
  301.                 x = x,
  302.                 y = y,
  303.                 data = data
  304.         }

  305.         return
  306. end
  307. map.setDoorState = function (self, isOpen, x, y)
  308.         local data = self.file:gettile(x, y)

  309.         if data then
  310.                 local idx = ycFunction:band(data.doorIndex, 127)
  311.                 local door = self.doors[idx]

  312.                 if door then
  313.                         for k, v in pairs(door) do
  314.                                 local tile = self.tiles[v.x][v.y]

  315.                                 if tile then
  316.                                         v.data.doorOpen = isOpen

  317.                                         tile.setDoorState(tile, v.data)
  318.                                 end
  319.                         end
  320.                 end
  321.         end

  322.         return
  323. end
  324. map.addSafeZoneEff = function (self, x, y, range)
  325.         local key = self.xy2key(self, x, y)

  326.         if self.safezoneEffs[key] then
  327.                 return
  328.         end

  329.         self.safezoneEffs[key] = true
  330.         local points = {
  331.                 {
  332.                         flag = 0,
  333.                         x = x - range,
  334.                         y = y - range - 1
  335.                 },
  336.                 {
  337.                         flag = 2,
  338.                         x = x + range,
  339.                         y = y - range - 1
  340.                 },
  341.                 {
  342.                         flag = 4,
  343.                         x = x + range,
  344.                         y = (y + range) - 1
  345.                 },
  346.                 {
  347.                         flag = 6,
  348.                         x = x - range,
  349.                         y = (y + range) - 1
  350.                 }
  351.         }

  352.         for i = 1, range*2 + 1, 1 do
  353.                 points[#points + 1] = {
  354.                         flag = 1,
  355.                         x = (x - range + i) - 1,
  356.                         y = y - range - 1
  357.                 }
  358.                 points[#points + 1] = {
  359.                         flag = 3,
  360.                         x = x + range,
  361.                         y = (y - range + i) - 2
  362.                 }
  363.                 points[#points + 1] = {
  364.                         flag = 5,
  365.                         x = (x - range + i) - 1,
  366.                         y = y + range + 1
  367.                 }
  368.                 points[#points + 1] = {
  369.                         flag = 7,
  370.                         x = x - range - 2,
  371.                         y = (y - range + i) - 2
  372.                 }
  373.         end

  374.         for i, v in ipairs(points) do
  375.                 local x = v.x
  376.                 local y = v.y

  377.                 if self.mapid ~= "0" or 319 > x or x > 337 or 261 > y or y > 276 or false then
  378.                         local spr = m2spr.playAnimation("magic10", v.flag*10 + 2040, 4, 0.2, true, nil, nil, nil, nil, 1):addto(self.layers.mid, 99999)

  379.                         __position(spr, x*mapDef.tile.w, (self.h - y)*mapDef.tile.h)
  380.                 end
  381.         end

  382.         return
  383. end
  384. map.canWalk = function (self, gamex, gamey, params)
  385.         local ret = {}

  386.         if params and params.useBlockInfo then
  387.                 if self.file:getblock(gamex, gamey) then
  388.                         ret.block = "block"
  389.                 end
  390.         else
  391.                 local data = self.file:gettile(gamex, gamey)

  392.                 if data then
  393.                         if 0 < ycFunction:band(data.doorIndex, 128) and not data.doorOpen then
  394.                                 ret.block = "door"
  395.                                 ret.data = data
  396.                         elseif not data.canWalk then
  397.                                 ret.block = "map"
  398.                         end
  399.                 end
  400.         end

  401.         if not ret.block then
  402.                 ret = self.isObjblock(self, gamex, gamey)
  403.         end

  404.         return ret
  405. end
  406. map.canFly = function (self, gamex, gamey, params)
  407.         local data = self.file:gettile(gamex, gamey)

  408.         return data.canFly
  409. end
  410. map.getObjeBlocks = function (self)
  411.         local objects = {}

  412.         local function checkRoles(roles)
  413.                 for k, v in pairs(roles) do
  414.                         if not v.isDummy and not v.die then
  415.                                 objects[#objects + 1] = cc.p(v.x, v.y)
  416.                         end
  417.                 end

  418.                 return
  419.         end

  420.         checkRoles(self.mons)
  421.         checkRoles(self.npcs)
  422.         checkRoles(self.heros)

  423.         for k, v in pairs(self.stalls) do
  424.                 if not v.isDummy and not g_data.map:isInSafeZone(self.mapid, v.x, v.y) then
  425.                         for i = 0, 2, 1 do
  426.                                 for j = 0, 2, 1 do
  427.                                         objects[#objects] = cc.p(v.x + i, v.y + j)
  428.                                 end
  429.                         end
  430.                 end
  431.         end

  432.         return objects
  433. end
  434. map.isObjblock = function (self, gamex, gamey)
  435.         local ret = {}

  436.         if not ret.block then
  437.                 for k, v in pairs(self.mons) do
  438.                         if not v.isDummy and gamex == v.x and gamey == v.y and not v.die then
  439.                                 ret.block = "mon"

  440.                                 break
  441.                         end
  442.                 end
  443.         end

  444.         if not ret.block then
  445.                 for k, v in pairs(self.npcs) do
  446.                         if not v.isDummy and gamex == v.x and gamey == v.y and not v.die then
  447.                                 ret.block = "npc"

  448.                                 break
  449.                         end
  450.                 end
  451.         end

  452.         if not ret.block then
  453.                 for k, v in pairs(self.heros) do
  454.                         if not v.isDummy and gamex == v.x and gamey == v.y and not v.die then
  455.                                 ret.block = "hero"

  456.                                 break
  457.                         end
  458.                 end
  459.         end

  460.         if not ret.block then
  461.                 for k, v in pairs(self.stalls) do
  462.                         if not v.die and v.x <= gamex and gamex <= v.x + 2 and v.y <= gamey and gamey <= v.y + 2 then
  463.                                 ret.block = "map"

  464.                                 break
  465.                         end
  466.                 end
  467.         end

  468.         return ret
  469. end
  470. map.procAllRoles = function (self, f)
  471.         for k, roles in ipairs({
  472.                 self.heros,
  473.                 self.npcs,
  474.                 self.mons
  475.         }) do
  476.                 for k, v in pairs(roles) do
  477.                         f(v)
  478.                 end
  479.         end

  480.         return
  481. end
  482. map.findRole = function (self, roleid, params)
  483.         local role = nil
  484.         role = self.heros[roleid]

  485.         if role then
  486.                 return role
  487.         end

  488.         role = self.npcs[roleid]

  489.         if role then
  490.                 return role
  491.         end

  492.         role = self.mons[roleid]

  493.         if role then
  494.                 return role
  495.         end

  496.         if params and params.feature then
  497.                 if type(params.feature) == "number" then
  498.                         params.feature = def.role.makeTFeature(params.feature)
  499.                 end

  500.                 return self.newRole(self, params), true
  501.         end

  502.         return
  503. end
  504. map.findRoelWithPos = function (self, x, y, type)
  505.         if not type or type == "hero" then
  506.                 for k, v in pairs(self.heros) do
  507.                         if v.x == x and v.y == y then
  508.                                 return v
  509.                         end
  510.                 end
  511.         end

  512.         if not type or type == "mon" then
  513.                 for k, v in pairs(self.mons) do
  514.                         if v.x == x and v.y == y then
  515.                                 return v
  516.                         end
  517.                 end
  518.         end

  519.         if not type or type == "npc" then
  520.                 for k, v in pairs(self.npcs) do
  521.                         if v.x == x and v.y == y then
  522.                                 return v
  523.                         end
  524.                 end
  525.         end

  526.         return
  527. end
  528. map.findHeroWithName = function (self, name)
  529.         for k, v in pairs(self.heros) do
  530.                 if v.info:getName() == name then
  531.                         return v
  532.                 end
  533.         end

  534.         return
  535. end
  536. map.findNPCWithName = function (self, name)
  537.         for k, v in pairs(self.npcs) do
  538.                 if v.info:getName() == name then
  539.                         return v
  540.                 end
  541.         end

  542.         return
  543. end
  544. map.findNearMon = function (self)
  545.         local bestDis, bestMon = nil

  546.         for k, v in pairs(self.mons) do
  547.                 local name = v.info:getName()

  548.                 if not v.die and not v.isPolice(v) then
  549.                         local x = math.abs(self.player.x - v.x)
  550.                         local y = math.abs(self.player.y - v.y)
  551.                         local dis = math.sqrt(x*x + y*y)

  552.                         if not bestDis or dis < bestDis then
  553.                                 bestDis = dis
  554.                                 bestMon = v
  555.                         end
  556.                 end
  557.         end

  558.         return bestMon
  559. end
  560. map.newRole = function (self, params)
  561.         assert(params.roleid, "map.newRole -> roleid must be not nil")

  562.         params.map = self
  563.         local race = params.feature:get("race")
  564.         local ret = nil

  565.         if race == 0 or race == 1 or race == 150 then
  566.                 ret = hero.new(params)

  567.                 ret.node:addTo(self.layers.obj)

  568.                 self.heros[params.roleid] = ret

  569.                 if params.isPlayer then
  570.                         self.setPlayer(self, ret)
  571.                 end
  572.         elseif race == 50 then
  573.                 ret = npc.new(params)

  574.                 ret.node:addTo(self.layers.obj)

  575.                 self.npcs[params.roleid] = ret
  576.         else
  577.                 ret = mon.new(params)

  578.                 ret.node:addTo(self.layers.obj)

  579.                 self.mons[params.roleid] = ret
  580.         end

  581.         if main_scene and main_scene.ui.panels.minimap then
  582.                 main_scene.ui.panels.minimap:addPoint(ret)
  583.         end

  584.         self.uptRoleXY(self, ret, false, params.x, params.y)

  585.         return ret
  586. end
  587. map.removeRole = function (self, roleid)
  588.         local role = nil
  589.         role = self.heros[roleid]

  590.         if role then
  591.                 self.uptRoleXY(self, role, true)
  592.                 role.info:remove()
  593.                 role.node:removeSelf()
  594.         end

  595.         self.heros[roleid] = nil
  596.         role = self.npcs[roleid]

  597.         if role then
  598.                 self.uptRoleXY(self, role, true)
  599.                 role.info:remove()
  600.                 role.node:removeSelf()
  601.         end

  602.         self.npcs[roleid] = nil
  603.         role = self.mons[roleid]

  604.         if role then
  605.                 self.uptRoleXY(self, role, true)
  606.                 role.info:remove()
  607.                 role.node:removeSelf()
  608.         end

  609.         self.mons[roleid] = nil

  610.         if main_scene and main_scene.ui.panels.minimap then
  611.                 main_scene.ui.panels.minimap:removePoint(roleid)
  612.         end

  613.         return
  614. end
  615. map.setPlayer = function (self, player)
  616.         if self.player then
  617.                 self.removeTopRenderNode(self, self.player)
  618.                 self.player.node:removeSelf()
  619.         end

  620.         self.player = player

  621.         self.addTopRenderNode(self, self.player.node)

  622.         return
  623. end
  624. map.xy2key = function (self, x, y)
  625.         return x*10000 + y
  626. end
  627. map.uptRoleXY = function (self, role, isRemove, x, y)
  628.         local oldKey = role.xyKey
  629.         local newKey = x and y and self.xy2key(self, x, y)

  630.         if oldKey == newKey then
  631.                 return
  632.         end

  633.         if oldKey then
  634.                 local roles = self.roleXYs[oldKey]

  635.                 if roles then
  636.                         for i, v in ipairs(roles) do
  637.                                 if v == role then
  638.                                         table.remove(roles, i)

  639.                                         break
  640.                                 end
  641.                         end
  642.                 end
  643.         end

  644.         if isRemove then
  645.                 return
  646.         end

  647.         local roles = self.roleXYs[newKey]

  648.         if not roles then
  649.                 roles = {}
  650.                 self.roleXYs[newKey] = roles
  651.         end

  652.         roles[#roles + 1] = role

  653.         if self.player and not self.isStage then
  654.                 role.isInScreen = math.abs(x - self.player.x + 1) <= self.screenw/2 + 1 and math.abs(y - self.player.y) < self.screenh/2 + 2
  655.         else
  656.                 role.isInScreen = true
  657.         end

  658.         for i, v in ipairs(roles) do
  659.                 v.uptIsIgnore(v)
  660.         end

  661.         role.uptIsIgnore(role)

  662.         role.xyKey = newKey

  663.         return
  664. end
  665. map.showItem = function (self, isshow, itemid, gamex, gamey, name, imgid, owner, state)
  666.         if isshow ~= self.items[itemid] ~= nil then
  667.                 if isshow then
  668.                         local x, y = self.getMapPos(self, gamex, gamey)
  669.                         local item = {
  670.                                 x = gamex,
  671.                                 y = gamey,
  672.                                 owner = owner,
  673.                                 imgid = imgid,
  674.                                 itemid = itemid,
  675.                                 spr = m2spr.new("dnitems", imgid, {
  676.                                         asyncPriority = 1
  677.                                 }):addto(self.layers.obj, gamey):pos(x + mapDef.tile.w/2, y + mapDef.tile.h/2):runs({
  678.                                         cc.DelayTime:create(math.random(3000)/1000),
  679.                                         cc.RepeatForever:create(transition.sequence({
  680.                                                 cc.CallFunc:create(function ()
  681.                                                         local spr = m2spr.playAnimation("prguse", 410, 9, 0.08, true, true, true, nil, nil, 1):addto(self.layers.itemEff)

  682.                                                         __position(spr, x, y + mapDef.tile.h)

  683.                                                         return
  684.                                                 end),
  685.                                                 cc.DelayTime:create(0.54),
  686.                                                 cc.DelayTime:create(5)
  687.                                         }))
  688.                                 })
  689.                         }
  690.                         local isGood = false
  691.                         local showName = false

  692.                         if state and 0 < state then
  693.                                 isGood = g_data.setting.getGoodAttItemSetting().isGood
  694.                                 showName = g_data.setting.getGoodAttItemSetting().hintName
  695.                         end

  696.                         isGood = isGood or settingLogic.isGoodItem(name)
  697.                         showName = showName or settingLogic.showItemName(name)

  698.                         if showName or isGood then
  699.                                 local nameColor = def.colors.skyBlue

  700.                                 if isGood then
  701.                                         nameColor = def.colors.clRed
  702.                                 end

  703.                                 if state and 0 < state then
  704.                                         nameColor = def.colors.clpurple
  705.                                 end

  706.                                 item.state = state
  707.                                 item.name = an.newLabel(name, 12, 1, {
  708.                                         bufferChannel = 8,
  709.                                         color = nameColor
  710.                                 }):addto(self.layers.itemName)

  711.                                 __position(item.name, x, y + 20)
  712.                         end

  713.                         self.items[itemid] = item
  714.                         item.itemName = name

  715.                         return
  716.                 end

  717.                 local item = self.items[itemid]

  718.                 item.spr:removeSelf()

  719.                 if item.name then
  720.                         item.name:removeSelf()
  721.                 end

  722.                 self.items[itemid] = nil
  723.         end
  724. end
  725. map.updateItems = function (self)
  726.         local t = self.items
  727.         self.items = {}

  728.         for k, v in pairs(t) do
  729.                 v.spr:removeSelf()

  730.                 if v.name then
  731.                         v.name:removeSelf()
  732.                 end

  733.                 self.showItem(self, true, k, v.x, v.y, v.itemName, v.imgid, v.owner, v.state)
  734.         end

  735.         return
  736. end
  737. map.getItems = function (self, x, y)
  738.         local ret = {}

  739.         for k, v in pairs(self.items) do
  740.                 if v.x == x and v.y == y then
  741.                         ret[#ret + 1] = v
  742.                 end
  743.         end

  744.         return ret
  745. end
  746. map.showMagic = function (self, roleid, effectType, effectID, x, y, target)
  747.         local role = self.findRole(self, roleid)

  748.         if not role then
  749.                 return
  750.         end

  751.         magic.showMagic(self, role, target, x, y, effectID)

  752.         return
  753. end
  754. map.showEffectForName = function (self, name, params)
  755.         magic.showWithName(self, name, params)

  756.         return
  757. end
  758. local __position = cc.Node.setPosition
  759. map.showEvent = function (self, serverID, x, y, type, eventMsg)
  760.         self.hideEvent(self, serverID)

  761.         if mapDef.ET_FIRE == type then
  762.                 local imgid = "magic"
  763.                 local begin = 1630
  764.                 local frame = 6
  765.                 x, y = self.getMapPos(self, x, y)
  766.                 self.events[serverID] = m2spr.playAnimation(imgid, begin, frame, 0.08, true):opacity(76.5):addto(self.layers.obj, y + mapDef.tile.h)
  767.         elseif mapDef.ET_HOLYCURTAIN == type then
  768.                 local imgid = "magic"
  769.                 local begin = 1390
  770.                 local frame = 10
  771.                 x, y = self.getMapPos(self, x, y)
  772.                 self.events[serverID] = m2spr.playAnimation(imgid, begin, frame, 0.08, true):addto(self.layers.obj, y + mapDef.tile.h)
  773.         elseif mapDef.ET_PILESTONES == type then
  774.                 local imgid = "effect"
  775.                 local begin = 64
  776.                 local frame = 5
  777.                 x, y = self.getMapPos(self, x, y)
  778.                 self.events[serverID] = m2spr.playAnimation(imgid, begin, frame, 0.12, false, false, true):addto(self.layers.mid, 99999)
  779.         elseif mapDef.ET_DIGOUTZOMBI == type then
  780.                 local imgid = "mon6"
  781.                 local begin = 420
  782.                 local frame = 6
  783.                 x, y = self.getMapPos(self, x, y)
  784.                 self.events[serverID] = m2spr.playAnimation(imgid, begin, frame, 0.3, false, false, true):addto(self.layers.mid, 99999)
  785.         elseif mapDef.ET_YanHuaTextEvent == type then
  786.                 x, y = self.getMapPos(self, x, y)
  787.                 x = x - 130
  788.                 self.events[serverID] = an.newLabel(eventMsg.get(eventMsg, "desc"), 100, 0.5, {
  789.                         color = cc.c3b(255, 255, 0),
  790.                         sc = display.COLOR_WHITE
  791.                 }):addto(self.layers.obj, 99999)
  792.         elseif mapDef.ET_CAKEFIRE == type then
  793.                 local imgid = "prguse3"
  794.                 local begin = mapDef.CAKEFIREBASE
  795.                 local frame = 30
  796.                 x, y = self.getMapPos(self, x, y)
  797.                 self.events[serverID] = m2spr.playAnimation(imgid, begin, frame, 0.08, true):addto(self.layers.obj, y + mapDef.tile.h)
  798.         elseif mapDef.ET_INTENTLY <= type and type <= mapDef.ET_SUCHASFOGDREAM then
  799.                 local frameBegin = {
  800.                         20,
  801.                         20,
  802.                         16,
  803.                         16,
  804.                         16,
  805.                         16,
  806.                         16
  807.                 }
  808.                 local imgid = "magic3"
  809.                 local begin = (type - mapDef.ET_INTENTLY)*20 + 60
  810.                 local frame = frameBegin[type - mapDef.ET_INTENTLY + 1]
  811.                 x, y = self.getMapPos(self, x, y)

  812.                 m2spr.playAnimation(imgid, begin, frame, 0.12, true, true, true):addto(self.layers.mid, 99999)
  813.         elseif mapDef.ET_STALL_EVENT == type then
  814.                 x, y = self.getMapPos(self, x, y)
  815.                 self.events[serverID] = stall.new({
  816.                         x = x,
  817.                         y = y,
  818.                         serverID = serverID,
  819.                         map = self,
  820.                         data = eventMsg
  821.                 }):addto(self.layers.obj, 99999)
  822.                 self.stalls[serverID] = self.events[serverID]
  823.         end

  824.         if self.events[serverID] then
  825.                 self.events[serverID]:pos(x, y + mapDef.tile.h)
  826.         end

  827.         return
  828. end
  829. map.hideEvent = function (self, serverID)
  830.         if self.events[serverID] then
  831.                 self.events[serverID]:removeSelf()

  832.                 self.events[serverID] = nil
  833.         end

  834.         return
  835. end
  836. map.removeStall = function (self, serverID)
  837.         if self.stalls[serverID] then
  838.                 self.stalls[serverID] = nil
  839.         end

  840.         return
  841. end
  842. map.getHeroNameList = function (self)
  843.         local ret = {}

  844.         for k, v in pairs(self.heros) do
  845.                 if not v.isPlayer and v.info:getName() and not v.info:isHero() and not v.isDummy then
  846.                         ret[#ret + 1] = v.info:getName()
  847.                 end
  848.         end

  849.         return ret
  850. end
  851. map.addTile = function (self, x, y)
  852.         self.readyTiles[self.xy2key(self, x, y)] = {
  853.                 x,
  854.                 y
  855.         }

  856.         return
  857. end
  858. map.processTile = function (self, x, y)
  859.         if not self.tiles[x] then
  860.                 self.tiles[x] = {}
  861.         end

  862.         if not self.tiles[x][y] then
  863.                 self.tiles[x][y] = maptile.new(self, x, y)

  864.                 return true
  865.         end

  866.         return
  867. end
  868. map.processTiles = function (self, dt)
  869.         local cnt = 0

  870.         for k, v in pairs(self.readyTiles) do
  871.                 self.readyTiles[k] = nil

  872.                 if self.processTile(self, v[1], v[2]) then
  873.                         cnt = cnt + 1

  874.                         if mapDef.loadNum < cnt then
  875.                                 return
  876.                         end
  877.                 end
  878.         end

  879.         if self.gray then
  880.                 self.setGrayState(self)
  881.         end

  882.         return
  883. end
  884. map.clearTiles = function (self)
  885.         local x = self.player.x
  886.         local y = self.player.y
  887.         local dis = math.floor(display.width/mapDef.tile.w) + mapDef.loadOutsideAreaBottom*2

  888.         for k, v in pairs(self.tiles) do
  889.                 for k2, v2 in pairs(v) do
  890.                         if dis < math.abs(x - k) or dis < math.abs(y - k2) then
  891.                                 v2.remove(v2)

  892.                                 self.tiles[k][k2] = nil
  893.                         end
  894.                 end
  895.         end

  896.         for k, v in pairs(self.readyTiles) do
  897.                 if dis < math.abs(x - v[1]) or dis < math.abs(y - v[2]) then
  898.                         self.readyTiles[k] = nil
  899.                 end
  900.         end

  901.         return
  902. end
  903. map.addMsg = function (self, params)
  904.         if params.remove then
  905.                 local tmpList = newList()

  906.                 while not self.msgs.isEmpty() do
  907.                         local msg = self.msgs.popFront()

  908.                         if msg.roleid ~= params.roleid then
  909.                                 tmpList.pushBack(msg)
  910.                         end
  911.                 end

  912.                 self.msgs = tmpList

  913.                 self.removeRole(self, params.roleid)

  914.                 return
  915.         end

  916.         self.msgs.pushBack(params)

  917.         return
  918. end
  919. map.processMsg = function (self, v)
  920.         if v.roleid then
  921.                 local role, isNewCreate = self.findRole(self, v.roleid, v)

  922.                 if role then
  923.                         if v.ident then
  924.                                 role.processMsg(role, v.ident, v.x, v.y, v.dir, v.feature, v.state, v.roleParams)
  925.                         end

  926.                         if v.job then
  927.                                 role.job = v.job
  928.                         end

  929.                         if v.name then
  930.                                 local race = role.getRace(role)

  931.                                 if race ~= 98 and (race ~= 153 or false) then
  932.                                         role.info:setName(v.name)
  933.                                 end
  934.                         end

  935.                         while true do
  936.                                 if role.__cname == "hero" then
  937.                                         local pName = role.info:getName()
  938.                                         local attData = g_data.relation:getAttention(pName)

  939.                                         if attData then
  940.                                                 local colorIdx = attData.get(attData, "color")

  941.                                                 role.info:setNameColor(colorIdx)

  942.                                                 if v.nameColor then
  943.                                                         attData.realNameColor = v.nameColor
  944.                                                 end

  945.                                                 break
  946.                                         end
  947.                                 end

  948.                                 if v.nameColor then
  949.                                         role.info:setNameColor(v.nameColor)
  950.                                 end

  951.                                 break
  952.                         end

  953.                         if v.hp and v.maxhp then
  954.                                 role.info:setHP(v.hp, v.maxhp, v.outhp)
  955.                         end

  956.                         if isNewCreate and v.roleid == g_data.hero.roleid then
  957.                                 self.player.hero = role
  958.                         end
  959.                 end
  960.         end

  961.         if v.magic then
  962.                 self.showMagic(self, unpack(v.magic))
  963.         end

  964.         if v.effect then
  965.                 self.showEffectForName(self, v.effect[1], v.effect[2])
  966.         end

  967.         return
  968. end
  969. map.processMsgs = function (self, dt)
  970.         local begin = socket.gettime()

  971.         while not self.msgs.isEmpty() do
  972.                 self.processMsg(self, self.msgs.popFront())

  973.                 if 0.01 < socket.gettime() - begin then
  974.                         break
  975.                 end
  976.         end

  977.         return
  978. end
  979. map.update = function (self, dt)
  980.         self.processTiles(self, dt)
  981.         self.processMsgs(self, dt)

  982.         local roleSize = def.role.size
  983.         local infoUpdate = roleInfo.update
  984.         local roleUpdate = role.update
  985.         local uptIsIgnore = role.uptIsIgnore
  986.         local getPosition = role.getPosition
  987.         local rnum = 0

  988.         for k, roles in ipairs({
  989.                 self.heros,
  990.                 self.npcs,
  991.                 self.mons
  992.         }) do
  993.                 for k, v in pairs(roles) do
  994.                         if 0 < #v.acts or v.isPlayer then
  995.                                 rnum = rnum + 1

  996.                                 roleUpdate(v, dt)
  997.                         end

  998.                         if v.info.dirty then
  999.                                 infoUpdate(v.info, dt)
  1000.                         end
  1001.                 end
  1002.         end

  1003.         self.current_frame_updatedRoles = rnum

  1004.         return
  1005. end
  1006. map.checkFlyTo = function (self, from, to)
  1007.         local i, adist, dist, dir = nil
  1008.         local x = from.x
  1009.         local y = from.y
  1010.         local tx = to.x
  1011.         local ty = to.y
  1012.         adist = math.abs(x - tx) + math.abs(y - ty)

  1013.         for i = 0, 8, 1 do
  1014.                 dir = self.getNextDirection(self, x, y, tx, ty)
  1015.                 local ok = nil
  1016.                 x, y, ok = self.getNextPosition(self, x, y, dir, 1)

  1017.                 if not ok or not self.canFly(self, x, y) then
  1018.                         return false
  1019.                 end

  1020.                 if x == tx and y == ty then
  1021.                         return true
  1022.                 else
  1023.                         dist = math.abs(x - tx) + math.abs(y - ty)

  1024.                         if adist < dist then
  1025.                                 return true
  1026.                         end
  1027.                 end
  1028.         end

  1029.         return true
  1030. end
  1031. map.getNextDirection = function (self, x, y, tx, ty)
  1032.         local fx, fy = nil

  1033.         if x < tx then
  1034.                 fx = 1
  1035.         elseif x == tx then
  1036.                 fx = 0
  1037.         else
  1038.                 fx = -1
  1039.         end

  1040.         if 2 < math.abs(y - ty) and tx - 1 <= x and x <= tx + 1 then
  1041.                 fx = 0
  1042.         end

  1043.         if y < ty then
  1044.                 fy = 1
  1045.         elseif y == ty then
  1046.                 fy = 0
  1047.         else
  1048.                 fy = -1
  1049.         end

  1050.         if 2 < math.abs(x - tx) and ty - 1 < y and y < ty + 1 then
  1051.                 fy = 0
  1052.         end

  1053.         if fx == 0 and fy == -1 then
  1054.                 return def.role.dir.up
  1055.         elseif fx == 1 and fy == -1 then
  1056.                 return def.role.dir.rightUp
  1057.         elseif fx == 1 and fy == 0 then
  1058.                 return def.role.dir.right
  1059.         elseif fx == 1 and fy == 1 then
  1060.                 return def.role.dir.rightBottom
  1061.         elseif fx == 0 and fy == 1 then
  1062.                 return def.role.dir.bottom
  1063.         elseif fx == -1 and fy == 1 then
  1064.                 return def.role.dir.leftBottom
  1065.         elseif fx == -1 and fy == 0 then
  1066.                 return def.role.dir.left
  1067.         elseif fx == -1 and fy == -1 then
  1068.                 return def.role.dir.leftUp
  1069.         else
  1070.                 return def.role.dir.up
  1071.         end

  1072.         return
  1073. end
  1074. map.getNextPosition = function (self, nx, ny, dir, step)
  1075.         local x = nx
  1076.         local y = ny

  1077.         if dir == def.role.dir.up then
  1078.                 if step - 1 < y then
  1079.                         y = y - step
  1080.                 end
  1081.         elseif dir == def.role.dir.rightUp then
  1082.                 if step - 1 < x and y < self.h - step then
  1083.                         x = x + step
  1084.                         y = y - step
  1085.                 end
  1086.         elseif dir == def.role.dir.right then
  1087.                 if x < self.w - step then
  1088.                         x = x + step
  1089.                 end
  1090.         elseif dir == def.role.dir.rightBottom then
  1091.                 if x < self.w - step and y < self.h - step then
  1092.                         x = x + step
  1093.                         y = y + step
  1094.                 end
  1095.         elseif dir == def.role.dir.bottom then
  1096.                 if y < self.h - step then
  1097.                         y = y + step
  1098.                 end
  1099.         elseif dir == def.role.dir.leftBottom then
  1100.                 if x < self.w - step and step - 1 < y then
  1101.                         x = x - step
  1102.                         y = y + step
  1103.                 end
  1104.         elseif dir == def.role.dir.left then
  1105.                 if step - 1 < x then
  1106.                         x = x - step
  1107.                 end
  1108.         elseif dir == def.role.dir.leftUp and step - 1 < x and step - 1 < y then
  1109.                 x = x - step
  1110.                 y = y - step
  1111.         end

  1112.         return x, y, x ~= nx or y ~= ny
  1113. end

  1114. return map
复制代码








上一篇:完整版Zircon源码C#游戏引擎+服务端特色铭文版
下一篇:战神引擎明文源码LOST修改攻速mir2.scenes.main.role
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

手机版|美林GM论坛 ( 蜀ICP备2020030293号-2 )|网站地图

禁止发布任何违反国家法律、法规的言论与图片等内容;本站内容均来自个人观点与网络等信息,非本站认同之观点.如遇版权问题,请及时QQ联系

GMT+8, 2024-5-9 04:32 , Processed in 0.279391 second(s), 48 queries .

Powered by Discuz! X3.5

Copyright © 2001-2024, Tencent Cloud.

快速回复 返回顶部 返回列表