dezhou_client/lua_probject/extend_project/extend/zipai/weimaque/EXGameController.lua

414 lines
14 KiB
Lua
Raw Blame History

This file contains ambiguous Unicode characters!

This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.

local RB_Protocol = import('.Protocol')
local FZTipList = require('main.zipai.FZData')
local RB_GameEvent = import('.RunBeard_GameEvent')
local checkHuxi = import('.checkHuxi')
local M = {}
--- Create a new HZ_GameController
function M.new()
setmetatable(M, {__index = GameController})
local self = setmetatable({}, {__index = M})
self:init('安乡偎麻雀')
self.class = 'RB_GameController'
return self
end
function M:init(name)
GameController.init(self, name)
self._eventmap[RB_Protocol.GAME_EVT_PLAYER_DEAL] = self.OnEventSendCards
self._eventmap[RB_Protocol.GAME_EVT_CHANGE_ACTIVE_PLAYER] = self.OnEventTurn
self._eventmap[RB_Protocol.GAME_EVT_DRAW] = self.OnEventTakeCard
self._eventmap[RB_Protocol.GAME_EVT_DISCARD_TIP] = self.OnEventOutHint
self._eventmap[RB_Protocol.GAME_EVT_DISCARD] = self.OnEventOutCard
self._eventmap[RB_Protocol.GAME_EVT_FZTIPS] = self.OnEventFzTips
self._eventmap[RB_Protocol.GAME_EVT_ACTION] = self.OnEventFzAction
self._eventmap[RB_Protocol.GAME_EVT_HU] = self.OnEventHu
self._eventmap[RB_Protocol.GAME_EVT_RESULT1] = self.OneventResult1
self._eventmap[RB_Protocol.GAME_EVT_QIPAI] = self.OnEventQIPAI
self._eventmap[RB_Protocol.GAME_EVT_ADD_CARD] = self.OnAddCard
self._eventmap[RB_Protocol.GAME_EVT_SUO_CARD] = self.OnSuoCard
self._eventmap[RB_Protocol.GAME_EVT_SI_SHOU] = self.OnSiSHou
self._eventmap[RB_Protocol.GAME_EVT_TING] = self.OnTingpai
end
-- 发送出牌指令到服务器
function M:SendOutCard(card)
local _data = {}
_data['card'] = card
local _room = self._room
local _client = ControllerManager.GameNetClinet
if _client ~= nil then
_client:send(RB_Protocol.GAME_DIS_CARD, _data)
end
end
--GAME_CHANGE_CARD GAME_DIS_CARD
function M:SendChangeCards(card_list)
local _data = {}
_data['card_list'] = card_list
local _client = ControllerManager.GameNetClinet
if _client ~= nil then
_client:send(RB_Protocol.GAME_CHANGE_CARD, _data)
end
end
function M:SendChangeTypeFace(TypeFace)
-- body
local _data = {}
_data['typeface'] = TypeFace
local _client = ControllerManager.GameNetClinet
if _client ~= nil then
_client:send(RB_Protocol.GAME_CHANGE_TYPEfACE, _data)
end
end
function M:ConformToNextGame()
local _client = ControllerManager.GameNetClinet
if _client ~= nil then
_client:send(RB_Protocol.GAME_EVT_CHUI)
end
end
-- 发送放子选择到服务器
function M:SendAction(id, num)
local _data = {}
_data['id'] = id
if num ~= nil then
_data['biid'] = num
end
local _client = ControllerManager.GameNetClinet
if _client ~= nil then
_client:send(RB_Protocol.GAME_ACTION, _data)
end
end
function M:OnEventSendCards(evt_data)
if ViewManager.GetCurrenView().dview_class == LobbyView then
self:ReturnToRoom()
return
end
local _room = self._room
_room.curren_round = evt_data['round']
if _room.curren_round > 0 then
_room.playing = true
end
local handcards = evt_data['card_list']
local p = _room.self_player
local seat = evt_data['bank_seat']
_room.banker_seat = seat
_room.SiShou = false
_room.tinglist = {}
for i = 1, #_room.player_list do
_room.self_player.handcard_list = {}
_room.self_player.card_list = {}
_room.player_list[i].hand_left_count = 20
_room.player_list[i].fz_list = {}
_room.player_list[i].card_list = {}
_room.player_list[i].outcard_list = {}
_room.player_list[i].hu_xi = 0
_room.player_list[i].jushou = 0
end
self._cacheEvent:Enqueue(
function()
_room.self_player.handcard_list = handcards
self._room.self_player.hand_left_count = #handcards
DispatchEvent(self._dispatcher, RB_GameEvent.SendCards, p)
end
)
end
function M:OnEventOutCard(evt_data)
local seat = evt_data['seat']
local card = evt_data['card']
local p = self._room:GetPlayerBySeat(seat)
self._cacheEvent:Enqueue(function()
print("jefe OnEventOutCard")
local _room = self._room
if (seat == _room.self_player.seat) then
list_remove(_room.self_player.handcard_list, card)
end
p.DiceCard = card
p.hand_left_count = p.hand_left_count - 1
DispatchEvent(self._dispatcher, RB_GameEvent.OutCard, p, card)
end
)
end
function M:OnEventQIPAI(evt_data)
local seat = evt_data['seat']
local card = evt_data['card']
local ischu = evt_data['ischu']
local p = self._room:GetPlayerBySeat(seat)
self._cacheEvent:Enqueue(
function()
local _room = self._room
if (not p.outcard_list) then
p.outcard_list = {}
end
local t = {}
t.card = card
t.ischu = ischu and ischu or 0
p.outcard_list[#p.outcard_list + 1] = t
DispatchEvent(self._dispatcher, RB_GameEvent.QiCard, seat, card)
end
)
end
function M:OnEventTakeCard(evt_data)
local _room = self._room
local seat = evt_data['seat']
local card = evt_data['card']
local left_count = evt_data['left_count']
local discard = evt_data['discard']
local p = _room:GetPlayerBySeat(seat)
self._cacheEvent:Enqueue(
function()
if discard == true then
local _room = self._room
if (seat == _room.self_player.seat) then
list_remove(_room.self_player.handcard_list, card)
end
p.DiceCard = card
p.hand_left_count = p.hand_left_count - 1
DispatchEvent(self._dispatcher, RB_GameEvent.OutCard, p, card)
else
if card ~= 0 then
p.DiceCard = card
end
DispatchEvent(self._dispatcher, RB_GameEvent.GetCard, seat, card, left_count)
end
end
)
end
function M:OnAddCard(evt_data)
local _room = self._room
local seat = evt_data['seat']
local card = evt_data['card']
local left_count = evt_data['left_count']
local p = _room:GetPlayerBySeat(seat)
self._cacheEvent:Enqueue(
function()
p.DiceCard = 0
p.hand_left_count = p.hand_left_count + 1
if (seat == _room.self_player.seat) then
_room.self_player.handcard_list[#_room.self_player.handcard_list + 1] = card
end
DispatchEvent(self._dispatcher, RB_GameEvent.AddCard, seat, card, left_count)
end
)
end
function M:OnSuoCard(evt_data)
local suoCard = evt_data['suoCard']
self._cacheEvent:Enqueue(function()
local _room = self._room
_room.suoCard = suoCard
DispatchEvent(self._dispatcher, RB_GameEvent.SuoCard, suoCard)
end
)
end
function M:OnEventOutHint(evt_data)
local tingList = evt_data['ting']
local _room = self._room
_room.tinglist = tingList
self._cacheEvent:Enqueue(function()
DispatchEvent(self._dispatcher, RB_GameEvent.OutHint)
end
)
end
function M:OnEventTurn(evt_data)
local seat = evt_data['seat']
self._cacheEvent:Enqueue(
function()
DispatchEvent(self._dispatcher, RB_GameEvent.EventTurn, seat)
end
)
end
function M:OnEventFzTips(evt_data)
self._cacheEvent:Enqueue(
function()
local tiplist = FZTipList.new()
local list = evt_data['tip_list']
local uid = evt_data['uid']
for i = 1, #list do
local dtip = list[i]
local tip = {}
tip.id = dtip['id']
tip.weight = dtip['weight']
tip.card = dtip['card']
tip.type = dtip['type']
tip.bi_list = dtip['bi_list']
if (dtip['opcard']) then
local opcard = dtip['opcard']
tip.OpCard = opcard
table.sort(tip.OpCard)
tip.OpCard[3] = tip.Card
end
tiplist:AddTip(tip)
end
DispatchEvent(self._dispatcher, RB_GameEvent.FZTips, tiplist, uid)
end
)
end
function M:OnEventFzAction(evt_data)
local _room = self._room
local playerid = evt_data['playerid']
local card = evt_data['card']
local actice_card = evt_data['active_card']
local ftype = evt_data['type']
local from_seat = evt_data['from_seat']
local opcard = evt_data['opcard']
local huxi = evt_data['huxi']
local p = _room:GetPlayerById(playerid)
self._cacheEvent:Enqueue(
function()
local isNeedDelHandCard = 0
local fz = {}
fz.card = card
fz.type = ftype
fz.active_card = card
fz.from_seat = from_seat
fz.opcard = opcard
fz.huxi = huxi
local remove_num = #opcard
local isPao = false
if ftype == RB_FZType.PengPao or ftype == RB_FZType.WeiPao then
isNeedDelHandCard = 1
fz.type = RB_FZType.Pao
for i = 1, #p.fz_list do
if p.fz_list[i].card == fz.card then
p.fz_list[i].type = RB_FZType.Pao
p.fz_list[i].opcard = fz.opcard
p.fz_list[i].huxi = fz.huxi
end
end
elseif ftype == RB_FZType.WeiTi then
isNeedDelHandCard = 1
fz.type = RB_FZType.Ti
for i = 1, #p.fz_list do
if p.fz_list[i].card == fz.card then
p.fz_list[i].type = RB_FZType.Ti
p.fz_list[i].opcard = fz.opcard
p.fz_list[i].huxi = fz.huxi
end
end
else
if p.seat == _room.self_player.seat then
for i = 1, #opcard do
list_remove(_room.self_player.handcard_list, opcard[i])
end
if fz.type == RB_FZType.Pao then
for i = 1, #p.fz_list do
if p.fz_list[i].card == fz.card and p.fz_list[i].type == RB_FZType.Kan then
p.fz_list[i].type = RB_FZType.Pao
p.fz_list[i].opcard = fz.opcard
p.fz_list[i].huxi = fz.huxi
isPao = true
end
end
elseif fz.type == RB_FZType.KanTi or fz.type == RB_FZType.Ti then
for i = 1, #p.fz_list do
if p.fz_list[i].card == fz.card and p.fz_list[i].type == RB_FZType.Kan then
p.fz_list[i].type = RB_FZType.Ti
p.fz_list[i].opcard = fz.opcard
p.fz_list[i].huxi = fz.huxi
isPao = true
end
end
end
end
if fz.type == RB_FZType.KanTi then
fz.type = RB_FZType.Ti
end
p.hand_left_count = p.hand_left_count - remove_num
if isPao == false then
p.fz_list[#p.fz_list + 1] = fz
end
end
DispatchEvent(self._dispatcher, RB_GameEvent.FangziAction, fz, p, isNeedDelHandCard)
end
)
end
function M:OnSiSHou(evt_data)
local seat = evt_data['seat']
self._cacheEvent:Enqueue(
function()
local _room = self._room
_room.SiShou = true
DispatchEvent(self._dispatcher, RB_GameEvent.SiShou, seat)
end
)
end
function M:OnTingpai(evt_data)
local tinglist = evt_data['tinglist']
self._cacheEvent:Enqueue(
function()
local _room = self._room
_room.showtinglist = tinglist
DispatchEvent(self._dispatcher, RB_GameEvent.Tingpai)
end
)
end
function M:OnEventHu(evt_data)
local cards = evt_data['card']
local win_p = self._room:GetPlayerBySeat(evt_data['seat'])
local lose_p = self._room:GetPlayerBySeat(evt_data['from_seat'])
local hutype = evt_data['hutype']
print("jefe OnEventHu")
self._cacheEvent:Enqueue(function()
print("jefe OnEventHu Enqueue")
win_p.card_list = cards
table.sort(win_p.card_list, ViewUtil.HandCardSort)
DispatchEvent(
self._dispatcher,
RB_GameEvent.ZPHuCard,
evt_data['seat'],
evt_data['from_seat'],
cards,
hutype
)
end
)
end
function M:OneventResult1(evt_data)
printlog("结算=============>>>")
pt(evt_data)
local over = evt_data.type
--0小结算 1小大结算 2大结算
self._room.playing = false
if 0 == over then
local result = evt_data.result
for i = 1, #self._room.player_list do
local p = self._room.player_list[i]
p.hand_left_count = 0
p.outcard_list = {}
end
self._cacheEvent:Enqueue(
function()
DispatchEvent(self._dispatcher, RB_GameEvent.ZPResult1, result)
end
)
elseif 1 == over or 2 == over then
DataManager.CurrenRoom.Over = true
ControllerManager.SetGameNetClient(nil, true)
local total_result = evt_data.total_result
local result = evt_data.result
print("jefe OneventResult1")
self._cacheEvent:Enqueue(function()
print("jefe Enqueue")
DispatchEvent(self._dispatcher, RB_GameEvent.ZPResult2, result, total_result, over);
end
)
end
end
return M