Blame view

src/models/Rune.lua 2.25 KB
43cc5f51   gaofengduan   调整 equip 数据结构
1
2
  local Rune = class("Rune", require("shared.ModelBase"))
  Rune.schema = {
ad484303   gaofengduan   add rune
3
4
  	uid 		= {"number"},      		-- 唯一自增id
  	type 		= {"number"},      		-- 装备位置
43cc5f51   gaofengduan   调整 equip 数据结构
5
6
  	id 			= {"number"},
  	level		= {"number", 0},		-- 等级
43cc5f51   gaofengduan   调整 equip 数据结构
7
  	refer		= {"number", 0},		-- 已装备英雄id
ad484303   gaofengduan   add rune
8
  	attrs       = {"string",""}         -- 基础属性值 id=value
43cc5f51   gaofengduan   调整 equip 数据结构
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
  }
  
  function Rune:ctor( properties )
  	Rune.super.ctor(self, properties)
  end
  
  function Rune:notifyUpdateProperty(field, newValue, oldValue)
  	local datas = {
  		key = field,
  		newValue = newValue,
  		oldValue = oldValue,
  	}
  	self:notifyUpdateProperties(datas)
  end
  
  function Rune:notifyUpdateProperties(params)
  	local updateData = {
ad484303   gaofengduan   add rune
26
  		uid = self:getProperty("uid"),
43cc5f51   gaofengduan   调整 equip 数据结构
27
28
29
30
31
32
33
34
35
36
37
38
39
40
  		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
ad484303   gaofengduan   add rune
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
  	self:notifyUpdateProperties(self:data())
  end
  
  -- types 类型=权重"2=100 3=100 4=100"  value最大值=最小值 "50=100 50=100 100=200"
  local function getRandomValue(types,values)
  	local typeMap = types:toNumMap()
  	local valueArry = values:toArray()
  	if table.nums(typeMap) ~= #valueArry then return nil end
  	local typ,value
  	local typTab,weightSum = {},0
  	for t,w in pairs(typeMap) do
  		weightSum = weightSum + w
  		table.insert(typTab,{t=t,w=weightSum})
  	end
  
  	local tk
  	local tmp = math.random(1,weightSum)
  	for k,v in ipairs(typTab) do
  		if v.w > tmp then
  			typ = v.t
  			tk = k
  			break
  		end
  	end
  
  	local range = valueArry[tk]:toArray(true,"=")
  	value = math.random(range[1],range[2])
ad484303   gaofengduan   add rune
68
69
70
71
72
73
  	return typ,value
  end
  
  function Rune:generateAttrs()
  	local runeData  = csvdb["runeCsv"][self:getProperty("type")][self:getProperty("id")]
  	local attrs = ""
ee3ac0b5   gaofengduan   fix magic
74
75
76
  	attrs = attrs:setv(getRandomValue(runeData.attr1,runeData.range1))
  	attrs = attrs:setv(getRandomValue(runeData.attr2,runeData.range2))
  	self:setProperty("attrs",attrs)
43cc5f51   gaofengduan   调整 equip 数据结构
77
78
79
80
  end
  
  function Rune:data()
  	return {
ad484303   gaofengduan   add rune
81
82
  		uid = self:getProperty("uid"),
  		type = self:getProperty("type"),
43cc5f51   gaofengduan   调整 equip 数据结构
83
  		id = self:getProperty("id"),
ad484303   gaofengduan   add rune
84
85
  		refer = self:getProperty("refer"),
  		attrs = self:getProperty("attrs"),
43cc5f51   gaofengduan   调整 equip 数据结构
86
87
88
89
  	}
  end
  
  return Rune