新增队伍系统,攻击不会打给同队,剩一队时游戏就结束(目前允许0~6,0号为自由队,每个人分别算一队)
添加/group命令来选择队伍
This commit is contained in:
@@ -188,12 +188,22 @@ end
|
|||||||
|
|
||||||
-- Royale mode
|
-- Royale mode
|
||||||
function randomTarget(P)-- Return a random opponent for P
|
function randomTarget(P)-- Return a random opponent for P
|
||||||
if #PLY_ALIVE>1 then
|
local l=TABLE.shift(PLY_ALIVE,0)
|
||||||
local R
|
local count=0
|
||||||
repeat
|
for i=1,#l do
|
||||||
R=PLY_ALIVE[rnd(#PLY_ALIVE)]
|
if P.group==0 and l[i]~=P or P.group~=l[i].group then
|
||||||
until R~=P
|
count=count+1
|
||||||
return R
|
end
|
||||||
|
end
|
||||||
|
if count==0 then return end
|
||||||
|
count=rnd(count)
|
||||||
|
for i=1,#l do
|
||||||
|
if P.group==0 and l[i]~=P or P.group~=l[i].group then
|
||||||
|
count=count-1
|
||||||
|
if count==0 then
|
||||||
|
return l[i]
|
||||||
|
end
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
function freshMostDangerous()
|
function freshMostDangerous()
|
||||||
|
|||||||
@@ -20,6 +20,16 @@ RANK_COLORS={
|
|||||||
{1,.5,.4},
|
{1,.5,.4},
|
||||||
{.95,.5,.95},
|
{.95,.5,.95},
|
||||||
}
|
}
|
||||||
|
GROUP_COLORS={
|
||||||
|
[0]=COLOR.Z,
|
||||||
|
[1]=COLOR.R,
|
||||||
|
[2]=COLOR.G,
|
||||||
|
[3]=COLOR.B,
|
||||||
|
[4]=COLOR.Y,
|
||||||
|
[5]=COLOR.M,
|
||||||
|
[6]=COLOR.C,
|
||||||
|
}
|
||||||
|
|
||||||
do-- SVG_TITLE_FILL, SVG_TITLE_LINE
|
do-- SVG_TITLE_FILL, SVG_TITLE_LINE
|
||||||
SVG_TITLE_FILL={
|
SVG_TITLE_FILL={
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -31,7 +31,7 @@ return{
|
|||||||
for i,p in next,L do
|
for i,p in next,L do
|
||||||
if p.uid==USER.uid then
|
if p.uid==USER.uid then
|
||||||
if p.playMode=='Gamer' then
|
if p.playMode=='Gamer' then
|
||||||
PLY.newPlayer(1)
|
PLY.newPlayer(1,false,p)
|
||||||
N=2
|
N=2
|
||||||
end
|
end
|
||||||
table.remove(L,i)
|
table.remove(L,i)
|
||||||
|
|||||||
@@ -689,7 +689,8 @@ function NET.wsCallBack.player_finish(body)
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
function NET.wsCallBack.player_joinGroup(body)-- TODO
|
function NET.wsCallBack.player_joinGroup(body)
|
||||||
|
NETPLY.map[body.data.playerId].group=body.data.group
|
||||||
end
|
end
|
||||||
function NET.wsCallBack.player_setHost(body)
|
function NET.wsCallBack.player_setHost(body)
|
||||||
if body.data.role=='Admin' then
|
if body.data.role=='Admin' then
|
||||||
@@ -697,7 +698,7 @@ function NET.wsCallBack.player_setHost(body)
|
|||||||
end
|
end
|
||||||
NETPLY.map[body.data.playerId].role=body.data.role
|
NETPLY.map[body.data.playerId].role=body.data.role
|
||||||
end
|
end
|
||||||
function NET.wsCallBack.player_setState(body)-- TODO (not used)
|
function NET.wsCallBack.player_setState(body)-- not used
|
||||||
end
|
end
|
||||||
function NET.wsCallBack.player_stream(body)
|
function NET.wsCallBack.player_stream(body)
|
||||||
_pumpStream(body.data)
|
_pumpStream(body.data)
|
||||||
@@ -716,7 +717,7 @@ function NET.wsCallBack.match_finish()
|
|||||||
TASK.unlock('netPlaying')
|
TASK.unlock('netPlaying')
|
||||||
end)
|
end)
|
||||||
end
|
end
|
||||||
function NET.wsCallBack.match_ready()-- TODO
|
function NET.wsCallBack.match_ready()-- not used
|
||||||
end
|
end
|
||||||
function NET.wsCallBack.match_start(body)
|
function NET.wsCallBack.match_start(body)
|
||||||
TASK.lock('netPlaying')
|
TASK.lock('netPlaying')
|
||||||
|
|||||||
@@ -6,16 +6,6 @@ local gc_stencil,gc_setStencilTest=gc.stencil,gc.setStencilTest
|
|||||||
local ins,rem=table.insert,table.remove
|
local ins,rem=table.insert,table.remove
|
||||||
local setFont=FONT.set
|
local setFont=FONT.set
|
||||||
|
|
||||||
local groupColor={
|
|
||||||
[0]=COLOR.Z,
|
|
||||||
[1]=COLOR.R,
|
|
||||||
[2]=COLOR.G,
|
|
||||||
[3]=COLOR.B,
|
|
||||||
[4]=COLOR.Y,
|
|
||||||
[5]=COLOR.M,
|
|
||||||
[6]=COLOR.C,
|
|
||||||
}
|
|
||||||
|
|
||||||
local posLists={
|
local posLists={
|
||||||
-- 1~5
|
-- 1~5
|
||||||
(function()
|
(function()
|
||||||
@@ -207,7 +197,7 @@ function NETPLY.draw()
|
|||||||
gc_rectangle('fill',0,0,p.w,p.h)
|
gc_rectangle('fill',0,0,p.w,p.h)
|
||||||
gc_setColor(COLOR.dH)
|
gc_setColor(COLOR.dH)
|
||||||
end
|
end
|
||||||
gc_setLineWidth(p.role=='Admin' and 4 or 2)
|
gc_setLineWidth(p.role=='Admin' and 4 or 1)
|
||||||
gc_rectangle('line',0,0,p.w,p.h)
|
gc_rectangle('line',0,0,p.w,p.h)
|
||||||
|
|
||||||
-- Stencil
|
-- Stencil
|
||||||
@@ -236,7 +226,7 @@ function NETPLY.draw()
|
|||||||
end
|
end
|
||||||
|
|
||||||
-- UID & Username
|
-- UID & Username
|
||||||
gc_setColor(groupColor[p.group] or COLOR.dH)
|
gc_setColor(GROUP_COLORS[p.group] or COLOR.dH)
|
||||||
if p.h>=47 then
|
if p.h>=47 then
|
||||||
setFont(40)
|
setFont(40)
|
||||||
gc_print("#"..p.uid,50,-5)
|
gc_print("#"..p.uid,50,-5)
|
||||||
|
|||||||
@@ -721,7 +721,7 @@ function draw.norm(P,repMode)
|
|||||||
|
|
||||||
-- Draw username
|
-- Draw username
|
||||||
setFont(30)
|
setFont(30)
|
||||||
gc_setColor(.97,.97,.97)
|
gc_setColor(GROUP_COLORS[P.group])
|
||||||
GC.mStr(P.username or USERS.getUsername(P.uid),300,-60)
|
GC.mStr(P.username or USERS.getUsername(P.uid),300,-60)
|
||||||
|
|
||||||
-- Draw HUD
|
-- Draw HUD
|
||||||
|
|||||||
@@ -192,7 +192,7 @@ local function _loadGameEnv(P)-- Load gameEnv
|
|||||||
-- else
|
-- else
|
||||||
-- print("default-"..k..":"..tostring(v))
|
-- print("default-"..k..":"..tostring(v))
|
||||||
end
|
end
|
||||||
if type(v)~='table' then -- Default setting
|
if type(v)~='table' then -- Default setting
|
||||||
ENV[k]=v
|
ENV[k]=v
|
||||||
else
|
else
|
||||||
ENV[k]=TABLE.copy(v)
|
ENV[k]=TABLE.copy(v)
|
||||||
@@ -219,11 +219,11 @@ local function _loadRemoteEnv(P,confStr)-- Load gameEnv
|
|||||||
if GAME.modeEnv[k]~=nil then
|
if GAME.modeEnv[k]~=nil then
|
||||||
v=GAME.modeEnv[k] -- Mode setting
|
v=GAME.modeEnv[k] -- Mode setting
|
||||||
elseif confStr[k]~=nil then
|
elseif confStr[k]~=nil then
|
||||||
v=confStr[k] -- Game setting
|
v=confStr[k] -- Game setting
|
||||||
elseif SETTING[k]~=nil then
|
elseif SETTING[k]~=nil then
|
||||||
v=SETTING[k] -- Global setting
|
v=SETTING[k] -- Global setting
|
||||||
end
|
end
|
||||||
if type(v)~='table' then-- Default setting
|
if type(v)~='table' then -- Default setting
|
||||||
ENV[k]=v
|
ENV[k]=v
|
||||||
else
|
else
|
||||||
ENV[k]=TABLE.copy(v)
|
ENV[k]=TABLE.copy(v)
|
||||||
@@ -407,14 +407,25 @@ function PLY.newRemotePlayer(id,mini,p)
|
|||||||
|
|
||||||
P.uid=p.uid
|
P.uid=p.uid
|
||||||
P.sid=NET.uid_sid[p.uid]
|
P.sid=NET.uid_sid[p.uid]
|
||||||
|
P.group=p.group
|
||||||
|
if not (P.group%1==0 and P.group>=1 and P.group<=6) then P.group=0 end
|
||||||
|
|
||||||
_loadRemoteEnv(P,p.config)
|
_loadRemoteEnv(P,p.config)
|
||||||
_applyGameEnv(P)
|
_applyGameEnv(P)
|
||||||
end
|
end
|
||||||
function PLY.newAIPlayer(id,AIdata,mini)
|
function PLY.newAIPlayer(id,AIdata,mini,p)
|
||||||
local P=_newEmptyPlayer(id,mini)
|
local P=_newEmptyPlayer(id,mini)
|
||||||
P.type='computer'
|
P.type='computer'
|
||||||
|
|
||||||
|
local pData={
|
||||||
|
uid=id,
|
||||||
|
group=0,
|
||||||
|
} if p then TABLE.coverR(p,pData) end
|
||||||
|
P.username='BOT'..pData.uid
|
||||||
|
P.sid=NET.uid_sid[pData.uid]
|
||||||
|
P.group=pData.group
|
||||||
|
if not (P.group%1==0 and P.group>=1 and P.group<=6) then P.group=0 end
|
||||||
|
|
||||||
_loadGameEnv(P)
|
_loadGameEnv(P)
|
||||||
P.gameEnv.face={0,0,0,0,0,0,0}
|
P.gameEnv.face={0,0,0,0,0,0,0}
|
||||||
P.gameEnv.skin={1,7,11,3,14,4,9}
|
P.gameEnv.skin={1,7,11,3,14,4,9}
|
||||||
@@ -422,13 +433,19 @@ function PLY.newAIPlayer(id,AIdata,mini)
|
|||||||
AIdata._20G=P._20G
|
AIdata._20G=P._20G
|
||||||
P:loadAI(AIdata)
|
P:loadAI(AIdata)
|
||||||
end
|
end
|
||||||
function PLY.newPlayer(id,mini)
|
function PLY.newPlayer(id,mini,p)
|
||||||
local P=_newEmptyPlayer(id,mini)
|
local P=_newEmptyPlayer(id,mini)
|
||||||
P.type='human'
|
P.type='human'
|
||||||
P.sound=true
|
P.sound=true
|
||||||
|
|
||||||
P.uid=USER.uid
|
local pData={
|
||||||
P.sid=NET.uid_sid[USER.uid]
|
uid=USER.uid,
|
||||||
|
group=0,
|
||||||
|
} if p then TABLE.coverR(p,pData) end
|
||||||
|
P.uid=pData.uid
|
||||||
|
P.sid=NET.uid_sid[pData.uid]
|
||||||
|
P.group=pData.group
|
||||||
|
if not (P.group%1==0 and P.group>=1 and P.group<=6) then P.group=0 end
|
||||||
|
|
||||||
_loadGameEnv(P)
|
_loadGameEnv(P)
|
||||||
_applyGameEnv(P)
|
_applyGameEnv(P)
|
||||||
|
|||||||
@@ -2845,15 +2845,33 @@ function Player:lose(force)
|
|||||||
gameOver()
|
gameOver()
|
||||||
self:newTask(#PLAYERS>1 and task_lose or task_finish)
|
self:newTask(#PLAYERS>1 and task_lose or task_finish)
|
||||||
if GAME.net and not NET.spectate then
|
if GAME.net and not NET.spectate then
|
||||||
NET.player_finish({foo="-- TODO"})
|
NET.player_finish({foo=""})
|
||||||
else
|
else
|
||||||
TASK.new(task_autoPause)
|
TASK.new(task_autoPause)
|
||||||
end
|
end
|
||||||
else
|
else
|
||||||
self:newTask(task_lose)
|
self:newTask(task_lose)
|
||||||
end
|
end
|
||||||
if #PLY_ALIVE==1 then
|
|
||||||
PLY_ALIVE[1]:win()
|
if #PLY_ALIVE>0 then
|
||||||
|
local cur=PLY_ALIVE[1].group
|
||||||
|
for i=2,#PLY_ALIVE do
|
||||||
|
local g=PLY_ALIVE[i].group
|
||||||
|
if cur==0 then
|
||||||
|
if g==0 then-- Two team 0, not finished
|
||||||
|
goto BREAK_notFinished
|
||||||
|
else-- Remember this may-be-last team
|
||||||
|
cur=g
|
||||||
|
end
|
||||||
|
elseif g==0 or cur~=g then-- Find another team, not finished
|
||||||
|
goto BREAK_notFinished
|
||||||
|
end
|
||||||
|
end
|
||||||
|
-- Only 1 team survived, all winner
|
||||||
|
for i=1,#PLY_ALIVE do
|
||||||
|
PLY_ALIVE[i]:win()
|
||||||
|
end
|
||||||
|
::BREAK_notFinished::
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
--------------------------<\Event>--------------------------
|
--------------------------<\Event>--------------------------
|
||||||
|
|||||||
@@ -142,6 +142,10 @@ function scene.keyDown(key,isRep)
|
|||||||
if tonumber(cmd[2]) then NET.room_kick(tonumber(cmd[2])) end
|
if tonumber(cmd[2]) then NET.room_kick(tonumber(cmd[2])) end
|
||||||
elseif cmd[1]=='/host' then
|
elseif cmd[1]=='/host' then
|
||||||
if tonumber(cmd[2]) then NET.player_setHost(tonumber(cmd[2])) end
|
if tonumber(cmd[2]) then NET.player_setHost(tonumber(cmd[2])) end
|
||||||
|
elseif cmd[1]=='/group' then
|
||||||
|
if tonumber(cmd[2]) and tonumber(cmd[2])%1==0 and tonumber(cmd[2])>=0 and tonumber(cmd[2])<=6 then
|
||||||
|
NET.player_joinGroup(tonumber(cmd[2]))
|
||||||
|
end
|
||||||
else
|
else
|
||||||
NET.textBox:push{COLOR.R,'Invalid command'}
|
NET.textBox:push{COLOR.R,'Invalid command'}
|
||||||
end
|
end
|
||||||
|
|||||||
Reference in New Issue
Block a user