【优化】主城假人改为NPC或者排行榜角色

dev_chengFeng
zhangqiang 2021-01-27 16:40:17 +08:00
parent 3028a31eb3
commit 7b01f5fc07
2 changed files with 124 additions and 5 deletions

View File

@ -520,11 +520,18 @@ function this:BindEvent()
local rect = btnClickMoveTran.rect
math.randomseed(os.time())
for i = 1, 10 do
local view = MainPlayerView.New(false, this.btnClickMove, rect, Vector2.New(math.random(rect.xMin, rect.xMax), math.random(rect.yMin, rect.yMax)))
view.NameText.text = NameManager.GetLocalRandomName()
view:SetAutoMove()
end
-- for i = 1, 10 do
-- local view = MainPlayerView.New(false, this.btnClickMove, rect, Vector2.New(math.random(rect.xMin, rect.xMax), math.random(rect.yMin, rect.yMax)))
-- view.NameText.text = NameManager.GetLocalRandomName()
-- view:SetAutoMove()
-- end
PlayerManager.GetMainPlayerNPCData(function(NPCList)
for i = 1, #NPCList do
local view = MainPlayerView.New(false, this.btnClickMove, rect, Vector2.New(math.random(rect.xMin, rect.xMax), math.random(rect.yMin, rect.yMax)))
view.NameText.text = NPCList[i].userName or NPCList[i].name
view:SetAutoMove()
end
end)
self.playerView = MainPlayerView.New(true, this.btnClickMove, rect, Vector2.New(-1210, 0))
--角色点击行走
self.trigger.onPointerClick = self.trigger.onPointerClick + function(p, d)

View File

@ -459,5 +459,117 @@ function this.StopBattleUpLvTipTime()
end
end
------- 主城NPC 选择star ----------
local rankNPCList = {}
local friendNPCList = {}
function this.GetMainPlayerNPCData(fun)
rankNPCList = {}
friendNPCList = {}
local friendRandomNum = math.random(1, 2)
-- LogGreen("friendRandomNum "..friendRandomNum)
if friendRandomNum == 2 and PlayerManager.familyId == 0 then
friendRandomNum = 1
end
if friendRandomNum == 1 then
NetManager.RequestGetFriendInfo(1,function(msg)
if #msg.Friends > 9 then
for i = 1, 9 do
this.RandomFirendNPC(msg.Friends)
end
else
for i = 1, #msg.Friends do
friendNPCList[i] = msg.Friends[i]
-- LogGreen("friend "..msg.Friends[i].name)
end
end
-- LogGreen("#friendNPCList "..#friendNPCList)
this.GetMainPlayerNPCData2(fun)
end)
else
MyGuildManager.RequestMyGuildMembers(function()
local MyGuildMemList = MyGuildManager.GetMyGuildMemList()
if #MyGuildMemList > 9 then
for i = 1, 9 do
this.RandomFirendNPC(MyGuildMemList)
end
else
for i = 1, #MyGuildMemList do
friendNPCList[i] = MyGuildMemList[i]
-- LogGreen("MyGuildMemList "..MyGuildMemList[i].userName)
end
end
-- LogGreen("#MyGuildMemList "..#friendNPCList)
this.GetMainPlayerNPCData2(fun)
end)
end
end
function this.GetMainPlayerNPCData2(fun)
local rankRandomNum = math.random(1, 4)
local needNum = 9 - LengthOfTable(friendNPCList)
needNum = 9 + needNum
-- LogGreen("rankRandomNum "..rankRandomNum)
RankingManager.InitData(rankKingList[rankRandomNum].rankType, function()
local rankAllList = RankingManager.GetRankingInfo()
local currankAllList = {}
for i = 1, 25 do
if rankAllList[i] and rankAllList[i].uid ~= PlayerManager.uid then
table.insert(currankAllList,rankAllList[i])
end
end
if #currankAllList > needNum then
for i = 1, needNum do
this.RandomRankNPC(currankAllList)
end
else
for i = 1, #currankAllList do
rankNPCList[i] = currankAllList[i]
-- LogGreen("rank "..currankAllList[i].userName)
end
end
-- LogGreen("#rankNPCList "..#rankNPCList)
this.GetMainPlayerNPCData3(fun)
end)
end
function this.GetMainPlayerNPCData3(fun)
local upList = {}
for key,val in pairs(friendNPCList) do
table.insert(upList,val)
end
for key,val in pairs(rankNPCList) do
table.insert(upList,val)
end
if #upList < 18 then
for i = 1, 18 - #upList do
local singleUserData = {}
singleUserData.userName = NameManager.GetLocalRandomName()
singleUserData.sex = math.random(1, 2)
singleUserData.uid = 1000 + i
table.insert(upList,singleUserData)
end
end
-- LogGreen("#upList "..#upList)
if fun then
fun(upList)
end
end
function this.RandomRankNPC(currankAllList)
local playerRandomNum = math.random(1, 25)
if rankNPCList[playerRandomNum] then
this.RandomRankNPC()
else
rankNPCList[playerRandomNum] = currankAllList[playerRandomNum]
-- LogGreen("rank "..currankAllList[playerRandomNum].userName)
end
end
function this.RandomFirendNPC(currankAllList)
local playerRandomNum = math.random(1, #currankAllList)
if friendNPCList[playerRandomNum] then
this.RandomFirendNPC()
else
friendNPCList[playerRandomNum] = currankAllList[playerRandomNum]
-- LogGreen("friend "..currankAllList[playerRandomNum].userName)
end
end
---------- 主城NPC 选择 end----------
return this