Rune.lua
2.88 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
local Rune = class("Rune", require("shared.ModelBase"))
Rune.schema = {
uid = {"number"}, -- 唯一自增id
type = {"number"}, -- 装备位置
id = {"number"},
level = {"number", 0}, -- 等级
refer = {"number", 0}, -- 已装备英雄id
attrs = {"string",""} -- 基础属性值 id=value
}
function Rune:ctor( properties )
Rune.super.ctor(self, properties)
end
function Rune:notifyUpdateProperty(field, newValue, oldValue)
local datas = {
uid = self:getProperty("uid"),
datas = {
{
key = field,
newValue = newValue,
oldValue = oldValue,
}
}
}
self:notifyUpdateProperties(datas)
end
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")
self.owner:mylog("rune_action", contents)
end
function Rune:notifyUpdateProperties(params)
local updateData = {
uid = self:getProperty("uid"),
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
local datas = {}
table.insert(datas, {key = params.field, newValue = self:getProperty(params.field)})
self:notifyUpdateProperties(datas)
end
-- types 类型=权重"2=100 3=100 4=100" value最大值=最小值 "50=100 50=100 100=200"
local function getRandomValue(types,values)
local typeMap = types:toArray()
local valueArry = values:toArray()
if #typeMap ~= #valueArry then return nil end
local typ, value
local typTab = {}
for _,w in ipairs(typeMap) do
w = w:toArray(true, "=")
table.insert(typTab,{t=w[1],w=w[2]})
end
local tk = math.randWeight(typTab, "w")
typ = typTab[tk]["t"]
local range = valueArry[tk]:toArray(true,"=")
value = math.randomInt(range[1],range[2])
return typ, value
end
function Rune:generateAttrs()
local runeData = csvdb["runeCsv"][self:getProperty("type")][self:getProperty("id")]
if not runeData then
print(self:getProperty("type"), self:getProperty("id"))
end
local attrs = ""
local typ, value = getRandomValue(runeData.attr1,runeData.range1)
attrs = attrs:setv(typ, value)
local typ, value = getRandomValue(runeData.attr2,runeData.range2)
attrs = attrs:setv(typ, value)
self:setProperty("attrs",attrs)
end
function Rune:data()
return {
uid = self:getProperty("uid"),
type = self:getProperty("type"),
id = self:getProperty("id"),
refer = self:getProperty("refer"),
attrs = self:getProperty("attrs"),
level = self:getProperty("level"),
}
end
return Rune