init
This commit is contained in:
@@ -0,0 +1,290 @@
|
||||
--英雄系统
|
||||
--#include "data\config\Hero\HeroConfig.txt" once
|
||||
|
||||
--人物升级时判断是否自动给予英雄
|
||||
function AutoAddHero(sysarg,level)
|
||||
print("[DEBUG] AutoAddHero, level="..level)
|
||||
for k,v in ipairs(HeroConfig.HeroList) do
|
||||
if level >= v.OpenLevel and v.AutoGet == true then
|
||||
local hasHero = Hero.getHeroProperty(sysarg,k,0)
|
||||
if hasHero == 0 then
|
||||
if Hero.canAddHero(sysarg,false) == true then
|
||||
--添加英雄和技能
|
||||
Hero.addHero(sysarg,k,1,1)
|
||||
HeroLearnSkill(sysarg,k,1)
|
||||
Actor.sendTipmsg(sysarg, OldLang.Script.Hero006, ttFlyTip)
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
--英雄经验是否已满
|
||||
function HeroExpIsFull(sysarg,AddExp)
|
||||
local nHeroId = Hero.getBattleHeroId(sysarg)
|
||||
if nHeroId == -1 then
|
||||
nHeroId = 1
|
||||
end
|
||||
local Stage = Hero.getHeroProperty(sysarg,nHeroId,enHeroStage)
|
||||
if Stage == 0 then
|
||||
return false
|
||||
end
|
||||
local Level = Hero.getHeroProperty(sysarg,nHeroId,enHeroLevel)
|
||||
local Exp = Hero.getHeroProperty(sysarg,nHeroId,enHeroExp)
|
||||
local cfg = HeroConfig.HeroList[nHeroId]
|
||||
if not cfg then
|
||||
return false
|
||||
end
|
||||
local LevelCfg = cfg.Levels[Level]
|
||||
local StageCfg = cfg.Stages[Stage]
|
||||
if not StageCfg or not LevelCfg then
|
||||
return false
|
||||
end
|
||||
local MaxLevel = StageCfg.MaxLevel
|
||||
local MaxExp = LevelCfg.LevelUpExp
|
||||
if Level == MaxLevel and ((Exp + AddExp) >= MaxExp) then
|
||||
return true
|
||||
end
|
||||
return false
|
||||
end
|
||||
|
||||
--英雄升级
|
||||
function HeroLevelUp(sysarg)
|
||||
local nHeroId = Hero.getBattleHeroId(sysarg)
|
||||
if nHeroId == -1 then
|
||||
nHeroId = 1
|
||||
end
|
||||
local Stage = Hero.getHeroProperty(sysarg,nHeroId,enHeroStage)
|
||||
if Stage == 0 then
|
||||
return false
|
||||
end
|
||||
local Level = Hero.getHeroProperty(sysarg,nHeroId,enHeroLevel)
|
||||
local nExp = 0
|
||||
for i=1,#HeroConfig.HeroExpConfig do
|
||||
nExp = nExp + UseHeroLevlUpItem(sysarg, nHeroId, HeroConfig.HeroExpConfig[i].itemid, HeroConfig.HeroExpConfig[i].exp)
|
||||
end
|
||||
local NewLevel = Hero.getHeroProperty(sysarg,nHeroId,enHeroLevel)
|
||||
local AddLevel = NewLevel - Level
|
||||
if nExp > 0 then
|
||||
if AddLevel > 0 then
|
||||
Actor.sendTipmsg(sysarg, string.format(OldLang.Script.Hero013,nExp,AddLevel), ttFlyTip)
|
||||
else
|
||||
Actor.sendTipmsg(sysarg, string.format(OldLang.Script.Hero012,nExp), ttFlyTip)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
function UseHeroLevlUpItem(sysarg, nHeroId,itemidx,ItemExp)
|
||||
local count = Actor.getItemCount(sysarg, itemidx)
|
||||
if count == 0 then return 0 end
|
||||
--判断英雄等级是否已经到了本阶最高等级
|
||||
local Stage = Hero.getHeroProperty(sysarg,nHeroId,enHeroStage)
|
||||
local Level = Hero.getHeroProperty(sysarg,nHeroId,enHeroLevel)
|
||||
local Exp = Hero.getHeroProperty(sysarg,nHeroId,enHeroExp)
|
||||
local cfg = HeroConfig.HeroList[nHeroId]
|
||||
if not cfg then
|
||||
return 0
|
||||
end
|
||||
local LevelCfg = cfg.Levels[Level]
|
||||
local StageCfg = cfg.Stages[Stage]
|
||||
if not StageCfg or not LevelCfg then
|
||||
return 0
|
||||
end
|
||||
local MaxLevel = StageCfg.MaxLevel
|
||||
local MaxExp = LevelCfg.LevelUpExp
|
||||
if Level == MaxLevel and Exp >= MaxExp then
|
||||
return 0
|
||||
end
|
||||
local canAddExp = MaxExp - Exp
|
||||
if Level < MaxLevel then
|
||||
for idx = Level + 1, MaxLevel do
|
||||
LevelCfg = cfg.Levels[idx]
|
||||
canAddExp = canAddExp + LevelCfg.LevelUpExp
|
||||
end
|
||||
end
|
||||
local useCount = math.ceil(canAddExp/ItemExp)
|
||||
if useCount > count then
|
||||
useCount = count
|
||||
end
|
||||
local logId,logStr = 303,"HeroExp"
|
||||
|
||||
useCount = Actor.removeItem(sysarg,itemidx,useCount,-1,-1,-1,logStr,logId)
|
||||
if useCount > 0 then
|
||||
local addExp = ItemExp * useCount
|
||||
if addExp > canAddExp then
|
||||
addExp = canAddExp
|
||||
end
|
||||
Hero.addExp(sysarg, addExp,nHeroId)
|
||||
return addExp
|
||||
end
|
||||
return 0
|
||||
end
|
||||
|
||||
--英雄进阶
|
||||
function HeroUpStage(sysarg,heroid,stage,bless,count)
|
||||
--BaseFuc_Print("HeroUpStage:", heroid,stage,bless)
|
||||
if count <= 0 then
|
||||
return
|
||||
end
|
||||
local ybReplace = true
|
||||
if count == 1 then
|
||||
ybReplace = false
|
||||
end
|
||||
local HeroCfg = HeroConfig.HeroList[heroid]
|
||||
if not HeroCfg then
|
||||
return
|
||||
end
|
||||
local StageCfg = HeroCfg.Stages[stage]
|
||||
if not StageCfg then
|
||||
return
|
||||
end
|
||||
--已达最高阶
|
||||
local NewStageCfg = HeroCfg.Stages[stage+1]
|
||||
if not NewStageCfg then
|
||||
Actor.sendTipmsg(sysarg, OldLang.Script.Hero001, ttFlyTip)
|
||||
return
|
||||
end
|
||||
local oldbless = bless
|
||||
local realCount = count
|
||||
local Succ = false
|
||||
for i=1,count do
|
||||
if not CheckConsumeCondReplaceEx(sysarg, StageCfg.Consumes, i, ybReplace) then
|
||||
realCount = i-1
|
||||
break
|
||||
end
|
||||
--如果祝福值已满,进阶必成功,否则按几率提升
|
||||
if bless >= StageCfg.MaxBless then
|
||||
Succ = true
|
||||
realCount = i
|
||||
break
|
||||
else
|
||||
local RandNum = System.getRandomNumber(10000)
|
||||
if RandNum <= GetStageSuccRate(StageCfg.SuccRate,bless) then
|
||||
Succ = true
|
||||
realCount = i
|
||||
break
|
||||
else
|
||||
bless = bless + GetStageUpBless(StageCfg.AddBless)
|
||||
if bless > StageCfg.MaxBless then
|
||||
bless = StageCfg.MaxBless
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
if realCount <= 0 then
|
||||
return
|
||||
end
|
||||
Actor.sendTipmsg(sysarg, string.format(OldLang.Script.Hero010,realCount), ttTipmsgWindow)
|
||||
if not Succ then
|
||||
Actor.sendTipmsg(sysarg, string.format(OldLang.Script.Hero011,bless-oldbless), ttTipmsgWindow)
|
||||
end
|
||||
local logId, logStr = 92, "HeroStageUp"
|
||||
if UseConsumeCondReplaceEx(sysarg, StageCfg.Consumes, realCount, ybReplace, logId, logStr) ~= true then
|
||||
return
|
||||
end
|
||||
if Succ then
|
||||
local newStage = stage + 1
|
||||
Hero.StageUp(sysarg, heroid,newStage,0)
|
||||
Actor.sendTipmsg(sysarg, string.format(OldLang.Script.Hero002,newStage), ttFlyTip)
|
||||
--升阶成功,自动学习技能
|
||||
HeroLearnSkill(sysarg,heroid,newStage)
|
||||
local broadcast = StageCfg.broadcast or false
|
||||
if broadcast then
|
||||
local msg = string.format(OldLang.Script.Hero008,Actor.getName(sysarg),newStage)
|
||||
System.broadcastTipmsg(msg, ttScreenCenter + ttChatWindow,HeroCfg.OpenLevel)
|
||||
end
|
||||
else
|
||||
Hero.StageUp(sysarg,heroid,stage,bless)
|
||||
Actor.sendTipmsg(sysarg, OldLang.Script.Hero003, ttFlyTip)
|
||||
end
|
||||
end
|
||||
|
||||
function GetStageSuccRate(cfg,bless)
|
||||
for k,v in ipairs(cfg) do
|
||||
if bless >= v.Min and bless <= v.Max then
|
||||
return v.rate
|
||||
end
|
||||
end
|
||||
return 0
|
||||
end
|
||||
|
||||
function GetStageUpBless(cfg)
|
||||
local nMin,nMax = cfg[1], cfg[2]
|
||||
local rand = System.getRandomNumber(nMax - nMin) + nMin
|
||||
return rand
|
||||
end
|
||||
|
||||
--英雄学习技能
|
||||
function HeroLearnSkill(sysarg,heroid,stage)
|
||||
local HeroCfg = HeroConfig.HeroList[heroid]
|
||||
if not HeroCfg then
|
||||
return
|
||||
end
|
||||
for k, v in ipairs(HeroCfg.Skills) do
|
||||
if v.stage == stage and Hero.getSkillLevel(sysarg,heroid, v.skillid) <= 0 then
|
||||
local flag = Hero.learnSkill(sysarg,heroid,v.skillid)
|
||||
if flag then
|
||||
Actor.sendTipmsg(sysarg, OldLang.Script.Hero007, ttFlyTip)
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
--英雄技能升级
|
||||
function HeroUpSkill(sysarg,heroid,skillid,level)
|
||||
--BaseFuc_Print("HeroUpSkill:",heroid,skillid,level)
|
||||
local cfg = GetHeroSKill(heroid,skillid)
|
||||
if not cfg then
|
||||
return
|
||||
end
|
||||
local LevelCfg = cfg.Levels[level]
|
||||
if not LevelCfg then
|
||||
return
|
||||
end
|
||||
--所需阶
|
||||
local stage = Hero.getHeroProperty(sysarg,heroid,enHeroStage)
|
||||
if stage < LevelCfg.stage then
|
||||
Actor.sendTipmsg(sysarg, string.format(OldLang.Script.Hero004,LevelCfg.stage), ttFlyTip)
|
||||
return
|
||||
end
|
||||
--消耗
|
||||
if CommonFunc.Consumes.Check(sysarg, LevelCfg.Consumes) ~= true then
|
||||
return
|
||||
end
|
||||
local logId, logStr = 91, "HeroSkillUp"
|
||||
if CommonFunc.Consumes.Remove(sysarg, LevelCfg.Consumes, logId, logStr) ~= true then
|
||||
return
|
||||
end
|
||||
Hero.skillLevelUp(sysarg,heroid,skillid)
|
||||
Actor.sendTipmsg(sysarg, OldLang.Script.Hero005, ttFlyTip)
|
||||
end
|
||||
|
||||
function GetHeroSKill(heroid,skillid)
|
||||
if not HeroConfig.HeroList[heroid] then
|
||||
return nil
|
||||
end
|
||||
for k,v in ipairs(HeroConfig.HeroList[heroid].Skills) do
|
||||
if v.skillid == skillid then
|
||||
return v
|
||||
end
|
||||
end
|
||||
return nil
|
||||
end
|
||||
|
||||
--英雄给人物加BUFF
|
||||
function HeroAddBuffToOwner(sysarg,heroid,skillid,skilllevel)
|
||||
local SkillCfg = GetHeroSKill(heroid,skillid)
|
||||
if not SkillCfg then
|
||||
return
|
||||
end
|
||||
local SkillLevelCfg = SkillCfg.Levels[skilllevel] or nil
|
||||
if not SkillLevelCfg then
|
||||
return
|
||||
end
|
||||
local BuffCfg = SkillLevelCfg.Buff or nil
|
||||
if BuffCfg then
|
||||
for i=1,#BuffCfg do
|
||||
Actor.addBuffById(sysarg, BuffCfg[i])
|
||||
end
|
||||
end
|
||||
end
|
||||
Reference in New Issue
Block a user