找回密码
 点一下
查看: 5001|回复: 7

列表式物品合成函数

[复制链接]
发表于 2007-12-4 09:06:06 | 显示全部楼层 |阅读模式
这是一个列表式的物品合成函数,我按照自己的思路写出的一个算法,不知道好不好了


//合成需求物品判断<公式成立后删除条件物品,给予合成物品>
//参数<条件单位,反还金币,完成物品,条件物品(1),条件物品(2),条件物品(3),条件物品(4),条件物品(5),条件物品(6)>
[codes=jass]
function CompoundItemEstimate takes unit Unia,integer Gold,integer CompoundItem,integer i0,integer i1,integer i2,integer i3,integer i4,integer i5 returns nothing
    local integer array Item
    local integer Inta
    local integer Intb
    local integer Intc
    local integer Intd
    set Item[0]=i0
    set Item[1]=i1
    set Item[2]=i2
    set Item[3]=i3
    set Item[4]=i4
    set Item[5]=i5
    set Inta=0
    set Intb=0
    loop
        exitwhen Inta>5
        if Item[Inta]!=0 then
            set Intb=Intb+1
        endif
        set Inta=Inta+1
    endloop
    set Intd=Intb
    set Inta=0
    set Intb=0
    set Intc=0
    loop
        exitwhen Inta>Intd
        loop
            exitwhen Intb>5
            if GetItemTypeId(UnitItemInSlot(Unia,Intb))!=0 and GetItemTypeId(UnitItemInSlot(Unia,Intb))==Item[Inta] then
                set Item[Inta+5]=Item[Inta]
                set Item[Inta]=0
                set Intc=Intc+1
            endif
            set Intb=Intb+1
        endloop
        set Inta=Inta+1
        set Intb=0
    endloop
    set Inta=0
    set Intb=0
    if Intc>=Intd then
        loop
            exitwhen Inta>Intd
            loop
                exitwhen Intb>5
                if GetItemTypeId(UnitItemInSlot(Unia,Intb))==Item[Inta+5] then
                    call RemoveItem(UnitItemInSlot(Unia,Intb))
                    set Intb=5
                endif
                set Intb=Intb+1
            endloop
            set Inta=Inta+1
            set Intb=0
        endloop
        call UnitAddItemById(Unia,CompoundItem)
        call DestroyEffect(AddSpecialEffect("Abilities\\Spells\\Items\\AIlm\\AIlmTarget.mdx",GetUnitX(Unia),GetUnitY(Unia)))
    else
//未达到合成条件的文字信息<声音、文字、反还金币>
        if GetLocalPlayer()==GetOwningPlayer(Unia) then
            call StartSound(gg_snd_Error)
            call ClearTextMessages()
            call DisplayTimedTextToPlayer(GetOwningPlayer(Unia),0.51,0,10,"")
        endif
        call SetPlayerState(GetOwningPlayer(Unia),PLAYER_STATE_RESOURCE_GOLD,GetPlayerState(GetOwningPlayer(Unia),PLAYER_STATE_RESOURCE_GOLD)+Gold)
    endif
endfunction
[/codes]
//条件:执行判断<B00a=合成卷轴>
//call CompoundItemEstimate 是合成公式算法
[codes=jass]
function ItemCompoundEstimate takes nothing returns boolean
    local boolean Booa=GetItemTypeId(GetManipulatedItem())=='I020'
    if Booa then
        call CompoundItemEstimate(物品获得的单位,反还金币的多少,结果物品(为0时自动跳过),条件物品1(为0时自动跳过),条件物品2(为0时自动跳过),条件物品3(为0时自动跳过),条件物品4(为0时自动跳过),条件物品5(为0时自动跳过),条件物品6(为0时自动跳过))
    endif
    return false
endfunction
[/codes]

//事件:任意单位获得物品
[codes=jass]
function InitTrig_Item_Compound takes nothing returns nothing
    local integer Inta=2
    set gg_trg_Item_Compound=CreateTrigger()
    loop
        exitwhen Inta>11
        call TriggerRegisterPlayerUnitEvent(gg_trg_Item_Compound,Player(Inta),EVENT_PLAYER_UNIT_PICKUP_ITEM,null)
        set Inta=Inta+1
    endloop
    call TriggerAddCondition(gg_trg_Item_Compound,Condition(function ItemCompoundEstimate))
endfunction
[/codes]
发表于 2007-12-4 09:27:49 | 显示全部楼层
vivan.milk
这个号我登不上去了。。。。不知道是不是符号原因。。
回复

使用道具 举报

发表于 2007-12-4 10:49:11 | 显示全部楼层
楼主的Jass不错.        (实际上我不应该这么说的,这么说就太狂妄了,实际上我的Jass水平也一般)

不过有几点要说的. 你的代码我看过了,
问题1:         你可能没有考虑到同类合成,比如,用5把加10攻击的剑,合成一个加50攻的剑.
问题2:         代码全是你自己写的么?(如果是的话,你一定是看别人的东西看得太多啦,以至于受影响很深)
                    你的代码有很多奇怪的地方啊.
回复

使用道具 举报

发表于 2007-12-4 15:13:39 | 显示全部楼层
写是完全自己写的
影响。。?不知道。。怪?哪里。。?
厄,我都指出过,这函数只是我自己用的,要增加新功能那得修改咯`
回复

使用道具 举报

发表于 2007-12-4 22:58:39 | 显示全部楼层
那就说说这怪的地方吧.

1.只为玩家3到玩家12注册了触发,没有给玩家1和玩家2注册.
2.那个条件函数,多数人的写法会是:
[codes=jass]
function ItemCompoundEstimate takes nothing returns nothing
      if GetItemTypeId(GetManipulatedItem())=='I020' then
            call CompoundItemEstimate(...)
      endif
endfunction
[/codes]
因为条件函数可以不必返回boolean类型.
3.
[codes=jass]
call DestroyEffect(AddSpecialEffect(...))
[/codes]
这个地方,可以创建在单位身上的特效的,创建在点上反而不好,有的单位是飞行的,或是长得很大,创建在点上,极有可能会不美观.       (同一个点,可能是山丘的头上,也在恶魔猎手的腰上,或是在一个鸟的脚下)
4.
使用一个没有初使化的声音
5.
call DisplayTimedTextToPlayer(GetOwningPlayer(Unia),0.51,0,10,"")
这个位置好像是屏幕中间吧.     (怎么不写一点什么吧,比如"合成失败"之类的)
6.
其实,这个检查也不是很麻烦.
比如6个物品合成1个,(记为a,b,c,d,e)
那么,先取6个boolean型变量(ai,bi,ci,di,ei),都为false.   再取一个boolean型变量X,为True
之后呢,对每一个合成所须物品,从物品栏中搜索,如果找到了,就把相就的变量位记为true,比如a物品在物品栏3找到,就把ci记为true. 表示这个物品被使用了.

如果合成所须的某个物品没有找到,那么把X设为false,跳出循环.

在循环外面,先看X的值,如果X是True的话,说明循环正常结束,所有所须物品都找到了,那就把所有被标记为true的物品栏物品删掉,再添加合成后的物品.

如果X的值是False,说明是被跳出循环的,也就是说,合成条件不符,那么返回金钱就可以了.

而像你这样做,明显没有处理的就是同类合成.
比如dota中的法术头盔,是用  1个铁盔,1个流浪斗篷,2个回复戒指  合成出来的.
而按你的检查方案,身上有 1个铁盔,1个流浪斗篷,1个回复戒指 也会合成出来的.  
而且,身上有:1个铁盔,1个流浪斗篷,4个回复戒指 ,还会在合成成功的情况下,把4个回复戒指全部删掉
晚上头晕,看错,楼主的方法没有问题.
回复

使用道具 举报

发表于 2007-12-4 23:18:57 | 显示全部楼层
厄,我不知道你是否看错
声音的初始没写在那
然后除了特效那一点外其他都没有问题。
我有物品是需要a+b+b+c合成的
我携带了a、b、b、b、c、c合成成功了但没删除多余的物品
然后我新做了一个需要a+a+a+a合成的东西测试
仍然没有问题
回复

使用道具 举报

发表于 2007-12-4 23:20:22 | 显示全部楼层
然后你的思路也挺好,但也是其中一种方法。我习惯了我的方法~呵呵
另外条件返回那里是直接转了然后没删除-。-
回复

使用道具 举报

发表于 2007-12-6 10:47:32 | 显示全部楼层
确实有2个同类的东西只需要1个就可以合成了-。-
没做这样的判断。。。
回复

使用道具 举报

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

本版积分规则

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

GMT+8, 2024-5-22 12:52 , Processed in 0.052722 second(s), 19 queries .

Powered by Discuz! X3.5

© 2001-2023 Discuz! Team.

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