黎川带精

master
罗家炜 2025-04-08 20:44:44 +08:00
parent 3fe036ca7d
commit 77943a6ed9
14 changed files with 109 additions and 104 deletions

View File

@ -6,17 +6,17 @@ local M = {}
--- Create a new GameController --- Create a new GameController
function M.new() function M.new()
setmetatable(M,{__index = GameController}) setmetatable(M, { __index = GameController })
local self = setmetatable({}, {__index = M}) local self = setmetatable({}, { __index = M })
self:init("南城麻将") self:init("南城麻将")
self.class = "TX_GameController" self.class = "TX_GameController"
return self return self
end end
function M:init(name) function M:init(name)
GameController.init(self,name) GameController.init(self, name)
self._eventmap[TX_Protocol.GAME_EVT_PLAYER_DEAL] = self.OnEventSendCards self._eventmap[TX_Protocol.GAME_EVT_PLAYER_DEAL] = self.OnEventSendCards
self._eventmap[TX_Protocol.GAME_EVT_CHANGE_ACTIVE_PLAYER] = self.OnEventTurn self._eventmap[TX_Protocol.GAME_EVT_CHANGE_ACTIVE_PLAYER] = self.OnEventTurn
self._eventmap[TX_Protocol.GAME_EVT_DRAW] = self.OnEventTakeCard self._eventmap[TX_Protocol.GAME_EVT_DRAW] = self.OnEventTakeCard
@ -36,7 +36,6 @@ function M:init(name)
self._eventmap[TX_Protocol.GAME_EVT_GANGZI] = self.OnEventGangCards self._eventmap[TX_Protocol.GAME_EVT_GANGZI] = self.OnEventGangCards
self._eventmap[TX_Protocol.GAME_EVT_BUGANG] = self.OnEventBuGang self._eventmap[TX_Protocol.GAME_EVT_BUGANG] = self.OnEventBuGang
end end
local __pre_delete_card = false local __pre_delete_card = false
@ -45,17 +44,17 @@ function M:SendOutCard(card, callback)
local _data = {} local _data = {}
_data["card"] = card _data["card"] = card
local _room = self._room local _room = self._room
local _client = ControllerManager.GameNetClinet local _client = ControllerManager.GameNetClinet
_client:send(TX_Protocol.GAME_DIS_CARD, _data) _client:send(TX_Protocol.GAME_DIS_CARD, _data)
-- 进行预删牌处理 -- 进行预删牌处理
local p = _room.self_player local p = _room.self_player
_room.curren_outcard_seat = -1 _room.curren_outcard_seat = -1
list_remove(p.card_list,card) list_remove(p.card_list, card)
table.sort(p.card_list, ViewUtil.HandCardSort) table.sort(p.card_list, ViewUtil.HandCardSort)
p.hand_left_count = p.hand_left_count - 1 p.hand_left_count = p.hand_left_count - 1
if not p.outcard_list then p.outcard_list = {} end if not p.outcard_list then p.outcard_list = {} end
p.outcard_list[#p.outcard_list+1] = card p.outcard_list[#p.outcard_list + 1] = card
__pre_delete_card = true __pre_delete_card = true
callback() callback()
end end
@ -63,28 +62,28 @@ end
function M:SendGangCard(card) function M:SendGangCard(card)
local _data = {} local _data = {}
_data["card"] = card _data["card"] = card
local _client = ControllerManager.GameNetClinet local _client = ControllerManager.GameNetClinet
_client:send(TX_Protocol.GAME_EVT_DOGANG, _data) _client:send(TX_Protocol.GAME_EVT_DOGANG, _data)
end end
function M:OnEventGangCards(evt_data) function M:OnEventGangCards(evt_data)
printlog("OnEventGangCards") printlog("OnEventGangCards")
pt(evt_data) pt(evt_data)
DispatchEvent(self._dispatcher,TX_GameEvent.SendGangZi,evt_data["gangzi1"],evt_data["gangzi2"],evt_data["gangnum"],true ) DispatchEvent(self._dispatcher, TX_GameEvent.SendGangZi, evt_data["gangzi1"], evt_data["gangzi2"],
evt_data["gangnum"], true)
end end
function M:OnEventBuGang(evt_data) function M:OnEventBuGang(evt_data)
printlog("OnEventBuGang") printlog("OnEventBuGang")
pt(evt_data) pt(evt_data)
DispatchEvent(self._dispatcher,TX_GameEvent.EventBuGang,evt_data["info"][1],evt_data["info"][2],true ) DispatchEvent(self._dispatcher, TX_GameEvent.EventBuGang, evt_data["info"][1], evt_data["info"][2], true)
end end
-- 发送放子选择到服务器 -- 发送放子选择到服务器
function M:SendAction(id) function M:SendAction(id)
local _data = {} local _data = {}
_data["id"] = id _data["id"] = id
local _client = ControllerManager.GameNetClinet local _client = ControllerManager.GameNetClinet
_client:send(TX_Protocol.GAME_ACTION, _data) _client:send(TX_Protocol.GAME_ACTION, _data)
end end
@ -94,42 +93,44 @@ function M:OnEventSendCards(evt_data)
return return
end end
local _room = self._room local _room = self._room
if not _room.room_config.piao_niao or _room.self_player.entrust then if not _room.room_config.piao_niao or _room.self_player.entrust then
_room.curren_round = _room.curren_round + 1 _room.curren_round = _room.curren_round + 1
end end
if _room.curren_round > 0 then _room.playing = true end if _room.curren_round > 0 then _room.playing = true end
printlog("开始发牌===========>>>")
pt(evt_data)
local room = DataManager.CurrenRoom
--printlog(evt_data.laiziCard)
--printlog(evt_data.laiziCard2)
--printlog(evt_data.laiziCardBefore)
--printlog(evt_data.laiziCard2Before)
DispatchEvent(self._dispatcher,TX_GameEvent.SendGangZi,102,103,0,true ) printlog("开始发牌===========>>>")
pt(evt_data)
local room = DataManager.CurrenRoom
--printlog(evt_data.laiziCard)
--printlog(evt_data.laiziCard2)
--printlog(evt_data.laiziCardBefore)
--printlog(evt_data.laiziCard2Before)
DispatchEvent(self._dispatcher, TX_GameEvent.SendGangZi, 102, 103, 0, true)
-- _room.SelfPlayer.AutoOutCard = false -- _room.SelfPlayer.AutoOutCard = false
local handcards = evt_data["card_list"] local handcards = evt_data["card_list"]
local p = _room.self_player local p = _room.self_player
local seat = evt_data["bank_seat"] local seat = evt_data["bank_seat"]
local jing = evt_data["jing"]
self._cacheEvent:Enqueue(function() self._cacheEvent:Enqueue(function()
_room.banker_seat = seat _room.banker_seat = seat
for i=1,#_room.player_list do _room.jing = jing
for i = 1, #_room.player_list do
_room.player_list[i].hand_left_count = 13 _room.player_list[i].hand_left_count = 13
_room.player_list[i].fz_list = {} _room.player_list[i].fz_list = {}
_room.player_list[i].card_list = {} _room.player_list[i].card_list = {}
end end
p.card_list = handcards p.card_list = handcards
self._room.self_player.hand_left_count = #handcards self._room.self_player.hand_left_count = #handcards
table.sort( handcards, ViewUtil.HandCardSort ) table.sort(handcards, ViewUtil.HandCardSort)
DispatchEvent(self._dispatcher,TX_GameEvent.SendCards, p) DispatchEvent(self._dispatcher, TX_GameEvent.SendCards, p)
end) end)
end end
function M:OnEventOutCard(evt_data) function M:OnEventOutCard(evt_data)
@ -138,7 +139,7 @@ function M:OnEventOutCard(evt_data)
local ting_list = nil local ting_list = nil
local p = self._room:GetPlayerBySeat(seat) local p = self._room:GetPlayerBySeat(seat)
self._cacheEvent:Enqueue(function() self._cacheEvent:Enqueue(function()
local _room = self._room local _room = self._room
_room.last_outcard_seat = seat _room.last_outcard_seat = seat
if seat == _room.self_player.seat and __pre_delete_card then if seat == _room.self_player.seat and __pre_delete_card then
__pre_delete_card = false __pre_delete_card = false
@ -149,13 +150,12 @@ function M:OnEventOutCard(evt_data)
end end
p.hand_left_count = p.hand_left_count - 1 p.hand_left_count = p.hand_left_count - 1
if not p.outcard_list then p.outcard_list = {} end if not p.outcard_list then p.outcard_list = {} end
p.outcard_list[#p.outcard_list+1] = card p.outcard_list[#p.outcard_list + 1] = card
DispatchEvent(self._dispatcher,TX_GameEvent.OutCard, p, card) DispatchEvent(self._dispatcher, TX_GameEvent.OutCard, p, card)
end end
end) end)
end end
function M:OnEventTakeCard(evt_data) function M:OnEventTakeCard(evt_data)
local _room = self._room local _room = self._room
local seat = evt_data["seat"] local seat = evt_data["seat"]
@ -163,19 +163,19 @@ function M:OnEventTakeCard(evt_data)
local left_count = evt_data["left_count"] local left_count = evt_data["left_count"]
local p = _room:GetPlayerBySeat(seat) local p = _room:GetPlayerBySeat(seat)
self._cacheEvent:Enqueue(function() self._cacheEvent:Enqueue(function()
p.hand_left_count = p.hand_left_count +1 p.hand_left_count = p.hand_left_count + 1
if (seat == _room.self_player.seat) then if (seat == _room.self_player.seat) then
_room.self_player.card_list[#_room.self_player.card_list+1] = card _room.self_player.card_list[#_room.self_player.card_list + 1] = card
-- table.sort( _room.self_player.card_list, ViewUtil.HandCardSort ) -- table.sort( _room.self_player.card_list, ViewUtil.HandCardSort )
end end
DispatchEvent(self._dispatcher,TX_GameEvent.GetCard, seat, card, left_count) DispatchEvent(self._dispatcher, TX_GameEvent.GetCard, seat, card, left_count)
end) end)
end end
function M:OnEventOutHint(evt_data) function M:OnEventOutHint(evt_data)
self._cacheEvent:Enqueue(function() self._cacheEvent:Enqueue(function()
self._room.curren_outcard_seat = self._room.self_player.seat self._room.curren_outcard_seat = self._room.self_player.seat
DispatchEvent(self._dispatcher,TX_GameEvent.OutHint) DispatchEvent(self._dispatcher, TX_GameEvent.OutHint)
end) end)
end end
@ -183,24 +183,24 @@ function M:OnEventTurn(evt_data)
local seat = evt_data["seat"] local seat = evt_data["seat"]
self._cacheEvent:Enqueue(function() self._cacheEvent:Enqueue(function()
-- self._room.curren_outcard_seat = seat -- self._room.curren_outcard_seat = seat
DispatchEvent(self._dispatcher,TX_GameEvent.EventTurn, seat) DispatchEvent(self._dispatcher, TX_GameEvent.EventTurn, seat)
end) end)
end end
function M:OnEventFzTips(evt_data) function M:OnEventFzTips(evt_data)
self._cacheEvent:Enqueue(function() self._cacheEvent:Enqueue(function()
local tiplist = FZTipList.new() local tiplist = FZTipList.new()
local list = evt_data["tip_list"] local list = evt_data["tip_list"]
local weight = evt_data["weight"] local weight = evt_data["weight"]
for i=1,#list do for i = 1, #list do
local dtip = list[i] local dtip = list[i]
local tip = {} local tip = {}
tip.id = dtip["id"] tip.id = dtip["id"]
tip.weight = dtip["weight"] tip.weight = dtip["weight"]
tip.card = dtip["card"] tip.card = dtip["card"]
tip.type = dtip["type"] tip.type = dtip["type"]
tip.opcard = dtip["opcard"] tip.opcard = dtip["opcard"]
-- if (dtip["opcard"]) then -- if (dtip["opcard"]) then
-- local opcard = dtip["opcard"] -- local opcard = dtip["opcard"]
-- tip.OpCard = opcard -- tip.OpCard = opcard
@ -209,12 +209,12 @@ function M:OnEventFzTips(evt_data)
-- end -- end
tiplist:AddTip(tip) tiplist:AddTip(tip)
end end
DispatchEvent(self._dispatcher,TX_GameEvent.FZTips, tiplist, weight) DispatchEvent(self._dispatcher, TX_GameEvent.FZTips, tiplist, weight)
end) end)
end end
function M:OnEventFzAction(evt_data) function M:OnEventFzAction(evt_data)
local _room = self._room local _room = self._room
local playerid = evt_data["playerid"] local playerid = evt_data["playerid"]
local card = evt_data["card"] local card = evt_data["card"]
local actice_card = evt_data["active_card"] local actice_card = evt_data["active_card"]
@ -229,12 +229,12 @@ function M:OnEventFzAction(evt_data)
local index = -1 local index = -1
local ftype = type local ftype = type
if (ftype == FZType.Gang_Peng) then if (ftype == FZType.Gang_Peng) then
for i=1,#p.fz_list do for i = 1, #p.fz_list do
if (p.fz_list[i].card == card) then if (p.fz_list[i].card == card) then
p.fz_list[i].card = card p.fz_list[i].card = card
fz = p.fz_list[i] fz = p.fz_list[i]
fz.type = type fz.type = type
index = i -1 index = i - 1
break break
end end
end end
@ -245,45 +245,46 @@ function M:OnEventFzAction(evt_data)
fz.active_card = actice_card fz.active_card = actice_card
if (index == -1) then if (index == -1) then
if (ftype == FZType.Chi) then if (ftype == FZType.Chi) then
local data ={} local data = {}
data[1] = opcard[1] data[1] = opcard[1]
data[2] = card data[2] = card
data[3] = opcard[2] data[3] = opcard[2]
fz.opcard =data fz.opcard = data
end end
p.fz_list[#p.fz_list+1] = fz p.fz_list[#p.fz_list + 1] = fz
end end
fz.from_seat = from_seat fz.from_seat = from_seat
local remove_num = #opcard local remove_num = #opcard
if (p == _room.self_player) then if (p == _room.self_player) then
for i=1,remove_num do for i = 1, remove_num do
list_remove(p.card_list,opcard[i]) list_remove(p.card_list, opcard[i])
end end
end end
p.hand_left_count = p.hand_left_count - remove_num p.hand_left_count = p.hand_left_count - remove_num
if from_seat ~= p.seat then if from_seat ~= p.seat then
-- if (fz.Type == FZType.Chi) then card = actice_card end -- if (fz.Type == FZType.Chi) then card = actice_card end
local fp = _room:GetPlayerBySeat(from_seat) local fp = _room:GetPlayerBySeat(from_seat)
table.remove(fp.outcard_list,#fp.outcard_list) table.remove(fp.outcard_list, #fp.outcard_list)
end end
DispatchEvent(self._dispatcher,TX_GameEvent.FangziAction, fz, p, index) DispatchEvent(self._dispatcher, TX_GameEvent.FangziAction, fz, p, index)
end) end)
end end
function M:OnEventHu(evt_data) function M:OnEventHu(evt_data)
local cards = evt_data["card"] local cards = evt_data["card"]
local win_p = self._room:GetPlayerBySeat(evt_data["seat"]) local win_p = self._room:GetPlayerBySeat(evt_data["seat"])
local lose_p = self._room:GetPlayerBySeat(evt_data["from_seat"]) local lose_p = self._room:GetPlayerBySeat(evt_data["from_seat"])
local win_card = evt_data["win_card"] local win_card = evt_data["win_card"]
local win_list = evt_data["win_list"] local win_list = evt_data["win_list"]
self._cacheEvent:Enqueue(function() self._cacheEvent:Enqueue(function()
win_p.card_list = cards win_p.card_list = cards
table.sort( win_p.card_list, ViewUtil.HandCardSort) table.sort(win_p.card_list, ViewUtil.HandCardSort)
DispatchEvent(self._dispatcher,TX_GameEvent.ZPHuCard, evt_data["seat"], evt_data["from_seat"], win_card, cards, win_list) DispatchEvent(self._dispatcher, TX_GameEvent.ZPHuCard, evt_data["seat"], evt_data["from_seat"], win_card, cards,
win_list)
end) end)
end end
@ -302,15 +303,15 @@ function M:OneventResult1(evt_data)
p.hand_left_count = 0 p.hand_left_count = 0
p.outcard_list = {} p.outcard_list = {}
end end
DispatchEvent(self._dispatcher,TX_GameEvent.ZPResult1, result); DispatchEvent(self._dispatcher, TX_GameEvent.ZPResult1, result);
end) end)
elseif 1 == over or 2 == over then elseif 1 == over or 2 == over then
DataManager.CurrenRoom.Over = true DataManager.CurrenRoom.Over = true
ControllerManager.SetGameNetClient(nil,true) ControllerManager.SetGameNetClient(nil, true)
local total_result = evt_data.total_result local total_result = evt_data.total_result
local result = evt_data.result local result = evt_data.result
self._cacheEvent:Enqueue(function() self._cacheEvent:Enqueue(function()
DispatchEvent(self._dispatcher,TX_GameEvent.ZPResult2, result, total_result, over); DispatchEvent(self._dispatcher, TX_GameEvent.ZPResult2, result, total_result, over);
end) end)
end end
end end
@ -318,13 +319,13 @@ end
-- function M:OnEventResult2(evt_data) -- function M:OnEventResult2(evt_data)
-- DataManager.CurrenRoom.Over = true -- DataManager.CurrenRoom.Over = true
-- ControllerManager.SetGameNetClient(nil,true) -- ControllerManager.SetGameNetClient(nil,true)
-- local info_list = evt_data["info_list"] -- local info_list = evt_data["info_list"]
-- if self._result ~= nil then -- if self._result ~= nil then
-- self._cacheEvent:Enqueue(function() -- self._cacheEvent:Enqueue(function()
-- self:OneventResult1(self._result) -- self:OneventResult1(self._result)
-- self._result = nil -- self._result = nil
-- end) -- end)
-- end -- end
-- self._cacheEvent:Enqueue(function() -- self._cacheEvent:Enqueue(function()
-- DispatchEvent(self._dispatcher,TX_GameEvent.ZPResult2, info_list) -- DispatchEvent(self._dispatcher,TX_GameEvent.ZPResult2, info_list)
-- ControllerManager.ChangeController(LoddyController) -- ControllerManager.ChangeController(LoddyController)
@ -335,7 +336,7 @@ function M:OnEventNiao(evt_data)
local list = evt_data["niao"] local list = evt_data["niao"]
local start_seat = evt_data["start_seat"] local start_seat = evt_data["start_seat"]
self._cacheEvent:Enqueue(function() self._cacheEvent:Enqueue(function()
DispatchEvent(self._dispatcher,TX_GameEvent.EventNiao, list, start_seat) DispatchEvent(self._dispatcher, TX_GameEvent.EventNiao, list, start_seat)
end) end)
end end
@ -346,41 +347,41 @@ function M:OnEventPiaoTip()
end end
self._cacheEvent:Enqueue(function() self._cacheEvent:Enqueue(function()
if not self._room._reload_flag then if not self._room._reload_flag then
self._room.curren_round = self._room.curren_round + 1 self._room.curren_round = self._room.curren_round + 1
end end
self._room.playing = true self._room.playing = true
DispatchEvent(self._dispatcher,TX_GameEvent.EvnetPiaoTip, evt_data) DispatchEvent(self._dispatcher, TX_GameEvent.EvnetPiaoTip, evt_data)
end) end)
end end
function M:OnEventPiao(evt_data) function M:OnEventPiao(evt_data)
self._cacheEvent:Enqueue(function() self._cacheEvent:Enqueue(function()
DispatchEvent(self._dispatcher,TX_GameEvent.EvnetPiao, evt_data.seat, evt_data.num) DispatchEvent(self._dispatcher, TX_GameEvent.EvnetPiao, evt_data.seat, evt_data.num)
end) end)
end end
function M:GetPosString( seat ) function M:GetPosString(seat)
if DataManager.CurrenRoom.room_config.people_num ~= 4 then return"" end if DataManager.CurrenRoom.room_config.people_num ~= 4 then return "" end
if seat == 1 then if seat == 1 then
return "" return ""
elseif seat == 2 then elseif seat == 2 then
return "西" return "西"
elseif seat == 3 then elseif seat == 3 then
return "" return ""
elseif seat == 4 then elseif seat == 4 then
return "" return ""
end end
end end
function M:Discard(card) function M:Discard(card)
local _data = {} local _data = {}
_data["card"] = card _data["card"] = card
local _room = self._room local _room = self._room
local _client = ControllerManager.GameNetClinet local _client = ControllerManager.GameNetClinet
-- list_remove(_room.SelfPlayer.Cards,card) -- list_remove(_room.SelfPlayer.Cards,card)
-- table.sort(_room.SelfPlayer.Cards) -- table.sort(_room.SelfPlayer.Cards)
_client:send(Protocol.Game_Da, _data) _client:send(Protocol.Game_Da, _data)
end end
return M return M

View File

@ -243,11 +243,11 @@ function M:OnEventFzAction(evt_data)
fz.active_card = actice_card fz.active_card = actice_card
if (index == -1) then if (index == -1) then
if (ftype == FZType.Chi) then if (ftype == FZType.Chi) then
local data = {} local data = {}
data[1] = opcard[1] data[1] = opcard[1]
data[2] = card data[2] = card
data[3] = opcard[2] data[3] = opcard[2]
fz.opcard = data fz.opcard = data
end end
p.fz_list[#p.fz_list + 1] = fz p.fz_list[#p.fz_list + 1] = fz
end end

View File

@ -92,19 +92,23 @@ function M:UpdateHandCard(getcard, mp)
b3d = "_3d" b3d = "_3d"
end end
local cards = DataManager.CurrenRoom.self_player.card_list local _room = DataManager.CurrenRoom
local cards = _room.self_player.card_list
if (not mp) then if (not mp) then
for i = 0, (#cards) - 1 do for i = 0, (#cards) - 1 do
local tem_card = cards[i + 1] local tem_card = cards[i + 1]
local btn_card = nil local btn_card = nil
if DataManager.CurrenRoom.room_config.people_num == 2 then if _room.room_config.people_num == 2 then
btn_card = UIPackage.CreateObject(self:GetCardObjPack(), "Btn_Card_jiangxi" .. b3d) btn_card = UIPackage.CreateObject(self:GetCardObjPack(), "Btn_Card_jiangxi" .. b3d)
else else
btn_card = UIPackage.CreateObject(self:GetCardObjPack(), "Btn_Card" .. b3d) btn_card = UIPackage.CreateObject(self:GetCardObjPack(), "Btn_Card" .. b3d)
btn_card:SetScale(1.05, 1.05) btn_card:SetScale(1.05, 1.05)
end end
if _room.jing and tem_card == _room.jing then
btn_card:GetController('jing').selectedIndex = 1
end
-- btn_card.icon = UIPackage.GetItemURL("Main_Majiang", "201_" .. tem_card) -- btn_card.icon = UIPackage.GetItemURL("Main_Majiang", "201_" .. tem_card)
self:fillCard(btn_card, "201_", tem_card) self:fillCard(btn_card, "201_", tem_card)
self:setHandCardPos(btn_card, i, i == #cards - 1 and getcard) self:setHandCardPos(btn_card, i, i == #cards - 1 and getcard)