Blame view

src/models/Rune.lua 2.98 KB
a12bfcce   liuzujun   添加英雄表
1
  local Rune = class("Rune", require("shared.ModelBaseMysql"))
43cc5f51   gaofengduan   调整 equip 数据结构
2
  Rune.schema = {
a12bfcce   liuzujun   添加英雄表
3
4
  	uid 		= {"number", 0, "pri"},      		-- 唯一自增id
  	roleid 		= {"number", 0, "index"},
ad484303   gaofengduan   add rune
5
  	type 		= {"number"},      		-- 装备位置
43cc5f51   gaofengduan   调整 equip 数据结构
6
7
  	id 			= {"number"},
  	level		= {"number", 0},		-- 等级
43cc5f51   gaofengduan   调整 equip 数据结构
8
  	refer		= {"number", 0},		-- 已装备英雄id
ad484303   gaofengduan   add rune
9
  	attrs       = {"string",""}         -- 基础属性值 id=value
43cc5f51   gaofengduan   调整 equip 数据结构
10
11
12
13
14
15
  }
  
  function Rune:ctor( properties )
  	Rune.super.ctor(self, properties)
  end
  
43cc5f51   gaofengduan   调整 equip 数据结构
16
17
  function Rune:notifyUpdateProperty(field, newValue, oldValue)
  	local datas = {
ee999bde   zhouhaihai   零件优化
18
19
20
21
22
23
24
25
  		uid = self:getProperty("uid"),
  		datas = {
  			{
  				key = field,
  				newValue = newValue,
  				oldValue = oldValue,
  			}
  		}
43cc5f51   gaofengduan   调整 equip 数据结构
26
27
28
29
  	}
  	self:notifyUpdateProperties(datas)
  end
  
f22a33af   zhouhaihai   自己的日志
30
31
32
33
34
35
36
37
  function Rune:mylog(contents)
  	contents = contents or {}
  	if contents["cint1"] or contents["cint2"] or contents["cint3"] then
  		print("heroLog error log have cint1 or cint2 or cint3 ", debug.traceback())
  	end
  	contents["cint1"] = self:getProperty("uid")
  	contents["cint2"] = self:getProperty("type")
  	contents["cint3"] = self:getProperty("id")
3133cb76   zhouhaihai   日志
38
  
f22a33af   zhouhaihai   自己的日志
39
  	self.owner:mylog("rune_action", contents)
3133cb76   zhouhaihai   日志
40
41
  end
  
43cc5f51   gaofengduan   调整 equip 数据结构
42
43
  function Rune:notifyUpdateProperties(params)
  	local updateData = {
52249374   liuzujun   添加铭文表
44
  		uid = self:getProperty("uid"),
43cc5f51   gaofengduan   调整 equip 数据结构
45
46
47
48
49
50
51
52
53
54
55
56
57
58
  		datas = params
  	}
  	SendPacket(actionCodes.Role_updateRune, MsgPack.pack(updateData))
  end
  
  function Rune:updateProperty(params)
  	if not params.field or (not params.delta and not params.value) then
  		return
  	end
  	if params.delta then
  		self:incrProperty(params.field, params.delta)
  	elseif params.value then
  		self:setProperty(params.field, params.value)
  	end
ee999bde   zhouhaihai   零件优化
59
60
61
62
  	local datas = {}
  	table.insert(datas, {key = params.field, newValue = self:getProperty(params.field)})
  
  	self:notifyUpdateProperties(datas)
ad484303   gaofengduan   add rune
63
64
65
66
  end
  
  -- types 类型=权重"2=100 3=100 4=100"  value最大值=最小值 "50=100 50=100 100=200"
  local function getRandomValue(types,values)
d3c0d87f   zhouhaihai   零件 bug
67
  	local typeMap = types:toArray()
ad484303   gaofengduan   add rune
68
  	local valueArry = values:toArray()
b58b5b49   zhouhaihai   零件bug
69
  
d3c0d87f   zhouhaihai   零件 bug
70
71
  	if #typeMap ~= #valueArry then return nil end
  
b58b5b49   zhouhaihai   零件bug
72
73
  	local typ, value
  	local typTab = {}
d3c0d87f   zhouhaihai   零件 bug
74
75
76
  	for _,w in ipairs(typeMap) do
  		w = w:toArray(true, "=")
  		table.insert(typTab,{t=w[1],w=w[2]})
ad484303   gaofengduan   add rune
77
78
  	end
  
b58b5b49   zhouhaihai   零件bug
79
80
  	local tk = math.randWeight(typTab, "w")
  	typ =  typTab[tk]["t"]
ad484303   gaofengduan   add rune
81
82
  
  	local range = valueArry[tk]:toArray(true,"=")
b58b5b49   zhouhaihai   零件bug
83
84
  	value = math.randomInt(range[1],range[2])
  	return typ, value
ad484303   gaofengduan   add rune
85
86
87
88
  end
  
  function Rune:generateAttrs()
  	local runeData  = csvdb["runeCsv"][self:getProperty("type")][self:getProperty("id")]
e3c5cc5e   zhouhaihai   跨服竞技场over
89
90
91
  	if not runeData then
  		print(self:getProperty("type"), self:getProperty("id"))
  	end
ad484303   gaofengduan   add rune
92
  	local attrs = ""
b58b5b49   zhouhaihai   零件bug
93
94
  	local typ, value = getRandomValue(runeData.attr1,runeData.range1)
  	attrs = attrs:setv(typ, value)
4e68858c   zhangqijia   fix: 铭文当随机出2个相同属性...
95
96
97
  	local typ, value = getRandomValue(runeData.attr2,runeData.range2)
      attrs = string.format("%s %d=%d", attrs, typ, value)
  	--attrs = attrs:setv(typ, value)
ee3ac0b5   gaofengduan   fix magic
98
  	self:setProperty("attrs",attrs)
43cc5f51   gaofengduan   调整 equip 数据结构
99
100
101
102
  end
  
  function Rune:data()
  	return {
ad484303   gaofengduan   add rune
103
104
  		uid = self:getProperty("uid"),
  		type = self:getProperty("type"),
43cc5f51   gaofengduan   调整 equip 数据结构
105
  		id = self:getProperty("id"),
ad484303   gaofengduan   add rune
106
107
  		refer = self:getProperty("refer"),
  		attrs = self:getProperty("attrs"),
37ad731e   gaofengduan   fix rune
108
  		level = self:getProperty("level"),
43cc5f51   gaofengduan   调整 equip 数据结构
109
110
111
112
  	}
  end
  
  return Rune