找回密码
 点一下
查看: 958|回复: 4

分享一个攻击/技能捕捉的思路

[复制链接]
发表于 2008-2-29 11:24:29 | 显示全部楼层 |阅读模式
其实想法很简单...就是用自己的函数来模拟所有的魔兽伤害
1、在游戏平衡常数里将各种攻击(如普通、穿刺、攻城、法术等)对护甲的伤害因素设成0,只保留一个攻击方式(比如混乱)
2、然后对每个加入地图的单位设置“伤害捕捉事件”,这时记得在条件中判断伤害值是否等于1,为什么会等于1不是0,我也不知道……
3、然后使用自定义的伤害函数对单位造成实际伤害
4、法术伤害也是一样的,需要捕捉伤害时候可以使用一个隐藏单位释放模板技能,同时在该单位身上用缓存绑定上伤害的大小、种类等数据

当然这样做代价是非常大的,必须输入游戏中所有单位的数据,同时游戏效率也会降低(因为大量使用缓存),所以如果你希望保留魔兽争霸的的伤害规则,那这种捕捉攻击的方式并不合适

下面放上我地图里使用的一些函数,他们可以做到普通攻击、五行抗性的伤害和伤害显示,其中五行抗性具有超过100以后补充生命值的功能

//基础伤害函数
function DamageUnit takes player hurter, real damage, unit victim returns boolean
local unit caster=GetACaster()
call UnitRemoveAbility(caster,'Aloc') //Otherwise the units would flee like crazy
call CS_MoveUnit(caster,GetUnitX(victim),GetUnitY(victim))
call SetUnitOwner(caster,hurter,false)
call UnitDamageTarget(caster,victim,damage,true,false,Caster_DefaultAttackType(),Caster_DefaultDamageType(),null)
call RecicleCaster(caster)
return GetWidgetLife(victim)<=0 // I thought UnitDamageTarget returned true when it killed the unit, but nope, it returns true when it was able to do the damage.
endfunction

//治疗一个单位
function HealUnit takes unit whichUnit, real value returns nothing
call SetUnitLifeBJ(whichUnit, GetWidgetLife(whichUnit)+value)
endfunction

//补充一个单位的魔法值
function ManaUnit takes unit whichUnit, real value returns nothing
call SetUnitManaBJ(whichUnit, GetUnitState(whichUnit, UNIT_STATE_MANA)+value)
endfunction

//一方对另一方的普通伤害
function UnitDamageUnitNormal takes unit hurter, real damage, unit victim returns real
    local real ndi = I2R(UnitGetNormalDamageIncreaseRate(hurter))/100   //普攻加成
    local real dr = I2R(UnitGetDamageReduceRate(victim))/100            //普伤减少%
    local integer da = UnitGetDamageAbsorb(victim)                      //普伤减少
    local real rdi = I2R(UnitGetRaceDamageRate(hurter, UnitGetRace(victim)))/100 //种族加成
   
    //判断对方是否存活
    if GetWidgetLife(victim)>0 then
        //调整伤害
        set damage = damage *(1+rdi)* (1+ndi) * (1-dr) - da
        if damage > 1 then
            if IsAttackCritical(GetTriggerUnit()) then
                set damage = damage * 2
                call ShowTexttagToPlayer(GetOwningPlayer(hurter), victim, DyeDamage(I2S(R2I(damage))+"!" ))
            else
                call ShowTexttagToPlayer(GetOwningPlayer(hurter), victim, DyeDamage(I2S(R2I(damage))))
            endif
            call DamageUnit(GetOwningPlayer(hurter), damage, victim)
        else
            call DamageUnit(GetOwningPlayer(hurter), 1.1, victim) //为了避免和原始攻击的1混淆,这里使用1.1作为伤害值
            call ShowTexttagToPlayer(GetOwningPlayer(hurter), victim, DyeDamage("1") )
        endif
    else
        set damage = 0
    endif
    return damage
endfunction
//一方对另一方的仙术伤害
function UnitDamageUnitMagic takes unit hurter, real damage, integer magictype, unit victim returns real
    local integer mrr = UnitGetMagicResistReduce(hurter, magictype)                 //忽略仙术抗性
    local real mr = I2R(UnitGetMagicResistRate(victim, magictype)-mrr)/100          //仙术抗性
    local real mi = I2R(UnitGetMagicIncreaseRate(hurter, magictype))/100            //仙术伤害加成   
    local real rdi = I2R(UnitGetRaceDamageRate(hurter, UnitGetRace(victim)))/100    //种族加成  
   
    if GetWidgetLife(victim)>0 then
        //调整伤害
        set damage = damage * (1+rdi) * (1+mi) * (1-mr)
        if damage > 1 then //伤害大于1 正常显示
            call ShowTexttagWithHeightToPlayer(GetOwningPlayer(hurter), victim,udg_magicname[magictype]+I2S(R2I(damage))+"|r", magictype*40)
            call DamageUnit(GetOwningPlayer(hurter), damage, victim)
        elseif 0<=damage and damage <= 1 then //0-1之间的伤害 只显示1
            set damage = 1
            call DamageUnit(GetOwningPlayer(hurter), 1.1, victim)
            call ShowTexttagWithHeightToPlayer(GetOwningPlayer(hurter), victim, udg_magicname[magictype]+"1|r", magictype*40)
        else //负伤害值,仙抗吸收伤害转换成生命值
            call ShowTexttagWithHeightToPlayer(GetOwningPlayer(hurter), victim, DyeHeal(I2S(R2I(-damage))), magictype*40)
            call HealUnit(victim, -damage)
        endif
    else
        set damage = 0
    endif
    return damage
endfunction
发表于 2008-3-1 00:16:58 | 显示全部楼层
J的。。。而且在水区。。。
回复

使用道具 举报

发表于 2008-3-1 00:24:06 | 显示全部楼层
一切皆有可能.(梦魇兄.好久不见
回复

使用道具 举报

发表于 2008-3-1 00:27:16 | 显示全部楼层
5555555好深奥,好多函数见都没见过………………
回复

使用道具 举报

发表于 2008-3-1 04:23:59 | 显示全部楼层
开学了,水也少了~争取每天来10帖~
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 点一下

本版积分规则

Archiver|移动端|小黑屋|地精研究院

GMT+8, 2024-10-1 17:18 , Processed in 0.257079 second(s), 19 queries .

Powered by Discuz! X3.5

© 2001-2023 Discuz! Team.

快速回复 返回顶部 返回列表