Equip.lua 1.18 KB
local Equip = class("Equip", require("shared.ModelBase"))

Equip.schema = {
	type 		= {"number"},      		-- 类型
	level		= {"number"},			-- 等级
	count		= {"number", 0},		-- 数量
	refer		= {"number", 0},		-- 已装备英雄数
}

function Equip:ctor( properties )
	Equip.super.ctor(self, properties)
end

function Equip:notifyUpdateProperty(field, newValue, oldValue)
	local datas = {
		key = field,
		newValue = newValue,
		oldValue = oldValue,
	}
	self:notifyUpdateProperties(datas)
end

function Equip:notifyUpdateProperties(params)
	local updateData = {
		type = self:getProperty("type"),
		level = self:getProperty("level"),
		datas = params
	}
	SendPacket(actionCodes.Role_updateEquip, MsgPack.pack(updateData))
end

function Equip: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
	self:notifyUpdateProperties(self:data())
end

function Equip:data()
	return {
		type = self:getProperty("type"),
		level = self:getProperty("level"),
		count = self:getProperty("count"),
	}
end

return Equip