Blame view

src/models/Rune.lua 3.04 KB
a12bfcce   测试   添加英雄表
1
  local Rune = class("Rune", require("shared.ModelBaseMysql"))
43cc5f51   gaofengduan   调整 equip 数据结构
2
  Rune.schema = {
a12bfcce   测试   添加英雄表
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
  
a12bfcce   测试   添加英雄表
16
17
18
19
  function Rune:getSimpleRuneId()
  	return self:getProperty("uid") % (self:getProperty("roleid") * MAX_RUNE_NUM)
  end
  
43cc5f51   gaofengduan   调整 equip 数据结构
20
21
  function Rune:notifyUpdateProperty(field, newValue, oldValue)
  	local datas = {
ee999bde   zhouhaihai   零件优化
22
23
24
25
26
27
28
29
  		uid = self:getProperty("uid"),
  		datas = {
  			{
  				key = field,
  				newValue = newValue,
  				oldValue = oldValue,
  			}
  		}
43cc5f51   gaofengduan   调整 equip 数据结构
30
31
32
33
  	}
  	self:notifyUpdateProperties(datas)
  end
  
f22a33af   zhouhaihai   自己的日志
34
35
36
37
38
39
40
41
  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   日志
42
  
f22a33af   zhouhaihai   自己的日志
43
  	self.owner:mylog("rune_action", contents)
3133cb76   zhouhaihai   日志
44
45
  end
  
43cc5f51   gaofengduan   调整 equip 数据结构
46
47
  function Rune:notifyUpdateProperties(params)
  	local updateData = {
a12bfcce   测试   添加英雄表
48
  		uid = self:getSimpleRuneId(),
43cc5f51   gaofengduan   调整 equip 数据结构
49
50
51
52
53
54
55
56
57
58
59
60
61
62
  		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   零件优化
63
64
65
66
  	local datas = {}
  	table.insert(datas, {key = params.field, newValue = self:getProperty(params.field)})
  
  	self:notifyUpdateProperties(datas)
ad484303   gaofengduan   add rune
67
68
69
70
  end
  
  -- types 类型=权重"2=100 3=100 4=100"  value最大值=最小值 "50=100 50=100 100=200"
  local function getRandomValue(types,values)
d3c0d87f   zhouhaihai   零件 bug
71
  	local typeMap = types:toArray()
ad484303   gaofengduan   add rune
72
  	local valueArry = values:toArray()
b58b5b49   zhouhaihai   零件bug
73
  
d3c0d87f   zhouhaihai   零件 bug
74
75
  	if #typeMap ~= #valueArry then return nil end
  
b58b5b49   zhouhaihai   零件bug
76
77
  	local typ, value
  	local typTab = {}
d3c0d87f   zhouhaihai   零件 bug
78
79
80
  	for _,w in ipairs(typeMap) do
  		w = w:toArray(true, "=")
  		table.insert(typTab,{t=w[1],w=w[2]})
ad484303   gaofengduan   add rune
81
82
  	end
  
b58b5b49   zhouhaihai   零件bug
83
84
  	local tk = math.randWeight(typTab, "w")
  	typ =  typTab[tk]["t"]
ad484303   gaofengduan   add rune
85
86
  
  	local range = valueArry[tk]:toArray(true,"=")
b58b5b49   zhouhaihai   零件bug
87
88
  	value = math.randomInt(range[1],range[2])
  	return typ, value
ad484303   gaofengduan   add rune
89
90
91
92
  end
  
  function Rune:generateAttrs()
  	local runeData  = csvdb["runeCsv"][self:getProperty("type")][self:getProperty("id")]
e3c5cc5e   zhouhaihai   跨服竞技场over
93
94
95
  	if not runeData then
  		print(self:getProperty("type"), self:getProperty("id"))
  	end
ad484303   gaofengduan   add rune
96
  	local attrs = ""
b58b5b49   zhouhaihai   零件bug
97
98
  	local typ, value = getRandomValue(runeData.attr1,runeData.range1)
  	attrs = attrs:setv(typ, value)
5697f9b3   zhouhaihai   零件属性bug
99
  	local typ, value = getRandomValue(runeData.attr2,runeData.range2) 
b58b5b49   zhouhaihai   零件bug
100
  	attrs = attrs:setv(typ, value)
ee3ac0b5   gaofengduan   fix magic
101
  	self:setProperty("attrs",attrs)
43cc5f51   gaofengduan   调整 equip 数据结构
102
103
104
105
  end
  
  function Rune:data()
  	return {
ad484303   gaofengduan   add rune
106
107
  		uid = self:getProperty("uid"),
  		type = self:getProperty("type"),
43cc5f51   gaofengduan   调整 equip 数据结构
108
  		id = self:getProperty("id"),
ad484303   gaofengduan   add rune
109
110
  		refer = self:getProperty("refer"),
  		attrs = self:getProperty("attrs"),
37ad731e   gaofengduan   fix rune
111
  		level = self:getProperty("level"),
43cc5f51   gaofengduan   调整 equip 数据结构
112
113
114
115
  	}
  end
  
  return Rune