From 8c74292c7f0c236af3a2f0f80e5494446fee51a0 Mon Sep 17 00:00:00 2001 From: zhouahaihai Date: Thu, 29 Nov 2018 13:50:58 +0800 Subject: [PATCH] 增加item 以及 角色突破 --- src/GlobalVar.lua | 208 +++++++++++++++++++++++----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- src/ProtocolCode.lua | 3 ++- src/actions/GmAction.lua | 10 ++++++++++ src/actions/HeroAction.lua | 21 +++++++++++++++++++++ src/models/Hero.lua | 39 ++++++++++++++++++++++++++++++++------- src/models/HeroPlugin.lua | 100 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ src/models/RolePlugin.lua | 96 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++---- 7 files changed, 280 insertions(+), 197 deletions(-) create mode 100644 src/models/HeroPlugin.lua diff --git a/src/GlobalVar.lua b/src/GlobalVar.lua index eae6725..1e8df82 100644 --- a/src/GlobalVar.lua +++ b/src/GlobalVar.lua @@ -1,211 +1,49 @@ XXTEA_KEY = "699D448D6D24f7F941E9F6E99F823E18" - -MAX_ROLE_NUM = 1000000 - RESET_TIME = 4 - -MAX_QUALITY_LEVEL = 5 - -MAX_HERO_STAR = 6 -MAX_HERO_LVL = 100 -MAX_EVOL_LVL = 5 -- 最高进化等级 -MAX_BREAK_LVL = 16 - -MAX_VIP = 15 - -MAIL_EXPIRE_TIME = 7*86400 - -MAX_FRIEND_SEARCH_COUNT = 5-- 最大搜索数目 - -MAX_YZ_LEVEL = 10 - -HOUR_ZONE = 9 -- 时区 - -carbonType = { - Normal = 10000, - Special = 20000, - Tower = 30000, - Trial = 40000, - Worldboss = 50000, - Yz = 60000, - Practice = 70000, -} - -FinishType = { - AllKill = 1, --全部清光 - BossKill = 2, --干光boss -} - -StageType = { - Common = 1, -- 普通 - Arrange = 2, -- 传送门 - WeakArrange = 3, -- 脆弱的传送门 - Supply = 4, -- 补给点 - Power = 5, -- 采集点 - Select = 6, -- 抉择点 - Cross = 7, -- 穿越点 - RandSelect = 8, -- 随机selet - OnceArrange = 9, -- 一次性召唤点 - -} - -AiType = { - Warn = 1, -- 警戒型 - Occupy = 2, -- 占领型 - Special = 3, -- 特殊型 - Eat = 4, -- 吞噬特殊型 -} - -MonsterType = { - Boss = 1, -- Boss - Assault = 2, -- 突击怪 - Maker = 3, -- 制造者 - Dregs = 4, -- 渣滓 - Eat = 5, -- 吞噬者 - Ghost = 6, -- 隐藏boss -} - -ItemType = { - RandGiftClose = 1, -- 随机道具 不打开 - RandGiftOpen = 2, -- 随机道具 打开 - Material1 = 3, -- 油 - Material2 = 4, -- 魔力 - Material3 = 5, -- 食材 - Material4 = 6, -- 调料 - HeroSkin = 7, -- 食灵皮肤券 - PackageStudy = 8, -- 套餐研究素材 - Hero = 9, -- 武将 - QuickProp = 10, -- 快速道具 - BuildDraw = 11, -- 建造图纸 - Diamond = 12, -- 钻石 - Medel = 13, -- 勋章 - EnergyItem = 14, -- 次元能量,固定消耗道具 - Seed = 15, -- 种子 - QuickPlant = 16, -- 快速种植 - JobPerfer = 17, -- 职业偏向 - LoveItem = 18, -- 好感度材料 - HeadFarme = 19, -- 头像框 - HeadIcon = 20, -- 头像 - HomeSkin = 21, -- 主城皮肤 - Equip = 22, -- 装备 - Proof = 23, -- 交易凭证 - Dress = 24, -- 时装 - Build = 25, -- 建筑材料 - HeroBag = 26, -- 食灵背包扩展凭证 - EquipBag = 27, -- 武器背包扩展凭证 - GiftBag = 28, -- 礼物背包扩展凭证 - TeamBag = 29, -- 套餐扩展凭证 - HeroBuild = 30, -- 烹饪扩展凭证 - EquipBuild = 31, -- 采购扩展凭证 - PvpCoin = 32, --pvp积分, 商城购买 - ChooseBox = 33, --玩家选择盒子, - DrawCoin = 34, --抽奖券, - ActivityCoin = 35, --活动积分 - DinerBox = 36, --便当盒 - Fitment = 37, --家具 - DinerCar = 38, --餐车 - Accessory = 39, --配件 - DinerCarNum = 40, --餐车数量扩展 - DinerBoxNum = 41, --便当盒数量扩展 - AccMaterial = 42, --升级消耗材料 - DinerCoin = 43, --金币银币 - PangCi = 44, --胖次 - SkillUpM = 45, --技能升级材料 -} - -ROUND = {[5]=true,[6]=true,[9]=true,[13]=true,[14]=true,} - -- 属性枚举 AttsEnum = { hp = 1, -- 血量 atk = 2, -- 攻击 - phyDef = 3, -- 物理防御 + def = 3, -- 物理防御 hit = 4, -- 命中 miss = 5, -- 闪避 crit = 6, -- 暴击 atkSpeed = 7, -- 攻击速度 critHurt = 8, -- 暴伤 + vampire = 9, -- 吸血 + pierce = 10, -- 穿透 } AttsEnumEx = { [1] = "hp", -- 血量 [2] = "atk", -- 攻击 - [3] = "phyDef", -- 物理防御 + [3] = "def", -- 物理防御 [4] = "hit", -- 命中 [5] = "miss", -- 闪避 [6] = "crit", -- 暴击 [7] = "atkSpeed", -- 攻击速度 [8] = "critHurt", -- 暴伤 + [9] = "vampire", -- 吸血 + [10] = "pierce", -- 穿透 } --- 物品起始id -ItemStartId = { - hero = 1000, -- 英雄 - equip = 2000, -- 装备 -} - -HeroType = { - legend = 1, -- 传说英雄 - diamond = 2, -- 钻石英雄 - normal = 3, -- 免费英雄 - lowStar = 4, -- 低星英雄 - monster = 5, -- 怪物 - npc = 6, -- npc - beauty = 7, -- 女神 -} - -ExploreType = { - Common = 1, -- 普通 - Born = 2, -- 出生点 - Score = 3, -- 积分点 - Cure = 4, -- 治疗点 - Item = 5, -- 道具店 - Cross = 6, -- 传送门 - Enemy = 7, -- 战斗点 - Event = 8, -- 抉择点 -} - -ExploreItemType = { - Bomb = 1, -- 炸弹 - Weak = 2, -- 虚弱 - Slow = 3, -- 迟缓 - Invincible = 4, -- 无敌 - Forbiden = 5, -- 封印 - Victory = 6, -- 必胜 - Dice1 = 7, -- 固定点数1 - Dice2 = 8, -- 固定点数2 - Dice3 = 9, -- 固定点数3 - Dice4 = 10, -- 固定点数4 - Dice5 = 11, -- 固定点数5 - Dice6 = 12, -- 固定点数6 - DiceAll = 13, -- 任意点数 - Fight = 14, -- 决斗卡 -} - -RoomEvent = { - move = 1, - useItem = 2, - playerOnStage = 3, - playerStart = 4, - playerEnd = 5, - playerExit = 6, - playerDice = 7, - playerFight = 8, - eventCross = 9, - eventFight = 10, - eventScore = 11, - eventItem = 12, - eventCure = 13, - addScore = 14, - updateMap = 15, - addMainList = 16, - addWaitList = 17, - playerRevive= 18, - playerTalk = 19, - addHealth = 20, +ItemType = { + Coin = 1, -- 货币&材料(金币、钻石、经验、突破材料等) + HeroFragment = 2, -- 角色碎片 + HeroFCommon = 3, -- 万能角色碎片(集齐N个,合成同稀有度随机角色) + Hero = 4, -- 角色 + Head = 5, -- 头像 + SkinFragment = 6, -- 皮肤碎片 + SkinFCommon = 7, -- 万能皮肤碎片(集齐N个,合成同稀有度随机皮肤) + Skin = 8, -- 皮肤 + EquipBase = 9, -- 基础装备 + Rune = 10, -- 符文 + Cuisine = 11, -- 料理(用于增加好感度、贩卖获得金币) + LunchBox = 12, -- 便当盒(料理合成,冒险系统消耗道具) + TimeBox = 13, -- 时间箱(开启需要时间,随机产出道具) } -BANTYPE = { - default = 0, - heartWarning = 1, +-- 物品起始id +ItemStartId = { + Hero = 1000, -- 英雄 } \ No newline at end of file diff --git a/src/ProtocolCode.lua b/src/ProtocolCode.lua index 367a9ce..1aa79a8 100644 --- a/src/ProtocolCode.lua +++ b/src/ProtocolCode.lua @@ -18,11 +18,12 @@ actionCodes = { Role_syncTimeRpc = 104, Role_updateProperty = 105, Role_updateProperties = 106, + Role_updateItems = 107, Hero_loadInfos = 201, Hero_updateProperty = 202, Hero_levelUpRpc = 203, - + Hero_breakRpc = 204, } rpcResponseBegin = 10000 diff --git a/src/actions/GmAction.lua b/src/actions/GmAction.lua index 8189056..7f337cf 100644 --- a/src/actions/GmAction.lua +++ b/src/actions/GmAction.lua @@ -22,4 +22,14 @@ function _M.hero(role, pms) return "成功" end +function _M.get(role, pms) + local itemId = tonum(pms.pm1) + if not csvdb["itemCsv"][itemId] then + return "物品不存在" + end + local count = tonum(pms.pm2) + role:award({[itemId] = count}, {}) + return "成功" +end + return _M \ No newline at end of file diff --git a/src/actions/HeroAction.lua b/src/actions/HeroAction.lua index b4408a9..5eee896 100644 --- a/src/actions/HeroAction.lua +++ b/src/actions/HeroAction.lua @@ -21,11 +21,32 @@ function _M.levelUpRpc( agent, data ) if not hero then return end if hero:getProperty("level") >= hero:getMaxLevel() then return end + local curData = csvdb["unit_expCsv"][hero:getProperty("level")] + local cost = {[2] = curData.exp, [1] = curData.gold} + if not role:checkItemEnough(cost) then return end + role:costItems(cost, {}) hero:updateProperty({field = "level", delta = 1}) SendPacket(actionCodes.Hero_levelUpRpc, '') return true end +function _M.breakRpc( agent, data ) + local role = agent.role + local msg = MsgPack.unpack(data) + local hero = role.heros[msg.id] + if not hero then return end + + if hero:getProperty("level") < hero:getMaxLevel() then return end + if hero:getProperty("breakL") >= #csvdb["unit_breakCsv"] then return end + local curData = csvdb["unit_breakCsv"][hero:getProperty("breakL")] + local cost = {[3] = curData.cost, [1] = curData.gold} + if not role:checkItemEnough(cost) then return end + role:costItems(cost, {}) + hero:updateProperty({field = "breakL", delta = 1}) + + SendPacket(actionCodes.Hero_breakRpc, '') + return true +end return _M \ No newline at end of file diff --git a/src/models/Hero.lua b/src/models/Hero.lua index 654ac87..8f07018 100644 --- a/src/models/Hero.lua +++ b/src/models/Hero.lua @@ -1,16 +1,31 @@ local Hero = class("Hero", require("shared.ModelBase")) +local HeroPlugin = import(".HeroPlugin") +HeroPlugin.bind(Hero) + Hero.schema = { key = { "string" }, id = {"number"}, type = {"number", 0}, - level = {"number", 1}, -- 等级 + 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}, -- 保存战斗力 + + } Hero.fields = { id = true, type = true, - level = true, + level = true, + breakL = true, + wakeL = true, + skillL = true, + talent = true, + battleV = true, } function Hero:ctor( properties ) @@ -53,18 +68,28 @@ function Hero:updateProperty(params) local datas = {} table.insert(datas, {key = params.field, newValue = self:getProperty(params.field)}) - self:notifyUpdateProperties(datas) -end + 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 -function Hero:getMaxLevel() - return #csvdb["unit_expCsv"] + self:notifyUpdateProperties(datas) end function Hero:data() return { id = self:getProperty("id"), type = self:getProperty("type"), - level = self:getProperty("level"), + level = self:getProperty("level"), + breakL = self:getProperty("breakL"), + wakeL = self:getProperty("wakeL"), + skillL = self:getProperty("skillL"), + talent = self:getProperty("talent"), + battleV = self:getProperty("battleV"), } end diff --git a/src/models/HeroPlugin.lua b/src/models/HeroPlugin.lua new file mode 100644 index 0000000..00ff0b0 --- /dev/null +++ b/src/models/HeroPlugin.lua @@ -0,0 +1,100 @@ +local HeroPlugin = {} + + +function HeroPlugin.bind(Hero) + + function Hero:getMaxLevel() + return math.min(#csvdb["unit_expCsv"], csvdb["unit_breakCsv"][self:getProperty("breakL")].levelLimit) + end + + function Hero:getSPoint() + local point = 0 + for i = 0, self:getProperty("wakeL") do + if csvdb["unit_wakeCsv"][i] then + point = point + csvdb["unit_wakeCsv"][i].sp + end + end + return point + end + + function Hero:getLSPoint() + local point = self:getSPoint() + for skill, level in pairs(self:getProperty("skillL"):toNumMap()) do + point = point - level + end + return point + end + --角色属性值 = 基础属性值(unit)* [ 1 + 升级属性(unit_exp)+ 突破属性(unit_break)] * [ 1 + 觉醒属性(unit_wake)+ 天赋属性(unit_talent)] + function Hero:getBaseAttrs(params) + params = params or {} + local unitData = csvdb["unitCsv"][self:getProperty("type")] + local level = params.level or self:getProperty("level") + local breakL = params.breakL or self:getProperty("breakL") + local wakeL = params.wakeL or self:getProperty("wakeL") + local talent = params.talent or self:getProperty("talent") + + + local attrs = {} + for _, attName in pairs(AttsEnumEx) do + attrs[attName] = unitData[attName] or 0 + end + local lData = csvdb["unit_expCsv"][level] + local blData = csvdb["unit_breakCsv"][breakL] + -- core + for attr, value in pairs(attrs) do + attrs[attr] = attrs[attr] * (100 + (lData[attr .. "Level"] or 0) + (blData[attr .. "Level"] or 0)) / 100 + end + + local talentAttrS = {} + -- 天赋阶段属性 + for i = 1, (talent:getv(0, 1) - 1) do + local curData = csvdb["unit_talentCsv"][i] + local effect = curData[#curData].effect:toArray(true, "=") + talentAttrS[AttsEnumEx[effect[1]]] = (talentAttrS[AttsEnumEx[effect[1]]] or 0) + effect[2] + end + -- 四个基础属性 + local curData = csvdb["unit_talentCsv"][talent:getv(0, 1)] + if not curData then -- 已经满阶段了 + curData = csvdb["unit_talentCsv"][#csvdb["unit_talentCsv"]] + local strength = curData[#curData].strength + for i = 1, 4 do + talentAttrS[AttsEnumEx[i]] = (talentAttrS[AttsEnumEx[i]] or 0) + strength + end + else + for i = 1, 4 do --4个天赋 + talentAttrS[AttsEnumEx[i]] = (talentAttrS[AttsEnumEx[i]] or 0) + curData[talent:getv(i, 0)].strength + end + end + + local wData = csvdb["unit_wakeCsv"][wakeL] + for attr, value in pairs(attrs) do + attrs[attr] = attrs[attr] * (100 + (wData[attr .. "Level"] or 0) + (talentAttrS[attr] or 0)) / 100 + end + + return attrs + end + + --当前属性 = [ 角色属性值 + 基础装备(固定)+ 专属装备(固定)] * [ 1 + 基础装备(百分比) + 专属装备(百分比)] + function Hero:getTotalAttrs(params) + local attrs = self:getBaseAttrs() + return attrs + end + -- 战斗力(当前属性)= POWER[(生命 + 防御 * 7 + 闪避 * 4)*(攻击 + 命中 * 4)*(1 + 暴击几率 * 暴击伤害)* 攻击速度 / 60000 ,0.8 ] + function Hero:getBattleValue() + local attrs = self:getTotalAttrs() + 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 + return math.floor(battleValue) + end + + function Hero:saveBattleValue() + local battleValue = self:getBattleValue() + if battleValue ~= self:getProperty("battleV") then + self:setProperty("battleV", battleValue) + end + return battleValue + end + +end + + +return HeroPlugin \ No newline at end of file diff --git a/src/models/RolePlugin.lua b/src/models/RolePlugin.lua index 91bb72d..f71ddb9 100644 --- a/src/models/RolePlugin.lua +++ b/src/models/RolePlugin.lua @@ -21,6 +21,97 @@ function RolePlugin.bind(Role) function Role:onOfflineEvent() end + + + local function _award(self, itemId, count, params) + local itemData = csvdb["itemCsv"][itemId] + local curType = itemData.type + local change = {} -- 奖励被转化为了其他奖励 id = count + + if curType == ItemType.Hero then + params.type = itemId - ItemStartId.Hero + for i = 1, count do + self:addHero(params) + end + else + params.itemId = itemId + params.count = count + self:addItem(params) + end + + return count, change -- count 刷新实际发放的奖励个数 change 物品实际奖励与当前id 不符 就发生转换 而不实际发奖 + end + + + -- 发奖功能入口 award string id=count or {[id] = count} + function Role:award(gift, params) + local tgift = {} + if type(award) == "string" then + for _, one in pairs(gift:toTableArray(true)) do + tgift[one[1]] = (tgift[one[1]] or 0) + one[2] + end + else + tgift = gift + end + local reward, allChange = {}, {} + + for itemId, count in pairs(tgift) do + local count, change = _award(self, itemId, count, clone(params or {})) + if next(change) then + local cr, cc = self:award(change, params) -- 内部转换忽略 + for _id, _ct in pairs(cr) do + reward[_id] = (reward[_id] or 0) + _ct + end + table.insert(allChange, {form = {[itemId] = count}, to = cr}) + else + reward[itemId] = (reward[itemId] or 0) + count + end + end + + return reward, allChange --实际获得的奖励 和 最高级奖励转化过程 + end + + function Role:addItem(params) + params = params or {} + local items = self:getProperty("items") + local origin = items:getv(params.itemId, 0) + local nums = origin+params.count + if nums <= 0 then + items = items:delk(params.itemId) + nums = 0 + else + items = items:incrv(params.itemId, params.count) + end + self:setProperty("items", items) + if not params.notNotify then + SendPacket(actionCodes.Role_updateItems, MsgPack.pack({[params.itemId] = nums})) + end + end + + function Role:checkItemEnough(itemCountT) + local less = {} + for itemId, count in pairs(itemCountT) do + local last = self:getItemCount(itemId) - count + if last < 0 then + less[itemId] = -last + end + end + return (not next(less)), less -- 是否足够,,缺什么缺多少 + end + + function Role:costItems(itemCountT, params) + for itemId, count in pairs(itemCountT) do + local pms = clone(params or {}) + pms.itemId = itemId + pms.count = - count + self:addItem(pms) + end + end + + function Role:getItemCount(itemId) + return self:getProperty("items"):getv(itemId, 0) + end + function Role:addHero(params) local roleId = self:getProperty("id") local heroId = tonum(redisproxy:hincrby(string.format(R_INCR, roleId), "hero", 1)) @@ -39,6 +130,7 @@ function RolePlugin.bind(Role) local newHero = require("models.Hero").new(heroInfo) newHero:create() newHero.owner = self + newHero:saveBattleValue() self.heros[heroId] = newHero if not params.notNotify then @@ -79,10 +171,6 @@ function RolePlugin.bind(Role) end end - -- 发奖功能入口 - function Role:award() - - end end return RolePlugin \ No newline at end of file -- libgit2 0.21.2