local Hero = class("Hero", require("shared.ModelBase")) Hero.schema = { key = { "string" }, id = {"number"}, type = {"number", 0}, level = {"number", 1}, -- 等级 } Hero.fields = { id = true, type = true, level = true, } function Hero:ctor( properties ) Hero.super.ctor(self, properties) end function Hero:notifyUpdateProperty(field, newValue, oldValue) local updateData = { id = self:getProperty("id"), datas = { { key = field, newValue = newValue, oldValue = oldValue or "", }, } } SendPacket(actionCodes.Hero_updateProperty, MsgPack.pack(updateData)) end function Hero:notifyUpdateProperties(params) local updateData = { id = self:getProperty("id"), datas = params } SendPacket(actionCodes.Hero_updateProperty, MsgPack.pack(updateData)) end function Hero: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 function Hero:getMaxLevel() return #csvdb["unit_expCsv"] end function Hero:data() return { id = self:getProperty("id"), type = self:getProperty("type"), level = self:getProperty("level"), } end return Hero