Commit 8c74292c7f0c236af3a2f0f80e5494446fee51a0

Authored by zhouahaihai
1 parent 5b28342d

增加item 以及 角色突破

src/GlobalVar.lua
1 1 XXTEA_KEY = "699D448D6D24f7F941E9F6E99F823E18"
2   -
3   -MAX_ROLE_NUM = 1000000
4   -
5 2 RESET_TIME = 4
6   -
7   -MAX_QUALITY_LEVEL = 5
8   -
9   -MAX_HERO_STAR = 6
10   -MAX_HERO_LVL = 100
11   -MAX_EVOL_LVL = 5 -- 最高进化等级
12   -MAX_BREAK_LVL = 16
13   -
14   -MAX_VIP = 15
15   -
16   -MAIL_EXPIRE_TIME = 7*86400
17   -
18   -MAX_FRIEND_SEARCH_COUNT = 5-- 最大搜索数目
19   -
20   -MAX_YZ_LEVEL = 10
21   -
22   -HOUR_ZONE = 9 -- 时区
23   -
24   -carbonType = {
25   - Normal = 10000,
26   - Special = 20000,
27   - Tower = 30000,
28   - Trial = 40000,
29   - Worldboss = 50000,
30   - Yz = 60000,
31   - Practice = 70000,
32   -}
33   -
34   -FinishType = {
35   - AllKill = 1, --全部清光
36   - BossKill = 2, --干光boss
37   -}
38   -
39   -StageType = {
40   - Common = 1, -- 普通
41   - Arrange = 2, -- 传送门
42   - WeakArrange = 3, -- 脆弱的传送门
43   - Supply = 4, -- 补给点
44   - Power = 5, -- 采集点
45   - Select = 6, -- 抉择点
46   - Cross = 7, -- 穿越点
47   - RandSelect = 8, -- 随机selet
48   - OnceArrange = 9, -- 一次性召唤点
49   -
50   -}
51   -
52   -AiType = {
53   - Warn = 1, -- 警戒型
54   - Occupy = 2, -- 占领型
55   - Special = 3, -- 特殊型
56   - Eat = 4, -- 吞噬特殊型
57   -}
58   -
59   -MonsterType = {
60   - Boss = 1, -- Boss
61   - Assault = 2, -- 突击怪
62   - Maker = 3, -- 制造者
63   - Dregs = 4, -- 渣滓
64   - Eat = 5, -- 吞噬者
65   - Ghost = 6, -- 隐藏boss
66   -}
67   -
68   -ItemType = {
69   - RandGiftClose = 1, -- 随机道具 不打开
70   - RandGiftOpen = 2, -- 随机道具 打开
71   - Material1 = 3, -- 油
72   - Material2 = 4, -- 魔力
73   - Material3 = 5, -- 食材
74   - Material4 = 6, -- 调料
75   - HeroSkin = 7, -- 食灵皮肤券
76   - PackageStudy = 8, -- 套餐研究素材
77   - Hero = 9, -- 武将
78   - QuickProp = 10, -- 快速道具
79   - BuildDraw = 11, -- 建造图纸
80   - Diamond = 12, -- 钻石
81   - Medel = 13, -- 勋章
82   - EnergyItem = 14, -- 次元能量,固定消耗道具
83   - Seed = 15, -- 种子
84   - QuickPlant = 16, -- 快速种植
85   - JobPerfer = 17, -- 职业偏向
86   - LoveItem = 18, -- 好感度材料
87   - HeadFarme = 19, -- 头像框
88   - HeadIcon = 20, -- 头像
89   - HomeSkin = 21, -- 主城皮肤
90   - Equip = 22, -- 装备
91   - Proof = 23, -- 交易凭证
92   - Dress = 24, -- 时装
93   - Build = 25, -- 建筑材料
94   - HeroBag = 26, -- 食灵背包扩展凭证
95   - EquipBag = 27, -- 武器背包扩展凭证
96   - GiftBag = 28, -- 礼物背包扩展凭证
97   - TeamBag = 29, -- 套餐扩展凭证
98   - HeroBuild = 30, -- 烹饪扩展凭证
99   - EquipBuild = 31, -- 采购扩展凭证
100   - PvpCoin = 32, --pvp积分, 商城购买
101   - ChooseBox = 33, --玩家选择盒子,
102   - DrawCoin = 34, --抽奖券,
103   - ActivityCoin = 35, --活动积分
104   - DinerBox = 36, --便当盒
105   - Fitment = 37, --家具
106   - DinerCar = 38, --餐车
107   - Accessory = 39, --配件
108   - DinerCarNum = 40, --餐车数量扩展
109   - DinerBoxNum = 41, --便当盒数量扩展
110   - AccMaterial = 42, --升级消耗材料
111   - DinerCoin = 43, --金币银币
112   - PangCi = 44, --胖次
113   - SkillUpM = 45, --技能升级材料
114   -}
115   -
116   -ROUND = {[5]=true,[6]=true,[9]=true,[13]=true,[14]=true,}
117   -
118 3 -- 属性枚举
119 4 AttsEnum = {
120 5 hp = 1, -- 血量
121 6 atk = 2, -- 攻击
122   - phyDef = 3, -- 物理防御
  7 + def = 3, -- 物理防御
123 8 hit = 4, -- 命中
124 9 miss = 5, -- 闪避
125 10 crit = 6, -- 暴击
126 11 atkSpeed = 7, -- 攻击速度
127 12 critHurt = 8, -- 暴伤
  13 + vampire = 9, -- 吸血
  14 + pierce = 10, -- 穿透
128 15 }
129 16  
130 17 AttsEnumEx = {
131 18 [1] = "hp", -- 血量
132 19 [2] = "atk", -- 攻击
133   - [3] = "phyDef", -- 物理防御
  20 + [3] = "def", -- 物理防御
134 21 [4] = "hit", -- 命中
135 22 [5] = "miss", -- 闪避
136 23 [6] = "crit", -- 暴击
137 24 [7] = "atkSpeed", -- 攻击速度
138 25 [8] = "critHurt", -- 暴伤
  26 + [9] = "vampire", -- 吸血
  27 + [10] = "pierce", -- 穿透
139 28 }
140 29  
141   --- 物品起始id
142   -ItemStartId = {
143   - hero = 1000, -- 英雄
144   - equip = 2000, -- 装备
145   -}
146   -
147   -HeroType = {
148   - legend = 1, -- 传说英雄
149   - diamond = 2, -- 钻石英雄
150   - normal = 3, -- 免费英雄
151   - lowStar = 4, -- 低星英雄
152   - monster = 5, -- 怪物
153   - npc = 6, -- npc
154   - beauty = 7, -- 女神
155   -}
156   -
157   -ExploreType = {
158   - Common = 1, -- 普通
159   - Born = 2, -- 出生点
160   - Score = 3, -- 积分点
161   - Cure = 4, -- 治疗点
162   - Item = 5, -- 道具店
163   - Cross = 6, -- 传送门
164   - Enemy = 7, -- 战斗点
165   - Event = 8, -- 抉择点
166   -}
167   -
168   -ExploreItemType = {
169   - Bomb = 1, -- 炸弹
170   - Weak = 2, -- 虚弱
171   - Slow = 3, -- 迟缓
172   - Invincible = 4, -- 无敌
173   - Forbiden = 5, -- 封印
174   - Victory = 6, -- 必胜
175   - Dice1 = 7, -- 固定点数1
176   - Dice2 = 8, -- 固定点数2
177   - Dice3 = 9, -- 固定点数3
178   - Dice4 = 10, -- 固定点数4
179   - Dice5 = 11, -- 固定点数5
180   - Dice6 = 12, -- 固定点数6
181   - DiceAll = 13, -- 任意点数
182   - Fight = 14, -- 决斗卡
183   -}
184   -
185   -RoomEvent = {
186   - move = 1,
187   - useItem = 2,
188   - playerOnStage = 3,
189   - playerStart = 4,
190   - playerEnd = 5,
191   - playerExit = 6,
192   - playerDice = 7,
193   - playerFight = 8,
194   - eventCross = 9,
195   - eventFight = 10,
196   - eventScore = 11,
197   - eventItem = 12,
198   - eventCure = 13,
199   - addScore = 14,
200   - updateMap = 15,
201   - addMainList = 16,
202   - addWaitList = 17,
203   - playerRevive= 18,
204   - playerTalk = 19,
205   - addHealth = 20,
  30 +ItemType = {
  31 + Coin = 1, -- 货币&材料(金币、钻石、经验、突破材料等)
  32 + HeroFragment = 2, -- 角色碎片
  33 + HeroFCommon = 3, -- 万能角色碎片(集齐N个,合成同稀有度随机角色)
  34 + Hero = 4, -- 角色
  35 + Head = 5, -- 头像
  36 + SkinFragment = 6, -- 皮肤碎片
  37 + SkinFCommon = 7, -- 万能皮肤碎片(集齐N个,合成同稀有度随机皮肤)
  38 + Skin = 8, -- 皮肤
  39 + EquipBase = 9, -- 基础装备
  40 + Rune = 10, -- 符文
  41 + Cuisine = 11, -- 料理(用于增加好感度、贩卖获得金币)
  42 + LunchBox = 12, -- 便当盒(料理合成,冒险系统消耗道具)
  43 + TimeBox = 13, -- 时间箱(开启需要时间,随机产出道具)
206 44 }
207 45  
208   -BANTYPE = {
209   - default = 0,
210   - heartWarning = 1,
  46 +-- 物品起始id
  47 +ItemStartId = {
  48 + Hero = 1000, -- 英雄
211 49 }
212 50 \ No newline at end of file
... ...
src/ProtocolCode.lua
... ... @@ -18,11 +18,12 @@ actionCodes = {
18 18 Role_syncTimeRpc = 104,
19 19 Role_updateProperty = 105,
20 20 Role_updateProperties = 106,
  21 + Role_updateItems = 107,
21 22  
22 23 Hero_loadInfos = 201,
23 24 Hero_updateProperty = 202,
24 25 Hero_levelUpRpc = 203,
25   -
  26 + Hero_breakRpc = 204,
26 27 }
27 28  
28 29 rpcResponseBegin = 10000
... ...
src/actions/GmAction.lua
... ... @@ -22,4 +22,14 @@ function _M.hero(role, pms)
22 22 return "成功"
23 23 end
24 24  
  25 +function _M.get(role, pms)
  26 + local itemId = tonum(pms.pm1)
  27 + if not csvdb["itemCsv"][itemId] then
  28 + return "物品不存在"
  29 + end
  30 + local count = tonum(pms.pm2)
  31 + role:award({[itemId] = count}, {})
  32 + return "成功"
  33 +end
  34 +
25 35 return _M
26 36 \ No newline at end of file
... ...
src/actions/HeroAction.lua
... ... @@ -21,11 +21,32 @@ function _M.levelUpRpc( agent, data )
21 21 if not hero then return end
22 22  
23 23 if hero:getProperty("level") >= hero:getMaxLevel() then return end
  24 + local curData = csvdb["unit_expCsv"][hero:getProperty("level")]
  25 + local cost = {[2] = curData.exp, [1] = curData.gold}
  26 + if not role:checkItemEnough(cost) then return end
  27 + role:costItems(cost, {})
24 28 hero:updateProperty({field = "level", delta = 1})
25 29  
26 30 SendPacket(actionCodes.Hero_levelUpRpc, '')
27 31 return true
28 32 end
29 33  
  34 +function _M.breakRpc( agent, data )
  35 + local role = agent.role
  36 + local msg = MsgPack.unpack(data)
  37 + local hero = role.heros[msg.id]
  38 + if not hero then return end
  39 +
  40 + if hero:getProperty("level") < hero:getMaxLevel() then return end
  41 + if hero:getProperty("breakL") >= #csvdb["unit_breakCsv"] then return end
  42 + local curData = csvdb["unit_breakCsv"][hero:getProperty("breakL")]
  43 + local cost = {[3] = curData.cost, [1] = curData.gold}
  44 + if not role:checkItemEnough(cost) then return end
  45 + role:costItems(cost, {})
  46 + hero:updateProperty({field = "breakL", delta = 1})
  47 +
  48 + SendPacket(actionCodes.Hero_breakRpc, '')
  49 + return true
  50 +end
30 51  
31 52 return _M
32 53 \ No newline at end of file
... ...
src/models/Hero.lua
1 1 local Hero = class("Hero", require("shared.ModelBase"))
2 2  
  3 +local HeroPlugin = import(".HeroPlugin")
  4 +HeroPlugin.bind(Hero)
  5 +
3 6 Hero.schema = {
4 7 key = { "string" },
5 8 id = {"number"},
6 9 type = {"number", 0},
7   - level = {"number", 1}, -- 等级
  10 + level = {"number", 1}, -- 等级
  11 + breakL = {"number", 0}, -- 突破等级
  12 + wakeL = {"number", 0}, -- 觉醒等级
  13 + skillL = {"string", ""}, -- 技能等级 1=0 2=0 3=0
  14 + talent = {"string", ""}, -- 0=阶段 1=1 2=1 3=1 4=1 四个天赋当前阶段的等级 阶段默认为1 等级默认为0
  15 + battleV = {"number", 0}, -- 保存战斗力
  16 +
  17 +
8 18 }
9 19  
10 20 Hero.fields = {
11 21 id = true,
12 22 type = true,
13   - level = true,
  23 + level = true,
  24 + breakL = true,
  25 + wakeL = true,
  26 + skillL = true,
  27 + talent = true,
  28 + battleV = true,
14 29 }
15 30  
16 31 function Hero:ctor( properties )
... ... @@ -53,18 +68,28 @@ function Hero:updateProperty(params)
53 68 local datas = {}
54 69 table.insert(datas, {key = params.field, newValue = self:getProperty(params.field)})
55 70  
56   - self:notifyUpdateProperties(datas)
57   -end
  71 + local check = {level = true, breakL = true, wakeL = true, talent = true}
  72 + if check[params.field] then
  73 + local orginValue = self:getProperty("battleV")
  74 + local curValue = self:saveBattleValue()
  75 + if orginValue ~= curValue then
  76 + table.insert(datas, { key = "battleV", newValue = curValue })
  77 + end
  78 + end
58 79  
59   -function Hero:getMaxLevel()
60   - return #csvdb["unit_expCsv"]
  80 + self:notifyUpdateProperties(datas)
61 81 end
62 82  
63 83 function Hero:data()
64 84 return {
65 85 id = self:getProperty("id"),
66 86 type = self:getProperty("type"),
67   - level = self:getProperty("level"),
  87 + level = self:getProperty("level"),
  88 + breakL = self:getProperty("breakL"),
  89 + wakeL = self:getProperty("wakeL"),
  90 + skillL = self:getProperty("skillL"),
  91 + talent = self:getProperty("talent"),
  92 + battleV = self:getProperty("battleV"),
68 93 }
69 94 end
70 95  
... ...
src/models/HeroPlugin.lua 0 → 100644
... ... @@ -0,0 +1,100 @@
  1 +local HeroPlugin = {}
  2 +
  3 +
  4 +function HeroPlugin.bind(Hero)
  5 +
  6 + function Hero:getMaxLevel()
  7 + return math.min(#csvdb["unit_expCsv"], csvdb["unit_breakCsv"][self:getProperty("breakL")].levelLimit)
  8 + end
  9 +
  10 + function Hero:getSPoint()
  11 + local point = 0
  12 + for i = 0, self:getProperty("wakeL") do
  13 + if csvdb["unit_wakeCsv"][i] then
  14 + point = point + csvdb["unit_wakeCsv"][i].sp
  15 + end
  16 + end
  17 + return point
  18 + end
  19 +
  20 + function Hero:getLSPoint()
  21 + local point = self:getSPoint()
  22 + for skill, level in pairs(self:getProperty("skillL"):toNumMap()) do
  23 + point = point - level
  24 + end
  25 + return point
  26 + end
  27 + --角色属性值 = 基础属性值(unit)* [ 1 + 升级属性(unit_exp)+ 突破属性(unit_break)] * [ 1 + 觉醒属性(unit_wake)+ 天赋属性(unit_talent)]
  28 + function Hero:getBaseAttrs(params)
  29 + params = params or {}
  30 + local unitData = csvdb["unitCsv"][self:getProperty("type")]
  31 + local level = params.level or self:getProperty("level")
  32 + local breakL = params.breakL or self:getProperty("breakL")
  33 + local wakeL = params.wakeL or self:getProperty("wakeL")
  34 + local talent = params.talent or self:getProperty("talent")
  35 +
  36 +
  37 + local attrs = {}
  38 + for _, attName in pairs(AttsEnumEx) do
  39 + attrs[attName] = unitData[attName] or 0
  40 + end
  41 + local lData = csvdb["unit_expCsv"][level]
  42 + local blData = csvdb["unit_breakCsv"][breakL]
  43 + -- core
  44 + for attr, value in pairs(attrs) do
  45 + attrs[attr] = attrs[attr] * (100 + (lData[attr .. "Level"] or 0) + (blData[attr .. "Level"] or 0)) / 100
  46 + end
  47 +
  48 + local talentAttrS = {}
  49 + -- 天赋阶段属性
  50 + for i = 1, (talent:getv(0, 1) - 1) do
  51 + local curData = csvdb["unit_talentCsv"][i]
  52 + local effect = curData[#curData].effect:toArray(true, "=")
  53 + talentAttrS[AttsEnumEx[effect[1]]] = (talentAttrS[AttsEnumEx[effect[1]]] or 0) + effect[2]
  54 + end
  55 + -- 四个基础属性
  56 + local curData = csvdb["unit_talentCsv"][talent:getv(0, 1)]
  57 + if not curData then -- 已经满阶段了
  58 + curData = csvdb["unit_talentCsv"][#csvdb["unit_talentCsv"]]
  59 + local strength = curData[#curData].strength
  60 + for i = 1, 4 do
  61 + talentAttrS[AttsEnumEx[i]] = (talentAttrS[AttsEnumEx[i]] or 0) + strength
  62 + end
  63 + else
  64 + for i = 1, 4 do --4个天赋
  65 + talentAttrS[AttsEnumEx[i]] = (talentAttrS[AttsEnumEx[i]] or 0) + curData[talent:getv(i, 0)].strength
  66 + end
  67 + end
  68 +
  69 + local wData = csvdb["unit_wakeCsv"][wakeL]
  70 + for attr, value in pairs(attrs) do
  71 + attrs[attr] = attrs[attr] * (100 + (wData[attr .. "Level"] or 0) + (talentAttrS[attr] or 0)) / 100
  72 + end
  73 +
  74 + return attrs
  75 + end
  76 +
  77 + --当前属性 = [ 角色属性值 + 基础装备(固定)+ 专属装备(固定)] * [ 1 + 基础装备(百分比) + 专属装备(百分比)]
  78 + function Hero:getTotalAttrs(params)
  79 + local attrs = self:getBaseAttrs()
  80 + return attrs
  81 + end
  82 + -- 战斗力(当前属性)= POWER[(生命 + 防御 * 7 + 闪避 * 4)*(攻击 + 命中 * 4)*(1 + 暴击几率 * 暴击伤害)* 攻击速度 / 60000 ,0.8 ]
  83 + function Hero:getBattleValue()
  84 + local attrs = self:getTotalAttrs()
  85 + local battleValue = ((attrs["hp"] + attrs["def"] * 7 + attrs["miss"] * 4) * (attrs["atk"] + attrs["hit"] * 4) * (1 + attrs["crit"] * attrs["critHurt"]) * attrs["atkSpeed"] / 60000) ^ 0.8
  86 + return math.floor(battleValue)
  87 + end
  88 +
  89 + function Hero:saveBattleValue()
  90 + local battleValue = self:getBattleValue()
  91 + if battleValue ~= self:getProperty("battleV") then
  92 + self:setProperty("battleV", battleValue)
  93 + end
  94 + return battleValue
  95 + end
  96 +
  97 +end
  98 +
  99 +
  100 +return HeroPlugin
0 101 \ No newline at end of file
... ...
src/models/RolePlugin.lua
... ... @@ -21,6 +21,97 @@ function RolePlugin.bind(Role)
21 21 function Role:onOfflineEvent()
22 22  
23 23 end
  24 +
  25 +
  26 + local function _award(self, itemId, count, params)
  27 + local itemData = csvdb["itemCsv"][itemId]
  28 + local curType = itemData.type
  29 + local change = {} -- 奖励被转化为了其他奖励 id = count
  30 +
  31 + if curType == ItemType.Hero then
  32 + params.type = itemId - ItemStartId.Hero
  33 + for i = 1, count do
  34 + self:addHero(params)
  35 + end
  36 + else
  37 + params.itemId = itemId
  38 + params.count = count
  39 + self:addItem(params)
  40 + end
  41 +
  42 + return count, change -- count 刷新实际发放的奖励个数 change 物品实际奖励与当前id 不符 就发生转换 而不实际发奖
  43 + end
  44 +
  45 +
  46 + -- 发奖功能入口 award string id=count or {[id] = count}
  47 + function Role:award(gift, params)
  48 + local tgift = {}
  49 + if type(award) == "string" then
  50 + for _, one in pairs(gift:toTableArray(true)) do
  51 + tgift[one[1]] = (tgift[one[1]] or 0) + one[2]
  52 + end
  53 + else
  54 + tgift = gift
  55 + end
  56 + local reward, allChange = {}, {}
  57 +
  58 + for itemId, count in pairs(tgift) do
  59 + local count, change = _award(self, itemId, count, clone(params or {}))
  60 + if next(change) then
  61 + local cr, cc = self:award(change, params) -- 内部转换忽略
  62 + for _id, _ct in pairs(cr) do
  63 + reward[_id] = (reward[_id] or 0) + _ct
  64 + end
  65 + table.insert(allChange, {form = {[itemId] = count}, to = cr})
  66 + else
  67 + reward[itemId] = (reward[itemId] or 0) + count
  68 + end
  69 + end
  70 +
  71 + return reward, allChange --实际获得的奖励 和 最高级奖励转化过程
  72 + end
  73 +
  74 + function Role:addItem(params)
  75 + params = params or {}
  76 + local items = self:getProperty("items")
  77 + local origin = items:getv(params.itemId, 0)
  78 + local nums = origin+params.count
  79 + if nums <= 0 then
  80 + items = items:delk(params.itemId)
  81 + nums = 0
  82 + else
  83 + items = items:incrv(params.itemId, params.count)
  84 + end
  85 + self:setProperty("items", items)
  86 + if not params.notNotify then
  87 + SendPacket(actionCodes.Role_updateItems, MsgPack.pack({[params.itemId] = nums}))
  88 + end
  89 + end
  90 +
  91 + function Role:checkItemEnough(itemCountT)
  92 + local less = {}
  93 + for itemId, count in pairs(itemCountT) do
  94 + local last = self:getItemCount(itemId) - count
  95 + if last < 0 then
  96 + less[itemId] = -last
  97 + end
  98 + end
  99 + return (not next(less)), less -- 是否足够,,缺什么缺多少
  100 + end
  101 +
  102 + function Role:costItems(itemCountT, params)
  103 + for itemId, count in pairs(itemCountT) do
  104 + local pms = clone(params or {})
  105 + pms.itemId = itemId
  106 + pms.count = - count
  107 + self:addItem(pms)
  108 + end
  109 + end
  110 +
  111 + function Role:getItemCount(itemId)
  112 + return self:getProperty("items"):getv(itemId, 0)
  113 + end
  114 +
24 115 function Role:addHero(params)
25 116 local roleId = self:getProperty("id")
26 117 local heroId = tonum(redisproxy:hincrby(string.format(R_INCR, roleId), "hero", 1))
... ... @@ -39,6 +130,7 @@ function RolePlugin.bind(Role)
39 130 local newHero = require("models.Hero").new(heroInfo)
40 131 newHero:create()
41 132 newHero.owner = self
  133 + newHero:saveBattleValue()
42 134 self.heros[heroId] = newHero
43 135  
44 136 if not params.notNotify then
... ... @@ -79,10 +171,6 @@ function RolePlugin.bind(Role)
79 171 end
80 172 end
81 173  
82   - -- 发奖功能入口
83   - function Role:award()
84   -
85   - end
86 174 end
87 175  
88 176 return RolePlugin
89 177 \ No newline at end of file
... ...