48 lines
1.7 KiB
Lua
48 lines
1.7 KiB
Lua
|
|
local skynet = require "skynet"
|
|||
|
|
local mysql = require "skynet.db.mysql"
|
|||
|
|
local oo = require "Class"
|
|||
|
|
local cmd = require "GameCmd"
|
|||
|
|
local json =require "json"
|
|||
|
|
local player = require "Player"
|
|||
|
|
local log = require "Log"
|
|||
|
|
local pb = require "pb"
|
|||
|
|
local sqlUrl = require "SqlUrl"
|
|||
|
|
local playerFields = require "PlayerFields"
|
|||
|
|
local redisKeyUrl = require "RedisKeyUrl"
|
|||
|
|
local dyeworkshop = require "DyeWorkShop"
|
|||
|
|
local errorInfo = require "ErrorInfo"
|
|||
|
|
local dataType = require "DataType"
|
|||
|
|
local cluserServer = require "ClusterServer"
|
|||
|
|
local serverId = tonumber(skynet.getenv "serverId")
|
|||
|
|
local Npc = oo.class()
|
|||
|
|
|
|||
|
|
function Npc:Init()
|
|||
|
|
local cfgAllNPCName = skynet.server.gameConfig:GetAllCfg( "NPCName")
|
|||
|
|
for k, v in pairs( cfgAllNPCName ) do
|
|||
|
|
local robotPartnerId = string.format( "Npc_%d" , v.id )
|
|||
|
|
if not skynet.server.personal:IsExistDetailKey( robotPartnerId ) then
|
|||
|
|
--不存在的玩家ID,设置到玩家数据中
|
|||
|
|
--skynet.server.personal:SetDetail( robotPartnerId , "userId" , k , "partnerId" , robotPartnerId , "nickName" , v.name )
|
|||
|
|
local initData = {}
|
|||
|
|
initData[ "userId" ] = k
|
|||
|
|
initData[ "partnerId" ] = robotPartnerId
|
|||
|
|
initData[ "nickName" ] = v.name
|
|||
|
|
|
|||
|
|
local packData = skynet.server.common:PackData( initData )
|
|||
|
|
local redisDetailKey = string.format( redisKeyUrl.GameServerPersonalDetail , robotPartnerId )
|
|||
|
|
local curPartnerRedis = skynet.server.redisCenter:GetPartnerRedis( robotPartnerId )
|
|||
|
|
curPartnerRedis:hmset( redisDetailKey , table.unpack( packData ))
|
|||
|
|
end
|
|||
|
|
end
|
|||
|
|
end
|
|||
|
|
|
|||
|
|
--每5秒调一次
|
|||
|
|
function Npc:On5SecTimer()
|
|||
|
|
if not cluserServer:IsGameServer(serverId) then
|
|||
|
|
return
|
|||
|
|
end
|
|||
|
|
end
|
|||
|
|
|
|||
|
|
skynet.server.npc = Npc
|
|||
|
|
return Npc
|