Blame view

src/models/RolePlugin.lua 1.99 KB
be83d162   zhouahaihai   登陆成功。 增加数据结构修正功能
1
2
3
4
5
6
7
8
9
10
11
  
  
  local RolePlugin = {}
  
  function RolePlugin.bind(Role)
  
  	function Role:log()
  
  	end
  
  	function Role:loadAll()
0a07bdd9   zhouahaihai   角色升级 。gm
12
  		self:loadHeros()
be83d162   zhouahaihai   登陆成功。 增加数据结构修正功能
13
14
15
  	end
  
  	function Role:reloadWhenLogin()
0a07bdd9   zhouahaihai   角色升级 。gm
16
17
18
19
20
  	end
  
  	function Role:onCrossDay(now)
  
  	end
5b28342d   zhouahaihai   离线方法
21
22
23
  	function Role:onOfflineEvent()
  		
  	end
0a07bdd9   zhouahaihai   角色升级 。gm
24
25
26
27
28
29
  	function Role:addHero(params)
  		local roleId = self:getProperty("id")
  		local heroId = tonum(redisproxy:hincrby(string.format(R_INCR, roleId), "hero", 1))
  
  		local heroType = params.type
  		local unitData = csvdb["unitCsv"][heroType]
be83d162   zhouahaihai   登陆成功。 增加数据结构修正功能
30
  
0a07bdd9   zhouahaihai   角色升级 。gm
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
  		redisproxy:sadd(string.format(R_HEROS, roleId), heroId)
  
  		local heroInfo = {
  			key = string.format(R_HERO, roleId, heroId),
  			id 	= heroId,
  			type= heroType,
  		}
  		
  		local newHero = require("models.Hero").new(heroInfo)
  		newHero:create()
  		newHero.owner = self
  		self.heros[heroId] = newHero
  
  		if not params.notNotify then
  			local heroResponse = {}
  			table.insert(heroResponse, newHero:data())
  			local bin = MsgPack.pack(heroResponse)
  			SendPacket(actionCodes.Hero_loadInfos, bin)
  		end
be83d162   zhouahaihai   登陆成功。 增加数据结构修正功能
50
51
  	end
  
0a07bdd9   zhouahaihai   角色升级 。gm
52
53
54
55
56
57
58
59
60
61
62
63
  	function Role:delHero(params)
  		local roleId = self:getProperty('id')
  		local hero = self.heros[heroId]
  		if not hero then return end
  
  		self.heros[heroId] = nil
  		redisproxy:pipelining(function (red)
  			red:del(string.format(R_HERO, roleId, heroId))
  			red:srem(string.format(R_HEROS, roleId), heroId)
  		end)
  		SendPacket(actionCodes.Hero_loadInfos, MsgPack.pack({{id = heroId, bDel = true}}))
  	end
be83d162   zhouahaihai   登陆成功。 增加数据结构修正功能
64
  
0a07bdd9   zhouahaihai   角色升级 。gm
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
  	function Role:loadHeros()
  		local roleId = self:getProperty("id")
  		local heroIds = redisproxy:smembers(string.format(R_HEROS, roleId))
  		local redret = redisproxy:pipelining(function (red)
  			for _, heroId in ipairs(heroIds) do
  				red:hgetall(string.format(R_HERO, roleId, heroId))
  			end
  		end)
  		for index, heroId in ipairs(heroIds) do
  			local hero = require("models.Hero").new({key = string.format(R_HERO, roleId, heroId)})
  			if hero:load(table.array2Table(redret[index])) then
  				hero.owner = self
  				self.heros[tonumber(heroId)] = hero
  			end
  		end
  	end
  
  	-- 发奖功能入口
  	function Role:award()
  		
  	end
be83d162   zhouahaihai   登陆成功。 增加数据结构修正功能
86
87
88
  end
  
  return RolePlugin