Blame view

src/models/Hero.lua 2.54 KB
0a07bdd9   zhouahaihai   角色升级 。gm
1
2
  local Hero = class("Hero", require("shared.ModelBase"))
  
8c74292c   zhouahaihai   增加item 以及 角色突破
3
4
5
  local HeroPlugin = import(".HeroPlugin")
  HeroPlugin.bind(Hero)
  
0a07bdd9   zhouahaihai   角色升级 。gm
6
7
8
9
  Hero.schema = {
  	key 		= { "string" },
  	id 			= {"number"},
  	type 		= {"number", 0},
8c74292c   zhouahaihai   增加item 以及 角色突破
10
11
12
13
14
15
16
17
      level       = {"number", 1},        -- 等级
      breakL      = {"number", 0},        -- 突破等级
      wakeL       = {"number", 0},        -- 觉醒等级
      skillL      = {"string", ""},       -- 技能等级 1=0 2=0 3=0
      talent      = {"string", ""},       -- 0=阶段 1=1 2=1 3=1 4=1 四个天赋当前阶段的等级  阶段默认为1  等级默认为0
  	battleV     = {"number", 0},		-- 保存战斗力
  
  
0a07bdd9   zhouahaihai   角色升级 。gm
18
19
20
21
22
  }
  
  Hero.fields = {
  	id 	= true,
  	type = true,
8c74292c   zhouahaihai   增加item 以及 角色突破
23
24
25
26
27
28
      level = true,
      breakL = true,
      wakeL = true,
      skillL = true,
      talent = true,
  	battleV = true,
0a07bdd9   zhouahaihai   角色升级 。gm
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
  }
  
  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)})
  
8c74292c   zhouahaihai   增加item 以及 角色突破
71
72
73
74
75
76
77
78
      local check = {level = true, breakL = true, wakeL = true, talent = true}
      if check[params.field] then
          local orginValue = self:getProperty("battleV")
          local curValue = self:saveBattleValue()
          if orginValue ~= curValue then
              table.insert(datas, { key = "battleV", newValue = curValue })
          end
      end
0a07bdd9   zhouahaihai   角色升级 。gm
79
  
8c74292c   zhouahaihai   增加item 以及 角色突破
80
      self:notifyUpdateProperties(datas)
0a07bdd9   zhouahaihai   角色升级 。gm
81
82
83
84
85
86
  end
  
  function Hero:data()
  	return {
  		id = self:getProperty("id"),
  		type = self:getProperty("type"),
8c74292c   zhouahaihai   增加item 以及 角色突破
87
88
89
90
91
92
          level = self:getProperty("level"),
          breakL = self:getProperty("breakL"),
          wakeL = self:getProperty("wakeL"),
          skillL = self:getProperty("skillL"),
          talent  = self:getProperty("talent"),
  		battleV = self:getProperty("battleV"),
0a07bdd9   zhouahaihai   角色升级 。gm
93
94
95
96
  	}
  end
  
  return Hero