找回密码
 点一下
查看: 2148|回复: 1

常用函数教学:类型额外数据注册

[复制链接]
发表于 2009-10-7 17:58:18 | 显示全部楼层 |阅读模式
global:
integer  array              SYS_ItemId
integer  array              SYS_ItemInitIndex_Count
integer  array              SYS_SkillId
----------------------------------------------------
[jass]
function Mod takes integer m, integer d returns integer
    return m - (m / d) * d
endfunction

function Mod_EX takes integer m, integer d,integer p returns integer
    return (m - (m / d) * d)/p
endfunction

function BlizzardId2Int takes integer b returns integer
   local integer k = b
   local integer n
   local integer s = 0
   set n = Mod(k,256)
   set s = s+BlizzardId2IntSingle(n)
   set k = k - n
   set n = Mod_EX(k,65536,256)
   set s = s+BlizzardId2IntSingle(n)*36
   set k = k - n
   set n = Mod_EX(k,16777216,65536)
   set s = s+BlizzardId2IntSingle(n)*1296
   set k = k - n
   set n = k/16777216
   set s = s+BlizzardId2IntSingle(n)*46656
   return s
endfunction

function GetHashIndex takes integer i returns integer
    return Mod(i,8191)+1
endfunction

function GetNextHashIndex takes integer i returns integer
    return Mod(i*33,8191)+1
endfunction

function GetItemHashIndexById takes integer id returns integer
    local integer idEx = BlizzardId2Int(id)
    local integer tmp = GetHashIndex(idEx)
    local integer c = 0
    local integer i = 0
    local integer ci = SYS_ItemInitIndex_Count[tmp]
    loop
       exitwhen(c>ci)
       if(SYS_ItemId[tmp]!=null)then
          if(SYS_ItemId[tmp]==id)then
              return tmp
          endif
          set c = c + 1
       endif
       set tmp = GetNextHashIndex(tmp)
       set i = i + 1
    endloop
    return 0
endfunction

function RegisterItemHashIndexById takes integer id returns integer
    local integer idEx = BlizzardId2Int(id)
    local integer tmp = GetHashIndex(idEx)
    local integer c = 0
    local integer i = 0
    local integer ci = SYS_ItemInitIndex_Count[tmp]
    if(SYS_ItemInitIndex_Count[tmp]==null or SYS_ItemInitIndex_Count[tmp]==0)then
        set SYS_ItemInitIndex_Count[tmp] = 1
    else
        set SYS_ItemInitIndex_Count[tmp] = SYS_ItemInitIndex_Count[tmp] + 1
    endif
    loop
       exitwhen(c>ci)
       if(SYS_ItemInitIndex[tmp]==0)then
          set SYS_ItemId[tmp] = id
          return tmp
          set c = c + 1
       elseif(SYS_ItemId[tmp]==id)then
          return 0
       endif
       set tmp = GetNextHashIndex(tmp)
       set i = i + 1
    endloop
    return 0
endfunction
[/jass]

Sample:
[jass]
----------------------------
RegisterItemSkill:
local integer index
set index = RegisterItemHashIndexById('I000')
set SYS_SkillId = 'A000'
----------------------------
GetItemSkill:
local integer itemId = GetItemTypeId(itm)
local integer index = GetItemHashIndexById(itemId)
return SYS_SkillId[index]
[/jass]

评分

参与人数 1威望 +2 收起 理由
疯人¢衰人 + 2 简单的绑定……

查看全部评分

发表于 2009-10-7 23:50:11 | 显示全部楼层
呃,有点眼花了。

[codes=jass]
#     loop
#        exitwhen(c>ci or i>300)   //这个c和ci没用的吧,而且下面也没有加到
#        if(SYS_ItemInitIndex[tmp]==0 or SYS_ItemInitIndex[tmp]==null)then  //这个数组是不是有点问题呢
#           set SYS_ItemId[tmp] = id
#           return tmp
#           set c = c + 1
#        elseif(SYS_ItemId[tmp]==id)then
#           return 0
#        endif
#        set tmp = GetNextHashIndex(tmp)
#        set i = i + 1
#     endloop
[/codes]

还有eff兄你在水区的帖子被删了呢,我刷新下就消失了呃。
回复

使用道具 举报

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

本版积分规则

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

GMT+8, 2024-11-24 20:17 , Processed in 0.402529 second(s), 23 queries .

Powered by Discuz! X3.5

© 2001-2023 Discuz! Team.

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